/* ════════════════════════════════════════════════════════════════
   SQP True Score Analyzer · orellana. brand skin
   Dark-first: Midnight Black ground, ivory text, Amazon Ember accents.
   Design tokens come from design/styles.css (linked first in index.html).
   ════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;

  /* ── Grounds ──────────────────────────────────────────────── */
  --page: var(--ink-900);          /* #0B0B0B Midnight Black */
  --surface-1: var(--ink-850);     /* #131313 panel */
  --surface-2: #1A1A1A;            /* nested / inset surface */
  --surface-raised: var(--ink-800);/* #1E1E1E hover + active */

  /* ── Ink on dark ──────────────────────────────────────────── */
  --text-primary: var(--white);
  --text-secondary: var(--text-on-dark-muted);   /* rgba(243,238,227,.66) */
  --text-faint: rgba(243, 238, 227, 0.42);

  /* ── Lines ────────────────────────────────────────────────── */
  --border: var(--border-on-dark);               /* rgba(243,238,227,.14) */
  --border-strong: rgba(243, 238, 227, 0.24);
  --gridline: rgba(243, 238, 227, 0.09);
  --baseline: rgba(243, 238, 227, 0.22);

  /* ── Chart series (validated against the #131313 panel) ───── */
  --series-1: #3987e5;             /* blue, cumulative / magnitude */
  --series-2: var(--ember-pressed);/* #E85A0A per-rank bars; passes dark band */

  /* Ordinal funnel ramp, light to dark, validated --ordinal on #131313 */
  --stage-1: #cde2fb;
  --stage-2: #86b6ef;
  --stage-3: #3987e5;
  --stage-4: #184f95;
  --stage-early: rgba(243, 238, 227, 0.30);

  /* ── Rate badge status (small text, all ≥4.5:1 on #131313) ── */
  --rate-good: #22b522;
  --rate-warn: var(--ember);       /* #FF6A14, legal on dark */
  --rate-bad: #e05555;
  --rate-good-bg: rgba(34, 181, 34, 0.12);
  --rate-warn-bg: rgba(255, 106, 20, 0.12);
  --rate-bad-bg: rgba(224, 85, 85, 0.12);

  /* ── Sidebar rail ─────────────────────────────────────────── */
  --rail-w: 248px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* Sidebar anchors smooth-scroll; the reduced-motion block below opts out. */
  scroll-behavior: smooth;
}

/* Anchor targets clear the top edge when scrolled to. */
:target,
section[id],
#report-top,
#controls-card,
#summary-panel { scroll-margin-top: var(--space-5); }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-body-sm);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-7) var(--space-6) var(--space-9);
}

@media (max-width: 720px) {
  .wrap { padding: var(--space-6) var(--space-4) var(--space-8); }
}

/* The shell shifts right of the fixed rail once the sidebar is showing.
   Until a report loads the sidebar is [hidden], so the page stays centred. */
.shell { transition: padding-left var(--dur) var(--ease-out); }

@media (min-width: 1024px) {
  body.has-sidebar .shell { padding-left: var(--rail-w); }
}

/* Visually hidden but reachable by screen readers and the file input. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: calc(var(--space-4) * -4);
  z-index: 60;
  padding: var(--space-3) var(--space-5);
  background: var(--ember);
  color: var(--ink-900);
  font-weight: var(--fw-bold);
  font-size: var(--text-body-sm);
  border-radius: var(--radius-pill);
  text-decoration: none;
  transition: top var(--dur) var(--ease-out);
}
.skip-link:focus { top: var(--space-4); }

/* ── Blueprint grid texture: expedition/map motif ───────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(243, 238, 227, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(243, 238, 227, 0.045) 1px, transparent 1px);
  background-size: 72px 72px;
  -webkit-mask-image: radial-gradient(ellipse 90% 55% at 50% 0%, #000 0%, transparent 75%);
          mask-image: radial-gradient(ellipse 90% 55% at 50% 0%, #000 0%, transparent 75%);
}
.wrap { position: relative; z-index: 1; }

/* ════════════════════════ Masthead ════════════════════════ */

