/* ==========================================================================
   KNHDAS theme — HIC design language (ux ui/hic-launcher-mockup.html)
   re-skinned in the project's pale-orange "ดอกจาน" brand.

   Token layers:
     1. HIC tokens   (--page, --surface, --ink-*, --brand-*, --tone tiles)
     2. Legacy/dataviz tokens (--surface-1, --text-*, --series-*, --gridline…)
        kept because dashboard.js and the chart partials read them by name.
   Dark mode: follows the OS unless the user picked one with the header
   toggle (stored as data-theme on <html>, see View.php).
   ========================================================================== */

:root {
  color-scheme: light;

  /* Brand — ดอกจาน orange */
  --knh-orange-50:  #fff6ee;
  --knh-orange-100: #ffebda;
  --knh-orange-200: #ffd3b0;
  --knh-orange-300: #ffb37a;
  --knh-orange-400: #f5915a;
  --knh-orange-500: #eb6834;
  --knh-orange-600: #d95926;
  --knh-orange-700: #b8471c;

  --brand-from: #c94a17;
  --brand-mid:  #e2622c;
  --brand-to:   #f08a4b;
  --brand:      #d95926;
  --brand-soft: color-mix(in srgb, var(--brand) 10%, transparent);
  --on-brand:   #ffffff;

  /* HIC surfaces / ink */
  --page:           #fdf8f4;
  --surface:        #ffffff;
  --surface-glass:  rgba(255, 255, 255, 0.74);
  --surface-sunken: #f7f1ec;
  --border:         #f0e6dd;
  --ink-strong:     #1d293d;
  --ink:            #314158;
  --ink-subtle:     #62748e;
  --ink-muted:      #90a1b9;
  --heading:        #c2410c;
  --focus:          #d95926;

  /* Module tones (tile background / ink) */
  --tone-blue-tile:   #dbeafe; --tone-blue-ink:   #1e40af;
  --tone-violet-tile: #ede9fe; --tone-violet-ink: #5b21b6;
  --tone-red-tile:    #fee2e2; --tone-red-ink:    #b91c1c;
  --tone-yellow-tile: #fef9c3; --tone-yellow-ink: #854d0e;
  --tone-green-tile:  #dcfce7; --tone-green-ink:  #166534;
  --tone-pink-tile:   #fce7f3; --tone-pink-ink:   #9d174d;
  --tone-orange-tile: #ffedd5; --tone-orange-ink: #c2410c;
  --tone-teal-tile:   #ccfbf1; --tone-teal-ink:   #0f766e;
  --tone-indigo-tile: #e0e7ff; --tone-indigo-ink: #3730a3;
  --tone-cyan-tile:   #cffafe; --tone-cyan-ink:   #0e7490;
  --tone-sky-tile:    #e0f2fe; --tone-sky-ink:    #075985;
  --tone-rose-tile:   #ffe4e6; --tone-rose-ink:   #9f1239;
  --tone-slate-tile:  #e2e8f0; --tone-slate-ink:  #334155;

  --shadow-card:       0 10px 30px -14px rgba(120, 72, 40, 0.20);
  --shadow-card-hover: 0 22px 44px -20px rgba(90, 50, 25, 0.28);
  --shadow-tile:       0 4px 12px -4px rgba(15, 23, 42, 0.12);
  --shadow-brand:      0 10px 24px -10px color-mix(in srgb, var(--brand-from) 55%, transparent);

  /* Legacy / dataviz tokens (read by JS + charts) */
  --surface-1:       var(--surface);
  --page-plane:      var(--page);
  --text-primary:    var(--ink-strong);
  --text-secondary:  var(--ink);
  --text-muted:      var(--ink-subtle);
  --gridline:        #ece6df;
  --baseline:        #c3c2b7;
  --border-hairline: var(--border);
  --success-text:    #047857;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --triage-red:    var(--status-critical);
  --triage-pink:   var(--series-5);
  --triage-yellow: var(--status-warning);
  --triage-green:  var(--status-good);
  --triage-white:  var(--ink-muted);

  /* Scale */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-9: 36px;
  --radius-chip: 10px;
  --radius-button: 12px;
  --radius-tile: 16px;
  --radius-card: 22px;
  --radius-full: 9999px;
  --header-height: 68px;
  /* Sarabun if installed, else Windows' Thai UI font — no web-font CDN
     (hospital network may be offline, see design spec). */
  --font-thai: Sarabun, "Leelawadee UI", "Noto Sans Thai", Tahoma, sans-serif;
  --font-num: ui-sans-serif, system-ui, "Segoe UI", "Leelawadee UI", sans-serif;
}

/* Dark tokens — applied by OS preference (unless forced light) or by toggle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0b0f1a; --surface: #131a2a; --surface-glass: rgba(19, 26, 42, 0.74);
    --surface-sunken: #1c2538; --border: #222c40;
    --ink-strong: #f1f5f9; --ink: #cbd5e1; --ink-subtle: #94a3b8; --ink-muted: #7c8aa0;
    --heading: #fdba74; --focus: #fdba74; --brand-soft: rgba(245, 145, 90, 0.16);
    --tone-blue-tile: rgba(59,130,246,.16);   --tone-blue-ink: #93c5fd;
    --tone-violet-tile: rgba(139,92,246,.16); --tone-violet-ink: #c4b5fd;
    --tone-red-tile: rgba(239,68,68,.16);     --tone-red-ink: #fca5a5;
    --tone-yellow-tile: rgba(234,179,8,.16);  --tone-yellow-ink: #fde047;
    --tone-green-tile: rgba(34,197,94,.16);   --tone-green-ink: #86efac;
    --tone-pink-tile: rgba(236,72,153,.16);   --tone-pink-ink: #f9a8d4;
    --tone-orange-tile: rgba(249,115,22,.16); --tone-orange-ink: #fdba74;
    --tone-teal-tile: rgba(20,184,166,.16);   --tone-teal-ink: #5eead4;
    --tone-indigo-tile: rgba(99,102,241,.16); --tone-indigo-ink: #a5b4fc;
    --tone-cyan-tile: rgba(6,182,212,.16);    --tone-cyan-ink: #67e8f9;
    --tone-sky-tile: rgba(14,165,233,.16);    --tone-sky-ink: #7dd3fc;
    --tone-rose-tile: rgba(244,63,94,.16);    --tone-rose-ink: #fda4af;
    --tone-slate-tile: rgba(100,116,139,.16); --tone-slate-ink: #cbd5e1;
    --shadow-card: 0 10px 30px -12px rgba(0,0,0,.6);
    --shadow-card-hover: 0 22px 44px -20px rgba(0,0,0,.75);
    --shadow-tile: 0 4px 12px -4px rgba(0,0,0,.5);
    --gridline: #263046; --baseline: #3a4458; --success-text: #34d399;
    --series-1: #3987e5; --series-2: #e8703c; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #22a55a; --series-7: #9085e9; --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b0f1a; --surface: #131a2a; --surface-glass: rgba(19, 26, 42, 0.74);
  --surface-sunken: #1c2538; --border: #222c40;
  --ink-strong: #f1f5f9; --ink: #cbd5e1; --ink-subtle: #94a3b8; --ink-muted: #7c8aa0;
  --heading: #fdba74; --focus: #fdba74; --brand-soft: rgba(245, 145, 90, 0.16);
  --tone-blue-tile: rgba(59,130,246,.16);   --tone-blue-ink: #93c5fd;
  --tone-violet-tile: rgba(139,92,246,.16); --tone-violet-ink: #c4b5fd;
  --tone-red-tile: rgba(239,68,68,.16);     --tone-red-ink: #fca5a5;
  --tone-yellow-tile: rgba(234,179,8,.16);  --tone-yellow-ink: #fde047;
  --tone-green-tile: rgba(34,197,94,.16);   --tone-green-ink: #86efac;
  --tone-pink-tile: rgba(236,72,153,.16);   --tone-pink-ink: #f9a8d4;
  --tone-orange-tile: rgba(249,115,22,.16); --tone-orange-ink: #fdba74;
  --tone-teal-tile: rgba(20,184,166,.16);   --tone-teal-ink: #5eead4;
  --tone-indigo-tile: rgba(99,102,241,.16); --tone-indigo-ink: #a5b4fc;
  --tone-cyan-tile: rgba(6,182,212,.16);    --tone-cyan-ink: #67e8f9;
  --tone-sky-tile: rgba(14,165,233,.16);    --tone-sky-ink: #7dd3fc;
  --tone-rose-tile: rgba(244,63,94,.16);    --tone-rose-ink: #fda4af;
  --tone-slate-tile: rgba(100,116,139,.16); --tone-slate-ink: #cbd5e1;
  --shadow-card: 0 10px 30px -12px rgba(0,0,0,.6);
  --shadow-card-hover: 0 22px 44px -20px rgba(0,0,0,.75);
  --shadow-tile: 0 4px 12px -4px rgba(0,0,0,.5);
  --gridline: #263046; --baseline: #3a4458; --success-text: #34d399;
  --series-1: #3987e5; --series-2: #e8703c; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #22a55a; --series-7: #9085e9; --series-8: #e66767;
}

/* Custom system colour (Settings → สีของระบบ, app/lib/Theme.php). layout()
   puts class="knh-custom-brand" and --brand-base / --on-brand / optional
   --brand-end on <html>; every brand token is derived from those. Without
   the class the hand-tuned orange above applies unchanged. */
