/* ---------- Design tokens ----------
   Grounded in the subject: this reads legal redlines of SEC filings, so the
   palette is a warm paper/ink tone rather than a cold SaaS gray, and every
   ticker, date, and figure is set in a monospace face -- the way filings,
   tickers, and ledgers actually set their numerals -- instead of the same
   proportional sans as the prose around it. */
:root {
  --bg: #f8f8fa;
  --bg-elevated: #ffffff;
  --text: #1b1c22;
  --text-muted: #63656f;
  --text-faint: #94969f;
  --border: #e6e6ec;
  --accent: #3454d1;
  --accent-hover: #2740a8;
  --accent-soft: #eaeeff;

  /* Icon-badge palette for stat tiles/cards -- distinct hues per tile so a
     row of stats reads at a glance, each still paired with a real number
     and label (never color standing in for a judgment). */
  --badge-purple: #6c4fe0;
  --badge-purple-soft: #efeafc;
  --badge-orange: #d97b1f;
  --badge-orange-soft: #fdf1e3;
  --badge-blue: #2f6fd6;
  --badge-blue-soft: #eaf1fd;
  --badge-teal: #0d9080;
  --badge-teal-soft: #e5f6f3;

  /* Diff palette: blue/orange, not red/green, so it stays legible for the
     most common forms of color vision deficiency. Color is never the only
     cue -- every added/removed chunk also gets a +/- glyph and (for
     removals) a strikethrough. */
  --added-bg: #eef4ff;
  --added-border: #2f5fd6;
  --added-text: #16305e;
  --removed-bg: #fff6ec;
  --removed-border: #c2660a;
  --removed-text: #5c3313;
  --unchanged-text: #6b6b70;

  /* A third hue, distinct from the added/removed pair, reserved for
     featured/highlight UI (movers strip, metrics panel accents) so it never
     collides with the diff's own color meaning. */
  --feature: #0d8f83;
  --feature-soft: #e5f6f4;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(30, 25, 10, 0.05), 0 4px 16px rgba(30, 25, 10, 0.06);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --font-prose: "Source Serif 4", Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --font-display: "Source Serif 4", Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  /* Every ticker, date, accession-style figure, and stat number uses this --
     the way an actual filing or a ledger sets its numerals, distinct from
     the surrounding prose/UI type. */
  --font-mono: "IBM Plex Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #16140f;
  --bg-elevated: #1e1b14;
  --text: #ece7d9;
  --text-muted: #a89f8a;
  --text-faint: #776f5c;
  --border: #35301f;
  --accent: #6b82f0;
  --accent-hover: #8497f5;
  --accent-soft: #232544;

  --added-bg: #1c223f;
  --added-border: #7c9dff;
  --added-text: #d3ddff;
  --removed-bg: #3a2413;
  --removed-border: #e6a353;
  --removed-text: #ffe2ba;
  --unchanged-text: #948c76;

  --feature: #2ba99b;
  --feature-soft: #17332f;

  --badge-purple: #8f7af5;
  --badge-purple-soft: #29234a;
  --badge-orange: #e6a353;
  --badge-orange-soft: #3a2413;
  --badge-blue: #7c9dff;
  --badge-blue-soft: #1c223f;
  --badge-teal: #2ba99b;
  --badge-teal-soft: #17332f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16140f;
    --bg-elevated: #1e1b14;
    --text: #ece7d9;
    --text-muted: #a89f8a;
    --text-faint: #776f5c;
    --border: #35301f;
    --accent: #6b82f0;
    --accent-hover: #8497f5;
    --accent-soft: #232544;

    --added-bg: #1c223f;
    --added-border: #7c9dff;
    --added-text: #d3ddff;
    --removed-bg: #3a2413;
    --removed-border: #e6a353;
    --removed-text: #ffe2ba;
    --unchanged-text: #948c76;

    --feature: #2ba99b;
    --feature-soft: #17332f;
    --badge-purple: #8f7af5;
    --badge-purple-soft: #29234a;
    --badge-orange: #e6a353;
    --badge-orange-soft: #3a2413;
    --badge-blue: #7c9dff;
    --badge-blue-soft: #1c223f;
    --badge-teal: #2ba99b;
    --badge-teal-soft: #17332f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---------- Page chrome: a slim top bar + a single full-width main area.
   No persistent sidebar -- the company universe lives on its own browse
   page (home.js renderHome), and opening a company navigates to a
   dedicated full-page view with its own "Back to all companies" link. ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  max-width: 1160px;
  margin: 0 auto;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-style: italic;
  font-size: 1.18rem;
  letter-spacing: -0.005em;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 9px;
}
.brand small {
  font-family: var(--font-mono);
  font-style: normal;
  font-weight: 500;
  font-size: 0.68rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page-main { flex: 1; }
.wrap { max-width: 1160px; margin: 0 auto; padding: 28px 24px 60px; }

.back-link { font-size: 0.85rem; display: inline-block; margin: 0 0 16px; }

/* ---------- Full-text filing search ---------- */
.text-search { max-width: 720px; }
.text-search-h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.9rem;
  margin: 6px 0 10px;
  letter-spacing: -0.01em;
}
.text-search-sub { color: var(--text-muted); margin: 0 0 18px; line-height: 1.55; }
.text-search input[type="text"] { width: 100%; font-size: 1rem; padding: 12px 14px; margin-bottom: 20px; }
.text-search-result {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  color: var(--text);
}
.text-search-result:hover { border-color: var(--accent); text-decoration: none; }
.tsr-row1 { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.tsr-ticker { font-family: var(--font-mono); font-weight: 700; font-size: 0.9rem; }
.tsr-name { color: var(--text-muted); font-size: 0.82rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tsr-label { font-family: var(--font-mono); color: var(--text-faint); font-size: 0.72rem; }
.tsr-snippet { margin: 0; font-family: var(--font-prose); font-size: 0.92rem; line-height: 1.55; color: var(--text-muted); }
.tsr-snippet mark { background: var(--added-bg); color: var(--added-text); }
.key-status {
  font-size: 0.8rem;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  background: var(--bg);
  white-space: nowrap;
  flex: none;
}
.key-status .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
}
.key-status.active { border-color: var(--added-border); color: var(--added-text); }
.key-status.active .dot { background: var(--added-border); }

.theme-toggle {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); transform: rotate(15deg); }

