/* ============================================================
   hub.css — Nudge hub layout & components
   RULE: no hardcoded hex or font-family names live here. Every
   colour / font / radius / shadow / space value is a var() from
   tokens.css. That is what makes the whitelabel swap genuine.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--color-ink);
  background: var(--color-surface);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

h1, h2, h3, .display { font-family: var(--font-display); }

a { color: inherit; text-decoration: none; }

/* ---- Brand wordmark (text comes from the theme) ---- */
.brand {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--color-ink);
  letter-spacing: -0.01em;
  line-height: 1;
}
.brand::before { content: var(--logo-label); }

/* ============================================================
   Top navigation (shared across every page but login)
   ============================================================ */
.nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 60px;
  padding: 0 var(--space-5);
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav .brand { font-size: 21px; }

.nav-links {
  display: flex;
  gap: var(--space-1);
  margin-left: var(--space-5);
}
.nav-link {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--color-ink-soft);
  padding: var(--space-2) 15px;
  border-radius: var(--radius-pill);
}
.nav-link:hover { background: var(--overlay-hover); }
.nav-link.active {
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.search {
  width: 190px;
  height: 36px;
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  color: var(--color-muted);
  font: inherit;
  font-size: 13px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  flex: none;
  border: none;
  cursor: pointer;
}

/* Light/dark toggle — wired automatically by js/color-scheme.js
   (any [data-color-scheme-toggle] element, anywhere in the suite). */
.color-scheme-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex: none;
  cursor: pointer;
}
.color-scheme-btn:hover { background: var(--color-chip); }

/* ============================================================
   Page shell
   ============================================================ */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-7);
}

.page-title {
  font-size: 32px;
  font-weight: 800;
  margin: 0;
  color: var(--color-ink);
}
.page-sub { color: var(--color-ink-soft); margin: var(--space-1) 0 0; }

.section-label {
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
  margin: var(--space-6) 0 var(--space-3);
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: var(--space-5); }

/* App icon tile (ink-filled monogram) */
.tile {
  border-radius: var(--radius-lg);
  background: var(--color-ink-tile);
  color: var(--color-on-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  flex: none;
}
.tile-lg { width: 56px; height: 56px; font-size: 20px; }
.tile-md { width: 44px; height: 44px; font-size: 16px; border-radius: var(--radius-md); }

/* Grid of tool cards */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}
.app-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.app-card h3 { font-size: 16px; margin: var(--space-3) 0 var(--space-1); }
.app-card .desc { font-size: 12.5px; color: var(--color-muted); margin: 0; }

/* ============================================================
   Progress bar (status wears a word — always labelled)
   ============================================================ */
.bar {
  height: 8px;
  background: var(--color-track);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--color-success);
  border-radius: var(--radius-pill);
}

/* ============================================================
   Chips & badges
   ============================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: 11px;
  color: var(--color-ink-soft);
  background: var(--color-chip);
  padding: 3px 9px;
  border-radius: var(--radius-pill);
}
.chip-streak {
  color: var(--color-highlight-ink);
  background: var(--color-highlight-soft);
  border: 1px solid var(--color-highlight-border);
  font-size: 13px;
  padding: 7px 14px;
}
.chip-streak .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--color-highlight);
}
.chip-risk {
  color: var(--color-on-primary);
  background: var(--color-warn);
}
.chip-ok { color: var(--color-on-primary); background: var(--color-success); }

/* ============================================================
   Buttons — one action, one colour
   ============================================================ */
.btn {
  /* inline-block (not the plain "inline" an <a>/<span> defaults to) so vertical
     padding always reserves its own space — plain inline padding doesn't affect
     line-box height, so it visually overlaps whatever's above it. Real <button>
     elements are inline-block by default already; this just makes anchor/span
     buttons behave identically instead of silently overlapping. */
  display: inline-block;
  text-align: center;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-pill);
  padding: 12px 22px;
  min-height: 44px;
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: var(--shadow-primary);
}
.btn-ghost {
  background: transparent;
  color: var(--color-ink-soft);
  border: 1px solid var(--color-border);
}
/* display:block (not inline-block) so width:100% actually applies — width has
   no effect on inline/inline-block boxes whose content determines their size
   otherwise; block-level is what "100%" needs to mean here. */
.btn-block { display: block; width: 100%; }

/* ============================================================
   Forms
   ============================================================ */