:root.knh-custom-brand {
  --brand: var(--brand-base);
  --brand-from: color-mix(in srgb, var(--brand-base) 86%, #000);
  --brand-to: var(--brand-end, color-mix(in srgb, var(--brand-base) 70%, #fff));
  --brand-mid: color-mix(in srgb, var(--brand-base) 65%, var(--brand-to));
}
:root.knh-custom-brand[data-theme="light"] {
  --page: color-mix(in srgb, var(--brand-base) 4%, #fff);
  --surface-sunken: color-mix(in srgb, var(--brand-base) 5%, #f6f6f6);
  --border: color-mix(in srgb, var(--brand-base) 9%, #ebebeb);
  --gridline: color-mix(in srgb, var(--brand-base) 6%, #e9e9e9);
  --heading: color-mix(in srgb, var(--brand-base) 80%, #000);
  --focus: var(--brand-base);
  --shadow-card: 0 10px 30px -14px color-mix(in srgb, color-mix(in srgb, var(--brand-base) 35%, #000) 22%, transparent);
  --shadow-card-hover: 0 22px 44px -20px color-mix(in srgb, color-mix(in srgb, var(--brand-base) 35%, #000) 30%, transparent);
}
@media (prefers-color-scheme: light) {
  :root.knh-custom-brand:not([data-theme="dark"]) {
    --page: color-mix(in srgb, var(--brand-base) 4%, #fff);
    --surface-sunken: color-mix(in srgb, var(--brand-base) 5%, #f6f6f6);
    --border: color-mix(in srgb, var(--brand-base) 9%, #ebebeb);
    --gridline: color-mix(in srgb, var(--brand-base) 6%, #e9e9e9);
    --heading: color-mix(in srgb, var(--brand-base) 80%, #000);
    --focus: var(--brand-base);
    --shadow-card: 0 10px 30px -14px color-mix(in srgb, color-mix(in srgb, var(--brand-base) 35%, #000) 22%, transparent);
    --shadow-card-hover: 0 22px 44px -20px color-mix(in srgb, color-mix(in srgb, var(--brand-base) 35%, #000) 30%, transparent);
  }
}
:root.knh-custom-brand[data-theme="dark"] {
  --heading: color-mix(in srgb, var(--brand-base) 50%, #fff);
  --focus: color-mix(in srgb, var(--brand-base) 50%, #fff);
  --brand-soft: color-mix(in srgb, var(--brand-base) 18%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root.knh-custom-brand:not([data-theme="light"]) {
    --heading: color-mix(in srgb, var(--brand-base) 50%, #fff);
    --focus: color-mix(in srgb, var(--brand-base) 50%, #fff);
    --brand-soft: color-mix(in srgb, var(--brand-base) 18%, transparent);
  }
}

/* ===== Base ============================================================== */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-thai);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(55% 420px at 0% 0%, color-mix(in srgb, var(--brand-mid) 10%, transparent), transparent 70%),
    radial-gradient(45% 380px at 100% 0%, color-mix(in srgb, var(--brand-to) 8%, transparent), transparent 70%),
    var(--page);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.knh-icon {
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  vertical-align: -0.2em;
  color: inherit;
}

.knh-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.knh-visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ===== Top bar =========================================================== */
.knh-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--header-height);
  padding: 0 var(--space-9);
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}

.knh-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  text-decoration: none;
}

.knh-logo {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand-from), var(--brand-to));
  color: var(--on-brand);
  box-shadow: var(--shadow-brand);
}
.knh-logo .knh-icon { width: 22px; height: 22px; }

.knh-brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.knh-brand-text b {
  font: 700 18px/22px var(--font-num);
  color: var(--ink-strong);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.knh-brand-text span {
  font-size: 12px;
  color: var(--ink-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.knh-nav { display: flex; align-items: center; align-self: stretch; gap: 2px; margin-left: var(--space-6); }

/* PC: plain text tabs, the current one underlined */
.knh-nav-link,
.knh-nav-group-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 0 14px;
  border: 0;
  background: none;
  color: var(--ink);
  text-decoration: none;
  font: inherit;
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s ease, box-shadow .15s ease;
}
.knh-nav-link .knh-icon { display: none; }
.knh-nav-link:hover,
.knh-nav-group-btn:hover { color: var(--brand); }
.knh-nav-link.is-active,
.knh-nav-group.has-active .knh-nav-group-btn {
  color: var(--brand);
  font-weight: 700;
  box-shadow: inset 0 -3px 0 var(--brand);
}
.knh-nav-settings { display: none; }

/* "รายงาน ▾" dropdown */
.knh-nav-group { position: relative; display: flex; align-items: stretch; }
.knh-nav-group-btn .knh-icon { width: 16px; height: 16px; transition: transform .15s ease; }
.knh-nav-group-btn[aria-expanded="true"] { color: var(--ink-strong); }
.knh-nav-group-btn[aria-expanded="true"] .knh-icon { transform: rotate(180deg); }
.knh-nav-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: -12px;
  z-index: 30;
  width: min(640px, calc(100vw - 48px));
  padding: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 24px 48px -16px rgba(90, 50, 25, 0.28);
}
.knh-nav-group.is-open .knh-nav-dropdown { display: grid; animation: knh-rise .15s ease both; }
.knh-report-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border-radius: 14px;
  color: var(--ink);
  text-decoration: none;
  transition: background-color .15s ease;
}
.knh-report-link:hover { background: var(--surface-sunken); }
.knh-report-link.is-active { background: var(--brand-soft); }
.knh-report-tile {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--tile);
  color: var(--tone-ink);
}
.knh-report-tile .knh-icon { width: 20px; height: 20px; }
.knh-report-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; line-height: 1.3; }
.knh-report-text b { font-size: 15px; color: var(--ink-strong); }
.knh-report-link.is-active .knh-report-text b { color: var(--brand); }
.knh-report-text small { font-size: 13px; color: var(--ink-subtle); }

:root[data-theme="dark"] .knh-nav-link.is-active,
:root[data-theme="dark"] .knh-nav-group.has-active .knh-nav-group-btn,
:root[data-theme="dark"] .knh-report-link.is-active .knh-report-text b { color: var(--heading); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .knh-nav-link.is-active,
  :root:not([data-theme="light"]) .knh-nav-group.has-active .knh-nav-group-btn,
  :root:not([data-theme="light"]) .knh-report-link.is-active .knh-report-text b { color: var(--heading); }
}

.knh-topbar-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }

.knh-iconbtn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-button);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s ease, color .15s ease;
}
.knh-iconbtn:hover { background: var(--surface-sunken); color: var(--ink-strong); }
.knh-iconbtn.is-active { background: var(--brand-soft); color: var(--brand); }
.knh-iconbtn .knh-icon { width: 19px; height: 19px; }

.knh-clock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink);
  font: 600 14px/1 var(--font-num);
  font-variant-numeric: tabular-nums;
}
.knh-clock .knh-icon { width: 15px; height: 15px; color: var(--brand); }

/* theme toggle shows the icon of the theme you'd switch TO */
.knh-theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .knh-theme-toggle .icon-sun { display: inline-block; }
:root[data-theme="dark"] .knh-theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .knh-theme-toggle .icon-sun { display: inline-block; }
  :root:not([data-theme="light"]) .knh-theme-toggle .icon-moon { display: none; }
}

/* phone-only menu button (shown in the ≤720px block) */
.knh-menu-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  height: 40px;
  margin-left: 4px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink-strong);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.knh-menu-toggle .knh-icon { width: 18px; height: 18px; }
.knh-menu-toggle .icon-close,
.knh-menu-toggle[aria-expanded="true"] .icon-open { display: none; }
.knh-menu-toggle[aria-expanded="true"] .icon-close { display: inline-block; }
.knh-menu-toggle[aria-expanded="true"] { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.knh-brand-text .knh-brand-page { display: none; }

/* ===== Page container ==================================================== */
.knh-page {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-9) 56px;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.knh-footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--space-9) 28px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--ink-subtle);
  font-size: 13px;
}

/* ===== Hero banner ======================================================= */
.knh-hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-6);
  padding: var(--space-8);
  border-radius: var(--radius-card);
  background: linear-gradient(120deg, var(--brand-from), var(--brand-mid) 55%, var(--brand-to));
  color: var(--on-brand);
  box-shadow: var(--shadow-brand);
  animation: knh-rise .5s cubic-bezier(.2,.8,.2,1) both;
}
.knh-hero-text { min-width: 0; }

.knh-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.18);
  font-size: 13px;
  font-weight: 500;
}
.knh-eyebrow .knh-icon { width: 15px; height: 15px; }

.knh-hero h1 { margin: 12px 0 4px; font-size: 28px; line-height: 1.35; font-weight: 700; color: inherit; }
.knh-hero p  { margin: 0; font-size: 15px; opacity: .94; }

.knh-hero-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: 14px; }

.knh-live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.knh-live::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, .7);
  animation: knh-pulse 2s infinite;
}
.knh-live.is-stale::before { background: #fde047; animation: none; }

.knh-hero-actions { position: relative; z-index: 1; display: flex; gap: var(--space-2); flex-wrap: wrap; }

.knh-hero-mark {
  position: absolute;
  z-index: -1;
  right: -30px;
  bottom: -70px;
  width: 260px;
  height: 260px;
  color: #fff;
  opacity: .09;
  transform: rotate(-12deg);
  pointer-events: none;
}

.knh-hero .knh-btn-glass {
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.knh-hero .knh-btn-glass:hover { background: rgba(255, 255, 255, 0.26); }
.knh-hero .knh-btn-light { color: var(--brand-from); background: #fff; box-shadow: 0 8px 18px -8px rgba(0,0,0,.35); }
.knh-hero .knh-btn-light:hover { background: color-mix(in srgb, var(--brand) 6%, #fff); }

/* ===== Buttons =========================================================== */
.knh-btn,
.knh-refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-button);
  font: 700 14.5px/20px var(--font-thai);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.knh-btn:active, .knh-refresh-btn:active { transform: scale(.97); }
.knh-btn .knh-icon, .knh-refresh-btn .knh-icon { width: 17px; height: 17px; }

.knh-btn-primary {
  color: var(--on-brand);
  background: linear-gradient(90deg, var(--brand-from), var(--brand-to));
  box-shadow: var(--shadow-brand);
}
.knh-btn-primary:hover { box-shadow: 0 14px 26px -10px color-mix(in srgb, var(--brand-from) 65%, transparent); }

.knh-btn-secondary,
.knh-refresh-btn {
  color: var(--ink-strong);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}
.knh-btn-secondary:hover, .knh-refresh-btn:hover { background: var(--surface-sunken); }

.knh-refresh-btn.is-spinning .knh-icon,
.knh-btn.is-spinning .knh-icon { animation: knh-spin .8s linear infinite; }

/* ===== Section heading =================================================== */
.knh-section { display: flex; flex-direction: column; gap: var(--space-4); }
.knh-section-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3); }
.knh-section-title { display: flex; align-items: center; gap: var(--space-3); }
.knh-section-title h2 { margin: 0; font-size: 18px; line-height: 1.4; font-weight: 700; color: var(--ink-strong); }
.knh-section-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-button);
  background: var(--surface);
  color: var(--heading);
  box-shadow: inset 0 0 0 1px var(--border);
}
.knh-section-icon .knh-icon { width: 18px; height: 18px; }

.knh-pill {
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--ink-subtle);
  font: 600 12px/20px var(--font-num);
}

/* ===== Generic card ====================================================== */
.knh-card {
  position: relative;
  min-width: 0;
  padding: var(--space-5) var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  animation: knh-rise .5s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.knh-card h2, .knh-card h3 {
  margin: 0 0 2px;
  font-size: 16px;
  line-height: 1.45;
  font-weight: 700;
  color: var(--ink-strong);
}

.knh-card-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.knh-card-head .knh-subtitle { margin: 0; }
.knh-card-head-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: var(--tile, var(--tone-orange-tile));
  color: var(--tone-ink, var(--tone-orange-ink));
}
.knh-card-head-icon .knh-icon { width: 19px; height: 19px; }

.knh-subtitle { margin: 0 0 var(--space-4); font-size: 13px; color: var(--ink-subtle); }

/* ===== Tones ============================================================= */
.tone-blue   { --tile: var(--tone-blue-tile);   --tone-ink: var(--tone-blue-ink); }
.tone-violet { --tile: var(--tone-violet-tile); --tone-ink: var(--tone-violet-ink); }
.tone-red    { --tile: var(--tone-red-tile);    --tone-ink: var(--tone-red-ink); }
.tone-yellow { --tile: var(--tone-yellow-tile); --tone-ink: var(--tone-yellow-ink); }
.tone-green  { --tile: var(--tone-green-tile);  --tone-ink: var(--tone-green-ink); }
.tone-pink   { --tile: var(--tone-pink-tile);   --tone-ink: var(--tone-pink-ink); }
.tone-orange { --tile: var(--tone-orange-tile); --tone-ink: var(--tone-orange-ink); }
.tone-teal   { --tile: var(--tone-teal-tile);   --tone-ink: var(--tone-teal-ink); }
.tone-indigo { --tile: var(--tone-indigo-tile); --tone-ink: var(--tone-indigo-ink); }
.tone-cyan   { --tile: var(--tone-cyan-tile);   --tone-ink: var(--tone-cyan-ink); }
.tone-sky    { --tile: var(--tone-sky-tile);    --tone-ink: var(--tone-sky-ink); }
.tone-rose   { --tile: var(--tone-rose-tile);   --tone-ink: var(--tone-rose-ink); }
.tone-slate  { --tile: var(--tone-slate-tile);  --tone-ink: var(--tone-slate-ink); }

.knh-tile {
  display: grid;
  place-items: center;
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-tile);
  background: var(--tile);
  color: var(--tone-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), var(--shadow-tile);
  transition: transform .25s cubic-bezier(.2,.8,.2,1);
}
.knh-tile .knh-icon { width: 24px; height: 24px; }

