/* styles.css — the viewer's look, matching the desktop grader's palette.
   Light and dark are both defined; dark follows the device setting. */

:root {
  --blue: #005BAA;
  --blue-2: #3d85c8;
  --blue-bg: #e8f1fb;
  --green: #1a9e5c;
  --green-bg: #e8f7ef;
  --red: #d63031;
  --red-bg: #fdecea;
  --orange: #e07b27;
  --orange-bg: #fdf1e4;

  --bg: #f8f9fc;
  --card: #ffffff;
  --line: #e2e6ef;
  --line-soft: #f0f2f7;
  --text: #1e2740;
  --muted: #5c6b80;

  --radius: 12px;
  --shadow: 0 2px 12px rgba(0, 91, 170, .08);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Chart series — one per section (Listening, GVR/GCVR, Writing, Speaking) */
  --s1: #005BAA;
  --s2: #e07b27;
  --s3: #1a9e5c;
  --s4: #8e44ad;
}

@media (prefers-color-scheme: dark) {
  :root {
    --blue: #4d9ae0;
    --blue-2: #7fb8ea;
    --blue-bg: #16283c;
    --green: #46c98a;
    --green-bg: #14302380;
    --red: #f47272;
    --red-bg: #3a1d1f80;
    --orange: #eda45f;
    --orange-bg: #35251580;

    --bg: #11151c;
    --card: #182029;
    --line: #2a3441;
    --line-soft: #212a35;
    --text: #e7ecf3;
    --muted: #9aa8bb;
    --shadow: 0 2px 12px rgba(0, 0, 0, .35);

    --s1: #5aa9ec;
    --s2: #eda45f;
    --s3: #46c98a;
    --s4: #bb8be0;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The layout rules below set `display` on elements the app hides with the
   `hidden` attribute, and a class selector outranks the browser's own
   [hidden] rule — so state it here, where it wins. */
[hidden] { display: none !important; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.45;
}

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 56px; }

/* ── Top bar ──────────────────────────────────────────────────────────────── */

.topbar {
  background: var(--blue);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark {
  width: 28px; height: 28px; flex: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, .18);
  display: grid; place-items: center;
  font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; }
.brand-text small { font-size: 11.5px; opacity: .8; }

.topbar-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.topbar-account { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.account { opacity: .85; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; }
.field > span { opacity: .85; text-transform: uppercase; letter-spacing: .5px; }

.topbar select {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .12);
  color: #fff;
  min-width: 140px;
  max-width: 60vw;
}
.topbar select option { color: #1e2740; background: #fff; }

/* ── Buttons, inputs ──────────────────────────────────────────────────────── */

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--blue);
  color: #fff;
  transition: filter .12s, background .12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; filter: none; }
.btn.primary { background: var(--blue); color: #fff; }
.topbar .btn.ghost, .topbar-account .btn.ghost {
  background: rgba(255, 255, 255, .14);
  border-color: rgba(255, 255, 255, .3);
  color: #fff;
}
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.small { padding: 5px 10px; font-size: 12px; }

input[type="text"], input[type="search"] {
  font: inherit;
  font-size: 13.5px;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--text);
  width: 100%;
}
input:focus { outline: none; border-color: var(--blue-2); }

