/* =====================================================================
   JVL Station — design system
   โทนสี: ฟ้า · ทอง · เขียวสาธารณสุข · ส้มกรมสุขภาพจิต บนพื้นเทานุ่มตา
   - โหมด:     html[data-theme="light" | "dark"]
   - พื้นหลัง:   html[data-tone="soft" | "gray" | "deep"]   (ค่าเริ่มต้น gray)
   - ขนาดอักษร: html[data-fs="sm" | "md" | "lg" | "xl"]
   - สีหลัก:    --primary* (ผู้ใช้เลือกเองได้ — hub.js คำนวณเฉดให้อัตโนมัติ)
   แก้สีทั้งระบบได้ที่ตัวแปรในส่วน "TOKENS" จุดเดียว
   ===================================================================== */

/* ============================== TOKENS ============================== */
:root {
  /* พื้นผิว — โหมดสว่าง เทากลาง (ค่าเริ่มต้น) */
  --bg: #e2e7ed;
  --surface: #f6f8fa;
  --surface-2: #ebeff4;
  --sidebar-bg: #edf1f5;
  --line: #d2dae3;
  --line-2: #e1e6ec;
  --ink: #102a43;
  --ink-2: #3e5469;
  --ink-3: #66798d;
  --overlay: rgba(10, 20, 32, .45);

  /* สีหลัก (ปุ่ม ลิงก์ เมนูที่เลือก) */
  --primary: #1d5fa8;
  --primary-hover: #174f8d;
  --primary-soft: rgba(29, 95, 168, .12);
  --primary-text: #1a5699;
  --on-primary: #ffffff;

  /* สีแบรนด์ (ไอคอน/ป้าย) */
  --blue: #1d5fa8;   --blue-soft: rgba(29, 95, 168, .11);
  --green: #0b7a4b;  --green-soft: rgba(11, 122, 75, .11);
  --gold: #946a12;   --gold-soft: rgba(196, 146, 40, .15);  --gold-bright: #d4a537;
  --orange: #c35714; --orange-soft: rgba(217, 102, 28, .12);
  --teal: #0b7279;   --teal-soft: rgba(13, 127, 134, .11);
  --violet: #5443a8; --violet-soft: rgba(94, 75, 181, .11);
  --rose: #a8325a;   --rose-soft: rgba(185, 59, 98, .11);
  --slate: #4f6074;  --slate-soft: rgba(86, 103, 122, .12);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 39, 66, .06);
  --shadow: 0 1px 2px rgba(15, 39, 66, .05), 0 6px 20px rgba(15, 39, 66, .07);
  --shadow-lg: 0 2px 6px rgba(15, 39, 66, .07), 0 18px 44px rgba(15, 39, 66, .14);

  --font: "Noto Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "IBM Plex Sans Thai", var(--font);
  --max: 1240px;
  --sb-w: 268px;
  --sb-w-mini: 74px;
  --topbar-h: 64px;
  color-scheme: light;
}
html[data-tone="soft"] { --bg: #eef1f5; --surface: #fcfdfe; --surface-2: #f0f3f7; --sidebar-bg: #f5f7fa; --line: #dce3ea; --line-2: #e9edf2; }
html[data-tone="deep"] { --bg: #d2d9e1; --surface: #eceff3; --surface-2: #e0e5eb; --sidebar-bg: #e2e7ec; --line: #c3cdd8; --line-2: #d5dce4; }

/* ---------- โหมดมืด ---------- */
html[data-theme="dark"] {
  --bg: #10171f;
  --surface: #18212b;
  --surface-2: #202b37;
  --sidebar-bg: #131b24;
  --line: #2b3847;
  --line-2: #222d3a;
  --ink: #e5ebf2;
  --ink-2: #b5c2cf;
  --ink-3: #8698aa;
  --overlay: rgba(0, 0, 0, .6);

  --primary: #3d82d6;
  --primary-hover: #5294e2;
  --primary-soft: rgba(97, 160, 234, .16);
  --primary-text: #8cbcf2;
  --on-primary: #ffffff;

  --blue: #7cb0ee;   --blue-soft: rgba(124, 176, 238, .14);
  --green: #55c793;  --green-soft: rgba(85, 199, 147, .14);
  --gold: #e3bb62;   --gold-soft: rgba(227, 187, 98, .15);  --gold-bright: #e3bb62;
  --orange: #f39d5a; --orange-soft: rgba(243, 157, 90, .15);
  --teal: #4fc8ce;   --teal-soft: rgba(79, 200, 206, .14);
  --violet: #ad9cf2; --violet-soft: rgba(173, 156, 242, .15);
  --rose: #f08fac;   --rose-soft: rgba(240, 143, 172, .14);
  --slate: #a3b4c6;  --slate-soft: rgba(163, 180, 198, .14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 2px 8px rgba(0, 0, 0, .3), 0 20px 48px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
html[data-theme="dark"][data-tone="soft"] { --bg: #1a232e; --surface: #222c38; --surface-2: #2a3542; --sidebar-bg: #1d2631; --line: #344252; --line-2: #2b3644; }
html[data-theme="dark"][data-tone="deep"] { --bg: #080b10; --surface: #0f151c; --surface-2: #161e27; --sidebar-bg: #0b1016; --line: #202b37; --line-2: #18212b; }

html[data-fs="sm"] { font-size: 15px; }
html[data-fs="md"] { font-size: 16px; }
html[data-fs="lg"] { font-size: 17.5px; }
html[data-fs="xl"] { font-size: 19px; }

/* ============================== BASE ============================== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); font-size: 1rem; line-height: 1.65;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}
h1, h2, h3, h4 { font-family: var(--font-head); line-height: 1.3; margin: 0 0 .5em; font-weight: 600; letter-spacing: -.005em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.25rem); }
h2 { font-size: clamp(1.25rem, 2.1vw, 1.55rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img { max-width: 100%; height: auto; }
small { font-size: .82em; }
:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; border-radius: 6px; box-shadow: 0 0 0 2px var(--primary); }
::selection { background: var(--primary-soft); }

.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 28px; }
.section { padding: 48px 0; }
.section-tight { padding: 32px 0; }
.muted { color: var(--ink-3); }
.center { text-align: center; }
.ok { color: var(--green); } .warn { color: var(--orange); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 200; }
.skip:focus { left: 8px; }

/* ============================== APP SHELL ============================== */
.app { display: flex; min-height: 100vh; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
main { flex: 1; display: block; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh; flex: none; width: var(--sb-w);
  display: flex; flex-direction: column; background: var(--sidebar-bg); border-right: 1px solid var(--line);
  transition: width .22s ease, transform .25s ease, background-color .25s; z-index: 60;
}
.sidebar::before { /* แถบสีแบรนด์ 4 สี */
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, #1d5fa8 0 25%, #d4a537 25% 50%, #0b7a4b 50% 75%, #e57a2e 75%);
}
.sb-head { position: relative; display: flex; align-items: center; gap: 8px; height: var(--topbar-h); padding: 0 12px 0 16px; flex: none; }
.sb-brand { display: flex; align-items: center; gap: 11px; min-width: 0; color: var(--ink); flex: 1; }
.sb-brand:hover { text-decoration: none; }
.sb-brand img { width: 38px; height: 38px; flex: none; object-fit: contain; }
.sb-brand .sb-label { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sb-brand strong { font-family: var(--font-head); font-size: 1.08rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.sb-brand small { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .76rem; }
.sb-collapse {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-3); display: grid; place-items: center; cursor: pointer; flex: none; transition: transform .22s, color .15s;
}
.sb-collapse:hover { color: var(--ink); border-color: var(--primary); }

.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 12px 12px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.sb-foot { flex: none; padding: 10px 12px 14px; border-top: 1px solid var(--line-2); }
.sb-section { padding: 18px 12px 6px; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; white-space: nowrap; }

.sb-link {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 42px; padding: 0 12px; margin: 2px 0;
  border: 0; border-radius: 10px; background: none; color: var(--ink-2); font: inherit; font-size: .94rem;
  text-align: left; cursor: pointer; white-space: nowrap; transition: background-color .15s, color .15s;
}
.sb-link > i:first-child { font-size: 1.12rem; width: 22px; text-align: center; flex: none; }
.sb-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sb-link.is-active { background: var(--primary-soft); color: var(--primary-text); font-weight: 600; }
.sb-toggle.is-active { background: none; }
.sb-toggle.is-active:hover { background: var(--surface-2); }
.sb-label { overflow: hidden; text-overflow: ellipsis; }
.sb-caret { margin-left: auto; font-size: .75rem; transition: transform .22s ease; opacity: .7; }
.sb-group.is-open > .sb-toggle .sb-caret { transform: rotate(180deg); }
.sb-sub { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .26s ease; }
.sb-group.is-open > .sb-sub { grid-template-rows: 1fr; }
.sb-sub-inner { overflow: hidden; margin-left: 22px; padding-left: 8px; border-left: 1px solid var(--line); }
.sb-group.is-open > .sb-sub > .sb-sub-inner { padding-bottom: 6px; }
.sb-sublink {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; margin: 1px 0; border-radius: 8px;
  color: var(--ink-2); font-size: .875rem; line-height: 1.35;
}
.sb-sublink > i { font-size: .95rem; width: 18px; text-align: center; flex: none; }
.sb-sublink > span:not(.sb-badge):not(.sb-lock) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-sublink:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sb-sublink.is-active { background: var(--primary-soft); color: var(--primary-text); font-weight: 600; }
.sb-badge { margin-left: auto; font-size: .7rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-3); flex: none; }
.sb-lock { margin-left: auto; color: var(--gold); font-size: .72rem; flex: none; }
.ic-blue { color: var(--blue); } .ic-green { color: var(--green); } .ic-gold { color: var(--gold); } .ic-orange { color: var(--orange); }
.ic-teal { color: var(--teal); } .ic-violet { color: var(--violet); } .ic-rose { color: var(--rose); } .ic-slate { color: var(--slate); }
.sb-backdrop { display: none; }

/* ---------- เมนูแบบย่อ (ไอคอน) — เฉพาะจอ ≥ 900px ---------- */
@media (min-width: 900px) {
  html[data-sidebar="collapsed"] .sidebar { width: var(--sb-w-mini); }
  html[data-sidebar="collapsed"] .sb-label,
  html[data-sidebar="collapsed"] .sb-caret,
  html[data-sidebar="collapsed"] .sb-badge,
  html[data-sidebar="collapsed"] .sb-sub { display: none; }
  html[data-sidebar="collapsed"] .sb-head { padding: 0; justify-content: center; }
  html[data-sidebar="collapsed"] .sb-brand { flex: none; }
  html[data-sidebar="collapsed"] .sb-collapse {
    position: absolute; right: -14px; top: 50%; margin-top: -14px; width: 28px; height: 28px; border-radius: 50%;
    transform: rotate(180deg); box-shadow: var(--shadow-sm); z-index: 2;
  }
  html[data-sidebar="collapsed"] .sb-nav, html[data-sidebar="collapsed"] .sb-foot { padding-left: 12px; padding-right: 12px; }
  html[data-sidebar="collapsed"] .sb-link { justify-content: center; padding: 0; }
  html[data-sidebar="collapsed"] .sb-link > i:first-child { width: auto; font-size: 1.2rem; }
  html[data-sidebar="collapsed"] .sb-group.has-active > .sb-toggle { background: var(--primary-soft); color: var(--primary-text); }
  html[data-sidebar="collapsed"] .sb-section { padding: 10px 0; font-size: 0; }
  html[data-sidebar="collapsed"] .sb-section::after { content: ""; display: block; height: 1px; background: var(--line); margin: 0 10px; }
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 24px; background: color-mix(in srgb, var(--surface) 88%, transparent); background: var(--surface);
  border-bottom: 1px solid var(--line);
}
@supports (backdrop-filter: blur(8px)) {
  .topbar { background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: saturate(1.3) blur(10px); }
}
.topbar .tb-menu, .topbar .tb-brand, .topbar .tb-search-btn { display: none; }
.tb-brand { align-items: center; gap: 8px; color: var(--ink); font-family: var(--font-head); font-size: 1.02rem; white-space: nowrap; }
.tb-brand:hover { text-decoration: none; }
.tb-title { font-size: 1.15rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tb-search {
  flex: 1; min-width: 0; max-width: 520px; display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid transparent; border-radius: 11px; color: var(--ink-3); transition: border-color .15s, background-color .15s;
}
.tb-search:focus-within { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 4px var(--primary-soft); }
.tb-search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; font: inherit; font-size: .93rem; color: var(--ink); }
.tb-search input::placeholder { color: var(--ink-3); }
kbd { font-family: ui-monospace, monospace; font-size: .72rem; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); color: var(--ink-3); background: var(--surface); }
.tb-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: none; }
@media (max-width: 1099.98px) { .user-name { display: none; } .user-btn { padding: 3px 8px 3px 3px; } }
.tb-admin-actions { display: flex; gap: 8px; margin-right: 6px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; border: 0; background: none;
  color: var(--ink-2); cursor: pointer; font-size: 1.08rem; flex: none; transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
html[data-theme="dark"] .i-moon, html[data-theme="light"] .i-sun { display: none; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 8px); left: 0; min-width: 230px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 70;
  opacity: 0; transform: translateY(-4px); pointer-events: none; transition: opacity .15s, transform .15s;
}
.dropdown-end .dropdown-menu { left: auto; right: 0; }
.dropdown.is-open .dropdown-menu { opacity: 1; transform: none; pointer-events: auto; }
.dropdown-menu a, .dropdown-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 8px;
  color: var(--ink); font: inherit; font-size: .93rem; background: none; border: 0; cursor: pointer; text-align: left;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-menu form { margin: 0; }
.dropdown-head { padding: 8px 12px 10px; border-bottom: 1px solid var(--line-2); margin-bottom: 4px; font-weight: 600; }
.dropdown-head small { display: block; color: var(--ink-3); font-weight: 400; }
.user-btn { display: flex; align-items: center; gap: 8px; background: none; border: 1px solid var(--line); padding: 3px 10px 3px 3px; border-radius: 999px; cursor: pointer; font: inherit; color: var(--ink); }
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, #1d5fa8, #0b7a4b); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: .9rem; flex: none; }
.user-name { max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }

/* ---------- มือถือ / แท็บเล็ตแนวตั้ง (< 900px): เมนูเลื่อนออกจากซ้าย ---------- */
@media (max-width: 899.98px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); transform: translateX(-102%); box-shadow: none; }
  html.sb-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .sb-collapse { transform: none; } /* บนมือถือปุ่มนี้ใช้ปิดเมนู */
  .sb-backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .25s; }
  html.sb-open .sb-backdrop { opacity: 1; pointer-events: auto; }
  html.sb-open body { overflow: hidden; }
  .topbar .tb-menu { display: grid; margin-left: -8px; }
  .topbar .tb-brand { display: flex; }
  .tb-brand + .tb-search, .tb-brand + .tb-title { margin-left: 8px; }
  .topbar { padding: 0 16px; gap: 6px; }
  .is-admin .topbar .tb-brand { display: none; }
}
@media (max-width: 680px) {
  .topbar .tb-search { display: none; }
  .topbar .tb-search-btn { display: grid; }
  .user-name, .user-btn .small { display: none; }
  .user-btn { padding: 3px; }
  .tb-login span { display: none; }
  .tb-login { padding: 0 10px; height: 38px; }
  .tb-admin-actions .btn-ghost { display: none; }
  .tb-admin-actions .btn { padding: 7px 10px; font-size: .85rem; }
}
@media (max-width: 420px) {
  .tb-brand strong { display: none; }
}

/* ============================== COMPONENTS ============================== */
/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 500;
  font-size: .94rem; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--primary);
  background: var(--primary); color: var(--on-primary); cursor: pointer; white-space: nowrap;
  transition: background-color .15s, box-shadow .15s, transform .1s;
}
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); text-decoration: none; box-shadow: 0 4px 14px var(--primary-soft); color: var(--on-primary); }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 7px 14px; font-size: .88rem; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); box-shadow: none; }
.btn-danger { background: var(--surface); color: var(--rose); border-color: var(--line); }
.btn-danger:hover { background: var(--rose-soft); border-color: var(--rose); color: var(--rose); box-shadow: none; }
.btn-link { background: none; border: 0; color: var(--primary-text); padding: 0; font: inherit; cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field label, .label { font-weight: 500; font-size: .92rem; color: var(--ink); }
.field .hint { font-size: .8rem; color: var(--ink-3); }
.input, .field input[type=text], .field input[type=password], .field input[type=url], .field input[type=email],
.field input[type=number], .field input[type=search], .field input[type=date], .field input[type=datetime-local], .field input[type=file], .field select, .field textarea {
  font: inherit; font-size: .94rem; width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.field input[type=file] { padding: 8px; background: var(--surface-2); }
.field textarea { min-height: 110px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .93rem; cursor: pointer; margin: 4px 18px 4px 0; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }

/* ---------- Flash & toast ---------- */
.flash-wrap { padding: 16px 28px 0; max-width: calc(var(--max)); margin: 0 auto; width: 100%; }
.flash { position: relative; padding: 12px 44px 12px 16px; border-radius: 10px; margin-bottom: 8px; font-size: .94rem; border: 1px solid; animation: slideDown .3s ease; }
.flash-success { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 35%, transparent); color: var(--green); }
.flash-error   { background: var(--rose-soft);  border-color: color-mix(in srgb, var(--rose) 35%, transparent); color: var(--rose); }
.flash-info    { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 30%, transparent); color: var(--primary-text); }
.flash-x { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 6px; }
.flash-x:hover { opacity: 1; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem;
  box-shadow: var(--shadow-lg); z-index: 300; transition: opacity .2s, transform .2s;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.drawer:not([hidden]) ~ .toast { bottom: 84px; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Colour utilities (ไอคอน/แท็ก/การ์ด) ---------- */
.c-blue   { --c: var(--blue);   --c-soft: var(--blue-soft); }
.c-green  { --c: var(--green);  --c-soft: var(--green-soft); }
.c-gold   { --c: var(--gold);   --c-soft: var(--gold-soft); }
.c-orange { --c: var(--orange); --c-soft: var(--orange-soft); }
.c-teal   { --c: var(--teal);   --c-soft: var(--teal-soft); }
.c-violet { --c: var(--violet); --c-soft: var(--violet-soft); }
.c-rose   { --c: var(--rose);   --c-soft: var(--rose-soft); }
.c-slate  { --c: var(--slate);  --c-soft: var(--slate-soft); }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: .76rem; font-weight: 500; padding: 2px 10px; border-radius: 999px; background: var(--c-soft, var(--surface-2)); color: var(--c, var(--ink-2)); }
.tag-pin { --c: var(--orange); --c-soft: var(--orange-soft); }
.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill-beta { background: var(--blue-soft); color: var(--blue); }
.pill-maintenance { background: var(--orange-soft); color: var(--orange); }
.pill-planned { background: var(--slate-soft); color: var(--slate); }
.pill-active, .pill-published { background: var(--green-soft); color: var(--green); }
.pill-draft { background: var(--gold-soft); color: var(--gold); }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .8rem; background: var(--surface-2); color: var(--ink-2); padding: 1px 6px; border-radius: 5px; }
mark { background: var(--gold-soft); color: inherit; padding: 0 2px; border-radius: 3px; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden; padding: 64px 0 76px; border-bottom: 1px solid var(--line);
  background:
    radial-gradient(900px 380px at 90% -10%, rgba(212, 165, 55, .14), transparent 60%),
    radial-gradient(700px 360px at 0% 110%, rgba(11, 122, 75, .10), transparent 60%),
    radial-gradient(800px 420px at 50% -30%, var(--primary-soft), transparent 65%),
    var(--surface);
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .55;
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 9%, transparent) 1px, transparent 1px); background-size: 22px 22px;
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent 85%); mask-image: linear-gradient(to bottom, #000, transparent 85%);
}
.hero .container { position: relative; z-index: 1; }
.hero-inner { max-width: 760px; margin: 0 auto; text-align: center; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: .84rem; font-weight: 500; color: var(--gold); background: var(--gold-soft); padding: 5px 14px; border-radius: 999px; margin-bottom: 18px; }
.hero h1 { font-size: clamp(1.9rem, 4.4vw, 3rem); font-weight: 700; margin-bottom: 14px; }
.hero h1 .accent { background: linear-gradient(90deg, var(--primary-text), var(--green)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .lead { font-size: 1.06rem; color: var(--ink-2); margin-bottom: 28px; }
.search-xl { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 7px 7px 7px 18px; box-shadow: var(--shadow-lg); max-width: 640px; margin: 0 auto; }
.search-xl:focus-within { border-color: var(--primary); box-shadow: 0 0 0 5px var(--primary-soft), var(--shadow-lg); }
.search-xl > i { color: var(--ink-3); font-size: 1.15rem; }
.search-xl input { flex: 1; border: 0; outline: none; font: inherit; font-size: 1rem; background: none; color: var(--ink); min-width: 0; padding: 8px 0; }
.quick-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 20px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); font-size: .87rem; transition: border-color .15s, transform .15s; }
.chip i { color: var(--c, var(--primary-text)); }
.chip:hover { border-color: var(--c, var(--primary)); color: var(--ink); text-decoration: none; transform: translateY(-1px); }