.knh-watermark {
  position: absolute;
  z-index: 0;
  right: -16px;
  bottom: -22px;
  width: 120px;
  height: 120px;
  color: var(--tone-ink);
  opacity: .06;
  transform: rotate(-12deg);
  pointer-events: none;
  transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .35s ease;
}

/* ===== KPI cards ========================================================= */
.knh-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-5);
}

.knh-kpi-card {
  overflow: hidden;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
  background:
    radial-gradient(130% 90% at 0% 0%, color-mix(in srgb, var(--tile, var(--tone-orange-tile)) 75%, transparent), transparent 55%),
    var(--surface);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s ease, border-color .25s ease;
}
.knh-kpi-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--tone-ink) 25%, var(--border));
  box-shadow: 0 22px 40px -22px color-mix(in srgb, var(--tone-ink) 45%, transparent), var(--shadow-card-hover);
}
.knh-kpi-card:hover .knh-tile { transform: scale(1.06) rotate(-4deg); }
.knh-kpi-card:hover .knh-watermark { opacity: .11; transform: rotate(0) scale(1.06); }
.knh-kpi-card > * { position: relative; z-index: 1; }
.knh-kpi-card > .knh-watermark { position: absolute; z-index: 0; }

.knh-kpi-top { display: flex; align-items: flex-start; gap: var(--space-3); }
.knh-kpi-label { display: flex; flex-direction: column; min-width: 0; }
.knh-kpi-label b { font-size: 15.5px; font-weight: 700; color: var(--ink-strong); line-height: 1.4; }
.knh-kpi-label span { font-size: 12.5px; color: var(--ink-subtle); }

