/* ═══════════════════════════════════════════════════════════
   tedu — design system
   แนวคิด: "หมึกบนกระดาษฟอร์ม" — mobile-first, สีหลักสีเดียว (หมึกน้ำเงิน)
   ═══════════════════════════════════════════════════════════ */

/* ───── Tokens ───── */
:root {
  --paper: #FAFAF8;
  --card: #FFFFFF;
  --card-2: #F3F3F0;
  --line: #E4E4E0;
  --line-strong: #CFCFC9;
  --text: #1A1A1F;
  --muted: #6B6B75;
  --faint: #A0A0A8;

  --ink: #2B3A8F;
  --ink-hover: #23307A;
  --ink-soft: #E9ECF8;
  --ink-text: #FFFFFF;

  --stamp: #C42B2B;
  --stamp-soft: #FBE9E9;
  --ok: #1F8A5B;
  --ok-soft: #E3F3EB;
  --warn: #B87100;
  --warn-soft: #FBF0DC;

  /* ฟอนต์ชุดเดียวกับระบบ pp56: Kanit สำหรับ UI, Sarabun สำหรับเอกสารพิมพ์/ตัวเลข (self-host ที่ assets/fonts) */
  --font-display: 'Kanit', 'Sarabun', system-ui, sans-serif;
  --font-body: 'Kanit', 'Sarabun', system-ui, sans-serif;
  --font-mono: 'Sarabun', 'Kanit', system-ui, sans-serif;
  --font-doc: 'Sarabun', 'TH Sarabun New', sans-serif;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .04), 0 8px 24px -12px rgba(20, 20, 30, .10);
  --shadow-lg: 0 24px 48px -16px rgba(20, 20, 30, .25);

  --appbar-h: 56px;
  --tabbar-h: 64px;
  --rail-w: 232px;
  --gutter: 16px;

  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

html[data-theme="dark"] {
  --paper: #0F1117;
  --card: #171A22;
  --card-2: #1E222C;
  --line: #272B37;
  --line-strong: #363B4A;
  --text: #ECEDF2;
  --muted: #9A9DAA;
  --faint: #6B6E7A;

  --ink: #8E9BFF;
  --ink-hover: #A5B0FF;
  --ink-soft: #232A4D;
  --ink-text: #0F1117;

  --stamp: #F06A6A;
  --stamp-soft: #3A1F22;
  --ok: #4CC38A;
  --ok-soft: #14302A;
  --warn: #F2B134;
  --warn-soft: #3A2E14;

  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
  --shadow-lg: 0 24px 48px -16px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --paper: #0F1117;
    --card: #171A22;
    --card-2: #1E222C;
    --line: #272B37;
    --line-strong: #363B4A;
    --text: #ECEDF2;
    --muted: #9A9DAA;
    --faint: #6B6E7A;
    --ink: #8E9BFF;
    --ink-hover: #A5B0FF;
    --ink-soft: #232A4D;
    --ink-text: #0F1117;
    --stamp: #F06A6A;
    --stamp-soft: #3A1F22;
    --ok: #4CC38A;
    --ok-soft: #14302A;
    --warn: #F2B134;
    --warn-soft: #3A2E14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 48px -16px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

/* ───── Reset ───── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 500; line-height: 1.3; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; font-family: var(--font-body); font-weight: 600; }
p { margin: 0 0 .75em; }
a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--ink-soft); }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ───── App shell ───── */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--appbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 var(--gutter);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.appbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.appbar .brand .mark {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: var(--ink); color: var(--ink-text);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 600; font-size: 15px;
}
.appbar .brand .name { font-family: var(--font-display); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .brand .name small { display: block; font-family: var(--font-body); font-size: 11px; color: var(--muted); line-height: 1.2; }
.appbar .actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--text);
  display: grid; place-items: center; position: relative;
  transition: background .15s var(--ease);
}
.icon-btn:hover { background: var(--card-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .dot {
  position: absolute; top: 8px; right: 8px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--stamp); color: #fff; font-size: 10px; font-weight: 600;
  display: grid; place-items: center; line-height: 1;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--ink-soft); color: var(--ink);
  display: grid; place-items: center; font-weight: 600; font-size: 13px; overflow: hidden; flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }

.main { flex: 1; padding: 20px var(--gutter) calc(var(--tabbar-h) + 24px); min-width: 0; overflow-x: hidden; }
.container { width: 100%; max-width: 720px; margin: 0 auto; }
.container.wide { max-width: 1180px; }

/* Bottom tab bar (mobile) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: stretch;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 500; text-decoration: none;
  transition: color .15s;
}
.tabbar a svg { width: 24px; height: 24px; stroke-width: 1.75; }
.tabbar a.active { color: var(--ink); }
.tabbar a.active svg { stroke-width: 2.25; }
.tabbar a:hover { text-decoration: none; }

/* Left rail (desktop) */
.rail { display: none; }
.appbar .page-title { display: none; font-family: var(--font-display); font-size: 18px; flex: 1; }
@media (min-width: 1024px) {
  .app { flex-direction: row; }
  .rail {
    display: flex; flex-direction: column;
    width: var(--rail-w); flex: none;
    position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    border-right: 1px solid var(--line);
    background: var(--card);
    padding: 16px 12px;
    gap: 4px;
  }
  .rail .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
  .rail .brand .mark { width: 36px; height: 36px; border-radius: 10px; background: var(--ink); color: var(--ink-text); display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; }
  .rail .brand .name { font-family: var(--font-display); font-size: 17px; line-height: 1.2; }
  .rail .brand .name small { display: block; font-family: var(--font-body); font-size: 11px; color: var(--muted); }
  .rail .section { font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--faint); text-transform: uppercase; padding: 14px 10px 4px; }
  .rail a.nav {
    display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px;
    color: var(--muted); font-weight: 500; font-size: 14px;
    transition: background .15s, color .15s;
  }
  .rail a.nav svg { width: 20px; height: 20px; stroke-width: 1.75; flex: none; }
  .rail a.nav:hover { background: var(--card-2); color: var(--text); text-decoration: none; }
  .rail a.nav.active { background: var(--ink-soft); color: var(--ink); }
  .rail .spacer { flex: 1; }
  .rail .user { display: flex; align-items: center; gap: 10px; padding: 10px; border-top: 1px solid var(--line); margin-top: 8px; }
  .rail .user .who { min-width: 0; flex: 1; }
  .rail .user .who b { display: block; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .rail .user .who span { font-size: 11px; color: var(--muted); }
  .content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .appbar { padding: 0 32px; }
  .appbar .brand { display: none; }
  .appbar .page-title { display: block; }
  .tabbar { display: none; }
  .main { padding: 28px 32px 48px; }
}
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ───── Page header ───── */
.page-head { margin-bottom: 20px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); text-transform: uppercase; }

