/* ==========================================================================
   SMIS-Q — Design System 5-Star Premium Pro
   ไฟล์เดียวใช้ทั้งหน้าสาธารณะและหลังบ้าน
   (กันบทเรียน #5: component class ที่ใช้ร่วมต้องมีในทุก stylesheet ที่หน้านั้นโหลด)
   ========================================================================== */

/* ── 1. Tokens ─────────────────────────────────────────────────────────── */
:root {
  /* Brand scale — ถูก override โดย theme_style_tag() ตามชุดสีที่ผู้ดูแลเลือก */
  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-300: #a5b4fc;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-800: #3730a3;
  --brand-900: #312e81;
  --brand-950: #1e1b4b;

  /* Accent หรู (ทอง) — แกนร่วมทุกชุดสี */
  --gold-200: #fde68a;
  --gold-400: #fbbf24;
  --gold-600: #d97706;

  /* Semantic */
  --ok-50:  #ecfdf5;  --ok-500:  #10b981; --ok-700:  #047857;
  --warn-50:#fffbeb;  --warn-500:#f59e0b; --warn-700:#b45309;
  --bad-50: #fef2f2;  --bad-500: #ef4444; --bad-700: #b91c1c;
  --info-50:#eff6ff;  --info-500:#3b82f6; --info-700:#1d4ed8;

  /* Surfaces */
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --surface-3:   #f1f5f9;
  --line:        #e2e8f0;
  --line-strong: #cbd5e1;

  /* Ink */
  --ink:       #0f172a;
  --ink-2:     #334155;
  --ink-muted: #64748b;
  --ink-faint: #94a3b8;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(15,23,42,.05);
  --shadow-sm: 0 2px 8px rgba(15,23,42,.06);
  --shadow-md: 0 8px 24px rgba(15,23,42,.08);
  --shadow-lg: 0 18px 44px rgba(15,23,42,.12);
  --shadow-brand: 0 8px 24px rgba(79,70,229,.22);

  /* Shape + motion */
  --r-sm: 10px; --r: 14px; --r-lg: 18px; --r-xl: 24px; --r-full: 999px;
  --ease: cubic-bezier(.22,.61,.36,1);
  --t: .28s var(--ease);

  --nav-h: 66px;
  --side-w: 274px;

  --font-display: 'Kanit', system-ui, -apple-system, sans-serif;
  --font-body: 'Sarabun', 'Kanit', system-ui, -apple-system, sans-serif;

  /* ── ทฤษฎีสี 60-30-10 ────────────────────────────────────────────────
     60% พื้นกลาง  — พื้นหลังหน้า พื้นการ์ด เส้นคั่น (ตาพัก ไม่ล้า)
     30% สีแบรนด์  — ฮีโร่ หัวข้อ ไอคอน แถบข้อมูล (บอกว่าเป็นระบบอะไร)
     10% สีเน้นทอง — ปุ่มหลัก ตัวเลขสำคัญ ป้ายไฮไลท์ (ใช้น้อย จึงสะดุดตา)

     กติกาใช้งาน: พื้นหลังใหญ่ห้ามใช้ --c10 · ปุ่มหลักของแต่ละหน้าจอมีได้ 1 ปุ่มที่ใช้ --c10
     เปลี่ยนชุดสีจากหลังบ้านแล้วทั้งสามระดับขยับตามอัตโนมัติ เพราะอิง --brand-* / --gold-* */
  --c60:        var(--bg);           /* พื้นหลักของหน้า */
  --c60-raise:  var(--surface);      /* พื้นการ์ดที่ลอยขึ้นมา */
  --c60-sink:   var(--surface-2);    /* พื้นที่จมลงไป เช่นแถบกราฟ */
  --c30:        var(--brand-600);    /* สีแบรนด์หลัก */
  --c30-deep:   var(--brand-900);    /* แบรนด์เข้ม ใช้กับพื้นมืด */
  --c30-soft:   var(--brand-300);    /* แบรนด์อ่อน ใช้กับเส้น/ไอคอนรอง */
  --c30-wash:   var(--brand-50);     /* แบรนด์จาง ใช้เป็นพื้นเน้นบาง ๆ */
  --c10:        var(--gold-400);     /* สีเน้น — ใช้ ≤10% ของพื้นที่ */
  --c10-deep:   var(--gold-600);
  --c10-soft:   var(--gold-200);
}

/* ── 2. Reset + base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink-2);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.35;
  margin: 0 0 .6em;
  font-weight: 600;
}

a { color: var(--brand-700); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--brand-500); }

img, svg { max-width: 100%; height: auto; }

p { margin: 0 0 1em; }

hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

::selection { background: var(--brand-200); color: var(--brand-950); }

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

.tabular { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── 3. Layout primitives ──────────────────────────────────────────────── */
.container { width: min(1240px, 100% - 40px); margin-inline: auto; }
.container-wide { width: min(1560px, 100% - 40px); margin-inline: auto; }

.stack > * + * { margin-top: 18px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.muted { color: var(--ink-muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

.grid { display: grid; gap: 16px; }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid-auto-sm { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 980px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .container, .container-wide { width: calc(100% - 28px); }
}

/* ── 4. Card ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-pad { padding: 22px 24px; }
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}
.card-head h2, .card-head h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 9px; }
.card-head .grow { min-width: 120px; }
.card-body { padding: 22px 24px; }
.card-foot {
  padding: 14px 24px; border-top: 1px solid var(--line);
  background: var(--surface-2); display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}

@media (max-width: 620px) {
  .card-pad, .card-body { padding: 18px 16px; }
  .card-head, .card-foot { padding: 14px 16px; }
}

/* ── 5. Hero + KPI strip ───────────────────────────────────────────────── */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-xl);
  padding: 30px 32px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-800), var(--brand-600) 55%, var(--brand-500));
  box-shadow: var(--shadow-lg);
  margin-bottom: 22px;
}
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(900px 240px at 8% -30%, rgba(255,255,255,.30), transparent 70%),
    radial-gradient(600px 200px at 100% 120%, rgba(251,191,36,.22), transparent 70%);
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -70px; width: 300px; height: 300px;
  border-radius: 50%; border: 34px solid rgba(255,255,255,.07); pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.22);
  padding: 5px 13px; border-radius: var(--r-full); margin-bottom: 12px;
  backdrop-filter: blur(8px);
}
.hero h1 { color: #fff; font-size: clamp(22px, 3vw, 31px); margin: 0 0 6px; font-weight: 700; }
.hero p { color: rgba(255,255,255,.86); margin: 0; max-width: 68ch; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.kpi-strip {
  display: grid; gap: 14px; margin-top: 24px;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
}
.kpi {
  background: rgba(255,255,255,.13);
  border: 1px solid rgba(255,255,255,.20);
  border-radius: var(--r);
  padding: 14px 16px;
  backdrop-filter: blur(12px);
  transition: transform var(--t), background var(--t);
}
.kpi:hover { transform: translateY(-3px); background: rgba(255,255,255,.19); }
.kpi-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: rgba(255,255,255,.80); margin-bottom: 4px; font-weight: 500;
}
.kpi-value {
  font-family: var(--font-display); font-weight: 700; font-size: 27px;
  color: #fff; line-height: 1.15; font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: 12px; color: rgba(255,255,255,.72); margin-top: 2px; }

@media (max-width: 620px) {
  .hero { padding: 22px 18px; border-radius: var(--r-lg); }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-value { font-size: 22px; }
}

/* ── 6. Stat cards (glass) ─────────────────────────────────────────────── */
.stat-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.stat {
  position: relative; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t), box-shadow var(--t);
}
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--stat-accent, var(--brand-500));
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-ico {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  font-size: 19px; color: #fff; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--stat-accent, var(--brand-500)), var(--stat-accent-2, var(--brand-700)));
  box-shadow: 0 6px 16px rgba(15,23,42,.14);
}
.stat-label { font-size: 13px; color: var(--ink-muted); font-weight: 500; }
.stat-value {
  font-family: var(--font-display); font-weight: 700; font-size: 30px;
  color: var(--ink); line-height: 1.15; margin-top: 6px; font-variant-numeric: tabular-nums;
}
.stat-foot { font-size: 12.5px; color: var(--ink-muted); margin-top: 4px; display: flex; align-items: center; gap: 5px; }
.stat-delta { font-weight: 600; }
.stat-delta.up { color: var(--ok-700); }
.stat-delta.down { color: var(--bad-700); }

/* ── 7. Buttons ────────────────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--brand-600);
  --btn-bg2: var(--brand-700);
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display); font-weight: 500; font-size: 14.5px;
  padding: 10px 18px; min-height: 44px;
  border: 1px solid transparent; border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--btn-bg), var(--btn-bg2));
  color: #fff; cursor: pointer; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(15,23,42,.14);
  transition: transform var(--t), box-shadow var(--t), background var(--t), color var(--t);
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(15,23,42,.18); color: #fff; }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; pointer-events: none; }

.btn-ghost {
  background: var(--surface); color: var(--ink-2);
  border-color: var(--line-strong); box-shadow: var(--shadow-xs);
}
.btn-ghost:hover { color: var(--brand-700); border-color: var(--brand-300); background: var(--brand-50); }

.btn-soft {
  background: var(--brand-50); color: var(--brand-700);
  border-color: var(--brand-200); box-shadow: none;
}
.btn-soft:hover { background: var(--brand-100); color: var(--brand-800); }

.btn-danger { --btn-bg: #f43f5e; --btn-bg2: #be123c; }
.btn-ok     { --btn-bg: #10b981; --btn-bg2: #047857; }
.btn-warn   { --btn-bg: #f59e0b; --btn-bg2: #b45309; }
.btn-gold   { --btn-bg: var(--gold-400); --btn-bg2: var(--gold-600); color: #451a03; }
.btn-gold:hover { color: #451a03; }

.btn-sm { padding: 6px 13px; min-height: 36px; font-size: 13px; }
.btn-lg { padding: 13px 26px; min-height: 52px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; min-height: 40px; padding: 0; border-radius: 12px; }

/* ripple */
.btn .ripple {
  position: absolute; border-radius: 50%; transform: scale(0);
  background: rgba(255,255,255,.45); pointer-events: none;
  animation: ripple .6s var(--ease);
}
@keyframes ripple { to { transform: scale(2.6); opacity: 0; } }

.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ── 8. Multi-state submit ─────────────────────────────────────────────── */
.submit-btn { position: relative; overflow: hidden; min-width: 170px; }
.submit-btn[data-state] { pointer-events: none; }
.submit-state { display: none; align-items: center; justify-content: center; gap: 8px; }
.submit-btn:not([data-state]) .submit-state-default,
.submit-btn[data-state="loading"] .submit-state-loading,
.submit-btn[data-state="success"] .submit-state-success,
.submit-btn[data-state="error"]   .submit-state-error { display: inline-flex; }
.submit-btn[data-state="loading"] { --btn-bg: #334155; --btn-bg2: #0f172a; }
.submit-btn[data-state="success"] { --btn-bg: #10b981; --btn-bg2: #047857; }
.submit-btn[data-state="error"]   { --btn-bg: #f43f5e; --btn-bg2: #be123c; animation: shake .5s; }

.dots { display: inline-flex; gap: 4px; }
.dots span {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: bounce 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: .18s; }
.dots span:nth-child(3) { animation-delay: .36s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: .55; } 30% { transform: translateY(-5px); opacity: 1; } }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-7px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
}

/* ── 9. Forms ──────────────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-full { grid-column: 1 / -1; }
.field > label, .label {
  font-family: var(--font-display); font-size: 13.5px; font-weight: 500; color: var(--ink-2);
  display: flex; align-items: center; gap: 6px;
}
.field .req { color: var(--bad-500); }
.field .hint { font-size: 12.5px; color: var(--ink-muted); }

.input, .field input[type="text"], .field input[type="password"], .field input[type="number"],
.field input[type="date"], .field input[type="email"], .field input[type="url"],
.field input[type="search"], .field input[type="tel"], .field select, .field textarea {
  width: 100%;
  font-family: var(--font-body); font-size: 15px; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 11px 13px; min-height: 46px;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
.field textarea { min-height: 108px; resize: vertical; line-height: 1.7; }

.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand-400);
  box-shadow: 0 0 0 4px var(--brand-100);
}
.input:disabled, .field input:disabled, .field select:disabled, .field textarea:disabled {
  background: var(--surface-3); color: var(--ink-muted); cursor: not-allowed;
}
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; padding-right: 38px;
}

.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad-500); }
.field.has-error input:focus, .field.has-error select:focus { box-shadow: 0 0 0 4px var(--bad-50); }
.field-error { font-size: 12.5px; color: var(--bad-700); display: flex; align-items: center; gap: 5px; }

.check {
  display: inline-flex; align-items: center; gap: 9px; cursor: pointer;
  padding: 9px 13px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); min-height: 44px; font-size: 14.5px;
  transition: all var(--t);
}
.check input { width: 18px; height: 18px; accent-color: var(--brand-600); cursor: pointer; }
.check:has(input:checked) { border-color: var(--brand-400); background: var(--brand-50); color: var(--brand-800); }

.switch-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* toolbar */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-full); padding: 10px 14px; box-shadow: var(--shadow-xs);
  margin-bottom: 18px;
}
.toolbar .field { flex-direction: row; align-items: center; gap: 7px; }
.toolbar .field > label { white-space: nowrap; font-size: 13px; color: var(--ink-muted); }
.toolbar .input, .toolbar select, .toolbar input { min-height: 40px; padding: 7px 12px; border-radius: var(--r-full); font-size: 14px; }
.toolbar select { padding-right: 34px; }