.knh-kpi-value-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; }
.knh-kpi-value {
  font: 700 38px/1.1 var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
}
.knh-kpi-value small { margin-left: 4px; font: 500 14px/1 var(--font-thai); color: var(--ink-subtle); letter-spacing: 0; }

.knh-kpi-delta-up,
.knh-kpi-delta-down {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font: 700 12.5px/20px var(--font-num);
}
.knh-kpi-delta-up   { color: var(--success-text); background: color-mix(in srgb, var(--status-good) 13%, transparent); }
.knh-kpi-delta-down { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 12%, transparent); }

.knh-chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.knh-chip {
  flex: 1 1 0;
  min-width: 64px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-sunken);
  text-align: center;
}
.knh-chip .knh-chip-value { font: 700 18px/1.3 var(--font-num); font-variant-numeric: tabular-nums; color: var(--ink-strong); }
.knh-chip .knh-chip-label { font-size: 12px; color: var(--ink-subtle); }

.knh-chip[data-triage] { min-width: 0; padding: 8px 4px; position: relative; background: color-mix(in srgb, var(--dot) 13%, var(--surface)); }
.knh-chip[data-triage]::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dot);
}
.knh-chip[data-triage="red"]    { --dot: var(--triage-red); }
.knh-chip[data-triage="pink"]   { --dot: var(--triage-pink); }
.knh-chip[data-triage="yellow"] { --dot: var(--triage-yellow); }
.knh-chip[data-triage="green"]  { --dot: var(--triage-green); }
.knh-chip[data-triage="white"]  { --dot: var(--triage-white); background: var(--surface-sunken); }

.knh-kpi-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
  font-size: 13px;
  color: var(--ink-subtle);
}
.knh-kpi-foot .knh-icon { width: 15px; height: 15px; }
.knh-kpi-foot b { color: var(--ink); font-family: var(--font-num); }

/* ===== Compact metric cards (secondary stats) ============================ */
.knh-metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--space-4);
}
.knh-metric {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
}
.knh-metric .knh-tile { width: 48px; height: 48px; border-radius: 14px; }
.knh-metric .knh-tile .knh-icon { width: 22px; height: 22px; }
.knh-metric-body { display: flex; flex-direction: column; min-width: 0; }
.knh-metric-label { font-size: 13px; color: var(--ink-subtle); }
.knh-metric-value { font: 700 24px/1.25 var(--font-num); font-variant-numeric: tabular-nums; color: var(--ink-strong); }
.knh-metric-value small { font: 500 13px/1 var(--font-thai); color: var(--ink-subtle); margin-left: 3px; }
.knh-metric-note { font-size: 12.5px; color: var(--ink-subtle); }
.knh-metric-split { display: flex; gap: 14px; }
.knh-metric-split span { display: flex; align-items: baseline; gap: 6px; font-size: 13px; color: var(--ink-subtle); }
.knh-metric-split b { font: 700 22px/1.25 var(--font-num); color: var(--ink-strong); }

.knh-meter { height: 6px; margin-top: 6px; border-radius: var(--radius-full); background: var(--surface-sunken); overflow: hidden; }
.knh-meter > span { display: block; height: 100%; border-radius: inherit; background: var(--tone-ink); }

/* ===== Ancillary services =============================================== */
.knh-ancillary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-3);
}
.knh-ancillary-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: 18px;
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--tile) 70%, transparent), transparent 60%),
    var(--surface);
  animation: knh-rise .5s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: calc(var(--i, 0) * 35ms);
  transition: transform .2s ease, border-color .2s ease;
}
.knh-ancillary-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--tone-ink) 25%, var(--border)); }
.knh-ancillary-card .knh-tile { width: 40px; height: 40px; border-radius: 12px; }
.knh-ancillary-card .knh-tile .knh-icon { width: 20px; height: 20px; }
.knh-ancillary-value { font: 700 26px/1.1 var(--font-num); font-variant-numeric: tabular-nums; color: var(--ink-strong); }
.knh-ancillary-label { font-size: 13px; color: var(--ink-subtle); }

/* ===== Panels row ======================================================== */
.knh-three-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-5);
}

/* rights bars */
.knh-bar-list { display: flex; flex-direction: column; gap: 12px; }
.knh-bar-row-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; font-size: 13.5px; color: var(--ink); }
.knh-bar-row-head b { font-family: var(--font-num); color: var(--ink-strong); }
.knh-bar-row-head small { color: var(--ink-subtle); font-family: var(--font-num); margin-left: 6px; }
.knh-bar { height: 10px; border-radius: var(--radius-full); background: var(--surface-sunken); overflow: hidden; }
.knh-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand-mid), var(--brand-to));
  transform-origin: left;
  animation: knh-grow .8s cubic-bezier(.2,.8,.2,1) both;
}

/* ranked list */
.knh-rank-list { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; scrollbar-width: thin; }
.knh-rank-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 4px 10px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
}
.knh-rank-list li:last-child { border-bottom: 0; }
.knh-rank {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 9px;
  background: var(--surface-sunken);
  color: var(--ink-subtle);
  font: 700 12px/1 var(--font-num);
}
.knh-rank-list li:nth-child(-n+3) .knh-rank { background: var(--brand-soft); color: var(--brand); }
.knh-rank-name { font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.knh-rank-count { font: 700 14px/1 var(--font-num); color: var(--ink-strong); }
.knh-rank-bar { grid-column: 2 / 4; height: 4px; border-radius: var(--radius-full); background: var(--surface-sunken); overflow: hidden; }
.knh-rank-bar > span { display: block; height: 100%; border-radius: inherit; background: color-mix(in srgb, var(--brand) 70%, transparent); }

/* states */
.knh-error-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--status-critical) 10%, transparent);
  color: var(--status-critical);
  font-size: 13.5px;
}
.knh-error-inline .knh-icon { width: 17px; height: 17px; }
.knh-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 0;
  color: var(--ink-subtle);
  font-size: 14px;
}
.knh-empty .knh-icon { width: 28px; height: 28px; opacity: .6; }

.knh-alert {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 14px;
}
.knh-alert .knh-icon { width: 18px; height: 18px; }
.knh-alert-success { background: color-mix(in srgb, var(--status-good) 12%, transparent); color: var(--success-text); }

/* ===== Analytics ========================================================= */
.knh-daterange-row,
.knh-toolbar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--space-3);
}
.knh-toolbar .knh-field { min-width: 170px; }

.knh-chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--space-5);
}
.knh-chart-card .knh-card-head { margin-bottom: var(--space-3); }
.knh-chart-card h3 { font-size: 15px; margin: 0; }
.knh-chart-wide { grid-column: 1 / -1; }
.knh-chart-box { position: relative; height: 260px; }
.knh-chart-box canvas { width: 100% !important; height: 100% !important; }

/* ===== Forms ============================================================= */
.knh-form { display: flex; flex-direction: column; gap: var(--space-5); }
/* 12-column grid so each section lays out predictably (auto-fit used to
   leave a lone field on its own row). Fields default to half width;
   .knh-col-4 / .knh-col-8 / .knh-field-wide override per field. */
