:root {
  --magenta: #e30168;
  --teal: #009688;
  --blue: #0170b9;
  --amber: #f59e0b;
  --red: #e11d48;
  --bg: #ffffff;
  --ink: #2b2b30;
  --muted: #5c6470; /* darkened for WCAG AA contrast on white */
  --line: #e7e7ee;
  --soft: #f6f6fb;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.05), 0 6px 20px rgba(20, 20, 40, 0.05);
  --radius: 14px;
}
* { box-sizing: border-box; }
/* Ensure the HTML `hidden` attribute always wins over display:flex/grid rules below. */
[hidden] { display: none !important; }
html, body {
  margin: 0;
  background: var(--soft);
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em; background: var(--soft); padding: 1px 6px; border-radius: 6px; color: var(--blue);
}

/* Top bar */
.topbar { background: var(--bg); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 20px; flex-wrap: wrap; }
.brandline { display: flex; align-items: center; gap: 12px; }
.brandline .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--magenta); box-shadow: 0 0 0 4px rgba(227, 1, 104, 0.14); }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 900; letter-spacing: -0.2px; }
.tagline { margin: 2px 0 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.meta { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 12px; font-weight: 800; padding: 6px 10px; border-radius: 999px; background: rgba(227, 1, 104, 0.1); color: var(--magenta); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pill.ghost { background: var(--soft); color: var(--muted); }
.pill.source { background: rgba(0, 150, 136, 0.12); color: var(--teal); font-family: inherit; }

.sectionnav { display: flex; gap: 2px; flex-wrap: wrap; padding: 0 20px 10px; }
.sectionnav a { font-size: 12.5px; font-weight: 800; color: var(--muted); text-decoration: none; padding: 6px 11px; border-radius: 8px; transition: background 0.12s, color 0.12s; }
.sectionnav a:hover { background: var(--soft); color: var(--magenta); }
.sectionnav a.active { background: rgba(227, 1, 104, 0.1); color: var(--magenta); }

main.wrap { padding-top: 22px; padding-bottom: 64px; }
.updated { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.updated .live { color: var(--teal); }

/* Date-range toolbar */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 18px; }
.tb-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-right: 4px; }
.tb-btn { font-family: inherit; font-size: 13px; font-weight: 800; color: var(--ink); background: var(--soft); border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; cursor: pointer; transition: all 0.12s; }
.tb-btn:hover { border-color: var(--magenta); color: var(--magenta); }
.tb-btn.active { background: var(--magenta); border-color: var(--magenta); color: #fff; }
.tb-btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.tb-btn.primary:hover { filter: brightness(0.95); color: #fff; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.tb-arrow { color: var(--muted); font-weight: 800; }
.toolbar input[type='date'] { font-family: inherit; font-size: 13px; font-weight: 700; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; }
.tb-loading { font-size: 12px; font-weight: 800; color: var(--teal); margin-left: 4px; }

/* Segment (drill-down) bar */
.segbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: rgba(227,1,104,0.06); border: 1px solid rgba(227,1,104,0.25); border-radius: var(--radius); padding: 11px 14px; margin-bottom: 18px; }
.seg-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: var(--magenta); }
.seg-chip { font-size: 13px; font-weight: 900; color: #fff; background: var(--magenta); padding: 4px 12px; border-radius: 999px; }
.seg-clear { font-family: inherit; font-size: 12.5px; font-weight: 800; color: var(--magenta); background: #fff; border: 1px solid rgba(227,1,104,0.3); border-radius: 9px; padding: 6px 11px; cursor: pointer; }
.seg-clear:hover { background: var(--magenta); color: #fff; }
.seg-hint { font-size: 12px; color: var(--muted); font-weight: 600; }

/* Clickable affordances */
table#contentTable tbody tr { cursor: pointer; }
.clickable-note { font-size: 11.5px; color: var(--muted); font-weight: 700; margin-top: 8px; }

.section-title { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.7px; color: var(--ink); margin: 34px 2px 14px; padding-top: 6px; scroll-margin-top: 130px; }
.section-title::before { content: ''; width: 4px; height: 18px; border-radius: 3px; background: var(--magenta); flex: 0 0 auto; }
.section-title small { text-transform: none; letter-spacing: 0; font-weight: 700; color: var(--muted); font-size: 13px; }

/* KPI cards */
.cards { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
.card { position: relative; background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px; overflow: hidden; }
.card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--line); }
.card .label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.card .value { font-size: 28px; font-weight: 900; letter-spacing: -1px; margin-top: 6px; line-height: 1; }
.card .value small { font-size: 14px; font-weight: 800; color: var(--muted); }
.card .sub { font-size: 11px; color: var(--muted); margin-top: 6px; font-weight: 700; }
.card.accent .value { color: var(--magenta); }
.card.accent::before { background: var(--magenta); }
.card.teal .value { color: var(--teal); }
.card.teal::before { background: var(--teal); }
/* Hero metric (engagement rate) gets visual priority */
.card.hero { box-shadow: 0 2px 4px rgba(227,1,104,0.1), 0 10px 28px rgba(227,1,104,0.1); }
.card.hero .value { font-size: 32px; }

/* Panels */
.panel { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.panel-head { margin-bottom: 2px; }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 900; }
.panel-head h3 small { font-weight: 700; color: var(--muted); font-size: 12px; }
.panel-head .sub { margin: 6px 0 0; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.sub b { color: var(--ink); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }

.chart-box { position: relative; height: 280px; margin-top: 12px; }
.chart-box.sm { height: 220px; }
canvas { max-width: 100%; }

/* Tables */
.table-scroll { overflow-x: auto; margin-top: 12px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); font-weight: 800; cursor: pointer; user-select: none; }
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--soft); }
table.data tr.best { background: rgba(0, 150, 136, 0.08); }
table.data tr.best td:first-child { box-shadow: inset 3px 0 0 var(--teal); font-weight: 900; }
.tag { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; }
.tag.meta { background: rgba(1, 112, 185, 0.12); color: var(--blue); }
.tag.google { background: rgba(227, 1, 104, 0.1); color: var(--magenta); }
.tag.reddit { background: rgba(255, 86, 0, 0.12); color: #d94600; }
.tag.other { background: var(--soft); color: var(--muted); }
.tag.warn { background: rgba(225, 29, 72, 0.1); color: var(--red); }
.tag.ok { background: rgba(0, 150, 136, 0.12); color: var(--teal); }
.bestbadge { font-size: 11px; font-weight: 900; color: var(--teal); margin-left: 8px; }
.empty { margin: 16px 4px 4px; font-size: 14px; color: var(--muted); }

.channel-status { list-style: none; margin: 14px 0 0; padding: 0; font-size: 13px; }
.channel-status li { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.status-dot.on { background: var(--teal); }
.status-dot.off { background: #d6d6de; }

/* Heatmap */
.heatmap { margin-top: 14px; overflow-x: auto; }
.heatmap table { border-collapse: collapse; }
.heatmap th { font-size: 10px; font-weight: 800; color: var(--muted); padding: 2px 4px; }
.heatmap td { width: 22px; height: 22px; border-radius: 4px; text-align: center; font-size: 9px; color: #fff; font-weight: 800; }
.heatmap .rowlabel { font-size: 11px; font-weight: 800; color: var(--muted); padding-right: 8px; text-align: right; }
.heatmap .legend { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.heatmap .legend .sw { width: 16px; height: 12px; border-radius: 3px; }

/* Quality */
.quality-banner { border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; font-size: 14px; font-weight: 700; }
.quality-banner.warn { background: #fff4f8; border: 1px solid rgba(225, 29, 72, 0.3); color: var(--red); }
.quality-banner.ok { background: rgba(0, 150, 136, 0.08); border: 1px solid rgba(0, 150, 136, 0.25); color: var(--teal); }
.quality-banner h4 { margin: 0 0 6px; font-size: 14px; font-weight: 900; }
.quality-banner ul { margin: 6px 0 0; padding-left: 18px; }
.quality-banner li { margin: 3px 0; font-weight: 600; }
.quality-detail .flag { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.quality-detail .flag:last-child { border-bottom: none; }
.methodology { margin-top: 16px; line-height: 1.6; }

/* Clarity behaviour */
.clarity-scope { font-size: 13px; font-weight: 800; padding: 9px 13px; border-radius: 10px; margin-bottom: 14px; background: var(--soft); border: 1px solid var(--line); color: var(--ink); }
.clarity-scope.chan { background: rgba(0,150,136,0.1); border-color: rgba(0,150,136,0.3); color: var(--teal); }
.clarity-scope.warn { background: #fff4f8; border-color: rgba(225,29,72,0.3); color: var(--red); }
.clarity-cards { margin-top: 4px; margin-bottom: 18px; }
.frictions-title { margin: 6px 0 12px; font-size: 14px; font-weight: 900; }
.frictions-title small { font-weight: 700; color: var(--muted); font-size: 12px; }
.frictions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.friction { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.friction.hot { background: #fff4f8; border-color: rgba(225, 29, 72, 0.35); }
.friction .fr-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.friction .fr-pct { font-size: 22px; font-weight: 900; letter-spacing: -0.5px; }
.friction.hot .fr-pct { color: var(--red); }
.friction .fr-count { font-size: 11px; font-weight: 700; color: var(--muted); }
@media (max-width: 760px) { .frictions { grid-template-columns: 1fr 1fr; } }

/* Decision gate */
.gate-body .row { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.gate-body .row:last-child { border-bottom: none; }
.gate-body .verdict { font-weight: 900; }
.gate-body .verdict.win { color: var(--teal); }
.gate-body .verdict.wait { color: var(--muted); }
.caveat { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); background: var(--soft); border-radius: 10px; padding: 12px 14px; line-height: 1.5; }
.footnote { font-size: 12px; color: var(--muted); text-align: center; margin-top: 26px; }

.errbox { background: #fff4f8; border: 1px solid rgba(227, 1, 104, 0.3); color: var(--magenta); border-radius: var(--radius); padding: 18px 20px; font-size: 14px; font-weight: 700; }
.errbox code { color: var(--ink); }

@media (max-width: 1000px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  .grid3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .grid2 { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .topbar { position: static; }
}
@media (max-width: 460px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .topbar h1 { font-size: 16px; }
}
