:root {
  --paper: #f3f6f7;
  --surface: #ffffff;
  --ink: #17242e;
  --ink-soft: #55656f;
  --line: #d5dde2;
  --line-soft: #e6ebee;
  --accent: #0f6e7a;
  --accent-ink: #ffffff;
  --accent-wash: #e2f1f2;
  --ok: #1c7a4d;
  --wait: #a06400;
  --stop: #b2301c;
  --off: #73808a;
  --stop-wash: #fbebe7;
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, "Segoe UI", sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, Consolas, monospace;
  --panel-width: 27rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10181e;
    --surface: #18232b;
    --ink: #e7eef2;
    --ink-soft: #9fb0bb;
    --line: #2f3d47;
    --line-soft: #25323b;
    --accent: #56bcc8;
    --accent-ink: #06262b;
    --accent-wash: #173a40;
    --ok: #5cc491;
    --wait: #e0a94a;
    --stop: #f0806c;
    --off: #8c9aa4;
    --stop-wash: #3a211c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--ink-soft); }
.code { font-family: var(--mono); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- controls ---------- */

label { display: grid; gap: 0.3rem; font-weight: 600; font-size: 0.92rem; }

input, select {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  min-height: 2.5rem;
  width: 100%;
}
input:hover, select:hover { border-color: var(--ink-soft); }

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 2.5rem;
  padding: 0.45rem 0.95rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-soft); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--stop); }
.btn.danger.solid { background: var(--stop); border-color: var(--stop); color: var(--surface); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn.quiet:hover { color: var(--ink); background: var(--line-soft); }

.error { color: var(--stop); font-weight: 600; }
.notice { background: var(--accent-wash); border-radius: 6px; padding: 0.6rem 0.75rem; }

/* ---------- sign in ---------- */

#signin { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.signin-card {
  width: min(24rem, 100%);
  display: grid;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 5px solid var(--accent);
  border-radius: 8px;
  padding: 2rem;
}
.lede { color: var(--ink-soft); }

/* ---------- shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; padding: 0.9rem 0; }
.topbar nav { display: flex; gap: 0.25rem; align-self: stretch; }
.topbar nav a {
  display: flex;
  align-items: center;
  padding: 0 0.8rem;
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.topbar nav a:hover { color: var(--ink); }
.topbar nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.who { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; color: var(--ink-soft); font-size: 0.92rem; }

.workspace { display: flex; align-items: flex-start; }
main { flex: 1; min-width: 0; padding: 1.75rem 1.5rem 3rem; }
main:focus { outline: none; }

.view-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem; }
.view-head h1 { margin-right: auto; }

.filters { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-bottom: 1rem; }
.filters label { min-width: 11rem; }
.filters .search { flex: 1 1 16rem; max-width: 26rem; }

/* status filter: counts double as the overview of who still has to enroll */
.tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.tab {
  font: inherit;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
}
.tab strong { color: var(--ink); font-size: 1.05rem; }
.tab:hover { border-color: var(--ink-soft); }
.tab[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-wash); color: var(--ink); }

/* ---------- tables ---------- */

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th {
  text-align: left;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--ink-soft);
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--paper); }
tr.selected td { background: var(--accent-wash); }
td.id { font-weight: 600; white-space: nowrap; }
td.when { white-space: nowrap; color: var(--ink-soft); }
.row-link { all: unset; cursor: pointer; font-weight: 600; }
.row-link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sub { display: block; color: var(--ink-soft); font-size: 0.86rem; }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-soft); }
.empty strong { display: block; color: var(--ink); margin-bottom: 0.25rem; }

.pager { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.9rem; color: var(--ink-soft); font-size: 0.92rem; }
.pager .spacer { flex: 1; }

/* status: a coloured dot plus words, so it never relies on colour alone */
.status { display: inline-flex; align-items: center; gap: 0.45rem; white-space: nowrap; }
.status::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--dot, var(--off)); }
.status.ENROLLED, .status.pass { --dot: var(--ok); }
.status.PENDING_ENROLLMENT { --dot: var(--wait); }
.status.LOCKED, .status.fail { --dot: var(--stop); }
.status.INACTIVE { --dot: var(--off); }
.status.PENDING_ENROLLMENT::before { background: transparent; box-shadow: inset 0 0 0 2px var(--wait); }

/* score rail: the score on a 0-1 track with a tick at the pass threshold */
.rail { display: inline-flex; align-items: center; gap: 0.5rem; white-space: nowrap; }
.rail-track { position: relative; width: 5.5rem; height: 0.5rem; background: var(--line-soft); border-radius: 2px; }
.rail-fill { position: absolute; inset: 0 auto 0 0; border-radius: 2px; background: var(--stop); }
.rail.pass .rail-fill { background: var(--ok); }
.rail-tick { position: absolute; top: -0.25rem; bottom: -0.25rem; width: 2px; background: var(--ink); }
.rail-num { min-width: 2.2rem; font-weight: 600; }