/* ---------- Section header ---------- */
.sec-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.sec-head h2 { margin: 0; }
.sec-head p { margin: 4px 0 0; color: var(--ink-3); }
.sec-head .more { font-size: .92rem; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: -40px; position: relative; z-index: 2; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.stat-top { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: .89rem; line-height: 1.35; }
.stat-top i { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--c-soft); color: var(--c); font-size: 1.05rem; flex: none; }
.stat-value { font-family: var(--font-head); font-size: 2rem; font-weight: 700; margin: 8px 0 2px; line-height: 1.1; }
.stat-value small { font-size: .95rem; font-weight: 500; color: var(--ink-3); margin-left: 4px; }
.stat-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 8px; font-size: .79rem; color: var(--ink-3); }
.bar { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 10px 0 8px; }
.bar > span { display: block; height: 100%; background: var(--c, var(--primary)); border-radius: 6px; transition: width .8s ease; }

/* ---------- App launcher ---------- */
.app-cat { margin-bottom: 36px; }
.app-cat-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.app-cat-head .cat-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--c-soft); color: var(--c); font-size: 1.1rem; flex: none; }
.app-cat-head h3 { margin: 0; }
.app-cat-head p { margin: 0; font-size: .86rem; color: var(--ink-3); }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 14px; }
.app-card {
  position: relative; display: flex; align-items: flex-start; gap: 14px; padding: 16px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; min-width: 0;
}
a.app-card:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--c) 40%, var(--line)); }
a.app-card:active { transform: translateY(-1px); }
.app-card::before { content: ""; position: absolute; left: 0; top: 16px; bottom: 16px; width: 3px; border-radius: 0 3px 3px 0; background: var(--c); opacity: 0; transition: opacity .18s; }
a.app-card:hover::before { opacity: 1; }
.app-icon { width: 48px; height: 48px; flex: none; border-radius: 13px; display: grid; place-items: center; font-size: 1.4rem; background: var(--c-soft); color: var(--c); }
.app-body { display: flex; flex-direction: column; min-width: 0; gap: 1px; padding-right: 18px; overflow-wrap: anywhere; }
.app-name { font-weight: 600; line-height: 1.35; }
.app-en { font-size: .78rem; color: var(--ink-3); }
.app-desc { font-size: .86rem; color: var(--ink-2); margin-top: 4px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.app-badges { display: flex; gap: 6px; margin-top: 8px; }
.app-lock { position: absolute; top: 10px; right: 10px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--gold-soft); color: var(--gold); font-size: .72rem; }
.app-lock.is-native { background: var(--slate-soft); color: var(--slate); }
.app-lock.is-sso { background: var(--green-soft); color: var(--green); }
.app-card.is-muted { background: color-mix(in srgb, var(--surface) 70%, var(--bg)); box-shadow: none; }
.app-card.is-muted .app-icon { filter: grayscale(.6); opacity: .65; }
.app-card.is-muted .app-name { color: var(--ink-2); }
.app-card.is-compact { align-items: center; padding: 12px 14px; }
.app-card.is-compact .app-icon { width: 42px; height: 42px; font-size: 1.2rem; }
.auth-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .82rem; color: var(--ink-3); margin: -8px 0 22px; }
.auth-legend span { display: inline-flex; align-items: center; gap: 6px; }
.auth-legend .app-lock { position: static; width: 20px; height: 20px; font-size: .62rem; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 24px; }
.filter-bar .search-sm { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; color: var(--ink-3); }
.filter-bar .search-sm:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.filter-bar .search-sm input { border: 0; outline: none; font: inherit; padding: 10px 0; flex: 1; background: none; min-width: 0; color: var(--ink); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { font: inherit; font-size: .88rem; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transition: border-color .15s, background-color .15s; }
.tab:hover { border-color: var(--c, var(--primary)); text-decoration: none; color: var(--ink); }
.tab.is-active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.tab .count { font-size: .74rem; opacity: .75; }
@media (max-width: 680px) { /* แท็บเลื่อนแนวนอนบนมือถือ */
  .tabs.scroll-x, .filter-bar .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; -webkit-overflow-scrolling: touch; }
  .filter-bar .tabs::-webkit-scrollbar { display: none; }
}

