/* Quad prototype: design tokens and shared components */

/* Self-hosted fonts (SIL Open Font License, see assets/fonts) */
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/figtree-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/figtree-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/figtree-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/figtree-latin-700-normal.woff2) format('woff2'); }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 800; font-display: swap; src: url(../fonts/figtree-latin-800-normal.woff2) format('woff2'); }
@font-face { font-family: 'Literata'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/literata-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'Literata'; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/literata-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Literata'; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/literata-latin-700-normal.woff2) format('woff2'); }

:root {
  --font-ui: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Literata', Georgia, 'Times New Roman', serif;

  --bg: #F1F4F8;
  --surface: #FFFFFF;
  --surface-2: #F6F8FB;
  --surface-3: #EBEFF5;
  --ink: #101923;
  --ink-2: #485462;
  --ink-3: #697586;
  --line: #E0E6EE;
  --line-strong: #C7D0DC;

  --good: #157A48;  --good-bg: #E2F3E9;
  --warn: #8A5600;  --warn-bg: #FCEFD5;
  --bad: #B42318;   --bad-bg: #FDE7E4;
  --info: #1D5FA8;  --info-bg: #E4EEF9;

  /* chart blue: validated data-viz slot (contrast, lightness and chroma checked) */
  --chart-1: #2A78D6;
  --chart-muted: #CBD3DE;
  --chart-grid: #E6EBF2;
  --chart-axis: #C4CEDB;

  --shadow-1: 0 1px 2px rgba(16, 25, 35, .05);
  --shadow-2: 0 10px 30px rgba(16, 25, 35, .12), 0 2px 6px rgba(16, 25, 35, .06);
  --shadow-3: 0 30px 70px rgba(16, 25, 35, .24);

  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 22px;

  /* brand values are recalculated from config.js by core.js */
  --brand: #1C6CB0; --brand-strong: #165489; --brand-deep: #103F66; --on-brand: #FFFFFF;
  --brand-soft: #DDE9F4; --brand-tint: #EEF4FA; --brand-ink: #1C6CB0;
  --accent: #52A0DC; --on-accent: #0F1720; --accent-soft: #E3F0FA; --accent-ink: #29506E;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0D131A;
  --surface: #151D26;
  --surface-2: #1A2430;
  --surface-3: #212C39;
  --ink: #E6ECF2;
  --ink-2: #B2BDCA;
  --ink-3: #8894A3;
  --line: #253140;
  --line-strong: #344354;
  --good: #57C891;  --good-bg: #163225;
  --warn: #F2B94B;  --warn-bg: #3A2D12;
  --bad: #F38B80;   --bad-bg: #3E1F1C;
  --info: #84B6F0;  --info-bg: #172A40;
  --chart-1: #3987E5;
  --chart-muted: #3A4656;
  --chart-grid: #232E3B;
  --chart-axis: #354253;
  --shadow-1: none;
  --shadow-2: 0 10px 30px rgba(0, 0, 0, .45);
  --shadow-3: 0 30px 70px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* University logo */
.logo-tile {
  --s: 32px;
  width: var(--s); height: var(--s); flex: none; display: inline-grid; place-items: center;
  border-radius: 28%; background: #FFFFFF; box-shadow: 0 0 0 1px rgba(16, 25, 35, .08);
}
.logo-tile img { height: 66%; width: auto; display: block; }
.crest-img { display: block; border-radius: 50%; flex: none; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.ic { display: inline-block; vertical-align: middle; flex: none; }
:focus-visible { outline: 2px solid var(--brand-ink); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--ink-3); }
.ink-2 { color: var(--ink-2); }
.tnum { font-variant-numeric: tabular-nums; }
.display { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.015em; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent;
  font-weight: 600; font-size: 14px; white-space: nowrap; text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s, transform .08s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-strong); }
.btn-accent { background: var(--accent); color: var(--on-accent); }
.btn-accent:hover { filter: brightness(.96); }
.btn-ghost { color: var(--ink); border-color: var(--line-strong); background: var(--surface); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-quiet { color: var(--brand-ink); padding: 0 10px; }
.btn-quiet:hover { background: var(--brand-tint); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px; border: 0;
  background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.dot-badge { position: absolute; top: 6px; right: 6px; min-width: 9px; height: 9px; border-radius: 9px; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.count-badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-size: 11.5px; font-weight: 800; line-height: 1;
}

/* ---------- Form controls ---------- */
.field { display: grid; gap: 6px; }
.field > .label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.hint { font-size: 12.5px; color: var(--ink-3); }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); font-size: 14.5px;
}
.textarea { height: auto; min-height: 110px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand-ink); box-shadow: 0 0 0 3px var(--brand-soft); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23778580' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-strong); transition: background-color .2s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + span { background: var(--chart-1); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand-ink); outline-offset: 2px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--surface-3); }
.seg button { height: 32px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1), 0 0 0 1px var(--line); }

