/* ── ตรวจสลิปค่าเทอม ─────────────────────────────────────────────────────
   A school-office tool: calm surfaces, one accent, and three status colours
   that carry meaning everywhere (green = matches, amber = look, red = fix).
   Phone first; from 960px a sidebar appears.
   Rules: grids use minmax(0, 1fr); user text wraps; colours come from the
   tokens so dark mode is complete; touch targets are at least 44px.
   ──────────────────────────────────────────────────────────────────────── */

@font-face { font-family: "Plex Thai"; font-weight: 400; font-display: swap;
  src: url(/assets/fonts/ibm-plex-sans-thai-thai-400-normal.woff2) format("woff2");
  unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 400; font-display: swap;
  src: url(/assets/fonts/ibm-plex-sans-thai-latin-400-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plex Thai"; font-weight: 600; font-display: swap;
  src: url(/assets/fonts/ibm-plex-sans-thai-thai-600-normal.woff2) format("woff2");
  unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 600; font-display: swap;
  src: url(/assets/fonts/ibm-plex-sans-thai-latin-600-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  color-scheme: light;
  --page: #f3f4f1;
  --surface: #ffffff;
  --surface-2: #f8f9f6;
  --ink: #1d2320;
  --ink-2: #4c5650;
  --ink-3: #5f6963;
  --line: #dde1dc;
  --line-strong: #c4cbc5;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-wash: #e6f0f7;
  --green: #1b6b3a;  --green-wash: #e3f3e8;  --green-mark: #2f9e57;
  --amber: #7a5200;  --amber-wash: #fdf1d6;  --amber-mark: #e0a21a;
  --red: #a8302a;    --red-wash: #fbe6e4;    --red-mark: #d0453d;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .05);
  --overlay: rgb(12 16 14 / .5);
  --font: "Plex Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 12px;
  --r-sm: 8px;
  --gutter: 16px;
  --sidebar-w: 232px;
  --target: 44px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #121614;
    --surface: #1a1f1c;
    --surface-2: #202622;
    --ink: #e8ece9;
    --ink-2: #b9c2bc;
    --ink-3: #9aa49e;
    --line: #2d3530;
    --line-strong: #3d4741;
    --accent: #7db8e0;
    --accent-ink: #0d1a24;
    --accent-wash: #1b2c38;
    --green: #8fd6a6;  --green-wash: #183223;  --green-mark: #4cbf74;
    --amber: #f0c66b;  --amber-wash: #382c12;  --amber-mark: #e5ad33;
    --red: #f2a19a;    --red-wash: #3d1d1b;    --red-mark: #e0645c;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    --overlay: rgb(0 0 0 / .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121614; --surface: #1a1f1c; --surface-2: #202622; --ink: #e8ece9; --ink-2: #b9c2bc; --ink-3: #9aa49e;
  --line: #2d3530; --line-strong: #3d4741; --accent: #7db8e0; --accent-ink: #0d1a24; --accent-wash: #1b2c38;
  --green: #8fd6a6; --green-wash: #183223; --green-mark: #4cbf74; --amber: #f0c66b; --amber-wash: #382c12; --amber-mark: #e5ad33;
  --red: #f2a19a; --red-wash: #3d1d1b; --red-mark: #e0645c; --shadow: 0 1px 2px rgb(0 0 0 / .4); --overlay: rgb(0 0 0 / .6);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 16px/1.6 var(--font); overflow-wrap: anywhere;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
img { max-width: 100%; display: block; }
.num, .amount, td.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sr-only:focus { position: fixed; top: 8px; left: 8px; width: auto; height: auto; clip: auto; z-index: 99;
  background: var(--surface); padding: 8px 12px; border-radius: var(--r-sm); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ── shell ─────────────────────────────────────────────────────────────── */
.shell { min-height: 100vh; }
.sidebar { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; min-width: 0; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: .95rem; flex: none; }
.main { padding: 18px var(--gutter) 96px; max-width: 1200px; margin: 0 auto; }
.bottom-nav {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; min-height: 56px;
  color: var(--ink-3); text-decoration: none; font-size: .75rem; position: relative; }
.bottom-nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.bottom-nav .ico { font-size: 1.2rem; line-height: 1; }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--red-mark); color: #fff; font-size: .75rem; font-weight: 600; line-height: 1; }
.bottom-nav .badge { position: absolute; top: 4px; left: calc(50% + 6px); }

@media (min-width: 960px) {
  .shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .topbar, .bottom-nav { display: none; }
  .sidebar { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--line); }
  .sidebar .brand { padding: 4px 8px 16px; }
  .nav a, .nav button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--target);
    padding: 8px 12px; border-radius: var(--r-sm); color: var(--ink-2); text-decoration: none; font: inherit;
    background: none; border: 0; cursor: pointer; text-align: left; }
  .nav a:hover, .nav button:hover { background: var(--surface-2); }
  .nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
  .nav .ico { width: 20px; text-align: center; }
  .nav .badge { margin-left: auto; }
  .nav-sep { height: 1px; background: var(--line); margin: 10px 8px; }
  .sidebar .who { margin-top: auto; padding: 12px; font-size: .85rem; color: var(--ink-3); }
  .main { padding: 28px 32px 48px; }
}