/* ---------- News ---------- */
.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 20px; }
.split .news-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 16px; }
.news-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: var(--ink); transition: transform .18s, box-shadow .18s; min-width: 0; }
.news-card:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.news-cover { aspect-ratio: 16 / 8.5; background: var(--surface-2); overflow: hidden; display: block; }
.news-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s ease; }
.news-card:hover .news-cover img { transform: scale(1.03); }
.news-cover-ph { width: 100%; height: 100%; display: grid; place-items: center; font-size: 2.2rem; color: var(--c); background: linear-gradient(135deg, var(--c-soft), transparent 75%); }
.news-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 16px 18px 0; font-size: .8rem; color: var(--ink-3); }
.news-title { font-family: var(--font-head); font-weight: 600; font-size: 1.04rem; padding: 8px 18px 0; line-height: 1.45; }
.news-sum { padding: 6px 18px 18px; font-size: .89rem; color: var(--ink-2); }

.article { max-width: 780px; margin: 0 auto; }
.article-cover { border-radius: var(--radius); overflow: hidden; margin: 0 0 28px; border: 1px solid var(--line); }
.article-cover img { width: 100%; display: block; }
.prose { font-size: 1.02rem; line-height: 1.85; overflow-wrap: anywhere; }
.prose h2 { margin-top: 1.6em; font-size: 1.32rem; }
.prose h3 { margin-top: 1.4em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin-bottom: .35em; }
.prose table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: .95rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose blockquote { margin: 1em 0; padding: 12px 18px; border-left: 4px solid var(--gold-bright); background: var(--gold-soft); border-radius: 0 10px 10px 0; }
.prose img { border-radius: 10px; }

