:root {
  --bg: #0a0e13;
  --surface: #111823;
  --surface-raised: #161f2c;
  --hairline: #212d3d;
  --text: #e7ecf2;
  --text-muted: #7c8ca0;
  --text-faint: #4c5b70;
  /* Categorical chart/accent colors - validated against this dark surface
     (#111823) with the dataviz skill's validator (OKLCH lightness band,
     CVD-safe adjacent separation, >=3:1 contrast). The originals (#42e8d6
     etc.) all measured L 0.70-0.84, well outside the dark-mode 0.48-0.67
     band - too light/washed-out, not just a stylistic quibble. */
  --cyan: #199e70;
  --violet: #9085e9;
  --amber: #c98500;
  --coral: #e66767;
  /* Dedicated "Other/fold-in" series color - deliberately low-chroma (reads
     as muted by design, unlike the 4 colors above), but still >=3:1 against
     the surface, unlike the old #7c8ca0 UI-text color it used to borrow. */
  --other-muted: #64748b;
  /* Single accent for ranked-bar-list widgets (Customers per AI Bot, Top
     Regions, Business Vertical) - bar length + label already encode rank,
     so cycling a rainbow of unrelated hues per row was a false categorical
     signal (item 8 re-using item 1's color implied a shared identity that
     doesn't exist). One consistent hue - bar length + label carry the
     ranking. */
  --rank-accent: #3987e5;
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }

/* Left tab nav (AI Bot Radar / Bot vs Human Traffic) + the existing content
   column, side by side below the full-width header. Sticky so the tabs stay
   reachable while scrolling a long dashboard - same "top" as .controls
   below, which already does this for the time-range chips. */
.app-body { display: flex; align-items: flex-start; }
.side-nav {
  flex: 0 0 220px;
  display: flex; flex-direction: column; gap: 4px;
  padding: 24px 12px;
  position: sticky; top: 0; height: 100vh;
  border-right: 1px solid var(--hairline);
}
.side-nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent; background: transparent; color: var(--text-muted);
  font-family: var(--font-body); cursor: pointer;
}
.side-nav-item:hover { color: var(--text); background: var(--surface-raised); }
.side-nav-item.active { color: var(--cyan); background: rgba(25,158,112,0.14); border-color: var(--cyan); }
.app-body > .wrap { flex: 1; min-width: 0; max-width: none; margin: 0; }
@media (max-width: 900px) {
  .app-body { flex-direction: column; }
  .side-nav { flex-direction: row; position: static; height: auto; width: 100%; border-right: none; border-bottom: 1px solid var(--hairline); }
}

header {
  border-bottom: 1px solid var(--hairline);
  position: relative;
  overflow: hidden;
}
header .glow {
  position: absolute; top: -120px; right: -80px; width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(circle, rgba(25,158,112,0.12) 0%, rgba(25,158,112,0) 70%);
  pointer-events: none;
}
header .inner {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px;
  padding: 20px 0; position: relative;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 36px; height: 36px; border-radius: 10px; background: rgba(25,158,112,0.14);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.brand-title { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.status { display: flex; align-items: center; gap: 16px; }
.status .live { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); animation: pulse 2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(25,158,112,0.6); }
  70% { box-shadow: 0 0 0 6px rgba(25,158,112,0); }
  100% { box-shadow: 0 0 0 0 rgba(25,158,112,0); }
}
button.refresh {
  display: flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 8px; font-size: 13px;
  border: 1px solid var(--hairline); background: var(--surface); color: var(--text); cursor: pointer;
}
button.refresh:hover { border-color: var(--cyan); }
.spin { display:inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.controls {
  display: flex; align-items: center; justify-content: flex-start; flex-wrap: wrap; gap: 12px;
  margin: 0 0 24px; padding: 14px 0; position: sticky; top: 0; z-index: 50;
  background: var(--bg); border-bottom: 1px solid var(--hairline);
}
.controls-label { font-size: 12px; color: var(--text-muted); margin-right: 4px; }

/* Non-blocking status banner (warming-up / refreshing / partial / error).
   Tinted by state via a modifier class; neutral (info) by default. */
.notice {
  margin: 0 0 20px; padding: 12px 16px; border-radius: 10px; font-size: 13px;
  border: 1px solid var(--hairline); background: var(--surface); color: var(--text-muted);
  display: flex; align-items: center; gap: 10px;
}
.notice::before { content: "ⓘ"; font-size: 14px; opacity: 0.8; }
.notice.working { border-color: rgba(25,158,112,0.4); color: var(--cyan); }
.notice.working::before { content: "⟳"; animation: spin 1s linear infinite; }
.notice.warn { border-color: rgba(201,133,0,0.4); color: var(--amber); }
.notice.warn::before { content: "⚠"; }
.notice.error { border-color: rgba(230,103,103,0.4); color: var(--coral); }
.notice.error::before { content: "⚠"; }
.chips { display: flex; align-items: center; gap: 8px; }
.chip {
  padding: 7px 16px; font-size: 13px; font-weight: 500; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--hairline); background: transparent; color: var(--text-muted); font-family: var(--font-body);
}
.chip.active { border-color: var(--cyan); background: rgba(25,158,112,0.14); color: var(--cyan); }

