/* ═══════════════════════════════════════════════════════════════════════════
   ui.css — ระบบออกแบบกลางของ LLT Backend (ทุกหน้า/ทุกโมดูลใช้ร่วมกัน)
   โลกดีไซน์ "การ์ดดำพรีเมียม" (เริ่มที่ Finance ต.ค. 69 → ขยายทั้งแอป พ.ย. 69):
   พื้นเทาอ่อนแบบแอป · การ์ดขาวลอยไม่มีขอบ · ดำ = ปุ่มหลัก/เมนูที่เลือก/การ์ดตัวเลขหลัก
   ปุ่ม/ตัวเลือกทรงแคปซูล · เขียว = เงินเข้า/ปกติ · แดง = เตือนเท่านั้น
   อ่านกติกาเต็มที่ DESIGN.md · ไอคอน: public/icons.svg (Lucide) + icon() ใน public/js/ui.js
   ทั้งไฟล์อยู่ใน @layer ui → CSS ของแต่ละโมดูล (ไม่มี layer) ชนะเสมอ ไม่ต้องสู้ specificity
   ═══════════════════════════════════════════════════════════════════════════ */
@layer ui {

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  /* พื้น/ตัวหนังสือ — เทาเย็นแบบแอป Apple */
  --bg: oklch(0.971 0.0027 286);          /* พื้นแอป */
  --surface: oklch(1 0 0);                /* การ์ด */
  --surface-2: oklch(0.962 0.0027 286);   /* ช่องกรอก / ปุ่มในการ์ด / ไอคอนวงกลม */
  --surface-3: oklch(0.935 0.004 286);    /* hover / รางตัวเลือกแบบแบ่งช่อง */
  --ink: oklch(0.179 0.0041 286);
  --ink-2: oklch(0.349 0.0034 286);
  --muted: oklch(0.54 0.0077 286);        /* ≥4.6:1 บนพื้นแอป */
  --line: oklch(0.944 0.004 286);
  --line-strong: oklch(0.896 0.0054 286);

  /* ดำ (การ์ดตัวเลขหลัก · ปุ่มหลัก · เมนูที่เลือก) */
  --black: oklch(0.192 0.004 286);
  --black-strong: oklch(0.12 0.003 286);
  --on-black: oklch(0.975 0.002 286);
  --on-black-2: oklch(0.717 0.0072 286);  /* ตัวหนังสือรองบนการ์ดดำ */
  --on-black-3: oklch(0.635 0.0089 286);  /* หมายเหตุบนการ์ดดำ */
  --on-black-soft: oklch(0.871 0.0055 286);
  --good-on-black: oklch(0.805 0.0984 159);
  --bad-on-black: oklch(0.79 0.0916 26);
  --champagne: oklch(0.689 0.0877 80);    /* เส้นทองบนการ์ดดำ + จุดเมนู เท่านั้น */
  --champagne-tint: oklch(0.899 0.0338 82);
  --chart-out: oklch(0.856 0.0068 286);    /* แท่งรองในกราฟ (เทาอ่อน) */

  /* แบรนด์ LLT (ทอง — ใช้น้อยมาก: ป้าย/แจ้งเตือนเฉพาะจุด) */
  --gold: oklch(0.84 0.17 85);
  --gold-strong: oklch(0.78 0.16 80);
  --gold-tint: oklch(0.965 0.045 90);

  /* สีสถานะ (ข้อความ/เส้น ใช้ตัวเข้ม · พื้นใช้ -tint) */
  --success: oklch(0.515 0.1102 157);
  --success-tint: oklch(0.957 0.0141 162);
  --warning: oklch(0.509 0.1025 71);
  --warning-tint: oklch(0.961 0.0261 82);
  --danger: oklch(0.535 0.1475 27);
  --danger-strong: oklch(0.46 0.14 27);
  --danger-tint: oklch(0.952 0.0133 29);
  --info: oklch(0.489 0.1101 260);
  --info-tint: oklch(0.96 0.012 260);

  /* สีหลักของปุ่ม/ตัวเลือก = ดำ ทุกโมดูล (เลิกสีประจำโมดูล พ.ย. 69 — แยกโมดูลด้วยไอคอน + ชื่อ) */
  --accent: var(--black);
  --accent-strong: var(--black-strong);
  --accent-ink: oklch(1 0 0);
  --accent-tint: var(--surface-2);
  --accent-line: var(--line-strong);

  /* ตัวอักษร */
  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --fs-xs: 0.75rem;   /* 12 */
  --fs-sm: 0.8125rem; /* 13 */
  --fs-md: 0.875rem;  /* 14 — ข้อความในตาราง/ฟอร์ม */
  --fs-base: 0.9375rem; /* 15 — body */
  --fs-lg: 1.0625rem; /* 17 */
  --fs-xl: 1.25rem;   /* 20 */
  --fs-2xl: 1.5rem;   /* 24 */

  /* ระยะ/มุม/เงา */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --r-sm: 10px; --r: 14px; --r-lg: 24px; --r-xl: 28px;
  --shadow-sm: 0 1px 2px oklch(0.18 0.004 286 / 0.05);
  --shadow: 0 1px 2px oklch(0.18 0.004 286 / 0.04), 0 8px 24px oklch(0.18 0.004 286 / 0.06);
  --shadow-hover: 0 1px 2px oklch(0.18 0.004 286 / 0.05), 0 12px 30px oklch(0.18 0.004 286 / 0.09);
  --shadow-lg: 0 2px 6px oklch(0.18 0.004 286 / 0.06), 0 24px 48px oklch(0.18 0.004 286 / 0.16);
  --shadow-black: inset 0 1px 0 oklch(1 0 0 / 0.11), 0 2px 4px oklch(0.18 0.004 286 / 0.06), 0 20px 44px oklch(0.18 0.004 286 / 0.2);
  --shadow-press: inset 0 1px 0 oklch(1 0 0 / 0.12), 0 6px 16px oklch(0.18 0.004 286 / 0.2);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 120ms; --t: 180ms;

  /* ลำดับชั้น */
  --z-sticky: 20; --z-dropdown: 30; --z-backdrop: 40; --z-modal: 50; --z-toast: 60;

  --header-h: 0px;      /* ไม่มีแถบบนติดจอ (หัวตารางติดบนสุดได้) */
  --content-w: 1280px;
  --side-w: 240px;      /* เมนูข้าง (จอคอม) */
  --tabbar-h: 66px;     /* แถบเมนูล่าง (มือถือ) */

  color-scheme: light;
  scrollbar-color: var(--line-strong) transparent;
}