header.masthead { margin-bottom: var(--space-7); }

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}

/* The wordmark SVG is authored with fill="currentColor" and is inlined in the
   markup so it inherits `color` from the page. An <img> would have no CSS
   context and render the glyphs black on our black ground. */
.wordmark {
  display: block;
  color: var(--white);
  line-height: 0;
  transition: color var(--dur) var(--ease-out);
}
.wordmark:hover { color: var(--ember); }
.wordmark:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 6px;
  border-radius: var(--radius-sm);
}
.wordmark-svg {
  height: 26px;
  width: auto;
  display: block;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-eyebrow);
  text-transform: uppercase;
  color: var(--text-secondary);
}
.eyebrow::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--ember);
  flex: none;
}

h1 {
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--text-h3);
  line-height: var(--lh-snug);
  letter-spacing: var(--track-display);
  margin: var(--space-4) 0 var(--space-2);
  color: var(--white);
}

@media (max-width: 720px) { h1 { font-size: var(--text-h4); } }

.report-meta {
  color: var(--text-secondary);
  font-size: var(--text-body-sm);
  margin-bottom: var(--space-5);
}

/* ── Formula plate ─────────────────────────────────────────── */

.formula {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  font-size: var(--text-body-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-6);
}
.formula strong {
  color: var(--white);
  font-weight: var(--fw-semibold);
}
.formula .accent { color: var(--ember); font-weight: var(--fw-semibold); }

/* .baselines is styled in the "Formula hierarchy" block further down, where
   each baseline gets its own line. */

/* ── Stat tiles ────────────────────────────────────────────── */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

/* The headline metric gets the Ember treatment: accent on dark. */
.tile.tile-accent {
  border-color: rgba(255, 106, 20, 0.38);
  background:
    linear-gradient(180deg, rgba(255, 106, 20, 0.10) 0%, rgba(255, 106, 20, 0) 70%),
    var(--surface-1);
}
.tile.tile-accent .value { color: var(--ember); }

.tile .label {
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  /* --text-secondary, not --text-faint: at caption size this is normal text
     for WCAG and must clear 4.5:1. --text-faint measures 3.70:1 here. */
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}

.tile .value {
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--text-h3);
  line-height: var(--lh-tight);
  letter-spacing: var(--track-display);
  color: var(--white);
  /* proportional figures on standalone numbers, never tabular */
}

.tile .sub {
  font-size: var(--text-caption);
  color: var(--text-secondary);
  margin-top: var(--space-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.masthead-note {
  font-size: var(--text-caption);
  color: var(--text-faint);
  margin-top: var(--space-4);
}

/* ════════════════════════ Controls ════════════════════════ */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  align-items: flex-end;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-6);
}

.control { display: flex; flex-direction: column; gap: var(--space-2); }

.control label {
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  /* Same reason as .tile .label: a form label must clear 4.5:1. */
  color: var(--text-secondary);
}

.control input[type='number'],
.control input[type='text'] {
  font-family: var(--font-body);
  font-size: var(--text-body-sm);
  font-weight: var(--fw-medium);
  padding: 10px var(--space-3);
  background: var(--page);
  color: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.control input[type='number'] { width: 104px; }

.control input:hover { border-color: var(--border-strong); }
.control input:focus {
  outline: none;
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.control input::placeholder { color: var(--text-secondary); }

/* ════════════════════════ Sections ════════════════════════ */

section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}

@media (max-width: 720px) { section { padding: var(--space-5) var(--space-4); } }

section h2 {
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--text-h5);
  line-height: var(--lh-heading);
  letter-spacing: var(--track-heading);
  margin: 0 0 var(--space-2);
  color: var(--white);
}

section h2 .idx {
  color: var(--ember);
  margin-right: var(--space-2);
}

section .desc {
  font-size: var(--text-body-sm);
  color: var(--text-secondary);
  margin: 0 0 var(--space-5);
  max-width: 70ch;
}

