/* ==========================================================================
   RoiSpends design system
   Ported from the brand token source (brand/identity.md, lib/tokens.ts).
   Hand-authored CSS rather than Tailwind so the Django project needs no
   Node build step — the token values are identical to the previous build.
   ========================================================================== */

:root {
  --bg: #000000;
  --bg-1: #0a0a0a;
  --bg-2: #111111;
  --bg-3: #1a1a1a;
  --fg: #ededed;
  --fg-dim: #a1a1a1;
  --fg-mute: #8a8a8a;   /* was #666666 — 3.66:1 on --bg, below the WCAG AA 4.5:1
                            floor for normal text (Lighthouse flagged 29 elements
                            on the homepage alone). #8a8a8a clears AA on every
                            surface: 6.08:1 on --bg, 5.04:1 on --bg-3. */
  --line: #1a1a1a;
  --acid: #c6ff00;
  --acid-dim: #8fb700;
  --magenta: #ff2d6f;
  --cyan: #00e5ff;

  --hairline: color-mix(in srgb, var(--fg) 8%, transparent);

  --font-sans: "Geist Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "JetBrains Mono", "SF Mono", monospace;

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --container: 1480px;
  --gutter: 1.5rem;
  --section-y: 8rem;
}

@media (min-width: 768px) {
  :root { --gutter: 2.5rem; --section-y: 11rem; }
}

/* The brand is dark-first and committed to it — no light-mode inversion. */
* { box-sizing: border-box; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  overscroll-behavior: none;
}

::selection { background: var(--acid); color: var(--bg); }

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

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

*:focus { outline: none; }
*:focus-visible { outline: 2px solid var(--acid); outline-offset: 2px; border-radius: 2px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 0; }

/* --------------------------------------------------------------- layout */

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.section { padding-block: var(--section-y); }
.section--tight { padding-block: calc(var(--section-y) * 0.55); }

.stack > * + * { margin-top: 1rem; }
.stack-lg > * + * { margin-top: 2rem; }

.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.hairline { border: 1px solid var(--hairline); }
.border-t { border-top: 1px solid var(--hairline); }
.border-b { border-bottom: 1px solid var(--hairline); }

/* ------------------------------------------------------------ typography */

h1, h2, h3, h4 { margin: 0; font-weight: 500; text-wrap: balance; }

.display {
  font-family: var(--font-mono);
  font-size: clamp(2.6rem, 9vw, 7.5rem);
  line-height: 0.88;
  letter-spacing: -0.04em;
}

h1, .h1 {
  font-family: var(--font-mono);
  font-size: clamp(2.4rem, 6vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
}

h2, .h2 {
  font-family: var(--font-mono);
  font-size: clamp(1.9rem, 4vw, 3.2rem);
  line-height: 1;
  letter-spacing: -0.03em;
}

h3, .h3 {
  font-family: var(--font-mono);
  font-size: clamp(1.3rem, 2.2vw, 1.75rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

p { margin: 0 0 1rem; text-wrap: pretty; }
p:last-child { margin-bottom: 0; }

.lead { font-size: 1.125rem; line-height: 1.6; color: var(--fg-dim); }
.dim { color: var(--fg-dim); }
.mute { color: var(--fg-mute); }
.acid { color: var(--acid); }
.magenta { color: var(--magenta); }
.mono { font-family: var(--font-mono); }

.label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-dim);
  display: block;
}

.measure { max-width: 68ch; }
.measure-sm { max-width: 52ch; }

/* --------------------------------------------------------------- brand */

.wordmark {
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: -0.02em;
  font-size: 1.0625rem;
  color: var(--fg);
}
.wordmark .dot { color: var(--acid); }

.mark {
  display: inline-grid;
  place-items: center;
  width: 28px; height: 28px;
  background: var(--acid);
  color: #000;
  border-radius: 5.6px;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: -2px;
  font-size: 1rem;
}

/* -------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1.4rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.btn:hover { background: var(--bg-2); border-color: color-mix(in srgb, var(--fg) 16%, transparent); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--acid); color: #000; border-color: var(--acid); font-weight: 500; }
.btn-primary:hover { background: #d4ff33; border-color: #d4ff33; color: #000; }

.btn-ghost { border-color: transparent; color: var(--fg-dim); }
.btn-ghost:hover { color: var(--fg); background: var(--bg-1); }

.btn-sm { padding: 0.5rem 0.9rem; font-size: 0.75rem; }
.btn-danger { color: var(--magenta); border-color: color-mix(in srgb, var(--magenta) 30%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--magenta) 12%, transparent); }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--bg-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 1.75rem;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.card:hover { background: var(--bg-2); border-color: color-mix(in srgb, var(--fg) 14%, transparent); }

a.card:hover { transform: translateY(-2px); }

.card-flat { background: var(--bg-1); border: 1px solid var(--hairline); border-radius: var(--radius-md); padding: 1.5rem; }
.card-flat:hover { background: var(--bg-1); }

.card__icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--acid);
  margin-bottom: 1rem;
}

.glow-acid {
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--acid) 35%, transparent),
    0 0 40px -10px color-mix(in srgb, var(--acid) 60%, transparent);
}

/* ----------------------------------------------------------------- nav */

.nav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--hairline);
}

