/* =====================================================================
   Let's Talk Portal — Design System
   ---------------------------------------------------------------------
   One stylesheet, no framework. Everything is built from the tokens in
   :root, so changing the brand colour in one place changes the whole
   portal. Mobile-first: base styles are the phone layout, and media
   queries add complexity as the screen grows.
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. Tokens
   --------------------------------------------------------------------- */
:root {
  /* Brand — warm yellow against near-black charcoal */
  --brand-50:  #fffaeb;
  --brand-100: #fff2c6;
  --brand-200: #ffe488;
  --brand-300: #ffd24a;
  --brand-400: #ffc020;
  --brand-500: #f2a900;   /* primary */
  --brand-600: #d68a00;
  --brand-700: #ab6702;
  --brand-800: #8c5108;
  --brand-900: #74430c;

  /* Charcoal neutrals */
  --ink-50:  #f7f7f8;
  --ink-100: #ededf0;
  --ink-200: #d8d8de;
  --ink-300: #b7b7c0;
  --ink-400: #8e8e9a;
  --ink-500: #6e6e7a;
  --ink-600: #575761;
  --ink-700: #45454e;
  --ink-800: #2b2b31;
  --ink-900: #1a1a1d;
  --ink-950: #0f0f11;

  /* Status */
  --ok-bg:   #e9f7ef;  --ok-fg:   #10693c;  --ok-line:  #7fcfa4;
  --warn-bg: #fff5e0;  --warn-fg: #8a5a00;  --warn-line:#f0c060;
  --bad-bg:  #fdeceb;  --bad-fg:  #a52620;  --bad-line: #eda49f;
  --info-bg: #eaf2fd;  --info-fg: #1a5199;  --info-line:#9cc2ef;

  /* Semantic surfaces — remapped wholesale in dark mode */
  --bg:          var(--ink-50);
  --surface:     #ffffff;
  --surface-2:   var(--ink-50);
  --surface-3:   var(--ink-100);
  --border:      var(--ink-200);
  --border-soft: var(--ink-100);
  --text:        var(--ink-900);
  --text-muted:  var(--ink-500);
  --text-subtle: var(--ink-400);
  --accent:      var(--brand-500);
  --accent-text: var(--ink-900);
  --focus:       var(--brand-400);

  /* Type — fluid, clamps between phone and desktop */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --text-xs:  0.75rem;
  --text-sm:  0.875rem;
  --text-base: 1rem;
  --text-lg:  1.125rem;
  --text-xl:  clamp(1.2rem, 1.1rem + 0.4vw, 1.375rem);
  --text-2xl: clamp(1.45rem, 1.3rem + 0.7vw, 1.75rem);
  --text-3xl: clamp(1.75rem, 1.5rem + 1.2vw, 2.25rem);
  --text-4xl: clamp(2.1rem, 1.7rem + 2vw, 3rem);

  /* Spacing — 4px base */
  --sp-1: 0.25rem; --sp-2: 0.5rem;  --sp-3: 0.75rem; --sp-4: 1rem;
  --sp-5: 1.25rem; --sp-6: 1.5rem;  --sp-8: 2rem;    --sp-10: 2.5rem;
  --sp-12: 3rem;   --sp-16: 4rem;   --sp-20: 5rem;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 15, 17, 0.06);
  --shadow:    0 2px 6px rgba(15, 15, 17, 0.07), 0 1px 2px rgba(15, 15, 17, 0.04);
  --shadow-md: 0 6px 16px rgba(15, 15, 17, 0.09), 0 2px 4px rgba(15, 15, 17, 0.05);
  --shadow-lg: 0 16px 40px rgba(15, 15, 17, 0.13), 0 4px 10px rgba(15, 15, 17, 0.06);

  --sidebar-w: 260px;
  --header-h:  64px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 120ms var(--ease);
  --t-base: 200ms var(--ease);
}