/* ── Base ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  font-family: var(--font); font-size: var(--fs-base); line-height: 1.6;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 600; letter-spacing: -0.005em; text-wrap: balance; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-base); }
p { margin: 0; }
a { color: inherit; }
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
code, kbd, .mono { font-family: var(--font-mono); font-size: 0.92em; }
.num, .tnum { font-variant-numeric: tabular-nums; }
::selection { background: var(--champagne-tint); color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 10px; }
[hidden] { display: none !important; }
.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; }

/* ── Icon ── <svg class="i"><use href="/public/icons.svg#name"/></svg> ── */
.i { width: 1.15em; height: 1.15em; flex: none; display: inline-block; vertical-align: -0.2em;
     fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 14px; height: 14px; }
.i-md { width: 18px; height: 18px; }
.i-lg { width: 22px; height: 22px; }
.i-xl { width: 28px; height: 28px; }
.spin { animation: ui-spin 0.9s linear infinite; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* ── แถบบนแบบเดิม (หน้าที่ยังไม่ย้ายเข้าโครงแอปใหม่) ───────────────────────── */
.app-bar { position: sticky; top: 0; z-index: var(--z-sticky); background: color-mix(in oklch, var(--bg) 92%, transparent); backdrop-filter: saturate(1.4) blur(14px); }
.app-bar-inner {
  max-width: var(--content-w); margin: 0 auto; height: 64px;
  padding: 0 var(--sp-6); display: flex; align-items: center; gap: var(--sp-4);
}
.app-brand { display: flex; align-items: center; gap: var(--sp-3); text-decoration: none; color: var(--ink); min-width: 0; }
.app-mark {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--black); color: var(--on-black);
  font-weight: 700; font-size: 16px; letter-spacing: -0.02em;
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.14), 0 4px 12px oklch(0.18 0.004 286 / 0.18);
}
.app-mark.is-module { background: var(--black); color: var(--on-black); }
.app-mark .i { width: 20px; height: 20px; stroke-width: 1.75; }
.app-title { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.app-title strong { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-title span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-bar-spacer { flex: 1; }
.app-bar-actions { display: flex; align-items: center; gap: var(--sp-2); }
.app-user { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--ink-2); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; background: var(--surface-3); color: var(--ink-2);
  display: grid; place-items: center; font-weight: 600; font-size: 13px; text-transform: uppercase;
}
.app-user .avatar { width: 32px; height: 32px; }
@media (max-width: 640px) {
  .app-bar-inner { padding: 0 var(--sp-4); gap: var(--sp-2); }
  .app-user .app-user-name, .hide-sm { display: none; }
}

/* ── โครงแอป (ทุกโมดูล) ────────────────────────────────────────────────────
   ≥1024px: เมนูข้างลอย .app-side · <1024px: ไอคอนแอปมุมบน .app-mbar + แถบล่าง .app-tabbar + แผ่น "เพิ่มเติม"
   เมนูสร้างเองจากแท็บเดิมของหน้า (public/js/shell.js) — ดูวิธีใช้ใน DESIGN.md */
.app-side { display: none; }
.app-tile {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--black); color: var(--on-black);
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.14), 0 4px 12px oklch(0.18 0.004 286 / 0.18);
  font-weight: 700; font-size: 16px;
}
.app-tile .i { width: 20px; height: 20px; stroke-width: 1.75; }
.app-side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; text-decoration: none; color: var(--ink); min-width: 0; }
.app-side-brand > span:last-child { min-width: 0; }
.app-side-brand strong { display: block; font-size: 16px; font-weight: 600; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-side-brand small { display: block; font-size: 12px; line-height: 16px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-side-nav { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; display: flex; flex-direction: column; gap: 2px; }
.app-side-nav::-webkit-scrollbar { display: none; }
.app-side-nav a, .app-side-foot .app-side-home {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 14px; border-radius: 14px; flex: none;
  color: var(--ink-2); font-size: 14.5px; font-weight: 500; text-decoration: none;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.app-side-nav a > span:not(.app-count) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-side-nav a .i, .app-side-foot .app-side-home .i { width: 20px; height: 20px; color: var(--muted); stroke-width: 1.75; }
.app-side-nav a:hover, .app-side-foot .app-side-home:hover { background: var(--surface-2); color: var(--ink); }
.app-side-nav a.active { background: var(--black); color: var(--on-black); font-weight: 600; box-shadow: var(--shadow-press); }
.app-side-nav a.active .i { color: var(--on-black); }
.app-side-nav a.active:not(:has(.app-count))::after { content: ""; margin-left: auto; width: 5px; height: 5px; border-radius: 50%; background: var(--champagne); flex: none; }
.app-count {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; flex: none;
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--surface-3); color: var(--ink-2);
}
.app-count.is-alert { background: var(--danger); color: oklch(1 0 0); }
.app-side-nav a.active .app-count:not(.is-alert) { background: oklch(1 0 0 / 0.16); color: var(--on-black); }
.app-side-foot { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; }
.app-me { display: flex; align-items: center; gap: 10px; padding: 8px 6px 8px 10px; border-radius: 18px; background: var(--surface-2); }
.app-me-name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-me-name small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.app-me form { margin: 0; }
.app-me .btn-icon { color: var(--muted); }
.app-me .btn-icon:hover { color: var(--ink); background: var(--surface-3); }

.app-mbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.app-round {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--surface); color: var(--ink-2); box-shadow: var(--shadow); text-decoration: none;
  border: 0; cursor: pointer; transition: box-shadow var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.app-round:hover { box-shadow: var(--shadow-hover); color: var(--ink); }
.app-round .i { width: 19px; height: 19px; stroke-width: 1.75; }

/* แถบเมนูล่าง (มือถือ/แท็บเล็ต) */
.app-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky);
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-radius: 22px 22px 0 0;
  box-shadow: 0 -1px 0 oklch(0.18 0.004 286 / 0.03), 0 -8px 28px oklch(0.18 0.004 286 / 0.07);
}
.app-tabbar:empty { display: none; }
.app-tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 50px; padding: 0 2px; border-radius: 14px; list-style: none; cursor: pointer;
  font-size: 11.5px; line-height: 16px; font-weight: 500; color: var(--muted); text-decoration: none; white-space: nowrap;
  min-width: 0;
}
.app-tab > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.app-tab::-webkit-details-marker { display: none; }
.app-tab .i { width: 23px; height: 23px; stroke-width: 1.7; }
.app-tab.active { color: var(--ink); font-weight: 600; }
.app-tab.active::after { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--champagne); margin-top: 1px; }
.app-tab .app-count { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; font-size: 11px; }
.app-tab-more { position: static; }
.app-tab-more > summary { height: 100%; }
.app-tab-more[open]::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: oklch(0.18 0.004 286 / 0.3); animation: ui-fade var(--t) var(--ease);
}
.app-sheet {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom));
  max-width: 520px; max-height: calc(100vh - var(--tabbar-h) - 40px); overflow-y: auto; margin: 0 auto; padding: 8px; display: grid; gap: 2px;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: ui-sheet-in var(--t) var(--ease);
}
.app-sheet a, .app-sheet button {
  appearance: none; border: 0; background: none; width: 100%; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 14px; min-height: 50px; padding: 0 14px; border-radius: 14px;
  font: inherit; font-size: 15px; font-weight: 500; color: var(--ink-2); text-decoration: none;
}
.app-sheet a > span:not(.app-count), .app-sheet button > span { flex: 1; min-width: 0; }
.app-sheet a .i, .app-sheet button .i { width: 20px; height: 20px; color: var(--muted); stroke-width: 1.75; }
.app-sheet a:hover, .app-sheet button:hover { background: var(--surface-2); color: var(--ink); }
.app-sheet a.active { background: var(--black); color: var(--on-black); font-weight: 600; }
.app-sheet a.active .i { color: var(--on-black); }
.app-sheet hr { border: 0; height: 1px; background: var(--line); margin: 4px 10px; }
@keyframes ui-sheet-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes ui-fade { from { opacity: 0; } to { opacity: 1; } }