.nav__bar { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 1.5rem; }
.nav__links { display: none; align-items: center; gap: 1.75rem; }

@media (min-width: 1024px) { .nav__links { display: flex; } }

.nav__link {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--fg-dim);
  transition: color 0.18s ease;
  position: relative;
}
.nav__link:hover, .nav__link[aria-current="page"] { color: var(--fg); }
.nav__link[aria-current="page"]::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px;
  height: 1px; background: var(--acid);
}

/* Dropdown built on <details> so it works without JavaScript. */
.dropdown { position: relative; }
.dropdown > summary {
  list-style: none; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.8125rem; color: var(--fg-dim);
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown[open] > summary { color: var(--fg); }
.dropdown__panel {
  position: absolute; top: calc(100% + 14px); left: 50%; transform: translateX(-50%);
  min-width: 560px; max-width: 92vw;
  background: var(--bg-1); border: 1px solid var(--hairline);
  border-radius: var(--radius-md); padding: 1.25rem;
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,0.9);
}
.dropdown__item { padding: 0.6rem 0.75rem; border-radius: var(--radius-sm); display: block; }
.dropdown__item:hover { background: var(--bg-3); }
.dropdown__item strong { display: block; font-family: var(--font-mono); font-size: 0.8125rem; font-weight: 500; }
.dropdown__item span { display: block; font-size: 0.75rem; color: var(--fg-mute); margin-top: 0.15rem; }

@media (max-width: 1023px) { .dropdown__panel { min-width: min(92vw, 420px); grid-template-columns: 1fr; } }

.nav__announce {
  border-bottom: 1px solid var(--hairline);
  font-family: var(--font-mono); font-size: 0.6875rem;
  letter-spacing: 0.14em; text-transform: uppercase;
  /* --fg-dim, not --fg-mute: .nav is 82% opaque, so this 11px text composites
     over whatever scrolls beneath it. --fg-mute held 6.08:1 over the black page
     but fell to 4.12:1 when an acid button or light element passed behind —
     under the AA 4.5:1 floor, and invisible to Lighthouse, which scored the page
     100 with the fault live. --fg-dim holds 5.51:1 in that worst case, and is
     already the colour .nav__link and .dropdown > summary use. */
  color: var(--fg-dim); padding: 0.55rem 0; text-align: center;
}
.nav__announce .dot-live {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--acid); margin-right: 0.5rem; vertical-align: middle;
  animation: blink 1.4s ease-in-out infinite;
}

@keyframes blink { 50% { opacity: 0.25; } }

/* -------------------------------------------------------------- footer */

.footer { border-top: 1px solid var(--hairline); padding-block: 4rem 2.5rem; margin-top: 4rem; }
.footer__grid { display: grid; gap: 2.5rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.footer__col h2 { font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--fg-mute); margin-bottom: 1rem; font-weight: 400; }
.footer__col a { display: block; font-size: 0.875rem; color: var(--fg-dim); padding-block: 0.3rem; }
.footer__col a:hover { color: var(--acid); }
.footer__bottom { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--hairline); font-size: 0.75rem; color: var(--fg-mute); }

