/* ==========================================================================
   Theme tokens: every colour lives here so light/dark is one attribute swap.
   Chart.js reads these same variables in app.js.
   ========================================================================== */
:root,
[data-theme='light'] {
  --hero: url('img/hero-light.webp');
  --hero-sm: url('img/hero-light-960.webp');
  --hero-bg: #eef2f8;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e3e8f2;
  --text: #0f172a;
  --text-muted: #5b6478;
  --accent: #2f5bea;
  --accent-soft: rgba(47, 91, 234, 0.12);
  --accent-2: #0ea5a4;
  --good: #12925f;
  --warn: #c27803;
  --bad: #d23b3b;
  --grid: rgba(15, 23, 42, 0.07);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --glow: none;
  color-scheme: light;
}

[data-theme='dark'] {
  --hero: url('img/hero-dark.webp');
  --hero-sm: url('img/hero-dark-960.webp');
  --hero-bg: #030817;
  --bg: #070b16;
  --surface: #0f1628;
  --surface-2: #151e35;
  --border: #1f2a45;
  --text: #e8edf9;
  --text-muted: #8d98b4;
  --accent: #6d8cff;
  --accent-soft: rgba(109, 140, 255, 0.16);
  --accent-2: #2dd4bf;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --grid: rgba(232, 237, 249, 0.07);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
  --glow: 0 0 0 1px rgba(109, 140, 255, 0.08), 0 0 32px rgba(109, 140, 255, 0.08);
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

[data-theme='dark'] body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(109, 140, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(45, 212, 191, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

h1, h2, p { margin: 0; }
a { color: var(--accent); }

.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; left: 1rem; top: -3rem; z-index: 10;
  background: var(--accent); color: #fff; padding: 0.5rem 1rem; border-radius: 8px;
}
.skip-link:focus { top: 1rem; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Icons (Lucide, swapped in from <i data-lucide>) ---------- */
.icon { width: 1em; height: 1em; flex-shrink: 0; stroke-width: 2; vertical-align: -0.125em; }
.card h2 { display: flex; align-items: center; gap: 0.5rem; }
.card h2 .icon {
  width: 30px; height: 30px; padding: 6px; border-radius: 9px;
  color: var(--accent); background: var(--accent-soft);
}
.field > span { display: inline-flex; align-items: center; gap: 0.3rem; }
.footer p .icon { margin-right: 0.4rem; }
.kpi-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.kpi-icon { width: 34px; height: 34px; padding: 8px; border-radius: 10px; color: var(--accent); background: var(--accent-soft); }
.insight-icon .icon { width: 17px; height: 17px; }
.delta .icon { width: 13px; height: 13px; }
.funnel-level .icon { width: 12px; height: 12px; vertical-align: -0.15em; }

/* ---------- Top bar ---------- */
.topbar {
  max-width: 1320px; margin: 0 auto; padding: 2rem 1.5rem 1rem;
  display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: flex-end; justify-content: space-between;
}
.brand { display: flex; gap: 0.9rem; align-items: center; }
.brand-logo { width: 44px; height: 44px; border-radius: 11px; box-shadow: var(--glow); display: block; }
.brand-name { font-weight: 800; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.78rem; color: var(--text-muted); }
.eyebrow { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
h1 { font-size: clamp(1.9rem, 3.6vw, 2.9rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; margin: 0.35rem 0 0.6rem; }

.controls { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.field { display: grid; gap: 0.25rem; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }
.field select {
  font: inherit; font-size: 0.9rem; font-weight: 500; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.55rem 2.2rem 0.55rem 0.8rem; min-width: 10rem; cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* ---------- Theme switch ---------- */
.theme-toggle { background: none; border: 0; padding: 0; cursor: pointer; margin-bottom: 2px; }
.toggle-track {
  display: block; width: 64px; height: 34px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); position: relative;
  transition: background-color 0.3s ease;
}
.toggle-thumb {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  display: grid; place-items: center; transition: transform 0.3s cubic-bezier(0.4, 0.2, 0.2, 1.3);
}
.toggle-thumb .icon { width: 16px; height: 16px; color: var(--warn); position: absolute; transition: opacity 0.2s; }
.icon-moon { opacity: 0; color: var(--accent) !important; }
[data-theme='dark'] .toggle-track { background: var(--accent-soft); }
[data-theme='dark'] .toggle-thumb { transform: translateX(30px); }
[data-theme='dark'] .icon-sun { opacity: 0; }
[data-theme='dark'] .icon-moon { opacity: 1; }

/* ---------- Layout ---------- */
main { max-width: 1320px; margin: 0 auto; padding: 0 1.5rem 2rem; }
/* ---------- Hero banner (image swaps with the theme) ---------- */
.hero {
  position: relative; overflow: hidden; margin-bottom: 1.25rem;
  aspect-ratio: 3 / 1; min-height: 260px;
  display: flex; align-items: center;
  border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow), var(--glow);
  background: var(--hero-bg) var(--hero) right center / cover no-repeat;
  transition: background-color 0.3s ease;
}
.hero-copy { position: relative; max-width: 36%; padding: 2rem 2.25rem; }
.hero-lead { color: var(--text-muted); font-size: 1rem; max-width: 34ch; }
.context {
  display: inline-block; margin-top: 1rem; padding: 0.35rem 0.75rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 500; color: var(--text-muted);
  background: color-mix(in srgb, var(--surface) 70%, transparent); border: 1px solid var(--border);
  backdrop-filter: blur(6px);
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow), var(--glow); padding: 1.25rem 1.35rem;
  transition: background-color 0.3s ease, border-color 0.3s ease;
  min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.card h2 { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.card-head p { font-size: 0.8rem; color: var(--text-muted); }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1.25rem; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }

.chart-wrap { position: relative; height: 300px; }
.chart-wrap.tall { height: 320px; }
.chart-wrap.units { height: 380px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1.25rem; margin-bottom: 1.25rem; }
.kpi { position: relative; overflow: hidden; }
.kpi::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: linear-gradient(var(--accent), var(--accent-2));
}
.kpi-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.kpi-value { font-size: clamp(1.6rem, 2.4vw, 2.1rem); font-weight: 800; letter-spacing: -0.03em; margin: 0.25rem 0 0.4rem; font-variant-numeric: tabular-nums; }
.delta { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.78rem; font-weight: 600; padding: 0.15rem 0.5rem; border-radius: 999px; }
.delta.up { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.delta.down { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.delta-note { font-size: 0.75rem; color: var(--text-muted); margin-left: 0.35rem; }

/* ---------- Insights ---------- */
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.insights li {
  display: grid; grid-template-columns: 32px 1fr; gap: 0.75rem; align-items: start;
  padding: 0.8rem; border-radius: 12px; background: var(--surface-2); font-size: 0.88rem;
}
.insight-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-size: 1rem; }
.insight-icon.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.insight-icon.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.insight-icon.info { background: var(--accent-soft); color: var(--accent); }
.insights strong { font-weight: 700; }

/* ---------- Funnel ---------- */
.funnel { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; }
.funnel li { display: grid; gap: 0.35rem; }
.funnel-top { display: flex; justify-content: space-between; font-size: 0.85rem; gap: 1rem; }
.funnel-top span:first-child { font-weight: 600; }
.funnel-top span:last-child { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.funnel-level { display: inline-block; font-size: 0.7rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 0.05rem 0.4rem; border-radius: 6px; margin-right: 0.4rem; }
.funnel-bar { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.funnel-fill {
  height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.funnel-value {
  margin-top: 0.4rem; padding: 0.9rem; border-radius: 12px; background: var(--accent-soft);
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; font-size: 0.85rem;
}
.funnel-value strong { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; }

/* ---------- Table ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap;
  font: inherit; font-size: 0.8rem; font-weight: 600; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 0.45rem 0.75rem; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn .icon { width: 15px; height: 15px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
th, td { padding: 0.6rem 0.5rem; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
tbody th { font-weight: 400; }
thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 700; }
th button {
  font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit;
  background: none; border: 0; padding: 0; cursor: pointer;
}
th button::after { content: ' ↕'; opacity: 0.35; }
th[aria-sort='ascending'] button::after { content: ' ↑'; opacity: 1; }
th[aria-sort='descending'] button::after { content: ' ↓'; opacity: 1; }
tbody tr:hover { background: var(--surface-2); }
.prog-name { font-weight: 600; }
.prog-dept { display: block; font-size: 0.72rem; color: var(--text-muted); font-weight: 500; }
.prog-dept { max-width: 15rem; overflow: hidden; text-overflow: ellipsis; }
.stream {
  display: inline-block; margin-left: 0.35rem; padding: 0 0.4rem; border-radius: 6px;
  font-size: 0.68rem; font-weight: 600; color: var(--accent); background: var(--accent-soft); vertical-align: 1px;
}
.funnel-note { display: block; margin-top: 0.2rem; font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.pill { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-weight: 700; font-size: 0.78rem; }
.pill.good { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.empty { text-align: center; color: var(--text-muted); padding: 2rem; }

/* ---------- Method + footer ---------- */
.method { margin-top: 1.25rem; }
.method h2 { margin-bottom: 0.75rem; }
.method-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; font-size: 0.85rem; color: var(--text-muted); }
.method strong { color: var(--text); }

.footer {
  max-width: 1320px; margin: 0 auto; padding: 1rem 1.5rem 2.5rem;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem;
  font-size: 0.8rem; color: var(--text-muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .hero-copy { max-width: 44%; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
}
@media (max-width: 720px) {
  /* Stack: text on top, illustration below */
  .hero {
    aspect-ratio: auto; min-height: 0; display: block;
    background-image: var(--hero-sm); background-size: 128% auto; background-position: 88% 100%;
    padding-bottom: 42vw;
  }
  .hero-copy { max-width: none; padding: 1.5rem 1.25rem 0; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .method-grid { grid-template-columns: 1fr; }
  .controls { width: 100%; }
  .field { flex: 1; }
  .field select { min-width: 0; width: 100%; }
}
@media (max-width: 420px) {
  .kpis { grid-template-columns: 1fr; }
}

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