/* ---------- Page head ---------- */
.page-head { background: var(--surface); border-bottom: 1px solid var(--line); padding: 30px 0 26px; background-image: radial-gradient(600px 200px at 100% 0%, var(--primary-soft), transparent 70%); }
.page-head h1 { margin-bottom: 6px; }
.page-head .lead { color: var(--ink-2); margin: 0; }
.page-head .eyebrow { margin-bottom: 12px; }
.page-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.page-head-row > div:first-child { min-width: 0; flex: 1 1 320px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 8px; font-size: .84rem; color: var(--ink-3); margin-bottom: 10px; }
.crumbs a { color: var(--ink-3); }

/* ---------- Timeline ---------- */
.journey { position: relative; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.journey::before { content: ""; position: absolute; left: 0; right: 0; top: 19px; height: 2px; background: linear-gradient(90deg, var(--blue), var(--gold-bright), var(--green), var(--orange)); opacity: .4; }
.jstep { position: relative; padding-top: 48px; }
.jdot { position: absolute; top: 6px; left: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--surface); border: 2px solid var(--c); display: grid; place-items: center; color: var(--c); font-size: .8rem; }
.jstep time { font-size: .82rem; font-weight: 600; color: var(--c); }
.jstep h4 { margin: 4px 0; font-size: 1rem; }
.jstep p { font-size: .88rem; color: var(--ink-2); margin: 0; }

/* ---------- Documents ---------- */
.doc-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 24px; align-items: start; }
.side-nav { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; position: sticky; top: calc(var(--topbar-h) + 16px); }
.side-nav a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 8px; color: var(--ink-2); font-size: .92rem; }
.side-nav a:hover { background: var(--surface-2); text-decoration: none; }
.side-nav a.is-active { background: var(--primary-soft); color: var(--primary-text); font-weight: 600; }
.side-nav a.sub { padding-left: 28px; font-size: .87rem; }
.side-nav .count { color: var(--ink-3); font-size: .8rem; }
.doc-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.doc-item { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); transition: background-color .15s; }
.doc-item:hover { background: var(--surface-2); }
.doc-item:last-child { border-bottom: 0; }
.doc-ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); font-size: 1.2rem; flex: none; }
.doc-main { flex: 1; min-width: 0; }
.doc-title { font-weight: 600; color: var(--ink); display: block; overflow-wrap: anywhere; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .79rem; color: var(--ink-3); margin-top: 2px; }

