/* Foreign Teacher Attendance Logbook — quiet chrome, one accent. Tokens first. */
:root {
  --ground: #f4f7f5; --surface: #ffffff; --raised: #eaf1ed; --mint: #dcebe3;
  --ink: #14211b; --ink-2: #44554c; --ink-3: #66776d;
  --accent: #0f5c43; --accent-ink: #ffffff; --accent-2: #0a4533; --gold: #a07a1c;
  --ok: #1a7f4f; --warn: #9a6a00; --bad: #b3261e; --info: #1f5fa8;
  --line: rgba(20, 33, 27, .10);
  --r-ctl: 8px; --r-card: 14px;
  --f-th: 'Kanit', system-ui, sans-serif; --f-en: 'Inter', system-ui, sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --fs: 16px;
}
[data-theme="dark"] {
  --ground: #0d1511; --surface: #131e18; --raised: #1b2922; --mint: #1f3328;
  --ink: #e9f0ec; --ink-2: #a9b9b0; --ink-3: #8a9b91;
  --accent: #3fbf8a; --accent-ink: #06150e; --accent-2: #5fd3a2; --gold: #d2a94a;
  --ok: #52c58a; --warn: #e0b04a; --bad: #ef7b73; --info: #6fa8e8;
  --line: rgba(233, 240, 236, .10);
}
* { box-sizing: border-box; }
html { font-size: var(--fs); }
body { margin: 0; background: var(--ground); color: var(--ink); font: 400 1rem/1.55 var(--f-en); -webkit-font-smoothing: antialiased; }
html[lang="th"] body, html[lang="th"] button, html[lang="th"] input, html[lang="th"] select, html[lang="th"] textarea { font-family: var(--f-th); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; font-weight: 500; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--ink-3); } .small { font-size: .875rem; } .num { font-variant-numeric: tabular-nums; }

/* shell */
.shell { display: grid; grid-template-columns: 17rem 1fr; min-height: 100vh; }
.shell.collapsed { grid-template-columns: 4.5rem 1fr; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .75rem; padding: .25rem .5rem 1.25rem; font-weight: 500; }
.brand-mark { width: 2.25rem; height: 2.25rem; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 600; flex: none; }
.brand-name { line-height: 1.15; font-size: .95rem; } .brand-name small { display: block; color: var(--ink-3); font-weight: 400; font-size: .75rem; }
.nav a { display: flex; align-items: center; gap: .75rem; height: 2.5rem; padding: 0 .75rem; border-radius: var(--r-ctl); color: var(--ink-2); text-decoration: none; transition: background-color .15s var(--ease), color .15s var(--ease); }
.nav a:hover { background: var(--raised); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--mint); color: var(--ink); font-weight: 500; }
.nav svg { width: 1.1rem; height: 1.1rem; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.nav-sep { margin: 1rem 0 .25rem; padding: 0 .75rem; color: var(--ink-3); font-size: .8rem; }
.collapsed .brand-name, .collapsed .nav span, .collapsed .nav-sep { display: none; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 3.5rem; display: flex; align-items: center; gap: .5rem; padding: 0 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.top .grow { flex: 1; }
.chip-btn { height: 2.25rem; min-width: 2.25rem; padding: 0 .75rem; border: 1px solid var(--line); border-radius: var(--r-ctl); background: transparent; cursor: pointer; text-decoration: none; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; transition: background-color .15s var(--ease); }
.chip-btn:hover { background: var(--raised); }
.who { text-align: right; line-height: 1.2; margin-left: .5rem; } .who b { font-weight: 500; font-size: .9rem; } .who span { display: block; color: var(--ink-3); font-size: .75rem; }
.page { padding: 1.5rem; width: 100%; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

/* controls */
.btn { height: 2.75rem; padding: 0 1.25rem; border: 0; border-radius: var(--r-ctl); background: var(--accent); color: var(--accent-ink); font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; text-decoration: none; transition: background-color .15s var(--ease), transform .12s var(--ease); }
.btn:hover { background: var(--accent-2); } .btn:active { transform: scale(.98); }
.btn.sec { background: var(--raised); color: var(--ink); } .btn.sec:hover { background: var(--mint); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.sm { height: 2.25rem; padding: 0 .9rem; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.field { display: grid; gap: .35rem; } .field > label { font-size: .875rem; color: var(--ink-2); }
.input, select.input, textarea.input { width: 100%; height: 2.75rem; padding: 0 .85rem; border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface); transition: border-color .15s var(--ease); }
textarea.input { height: auto; padding: .6rem .85rem; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.hint { font-size: .8rem; color: var(--ink-3); }
.grid { display: grid; gap: 1rem; } .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border-radius: var(--r-card); padding: 1.25rem; }
.card.flat { background: var(--raised); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { background: var(--surface); border-radius: var(--r-card); padding: 1rem 1.25rem; }
.stat .v { font-size: 2rem; font-weight: 500; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--ink-3); font-size: .85rem; }
.stat.bad .v { color: var(--bad); } .stat.warn .v { color: var(--warn); }

/* tables */
.tablewrap { overflow-x: auto; background: var(--surface); border-radius: var(--r-card); }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: .82rem; padding: .85rem 1rem; background: var(--raised); white-space: nowrap; }
table.t td { padding: .8rem 1rem; vertical-align: middle; border-top: 1px solid var(--line); }
table.t td.r, table.t th.r { text-align: right; } table.t tbody tr:hover { background: color-mix(in srgb, var(--mint) 35%, transparent); }
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; background: var(--raised); color: var(--ink-2); }
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); } .badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); } .badge.info { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); }
.rowactions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--ink-3); }