section { margin-bottom: 30px; }
.section-title { font-family: var(--font-display); font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.section-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px; padding: 18px;
}
/* Sections mix full-width cards with paired grids - space direct children
   uniformly regardless of which shape they are, so a full-width hero chart
   and a grid-2 pair below it get the same rhythm. */
section > .card, section > .grid-2, section > .grid-3, section > .grid-hero, section > .kpi-grid {
  margin-bottom: 16px;
}
section > .card:last-child, section > .grid-2:last-child, section > .grid-3:last-child, section > .grid-hero:last-child, section > .kpi-grid:last-child {
  margin-bottom: 0;
}
.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.kpi-value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; margin: 6px 0 4px; }
.kpi-delta { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.kpi-delta.up { color: var(--cyan); }
.kpi-delta.down { color: var(--coral); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
/* Small ratio/summary widget beside a larger detail chart - an asymmetric
   pairing instead of forcing every two widgets into equal halves. */
.grid-hero { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-hero { grid-template-columns: 1fr; }
}

/* Charts fill their card's width. Without an explicit width a <canvas>
   falls back to its intrinsic 300px, leaving every chart in the left third
   of its card - setupCanvas() in charts.js also sets this, this is the
   pre-JS/first-paint guarantee. */
canvas { width: 100%; max-height: 400px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--hairline); }
td { padding: 9px 10px; border-bottom: 1px solid var(--hairline); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-verified { color: var(--cyan); display:flex; align-items:center; gap:4px; font-size:12px; }
.badge-unverified { color: var(--amber); display:flex; align-items:center; gap:4px; font-size:12px; }
.bar-track { flex: 1; height: 6px; border-radius: 3px; background: var(--hairline); overflow: hidden; }
.bar-fill { height: 100%; }
.row-flex { display: flex; align-items: center; gap: 8px; }

.growth-list { display: flex; flex-direction: column; gap: 10px; }
.growth-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--surface-raised); border-radius: 8px; }
.growth-name { font-weight: 600; font-size: 13px; }
.growth-pct { font-family: var(--font-mono); font-size: 14px; }
.growth-pct.up { color: var(--cyan); }
.growth-pct.down { color: var(--coral); }

.legend-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Bold color-coded number callouts under a chart title, read at a glance
   without hovering - e.g. "AI Bots  8.1%" in the series color, big and bold.
   Replaces a plain dot+text legend wherever a widget's headline numbers are
   worth surfacing directly. */
.stat-legend { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 14px; row-gap: 12px; }
.stat-legend-item { display: flex; flex-direction: column; gap: 5px; }
.stat-legend-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.stat-legend-value { font-family: var(--font-mono); font-size: 21px; font-weight: 700; }

