/* TIS Trellis Analytics — styles. No external fonts or libraries. */

:root {
  color-scheme: light;
  --page: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #1a2130;
  --ink-2: #4b5466;
  --ink-3: #7b8394;
  --rule: #dde1e8;
  --rule-soft: #eceff3;
  --accent: #33429a;
  --accent-ink: #ffffff;
  --accent-soft: #e7eaf8;
  --mark: #fff2a8;
  --danger: #b4302f;
  --focus: #33429a;

  /* charts (validated reference palette, light) */
  --chart-surface: #fcfcfb;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  /* sequential blue, for cell shading */
  --q1: #f1f6fd; --q2: #dce9fa; --q3: #c3daf7; --q4: #a6c8f3;

  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #111316;
    --surface: #1a1c20;
    --surface-2: #202328;
    --ink: #eef0f4;
    --ink-2: #b9bfcb;
    --ink-3: #8b92a0;
    --rule: #30343b;
    --rule-soft: #262930;
    --accent: #8f9cf0;
    --accent-ink: #11131a;
    --accent-soft: #272c4a;
    --mark: #4a4220;
    --danger: #ef7d7c;
    --focus: #8f9cf0;
    --chart-surface: #1a1a19;
    --grid: #2c2c2a;
    --axis: #383835;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --q1: #1b2534; --q2: #1d3150; --q3: #224070; --q4: #285090;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--rule); background: var(--surface); cursor: pointer;
  text-decoration: none; color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-quiet { background: transparent; }
.btn-wide { width: 100%; }
/* switched-off buttons look switched off (grey, no hover effect) */
.btn:disabled, .btn:disabled:hover {
  background: var(--surface-2); border-color: var(--rule); color: var(--ink-3);
  filter: none; cursor: not-allowed; font-weight: inherit;
}
.link-btn { background: none; border: 0; padding: 0; color: var(--ink-2); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
input[type="search"], input[type="number"], input[type="text"], select, textarea {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--rule);
  border-radius: var(--radius); background: var(--surface);
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
select { padding-right: 6px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--ink-3); }
#f-search-hint { margin: 6px 0 0; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); margin-top: 8px; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  height: 52px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-school {
  font-weight: 800; font-size: 13px; letter-spacing: .04em;
  color: var(--accent-ink); background: var(--accent); padding: 2px 7px; border-radius: 4px;
}
.brand-name { font-weight: 650; font-size: 15px; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tab {
  height: 100%; padding: 0 12px; border: 0; background: none; cursor: pointer;
  color: var(--ink-2); border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.who { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: 13px; color: var(--ink-2); }
.who form { margin: 0; }

/* ---------- explore layout ---------- */
.view { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: calc(100vh - 52px); }
#view-sql, #view-people, #view-upload, #view-mydata, #view-student, #view-dpc { grid-template-columns: minmax(0, 1fr); }
.filters {
  border-right: 1px solid var(--rule); background: var(--surface);
  padding: 18px 18px 40px; overflow-y: auto;
  position: sticky; top: 52px; height: calc(100vh - 52px);
}
.presets { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--rule-soft); }
.fgroup { margin-bottom: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 28px; padding: 0 10px; border-radius: 14px; cursor: pointer;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2); font-size: 13px;
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.chips-tight .chip { padding: 0 8px; }
.chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more-link { font-size: 12px; height: 28px; }
.chip-empty { font-size: 12px; color: var(--ink-3); }
.chip-all { font-weight: 600; }
.checklist label.check-all { font-weight: 600; border-bottom: 1px solid var(--rule-soft); }
.seg { display: flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.seg button { flex: 1; height: 32px; padding: 0 12px; white-space: nowrap; border: 0; background: var(--surface); cursor: pointer; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-checked="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.checklist {
  max-height: 210px; overflow-y: auto; border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 4px 0; background: var(--surface);
}
.checklist label { display: flex; gap: 8px; align-items: center; padding: 4px 10px; font-size: 13px; cursor: pointer; }
.checklist label:hover { background: var(--surface-2); }
.checklist .muted { color: var(--ink-3); }
.range { display: flex; gap: 8px; align-items: center; color: var(--ink-3); font-size: 13px; }

/* ---------- the report page ---------- */
.report { padding: 24px 28px 60px; min-width: 0; }
.report-paper {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 8px;
  padding: 26px 28px 28px; max-width: 100%;
}
.report-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
/* "input." makes these win over the general text-box style (input[type="text"]) */
input.report-title {
  font-size: 24px; font-weight: 700; line-height: 1.25; height: auto; border: 0; padding: 2px 4px; margin: -2px -4px;
  border-radius: 4px; background: transparent; width: min(640px, 100%);
}
input.report-title:hover { background: var(--surface-2); }
input.report-title:focus { background: var(--mark); outline: none; color: #1a2130; }
.report-sub { margin: 6px 0 0; color: var(--ink-2); font-size: 13px; max-width: 80ch; }
.report-meta { display: none; }
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin: 22px 0 12px; padding-top: 16px; border-top: 1px solid var(--rule-soft);
}
.toolbar .spacer { flex: 1; }
.count { font-size: 13px; color: var(--ink-2); }
.notice {
  margin: 0 0 12px; padding: 8px 12px; border-radius: var(--radius); font-size: 13px;
  background: var(--surface-2); border-left: 3px solid var(--ink-3); color: var(--ink-2);
}
.notice.warn { border-left-color: #c98500; }
.error { color: var(--danger); }

/* ---------- chart ---------- */
.chart-box { margin-top: 20px; }
.chart-controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; margin-bottom: 10px; }
.chart-controls label { display: flex; flex-direction: column; font-size: 12px; font-weight: 600; color: var(--ink-2); gap: 4px; }
.chart-controls select:disabled { opacity: .5; cursor: not-allowed; }
.chart-controls select { width: auto; min-width: 120px; height: 30px; font-weight: 400; color: var(--ink); }
.chart-frame { position: relative; background: var(--chart-surface); border: 1px solid var(--rule-soft); border-radius: var(--radius); padding: 10px 6px 4px; }
.chart-title { font-size: 14px; font-weight: 600; margin: 4px 10px 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 4px 10px 6px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.legend i.box { width: 10px; height: 10px; border-radius: 2px; }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { font: 11px var(--font); fill: var(--ink-3); font-variant-numeric: tabular-nums; }
svg.chart text.end-label { fill: var(--ink-2); font-weight: 600; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .base { stroke: var(--axis); stroke-width: 1; }
svg.chart .xhair { stroke: var(--ink-3); stroke-width: 1; }
svg.chart .bar:hover, svg.chart .bar:focus { opacity: .8; outline: none; }
.chart-empty { padding: 30px 12px; color: var(--ink-3); font-size: 13px; text-align: center; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(20, 25, 40, .14); padding: 8px 10px; font-size: 12px; min-width: 140px;
}
.tooltip .tt-head { color: var(--ink-2); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row i { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink); min-width: 34px; }
.tooltip .tt-row span { color: var(--ink-2); }
.tooltip .tt-n { color: var(--ink-3); }

/* ---------- table ---------- */
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--rule); border-radius: var(--radius); }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--rule-soft); text-align: left; white-space: nowrap; }
table.data thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--ink-2);
  font-size: 12px; font-weight: 600; vertical-align: bottom; border-bottom: 1px solid var(--rule);
  cursor: pointer; user-select: none; line-height: 1.3;
}
table.data thead th small { display: block; font-weight: 400; color: var(--ink-3); }
table.data thead th:hover { color: var(--ink); }
table.data thead th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
table.data thead th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
table.data td.num, table.data th.num { text-align: right; }
table.data td.txt-val { color: var(--ink-2); font-style: italic; }
table.data td.empty { color: var(--ink-3); text-align: center; }
table.data td.sticky, table.data th.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; border-right: 1px solid var(--rule-soft); }
table.data thead th.sticky { z-index: 2; background: var(--surface-2); }
table.data tbody tr:hover td { background: var(--mark); color: var(--ink); }
table.data td.q1 { background: var(--q1); } table.data td.q2 { background: var(--q2); }
table.data td.q3 { background: var(--q3); } table.data td.q4 { background: var(--q4); }
table.data th.pick, table.data td.pick { position: sticky; left: 0; z-index: 1; width: 36px; min-width: 36px; padding: 0 0 0 12px; background: var(--surface); }
table.data thead th.pick { z-index: 2; background: var(--surface-2); }
table.data td.after-pick, table.data th.after-pick { left: 36px; }
table.data th.nosort { cursor: default; }
td.pick input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.pick-bar { display: inline-flex; gap: 10px; align-items: center; margin-left: 12px; }
.btn-small { height: 30px; padding: 0 12px; font-size: 13px; }
.student-id { color: var(--ink-3); font-size: 12px; }
.empty-state { padding: 40px 16px; text-align: center; color: var(--ink-2); }
.loading { opacity: .5; transition: opacity .15s; }