.knh-fieldset {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
  gap: var(--space-4) var(--space-5);
  margin: 0;
  padding: var(--space-1) 0 var(--space-2);
  border: 0;
}
.knh-fieldset > .knh-field { grid-column: span 6; }
.knh-fieldset > .knh-col-4 { grid-column: span 4; }
.knh-fieldset > .knh-col-8 { grid-column: span 8; }
.knh-fieldset-head { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-3); padding-bottom: var(--space-4); margin-bottom: var(--space-1); border-bottom: 1px solid var(--border); }
.knh-fieldset-head div b { display: block; color: var(--ink-strong); font-size: 15px; }
.knh-fieldset-head div span { display: block; font-size: 12.5px; color: var(--ink-subtle); }
.knh-fieldset-head .knh-card-head-icon { width: 40px; height: 40px; border-radius: 12px; flex: none; }
.knh-fieldset > .knh-field-wide, .knh-field-wide { grid-column: 1 / -1; }

.knh-field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--ink-strong); }
.knh-checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-2); }
.knh-check {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  background: var(--surface);
  font-weight: 400; cursor: pointer;
}
.knh-check:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--surface)); }
.knh-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); flex: none; }
.knh-field .knh-hint { font-weight: 400; font-size: 12.5px; line-height: 1.55; color: var(--ink-subtle); }

.knh-input,
.knh-daterange-row input[type="date"] {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  background: var(--surface);
  color: var(--ink-strong);
  font: 400 15px/20px var(--font-thai);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.knh-input:hover { border-color: color-mix(in srgb, var(--brand) 30%, var(--border)); }
.knh-input:focus,
.knh-daterange-row input[type="date"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 16%, transparent);
}
.knh-input::placeholder { color: var(--ink-muted); }

.knh-form-actions { display: flex; justify-content: flex-end; gap: var(--space-2); padding-top: var(--space-2); }
/* Settings: keep save/cancel reachable while scrolling the long form. */
.knh-settings .knh-form-actions {
  position: sticky;
  bottom: var(--space-4);
  z-index: 5;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-glass);
  box-shadow: var(--shadow-card);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.knh-narrow { width: 100%; max-width: 960px; margin: 0 auto; }
.knh-settings { display: flex; flex-direction: column; gap: var(--space-5); }
.knh-settings .knh-card { padding: var(--space-6) var(--space-8); }
.knh-login { width: 100%; max-width: 400px; margin: 6vh auto 0; text-align: center; }
.knh-login .knh-tile { margin: 0 auto var(--space-4); width: 60px; height: 60px; border-radius: 18px; }
.knh-login .knh-tile .knh-icon { width: 28px; height: 28px; }
.knh-login .knh-form { text-align: left; margin-top: var(--space-5); }
.knh-login .knh-btn { width: 100%; }
.knh-link { color: var(--ink-subtle); font-size: 13.5px; text-decoration: none; }
/* Settings → สีของระบบ */
.knh-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-2); }
.knh-swatch {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  background: var(--surface);
  color: var(--ink-strong);
  font: 500 13.5px/1.3 var(--font-thai);
  text-align: left; cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.knh-swatch:hover { border-color: color-mix(in srgb, var(--sw-a) 50%, var(--border)); transform: translateY(-1px); }
.knh-swatch[aria-pressed="true"] { border-color: var(--sw-a); box-shadow: inset 0 0 0 1px var(--sw-a); font-weight: 700; }
.knh-swatch-dot { flex: none; width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg, var(--sw-a), var(--sw-b)); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.knh-color { display: flex; align-items: center; gap: var(--space-3); }
.knh-color input[type="color"] {
  width: 64px; height: 42px; padding: 3px; flex: none;
  border: 1px solid var(--border); border-radius: var(--radius-button);
  background: var(--surface); cursor: pointer;
}
.knh-color input[type="color"]:disabled { opacity: .45; cursor: not-allowed; }
.knh-color code { font: 500 14px/1 var(--font-num); color: var(--ink-subtle); text-transform: uppercase; }
.knh-theme-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }

/* Inline unlock form for patient-identifying lists (assets/js/unlock.js). */
.knh-unlock { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 420px; margin: 0 auto; padding: var(--space-8) var(--space-4); text-align: center; }
.knh-unlock .knh-tile { width: 52px; height: 52px; border-radius: 16px; margin-bottom: var(--space-2); }
.knh-unlock .knh-tile .knh-icon { width: 24px; height: 24px; }
.knh-unlock b { color: var(--ink-strong); font-size: 16px; }
.knh-unlock-sub { font-size: 13px; color: var(--ink-subtle); }
.knh-unlock-row { display: flex; gap: var(--space-2); width: 100%; margin-top: var(--space-3); }
.knh-unlock-row .knh-input { flex: 1; min-width: 0; }
.knh-unlock-error { margin: 0; font-size: 13px; color: var(--tone-red-ink); }
.knh-link:hover { color: var(--brand); }

/* ===== Appointment calendar (/appointments) ============================= */
.knh-cal { display: flex; flex-direction: column; gap: var(--space-4); }
.knh-cal-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3); }
.knh-cal-nav { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.knh-cal-arrow { width: 40px; padding: 0; }
.knh-cal .knh-cal-title { margin: 0 0 0 var(--space-2); font-size: 20px; line-height: 1.35; color: var(--ink-strong); }
.knh-cal-controls { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.knh-cal-select { width: auto; min-width: 180px; max-width: 260px; height: 40px; }

.knh-segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius-button); background: var(--surface-sunken); }
.knh-segmented button {
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-subtle);
  font: 600 14px/20px var(--font-thai);
  cursor: pointer;
}
.knh-segmented button:hover { color: var(--ink-strong); }
.knh-segmented button.is-active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-tile); font-weight: 700; }

.knh-cal-summary:empty { display: none; }

/* hourly panel — one clickable column per hour, also the hour filter */
.knh-cal-hours:empty { display: none; }
.knh-cal-hours { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-tile); background: var(--surface-sunken); }
.knh-cal-hours-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 8px; font-size: 12.5px; color: var(--ink-subtle); }
.knh-cal-hours-head > b { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-strong); }
.knh-cal-hours-head > b .knh-icon { width: 16px; height: 16px; color: var(--brand); }
.knh-cal-hour-clear {
  display: inline-flex; align-items: center; gap: 6px; margin-left: auto;
  height: 28px; padding: 0 12px; border: 1px solid var(--brand); border-radius: var(--radius-full);
  background: var(--brand-soft); color: var(--brand); font: 700 12.5px/1 var(--font-thai); cursor: pointer;
}
.knh-cal-hour-bars { display: flex; align-items: stretch; gap: 4px; overflow-x: auto; scrollbar-width: thin; }
.knh-cal-hour {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  flex: 1 0 44px; min-width: 44px; max-width: 84px; padding: 4px 2px;
  border: 1px solid transparent; border-radius: 10px; background: transparent;
  color: var(--ink-subtle); font: inherit; cursor: pointer;
}
.knh-cal-hour:hover { background: var(--surface); border-color: var(--border); }
.knh-cal-hour b { min-height: 18px; font-size: 12.5px; line-height: 18px; color: var(--ink-strong); }
.knh-cal-hour small { font-size: 11.5px; white-space: nowrap; }
.knh-cal-hour-track { display: flex; align-items: flex-end; width: 100%; max-width: 30px; height: 64px; border-radius: 6px; background: color-mix(in srgb, var(--ink-muted) 12%, transparent); overflow: hidden; }
.knh-cal-hour-track > span { display: block; width: 100%; border-radius: 6px 6px 0 0; background: color-mix(in srgb, var(--brand) 55%, transparent); transition: height .25s ease; }
.knh-cal-hour.is-zero { opacity: .55; }
.knh-cal-hour.is-active { background: var(--surface); border-color: var(--brand); color: var(--brand); }
.knh-cal-hour.is-active .knh-cal-hour-track > span { background: var(--brand); }
:root[data-theme="dark"] .knh-cal-hour-clear,
:root[data-theme="dark"] .knh-cal-hour.is-active { color: var(--heading); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .knh-cal-hour-clear,
  :root:not([data-theme="light"]) .knh-cal-hour.is-active { color: var(--heading); }
}