/* alerts + toast */
.alert { padding: .8rem 1rem; border-radius: var(--r-ctl); margin-bottom: 1rem; background: var(--raised); }
.alert.err { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); color: var(--bad); } .alert.okk { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); color: var(--ok); }
.cred { font: 500 1.4rem/1 ui-monospace, monospace; letter-spacing: .05em; padding: .75rem 1rem; background: var(--surface); border-radius: var(--r-ctl); display: inline-block; user-select: all; }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 50; }
.toast { background: var(--ink); color: var(--ground); padding: .75rem 1rem; border-radius: var(--r-ctl); max-width: 22rem; animation: rise .25s var(--ease); }
.toast.bad { background: var(--bad); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
dialog { border: 0; border-radius: var(--r-card); padding: 1.5rem; background: var(--surface); color: var(--ink); max-width: 26rem; width: calc(100% - 2rem); }
dialog::backdrop { background: rgba(8, 16, 12, .5); }
dialog .row { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }

/* login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: var(--accent); color: var(--accent-ink); padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; }
.login-art h1 { font-size: clamp(2.2rem, 4.4vw, 3.6rem); line-height: 1.05; letter-spacing: -.03em; max-width: 18ch; }
.login-art p { max-width: 34ch; opacity: .85; }
.login-form { padding: 3rem; display: flex; flex-direction: column; justify-content: center; max-width: 28rem; width: 100%; margin: 0 auto; gap: 1rem; }

/* attendance */
.punch { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; align-items: start; }
.clock { font-size: clamp(2.8rem, 8vw, 4.5rem); font-weight: 500; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.bigbtns { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1.25rem; }
.bigbtn { height: 5rem; font-size: 1.15rem; border-radius: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0; } .kv dt { color: var(--ink-3); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.gps-pill { display: inline-flex; align-items: center; gap: .5rem; padding: .35rem .8rem; border-radius: 999px; background: var(--raised); font-size: .9rem; }
.dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--ink-3); } .dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }
.sigpad { width: 100%; height: 14rem; background: repeating-conic-gradient(var(--raised) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; border-radius: var(--r-ctl); touch-action: none; display: block; cursor: crosshair; }
.sigprev { max-width: 100%; max-height: 7rem; display: block; background: repeating-conic-gradient(var(--raised) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; border-radius: var(--r-ctl); padding: .5rem; }
.tabs { display: inline-flex; background: var(--raised); border-radius: var(--r-ctl); padding: .2rem; margin-bottom: 1rem; }
.tabs button { border: 0; background: transparent; padding: .45rem 1rem; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 500; }
#map { height: 22rem; border-radius: var(--r-ctl); z-index: 0; }

.bottomnav { display: none; }
@media (max-width: 960px) {
  .shell, .shell.collapsed { grid-template-columns: 1fr; }
  .side { display: none; }
  .page { padding: 1rem 1rem 6rem; } .top { padding: 0 1rem; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; } .login-art { padding: 1.5rem; min-height: 14rem; } .login-form { padding: 1.5rem; }
  .punch { grid-template-columns: 1fr; }
  .bigbtn { height: 5.5rem; }
  .bottomnav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a, .bottomnav button { display: grid; place-items: center; gap: .15rem; padding: .55rem 0; font-size: .72rem; color: var(--ink-3); text-decoration: none; background: none; border: 0; cursor: pointer; }
  .bottomnav a[aria-current="page"] { color: var(--accent); font-weight: 500; }
  .bottomnav svg { width: 1.3rem; height: 1.3rem; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  .who { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* phase 5: personal calendar, history, dashboard charts */
.stats.s5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.monthnav { display: flex; align-items: center; gap: .75rem; } .monthnav b { min-width: 9rem; text-align: center; font-weight: 500; }
.chip-btn.off { opacity: .35; cursor: default; }
.mine { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .35rem; }
.cal-h { text-align: center; font-size: .8rem; color: var(--ink-3); padding-bottom: .25rem; }
.cal-d { display: flex; flex-direction: column; justify-content: space-between; min-height: 4.25rem; padding: .4rem .5rem; border-radius: 10px; text-decoration: none; color: var(--ink); background: var(--raised); border: 1px solid transparent; transition: border-color .15s var(--ease); }
.cal-d:hover { border-color: var(--line); } .cal-d.sel { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.cal-d .n { font-weight: 500; } .cal-d .lb { font-size: .72rem; color: var(--ink-2); line-height: 1.2; }
.s-on_time { background: color-mix(in srgb, var(--ok) 18%, var(--surface)); } .s-late { background: color-mix(in srgb, var(--warn) 22%, var(--surface)); }
.s-present { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); } .s-leave { background: color-mix(in srgb, var(--info) 16%, var(--surface)); }
.s-missing { background: color-mix(in srgb, var(--bad) 16%, var(--surface)); } .s-off, .s-future { background: transparent; border-color: var(--line); } .s-off .lb, .s-future .lb { color: var(--ink-3); }
.s-today { background: var(--surface); border-color: var(--accent); }
.badge.s-on_time, .badge.s-present { color: var(--ok); } .badge.s-late { color: var(--warn); } .badge.s-missing { color: var(--bad); } .badge.s-leave { color: var(--info); }
.legend { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin-top: 1rem; font-size: .85rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; } .sw { width: .9rem; height: .9rem; border-radius: 4px; display: inline-block; border: 1px solid var(--line); }
.sigrow { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; } .sigrow figure { margin: 0; }
.filters { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .75rem; align-items: end; }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }
.dash { grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); margin-bottom: 1.5rem; align-items: stretch; }
.chartbox { position: relative; height: 16rem; margin-top: 1rem; }
.feed { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .1rem; max-height: 17rem; overflow-y: auto; }
.feed li { display: grid; grid-template-columns: 3rem 1fr auto; gap: .75rem; align-items: baseline; padding: .5rem 0; border-top: 1px solid var(--line); font-size: .92rem; }
.feed li:first-child { border-top: 0; } .feed .tm { color: var(--ink-3); font-variant-numeric: tabular-nums; } .feed .sc { color: var(--ink-3); font-size: .8rem; }
.live-dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: var(--ok); margin-right: .4rem; }
@media (max-width: 960px) { .stats.s5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .mine, .dash { grid-template-columns: 1fr; } .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cal-d { min-height: 3.25rem; } .cal-d .lb { display: none; } }
@media print {
  .side, .top, .bottomnav, .noprint, #toasts { display: none !important; }
  .shell { display: block; } body { background: #fff; color: #000; } .page { max-width: none; padding: 0; }
  .tablewrap, .card { background: #fff; border-radius: 0; } table.t { font-size: 10pt; } table.t th { background: #eee; color: #000; }
  .badge { background: none; border: 1px solid #999; color: #000; }
}

/* phase 6: reports */
.tabbtn { position: relative; } .tabbtn input { position: absolute; opacity: 0; pointer-events: none; }
.tabbtn span { display: inline-block; padding: .45rem 1rem; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.tabbtn input:checked + span { background: var(--surface); color: var(--ink); font-weight: 500; }
.tabbtn input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
#rep-form .filters { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
.rep-sec { margin-top: 1.5rem; } .rep-h { margin-bottom: .6rem; }
table.t.grid th, table.t.grid td { padding: .35rem .25rem; font-size: .78rem; min-width: 1.6rem; }
table.t.grid td.nm { white-space: nowrap; padding-right: .75rem; font-size: .85rem; }
td.gc { font-weight: 500; } td.c, th.c { text-align: center; }
[hidden] { display: none !important; }

/* phase 7: system management */
.brand-logo { width: 2.25rem; height: 2.25rem; object-fit: contain; border-radius: 8px; flex: none; }
.settings .card h2 { margin-bottom: .75rem; }
label.check { display: flex; gap: .6rem; align-items: flex-start; margin-top: .75rem; cursor: pointer; }
label.check input { margin-top: .3rem; width: 1rem; height: 1rem; accent-color: var(--accent); }
label.check .hint { display: block; }
.inputunit { display: flex; align-items: center; gap: .5rem; } .inputunit .input { flex: 1; } .inputunit span { color: var(--ink-3); font-size: .85rem; white-space: nowrap; }
.actions-bar { position: sticky; bottom: 0; padding: .75rem 0; background: var(--ground); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }
.brandslot { display: grid; gap: .6rem; align-content: start; }
.brandprev { height: 6rem; display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 10px; background: var(--raised); }
.brandprev img { max-height: 5rem; max-width: 90%; object-fit: contain; }
.brandform { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; } .brandform input[type=file] { font-size: .85rem; max-width: 100%; }
.tabs a.tabbtn { text-decoration: none; } .tabbtn span.on { background: var(--surface); color: var(--ink); font-weight: 500; }
pre.json { margin: 0; padding: .6rem .75rem; background: var(--raised); border-radius: 8px; font: .78rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; max-height: 18rem; overflow: auto; }
tr.detail td { background: var(--raised); padding-top: 0; } tr.detail summary { cursor: pointer; color: var(--ink-2); padding: .35rem 0; }
.stats.s4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row-form { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; } .row-form label.check { margin-top: 0; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.foot-line { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--line); font-size: .82rem; color: var(--ink-3); }
.foot-line a { color: var(--ink-2); }
.doc { max-width: 46rem; margin: 0 auto; padding: 2rem 1.25rem 4rem; line-height: 1.7; }
.doc h1 { margin: 1.5rem 0 .25rem; } .doc h2 { margin: 1.75rem 0 .4rem; font-size: 1.1rem; } .doc ul { padding-left: 1.2rem; }
@media (max-width: 960px) { .stats.s4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.rowbtns { display: flex; gap: .4rem; justify-content: flex-end; flex-wrap: wrap; } .rowbtns form { margin: 0; } .stat .v.vsm { font-size: 1.35rem; line-height: 1.3; }