/* แท็บเดิมของหน้า: ใช้เป็นต้นทางให้เมนูโครงแอป → ซ่อนเมื่อ shell.js สร้างเมนูแล้ว */
html.shell-ready [data-shell-tabs] { display: none; }

body.has-shell .page { padding-bottom: calc(var(--tabbar-h) + 40px + env(safe-area-inset-bottom)); }
@media (max-width: 1023px) {
  body.has-shell .app-mbar { position: absolute; top: 14px; left: 0; right: 0; z-index: 2; padding: 0 var(--sp-4); pointer-events: none; }
  body.has-shell .app-mbar > * { pointer-events: auto; }
  body.has-shell .page { padding-top: 14px; }
  body.has-shell .page-head > div:first-child { min-height: 40px; padding: 0 52px 0 54px; display: flex; flex-direction: column; justify-content: center; }
  body.has-shell .page-head h1 { font-size: 24px; line-height: 32px; }
}
@media (min-width: 1024px) {
  .app-mbar, .app-tabbar { display: none; }
  .app-side {
    display: flex; flex-direction: column; position: fixed; z-index: var(--z-sticky);
    top: 16px; bottom: 16px; left: 16px; width: var(--side-w);
    padding: 18px 12px 12px; background: var(--surface); border-radius: var(--r-lg);
    box-shadow: 0 1px 2px oklch(0.18 0.004 286 / 0.04), 0 12px 32px oklch(0.18 0.004 286 / 0.07);
  }
  body.has-shell .page { margin-left: calc(var(--side-w) + 40px); margin-right: auto; max-width: 1440px; padding: 28px 32px 56px 0; }
}

