/* =====================================================================
   City & Guilds Portal: design system + app shell
   Restrained and institutional: neutral surfaces, hairline borders,
   one brand red (#EB1C25, sampled from the C&G master logo) used
   sparingly, Inter for interface text, Literata for reading. Motion is
   reserved for meaning: page turns, answers, progress, arrivals.
   ===================================================================== */

:root {
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-display: var(--font-ui);
  --font-read: 'Literata', Georgia, 'Times New Roman', serif;
  --font-hyper: 'Atkinson Hyperlegible Next', 'Inter', sans-serif;

  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --surface-2: #F3F3F0;
  --surface-3: #E9E9E5;
  --ink: #141416;
  --ink-2: #55555C;
  --ink-3: #85858C;
  --line: #E7E7E2;
  --line-2: #D8D8D2;
  --brand: #D7141D;
  --brand-2: #EB1C25;
  --brand-tint: #FCEBEC;
  --on-brand: #FFFFFF;
  --focus: #2563EB;

  /* muted category tones (small badges, never large fills) */
  --lilac: #EEEBF8; --lilac-ink: #4B3F8F;
  --lime: #EEF3E2; --lime-ink: #44561A;
  --sky: #E8F0F8; --sky-ink: #24527A;
  --peach: #F8EDE6; --peach-ink: #8A4A26;
  --butter: #F7F1DF; --butter-ink: #7A5E14;
  --mint: #E6F2EC; --mint-ink: #22654A;

  --ok: #157F4F; --ok-tint: #E6F4EC;
  --warn: #8F6200; --warn-tint: #FBF1DA;
  --bad: #B42318; --bad-tint: #FCECEA;
  --info: #2554B8; --info-tint: #E9EFFB;

  --r-xs: 6px; --r-sm: 8px; --r: 10px; --r-lg: 12px; --r-xl: 14px; --r-2xl: 18px;
  --sh-1: 0 1px 2px rgba(20, 20, 22, .05);
  --sh-2: 0 1px 2px rgba(20, 20, 22, .04), 0 8px 24px -12px rgba(20, 20, 22, .14);
  --sh-3: 0 2px 6px rgba(20, 20, 22, .06), 0 24px 56px -20px rgba(20, 20, 22, .26);
  --ease: cubic-bezier(.22, .8, .24, 1);
  --ease-in: cubic-bezier(.5, 0, .75, 0);
  --spring: cubic-bezier(.34, 1.4, .64, 1);
  --sidebar: 244px;
  --topbar: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C0C0D; --surface: #141416; --surface-2: #1A1A1D; --surface-3: #242428;
    --ink: #EDEDEF; --ink-2: #A3A3AA; --ink-3: #74747C; --line: #232327; --line-2: #2F2F34;
    --brand: #F0444B; --brand-2: #F0444B; --brand-tint: #2A1517;
    --lilac: #1E1C2B; --lilac-ink: #C9C0F2; --lime: #1C2016; --lime-ink: #CFE39A; --sky: #172230; --sky-ink: #B5D2EE;
    --peach: #2A1E18; --peach-ink: #F0C3A6; --butter: #27231A; --butter-ink: #EBD59A; --mint: #16241D; --mint-ink: #A9E0C4;
    --ok: #4CC38A; --ok-tint: #14261D; --warn: #E2B24B; --warn-tint: #2A2416; --bad: #F2867C; --bad-tint: #2D1816; --info: #8AAEF5; --info-tint: #17213A;
    --focus: #7AA2F7;
    --sh-1: 0 1px 2px rgba(0, 0, 0, .4); --sh-2: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7); --sh-3: 0 2px 8px rgba(0, 0, 0, .4), 0 30px 70px -24px rgba(0, 0, 0, .85);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C0C0D; --surface: #141416; --surface-2: #1A1A1D; --surface-3: #242428;
  --ink: #EDEDEF; --ink-2: #A3A3AA; --ink-3: #74747C; --line: #232327; --line-2: #2F2F34;
  --brand: #F0444B; --brand-2: #F0444B; --brand-tint: #2A1517;
  --lilac: #1E1C2B; --lilac-ink: #C9C0F2; --lime: #1C2016; --lime-ink: #CFE39A; --sky: #172230; --sky-ink: #B5D2EE;
  --peach: #2A1E18; --peach-ink: #F0C3A6; --butter: #27231A; --butter-ink: #EBD59A; --mint: #16241D; --mint-ink: #A9E0C4;
  --ok: #4CC38A; --ok-tint: #14261D; --warn: #E2B24B; --warn-tint: #2A2416; --bad: #F2867C; --bad-tint: #2D1816; --info: #8AAEF5; --info-tint: #17213A;
  --focus: #7AA2F7;
  --sh-1: 0 1px 2px rgba(0, 0, 0, .4); --sh-2: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7); --sh-3: 0 2px 8px rgba(0, 0, 0, .4), 0 30px 70px -24px rgba(0, 0, 0, .85);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink);
  font: 14.5px/1.55 var(--font-ui); font-optical-sizing: auto; font-feature-settings: 'cv11', 'ss03';
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; letter-spacing: -.003em;
}
h1, h2, h3, h4 { font-family: var(--font-ui); font-weight: 600; letter-spacing: -.022em; line-height: 1.2; margin: 0; }
h1 { font-size: clamp(24px, 2.4vw, 30px); letter-spacing: -.028em; }
h2 { font-size: 19px; }
h3 { font-size: 15.5px; letter-spacing: -.012em; }
p { margin: 0; }
a { color: inherit; }
img { display: block; max-width: 100%; }
svg { display: inline-block; vertical-align: -0.18em; max-width: 100%; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: color-mix(in srgb, var(--focus) 22%, transparent); }
.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.eyebrow { font: 600 11px/1.2 var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 999; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }
.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot img { border-radius: 14px; animation: breathe 1.6s var(--ease) infinite; }
@keyframes breathe { 50% { opacity: .55; transform: scale(.97); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }

/* ----------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100dvh; }
.shell.collapsed { --sidebar: 68px; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 2px; padding: 14px 12px;
  border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; z-index: 30;
}
.brandmark { display: flex; align-items: center; gap: 11px; padding: 4px 6px 14px; text-decoration: none; }
.brandmark .logo { width: 36px; height: 36px; border-radius: 8px; background: #fff; padding: 2px; flex: none; border: 1px solid var(--line); }
.brandmark .wm { line-height: 1.15; min-width: 0; }
.brandmark .wm b { display: block; font-weight: 650; font-size: 14px; letter-spacing: -.01em; }
.brandmark .wm span { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.workspace { margin: 0 2px 8px; padding: 9px 10px; border-radius: var(--r); border: 1px solid var(--line); font-size: 12px; color: var(--ink-3); }
.workspace b { display: block; color: var(--ink); font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-group { margin-top: 12px; }
.nav-group > .eyebrow { padding: 4px 10px 6px; font-size: 10.5px; }
.nav a {
  display: flex; align-items: center; gap: 11px; min-height: 36px; padding: 7px 10px; border-radius: 8px; text-decoration: none;
  color: var(--ink-2); font-weight: 500; font-size: 14px; position: relative; transition: background .15s var(--ease), color .15s;
}
.nav a svg { flex: none; width: 18px; height: 18px; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.nav a[aria-current="page"]::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.nav a .count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; display: grid; place-items: center; font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--ink-2); }
.sidebar .spacer { flex: 1; min-height: 12px; }
.me-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r); border: 1px solid transparent; background: none; text-align: left; transition: background .15s, border-color .15s; }
.me-card:hover { background: var(--surface-2); }
.me-card .who { min-width: 0; flex: 1; line-height: 1.25; }
.me-card .who b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-card .who span { font-size: 12px; color: var(--ink-3); }
.shell.collapsed .brandmark .wm, .shell.collapsed .workspace, .shell.collapsed .nav a span, .shell.collapsed .nav-group > .eyebrow, .shell.collapsed .me-card .who, .shell.collapsed .me-card > svg, .shell.collapsed .nav a .count { display: none; }
.shell.collapsed .nav a { justify-content: center; padding: 8px; }
.shell.collapsed .me-card { justify-content: center; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar); display: flex; align-items: center; gap: 10px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.3) blur(12px); border-bottom: 1px solid transparent; transition: border-color .2s;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; overflow: hidden; font-size: 13.5px; color: var(--ink-3); }
@media (max-width: 680px) { .topbar .crumbs a, .topbar .crumbs > svg { display: none; } }
.topbar .crumbs a { text-decoration: none; color: var(--ink-3); white-space: nowrap; }
.topbar .crumbs a:hover { color: var(--ink); }
.topbar .crumbs svg { flex: none; opacity: .6; }
.topbar .crumbs b { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .grow { flex: 1; }
.searchbtn {
  display: flex; align-items: center; gap: 9px; height: 34px; padding: 0 8px 0 11px; min-width: 240px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-3); font-size: 13.5px; text-align: left; transition: border-color .15s, color .15s;
}
.searchbtn:hover { border-color: var(--ink-3); color: var(--ink-2); }
.searchbtn kbd { margin-left: auto; }
kbd { font: 500 11px/1 var(--font-ui); padding: 3px 5px; border-radius: 5px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink-3); }
.iconbtn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--ink-2); position: relative; flex: none;
  transition: background .15s, color .15s, transform .12s var(--ease);
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.iconbtn:active { transform: scale(.94); }
.iconbtn .dot { position: absolute; top: 7px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 2px var(--bg); }
.page { padding: 8px 28px 64px; max-width: 1280px; width: 100%; margin: 0 auto; animation: pageIn .32s var(--ease); }
.page.wide { max-width: none; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 14px 0 22px; }
.page-head .lede { color: var(--ink-2); margin-top: 6px; max-width: 68ch; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.bottombar { display: none; }
.scrim { display: none; }

@media (max-width: 980px) {
  .shell, .shell.collapsed { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); transform: translateX(-102%); transition: transform .28s var(--ease); box-shadow: var(--sh-3); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.collapsed .brandmark .wm, .shell.collapsed .workspace, .shell.collapsed .nav a span, .shell.collapsed .nav-group > .eyebrow, .shell.collapsed .me-card .who { display: revert; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .36); z-index: 25; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .shell.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .topbar { padding: 0 12px; }
  .searchbtn { min-width: 0; width: 34px; padding: 0; justify-content: center; }
  .searchbtn .label, .searchbtn kbd { display: none; }
  .page { padding: 4px 16px 104px; }
  .bottombar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(60px + env(safe-area-inset-bottom)); padding: 4px 6px env(safe-area-inset-bottom); background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(16px) saturate(1.3); border-top: 1px solid var(--line);
  }
  .bottombar a { display: grid; place-items: center; gap: 2px; align-content: center; text-decoration: none; color: var(--ink-3); font-size: 10.5px; font-weight: 500; position: relative; }
  .bottombar a[aria-current="page"] { color: var(--ink); font-weight: 600; }
  .bottombar a[aria-current="page"]::before { content: ''; position: absolute; top: 0; width: 22px; height: 2px; border-radius: 2px; background: var(--brand); }
}
@media (min-width: 981px) { .only-mobile { display: none !important; } }
@media (max-width: 980px) { .only-desktop { display: none !important; } }

/* --------------------------------------------------------------- buttons */
.btn {
  --b-bg: var(--surface); --b-ink: var(--ink); --b-line: var(--line-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--b-line);
  background: var(--b-bg); color: var(--b-ink); font-weight: 550; font-size: 13.5px; text-decoration: none; white-space: nowrap; user-select: none;
  transition: transform .12s var(--ease), background .15s, border-color .15s, box-shadow .15s, opacity .15s;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: scale(.98); }
.btn[disabled], .btn.loading { opacity: .5; pointer-events: none; }
.btn.primary { --b-bg: var(--ink); --b-ink: var(--bg); --b-line: var(--ink); }
.btn.primary:hover { --b-bg: color-mix(in srgb, var(--ink) 88%, var(--bg)); }
.btn.brand { --b-bg: var(--brand); --b-ink: #fff; --b-line: var(--brand); }
.btn.brand:hover { --b-bg: color-mix(in srgb, var(--brand) 90%, #000); }
.btn.ghost { --b-bg: transparent; --b-line: transparent; }
.btn.ghost:hover { --b-bg: var(--surface-2); }
.btn.danger { --b-bg: transparent; --b-ink: var(--bad); --b-line: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn.danger:hover { --b-bg: var(--bad-tint); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn.lg { height: 44px; padding: 0 18px; font-size: 15px; border-radius: 10px; }
.btn.lg svg { width: 18px; height: 18px; }
.btn.block { width: 100%; }
.btn.loading::after { content: ''; width: 13px; height: 13px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ----------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 20px; min-width: 0; }
.card.flat { background: var(--surface); }
.card.pad-lg { padding: 28px; }
.card.hover { transition: border-color .15s, box-shadow .2s, transform .2s var(--ease); }
.card.hover:hover { border-color: var(--line-2); box-shadow: var(--sh-2); transform: translateY(-1px); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { font-size: 15px; }
.card-head .link { font-size: 13px; font-weight: 500; color: var(--ink-3); text-decoration: none; display: inline-flex; align-items: center; gap: 3px; transition: color .15s; }
.card-head .link:hover { color: var(--ink); }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
@media (max-width: 1100px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 680px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } .card { padding: 16px; } }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.tile { border-radius: var(--r-lg); padding: 16px; border: 1px solid var(--line); background: var(--surface-2); }
.tile.lilac { background: var(--lilac); color: var(--lilac-ink); border-color: transparent; }
.tile.lime { background: var(--lime); color: var(--lime-ink); border-color: transparent; }
.tile.sky { background: var(--sky); color: var(--sky-ink); border-color: transparent; }
.tile.peach { background: var(--peach); color: var(--peach-ink); border-color: transparent; }
.tile.butter { background: var(--butter); color: var(--butter-ink); border-color: transparent; }
.tile.mint { background: var(--mint); color: var(--mint-ink); border-color: transparent; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }

/* stat */
.stat { display: flex; flex-direction: column; gap: 8px; }
.stat .k { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-weight: 500; font-size: 13px; }
.stat .k .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); }
.stat .v { font-weight: 600; font-size: 28px; line-height: 1.05; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat .d { font-size: 12.5px; color: var(--ink-3); }
.delta-up { color: var(--ok); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }

/* chips, badges */
.chip { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--ink-2); border: 1px solid transparent; white-space: nowrap; }
.chip svg { width: 13px; height: 13px; }
.chip.sm { height: 20px; padding: 0 6px; font-size: 11.5px; }
.chip.ok { background: var(--ok-tint); color: var(--ok); }
.chip.warn { background: var(--warn-tint); color: var(--warn); }
.chip.bad { background: var(--bad-tint); color: var(--bad); }
.chip.info { background: var(--info-tint); color: var(--info); }
.chip.brand { background: var(--brand-tint); color: var(--brand); }
.chip.ink { background: var(--ink); color: var(--bg); }
.chip.outline { background: transparent; border-color: var(--line-2); }
button.chip { cursor: pointer; transition: background .15s, border-color .15s; height: 28px; padding: 0 10px; border-radius: 7px; }
button.chip:hover { border-color: var(--ink-3); }
button.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.dotlabel { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; }
.dotlabel::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* avatar */
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 12.5px; color: var(--ink-2); flex: none; overflow: hidden; background: var(--surface-3); border: 1px solid var(--line); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 64px; height: 64px; font-size: 21px; }

/* progress */
.bar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--ink); transform-origin: left; animation: fillIn 1s var(--ease) both; transition: width .6s var(--ease); }
.bar.brand > i { background: var(--brand); }
.bar.ok > i { background: var(--ok); }
@keyframes fillIn { from { transform: scaleX(0); } }
.ring { --size: 64px; --w: 5px; --c: var(--ink); width: var(--size); height: var(--size); display: grid; place-items: center; position: relative; flex: none; }
.ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: var(--w); }
.ring .track { stroke: var(--surface-3); }
.ring .val { stroke: var(--c); stroke-linecap: round; animation: ringIn 1.1s var(--ease) both; }
@keyframes ringIn { from { stroke-dashoffset: var(--full); } }
.ring b { position: relative; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .label { font-size: 13px; font-weight: 550; color: var(--ink); }
.field .hint { font-size: 12.5px; color: var(--ink-3); }
.field .err { font-size: 12.5px; color: var(--bad); font-weight: 500; animation: errIn .25s var(--ease); }
@keyframes errIn { from { opacity: 0; transform: translateY(-3px); } }
.input, select.input, textarea.input {
  width: 100%; min-height: 38px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  transition: border-color .15s, box-shadow .15s; font-size: 14px;
}
textarea.input { min-height: 104px; resize: vertical; line-height: 1.55; }
.input::placeholder { color: var(--ink-3); }
.input:hover { border-color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--ink-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 16%, transparent); }
.input[aria-invalid="true"] { border-color: var(--bad); animation: shake .35s var(--ease); }
select.input { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2385858C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 680px) { .form-grid { grid-template-columns: 1fr; } }
.inputwrap { position: relative; }
.inputwrap .input { padding-left: 36px; }
.inputwrap > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; width: 16px; height: 16px; }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; min-height: 24px; }
.check input { width: 16px; height: 16px; accent-color: var(--ink); }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--line-2); transition: background .2s; pointer-events: none; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: var(--sh-1); transition: transform .22s var(--spring); }
.switch input:checked + span { background: var(--ink); border-color: var(--ink); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); flex-wrap: wrap; }
.seg button, .seg a { height: 28px; padding: 0 11px; border-radius: 6px; border: 0; background: transparent; font-weight: 500; font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; text-decoration: none; transition: background .15s, color .15s, box-shadow .15s; }
.seg [aria-pressed="true"], .seg .on { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }
.dropzone { border: 1px dashed var(--line-2); border-radius: var(--r-lg); padding: 24px; text-align: center; color: var(--ink-2); transition: border-color .15s, background .15s; cursor: pointer; }
.dropzone.over, .dropzone:hover { border-color: var(--ink-2); background: var(--surface-2); }
.dropzone input { display: none; }
@keyframes shake { 20%, 60% { transform: translateX(-3px); } 40%, 80% { transform: translateX(3px); } }