/* ───── Card ───── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 18px; margin-bottom: 14px;
}
.card.flat { box-shadow: none; }
.card.tight { padding: 12px 14px; }
.card.ink { background: var(--ink); color: var(--ink-text); border-color: var(--ink); }
.card.ink .muted { color: color-mix(in srgb, var(--ink-text) 70%, transparent); }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title h2, .card-title h3 { flex: 1; }
.card > :last-child { margin-bottom: 0; }

/* ───── Buttons ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--r);
  border: 1px solid var(--ink); background: var(--ink); color: var(--ink-text);
  font-weight: 600; font-size: 15px; text-decoration: none; white-space: nowrap;
  transition: background .15s var(--ease), transform .1s var(--ease), border-color .15s;
  user-select: none;
}
.btn:hover { background: var(--ink-hover); border-color: var(--ink-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn.secondary:hover { background: var(--ink-soft); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--card-2); }
.btn.subtle { background: var(--card-2); color: var(--text); border-color: transparent; }
.btn.subtle:hover { background: var(--line); }
.btn.danger { background: var(--stamp); border-color: var(--stamp); color: #fff; }
.btn.danger:hover { background: color-mix(in srgb, var(--stamp) 85%, black); }
.btn.danger.secondary { background: transparent; color: var(--stamp); }
.btn.danger.secondary:hover { background: var(--stamp-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { background: color-mix(in srgb, var(--ok) 85%, black); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.sm svg { width: 16px; height: 16px; }
.btn.lg { min-height: 56px; font-size: 17px; border-radius: 14px; }
.btn.block { width: 100%; }
.btn.icon { padding: 0; width: 44px; }
.btn.icon.sm { width: 34px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }
.btn-row > .btn { flex: 1 1 auto; }
@media (min-width: 640px) { .btn-row > .btn { flex: 0 0 auto; } }

/* ───── Forms ───── */
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.field .error { font-size: 12px; color: var(--stamp); margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  appearance: none; -webkit-appearance: none;
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-soft); }
.input::placeholder { color: var(--faint); }
.input:disabled, .input[readonly] { background: var(--card-2); color: var(--muted); }
.input.mono { font-family: var(--font-mono); }
.input.error { border-color: var(--stamp); }
select.input {
  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='%236B6B75' 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; padding-right: 36px;
}
input[type="date"].input, input[type="time"].input, input[type="month"].input { font-family: var(--font-mono); font-size: 14px; }
input[type="file"].input { padding: 6px 8px; font-size: 13px; color: var(--muted); }
input[type="file"].input::file-selector-button { font: inherit; font-weight: 500; color: var(--ink); background: var(--ink-soft); border: 0; border-radius: 8px; padding: 6px 12px; margin-right: 10px; cursor: pointer; }
.input-group { display: flex; }
.input-group .input { border-radius: 10px 0 0 10px; }
.input-group .btn { border-radius: 0 10px 10px 0; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .span-2 { grid-column: span 2; } }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }
.radio-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.radio-cards label {
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px;
  transition: border-color .15s, background .15s;
}
.radio-cards input { accent-color: var(--ink); width: 18px; height: 18px; margin: 0; flex: 0 0 auto; }
.radio-cards input:focus-visible { outline: none; }
.radio-cards label:hover { border-color: var(--ink); }
.radio-cards label:has(input:checked) { border-color: var(--ink); background: var(--ink-soft); color: var(--ink); }
.radio-cards label:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--ink-soft); border-color: var(--ink); }
.check input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ink-soft); border-radius: 4px; }

/* Segmented control */
.seg { display: inline-flex; background: var(--card-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button, .seg a {
  border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 8px;
  font-weight: 500; font-size: 14px; text-decoration: none; transition: background .15s, color .15s;
}
.seg .active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg.block { display: flex; }
.seg.block > * { flex: 1; text-align: center; }

/* ───── Badges ───── */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.6; white-space: nowrap;
  background: var(--card-2); color: var(--muted);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.ink { background: var(--ink-soft); color: var(--ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--stamp-soft); color: var(--stamp); }
.badge.plain::before { display: none; }

/* ───── Stamp (signature) ───── */
.stamp {
  display: inline-block; padding: 3px 10px;
  border: 2px solid currentColor; border-radius: 6px;
  box-shadow: inset 0 0 0 1.5px var(--card), inset 0 0 0 3px currentColor;
  font-family: var(--font-display); font-weight: 600; font-size: 14px; letter-spacing: .06em;
  transform: rotate(-6deg); opacity: .9; line-height: 1.5;
  mix-blend-mode: multiply;
}
html[data-theme="dark"] .stamp { mix-blend-mode: screen; }
.stamp.approved { color: var(--ink); }
.stamp.rejected { color: var(--stamp); }
.stamp.pending { color: var(--warn); border-style: dashed; box-shadow: none; }
.stamp.cancelled { color: var(--faint); border-style: dashed; box-shadow: none; }
.stamp.lg { font-size: 22px; padding: 6px 18px; border-width: 3px; box-shadow: inset 0 0 0 2px var(--card), inset 0 0 0 4px currentColor; }

/* ───── Lists ───── */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--line); color: inherit; text-decoration: none;
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { text-decoration: none; }
a.list-item:hover .title { color: var(--ink); }
.list-item .lead { flex: none; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; display: block; }
.list-item .meta { font-size: 13px; color: var(--muted); display: block; }
.list-item .trail { flex: none; text-align: right; }
.list-item .trail .mono { font-size: 14px; }
.list.card-list .list-item { padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 8px; }

/* ───── Table ───── */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--card-2); white-space: nowrap; position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--card-2) 50%, transparent); }
.table td.num, .table th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }
.table .compact td, .table .compact th { padding: 6px 10px; }
.table tfoot td { font-weight: 600; background: var(--card-2); }