.linklike {
  color: var(--blue);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Cards, gates ─────────────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.gate { display: grid; place-items: center; padding: 32px 0; }
.gate-card { width: min(560px, 100%); display: flex; flex-direction: column; gap: 14px; }
.gate-card h1 { font-size: 20px; color: var(--blue); }
.gate-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.gate-local { border-top: 1px solid var(--line-soft); padding-top: 14px; }
.centred { align-items: center; text-align: center; }

.stacked { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; }
.stacked small { font-weight: 400; }

.help summary { cursor: pointer; font-weight: 600; color: var(--blue); font-size: 13px; }
.help-steps { margin: 10px 0 0 18px; display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.mono { font-family: var(--mono); font-size: .92em; background: var(--line-soft); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error {
  background: var(--red-bg); border: 1px solid var(--red);
  color: var(--red); border-radius: 8px; padding: 10px 12px; font-size: 13px;
}

.spinner {
  width: 34px; height: 34px; margin: 0 auto 4px;
  border: 3px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 6px; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 600; font-size: 13.5px;
  padding: 10px 16px;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.source-line { margin: 0 0 16px; }
.panel { display: flex; flex-direction: column; gap: 18px; }

/* ── Stats ────────────────────────────────────────────────────────────────── */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-v { font-size: 23px; font-weight: 700; color: var(--blue); line-height: 1.2; }
.stat-l { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }

.card-title {
  font-size: 14px; font-weight: 700; color: var(--blue);
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card-title .spacer { margin-left: auto; }

/* ── Tables ───────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
/* Below this width a table stops wrapping every cell into a column of single
   words and scrolls inside its own card instead — the page itself never does. */
table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 8px 10px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.centre { text-align: center; }

.tag {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 5px; white-space: nowrap;
}
.tag.ecce { background: var(--blue-bg); color: var(--blue); }
.tag.ecpe { background: var(--orange-bg); color: var(--orange); }
.tag.other { background: var(--line-soft); color: var(--muted); }
.tag.pass { background: var(--green-bg); color: var(--green); }
.tag.fail { background: var(--red-bg); color: var(--red); }
.tag.count { background: var(--red-bg); color: var(--red); }
.tag.zero { background: var(--green-bg); color: var(--green); }

/* ── Students ─────────────────────────────────────────────────────────────── */

.split { display: grid; grid-template-columns: minmax(220px, 300px) 1fr; gap: 18px; align-items: start; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }
/* Grid children default to min-width:auto, so a wide table inside one would
   stretch its column and push the whole page sideways. */
.split > *, .two-col > *, .stat-grid > * { min-width: 0; }

.list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; max-height: 62vh; overflow-y: auto; }
.list-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; font-size: 13.5px; width: 100%;
  background: none; border: none; border-bottom: 1px solid var(--line-soft);
  color: var(--text); font-family: inherit; text-align: left; cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--blue-bg); }
.list-item.active { background: var(--blue-bg); color: var(--blue); font-weight: 600; }
.list-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item.static { cursor: default; }
.list-item.static:hover { background: none; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
.col-head { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.col-head.ok { color: var(--green); }
.col-head.warn { color: var(--orange); }
.col-head span { color: var(--muted); font-weight: 500; }

.empty { padding: 12px; font-size: 13px; color: var(--muted); }
.empty.ok { color: var(--green); }

.stack { display: flex; flex-direction: column; gap: 10px; }
.stack-lg { display: flex; flex-direction: column; gap: 18px; }
.stack-xs { display: flex; flex-direction: column; gap: 3px; }
.strong { font-weight: 600; }
.ok-text { color: var(--green); }
.desc { margin-bottom: 14px; }
.tests-line { margin: -8px 0 12px; }

.date-field { color: var(--muted); }
.date-field select {
  font: inherit; font-size: 13px; padding: 6px 10px;
  border-radius: 8px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--text);
}

/* ── Chart ────────────────────────────────────────────────────────────────── */

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .pass-line { stroke: var(--green); stroke-width: 1; stroke-dasharray: 4 4; opacity: .7; }
.chart .axis-text { fill: var(--muted); font-size: 10px; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-dot { stroke: var(--card); stroke-width: 1.5; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ── Phones ───────────────────────────────────────────────────────────────── */

@media (max-width: 560px) {
  .brand-text small { display: none; }        /* the tagline costs a whole row */
  .account { display: none; }                 /* who is signed in stays in Settings */
  .topbar select { min-width: 120px; max-width: 42vw; }
  main { padding: 16px 12px 48px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .stat-v { font-size: 20px; }
  /* The chart scales with its viewBox, so on a phone its labels have to grow
     in viewBox units to stay readable. */
  .chart .axis-text { font-size: 17px; }
  .chart .series-line { stroke-width: 3; }
}