/* Compact stat tile - a big headline number + meter + raw-value legend,
   for a binary/simple split that doesn't earn a full-size donut. When it's
   paired in a grid row with a taller chart card, center the content block
   vertically so the tile reads as intentional rather than top-weighted with
   a void below (the grid stretches both cards to the taller one's height). */
#card-ai-share-tile { display: flex; flex-direction: column; justify-content: center; }
.stat-tile-label { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.stat-tile-value { font-family: var(--font-mono); font-size: 34px; font-weight: 700; line-height: 1; margin-bottom: 8px; }
.stat-tile-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }
.meter-track { height: 10px; border-radius: 5px; background: var(--hairline); overflow: hidden; margin-bottom: 16px; }
.meter-fill { height: 100%; }
.tile-legend { display: flex; flex-direction: column; gap: 10px; }
.tile-legend-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--text-muted); }
.tile-legend-value { font-family: var(--font-mono); color: var(--text); }

.footnote { font-size: 11px; color: var(--text-faint); text-align: center; padding: 20px 0; }

canvas { display: block; }

.chart-tooltip {
  position: fixed;
  display: none;
  background: #0d1420;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  pointer-events: none;
  z-index: 9999;
  max-width: 260px;
}
.chart-tooltip-title { font-weight: 600; margin-bottom: 6px; color: var(--text); }
.chart-tooltip-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; color: var(--text-muted); }
.chart-tooltip-row strong { color: var(--text); font-family: var(--font-mono); font-weight: 600; margin-left: auto; padding-left: 10px; }
.chart-tooltip-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex-shrink: 0; }

/* ---- AI-Generated Insight panel (deterministic, templated from real numbers
   in server/metrics.js buildInsights; see CLAUDE.md - never LLM-invented) ---- */
.insight {
  margin-top: 16px;
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--violet);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(144,133,233,0.06), rgba(144,133,233,0.02));
  padding: 14px 16px;
}
.insight[hidden] { display: none; }
.insight-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.8px;
  color: var(--violet); margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.insight-body { font-size: 14px; line-height: 1.55; color: var(--text); }
.insight-body strong { font-weight: 700; }
.insight-meta { font-size: 11px; color: var(--text-faint); margin-top: 10px; }

/* ---- Toggle legend for the per-bot daily trend (click a bot to show/hide) ---- */
.toggle-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toggle-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--hairline); background: var(--surface-raised);
  color: var(--text); font-family: var(--font-body); font-size: 12px;
  transition: opacity 0.12s ease;
}
.toggle-chip.off { opacity: 0.4; text-decoration: line-through; }
.toggle-chip:hover { border-color: var(--text-faint); }

/* ---- AI Bots in Coverage roster ---- */
.roster-head { display: flex; align-items: baseline; gap: 20px; flex-wrap: wrap; margin-bottom: 14px; }
.roster-stat { display: flex; align-items: baseline; gap: 10px; }
.roster-num { font-size: 40px; font-weight: 700; line-height: 1; color: var(--text); }
.roster-lbl { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.roster-active { font-size: 13px; color: var(--text-muted); }
.roster-active b { color: var(--text); font-weight: 700; }
.roster-muted { color: var(--text-faint); font-weight: 400; }
.roster-cats { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 14px; }
.roster-catcount { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.roster-catcount b { color: var(--text); font-weight: 700; }
.roster-toggle {
  border: 1px solid var(--hairline); background: transparent; color: var(--text-muted);
  font-family: var(--font-body); font-size: 12px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.roster-toggle:hover { border-color: var(--text-faint); color: var(--text); }
.roster-list { margin-top: 16px; display: flex; flex-direction: column; gap: 16px; }
.roster-list[hidden] { display: none; }
.roster-group-title { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; }
.roster-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.roster-chip {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--hairline); background: var(--surface-raised);
  color: var(--text); font-size: 12px;
}
.roster-chip.dim { opacity: 0.4; }