/* เนื้อหาหลัก */
.page { max-width: var(--content-w); margin: 0 auto; padding: var(--sp-6) var(--sp-6) var(--sp-10); }
@media (max-width: 640px) { .page { padding: var(--sp-4) var(--sp-4) var(--sp-8); } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head h1 { font-size: 30px; line-height: 38px; font-weight: 600; letter-spacing: -0.01em; }
.page-head p { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
@media (max-width: 720px) {
  .page-head h1 { font-size: 26px; line-height: 34px; }
  .page-head p:not(.keep-sm) { display: none; }
}
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }

/* ── แท็บ (ตัวเลือกแบบแบ่งช่อง ทรงแคปซูล) ───────────────────────────────── */
.tabs {
  display: flex; flex-wrap: wrap; gap: 2px; padding: 4px; align-self: flex-start;
  background: var(--surface-3); border-radius: 22px; margin-bottom: var(--sp-5);
}
.tab {
  appearance: none; background: none; border: 0; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 14px; border-radius: 999px; font-size: var(--fs-md); font-weight: 500; color: var(--ink-2);
  text-decoration: none; transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab.active, .tab[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px oklch(0.18 0.004 286 / 0.06), 0 2px 8px oklch(0.18 0.004 286 / 0.06); }
.tab .count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: var(--fs-xs); font-weight: 600;
  display: inline-grid; place-items: center; background: var(--surface-3); color: var(--ink-2);
}
.tab .count.is-alert { background: var(--danger); color: #fff; }

/* ── ปุ่ม (ทรงแคปซูล · บนพื้นแอป = ขาวลอยมีเงา · ในการ์ด = เทาอ่อนไม่มีเงา) ───── */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  border: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 600; line-height: 1; white-space: nowrap; text-decoration: none;
  transition: background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:hover { box-shadow: var(--shadow-hover); }
.btn:active { transform: translateY(1px); }
.btn .i { width: 17px; height: 17px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn.is-loading { pointer-events: none; opacity: 0.75; }
.btn-primary { background: var(--black); color: var(--on-black); box-shadow: var(--shadow-press); }
.btn-primary:hover { background: var(--black-strong); box-shadow: var(--shadow-press); }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { background: var(--gold-strong); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-tint); }
.btn-danger-solid { background: var(--danger); color: oklch(1 0 0); box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.14), 0 6px 16px oklch(0.18 0.004 286 / 0.16); }
.btn-danger-solid:hover { background: var(--danger-strong); }
.btn-success { background: var(--success); color: oklch(1 0 0); box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.14), 0 6px 16px oklch(0.18 0.004 286 / 0.14); }
.btn-success:hover { background: color-mix(in oklch, var(--success) 85%, black); }
.btn-ghost { background: transparent; box-shadow: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-3); box-shadow: none; color: var(--ink); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; gap: 6px; }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: 15px; }
.btn-icon { width: 40px; padding: 0; }
.btn-sm.btn-icon { width: 34px; }
.btn-block { width: 100%; }
:is(.panel, dialog.dialog, .card) .btn:not(.btn-primary, .btn-ghost, .btn-danger-solid, .btn-success, .btn-gold) { background: var(--surface-2); box-shadow: none; }
:is(.panel, dialog.dialog, .card) .btn:not(.btn-primary, .btn-ghost, .btn-danger-solid, .btn-success, .btn-gold):hover { background: var(--surface-3); }
:is(.panel, dialog.dialog, .card) .btn-danger:hover { background: var(--danger-tint); }
@media (pointer: coarse) { .btn { min-height: 44px; } .btn-sm { min-height: 38px; } }