/* ----------------------------------------------------------------- tables */
.table-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.table-tools .inputwrap { flex: 1; min-width: 220px; max-width: 380px; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--surface); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.t th { text-align: left; font-size: 12px; font-weight: 500; color: var(--ink-3); padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
table.t th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
table.t th button:hover { color: var(--ink); }
table.t td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr { transition: background .12s; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t tbody tr.clickable { cursor: pointer; }
table.t .cell-main { display: flex; align-items: center; gap: 11px; min-width: 0; }
table.t .cell-main b { display: block; font-weight: 550; }
table.t .cell-main span { font-size: 12.5px; color: var(--ink-3); }
table.t td.actions { text-align: right; white-space: nowrap; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 2px 0; font-size: 13px; color: var(--ink-3); }

/* ------------------------------------------------------------ overlays */
.modal-scrim { position: fixed; inset: 0; z-index: 100; background: rgba(12, 12, 14, .42); display: grid; place-items: center; padding: 18px; animation: fadeIn .18s var(--ease); }
.modal {
  width: min(540px, 100%); max-height: calc(100dvh - 36px); overflow: auto; background: var(--surface); border-radius: var(--r-2xl); box-shadow: var(--sh-3); border: 1px solid var(--line);
  animation: modalIn .28s var(--ease);
}
.modal.wide { width: min(860px, 100%); }
.modal.xl { width: min(1080px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px 6px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-head h2 { font-size: 17px; }
.modal-head p { color: var(--ink-2); margin-top: 4px; font-size: 13.5px; }
.modal-body { padding: 12px 22px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 18px; position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.985); } }
@media (max-width: 680px) {
  .modal-scrim { align-items: end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92dvh; animation: sheetIn .32s var(--ease); }
  @keyframes sheetIn { from { transform: translateY(100%); } }
}
.drawer-scrim { position: fixed; inset: 0; z-index: 100; background: rgba(12, 12, 14, .28); animation: fadeIn .2s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); z-index: 100; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--sh-3); display: flex; flex-direction: column; animation: drawerIn .3s var(--ease); }
@keyframes drawerIn { from { transform: translateX(100%); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { font-size: 15px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; }

.menu { position: fixed; z-index: 120; min-width: 200px; padding: 5px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--sh-3); animation: menuIn .16s var(--ease); transform-origin: top right; }
@keyframes menuIn { from { opacity: 0; transform: scale(.97) translateY(-3px); } }
.menu button, .menu a { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border-radius: 6px; border: 0; background: none; text-align: left; font-size: 13.5px; text-decoration: none; color: var(--ink); }
.menu svg { width: 16px; height: 16px; color: var(--ink-3); }
.menu button:hover, .menu a:hover, .menu button:focus-visible, .menu a:focus-visible { background: var(--surface-2); outline: none; }
.menu .danger, .menu .danger svg { color: var(--bad); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }

#toasts { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; width: min(92vw, 400px); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px; background: var(--ink); color: var(--bg); box-shadow: var(--sh-3); font-weight: 500; font-size: 13.5px; animation: toastIn .3s var(--ease); max-width: 100%; }
.toast svg { width: 17px; height: 17px; flex: none; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.leave { animation: toastOut .22s var(--ease-in) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(12px); } }
@media (max-width: 980px) { #toasts { right: 12px; left: 12px; width: auto; bottom: 76px; align-items: stretch; } }

/* command palette */
.cmdk { width: min(620px, 100%); align-self: start; margin-top: 12vh; background: var(--surface); border-radius: 14px; border: 1px solid var(--line); box-shadow: var(--sh-3); overflow: hidden; animation: modalIn .2s var(--ease); }
.cmdk .q { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.cmdk .q input { flex: 1; border: 0; outline: 0; background: none; font-size: 16px; }
.cmdk .list { max-height: 56vh; overflow-y: auto; padding: 6px; }
.cmdk .item { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px; cursor: pointer; text-decoration: none; }
.cmdk .item[aria-selected="true"] { background: var(--surface-2); }
.cmdk .item .ic { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; border: 1px solid var(--line); flex: none; color: var(--ink-2); }
.cmdk .item .ic svg { width: 16px; height: 16px; }
.cmdk .item b { display: block; font-weight: 550; font-size: 14px; }
.cmdk .item span { font-size: 12px; color: var(--ink-3); }
.cmdk .group { padding: 10px 10px 4px; }

/* -------------------------------------------------------------- empty / skeleton */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 20px; color: var(--ink-2); }
.empty .art { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-3); margin-bottom: 6px; }
.empty .art svg { width: 22px; height: 22px; }
.empty h3 { color: var(--ink); }
.empty p { max-width: 44ch; font-size: 13.5px; }
.empty .btn { margin-top: 8px; }
.skel { border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 300% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border-radius: var(--r); background: var(--info-tint); color: var(--ink); font-size: 13.5px; }
.callout.warn { background: var(--warn-tint); }
.callout.bad { background: var(--bad-tint); }
.callout.ok { background: var(--ok-tint); }
.callout svg { flex: none; margin-top: 1px; width: 17px; height: 17px; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs button, .tabs a { position: relative; height: 38px; padding: 0 12px; border: 0; background: none; font-weight: 500; font-size: 13.5px; color: var(--ink-3); white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 7px; transition: color .15s; }
.tabs button:hover, .tabs a:hover { color: var(--ink); }
.tabs [aria-selected="true"] { color: var(--ink); }
.tabs [aria-selected="true"]::after { content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--ink); animation: tabIn .25s var(--ease); }
@keyframes tabIn { from { transform: scaleX(.4); opacity: 0; } }

/* list rows */
.list { display: flex; flex-direction: column; }
.list .li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); text-decoration: none; min-width: 0; }
.list .li:last-child { border-bottom: 0; }
.list .li .main { flex: 1; min-width: 0; }
.list .li .main b { display: block; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .li .main span { font-size: 12.5px; color: var(--ink-3); }
.list.wrap .li .main b { white-space: normal; overflow: visible; }
a.li { transition: background .12s; border-radius: 6px; }
a.li:hover { background: var(--surface-2); }

/* charts */
.chart { width: 100%; height: auto; overflow: visible; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--ink-3); font: 500 11px var(--font-ui); }
.chart rect.b { transform-box: fill-box; transform-origin: bottom; animation: growUp .7s var(--ease) both; }
@keyframes growUp { from { transform: scaleY(0); } }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ----------------------------------------------------------------- auth */
.auth {
  min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 32px 16px; position: relative; overflow: hidden; isolation: isolate;
  background: var(--bg);
}
.auth::before { /* faint engineering grid, masked to a soft ellipse */
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px; background-position: center center;
  -webkit-mask-image: radial-gradient(ellipse 60% 55% at 50% 45%, #000 15%, transparent 72%); mask-image: radial-gradient(ellipse 60% 55% at 50% 45%, #000 15%, transparent 72%);
  opacity: .7;
}
.auth::after { content: ''; position: absolute; left: 50%; top: 42%; width: 760px; height: 520px; transform: translate(-50%, -50%); z-index: -1; pointer-events: none; background: radial-gradient(closest-side, color-mix(in srgb, var(--surface) 90%, transparent), transparent); }
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px 30px 26px;
  box-shadow: 0 1px 2px rgba(20, 20, 22, .04), 0 20px 50px -24px rgba(20, 20, 22, .22); display: flex; flex-direction: column; gap: 16px;
  animation: cardIn .5s var(--ease);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(12px); } }