.knh-cal-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-2); }
.knh-cal-stat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 10px 14px;
  border-radius: var(--radius-tile);
  background: var(--tile, var(--surface-sunken));
}
.knh-cal-stat span { font-size: 12.5px; color: var(--tone-ink, var(--ink-subtle)); }
.knh-cal-stat b { font-size: 24px; line-height: 1.25; color: var(--ink-strong); }
.knh-cal-stat small { font-size: 12px; color: var(--ink-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* OPD ALERT & ACTION (waittime) */
.knh-insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: var(--space-2); }
.knh-insight {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px 10px;
  padding: 12px 14px;
  border-radius: var(--radius-tile);
  border-left: 4px solid var(--tone-ink, var(--border));
  background: var(--tile, var(--surface-sunken));
}
.knh-insight > .knh-icon { grid-row: span 3; width: 20px; height: 20px; margin-top: 2px; color: var(--tone-ink, var(--ink-subtle)); }
.knh-insight b { font-size: 14px; color: var(--ink-strong); }
.knh-insight p { margin: 0; font-size: 13px; color: var(--ink-subtle); }
.knh-insight ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--ink-strong); }
.knh-insight li + li { margin-top: 2px; }

/* month grid */
.knh-cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.knh-cal-dow { padding: 4px 8px; font-size: 13px; font-weight: 700; color: var(--ink-subtle); text-align: center; }
.knh-cal-dow.is-weekend { color: var(--heading); }
.knh-cal-cell {
  --heat-bg: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  min-height: 112px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--heat-bg);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.knh-cal-cell:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); box-shadow: var(--shadow-tile); transform: translateY(-1px); }
.knh-cal-cell.is-weekend { --heat-bg: var(--surface-sunken); }
.knh-cal-cell[data-heat="1"], .knh-cal-legend i[data-heat="1"] { --heat-bg: color-mix(in srgb, var(--brand) 6%, var(--surface)); }
.knh-cal-cell[data-heat="2"], .knh-cal-legend i[data-heat="2"] { --heat-bg: color-mix(in srgb, var(--brand) 12%, var(--surface)); }
.knh-cal-cell[data-heat="3"], .knh-cal-legend i[data-heat="3"] { --heat-bg: color-mix(in srgb, var(--brand) 20%, var(--surface)); }
.knh-cal-cell[data-heat="4"], .knh-cal-legend i[data-heat="4"] { --heat-bg: color-mix(in srgb, var(--brand) 30%, var(--surface)); }
.knh-cal-cell.is-outside { opacity: .45; }
.knh-cal-cell.is-today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.knh-cal-cell-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.knh-cal-daynum { font: 700 15px/1.4 var(--font-num); color: var(--ink-strong); }
.knh-cal-cell.is-today .knh-cal-daynum {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand); color: var(--on-brand); font-size: 13.5px;
}
.knh-cal-count {
  padding: 1px 9px;
  border-radius: var(--radius-full);
  background: var(--brand);
  color: var(--on-brand);
  font-size: 13px;
  font-weight: 700;
  line-height: 20px;
}
.knh-cal-clinics, .knh-cal-wlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.knh-cal-clinics li, .knh-cal-wlist li { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; line-height: 1.45; color: var(--ink); }
.knh-cal-clinics li span, .knh-cal-wlist li span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.knh-cal-clinics li b, .knh-cal-wlist li b { flex: none; color: var(--ink-strong); }
.knh-cal-clinics li.knh-cal-more { color: var(--ink-subtle); font-style: italic; }

.knh-cal-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12.5px; color: var(--ink-subtle); }
.knh-cal-legend i { --heat-bg: var(--surface); width: 18px; height: 12px; border-radius: 4px; border: 1px solid var(--border); background: var(--heat-bg); }
.knh-cal-legend-hint { margin-left: auto; }

/* week columns */
.knh-cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.knh-cal-wcol { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 8px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.knh-cal-wcol.is-weekend { background: var(--surface-sunken); }
.knh-cal-wcol.is-today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.knh-cal-whead {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0;
  padding: 8px 10px; border: 0; border-radius: 10px;
  background: var(--brand-soft); color: var(--ink-subtle);
  font: 400 12.5px/1.4 var(--font-thai); text-align: left; cursor: pointer;
}
.knh-cal-whead:hover { background: color-mix(in srgb, var(--brand) 18%, transparent); }
.knh-cal-whead > b { font-size: 15px; color: var(--ink-strong); }
.knh-cal-wtotal b { font-size: 22px; color: var(--brand); }
:root[data-theme="dark"] .knh-cal-wtotal b { color: var(--heading); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .knh-cal-wtotal b { color: var(--heading); } }
.knh-cal-wlist li { padding: 3px 4px; border-bottom: 1px dashed var(--border); font-size: 12.5px; }
.knh-cal-wlist li:last-child { border-bottom: 0; }
.knh-cal-none { margin: 0; padding: 6px 4px; font-size: 12.5px; color: var(--ink-muted); }

/* day list */
.knh-cal-clinic-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.knh-cal-clinic-chips button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-full);
  background: var(--surface); color: var(--ink);
  font: 500 13px/1 var(--font-thai); cursor: pointer;
}
.knh-cal-clinic-chips button:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); }
.knh-cal-clinic-chips button.is-active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.knh-cal-search { position: relative; margin-top: var(--space-3); max-width: 460px; }
.knh-cal-search .knh-icon { position: absolute; left: 13px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); color: var(--ink-muted); }
.knh-cal-search .knh-input { padding-left: 38px; }
.knh-cal-foot { margin: var(--space-2) 0 0; font-size: 12.5px; color: var(--ink-subtle); }
#knh-cal-table { margin-top: var(--space-3); }

.knh-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-tile); }
.knh-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.knh-table th {
  padding: 10px 12px; background: var(--surface-sunken);
  color: var(--ink-subtle); font-size: 12.5px; font-weight: 700; text-align: left; white-space: nowrap;
}
.knh-table td { padding: 9px 12px; border-top: 1px solid var(--border); color: var(--ink); vertical-align: top; }
.knh-table td b { color: var(--ink-strong); font-weight: 600; }
.knh-table td small { display: block; font-size: 12px; color: var(--ink-subtle); }
.knh-table tbody tr:hover td { background: color-mix(in srgb, var(--brand) 4%, transparent); }
.knh-table tr.is-cancelled td { color: var(--ink-muted); }
.knh-table tr.is-cancelled td b { color: var(--ink-muted); text-decoration: line-through; }
.knh-table .knh-num { white-space: nowrap; }
.knh-muted { color: var(--ink-muted) !important; }
.knh-status {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius-full);
  background: var(--tile); color: var(--tone-ink);
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.knh-sort {
  display: inline-flex; align-items: center; gap: 5px;
  margin: -4px -6px; padding: 4px 6px;
  border: 0; border-radius: 6px; background: transparent;
  color: inherit; font: inherit; white-space: nowrap; cursor: pointer;
}
.knh-sort:hover { color: var(--ink-strong); background: color-mix(in srgb, var(--brand) 8%, transparent); }
.knh-sort.is-active { color: var(--brand); }
:root[data-theme="dark"] .knh-sort.is-active { color: var(--heading); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .knh-sort.is-active { color: var(--heading); } }
.knh-sort-arrow { font-size: 10px; opacity: .55; }
.knh-sort.is-active .knh-sort-arrow { opacity: 1; }
.knh-phones { white-space: nowrap; }
.knh-tel { display: block; color: var(--ink-strong); font-family: var(--font-num); font-variant-numeric: tabular-nums; text-decoration: none; }
.knh-tel:hover { color: var(--brand); text-decoration: underline; }
.knh-phones small .knh-tel { display: inline; color: inherit; }
.knh-phones small .knh-tel + .knh-tel::before { content: ', '; }