/* ---------- Layout helpers ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 28px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.panel h3 { display: flex; align-items: center; gap: 8px; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.list-plain li:last-child { border-bottom: 0; }

/* ---------- Search results ---------- */
.result-group { margin-bottom: 32px; }
.result-group h3 { font-size: 1rem; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.result { display: block; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; color: var(--ink); transition: border-color .15s; }
.result:hover { text-decoration: none; border-color: var(--primary); }
.result strong { display: block; }
.result span { font-size: .88rem; color: var(--ink-2); }

/* ---------- Auth ---------- */
.auth-wrap { min-height: calc(100vh - 300px); display: grid; place-items: center; padding: 40px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 32px; box-shadow: var(--shadow-lg); }
.auth-card .auth-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.auth-card h1 { font-size: 1.42rem; text-align: center; margin-bottom: 4px; }
.auth-card .muted { text-align: center; margin-bottom: 24px; }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--ink-3); }
.empty i { font-size: 2.2rem; display: block; margin-bottom: 8px; opacity: .6; }
.pager { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-top: 28px; }
.pager a, .pager span { min-width: 38px; height: 38px; display: grid; place-items: center; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: .92rem; }
.pager a:hover { border-color: var(--primary); text-decoration: none; }
.pager .is-current { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.pager .gap { border: 0; background: none; }

/* ---------- Footer ---------- */
.site-footer { margin-top: 56px; background: var(--surface); border-top: 1px solid var(--line); padding: 32px 28px 0; font-size: .9rem; }
.footer-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 28px; max-width: var(--max); margin: 0 auto; }
.footer-grid h4 { font-size: .95rem; margin-bottom: 10px; }
.footer-grid > div > a, .footer-grid > div > span { display: flex; align-items: center; gap: 8px; color: var(--ink-2); padding: 3px 0; }
.footer-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.footer-brand small { display: block; color: var(--ink-3); }
.footer-bottom { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--line-2); margin: 24px auto 0; padding: 14px 0 20px; color: var(--ink-3); font-size: .82rem; max-width: var(--max); }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  .reveal { opacity: 0; transform: translateY(12px); transition: opacity .5s ease, transform .5s ease; }
  .reveal.is-in { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ============================== PREFERENCES DRAWER ============================== */
.drawer { position: fixed; inset: 0; z-index: 250; }
.drawer-backdrop { position: absolute; inset: 0; background: var(--overlay); opacity: 0; transition: opacity .25s; }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(390px, 100%); background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}
.drawer.is-open .drawer-backdrop { opacity: 1; }
.drawer.is-open .drawer-panel { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 14px 22px; border-bottom: 1px solid var(--line-2); }
.drawer-head h2 { font-size: 1.1rem; margin: 0; display: flex; align-items: center; gap: 10px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 8px 22px 22px; }
.drawer-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 22px; border-top: 1px solid var(--line-2); }
.pref { padding: 16px 0; border-bottom: 1px solid var(--line-2); }
.pref:last-child { border-bottom: 0; }
.pref h3 { font-size: .92rem; margin: 0 0 10px; color: var(--ink-2); font-family: var(--font); font-weight: 600; }
.pref-hint, .pref-status { font-size: .8rem; color: var(--ink-3); margin: 8px 0 0; }
.pref-status { margin: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button {
  border: 0; background: none; padding: 9px 6px; border-radius: 9px; color: var(--ink-2); font: inherit; font-size: .87rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; transition: background-color .15s, color .15s;
}
.seg button:hover { color: var(--ink); }
.seg button.is-on { background: var(--surface); color: var(--primary-text); box-shadow: var(--shadow-sm); font-weight: 600; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, 40px); gap: 12px; }
.swatch {
  position: relative; width: 40px; height: 40px; border-radius: 50%; background: var(--sw); cursor: pointer;
  border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); transition: transform .15s, box-shadow .15s; padding: 0;
}
.swatch:hover { transform: scale(1.08); }
.swatch.is-on { box-shadow: 0 0 0 2px var(--ink); }
.swatch.is-on::after { content: "\2713"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 700; text-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.swatch-custom { background: conic-gradient(#e53935, #fdd835, #43a047, #00acc1, #1e88e5, #8e24aa, #e53935); display: grid; place-items: center; color: #fff; font-size: .9rem; text-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }
.swatch-custom.is-on::after { content: none; }
.preview-card { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.preview-card .app-icon { width: 40px; height: 40px; font-size: 1.1rem; }
.preview-card div { flex: 1; min-width: 0; }
.preview-card strong { display: block; font-size: .95rem; }
.preview-card small { color: var(--ink-3); }

/* ============================== ADMIN ============================== */
.admin-body { padding: 24px 28px 48px; max-width: 1400px; width: 100%; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2 { font-size: 1.08rem; margin: 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.table { width: 100%; border-collapse: collapse; font-size: .91rem; }
.table th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: .8rem; background: var(--surface-2); padding: 10px 12px; white-space: nowrap; }
.table th:first-child { border-radius: 8px 0 0 8px; } .table th:last-child { border-radius: 0 8px 8px 0; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table .actions { white-space: nowrap; text-align: right; }
.table .actions form { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; border-top: 1px solid var(--line-2); margin-top: 8px; padding-top: 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; gap: 12px; align-items: center; min-width: 0; }
.kpi i { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--c-soft); color: var(--c); font-size: 1.2rem; flex: none; }
.kpi b { font-family: var(--font-head); font-size: 1.5rem; display: block; line-height: 1.1; }
.kpi span { font-size: .83rem; color: var(--ink-3); }
.icon-preview { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--c-soft); color: var(--c); font-size: 1.2rem; flex: none; }
.thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.bar-row { display: grid; grid-template-columns: minmax(0, 180px) 1fr 44px; gap: 10px; align-items: center; font-size: .87rem; padding: 4px 0; }
.bar-row .bar { margin: 0; height: 8px; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 10px; }
.choice { position: relative; display: flex; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.choice:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice.is-checked, .choice:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.choice > i { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); flex: none; font-size: 1.05rem; }
.choice.is-checked > i, .choice:has(input:checked) > i { background: var(--primary-soft); color: var(--primary-text); }
.choice strong { display: block; font-size: .92rem; line-height: 1.35; }
.choice small { display: block; color: var(--ink-3); font-size: .79rem; line-height: 1.45; margin-top: 3px; }
.subpanel { background: var(--bg); border: 1px dashed var(--line); border-radius: 12px; padding: 16px 16px 4px; margin-bottom: 16px; min-width: 0; }
.secret { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .8rem; word-break: break-all; }
pre.snippet { background: #0f1b28; color: #dbe6f2; padding: 14px 16px; border-radius: 10px; font-size: .8rem; overflow-x: auto; line-height: 1.55; border: 1px solid var(--line); }

/* ============================== RESPONSIVE ============================== */
@media (max-width: 1199.98px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1023.98px) {
  .split, .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .side-nav { position: static; display: flex; overflow-x: auto; gap: 4px; padding: 6px; }
  .side-nav a { white-space: nowrap; flex: none; }
  .side-nav a.sub { padding-left: 12px; }
  .footer-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 680px) {
  .container { padding: 0 16px; }
  .section { padding: 34px 0; }
  .section-tight { padding: 24px 0; }
  .hero { padding: 40px 0 60px; }
  .hero .lead { font-size: .98rem; }
  .search-xl { padding-left: 14px; }
  .search-xl .btn { padding: 9px 14px; }
  .stats { gap: 10px; margin-top: -34px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 1.5rem; }
  .stat-top { font-size: .82rem; }
  .stat-top i { width: 30px; height: 30px; font-size: .95rem; }
  .journey { grid-template-columns: 1fr; gap: 16px; }
  .journey::before { left: 13px; right: auto; top: 0; bottom: 0; width: 2px; height: auto; }
  .jstep { padding: 0 0 0 44px; }
  .jdot { top: 0; }
  .sec-head { flex-direction: column; align-items: flex-start; gap: 6px; }
  .footer-grid { grid-template-columns: 1fr; }
  .site-footer { padding: 28px 16px 0; }
  .flash-wrap { padding: 12px 16px 0; }
  .auth-card { padding: 24px 20px; }
  .doc-item { padding: 12px 14px; gap: 12px; }
  .admin-body { padding: 16px 14px 40px; }
  .card { padding: 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .bar-row { grid-template-columns: minmax(0, 110px) 1fr 36px; }
  .form-actions .btn { flex: 1; }
}
@media (max-width: 380px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
}
@media print {
  .sidebar, .topbar, .site-footer, .drawer, .toast, .sb-backdrop { display: none !important; }
  body { background: #fff; color: #000; }
}

/* ---------------------------------------------------------------- admin/system.php */
.sys-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sys-checks li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.sys-checks li > i { margin-top: 2px; }
.sys-checks li div { display: flex; flex-direction: column; min-width: 0; }
.sys-checks small { color: var(--ink-2); font-size: .84rem; }
.sys-ok > i, .sys-inline.sys-ok { color: var(--green); }
.sys-warn > i { color: var(--gold, #b8860b); }
.sys-bad > i, .sys-inline.sys-bad { color: var(--rose); }
.sys-inline { margin-left: 8px; font-size: .88rem; }
.sys-kv th { width: 42%; background: none; white-space: normal; }
.sys-kv td { word-break: break-all; }
.sys-log { margin: 0 0 14px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: .88rem; display: grid; gap: 4px; }
.sys-log .sys-ok { color: var(--green); } .sys-log .sys-bad { color: var(--rose); }
.sys-backup { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.sys-backup form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- ระบบงาน: 3 มุมมอง (การ์ดภาพปก / ตาราง / ไอคอน) */
.view-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.view-switch { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.vs-btn { font: inherit; font-size: .84rem; border: 0; background: none; color: var(--ink-3); padding: 6px 10px; border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.vs-btn:hover { color: var(--ink); }
.vs-btn.is-active { background: var(--primary-soft); color: var(--primary-text); font-weight: 600; }
.sort-sel { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 10px; color: var(--ink-3); }
.sort-sel select { border: 0; background: none; font: inherit; font-size: .86rem; color: var(--ink); padding: 8px 0; outline: none; cursor: pointer; }
@media (max-width: 680px) { .vs-btn span { display: none; } .view-tools { margin-left: 0; } }

.app-tile { position: relative; display: flex; flex-direction: column; min-width: 0; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
a.app-tile:hover { text-decoration: none; }
.app-cover { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--c-soft); overflow: hidden; flex: none; }
.app-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .35s ease; }
.app-cover-ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 3rem; color: var(--c);
  background: radial-gradient(120% 90% at 20% 10%, color-mix(in srgb, var(--c) 18%, transparent), transparent 60%), var(--c-soft); }
.app-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 16px 18px 4px; }
.app-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-tile .app-icon { width: 38px; height: 38px; border-radius: 10px; font-size: 1.1rem; }
.app-titles { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.app-tile .app-desc { margin-top: 0; }
.app-cat-pill { display: inline-block; font-size: .76rem; padding: 2px 9px; border-radius: 999px; background: var(--c-soft); color: var(--c); font-weight: 600; white-space: nowrap; }
.app-auth-col { display: flex; flex-direction: column; font-size: .84rem; color: var(--ink-2); }
.app-auth-col small { color: var(--gold); }
.app-cat-col, .app-auth-col, .app-status-col, .app-th { display: none; }
.app-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 18px 14px; }
.app-open { font-size: .86rem; color: var(--c); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.app-tile.is-muted { box-shadow: none; }
.app-tile.is-muted .app-cover, .app-tile.is-muted .app-icon { filter: grayscale(.7); opacity: .7; }
.app-tile.is-muted .app-open { color: var(--ink-3); font-weight: 400; }

/* การ์ดภาพปก */
.apps-view-cover .app-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 20px; }
.apps-view-cover a.app-tile:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--c) 40%, var(--line)); }
.apps-view-cover a.app-tile:hover .app-cover img { transform: scale(1.04); }
.apps-view-cover .app-foot { border-top: 1px solid var(--line-2); margin: 10px 18px 0; padding: 12px 0 14px; }

/* ตาราง */
.apps-view-list .app-tiles { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.apps-view-list .app-th, .apps-view-list .app-tile {
  display: grid; grid-template-columns: 84px minmax(0, 2.6fr) minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, .8fr) 44px; align-items: center; gap: 16px; padding: 10px 16px; }
.apps-view-list .app-th { font-size: .78rem; font-weight: 600; color: var(--ink-2); background: var(--surface-2); padding-top: 9px; padding-bottom: 9px; }
.apps-view-list .app-tile { border: 0; border-top: 1px solid var(--line-2); border-radius: 0; box-shadow: none; overflow: visible; }
.apps-view-list a.app-tile:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.apps-view-list .app-cover { width: 84px; aspect-ratio: 16 / 10; border-radius: 8px; border: 1px solid var(--line-2); }
.apps-view-list .app-cover-ph { font-size: 1.4rem; }
.apps-view-list .app-cover .app-lock, .apps-view-list .app-tile .app-icon, .apps-view-list .app-foot .pill { display: none; }
.apps-view-list .app-main { padding: 0; gap: 2px; }
.apps-view-list .app-tile .app-desc { -webkit-line-clamp: 1; font-size: .84rem; }
.apps-view-list .app-cat-col, .apps-view-list .app-auth-col, .apps-view-list .app-status-col { display: block; }
.apps-view-list .app-auth-col { display: flex; }
.apps-view-list .app-foot { margin: 0; padding: 0; justify-content: flex-end; }
.apps-view-list .app-open { font-size: 0; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); justify-content: center; color: var(--ink-3); }
.apps-view-list .app-open i { font-size: .95rem; }
.apps-view-list a.app-tile:hover .app-open { background: var(--c-soft); color: var(--c); }
@media (max-width: 760px) {
  .apps-view-list .app-th { display: none; }
  .apps-view-list .app-tile { grid-template-columns: 72px minmax(0, 1fr) 36px; gap: 12px; }
  .apps-view-list .app-cover { width: 72px; }
  .apps-view-list .app-cat-col, .apps-view-list .app-auth-col, .apps-view-list .app-status-col { display: none; }
}

/* ไอคอน (กะทัดรัด) */
.apps-view-compact .app-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 12px; }
.apps-view-compact .app-tile { flex-direction: row; align-items: center; padding: 12px 40px 12px 14px; }
.apps-view-compact a.app-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--c) 40%, var(--line)); }
.apps-view-compact .app-cover { display: contents; }
.apps-view-compact .app-cover > img, .apps-view-compact .app-cover-ph, .apps-view-compact .app-desc, .apps-view-compact .app-foot { display: none; }
.apps-view-compact .app-main { padding: 0; }
.apps-view-compact .app-tile .app-icon { width: 44px; height: 44px; font-size: 1.25rem; border-radius: 12px; }
.apps-view-compact .app-lock { top: 50%; transform: translateY(-50%); }

/* หลังบ้าน: ภาพปกระบบงาน */
.cover-field { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 16px; align-items: start; }
.cover-preview { aspect-ratio: 16 / 9; border-radius: 12px; border: 1px dashed var(--line); background: var(--surface-2); display: grid; place-items: center; overflow: hidden; color: var(--ink-3); font-size: .85rem; text-align: center; padding: 0; cursor: pointer; }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.cover-preview.is-drag { border-color: var(--primary); background: var(--primary-soft); }
.thumb-cover { width: 72px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; border: 1px solid var(--line-2); display: block; }
@media (max-width: 680px) { .cover-field { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- สมัครสมาชิก / ลืมรหัสผ่าน */
.auth-card.auth-wide { max-width: 720px; }
.auth-row { display: flex; justify-content: flex-end; gap: 8px; font-size: .88rem; margin: -4px 0 14px; color: var(--ink-3); }
.auth-alt { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-2); font-size: .9rem; color: var(--ink-3); }
.reg-h { font-size: 1rem; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; color: var(--ink); }
.reg-units { display: grid; gap: 8px; }
.reg-unit { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 190px) auto; gap: 8px; align-items: center; }
.reg-unit select { width: 100%; min-width: 0; }
@media (max-width: 560px) { .reg-unit { grid-template-columns: minmax(0, 1fr) auto; } .reg-unit select:first-child { grid-column: 1 / -1; } }
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.mail-preview { margin: 12px 0; padding: 10px 12px; border: 1px dashed var(--gold); border-radius: 10px; background: var(--gold-soft); font-size: .84rem; }
.mail-preview pre { white-space: pre-wrap; font-family: inherit; margin: 6px 0 0; }

/* หลังบ้าน: สิทธิ์ตัวชี้วัดของผู้ใช้ */
.grant-table td { vertical-align: middle; }
.grant-table select { min-width: 0; width: 100%; }
.grant-table .cap { text-align: center; }
.grant-table tr.is-req td { background: color-mix(in srgb, var(--gold-soft) 60%, transparent); }
.approve-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-radius: 12px; background: var(--gold-soft); margin-bottom: 16px; }
.approve-bar .grow { flex: 1 1 260px; }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 18px; align-items: start; }
.profile-grid > .card { margin: 0; }
.profile-grid .span-all { grid-column: 1 / -1; }
.home-kpi-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 14px 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }

/* =====================================================================
   v1.16 — โต้ตอบได้มากขึ้น: ช่องสรุปกดได้ · แถว/การ์ดกดได้ · กรองทันที · เรียงตาราง
   ===================================================================== */
.kpi { position: relative; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.kpi b small { font-size: .62em; font-weight: 500; color: var(--ink-3); margin-left: 2px; }
a.kpi.is-link { color: inherit; text-decoration: none; cursor: pointer; }
a.kpi.is-link:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--c, var(--primary)); }
a.kpi.is-link:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
a.kpi.is-active { border-color: var(--c); box-shadow: 0 0 0 2px var(--c-soft), var(--shadow-sm); background: linear-gradient(135deg, var(--c-soft), var(--surface) 70%); }
.kpi .kpi-go { position: absolute; top: 8px; right: 8px; font-size: 1rem; color: var(--ink-3); opacity: 0; transition: opacity .15s; }
.kpi .kpi-go i { width: auto; height: auto; background: none; font-size: 1.05rem; color: inherit; border-radius: 0; display: inline; }
a.kpi:hover .kpi-go, a.kpi.is-active .kpi-go { opacity: 1; }
.row-link { cursor: pointer; transition: background .12s; }
.row-link:hover > td { background: var(--primary-soft); }
[data-href][tabindex]:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.th-sort::after { content: "↕"; opacity: .3; margin-left: 5px; font-size: .8em; }
th.th-sort[aria-sort="ascending"]::after { content: "↑"; opacity: .9; }
th.th-sort[aria-sort="descending"]::after { content: "↓"; opacity: .9; }
th.th-sort:hover { color: var(--primary-text); }
[hidden] { display: none !important; }