/* Dark mode: follows the OS, and the [data-theme] attribute wins over it
   so the in-app toggle works in both directions. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          var(--ink-950);
    --surface:     #17171a;
    --surface-2:   #1f1f24;
    --surface-3:   #2a2a31;
    --border:      #34343d;
    --border-soft: #26262d;
    --text:        var(--ink-50);
    --text-muted:  var(--ink-300);
    --text-subtle: var(--ink-400);
    --accent:      var(--brand-400);
    --accent-text: var(--ink-950);

    --ok-bg:   #102a1c; --ok-fg:   #6fd39d; --ok-line:  #1f6340;
    --warn-bg: #2e2408; --warn-fg: #f0c060; --warn-line:#7a5c14;
    --bad-bg:  #2e1513; --bad-fg:  #f09b95; --bad-line: #7a2f29;
    --info-bg: #101f33; --info-fg: #8ab8ef; --info-line:#1f4a80;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow:    0 2px 6px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  --bg:          var(--ink-950);
  --surface:     #17171a;
  --surface-2:   #1f1f24;
  --surface-3:   #2a2a31;
  --border:      #34343d;
  --border-soft: #26262d;
  --text:        var(--ink-50);
  --text-muted:  var(--ink-300);
  --text-subtle: var(--ink-400);
  --accent:      var(--brand-400);
  --accent-text: var(--ink-950);

  --ok-bg:   #102a1c; --ok-fg:   #6fd39d; --ok-line:  #1f6340;
  --warn-bg: #2e2408; --warn-fg: #f0c060; --warn-line:#7a5c14;
  --bad-bg:  #2e1513; --bad-fg:  #f09b95; --bad-line: #7a2f29;
  --info-bg: #101f33; --info-fg: #8ab8ef; --info-line:#1f4a80;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow:    0 2px 6px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
}

/* ---------------------------------------------------------------------
   2. Reset and base
   --------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
}

img, svg, video { display: block; max-width: 100%; height: auto; }

input, button, textarea, select { font: inherit; color: inherit; }

h1, h2, h3, h4 { line-height: 1.25; font-weight: 650; letter-spacing: -0.015em; }
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; }

a { color: inherit; text-decoration-color: var(--brand-400); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }

/* One visible focus style everywhere, keyboard-only. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--brand-200); color: var(--ink-900); }

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

.skip-link {
  position: absolute; top: -100px; left: var(--sp-4); z-index: 200;
  background: var(--accent); color: var(--accent-text);
  padding: var(--sp-3) var(--sp-5); border-radius: var(--radius);
  font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: var(--sp-4); }

/* ---------------------------------------------------------------------
   3. Layout
   --------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: 1240px;
  margin-inline: auto;
  padding-inline: var(--sp-4);
}
@media (min-width: 768px) { .container { padding-inline: var(--sp-6); } }

.container-narrow { max-width: 720px; }
.container-tight  { max-width: 460px; }

.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-8); }

.row {
  display: flex; align-items: center; gap: var(--sp-3);
  flex-wrap: wrap;
}
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.spacer { flex: 1 1 auto; }

.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (min-width: 640px)  { .grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (min-width: 900px)  { .grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
                             .grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); } }

/* App shell: sidebar + content. Sidebar becomes a drawer on small screens. */
.app-shell { display: flex; min-height: 100dvh; }

.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0;
  width: var(--sidebar-w); z-index: 60;
  background: var(--ink-900); color: var(--ink-100);
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--t-base);
  overflow-y: auto; overscroll-behavior: contain;
}
.sidebar.is-open { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(15,15,17,.55);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-base);
  backdrop-filter: blur(2px);
}
.sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

@media (min-width: 1024px) {
  .sidebar { transform: none; }
  .sidebar-backdrop { display: none; }
  .app-main { margin-inline-start: var(--sidebar-w); }
  .nav-toggle { display: none; }
}

.sidebar-brand {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-5); border-bottom: 1px solid rgba(255,255,255,.08);
  font-weight: 700; letter-spacing: -0.02em; color: #fff;
}
.brand-mark {
  width: 36px; height: 36px; flex: 0 0 36px;
  border-radius: 9px; background: var(--brand-500); color: var(--ink-900);
  display: grid; place-items: center; font-weight: 800; font-size: .8rem;
}