/* ───── Stats ───── */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat .v { font-family: var(--font-mono); font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 13px; color: var(--muted); font-family: var(--font-body); margin-left: 3px; }
.stat.ok .v { color: var(--ok); }
.stat.warn .v { color: var(--warn); }
.stat.danger .v { color: var(--stamp); }
.stat.ink .v { color: var(--ink); }

/* ───── Clock hero (ลงเวลา) ───── */
.clock-hero { text-align: center; padding: 22px 0 8px; }
.clock-hero .date { color: var(--muted); font-size: 14px; }
.clock-hero .time { font-family: var(--font-mono); font-size: 60px; font-weight: 600; letter-spacing: -.02em; line-height: 1; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.clock-hero .time small { font-size: 22px; color: var(--muted); font-weight: 400; }
.clock-hero .state { font-size: 14px; color: var(--muted); }
.gps-line { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; color: var(--muted); min-height: 22px; }
.gps-line .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 1.6s infinite; }
.gps-line .pulse.bad { background: var(--stamp); animation: none; }
.gps-line .pulse.wait { background: var(--warn); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }

/* Timeline (in/out) */
.timeline { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.timeline .slot { border: 1px dashed var(--line-strong); border-radius: var(--r); padding: 12px; text-align: center; }
.timeline .slot.done { border-style: solid; border-color: var(--line); background: var(--card-2); }
.timeline .slot .k { font-size: 12px; color: var(--muted); }
.timeline .slot .t { font-family: var(--font-mono); font-size: 24px; font-weight: 600; margin-top: 2px; }
.timeline .slot .t.empty { color: var(--faint); }

/* ───── Ledger (สมุดบัญชี) ───── */
.passbook { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.passbook .cover { padding: 18px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, var(--ink-soft), transparent); }
.passbook .cover .acct { font-family: var(--font-mono); font-size: 13px; color: var(--muted); letter-spacing: .08em; }
.passbook .cover .bal { font-family: var(--font-mono); font-size: 36px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.passbook .cover .bal small { font-size: 14px; color: var(--muted); font-family: var(--font-body); }
.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
.ledger th { font-size: 11px; font-weight: 600; color: var(--muted); padding: 8px 12px; text-align: left; border-bottom: 2px solid var(--line-strong); letter-spacing: .04em; }
.ledger td { padding: 9px 12px; border-bottom: 1px solid var(--line); background-image: none; font-variant-numeric: tabular-nums; }
.ledger td.num { text-align: right; font-family: var(--font-mono); font-weight: 500; font-size: 15px; }
.ledger td.dep { color: var(--ok); }
.ledger td.wd { color: var(--stamp); }
.ledger td.bal { font-weight: 500; }
.ledger tr:nth-child(even) td { background: color-mix(in srgb, var(--card-2) 45%, transparent); }
.ledger .date { font-family: var(--font-mono); font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ───── Modal / sheet ─────
   มือถือ = bottom sheet · ≥640px = กล่องกลางจอ · หัวเรื่อง (h2) และแถวปุ่ม (.modal-actions) ติดขอบขณะเลื่อน
   โครงที่ทุกหน้าใช้: .modal-bg > .modal > [.grab] h2 [p] … .modal-actions (อยู่ใน form ก็ได้) */
.modal-bg {
  position: fixed; inset: 0; z-index: 60; background: rgba(10, 12, 20, .5);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .18s var(--ease);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal-bg.open { opacity: 1; pointer-events: auto; }
.modal {
  --m-pad: var(--gutter); --m-pt: 14px;
  position: relative; width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 20px 20px 0 0; padding: var(--m-pt) var(--m-pad) 0;
  transform: translateY(24px); transition: transform .22s var(--ease);
  box-shadow: var(--shadow-lg);
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; scrollbar-gutter: stable;
}
.modal::-webkit-scrollbar { width: 6px; }
.modal::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
.modal::-webkit-scrollbar-track { background: transparent; }
.modal-bg.open .modal { transform: translateY(0); }
.modal .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: -4px auto 8px; }
/* หัวเรื่องติดขอบบน — ถอยออกเต็มความกว้าง แล้วใส่พื้นหลังทับเนื้อหาที่เลื่อนผ่าน (top ติดลบเท่า padding ของกล่อง ให้ชิดขอบจริง) */
.modal > h2 {
  position: sticky; top: calc(-1 * var(--m-pt)); z-index: 3; background: var(--card);
  margin: 0 calc(-1 * var(--m-pad)) 10px; padding: 6px var(--m-pad) 10px; padding-right: calc(var(--m-pad) + 36px);
  font-size: 19px; box-shadow: 0 1px 0 var(--line);
}
.modal > h2 + p { margin-top: -2px; margin-bottom: 12px; }
.modal .field:last-child { margin-bottom: 0; }
/* ปุ่มปิดมุมขวาบน (app.js ใส่ไว้ใน h2 ให้อัตโนมัติ — ติดขอบไปพร้อมหัวเรื่อง) */
.modal .modal-x {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%); z-index: 4;
  width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--card-2); color: var(--muted);
  display: grid; place-items: center; cursor: pointer; transition: background .15s, color .15s;
}
.modal > .modal-x { top: 12px; transform: none; } /* modal ที่ไม่มี h2 ตรงๆ (เช่น ฝาก/ถอน) — วางมุมขวาบนของกล่อง */
.modal .modal-x:hover { background: var(--line); color: var(--text); }
.modal .modal-x svg { width: 18px; height: 18px; }
/* แถวปุ่มติดขอบล่าง */
.modal .modal-actions {
  position: sticky; bottom: 0; z-index: 3; display: flex; gap: 10px;
  margin: 18px calc(-1 * var(--m-pad)) 0; padding: 12px var(--m-pad) calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.modal .modal-actions .btn { flex: 1; }
.modal .modal-actions .btn.ghost { flex: 0 1 auto; min-width: 96px; }
@media (min-width: 640px) {
  .modal-bg { align-items: center; padding: 24px; }
  .modal { --m-pad: 24px; --m-pt: 18px; border-radius: 18px; transform: translateY(12px) scale(.98); }
  .modal-bg.open .modal { transform: none; }
  .modal .grab { display: none; }
  .modal > h2 { padding-top: 0; font-size: 20px; }
  .modal .modal-actions { justify-content: flex-end; }
  .modal .modal-actions .btn, .modal .modal-actions .btn.ghost { flex: 0 0 auto; min-width: 0; }
}
body.modal-open { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .modal, .modal-bg { transition: none; } }

/* ───── Toast ───── */
.toasts { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px); transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
@media (min-width: 1024px) { .toasts { bottom: 24px; } }
.toast {
  background: var(--text); color: var(--paper); padding: 11px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: toast-in .25s var(--ease);
}
.toast.ok { background: var(--ok); color: #fff; }
.toast.error { background: var(--stamp); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ───── Empty state ───── */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .empty-icon { font-size: 40px; margin-bottom: 8px; opacity: .7; }
.empty h2, .empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

/* ───── Alerts / flash ───── */
.alert { padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--card-2); margin-bottom: 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.alert.error { background: var(--stamp-soft); border-color: transparent; color: var(--stamp); }
.alert.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.alert.ink { background: var(--ink-soft); border-color: transparent; color: var(--ink); }

/* ───── Tabs ───── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .tabs button {
  padding: 10px 14px; border: 0; background: none; color: var(--muted); font-weight: 500; font-size: 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none;
}
.tabs .active { color: var(--ink); border-bottom-color: var(--ink); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ───── Calendar grid ───── */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.cal .day {
  aspect-ratio: 1; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 13px; border: 1px solid transparent; position: relative; cursor: default;
}
.cal .day.out { color: var(--faint); }
.cal .day.today { border-color: var(--ink); font-weight: 600; }
.cal .day .m { width: 6px; height: 6px; border-radius: 50%; margin-top: 3px; }
.cal .day.on_time .m { background: var(--ok); }
.cal .day.late .m { background: var(--warn); }
.cal .day.absent .m { background: var(--stamp); }
.cal .day.leave .m, .cal .day.official .m, .cal .day.outing .m { background: var(--ink); }
.cal .day.holiday { background: var(--card-2); color: var(--faint); }
.cal .day.weekend { color: var(--faint); }
.cal .day.clickable { cursor: pointer; }
.cal .day.clickable:hover { background: var(--card-2); }
.cal .day.selected { background: var(--ink-soft); border-color: var(--ink); }

/* ───── Progress bar ───── */
.bar { height: 8px; border-radius: 4px; background: var(--card-2); overflow: hidden; display: flex; }
.bar > i { display: block; height: 100%; }
.bar .p { background: var(--ok); } .bar .l { background: var(--warn); } .bar .a { background: var(--stamp); } .bar .v { background: var(--ink); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

/* ───── Utilities ───── */
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.row.start { align-items: flex-start; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 14px; }
.grid-2 > *, .grid-3 > * { min-width: 0; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }
.bold { font-weight: 600; }
.ink-text { color: var(--ink); }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.danger-text { color: var(--stamp); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 20px; } .mt-4 { margin-top: 32px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 20px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.hide-mobile { display: none !important; }
@media (min-width: 720px) { .hide-mobile { display: initial !important; } .hide-desktop { display: none !important; } }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skeleton { background: linear-gradient(90deg, var(--card-2) 25%, var(--line) 50%, var(--card-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; min-height: 16px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.reveal { animation: reveal .35s var(--ease) both; }
@keyframes reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Quick action tiles (dashboard) */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px;
  display: flex; flex-direction: column; gap: 10px; color: inherit; text-decoration: none; min-height: 104px;
  transition: border-color .15s, transform .15s var(--ease);
}
.tile:hover { border-color: var(--ink); text-decoration: none; transform: translateY(-1px); }
.tile .ico { width: 36px; height: 36px; border-radius: 10px; background: var(--ink-soft); color: var(--ink); display: grid; place-items: center; }
.tile .ico svg { width: 20px; height: 20px; }
.tile b { font-weight: 600; font-size: 14px; }
.tile span { font-size: 12px; color: var(--muted); }
.tile .count { position: absolute; }

/* ───── Login page ───── */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px var(--gutter); }
.login-card { width: 100%; max-width: 380px; }
.login-card .mark { width: 52px; height: 52px; border-radius: 14px; background: var(--ink); color: var(--ink-text); display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; font-size: 22px; margin-bottom: 18px; }
.login-card h1 { font-size: 26px; }
.login-card .school { color: var(--muted); margin-bottom: 22px; }

/* ───── Print ───── */
@media print {
  body { background: #fff; color: #000; font-size: 13pt; }
  .appbar, .tabbar, .rail, .no-print, .toasts { display: none !important; }
  .main { padding: 0; }
  .card { border: 0; padding: 0; }
  a { color: inherit; text-decoration: none; }
}
