/* Discovery dashboard — warm, calm, editorial-analytics.
   Tokens and rules follow the design brief in the "SEO/AEO growth pages"
   design project (Discovery.dc.html): flat surfaces, hairline borders, one
   terracotta accent, dataviz palette separate from UI accent, no shadows,
   no gradients, no gauges, sentence case. */

:root {
  --canvas: #FAF7F1;
  --surface: #FFFFFF;
  --ink: #26221C;
  --ink-2: #6B655C;
  --hairline: #E7E1D6;
  --hairline-soft: #EFEADF;
  --terracotta: #C05B33;
  --terracotta-deep: #8A3E20;
  --terracotta-tint: #FBEEE8;
  --terracotta-tint-border: #E7CFC2;
  --sidebar-bg: #FCFAF5;
  --hover: #F1EBE0;
  --row-hover: #FBF9F4;
  --chip-bg: #F1EBE0;
  --series-1: #2A78D6; /* organic / primary / treated */
  --series-2: #EB6834; /* AI referrals */
  --series-3: #1BAF7A; /* direct */
  --series-neutral: #8A867D;
  --ramp-1: #EAF2FC;
  --ramp-2: #B5D4F4;
  --ramp-3: #85B7EB;
  --ramp-4: #378ADD;
  --ramp-5: #185FA5;
  --up: #1E7F3C;
  --down: #C23B2E;
  --caution: #B97F1A;
  --caution-bg: #F6EFDD;
  --caution-border: #E7D6AE;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-feature-settings: 'tnum' 1;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--terracotta-deep); text-decoration: none; }
a:hover { color: var(--terracotta); }

.layout { display: flex; height: 100vh; overflow: hidden; }

/* ---------- sidebar ---------- */

.sidebar {
  width: 220px;
  flex: none;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--hairline);
}

.wordmark { padding: 20px 18px 14px; }
.wordmark-row { display: flex; align-items: center; gap: 9px; }
.wordmark-dot {
  width: 20px; height: 20px; border-radius: 6px;
  background: var(--terracotta);
  display: flex; align-items: center; justify-content: center;
}
.wordmark-dot::after {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--sidebar-bg);
}
.wordmark-name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.wordmark-sub { font-size: 11px; color: var(--ink-2); margin-top: 3px; padding-left: 29px; }

.switcher { padding: 0 14px 12px; position: relative; }
.switcher-btn {
  width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; background: var(--surface);
  border: 1px solid var(--hairline); border-radius: 8px;
  cursor: pointer; text-align: left; font: inherit; color: inherit;
}
.switcher-btn:hover { background: var(--hover); }
.switcher-initial {
  width: 22px; height: 22px; border-radius: 6px; background: #EFE7DA;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--terracotta-deep); flex: none;
}
.switcher-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.switcher-tag {
  font-size: 10.5px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.switcher-caret { color: var(--ink-2); font-size: 11px; margin-left: auto; }
.switcher-menu {
  position: absolute; left: 14px; right: 14px; top: 52px; z-index: 40;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 8px; padding: 5px;
  box-shadow: 0 8px 24px rgba(38, 34, 28, 0.10);
}
.switcher-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 8px; border: 0; background: none; border-radius: 6px;
  cursor: pointer; text-align: left; font: inherit; color: inherit;
}
.switcher-item:hover { background: var(--hover); }
.switcher-check { margin-left: auto; color: var(--terracotta); font-size: 11px; }

.nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 7px; cursor: pointer;
  color: var(--ink); font-size: 13.5px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active {
  color: var(--terracotta);
  font-weight: 600;
  border-left-color: var(--terracotta);
  border-radius: 0 7px 7px 0;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-eyebrow {
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: #A69E90; padding: 14px 12px 6px;
}

.sidebar-foot {
  padding: 12px 16px; border-top: 1px solid var(--hairline);
  font-family: var(--mono); font-size: 10px; color: var(--ink-2);
  line-height: 1.5;
}

/* ---------- main ---------- */

.main { flex: 1; height: 100vh; overflow-y: auto; }

.page-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(250, 247, 241, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--hairline);
  padding: 20px 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.page-title { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.page-subtitle { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.run-stamp {
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  background: var(--chip-bg); border-radius: 999px; padding: 6px 12px;
  white-space: nowrap;
}

.content { padding: 28px 32px 56px; max-width: 1280px; }

/* ---------- cards & grids ---------- */

.grid { display: grid; gap: 20px; margin-bottom: 22px; }
.grid-kpi { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; gap: 22px; }
.grid-main-side { grid-template-columns: 1.9fr 1fr; gap: 22px; }
.grid-side-main { grid-template-columns: 1fr 1.9fr; gap: 22px; }

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 20px;
  min-width: 0;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.card-body { margin-top: 14px; }

.kpi { padding: 18px 20px; }
.kpi-label { font-size: 13px; color: var(--ink-2); }
.kpi-row { display: flex; align-items: baseline; gap: 9px; margin-top: 9px; }
.kpi-value { font-size: 28px; font-weight: 600; letter-spacing: -0.015em; line-height: 1; }
.kpi-context { font-size: 12px; color: var(--ink-2); margin-top: 9px; }

.delta { font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--ink-2); font-weight: 400; }

/* ---------- tables & rows ---------- */

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  text-align: left; font-weight: 500; font-size: 10.5px;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2);
  padding: 0 8px 8px 0;
}
th.num, td.num { text-align: right; padding-right: 0; }
td { padding: 11px 8px 11px 0; border-top: 1px solid var(--hairline-soft); }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--row-hover); }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 11px; color: var(--ink-2); }
.mono { font-family: var(--mono); font-size: 11.5px; }

