/* BANKHUM SIS — Mobile first */
:root {
  --bg: #f2faf4;
  --surface: #ffffff;
  --surface-2: #f7fbf8;
  --ink: #17301f;
  --ink-2: #3f5a48;
  --ink-3: #6e8576;
  --line: #dcebe0;
  --primary: #169a45;      /* เขียวตราโรงเรียน */
  --primary-2: #0e7a35;
  --primary-ink: #ffffff;
  --primary-soft: #e2f5e8;
  --accent: #ffc72c;       /* เหลืองตราโรงเรียน */
  --accent-soft: #fff4cc;
  --blue: #2a56c6;         /* น้ำเงินตัวอักษรในตรา */
  --danger: #e2462f;

  /* สถานะการมาเรียน: สีสด อ่านง่าย */
  --st-present: #16a34a;  --st-present-bg: #dcfce7;
  --st-late: #f59e0b;     --st-late-bg: #fef3c7;
  --st-leave: #2563eb;    --st-leave-bg: #dbeafe;
  --st-sick: #9333ea;     --st-sick-bg: #f3e8ff;
  --st-absent: #ef4444;   --st-absent-bg: #fee2e2;
  --st-none: #64748b;     --st-none-bg: #eef2f6;

  --radius: 18px;
  --shadow: 0 2px 4px rgba(22, 120, 60, .05), 0 8px 24px rgba(22, 120, 60, .08);
  --nav-h: 66px;
  --font: 'IBM Plex Sans Thai', 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.35rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; font-weight: 600; color: var(--ink-2); }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--ink); }
.brand img { width: 34px; height: 34px; flex: none; }
.brand-name { font-weight: 700; letter-spacing: .02em; font-size: 1rem; }
.brand-sub { font-size: .72rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.user-chip { font-size: .85rem; color: var(--ink-2); text-align: right; line-height: 1.25; max-width: 45vw; }
.user-chip b { display: block; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { padding: 16px; max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
.page-head .sub { color: var(--ink-3); font-size: .9rem; margin-top: 2px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.bottomnav a, .sidenav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-3); font-size: .72rem; font-weight: 500;
}
.bottomnav a.active, .sidenav a.active { color: var(--primary); }
.bottomnav svg, .sidenav svg { width: 24px; height: 24px; }
.bottomnav a.duty { color: var(--st-late); }
.sidenav { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 230px 1fr; grid-template-rows: auto 1fr; padding-bottom: 0; }
  .topbar { grid-column: 1 / -1; }
  .bottomnav { display: none; }
  .sidenav {
    display: flex; flex-direction: column; gap: 2px; padding: 16px 12px; border-right: 1px solid var(--line);
    background: var(--surface-2); position: sticky; top: 61px; height: calc(100vh - 61px);
  }
  .sidenav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: .95rem; color: var(--ink-2); }
  .sidenav a:hover { background: var(--primary-soft); }
  .sidenav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
  .sidenav .sep { height: 1px; background: var(--line); margin: 8px 4px; }
  main { padding: 24px 32px; width: 100%; }
}

/* ---------- Cards & tiles ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .stack > * + * { margin-top: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tiles .tile.total { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 10px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(7, 1fr); } .tiles .tile.total { grid-column: auto; display: block; } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.tile .v { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .l { font-size: .8rem; color: var(--ink-2); }
.tile.total { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.tile.total .l { color: inherit; opacity: .85; }
.tile.PRESENT .v { color: var(--st-present); } .tile.LATE .v { color: var(--st-late); }
.tile.LEAVE .v { color: var(--st-leave); } .tile.SICK .v { color: var(--st-sick); }
.tile.ABSENT .v { color: var(--st-absent); } .tile.NONE .v { color: var(--st-none); }

.banner { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-radius: var(--radius); margin-bottom: 12px; }
.banner.duty { background: var(--st-late-bg); color: var(--ink); border: 1px solid color-mix(in srgb, var(--st-late) 35%, transparent); }
.banner.info { background: var(--primary-soft); }
.banner.warn { background: var(--st-absent-bg); }
.banner .grow { flex: 1; min-width: 0; }
.banner > svg { width: 28px; height: 28px; flex: none; }
.banner b { display: block; }

/* แถบสัดส่วนสถานะ */
.bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: var(--st-none-bg); }
.bar span { display: block; height: 100%; }
.bar .PRESENT { background: var(--st-present); } .bar .LATE { background: var(--st-late); }
.bar .LEAVE { background: var(--st-leave); } .bar .SICK { background: var(--st-sick); } .bar .ABSENT { background: var(--st-absent); }