/* Container grows with content so the x-axis band is never clipped. */
.chart-box { position: relative; width: 100%; }

/* ── Legend ────────────────────────────────────────────────── */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin: 0 0 var(--space-4);
  font-size: var(--text-caption);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
}
.legend .item { display: flex; align-items: center; gap: var(--space-2); }
.legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: none;
}

/* ══════════════ Section 4: Funnel Diagnostic ══════════════ */

.funnel-layout {
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
  gap: var(--space-6);
  align-items: start;
}

@media (max-width: 900px) {
  .funnel-layout { grid-template-columns: 1fr; }
}

/* ── The tapered funnel graphic ────────────────────────────── */

.funnel-graphic { width: 100%; display: block; }

.funnel-band {
  cursor: pointer;
  transition: opacity var(--dur) var(--ease-out);
}
.funnel-band .band-shape {
  transition: fill-opacity var(--dur) var(--ease-out),
              stroke var(--dur) var(--ease-out);
  stroke: transparent;
  stroke-width: 2;
}
.funnel-band:hover .band-shape { fill-opacity: 0.92; }

/* Active stage: Ember outline, accent on dark, never a large fill */
.funnel-band.is-active .band-shape {
  stroke: var(--ember);
  stroke-width: 2.5;
}
.funnel-band:not(.is-active) .band-shape { fill-opacity: 0.62; }

.funnel-band:focus-visible { outline: none; }
.funnel-band:focus-visible .band-shape {
  stroke: var(--ember);
  stroke-width: 2.5;
}

.funnel-band .band-label {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: var(--fw-semibold);
  fill: var(--ink-900);
  pointer-events: none;
}
.funnel-band .band-value {
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: var(--fw-medium);
  fill: rgba(11, 11, 11, 0.72);
  pointer-events: none;
}
/* Deepest band is dark, so its text flips to ivory for contrast. */
.funnel-band.on-dark .band-label { fill: var(--ivory); }
.funnel-band.on-dark .band-value { fill: rgba(243, 238, 227, 0.75); }

.funnel-band .band-rate {
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: var(--fw-medium);
  fill: var(--text-faint);
  pointer-events: none;
}

/* ── "Too early to tell" note beneath the funnel ───────────── */

.too-early {
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out);
}
.too-early:hover { background: var(--surface-raised); }
.too-early.is-active {
  border-style: solid;
  border-color: var(--ember);
  background: var(--surface-raised);
}
.too-early:focus-visible {
  outline: none;
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.too-early .te-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--stage-early);
  flex: none;
}
.too-early .te-text { flex: 1; min-width: 0; }
.too-early .te-label {
  display: block;
  font-size: var(--text-body-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}
.too-early .te-sub {
  display: block;
  font-size: var(--text-caption);
  color: var(--text-faint);
  margin-top: 2px;
}
.too-early .te-stat {
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.funnel-caption {
  font-size: var(--text-caption);
  color: var(--text-faint);
  margin-top: var(--space-4);
  line-height: var(--lh-body);
}

/* ── Query card list ───────────────────────────────────────── */

.stage-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.stage-panel-head h3 {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: var(--text-h5);
  letter-spacing: var(--track-heading);
  margin: 0;
  color: var(--white);
}

.stage-panel-head .stage-stat {
  font-size: var(--text-caption);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.query-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-height: 620px;
  overflow-y: auto;
  padding-right: var(--space-2);
}

/* Scrollbar, dark */
.query-cards::-webkit-scrollbar { width: 8px; }
.query-cards::-webkit-scrollbar-track { background: transparent; }
.query-cards::-webkit-scrollbar-thumb {
  background: rgba(243, 238, 227, 0.16);
  border-radius: var(--radius-pill);
}
.query-cards::-webkit-scrollbar-thumb:hover { background: rgba(243, 238, 227, 0.28); }

.query-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  transition: transform var(--dur) var(--ease-out),
              box-shadow var(--dur) var(--ease-out),
              border-color var(--dur) var(--ease-out);
}
.query-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-lg);
}