/* ---------- Buttons / inputs ---------- */
button {
  font-family: inherit;
  cursor: pointer;
}
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.secondary:hover { background: var(--accent-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="text"], input[type="password"], select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
}
input[type="text"]:focus, input[type="password"]:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Overview (main panel, no company selected) ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 32px;
  align-items: center;
  padding: 36px 0 44px;
  margin: 8px 0 12px;
  border-bottom: 1px solid var(--border);
}
.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 14px;
}
.hero h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2.6rem;
  line-height: 1.12;
  margin: 0 0 14px;
  letter-spacing: -0.015em;
}
.hero p { color: var(--text-muted); max-width: 46ch; margin: 0; font-size: 1.02rem; line-height: 1.6; }

.data-asof {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-faint);
  margin-top: 16px;
}

/* The hero's signature element: a real excerpt from the biggest recent
   mover's actual diff -- not decoration, the product itself, front and
   center. Styled like a torn-off strip of the redlined document. */
.hero-redline {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 4px 0;
  position: relative;
}
.hero-redline::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: repeating-linear-gradient(180deg, var(--accent) 0 6px, transparent 6px 12px);
  opacity: 0.5;
}
.hero-redline-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 12px 20px 0;
}
.hero-redline-body { padding: 8px 0 16px; }
.hero-redline-ticker {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-faint);
  padding: 4px 20px 10px;
}
.hero-redline-line {
  display: flex;
  gap: 10px;
  padding: 8px 20px;
  font-family: var(--font-prose);
  font-size: 0.92rem;
  line-height: 1.55;
}
.hero-redline-line .glyph { flex: none; font-family: var(--font-ui); font-weight: 700; }
.hero-redline-line.added { background: var(--added-bg); color: var(--added-text); }
.hero-redline-line.added .glyph { color: var(--added-border); }
.hero-redline-line.removed { background: var(--removed-bg); color: var(--removed-text); text-decoration: line-through; text-decoration-color: var(--removed-border); }
.hero-redline-line.removed .glyph { color: var(--removed-border); }
.hero-redline-link {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 12px 20px 4px;
}
.hero-redline[hidden] { display: none; }