.field { text-align: left; margin-bottom: var(--space-4); }
.field label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--color-ink);
  margin-bottom: 7px;
}
.input {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-card);
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--color-ink);
}
.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--overlay-focus);
}
.field-hint { font-size: 12px; color: var(--color-muted); margin-top: 6px; }
.input-error { border-color: var(--color-warn); }

/* Segmented role / option toggle */
.segment {
  display: flex;
  gap: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: var(--space-1);
  border-radius: 14px;
}
.segment button {
  flex: 1;
  padding: 11px;
  border: none;
  cursor: pointer;
  border-radius: 10px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  color: var(--color-ink-soft);
  background: transparent;
}
.segment button.active {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

/* ============================================================
   Login screen
   ============================================================ */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-7);
  background: var(--color-surface);
}
.auth-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-float);
  padding: var(--space-7) 40px;
  width: 420px;
  max-width: 100%;
  text-align: center;
}
.auth-card .brand { font-size: 40px; display: inline-block; }

/* ============================================================
   Roster table (teacher progress view)
   ============================================================ */
.table-wrap { overflow-x: auto; }
table.roster {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
table.roster th,
table.roster td {
  text-align: center;
  padding: 12px 10px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13.5px;
}
table.roster th {
  color: var(--color-muted);
  font-weight: 600;
  font-size: 12px;
}
table.roster td:first-child,
table.roster th:first-child { text-align: left; }

/* ============================================================
   Utilities
   ============================================================ */
.row { display: flex; align-items: center; gap: var(--space-4); }
.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: var(--space-3); }
.muted { color: var(--color-muted); }
.center { text-align: center; }

/* Stat tiles (dashboard quick stats) */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.stat {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
}
.stat .num { font-family: var(--font-display); font-weight: 800; font-size: 26px; }
.stat .lbl { color: var(--color-muted); font-size: 13px; }

/* ============================================================
   Responsive — collapse to mobile
   ============================================================ */
@media (max-width: 760px) {
  .page { padding: var(--space-5) var(--space-4); }
  .grid, .stats, .split { grid-template-columns: 1fr; }
  .search { display: none; }
  .nav { padding: 0 var(--space-4); }
  /* The old horizontally-scrolling nav-links row didn't reliably scroll (a
     flex child needs min-width:0 to actually shrink/scroll instead of just
     overflowing) — replaced below by the hamburger drawer or bottom tab bar,
     whichever js/mobile-nav.js has picked from the user's own device setting. */
  .nav-links { display: none; }
  .page-title { font-size: 26px; }
  .lb-name { width: 88px; }
}

/* ============================================================
   Mobile navigation — hamburger drawer OR bottom tab bar (iOS-style).
   A personal, per-device preference (localStorage only — NOT part of the
   school-wide nudgeSettings doc, since one teacher's phone-vs-tablet choice
   has no business syncing to the whole school), set in Settings and applied
   by js/mobile-nav.js via a data-mobile-nav attribute on <body>. Desktop
   (>760px) is untouched either way — the classic top nav-links row is what
   renders there, exactly as before.
   ============================================================ */
.hamburger-btn {
  display: none;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  border: none; background: transparent;
  color: var(--color-ink);
  font-size: 20px;
  cursor: pointer;
  margin-left: var(--space-2);
}
@media (max-width: 760px) {
  body[data-mobile-nav="hamburger"] .hamburger-btn { display: flex; }
}

.mobile-drawer-backdrop, .more-sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.mobile-drawer-backdrop { z-index: 90; }
.more-sheet-backdrop { z-index: 92; }
.mobile-drawer-backdrop.open, .more-sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.mobile-drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(280px, 80vw);
  background: var(--color-card);
  z-index: 91;
  box-shadow: 8px 0 24px -8px rgba(0,0,0,.25);
  transform: translateX(-100%);
  transition: transform .22s ease;
  display: flex; flex-direction: column;
  padding: var(--space-5) var(--space-3);
  padding-top: calc(var(--space-5) + env(safe-area-inset-top, 0px));
  overflow-y: auto;
}
.mobile-drawer.open { transform: translateX(0); }
.mobile-drawer .brand { font-size: 21px; padding: 0 var(--space-3); margin-bottom: var(--space-4); display: block; }

.mobile-drawer-link, .more-sheet-link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3); border-radius: var(--radius-md);
  font-weight: 600; font-size: 15px; color: var(--color-ink-soft);
}
.mobile-drawer-link .icon, .more-sheet-link .icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.mobile-drawer-link.active, .more-sheet-link.active { color: var(--color-primary); background: var(--color-primary-soft); }