@media (max-width: 1100px) {
  .knh-cal-week { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (max-width: 720px) {
  .knh-cal-nav { width: 100%; flex-wrap: wrap; }
  .knh-cal .knh-cal-title { width: 100%; margin: 4px 0 0; font-size: 18px; }
  .knh-cal-controls { width: 100%; }
  .knh-cal-select { flex: 1; min-width: 0; max-width: none; }
  .knh-segmented { width: 100%; }
  .knh-segmented button { flex: 1; padding: 0 6px; }
  .knh-cal-month { gap: 3px; }
  .knh-cal-dow { padding: 2px 0; font-size: 12px; }
  .knh-cal-cell { min-height: 58px; padding: 5px 3px; align-items: center; border-radius: 10px; }
  .knh-cal-cell-head { flex-direction: column; gap: 2px; }
  .knh-cal-clinics { display: none; }
  .knh-cal-count { padding: 0 6px; font-size: 11.5px; line-height: 18px; }
  .knh-cal-legend-hint { width: 100%; margin-left: 0; }
  .knh-cal-week { grid-template-columns: minmax(0, 1fr); }
}

/* ===== Telemedicine target (/telemed) =================================== */
.knh-tele-goal-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: var(--space-4);
  border: 1px solid color-mix(in srgb, var(--tone-ink) 25%, var(--border));
  border-radius: 18px;
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--tile) 80%, transparent), transparent 65%),
    var(--surface);
}
.knh-tele-goal-card p { margin: 0; font-size: 13px; }
.knh-tele-goal-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: var(--space-3); }
.knh-tele-goal-head > div { display: flex; flex-direction: column; }
.knh-tele-goal-head span { font-size: 13px; color: var(--tone-ink); font-weight: 600; }
.knh-tele-goal-head b { font: 700 34px/1.15 var(--font-num); font-variant-numeric: tabular-nums; color: var(--ink-strong); }
.knh-tele-goal-head small { font-size: 12.5px; color: var(--ink-subtle); }
.knh-tele-goal-pct { text-align: right; align-items: flex-end; }
.knh-tele-goal-pct b { color: var(--tone-ink); }
.knh-tele-goal-card .knh-tele-bar { height: 14px; }
.knh-tele-bar { height: 8px; border-radius: var(--radius-full); background: var(--surface-sunken); overflow: hidden; }
.knh-tele-bar > span {
  display: block; height: 100%; border-radius: inherit;
  background: var(--tone-ink);
  transform-origin: left;
  animation: knh-grow .8s cubic-bezier(.2,.8,.2,1) both;
}

.knh-tele-link {
  border: 0; font: inherit; font-size: 12px; cursor: pointer;
  transition: filter .15s ease, transform .15s ease;
}
.knh-tele-link:hover, .knh-tele-stat-link:hover { filter: brightness(.95); transform: translateY(-1px); }
.knh-tele-link:focus-visible, .knh-tele-stat-link:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.knh-tele-stat-link {
  border: 0; font: inherit; text-align: left; cursor: pointer;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone-ink) 35%, transparent);
  transition: filter .15s ease, transform .15s ease;
}

/* ===== Motion ============================================================ */
@keyframes knh-rise  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes knh-grow  { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes knh-spin  { to { transform: rotate(360deg); } }
@keyframes knh-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, .7); }
  70%  { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

/* ===== TV / kiosk mode (?tv=1) ========================================== */
.is-tv .knh-topbar { position: static; }
.is-tv .knh-hero-actions .knh-btn-glass,
.is-tv .knh-theme-toggle { display: none; }

/* ===== Responsive ======================================================== */
@media (max-width: 1100px) {
  .knh-clock { display: none; }
  .knh-nav { margin-left: var(--space-2); }
  .knh-nav-link, .knh-nav-group-btn { padding: 0 10px; }
}
@media (max-width: 920px) {
  .knh-brand-text { display: none; }
}
@media (max-width: 720px) {
  /* phone: brand + actions + "เมนู" button; the menu opens as a 2-column panel under the bar */
  .knh-topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 60px;
    padding: 0 var(--space-4);
    gap: 0 var(--space-2);
  }
  .knh-brand { flex: 1 1 0; height: 60px; }
  .knh-logo { width: 38px; height: 38px; border-radius: 12px; }
  .knh-logo .knh-icon { width: 20px; height: 20px; }
  .knh-brand-text b { font-size: 16px; line-height: 20px; }
  .knh-brand-text { display: flex; }
  .knh-brand-text span, .knh-clock, .knh-tv-link, .knh-settings-link { display: none; }
  .knh-brand-text .knh-brand-page { display: block; color: var(--brand); font-weight: 600; font-size: 12.5px; }
  .knh-topbar-actions { gap: 2px; }
  .knh-menu-toggle { display: inline-flex; }
  .knh-nav {
    display: none;
    order: 3;
    flex: 1 0 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
    align-self: auto;
    margin: 0;
    padding: var(--space-1) 0 var(--space-4);
  }
  /* every page listed flat: the รายงาน dropdown dissolves into the grid */
  .knh-nav-group, .knh-nav .knh-nav-dropdown { display: contents; }
  .knh-nav-group-btn, .knh-report-text small { display: none; }
  .knh-nav-settings { display: flex; }
  .knh-topbar.is-menu-open .knh-nav { display: grid; animation: knh-rise .18s ease both; }
  .knh-nav a {
    height: 52px;
    padding: 0 14px;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-button);
    background: var(--surface);
    font-size: 15px;
    white-space: normal;
    line-height: 1.2;
  }
  .knh-nav a span { display: inline; }
  .knh-nav a .knh-icon { display: inline-block; flex: none; width: 20px; height: 20px; color: var(--brand); }
  .knh-nav a.is-active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 700; box-shadow: none; }
  .knh-report-tile { width: auto; height: auto; background: none; }
  .knh-report-text b { font-size: 15px; font-weight: 500; color: inherit; }
  .knh-report-link.is-active .knh-report-text b { font-weight: 700; }
  .knh-page { padding: var(--space-5) var(--space-4) 40px; gap: var(--space-5); }
  .knh-footer { padding: 0 var(--space-4) 24px; }
  .knh-hero { padding: var(--space-6); }
  .knh-hero h1 { font-size: 23px; }
  .knh-kpi-value { font-size: 32px; }
  .knh-three-panel, .knh-chart-grid { grid-template-columns: minmax(0, 1fr); }
  .knh-ancillary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .knh-fieldset > .knh-field { grid-column: 1 / -1; }
  .knh-settings .knh-card { padding: var(--space-5); }
  .knh-settings .knh-form-actions .knh-btn { flex: 1; justify-content: center; }
}
@media (max-width: 360px) {
  .knh-brand-text { display: none; }
}

/* ===== Settings (KNHEPN-style) ===========================================
   Category menu on the left (sticky) + one panel per category; every panel
   is a card with two-column rows and its own save button. Phone: the menu
   becomes a horizontal scroller above the content. */