/* ── ฟอร์ม (ช่องกรอกพื้นเทา ไม่มีขอบ แบบแอป) ────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger); }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid transparent; background-color: var(--surface-2); color: var(--ink);
  font-size: 14.5px; line-height: 1.4;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2363636e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; background-color: var(--surface); border-color: var(--ink); box-shadow: 0 0 0 4px oklch(0.18 0.004 286 / 0.08); }
.input:disabled, .select:disabled, .textarea:disabled { background-color: var(--surface-2); color: var(--muted); opacity: 0.7; cursor: not-allowed; }
.input[readonly] { background-color: var(--surface-3); color: var(--ink-2); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-group { position: relative; display: flex; align-items: center; }
.input-group > .i { position: absolute; left: 13px; color: var(--muted); pointer-events: none; z-index: 1; }
.input-group > .input { padding-left: 38px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-md); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--black); margin: 0; }
.input[type="file"] { padding: 6px 8px; cursor: pointer; }
.input[type="file"]::file-selector-button {
  font: inherit; font-size: 13px; font-weight: 600; margin-right: 10px; padding: 6px 14px; cursor: pointer;
  border: 0; border-radius: 999px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
}
@media (max-width: 640px) { .input, .select, .textarea { font-size: 16px; } } /* กัน iOS ซูม */