/* ---------------------------------------------------------------- hero */

.hero { padding-block: clamp(5rem, 14vh, 9rem) var(--section-y); position: relative; overflow: hidden; }
.hero__mesh {
  position: absolute; inset: -20% -10% auto -10%; height: 620px; pointer-events: none;
  background:
    radial-gradient(closest-side, color-mix(in srgb, var(--acid) 13%, transparent), transparent) 18% 30% / 55% 75% no-repeat,
    radial-gradient(closest-side, color-mix(in srgb, var(--cyan) 9%, transparent), transparent) 78% 20% / 45% 60% no-repeat;
  filter: blur(30px);
  opacity: 0.75;
}
.hero__inner { position: relative; }

/* --------------------------------------------------------------- stats */

.stat { border-left: 1px solid var(--hairline); padding-left: 1.25rem; }
.stat__value { font-family: var(--font-mono); font-size: clamp(1.75rem, 3.4vw, 2.75rem); letter-spacing: -0.03em; line-height: 1; }
.stat__label { margin-top: 0.5rem; font-size: 0.75rem; color: var(--fg-mute); }

/* --------------------------------------------------------------- table */

.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th, .table td { text-align: left; padding: 0.85rem 1rem; border-bottom: 1px solid var(--hairline); }
.table th {
  font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--fg-mute); font-weight: 400;
}
.table td.num, .table th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--bg-1); }
.table-wrap { overflow-x: auto; border: 1px solid var(--hairline); border-radius: var(--radius-md); }

/* -------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.22rem 0.6rem; border-radius: 999px;
  font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: 0.06em;
  border: 1px solid var(--hairline); color: var(--fg-dim);
}
.badge--acid { color: var(--acid); border-color: color-mix(in srgb, var(--acid) 32%, transparent); background: color-mix(in srgb, var(--acid) 8%, transparent); }
.badge--magenta { color: var(--magenta); border-color: color-mix(in srgb, var(--magenta) 32%, transparent); background: color-mix(in srgb, var(--magenta) 8%, transparent); }
.badge--cyan { color: var(--cyan); border-color: color-mix(in srgb, var(--cyan) 30%, transparent); }
.badge--mute { color: var(--fg-mute); }

/* Severity mapping for optimizer findings. */
.sev-critical { color: var(--magenta); border-color: color-mix(in srgb, var(--magenta) 40%, transparent); }
.sev-high { color: #ff9d3d; border-color: color-mix(in srgb, #ff9d3d 35%, transparent); }
.sev-medium { color: var(--acid); border-color: color-mix(in srgb, var(--acid) 30%, transparent); }
.sev-low, .sev-info { color: var(--fg-mute); }

/* --------------------------------------------------------------- forms */

.field { display: block; margin-bottom: 1.25rem; }
.field > label,
.field > .field__legend {
  display: block; font-family: var(--font-mono); font-size: 0.6875rem;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--fg-dim); margin-bottom: 0.5rem;
}

input[type="text"], input[type="email"], input[type="url"], input[type="password"],
input[type="number"], select, textarea {
  width: 100%;
  background: var(--bg-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  padding: 0.8rem 0.9rem;
  transition: border-color 0.18s ease, background 0.18s ease;
}
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--fg) 16%, transparent); }
input:focus, select:focus, textarea:focus { border-color: var(--acid); background: var(--bg-2); }
input::placeholder, textarea::placeholder { color: var(--fg-mute); }
textarea { resize: vertical; min-height: 120px; }

/* Django renders CheckboxSelectMultiple as a <div> containing one <div> per
   choice, so the grid is applied to that inner wrapper rather than to labels. */
.checkbox-grid > div { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.6rem 1rem; }
.checkbox-grid > div > div { display: flex; align-items: center; gap: 0.55rem; }
.checkbox-grid label { font-size: 0.875rem; color: var(--fg-dim); cursor: pointer; margin: 0; }
.checkbox-grid input { width: auto; margin: 0; accent-color: var(--acid); flex: none; }

.field--inline { display: flex; align-items: center; gap: 0.6rem; }
.field--inline > label {
  margin: 0; text-transform: none; letter-spacing: normal;
  font-family: var(--font-sans); font-size: 0.875rem; color: var(--fg-dim); cursor: pointer;
}
.field--inline input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--acid); }