.auth-card .logo { width: 56px; height: 56px; border-radius: 12px; background: #fff; padding: 3px; border: 1px solid var(--line); }
.auth-card h1 { font-size: 22px; letter-spacing: -.025em; }
.auth-card .sub { color: var(--ink-2); font-size: 13.5px; margin-top: 4px; }
.auth-foot { margin-top: 22px; text-align: center; font-size: 12px; color: var(--ink-3); }
.auth-foot a { color: var(--ink-3); }
.demo-row { display: flex; flex-wrap: wrap; gap: 6px; }
.textlink { background: none; border: 0; padding: 0; color: var(--ink-2); font-size: 13px; font-weight: 500; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; transition: color .15s, text-decoration-color .15s; }
.textlink:hover { color: var(--ink); text-decoration-color: currentColor; }

/* ---------------------------------------------------------- celebration */
.burst { position: fixed; inset: 0; pointer-events: none; z-index: 300; }
.burst i { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--brand)); animation: burst .9s var(--ease) forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
.draw-check path { stroke-dasharray: 30; stroke-dashoffset: 30; animation: draw .45s .1s var(--ease) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* print */
@media print {
  .sidebar, .topbar, .bottombar, #toasts, .no-print { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
}

/* bar chart (HTML so labels keep their size at any width) */
.bars { display: flex; align-items: stretch; gap: 6px; height: calc(var(--h) + 22px); }
.bars .col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; }
.bars .b { width: 100%; max-width: 34px; border-radius: 5px 5px 2px 2px; transform-origin: bottom; animation: growUp .7s var(--ease) both; min-height: 0; }
.bars .val { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-height: 14px; }
.bars .lab { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bars .track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; min-height: 0; }

/* ------------------------------------------------------------ maths (KaTeX) */
.math-block { margin: 10px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.math-inline .katex { font-size: 1.05em; }
.katex { color: inherit; }

/* ------------------------------------------------------- proctor self-view */
.proctor-tile { position: relative; width: 168px; aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden; background: #000; border: 1px solid var(--line); box-shadow: var(--sh-2); }
.proctor-tile video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.proctor-dot { position: absolute; top: 9px; left: 9px; width: 8px; height: 8px; border-radius: 50%; background: #2FB463; box-shadow: 0 0 0 3px rgba(47, 180, 99, .25); animation: breathe 2s var(--ease) infinite; }
.proctor-label { position: absolute; left: 22px; top: 5px; font-size: 11px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.proctor-tile.lost { border-color: var(--bad); }
.proctor-tile.lost .proctor-dot { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 30%, transparent); }