.sidebar-nav { padding: var(--sp-4) var(--sp-3); flex: 1; }
.nav-label {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-400); font-weight: 700;
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3); border-radius: var(--radius);
  color: var(--ink-200); text-decoration: none; font-weight: 500;
  font-size: var(--text-sm);
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.is-active {
  background: var(--brand-500); color: var(--ink-900); font-weight: 650;
}
.nav-item .icon { flex: 0 0 18px; opacity: .9; }
.nav-item.is-active .icon { opacity: 1; }
.nav-badge {
  margin-inline-start: auto; background: var(--bad-fg); color: #fff;
  font-size: var(--text-xs); font-weight: 700;
  min-width: 20px; height: 20px; padding-inline: 6px;
  border-radius: var(--radius-full); display: grid; place-items: center;
}
.nav-item.is-active .nav-badge { background: var(--ink-900); color: #fff; }

.sidebar-footer {
  padding: var(--sp-4); border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: var(--sp-3);
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--sp-3);
  padding-inline: var(--sp-4);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
@media (min-width: 768px) { .topbar { padding-inline: var(--sp-6); } }

.topbar h1 { font-size: var(--text-lg); font-weight: 650; }

.nav-toggle {
  display: grid; place-items: center;
  width: 40px; height: 40px; flex: 0 0 40px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
}
.nav-toggle:hover { background: var(--surface-2); }

.page { padding: var(--sp-6) var(--sp-4) var(--sp-16); flex: 1; }
@media (min-width: 768px) { .page { padding: var(--sp-8) var(--sp-6) var(--sp-20); } }

.page-head { margin-bottom: var(--sp-6); }
.page-head h2 { margin-bottom: var(--sp-1); }
.page-head .lede { color: var(--text-muted); font-size: var(--text-sm); }

/* ---------------------------------------------------------------------
   4. Cards and panels
   --------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: flex-start; gap: var(--sp-4);
  justify-content: space-between; flex-wrap: wrap;
  padding: var(--sp-5); border-bottom: 1px solid var(--border-soft);
}
.card-head h3 { font-size: var(--text-lg); }
.card-head .sub { color: var(--text-muted); font-size: var(--text-sm); margin-top: 2px; }
.card-body { padding: var(--sp-5); }
.card-foot {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border-soft);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.card-hover { transition: transform var(--t-base), box-shadow var(--t-base); }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* Stat tiles */
.stat {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: var(--text-xs); font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-subtle);
}
.stat-value {
  font-size: var(--text-3xl); font-weight: 700; line-height: 1.1;
  margin-top: var(--sp-2); letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat-meta { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--sp-1); }
.stat-accent { border-inline-start: 3px solid var(--accent); }

/* ---------------------------------------------------------------------
   5. Buttons
   --------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-2);
  padding: 0.625rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-sm); font-weight: 600;
  line-height: 1.4; text-decoration: none;
  cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
              transform var(--t-fast), box-shadow var(--t-fast);
  /* Comfortable tap target on phones */
  min-height: 42px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent); color: var(--accent-text);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-600); }

.btn-dark { background: var(--ink-900); color: #fff; }
.btn-dark:hover:not(:disabled) { background: var(--ink-800); }

.btn-secondary {
  background: var(--surface); color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--ink-300); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn-danger { background: var(--bad-fg); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.92); }

.btn-sm { padding: 0.4rem 0.75rem; font-size: var(--text-xs); min-height: 34px; }
.btn-lg { padding: 0.85rem 1.6rem; font-size: var(--text-base); min-height: 50px; }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 38px; min-height: 38px; flex: 0 0 38px; }

/* ---------------------------------------------------------------------
   6. Forms
   --------------------------------------------------------------------- */
.field { display: block; margin-bottom: var(--sp-4); }
.field > label,
.label {
  display: block; font-size: var(--text-sm); font-weight: 600;
  margin-bottom: var(--sp-2);
}
.hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--sp-2); }
.required { color: var(--bad-fg); }

.input, .select, .textarea {
  width: 100%;
  padding: 0.625rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-base);
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  /* 16px minimum stops iOS Safari zooming on focus */
  min-height: 42px;
}
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }

.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-300); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.textarea { min-height: 6rem; resize: vertical; line-height: 1.55; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236e6e7a' d='M1.4 0 6 4.6 10.6 0 12 1.4 6 7.4 0 1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  padding-inline-end: 2.2rem;
}

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea { border-color: var(--bad-fg); }
.field-error { font-size: var(--text-xs); color: var(--bad-fg); margin-top: var(--sp-2); font-weight: 500; }

.check {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  cursor: pointer; font-size: var(--text-sm);
  padding: var(--sp-2) 0;
}
.check input { margin-top: 0.2rem; width: 17px; height: 17px; accent-color: var(--accent); flex: 0 0 auto; }

.input-group { display: flex; gap: var(--sp-2); }
.input-group .input { flex: 1; }

/* File input styled as a drop zone */
.file-field {
  display: block; padding: var(--sp-5);
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  background: var(--surface-2); text-align: center; cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.file-field:hover { border-color: var(--accent); background: var(--brand-50); }
.file-field input[type="file"] { display: none; }
.file-field .file-cta { font-weight: 600; font-size: var(--text-sm); }
.file-field .file-meta { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--sp-1); }
:root[data-theme="dark"] .file-field:hover { background: var(--surface-3); }

/* Auth pages */
.auth-wrap {
  min-height: 100dvh; display: grid; place-items: center;
  padding: var(--sp-6) var(--sp-4);
  background:
    radial-gradient(1100px 500px at 50% -12%, var(--brand-100), transparent 62%),
    var(--bg);
}
:root[data-theme="dark"] .auth-wrap {
  background: radial-gradient(1100px 500px at 50% -12%, #2b2408, transparent 62%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  padding: var(--sp-8) var(--sp-6);
}
@media (min-width: 480px) { .auth-card { padding: var(--sp-10) var(--sp-8); } }
.auth-head { text-align: center; margin-bottom: var(--sp-6); }
.auth-head .brand-mark { margin: 0 auto var(--sp-4); width: 48px; height: 48px; font-size: .95rem; }
.auth-head h1 { font-size: var(--text-2xl); margin-bottom: var(--sp-2); }
.auth-head p { color: var(--text-muted); font-size: var(--text-sm); }
.auth-foot {
  margin-top: var(--sp-6); padding-top: var(--sp-5);
  border-top: 1px solid var(--border-soft);
  text-align: center; font-size: var(--text-sm); color: var(--text-muted);
}

/* ---------------------------------------------------------------------
   7. Tables
   --------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
}
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: start;
  border-bottom: 1px solid var(--border-soft);
}
.table th {
  font-weight: 650; font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-subtle); white-space: nowrap;
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 2;
}
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------
   8. Progress matrix
   Rows are materials, columns are students. Both header row and the first
   columns stay pinned while scrolling in either direction.
   --------------------------------------------------------------------- */
.matrix-wrap {
  overflow: auto;
  max-height: min(70dvh, 760px);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.matrix { border-collapse: separate; border-spacing: 0; font-size: var(--text-sm); }

.matrix th, .matrix td {
  border-bottom: 1px solid var(--border-soft);
  border-inline-end: 1px solid var(--border-soft);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
}
.matrix thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface-2);
  font-size: var(--text-xs); font-weight: 650;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-subtle);
  vertical-align: bottom;
}
.matrix .col-no    { position: sticky; inset-inline-start: 0;     z-index: 2; width: 56px; text-align: center; color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.matrix .col-title { position: sticky; inset-inline-start: 56px;  z-index: 2; min-width: 240px; }
.matrix thead .col-no, .matrix thead .col-title { z-index: 4; }

/* The pinned columns need a hard edge or content shows through while scrolling */
.matrix .col-title { box-shadow: 1px 0 0 var(--border); }

.matrix .student-col { min-width: 92px; text-align: center; }
.matrix .student-col .name { display: block; font-weight: 650; color: var(--text); text-transform: none; letter-spacing: 0; }
.matrix .student-col .class { display: block; font-size: var(--text-xs); font-weight: 400; color: var(--text-subtle); }

.matrix .group-row td {
  background: var(--surface-3); font-weight: 650;
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted);
}