/* แถบกรอง (ภาพรวมตัวชี้วัด / สิ่งที่ต้องทำ) */
.ov-bar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin: 0 0 14px; }
.ov-search { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; min-height: 40px; }
.ov-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.ov-search i { color: var(--ink-3); }
.ov-search input { border: 0; background: transparent; outline: 0; flex: 1; min-width: 0; font: inherit; color: var(--ink); padding: 8px 0; }
.ov-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ov-chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .84rem; cursor: pointer; text-decoration: none; transition: all .12s; }
.ov-chip i { color: var(--c, var(--ink-3)); }
.ov-chip:hover { border-color: var(--c, var(--primary)); color: var(--ink); text-decoration: none; }
.ov-chip.is-on { background: var(--c, var(--primary)); border-color: var(--c, var(--primary)); color: #fff; }
.ov-chip.is-on i { color: #fff; }
.ov-chip b { font-weight: 700; }
.ov-right { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.seg.seg-sm { display: inline-grid; padding: 3px; border-radius: 10px; }
.seg.seg-sm a { display: grid; place-items: center; padding: 5px 11px; border-radius: 8px; color: var(--ink-3); }
.seg.seg-sm a.is-on { background: var(--surface); color: var(--primary-text); box-shadow: var(--shadow-sm); }
.ov-active { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .85rem; color: var(--ink-3); margin: -4px 0 14px; }
.ov-active .tag { text-decoration: none; }

/* ช่องเลือกแบบพิมพ์ค้นหา (Tom Select) ให้เข้ากับธีม */
.ts-wrapper { min-width: 0; }
.ts-wrapper .ts-control { background: var(--surface) !important; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px; color: var(--ink); font: inherit; box-shadow: none; min-height: 42px; }
.ts-wrapper.focus .ts-control { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.ts-wrapper .ts-control input { color: var(--ink); font: inherit; }
.ts-dropdown { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); color: var(--ink); z-index: 60; margin-top: 4px; }
.ts-dropdown .dropdown-input-wrap { padding: 8px; border-bottom: 1px solid var(--line-2); }
.ts-dropdown .dropdown-input { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); color: var(--ink); font: inherit; width: 100%; }
.ts-dropdown .ts-dropdown-content { max-height: 360px; }
.ts-dropdown .option { padding: 8px 12px; border-bottom: 1px solid var(--line-2); }
.ts-dropdown .option.active { background: var(--primary-soft); color: var(--ink); }
.ts-dropdown .highlight { background: rgba(255, 200, 40, .45); border-radius: 2px; }
.ts-opt { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; line-height: 1.4; }
.ts-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8em; font-weight: 700; color: var(--primary-text); background: var(--primary-soft); padding: 1px 6px; border-radius: 5px; white-space: nowrap; }
.ts-name { flex: 1 1 260px; min-width: 0; }
.ts-old { flex-basis: 100%; color: var(--ink-3); font-size: .78rem; }
.ts-dropdown .no-results { padding: 10px 12px; color: var(--ink-3); }

/* =====================================================================
   สไตล์ "สดใส" (ค่าเริ่มต้น) และ "ส้มคิดดี้"
   ===================================================================== */
html[data-style="vivid"] .kpi i, html[data-style="kiddee"] .kpi i { background: var(--c); background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 55%, #fff)); color: #fff; box-shadow: 0 6px 14px -6px var(--c); }
html[data-style="vivid"] .kpi .kpi-go i, html[data-style="kiddee"] .kpi .kpi-go i { background: none; box-shadow: none; color: var(--ink-3); }
html[data-style="vivid"] .kpi, html[data-style="kiddee"] .kpi { box-shadow: var(--shadow-sm); border-color: transparent; background: linear-gradient(160deg, var(--surface) 60%, var(--c-soft)); }
html[data-style="vivid"] .card, html[data-style="kiddee"] .card { box-shadow: var(--shadow-sm); }
html[data-style="vivid"] .page-head { background-image: radial-gradient(700px 240px at 100% 0%, var(--primary-soft), transparent 70%), radial-gradient(500px 200px at 0% 100%, rgba(217, 102, 28, .08), transparent 70%); }
html[data-style="vivid"] .sb-sublink > i { color: var(--primary-text); opacity: .85; }
html[data-style="vivid"] .sb-nav > .sb-group:nth-of-type(6n+1) > .sb-toggle > i:first-child { color: var(--blue); }
html[data-style="vivid"] .sb-nav > .sb-group:nth-of-type(6n+2) > .sb-toggle > i:first-child { color: var(--orange); }
html[data-style="vivid"] .sb-nav > .sb-group:nth-of-type(6n+3) > .sb-toggle > i:first-child { color: var(--green); }
html[data-style="vivid"] .sb-nav > .sb-group:nth-of-type(6n+4) > .sb-toggle > i:first-child { color: var(--violet); }
html[data-style="vivid"] .sb-nav > .sb-group:nth-of-type(6n+5) > .sb-toggle > i:first-child { color: var(--teal); }
html[data-style="vivid"] .sb-nav > .sb-group:nth-of-type(6n) > .sb-toggle > i:first-child { color: var(--rose); }
html[data-style="vivid"] .sb-nav > a.sb-link > i:first-child { color: var(--primary-text); }
html[data-style="vivid"] .md-card:hover, html[data-style="kiddee"] .md-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

/* ส้มคิดดี้: โทนส้มอบอุ่น (ถ้าผู้ใช้เลือกสีหลักเอง สีนั้นยังมีผล) */
html[data-style="kiddee"] { --primary: #d9661c; --primary-hover: #bd5514; --primary-soft: rgba(217, 102, 28, .13); --primary-text: #b4500f; }
html[data-style="kiddee"]:not([data-theme="dark"]) { --bg: #f3e9df; --surface: #fffaf5; --surface-2: #f8eee4; --sidebar-bg: #fbf2e9; --line: #ead8c6; --line-2: #f1e3d5; }
html[data-style="kiddee"][data-theme="dark"] { --primary: #f08a3e; --primary-hover: #f59d5b; --primary-soft: rgba(240, 138, 62, .17); --primary-text: #f6ab70; --bg: #17120e; --surface: #221a14; --surface-2: #2b2119; --sidebar-bg: #1b1510; --line: #3a2d22; --line-2: #2f251c; }
html[data-style="kiddee"] .page-head { background-image: radial-gradient(700px 260px at 100% 0%, rgba(240, 138, 62, .22), transparent 70%), radial-gradient(400px 200px at 0% 100%, rgba(11, 122, 75, .08), transparent 70%); }
html[data-style="kiddee"] .sb-nav i:first-child { color: var(--primary-text); }

/* =====================================================================
   น้องคิดดี้ (ผู้ช่วยมุมขวาล่าง)
   ===================================================================== */
.kd { position: fixed; right: 18px; bottom: 18px; z-index: 80; width: 72px; height: 72px; }
.kd-fab { width: 72px; height: 72px; border-radius: 50%; border: 0; padding: 0; cursor: grab; touch-action: none; user-select: none; -webkit-user-drag: none; background: radial-gradient(circle at 50% 60%, #fff 0 58%, #ffe3cc 59% 100%); box-shadow: 0 10px 24px -8px rgba(195, 87, 20, .55), 0 0 0 3px #fff; position: relative; transition: transform .2s; }
.kd-fab:hover { transform: translateY(-3px) rotate(-4deg); }
.kd-fab img { width: 64px; height: 64px; object-fit: contain; margin-top: 2px; pointer-events: none; }
.kd.is-dragging .kd-fab { cursor: grabbing; transform: scale(1.08); transition: none; box-shadow: 0 18px 36px -10px rgba(195, 87, 20, .6), 0 0 0 3px #fff; }
.kd.is-open .kd-fab { transform: scale(.92); }
.kd-x { position: absolute; top: -6px; left: -6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: #5b6876; color: #fff; display: grid; place-items: center; font-size: .8rem; cursor: pointer; padding: 0; z-index: 2; opacity: 0; transform: scale(.7); transition: opacity .15s, transform .15s; box-shadow: var(--shadow-sm); }
.kd:hover .kd-x, .kd-x:focus-visible, .kd.is-touch .kd-x { opacity: 1; transform: none; }
.kd-x:hover { background: #e5484d; }
.kd-panel, .kd-peek { position: absolute; right: 0; bottom: calc(100% + 12px); }
.kd.is-down .kd-panel, .kd.is-down .kd-peek { bottom: auto; top: calc(100% + 12px); }
.kd.is-left .kd-panel, .kd.is-left .kd-peek { right: auto; left: 0; }
.kd-hint { position: absolute; right: calc(100% + 10px); top: 50%; transform: translateY(-50%); white-space: nowrap; background: var(--ink); color: var(--surface); font-size: .76rem; padding: 4px 9px; border-radius: 8px; pointer-events: none; opacity: 0; transition: opacity .2s; }
.kd.is-left .kd-hint { right: auto; left: calc(100% + 10px); }
.kd-fab:hover + .kd-hint { opacity: .92; }
.kd.is-dragging .kd-hint, .kd.is-open .kd-hint { opacity: 0 !important; }
.kd-dot { position: absolute; top: 4px; right: 4px; width: 14px; height: 14px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 3px #fff; animation: kdPulse 1.6s infinite; }
@keyframes kdPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.25); } }
.kd-pop { animation: kdPop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes kdPop { 0% { transform: scale(.7) rotate(-8deg); } 100% { transform: scale(1) rotate(0); } }
.kd-peek { width: max-content; max-width: min(300px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 16px 16px 4px 16px; box-shadow: var(--shadow-lg); padding: 12px 34px 12px 14px; font-size: .88rem; line-height: 1.5; cursor: pointer; position: relative; animation: kdIn .3s ease; }
.kd-peek-x { position: absolute; top: 6px; right: 6px; border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 1.1rem; padding: 2px; }
@keyframes kdIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.kd-panel { width: min(380px, calc(100vw - 24px)); max-height: min(620px, calc(100vh - 120px)); display: flex; flex-direction: column; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg); overflow: hidden; animation: kdIn .25s ease; }
.kd-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 10px; background: linear-gradient(135deg, #f28a35, #d9661c); color: #fff; }
.kd-head img { width: 62px; height: 62px; object-fit: contain; background: rgba(255, 255, 255, .92); border-radius: 50%; padding: 3px; flex: none; }
.kd-head > div { flex: 1; min-width: 0; line-height: 1.25; }
.kd-head b { display: block; font-size: 1.05rem; font-family: var(--font-head); }
.kd-head small { opacity: .9; font-size: .8rem; }
.kd-head .icon-btn { color: #fff; background: rgba(255, 255, 255, .15); }
.kd-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); min-height: 120px; }
.kd-msg { max-width: 92%; align-self: flex-start; background: var(--surface); border: 1px solid var(--line-2); border-radius: 4px 16px 16px 16px; padding: 10px 12px; font-size: .88rem; line-height: 1.55; box-shadow: var(--shadow-sm); animation: kdIn .25s ease; }
.kd-msg.is-me { align-self: flex-end; background: var(--primary); color: var(--on-primary); border-color: transparent; border-radius: 16px 4px 16px 16px; }
.kd-msg b { color: var(--primary-text); }
.kd-msg.is-me b { color: inherit; }
.kd-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.kd-act { display: inline-flex; align-items: center; gap: 2px; font-size: .8rem; padding: 4px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-text); text-decoration: none; font-weight: 600; }
.kd-act:hover { background: var(--primary); color: var(--on-primary); text-decoration: none; }
.kd-items { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.kd-item { display: flex; gap: 8px; align-items: flex-start; padding: 7px 8px; border-radius: 10px; color: var(--ink); text-decoration: none; background: var(--surface-2); }
.kd-item:hover { background: var(--primary-soft); text-decoration: none; }
.kd-item i { color: var(--primary-text); margin-top: 2px; }
.kd-item span { min-width: 0; }
.kd-item b { display: block; font-weight: 600; font-size: .84rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.kd-item small { color: var(--ink-3); font-size: .76rem; }
.kd-typing { display: flex; gap: 4px; padding: 4px 2px; }
.kd-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: kdDot 1s infinite; }
.kd-typing i:nth-child(2) { animation-delay: .15s; } .kd-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes kdDot { 0%, 100% { opacity: .3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }
.kd-quick { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 0; scrollbar-width: none; }
.kd-quick button { flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: .8rem; cursor: pointer; }
.kd-quick button:hover { border-color: var(--primary); color: var(--primary-text); }
.kd-ask { display: flex; gap: 8px; padding: 10px 12px; }
.kd-ask input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; background: var(--surface-2); color: var(--ink); font: inherit; font-size: .9rem; }
.kd-ask input:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.kd-ask .btn { border-radius: 50%; width: 40px; height: 40px; padding: 0; display: grid; place-items: center; }
.kd-note { margin: 0; padding: 0 14px 10px; font-size: .72rem; color: var(--ink-3); }
@media (max-width: 600px) {
  .kd { right: 10px; bottom: 10px; width: 58px; height: 58px; }
  .kd-fab { width: 58px; height: 58px; }
  .kd-fab img { width: 52px; height: 52px; }
  .kd-panel { max-height: calc(100vh - 100px); }
}
@media print { .kd { display: none !important; } }
.kd-quick, .kd-ask, .kd-note, .kd-head { flex: none; }

/* v1.16.1 — แบ่งหน้า · เลือกหลายหมวด · ลำดับในหมวด */
.pager { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; padding: 14px 4px 2px; border-top: 1px solid var(--line-2); margin-top: 6px; font-size: .86rem; color: var(--ink-3); }
.pager:empty { display: none; }
.pager-flat { border-top: 0; margin-bottom: 20px; }
.pg-info b { color: var(--ink); }
.pg-nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pg-btn { min-width: 36px; height: 36px; padding: 0 9px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font: inherit; font-size: .86rem; cursor: pointer; display: inline-grid; place-items: center; }
.pg-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary-text); }
.pg-btn.is-on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.pg-btn:disabled { opacity: .4; cursor: default; }
.pg-gap { padding: 0 2px; }
.pg-size { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pg-size select { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: var(--surface); color: var(--ink); font: inherit; }
.fw-pick { margin-bottom: 16px; }
.fw-pick .fw-chips { margin-bottom: 0; }
.fw-pick-hint { display: flex; gap: 6px; align-items: flex-start; font-size: .82rem; color: var(--ink-3); margin-bottom: 8px; }
.fw-pick-hint i { color: var(--primary-text); margin-top: 2px; }
.fw-pick-hint b { color: var(--ink-2); font-weight: 600; }
.rank-col { width: 64px; }
.rank { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 8px; background: var(--primary-soft); color: var(--primary-text); font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 700px) { .pager { justify-content: center; } .pg-info { width: 100%; text-align: center; } }

/* v1.17 — ภาพมุมสูงของโรงพยาบาลเป็นพื้นหลังหัวหน้า (ชิดขวา จางไปทางซ้าย) — เปลี่ยนภาพได้ที่ assets/img/hospital-hero.jpg */
.page-head, .hero { position: relative; overflow: hidden; isolation: isolate; }
.page-head::before, .hero::before {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: min(62%, 900px); z-index: -1; pointer-events: none;
  background: url("../img/hospital-hero.jpg") right center / cover no-repeat;
  opacity: .5; filter: saturate(1.05);
  -webkit-mask-image: linear-gradient(to left, #000 0%, rgba(0,0,0,.75) 35%, transparent 100%);
          mask-image: linear-gradient(to left, #000 0%, rgba(0,0,0,.75) 35%, transparent 100%);
}
.hero::before { width: 100%; opacity: .22; -webkit-mask-image: linear-gradient(to bottom, #000, transparent 95%); mask-image: linear-gradient(to bottom, #000, transparent 95%); }
html[data-theme="dark"] .page-head::before { opacity: .28; filter: saturate(.8) brightness(.8); }
html[data-theme="dark"] .hero::before { opacity: .14; }
.page-head > .container { position: relative; }
@media (max-width: 700px) { .page-head::before { width: 100%; opacity: .22; } }
@media print { .page-head::before, .hero::before { display: none; } }

/* สลับมุมมองหน้าแรก: มาตรฐาน / Digital Twin */
.home-viewswitch { display: inline-flex; align-items: center; gap: 2px; margin-top: 14px; padding: 3px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.home-viewswitch > span { padding: 0 8px 0 10px; font-size: .8rem; color: var(--ink-3); display: inline-flex; gap: 5px; }
.home-viewswitch a { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; color: var(--ink-2); font-size: .84rem; font-weight: 600; text-decoration: none; }
.home-viewswitch a.is-on { background: var(--primary); color: #fff; }
.home-viewswitch a:not(.is-on):hover { background: var(--primary-soft); color: var(--ink); }

/* ---------- เอกสารคุณภาพ (v1.25 — รวม Q-DOC) ---------- */
.doc-cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 10px; margin-bottom: 14px; }
.doc-cat { position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 12px 14px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); overflow: hidden; transition: border-color .15s, transform .15s, box-shadow .15s; }
.doc-cat:hover { text-decoration: none; border-color: var(--c); transform: translateY(-1px); box-shadow: var(--shadow-sm, 0 2px 8px rgba(0,0,0,.06)); color: var(--ink); }
.doc-cat i { grid-row: 1 / 3; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--c-soft); color: var(--c); font-size: 1.1rem; font-style: normal; }
.doc-cat span { font-size: .82rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-cat b { font-family: var(--font-head); font-size: 1.35rem; line-height: 1.15; color: var(--ink); }
.doc-cat.is-on { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); background: color-mix(in srgb, var(--c-soft) 45%, var(--surface)); }
.doc-cat.is-total i { background: var(--c); color: #fff; }
.doc-subtabs { margin: 0 0 14px; }
.doc-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.doc-filter .search-sm { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; color: var(--ink-3); }
.doc-filter .search-sm:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.doc-filter .search-sm input { border: 0; outline: none; font: inherit; padding: 10px 0; flex: 1; background: none; min-width: 0; color: var(--ink); }
.doc-filter select.input { width: auto; max-width: 240px; padding-top: 9px; padding-bottom: 9px; }
.doc-more { position: relative; }
.doc-more summary { list-style: none; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink-2); font-size: .9rem; }
.doc-more summary::-webkit-details-marker { display: none; }
.doc-more[open] summary { border-color: var(--primary); color: var(--primary-text); }
.doc-more > div { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.doc-more label { display: inline-flex; gap: 6px; align-items: center; font-size: .85rem; color: var(--ink-2); }
.doc-more input { width: auto; }
.doc-count { margin: 6px 0 10px; font-size: .86rem; color: var(--ink-3); min-height: 1em; }
.doc-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); align-items: start; }
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: var(--surface-2); }
.doc-row.is-off { opacity: .6; }
.doc-row .doc-ico { background: var(--c-soft); color: var(--c); }
.doc-row .doc-title .code { margin-right: 2px; vertical-align: 1px; }
.doc-row .doc-meta i { margin-right: 2px; }
.doc-desc { margin: 4px 0 0; font-size: .84rem; color: var(--ink-2); }
.doc-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; min-width: 150px; }
.doc-fbtn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 10px; background: var(--primary); color: var(--on-primary); font-size: .84rem; font-weight: 600; white-space: nowrap; }
.doc-fbtn:hover { text-decoration: none; background: var(--primary-hover); color: var(--on-primary); }
.doc-fbtn.is-old { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); font-weight: 500; padding: 3px 9px; font-size: .78rem; }
.doc-fbtn.is-old:hover { border-color: var(--primary); color: var(--primary-text); background: var(--surface); }
.doc-acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.doc-hist { margin-top: 6px; font-size: .82rem; }
.doc-hist summary { cursor: pointer; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; }
.doc-hist ul { list-style: none; margin: 6px 0 0; padding: 8px 10px; border-left: 3px solid var(--line); background: var(--surface-2); border-radius: 0 10px 10px 0; display: grid; gap: 6px; }
.doc-hist li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--ink-2); }
.small { font-size: .82rem; }
.narrow-form { max-width: 920px; }
.doc-note { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 14px; background: var(--green-soft); border: 1px solid color-mix(in srgb, var(--green) 30%, transparent); margin-bottom: 16px; font-size: .9rem; }
.doc-note > i { font-size: 1.3rem; color: var(--green); }
.doc-note.is-soft { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 25%, transparent); }
.doc-note.is-soft > i { color: var(--blue); }
.doc-files-box { border: 1px dashed var(--line); border-radius: 14px; padding: 14px 16px 2px; margin: 4px 0 18px; }
.doc-files-box legend { padding: 0 6px; font-weight: 600; font-size: .92rem; }
.doc-curfiles { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.doc-curfiles li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.doc-curfiles .check { margin: 0 0 0 auto; font-size: .84rem; }
.doc-danger { display: flex; justify-content: space-between; align-items: center; gap: 16px; border-color: color-mix(in srgb, var(--rose) 30%, var(--line)); }
.doc-danger p { margin: 2px 0 0; }
@media (max-width: 760px) {
  .doc-cats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .doc-cat { padding: 10px; }
  .doc-cat i { width: 32px; height: 32px; font-size: .95rem; }
  .doc-row { grid-template-columns: auto minmax(0, 1fr); padding: 12px 14px; }
  .doc-side { grid-column: 2; align-items: flex-start; min-width: 0; flex-direction: row; flex-wrap: wrap; }
  .doc-filter select.input { flex: 1 1 140px; max-width: none; }
}
.steps-list { margin: 0 0 16px; padding-left: 22px; display: grid; gap: 6px; color: var(--ink-2); font-size: .92rem; }
.h-sm { font-size: .98rem; margin: 20px 0 10px; }
.chips-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-wrap .pill { font-size: .8rem; padding: 4px 10px; }
.import-opts { margin-top: 18px; }

/* ---------- หน้าแรกแบบกระชับ (v1.26) ---------- */
.tb-viewswitch { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); margin-right: 4px; }
.tb-viewswitch a { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; color: var(--ink-2); font-size: .82rem; font-weight: 600; white-space: nowrap; }
.tb-viewswitch a:hover { color: var(--ink); text-decoration: none; background: var(--surface); }
.tb-viewswitch a.is-on { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-sm); }
@media (max-width: 1100px) { .tb-viewswitch a span { display: none; } .tb-viewswitch a { padding: 0 10px; } }
.hero.hero-compact { padding: 30px 0 34px; }
.hero-compact h1 { font-size: clamp(1.45rem, 2.8vw, 2.1rem); margin-bottom: 6px; }
.hero-compact .lead { font-size: .95rem; margin-bottom: 16px; }
.hero-compact .search-xl { box-shadow: var(--shadow); }
.home-main { padding: 28px 0 8px; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 24px; align-items: start; }
.home-grid.is-full { grid-template-columns: minmax(0, 1fr); }
.home-apps .sec-head { margin-bottom: 12px; }
.home-apps .sec-head h2 { font-size: 1.35rem; }
.home-apps .apps-view-cover .app-tiles { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 16px; }
.home-side { position: sticky; top: calc(var(--topbar-h) + 16px); display: grid; gap: 14px; }
.side-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 10px; }
.side-card h3 { font-size: .9rem; margin: 0 0 8px; display: flex; gap: 6px; align-items: center; color: var(--ink-2); }
.side-card .more { display: inline-flex; gap: 4px; align-items: center; font-size: .84rem; margin: 6px 0 2px; }
.home-mykpi-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.mstat { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; padding: 9px 0; border-top: 1px solid var(--line-2); }
.mstat:first-of-type { border-top: 0; }
.mstat-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--c-soft); color: var(--c); font-style: normal; font-size: .95rem; }
.mstat-body { min-width: 0; display: flex; flex-direction: column; }
.mstat-label { font-size: .78rem; color: var(--ink-2); line-height: 1.3; }
.mstat-value { font-family: var(--font-head); font-size: 1.25rem; font-weight: 700; line-height: 1.25; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
.mstat-value small { font-size: .78rem; font-weight: 500; color: var(--ink-3); }
.mstat-value em { margin-left: auto; font-family: var(--font-body, inherit); font-style: normal; font-size: .72rem; font-weight: 500; }
.mstat .bar { height: 4px; margin: 4px 0 3px; }
.mstat-foot { font-size: .72rem; color: var(--ink-3); }
@media (max-width: 1100px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .home-side { position: static; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); column-gap: 16px; }
  .mini-stats h3 { grid-column: 1 / -1; }
  .mini-stats .mstat { border-top: 1px solid var(--line-2); }
}
@media (max-width: 760px) {
  .hero.hero-compact { padding: 20px 0 22px; }
  .hero-compact .lead { display: none; }
  .home-main { padding-top: 18px; }
}