.bottom-nav {
  display: none;
  position: fixed; left: var(--space-3); right: var(--space-3); bottom: var(--space-3);
  z-index: 90;
  align-items: center;
  background: color-mix(in srgb, var(--color-card) 88%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 28px -8px rgba(0,0,0,.22);
  padding: 6px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
}
@media (max-width: 760px) {
  body[data-mobile-nav="bottom"] .bottom-nav { display: flex; }
  /* Room so page content never sits behind the fixed bar. */
  body[data-mobile-nav="bottom"] .page { padding-bottom: calc(var(--space-6) + 66px + env(safe-area-inset-bottom, 0px)); }
}
.bottom-nav-tabs { display: flex; flex: 1; }
.bottom-nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px; border-radius: var(--radius-lg);
  color: var(--color-muted); background: none; border: none; cursor: pointer;
  font-family: var(--font-body); font-size: 10.5px; font-weight: 600;
}
.bottom-nav-tab .icon { font-size: 20px; line-height: 1; }
.bottom-nav-tab.active { color: var(--color-primary); background: var(--color-primary-soft); }

.more-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--color-card);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 93;
  padding: var(--space-5) var(--space-4);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform .22s ease;
}
.more-sheet.open { transform: translateY(0); }

/* ============================================================
   M7 polish + Settings + Class-competition viz
   ============================================================ */

/* Responsive two-column that actually collapses (an inline
   grid-template-columns beats the media query — use this class). */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  align-items: start;
}

/* Empty states */
.empty {
  text-align: center;
  color: var(--color-muted);
  padding: var(--space-6) var(--space-4);
}

/* Toggle switch (settings restrictions) */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}
.switch-row:last-child { border-bottom: none; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0; background: var(--color-track);
  border-radius: var(--radius-pill); transition: background .15s;
}
.switch .knob {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--color-card);
  box-shadow: var(--shadow-card); transition: transform .15s;
}
.switch input:checked + .track { background: var(--color-success); }
.switch input:checked + .track + .knob { transform: translateX(18px); }

/* Restricted app card (teacher sees it greyed with a badge; students don't see it) */
.app-card.is-disabled { opacity: .5; }
.badge-off {
  display: inline-block; font-size: 11px; font-weight: 600;
  color: var(--color-ink-soft); background: var(--color-chip);
  padding: 2px 8px; border-radius: var(--radius-pill); margin-left: var(--space-2);
}

/* Podium (top 3) */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: var(--space-3); }
.podium .place { text-align: center; flex: 1; max-width: 150px; }
.podium .col {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: var(--space-2); color: var(--color-ink);
  font-family: var(--font-display); font-weight: 800; font-size: 22px;
}
.podium .p1 .col { background: var(--medal-gold);   height: 118px; }
.podium .p2 .col { background: var(--medal-silver); height: 90px; }
.podium .p3 .col { background: var(--medal-bronze); height: 68px; }
.podium .who { font-weight: 700; margin-top: var(--space-2); }
.podium .pts { color: var(--color-muted); font-size: 13px; }

/* Leaderboard (single-series bars, ranked) */
.lb { display: flex; flex-direction: column; gap: var(--space-2); }
.lb-row { display: flex; align-items: center; gap: var(--space-3); }
.lb-row.is-you .lb-name { color: var(--color-primary); }
.lb-rank { width: 26px; text-align: center; font-family: var(--font-display); font-weight: 800; color: var(--color-ink-soft); flex: none; }
.lb-name { width: 120px; flex: none; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-bar { flex: 1; height: 22px; background: var(--color-track); border-radius: var(--radius-pill); overflow: hidden; }
.lb-bar > span { display: block; height: 100%; background: var(--color-primary); border-radius: var(--radius-pill); }
.lb-pts { width: 60px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; flex: none; }

/* Heatmap (sequential single-hue; cell colors set inline from the ramp) */
.heat { border-collapse: separate; border-spacing: 3px; width: 100%; }
.heat th { font-size: 11px; color: var(--color-muted); font-weight: 600; padding: 4px 2px; }
.heat td.name { text-align: left; font-weight: 600; font-size: 13px; white-space: nowrap; padding-right: 8px; }
.heat td.cell { text-align: center; font-size: 12px; font-weight: 600; border-radius: 8px; height: 34px; }
