/* BSIT IA Attendance Checker — layout and components. Tokens live in tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.icon { flex: none; display: block; }
[hidden] { display: none !important; } /* component display rules must not override the hidden attribute */
:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }
#view:focus { outline: none; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--blue-600); color: #fff; padding: 10px 14px; border-radius: 8px; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ---------- App frame ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.main { min-width: 0; display: flex; flex-direction: column; }
#view { width: 100%; max-width: 1320px; margin: 0 auto; padding: 26px 32px 48px; flex: 1; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; z-index: 40;
  display: flex; flex-direction: column; gap: 22px;
  padding: 22px 14px 18px;
  color: #b9c5dc;
  background:
    radial-gradient(120% 60% at 0% 0%, rgba(59, 130, 246, 0.16), transparent 60%),
    linear-gradient(180deg, var(--navy-800), var(--navy-900) 70%, var(--navy-950));
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; text-decoration: none; color: #fff; }
.brand__mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: linear-gradient(145deg, var(--blue-500), var(--blue-700)); box-shadow: var(--shadow-blue);
}
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text strong { font-size: 17px; letter-spacing: 0.01em; }
.brand__text span { font-size: 12.5px; color: #9fb0cf; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav__link {
  display: flex; align-items: center; gap: 13px; padding: 11px 14px; border-radius: 11px;
  color: #b9c5dc; text-decoration: none; font-weight: 500; font-size: 14.5px;
  transition: background 0.15s, color 0.15s;
}
.nav__link:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav__link[aria-current="page"] { background: var(--blue-600); color: #fff; box-shadow: var(--shadow-blue); }

.sync-pill {
  display: flex; align-items: center; gap: 11px; padding: 12px 14px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.08);
}
.sync-pill strong { display: block; color: #fff; font-size: 13.5px; line-height: 1.2; }
.sync-pill small { color: #94a6c7; font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18); flex: none; }
.is-offline .dot { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2); }

.scrim { position: fixed; inset: 0; z-index: 39; background: rgba(8, 19, 38, 0.55); backdrop-filter: blur(2px); }
.scrim[hidden] { display: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 32px;
  background: rgba(243, 246, 251, 0.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__spacer { flex: 1; }
.topbar__brand { display: none; font-weight: 700; font-size: 15.5px; }
.icon-btn.menu-btn { display: none; }
.search {
  display: flex; align-items: center; gap: 10px; width: min(420px, 38vw); height: 42px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; color: var(--subtle);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 14px; }
.search input::placeholder { color: var(--subtle); }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--text-2); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface); border-color: var(--border); }
.net-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: var(--radius-pill);
  background: var(--green-50); color: var(--green-700); font-size: 13px; font-weight: 600;
}
.net-chip .dot { width: 8px; height: 8px; box-shadow: none; }
.is-offline .net-chip { background: var(--amber-50); color: var(--amber-700); }
.user { display: flex; align-items: center; gap: 10px; padding-left: 6px; }
.user__name { font-size: 14px; font-weight: 600; color: var(--text-2); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--blue-500), var(--blue-700)); color: #fff; font-weight: 700; font-size: 13px;
}

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; line-height: 1.2; letter-spacing: -0.015em; }
.page-head p { color: var(--muted); margin-top: 4px; }
.page-head__actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.clock { text-align: right; }
.clock strong { display: block; font-size: 26px; letter-spacing: -0.02em; line-height: 1.1; }
.clock span { color: var(--muted); font-size: 13px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.card__head h2 { font-size: 16px; letter-spacing: -0.005em; }
.card__body { padding: 16px 20px 20px; }
.card--flush .card__body { padding: 0; }

.grid { display: grid; gap: 18px; }
.dash-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-6 { grid-column: span 6; } .span-4 { grid-column: span 4; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }

.stat { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.stat__label { color: var(--muted); font-size: 13.5px; font-weight: 500; }
.stat__value { font-size: 32px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; margin-top: 2px; }
.tile { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; }
.tile--blue { background: var(--blue-50); color: var(--blue-600); }
.tile--green { background: var(--green-50); color: var(--green-600); }
.tile--red { background: var(--red-50); color: var(--red-600); }
.tile--amber { background: var(--amber-50); color: var(--amber-600); }

.rate { display: flex; align-items: center; gap: 20px; padding: 20px; height: 100%; }
.ring { position: relative; width: 112px; height: 112px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring__track { stroke: var(--blue-50); }
.ring__bar { stroke: var(--blue-600); stroke-linecap: round; }
.ring__label { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.rate h2 { font-size: 16px; }
.rate p { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 18px;
  border-radius: 11px; border: 1px solid transparent; font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.btn--primary { background: var(--blue-600); color: #fff; box-shadow: var(--shadow-blue); }
.btn--primary:hover:not(:disabled) { background: var(--blue-700); }
.btn--secondary { background: var(--surface); color: var(--blue-700); border-color: var(--blue-100); }
.btn--secondary:hover:not(:disabled) { background: var(--blue-50); }
.btn--ghost { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.btn--ghost:hover:not(:disabled) { background: var(--bg); }
.btn--block { width: 100%; }
.btn:disabled { cursor: not-allowed; opacity: 0.55; box-shadow: none; }

.stage-tag {
  display: inline-block; padding: 2px 9px; border-radius: var(--radius-pill); background: var(--blue-50); color: var(--blue-700);
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); font-size: 14.5px;
}
.input:disabled { background: #f8fafc; color: var(--subtle); cursor: not-allowed; }
.hint { font-size: 12.5px; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--border); }
.switch-row:first-child { border-top: 0; }
.switch-row strong { display: block; font-size: 14px; }
.switch-row small { color: var(--muted); font-size: 12.5px; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 42px; height: 24px; border-radius: 99px; background: var(--border-strong);
  position: relative; margin: 0; transition: background 0.15s;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform 0.15s; }
.switch:checked { background: var(--blue-600); }
.switch:checked::after { transform: translateX(18px); }
.switch:disabled { opacity: 0.6; cursor: not-allowed; }

.segmented { display: inline-flex; padding: 3px; background: var(--bg); border: 1px solid var(--border); border-radius: 11px; }
.segmented button { border: 0; background: transparent; padding: 7px 16px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--blue-600); color: #fff; }
.segmented button:disabled { cursor: not-allowed; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.toolbar .input { width: auto; min-width: 150px; }
.toolbar .grow { flex: 1; min-width: 200px; }

/* ---------- Tables & badges ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 13px 20px; background: #f8fafc; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 14px 20px; border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
td.empty-cell { padding: 0; }
table.table--empty { min-width: 0; } /* nothing to scroll while the table only holds an empty state */

.badge { display: inline-flex; align-items: center; gap: 7px; padding: 3px 11px 3px 9px; border-radius: var(--radius-pill); font-size: 12.5px; font-weight: 600; }
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--present { background: var(--green-50); color: var(--green-700); }
.badge--late { background: var(--amber-50); color: var(--amber-700); }
.badge--absent { background: var(--red-50); color: var(--red-700); }
.badge--info { background: var(--blue-50); color: var(--blue-700); }
.badge--muted { background: #f1f5f9; color: var(--muted); }

/* ---------- Empty states ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 38px 24px; }
.empty__icon { width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; background: var(--blue-50); color: var(--blue-600); margin-bottom: 4px; }
.empty h3 { font-size: 16px; }
.empty p { color: var(--muted); max-width: 42ch; font-size: 14px; }
.empty .btn { margin-top: 8px; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.quick { display: flex; flex-direction: column; gap: 10px; }
.steps { counter-reset: s; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; padding: 0; margin: 0; list-style: none; }
.steps li { counter-increment: s; display: flex; gap: 14px; align-items: flex-start; }
.steps li::before { content: counter(s); flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--blue-600); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.steps strong { display: block; font-size: 14.5px; }
.steps span { color: var(--muted); font-size: 13.5px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); font-size: 14px; }
.kv:first-child { border-top: 0; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 600; text-align: right; }

.report-card { display: flex; flex-direction: column; gap: 10px; padding: 22px; }
.report-card h3 { font-size: 16px; }
.report-card p { color: var(--muted); font-size: 14px; flex: 1; }

/* ---------- Scan page ---------- */
.scan-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.viewfinder {
  position: relative; aspect-ratio: 4 / 3; overflow: hidden; border-radius: var(--radius);
  display: grid; place-items: center; text-align: center; color: #c5d1e8;
  background: radial-gradient(70% 70% at 50% 40%, #1b2c52, var(--navy-950));
  box-shadow: var(--shadow);
}
.viewfinder__hint { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 24px; max-width: 34ch; font-size: 14px; }
.viewfinder__hint .icon { color: #7ea6f5; }
.viewfinder__caption { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; font-size: 12.5px; color: #9fb0cf; }
.vf-corner { position: absolute; width: 44px; height: 44px; border: 0 solid var(--blue-500); }
.vf-corner.tl { top: 16%; left: 20%; border-top-width: 5px; border-left-width: 5px; border-top-left-radius: 14px; }
.vf-corner.tr { top: 16%; right: 20%; border-top-width: 5px; border-right-width: 5px; border-top-right-radius: 14px; }
.vf-corner.bl { bottom: 16%; left: 20%; border-bottom-width: 5px; border-left-width: 5px; border-bottom-left-radius: 14px; }
.vf-corner.br { bottom: 16%; right: 20%; border-bottom-width: 5px; border-right-width: 5px; border-bottom-right-radius: 14px; }
.notice { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--blue-50); border: 1px solid var(--blue-100); color: var(--blue-700); font-size: 13.5px; font-weight: 500; }
.side-stack { display: flex; flex-direction: column; gap: 18px; }

/* ---------- Subjects ---------- */
.split { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 2fr); gap: 20px; align-items: start; }
.legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.legend p { color: var(--muted); font-size: 13.5px; margin-top: 6px; }

/* ---------- Subjects, dialogs, toasts (Stage 2) ---------- */
.btn--danger { background: var(--red-600); color: #fff; }
.btn--danger:hover:not(:disabled) { background: var(--red-700); }
.btn--danger-text { color: var(--red-700); }
.btn--danger-text:hover:not(:disabled) { background: var(--red-50); border-color: #fecaca; }

.field-error { color: var(--red-600); font-size: 12.5px; font-weight: 500; }
.field-error:empty { display: none; }
.input[aria-invalid="true"] { border-color: var(--red-600); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }
.input:focus-visible { border-color: var(--blue-500); outline-offset: 0; }
.optional { color: var(--subtle); font-weight: 500; }

.subject-list { display: flex; flex-direction: column; gap: 8px; }
.subject-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; color: var(--muted);
  transition: background 0.15s, border-color 0.15s;
}
.subject-item:hover { background: var(--blue-50); border-color: var(--blue-100); }
.subject-item[aria-pressed="true"] { background: var(--blue-50); border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.subject-item__code {
  flex: none; min-width: 52px; max-width: 92px; height: 40px; padding: 0 10px; border-radius: 10px; display: grid; place-items: center;
  background: var(--blue-600); color: #fff; font-weight: 700; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.subject-item__main { flex: 1; min-width: 0; }
.subject-item__main strong { display: block; color: var(--text); font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subject-item__main small { color: var(--muted); font-size: 12.5px; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.rule { display: grid; gap: 10px; }
.rule__row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; background: #f8fafc; font-size: 14px; }

dialog.modal {
  border: 0; padding: 0; border-radius: 16px; width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  color: var(--text); background: var(--surface); box-shadow: 0 24px 60px rgba(8, 19, 38, 0.35);
}
dialog.modal::backdrop { background: rgba(8, 19, 38, 0.55); backdrop-filter: blur(2px); }
.modal__form { display: flex; flex-direction: column; max-height: inherit; }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 4px 24px; }
.modal__head h2 { font-size: 18px; }
.modal__body { padding: 12px 24px 6px; overflow-y: auto; }
.modal__body p { color: var(--text-2); }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 20px; }

#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px; background: var(--navy-900); color: #fff; font-size: 14px; font-weight: 500; box-shadow: 0 10px 30px rgba(8, 19, 38, 0.3); animation: toast-in 0.2s ease; }
.toast--success .icon { color: #4ade80; }
.toast--error { background: var(--red-700); }
.toast--error .icon { color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Students & QR cards (Stage 3) ---------- */
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.93em; letter-spacing: 0.01em; }
.table-foot { padding: 12px 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.th-actions { text-align: right; }
.c-name strong { display: block; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.icon-btn--sm { width: 38px; height: 38px; border-radius: 10px; }
.icon-btn--danger:hover { background: var(--red-50); color: var(--red-700); border-color: #fecaca; }
.input[readonly] { background: #f8fafc; color: var(--text-2); cursor: not-allowed; }
.qr-thumb {
  display: block; width: 46px; height: 46px; padding: 2px; background: #fff; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 10px; transition: border-color 0.15s, box-shadow 0.15s;
}
.qr-thumb:hover { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.qr-thumb svg { display: block; width: 100%; height: 100%; }
@keyframes row-flash { from { background: var(--blue-100); } to { background: transparent; } }
.row--flash td { animation: row-flash 1.8s ease-out; }

.qr-view { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 4px 0 10px; }
.qr-view__code { width: min(300px, 72vw); aspect-ratio: 1; background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 6px; }
.qr-view__code svg { display: block; width: 100%; height: 100%; }
.qr-view__card { display: block; width: min(320px, 78vw); height: auto; border-radius: 6.5%/5.1%; box-shadow: var(--shadow); }
.qr-view h3 { font-size: 20px; margin-top: 12px; overflow-wrap: anywhere; }
.qr-view p { color: var(--text-2); }
.qr-view .hint { max-width: 38ch; margin-top: 4px; color: var(--muted); }

.modal__foot { flex-wrap: wrap; }
.modal__foot > .btn--ghost:not(.btn--danger-text) { order: -2; }
.modal__foot > [data-again] { order: -1; }

/* Print: only #printArea is shown. Single card = one large centred card; "all" = 2-column grid that breaks between cards. */
#printArea { display: none; }
@media print {
  @page { margin: 10mm; }
  html, body.is-printing { background: #fff; }
  body.is-printing > *:not(#printArea) { display: none !important; }
  body.is-printing #printArea { display: block; }
  .print-sheet--grid { display: grid; grid-template-columns: repeat(2, 84mm); justify-content: center; gap: 8mm; }
  .print-sheet--single { display: flex; justify-content: center; padding-top: 14mm; }
  .print-card { margin: 0; break-inside: avoid; page-break-inside: avoid; }
  .print-card__img { display: block; width: 84mm; height: auto; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-sheet--single .print-card__img { width: 110mm; }
}

/* ---------- Bottom nav (phones) ---------- */
.bottomnav { display: none; }

/* ======================= Responsive ======================= */
@media (max-width: 1180px) {
  .stats { grid-column: span 12; }
  .dash-grid .rate-col { grid-column: span 12; }
  .dash-grid .span-4 { grid-column: span 6; }
  .dash-grid .span-4:last-child { grid-column: span 12; }
  .steps { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); height: 100dvh;
    transform: translateX(-102%); visibility: hidden; /* hidden = off-canvas links aren't focusable */
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }
  .drawer-open .sidebar { transform: none; visibility: visible; transition-delay: 0s; box-shadow: 8px 0 32px rgba(8, 19, 38, 0.35); }
  .icon-btn.menu-btn { display: grid; }
  .topbar { padding: 0 16px; }
  .topbar__brand { display: block; }
  .topbar .search, .user__name { display: none; } /* scoped: the Students page search must stay visible */
  #view { padding: 20px 16px 32px; }
  .scan-grid, .split { grid-template-columns: minmax(0, 1fr); }
  .legend { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 23px; }
}

@media (max-width: 720px) {
  .bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.06);
  }
  .bottomnav__link {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: none;
    color: var(--muted); font-size: 11.5px; font-weight: 600; text-decoration: none; cursor: pointer;
  }
  .bottomnav__link[aria-current="page"] { color: var(--blue-600); }
  #view { padding-bottom: calc(var(--bottomnav-h) + 36px); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 14px; gap: 10px; }
  .stat__value { font-size: 27px; }
  .dash-grid .span-4, .dash-grid .span-4:last-child { grid-column: span 12; }
  .form-row { grid-template-columns: 1fr; }
  .net-chip { display: none; }
  .page-head__actions { width: 100%; }
  .page-head__actions .btn { flex: 1; }
  .toolbar .input { flex: 1; min-width: 130px; }
  table.table--empty thead { display: none; }
  /* Students list: each row becomes a card (QR thumbnail, name, ID, then actions) */
  table.table--stack { min-width: 0; }
  table.table--stack, .table--stack tbody { display: block; }
  .table--stack thead { display: none; }
  .table--stack tbody tr {
    display: grid; grid-template-columns: 56px minmax(0, 1fr); grid-template-areas: "qr name" "qr id" "sub sub" "act act";
    column-gap: 14px; row-gap: 2px; padding: 14px 16px; border-bottom: 1px solid var(--border);
  }
  .table--stack tbody tr:last-child { border-bottom: 0; }
  .table--stack td { padding: 0; border: 0; min-width: 0; }
  .table--stack .c-qr { grid-area: qr; align-self: start; }
  .table--stack .c-name { grid-area: name; align-self: end; }
  .table--stack .c-name strong { white-space: normal; max-width: none; overflow-wrap: anywhere; } /* show the full name on phones */
  .table--stack .c-id { grid-area: id; }
  .table--stack .c-reg { display: none; }
  .table--stack .c-sub { grid-area: sub; margin-top: 8px; }
  .table--stack .c-act { grid-area: act; margin-top: 10px; }
  .table--stack .row-actions { justify-content: flex-start; gap: 6px; }
  .table--stack .icon-btn--sm { border-color: var(--border); }
  .qr-thumb { width: 56px; height: 56px; }
  .modal__foot .btn { flex: 1 1 auto; }
  #toasts { bottom: calc(var(--bottomnav-h) + 16px); }
  .clock { text-align: left; }
  .clock strong { font-size: 22px; }
  .viewfinder { aspect-ratio: 1 / 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Scanning (Stage 4) ---------- */
.scan-bar { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 14px 18px; align-items: end; padding: 18px 20px; margin-bottom: 20px; }
.scan-bar__field { display: flex; flex-direction: column; gap: 6px; }
.scan-bar__field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.scan-bar__actions { display: flex; gap: 10px; }
.scan-bar__info { grid-column: 1 / -1; margin: 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13.5px; line-height: 1.5; color: var(--muted); }
.scan-bar__info strong { color: var(--text); font-size: 15px; }
.scan-bar > .empty { grid-column: 1 / -1; }

.viewfinder { max-height: 64vh; }
.viewfinder video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; background: #000; }
.viewfinder[data-state="on"] video { display: block; }
.viewfinder .vf-corner, .viewfinder__caption { z-index: 2; display: none; }
.viewfinder[data-state="on"] .vf-corner, .viewfinder[data-state="on"] .viewfinder__caption { display: block; }
.viewfinder[data-state="on"] .viewfinder__caption { text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7); color: #fff; }
.viewfinder[data-state="on"] .viewfinder__hint { display: none; }
.viewfinder[data-state="error"] .viewfinder__hint .icon { color: #fca5a5; }
.viewfinder__chip { position: absolute; z-index: 3; top: 12px; left: 12px; max-width: calc(100% - 24px); padding: 6px 12px; border-radius: var(--radius-pill); background: rgba(8, 19, 38, 0.78); color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewfinder__hint { max-width: 44ch; }

.scan-result { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; padding: 16px 18px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.scan-result__icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--bg); color: var(--muted); }
.scan-result__main { min-width: 0; }
.scan-result h3 { font-size: 15px; }
.scan-result p { margin: 2px 0 0; }
.scan-result__name { font-size: 19px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.scan-result__id { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--text-2); font-weight: 600; }
.scan-result__meta { color: var(--muted); font-size: 13.5px; }
.scan-result--success { background: var(--green-50); border-color: #bbf7d0; }
.scan-result--success .scan-result__icon { background: #dcfce7; color: var(--green-700); }
.scan-result--success h3 { color: var(--green-700); }
.scan-result--duplicate { background: var(--amber-50); border-color: #fde68a; }
.scan-result--duplicate .scan-result__icon { background: #fef3c7; color: var(--amber-700); }
.scan-result--duplicate h3 { color: var(--amber-700); }
.scan-result--invalid, .scan-result--error { background: var(--red-50); border-color: #fecaca; }
.scan-result--invalid .scan-result__icon, .scan-result--error .scan-result__icon { background: #fee2e2; color: var(--red-700); }
.scan-result--invalid h3, .scan-result--error h3 { color: var(--red-700); }

.scan-log { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.scan-log li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.scan-log li:last-child { border-bottom: 0; }
.scan-log__who { min-width: 0; display: flex; flex-direction: column; }
.scan-log__who strong { font-size: 14px; overflow-wrap: anywhere; }
.scan-log small { color: var(--muted); font-size: 12.5px; }
.scan-log__what { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

@media (max-width: 900px) {
  .scan-bar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .scan-bar__actions { grid-column: 1 / -1; }
  .scan-bar__actions .btn { flex: 1; }
}
@media (max-width: 720px) {
  .scan-bar { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .scan-bar .input { font-size: 16px; } /* stops iOS zooming into the select */
}

/* ---------- Stage 5: records, filters, reports, dashboard ---------- */
.toolbar--chips { padding-bottom: 12px; border-bottom: 0; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; padding: 0 20px 16px; border-bottom: 1px solid var(--border); }
.filters .field + .field { margin-top: 0; }
.filters .field--grow { grid-column: span 2; }
.filters .input { width: 100%; }
.segmented button:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.rec-summary { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 12px 20px; font-size: 14px; color: var(--muted); border-bottom: 1px solid var(--border); }
.rec-summary strong { color: var(--text); }
.rec-note { margin: 0; padding: 10px 20px; font-size: 13px; color: var(--amber-700); background: var(--amber-50); border-bottom: 1px solid var(--border); }
.rec-check { display: flex; gap: 8px; align-items: center; padding: 10px 20px; font-size: 13.5px; color: var(--text-2); border-bottom: 1px solid var(--border); }
.row--derived td { background: #fafbfd; }
.muted { color: var(--muted); }
.table--records .c-sub .muted { margin-left: 4px; }
.legend--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.subtle-note { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.rate-note { color: var(--amber-700); font-size: 12.5px; margin-top: 8px; }
.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.mini-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); font-size: 14px; }
.mini-list li:first-child { border-top: 0; }
.mini-list .who { min-width: 0; }
.mini-list .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-list .who span { color: var(--muted); font-size: 12.5px; }
.report-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; padding: 16px 20px; }
.report-tools .field + .field { margin-top: 0; }
.report-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
.card + .card.report-sec { margin-top: 18px; }
@media (max-width: 900px) { .legend--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .filters .field--grow { grid-column: span 1; } }
@media (max-width: 720px) {
  .legend--4 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; padding: 0 16px 14px; }
  .filters .field--grow { grid-column: span 2; }
  .toolbar--chips { padding: 14px 16px 10px; overflow-x: auto; }
  .segmented { max-width: 100%; }
  .segmented button { padding: 7px 12px; white-space: nowrap; }
  .rec-summary, .rec-note, .rec-check { padding-left: 16px; padding-right: 16px; }
  table.table--records { min-width: 0; }
  table.table--records, .table--records tbody { display: block; }
  .table--records thead { display: none; }
  .table--records tbody tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name status" "id status" "sub sub" "when when" "method method";
    column-gap: 12px; row-gap: 3px; padding: 14px 16px; border-bottom: 1px solid var(--border);
  }
  .table--records tbody tr:last-child { border-bottom: 0; }
  .table--records td { padding: 0; border: 0; min-width: 0; }
  .table--records .c-name { grid-area: name; } .table--records .c-name strong { overflow-wrap: anywhere; }
  .table--records .c-id { grid-area: id; } .table--records .c-sub { grid-area: sub; margin-top: 6px; }
  .table--records .c-status { grid-area: status; align-self: start; }
  .table--records .c-date { grid-area: when; display: inline; } .table--records .c-time { grid-area: when; justify-self: end; }
  .table--records .c-method { grid-area: method; font-size: 12.5px; color: var(--muted); }
}

/* ---------- Stage 5.5: sessions + enrollment ---------- */
fieldset.choices { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; min-width: 0; }
fieldset.choices legend { font-size: 13px; font-weight: 600; color: var(--text-2); padding: 0; margin-bottom: 6px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: 12px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--blue-600); background: var(--blue-50); }
.choice:has(input:focus-visible) { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.choice input { margin-top: 3px; flex: none; }
.choice strong { display: block; font-size: 14px; }
.choice small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.session-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 16px; border-radius: 12px; background: #f8fafc; border: 1px solid var(--border); margin-top: 12px; font-size: 14px; }
.session-bar--warn { background: var(--amber-50); border-color: #fde68a; }
.session-bar--ok { background: var(--green-50); border-color: #bbf7d0; }
.session-bar .grow { flex: 1; min-width: 160px; }
.roster-list { display: grid; gap: 0; max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 12px; margin-top: 10px; }
.roster-row { display: flex; gap: 12px; align-items: center; padding: 9px 12px; border-top: 1px solid var(--border); cursor: pointer; }
.roster-row:first-child { border-top: 0; }
.roster-row:has(input:focus-visible) { outline: 2px solid var(--blue-500); outline-offset: -2px; }
.roster-row.is-changed { background: var(--blue-50); }
.roster-row .who { min-width: 0; flex: 1; }
.roster-row .who strong { display: block; overflow-wrap: anywhere; }
.roster-row .who span { color: var(--muted); font-size: 12.5px; }
.roster-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.roster-dates .field + .field { margin-top: 0; }
.roster-errors { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--red-50); color: var(--red-700); font-size: 13.5px; }
.roster-errors ul { margin: 6px 0 0 18px; padding: 0; }
dialog.modal.modal--wide { width: min(640px, calc(100vw - 32px)); }
@media (max-width: 720px) {
  .session-bar { padding: 8px 12px; gap: 6px 10px; margin-top: 10px; font-size: 13.5px; }
  .session-bar .btn { min-height: 36px; padding: 6px 14px; }
}

/* ---------- Stage 6: PWA (offline status, install, update) ---------- */
.install-box { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.install-box[hidden] { display: none; }
.install-box .btn { flex: 1; }
.install-box__x { border: 0; background: none; color: #94a6c7; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.install-box__x:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.update-bar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 190; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  width: max-content; max-width: calc(100vw - 24px); padding: 10px 14px; border-radius: 14px; background: var(--navy-900); color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: 0 12px 34px rgba(8, 19, 38, 0.35);
}
.update-bar[hidden] { display: none; }
.update-bar__text { flex: 1 1 auto; }
.update-bar__msg { flex-basis: 100%; color: #fcd34d; font-size: 13px; }
.update-bar__msg[hidden] { display: none; }
.update-bar .btn--ghost { color: #cbd5e1; }
.btn--sm { padding: 6px 12px; font-size: 13px; min-height: 0; }
@media (max-width: 720px) {
  .update-bar { bottom: calc(var(--bottomnav-h) + 12px + env(safe-area-inset-bottom)); }
  /* the status chip is hidden on phones, but when offline it is the one thing worth showing */
  .is-offline .net-chip { display: inline-flex; }
}