.search-wrap { position: relative; flex: 1 1 220px; min-width: 160px; }
.search-wrap i {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--ink-faint); pointer-events: none; font-size: 15px;
}
.search-wrap input { padding-left: 38px !important; }

.chip-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; min-height: 38px; border-radius: var(--r-full);
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 13.5px; color: var(--ink-2); cursor: pointer; white-space: nowrap;
  transition: all var(--t); text-decoration: none;
}
.chip:hover { border-color: var(--brand-300); color: var(--brand-700); }
.chip.is-active {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-700));
  border-color: transparent; color: #fff; box-shadow: var(--shadow-brand);
}
.chip.is-active:hover { color: #fff; }

@media (max-width: 620px) {
  .toolbar { border-radius: var(--r-lg); }
}

/* ── 10. Badges + pills ────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 11px; border-radius: var(--r-full);
  font-size: 12.5px; font-weight: 600; font-family: var(--font-display);
  background: var(--surface-3); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge-ok   { background: var(--ok-50);   color: var(--ok-700);   border-color: #a7f3d0; }
.badge-warn { background: var(--warn-50); color: var(--warn-700); border-color: #fde68a; }
.badge-bad  { background: var(--bad-50);  color: var(--bad-700);  border-color: #fecaca; }
.badge-info { background: var(--info-50); color: var(--info-700); border-color: #bfdbfe; }
.badge-brand{ background: var(--brand-50);color: var(--brand-700);border-color: var(--brand-200); }

/* สีพัฒนาการ 5 ระดับ */
.color-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dev-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--r-full);
  font-family: var(--font-display); font-weight: 600; font-size: 12.5px;
  border: 1px solid; white-space: nowrap;
}
.dev-purple { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.dev-blue   { background: #f0f9ff; color: #0369a1; border-color: #bae6fd; }
.dev-green  { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.dev-yellow { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.dev-red    { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

.role-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 11px; border-radius: var(--r-full);
  font-family: var(--font-display); font-weight: 600; font-size: 12px;
  border: 1px solid transparent;
}
.role-chip-admin  { background: linear-gradient(135deg, var(--gold-200), var(--gold-400)); color: #78350f; }
.role-chip-member { background: linear-gradient(135deg, #a7f3d0, #34d399); color: #065f46; }

/* ── 11. Tables → Card grid บนมือถือ ───────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); }
.table {
  width: 100%; border-collapse: collapse; font-size: 14.5px; background: var(--surface);
}
.table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  font-family: var(--font-display); font-weight: 600; font-size: 13px;
  color: var(--ink-muted); text-align: left; white-space: nowrap;
  padding: 12px 14px; border-bottom: 2px solid var(--line);
}
.table tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background var(--t); }
.table tbody tr:hover { background: var(--brand-50); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { white-space: nowrap; text-align: right; }

@media (max-width: 820px) {
  .table thead { display: none; }
  .table, .table tbody { display: block; }
  .table tbody tr {
    display: block; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r); margin-bottom: 12px; padding: 6px 14px; box-shadow: var(--shadow-xs);
  }
  .table tbody td {
    display: flex; justify-content: space-between; gap: 14px; align-items: center;
    padding: 9px 0; border-bottom: 1px dashed var(--line); text-align: right;
  }
  .table tbody td::before {
    content: attr(data-label);
    font-family: var(--font-display); font-weight: 600; font-size: 12.5px;
    color: var(--ink-muted); text-align: left; flex: 0 0 auto;
  }
  .table tbody td:last-child { border-bottom: 0; }
  .table .actions { justify-content: flex-end; }
}

/* ── 12. Entity cards ──────────────────────────────────────────────────── */
.ent-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.ent {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column; gap: 12px;
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}
.ent:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--brand-200); }
.ent-head { display: flex; gap: 12px; align-items: flex-start; }
.ent-avatar {
  width: 46px; height: 46px; border-radius: 13px; flex: 0 0 auto;
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 17px;
  background: linear-gradient(135deg, var(--brand-100), var(--brand-200)); color: var(--brand-800);
  overflow: hidden;
}
.ent-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ent-title { font-family: var(--font-display); font-weight: 600; font-size: 15.5px; color: var(--ink); line-height: 1.4; }
.ent-sub { font-size: 13px; color: var(--ink-muted); }
.ent-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ent-metric { background: var(--surface-2); border-radius: var(--r-sm); padding: 9px 10px; text-align: center; }
.ent-metric b { display: block; font-family: var(--font-display); font-size: 16px; color: var(--ink); font-variant-numeric: tabular-nums; }
.ent-metric span { font-size: 11.5px; color: var(--ink-muted); }
.ent-foot { display: flex; gap: 7px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }

/* ── 13. Progress ──────────────────────────────────────────────────────── */
.bar { height: 9px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.bar > i {
  display: block; height: 100%; border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--brand-400), var(--brand-600));
  position: relative; transition: width .8s var(--ease);
}
.bar > i::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
  animation: shimmer 2.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.bar.ok > i   { background: linear-gradient(90deg, #34d399, #059669); }
.bar.warn > i { background: linear-gradient(90deg, #fbbf24, #d97706); }
.bar.bad > i  { background: linear-gradient(90deg, #fb7185, #be123c); }

/* ── 14. Empty / alert ─────────────────────────────────────────────────── */
.empty {
  text-align: center; padding: 54px 24px; color: var(--ink-muted);
}
.empty-ico {
  width: 76px; height: 76px; border-radius: 24px; margin: 0 auto 16px;
  display: grid; place-items: center; font-size: 32px;
  background: linear-gradient(135deg, var(--brand-50), var(--brand-100)); color: var(--brand-500);
}
.empty h3 { font-size: 17px; margin-bottom: 6px; color: var(--ink-2); }
.empty p { max-width: 46ch; margin: 0 auto 18px; font-size: 14px; }

.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 15px 18px; border-radius: var(--r); border: 1px solid;
  font-size: 14.5px; margin-bottom: 18px;
}
.alert i { font-size: 19px; flex: 0 0 auto; margin-top: 1px; }
.alert-info { background: var(--info-50); border-color: #bfdbfe; color: #1e40af; }
.alert-ok   { background: var(--ok-50);   border-color: #a7f3d0; color: #065f46; }
.alert-warn { background: var(--warn-50); border-color: #fde68a; color: #92400e; }
.alert-bad  { background: var(--bad-50);  border-color: #fecaca; color: #991b1b; }
.alert b { font-family: var(--font-display); }

/* ── 15. Skeleton ──────────────────────────────────────────────────────── */
.skel {
  background: linear-gradient(90deg, var(--surface-3) 25%, #e9eef5 37%, var(--surface-3) 63%);
  background-size: 400% 100%; animation: skel 1.4s ease infinite; border-radius: var(--r-sm);
}
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skel-line { height: 13px; margin-bottom: 9px; }
.skel-card { height: 118px; border-radius: var(--r-lg); }

/* ── 16. Panel shell (navbar + sidebar) ────────────────────────────────── */
body.panel { background: var(--bg); }

.shell { display: flex; min-height: 100dvh; }

.side {
  width: var(--side-w); flex: 0 0 var(--side-w);
  background: linear-gradient(180deg, var(--brand-950), #0b1020);
  color: #cbd5e1; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100dvh; overflow-y: auto; z-index: 40;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent;
}
.side::-webkit-scrollbar { width: 6px; }
.side::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 3px; }

.side-head { padding: 18px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side-brand { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.side-logo {
  width: 44px; height: 44px; border-radius: 13px; flex: 0 0 auto;
  display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  box-shadow: 0 0 0 3px rgba(255,255,255,.08), 0 8px 20px rgba(79,70,229,.42);
}
.side-logo img { width: 78%; height: 78%; object-fit: contain; }
.side-name { font-family: var(--font-display); font-weight: 700; font-size: 17px; color: #fff; line-height: 1.2; }
.side-org { font-size: 11.5px; color: #94a3b8; }

.side-clock {
  margin: 12px 0 0; padding: 11px 13px; border-radius: var(--r);
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.09);
  backdrop-filter: blur(8px); text-align: center;
}
.side-time {
  font-family: var(--font-display); font-weight: 700; font-size: 21px; color: #fff;
  font-variant-numeric: tabular-nums; letter-spacing: .04em;
  text-shadow: 0 0 18px rgba(129,140,248,.55);
}
.side-date { font-size: 11.5px; color: #94a3b8; margin-top: 1px; }

.side-user {
  margin: 10px 0 0; padding: 11px 12px; border-radius: var(--r);
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.09);
  display: flex; align-items: center; gap: 10px;
}
.side-avatar {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 14px;
  background: linear-gradient(135deg, var(--brand-300), var(--brand-500)); color: #fff;
}
.side-user-name {
  font-family: var(--font-display); font-size: 13.5px; color: #fff; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.side-nav { padding: 12px 10px 26px; flex: 1 1 auto; }
.side-section {
  display: flex; align-items: center; gap: 7px;
  font-family: var(--font-display); font-size: 10.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: #64748b;
  padding: 16px 10px 7px;
}
.side-section::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--brand-400); box-shadow: 0 0 9px var(--brand-400);
}
.sb-link {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; margin-bottom: 2px; border-radius: 11px;
  color: #cbd5e1; font-size: 14.2px; text-decoration: none; min-height: 44px;
  transition: background var(--t), color var(--t);
}
.sb-link > i:first-child { font-size: 16px; width: 20px; text-align: center; flex: 0 0 auto; opacity: .9; }
.sb-link .tx { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sb-link.is-active {
  background: linear-gradient(90deg, rgba(99,102,241,.30), rgba(99,102,241,.06));
  color: #fff; box-shadow: inset 0 0 0 1px rgba(129,140,248,.24);
}
.sb-link.is-active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, var(--brand-300), var(--brand-500));
  box-shadow: 0 0 12px var(--brand-400);
}

/* count badges */
.sb-link .cnt {
  margin-left: auto; flex: 0 0 auto; min-width: 26px; text-align: center;
  font-family: var(--font-display); font-weight: 600; font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 1px 8px; border-radius: var(--r-full);
  background: rgba(255,255,255,.10); color: #e2e8f0; border: 1px solid rgba(255,255,255,.09);
}
.sb-link .cnt-warn {
  position: relative;
  background: rgba(251,191,36,.18); color: var(--gold-200); border-color: rgba(251,191,36,.32);
}
.sb-link .cnt-warn::after {
  content: ""; position: absolute; top: -2px; right: -2px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--gold-400); animation: pulseDot 2.2s ease-out infinite;
}
.sb-link .cnt-ok { background: rgba(16,185,129,.18); color: #6ee7b7; border-color: rgba(16,185,129,.30); }
.sb-link .cnt-zero { background: rgba(255,255,255,.05); color: #64748b; border-color: transparent; }
.sb-link .cnt-zero::after { display: none; }
@keyframes pulseDot {
  0% { transform: scale(1); opacity: 1; }
  70% { transform: scale(2.1); opacity: 0; }
  100% { transform: scale(2.1); opacity: 0; }
}

/* main column */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  min-height: var(--nav-h);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 22px;
  background: rgba(255,255,255,.86); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-ico {
  width: 42px; height: 42px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 18px; color: #fff;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  box-shadow: var(--shadow-brand);
}
.topbar-title { font-family: var(--font-display); font-weight: 600; font-size: 16.5px; color: var(--ink); line-height: 1.25; }
.topbar-sub { font-size: 12.5px; color: var(--ink-muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px; border-radius: var(--r-full);
  background: var(--surface); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink-muted); white-space: nowrap;
}
.pill-live .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok-500);
  box-shadow: 0 0 0 0 rgba(16,185,129,.6); animation: live 2s infinite;
}
@keyframes live {
  0% { box-shadow: 0 0 0 0 rgba(16,185,129,.55); }
  70% { box-shadow: 0 0 0 8px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

.menu-btn { display: none; }

/* profile dropdown */
.pop-wrap { position: relative; }
.pop {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 60;
  min-width: 250px; padding: 8px;
  background: rgba(255,255,255,.97); backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden; transform: translateY(-8px) scale(.97);
  transform-origin: top right; transition: all .22s var(--ease);
}
.pop.is-open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.pop-head { padding: 12px 13px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.pop-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 13px; border-radius: 10px; min-height: 44px;
  color: var(--ink-2); font-size: 14px; text-decoration: none;
  background: none; border: 0; width: 100%; cursor: pointer; font-family: var(--font-body);
  transition: background var(--t), color var(--t);
}
.pop-item:hover { background: var(--brand-50); color: var(--brand-700); }
.pop-item.danger:hover { background: var(--bad-50); color: var(--bad-700); }

.content { flex: 1 1 auto; padding: 22px; min-width: 0; }

@media (max-width: 1024px) {
  .side {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .3s var(--ease); box-shadow: var(--shadow-lg);
  }
  body.nav-open .side { transform: translateX(0); }
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; z-index: 35;
    background: rgba(15,23,42,.5); backdrop-filter: blur(3px);
  }
  .menu-btn { display: inline-grid; }
  .content { padding: 16px 14px calc(78px + env(safe-area-inset-bottom)); }
  .topbar { padding: 10px 14px; }
}

/* ── แถบหัวหลังบ้านบนมือถือ ────────────────────────────────────────────
   ปัญหาเดิม: ชื่อหน้า + คำอธิบายยาว ถูกบีบจนตัดเป็น 3-4 บรรทัด แถบสูงผิดรูป
   หลักการ: เหลือเฉพาะสิ่งที่จำเป็นต่อการรู้ว่า "อยู่หน้าไหน" + ปุ่มที่ต้องกดได้จริง */
@media (max-width: 720px) {
  .topbar {
    gap: 8px; padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  .topbar .grow { min-width: 0; }                 /* ★ ขาดข้อนี้ ellipsis จะไม่ทำงาน */
  .topbar-title {
    font-size: 15px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-sub { display: none; }                  /* คำอธิบายเป็นข้อมูลเสริม ตัดได้ */
  .topbar-ico { width: 36px; height: 36px; border-radius: 11px; font-size: 16px; }
  .topbar .pill { padding: 6px 10px; font-size: 12px; }
  .topbar .pill-word { display: none; }           /* เหลือ "ปฏิทิน 2568" */
  /* ปุ่มทุกตัวบนแถบต้องแตะได้จริง ≥44px ตาม Apple HIG */
  .topbar .btn { min-height: 44px; min-width: 44px; }
  .pop { right: -6px; min-width: min(280px, calc(100vw - 24px)); }
}

@media (max-width: 420px) {
  /* จอเล็กมาก: ไอคอนหน้ากับป้ายปีแย่งที่กัน — ตัดไอคอนหน้าออก ชื่อหน้าสำคัญกว่า */
  .topbar-ico { display: none; }
}

/* ── 17. Bottom nav (มือถือ) ───────────────────────────────────────────── */
.bottom-nav { display: none; }

@media (max-width: 1024px) {
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    display: flex; justify-content: space-around; align-items: center;
    background: rgba(255,255,255,.97); backdrop-filter: blur(20px);
    border-top: 1px solid var(--line);
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 24px rgba(15,23,42,.08);
  }
  .bn-item {
    position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    min-width: 62px; min-height: 46px; padding: 5px 8px;
    color: var(--ink-muted); font-size: 10.5px; text-decoration: none;
    background: none; border: 0; cursor: pointer; font-family: var(--font-body);
  }
  .bn-item i { font-size: 19px; }
  .bn-item.is-active { color: var(--brand-700); }
  .bn-item.is-active::before {
    content: ""; position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
    width: 24px; height: 3px; border-radius: 0 0 4px 4px; background: var(--gold-400);
  }
  .bn-fab { margin-top: -24px; }
  .bn-fab .fab {
    width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
    font-size: 22px; color: #fff; border: 4px solid #fff;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    box-shadow: 0 8px 20px rgba(79,70,229,.42);
  }
  .bn-item:active { transform: scale(.94); }
}

/* ── 18. Charts (SVG ล้วน) ─────────────────────────────────────────────── */
.chart { width: 100%; display: block; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 12.5px; color: var(--ink-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.chart-empty { display: grid; place-items: center; min-height: 180px; color: var(--ink-faint); font-size: 14px; gap: 8px; }

.donut-center {
  font-family: var(--font-display); font-weight: 700; fill: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ── 19. Footer ────────────────────────────────────────────────────────── */
.foot {
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 20px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.foot-left { font-size: 13px; color: var(--ink-muted); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ver-pill {
  padding: 2px 10px; border-radius: var(--r-full); font-size: 11.5px; font-weight: 600;
  background: var(--brand-50); color: var(--brand-700); border: 1px solid var(--brand-200);
  font-family: var(--font-display);
}
.foot-dev { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.foot-dev-logo {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--brand-200); box-shadow: 0 0 0 4px var(--brand-50), 0 4px 14px rgba(79,70,229,.18);
}
.foot-dev-text { line-height: 1.35; }
.foot-dev-text small { display: block; font-size: 11px; color: var(--ink-faint); }
.foot-dev-text b { font-family: var(--font-display); font-size: 13.5px; color: var(--ink-2); font-weight: 600; }

.foot-dark { background: transparent; border-top-color: rgba(255,255,255,.12); }
.foot-dark .foot-left { color: rgba(255,255,255,.62); }
.foot-dark .foot-dev-text b { color: rgba(255,255,255,.9); }
.foot-dark .foot-dev-text small { color: rgba(255,255,255,.5); }
.foot-dark .ver-pill { background: rgba(255,255,255,.10); color: #e2e8f0; border-color: rgba(255,255,255,.16); }

@media (max-width: 560px) {
  .foot { flex-direction: column-reverse; text-align: center; }
  .foot-left { justify-content: center; }
}

/* ── 20. Modal / bottom sheet ──────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 90; display: none; }
.modal.is-open { display: block; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(15,23,42,.55); backdrop-filter: blur(4px);
  animation: fadeIn .25s var(--ease);
}
.modal-panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(720px, calc(100% - 32px)); max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  animation: popIn .28s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translate(-50%, -46%) scale(.96); } }

.modal-head {
  position: relative; overflow: hidden; padding: 22px 24px; color: #fff;
  background: linear-gradient(135deg, var(--brand-700), var(--brand-500));
}
.modal-head h3 { color: #fff; margin: 0; font-size: 18px; }
.modal-head p { color: rgba(255,255,255,.82); margin: 4px 0 0; font-size: 13.5px; }
.modal-close {
  position: absolute; right: 16px; top: 16px; width: 36px; height: 36px;
  border-radius: 50%; border: 1px solid rgba(255,255,255,.28); background: rgba(255,255,255,.14);
  color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 16px;
  transition: background var(--t);
}
.modal-close:hover { background: rgba(255,255,255,.26); }
.modal-body { padding: 22px 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 540px) {
  .modal-panel {
    top: auto; bottom: 0; left: 0; transform: none; width: 100%;
    border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92dvh;
    animation: sheetUp .3s var(--ease);
  }
  @keyframes sheetUp { from { transform: translateY(100%); } }
  .modal-foot { justify-content: stretch; }
  .modal-foot .btn { flex: 1 1 auto; }
}

/* ── 21. Micro-interactions ────────────────────────────────────────────── */
/* ★ ซ่อนไว้เพื่อทำแอนิเมชันได้ "เฉพาะเมื่อมี JS" เท่านั้น (html.js ถูกใส่ใน <head>)
   ถ้า JS ถูกปิด/โหลดไม่สำเร็จ กฎนี้จะไม่ทำงาน → เนื้อหาทั้งหน้ายังอ่านได้ตามปกติ
   (เคยพลาด: ตั้ง opacity:0 แบบไม่มีเงื่อนไข → สกรีนช็อต/บอต/ผู้ใช้ที่ JS พังเห็นหน้าว่างเปล่า) */
.js [data-reveal] { opacity: 0; transform: translateY(24px); transition: opacity .6s var(--ease), transform .6s var(--ease); }
.js [data-reveal].is-in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .js [data-reveal] { opacity: 1; transform: none; }
}

.stagger > * { animation: fadeUp .55s var(--ease) backwards; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .08s; }
.stagger > *:nth-child(3) { animation-delay: .14s; }
.stagger > *:nth-child(4) { animation-delay: .20s; }
.stagger > *:nth-child(5) { animation-delay: .26s; }
.stagger > *:nth-child(6) { animation-delay: .32s; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } }

/* ── 22. Contact FAB ───────────────────────────────────────────────────── */
.fab-contact {
  position: fixed; right: 22px; bottom: 22px; z-index: 70;
  display: flex; flex-direction: column-reverse; align-items: flex-end; gap: 12px;
  /* ★ กล่องนี้สูงเกือบ 300px เพราะเมนูที่ซ่อนอยู่ยังกินพื้นที่ layout
     ถ้าไม่ปิด pointer-events มันจะกินคลิกของทุกอย่างที่อยู่ใต้มุมขวาล่าง
     (เคยทำให้ปุ่ม "กลับขึ้นบน" กดไม่ได้ทั้งที่มองเห็น) — เปิดรับคลิกเฉพาะตัวที่กดได้จริง */
  pointer-events: none;
}
.fab-menu { display: flex; flex-direction: column-reverse; gap: 10px; pointer-events: none; }
.fab-item {
  display: flex; align-items: center; gap: 10px;
  opacity: 0; transform: translateY(12px) scale(.85); pointer-events: none;
  transition: all .25s var(--ease); text-decoration: none;
}
.fab-contact.is-open .fab-item { opacity: 1; transform: none; pointer-events: auto; }
.fab-contact.is-open .fab-item:nth-child(1) { transition-delay: .04s; }
.fab-contact.is-open .fab-item:nth-child(2) { transition-delay: .08s; }
.fab-contact.is-open .fab-item:nth-child(3) { transition-delay: .12s; }
.fab-contact.is-open .fab-item:nth-child(4) { transition-delay: .16s; }
.fab-label {
  background: rgba(15,23,42,.92); color: #fff; font-size: 12.5px;
  padding: 5px 12px; border-radius: var(--r-full); white-space: nowrap;
}
.fab-dot {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 18px; background: var(--c, var(--brand-600));
  box-shadow: 0 6px 18px rgba(15,23,42,.26);
}
.fab-toggle {
  position: relative; pointer-events: auto;
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; font-size: 23px; color: #fff;
  background: linear-gradient(135deg, #22c55e, #15803d);
  box-shadow: 0 10px 26px rgba(21,128,61,.42);
  transition: transform var(--t), background var(--t);
}
.fab-contact.is-open .fab-toggle {
  transform: rotate(135deg);
  background: linear-gradient(135deg, #f87171, #b91c1c);
}
.fab-ring {
  position: absolute; inset: 0; border-radius: 50%; border: 2px solid #22c55e;
  animation: ring 2.4s ease-out infinite; pointer-events: none;
}
.fab-contact.is-open .fab-ring { display: none; }
@keyframes ring {
  0% { transform: scale(1); opacity: .7; }
  100% { transform: scale(1.75); opacity: 0; }
}

@media (max-width: 1024px) {
  .fab-contact { bottom: calc(86px + env(safe-area-inset-bottom)); right: 16px; }
}

/* ── 23. Print ─────────────────────────────────────────────────────────── */
@media print {
  @page { size: A4 portrait; margin: 14mm 12mm; }
  body { background: #fff; font-size: 12px; }
  .side, .topbar, .bottom-nav, .foot, .toolbar, .fab-contact, .no-print, .btn { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  .card, .stat, .hero { box-shadow: none !important; border: 1px solid #cbd5e1 !important; break-inside: avoid; }
  .hero { background: #f1f5f9 !important; color: #0f172a !important; }
  .hero h1, .hero p, .kpi-value, .kpi-label, .kpi-sub { color: #0f172a !important; }
  .kpi { background: #fff !important; border-color: #cbd5e1 !important; }
  .table thead { display: table-header-group; }
  .table thead th { position: static; background: #f1f5f9 !important; }
  .table tbody tr { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* ── 24. Accessibility ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── 25. Public site ───────────────────────────────────────────────────── */
body.site { background: var(--surface); }

.site-nav {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255,255,255,.88); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.site-nav-in {
  display: flex; align-items: center; gap: 14px;
  min-height: 70px; padding: 10px 0;
}
.site-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.site-brand-logo {
  width: 46px; height: 46px; border-radius: 13px; flex: 0 0 auto;
  display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(135deg, var(--brand-50), var(--brand-100));
  border: 1px solid var(--brand-200);
}
.site-brand-logo img { width: 80%; height: 80%; object-fit: contain; }
.site-brand-name { font-family: var(--font-display); font-weight: 700; font-size: 20px; color: var(--brand-800); line-height: 1.15; }
.site-brand-sub { font-size: 11.5px; color: var(--ink-muted); }

.site-hero {
  position: relative; overflow: hidden;
  padding: clamp(48px, 8vw, 96px) 0;
  background: linear-gradient(160deg, var(--brand-950), var(--brand-800) 55%, var(--brand-700));
  color: #fff;
}
.site-hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(1100px 320px at 12% -10%, rgba(255,255,255,.16), transparent 70%),
    radial-gradient(700px 260px at 95% 110%, rgba(251,191,36,.18), transparent 70%);
}
.site-hero-grid {
  position: relative; z-index: 1;
  display: grid; gap: 40px; align-items: center;
  grid-template-columns: 1.15fr .85fr;
}
.site-hero h1 {
  color: #fff; font-size: clamp(30px, 5vw, 50px); font-weight: 800;
  line-height: 1.2; margin-bottom: 14px;
}
.site-hero h1 span {
  background: linear-gradient(90deg, var(--gold-200), var(--gold-400));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.site-hero p { color: rgba(255,255,255,.84); font-size: clamp(15px, 1.6vw, 18px); max-width: 54ch; }
/* บนภาพถ่ายที่มีทั้งส่วนสว่างและมืด เงาตัวอักษรช่วยให้อ่านออกโดยไม่ต้องเพิ่มความทึบของ overlay
   (เพิ่ม overlay = ภาพจม ผิดเจตนาที่ผู้ดูแลอัปโหลดภาพมา) */
.site-hero.has-image h1,
.site-hero.has-image p,
.site-hero.has-image .hero-eyebrow { text-shadow: 0 2px 10px rgba(15,23,42,.45); }

.hero-panel {
  background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.16);
  border-radius: var(--r-xl); padding: 24px; backdrop-filter: blur(14px);
}
.hero-panel h3 { color: #fff; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.hero-mini { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.hero-mini-item { background: rgba(255,255,255,.09); border-radius: var(--r); padding: 13px 15px; }
.hero-mini-item b {
  display: block; font-family: var(--font-display); font-size: 25px; color: #fff;
  font-variant-numeric: tabular-nums;
}
.hero-mini-item span { font-size: 12px; color: rgba(255,255,255,.72); }

@media (max-width: 900px) {
  .site-hero-grid { grid-template-columns: 1fr; }
}

/* ── ภาพพื้นหลังฮีโร่ที่ผู้ดูแลอัปโหลดเอง ───────────────────────────────
   ไล่เฉดทิศทางเดียว: ฝั่งข้อความ (ซ้าย) ทึบ 88% → ฝั่งภาพ (ขวา) โปร่ง 18%
   ตัวอักษรอ่านออกเสมอไม่ว่าภาพจะสว่างแค่ไหน
   ถ้าเบราว์เซอร์ไม่รู้จัก color-mix ทั้ง declaration จะถูกทิ้ง → กลับไปใช้
   พื้นหลังไล่เฉดสีของ .site-hero เองโดยอัตโนมัติ (graceful fallback) */
.site-hero.has-image {
  background-image:
    linear-gradient(100deg,
      color-mix(in srgb, var(--brand-950) 92%, transparent) 0%,
      color-mix(in srgb, var(--brand-900) 80%, transparent) 42%,
      color-mix(in srgb, var(--brand-800) 46%, transparent) 68%,
      color-mix(in srgb, var(--brand-950) 20%, transparent) 100%),
    var(--hero-img);
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
}
@media (max-width: 900px) {
  /* จอแคบ ข้อความทับภาพเต็มความกว้าง → ต้องทึบขึ้นทั้งผืน */
  .site-hero.has-image {
    background-image:
      linear-gradient(175deg,
        color-mix(in srgb, var(--brand-950) 88%, transparent) 0%,
        color-mix(in srgb, var(--brand-900) 78%, transparent) 100%),
      var(--hero-img);
  }
}

.section { padding: clamp(46px, 6vw, 78px) 0; }
.section-alt { background: var(--surface-2); }
.section-head { text-align: center; max-width: 62ch; margin: 0 auto 38px; }
.section-head .eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-display); font-size: 12px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--brand-700); background: var(--brand-50); border: 1px solid var(--brand-200);
  padding: 5px 14px; border-radius: var(--r-full); margin-bottom: 14px;
}
.section-head h2 { font-size: clamp(23px, 3.2vw, 33px); font-weight: 700; margin-bottom: 10px; }
.section-head p { color: var(--ink-muted); font-size: 15.5px; margin: 0; }

.feature {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 26px 24px; height: 100%;
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}
.feature:hover { transform: translateY(-6px); box-shadow: var(--shadow-md); border-color: var(--brand-200); }
.feature-ico {
  width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center;
  font-size: 23px; color: #fff; margin-bottom: 16px;
  background: linear-gradient(135deg, var(--f1, var(--brand-500)), var(--f2, var(--brand-700)));
  box-shadow: 0 8px 20px rgba(15,23,42,.14);
}
.feature h3 { font-size: 17px; margin-bottom: 8px; }
.feature p { color: var(--ink-muted); font-size: 14.5px; margin: 0; }

.color-legend { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.color-legend-item {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--c, var(--brand-500));
  border-radius: var(--r); padding: 14px 16px;
}
.color-legend-item b { font-family: var(--font-display); font-size: 15px; color: var(--ink); display: block; }
.color-legend-item span { font-size: 13px; color: var(--ink-muted); }

/* ══ การ์ดสถิติสาธารณะบนหน้าแรก — สัดส่วนกลุ่มสี · พัฒนาการย้อนหลัง ══ */
.insight-grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.insight-card { overflow: hidden; }
.insight-card .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.insight-card .card-head h2 { font-size: 16px; display: flex; align-items: center; gap: 9px; }
.insight-body { display: grid; gap: 16px; }

/* โดนัท SVG ของหน้าแรก — ไม่ใช้ chart library
   ⚠ ห้ามใช้ชื่อ .donut-center ซ้ำ! ชื่อนั้นถูกใช้กับ <text> ใน SVG ของกราฟแดชบอร์ดอยู่แล้ว
     (assets/js/app.js → Chart.donut) การประกาศทับจะพังกราฟทุกหน้าที่ใช้โดนัท — กฎเหล็ก #15 */
.stat-donut { position: relative; width: 168px; margin: 2px auto 0; }
.stat-donut svg { width: 100%; height: auto; transform: rotate(-90deg); display: block; }
.stat-donut circle { fill: none; stroke-width: 15; stroke-linecap: butt; }
.stat-donut-track { stroke: var(--surface-2); }
/* วงสีไล่กันโผล่ทีละกลุ่ม — ตัวเลือก [style] เจาะเฉพาะ segment (วงพื้นหลังไม่มี style attribute)
   @media prefers-reduced-motion ด้านบนตัดแอนิเมชันนี้ให้อัตโนมัติ */
.stat-donut circle[style] { animation: donutIn .6s ease-out both; animation-delay: var(--d, 0ms); }
@keyframes donutIn { from { opacity: 0; stroke-width: 4; } }
.stat-donut-hole {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.1;
}
.stat-donut-hole b {
  display: block; font-family: var(--font-display); font-size: 30px; font-weight: 800;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.stat-donut-hole span { font-size: 12px; color: var(--ink-muted); }

/* แถวสัดส่วน — ชื่อ · จำนวน · ร้อยละ · แถบ (ไม่มีชื่อโรงเรียนโดยเจตนา) */
.dist-list, .prog-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 11px; }
.dist-row, .prog-row {
  display: grid; align-items: center; gap: 6px 10px;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas: "dot name num pct" "bar bar bar bar";
}
.dist-dot {
  grid-area: dot; width: 11px; height: 11px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 20%, transparent);
}
.dist-name, .prog-name { grid-area: name; font-size: 14px; font-weight: 600; color: var(--ink); }
.dist-num, .prog-num { grid-area: num; font-size: 14px; font-weight: 700; color: var(--ink); }
.dist-num i, .prog-num i { font-style: normal; font-size: 11.5px; font-weight: 400; color: var(--ink-muted); }
.dist-pct, .prog-pct {
  grid-area: pct; min-width: 54px; text-align: right;
  font-family: var(--font-display); font-size: 15px; font-weight: 700; color: var(--c);
}
.dist-bar {
  grid-area: bar; display: block; height: 7px; border-radius: var(--r-full);
  background: var(--surface-2); overflow: hidden;
}
.dist-bar i {
  display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 65%, #fff), var(--c));
  /* transform-origin ต้องอยู่บน element ไม่ใช่ใน keyframe — ไม่งั้นจุดหมุนจะถูก interpolate ไปกลางแท่ง */
  transform-origin: left center;
  animation: barGrow .9s cubic-bezier(.22,1,.36,1) both;
}
@keyframes barGrow { from { transform: scaleX(0); } }

.prog-ico {
  grid-area: dot; display: grid; place-content: center; width: 26px; height: 26px; border-radius: 9px;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); font-size: 15px;
}

/* บล็อกสรุปพัฒนาการ */
.prog-hero {
  display: flex; align-items: center; gap: 16px;
  background: linear-gradient(120deg, var(--brand-50), var(--surface));
  border: 1px solid var(--brand-100); border-radius: var(--r-lg); padding: 16px 18px;
}
.prog-hero-ring {
  flex: 0 0 auto; display: grid; place-content: center; width: 74px; height: 74px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-700), var(--brand-500)); color: #fff;
  font-family: var(--font-display); line-height: 1;
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--brand-700) 70%, transparent);
}
.prog-hero-ring b { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; }
.prog-hero-ring span { font-size: 11px; opacity: .82; text-align: center; display: block; }
.prog-hero-num {
  font-family: var(--font-display); font-size: 27px; font-weight: 800; color: var(--brand-800);
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.prog-hero-cap { display: block; font-size: 14px; font-weight: 600; color: var(--ink); }
.prog-hero-sub { display: block; font-size: 12px; color: var(--ink-muted); margin-top: 3px; }

.insight-note {
  font-size: 12.5px; color: var(--ink-muted); line-height: 1.7; margin: 0;
  border-top: 1px dashed var(--line); padding-top: 12px;
}
.insight-note b { color: var(--ink); }

@media (max-width: 420px) {
  .dist-row, .prog-row { grid-template-columns: auto 1fr auto; grid-template-areas: "dot name pct" "num num num" "bar bar bar"; }
  .dist-num, .prog-num { text-align: left; }
}

/* ── ฟิลด์อัปโหลดรูปในหน้าตั้งค่า ─────────────────────────────────── */
.img-setting { display: grid; gap: 12px; grid-template-columns: minmax(180px, 260px) 1fr; align-items: start; }
.img-setting-preview {
  border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
  background: var(--surface-2); aspect-ratio: 16 / 9;
}
.img-setting-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-setting-preview.is-empty {
  display: grid; place-content: center; text-align: center; padding: 12px;
  font-size: 12.5px; color: var(--ink-muted); border-style: dashed;
}
.img-setting-controls { display: grid; gap: 10px; }
@media (max-width: 640px) { .img-setting { grid-template-columns: 1fr; } }

/* ══ หน้าทีมผู้พัฒนาระบบ ═══════════════════════════════════════════════ */
.page-hero {
  position: relative; overflow: hidden; text-align: center;
  padding: clamp(40px, 6vw, 72px) 0 clamp(44px, 6vw, 76px);
  background: linear-gradient(160deg, var(--brand-950), var(--brand-800) 60%, var(--brand-700));
  color: #fff;
}
.page-hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(900px 280px at 20% -20%, rgba(255,255,255,.16), transparent 70%),
    radial-gradient(600px 240px at 88% 120%, rgba(251,191,36,.18), transparent 70%);
}
.page-hero .container { position: relative; z-index: 1; }
.page-hero h1 { color: #fff; font-size: clamp(26px, 4.2vw, 40px); font-weight: 800; margin-bottom: 12px; }
.page-hero p { color: rgba(255,255,255,.84); font-size: clamp(14.5px, 1.5vw, 17px); max-width: 62ch; margin: 0 auto; }
.page-hero .hero-actions { justify-content: center; }

.team-grid {
  display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.team-card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--shadow-sm);
  transition: transform .28s var(--ease), box-shadow .28s var(--ease), border-color .28s var(--ease);
}
.team-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 38px -18px color-mix(in srgb, var(--c) 55%, transparent);
  border-color: color-mix(in srgb, var(--c) 35%, var(--line));
}
.team-cover {
  height: 88px;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 45%, var(--brand-900)));
  position: relative;
}
.team-cover::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(420px 120px at 25% 0%, rgba(255,255,255,.28), transparent 70%);
}
.team-avatar {
  width: 112px; height: 112px; margin: -56px auto 0; position: relative; z-index: 1;
  border-radius: 50%; overflow: hidden; background: var(--surface-2);
  border: 5px solid var(--surface); box-shadow: 0 10px 24px -12px rgba(15,23,42,.5);
  display: grid; place-items: center;
}
.team-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.team-initial {
  font-family: var(--font-display); font-size: 42px; font-weight: 700; color: #fff;
  width: 100%; height: 100%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 50%, var(--brand-900)));
}
.team-body { padding: 14px 20px 22px; text-align: center; }
.team-role {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-display); font-size: 11.5px; font-weight: 600; letter-spacing: .03em;
  padding: 4px 12px; border-radius: var(--r-full); margin-bottom: 10px;
  background: color-mix(in srgb, var(--c) 12%, transparent);
  color: color-mix(in srgb, var(--c) 78%, #000);
  border: 1px solid color-mix(in srgb, var(--c) 26%, transparent);
}
.team-body h3 { font-size: 18px; color: var(--ink); margin-bottom: 3px; }
.team-position { font-size: 14px; color: var(--c); font-weight: 600; margin: 0 0 6px; }
.team-affil { font-size: 12.5px; color: var(--ink-muted); margin: 0 0 10px; }
.team-bio {
  font-size: 13.5px; color: var(--ink-muted); line-height: 1.75; margin: 0;
  padding-top: 12px; border-top: 1px dashed var(--line);
}
.team-links { display: flex; justify-content: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.team-links a {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-muted);
  font-size: 16px; transition: all .2s var(--ease);
}
.team-links a:hover { background: var(--c); border-color: var(--c); color: #fff; transform: translateY(-2px); }

/* รายการทีมพัฒนาในหลังบ้าน */
.dev-admin-list { display: grid; gap: 10px; }
.dev-admin-item {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); transition: border-color .2s var(--ease), background .2s var(--ease);
}
.dev-admin-item:hover { border-color: var(--brand-300); }
.dev-admin-item.is-editing { background: var(--brand-50); border-color: var(--brand-400); }
.dev-admin-photo {
  width: 56px; height: 56px; flex: 0 0 auto; border-radius: 50%; overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center;
  color: var(--ink-faint); font-size: 24px; border: 1px solid var(--line);
}
.dev-admin-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dev-admin-info { flex: 1 1 200px; min-width: 0; }
.dev-admin-info b { display: block; font-family: var(--font-display); font-size: 15px; color: var(--ink); }
.dev-admin-info > span { display: block; font-size: 13px; color: var(--ink-muted); margin-bottom: 6px; }
.dev-admin-tags { display: flex; gap: 6px; flex-wrap: wrap; }

/* ══ หน้าออฟไลน์ (PWA) ════════════════════════════════════════════════ */
.offline-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--brand-950), var(--brand-800));
}
.offline-card {
  max-width: 480px; width: 100%; text-align: center;
  background: rgba(255,255,255,.96); border-radius: var(--r-xl);
  padding: 38px 30px; box-shadow: 0 30px 70px -30px rgba(0,0,0,.6);
}
.offline-ico {
  width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 26px;
  display: grid; place-items: center; font-size: 38px; color: #fff;
  background: linear-gradient(135deg, var(--brand-700), var(--brand-500));
}
.offline-card h1 { font-size: 21px; color: var(--ink); margin-bottom: 10px; }
.offline-card > p { font-size: 14.5px; color: var(--ink-muted); line-height: 1.8; margin-bottom: 18px; }
.offline-tips {
  list-style: none; margin: 0 0 20px; padding: 16px; text-align: left;
  background: var(--surface-2); border-radius: var(--r); display: grid; gap: 10px;
  font-size: 13.5px; color: var(--ink-2);
}
.offline-tips li { display: flex; gap: 10px; align-items: center; }
.offline-tips i { color: var(--brand-600); font-size: 16px; }
.offline-status {
  margin: 18px 0 0; font-size: 12.5px; color: var(--ink-muted);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.offline-status .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--warn-500, #f59e0b);
  animation: pulseDot 1.8s ease-out infinite;
}
.offline-status.is-online { color: var(--ok-700, #047857); font-weight: 600; }
.offline-status.is-online .dot { background: #10b981; }
@keyframes pulseDot { 50% { opacity: .3; transform: scale(.75); } }

.site-footer { background: var(--brand-950); color: rgba(255,255,255,.72); padding: 44px 0 0; }
.site-footer h4 { color: #fff; font-size: 15px; margin-bottom: 14px; }
.site-footer a { color: rgba(255,255,255,.72); }
.site-footer a:hover { color: var(--gold-400); }
.site-footer-grid { display: grid; gap: 32px; grid-template-columns: 1.4fr 1fr 1fr; padding-bottom: 30px; }
.site-footer-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 9px; font-size: 14px; }
.site-footer-list li { display: flex; gap: 9px; align-items: flex-start; }
.site-footer-list i { margin-top: 4px; color: var(--brand-300); }

@media (max-width: 860px) { .site-footer-grid { grid-template-columns: 1fr; } }

/* ── 26. Login — Premium Split Stage ───────────────────────────────────── */
body.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 15% -10%, var(--brand-800), transparent 60%),
              radial-gradient(900px 500px at 100% 110%, #1e1b4b, transparent 60%),
              #070b1a;
}
.auth-stage {
  width: min(1080px, 100%);
  display: grid; grid-template-columns: 1.1fr 1fr;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.10);
  border-radius: 28px; overflow: hidden; backdrop-filter: blur(18px);
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}

.auth-brand { padding: 44px 40px; color: #fff; position: relative; overflow: hidden; }
.auth-brand::before {
  content: ""; position: absolute; width: 320px; height: 320px; right: -110px; top: -110px;
  border-radius: 50%; background: radial-gradient(circle, rgba(129,140,248,.30), transparent 70%);
  animation: pulseGlow 5s ease-in-out infinite;
}
@keyframes pulseGlow { 50% { transform: scale(1.18); opacity: .7; } }
.auth-brand > * { position: relative; z-index: 1; }
.auth-logo {
  width: 58px; height: 58px; border-radius: 17px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600)); overflow: hidden;
  box-shadow: 0 0 0 4px rgba(255,255,255,.08), 0 12px 30px rgba(79,70,229,.5); margin-bottom: 22px;
}
.auth-logo img { width: 76%; height: 76%; object-fit: contain; }
.auth-brand h1 {
  color: #fff; font-size: clamp(24px, 3vw, 31px); font-weight: 800; line-height: 1.25; margin-bottom: 10px;
}
.auth-brand h1 span {
  background: linear-gradient(90deg, var(--gold-200), var(--gold-400), var(--gold-200));
  background-size: 200% auto; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shine 4s linear infinite;
}
@keyframes shine { to { background-position: 200% center; } }
.auth-brand > p { color: rgba(255,255,255,.72); font-size: 14.5px; margin-bottom: 26px; }

.auth-features { display: grid; gap: 11px; }
.auth-feature {
  display: flex; gap: 12px; align-items: flex-start;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.09);
  border-radius: var(--r); padding: 13px 15px;
}
.auth-feature i {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 15px; color: #fff;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
}
.auth-feature b { display: block; font-family: var(--font-display); font-size: 14px; color: #fff; font-weight: 500; }
.auth-feature span { font-size: 12.5px; color: rgba(255,255,255,.62); }

.auth-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 24px;
  padding-top: 22px; border-top: 1px solid rgba(255,255,255,.10);
}
.auth-stat b {
  display: block; font-family: var(--font-display); font-size: 21px; color: #fff;
  font-variant-numeric: tabular-nums;
}
.auth-stat span { font-size: 11.5px; color: rgba(255,255,255,.58); }

.auth-form-wrap {
  background: var(--surface); padding: 44px 40px;
  display: flex; flex-direction: column; justify-content: center;
}
.auth-mini { display: none; align-items: center; gap: 11px; margin-bottom: 22px; }
.auth-form-wrap h2 { font-size: 25px; margin-bottom: 4px; }
.auth-form-wrap > p { color: var(--ink-muted); font-size: 13.5px; margin-bottom: 24px; }

.auth-form { display: grid; gap: 15px; }
.auth-form.shake { animation: shake .5s; }

.pw-wrap { position: relative; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border-radius: 10px; border: 0; background: none;
  color: var(--ink-muted); cursor: pointer; display: grid; place-items: center; font-size: 16px;
}
.pw-toggle:hover { color: var(--brand-600); background: var(--brand-50); }
.caps-hint {
  display: none; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--warn-700); background: var(--warn-50);
  border: 1px solid #fde68a; border-radius: 9px; padding: 6px 11px;
}
.caps-hint.is-on { display: flex; }

@media (max-width: 900px) {
  .auth-stage { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-mini { display: flex; }
  .auth-form-wrap { padding: 34px 24px; border-radius: 28px; }
}

/* ── 27. Toast (ไม่พึ่ง lib ภายนอกเมื่อ SweetAlert2 โหลดไม่ได้) ────────── */
.toast-host {
  position: fixed; right: 18px; top: 18px; z-index: 120;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 11px;
  min-width: 260px; max-width: 380px; padding: 13px 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--brand-500);
  border-radius: var(--r); box-shadow: var(--shadow-lg);
  font-size: 14px; pointer-events: auto;
  animation: toastIn .32s var(--ease);
}
.toast.ok   { border-left-color: var(--ok-500); }
.toast.bad  { border-left-color: var(--bad-500); }
.toast.warn { border-left-color: var(--warn-500); }
.toast i { font-size: 18px; }
.toast.ok i   { color: var(--ok-700); }
.toast.bad i  { color: var(--bad-700); }
.toast.warn i { color: var(--warn-700); }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } }

@media (max-width: 560px) {
  .toast-host { left: 12px; right: 12px; top: 12px; }
  .toast { min-width: 0; max-width: none; }
}

/* ── 28. Spinner overlay ───────────────────────────────────────────────── */
.spin-host {
  position: fixed; inset: 0; z-index: 130; display: none;
  place-items: center; background: rgba(15,23,42,.55); backdrop-filter: blur(5px);
}
.spin-host.is-on { display: grid; }
.spin-card {
  background: var(--surface); border-radius: var(--r-xl); padding: 32px 40px;
  box-shadow: var(--shadow-lg); text-align: center; min-width: 240px;
}
.spin-ring {
  width: 58px; height: 58px; margin: 0 auto 16px; position: relative;
}
.spin-ring::before, .spin-ring::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid transparent;
}
.spin-ring::before { border-top-color: var(--brand-600); animation: spin 1s linear infinite; }
.spin-ring::after  { border-bottom-color: var(--brand-300); animation: spin 1.6s linear infinite reverse; inset: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.spin-title { font-family: var(--font-display); font-weight: 600; color: var(--ink); font-size: 15.5px; }
.spin-stage { font-size: 13px; color: var(--ink-muted); margin-top: 4px; min-height: 20px; }

/* ══════════════════════════════════════════════════════════════════════
   ปุ่มสไตล์แอปพลิเคชัน · แถบความคืบหน้าการเลื่อน · ปุ่มกลับขึ้นบน
   (ชั้นการแสดงผลล้วน — ไม่แตะลอจิกหรือปลายทางของปุ่มเดิม)
   ══════════════════════════════════════════════════════════════════════ */
.btn-app {
  position: relative; overflow: hidden;
  border-radius: var(--r-full);
  font-family: var(--font-display); font-weight: 600;
  transition: transform .16s var(--ease), box-shadow .22s var(--ease), background .22s var(--ease);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn-app:active { transform: scale(.965); }
@media (hover: hover) {
  .btn-app:hover { transform: translateY(-1px); }
}
/* คลื่นตอนกด — วาดด้วย element ที่ JS ใส่ให้ ไม่มี inline handler */
.btn-app .ripple {
  position: absolute; border-radius: 50%; transform: scale(0);
  background: rgba(255,255,255,.45); pointer-events: none;
  animation: rippleOut .55s var(--ease) forwards;
}
@keyframes rippleOut { to { transform: scale(2.6); opacity: 0; } }
.btn-on-dark {
  background: rgba(255,255,255,.14) !important;
  border-color: rgba(255,255,255,.28) !important;
  color: #fff !important; backdrop-filter: blur(8px);
}
@media (hover: hover) { .btn-on-dark:hover { background: rgba(255,255,255,.24) !important; } }

.scroll-progress {
  position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 60; pointer-events: none;
  background: transparent;
}
.scroll-progress i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--c30), var(--c10));
  box-shadow: 0 0 12px color-mix(in srgb, var(--c10) 60%, transparent);
}

.to-top {
  /* z-index สูงกว่า .fab-contact (70) เป็นเกราะชั้นสอง — ถึงมี overlay ใสมาทับก็ยังกดได้ */
  position: fixed; right: 22px; bottom: 96px; z-index: 75;
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--c60-raise); color: var(--c30); font-size: 18px;
  display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0; visibility: hidden; transform: translateY(10px);
  transition: opacity .25s var(--ease), transform .25s var(--ease), visibility .25s;
}
.to-top.is-on { opacity: 1; visibility: visible; transform: none; }
.to-top:active { transform: scale(.92); }

/* แถบเทียบรายอำเภอ */
.dist-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.dist-card { padding: 18px 20px; }
.dist-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.dist-pin {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  background: var(--c30-wash); color: var(--c30); font-size: 18px; flex: 0 0 auto;
}
.dist-card-head b { display: block; font-family: var(--font-display); font-size: 16px; color: var(--ink); }
.dist-card-head span { font-size: 12.5px; color: var(--ink-muted); }
.dist-metrics { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.dist-metrics li { display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 10px; }
.dist-metric-label { font-size: 12px; font-weight: 600; color: var(--ink-muted); }
.dist-metric-track { height: 8px; border-radius: var(--r-full); background: var(--c60-sink); overflow: hidden; }
.dist-metric-track i {
  display: block; height: 100%; border-radius: inherit; background: var(--c);
  transform-origin: left center; animation: barGrow 1s cubic-bezier(.22,1,.36,1) both;
}
.dist-metrics b { font-size: 13.5px; color: var(--ink); min-width: 46px; text-align: right; }

/* ══════════════════════════════════════════════════════════════════════
   โหมดแอปมือถือ (≤768px) — §13/§20
   สลับด้วย CSS ล้วน · เดสก์ท็อปถูกซ่อนจริง ไม่ render ซ้อนกันสองชุด
   ══════════════════════════════════════════════════════════════════════ */
.m-app, .m-bottom-nav, .m-sheet { display: none; }

@media (max-width: 768px) {
  /* ซ่อนเลย์เอาต์เดสก์ท็อปจริง ๆ — ห้าม render ทั้งสองชุดพร้อมกัน (§13 ข้อ 4)
     ★ .fab-contact ต้องซ่อนด้วย เพราะแถบล่างมีปุ่มลอยกลางอยู่แล้ว
       สองปุ่มลอยพร้อมกัน = ทับกันและผิดหลัก "FAB เด่นได้ปุ่มเดียว" */
  body.m-mobile-mode .dt-home,
  body.m-mobile-mode .site-nav,
  body.m-mobile-mode .site-footer,
  body.m-mobile-mode .fab-contact,
  body.m-mobile-mode .to-top { display: none !important; }

  body.m-mobile-mode { background: var(--c60); }

  .m-app {
    display: block;
    padding-bottom: calc(86px + env(safe-area-inset-bottom));
  }
  .m-bottom-nav { display: flex; }
  .m-sheet { display: block; }

  /* 1 · แถบหัว */
  .m-header {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px calc(12px);
    padding-top: calc(12px + env(safe-area-inset-top));
    background: linear-gradient(135deg, var(--c30-deep), var(--c30));
    color: #fff; box-shadow: 0 4px 14px rgba(15,23,42,.16);
  }
  .m-header-brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
  .m-header-logo {
    width: 38px; height: 38px; border-radius: 12px; flex: 0 0 auto;
    background: rgba(255,255,255,.16); display: grid; place-items: center; overflow: hidden;
  }
  .m-header-logo img { width: 78%; height: 78%; object-fit: contain; }
  .m-header-text { min-width: 0; line-height: 1.25; }
  .m-greet { display: block; font-size: 11.5px; color: rgba(255,255,255,.78); }
  .m-header-text strong {
    display: block; font-family: var(--font-display); font-size: 15px; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-header-actions { display: flex; gap: 8px; flex: 0 0 auto; }
  .m-icon-btn {
    width: 44px; height: 44px; border-radius: 14px; border: 0;
    background: rgba(255,255,255,.16); color: #fff; font-size: 17px;
    display: grid; place-items: center; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .m-icon-btn:active { transform: scale(.9); }

  /* 2 · การ์ดแบนเนอร์ */
  .m-hero { padding: 14px 14px 0; }
  .m-hero-in {
    position: relative; overflow: hidden;
    border-radius: var(--r-xl); padding: 22px 20px 20px; color: #fff;
    background: linear-gradient(140deg, var(--c30-deep), var(--c30) 70%, var(--brand-500));
    box-shadow: 0 14px 30px -16px color-mix(in srgb, var(--c30-deep) 80%, transparent);
  }
  .m-hero.has-image .m-hero-in {
    background-image:
      linear-gradient(160deg,
        color-mix(in srgb, var(--brand-950) 86%, transparent),
        color-mix(in srgb, var(--brand-800) 62%, transparent)),
      var(--hero-img);
    background-size: cover; background-position: center;
  }
  .m-hero-in::after {
    content: ""; position: absolute; right: -30px; top: -30px; width: 150px; height: 150px;
    border-radius: 50%; background: radial-gradient(circle, rgba(251,191,36,.28), transparent 68%);
    pointer-events: none;
  }
  .m-hero-tag {
    display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
    background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.24);
    padding: 4px 11px; border-radius: var(--r-full); margin-bottom: 10px;
  }
  .m-hero-in h1 { font-size: 23px; font-weight: 800; color: #fff; line-height: 1.3; margin: 0 0 6px; }
  .m-hero-in h1 span {
    background: linear-gradient(90deg, var(--c10-soft), var(--c10));
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }
  .m-hero-in p { font-size: 13px; color: rgba(255,255,255,.82); margin: 0 0 16px; }
  .m-hero-cta {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px;
    padding: 10px 22px; border-radius: var(--r-full); text-decoration: none;
    background: linear-gradient(135deg, var(--c10), var(--c10-deep)); color: #451a03;
    font-weight: 700; box-shadow: 0 8px 18px -8px var(--c10-deep);
  }

  /* 3 · สถิติย่อ */
  .m-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 14px; }
  .m-stat {
    background: var(--c60-raise); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: 14px 14px 12px; box-shadow: var(--shadow-xs);
  }
  .m-stat-ico {
    width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
    background: color-mix(in srgb, var(--c) 12%, transparent); color: var(--c);
    font-size: 16px; margin-bottom: 8px;
  }
  .m-stat b {
    display: block; font-family: var(--font-display); font-size: 24px; font-weight: 800;
    color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.1;
  }
  .m-stat-label { font-size: 11.5px; color: var(--ink-muted); }

  /* 4 · ตารางเมนูแบบแอป */
  .m-section { padding: 6px 14px 16px; }
  .m-section-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 2px 12px; }
  .m-section-head h2 {
    font-family: var(--font-display); font-size: 15px; color: var(--ink); margin: 0;
    display: flex; align-items: center; gap: 8px;
  }
  .m-section-head h2 i { color: var(--c30); }
  .m-more { font-size: 12.5px; color: var(--c30); text-decoration: none; display: inline-flex; align-items: center; gap: 2px; }
  .m-empty { font-size: 13px; color: var(--ink-muted); text-align: center; padding: 20px 0; }

  .m-menu-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .m-menu-item {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 7px;
    padding: 12px 4px; text-decoration: none; border-radius: var(--r);
    -webkit-tap-highlight-color: transparent;
  }
  .m-menu-icon {
    width: 54px; height: 54px; border-radius: 17px; display: grid; place-items: center;
    font-size: 22px; color: var(--c);
    background: color-mix(in srgb, var(--c) 13%, var(--c60-raise));
    border: 1px solid color-mix(in srgb, var(--c) 22%, transparent);
    box-shadow: 0 4px 12px rgba(15,23,42,.07);
    transition: transform .18s var(--ease);
  }
  .m-menu-item:active .m-menu-icon { transform: scale(.9) rotate(-4deg); }
  .m-menu-label {
    font-size: 11px; color: var(--ink-2); text-align: center; line-height: 1.3;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .m-menu-badge {
    position: absolute; top: 6px; right: 50%; transform: translateX(30px);
    background: var(--bad-500); color: #fff; font-size: 9.5px; font-weight: 700;
    padding: 1px 6px; border-radius: var(--r-full);
  }

  /* 5 · การ์ดกลุ่มสีเลื่อนแนวนอน */
  .m-hscroll {
    display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 8px;
    scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .m-hscroll::-webkit-scrollbar { display: none; }
  .m-color-card {
    flex: 0 0 132px; scroll-snap-align: start;
    background: var(--c60-raise); border: 1px solid var(--line);
    border-top: 3px solid var(--c); border-radius: var(--r-lg);
    padding: 12px 13px; box-shadow: var(--shadow-xs);
  }
  .m-color-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); display: block; margin-bottom: 7px; }
  .m-color-card b { display: block; font-size: 13px; color: var(--ink); font-family: var(--font-display); }
  .m-color-num {
    font-family: var(--font-display); font-size: 25px; font-weight: 800; color: var(--c);
    font-variant-numeric: tabular-nums; line-height: 1.2;
  }
  .m-color-unit { font-size: 11px; color: var(--ink-muted); margin-left: 4px; }
  .m-color-pct { display: block; font-size: 11.5px; color: var(--ink-muted); margin: 2px 0 6px; }
  .m-color-bar { display: block; height: 5px; border-radius: var(--r-full); background: var(--c60-sink); overflow: hidden; }
  .m-color-bar i { display: block; height: 100%; background: var(--c); transform-origin: left; animation: barGrow .9s var(--ease) both; }

  /* 6 · พัฒนาการ */
  .m-prog-card {
    background: var(--c60-raise); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: 16px; box-shadow: var(--shadow-xs);
  }
  .m-prog-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
  .m-prog-ring {
    flex: 0 0 auto; width: 66px; height: 66px; border-radius: 50%; display: grid; place-content: center;
    background: linear-gradient(135deg, var(--c30), var(--brand-500)); color: #fff;
    font-family: var(--font-display); line-height: 1; text-align: center;
  }
  .m-prog-ring b { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
  .m-prog-ring span { font-size: 10px; opacity: .85; }
  .m-prog-cap { font-size: 14px; color: var(--ink); }
  .m-prog-cap b { font-family: var(--font-display); font-size: 22px; color: var(--c30); }
  .m-prog-cap small { display: block; font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; }
  .m-prog-list { list-style: none; margin: 0; padding: 12px 0 0; border-top: 1px dashed var(--line); display: grid; gap: 9px; }
  .m-prog-list li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
  .m-prog-list li span { flex: 1; color: var(--ink-2); }
  .m-prog-list li b { font-family: var(--font-display); color: var(--ink); }
  .m-prog-list li i { font-style: normal; font-size: 12px; color: var(--ink-muted); min-width: 46px; text-align: right; }

  /* 6.5 · ความสามารถของระบบ */
  .m-feat-list { display: grid; gap: 10px; }
  .m-feat {
    display: flex; gap: 12px; align-items: flex-start;
    background: var(--c60-raise); border: 1px solid var(--line);
    border-left: 3px solid var(--c); border-radius: var(--r-lg);
    padding: 13px 14px; box-shadow: var(--shadow-xs);
  }
  .m-feat-ico {
    width: 38px; height: 38px; flex: 0 0 auto; border-radius: 12px;
    display: grid; place-items: center; font-size: 17px; color: var(--c);
    background: color-mix(in srgb, var(--c) 13%, transparent);
  }
  .m-feat b { display: block; font-family: var(--font-display); font-size: 14px; color: var(--ink); }
  .m-feat p { margin: 3px 0 0; font-size: 12.5px; line-height: 1.65; color: var(--ink-muted); }

  /* 6.6 · เกณฑ์การจัดกลุ่ม */
  .m-note { font-size: 12.5px; line-height: 1.75; color: var(--ink-muted); margin: 0 2px 12px; }
  .m-legend { display: grid; gap: 8px; }
  .m-legend-item {
    display: flex; gap: 11px; align-items: flex-start;
    background: var(--c60-raise); border: 1px solid var(--line);
    border-left: 4px solid var(--c); border-radius: var(--r); padding: 11px 13px;
  }
  .m-legend-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-top: 6px; flex: 0 0 auto; }
  .m-legend-item b { display: block; font-family: var(--font-display); font-size: 13.5px; color: var(--ink); }
  .m-legend-item span { font-size: 12px; color: var(--ink-muted); line-height: 1.6; }

  /* จุดยึด: เผื่อที่ให้แถบหัวที่ปักอยู่ ไม่งั้นหัวข้อโดนบัง */
  .m-section[id], .m-app [id] { scroll-margin-top: 76px; }

  /* 7 · การ์ดท้ายหน้า */
  .m-foot-card {
    background: linear-gradient(150deg, var(--c30-deep), var(--c30)); color: #fff;
    border-radius: var(--r-xl); padding: 22px 18px; text-align: center;
  }
  .m-foot-logo {
    width: 52px; height: 52px; margin: 0 auto 10px; border-radius: 16px;
    background: rgba(255,255,255,.16); display: grid; place-items: center; overflow: hidden;
  }
  .m-foot-logo img { width: 78%; height: 78%; object-fit: contain; }
  .m-foot-card b { display: block; font-family: var(--font-display); font-size: 14.5px; }
  .m-foot-card p { font-size: 12.5px; color: rgba(255,255,255,.78); margin: 4px 0 14px; }
  .m-foot-links { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
  .m-foot-card small { font-size: 11px; color: rgba(255,255,255,.6); }

  .btn-app-ghost {
    display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
    padding: 9px 16px; border-radius: var(--r-full); text-decoration: none; font-size: 13px;
    background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.24); color: #fff;
  }

  /* แถบนำทางล่าง */
  .m-bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    display: flex; justify-content: space-around; align-items: flex-end;
    background: color-mix(in srgb, var(--c60-raise) 94%, transparent);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .m-nav-item {
    /* flex-basis 0 + min-width 0 = ทุกช่องกว้างเท่ากันเสมอ ไม่ว่าข้อความจะยาวแค่ไหน
       (ถ้าปล่อย min-width:auto ช่องที่ข้อความยาวจะดันช่องอื่นตกขอบจอ) */
    position: relative; flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    min-height: 46px; padding: 6px 4px; border: 0; background: none; cursor: pointer;
    font-family: var(--font-body); font-size: 10.5px; color: var(--ink-muted); text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  .m-nav-item i { font-size: 19px; }
  .m-nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-nav-item:active { transform: scale(.94); }
  .m-nav-item.is-active { color: var(--c30); }
  .m-nav-item.is-active::before {
    content: ""; position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
    width: 26px; height: 3px; background: var(--c10); border-radius: 0 0 4px 4px;
  }
  .m-nav-item-fab { margin-top: -24px; }
  .m-nav-fab {
    width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--c10), var(--c10-deep)); color: #451a03;
    font-size: 23px; border: 4px solid var(--c60-raise);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--c10) 45%, transparent);
  }
  .m-nav-item-fab .m-nav-fab-label { font-size: 10.5px; margin-top: 2px; }

  /* แผ่นเมนูด้านล่าง */
  .m-sheet { position: fixed; inset: 0; z-index: 90; pointer-events: none; }
  .m-sheet.is-open { pointer-events: auto; }
  .m-sheet-backdrop {
    position: absolute; inset: 0; opacity: 0;
    background: rgba(15,23,42,.55); backdrop-filter: blur(3px);
    transition: opacity .3s var(--ease);
  }
  .m-sheet.is-open .m-sheet-backdrop { opacity: 1; }
  .m-sheet-content {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: var(--c60-raise); border-radius: 24px 24px 0 0;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
    max-height: 82dvh; overflow-y: auto;
    transform: translateY(100%); transition: transform .32s var(--ease);
  }
  .m-sheet.is-open .m-sheet-content { transform: none; }
  .m-sheet-handle {
    display: block; width: 46px; height: 4px; border-radius: 2px;
    background: var(--line-strong); margin: 6px auto 12px;
  }
  .m-sheet-content h3 {
    font-family: var(--font-display); font-size: 15px; color: var(--ink);
    display: flex; align-items: center; gap: 8px; margin: 0 0 12px;
  }
  .m-sheet-content h3 i { color: var(--c30); }
  .m-sheet-list { display: grid; gap: 6px; margin-bottom: 14px; }
  .m-sheet-list a {
    display: flex; align-items: center; gap: 12px; min-height: 52px;
    padding: 8px 12px; border-radius: var(--r); text-decoration: none;
    color: var(--ink-2); font-size: 14px; border: 1px solid var(--line);
    background: var(--c60-sink);
  }
  .m-sheet-list a:active { background: var(--c30-wash); }
  .m-sheet-list a > i { color: var(--ink-faint); font-size: 14px; }
  .m-sheet-ico {
    width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
    background: color-mix(in srgb, var(--c) 13%, transparent); color: var(--c); font-size: 17px;
    flex: 0 0 auto;
  }
  .m-sheet-close { width: 100%; justify-content: center; background: var(--c60-sink); border-color: var(--line); color: var(--ink-2); }
}

/* จอใหญ่: ไม่ต้องโหลดภาพพื้นหลังของการ์ดมือถือ */
@media (min-width: 769px) {
  .m-app, .m-bottom-nav, .m-sheet { display: none !important; }
}

/* ══════════════════════════════════════════════════════════════════════
   App Launcher (Waffle Grid) — ทางลัดแบบ Google apps + overflow menu ของ navbar
   ══════════════════════════════════════════════════════════════════════ */
.applauncher { position: relative; flex: 0 0 auto; }
.applauncher-btn {
  width: 42px; height: 42px; border-radius: var(--r); cursor: pointer;
  display: grid; place-items: center;
  background: var(--c60-raise); border: 1px solid var(--line); color: var(--ink-muted);
  transition: background .2s var(--ease), border-color .2s var(--ease), transform .16s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.applauncher-btn:active { transform: scale(.93); }
@media (hover: hover) { .applauncher-btn:hover { background: var(--c30-wash); border-color: var(--c30-soft); } }
.applauncher.is-open .applauncher-btn { background: var(--c30-wash); border-color: var(--c30-soft); color: var(--c30); }

.waffle { display: grid; grid-template-columns: repeat(3, 4px); gap: 3px; }
.waffle i { width: 4px; height: 4px; border-radius: 1px; background: currentColor; transition: transform .2s var(--ease); }
.applauncher.is-open .waffle i:nth-child(odd) { transform: scale(1.25); }

.applauncher-panel {
  position: absolute; top: calc(100% + 12px); right: 0; z-index: 70;
  width: min(340px, calc(100vw - 32px));
  background: color-mix(in srgb, var(--c60-raise) 96%, transparent);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 14px; transform-origin: top right;
  opacity: 0; visibility: hidden; transform: scale(.94) translateY(-6px);
  transition: opacity .2s var(--ease), transform .2s var(--ease), visibility .2s;
}
.applauncher.is-open .applauncher-panel { opacity: 1; visibility: visible; transform: none; }
.applauncher-panel::before {
  content: ""; position: absolute; top: -7px; right: 15px;
  width: 12px; height: 12px; transform: rotate(45deg);
  background: inherit; border-left: 1px solid var(--line); border-top: 1px solid var(--line);
}
.applauncher-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.applauncher-grid a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 12px 6px; border-radius: var(--r); text-decoration: none;
  transition: background .18s var(--ease), transform .18s var(--ease);
}
@media (hover: hover) { .applauncher-grid a:hover { background: var(--c60-sink); transform: translateY(-2px); } }
.applauncher-grid a:active { transform: scale(.95); }
.applauncher-ico {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  font-size: 19px; color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 20%, transparent);
  transition: transform .2s var(--ease);
}
@media (hover: hover) { .applauncher-grid a:hover .applauncher-ico { transform: rotate(-5deg) scale(1.05); } }
.applauncher-label {
  font-size: 11px; line-height: 1.3; text-align: center; color: var(--ink-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.applauncher-badge {
  position: absolute; top: 6px; right: 12px;
  background: var(--bad-500); color: #fff; font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: var(--r-full);
}

/* ★ จอแคบ: ปุ่ม waffle ไม่ได้อยู่ชิดขอบขวาของจอ (มีปุ่มเข้าสู่ระบบต่อท้าย)
   การยึด right:0 กับตัวปุ่มจึงดันแผงกว้าง 340px ทะลุขอบซ้ายจนไอคอนโดนตัด
   → เปลี่ยนเป็นยึดกับ "จอ" แทน แล้ววางใต้แถบนำทางที่ปักอยู่ */
@media (max-width: 640px) {
  .applauncher-panel {
    position: fixed;
    top: calc(70px + 8px + env(safe-area-inset-top));
    left: 10px; right: 10px; width: auto;
    max-height: calc(100dvh - 96px - env(safe-area-inset-top)); overflow-y: auto;
    transform-origin: top center;
  }
  .applauncher-panel::before { display: none; }   /* ลูกศรชี้ปุ่มไม่ตรงแล้วเมื่อยึดกับจอ */
  .applauncher-grid { grid-template-columns: repeat(4, 1fr); }
  .applauncher-ico { width: 40px; height: 40px; border-radius: 13px; font-size: 17px; }
  .applauncher-label { font-size: 10.5px; }
}

/* ★ Overflow: จอกลาง ๆ ที่เมนูเริ่มเบียด → ซ่อนลิงก์ในแถบ เหลือ waffle ปุ่มเดียว
   (ตั้ง breakpoint "ก่อน" จุดที่เริ่มเบียดจริง เผื่อข้อความปุ่มยาวสุด) */
@media (max-width: 1080px) {
  .site-nav-link { display: none !important; }
}

/* ══════════════════════════════════════════════════════════════════════
   คลื่นไหล WebGL บนส่วนหัว — progressive enhancement
   ไม่มี WebGL / JS ปิด / ลดการเคลื่อนไหว → canvas ไม่ถูกวาด พื้นหลังเดิมยังอยู่ครบ
   ══════════════════════════════════════════════════════════════════════ */
.hero-wave {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; pointer-events: none; z-index: 0;
  opacity: 0; transition: opacity 1.1s var(--ease);
}
.hero-wave.is-live { opacity: .85; }
/* มีภาพถ่ายอยู่แล้ว → ลดความเข้มลง ไม่ให้กลบภาพที่ผู้ดูแลตั้งใจใส่ */
.site-hero.has-image .hero-wave.is-live { opacity: .42; mix-blend-mode: screen; }
.site-hero-grid { position: relative; z-index: 1; }
@media (prefers-reduced-motion: reduce) { .hero-wave { display: none; } }

/* ══ หน้าจัดการเส้นทาง API ══════════════════════════════════════════════ */
.ep-list { display: grid; gap: 10px; }
.ep-item {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--c60-raise); transition: border-color .2s var(--ease), opacity .2s var(--ease);
}
.ep-item:hover { border-color: var(--c30-soft); }
.ep-item.is-off { opacity: .55; background: var(--c60-sink); }
.ep-info { flex: 1 1 260px; min-width: 0; }
.ep-path { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.ep-method {
  font-family: var(--font-display); font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 6px;
  background: color-mix(in srgb, var(--ok-500) 14%, transparent); color: var(--ok-700);
}
.ep-path code {
  font-size: 13px; color: var(--ink); background: var(--c60-sink);
  padding: 2px 8px; border-radius: 7px; border: 1px solid var(--line);
}
.ep-query { font-size: 11.5px; color: var(--ink-faint); }
.ep-info p { margin: 5px 0 0; font-size: 12.5px; color: var(--ink-muted); }

/* สวิตช์เปิด/ปิดรายเส้นทาง */
.ep-switch { flex: 0 0 auto; display: inline-flex; cursor: pointer; }
.ep-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.ep-track {
  width: 46px; height: 26px; border-radius: var(--r-full); padding: 3px;
  background: var(--line-strong); display: block;
  transition: background .22s var(--ease);
}
.ep-knob {
  width: 20px; height: 20px; border-radius: 50%; background: #fff; display: block;
  box-shadow: var(--shadow-sm); transition: transform .22s var(--ease);
}
.ep-switch input:checked + .ep-track { background: var(--ok-500); }
.ep-switch input:checked + .ep-track .ep-knob { transform: translateX(20px); }
.ep-switch input:focus-visible + .ep-track { outline: 2px solid var(--c30); outline-offset: 2px; }

.code-box {
  background: var(--brand-950); color: #e2e8f0; border-radius: var(--r);
  padding: 13px 14px; font-size: 12px; line-height: 1.7; overflow-x: auto;
  margin: 0 0 10px; white-space: pre;
}
.ip-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ip-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ip-list code { font-size: 12px; color: var(--ink-2); background: var(--c60-sink); padding: 2px 7px; border-radius: 6px; }
.ip-list b { font-family: var(--font-display); color: var(--c30); }
.ip-list i { font-style: normal; font-size: 11.5px; color: var(--ink-faint); min-width: 58px; text-align: right; }

@media (max-width: 560px) {
  .ep-item { gap: 10px; }
  .ep-item .btn-group { width: 100%; justify-content: flex-end; }
}

/* ─────────────────────────────────────────────────────────────
   Color Timeline (ctl-) — เส้นทางกลุ่มสีรายโรงเรียนย้อนหลัง
   ใช้เฉพาะหน้า "รายงานผลการพัฒนาตามสี" (report-progression)
   ───────────────────────────────────────────────────────────── */
.ctl-line {
  display: flex; align-items: flex-start; gap: 0;
  flex-wrap: nowrap; overflow-x: auto; padding: 2px 0 1px;
  scrollbar-width: thin;
}
.ctl-node {
  position: relative; flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  min-width: 46px; padding: 0 3px;
}
/* เส้นเชื่อมระหว่างปี — วาดจากจุดก่อนหน้าไปยังจุดนี้ */
.ctl-node + .ctl-node::before {
  content: ""; position: absolute; top: 10px; right: 50%; left: -50%;
  height: 2px; background: var(--line); z-index: 0;
}
.ctl-node > i {
  position: relative; z-index: 1;
  width: 21px; height: 21px; border-radius: 50%;
  background: var(--c, var(--line-strong));
  box-shadow: 0 0 0 3px var(--surface), 0 2px 6px rgba(15, 23, 42, .18);
  transition: transform .2s var(--ease);
}
.ctl-node > em {
  font-style: normal; font-size: 11px; font-weight: 600;
  color: var(--ink-muted); font-variant-numeric: tabular-nums;
}
.ctl-node.is-empty > i {
  background: transparent; border: 2px dashed var(--line-strong);
  box-shadow: 0 0 0 3px var(--surface);
}
.ctl-node.is-empty > em { color: var(--ink-faint); }
.ctl-node:hover > i { transform: scale(1.18); }

/* ป้ายทิศทางการพัฒนา */
.ctl-dir {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: var(--r-full);
  font-family: var(--font-display); font-size: 12.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.ctl-dir.is-up   { background: var(--ok-50);   color: var(--ok-700);   border-color: #a7f3d0; }
.ctl-dir.is-down { background: var(--bad-50);  color: var(--bad-700);  border-color: #fecaca; }
.ctl-dir.is-same { background: var(--info-50); color: var(--info-700); border-color: #bfdbfe; }
.ctl-dir.is-none { background: var(--c60-sink); color: var(--ink-muted); border-color: var(--line); }

/* จอแคบ — ตารางกลายเป็นการ์ด เส้นทางสีเลื่อนแนวนอนได้ */
@media (max-width: 768px) {
  .ctl-table .ctl-line { justify-content: flex-start; width: 100%; }
  .ctl-node { min-width: 44px; }
}

@media print {
  .ctl-node > i { box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .ctl-dir { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .ctl-line { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .ctl-node > i { transition: none; }
  .ctl-node:hover > i { transform: none; }
}

/* ─────────────────────────────────────────────────────────────
   Print Document (pd-) — ฉบับพิมพ์ระดับเอกสารราชการ
   ใช้กับหน้ารายงานที่ include partials/print-doc + print-sign
   ทุกอย่างซ่อนบนจอ ปรากฏเฉพาะตอนสั่งพิมพ์
   ───────────────────────────────────────────────────────────── */
.pd-only { display: none !important; }
.pd-cell { display: none; }
.table tfoot.pd-foot-row { display: none; }

@media print {
  /* ── หน้ากระดาษ ── (ขอบล่างเผื่อแถบท้ายกระดาษที่ซ้ำทุกหน้า) */
  @page { size: A4 portrait; margin: 14mm 12mm 24mm; }

  body { background: #fff; font-family: 'Sarabun', 'Kanit', sans-serif; font-size: 11px; color: #0f172a; }

  .pd-only { display: block !important; }
  th.pd-cell, td.pd-cell { display: table-cell !important; }

  /* ── ตราครุฑ/โลโก้ + ชื่อหน่วยงาน ── */
  .pd-head { margin: 0 0 6mm; }
  .pd-letter { display: flex; align-items: center; gap: 10px; }
  .pd-logo { width: 52px; height: 52px; object-fit: contain; flex: 0 0 auto; }
  .pd-org { min-width: 0; }
  .pd-org b {
    display: block; font-family: 'Kanit', sans-serif; font-size: 14.5px;
    font-weight: 600; color: #0f172a; line-height: 1.35;
  }
  .pd-org span { display: block; font-size: 9.5px; color: #475569; line-height: 1.5; }

  /* เส้นคู่ใต้หัวจดหมาย — แบบเอกสารราชการ */
  .pd-rule { border-top: 2px solid #1e3a8a; border-bottom: 0.6px solid #1e3a8a; height: 2.4px; margin: 4mm 0 5mm; }

  .pd-title { text-align: center; margin-bottom: 3mm; }
  .pd-title h1 { font-family: 'Kanit', sans-serif; font-size: 18px; font-weight: 600; margin: 0; letter-spacing: .2px; }
  .pd-title p { font-size: 11.5px; color: #475569; margin: 2mm 0 0; }

  .pd-bar {
    display: flex !important; justify-content: space-between; gap: 6px; flex-wrap: wrap;
    font-size: 9.5px; color: #334155;
    border: 0.6px solid #cbd5e1; background: #f8fafc; border-radius: 3px; padding: 2mm 3mm;
  }
  .pd-bar b, .pd-meta b { font-weight: 600; color: #0f172a; }
  .pd-meta { font-size: 9.5px; color: #334155; margin-top: 2mm; line-height: 1.7; }

  /* ── ลายน้ำ (ซ้ำทุกหน้า) ── */
  .pd-mark {
    position: fixed; top: 45%; left: 0; right: 0; z-index: 0;
    text-align: center; font-family: 'Kanit', sans-serif; font-size: 62px; font-weight: 700;
    color: #1e3a8a; opacity: .035; transform: rotate(-20deg); pointer-events: none;
  }

  /* ── ส่วนหัวเดิมของหน้าจอ: เหลือเฉพาะแถบตัวเลขสรุป ── */
  .pd-head ~ .hero {
    background: #fff !important; border: 0 !important; box-shadow: none !important;
    padding: 0 !important; margin: 0 0 5mm !important; color: #0f172a !important;
  }
  .pd-head ~ .hero::before, .pd-head ~ .hero::after { display: none !important; }
  .pd-head ~ .hero > .hero-eyebrow,
  .pd-head ~ .hero > h1,
  .pd-head ~ .hero > p { display: none !important; }
  .pd-head ~ .hero .kpi-strip {
    display: grid !important; grid-template-columns: repeat(6, 1fr); gap: 0;
    border: 0.6px solid #94a3b8; border-radius: 3px; overflow: hidden;
  }
  .pd-head ~ .hero .kpi {
    background: #fff !important; border: 0 !important; border-right: 0.6px solid #cbd5e1 !important;
    border-radius: 0 !important; padding: 2.5mm 1.5mm !important; text-align: center;
  }
  .pd-head ~ .hero .kpi:last-child { border-right: 0 !important; }
  .pd-head ~ .hero .kpi-label { font-size: 8.5px !important; color: #475569 !important; justify-content: center; }
  .pd-head ~ .hero .kpi-value { font-size: 16px !important; color: #0f172a !important; }
  .pd-head ~ .hero .kpi-sub   { font-size: 8px !important; color: #64748b !important; }

  /* ── ตัวควบคุมหน้าจอที่ไม่ต้องพิมพ์ ── */
  .chip-group, .search-wrap, .alert, .modal, [data-filter-empty], .ctl-only { display: none !important; }

  /* ── การ์ด/กราฟ ── */
  /* การ์ดที่มีตารางยาวต้องไหลข้ามหน้าได้ (ถ้า avoid ทั้งก้อนจะดันขึ้นหน้าใหม่แล้วเหลือหน้าว่าง) */
  .card { border: 0.6px solid #cbd5e1 !important; border-radius: 4px; margin-bottom: 4mm; break-inside: auto; }
  /* การ์ดที่ไม่มีตารางยาว ควรอยู่ครบในหน้าเดียว */
  .card:not(:has(.table-wrap)) { break-inside: avoid; }
  .card-head { padding: 2mm 3mm !important; background: #f8fafc !important; border-bottom: 0.6px solid #cbd5e1 !important; }
  .card-head h2 { font-size: 12px !important; }
  .card-head .small, .card-head .muted, .card-head .badge { font-size: 8.5px !important; }
  .card-body { padding: 3mm !important; }
  .chart { max-height: 52mm; }
  .chart-legend { font-size: 8.5px; gap: 6px; margin-top: 4px; }
  [data-chart] { break-inside: avoid; }
  /* กราฟสองใบวางคู่กันเพื่อไม่ให้กินหน้ากระดาษเกินจำเป็น */
  .grid { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 4mm !important; align-items: start; }

  /* ── ตารางเอกสาร ──
     ⚠ จอแคบกว่า 820px ระบบจะแปลงตารางเป็นการ์ด — ความกว้าง A4 เข้าเงื่อนไขนั้นด้วย
     จึงต้องบังคับให้กลับเป็นตารางจริงเสมอตอนพิมพ์ (selector ต้องชนะกฎของจอมือถือ) */
  .table { display: table !important; font-size: 10px; border-collapse: collapse; width: 100%; }
  .table tbody { display: table-row-group !important; }
  .table tbody tr {
    display: table-row !important;
    background: transparent !important; border: 0 !important; border-radius: 0 !important;
    margin: 0 !important; padding: 0 !important; box-shadow: none !important;
  }
  .table tbody td {
    display: table-cell !important; text-align: left;
  }
  .table tbody td::before { display: none !important; }
  .table tbody td.num, .table tbody td.tabular { text-align: right; }
  /* คอลัมน์ที่ไม่ต้องพิมพ์ — specificity ต้องสูงกว่ากฎ .table tbody td ข้างบน */
  .table td.no-print, .table th.no-print,
  .table td.actions, .table th.actions,
  .table td.ctl-only, .table th.ctl-only { display: none !important; }
  .table thead { display: table-header-group !important; }
  .table thead th {
    background: #eef2f7 !important; border: 0.6px solid #94a3b8 !important;
    padding: 1.6mm 2mm !important; font-size: 9.5px; font-weight: 600; text-align: left;
  }
  .table tbody td { border: 0.6px solid #cbd5e1 !important; padding: 1.4mm 2mm !important; vertical-align: middle; }
  .table tbody tr { break-inside: avoid; page-break-inside: avoid; }
  .table tbody td .small { font-size: 8.5px; }

  /* ลำดับที่ */
  td.pd-no, th.pd-no { text-align: center; width: 9mm; font-variant-numeric: tabular-nums; }

  /* เซลล์กลุ่มสีรายปี — มีทั้งจุดสีและตัวอักษร อ่านออกแม้พิมพ์ขาวดำ */
  td.pd-cell { white-space: nowrap; font-size: 9.5px; }
  .pd-dot {
    display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    background: var(--c, #94a3b8); margin-right: 3px; vertical-align: middle;
    border: 0.4px solid rgba(15, 23, 42, .25);
  }
  .pd-none { color: #94a3b8; }

  /* ── ช่องลงนาม ── */
  .pd-signs {
    display: flex !important; gap: 6mm; margin: 10mm 0 0;
    break-inside: avoid; page-break-inside: avoid;
  }
  /* เว้นท้ายเอกสารให้พ้นแถบท้ายกระดาษที่ตรึงอยู่ทุกหน้า */
  .pd-signs:last-child { margin-bottom: 14mm; }
  .pd-sign { flex: 1 1 0; text-align: center; font-size: 10px; line-height: 2.1; }
  .pd-sign-role { display: block; font-weight: 600; font-family: 'Kanit', sans-serif; margin-bottom: 6mm; }
  .pd-sign-line { display: block; }
  .pd-sign-name { display: block; }
  .pd-sign-pos  { display: block; font-size: 9px; color: #475569; }
  .pd-sign-date { display: block; font-size: 9px; color: #64748b; margin-top: 1mm; }
  .pd-sign-note { font-size: 8.5px; color: #64748b; text-align: center; margin: 6mm 0 14mm; }

  /* ── ท้ายกระดาษ ──
     Chrome วาง position:fixed ซ้ำทุกหน้าก็จริง แต่ถ้าดันออกนอกพื้นที่พิมพ์จะไปโผล่ผิดหน้า
     และถ้าวางในพื้นที่พิมพ์ก็ทับแถวสุดท้าย → ใช้ <tfoot> ที่เบราว์เซอร์ทำซ้ำท้ายทุกหน้า
     และกินพื้นที่จริงแทน ส่วน .pd-foot เป็นแถบปิดท้ายเอกสารครั้งเดียว */
  .table tfoot.pd-foot-row { display: table-footer-group !important; }
  .table tfoot.pd-foot-row td {
    border: 0 !important; border-top: 0.6px solid #cbd5e1 !important;
    padding: 1.2mm 0 0 !important; font-size: 8px; color: #94a3b8;
  }
  .table tfoot.pd-foot-row td span:last-child { float: right; }

  .pd-foot {
    display: flex !important; justify-content: space-between; gap: 8px;
    margin-top: 6mm; padding-top: 1.5mm;
    font-size: 8.5px; color: #64748b; border-top: 0.6px solid #cbd5e1;
  }

  /* สีต้องพิมพ์ออกทุกชิ้น */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ─────────────────────────────────────────────────────────────
   คู่มือการใช้งาน — การ์ดหน้าสาธารณะ (manual-) และรายการหลังบ้าน (mn-)
   ───────────────────────────────────────────────────────────── */
.manual-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.manual {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 20px; box-shadow: var(--shadow-xs);
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}
.manual:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--brand-200); }

/* ตราชนิดไฟล์ — สีประจำชนิดทำให้กวาดตาหาได้เร็ว */
.manual-file, .mn-file {
  flex: 0 0 auto; width: 54px; height: 62px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--c60-sink); color: var(--ink-muted);
  border: 1px solid var(--line);
}
.manual-file i, .mn-file i { font-size: 24px; line-height: 1; }
.manual-file em, .mn-file em {
  font-style: normal; font-size: 9.5px; font-weight: 700; letter-spacing: .06em;
  font-family: var(--font-display);
}
.mn-file-pdf  { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.mn-file-docx { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.mn-file-xlsx { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.mn-file-pptx { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }
.mn-file-jpg, .mn-file-jpeg, .mn-file-png, .mn-file-webp, .mn-file-gif {
  background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe;
}

.manual-body { flex: 1 1 auto; min-width: 0; }
.manual-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; color: var(--brand-700);
  background: var(--brand-50); border: 1px solid var(--brand-100);
  padding: 3px 10px; border-radius: var(--r-full); margin-bottom: 9px;
}
.manual-body h3 {
  font-size: 16.5px; margin: 0 0 6px; line-height: 1.45;
  font-family: var(--font-display); color: var(--ink);
}
.manual-body p { font-size: 13.5px; color: var(--ink-muted); margin: 0 0 10px; line-height: 1.65; }
.manual-meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--ink-faint); }
.manual-meta span { display: inline-flex; align-items: center; gap: 4px; }
.manual-actions { display: flex; gap: 8px; }
.manual-actions .btn:first-child { flex: 1 1 auto; justify-content: center; }

/* ── หลังบ้าน ── */
.mn-admin-list { display: grid; gap: 12px; }
.mn-admin-item {
  display: flex; align-items: flex-start; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px;
  transition: border-color var(--t), box-shadow var(--t);
}
.mn-admin-item:hover { border-color: var(--brand-200); box-shadow: var(--shadow-xs); }
.mn-admin-item.is-editing { border-color: var(--brand-400); box-shadow: 0 0 0 3px var(--brand-50); }
.mn-admin-info { flex: 1 1 auto; min-width: 0; }
.mn-admin-info b { display: block; font-family: var(--font-display); font-size: 14.5px; color: var(--ink); }
.mn-admin-info > span {
  display: block; font-size: 12.5px; color: var(--ink-muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.mn-admin-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mn-current {
  display: flex; align-items: center; gap: 12px;
  background: var(--c60-sink); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 10px 12px; margin-bottom: 10px;
}
.mn-current b { display: block; font-size: 13px; word-break: break-all; }

@media (max-width: 560px) {
  .mn-admin-item { flex-wrap: wrap; }
  .mn-admin-item .btn-group { width: 100%; justify-content: flex-end; }
  .manual-actions { flex-wrap: wrap; }
}

/* การ์ดคู่มือในโหมดแอปมือถือ */
.m-manual {
  flex: 0 0 auto; width: 172px; scroll-snap-align: start;
  display: flex; flex-direction: column; gap: 7px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px; text-decoration: none;
  box-shadow: var(--shadow-xs);
}
.m-manual:active { transform: scale(.97); }
.m-manual b {
  font-family: var(--font-display); font-size: 13.5px; line-height: 1.45; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.m-manual-tag {
  font-size: 10.5px; color: var(--brand-700); background: var(--brand-50);
  border-radius: var(--r-full); padding: 2px 8px; align-self: flex-start;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.m-manual small { font-size: 11px; color: var(--ink-faint); }
.m-manual-cta {
  margin-top: auto; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; color: var(--brand-700);
  min-height: 24px;
}

/* หน้าอัปเดตฐานข้อมูล — ผลการทำงานของ migration */
.run-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px 18px; font-size: 13.5px; }
.run-list li { display: inline-flex; align-items: center; gap: 7px; }
.run-item {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 9px 12px; border-radius: var(--r-sm); font-size: 13px;
  background: var(--c60-sink); border: 1px solid var(--line);
}
.run-item i { margin-top: 2px; flex: 0 0 auto; }
.run-item span { min-width: 0; word-break: break-word; }
.run-item b { display: block; font-family: var(--font-display); font-size: 13.5px; }
.run-item em { display: block; font-style: normal; font-size: 12px; margin-top: 3px; opacity: .9; }
.run-item.is-ok   { background: var(--ok-50);  border-color: #a7f3d0; color: var(--ok-700); }
.run-item.is-fail { background: var(--bad-50); border-color: #fecaca; color: var(--bad-700); }
.mg-name { font-size: 12px; color: var(--ink-2); background: var(--c60-sink); padding: 3px 8px; border-radius: 6px; }