.knh-set { width: 100%; max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-5); }
.knh-set-header { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.knh-set-header > div { flex: 1; min-width: 220px; }
.knh-set-header h1 { margin: 0; font-size: 24px; line-height: 1.2; color: var(--ink-strong); }
.knh-set-header p { margin: 2px 0 0; font-size: 13.5px; color: var(--ink-subtle); }
.knh-set-header-icon {
  display: grid; place-items: center; flex: none; width: 48px; height: 48px; border-radius: 14px;
  background: linear-gradient(135deg, var(--brand-from), var(--brand-to)); color: var(--on-brand); box-shadow: var(--shadow-brand);
}
.knh-set-header-icon .knh-icon { width: 24px; height: 24px; }

.knh-set-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: var(--space-6); align-items: start; }
.knh-set-aside { position: sticky; top: calc(var(--header-height, 64px) + 16px); display: flex; flex-direction: column; gap: var(--space-4); }
.knh-set-nav, .knh-set-status {
  padding: 8px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
}
.knh-set-nav { display: flex; flex-direction: column; gap: 2px; }
.knh-set-nav-group { margin: 0; padding: 12px 12px 4px; font-size: 12px; font-weight: 700; letter-spacing: .02em; color: var(--ink-subtle); }
.knh-set-nav-group:first-child { padding-top: 6px; }
.knh-set-nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px;
  border: 0; border-radius: 12px; background: transparent; text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  transition: background-color .15s ease;
}
.knh-set-nav-icon {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 11px;
  background: var(--tile); color: var(--tone-ink); transition: transform .2s ease;
}
.knh-set-nav-icon .knh-icon { width: 18px; height: 18px; }
.knh-set-nav-text { flex: 1; min-width: 0; line-height: 1.3; }
.knh-set-nav-text b { display: block; font-size: 14.5px; font-weight: 600; color: var(--ink-strong); }
.knh-set-nav-text small { display: block; margin-top: 1px; font-size: 12px; color: var(--ink-subtle); }
.knh-set-nav-item:hover { background: var(--surface-sunken); }
.knh-set-nav-item:hover .knh-set-nav-icon { transform: scale(1.06) rotate(-4deg); }
.knh-set-nav-item.is-active { background: color-mix(in srgb, var(--brand) 10%, var(--surface)); }
.knh-set-nav-item.is-active .knh-set-nav-icon { background: linear-gradient(135deg, var(--brand-from), var(--brand-to)); color: var(--on-brand); box-shadow: var(--shadow-brand); }
.knh-set-nav-item.is-active .knh-set-nav-text b { color: var(--brand); font-weight: 700; }
:root[data-theme="dark"] .knh-set-nav-item.is-active .knh-set-nav-text b { color: var(--heading); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .knh-set-nav-item.is-active .knh-set-nav-text b { color: var(--heading); } }

.knh-set-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-muted); }
.knh-set-dot.is-ok { background: var(--status-good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-good) 20%, transparent); }
.knh-set-dot.is-bad { background: var(--status-critical); box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-critical) 20%, transparent); animation: knh-set-blink 1.6s ease-in-out infinite; }
.knh-set-dot.is-warn { background: var(--status-warning); box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-warning) 22%, transparent); }
@keyframes knh-set-blink { 50% { opacity: .35; } }
.knh-set-swatch { flex: none; width: 18px; height: 18px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35); }
.knh-set-status { padding: 6px 8px 10px; }
.knh-set-status-row { display: flex; align-items: center; gap: 10px; padding: 7px 12px; font-size: 13px; color: var(--ink-subtle); }
.knh-set-status-row span:nth-child(2) { flex: 1; }
.knh-set-status-row b { font-weight: 600; color: var(--ink-strong); }

.knh-set-content { min-width: 0; display: flex; flex-direction: column; gap: var(--space-4); }
.knh-set-content > .knh-alert, .knh-set-content > .knh-error-inline { margin: 0; }
.knh-set-panel { display: flex; flex-direction: column; gap: var(--space-4); animation: knh-rise .3s ease both; }
.knh-set-panel[hidden] { display: none; }

.knh-set-card { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); overflow: hidden; }
.knh-set-card-head { display: flex; align-items: center; gap: 14px; padding: 20px 24px 14px; }
.knh-set-card-icon { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 12px; background: var(--tile); color: var(--tone-ink); }
.knh-set-card-icon .knh-icon { width: 20px; height: 20px; }
.knh-set-card-head h3 { margin: 0; font-size: 17px; color: var(--ink-strong); }
.knh-set-card-head p { margin: 2px 0 0; font-size: 13px; line-height: 1.55; color: var(--ink-subtle); }
.knh-set-card-head p a { color: var(--brand); font-weight: 600; }
.knh-set-body { padding: 4px 24px 18px; }
.knh-set-rows { padding: 0 24px 6px; }
.knh-set-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 10px 28px; align-items: start;
  padding: 16px 0; border-top: 1px solid var(--border);
}
.knh-set-row:first-child { border-top: 0; }
.knh-set-body + .knh-set-rows .knh-set-row:first-child { border-top: 1px solid var(--border); }
.knh-set-row-label { display: block; font-size: 14.5px; font-weight: 600; color: var(--ink-strong); }
.knh-set-row-desc { margin: 3px 0 0; font-size: 13px; line-height: 1.55; color: var(--ink-subtle); }
.knh-set-row-control { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.knh-set-row-control > .knh-set-input { width: 100%; }
.knh-set-input { position: relative; display: flex; }
.knh-set-input .knh-input { flex: 1; min-width: 0; }
.knh-set-input.has-unit .knh-input { padding-right: 72px; }
.knh-set-input.has-btn .knh-input { padding-right: 70px; }
.knh-set-unit {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); padding: 3px 10px; border-radius: 8px;
  background: var(--surface-sunken); font-size: 12.5px; font-weight: 600; color: var(--ink-subtle); pointer-events: none;
}
.knh-set-input-btn {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%); height: calc(100% - 10px); padding: 0 12px;
  border: 0; border-radius: 8px; background: var(--surface-sunken); font: 600 12.5px var(--font-thai); color: var(--ink-subtle); cursor: pointer;
}
.knh-set-input-btn:hover { color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--surface)); }
.knh-set-hint { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12.5px; color: var(--ink-subtle); }
.knh-set-hint .knh-icon { width: 15px; height: 15px; }
.knh-set-hint.is-ok .knh-icon { color: var(--status-good); }
.knh-set-hint.is-warn .knh-icon { color: var(--status-warning); }
.knh-set-card-foot {
  display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 14px 24px; background: var(--surface-sunken); border-top: 1px solid var(--border);
}

.knh-set-switch { position: relative; display: inline-flex; align-items: center; gap: 12px; min-height: 40px; cursor: pointer; user-select: none; }
.knh-set-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.knh-set-switch-track { position: relative; flex: none; width: 48px; height: 28px; border-radius: var(--radius-full); background: var(--border); transition: background-color .2s ease; }
.knh-set-switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(15, 23, 42, .25); transition: transform .25s cubic-bezier(.34, 1.56, .64, 1);
}
.knh-set-switch input:checked + .knh-set-switch-track { background: linear-gradient(120deg, var(--brand-from), var(--brand-to)); }
.knh-set-switch input:checked + .knh-set-switch-track::after { transform: translateX(20px); }
.knh-set-switch input:focus-visible + .knh-set-switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.knh-set-switch-text { font-size: 13px; font-weight: 600; color: var(--ink-subtle); }

.knh-set-conn { display: flex; align-items: center; gap: 14px; padding: 16px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.knh-set-conn-icon { display: grid; place-items: center; flex: none; width: 46px; height: 46px; border-radius: 14px; }
.knh-set-conn-icon .knh-icon { width: 22px; height: 22px; }
.knh-set-conn.is-ok .knh-set-conn-icon { background: color-mix(in srgb, var(--status-good) 14%, transparent); color: var(--status-good); }
.knh-set-conn.is-bad .knh-set-conn-icon { background: color-mix(in srgb, var(--status-critical) 14%, transparent); color: var(--status-critical); }
.knh-set-conn small { display: block; font-size: 12px; font-weight: 700; color: var(--ink-subtle); }
.knh-set-conn b { display: block; font-size: 16px; color: var(--ink-strong); }
.knh-set-conn code { font: 500 12px var(--font-num); color: var(--ink-subtle); word-break: break-all; }

@media (max-width: 960px) {
  .knh-set-layout { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
  .knh-set-aside { position: static; }
  .knh-set-nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .knh-set-nav::-webkit-scrollbar { display: none; }
  .knh-set-nav-group, .knh-set-nav-text small, .knh-set-status { display: none; }
  .knh-set-nav-item { width: auto; flex: none; padding: 8px 12px; }
  .knh-set-nav-icon { width: 30px; height: 30px; }
  .knh-set-nav-text b { white-space: nowrap; font-size: 13.5px; }
}
@media (max-width: 720px) {
  .knh-set-row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .knh-set-rows, .knh-set-body { padding-left: var(--space-4); padding-right: var(--space-4); }
  .knh-set-card-head { padding: 16px var(--space-4) 12px; }
  .knh-set-card-foot { padding: 12px var(--space-4); }
  .knh-set-card-foot .knh-btn { flex: 1; justify-content: center; }
  .knh-set-header .knh-btn { width: 100%; justify-content: center; }
}