.matrix .material-title { font-weight: 550; color: var(--text); }
.matrix .material-meta { font-size: var(--text-xs); color: var(--text-subtle); }

/* Status cells — colour-coded, but never colour alone: each state also has
   a distinct glyph, so it reads for colour-blind users too. */
.cell { padding: 0 !important; text-align: center; }
.cell-btn {
  width: 100%; min-height: 40px;
  border: 0; background: transparent; cursor: pointer;
  font-size: var(--text-sm); font-weight: 700;
  display: grid; place-items: center;
  transition: background var(--t-fast);
}
.cell-btn:hover { background: var(--surface-3); }
.cell-none .cell-btn { color: var(--text-subtle); }
.cell-done { background: var(--ok-bg); }
.cell-done .cell-btn { color: var(--ok-fg); }
.cell-not_done { background: var(--bad-bg); }
.cell-not_done .cell-btn { color: var(--bad-fg); }
.cell.is-saving { position: relative; }
.cell.is-saving::after {
  content: ""; position: absolute; inset-block-end: 0; inset-inline: 0; height: 2px;
  background: var(--accent); animation: cell-pulse 900ms var(--ease) infinite;
}
@keyframes cell-pulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
.cell.is-error { box-shadow: inset 0 0 0 2px var(--bad-fg); }