.qc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.qc-query {
  font-size: var(--text-body);
  font-weight: var(--fw-semibold);
  color: var(--white);
  line-height: 1.35;
  word-break: break-word;
}

.qc-score {
  text-align: right;
  flex: none;
}
.qc-score .pts {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: var(--text-h5);
  line-height: var(--lh-tight);
  letter-spacing: var(--track-heading);
  color: var(--white);
  white-space: nowrap;
}
.qc-score .share {
  font-size: var(--text-caption);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
  white-space: nowrap;
}

/* ── Rate badges ───────────────────────────────────────────── */

.qc-rates {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.rate-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}

.rate-badge .rb-name {
  font-weight: var(--fw-medium);
  opacity: 0.78;
}

/* Line-icon only, no emoji, per the brand rules. */
.rate-badge svg { width: 12px; height: 12px; flex: none; }

.rate-badge.is-good {
  background: var(--rate-good-bg);
  border-color: rgba(34, 181, 34, 0.32);
  color: var(--rate-good);
}
.rate-badge.is-warn {
  background: var(--rate-warn-bg);
  border-color: rgba(255, 106, 20, 0.34);
  color: var(--rate-warn);
}
.rate-badge.is-bad {
  background: var(--rate-bad-bg);
  border-color: rgba(224, 85, 85, 0.34);
  color: var(--rate-bad);
}
.rate-badge.is-na {
  background: rgba(243, 238, 227, 0.05);
  border-color: var(--border);
  color: var(--text-faint);
}

.empty-state {
  padding: var(--space-7) var(--space-5);
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-body-sm);
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

.baseline-note {
  font-size: var(--text-caption);
  color: var(--text-faint);
  margin-top: var(--space-4);
  line-height: var(--lh-body);
}

/* ══════════════ Summary panel (manual AI round-trip) ══════════════ */

/* Ember-tinted so it reads as the one generative surface on the page. */
.summary-panel {
  border-color: rgba(255, 106, 20, 0.30);
  background:
    linear-gradient(180deg, rgba(255, 106, 20, 0.07) 0%, rgba(255, 106, 20, 0) 60%),
    var(--surface-1);
}

.summary-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.summary-head h2 { margin: 0; }

/* "AI" reads as an eyebrow label rather than a section numeral. */
.summary-head h2 .idx {
  font-family: var(--font-body);
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-eyebrow);
  vertical-align: 2px;
}

.summary-status {
  font-size: var(--text-caption);
  color: var(--text-faint);
}

.summary-text {
  font-size: var(--text-body-sm);
  line-height: var(--lh-relaxed);
  color: var(--text-secondary);
  margin: 0 0 var(--space-4);
  max-width: 78ch;
}

/* Each top-level block ("The big picture", "Fix #N", "PPC moves", "Do this
   first") is separated by a hairline rule and indented off a left border,
   the same card language as the Section 4 query cards. */
.summary-text .sum-section + .sum-section {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--gridline);
}

.summary-text .sum-head {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: var(--text-body);
  line-height: var(--lh-heading);
  letter-spacing: var(--track-heading);
  color: var(--white);
  margin: 0 0 var(--space-3);
  padding-left: var(--space-3);
  border-left: 2px solid var(--ember);
}

/* PPC subgroups sit one level in, with a recessive marker. */
.summary-text .sum-subhead {
  font-family: var(--font-body);
  font-weight: var(--fw-semibold);
  font-size: var(--text-body-sm);
  letter-spacing: 0.02em;
  color: var(--text-primary);
  margin: var(--space-4) 0 var(--space-2);
  padding-left: var(--space-3);
  border-left: 2px solid var(--border-strong);
}

.summary-text .sum-para {
  margin: 0 0 var(--space-2);
}
.summary-text .sum-para:last-child { margin-bottom: 0; }