/* ── แผง/การ์ด (ขาว ไม่มีขอบ มุม 24 เงานุ่ม) ─────────────────────────────── */
.panel { background: var(--surface); border: 0; border-radius: var(--r-lg); box-shadow: var(--shadow); min-width: 0; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  padding: 20px 24px 6px;
}
.panel-head h2, .panel-head h3 { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-head :is(h2, h3) > .i:first-child { display: none; }
.panel-head p { font-size: 13px; color: var(--muted); }
.panel-body { padding: 18px 24px 24px; }
.panel-head + .panel-body { padding-top: 12px; }
.panel-foot { padding: 14px 24px; border-top: 1px solid var(--line); background: transparent; border-radius: 0 0 var(--r-lg) var(--r-lg); }
@media (max-width: 640px) {
  .panel { border-radius: 22px; }
  .panel-head, .panel-body, .panel-foot { padding-left: 18px; padding-right: 18px; }
}

/* การ์ดดำ (ตัวเลข/สถานะหลักของหน้า — หน้าละไม่เกิน 1 ใบ) */
.card-black {
  position: relative; min-width: 0; color: var(--on-black); background: var(--black);
  border-radius: var(--r-xl); padding: 22px 26px; box-shadow: var(--shadow-black);
}
.card-black-label { font-size: 13.5px; color: var(--on-black-2); }
.card-black-rule { position: relative; height: 1px; margin: 18px 0 16px; background: oklch(1 0 0 / 0.1); }
.card-black-rule::before { content: ""; position: absolute; left: 0; top: 0; width: 36px; height: 1px; background: var(--champagne); }
@media (max-width: 640px) { .card-black { padding: 18px 20px; border-radius: 26px; } }

/* ตัวเลขสรุป (แผงเดียว แบ่งช่อง — ไม่ใช่การ์ดซ้ำๆ) */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); background: var(--surface); border: 0; border-radius: var(--r-lg); box-shadow: var(--shadow); }
.panel > .stats { box-shadow: none; border-radius: 0; border-bottom: 1px solid var(--line); }
.stat { padding: 18px 24px; border-right: 1px solid var(--line); min-width: 0; }
.stat:last-child { border-right: 0; }
.stat-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat-label .i { width: 14px; height: 14px; }
.stat-value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat-note { font-size: var(--fs-xs); color: var(--muted); }
.stat.is-alert .stat-value { color: var(--danger); }
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats .stat { padding: 14px 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .stats .stat:nth-child(2n) { border-right: 0; }
  .stats .stat:last-child:nth-child(odd) { grid-column: 1 / -1; border-right: 0; }
  .stats .stat:last-child, .stats .stat:nth-last-child(2):nth-child(odd) { border-bottom: 0; }
  .stats .stat-value { font-size: 19px; }
}

/* ── ตาราง ────────────────────────────────────────────────────────────────── */
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* position: relative = ให้ป้ายซ่อนสำหรับโปรแกรมอ่านจอ (.sr-only — position:absolute) อยู่ในกรอบเลื่อน
   ไม่หลุดออกมาดันทั้งหน้าให้เลื่อนซ้าย-ขวาได้ (บั๊กเดิม: จอ ≤1024px ทั้งหน้าเลื่อนข้างได้ 200px) */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.table th {
  text-align: left; font-weight: 500; font-size: 12.5px; color: var(--muted);
  padding: 12px 14px; background: transparent; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th:first-child, .table td:first-child { padding-left: 24px; }
.table th:last-child, .table td:last-child { padding-right: 24px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t-fast) var(--ease); }
.table tbody tr:hover { background: oklch(0.971 0.0027 286 / 0.7); }
.table .t-right, .table td.num, .table th.num { text-align: right; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 640px) { .table th:first-child, .table td:first-child { padding-left: 18px; } .table th:last-child, .table td:last-child { padding-right: 18px; } }