.list-row {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 0; border-top: 1px solid var(--hairline-soft);
}
.list-row:first-child { border-top: 0; }

/* ---------- chips, pills, banners ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; border-radius: 999px; padding: 3px 10px;
  background: var(--chip-bg); color: var(--ink-2);
  font-family: var(--mono);
  white-space: nowrap;
}
.pill.caution {
  background: var(--caution-bg); color: var(--caution);
  border: 1px solid var(--caution-border);
}
.pill.accent {
  background: var(--terracotta-tint); color: var(--terracotta-deep);
  border: 1px solid var(--terracotta-tint-border);
}

.banner {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; color: var(--caution);
  background: var(--caution-bg); border: 1px solid var(--caution-border);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 22px;
}

.placeholder-note {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11px; color: var(--caution);
  background: var(--caution-bg); border: 1px solid var(--caution-border);
  border-radius: 999px; padding: 4px 11px;
}

/* ---------- empty states ---------- */

.empty {
  border: 1px dashed var(--hairline);
  border-radius: 8px;
  padding: 18px;
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.55;
  background: var(--canvas);
}
.empty .empty-title {
  font-weight: 600; color: var(--ink); font-size: 12.5px; margin-bottom: 4px;
}

/* ---------- source links footer ---------- */

.sources {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 4px;
}
.source-link {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; border: 1px solid var(--hairline);
  border-radius: 999px; padding: 6px 12px; background: var(--surface);
}
.source-link .dot { width: 6px; height: 6px; border-radius: 50%; }
.source-link .dot.fresh { background: var(--up); }
.source-link .dot.stale { background: var(--caution); }
.source-link .dot.missing { background: var(--down); }
.source-link .age { font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); }

/* ---------- charts ---------- */

.chart svg { display: block; width: 100%; height: auto; }
.legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 11px; color: var(--ink-2); margin-top: 10px;
}
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 16px; height: 0; border-top-width: 2px; border-top-style: solid; }
.legend .swatch.square { width: 10px; height: 10px; border: 0; border-radius: 2px; }

.axis-label { font-size: 11px; fill: var(--ink-2); }

.bar-label { font-size: 12px; fill: var(--ink); }

/* Tooltip text is plain textContent (never innerHTML — see app.js);
   newlines in the tip string become line breaks via pre-line. */
.tooltip {
  position: fixed; z-index: 80; pointer-events: none;
  background: var(--ink); color: #FCFAF5;
  font-size: 11.5px; line-height: 1.5;
  border-radius: 6px; padding: 7px 10px;
  max-width: 320px;
  white-space: pre-line;
  font-feature-settings: 'tnum' 1;
  opacity: 0; transition: opacity 0.08s ease;
}
.tooltip.on { opacity: 1; }

/* ---------- misc ---------- */

.loading { padding: 60px 32px; }
.skeleton {
  height: 13px; border-radius: 4px; background: var(--hairline-soft);
  margin-bottom: 12px;
}

.footnote { font-size: 11.5px; color: var(--ink-2); margin-top: 12px; line-height: 1.5; }

@media (max-width: 1100px) {
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-main-side, .grid-side-main { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  /* No overflow on the sidebar itself: a scroll container clips absolutely
     positioned children, which swallowed the project-switcher dropdown.
     Only the nav strip scrolls; the dropdown becomes a fixed overlay. */
  .sidebar { width: 100%; height: auto; flex-direction: row; align-items: center; }
  .wordmark { padding: 12px; flex: none; }
  .wordmark-sub, .sidebar-foot, .nav-eyebrow { display: none; }
  .switcher { padding: 0 8px; width: 200px; flex: none; }
  .switcher-menu {
    position: fixed; left: 12px; right: 12px; top: 60px;
    max-height: 70vh; overflow-y: auto;
  }
  .nav { display: flex; padding: 8px; overflow-x: auto; min-width: 0; }
  .nav-item { white-space: nowrap; }
  .main { height: auto; }
  .grid-kpi { grid-template-columns: 1fr; }
  .content { padding: 20px 16px 48px; }
  .page-header { padding: 14px 16px; }
}
