/* ============ บ้านครู ร่างทอง — ระบบดีไซน์ ============
 * สีทั้งหมดเป็นตัวแปร (token) — โหมดมืดสลับที่ token ชุดเดียว
 * ธีม: อัตโนมัติตามเครื่อง / [data-theme="light"] / [data-theme="dark"]
 * ===================================================== */
:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface2: #f1efe8;
  --surface3: #e9e6dc;
  --ink: #1b2230;
  --ink2: #535d70;
  --ink3: #8d95a5;
  --line: #e4e0d4;
  --brand: #3450c9;
  --brand-ink: #ffffff;
  --brand-soft: #e8ecfc;
  --gold: #b8860b;
  --gold2: #e0b43a;
  --gold-soft: #fbf1d6;
  --green: #17895a;
  --green-soft: #def4e8;
  --red: #cf3f3f;
  --red-soft: #fce8e8;
  --amber: #a86d00;
  --amber-soft: #fcf0d3;
  --orange: #e8833a;
  --radius: 16px;
  --radius-s: 11px;
  --shadow: 0 1px 2px rgba(27,34,48,.05), 0 6px 20px rgba(27,34,48,.05);
  --shadow-lg: 0 18px 60px rgba(10,14,25,.28);
  --sidebar-w: 232px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c111c; --surface: #141b2a; --surface2: #1b2436; --surface3: #243049;
    --ink: #e9eef7; --ink2: #aab4c6; --ink3: #6d7890; --line: #263149;
    --brand: #7d95ff; --brand-ink: #0c111c; --brand-soft: rgba(125,149,255,.14);
    --gold: #f0c050; --gold2: #f7d57a; --gold-soft: rgba(240,192,80,.13);
    --green: #3fd08f; --green-soft: rgba(63,208,143,.13); --red: #ff7a7a; --red-soft: rgba(255,122,122,.13);
    --amber: #f5b945; --amber-soft: rgba(245,185,69,.13);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c111c; --surface: #141b2a; --surface2: #1b2436; --surface3: #243049;
  --ink: #e9eef7; --ink2: #aab4c6; --ink3: #6d7890; --line: #263149;
  --brand: #7d95ff; --brand-ink: #0c111c; --brand-soft: rgba(125,149,255,.14);
  --gold: #f0c050; --gold2: #f7d57a; --gold-soft: rgba(240,192,80,.13);
  --green: #3fd08f; --green-soft: rgba(63,208,143,.13); --red: #ff7a7a; --red-soft: rgba(255,122,122,.13);
  --amber: #f5b945; --amber-soft: rgba(245,185,69,.13);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'Sarabun', 'Leelawadee UI', 'Thonburi', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15.5px; line-height: 1.55;
  min-height: 100vh;
}
button { font-family: inherit; font-size: inherit; cursor: pointer; color: inherit; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 14px; }
.brand-logo { width: 46px; height: 46px; border-radius: 13px; box-shadow: 0 4px 14px rgba(224,168,46,.28); flex-shrink: 0; }
.tb-logo { width: 26px; height: 26px; border-radius: 8px; vertical-align: -7px; }
.brand-name { font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--ink3); }
.gold-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .3px; vertical-align: 2px;
  padding: 1px 7px; border-radius: 99px; color: #5a3d00;
  background: linear-gradient(135deg, #f7d57a, #e0a82e); box-shadow: 0 1px 4px rgba(224,168,46,.35);
}
#nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; margin-bottom: 2px;
  color: var(--ink2); font-weight: 500;
  border: none; background: none; width: 100%; text-align: start; position: relative;
}
.nav-item:hover { background: var(--surface2); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.active::before { content: ''; position: absolute; inset-inline-start: -10px; top: 9px; bottom: 9px; width: 4px; border-radius: 4px; background: var(--gold2); }
.nav-item .ico { font-size: 18px; width: 24px; text-align: center; }
.nav-badge {
  margin-inline-start: auto; background: var(--red); color: #fff;
  font-size: 11.5px; font-weight: 700; border-radius: 99px;
  padding: 1px 7px; min-width: 20px; text-align: center;
}
.sidebar-foot { padding: 10px 12px 14px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.sidebar-foot .ver { font-size: 11px; color: var(--ink3); padding-inline-start: 4px; }

/* ---------- Sync badge ---------- */
.sync-badge {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface2);
  border-radius: 99px; padding: 4px 11px 4px 8px; font-size: 12.5px; font-weight: 600; color: var(--ink2);
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sync-badge i { font-style: normal; font-size: 11px; }
.sync-badge span { overflow: hidden; text-overflow: ellipsis; }
.sync-badge.s-synced { color: var(--green); background: var(--green-soft); border-color: transparent; }
.sync-badge.s-pushing, .sync-badge.s-connecting { color: var(--brand); background: var(--brand-soft); border-color: transparent; }
.sync-badge.s-pushing i, .sync-badge.s-connecting i { animation: spin 1.1s linear infinite; display: inline-block; }
.sync-badge.s-offline { color: var(--amber); background: var(--amber-soft); border-color: transparent; }
.sync-badge.s-error { color: var(--red); background: var(--red-soft); border-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Topbar / Bottom nav (มือถือ) ---------- */
#topbar { display: none; }
#bottomnav { display: none; }

/* ---------- Main ---------- */
#main { flex: 1; padding: 24px 28px 90px; min-width: 0; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -.2px; }
.page-sub { color: var(--ink2); font-size: 13.5px; margin-top: 2px; }

/* ---------- Cards / layout ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card + .card { margin-top: 14px; }
.card-title { font-weight: 700; font-size: 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.tile .t-label { font-size: 12.5px; color: var(--ink2); font-weight: 500; }
.tile .t-value { font-size: 25px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.tile .t-note { font-size: 12px; color: var(--ink3); }
.tile.warn .t-value { color: var(--red); }
.tile.good .t-value { color: var(--green); }
.tile.gold { background: linear-gradient(135deg, var(--gold-soft), var(--surface) 70%); }
.tile.gold .t-value { color: var(--gold); }
.tile.click { cursor: pointer; }
.tile.click:hover { border-color: var(--brand); }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius-s); padding: 8px 14px; font-weight: 600; font-size: 14px; line-height: 1.3;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px;
  transition: background .12s, filter .12s, transform .06s;
}
.btn:hover { background: var(--surface2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.gold { background: linear-gradient(135deg, #f7d57a, #e0a82e); border-color: #e0a82e; color: #3d2900; }
.btn.gold:hover { filter: brightness(1.05); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.btn.danger:hover { background: var(--red-soft); }
.btn.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 9px; min-height: 32px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink2); }
.btn.ghost:hover { background: var(--surface2); }
.btn.block { display: flex; width: 100%; }
.btn.google { background: var(--surface); }
.btn.google .g { font-weight: 800; font-size: 16px; background: conic-gradient(from -45deg, #ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0); -webkit-background-clip: text; background-clip: text; color: transparent; }
input[type="date"], input[type="time"], input[type="text"], input[type="number"], input[type="email"], input[type="password"], input[type="search"], input[type="tel"], select, textarea {
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 8px 11px;
  background: var(--surface); font-size: 15px; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; line-height: 1.5; }
label.fld { display: block; font-size: 13px; color: var(--ink2); font-weight: 600; margin-bottom: 12px; }
label.fld > input, label.fld > select, label.fld > textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 500; }
label.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.search { position: relative; }
.search input { padding-inline-start: 34px; width: 100%; }
.search::before { content: '🔍'; position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: .7; }

/* แท็บเลือก (segmented) */
.tabs { display: inline-flex; background: var(--surface2); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.tabs button { border: none; background: transparent; padding: 6px 13px; border-radius: 9px; font-weight: 600; font-size: 13.5px; color: var(--ink2); min-height: 34px; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tabs button .n { font-size: 11.5px; color: var(--ink3); margin-inline-start: 3px; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: start; color: var(--ink2); font-size: 12.5px; font-weight: 600; padding: 8px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px 9px; border-bottom: 1px solid var(--surface2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .num { text-align: end; font-variant-numeric: tabular-nums; }
.tbl tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.tbl tbody tr.link { cursor: pointer; }
.tbl tbody tr.link:hover td { background: var(--surface2); }

/* ---------- Badges / chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 99px; padding: 1px 9px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.blue { background: var(--brand-soft); color: var(--brand); }
.chip.gray { background: var(--surface2); color: var(--ink2); }
.chip.gold { background: var(--gold-soft); color: var(--gold); }
.dot-progress { display: inline-flex; gap: 3px; align-items: center; vertical-align: -1px; }
.dot-progress i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); display: inline-block; }
.dot-progress i.on { background: var(--green); }

/* ---------- รายการทั่วไป ---------- */
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--surface2); }
.list-row:last-child { border-bottom: none; }
.list-row > div:first-child { flex: 1; min-width: 0; }
.kv { display: grid; gap: 6px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.kv > div > span { color: var(--ink2); }

/* ---------- เช็คชื่อ ---------- */
.checkin-row { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--surface2); flex-wrap: wrap; }
.checkin-row:last-child { border-bottom: none; }
.checkin-name { flex: 1; min-width: 140px; }
.checkin-name .lv { color: var(--ink3); font-size: 12.5px; margin-inline-start: 6px; }
.checkin-name b.link { cursor: pointer; }
.checkin-name b.link:hover { color: var(--brand); text-decoration: underline; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: none; background: var(--surface); padding: 8px 15px; font-weight: 600; font-size: 14px; color: var(--ink2); min-height: 40px; }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button.on-present { background: var(--green); color: #fff; }
.seg button.on-absent { background: var(--red); color: #fff; }
.hours-sel { width: 76px; }
.round-alert { background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 25%, transparent); border-radius: 12px; padding: 7px 11px; font-size: 13.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.group-dot { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-inline-end: 6px; vertical-align: -1px; }

/* ---------- กริดรายปี ---------- */
.gridwrap { overflow: auto; max-height: 74vh; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
table.year-grid { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; }
.year-grid th, .year-grid td { border-bottom: 1px solid var(--surface2); border-inline-end: 1px solid var(--surface2); padding: 0; text-align: center; }
.year-grid thead th { position: sticky; top: 0; background: var(--surface); z-index: 3; font-size: 11.5px; color: var(--ink2); padding: 5px 3px; white-space: nowrap; line-height: 1.25; }
.year-grid thead th.today { background: var(--gold-soft); color: var(--gold); }
.year-grid thead th.mon-start, .year-grid td.mon-start, .year-grid tfoot td.mon-start { border-inline-start: 2px solid var(--line); }
.year-grid .rowhead { position: sticky; inset-inline-start: 0; background: var(--surface); z-index: 2; text-align: start; padding: 5px 10px; white-space: nowrap; font-weight: 600; min-width: 128px; box-shadow: 1px 0 0 var(--line); cursor: pointer; }
.year-grid .rowhead:hover { color: var(--brand); }
.year-grid thead .rowhead { z-index: 4; cursor: default; }
.year-grid tfoot td { position: sticky; bottom: 0; background: var(--surface2); font-weight: 700; font-size: 11.5px; padding: 5px 3px; white-space: nowrap; z-index: 2; }
.year-grid tfoot .rowhead { z-index: 4; background: var(--surface2); cursor: default; }
.year-grid td.sum { padding: 0 8px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell { width: 36px; height: 34px; display: flex; align-items: center; justify-content: center; font-weight: 600; border: none; background: transparent; font-size: 12.5px; position: relative; color: var(--ink3); touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.cell:hover { outline: 2px solid var(--brand); border-radius: 7px; z-index: 1; }
.cell.present { background: var(--green-soft); color: var(--green); }
.cell.absent { color: var(--ink3); background: repeating-linear-gradient(45deg, transparent, transparent 4px, rgba(127,127,127,.09) 4px, rgba(127,127,127,.09) 8px); }
.cell.paid { box-shadow: inset 0 0 0 2px var(--brand); border-radius: 7px; color: var(--brand); background: var(--brand-soft); }
.cell.due { box-shadow: inset 0 0 0 2px var(--red); border-radius: 7px; color: var(--red); background: var(--red-soft); }
.cell.cancel { background: var(--amber-soft); color: var(--amber); font-size: 10.5px; }
.cell.flash { animation: flash .35s ease; }
@keyframes flash { from { transform: scale(1.25); } }
td.today-col { background: color-mix(in srgb, var(--gold-soft) 60%, transparent); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink2); margin-top: 10px; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-inline-end: 4px; }
.mode-on { background: var(--gold-soft) !important; border-color: var(--gold2) !important; color: var(--gold) !important; }

/* ---------- ตารางสอน ---------- */
.tt-wrap { overflow-x: auto; }
.tt { display: grid; grid-template-columns: 52px repeat(7, minmax(110px, 1fr)); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); min-width: 860px; }
.tt-head { background: var(--surface2); font-weight: 700; text-align: center; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tt-head.today { color: var(--brand); }
.tt-time { font-size: 11px; color: var(--ink3); text-align: center; border-inline-end: 1px solid var(--line); padding-top: 2px; transform: translateY(-7px); background: var(--surface); }
.tt-col { position: relative; border-inline-end: 1px solid var(--surface2); }
.tt-col:last-child { border-inline-end: none; }
.tt-hourline { position: absolute; inset-inline: 0; border-top: 1px solid var(--surface2); }
.tt-slot { position: absolute; border-radius: 9px; padding: 5px 8px; font-size: 12.5px; color: #fff; overflow: hidden; border: none; text-align: start; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.tt-slot b { display: block; font-size: 13px; line-height: 1.25; }
.tt-slot small { opacity: .9; }
.tt-slot:hover { filter: brightness(1.1); }

/* ---------- ค่าเรียน ---------- */
.stu-card { border: 1px solid var(--line); border-radius: 14px; padding: 13px 15px; margin-bottom: 10px; background: var(--surface); box-shadow: var(--shadow); }
.stu-card.hot { border-inline-start: 4px solid var(--red); }
.stu-card .head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stu-card .head .name { font-weight: 700; font-size: 16px; cursor: pointer; }
.stu-card .head .name:hover { color: var(--brand); }
.stu-card .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.rounds { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.round-chip { border-radius: 9px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; border: 1px solid transparent; min-height: 30px; }
.round-chip.paid { background: var(--brand-soft); color: var(--brand); }
.round-chip.due { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.round-chip.open { background: var(--surface2); color: var(--ink2); border-style: dashed; border-color: var(--ink3); }
.big-amount { font-size: 34px; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.pay-list label.check { padding: 9px 4px; border-bottom: 1px solid var(--surface2); }

/* ภาพการ์ด (สลิป/ตารางเรียน) */
.slip-view { display: grid; grid-template-columns: minmax(0, 380px) 1fr; gap: 18px; align-items: start; }
.slip-view .img-wrap { background: #070b16; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.slip-view img, .slip-view canvas { width: 100%; height: auto; display: block; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.gallery figure { background: var(--surface2); border-radius: 12px; overflow: hidden; }
.gallery img { width: 100%; display: block; }
.gallery figcaption { padding: 6px 8px; font-size: 13px; display: flex; gap: 6px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* ---------- โปรไฟล์นักเรียน ---------- */
.profile-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.avatar { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; font-size: 28px; font-weight: 700; color: #fff; flex-shrink: 0; background: linear-gradient(135deg, var(--brand), #9a6bff); }
.heat { display: flex; flex-wrap: wrap; gap: 4px; }
.heat i { width: 16px; height: 16px; border-radius: 4px; background: var(--surface2); display: inline-block; }
.heat i.p { background: var(--green); }
.heat i.a { background: var(--red); opacity: .55; }
.heat i.paid { box-shadow: inset 0 0 0 2px var(--brand); }
.heat-month { display: grid; grid-template-columns: 58px 1fr; gap: 8px; align-items: center; font-size: 12.5px; color: var(--ink2); padding: 3px 0; }

/* ---------- Chart ---------- */
.chart { margin-top: 6px; }
.chart .bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 22px; }
.chart .bcol { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; height: 100%; justify-content: flex-end; position: relative; }
.chart .bar { width: 100%; max-width: 42px; background: var(--brand); border-radius: 5px 5px 0 0; min-height: 2px; position: relative; }
.chart .bcol:hover .bar { filter: brightness(1.12); }
.chart .bval { font-size: 10.5px; color: var(--ink2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart .baseline { border-top: 1px solid var(--line); }
.chart .xlabels { display: flex; gap: 6px; margin-top: 4px; }
.chart .xlabels span { flex: 1; text-align: center; font-size: 11.5px; color: var(--ink2); }
.bar-list .bl-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.bar-list .bl-track { height: 12px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.bar-list .bl-fill { height: 100%; border-radius: 99px; background: var(--brand); }
.bar-list .bl-val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ---------- Modal ---------- */
#modal-root:empty { display: none; }
.modal-back { position: fixed; inset: 0; background: rgba(10,14,25,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; animation: fade-in .15s ease; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; padding: 18px 22px 20px; animation: pop-in .18s ease; }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.modal-head h3 { font-size: 18px; flex: 1; }
.modal-x { border: none; background: var(--surface2); width: 32px; height: 32px; border-radius: 10px; color: var(--ink2); flex-shrink: 0; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.menu-tile { border: 1px solid var(--line); background: var(--surface2); border-radius: 14px; padding: 14px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 600; font-size: 13.5px; position: relative; }
.menu-tile .ico { font-size: 24px; }
.menu-tile.active { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.menu-tile .nav-badge { position: absolute; top: 6px; inset-inline-end: 6px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: calc(20px + var(--safe-b)); inset-inline-start: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 24px); }
.toast { background: #1b2230; color: #fff; border-radius: 12px; padding: 10px 14px 10px 18px; font-size: 14px; box-shadow: var(--shadow-lg); animation: toast-in .2s ease; display: flex; align-items: center; gap: 12px; }
.toast.err { background: var(--red); }
.toast-act { border: none; background: rgba(255,255,255,.16); color: #fff; font-weight: 700; padding: 5px 11px; border-radius: 8px; white-space: nowrap; }
.toast-act:hover { background: rgba(255,255,255,.28); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.gate { max-width: 440px; margin: 6vh auto 0; }
.gate-hero { text-align: center; margin-bottom: 18px; }
.gate-logo { width: 108px; height: 108px; margin: 0 auto 12px; display: block; border-radius: 28px; box-shadow: 0 10px 36px rgba(224,168,46,.35); }
.gate-title { font-size: 28px; font-weight: 700; }
.gate-sub { color: var(--ink2); font-size: 14px; margin-top: 4px; }
.gate-card { padding: 22px; }
.login-box .or { display: flex; align-items: center; gap: 10px; color: var(--ink3); font-size: 12.5px; margin: 14px 0; }
.login-box .or::before, .login-box .or::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.login-err { color: var(--red); margin-top: 10px; min-height: 1em; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface3); border-top-color: var(--brand); animation: spin .8s linear infinite; margin: 0 auto 12px; }
body.no-data #sidebar, body.no-data #bottomnav, body.no-data #topbar { display: none !important; }
body.no-data #main { max-width: none; }

/* ---------- Banner ---------- */
.banner { display: flex; gap: 12px; align-items: center; border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; background: var(--gold-soft); border: 1px solid color-mix(in srgb, var(--gold2) 45%, transparent); flex-wrap: wrap; }
.banner .b-ico { font-size: 22px; }
.banner .b-text { flex: 1; min-width: 200px; font-size: 14px; }

.muted { color: var(--ink3); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt14 { margin-top: 14px; } .mt20 { margin-top: 20px; }
.empty { text-align: center; color: var(--ink3); padding: 26px 10px; }
.num-tab { font-variant-numeric: tabular-nums; }
hr.sep { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- iPad แนวตั้ง / จอกลาง ---------- */
@media (max-width: 1100px) and (min-width: 861px) {
  :root { --sidebar-w: 200px; }
  #main { padding: 20px 20px 90px; }
}

/* ---------- มือถือ ---------- */
@media (max-width: 860px) {
  #sidebar { display: none; }
  #app { flex-direction: column; }
  #topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 50; padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
    background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  #topbar .tb-brand { font-size: 16px; white-space: nowrap; }
  #topbar .sync-badge { max-width: 52vw; }
  #bottomnav {
    display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 60;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 4px 4px calc(4px + var(--safe-b));
  }
  .bn-item { flex: 1; border: none; background: none; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; color: var(--ink3); font-size: 11.5px; font-weight: 600; position: relative; border-radius: 12px; min-height: 52px; }
  .bn-item .ico { font-size: 21px; line-height: 1.1; }
  .bn-item.active { color: var(--brand); }
  .bn-item.active .ico { transform: translateY(-1px); }
  .bn-item .nav-badge { position: absolute; top: 2px; inset-inline-start: 55%; font-size: 10px; padding: 0 5px; min-width: 16px; }
  #main { padding: 14px 12px calc(92px + var(--safe-b)); }
  #toast-root { bottom: calc(82px + var(--safe-b)); }
  .page-title { font-size: 21px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile .t-value { font-size: 21px; }
  .slip-view { grid-template-columns: 1fr; }
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { border-radius: 22px 22px 0 0; max-height: 90vh; padding-bottom: calc(20px + var(--safe-b)); }
  .card { padding: 14px; }
  .bar-list .bl-row { grid-template-columns: 90px 1fr auto; }
}

/* ---------- Print ---------- */
@media print {
  #sidebar, #topbar, #bottomnav, .no-print, #toast-root { display: none !important; }
  #main { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