@media (max-width: 800px) {
  .hero { grid-template-columns: 1fr; }
}

.movers-strip { margin: 28px 0 8px; }
.movers-strip h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.movers-strip h2::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--feature);
  display: inline-block;
}
.movers-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.mover-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--feature);
  border-radius: 4px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.mover-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.mover-card .ticker { font-family: var(--font-mono); font-weight: 700; font-size: 0.92rem; }
.mover-card .magnitude { font-family: var(--font-mono); font-size: 1.05rem; font-weight: 700; color: var(--feature); font-variant-numeric: tabular-nums; }
.mover-card .magnitude-lbl { font-size: 0.7rem; color: var(--text-faint); }

.sort-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex: none;
}
.sort-toggle button {
  background: var(--bg-elevated);
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 9px 14px;
  font-family: inherit;
}
.sort-toggle button + button { border-left: 1px solid var(--border); }
.sort-toggle button.active { background: var(--accent); color: #fff; }

/* ---------- Browse page: toolbar + company card grid ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  margin: 22px 0 20px;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar input[type="text"] { flex: 1; min-width: 200px; }
.toolbar .text-search-cta { margin-left: auto; flex: none; }
.sort-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex: none;
}
.sort-toggle button {
  background: var(--bg-elevated);
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 9px 14px;
  font-family: inherit;
}
.sort-toggle button + button { border-left: 1px solid var(--border); }
.sort-toggle button.active { background: var(--accent); color: #fff; }

.company-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  padding-bottom: 20px;
}
.company-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 4px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.company-card:hover { border-color: var(--accent); border-left-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
.cc-row1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cc-ticker { font-family: var(--font-mono); font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; }
.cc-sector {
  font-size: 0.66rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.cc-name { color: var(--text-muted); font-size: 0.83rem; line-height: 1.3; }
.cc-change { display: flex; gap: 8px; align-items: center; font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.cc-change .added { color: var(--added-border); }
.cc-change .removed { color: var(--removed-border); }
.cc-change .cc-asof { color: var(--text-faint); font-weight: 500; margin-left: auto; font-size: 0.72rem; }
.cc-change.muted { color: var(--text-faint); font-family: var(--font-ui); font-weight: 500; }

/* ---------- Status pills (company detail header) ---------- */
.meta-pills { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 8px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
}
.pill-success { background: var(--added-bg); color: var(--added-border); }
.pill-accent { background: var(--badge-purple-soft); color: var(--badge-purple); }
.pill-neutral { background: var(--bg); border: 1px solid var(--border); color: var(--text-faint); }
.meta-dot { color: var(--text-faint); margin: 0 2px; }

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.import-panel {
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: -6px 0 30px;
}
.import-panel-status { color: var(--text-faint); font-size: 0.85rem; }
.import-panel-heading {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  margin-bottom: 10px;
}
.import-candidates {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.import-candidate {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  transition: border-color 0.15s;
}
.import-candidate:hover:not(:disabled) { border-color: var(--accent); }
.import-candidate:disabled { opacity: 0.7; cursor: wait; }
.import-candidate .ticker { font-family: var(--font-mono); font-weight: 700; font-size: 0.9rem; }
.import-candidate .name { color: var(--text-muted); font-size: 0.78rem; }
.import-candidate .import-cta { color: var(--accent); font-size: 0.76rem; font-weight: 600; margin-top: 2px; }

/* ---------- Company detail ---------- */
.company-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  padding: 6px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.company-header h1 { font-family: var(--font-display); font-weight: 600; margin: 0 0 4px; font-size: 1.7rem; letter-spacing: -0.01em; }
.company-header h1 .ticker-sub { font-family: var(--font-mono); font-weight: 500; color: var(--text-faint); }
.company-header .meta-line { font-family: var(--font-mono); color: var(--text-muted); font-size: 0.85rem; }

.company-header-main { flex: 1; min-width: 280px; }
.period-picker {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 20px;
  flex: none;
  max-width: 460px;
}
.period-field { display: flex; flex-direction: column; gap: 5px; }
.period-field label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 600;
}
.period-arrow { color: var(--text-faint); font-size: 1.1rem; margin-top: 16px; }

.timeline {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding-top: 16px;
}
.timeline-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg-elevated);
  cursor: pointer;
  transition: background 0.15s;
}
.timeline-dot.in-range { background: var(--accent-soft); }
.timeline-dot.endpoint { background: var(--accent); }
.timeline-line { width: 22px; height: 2px; background: var(--border); }
.timeline-line.in-range { background: var(--accent); }

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.stat-tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-icon {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 10px;
}
.stat-icon.purple { background: var(--badge-purple-soft); color: var(--badge-purple); }
.stat-icon.orange { background: var(--badge-orange-soft); color: var(--badge-orange); }
.stat-icon.blue { background: var(--badge-blue-soft); color: var(--badge-blue); }
.stat-icon.teal { background: var(--badge-teal-soft); color: var(--badge-teal); }
.stat-tile-num { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; color: var(--text); }
.stat-tile-lbl { color: var(--text-faint); font-size: 0.76rem; margin-top: 3px; }
.source-links-row { display: flex; gap: 16px; font-size: 0.8rem; color: var(--text-faint); margin-bottom: 20px; }

