@font-face {
  font-family: "Sarabun";
  src: url("assets/fonts/sarabun/Sarabun-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Sarabun";
  src: url("assets/fonts/sarabun/Sarabun-SemiBold.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Sarabun";
  src: url("assets/fonts/sarabun/Sarabun-Bold.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

:root {
  /* Keep full content font sizes without changing rem-based spacing. */
  --content-font-reduction: 0px;
  color-scheme: light;
  --medical-blue: #0f4c81;
  --light-blue: #eaf6ff;
  --surface: #ffffff;
  --surface-soft: #f7fbff;
  --text: #172033;
  --muted: #627083;
  --border: #d9e7f2;
  --ribbon-green: #28a745;
  --ribbon-green-dark: #21884d;
  --ribbon-green-light: #87d843;
  /* ธีมสีหลักของระบบ ปรับได้จากหน้า จัดการข้อมูลหลัก > ตั้งค่าธีมสี */
  --theme-sidebar-bg: var(--ribbon-green-dark);
  --theme-sidebar-start: #17683a;
  --theme-sidebar-end: #11552f;
  --theme-sidebar-text: #ffffff;
  --theme-sidebar-text-soft: rgba(255, 255, 255, 0.78);
  --theme-sidebar-accent-rgb: 135, 216, 67;
  --theme-header-start: #dff7d2;
  --theme-header-mid: #c8f0be;
  --theme-header-end: #edf6ef;
  --theme-header-dk-start: #86d73f;
  --theme-header-dk-mid: #2fb84f;
  --theme-header-dk-end: #087d5a;
  --theme-card-header-start: var(--ribbon-green-light);
  --theme-card-header-mid: var(--ribbon-green);
  --theme-card-header-end: var(--ribbon-green-dark);
  --theme-card-header-text: #ffffff;
  --theme-table-header-start: var(--ribbon-green-dark);
  --theme-table-header-end: var(--ribbon-green-dark);
  --theme-table-header-text: #ffffff;
  --success: #28a745;
  --warning: #ffc107;
  --orange: #f58220;
  --critical: #dc3545;
  --shadow: 0 16px 40px rgba(15, 76, 129, 0.12);
}

body.dark {
  color-scheme: dark;
  --surface: #111827;
  --surface-soft: #172033;
  --text: #eef6ff;
  --muted: #aab8ca;
  --border: #2f4054;
  --light-blue: #0b263f;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 150px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  font-size: calc(1rem - var(--content-font-reduction));
  margin: 0;
  min-height: 100vh;
  font-family: "Sarabun", "Segoe UI", Tahoma, Arial, sans-serif;
  font-weight: 400;
  line-height: 1.6;
  background: var(--light-blue);
  color: var(--text);
}

button, input, select, textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.22s ease;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background:
    linear-gradient(180deg, var(--theme-sidebar-start, #17683a) 0%, var(--theme-sidebar-bg, #21884d) 48%, var(--theme-sidebar-end, #11552f) 100%) !important;
  color: var(--theme-sidebar-text, #fff);
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: 10px 0 28px rgba(17, 85, 47, 0.18);
  overflow-x: hidden;
  overflow-y: auto;
  transition: padding 0.22s ease, gap 0.22s ease, box-shadow 0.22s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
}

.brand, .profile-mini {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.brand {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.brand-mark, .avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  color: var(--ribbon-green-dark);
  font-weight: 800;
}

.brand-mark {
  width: 103px;
  height: 103px;
  border-radius: 50%;
  overflow: hidden;
  padding: 6px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(17, 85, 47, 0.18);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  display: block;
}

.avatar {
  overflow: hidden;
}

.avatar img {
  width: var(--profile-zoom, 125%);
  height: var(--profile-zoom, 125%);
  object-fit: cover;
  transform: translate(var(--profile-x, 0), var(--profile-y, 0));
  display: block;
}

.brand span, .profile-mini span, .developer-credit span {
  display: block;
  margin-top: 3px;
  color: var(--theme-sidebar-text-soft, rgba(255,255,255,0.75));
  font-size: calc(0.82rem - var(--content-font-reduction, 0px));
}

.nav-list {
  display: grid;
  gap: 7px;
  flex: 0 0 auto;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--theme-sidebar-text-soft, rgba(255,255,255,0.82));
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
  background: rgba(var(--theme-sidebar-accent-rgb, 135, 216, 67), 0.2);
  border-color: rgba(var(--theme-sidebar-accent-rgb, 135, 216, 67), 0.32);
  color: var(--theme-sidebar-text, #fff);
  transform: translateX(2px);
}

.profile-mini {
  margin-top: 0;
  padding: 12px;
  border: 1px solid rgba(135,216,67,0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
}

.profile-mini > div:not(.avatar) {
  min-width: 0;
}

.profile-mini strong,
.profile-mini span {
  overflow-wrap: anywhere;
}

.developer-credit {
  padding: 12px;
  border-top: 1px solid rgba(135,216,67,0.24);
  flex: 0 0 auto;
}

.developer-credit strong {
  display: block;
  margin-top: 4px;
}

.sidebar-toggle {
  display: none;
}

@media (min-width: 1121px) {
  .app-shell {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .app-shell.sidebar-expanded {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .sidebar {
    padding: 18px 12px;
    gap: 18px;
    overflow-y: hidden;
  }

  .app-shell.sidebar-expanded .sidebar {
    padding: 24px 18px;
    gap: 24px;
    box-shadow: 14px 0 34px rgba(17, 85, 47, 0.24);
    overflow-y: auto;
  }

  .brand {
    align-items: center;
  }

  .app-shell.sidebar-expanded .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    transition: width 0.22s ease, height 0.22s ease;
  }

  .app-shell.sidebar-expanded .brand-mark {
    width: 103px;
    height: 103px;
  }

  .brand > div:not(.brand-mark),
  .nav-list,
  .profile-mini > div,
  .developer-credit {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-8px);
    transition: opacity 0.16s ease, transform 0.16s ease;
  }

  .nav-list,
  .developer-credit {
    display: none;
  }

  .app-shell.sidebar-expanded .brand > div:not(.brand-mark),
  .app-shell.sidebar-expanded .nav-list,
  .app-shell.sidebar-expanded .profile-mini > div,
  .app-shell.sidebar-expanded .developer-credit {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }

  .app-shell.sidebar-expanded .nav-list,
  .app-shell.sidebar-expanded .developer-credit {
    display: grid;
  }

  .app-shell.sidebar-expanded .developer-credit {
    display: block;
  }

  .profile-mini {
    justify-content: center;
    padding: 10px;
  }

  .app-shell.sidebar-expanded .profile-mini {
    justify-content: flex-start;
    padding: 12px;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 40px;
    min-height: 36px;
    padding: 0 8px;
    border: 1px solid rgba(var(--theme-sidebar-accent-rgb, 135, 216, 67), 0.32);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--theme-sidebar-text-soft, rgba(255, 255, 255, 0.9));
    font-weight: 700;
    cursor: pointer;
    flex: 0 0 auto;
    align-self: center;
    overflow: hidden;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
  }

  .sidebar-toggle:hover {
    background: rgba(var(--theme-sidebar-accent-rgb, 135, 216, 67), 0.2);
    border-color: rgba(var(--theme-sidebar-accent-rgb, 135, 216, 67), 0.5);
    color: var(--theme-sidebar-text, #fff);
  }

  .sidebar-toggle:focus-visible {
    outline: 2px solid rgba(135, 216, 67, 0.85);
    outline-offset: 2px;
  }

  .sidebar-toggle-icon {
    font-size: calc(1.05rem - var(--content-font-reduction, 0px));
    line-height: 1;
    transition: transform 0.22s ease;
  }

  .sidebar-toggle-label {
    display: none;
    white-space: nowrap;
    font-size: calc(0.85rem - var(--content-font-reduction, 0px));
  }

  .app-shell.sidebar-expanded .sidebar-toggle {
    width: 100%;
    justify-content: flex-start;
  }

  .app-shell.sidebar-expanded .sidebar-toggle-label {
    display: inline;
  }

  .app-shell.sidebar-expanded .sidebar-toggle-icon {
    transform: rotate(180deg);
  }
}

.main-content {
  min-width: 0;
  padding: 26px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 82px 22px 14px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.97) 0%, rgba(255, 255, 255, 0.85) 45%, rgba(255, 255, 255, 0.12) 100%) 0 0 / 100% 100% no-repeat,
    url("assets/images/hospital-kpi-header.png") right center / auto 140% no-repeat,
    linear-gradient(180deg, #ffffff 0%, #f4fbff 100%) !important;
  border: 1px solid rgba(217, 231, 242, 0.82) !important;
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(15, 76, 129, 0.16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.topbar::before,
.topbar::after {
  content: "";
  position: absolute;
  top: 0;
  height: 68px;
  pointer-events: none;
}

.topbar::before {
  left: 36px;
  width: min(64vw, 620px);
  z-index: 1;
  background:
    linear-gradient(90deg, var(--theme-header-start, #dff7d2) 0%, var(--theme-header-mid, #c8f0be) 42%, var(--theme-header-end, #edf6ef) 100%);
  box-shadow: 0 9px 18px rgba(17, 85, 47, 0.12);
  clip-path: polygon(0 0, 100% 0, calc(100% - 46px) 100%, 0 100%);
}

.topbar::after {
  left: min(34vw, 290px);
  width: min(46vw, 360px);
  top: 8px;
  z-index: 0;
  background: linear-gradient(90deg, rgba(6, 78, 59, 0.12), rgba(33, 136, 77, 0.12));
  clip-path: polygon(44px 0, 100% 0, calc(100% - 40px) 100%, 0 100%);
}

.topbar > * {
  position: relative;
  z-index: 2;
}

.topbar-title {
  position: static;
  z-index: auto;
  min-width: 0;
}

.topbar-title h1,
.topbar-title .program-credit {
  position: relative;
  z-index: 2;
  color: #064e3b;
}

body:not(.dark) .topbar-title h1,
body:not(.dark) .topbar-title .program-credit,
body:not(.dark) .topbar .eyebrow,
body:not(.dark) .topbar-hospital-name,
body:not(.dark) .topbar-hospital-detail {
  color: #064e3b !important;
  text-shadow: none;
}

.topbar .eyebrow {
  position: absolute;
  top: 0;
  left: 36px;
  width: min(64vw, 620px);
  height: 68px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 0 60px 0 14px;
  color: #ffffff;
  font-size: calc(clamp(1rem, 1.45vw, 1.35rem) - var(--content-font-reduction, 0px));
  font-weight: 900;
  line-height: 1.15;
  text-transform: none;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.topbar-hospital-name,
.topbar-hospital-detail {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-hospital-name {
  font-size: calc(clamp(1.3rem, 2.2vw, 2.1rem) - var(--content-font-reduction, 0px));
  letter-spacing: 0.2px;
}

body:not(.dark) header.topbar .eyebrow .topbar-hospital-name {
  text-shadow: 0 1px 2px rgba(6, 78, 59, 0.45), 0 2px 5px rgba(6, 78, 59, 0.35), 0 4px 10px rgba(0, 0, 0, 0.22) !important;
}

body.dark header.topbar .eyebrow .topbar-hospital-name {
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.75), 0 4px 12px rgba(0, 0, 0, 0.55) !important;
}

.topbar-title h1 {
  font-size: calc(clamp(1.15rem, 1.9vw, 1.9rem) - var(--content-font-reduction, 0px));
  font-weight: 800;
  letter-spacing: 0.2px;
}

body:not(.dark) .topbar-title h1 {
  text-shadow: 0 1px 2px rgba(6, 78, 59, 0.35), 0 3px 8px rgba(0, 0, 0, 0.18) !important;
}

body.dark .topbar-title h1 {
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.7), 0 4px 12px rgba(0, 0, 0, 0.5) !important;
}

.topbar-hospital-detail {
  margin-top: 5px;
  font-size: calc(clamp(0.8rem, 1.05vw, 1rem) - var(--content-font-reduction, 0px));
  font-weight: 800;
  letter-spacing: -0.3px;
  opacity: 1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--medical-blue);
  font-size: calc(0.78rem - var(--content-font-reduction, 0px));
  font-weight: 800;
  text-transform: uppercase;
}

body.dark .eyebrow { color: #8cc7ff; }

body.dark .topbar {
  background:
    linear-gradient(90deg, rgba(17, 24, 39, 0.98) 0%, rgba(17, 24, 39, 0.98) 65%, rgba(17, 24, 39, 0.55) 100%) 0 0 / 100% 100% no-repeat,
    url("assets/images/hospital-kpi-header.png") right center / auto 140% no-repeat,
    linear-gradient(180deg, #111827 0%, #020617 100%) !important;
  border-color: rgba(47, 64, 84, 0.86) !important;
}

body.dark .topbar::before {
  background: linear-gradient(90deg, var(--theme-header-dk-start, #86d73f) 0%, var(--theme-header-dk-mid, #2fb84f) 42%, var(--theme-header-dk-end, #087d5a) 100%);
  box-shadow: 0 9px 18px rgba(17, 85, 47, 0.22);
}

body.dark .topbar-title h1,
body.dark .topbar-title .program-credit {
  color: #ffffff !important;
}

body.dark .topbar::after { background: rgba(214, 222, 230, 0.28); }

body.dark .topbar-sub {
  background: linear-gradient(180deg, #111827 0%, #020617 100%) !important;
  border-color: rgba(47, 64, 84, 0.86) !important;
}

body.dark .fallback-value,
body.dark .fallback-bar-item small {
  color: #e5edf6;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: calc(clamp(1.55rem, 2vw, 2.3rem) - var(--content-font-reduction, 0px)); }
h2 { margin-bottom: 0; font-size: calc(1.35rem - var(--content-font-reduction, 0px)); }
h3 { margin-bottom: 0; font-size: calc(1rem - var(--content-font-reduction, 0px)); }

.program-credit {
  margin: 7px 0 0;
  font-size: calc(0.92rem - var(--content-font-reduction, 0px));
  font-weight: 700;
}

.section-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: calc(0.9rem - var(--content-font-reduction, 0px));
}

.topbar-actions, .report-actions, .table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-actions select {
  width: auto;
  flex: 0 1 auto;
  min-width: 150px;
}

.topbar-actions {
  justify-content: flex-end;
  min-width: 0;
}

#departmentFilter, #categoryFilter {
  flex: 1 1 180px;
  min-width: 0;
  max-width: 100%;
}

.topbar-actions :is(#departmentFilter, #categoryFilter, #yearFilter) {
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.topbar-actions :is(#departmentFilter, #categoryFilter, #yearFilter):hover,
#kpiForm :is(input:not([type="hidden"]), select, textarea):not(:disabled):hover,
#entry :is(input:not([type="hidden"]), select, textarea):not(:disabled):hover {
  border-color: #08795f;
  background-color: #effaf5;
  box-shadow: 0 0 0 3px rgba(8, 121, 95, 0.12), 0 4px 12px rgba(8, 121, 95, 0.12);
}

.topbar-actions :is(#departmentFilter, #categoryFilter, #yearFilter):focus-visible,
#kpiForm :is(input:not([type="hidden"]), select, textarea):not(:disabled):focus-visible,
#entry :is(input:not([type="hidden"]), select, textarea):not(:disabled):focus-visible {
  outline: 2px solid #08795f;
  outline-offset: 2px;
}

body.dark .topbar-actions :is(#departmentFilter, #categoryFilter, #yearFilter):hover,
body.dark #kpiForm :is(input:not([type="hidden"]), select, textarea):not(:disabled):hover,
body.dark #entry :is(input:not([type="hidden"]), select, textarea):not(:disabled):hover {
  border-color: #6ee7b7;
  background-color: #173d33;
  box-shadow: 0 0 0 3px rgba(110, 231, 183, 0.15), 0 4px 12px rgba(0, 0, 0, 0.2);
}

body.dark .topbar-actions :is(#departmentFilter, #categoryFilter, #yearFilter):focus-visible,
body.dark #kpiForm :is(input:not([type="hidden"]), select, textarea):not(:disabled):focus-visible,
body.dark #entry :is(input:not([type="hidden"]), select, textarea):not(:disabled):focus-visible {
  outline-color: #6ee7b7;
}

#kpiForm :is(input:not([type="hidden"]), select, textarea):not(:disabled),
#entry :is(input:not([type="hidden"]), select, textarea):not(:disabled) {
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

#kpiForm select:not(:disabled), #entry select:not(:disabled) { cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  .topbar-actions :is(#departmentFilter, #categoryFilter, #yearFilter),
  #kpiForm :is(input:not([type="hidden"]), select, textarea):not(:disabled),
  #entry :is(input:not([type="hidden"]), select, textarea):not(:disabled) { transition: none; }
}

.topbar-actions .filter-note {
  flex-basis: 100%;
  width: 100%;
  margin: 2px 0 0;
  text-align: right;
  color: var(--muted);
  font-size: calc(0.88rem - var(--content-font-reduction, 0px));
  font-weight: 600;
}

body.dark .topbar-actions .filter-note {
  color: #93a4b8;
}

.manual-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.manual-option {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background-color: var(--surface);
  background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.88) 45%, rgba(255, 255, 255, 0.5) 100%), var(--manual-background);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.manual-option--pptx {
  --manual-background: url("manual/images/pptx-background.png");
}

.manual-option--mp4 {
  --manual-background: url("manual/images/mp4-background.png");
}

body.dark .manual-option {
  background-image: linear-gradient(90deg, rgba(17, 24, 39, 0.97) 0%, rgba(17, 24, 39, 0.9) 45%, rgba(17, 24, 39, 0.68) 100%), var(--manual-background);
}

.manual-format {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--light-blue);
  color: var(--text);
  font-weight: 700;
}

.manual-option h3 { margin: 16px 0 8px; }
.manual-option p { color: var(--text); line-height: 1.7; margin: 0 0 20px; }
.manual-option a { display: inline-block; text-decoration: none; }
.manual-option .primary-button, .manual-option .secondary-button { margin: 0 6px 8px 0; }
.manual-video-panel { margin-top: 24px; }
.manual-video-panel video { display: block; width: 100%; max-height: 70vh; border-radius: 12px; background: #000; }

.manual-chapters { margin-top: 24px; }
.manual-chapter-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.manual-chapter-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  font-size: calc(0.78rem - var(--content-font-reduction, 0px));
  line-height: 1.45;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
.manual-chapter-title { grid-column: 1 / -1; font-weight: 700; overflow-wrap: anywhere; }
.manual-chapter-time { grid-column: 2; grid-row: 2; align-self: end; color: var(--muted); font-size: calc(0.72rem - var(--content-font-reduction, 0px)); font-variant-numeric: tabular-nums; }
.manual-chapter-action { grid-column: 1; grid-row: 2; align-self: end; color: #08795f; font-weight: 700; font-size: calc(0.72rem - var(--content-font-reduction, 0px)); }
.manual-chapter-button.is-active { border-color: #08795f; background: var(--light-blue); }
.manual-chapter-button:hover { border-color: #08795f; background: #e6f5ee; box-shadow: 0 4px 12px rgba(8, 121, 95, 0.16); transform: translateY(-2px); }
.manual-chapter-button:focus-visible { outline: 3px solid #08795f; outline-offset: 3px; }
.manual-current-topic { color: var(--text); font-weight: 700; margin: 0 0 8px; }
#manualVideoStatus { margin-bottom: 12px; }
#manualVideoStatus:empty { display: none; }
body.dark .manual-chapter-action { color: #6ee7b7; }
body.dark .manual-chapter-button:hover, body.dark .manual-chapter-button.is-active { border-color: #6ee7b7; }
body.dark .manual-chapter-button:hover { background: #173d33; }

@media (prefers-reduced-motion: reduce) {
  .manual-chapter-button { transition: none; }
  .manual-chapter-button:hover { transform: none; }
}

@media (max-width: 1000px) {
  .manual-chapter-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .manual-options { grid-template-columns: 1fr; }
  .manual-option { padding: 18px; }
  .manual-chapter-list { grid-template-columns: 1fr; }
}

.topbar-sub {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 12px;
  padding: 16px 22px;
  background: linear-gradient(180deg, #ffffff 0%, #f4fbff 100%) !important;
  border: 1px solid rgba(217, 231, 242, 0.82) !important;
  border-radius: 8px;
  box-shadow: 0 20px 46px rgba(15, 76, 129, 0.14);
}

.topbar-auth {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 100%;
}

select, input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
}

.icon-button, .primary-button, .secondary-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.icon-button {
  width: 42px;
  background: var(--surface);
  color: var(--ribbon-green-dark);
  border: 1px solid rgba(33, 136, 77, 0.28);
}

.primary-button {
  padding: 0 16px;
  color: #fff;
  background: var(--ribbon-green-dark);
  font-weight: 700;
}

.secondary-button {
  padding: 0 14px;
  color: var(--ribbon-green-dark);
  background: var(--surface);
  border: 1px solid rgba(33, 136, 77, 0.28);
  font-weight: 700;
}

.primary-button:not(:disabled):hover,
.secondary-button:not(:disabled):hover,
.icon-button:not(:disabled):hover {
  color: #ffffff;
  background: #17683a;
  border-color: #17683a;
  box-shadow: 0 8px 18px rgba(33, 136, 77, 0.24);
  transform: translateY(-1px);
}

.primary-button:not(:disabled):active,
.secondary-button:not(:disabled):active,
.icon-button:not(:disabled):active {
  transform: translateY(0);
  box-shadow: 0 4px 10px rgba(33, 136, 77, 0.2);
}

.primary-button:focus-visible,
.secondary-button:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid rgba(135, 216, 67, 0.38);
  outline-offset: 2px;
}

body.dark .secondary-button, body.dark .icon-button { color: #bff0c9; }

.hidden { display: none !important; }

.auth-status {
  max-width: 260px;
  color: var(--muted);
  font-size: calc(0.9rem - var(--content-font-reduction, 0px));
  font-weight: 700;
}

.topbar-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--medical-blue);
  font-weight: 900;
  flex: 0 0 auto;
}

.topbar-avatar img {
  width: var(--profile-zoom, 125%);
  height: var(--profile-zoom, 125%);
  object-fit: cover;
  transform: translate(var(--profile-x, 0), var(--profile-y, 0));
  display: block;
}

.danger-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(220, 53, 69, 0.25);
  border-radius: 8px;
  color: #fff;
  background: var(--critical);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.section-band {
  margin-bottom: 12px;
  padding: 22px;
  background: rgba(255,255,255,0.58);
  border: 1px solid var(--border);
  border-radius: 8px;
}

body.dark .section-band { background: rgba(17,24,39,0.78); }

#kpi-management {
  background:
    linear-gradient(180deg, rgba(204, 232, 247, 0.96), rgba(229, 244, 252, 0.78));
}

body.dark #kpi-management {
  background:
    linear-gradient(180deg, rgba(15, 76, 129, 0.42), rgba(17, 24, 39, 0.86));
}

.section-heading, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.live-pill, .status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: calc(0.86rem - var(--content-font-reduction, 0px));
}

.live-pill span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(40,167,69,0.15);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.access-metric-grid {
  margin-top: 14px;
}

.access-count { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.access-count-unit { font-size: calc(0.78rem - var(--content-font-reduction, 0px)); }
.access-stats-note { margin: 10px 0 0; line-height: 1.6; }

[data-access-detail] { cursor: pointer; transition: transform 0.18s ease, box-shadow 0.18s ease; }
[data-access-detail]:is(:hover, :focus-visible) {
  transform: translateY(-3px);
  outline: 2px solid var(--primary, #08795f);
  outline-offset: 2px;
}
.access-detail-popup {
  position: fixed;
  z-index: 120;
  width: min(760px, calc(100vw - 20px));
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 14px 45px rgba(0, 55, 42, 0.22);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.access-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.access-detail-head h3 { margin: 0; font-size: 0.95rem; font-weight: 600; }
.access-detail-head button { padding: 4px 10px; }
.access-detail-popup .section-note { margin: 0; font-size: 0.76rem; }
.access-detail-table { overflow: auto; min-height: 0; }
.access-detail-table table { width: 100%; min-width: 660px; border-collapse: collapse; font-size: 0.76rem; }
.access-detail-table :is(th, td) { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.access-detail-table th { position: sticky; top: 0; background: #08795f; color: #fff; white-space: nowrap; }
.access-detail-table td { overflow-wrap: anywhere; min-width: 90px; }
.access-detail-table tbody tr:hover { background: rgba(8, 121, 95, 0.08); }
.access-detail-empty { text-align: center !important; color: var(--muted); }

.metric-card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
  border-left: 5px solid var(--medical-blue);
}

.metric-card.success { border-left-color: var(--success); }
.metric-card.warning { border-left-color: var(--warning); }
.metric-card.danger { border-left-color: var(--critical); }

#executive .metric-kpi-total { --metric-art: url("assets/images/dashboard/kpi-total.png"); }
#executive .metric-kpi-passed { --metric-art: url("assets/images/dashboard/kpi-passed.png"); }
#executive .metric-kpi-watch { --metric-art: url("assets/images/dashboard/kpi-watch.png"); }
#executive .metric-kpi-critical { --metric-art: url("assets/images/dashboard/kpi-critical.png"); }
#executive .metric-access-total { --metric-art: url("assets/images/dashboard/access-total.png"); }
#executive .metric-access-today { --metric-art: url("assets/images/dashboard/access-today.png"); }
#executive .metric-access-signins { --metric-art: url("assets/images/dashboard/access-signins.png"); }
#executive .metric-access-departments { --metric-art: url("assets/images/dashboard/access-departments.png"); }

#executive .metric-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

#executive .metric-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.85) 35%, rgba(255, 255, 255, 0.28) 100%), var(--metric-art);
  background-position: center, right center;
  background-size: cover, cover;
  background-repeat: no-repeat;
  opacity: 0.8;
  pointer-events: none;
}

body.dark #executive .metric-card::before {
  background-image: linear-gradient(90deg, rgba(15, 23, 42, 0.98) 0%, rgba(15, 23, 42, 0.88) 40%, rgba(15, 23, 42, 0.58) 100%), var(--metric-art);
  opacity: 0.7;
}

.metric-card span, .metric-card small, .panel-head span {
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 9px 0 5px;
  font-size: calc(2rem - var(--content-font-reduction, 0px));
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.executive-summary-panel {
  margin: 18px 0;
}

.panel {
  position: relative;
  padding: 16px;
  padding-top: 66px;
  overflow: hidden;
  min-width: 0;
}

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  height: 37px;
  pointer-events: none;
}

.panel::before {
  top: 0;
  left: 38px;
  width: min(80%, 420px);
  z-index: 1;
  background: linear-gradient(90deg, var(--theme-card-header-start, #87d843) 0%, var(--theme-card-header-mid, #28a745) 58%, var(--theme-card-header-end, #21884d) 100%);
  clip-path: polygon(0 0, 100% 0, calc(100% - 46px) 100%, 0 100%);
}

.panel::after {
  top: 8px;
  left: min(45%, 220px);
  width: min(46%, 260px);
  z-index: 0;
  background: rgba(112, 112, 112, 0.38);
  clip-path: polygon(44px 0, 100% 0, calc(100% - 40px) 100%, 0 100%);
}

.panel > * {
  position: relative;
  z-index: 2;
}

.panel .panel-head {
  position: absolute;
  top: 0;
  left: 38px;
  width: min(80%, 420px);
  height: 37px;
  margin: 0;
  padding: 0 56px 0 14px;
  align-items: center;
  color: #ffffff;
  z-index: 3;
  pointer-events: none;
}

.panel .panel-head h3,
.panel .panel-head span {
  color: var(--theme-card-header-text, #ffffff);
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.panel .panel-head h3 {
  min-width: 0;
}

.panel .panel-head span {
  flex: 0 1 auto;
  font-weight: 700;
  opacity: 0.92;
}

body.dark .panel::after { background: rgba(214, 222, 230, 0.24); }

/* หัวกราฟ Dashboard ต้องแสดงข้อความครบและขยายตามจำนวนบรรทัด */
:is(#executive, #history-dashboard) .panel {
  padding-top: 16px;
}

:is(#executive, #history-dashboard) .panel::before,
:is(#executive, #history-dashboard) .panel::after {
  display: none;
}

:is(#executive, #history-dashboard) .panel .panel-head {
  position: relative;
  top: auto;
  left: auto;
  width: 100%;
  height: auto;
  min-height: 37px;
  margin: -16px 0 16px;
  padding: 10px 34px 10px 14px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 3px;
  background: linear-gradient(90deg, var(--theme-card-header-start, #87d843) 0%, var(--theme-card-header-mid, #28a745) 58%, var(--theme-card-header-end, #21884d) 100%);
  clip-path: polygon(0 0, 100% 0, calc(100% - 24px) 100%, 0 100%);
}

:is(#executive, #history-dashboard) .panel .panel-head h3,
:is(#executive, #history-dashboard) .panel .panel-head span {
  max-width: 100%;
  margin: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

:is(#executive, #history-dashboard) .panel .panel-head h3 {
  font-size: calc(0.9rem - var(--content-font-reduction, 0px));
}

:is(#executive, #history-dashboard) .panel .panel-head span {
  font-size: calc(0.75rem - var(--content-font-reduction, 0px));
}

#executive .kpi-chart-title {
  flex-wrap: wrap;
  gap: 6px 10px;
}

#executive .kpi-chart-title strong {
  flex: 1 1 180px;
  max-width: 100%;
  font-size: calc(0.86rem - var(--content-font-reduction, 0px));
  line-height: 1.5;
  white-space: normal;
  overflow-wrap: anywhere;
}

#executive .kpi-chart-actions {
  flex: 0 1 auto;
  max-width: 100%;
}

#executive .kpi-chart-title small {
  white-space: normal;
  overflow-wrap: anywhere;
}

.panel.wide { grid-column: span 2; }

.dashboard-grid .panel.heatmap-panel { grid-column: 1 / -1; }

.chart-wrap {
  position: relative;
  height: 290px;
}

.chart-wrap.tall-chart {
  height: 330px;
}

.historical-dashboard-grid {
  align-items: stretch;
}

.historical-table-wrap {
  max-height: 330px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.historical-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: calc(0.88rem - var(--content-font-reduction, 0px));
}

.historical-table th,
.historical-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: top;
}

.historical-table th:first-child,
.historical-table td:first-child {
  width: 42%;
  text-align: left;
}

.historical-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #ffffff;
  background: var(--medical-blue);
}

.historical-table td strong,
.historical-table td span {
  display: block;
}

.historical-table td span {
  margin-top: 4px;
  color: var(--muted);
  font-size: calc(0.78rem - var(--content-font-reduction, 0px));
}

.kpi-chart-grid {
  display: grid;
  gap: 12px;
  max-height: 620px;
  overflow: auto;
  padding-right: 2px;
}

.trend-chart-grid {
  grid-template-columns: 1fr;
}

.status-chart-grid {
  grid-template-columns: 1fr;
}

.kpi-chart-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-chart-grid .kpi-chart-card {
  padding: 10px;
}

.kpi-chart-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
  margin-bottom: 8px;
}

.kpi-chart-title strong {
  min-width: 0;
  font-size: calc(0.95rem - var(--content-font-reduction, 0px));
  line-height: 1.25;
}

.kpi-chart-title small {
  color: var(--muted);
  white-space: nowrap;
}

.kpi-chart-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.chart-export-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(33, 136, 77, 0.26);
  border-radius: 8px;
  color: var(--ribbon-green-dark);
  background: var(--surface);
  cursor: pointer;
  font-size: calc(0.78rem - var(--content-font-reduction, 0px));
  font-weight: 800;
  white-space: nowrap;
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.chart-export-button:not(:disabled):hover {
  color: #ffffff;
  background: #17683a;
  border-color: #17683a;
  box-shadow: 0 7px 16px rgba(33, 136, 77, 0.22);
  transform: translateY(-1px);
}

.chart-export-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.chart-export-frame {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.chart-export-toolbar {
  display: flex;
  justify-content: flex-end;
}

.chart-export-surface {
  min-width: 0;
  min-height: 0;
  padding: 2px;
  border-radius: 8px;
  background: var(--surface);
}

.kpi-mini-chart {
  position: relative;
  height: 238px;
  overflow-x: auto;
  overflow-y: hidden;
}

.status-chart-grid .kpi-mini-chart {
  height: 138px;
}

.empty-chart-state {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
}

.fallback-bars {
  height: 100%;
  width: 100%;
  min-width: 520px;
  min-height: 208px;
  display: grid;
  grid-template-columns: repeat(12, minmax(32px, 1fr));
  gap: 9px;
  align-items: end;
  padding: 34px 4px 42px;
  position: relative;
}

.fallback-bar-item {
  height: 100%;
  position: relative;
  min-width: 0;
}

.fallback-value {
  position: absolute;
  left: 50%;
  bottom: calc(27px + var(--bar-height, 0%) + 5px);
  min-height: 18px;
  max-width: 100%;
  font-size: calc(0.76rem - var(--content-font-reduction, 0px));
  font-weight: 900;
  line-height: 1;
  color: #0f172a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: rotate(-35deg);
  transform-origin: center bottom;
  translate: -50% 0;
}

.fallback-bar {
  position: absolute;
  left: 50%;
  bottom: 27px;
  width: min(56%, 24px);
  height: var(--bar-height, 0%);
  min-height: 0;
  border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--medical-blue), #5aa1d8);
  translate: -50% 0;
}

.fallback-bar.below-target {
  background: linear-gradient(180deg, #dc3545, #f87171);
}

.fallback-bar-item small {
  position: absolute;
  left: 50%;
  bottom: 0;
  color: #334155;
  font-size: calc(0.76rem - var(--content-font-reduction, 0px));
  font-weight: 800;
  line-height: 1;
  transform: rotate(-35deg);
  transform-origin: center top;
  white-space: nowrap;
  translate: -50% 0;
}

.fallback-target {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  padding-top: 6px;
  border-top: 2px dashed var(--critical);
  color: var(--muted);
  font-size: calc(0.78rem - var(--content-font-reduction, 0px));
}

.fallback-status {
  min-height: 150px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.fallback-status strong {
  font-size: calc(2rem - var(--content-font-reduction, 0px));
}

.fallback-status.ok strong { color: var(--success); }
.fallback-status.warn strong { color: var(--warning); }
.fallback-status.risk strong { color: var(--critical); }

.fallback-donut {
  width: 140px;
  height: 140px;
  margin: 4px auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--status-color) var(--value), rgba(148,163,184,0.22) 0);
}

.status-chart-grid .fallback-donut {
  width: 104px;
  height: 104px;
  margin: 0 auto 8px;
}

.status-chart-grid .fallback-donut-core {
  width: 64px;
  height: 64px;
}

.status-chart-grid .fallback-donut-core strong {
  font-size: calc(1rem - var(--content-font-reduction, 0px));
}

.status-chart-grid .fallback-donut-core span,
.status-chart-grid .fallback-status-text {
  font-size: calc(0.72rem - var(--content-font-reduction, 0px));
}

.fallback-donut-core {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  background: var(--surface-soft);
}

.fallback-donut-core strong {
  font-size: calc(1.35rem - var(--content-font-reduction, 0px));
}

.fallback-donut-core span, .fallback-status-text {
  color: var(--muted);
  font-size: calc(0.82rem - var(--content-font-reduction, 0px));
}

.fallback-status-text {
  text-align: center;
  font-weight: 800;
}

.fallback-status-text.ok { color: var(--success); }
.fallback-status-text.warn { color: var(--warning); }
.fallback-status-text.risk { color: var(--critical); }

.analytics-bars {
  min-height: 240px;
  display: grid;
  gap: 12px;
  align-content: center;
}

.analytics-bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(130px, 2fr) 56px;
  gap: 10px;
  align-items: center;
}

.analytics-bar-row strong {
  font-size: calc(0.9rem - var(--content-font-reduction, 0px));
}

.analytics-bar-track {
  height: 18px;
  border-radius: 999px;
  background: rgba(148,163,184,0.2);
  overflow: hidden;
}

.analytics-bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.analytics-bar-row em, .balance-item em {
  color: var(--text);
  font-style: normal;
  font-weight: 900;
  text-align: right;
}

.analytics-balance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-content: center;
}

.analytics-radar-layout {
  min-height: 240px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 1fr);
  gap: 12px;
  align-items: start;
}

.analytics-radar {
  width: min(100%, 300px);
  min-height: 240px;
  justify-self: center;
  overflow: visible;
}

.radar-ring {
  fill: none;
  stroke: var(--border);
  stroke-width: 1;
}

.radar-axis {
  stroke: var(--border);
  stroke-width: 1;
}

.radar-area {
  fill: rgba(15,76,129,0.18);
  stroke: none;
}

.radar-line {
  fill: none;
  stroke: var(--medical-blue);
  stroke-width: 3;
  stroke-linejoin: round;
}

.radar-dot {
  fill: var(--medical-blue);
  stroke: var(--surface);
  stroke-width: 2;
}

.radar-label {
  fill: var(--muted);
  font-size: calc(9px - var(--content-font-reduction, 0px));
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}

.radar-value {
  fill: var(--text);
  font-size: calc(9px - var(--content-font-reduction, 0px));
  font-weight: 900;
  text-anchor: middle;
}

.balance-item {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  display: grid;
  gap: 8px;
  min-height: 86px;
}

.balance-item strong {
  min-height: 32px;
  font-size: calc(0.88rem - var(--content-font-reduction, 0px));
}

.balance-meter {
  height: 10px;
  border-radius: 999px;
  background: rgba(148,163,184,0.22);
  overflow: hidden;
}

.balance-meter span {
  display: block;
  width: var(--value);
  height: 100%;
  border-radius: inherit;
  background: var(--meter-color);
}

.ranking-list, .insight-list, .alert-grid, .user-grid {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.ranking-item, .insight-item, .alert-item, .user-card, .audit-row {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.user-card {
  display: grid;
  align-content: start;
  gap: 6px;
}

.user-table {
  width: 100%;
  min-width: 1120px;
}

.user-table th,
.user-table td {
  vertical-align: top;
  white-space: nowrap;
}

.user-table-actions {
  align-items: flex-start;
  min-width: 360px;
}

.user-role-form {
  display: grid;
  gap: 8px;
  min-width: 360px;
}

.user-role-form label {
  display: grid;
  gap: 5px;
  font-weight: 800;
}

.user-role-form select {
  width: min(100%, 320px);
}

#users {
  overflow: hidden;
}

.user-summary { margin-bottom: 20px; }
.user-summary-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.user-summary-total { display: flex; align-items: baseline; gap: 8px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--light-blue); }
.user-summary-total strong { font-size: calc(1.5rem - var(--content-font-reduction, 0px)); color: var(--text); }
.user-role-summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.user-role-summary-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.user-role-summary-card > div:first-child { min-width: 0; }
.user-role-summary-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.user-role-summary-card small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.5; }
.user-role-summary-count { display: flex; align-items: baseline; gap: 6px; flex-shrink: 0; }
.user-role-summary-count strong { font-size: calc(1.5rem - var(--content-font-reduction, 0px)); }
.user-role-summary-count span { color: var(--muted); font-size: calc(0.78rem - var(--content-font-reduction, 0px)); }

@media (max-width: 1000px) { .user-role-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 680px) { .user-role-summary-grid { grid-template-columns: 1fr; } }

.user-grid > * {
  min-width: 0;
}

.user-grid .user-table-wrap {
  grid-column: 1 / -1;
}

.user-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: auto;
}

.user-table-wrap::-webkit-scrollbar {
  height: 12px;
}

.user-table-wrap::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--ribbon-green-dark);
}

.user-table-wrap::-webkit-scrollbar-track {
  background: var(--surface-soft);
}

.user-card-avatar,
.user-list-avatar {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--medical-blue);
  font-weight: 900;
}

.user-card-avatar img,
.user-list-avatar img {
  width: var(--profile-zoom, 125%);
  height: var(--profile-zoom, 125%);
  object-fit: cover;
  transform: translate(var(--profile-x, 0), var(--profile-y, 0));
  display: block;
}

.ranking-item {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
}

.progress {
  height: 9px;
  margin-top: 7px;
  border-radius: 999px;
  background: #d8e8f5;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--success);
}

.heatmap {
  display: grid;
  grid-template-columns: 150px repeat(8, minmax(70px, 1fr));
  gap: 7px;
  overflow-x: auto;
}

.heat-cell {
  min-height: 46px;
  padding: 8px;
  border-radius: 8px;
  color: #fff;
  font-size: calc(0.82rem - var(--content-font-reduction, 0px));
  font-weight: 700;
}

.heat-label {
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

input[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
  cursor: not-allowed;
}

#kpiForm select:disabled {
  background: var(--surface-soft);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 1;
}

.topbar-actions #departmentFilter:disabled {
  background: var(--surface-soft);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 1;
}

.form-field-note {
  color: #08795f;
  font-size: calc(0.76rem - var(--content-font-reduction, 0px));
  font-weight: 700;
  line-height: 1.35;
}

body.dark .form-field-note { color: #6ee7b7; }

.form-grid.compact { grid-template-columns: repeat(5, minmax(0, 1fr)); }

/* ฟอร์มบันทึกผล KPI: ลดความกว้าง เดือน/ค่าที่ทำได้จริง และขยายช่องหลักฐาน */
#resultForm.form-grid.compact { grid-template-columns: 1fr 0.6fr 0.9fr 0.75fr 1.75fr; }

.entry-block {
  margin: 18px 0 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(196, 238, 214, 0.98), rgba(225, 246, 234, 0.9));
}

body.dark .entry-block {
  background:
    linear-gradient(180deg, rgba(33, 136, 77, 0.34), rgba(17, 24, 39, 0.94));
}

.entry-block .form-grid {
  margin-bottom: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: calc(0.88rem - var(--content-font-reduction, 0px));
  font-weight: 700;
}

.full { grid-column: 1 / -1; }
.form-action { height: 42px; }

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-card-actions {
  justify-content: center;
  margin-top: 10px;
}

.row-actions .secondary-button,
.row-actions .danger-button,
.row-actions .primary-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: calc(0.86rem - var(--content-font-reduction, 0px));
}

.table-toolbar {
  justify-content: space-between;
  margin-bottom: 10px;
}

.table-controls,
.table-pagination,
.pagination-actions,
.page-size-control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.table-controls {
  flex: 1 1 520px;
}

.page-size-control {
  grid-template-columns: none;
  color: var(--text);
  white-space: nowrap;
}

.page-size-control select {
  width: auto;
  min-width: 126px;
}

.table-toolbar input {
  max-width: 360px;
  min-width: 230px;
}

.table-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.table-pagination {
  justify-content: space-between;
  margin-top: 12px;
  color: var(--muted);
  font-size: calc(0.9rem - var(--content-font-reduction, 0px));
}

.pagination-actions .secondary-button {
  min-height: 34px;
  padding: 0 12px;
}

.page-status {
  min-width: 86px;
  color: var(--text);
  font-weight: 800;
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th, td {
  padding: 13px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--theme-table-header-text, #ffffff);
  background: linear-gradient(90deg, var(--theme-table-header-start, #21884d), var(--theme-table-header-end, #21884d));
  font-size: calc(0.84rem - var(--content-font-reduction, 0px));
  font-weight: 800;
}

.status-chip.ok { color: var(--success); }
.status-chip.warn { color: #946700; }
.status-chip.risk { color: var(--critical); }

.category-rowspan-cell {
  width: 120px;
  min-width: 120px;
  max-width: 120px;
  background: var(--surface-soft);
  font-weight: 800;
  color: var(--ribbon-green-dark);
  vertical-align: top;
  border-bottom: 3px solid var(--ribbon-green-dark);
}

.category-rowspan-label {
  display: inline-block;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

#kpiTable tr.category-group-end > td {
  border-bottom: 3px solid var(--ribbon-green-dark);
}

.monthly-score-section {
  margin-top: 22px;
}

.dashboard-report-section,
.dashboard-score-section {
  margin-top: 22px;
}

.dashboard-table-wrap {
  max-height: 520px;
}

.score-table-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.score-table-heading h3 {
  margin: 0 0 2px;
  font-size: calc(1rem - var(--content-font-reduction, 0px));
}

.score-table-heading span {
  color: var(--muted);
  font-size: calc(0.86rem - var(--content-font-reduction, 0px));
  font-weight: 800;
}

.score-table {
  min-width: 1360px;
}

.score-table th,
.score-table td {
  font-size: calc(0.84rem - var(--content-font-reduction, 0px));
}

.score-table th {
  text-align: center;
  vertical-align: middle;
}

.score-table td:nth-child(1):not(.category-rowspan-cell),
.score-table td:nth-child(2),
.score-table td:nth-child(3),
.score-table td:nth-child(4),
.monthly-score-cell {
  text-align: center;
}

/* คอลัมน์ KPI: จัดชิดซ้ายทุกแถว — ใช้ class แทน nth-child เพราะเซลล์ "หมวด" ใช้ rowspan
   ทำให้ตำแหน่ง td ของแถวถัดไปในกลุ่มเลื่อนไป 1 ช่อง (KPI กลายเป็นลูกที่ 2 แทนที่จะเป็น 3) */
.score-table td.kpi-name-cell,
#dashboardKpiScoreTable td.kpi-name-cell,
#kpiScoreTable td.kpi-name-cell,
#dashboardKpiReportTable td.kpi-name-cell {
  text-align: left;
}

#dashboardKpiScoreTable td.score-owner-cell {
  min-width: 160px;
  width: 160px;
  font-size: calc(0.66rem - var(--content-font-reduction, 0px));
  line-height: 1.5;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}

.dashboard-score-section .score-owner-name { display: block; }
.dashboard-score-section .score-owner-department { display: block; margin-top: 4px; font-size: calc(0.62rem - var(--content-font-reduction, 0px)); line-height: 1.5; color: var(--muted); }

.center-heading {
  text-align: center;
}

.monthly-score-cell {
  min-width: 62px;
  font-weight: 800;
  white-space: nowrap;
}

.monthly-score-cell.empty {
  color: var(--muted);
  font-weight: 700;
}

#kpiScoreTable tr.category-group-end > td {
  border-bottom: 3px solid var(--ribbon-green-dark);
}

#dashboardKpiReportTable tr.category-group-end > td,
#dashboardKpiScoreTable tr.category-group-end > td {
  border-bottom: 3px solid var(--ribbon-green-dark);
}

.analytics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.analytics-grid .wide { grid-column: 1 / -1; }
.analytics-grid .chart-wrap {
  height: auto;
  min-height: 290px;
}

.alert-grid, .user-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.auth-admin-panel {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.auth-admin-panel h3 {
  margin-bottom: 12px;
}

.master-data-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.master-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.backup-card {
  margin-bottom: 14px;
}

.hospital-profile-card {
  margin-bottom: 14px;
}

.hospital-profile-form {
  margin-top: 12px;
}

.hospital-profile-table {
  margin-top: 12px;
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.compact-table table {
  min-width: 520px;
}

.pending-list {
  display: grid;
  gap: 10px;
}

.pending-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.pending-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: calc(0.88rem - var(--content-font-reduction, 0px));
}

.alert-item {
  border-left: 5px solid var(--warning);
}

.alert-endpoint {
  display: grid;
  gap: 8px;
  max-width: 760px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--medical-blue);
  border-radius: 8px;
  background: var(--surface-soft);
}

.alert-endpoint code {
  display: block;
  overflow-x: auto;
  white-space: nowrap;
  color: var(--ribbon-green-dark);
  font-weight: 800;
}

.alert-endpoint-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.alert-endpoint-row .secondary-button {
  min-height: 36px;
  padding: 0 12px;
  white-space: nowrap;
}

.alert-item.critical { border-left-color: var(--critical); }
.alert-item.success { border-left-color: var(--success); }

.report-preview {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.audit-log {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.audit-toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.audit-toolbar label {
  width: 150px;
}

.app-footer {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 58px;
  margin-top: 18px;
  padding: 12px 22px;
  overflow: hidden;
  color: #4e2a14;
  font-size: calc(0.9rem - var(--content-font-reduction, 0px));
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  background: var(--surface);
}

.app-footer::before,
.app-footer::after {
  content: "";
  position: absolute;
  inset-block: 0;
  pointer-events: none;
}

.app-footer::before {
  left: 0;
  width: 82%;
  z-index: 1;
  background: linear-gradient(90deg, var(--ribbon-green-dark) 0%, var(--ribbon-green) 54%, var(--ribbon-green-light) 100%);
  clip-path: polygon(0 0, calc(100% - 58px) 0, 100% 100%, 0 100%);
}

.app-footer::after {
  right: 0;
  width: 44%;
  z-index: 0;
  background: rgba(112, 112, 112, 0.34);
  clip-path: polygon(58px 0, 100% 0, 100% 100%, 0 100%);
}

.app-footer span,
.app-footer strong {
  position: relative;
  z-index: 2;
  text-shadow: none;
}

.app-footer span {
  font-weight: 700;
}

.app-footer strong {
  color: #4e2a14;
  text-align: right;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: 8px;
  color: #fff;
  background: var(--medical-blue);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 20, 35, 0.58);
}

.auth-modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.database-setup-modal {
  width: min(560px, 100%);
}

.signup-success-modal {
  width: min(520px, 100%);
}

.login-status-modal,
.profile-save-success-modal {
  width: min(440px, 100%);
}

.signup-success-message {
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  line-height: 1.7;
}

.login-status-message,
.profile-save-success-message {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  line-height: 1.7;
}

.login-status-message.success,
.profile-save-success-message {
  border: 1px solid rgba(40, 167, 69, 0.28);
  background: rgba(40, 167, 69, 0.1);
}

.login-status-message.error {
  border: 1px solid rgba(220, 53, 69, 0.3);
  background: rgba(220, 53, 69, 0.1);
}

.signup-success-actions {
  display: flex;
  justify-content: flex-end;
}

.setup-status {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  line-height: 1.65;
}

.setup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.setup-db-form {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.setup-db-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.setup-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: var(--muted);
}

.setup-progress span {
  width: 18px;
  height: 18px;
  border: 3px solid var(--border);
  border-top-color: var(--ribbon-green-dark);
  border-radius: 999px;
  animation: setup-spin 0.8s linear infinite;
}

body.project-closed .app-shell {
  display: none;
}

.project-closed-message {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--light-blue);
  color: var(--text);
  text-align: center;
}

.project-closed-message > div {
  width: min(560px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

@keyframes setup-spin {
  to { transform: rotate(360deg); }
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.auth-tabs button {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.auth-tabs button.active {
  background: var(--ribbon-green-dark);
  color: #fff;
}

.auth-tabs button:hover {
  border-color: var(--ribbon-green-dark);
  color: var(--ribbon-green-dark);
}

.auth-tabs button.active:hover {
  color: #fff;
  background: #17683a;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form small {
  color: var(--muted);
}

.auth-form .password-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: -2px;
  color: var(--muted);
  font-size: calc(0.88rem - var(--content-font-reduction, 0px));
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.auth-form .password-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--medical-green);
  cursor: pointer;
}

.auth-link-button {
  border: 0;
  background: transparent;
  color: var(--medical-blue);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  justify-self: center;
  padding: 2px 6px;
}

.auth-link-button:hover,
.auth-link-button:focus-visible {
  color: var(--medical-green);
  text-decoration: underline;
}

.profile-photo-row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.profile-preview {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--medical-blue);
  font-size: calc(1.3rem - var(--content-font-reduction, 0px));
  font-weight: 900;
}

.profile-preview img {
  width: var(--profile-zoom, 125%);
  height: var(--profile-zoom, 125%);
  object-fit: cover;
  transform: translate(var(--profile-x, 0), var(--profile-y, 0));
  display: block;
}

.profile-positioned-img {
  max-width: none;
  flex: 0 0 auto;
}

.photo-position-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.photo-position-controls input[type="range"] {
  padding: 0;
  accent-color: var(--medical-blue);
}

.password-form {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.password-form h3 {
  margin-bottom: 0;
}

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
  }
  .nav-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .profile-mini { margin-top: 0; }
  .metric-grid, .form-grid, .form-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #resultForm.form-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .analytics-grid, .alert-grid, .user-grid, .master-data-grid { grid-template-columns: 1fr; }
  .panel.wide, .analytics-grid .wide { grid-column: auto; }
  .trend-chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .main-content { padding: 14px; }
  .section-band { padding: 16px; }
  #users {
    margin-left: 0;
    margin-right: 0;
  }
  .alert-endpoint-row {
    grid-template-columns: 1fr;
  }
  .topbar, .section-heading { align-items: stretch; flex-direction: column; }
  .topbar { padding: 78px 14px 12px; gap: 10px; }
  .topbar-sub { flex-direction: column; align-items: stretch; padding: 14px 16px; }
  html { scroll-padding-top: 215px; }
  .topbar::before { left: 18px; width: 86vw; }
  .topbar::after { left: 38vw; width: 46vw; }
  .topbar .eyebrow {
    left: 18px;
    width: 86vw;
    padding-right: 54px;
    font-size: calc(1rem - var(--content-font-reduction, 0px));
  }
  .topbar-hospital-detail {
    font-size: calc(0.72rem - var(--content-font-reduction, 0px));
  }
  .panel { padding-top: 52px; }
  .panel::before { left: 18px; width: 82%; }
  .panel::after { left: 42%; width: 46%; }
  .panel .panel-head {
    left: 18px;
    width: 82%;
    padding-right: 48px;
  }
  .topbar-actions { width: 100%; }
  .topbar-actions select { flex: 1 1 150px; }
  .table-actions {
    width: 100%;
    justify-content: stretch;
  }
  .table-actions .secondary-button { flex: 1 1 150px; }
  .nav-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid, .form-grid, .form-grid.compact { grid-template-columns: 1fr; }
  #resultForm.form-grid.compact { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr; }
  .chart-wrap { height: 240px; }
  .chart-wrap.tall-chart { height: 300px; }
  .analytics-grid .chart-wrap {
    height: auto;
    min-height: 240px;
  }
  .historical-table-wrap { max-height: 360px; }
  .kpi-chart-grid { max-height: none; }
  .kpi-chart-title { flex-direction: column; }
  .kpi-chart-title small { white-space: normal; }
  .kpi-chart-actions {
    width: 100%;
    justify-content: space-between;
  }
  .kpi-mini-chart { height: 230px; }
  .fallback-bars {
    min-width: 480px;
    grid-template-columns: repeat(12, minmax(30px, 1fr));
    gap: 6px;
  }
  .fallback-value { font-size: calc(0.68rem - var(--content-font-reduction, 0px)); }
  .fallback-bar { width: min(50%, 20px); }
  .fallback-bar-item small { font-size: calc(0.68rem - var(--content-font-reduction, 0px)); }
  .analytics-radar-layout { grid-template-columns: 1fr; }
  .analytics-balance-grid { grid-template-columns: 1fr; }
  .heatmap { grid-template-columns: 120px repeat(8, minmax(66px, 1fr)); }
  .pending-item { align-items: stretch; flex-direction: column; }
  .row-actions { width: 100%; }
  .app-footer {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 16px;
  }
  .app-footer::before { width: 94%; }
  .app-footer::after { width: 52%; }
  .app-footer strong { text-align: left; }
}

@media print {
  .sidebar, .topbar-actions, .topbar-auth, .primary-button, .secondary-button, .table-toolbar, #entry, #kpi-management, #alerts, #users, #master-data { display: none !important; }
  .topbar { position: static; }
  .app-shell { display: block; }
  .main-content { padding: 0; }
  .section-band, .panel { box-shadow: none; break-inside: avoid; }
}
/* ปุ่มเลือกไฟล์ภาษาไทย (แทน Choose File ของเบราว์เซอร์) */
.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.file-field {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.file-pick-button {
  flex: 0 0 auto;
  padding: 8px 14px;
  border: 1px solid rgba(33, 136, 77, 0.28);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ribbon-green-dark);
  font-weight: 700;
  font-size: calc(0.85rem - var(--content-font-reduction, 0px));
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.file-pick-button:hover {
  color: #ffffff;
  background: #17683a;
  border-color: #17683a;
}

.file-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(0.85rem - var(--content-font-reduction, 0px));
  font-weight: 700;
  color: var(--muted);
}

.file-name.has-file {
  color: var(--ribbon-green-dark);
}

body.dark .file-pick-button {
  background: rgba(33, 136, 77, 0.18);
  border-color: rgba(134, 239, 172, 0.35);
  color: #a7f3d0;
}

body.dark .file-pick-button:hover {
  background: #17683a;
  border-color: #17683a;
  color: #ffffff;
}

body.dark .file-name.has-file {
  color: #86efac;
}
/* ===== ตั้งค่าสีทีม (Team Color Template) ===== */
.team-color-card {
  margin-bottom: 14px;
}

.team-color-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(122px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.team-color-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: calc(0.76rem - var(--content-font-reduction, 0px));
  font-weight: 700;
  color: var(--muted);
}

.team-color-chip-preview {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.team-color-list {
  display: grid;
  gap: 10px;
}

.team-color-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.team-color-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.team-color-info strong {
  font-size: calc(0.92rem - var(--content-font-reduction, 0px));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-color-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.analytics-team-dot {
  margin-right: 7px;
  vertical-align: -2px;
}

.table-team-dot {
  margin-right: 7px;
  vertical-align: -2px;
}

.team-color-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.team-color-swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.team-color-swatch:hover {
  transform: scale(1.14);
}

.team-color-swatch.active {
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px var(--ribbon-green-dark);
}

@media (max-width: 680px) {
  .team-color-palette {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  }
  .team-color-row {
    align-items: stretch;
    flex-direction: column;
  }
  .team-color-choices {
    justify-content: flex-start;
  }
}
/* ===== แถบบันทึกการตั้งค่าทั้งหมด (Master Data) ===== */
.settings-save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px dashed rgba(33, 136, 77, 0.35);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.65);
}

body.dark .settings-save-bar {
  border-color: rgba(135, 216, 67, 0.3);
  background: rgba(17, 24, 39, 0.72);
}

.settings-save-bar strong {
  display: block;
  font-size: calc(0.95rem - var(--content-font-reduction, 0px));
  color: var(--text);
}

.settings-save-bar .section-note {
  margin-top: 3px;
}

.settings-save-bar.pending {
  border-style: solid;
  border-color: var(--ribbon-green-dark);
  background: rgba(135, 216, 67, 0.16);
}

body.dark .settings-save-bar.pending {
  border-color: rgba(135, 216, 67, 0.7);
  background: rgba(33, 136, 77, 0.28);
}

.save-all-button {
  min-width: 168px;
}

/* ===== ตั้งค่าธีมสี (Theme Colors) ===== */
.theme-color-card {
  margin-bottom: 14px;
}

.theme-preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.theme-preset-button {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: calc(0.85rem - var(--content-font-reduction, 0px));
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.theme-preset-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.theme-preset-button.active {
  border-color: var(--ribbon-green-dark);
  box-shadow: 0 0 0 2px rgba(33, 136, 77, 0.22);
}

.theme-preset-preview {
  display: flex;
  height: 26px;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.theme-preset-preview span {
  flex: 1 1 0;
}

.theme-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.theme-color-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.theme-color-item input[type="color"] {
  width: 46px;
  height: 36px;
  flex: 0 0 auto;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.theme-color-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.theme-color-meta strong {
  font-size: calc(0.86rem - var(--content-font-reduction, 0px));
  color: var(--text);
}

.theme-color-meta small {
  color: var(--muted);
  font-size: calc(0.74rem - var(--content-font-reduction, 0px));
  letter-spacing: 0.4px;
}

.theme-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 680px) {
  .theme-preset-grid {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  }
  .theme-color-grid {
    grid-template-columns: 1fr;
  }
  .settings-save-bar {
    align-items: stretch;
    flex-direction: column;
  }
}

/* ===== Modal ยืนยันตัวตนสำรอง/เรียกคืนข้อมูล ===== */
.backup-confirm-modal {
  width: min(460px, 100%);
}

.backup-confirm-note {
  margin-bottom: 14px;
  font-size: calc(0.85rem - var(--content-font-reduction, 0px));
  font-weight: 700;
  color: var(--muted);
  line-height: 1.65;
}


/* Keep both header bands and footer at their original font sizes. */
.topbar, .topbar-sub, .app-footer {
  --content-font-reduction: 0px;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.5;
}
.topbar, .topbar-sub { font-size: 1rem; }

/* Regular Thai copy with lighter headings; retain the current font sizes. */
:is(.section-band, .sidebar, .modal-backdrop) :is(h1, h2, h3, h4, strong, b, label, button),
.sidebar .nav-link {
  font-weight: 600;
}

.section-band td { font-weight: 400; line-height: 1.65; }
.section-band td :is(strong, b), .section-band th { font-weight: 600; }
.section-band .kpi-name-cell { line-height: 1.65; }
.section-band .metric-card strong { font-weight: 700; }