.summary-text .sum-list {
  list-style: none;
  margin: 0 0 var(--space-2);
  padding: 0;
}
.summary-text .sum-list:last-child { margin-bottom: 0; }

.summary-text .sum-list li {
  position: relative;
  padding-left: var(--space-5);
  margin-bottom: var(--space-2);
}
.summary-text .sum-list li:last-child { margin-bottom: 0; }

/* Visible marker in the accent, matching the eyebrow dot motif. */
.summary-text .sum-list li::before {
  content: '';
  position: absolute;
  left: var(--space-2);
  top: 0.62em;
  width: 5px;
  height: 5px;
  border-radius: 1px;
  background: var(--ember);
}

.summary-text strong {
  color: var(--white);
  font-weight: var(--fw-semibold);
}

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  margin-top: var(--space-4);
}

.summary-input {
  width: 100%;
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--page);
  color: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-body-sm);
  line-height: var(--lh-body);
  resize: vertical;
  min-height: 120px;
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.summary-input:hover { border-color: var(--border-strong); }
.summary-input:focus {
  outline: none;
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.summary-input::placeholder { color: var(--text-secondary); }

/* Secondary action: outline, so only one Ember fill sits in the panel. */
button.btn.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-strong);
}
button.btn.btn-ghost:hover {
  background: var(--surface-raised);
  border-color: var(--ember);
  color: var(--ember);
  box-shadow: none;
}

button.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}
button.btn[disabled]:hover { background: var(--ember); }
button.btn.btn-ghost[disabled]:hover {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-primary);
}

/* Status notes. These sit on elements that also carry .count-note, which is
   declared later in this file, so they need the extra class to win on
   specificity rather than relying on source order. Without it a rejection
   message renders in muted grey and reads as ignorable. */
.note-ok,
.count-note.note-ok { color: var(--rate-good); font-weight: var(--fw-semibold); }
.note-bad,
.count-note.note-bad { color: var(--rate-bad); font-weight: var(--fw-semibold); }
.note-warn,
.count-note.note-warn { color: var(--ember); font-weight: var(--fw-semibold); }

/* ════════════════════════ Tables ════════════════════════ */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-sm);
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: var(--space-3) var(--space-4);
  text-align: right;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

th:first-child, td:first-child,
th.q, td.q { text-align: left; }

td.q {
  white-space: normal;
  min-width: 180px;
  max-width: 340px;
  font-variant-numeric: normal;
  color: var(--text-primary);
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-faint);
  font-weight: var(--fw-semibold);
  font-size: var(--text-caption);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  z-index: 1;
  border-bottom: 1px solid var(--border-strong);
}

tbody td { color: var(--text-secondary); }
tbody td:nth-child(3) { color: var(--text-primary); font-weight: var(--fw-semibold); }

th.sortable { cursor: pointer; user-select: none; transition: color var(--dur) var(--ease-out); }
th.sortable:hover { color: var(--white); }
th.sortable.is-sorted { color: var(--ember); }
th .arrow { font-size: 9px; margin-left: 2px; }

tbody tr { transition: background var(--dur-fast) var(--ease-out); }
tbody tr:hover { background: rgba(243, 238, 227, 0.04); }
tbody tr:last-child td { border-bottom: none; }

/* ════════════════════════ Toolbar & buttons ════════════════ */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.toolbar-right {
  display: flex;
  gap: var(--space-4);
  align-items: center;
}

.count-note {
  font-size: var(--text-caption);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* Ember pill CTA: accent on dark, with the brand glow */
button.btn {
  font-family: var(--font-button);
  font-size: var(--text-body-sm);
  font-weight: var(--fw-bold);
  padding: 11px var(--space-5);
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: var(--ember);
  color: var(--ink-900);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--dur) var(--ease-out),
              box-shadow var(--dur) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
button.btn:hover {
  background: var(--ember-pressed);
  box-shadow: var(--shadow-ember);
}
button.btn:active { transform: translateY(1px); }
button.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}
button.btn svg { width: 15px; height: 15px; }