/* ---------- Change-breakdown donut + largest-changes cards ---------- */
.insight-row {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 14px;
  margin-bottom: 20px;
  align-items: stretch;
}
.insight-row > * { margin-bottom: 0 !important; }
.change-donut-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.change-donut-card h3 {
  margin: 0 0 14px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
}
.change-donut-row { display: flex; align-items: center; gap: 16px; }
.donut-center-num { font-family: var(--font-mono); font-weight: 700; font-size: 1.3rem; fill: var(--text); }
.donut-center-lbl { font-family: var(--font-mono); font-size: 0.6rem; fill: var(--text-faint); }
.change-donut-legend { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.donut-legend-row { display: flex; align-items: center; gap: 7px; font-size: 0.76rem; }
.donut-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.donut-legend-lbl { color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend-val { font-family: var(--font-mono); color: var(--text-faint); font-size: 0.72rem; flex: none; }

.top-changes-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 20px;
}
.top-changes-card h3 {
  margin: 0 0 12px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
}
.top-changes-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.top-change-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tc-tag {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.tc-tag.added { background: var(--added-bg); color: var(--added-border); }
.tc-tag.removed { background: var(--removed-bg); color: var(--removed-border); }
.tc-snippet { margin: 0; font-family: var(--font-prose); font-size: 0.86rem; line-height: 1.5; color: var(--text-muted); flex: 1; }
.tc-words { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-faint); }

.ai-panel {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.ai-panel h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-panel p { margin: 0; line-height: 1.65; font-size: 0.96rem; }
.ai-panel .ai-caveat { margin-top: 10px; font-size: 0.76rem; color: var(--text-faint); }
.ai-panel .ai-loading { color: var(--text-faint); font-style: italic; }
.ai-panel .ai-error { color: var(--removed-border); }
.ai-panel.local-ai-panel { background: var(--feature-soft); border-color: var(--feature); }
.ai-panel.local-ai-panel h3 { color: var(--feature); }

/* ---------- Peer context (inside the metrics panel) ---------- */
.peer-context {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.peer-context-lbl {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.peer-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.peer-row-lbl { flex: none; width: 84px; font-size: 0.72rem; color: var(--text-muted); }
.peer-bar-track { flex: 1; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.peer-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.peer-row-val { flex: none; font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-faint); width: 52px; text-align: right; }

/* ---------- Section (sub-topic) breakdown ---------- */
.section-breakdown {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 20px;
}
.section-breakdown h3 {
  margin: 0 0 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
}
.section-breakdown-sub { margin: 0 0 14px; font-size: 0.76rem; color: var(--text-faint); }
.sb-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sb-title {
  flex: none;
  width: 34%;
  font-size: 0.8rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sb-bar-track { flex: 1; height: 16px; border-radius: 3px; background: var(--bg); position: relative; overflow: hidden; }
.sb-bar-fill { height: 100%; background: var(--accent); opacity: 0.35; border-radius: 3px; }
.sb-bar-delta {
  position: absolute;
  left: 6px; top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--text-muted);
}
.sb-share { flex: none; width: 40px; text-align: right; font-family: var(--font-mono); font-size: 0.74rem; color: var(--text-faint); }

/* ---------- Detail layout: main column + sticky sidebar ---------- */
.detail-body {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 20px;
  align-items: start;
}
.detail-sidebar {
  /* Sticky relative to .main-panel, which is its own scroll container in
     the shell layout (there's no fixed top bar above it anymore). */
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 100vh;
}

.metrics-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.metrics-panel h3, .section-nav h3 {
  margin: 0 0 12px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
}
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 10px;
}
.metric-tile .val {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.metric-tile .val.feature-color { color: var(--feature); }
.metric-tile .delta { font-size: 0.72rem; font-weight: 600; margin-left: 4px; }
.metric-tile .delta.up { color: var(--removed-border); }
.metric-tile .delta.down { color: var(--added-border); }
.metric-tile .lbl { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); margin-top: 2px; }
.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;
}

.trend-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}
.trend-chart-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 8px;
}
.trend-chart-card h3 {
  margin: 0 0 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
}
.trend-chart-card .chart-wrap { position: relative; }
.trend-chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-gridline { stroke: var(--border); stroke-width: 1; }
.chart-dot { pointer-events: none; }
.chart-hit { cursor: pointer; }
.chart-hit:focus { outline: none; }
.chart-end-label {
  font-size: 10px;
  font-weight: 700;
  fill: var(--text);
  font-family: var(--font-mono);
}
.chart-x-label {
  font-size: 9px;
  fill: var(--text-faint);
  font-family: var(--font-mono);
}
.chart-empty { color: var(--text-faint); font-size: 0.8rem; padding: 20px 0; }
.chart-tooltip {
  position: absolute;
  top: -6px;
  transform: translate(-50%, -100%);
  background: var(--text);
  color: var(--bg);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
}