/* ---------- student record panel ---------- */

#panel {
  width: var(--panel-width);
  flex: none;
  position: sticky;
  top: 3.4rem;
  height: calc(100vh - 3.4rem);
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 1.5rem;
  animation: panel-in 0.16s ease-out;
}
@keyframes panel-in { from { transform: translateX(1.5rem); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #panel { animation: none; } }

.panel-head { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 0.4rem; }
.panel-head h2 { flex: 1; overflow-wrap: anywhere; }
.panel-section { border-top: 1px solid var(--line-soft); margin-top: 1.25rem; padding-top: 1.25rem; display: grid; gap: 0.8rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; font-size: 0.95rem; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.form-grid { display: grid; gap: 0.75rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.help { color: var(--ink-soft); font-size: 0.9rem; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; font-size: 0.93rem; }
.history li { display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.75rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--line-soft); }
.history li:last-child { border-bottom: 0; }
.history .when { color: var(--ink-soft); text-align: right; }
.history .scores { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; color: var(--ink-soft); }

/* ---------- dialogs ---------- */

dialog {
  width: min(32rem, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgb(12 22 28 / 0.55); }
dialog form, .dialog-body { display: grid; gap: 0.9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.4rem; }

.code-reveal {
  font-family: var(--mono);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-align: center;
  padding: 1rem;
  background: var(--accent-wash);
  border-radius: 8px;
  user-select: all;
}
.import-errors { max-height: 12rem; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.import-errors table { font-size: 0.88rem; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 20;
  max-width: calc(100vw - 2rem);
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--stop); color: #fff; }

/* ---------- small screens ---------- */

@media (max-width: 1100px) {
  #panel { position: fixed; inset: 0 0 0 auto; top: 0; height: 100vh; width: min(var(--panel-width), 100vw); z-index: 10; box-shadow: -12px 0 30px rgb(12 22 28 / 0.25); }
}
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; gap: 0 1rem; padding: 0 1rem; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  .topbar nav a { padding: 0.6rem 0.7rem; }
  #who-email { display: none; }
  main { padding: 1.25rem 1rem 3rem; }
}

td a, td .row-link { white-space: nowrap; }

/* ---------- identify photo ---------- */

.identify { display: grid; grid-template-columns: minmax(0, 3fr) minmax(17rem, 2fr); gap: 1.5rem; align-items: start; margin-top: 0.5rem; }
.photo { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.photo img { display: block; width: 100%; height: auto; }
.face-box { position: absolute; border: 2px solid var(--wait); border-radius: 3px; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.45); }
.face-box.known { border-color: #3fd08c; }
.face-box.unknown { border-color: #ffc14d; border-style: dashed; }
.face-box.hot { border-width: 4px; margin: -2px; }
.face-num {
  display: inline-grid; place-items: center;
  min-width: 1.5rem; height: 1.5rem; padding: 0 0.3rem;
  border-radius: 0.75rem; background: var(--ink); color: var(--paper);
  font-size: 0.82rem; font-weight: 700;
}
.face-box .face-num { position: absolute; left: -2px; bottom: 100%; margin-bottom: 2px; background: #111c24; color: #fff; }
.people { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.people li { display: grid; grid-template-columns: auto 1fr auto; gap: 0.75rem; align-items: center; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--line-soft); }
.people li:last-child { border-bottom: 0; }
.people li.hot { background: var(--accent-wash); }
.people li.unknown .who-is > span:first-child { color: var(--ink-soft); }
.who-is a { font-weight: 600; }
input[type="file"] { padding: 0.35rem 0.5rem; }
@media (max-width: 900px) { .identify { grid-template-columns: 1fr; } }

/* ---------- hostels, in/out report, saved photos ---------- */

.status.in { --dot: var(--ok); }
.status.out { --dot: var(--wait); }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn { min-height: 2rem; padding: 0.2rem 0.6rem; }
.filters label.date { min-width: 9.5rem; }

.thumb-button { all: unset; cursor: zoom-in; display: block; width: 3rem; height: 3rem; border-radius: 6px; overflow: hidden; background: var(--line-soft); }
.thumb-button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.thumb { display: block; width: 100%; height: 100%; object-fit: cover; }
dialog.wide { width: min(46rem, calc(100vw - 2rem)); }
.selfie-full { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; border-radius: 8px; }

.history li { grid-template-columns: auto 1fr auto; align-items: center; }