/* ---------- Chips & badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 13.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.chip:hover { border-color: var(--ink-3); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
  border-radius: 6px; font-size: 12px; font-weight: 700; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-2);
}
.badge .ic { width: 13px; height: 13px; }
.badge--good { background: var(--good-bg); color: var(--good); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--bad { background: var(--bad-bg); color: var(--bad); }
.badge--info { background: var(--info-bg); color: var(--info); }
.badge--brand { background: var(--brand-soft); color: var(--brand-ink); }
.badge--accent { background: var(--accent-soft); color: var(--accent-ink); }
.demo-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px;
  border-radius: 999px; border: 1px dashed var(--line-strong); color: var(--ink-3);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.demo-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* ---------- Avatars ---------- */
.avatar {
  --s: 36px;
  width: var(--s); height: var(--s); flex: none;
  display: inline-grid; place-items: center; border-radius: 50%;
  background: var(--av); color: #fff;
  font-weight: 700; font-size: calc(var(--s) * .37); letter-spacing: .02em; line-height: 1;
  user-select: none;
}
.avatar--square { border-radius: 30%; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.card-head h3 { font-size: 15.5px; font-weight: 700; }
.card-sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.card-body { padding: 14px 18px 18px; }
.card-link { font-size: 13.5px; font-weight: 600; color: var(--brand-ink); text-decoration: none; white-space: nowrap; }
.card-link:hover { text-decoration: underline; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12.5px; font-weight: 600; color: var(--ink-3);
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface);
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.cell-person { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.cell-person b { display: block; font-weight: 600; }
.cell-person small { display: block; color: var(--ink-3); font-size: 12.5px; }
.table .input { height: 34px; width: 64px; padding: 0 8px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Toasts ---------- */
#toast-host { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 1000; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-radius: 12px; background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow-2);
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast--error { background: var(--bad); color: #fff; }

/* ---------- Modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 18, 15, .5); opacity: 0; transition: opacity .2s; }
.modal {
  position: relative; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-3);
  transform: translateY(12px) scale(.98); opacity: 0; transition: transform .2s, opacity .2s;
}
.modal.wide { width: min(760px, 100%); }
.modal-wrap.open .modal-backdrop { opacity: 1; }
.modal-wrap.open .modal { transform: none; opacity: 1; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 0 24px; }
.modal-head h2 { font-size: 19px; }
.modal-sub { margin-top: 4px; font-size: 13.5px; color: var(--ink-3); }
.modal-body { padding: 16px 24px 8px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 22px; }

/* ---------- Charts ---------- */
.viz-card .viz-table { display: none; }
.viz-card.show-table .viz-table { display: block; }
.viz-card.show-table .viz-plot { display: none; }
.viz-tip {
  position: fixed; left: 0; top: 0; z-index: 2000; display: none; flex-direction: column; gap: 1px;
  padding: 8px 11px; border-radius: 10px; background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-2), 0 0 0 1px var(--line); pointer-events: none; max-width: 260px;
}
.viz-tip strong { font-size: 14.5px; font-weight: 700; }
.viz-tip span { font-size: 12.5px; color: var(--ink-3); }
.colchart, .linechart { --h: 180px; padding-left: 40px; }
.cc-plot { position: relative; height: var(--h); }
.cc-grid { position: absolute; inset: 0; }
.cc-grid .gl { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--chart-grid); }
.cc-grid .gl-base { border-top-color: var(--chart-axis); }
.cc-grid .gl span { position: absolute; right: calc(100% + 8px); top: -8px; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cc-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.col { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline-offset: -2px; }
.col .bar { position: relative; width: min(24px, 70%); background: var(--chart-1); border-radius: 4px 4px 0 0; min-height: 2px; transition: filter .12s; }
.col:hover .bar, .col:focus-visible .bar { filter: brightness(1.15); }
.col.is-dim .bar { background: var(--chart-muted); }
.col-val { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; white-space: nowrap; color: var(--ink); }
.cc-x { display: flex; gap: 2px; margin-top: 8px; }
.cc-x span { flex: 1; text-align: center; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: visible; }
.lc-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.lc-line { fill: none; stroke: var(--chart-1); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.lc-area { fill: var(--chart-1); opacity: .1; stroke: none; }
.lc-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--chart-1); box-shadow: 0 0 0 2px var(--surface); }
.lc-endlabel { position: absolute; right: -6px; transform: translate(100%, -50%); font-size: 12px; font-weight: 700; padding-left: 8px; white-space: nowrap; }
.linechart { padding-right: 44px; }
.lc-hits { position: absolute; inset: 0; display: grid; }
.lc-hit { position: relative; }
.lc-hit::after { content: ''; position: absolute; top: 0; bottom: 0; left: 50%; border-left: 1px solid var(--ink-3); opacity: 0; }
.lc-hit:hover::after, .lc-hit:focus-visible::after { opacity: .5; }
.lc-x { display: grid; }
.lc-x span { text-align: center; }
.hbars { display: grid; gap: 12px; }
.hb-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr; align-items: center; gap: 12px; border-radius: 6px; }
.hb-label { font-size: 13.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hb-track { position: relative; display: flex; align-items: center; gap: 8px; height: 22px; }
.hb-bar { height: 16px; background: var(--chart-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hb-row:hover .hb-bar, .hb-row:focus-visible .hb-bar { filter: brightness(1.15); }
.hb-val { font-size: 12.5px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.spark { overflow: visible; }
.spark path { fill: none; stroke: var(--ink-3); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; opacity: .7; }
.spark circle { fill: var(--chart-1); stroke: var(--surface); stroke-width: 2; }
.meter { height: 8px; border-radius: 999px; background: var(--brand-soft); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 999px; background: var(--chart-1); }
.meter--warn { background: var(--warn-bg); } .meter--warn span { background: #D4900F; }
.meter--bad { background: var(--bad-bg); } .meter--bad span { background: #D03B3B; }
.meter--accent { background: var(--accent-soft); } .meter--accent span { background: var(--accent); }
.ring-track { fill: none; stroke: var(--brand-soft); }
.ring-fill { fill: none; stroke: var(--chart-1); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }

/* ---------- Stat tiles ---------- */
.stat { display: grid; gap: 6px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { font-size: 13.5px; color: var(--ink-2); font-weight: 600; }
.stat-ic { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--brand-tint); color: var(--brand-ink); }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat-foot { display: flex; align-items: center; gap: 8px; min-height: 28px; flex-wrap: wrap; }
.stat-foot .spark { margin-left: auto; }
.stat-note { font-size: 12.5px; color: var(--ink-3); }
.delta { font-size: 12.5px; font-weight: 700; }
.delta--good { color: var(--good); }
.delta--bad { color: var(--bad); }
.delta--neutral { color: var(--ink-2); }

/* ---------- QR ---------- */
.qr { width: 100%; height: auto; border-radius: 6px; }
.qr-fallback { font-size: 12px; word-break: break-all; padding: 8px; border: 1px dashed var(--line-strong); border-radius: 8px; }

/* ---------- Misc ---------- */
.empty { display: grid; justify-items: center; gap: 8px; padding: 32px 16px; text-align: center; color: var(--ink-3); }
.empty .ic { color: var(--ink-3); }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 12px; }
.file-chip {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); text-decoration: none; color: inherit;
}
.file-chip .file-ic { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; background: var(--bad-bg); color: var(--bad); flex: none; }
.file-chip .file-ic.vid { background: var(--info-bg); color: var(--info); }
.file-chip b { display: block; font-size: 14px; font-weight: 600; line-height: 1.3; }
.file-chip small { font-size: 12.5px; color: var(--ink-3); }
.kbd { font-family: inherit; font-size: 12px; padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 5px; }