.metrics-panel .cite {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.68rem;
  color: var(--text-faint);
  line-height: 1.5;
}

.section-nav {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.section-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.section-nav li a {
  display: block;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.section-nav li a:hover { background: var(--accent-soft); color: var(--text); text-decoration: none; }
.section-nav li a.active { border-left-color: var(--accent); color: var(--accent); font-weight: 600; background: var(--accent-soft); }
.section-nav .empty-note { font-size: 0.78rem; color: var(--text-faint); }

/* ---------- Peer compare panel ---------- */
.peer-compare {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.peer-compare h3 {
  margin: 0 0 10px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
}
.peer-compare select { width: 100%; }
.peer-compare-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.8rem; }
.peer-compare-table th, .peer-compare-table td { padding: 6px 4px; text-align: right; }
.peer-compare-table th:first-child, .peer-compare-table td:first-child { text-align: left; color: var(--text-faint); font-size: 0.72rem; }
.peer-compare-table th { font-family: var(--font-mono); color: var(--text-muted); border-bottom: 1px solid var(--border); }
.peer-compare-table td { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.peer-compare-note { margin: 10px 0 0; font-size: 0.7rem; color: var(--text-faint); line-height: 1.5; }

/* ---------- Diff view (the centerpiece) ---------- */
.diff-view {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 0 10px;
  margin-bottom: 40px;
  overflow: hidden;
}
/* Each legend chip is styled as a miniature sample of its own chunk type
   (same background tint, border, glyph) so the legend explains itself by
   looking like the thing it's labeling, rather than an abstract swatch. */
.diff-legend {
  display: flex;
  gap: 10px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.legend-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.legend-glyph {
  font-family: var(--font-ui);
  font-weight: 700;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  line-height: 1;
}
.legend-count {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--text-faint);
  padding-left: 3px;
  border-left: 1px solid var(--border);
  margin-left: 1px;
  padding-left: 7px;
}
.legend-chip.added { background: var(--added-bg); border-color: var(--added-border); color: var(--added-text); }
.legend-chip.added .legend-glyph { background: var(--added-border); color: var(--bg-elevated); }
.legend-chip.removed { background: var(--removed-bg); border-color: var(--removed-border); color: var(--removed-text); }
.legend-chip.removed .legend-glyph { background: var(--removed-border); color: var(--bg-elevated); }
.legend-chip.unchanged { color: var(--text-muted); }
.legend-chip.unchanged .legend-glyph { background: var(--border); }

.diff-body {
  font-family: var(--font-prose);
  font-size: 1.02rem;
  line-height: 1.75;
  padding: 10px 0 18px;
}
.chunk {
  display: flex;
  gap: 12px;
  padding: 10px 21px;
  max-width: 78ch;
}
.chunk .glyph {
  flex: none;
  width: 18px;
  font-family: var(--font-ui);
  font-weight: 700;
  text-align: center;
  padding-top: 2px;
  user-select: none;
}
.chunk .txt { flex: 1; }
/* Added/removed chunks read as distinct redline blocks -- rounded,
   spaced apart from the surrounding prose -- rather than blending into a
   continuous column of text, so a real change never gets lost next to
   the unchanged paragraphs around it. */
.chunk.added {
  background: var(--added-bg);
  border-left: 3px solid var(--added-border);
  border-radius: 0 6px 6px 0;
  margin: 3px 21px 3px 0;
  padding: 12px 16px 12px 13px;
}
.chunk.added .glyph { color: var(--added-border); }
.chunk.added .txt { color: var(--added-text); }
.chunk.removed {
  background: var(--removed-bg);
  border-left: 3px solid var(--removed-border);
  border-radius: 0 6px 6px 0;
  margin: 3px 21px 3px 0;
  padding: 12px 16px 12px 13px;
}
.chunk.removed .glyph { color: var(--removed-border); }
.chunk.removed .txt { color: var(--removed-text); text-decoration: line-through; text-decoration-color: var(--removed-border); text-decoration-thickness: 1px; }
.chunk.unchanged { color: var(--unchanged-text); }
.chunk.unchanged .glyph { color: var(--text-faint); }
/* Section headings stick to the top of the scroll as you read through a
   long filing, like a sticky list-section header, so you always know
   which risk topic the paragraphs on screen belong to. */
.chunk.heading {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding-top: 12px;
  padding-bottom: 12px;
  scroll-margin-top: 0;
}
.chunk.heading .txt {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.94rem;
  color: var(--text);
  letter-spacing: 0.01em;
}
.chunk.heading.added .txt, .chunk.heading.removed .txt { color: inherit; }
.chunk.heading.removed .txt { text-decoration: line-through; text-decoration-color: var(--removed-border); }

/* Long runs of unchanged text collapse behind a native <details> toggle --
   accessible and keyboard-operable for free -- so the real changes aren't
   buried in a wall of grey prose. */
.unchanged-collapse { margin: 6px 21px; }
.unchanged-collapse summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border: 1px dashed var(--border);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-faint);
  user-select: none;
}
.unchanged-collapse summary::-webkit-details-marker { display: none; }
.unchanged-collapse summary::before { content: "\25B8"; display: inline-block; transition: transform 0.15s; }
.unchanged-collapse[open] summary::before { transform: rotate(90deg); }
.unchanged-collapse summary:hover { border-color: var(--accent); color: var(--text-muted); }
.unchanged-collapse-body { padding-top: 2px; }

/* Floating prev/next-change nav, pinned to the bottom of the diff as you
   scroll -- jumps straight between real added/removed chunks. */
.change-nav {
  position: sticky;
  bottom: 16px;
  width: fit-content;
  margin: 10px 24px 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
  box-shadow: var(--shadow);
  z-index: 5;
}
.change-nav[hidden] { display: none; }
.change-nav-count { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-faint); white-space: nowrap; }
.change-nav-prev, .change-nav-next {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
}
.change-nav-prev:hover, .change-nav-next:hover { border-color: var(--accent); color: var(--accent); }

