/*
 * Theme. The page follows the viewer's choice (the toggle in the top bar, remembered in the browser), and
 * their system setting until they choose. The accent is #E63968. Text and links use a deeper pink in light mode
 * and a lighter one in dark mode, because the exact accent is a little too pale to read as small text on
 * the light page. Change a colour here and the whole app follows.
 */
:root,
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.045);
  --series: #e63968;
  --series-hover: #c4264f;
  --context: #c3c2b7;
  --accent: #e63968;
  --accent-hover: #d12c5b;
  --on-accent: #0b0b0b; /* white on #E63968 is 4.1:1, under the 4.5:1 minimum; near-black is 4.8:1 */
  --accent-ink: #c4264f;
  --accent-wash: rgba(230, 57, 104, 0.1);
  --meter-track: #fbd5e0;
  --critical: #d03b3b;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a09e97;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.06);
    --series: #e63968;
    --series-hover: #ff7a9c;
    --context: #5a5954;
    --accent: #e63968;
    --accent-hover: #f0527b;
    --on-accent: #0b0b0b;
    --accent-ink: #ff7a9c;
    --accent-wash: rgba(230, 57, 104, 0.18);
    --meter-track: #4a1526;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a09e97;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.06);
    --series: #e63968;
    --series-hover: #ff7a9c;
    --context: #5a5954;
    --accent: #e63968;
    --accent-hover: #f0527b;
    --on-accent: #0b0b0b;
    --accent-ink: #ff7a9c;
    --accent-wash: rgba(230, 57, 104, 0.18);
    --meter-track: #4a1526;
  }
}