/* ════════════════════════ Status & errors ════════════════ */

#status {
  padding: var(--space-9) 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--text-body);
}

.error-box {
  border: 1px solid rgba(224, 85, 85, 0.45);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  background: var(--surface-1);
  text-align: left;
}
.error-box h2 {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: var(--text-h5);
  letter-spacing: var(--track-heading);
  color: var(--rate-bad);
  margin: 0 0 var(--space-3);
}
.error-box code {
  display: block;
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-caption);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  color: var(--text-secondary);
  line-height: var(--lh-body);
}

/* ════════════════════════ Footer ════════════════════════ */

footer.colophon {
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  font-size: var(--text-caption);
  color: var(--text-faint);
}
footer.colophon .mark {
  color: var(--white);
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--text-body);
  letter-spacing: var(--track-heading);
}

.hidden { display: none !important; }

/* ════════════════════ Sidebar navigation ════════════════════
   Anchor links into the one continuous document. Every value below is an
   orellana. token; nothing here is a raw literal except the rail width,
   which is declared as --rail-w alongside the other layout values. */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rail-w);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-6) var(--space-4);
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sidebar[hidden] { display: none; }

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.sidebar-mark {
  text-decoration: none;
  color: var(--white);
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--text-body);
  letter-spacing: var(--track-heading);
  transition: color var(--dur) var(--ease-out);
}
.sidebar-mark:hover { color: var(--ember); }
.sidebar-mark:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 4px;
  border-radius: var(--radius-sm);
}

/* Hamburger, only ever visible on narrow widths. */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}
.sidebar-toggle svg { width: 18px; height: 18px; }
.sidebar-toggle:hover { border-color: var(--ember); color: var(--ember); }
.sidebar-toggle:focus-visible {
  outline: none;
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.sidebar-nav { flex: 1; min-height: 0; }

.sidebar-label {
  display: block;
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-eyebrow);
  text-transform: uppercase;
  /* --text-secondary, not --text-faint: this is a real label, and it has to
     clear 4.5:1 as normal-size text. */
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
  padding-left: var(--space-3);
}

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: var(--text-body-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.sidebar-link:hover {
  background: var(--surface-raised);
  color: var(--text-primary);
}
.sidebar-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* Active section: Ember marker plus a full-strength label. Position is never
   carried by color alone, the left rule and the weight change carry it too. */
.sidebar-link.is-active {
  background: var(--surface-raised);
  border-left-color: var(--ember);
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
}
.sidebar-link.is-active .sl-idx { color: var(--ember); }

.sidebar-link .sl-idx {
  flex: none;
  width: 22px;
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
}
.sidebar-link .sl-idx svg { width: 13px; height: 13px; }
.sidebar-link .sl-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.sidebar-action {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--text-body-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.sidebar-action svg { width: 15px; height: 15px; flex: none; }
.sidebar-action:hover {
  background: var(--surface-raised);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.sidebar-action:focus-visible {
  outline: none;
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* Narrow widths: the rail becomes a collapsible bar across the top rather
   than overlapping the report. */
@media (max-width: 1023px) {
  .sidebar {
    position: sticky;
    inset: 0 auto auto 0;
    width: auto;
    max-height: none;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }
  .sidebar-toggle { display: inline-flex; }
  /* Collapsed by default on narrow screens; the toggle opens it. */
  .sidebar-nav,
  .sidebar-foot { display: none; }
  .sidebar.is-open .sidebar-nav { display: block; }
  .sidebar.is-open .sidebar-foot { display: flex; }
  .sidebar-foot { border-top: 1px solid var(--border); padding-top: var(--space-3); }
}

/* ════════════════════ Landing / dropzone ════════════════════ */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-9) var(--space-6);
  background: var(--surface-1);
  border: var(--border-w-strong) dashed var(--border-strong);
  border-radius: var(--radius-xl);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease-out),
              background var(--dur) var(--ease-out);
}
.dropzone:hover { border-color: var(--ember); background: var(--surface-raised); }
.dropzone:focus-visible {
  outline: none;
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.dropzone.is-dragover {
  border-style: solid;
  border-color: var(--ember);
  background: var(--surface-raised);
}

.dropzone .dz-icon {
  width: 40px;
  height: 40px;
  color: var(--ember);
  margin-bottom: var(--space-2);
}

.dropzone .dz-title {
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--text-h5);
  line-height: var(--lh-heading);
  letter-spacing: var(--track-heading);
  color: var(--white);
  margin: 0;
}

.dropzone .dz-hint {
  font-size: var(--text-body-sm);
  color: var(--text-secondary);
  margin: 0;
  max-width: 52ch;
}

.dropzone .dz-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.dropzone .dz-note {
  font-size: var(--text-caption);
  color: var(--text-secondary);
  margin: var(--space-3) 0 0;
}

/* Full-viewport drag feedback, so a file dropped anywhere is accepted. */
.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(11, 11, 11, 0.86);
  pointer-events: none;
}
body.is-dragging .drag-overlay { display: flex; }