/* ── building blocks ───────────────────────────────────────────────────── */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--ink-3); margin: 2px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .stack > * + * { margin-top: 14px; }
.card h2 { margin-bottom: 12px; }
.grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.grid > * + *, .grid > .card + .card { margin-top: 0; }
@media (min-width: 720px) {
  .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.wide-left { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
}

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--target);
  padding: 8px 16px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.good { background: var(--green-mark); border-color: var(--green-mark); color: #fff; }
.btn.danger { color: var(--red); border-color: var(--red-mark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field label, .label { font-weight: 600; font-size: .92rem; }
.field .hint { color: var(--ink-3); font-size: .85rem; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: var(--target); padding: 8px 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm); }
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-wash); border-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 3px; flex: none; accent-color: var(--accent); }

.notice { padding: 12px 14px; border-radius: var(--r-sm); background: var(--accent-wash); color: var(--ink); margin-bottom: 14px; }
.notice.good { background: var(--green-wash); }
.notice.warn { background: var(--amber-wash); }
.notice.bad { background: var(--red-wash); }
.notice > :last-child { margin-bottom: 0; }

/* status chips and colour dots */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .82rem;
  font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.chip.green { background: var(--green-wash); color: var(--green); } .chip.green::before { background: var(--green-mark); }
.chip.amber { background: var(--amber-wash); color: var(--amber); } .chip.amber::before { background: var(--amber-mark); }
.chip.red { background: var(--red-wash); color: var(--red); }       .chip.red::before { background: var(--red-mark); }
.chip.plain::before { display: none; }

/* stats */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 1.7rem; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--ink-3); font-size: .9rem; }
a.stat-card { text-decoration: none; color: inherit; display: block; }
a.stat-card:hover { border-color: var(--line-strong); }
.stat-card.green { border-left: 5px solid var(--green-mark); }
.stat-card.amber { border-left: 5px solid var(--amber-mark); }
.stat-card.red { border-left: 5px solid var(--red-mark); }

/* progress bar: paid share of a class */
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: var(--green-mark); }

/* tables: rows become cards on phones */
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { text-align: left; font-size: .82rem; color: var(--ink-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table a.row-link { color: var(--ink); font-weight: 600; text-decoration: none; }
.table a.row-link:hover { text-decoration: underline; }
@media (max-width: 719px) {
  .table.stack-sm thead { display: none; }
  .table.stack-sm tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table.stack-sm td { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border: 0; }
  .table.stack-sm td::before { content: attr(data-label); color: var(--ink-3); font-size: .85rem; }
  .table.stack-sm td.num { text-align: right; }
}

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; }
.seg a { padding: 8px 14px; min-height: 40px; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2);
  text-decoration: none; border-right: 1px solid var(--line); background: var(--surface); }
.seg a:last-child { border-right: 0; }
.seg a[aria-current="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg a[aria-current="true"] .muted { color: inherit; opacity: .85; }

/* ── approval queue ────────────────────────────────────────────────────── */
.queue { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .queue { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.slip-card { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 14px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow);
  border-left: 5px solid var(--line-strong); }
.slip-card.green { border-left-color: var(--green-mark); }
.slip-card.amber { border-left-color: var(--amber-mark); }
.slip-card.red { border-left-color: var(--red-mark); }
.slip-card .thumb { width: 92px; height: 120px; object-fit: cover; object-position: top; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface-2); }
.slip-card .no-img { width: 92px; height: 120px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px dashed var(--line-strong);
  display: grid; place-items: center; color: var(--ink-3); font-size: .8rem; text-align: center; padding: 6px; }
.slip-card .top { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: baseline; }
.slip-card .amount { font-size: 1.3rem; font-weight: 600; }
.slip-card .who { font-weight: 600; margin: 2px 0; }
.slip-card .meta { color: var(--ink-3); font-size: .86rem; }
.slip-card .first-reason { font-size: .9rem; margin-top: 6px; }
.slip-card .row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.slip-card .pick { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.slip-card .pick input { width: 20px; height: 20px; accent-color: var(--green-mark); }

.reasons { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.reasons li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 8px; align-items: start; font-size: .95rem; }
.reasons li::before { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 600; margin-top: 2px; }
.reasons li.ok::before { content: "✓"; background: var(--green-wash); color: var(--green); }
.reasons li.amber::before { content: "!"; background: var(--amber-wash); color: var(--amber); }
.reasons li.red::before { content: "✕"; background: var(--red-wash); color: var(--red); }
.reasons li.note::before { content: "i"; background: var(--accent-wash); color: var(--accent); font-style: italic; }

/* ── slip detail ───────────────────────────────────────────────────────── */
.slip-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .slip-layout { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); align-items: start; } }
.slip-image { border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); width: 100%; }
/* On a phone the slip is a reference, not the task: keep it short so the approval form is close. */
@media (max-width: 899px) { .slip-image { max-height: 46vh; object-fit: contain; } }
@media (min-width: 900px) { .slip-image-wrap { position: sticky; top: 24px; } }
.facts { display: grid; grid-template-columns: minmax(0, 9rem) minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: .95rem; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; min-width: 0; }
.big-amount { font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }

.alloc { display: grid; gap: 8px; margin: 10px 0; }
.alloc-row { display: grid; grid-template-columns: minmax(0, 1fr) 8.5rem 44px; gap: 8px; align-items: start; }
.alloc-row .student { min-width: 0; }
.alloc-row .student .chosen { padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface-2); min-height: var(--target); display: flex; flex-direction: column; justify-content: center; }
.alloc-row .student .chosen small { color: var(--ink-3); }
.alloc-row input[type=number] { text-align: right; }
@media (max-width: 559px) {
  .alloc-row { grid-template-columns: minmax(0, 1fr) 44px; }
  .alloc-row .student { grid-column: 1 / -1; }
}
.alloc-sum { display: flex; justify-content: space-between; font-size: .95rem; padding: 6px 2px; }
.alloc-sum.off { color: var(--red); font-weight: 600; }
.search-box { position: relative; }
.search-results { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; }
.search-results button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none;
  font: inherit; color: var(--ink); cursor: pointer; border-bottom: 1px solid var(--line); }
.search-results button:hover, .search-results button:focus { background: var(--accent-wash); }
.search-results small { color: var(--ink-3); display: block; }
.suggest-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.message-box { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px; font-size: .95rem; }

/* ── upload ────────────────────────────────────────────────────────────── */
.drop { border: 2px dashed var(--line-strong); border-radius: var(--r); padding: 36px 18px; text-align: center; background: var(--surface);
  cursor: pointer; display: block; }
.drop.over { border-color: var(--accent); background: var(--accent-wash); }
.drop .big { font-size: 1.1rem; font-weight: 600; }
.file-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-list { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 8px; }
.upload-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); }
.upload-list .name { min-width: 0; }
.upload-list .name small { display: block; color: var(--ink-3); }

/* ── import mapping ────────────────────────────────────────────────────── */
.preview-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); max-height: 340px; }
.preview { border-collapse: collapse; font-size: .82rem; white-space: nowrap; }
.preview td, .preview th { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 4px 8px; }
.preview th { background: var(--surface-2); position: sticky; top: 0; }
.preview tr.header td { background: var(--accent-wash); font-weight: 600; }
.mapping { display: grid; gap: 10px 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .mapping { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ── dialogs and toasts ────────────────────────────────────────────────── */
dialog { border: 0; border-radius: var(--r); padding: 0; width: min(92vw, 480px); background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgb(0 0 0 / .3); }
dialog::backdrop { background: var(--overlay); }
dialog .dialog-body { padding: 20px; }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px; flex-wrap: wrap; }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 50; display: grid; gap: 8px; width: min(92vw, 440px); }
@media (min-width: 960px) { .toasts { bottom: 24px; } }
.toast { background: var(--ink); color: var(--page); padding: 12px 16px; border-radius: var(--r-sm); box-shadow: var(--shadow); }
.toast.bad { background: var(--red-mark); color: #fff; }

/* ── sign in ───────────────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px var(--gutter); }
.auth .card { width: min(100%, 400px); padding: 28px; }
.auth h1 { display: flex; align-items: center; gap: 10px; }

.empty { text-align: center; padding: 40px 16px; color: var(--ink-3); }
.empty .big { font-size: 2rem; }
.kv-list { list-style: none; padding: 0; margin: 0; }
.kv-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv-list li:last-child { border-bottom: 0; }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.steps { padding-left: 1.3rem; margin: 0; }
.steps li { margin-bottom: 6px; }