/* ── ป้าย (pill) ──────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  padding: 2px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 500; line-height: 1.6;
  background: var(--surface-3); color: var(--ink-2);
}
.pill .i { width: 12px; height: 12px; }
.pill-success { background: var(--success-tint); color: var(--success); }
.pill-warning { background: var(--warning-tint); color: var(--warning); }
.pill-danger  { background: var(--danger-tint);  color: var(--danger); }
.pill-info    { background: var(--info-tint);    color: var(--info); }
.pill-accent  { background: var(--black);        color: var(--on-black); }
.pill-gold    { background: var(--gold-tint);    color: oklch(0.42 0.09 75); }
.pill-muted   { background: var(--surface-3);    color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot-success { background: var(--success); } .dot-warning { background: var(--warning); } .dot-danger { background: var(--danger); }

/* ── กล่องแจ้ง (callout) — พื้นอ่อน + ไอคอนนำ · ห้ามใช้เส้นข้างซ้ายหนา ── */
.callout {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: 14px 16px; border-radius: 16px; border: 0;
  background: var(--surface); box-shadow: var(--shadow); font-size: var(--fs-md); color: var(--ink);
}
.callout > .i { margin-top: 3px; color: var(--ink-2); }
.callout strong { font-weight: 600; }
.callout .callout-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.callout-info    { background: var(--info-tint);    box-shadow: none; }
.callout-info > .i { color: var(--info); }
.callout-success { background: var(--success-tint); box-shadow: none; }
.callout-success > .i { color: var(--success); }
.callout-warning { background: var(--warning-tint); box-shadow: none; }
.callout-warning > .i { color: var(--warning); }
.callout-danger  { background: var(--danger-tint);  box-shadow: none; }
.callout-danger > .i { color: var(--danger); }

/* ── สถานะว่าง / โหลด ──────────────────────────────────────────────────────── */
.empty { padding: 48px 24px; text-align: center; color: var(--muted); font-size: var(--fs-md); }
.empty > .i { width: 44px; height: 44px; padding: 11px; margin: 0 auto var(--sp-3); border-radius: 50%; background: var(--surface-2); color: var(--muted); }
.empty strong { display: block; color: var(--ink-2); font-weight: 600; margin-bottom: 4px; }
.empty .btn { margin-top: var(--sp-4); }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%;
  animation: ui-shimmer 1.4s ease-in-out infinite; border-radius: var(--r-sm); min-height: 14px; }
@keyframes ui-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Dialog (native <dialog>) ─────────────────────────────────────────────── */
dialog.dialog {
  border: 0; padding: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 48px); color: var(--ink); background: var(--surface);
}
dialog.dialog::backdrop { background: oklch(0.18 0.004 286 / 0.4); }
dialog.dialog[open] { animation: ui-pop var(--t) var(--ease); }
.dialog-head { display: flex; align-items: center; gap: var(--sp-3); padding: 22px 24px 10px; }
.dialog-head h2 { font-size: var(--fs-lg); flex: 1; }
.dialog-body { padding: 0 24px 18px; font-size: var(--fs-md); color: var(--ink-2); display: flex; flex-direction: column; gap: var(--sp-3); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: 6px 24px 24px; flex-wrap: wrap; }
@keyframes ui-pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-stack { position: fixed; z-index: var(--z-toast); bottom: var(--sp-5); right: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); max-width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--black); color: var(--on-black); border-radius: 14px; box-shadow: var(--shadow-lg); font-size: var(--fs-md);
  animation: ui-toast-in var(--t) var(--ease);
}
.toast .i { margin-top: 2px; }
.toast-success .i { color: var(--good-on-black); }
.toast-error .i { color: var(--bad-on-black); }
.toast-warning .i { color: var(--champagne-tint); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity var(--t) var(--ease), transform var(--t) var(--ease); }
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) { .toast-stack { left: var(--sp-4); right: var(--sp-4); bottom: var(--sp-4); max-width: none; } }
@media (max-width: 1023px) { body.has-shell .toast-stack { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); } }

/* ── อื่นๆ ─────────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--line); border: 0; margin: var(--sp-4) 0; }
.kbd { font-family: var(--font-mono); font-size: var(--fs-xs); padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); }
.link { color: var(--ink); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.link:hover { text-decoration-color: currentColor; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .spin { animation: ui-spin 0.9s linear infinite !important; }
}

} /* @layer ui */
