:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --line: #e3e8f2;
  --ink: #0f1a2e;
  --ink-2: #4d5b76;
  --ink-3: #7c89a3;
  --brand: #0f2a5c;
  --brand-2: #1e4fa8;
  --accent: #f5a524;
  --good: #15803d;   --good-bg: #e8f6ee;
  --warn: #b45309;   --warn-bg: #fdf3e2;
  --bad: #b91c1c;    --bad-bg: #fdecec;
  --info: #1d4ed8;   --info-bg: #e9effd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
[hidden] { display: none !important; }
a { color: var(--brand-2); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.error { color: var(--bad); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; word-break: break-all; }
.num { font-variant-numeric: tabular-nums; }

/* Buttons & inputs */
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #1b1300; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.25); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.icon-btn { background: none; border: 0; font-size: 22px; cursor: pointer; display: none; color: var(--ink); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand-2) 35%, transparent); border-color: var(--brand-2); }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0f2a5c, #1e4fa8); }
.login-card { background: var(--surface); padding: 32px; border-radius: 18px; width: min(400px, 100%); display: grid; gap: 14px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.login-card img { margin: 0 auto; }
.login-card h1 { font-size: 19px; }
.login-card label { text-align: left; }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #dfe7f7; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 16px 12px; }
.side-brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.side-brand strong { display: block; color: #fff; font-size: 16px; }
.side-brand span { font-size: 11.5px; opacity: .8; }
#nav { display: grid; gap: 2px; flex: 1; align-content: start; }
#nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 9px; color: #dfe7f7; text-decoration: none; font-weight: 500; }
#nav a:hover { background: rgba(255,255,255,.08); }
#nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.side-foot { display: grid; gap: 10px; }
.user-row { display: flex; justify-content: space-between; font-size: 12.5px; opacity: .9; padding: 0 4px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { font-size: 18px; flex: 1; }
.live-dot { font-size: 12px; font-weight: 700; color: var(--ink-3); }
.live-dot.on { color: var(--good); }
.view { padding: 20px 24px 48px; display: grid; gap: 18px; align-content: start; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); }
  .icon-btn { display: block; }
  .view { padding: 16px 16px 40px; }
  .topbar { padding: 12px 16px; }
}

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 18px; }
@media (max-width: 1100px) { .grid-main { grid-template-columns: 1fr; } }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.toolbar .spacer { flex: 1; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.tile .label { color: var(--ink-2); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.tile .value { font-size: 30px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--ink-3); font-size: 12.5px; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-3); font-weight: 700; background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
td.actions { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--ink-3); padding: 28px 10px; }

/* Chips */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.muted { background: #eef1f6; color: var(--ink-2); }

/* Avatars */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #e6ebf5 center/cover no-repeat; display: inline-grid; place-items: center; font-weight: 700; color: var(--ink-2); font-size: 13px; flex: none; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who b { display: block; }
.who small { color: var(--ink-3); }

/* Feed */
.feed { display: grid; gap: 2px; max-height: 520px; overflow: auto; }
.feed-item { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 8px; }
.feed-item.new { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #fff4d6; } }
.feed-item .meta { margin-left: auto; text-align: right; font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }

/* Chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.chart .bar { fill: var(--brand-2); }
.chart .bar.today { fill: var(--accent); }
.chart .hit:hover + .bar, .chart .bar:hover { opacity: .85; }
.tooltip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -110%); box-shadow: 0 6px 20px rgba(0,0,0,.18); }

/* Progress */
.bar-track { height: 8px; background: #eef1f6; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar-fill { height: 100%; background: var(--brand-2); border-radius: 99px; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,26,46,.5); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fadein .12s; }
@keyframes fadein { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 16px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.modal.wide { width: min(900px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 18px 20px; display: grid; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* Enrollment */
.enroll { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 700px) { .enroll { grid-template-columns: 1fr; } }
.enroll-cam { position: relative; aspect-ratio: 4/3; background: #0b1220; border-radius: 12px; overflow: hidden; }
.enroll-cam video, .enroll-cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.enroll-cam .msg { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff; font-weight: 600; text-align: center; }
.samples { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.samples div { aspect-ratio: 1; border-radius: 8px; background: #eef1f6 center/cover; border: 2px dashed var(--line); }
.samples div.done { border: 2px solid var(--good); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-color: var(--accent); }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); max-width: 360px; animation: fadein .15s; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--good); }

.banner { background: var(--warn-bg); color: var(--warn); border: 1px solid #f6d9a8; padding: 12px 16px; border-radius: 10px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.code-box { background: #0f1a2e; color: #e6edf8; padding: 12px 14px; border-radius: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { display: flex; align-items: center; gap: 4px; font-weight: 500; color: var(--ink); background: var(--surface-2); padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; }