.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .8rem; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 500; }
.list .meta { font-size: .82rem; color: var(--ink-3); }
.list a.row { display: flex; align-items: center; gap: 12px; color: inherit; width: 100%; }
.roll { width: 28px; text-align: right; color: var(--ink-3); font-variant-numeric: tabular-nums; flex: none; font-size: .9rem; }

.room-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); color: inherit; }
.room-row:last-child { border-bottom: 0; }
.room-row .bar { grid-column: 1 / -1; }
.room-row .name { font-weight: 600; }
.room-row .stat { font-size: .82rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.PRESENT { background: var(--st-present-bg); color: var(--st-present); }
.badge.LATE { background: var(--st-late-bg); color: var(--st-late); }
.badge.LEAVE { background: var(--st-leave-bg); color: var(--st-leave); }
.badge.SICK { background: var(--st-sick-bg); color: var(--st-sick); }
.badge.ABSENT { background: var(--st-absent-bg); color: var(--st-absent); }
.badge.NONE, .badge.gray { background: var(--st-none-bg); color: var(--st-none); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }

/* ---------- Attendance check ---------- */
.att-toolbar { margin-bottom: 4px; }
.att-toolbar .actions { width: 100%; }
.att-toolbar .actions .input { flex: 0 0 auto; }
.att-toolbar .actions .btn { flex: 1; }
/* มือถือ: เฉพาะแถบนับสถานะที่ติดด้านบน ไม่กินพื้นที่จอ */
.att-counts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.att-sticky-bar {
  position: sticky; top: 61px; z-index: 10; background: var(--bg);
  margin: 8px -16px 0; padding: 8px 16px; border-bottom: 1px solid var(--line);
}
@media (min-width: 760px) { .att-toolbar .actions { width: auto; } .att-toolbar .actions .btn { flex: none; } }
.att-list { list-style: none; margin: 0; padding: 0; }
.att-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.att-item.changed { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.att-who { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.att-who .name { font-weight: 500; flex: 1; min-width: 0; }
.att-who .nick { color: var(--ink-3); font-size: .85rem; }
.att-note { font-size: .82rem; color: var(--ink-2); margin-top: 6px; }
.seg { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.seg button {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  font-weight: 600; font-size: .92rem; cursor: pointer; color: var(--ink-2); padding: 0 4px;
  transition: background .12s, color .12s, border-color .12s;
}
.seg button:disabled { cursor: default; opacity: .55; }
.seg button[aria-pressed="true"].PRESENT { background: var(--st-present); border-color: var(--st-present); color: #fff; }
.seg button[aria-pressed="true"].LATE { background: var(--st-late); border-color: var(--st-late); color: #fff; }
.seg button[aria-pressed="true"].LEAVE { background: var(--st-leave); border-color: var(--st-leave); color: #fff; }
.seg button[aria-pressed="true"].SICK { background: var(--st-sick); border-color: var(--st-sick); color: #fff; }
.seg button[aria-pressed="true"].ABSENT { background: var(--st-absent); border-color: var(--st-absent); color: #fff; }
@media (min-width: 760px) {
  .att-item { display: grid; grid-template-columns: 1fr 420px; align-items: center; gap: 12px; }
  .att-who { margin-bottom: 0; }
  .att-note { grid-column: 1 / -1; margin-top: 0; }
}
.savebar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 25;
  padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; gap: 10px; align-items: center; box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
.savebar .grow { flex: 1; font-size: .9rem; color: var(--ink-2); }
@media (min-width: 900px) { .savebar { left: 230px; bottom: 0; } }
.pad-for-savebar { height: 80px; }

/* ---------- Forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer;
  color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: .85rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .85rem; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); outline: none;
}
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-row { display: grid; gap: 0 12px; }
@media (min-width: 560px) { .form-row { grid-template-columns: repeat(var(--cols, 2), 1fr); } }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.searchbar .input { flex: 1 1 200px; }
.searchbar select.input { flex: 0 1 160px; }

/* ---------- Tables (desktop) ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: .8rem; color: var(--ink-3); font-weight: 600; background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr.err td { background: var(--st-absent-bg); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand img { width: 72px; height: 72px; }
.auth-brand .name { font-size: 1.5rem; font-weight: 700; letter-spacing: .03em; margin-top: 8px; }
.auth-brand .en { font-size: .8rem; color: var(--ink-3); }
.auth-brand .th { font-size: .9rem; color: var(--ink-2); margin-top: 2px; }
.error-msg { background: var(--st-absent-bg); color: var(--st-absent); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .9rem; }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(10, 15, 25, .45); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) { .modal-back { align-items: center; } .modal { border-radius: 18px; padding: 24px; } }
.modal h2 { margin-bottom: 14px; }
.modal .actions { justify-content: flex-end; margin-top: 16px; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 90px); transform: translateX(-50%) translateY(20px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

.empty { text-align: center; color: var(--ink-3); padding: 28px 12px; }
.secret { font-family: ui-monospace, monospace; font-size: 1.25rem; letter-spacing: .08em; background: var(--surface-2); border: 1px dashed var(--line); padding: 10px 14px; border-radius: 10px; text-align: center; user-select: all; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.menu-grid a { display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-weight: 600; }
.menu-grid a span { font-weight: 400; font-size: .8rem; color: var(--ink-3); }
.menu-grid svg { width: 26px; height: 26px; color: var(--primary); }
.trend { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.trend .col { flex: 1; max-width: 56px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.trend .stackbar { display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; }
.trend .lbl { font-size: .65rem; color: var(--ink-3); text-align: center; margin-top: 4px; white-space: nowrap; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: .92rem; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; }
@media (min-width: 900px) { .att-sticky-bar { margin: 8px -32px 0; padding: 8px 32px; } }

/* =================================================================
   ธีมสบายตา (เขียวตราโรงเรียน แบบนุ่มลง) — ครูทดลองใช้แล้วบอกว่าแบบสีจัดแสบตา
   ================================================================= */
:root {
  --bg: #f4f6f4; --surface: #ffffff; --surface-2: #f8faf8; --ink: #1f2d24; --ink-2: #48594d; --ink-3: #788a7e;
  --line: #e2e8e3; --primary: #2e8b57; --primary-2: #24724a; --primary-soft: #e6f2ea; --accent: #e3b341; --accent-soft: #fbf3dc;
  --blue: #3b67b8;
  --st-present: #2f9e5b; --st-present-bg: #e5f4ea;
  --st-late: #c98a12;    --st-late-bg: #fbf1dc;
  --st-leave: #3b6fc4;   --st-leave-bg: #e6eefa;
  --st-sick: #8457c4;    --st-sick-bg: #f0e9f9;
  --st-absent: #cf4c3f;  --st-absent-bg: #fbe8e5;
  --st-none: #6f7d86;    --st-none-bg: #eef1f3;
  --shadow: 0 1px 2px rgba(20, 40, 28, .05), 0 4px 14px rgba(20, 40, 28, .05);
}
h1 { color: var(--ink); }

.topbar { background: #24724a; border-bottom: 0; color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.06); }
.brand, .brand-name { color: #fff; white-space: nowrap; }
.brand-sub { color: rgba(255,255,255,.8); }
.brand img { width: 40px; height: 40px; background: #fff; border-radius: 50%; padding: 2px; }
.user-chip, .user-chip b { color: #fff; }
.user-chip .badge.LATE { background: var(--accent); color: #4a3300; }

.bottomnav { border-top: 1px solid var(--line); }
.bottomnav a.active { color: var(--primary); }
.bottomnav a.active svg { background: var(--primary-soft); border-radius: 12px; padding: 3px; width: 34px; height: 30px; }
.bottomnav a.duty { color: var(--st-late); }
@media (min-width: 900px) {
  .sidenav { background: var(--surface); top: 60px; height: calc(100vh - 60px); }
  .sidenav a.active { background: var(--primary-soft); color: var(--primary-2); box-shadow: inset 3px 0 0 var(--primary); }
}

.card { border: 1px solid var(--line); box-shadow: var(--shadow); }
.card-head h2::before { content: ''; display: inline-block; width: 4px; height: 16px; border-radius: 2px; background: var(--primary); margin-right: 8px; vertical-align: -2px; }

/* ช่องตัวเลข: พื้นอ่อน ตัวเลขสีเข้ม แถบสีด้านซ้าย */
.tile { border: 1px solid var(--line); background: var(--surface); box-shadow: none; position: relative; border-left-width: 4px; }
.tile .l { color: var(--ink-2); font-weight: 500; }
.tile.total { background: var(--primary-soft); border-color: var(--primary-soft); border-left-color: var(--primary); color: var(--ink); }
.tile.total .v { color: var(--primary-2); } .tile.total .l { color: var(--ink-2); opacity: 1; }
.tile.PRESENT { background: var(--st-present-bg); border-color: var(--st-present-bg); border-left-color: var(--st-present); }
.tile.LATE { background: var(--st-late-bg); border-color: var(--st-late-bg); border-left-color: var(--st-late); }
.tile.LEAVE { background: var(--st-leave-bg); border-color: var(--st-leave-bg); border-left-color: var(--st-leave); }
.tile.SICK { background: var(--st-sick-bg); border-color: var(--st-sick-bg); border-left-color: var(--st-sick); }
.tile.ABSENT { background: var(--st-absent-bg); border-color: var(--st-absent-bg); border-left-color: var(--st-absent); }
.tile.NONE { background: var(--st-none-bg); border-color: var(--st-none-bg); border-left-color: var(--st-none); }
.tile.PRESENT .v { color: var(--st-present); } .tile.LATE .v { color: var(--st-late); } .tile.LEAVE .v { color: var(--st-leave); }
.tile.SICK .v { color: var(--st-sick); } .tile.ABSENT .v { color: var(--st-absent); } .tile.NONE .v { color: var(--st-none); }

.btn { border-radius: 12px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: none; }
.btn.primary:hover { background: var(--primary-2); }
.btn.ghost { color: var(--primary-2); }
.badge.blue { background: #e8eef9; color: var(--blue); }

.att-item { border: 1px solid var(--line); box-shadow: none; }
.att-item.changed { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.seg button:not([aria-pressed="true"]) { background: var(--surface-2); border-color: var(--line); }
.seg button.PRESENT { color: var(--st-present); } .seg button.LATE { color: var(--st-late); }
.seg button.LEAVE { color: var(--st-leave); } .seg button.SICK { color: var(--st-sick); } .seg button.ABSENT { color: var(--st-absent); }
.savebar { border-top: 1px solid var(--line); box-shadow: 0 -2px 10px rgba(0,0,0,.05); }

.banner.duty { background: var(--accent-soft); border: 1px solid #f0dca6; }
.banner.info { background: var(--primary-soft); }
.banner.warn { background: var(--st-absent-bg); }

.menu-grid a { border: 1px solid var(--line); box-shadow: none; }
.menu-grid a svg { width: 38px; height: 38px; padding: 8px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); }

/* หน้าเข้าสู่ระบบ: เขียวเข้มเรียบ */
.auth { background: linear-gradient(180deg, #24724a 0%, #2e8b57 55%, #e9f2ec 55.1%, #f4f6f4 100%); }
.auth-brand .logo-main { width: min(250px, 66vw); height: auto; filter: drop-shadow(0 6px 12px rgba(0,0,0,.18)); }
.auth-brand .seal { width: 26px; height: 26px; border-radius: 50%; background: #fff; padding: 1px; vertical-align: -7px; margin-right: 6px; }
.auth-brand .en { margin-top: 6px; }
.auth-brand .en, .auth-brand .th { color: #fff; }
.auth-card .card { box-shadow: 0 10px 30px rgba(0,0,0,.10); }
.boot { background: #24724a; color: #fff; }

/* ---------- ปุ่มควบคุม: ติดตั้งแอป / ภาษา / ธีม ---------- */
.controls { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; min-width: 36px; padding: 0 10px; border-radius: 999px;
  border: 0; cursor: pointer; font-weight: 600; font-size: .82rem; background: rgba(255,255,255,.2); color: #fff;
}
.icon-btn:hover { background: rgba(255,255,255,.32); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn i { display: inline-flex; font-style: normal; }
.topbar-controls [data-install] span { display: none; }
@media (min-width: 900px) { .topbar-controls [data-install] span { display: inline; } }
@media (max-width: 520px) { .topbar .brand-sub .wide { display: none; } .user-chip { max-width: 30vw; font-size: .75rem; } }
.topbar-logout { padding: 0; width: 36px; justify-content: center; flex: none; }
.auth-controls { position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 14px; }
.auth { position: relative; }
.menu-controls { flex-wrap: wrap; gap: 10px; }
.menu-controls .icon-btn { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); height: 46px; padding: 0 16px; }
.menu-controls .icon-btn svg { color: var(--primary); }

/* ---------- เครดิตผู้พัฒนา ---------- */
.credit { font-size: .78rem; line-height: 1.6; color: var(--ink-3); text-align: center; margin-top: 18px; }
.credit a { color: var(--primary); font-weight: 600; }
.credit span { white-space: nowrap; }
.auth .credit { color: var(--ink-3); }
.auth .credit a { color: var(--primary-2); }
.sidenav .grow-space { flex: 1; }
.sidenav .credit { text-align: left; padding: 10px 12px; margin: 0; border-top: 1px solid var(--line); }

/* =================================================================
   โหมดมืด (เลือกเองได้จากปุ่มพระจันทร์)
   ================================================================= */
:root[data-theme="dark"] {
  --bg: #0d1712; --surface: #16231b; --surface-2: #1b2a21; --ink: #e7f3ea; --ink-2: #b9cfc0; --ink-3: #85a08e;
  --line: #24382b; --primary: #34c46c; --primary-2: #4ade80; --primary-soft: #183b26; --accent-soft: #3a3214;
  --blue: #7aa2ff; --st-present-bg: #153b25; --st-late-bg: #3d2f0e; --st-leave-bg: #172c52; --st-sick-bg: #2f1d4a;
  --st-absent-bg: #47201c; --st-none-bg: #222e27; --shadow: 0 2px 10px rgba(0,0,0,.35);
  color-scheme: dark;
}
:root[data-theme="dark"] body { background: var(--bg); }
:root[data-theme="dark"] .topbar { background: #133f28; }
:root[data-theme="dark"] .seg button:not([aria-pressed="true"]) { background: #1c2a22; border-color: var(--line); }
:root[data-theme="dark"] .banner.duty { background: #3a3214; border-color: #5a4a1a; }
:root[data-theme="dark"] .banner.info { background: var(--primary-soft); }
:root[data-theme="dark"] .banner.warn { background: var(--st-absent-bg); }
:root[data-theme="dark"] .sidenav { background: var(--surface); }
:root[data-theme="dark"] .sidenav a.active { background: var(--primary-soft); }
:root[data-theme="dark"] .menu-grid a:nth-child(5n+3) svg { background: #172c52; }
:root[data-theme="dark"] .menu-grid a:nth-child(5n+4) svg { background: #47201c; }
:root[data-theme="dark"] .menu-grid a:nth-child(5n+5) svg { background: #2f1d4a; }
:root[data-theme="dark"] .badge.blue { background: #172c52; }
:root[data-theme="dark"] .auth { background: linear-gradient(180deg, #133f28 0%, #1b5235 55%, #0d1712 55.1%); }
:root[data-theme="dark"] .tbl th { background: var(--surface-2); }
:root[data-theme="dark"] .input { background: var(--surface-2); }
:root[data-theme="dark"] #toast { background: #e7f3ea; color: #0d1712; }

:root[data-theme="dark"] .tile.total { background: var(--primary-soft); border-color: var(--primary-soft); border-left-color: var(--primary); }
:root[data-theme="dark"] .tile.total .v { color: var(--primary-2); }
:root[data-theme="dark"] .btn.primary { background: #2e8b57; border-color: #2e8b57; }
:root[data-theme="dark"] .menu-grid a svg { background: var(--primary-soft); color: var(--primary); }

/* มือถือ: ปุ่มภาษา/ธีม/ติดตั้งอยู่ที่หน้า "เมนู" แทน เพื่อไม่ให้ทับชื่อระบบ */
@media (max-width: 640px) { .topbar-controls { display: none; } }
.brand { flex-shrink: 1; overflow: hidden; }
.controls .lbl { display: none; }
.menu-controls .lbl { display: inline; }

/* ---------- ระเบียบวินัย ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.tabs button { flex: none; min-height: 36px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer; font-weight: 500; }
.tabs button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.card.narrow { max-width: 720px; }
fieldset.field { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
fieldset.field > legend, .field > .label { display: block; font-size: .85rem; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; padding: 0; }
.check-grid { display: grid; grid-template-columns: 1fr; gap: 0 12px; margin-bottom: 8px; }
@media (min-width: 560px) { .check-grid { grid-template-columns: 1fr 1fr; } }
.picked { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-radius: 10px; background: var(--primary-soft); }
.pick-list > li { padding: 0; }
.pick-list button.row { display: flex; width: 100%; text-align: left; background: none; border: 0; padding: 10px 4px; cursor: pointer; color: inherit; }
.pick-list button.row:hover { background: var(--surface-2); }
.pre { white-space: pre-wrap; }
.plain { list-style: none; margin: 0; padding: 0; line-height: 1.9; }
.score { display: flex; align-items: baseline; gap: 8px; }
.score b { font-size: 2.2rem; color: var(--st-present); line-height: 1; }
.score b.low { color: var(--st-absent); }
.score span { color: var(--ink-3); }

/* แบบฟอร์มพิมพ์ (A4, ฟอนต์ราชการ) */
.print-doc { font-family: 'Sarabun', 'TH Sarabun New', sans-serif; color: #000; }
.ppage { background: #fff; color: #000; width: 100%; max-width: 210mm; margin: 0 auto 16px; padding: 18mm 18mm 16mm 25mm;
  box-shadow: var(--shadow); font-size: 15px; line-height: 1.75; box-sizing: border-box; }
.print-doc[data-show="1"] [data-page="2"], .print-doc[data-show="2"] [data-page="1"] { display: none; }
.ppage p { margin: 0 0 2px; }
.ppage h2 { font-size: 26px; margin: 0; text-align: center; flex: 1; }
.ppage h3 { font-size: 18px; margin: 0 0 4px; }
.ppage .pc { text-align: center; } .ppage .pr { text-align: right; }
.ppage .pind { text-indent: 2.5em; } .ppage .pind2 { padding-left: 6em; margin: 8px 0; }
.ppage .pspread { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ppage .pline { border-bottom: 1px solid #000; padding-bottom: 6px; margin-bottom: 8px; }
.pmemo-head { display: flex; align-items: center; margin-bottom: 10px; }
.pmemo-head img { width: 52px; height: 52px; object-fit: contain; }
.pmemo-head::after { content: ''; width: 52px; }
.pgrid3, .pgrid2 { display: grid; gap: 0 10px; margin: 2px 0 6px; }
.pgrid3 { grid-template-columns: repeat(3, 1fr); } .pgrid2 { grid-template-columns: repeat(2, 1fr); padding-left: 2em; }
.pbox { display: inline-flex; align-items: center; justify-content: center; width: 1.05em; height: 1.05em; border: 1px solid #000; border-radius: 2px; font-size: .85em; line-height: 1; vertical-align: -2px; }
.pfill { border-bottom: 1px dotted #000; padding: 0 .4em; }
.pdots { display: inline-block; border-bottom: 1px dotted #000; height: 1.1em; vertical-align: baseline; }
.pdots.block { display: block; height: 1.6em; }
.psign { text-align: center; margin: 14px 0 10px auto; width: 60%; line-height: 1.9; }
.psign2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.psign2 .psign { width: auto; margin: 14px 0 10px; }
@media (max-width: 640px) {
  .ppage { padding: 14px; font-size: 13px; }
  .pgrid3 { grid-template-columns: 1fr 1fr; }
  .psign { width: 100%; }
}
@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff !important; }
  .topbar, .sidenav, .bottomnav, .no-print, .credit, .toast { display: none !important; }
  .shell { display: block !important; padding: 0 !important; min-height: 0; }
  main { padding: 0 !important; max-width: none !important; }
  .ppage { box-shadow: none; margin: 0; max-width: none; width: 210mm; min-height: 297mm; padding: 15mm 18mm 15mm 25mm; font-size: 15.5px; break-after: page; }
  .ppage:last-child { break-after: auto; }
  .pgrid3 { grid-template-columns: 1.25fr 1fr .9fr !important; }
  .psign { width: 60% !important; }
}
.pgrid3 { grid-template-columns: 1.25fr 1fr .9fr; }
.psign2 .pdots { min-width: 9em !important; }