/* ---------------------------------------------------------------------
   9. Badges, pills, avatars
   --------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 650;
  line-height: 1.5; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-ok      { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-line); }
.badge-warn    { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.badge-bad     { background: var(--bad-bg);  color: var(--bad-fg);  border-color: var(--bad-line); }
.badge-info    { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); }
.badge-neutral { background: var(--surface-3); color: var(--text-muted); border-color: var(--border); }

.avatar {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: var(--radius-full);
  background: var(--brand-200); color: var(--ink-900);
  display: grid; place-items: center;
  font-weight: 700; font-size: var(--text-sm);
  text-transform: uppercase;
}
.avatar-sm { width: 30px; height: 30px; flex-basis: 30px; font-size: var(--text-xs); }
.avatar-lg { width: 56px; height: 56px; flex-basis: 56px; font-size: var(--text-lg); }
:root[data-theme="dark"] .avatar { background: var(--brand-700); color: var(--brand-50); }

/* Progress bar */
.bar {
  height: 7px; border-radius: var(--radius-full);
  background: var(--surface-3); overflow: hidden;
}
.bar > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--brand-400), var(--brand-500));
  border-radius: inherit;
  transition: width 500ms var(--ease);
}
.bar-ok > span  { background: linear-gradient(90deg, #4fbf85, var(--ok-fg)); }
.bar-bad > span { background: linear-gradient(90deg, #e8837c, var(--bad-fg)); }

/* ---------------------------------------------------------------------
   10. Alerts and toasts
   --------------------------------------------------------------------- */
.alert {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid; border-inline-start-width: 3px;
  font-size: var(--text-sm);
}
.alert-success { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-line); }
.alert-error   { background: var(--bad-bg);  color: var(--bad-fg);  border-color: var(--bad-line); }
.alert-warning { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.alert-info    { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); }
.alert strong { font-weight: 700; }

.toast-region {
  position: fixed; inset-block-end: var(--sp-4); inset-inline: var(--sp-4);
  z-index: 100; display: flex; flex-direction: column; gap: var(--sp-2);
  pointer-events: none;
}
@media (min-width: 640px) {
  .toast-region { inset-inline: auto var(--sp-6); inset-block-end: var(--sp-6); max-width: 380px; }
}
.toast {
  pointer-events: auto;
  background: var(--ink-900); color: #fff;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm); font-weight: 500;
  display: flex; align-items: center; gap: var(--sp-3);
  animation: toast-in 220ms var(--ease);
}
.toast-success { background: #14603c; }
.toast-error   { background: #93231d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: all 180ms var(--ease); }

/* Empty state */
.empty {
  text-align: center; padding: var(--sp-12) var(--sp-5);
  color: var(--text-muted);
}
.empty-icon {
  width: 48px; height: 48px; margin: 0 auto var(--sp-4);
  border-radius: var(--radius-lg); background: var(--surface-3);
  display: grid; place-items: center; color: var(--text-subtle);
}
.empty h3 { font-size: var(--text-base); color: var(--text); margin-bottom: var(--sp-2); }
.empty p { font-size: var(--text-sm); max-width: 34ch; margin-inline: auto; }

/* ---------------------------------------------------------------------
   11. Modal
   --------------------------------------------------------------------- */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 120;
  display: grid; place-items: center;
  padding: var(--sp-4);
  background: rgba(15,15,17,.55); backdrop-filter: blur(3px);
  animation: fade-in 160ms var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-panel {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  max-height: 88dvh; overflow-y: auto;
  animation: modal-in 200ms var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { padding: var(--sp-5); border-bottom: 1px solid var(--border-soft); }
.modal-body { padding: var(--sp-5); }
.modal-foot {
  padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border-soft);
  display: flex; gap: var(--sp-3); justify-content: flex-end; flex-wrap: wrap;
}

/* ---------------------------------------------------------------------
   12. Filter bar, tabs, pagination
   --------------------------------------------------------------------- */
.filters {
  display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: flex-end;
  padding: var(--sp-4); background: var(--surface-2);
  border: 1px solid var(--border-soft); border-radius: var(--radius-lg);
  margin-bottom: var(--sp-5);
}
.filters .field { margin-bottom: 0; flex: 1 1 170px; min-width: 0; }

.tabs {
  display: flex; gap: var(--sp-1); overflow-x: auto;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: var(--sp-5);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm); font-weight: 600;
  color: var(--text-muted); text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.pagination { display: flex; gap: var(--sp-2); align-items: center; justify-content: center; margin-top: var(--sp-6); }
.pagination a, .pagination span {
  min-width: 38px; height: 38px; padding-inline: var(--sp-2);
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: var(--text-sm); text-decoration: none;
}
.pagination a:hover { background: var(--surface-2); }
.pagination .is-current { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 650; }
.pagination .is-disabled { opacity: .4; pointer-events: none; }

/* ---------------------------------------------------------------------
   13. Material and list items
   --------------------------------------------------------------------- */
.item-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.item {
  display: flex; gap: var(--sp-4); align-items: flex-start;
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  /* An .item is sometimes a whole clickable row. Without this the card would
     arrive underlined, title and meta line both. */
  text-decoration: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.item:hover { border-color: var(--border); box-shadow: var(--shadow-sm); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 650; font-size: var(--text-base); }
.item-meta {
  display: flex; gap: var(--sp-3); flex-wrap: wrap;
  font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--sp-1);
}
.item-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
@media (max-width: 640px) {
  .item { flex-direction: column; }
  .item-actions { width: 100%; }
}

.link-chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 0.3rem 0.65rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs); font-weight: 550;
  text-decoration: none; color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.link-chip:hover { background: var(--brand-50); color: var(--brand-800); border-color: var(--brand-300); }
:root[data-theme="dark"] .link-chip:hover { background: var(--surface-3); color: var(--brand-300); }

/* ---------------------------------------------------------------------
   14. Utilities
   --------------------------------------------------------------------- */
.muted   { color: var(--text-muted); }
.subtle  { color: var(--text-subtle); }
.small   { font-size: var(--text-sm); }
.tiny    { font-size: var(--text-xs); }
.bold    { font-weight: 650; }
.center  { text-align: center; }
.end     { text-align: end; }
.nowrap  { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }

.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-8); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }

.hide { display: none !important; }
@media (max-width: 767px)  { .hide-sm { display: none !important; } }
@media (min-width: 768px)  { .show-sm-only { display: none !important; } }

/* ---------------------------------------------------------------------
   15. Print — teachers print the progress sheet and reports
   --------------------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .filters, .btn, .toast-region, .no-print { display: none !important; }
  .app-main { margin: 0 !important; }
  .page { padding: 0 !important; }
  .card, .matrix-wrap { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; }
  .matrix-wrap { max-height: none !important; overflow: visible !important; }
  body { background: #fff !important; color: #000 !important; font-size: 11pt; }
  a[href]::after { content: ""; }
}