.helptext { font-size: 0.75rem; color: var(--fg-mute); margin-top: 0.4rem; }
.helptext a { color: var(--fg-dim); text-decoration: underline; text-underline-offset: 2px; }
.errorlist { list-style: none; padding: 0; margin: 0.5rem 0 0; color: var(--magenta); font-size: 0.8125rem; }

.form-narrow { max-width: 620px; }

/* ------------------------------------------------------------- messages */

.messages { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.messages li {
  padding: 0.85rem 1.1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--hairline); background: var(--bg-1);
  font-size: 0.875rem; margin-bottom: 0.5rem;
}
.messages li.success { border-color: color-mix(in srgb, var(--acid) 35%, transparent); color: var(--acid); }
.messages li.error { border-color: color-mix(in srgb, var(--magenta) 35%, transparent); color: var(--magenta); }

/* ---------------------------------------------------------- app shell */

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
@media (max-width: 900px) { .app-shell { grid-template-columns: 1fr; } }

.app-side {
  border-right: 1px solid var(--hairline);
  padding: 1.5rem 1rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
@media (max-width: 900px) { .app-side { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--hairline); } }

.app-side__link {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.7rem; border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 0.8125rem; color: var(--fg-dim);
}
.app-side__link:hover { background: var(--bg-1); color: var(--fg); }
.app-side__link[aria-current="page"] { background: var(--bg-2); color: var(--acid); }

.app-main { padding: 2rem var(--gutter) 5rem; min-width: 0; }

.org-switcher {
  width: 100%; margin-bottom: 1.5rem;
  background: var(--bg-1); border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); padding: 0.6rem 0.7rem;
  font-family: var(--font-mono); font-size: 0.8125rem; color: var(--fg);
}

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--hairline); border: 1px solid var(--hairline); border-radius: var(--radius-md); overflow: hidden; }
.kpi { background: var(--bg); padding: 1.25rem; }
.kpi__label { font-family: var(--font-mono); font-size: 0.625rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--fg-mute); }
.kpi__value { font-family: var(--font-mono); font-size: 1.75rem; letter-spacing: -0.02em; margin-top: 0.5rem; font-variant-numeric: tabular-nums; }
.kpi__value.unavailable { color: var(--fg-mute); font-size: 1rem; letter-spacing: 0.02em; }
.kpi__note { font-size: 0.6875rem; color: var(--fg-mute); margin-top: 0.35rem; }

/* Empty states */
.empty { text-align: center; padding: 4rem 1.5rem; border: 1px dashed var(--hairline); border-radius: var(--radius-md); }
.empty h2, .empty h3 { margin-bottom: 0.75rem; }

/* ------------------------------------------------------------ prose */

.prose { max-width: 72ch; }
.prose h2 { margin-top: 3rem; margin-bottom: 1rem; }
.prose h3 { margin-top: 2rem; margin-bottom: 0.75rem; }
.prose p, .prose li { color: var(--fg-dim); }
.prose ul, .prose ol { padding-left: 1.25rem; }
.prose li { margin-bottom: 0.5rem; }
.prose a { color: var(--acid); text-decoration: underline; text-underline-offset: 3px; }
.prose blockquote {
  margin: 2rem 0; padding-left: 1.25rem;
  border-left: 2px solid var(--acid); color: var(--fg); font-size: 1.0625rem;
}
.prose code { font-family: var(--font-mono); font-size: 0.875em; background: var(--bg-2); padding: 0.15em 0.4em; border-radius: var(--radius-xs); }

/* ---------------------------------------------------------- utilities */

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 1rem; top: 1rem; z-index: 200; background: var(--acid); color: #000; padding: 0.6rem 1rem; border-radius: var(--radius-sm); }

.tabular { font-variant-numeric: tabular-nums; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; } .mt-4 { margin-top: 2rem; } .mt-6 { margin-top: 3rem; }
.mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; } .mb-4 { margin-bottom: 2rem; }
.hide-sm { display: none; }
@media (min-width: 768px) { .hide-sm { display: revert; } }

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