/* ---------- SQL & people ---------- */
.sql-pane { padding: 24px 28px 0; }
#sql-text { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; line-height: 1.5; }
.sql-actions { display: flex; gap: 14px; align-items: center; margin-top: 10px; }
.people { padding: 28px; max-width: 900px; }
.people h2 { margin: 0 0 4px; font-size: 22px; }
.people .lede { color: var(--ink-2); margin: 0 0 20px; max-width: 70ch; }
.people-add { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 16px; margin-bottom: 20px; }
.people-row { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.people-row select { width: 130px; }
.role-tag { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--rule); }
.wb-check { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
#people-log { margin-top: 8px; }
.role-tag.admin { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- upload data ---------- */
.upload { padding: 28px; max-width: 1100px; }
.upload h2 { margin: 0 0 4px; font-size: 22px; }
.upload .lede { color: var(--ink-2); margin: 0 0 20px; max-width: 75ch; }
.mb-box .hint { margin-left: 4px; }
.upload-form { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 16px; margin-bottom: 20px; }
.upload-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.upload-row input[type="file"] { max-width: 100%; }
.upload-h { font-size: 16px; margin: 28px 0 8px; }
.upload-h small { font-weight: 400; color: var(--ink-3); margin-left: 6px; }
.preview { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 18px; }
.preview-title { margin: 0 0 2px; font-size: 18px; }
.preview-file { margin: 0 0 14px; color: var(--ink-3); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { border: 1px solid var(--rule-soft); background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--ink-2); }
.stat.hot { border-color: var(--accent); background: var(--accent-soft); }
.preview .table-wrap { max-height: 360px; }
td.old { color: var(--ink-3); text-decoration: line-through; }
td.new { font-weight: 600; }
.preview-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule-soft); }
.notice.ok { border-left-color: #1baf7a; }

/* ---------- my data ---------- */
.md-step { margin: 0 0 6px; font-size: 15px; }
#md-check:not(:empty) { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--rule-soft); }
.md-fields { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: end; margin-bottom: 14px; }
.md-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.md-fields input[type="text"] { width: 300px; }
.md-fields select { width: auto; min-width: 140px; }
table.map-table th { vertical-align: bottom; }
table.map-table th select { width: auto; min-width: 104px; height: 30px; font-weight: 400; margin-bottom: 6px; display: block; }
table.map-table th .colname { display: block; font-weight: 650; }
table.map-table th.as-student, table.map-table td.as-student { background: var(--accent-soft); }
table.map-table th.as-result, table.map-table td.as-result { background: var(--q1); }
table.map-table td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.fix-input { width: 320px; height: 30px; }
.shares { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.share-tag { font-size: 12px; padding: 1px 4px 1px 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--rule); }
.share-tag button { border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 0 4px; }
.row-actions { display: flex; gap: 10px; white-space: nowrap; }
dialog.md-dialog { border: 1px solid var(--rule); border-radius: 10px; padding: 20px; width: min(460px, 92vw); background: var(--surface); color: var(--ink); }
dialog.md-dialog::backdrop { background: rgba(0,0,0,.35); }
dialog.md-dialog h3 { margin: 0 0 6px; }
dialog.md-dialog .dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
dialog.md-dialog label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 10px 0 4px; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--rule);
  border-radius: 10px; padding: 32px 30px;
}
.login-school { margin: 0 0 4px; color: var(--ink-2); font-size: 13px; }
.login-card h1 { margin: 0 0 6px; font-size: 26px; }
.login-lede { margin: 0 0 24px; color: var(--ink-2); }
.login-error { background: var(--surface-2); border-left: 3px solid var(--danger); padding: 8px 12px; border-radius: 4px; font-size: 13px; }
.login-note { font-size: 12px; color: var(--ink-3); margin: 8px 0 0; }
.login-dev { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--rule-soft); }


