:root {
  --ground: #f4f5f1; --surface: #ffffff; --sunk: #eceee8; --line: #dde0d8; --line-strong: #c6cbc1;
  --ink: #1b2230; --ink-2: #4a5552; --muted: #6d7773;
  --accent: #0f6b66; --accent-ink: #ffffff; --accent-soft: #dcefec;
  --good: #2f7d4f; --good-soft: #e1f1e7; --warn: #a86a12; --warn-soft: #f8ecd6; --bad: #b83b27; --bad-soft: #f8e1dc;
  --shadow: 0 1px 2px rgba(27,34,48,.06), 0 8px 24px rgba(27,34,48,.06);
  --display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #111517; --surface: #181d20; --sunk: #1f2528; --line: #2a3134; --line-strong: #3a4246;
    --ink: #e7ece9; --ink-2: #b9c2be; --muted: #8b9692;
    --accent: #4fb8ae; --accent-ink: #0b1716; --accent-soft: #173432;
    --good: #5cc28a; --good-soft: #17301f; --warn: #e0a54a; --warn-soft: #33270f; --bad: #ef7d68; --bad-soft: #3a1c16;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #111517; --surface: #181d20; --sunk: #1f2528; --line: #2a3134; --line-strong: #3a4246;
  --ink: #e7ece9; --ink-2: #b9c2be; --muted: #8b9692;
  --accent: #4fb8ae; --accent-ink: #0b1716; --accent-soft: #173432;
  --good: #5cc28a; --good-soft: #17301f; --warn: #e0a54a; --warn-soft: #33270f; --bad: #ef7d68; --bad-soft: #3a1c16;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 14px/1.5 var(--sans); }
.wrap { max-width: 1180px; margin: 0 auto; padding-inline: 20px; padding-block: 20px 48px; display: grid; gap: 20px; }
.wrap > *, .panel, .panel > * { min-width: 0; }         /* a wide table scrolls in its box, never the page */
h1, h2, h3 { margin: 0; text-wrap: balance; }
h2 { font-size: 15px; font-weight: 600; }
.num, td.n, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.demo { background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
        border-radius: 8px; padding: 8px 12px; font-size: 13px; }

/* ---------------------------------------------------------------- header -- */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-text { display: grid; gap: 2px; }
.brand-logo { height: 44px; width: auto; max-width: 160px; object-fit: contain; }
.login-logo { height: 56px; width: auto; max-width: 220px; object-fit: contain; justify-self: start; }
:root[data-theme="dark"] .brand-logo, :root[data-theme="dark"] .login-logo { background: #f4f5f1; border-radius: 8px; padding: 4px 6px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-logo, :root:not([data-theme="light"]) .login-logo { background: #f4f5f1; border-radius: 8px; padding: 4px 6px; } }
.brand h1 { font-family: var(--display); font-weight: 600; font-size: 22px; letter-spacing: -.01em; }
.brand .sub { color: var(--muted); font-size: 13px; }
.who { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 13px; }
.btn { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 12px; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

/* pilot countdown: 14 day ticks */
.pilot { display: grid; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; min-width: min(100%, 340px); }
.pilot .row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.pilot b { font-weight: 600; }
.ticks { display: grid; grid-template-columns: repeat(14, 1fr); gap: 3px; }
.ticks i { height: 8px; border-radius: 2px; background: var(--sunk); }
.ticks i.done { background: var(--accent); }
.ticks i.today { background: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.pilot.ending .ticks i.done, .pilot.ending .ticks i.today { background: var(--warn); }

/* --------------------------------------------------------------- summary -- */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 8px; align-content: start; }
.stat .label { color: var(--muted); font-size: 12px; letter-spacing: .03em; text-transform: uppercase; }
.stat .value { font-size: 26px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 14px; font-weight: 400; color: var(--muted); }
.stat .hint { font-size: 12.5px; color: var(--ink-2); }
.bar { height: 6px; border-radius: 3px; background: var(--sunk); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.warn > span { background: var(--warn); } .bar.bad > span { background: var(--bad); }

/* ------------------------------------------------------------ panels ------ */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.panel > header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel > .body { padding: 14px 16px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .limit { stroke: var(--bad); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .axis { fill: var(--muted); font: 11px var(--sans); }
.chart rect.b { fill: var(--accent); }
.chart rect.b.over { fill: var(--bad); }
.chart rect.b.today { fill: var(--accent); opacity: .55; }
.chart .limit-t { fill: var(--bad); font: 11px var(--sans); }

.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; width: 220px; max-width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 10px; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- table --- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: .02em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.row { cursor: pointer; }
tr.row:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
tr.off td { color: var(--muted); }
td.n { text-align: right; white-space: nowrap; }
.name { font-weight: 600; } .name .role { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.band { display: inline-block; min-width: 34px; text-align: center; padding: 2px 6px; border-radius: 6px; font-weight: 600; font-variant-numeric: tabular-nums; background: var(--sunk); }
.band.hi { background: var(--good-soft); color: var(--good); } .band.lo { background: var(--bad-soft); color: var(--bad); } .band.mid { background: var(--warn-soft); color: var(--warn); }
.band.none { background: transparent; color: var(--muted); font-weight: 400; }
.band.est { outline: 1px dashed currentColor; outline-offset: -1px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; max-width: 260px; }
.chip { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--sunk); color: var(--ink-2); white-space: nowrap; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill.on { background: var(--good-soft); color: var(--good); } .pill.idle { background: var(--warn-soft); color: var(--warn); } .pill.off { background: var(--sunk); color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); padding: 10px 16px; }

/* ------------------------------------------------------ add + code ticket -- */
.add { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.add label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.add input, .add select { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.ticket { margin-top: 12px; display: grid; gap: 8px; justify-items: start; border: 1.5px dashed var(--accent); border-radius: 12px; padding: 14px 16px; background: var(--accent-soft); }
.ticket .code { font-family: var(--mono); font-size: 26px; font-weight: 600; letter-spacing: .08em; color: var(--ink); user-select: all; }
.ticket .who { font-size: 13px; }
.ticket .warn { font-size: 12.5px; color: var(--ink-2); }

/* -------------------------------------------------------------- drawer ---- */
.scrim { position: fixed; inset: 0; background: rgba(12,16,20,.35); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--surface); z-index: 11;
          border-left: 1px solid var(--line); box-shadow: var(--shadow); display: grid; grid-template-rows: auto 1fr;
          padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.drawer > header { display: flex; justify-content: space-between; align-items: start; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer > .content { overflow-y: auto; padding: 16px 18px; display: grid; gap: 18px; align-content: start; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.hist { display: grid; gap: 6px; }
.hist .h { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 7px 10px; border-radius: 8px; background: var(--sunk); }
.spot { display: grid; gap: 2px; padding: 8px 10px; border-left: 3px solid var(--warn); background: var(--warn-soft); border-radius: 0 8px 8px 0; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; padding: 10px; border-radius: 8px; background: var(--bad-soft); }

/* ---------------------------------------------------------- login / misc -- */
.login { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); }
.login h1 { font-family: var(--display); font-size: 20px; font-weight: 600; }
.login input { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 18px; letter-spacing: .06em; text-transform: uppercase; width: 100%; }
.err { color: var(--bad); font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--ground);
         padding: 9px 14px; border-radius: 8px; font-size: 13px; z-index: 20; }
details.audit summary { cursor: pointer; padding: 14px 16px; font-weight: 600; }
details.audit .body { padding: 0 16px 14px; display: grid; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.limitform { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.limitform input { width: 90px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 6px 8px; }

@media (max-width: 560px) {
  .wrap { padding-inline: 16px; }
  .brand h1 { font-size: 18px; }
  .who { width: 100%; justify-content: space-between; }
  .stat .value { font-size: 22px; }
  .search { width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  .drawer { animation: slide .18s ease-out; }
  @keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.goal { white-space: nowrap; }
.goal .course { font-size: 11px; font-weight: 600; letter-spacing: .02em; color: var(--muted, #6b6b76); }
.goalbox { display: grid; gap: 8px; }
.goalbox h3 { font-size: 13px; }
.goalline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.goalform { display: grid; gap: 10px; }
.goalform .grow { display: flex; gap: 10px; }
.goalform .grow[hidden] { display: none; }
.goalform label { flex: 1; display: grid; gap: 4px; font-size: 12px; }
.goalform .err:empty { display: none; }
.goalform select { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; }
.goalform .seg { justify-self: start; }
.goal .pending { font-size: 11px; color: #a05a00; white-space: nowrap; }
.goalline .actions { display: flex; gap: 6px; }
.add .pair { display: flex; align-items: center; gap: 6px; }
.add label[hidden] { display: none; }
.teacherpick { display: grid; gap: 4px; font-size: 12px; }
.teacherpick select, .add .pair select { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .goal .pending { color: #e0a24a; } }
.report .summary { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.unverified { color: #a05a00; font-size: 12px; }