.drag-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-8) var(--space-9);
  border: var(--border-w-strong) dashed var(--ember);
  border-radius: var(--radius-xl);
  background: var(--surface-1);
  color: var(--white);
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: var(--text-h5);
  letter-spacing: var(--track-heading);
}
.drag-overlay-inner svg { width: 42px; height: 42px; color: var(--ember); }

/* ════════════════════ Header actions + picker ════════════════════ */

.title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
.title-block { min-width: 0; }
.title-block h1 { margin-bottom: var(--space-2); }
.title-block .report-meta { margin-bottom: 0; }

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.picker-wrap { position: relative; }

.report-picker {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  z-index: 30;
  min-width: 320px;
  max-width: 460px;
  max-height: 420px;
  overflow-y: auto;
  padding: var(--space-2);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.report-picker[hidden] { display: none; }

.picker-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-3);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.picker-item:hover { background: var(--surface-raised); }
.picker-item:focus-visible {
  outline: none;
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.picker-item .pi-name {
  display: block;
  font-size: var(--text-body-sm);
  font-weight: var(--fw-semibold);
  word-break: break-word;
}
.picker-item .pi-meta {
  display: block;
  font-size: var(--text-caption);
  color: var(--text-secondary);
  margin-top: 2px;
}

.picker-note {
  padding: var(--space-4) var(--space-3);
  font-size: var(--text-body-sm);
  color: var(--text-secondary);
  text-align: center;
}
.picker-note.is-error { color: var(--rate-bad); }

/* ════════════════════ Controls card ════════════════════ */

.controls-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-5);
}
@media (max-width: 720px) { .controls-card { padding: var(--space-5) var(--space-4); } }

.controls-head { margin-bottom: var(--space-4); }

.controls-title {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  font-size: var(--text-body-lg);
  line-height: var(--lh-heading);
  letter-spacing: var(--track-heading);
  color: var(--white);
  margin: 0 0 var(--space-1);
}

.controls-caption {
  font-size: var(--text-body-sm);
  color: var(--text-secondary);
  margin: 0;
}

/* The inner control row loses the card chrome it used to carry itself. */
.controls-card .controls {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  margin-bottom: 0;
}

/* ════════════════════ Brand name field ════════════════════ */

.brand-field {
  padding: var(--space-4) var(--space-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-5);
}