/* ---------- My reports ---------- */
#view-reports { grid-template-columns: minmax(0, 1fr); }
.reports-list { padding: 28px; max-width: 960px; }
.reports-head { display: flex; gap: 20px; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.reports-head h2 { margin: 0 0 4px; font-size: 22px; }
.reports-head .lede { margin: 0; color: var(--ink-2); max-width: 70ch; }
.report-link { font-weight: 600; color: var(--ink); text-align: left; }

.rdoc-wrap { padding: 0 28px 60px; }
.rep-toolbar {
  position: sticky; top: 52px; z-index: 5; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  max-width: 900px; margin: 0 auto; padding: 10px 0; background: var(--page);
}
.rep-toolbar .spacer { flex: 1; }
.tb-sep { width: 1px; height: 22px; background: var(--rule); margin: 0 4px; }
.rdoc-status { font-size: 12px; color: var(--ink-3); margin-left: 8px; }
.rdoc { max-width: 900px; margin: 6px auto 0; padding: 40px 48px 48px; }
input.rdoc-title { width: 100%; font-size: 28px; font-weight: 700; line-height: 1.25; height: auto; border: 0; padding: 2px 4px; margin: 0 -4px; border-radius: 4px; background: transparent; }
input.rdoc-title:hover { background: var(--surface-2); }
input.rdoc-title:focus { outline: none; background: var(--surface-2); }
.rdoc-meta { color: var(--ink-3); font-size: 13px; margin: 4px 0 24px; }
.rdoc-empty { color: var(--ink-2); background: var(--surface-2); border-radius: var(--radius); padding: 16px; }

.rblock { position: relative; margin: 0 -12px; padding: 4px 12px; border-radius: 6px; }
.rblock:hover, .rblock:focus-within { background: var(--surface-2); }
.rblock-controls {
  position: absolute; top: 4px; right: 8px; display: none; gap: 2px; z-index: 2;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 2px;
}
.rblock:hover .rblock-controls, .rblock:focus-within .rblock-controls { display: flex; }
.rblock-controls .ctl { border: 0; background: none; cursor: pointer; padding: 3px 7px; border-radius: 4px; font-size: 12px; color: var(--ink-2); }
.rblock-controls .ctl:hover { background: var(--accent-soft); color: var(--ink); }
.rblock-controls .ctl:disabled { opacity: .35; cursor: default; background: none; }
.rblock [contenteditable] { outline: none; min-height: 1.5em; }
.rblock [contenteditable]:empty::before { content: attr(data-placeholder); color: var(--ink-3); }
.rblock-heading { margin: 18px 0 6px; font-size: 21px; line-height: 1.3; }
h3.rblock-heading { font-size: 17px; }
.rblock-text { font-size: 15px; line-height: 1.6; padding: 4px 0; max-width: 80ch; }
.rblock-text p { margin: 0 0 8px; }
.rblock-text ul, .rblock-text ol { margin: 4px 0 8px; padding-left: 24px; }
.rblock-figure { margin: 14px 0; }
.rblock-caption { margin-bottom: 8px; }
.rblock-title { font-weight: 650; font-size: 15px; }
.rblock-sub { font-size: 12px; color: var(--ink-3); margin: 2px 0 0; }
.rblock-figure .table-wrap { max-height: 60vh; }

dialog.picker { border: 1px solid var(--rule); border-radius: 10px; padding: 22px 24px; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); }
dialog.picker::backdrop { background: rgba(15, 20, 35, .35); }
dialog.picker h3 { margin: 0 0 14px; font-size: 18px; }
dialog.picker select, dialog.picker input[type="text"] { margin-bottom: 12px; }
.pick-what { display: flex; gap: 18px; margin: 4px 0 8px; }
.pick-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60;
  display: flex; gap: 14px; align-items: center; background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 24px rgba(15, 20, 35, .25);
}
.toast .link-btn { color: var(--surface); font-weight: 600; }