.diff-body { animation: diff-in 0.25s ease both; }
@keyframes diff-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .diff-body { animation: none; }
}

/* ---------- Settings modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 10, 15, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-width: 460px;
  width: 100%;
  padding: 24px;
}
.modal h2 { margin: 0 0 6px; font-size: 1.1rem; }
.modal .sub { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 16px; line-height: 1.5; }
.modal .privacy-note {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-top: 14px;
}
.modal .field-row { display: flex; gap: 8px; margin-top: 4px; }
.modal .field-row input { flex: 1; }
.modal-actions { display: flex; justify-content: space-between; margin-top: 18px; gap: 10px; }

/* ---------- Footer / disclaimer: a slim bar pinned below the shell, always
   visible regardless of scroll position in either the rail or main panel. ---------- */
.site-footer {
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 8px 18px;
}
.disclaimer {
  font-size: 0.7rem;
  color: var(--text-faint);
  line-height: 1.5;
  margin: 0;
}
.disclaimer strong { color: var(--text-muted); }
.disclaimer a { color: var(--text-faint); text-decoration: underline; }

.loading-note, .error-note {
  color: var(--text-faint);
  padding: 40px 0;
  text-align: center;
}
.error-note { color: var(--removed-border); }

@media (max-width: 900px) {
  .detail-body { grid-template-columns: 1fr; }
  /* Sidebar comes after the diff in document order (sensible reading order
     for screen readers/no-CSS), but on a narrow screen that would bury the
     section nav and metrics below a very long diff. Visually move it above
     the diff instead -- grid `order` doesn't change DOM/tab order. */
  .detail-sidebar { position: static; max-height: none; flex-direction: row; flex-wrap: wrap; order: 1; }
  .detail-main { order: 2; }
  .metrics-panel, .section-nav { flex: 1; min-width: 240px; }
  .section-nav ul { max-height: 180px; }
}

@media (max-width: 640px) {
  /* Above 640px the sidebar wraps two panels side by side (see the 900px
     breakpoint); below it, two 240px-min-width panels no longer fit next to
     each other and would overflow the viewport instead of wrapping, so stack
     them in a single column instead. */
  .detail-sidebar { flex-direction: column; }
  .company-header { flex-direction: column; }
  .period-picker { flex-direction: column; align-items: stretch; }
  .period-arrow { display: none; }
  .timeline { margin-left: 0; }
  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
  .insight-row { grid-template-columns: 1fr; }
  .top-changes-grid { grid-template-columns: 1fr; }
  .chunk { padding: 10px 16px; max-width: none; }
  .chunk.added, .chunk.removed { margin: 3px 16px 3px 0; padding: 10px 12px 10px 10px; }
  .unchanged-collapse { margin: 6px 16px; }
  .change-nav { margin-right: 16px; }
  .diff-legend { padding: 12px 16px; }
  .hero h1 { font-size: 1.7rem; }
  .trend-charts { grid-template-columns: 1fr; }
}