/* Category label colours. One hue per category; the label text always says what it is, so colour is only a cue. */
.cat-product { --c: #2f7de1; }
.cat-finance { --c: #1e9e6a; }
.cat-marketing { --c: #ee7d2b; }
.cat-technology { --c: #7c5ce6; }
.cat-deals { --c: #14a3b8; }
.cat-people { --c: #c9971a; }
.cat-legal { --c: #c0453b; }
.cat-operations { --c: #64748b; }
.cat-sustainability { --c: #7ba318; }
.cat-health { --c: #b04fc7; }
.cat-general { --c: #8a8a85; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; border-radius: 4px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 24px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 6px 10px; border-radius: 6px; z-index: 10; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Top bar */
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 12px; min-width: 0; color: var(--ink); }
.brand-text { display: grid; min-width: 0; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: 0.14em; }
.brand-sub { margin-top: 3px; font-size: 10.5px; letter-spacing: 0.04em; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand:hover { text-decoration: none; }
.brand-tile { fill: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 12px; flex: none; }
.theme-toggle { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--ink-2); cursor: pointer; }
.theme-toggle:hover { background: var(--wash); color: var(--ink); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.login { max-width: 380px; margin: 48px auto 0; display: grid; gap: 14px; }
.login h1 { font-size: 20px; font-weight: 600; }
.login .sub { color: var(--ink-2); }
.login form { display: grid; gap: 12px; }
.status { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.status:empty { display: none; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--series); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

main { padding-top: 28px; padding-bottom: 72px; outline: none; }
main.is-refreshing > * { opacity: 0.7; }

/* Page header */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
.page-head .sub { color: var(--ink-2); margin-top: 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back { display: inline-block; margin-bottom: 10px; color: var(--ink-2); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font-weight: 500; text-decoration: none;
}
.btn:hover { background: var(--wash); text-decoration: none; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--critical); border-color: transparent; color: #fff; }
.btn-danger:hover { background: var(--critical); filter: brightness(0.92); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); padding: 0 8px; }
.btn-small { min-height: 28px; padding: 0 10px; font-size: 13px; }

/* Cards and tiles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 14px; }
.card-head h2 { font-size: 14px; font-weight: 600; }
.card-head .hint { color: var(--muted); font-size: 12px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; margin-top: 16px; }
@media (min-width: 860px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.stack { margin-top: 16px; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.tile-label { color: var(--ink-2); font-size: 13px; }
.tile-value { font-size: 28px; line-height: 1.2; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.tile-note { color: var(--ink-2); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
.delta { display: inline-flex; align-items: center; gap: 4px; }

/* Chips */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--wash); color: var(--ink-2); white-space: nowrap; }
.chip-accent { background: var(--accent-wash); color: var(--accent-ink); }
.chip-cat { background: var(--accent-wash); color: var(--accent-ink); font-weight: 500; }
.chip-cat[class*="cat-"] {
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  color: color-mix(in srgb, var(--c) 60%, var(--ink));
}
.chip-cat.is-general { font-weight: 400; }
.chip-btn { border: 0; cursor: pointer; font: inherit; font-size: 12px; line-height: inherit; }
.chip-btn:hover { filter: brightness(1.12); text-decoration: underline; }
.feed .byline { align-items: center; }
.chip-query { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

/* Range filter (one row above the charts) */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; }
.filters .label { color: var(--ink-2); font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 0 14px; min-height: 32px; cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--wash); }
.seg button[aria-pressed="true"] { color: var(--ink); font-weight: 600; background: var(--accent-wash); }
.seg button[aria-pressed="true"]::before { content: "✓"; font-weight: 700; color: var(--accent-ink); }
.seg-small button { min-height: 26px; padding: 0 10px; font-size: 13px; }

/* Topic cards */
.topic-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.topic-card { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.topic-card h2 { font-size: 16px; font-weight: 600; line-height: 1.3; }
.topic-card h2 a { color: var(--ink); }
.topic-card .meta { color: var(--muted); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.topic-top > div:first-child { min-width: 0; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.topic-figure { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.big { font-size: 32px; line-height: 1.1; font-weight: 600; letter-spacing: -0.02em; }
.big-label { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.topic-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--grid); padding-top: 10px; color: var(--ink-2); font-size: 12px; margin-top: auto; }
.topic-foot dl { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; }
.topic-foot dt { display: inline; color: var(--muted); }
.topic-foot dd { display: inline; margin: 0 0 0 4px; color: var(--ink); font-weight: 500; }
.spark { display: block; flex: none; }
.spark .past { fill: var(--context); }
.spark .now { fill: var(--series); }

/* Charts */
.chart-wrap { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series); }
.chart .bar.partial { opacity: 0.55; }
.chart .bar.is-active { fill: var(--series-hover); opacity: 1; }
.chart .peak { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:focus-visible { outline: none; stroke: var(--accent-ink); stroke-width: 2; }
.chart-note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.empty-chart { color: var(--ink-2); padding: 40px 0; text-align: center; }

.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); }
.data-table th { color: var(--ink-2); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
.data-table td:last-child, .data-table th:last-child { text-align: right; }
.table-scroll { max-height: 280px; overflow: auto; }

/* Horizontal bar lists */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.bar-row {
  display: grid; grid-template-columns: minmax(0, 38%) 1fr; align-items: center; gap: 12px;
  width: 100%; padding: 5px 8px; margin: 0 -8px; border: 0; background: transparent; border-radius: 6px;
  text-align: left; cursor: pointer; width: calc(100% + 16px);
}
.bar-row:hover, .bar-row[aria-pressed="true"] { background: var(--wash); }
.bar-row[aria-pressed="true"] .bar-name { font-weight: 600; }
.bars.wide .bar-row { grid-template-columns: minmax(0, 54%) 1fr; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-fill { height: 10px; border-radius: 0 4px 4px 0; background: var(--series); width: calc(var(--w) * (100% - 44px)); min-width: 2px; flex: none; }
.bar-row[class*="cat-"] .bar-fill { background: color-mix(in srgb, var(--c) 85%, var(--ink)); }
.bar-value { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 12px; flex: none; }
.empty { color: var(--ink-2); padding: 8px 0; }

/* Headline feed */
.feed-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.input, .select {
  min-height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); width: 100%;
}
.feed-tools .input { flex: 1 1 220px; width: auto; }
.feed-tools .select { flex: 0 1 220px; width: auto; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 10px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--grid); }
.feed li:first-child { border-top: 0; }
.feed li.no-dot { grid-template-columns: 1fr; }
.feed .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; }
.feed .dot.new { background: var(--series); }
.feed a.title { color: var(--ink); font-weight: 500; }
.feed a.title:hover { color: var(--accent-ink); }
.feed .byline { color: var(--ink-2); font-size: 12px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 2px 8px; }
.feed .snippet { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.more { display: flex; justify-content: center; margin-top: 12px; }

/* Banners and meters */
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); }
.banner .icon { flex: none; width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; background: var(--series); margin-top: 1px; }
.banner.error { border-color: var(--critical); }
.banner.error .icon { background: var(--critical); }
.banner strong { font-weight: 600; }
.meter { height: 6px; border-radius: 3px; background: var(--meter-track); overflow: hidden; margin-top: 6px; width: 100%; max-width: 260px; }
.meter > span { display: block; height: 100%; background: var(--series); width: calc(var(--p) * 100%); }

/* Empty state */
.hero-empty { text-align: center; padding: 56px 24px; }
.hero-empty h2 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.hero-empty p { color: var(--ink-2); max-width: 520px; margin: 0 auto 18px; }

/* Dialogs */
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 0; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-body { padding: 22px 24px 8px; display: grid; gap: 14px; }
.dialog-body h2 { font-size: 18px; font-weight: 600; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px 20px; }
.field { display: grid; gap: 4px; }
.field label, .field .label { font-weight: 500; }
.field .help { color: var(--ink-2); font-size: 12px; }
.field .check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-top: 8px; }
.help.note { padding: 8px 12px; background: var(--wash); border-radius: 8px; color: var(--ink-2); font-size: 12px; }
.field details summary { cursor: pointer; font-weight: 500; }
.field details[open] summary { margin-bottom: 8px; }
.form-error { color: var(--ink); font-size: 13px; padding: 8px 12px; border-left: 3px solid var(--critical); background: var(--wash); border-radius: 4px; }
.form-error:empty { display: none; }

/* Tooltip (chart hover and focus) */
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14); font-size: 12px; transform: translate(-50%, -100%); white-space: nowrap; }
.tooltip[hidden] { display: none; }
.tooltip .tv { font-size: 14px; font-weight: 600; display: block; }
.tooltip .tl { color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--page); padding: 8px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 30; }
.toast.show { opacity: 1; }

@media (max-width: 560px) {
  .status { font-size: 0; } /* just the pulsing dot; the page itself says what is loading */
  .brand-name { font-size: 16px; }
  .wrap { padding: 0 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 24px; }
  .bar-row { grid-template-columns: minmax(0, 45%) 1fr; }
}
@media (forced-colors: active) {
  .chart .bar, .bar-fill, .spark rect { forced-color-adjust: none; fill: CanvasText; background: CanvasText; }
}