.brand-field > label {
  display: block;
  font-size: var(--text-caption);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.brand-row-input {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.brand-field input[type='text'] {
  flex: 1;
  min-width: 220px;
  max-width: 360px;
  font-family: var(--font-body);
  font-size: var(--text-body-sm);
  font-weight: var(--fw-medium);
  padding: 10px var(--space-3);
  background: var(--page);
  color: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.brand-field input:hover { border-color: var(--border-strong); }
.brand-field input:focus {
  outline: none;
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.brand-field input::placeholder { color: var(--text-secondary); }

.brand-help {
  font-size: var(--text-caption);
  color: var(--text-secondary);
  margin: var(--space-2) 0 0;
  max-width: 68ch;
}

/* ════════════════════ Formula hierarchy ════════════════════
   The formula and its three baselines each get their own line. Deliberately
   not compressed into a single dense row. */

.formula-line {
  font-size: var(--text-body);
  line-height: var(--lh-body);
  color: var(--text-primary);
}

.formula-note {
  font-size: var(--text-body-sm);
  color: var(--text-secondary);
  margin: var(--space-2) 0 0;
}

.baselines {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--gridline);
  font-size: var(--text-body-sm);
  /* Was --text-faint at caption size. These are real content lines, so they
     move up to --text-secondary to clear 4.5:1. */
  color: var(--text-secondary);
}
.baselines span {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
/* Ember tick, matching the eyebrow dot motif elsewhere. */
.baselines span::before {
  content: '';
  width: 5px;
  height: 5px;
  flex: none;
  background: var(--ember);
  transform: translateY(-2px);
}

/* ════════════════════ Print / PDF export ════════════════════
   window.print() plus this sheet. Interactive chrome is removed; the report,
   its charts, and any saved summary stay. */

@media print {
  /* Ink-on-white: chart canvases are raster images that already carry their
     own colors, so only the page furniture needs flipping. */
  html, body {
    background: #FFFFFF !important;
    color: #0B0B0B !important;
  }
  body::before { display: none !important; }

  /* Interactive-only chrome. */
  .sidebar,
  .skip-link,
  .header-actions,
  .drag-overlay,
  #landing,
  .controls-card,
  .toolbar,
  .summary-actions,
  .summary-input,
  #summary-compose,
  .brand-help,
  .summary-status,
  .too-early,
  button {
    display: none !important;
  }

  .shell { padding-left: 0 !important; }
  .wrap { max-width: none; padding: 0; }

  /* Focus rings must not print. */
  *:focus,
  *:focus-visible { outline: none !important; box-shadow: none !important; }

  /* Cards flatten to hairline-ruled blocks so they read on paper. */
  section,
  .controls-card,
  .tile,
  .query-card,
  .brand-field,
  .formula,
  .summary-panel {
    background: #FFFFFF !important;
    border: 1px solid #BCBCBC !important;
    box-shadow: none !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  h1, h2, h3,
  .tile .value,
  .qc-query,
  .qc-score .pts,
  .summary-text strong,
  .summary-text .sum-head,
  .formula-line,
  .formula strong,
  .sidebar-mark,
  footer.colophon .mark {
    color: #0B0B0B !important;
  }

  .desc,
  .report-meta,
  .baselines,
  .count-note,
  .controls-caption,
  .funnel-caption,
  .baseline-note,
  .summary-text,
  .brand-field > label,
  tbody td,
  footer.colophon {
    color: #353535 !important;
  }

  /* The section accent numerals stay, in ink rather than Ember. */
  section h2 .idx,
  .summary-head h2 .idx { color: #666666 !important; }

  /* The brand name still matters on paper, so the input value is echoed as
     text via a data attribute set in app.js. */
  .brand-field input { display: none !important; }
  .brand-field::after {
    content: attr(data-print-brand);
    font-size: 12px;
    color: #0B0B0B;
  }

  /* Each numbered section starts a fresh page; the summary rides with the
     masthead on page one. */
  #section-magnitude,
  #section-concentration,
  #section-composition,
  #section-funnel,
  #section-table {
    break-before: page;
    page-break-before: always;
  }

  /* Scroll containers must expand, or printing clips them to one screenful. */
  .query-cards,
  .table-scroll,
  .formula {
    max-height: none !important;
    overflow: visible !important;
  }

  thead th {
    position: static !important;
    background: #F3EEE3 !important;
    color: #0B0B0B !important;
  }
  thead { display: table-header-group; }
  tr { break-inside: avoid; page-break-inside: avoid; }

  @page { margin: 14mm; }
}

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