@media (max-width: 860px) { .rdoc { padding: 24px 18px; } .rdoc-wrap { padding: 0 12px 40px; } }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .topbar { gap: 12px; padding: 0 12px; overflow-x: auto; }
  .who-name { display: none; }
  .view { grid-template-columns: 1fr; }
  .filters { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--rule); }
  .report { padding: 16px; }
  .report-paper { padding: 18px 16px; }
}

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

/* ---------- print / PDF ---------- */
@page { size: A4 landscape; margin: 12mm; }
@page report { size: A4 portrait; margin: 16mm 14mm; }   /* written reports print portrait */
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 10pt; }
  .topbar, .filters, .sql-pane, .report-actions, .toolbar .btn, .toolbar select, .toolbar .view-switch,
  .chart-controls, .tooltip, .no-print { display: none !important; }
  .view { display: block; min-height: 0; }
  .view[hidden] { display: none !important; }
  .report { padding: 0; }
  .report-paper { border: 0; padding: 0; }
  input.report-title { font-size: 18pt; padding: 0; margin: 0; border: 0; width: 100%; background: none; }
  svg.chart .xhair { display: none; }
  .report-meta { display: block; font-size: 8.5pt; color: #555; margin-top: 4px; }
  .toolbar { margin: 10px 0 6px; padding-top: 0; border-top: 0; }
  .chart-frame { border: 0; padding: 0; break-inside: avoid; }
  .chart-box { break-inside: avoid; margin-top: 8px; }
  .table-wrap { overflow: visible; max-height: none; border: 0; }
  table.data { font-size: 8pt; }
  table.data th, table.data td { padding: 3px 5px; border-bottom: .5pt solid #ccc; }
  table.data thead { display: table-header-group; }
  table.data thead th { position: static; background: #f0f0f0 !important; color: #000; }
  table.data td.sticky, table.data th.sticky { position: static; }
  table.data tr { break-inside: avoid; }
  table.data tbody tr:hover td { background: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rdoc-wrap { padding: 0; }
  .rdoc { padding: 0; max-width: none; margin: 0; page: report; }
  input.rdoc-title { font-size: 20pt; padding: 0; margin: 0; background: none; }
  .rdoc-meta { font-size: 8.5pt; margin: 2px 0 14pt; }
  .rblock { margin: 0; padding: 0; background: none !important; }
  .rblock-heading { break-after: avoid; page-break-after: avoid; }
  .rblock-text { font-size: 10.5pt; max-width: none; }
  /* Chrome ignores break-inside:avoid on a named page, so make each chart one unbreakable box */
  .rb-chart { display: inline-block; width: 100%; vertical-align: top; }
  .rblock-figure .table-wrap { max-height: none; }
  .rblock [contenteditable]:empty { display: none; }
}

/* Watch list */
.watch-form .wrow { display: grid; grid-template-columns: 1fr 64px 52px; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.watch-form .wrow input { width: 64px; padding: 4px 6px; font-size: 13px; }
.watch-form .unit { font-size: 12px; color: var(--ink-3); }
.watch-form .check { display: flex; align-items: flex-start; gap: 6px; font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.watch-form .hint { margin-top: 8px; }
.watch-main { padding: 28px; max-width: 1000px; }
.watch-main h2 { margin: 0 0 4px; font-size: 22px; }
.watch-main .lede { color: var(--ink-2); margin: 0 0 4px; max-width: 75ch; }
.watch-main > .hint { margin: 0 0 20px; }
.watch-count { font-size: 13px; color: var(--ink-2); margin: 0 0 10px; }
.watch-table td { vertical-align: top; }
.watch-table .sub { display: block; font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.watch-table .concern { display: block; line-height: 1.6; }
.watch-table .when { font-size: 12px; color: var(--ink-3); margin-left: 6px; }
.watch-table .hit { color: #a12a1f; }
.watch-table tr.muted-row td { opacity: .7; }
.uni-summary { margin: 0 0 10px; color: var(--ink-2); }
.uni-table .uni-app { display: block; line-height: 1.5; margin-bottom: 6px; }
.uni-table .uni-app .sub { display: block; margin-top: 0; }
.uni-stage { font-size: 12px; margin-left: 8px; padding: 1px 7px; border-radius: 10px; background: var(--bg-2, #eef0f2); color: var(--ink-2); }
.uni-stage.stage-enrolled { background: #e3f1e6; color: #1f5f32; }
.uni-stage.stage-passed { background: #e7eef8; color: #24477a; }
.uni-stage.stage-conditional { background: #f6efdf; color: #6c5317; }
.uni-table td.num, .uni-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
#view-unis .filters select, #view-unis .filters input[type=search] { width: 100%; }

/* ---------------- one student's page: in the style of the MAP class profile sheet (white, also in dark mode) */
.student-page { padding: 24px 28px; max-width: 1200px; }
.student-find { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.student-find .field-label { margin: 0; }
.student-find input { width: 340px; max-width: 100%; }
.sheet { background: #fff; color: #222; font-family: Arial, Helvetica, sans-serif; font-size: 12px; border: 1px solid #d0d0d0; padding: 0 14px 16px; }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 12px 0 4px; }
.sheet-name { font-size: 22px; }
.sheet-meta { color: #555; font-size: 13px; }
.sheet-row { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 0 18px; align-items: start; }
.sheet-sec { margin-top: 14px; min-width: 0; }
@media (max-width: 900px) { .sheet-row { grid-template-columns: minmax(0, 1fr); } }
.band-bar { background: #8E7CC3; color: #fff; font-size: 16px; padding: 4px 10px; }
.band-btn { float: right; background: none; border: 0; color: #fff; font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; padding: 2px 0; }
.sheet-t { border-collapse: collapse; table-layout: fixed; width: 100%; }
.sheet-t td { border: 1px solid #e2e2e2; padding: 4px 6px; height: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-t col.c-when { width: 150px; } .sheet-t col.c-sq { width: 32px; } .sheet-t col.c-ib { width: 84px; }
.sheet-t td.hd { font-size: 11px; color: #555; background: #fafafa; }
.sheet-t td.hd.subj { white-space: normal; line-height: 1.2; vertical-align: bottom; }
.sheet-t td.lab { font-size: 12px; white-space: normal; }
.sheet-t td.rit, .sheet-t td.num { text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; }
.sheet-t td.rit .ave { display: block; font-size: 10px; color: #777; line-height: 1.1; }
.sheet-t td.txt { color: #444; white-space: normal; }
.sheet-t td.sq { text-align: center; font-size: 12px; }
.sheet-t td.below, .key.below { background: #FCE5CD; }
.sheet-t tr.avg td { background: #FFF2CC; }
.sheet-t tr.new-year td { border-top: 2px solid #b8b8b8; }
.sheet-t .b1, .key.b1 { background: #E53935; color: #fff; }
.sheet-t .b2, .key.b2 { background: #F57C00; color: #fff; }
.sheet-t .b3, .key.b3 { background: #F9C200; color: #3a2a00; }
.sheet-t .b4, .key.b4 { background: #43A047; color: #fff; }
.sheet-t .b5, .key.b5 { background: #3D7FE0; color: #fff; }
.sheet .legend { color: #666; font-size: 11px; padding: 6px 0 0; }
.key { display: inline-block; padding: 0 6px; margin-right: 4px; border-radius: 2px; }
.sheet .crit-btn { color: #222; text-align: left; font-size: 11px; line-height: 1.2; }
.sheet .crit-btn.on { color: #5b47a8; }
.crit-box { margin-top: 8px; max-width: 520px; }
.sheet .risk-note { margin: 8px 0 0; padding: 6px 10px; background: #FCE5CD; color: #4a2a00; font-size: 12px; }
.crit-title { font-size: 12px; color: #444; padding: 2px 0; display: flex; gap: 10px; }
/* DP cohort sheet: the colours of the cohort grade sheet */
.dpc-page { max-width: 1520px; }
.dpc-sheet { padding: 0 12px 16px; overflow-x: auto; }
.dpc-t { margin-top: 16px; min-width: 1400px; }
.dpc-t col.c-subj { width: 180px; } .dpc-t col.c-teacher { width: 130px; } .dpc-t col.c-lvl { width: 44px; } .dpc-t col.c-num { width: 50px; }
.dpc-t td { text-align: center; height: 21px; padding: 2px 3px; }
.dpc-t td.lab, .dpc-t td.teacher { text-align: left; }
.dpc-t td.teacher { font-size: 11px; color: #333; }
.dpc-t tr.dpc-h1 td { font-size: 13px; border-top: 2px solid #999; }
.dpc-t td.dpc-name { text-align: left; font-size: 14px; }
.dpc-t td.dpc-name .link-btn { color: #222; font-size: 14px; }
.dpc-t .dpc-id { color: #777; font-size: 11px; margin-left: 10px; }
#dpc-cohort { width: auto; min-width: 240px; }
.dpc-t tr.dpc-h2 td { font-size: 10.5px; border-bottom: 2px solid #999; }
.dpc-t .g-rep, .dpc-t .c-rep { background: #FFF2CC; }
.dpc-t .g-ee, .dpc-t .c-ee { background: #EFEFEF; }
.dpc-t .c-ee.dark { background: #D9D9D9; }
.dpc-t .g-proj { background: #FFFF00; }
.dpc-t .g-exam, .dpc-t .c-exam { background: #D9EAD3; }
.dpc-t td.lvl.hl { background: #B6D7A8; }
.dpc-t tr.core td.lab { color: #444; }
.dpc-t tr.tot td { border-top: 1px solid #bbb; }
.dpc-t tr.dip td.c-note { text-align: right; color: #444; background: #fff; }
.dpc-t td.strong-total { font-size: 14px; }

@media print {
  .student-page { padding: 0; }
  .dpc-t { break-inside: avoid; min-width: 0; }
  .sheet { border: 0; padding: 0; }
  .sheet, .sheet * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-sec { break-inside: avoid; }
}
