/* Archivo (variable, latin subset) — SIL Open Font License 1.1, see assets/fonts/OFL.txt.
   Self-hosted so the dashboard renders correctly offline and behind a proxy. */
@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 400 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url("fonts/archivo-latin.woff2") format("woff2");
}

/* Crooked Ideas — Weekly Social Analytics dashboard
   Brand tokens live here; everything else reads from them. */

:root {
  color-scheme: light;

  /* Brand surfaces + ink */
  --surface: #f0eee9;
  --surface-raised: #f7f6f2;
  --ink: #191919;
  --ink-secondary: #5b5a55;
  --ink-muted: #8a8781;
  --rule: rgba(25, 25, 25, 0.14);
  --grid: rgba(25, 25, 25, 0.11);

  /* Brand palette (from the weekly chart deck) */
  --blue: #3b5bf5;
  --pink: #ff8ac5;
  --green: #1e6a45;
  --yellow: #fce94d;

  /* Categorical series steps — validated for CVD separation and
     contrast against --surface. Colour follows the platform, never its rank. */
  --series-instagram: #3b5bf5;
  --series-tiktok: #e0489b;
  --series-threads: #2f8f5b;

  --pos: #1e6a45;
  --neg: #b3312f;

  --font: "Archivo", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --radius: 4px;
  --maxw: 1360px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding-inline: 24px;
  padding-block: 0 64px;
}

/* ---------- Header ---------- */

.masthead {
  padding-block: 40px 28px;
  border-bottom: 2px solid var(--ink);
}

.eyebrow {
  font-size: 15px;
  font-weight: 700;
  font-stretch: 92%;
  color: var(--blue);
  margin: 0 0 6px;
  letter-spacing: 0.01em;
}

h1 {
  font-size: clamp(38px, 7vw, 72px);
  font-weight: 900;
  font-stretch: 105%;
  letter-spacing: -0.022em;
  line-height: 0.94;
  margin: 0 0 12px;
  text-transform: uppercase;
}

.dek {
  margin: 0;
  max-width: 62ch;
  color: var(--ink-secondary);
  font-size: 16px;
}

.masthead-meta {
  margin-top: 16px;
  font-size: 13px;
  color: var(--ink-muted);
  font-stretch: 92%;
}

/* ---------- Stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 2px;
  margin-block: 28px 8px;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.tile {
  background: var(--surface);
  padding: 18px 18px 16px;
}

.tile-label {
  font-size: 12px;
  font-weight: 700;
  font-stretch: 88%;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 8px;
}

.tile-value {
  font-size: 34px;
  font-weight: 900;
  font-stretch: 100%;
  letter-spacing: -0.02em;
  line-height: 1;
  margin: 0;
}

.tile-delta {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  font-stretch: 92%;
  color: var(--ink-secondary);
}

.tile-delta .up { color: var(--pos); }
.tile-delta .down { color: var(--neg); }
.tile-delta .flat { color: var(--ink-muted); }

/* ---------- Controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  padding: 14px 0 18px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 20;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.seg {
  display: inline-flex;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  font-stretch: 92%;
  color: var(--ink);
  padding: 6px 12px;
  cursor: pointer;
  border-right: 1.5px solid var(--ink);
}

.seg button:last-child { border-right: 0; }
.seg button:hover { background: rgba(59, 91, 245, 0.1); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.linkish {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  font-stretch: 92%;
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

/* ---------- Sections + chart cards ---------- */

.section-head {
  margin: 40px 0 16px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.section-head h2 {
  font-size: 22px;
  font-weight: 900;
  font-stretch: 100%;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  margin: 0;
}

.section-head p {
  margin: 0;
  font-size: 14px;
  color: var(--ink-secondary);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
  gap: 20px;
}

.card {
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  background: var(--surface);
  min-width: 0;
}

.card h3 {
  font-size: clamp(26px, 3.4vw, 38px);
  font-weight: 900;
  font-stretch: 104%;
  letter-spacing: -0.02em;
  line-height: 1;
  text-transform: uppercase;
  margin: 0 0 6px;
}

.card-sub {
  margin: 0 0 4px;
  font-size: 13.5px;
  color: var(--ink-secondary);
}

.card-foot {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--ink-muted);
  font-stretch: 92%;
}

/* ---------- Legend ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 10px 0 2px;
}

.legend button {
  appearance: none;
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: 999px;
  padding: 4px 11px 4px 8px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  font-stretch: 92%;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend button:hover { border-color: var(--ink); }
.legend button[aria-pressed="false"] { color: var(--ink-muted); }
.legend button[aria-pressed="false"] .key { opacity: 0.3; }

.legend .key {
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  flex: none;
}

/* ---------- Chart plot ---------- */

.plot {
  position: relative;
  width: 100%;
}

.plot svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.plot svg:focus { outline: none; }
.plot svg:focus-visible { outline: 3px solid var(--blue); outline-offset: -2px; }

.tip {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  background: #191919;
  color: #f7f6f2;
  border-radius: var(--radius);
  padding: 9px 11px;
  font-size: 12.5px;
  line-height: 1.4;
  min-width: 132px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  z-index: 5;
}

.tip[data-open="true"] { opacity: 1; }

.tip-head {
  font-weight: 700;
  font-stretch: 90%;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 11px;
  color: rgba(247, 246, 242, 0.68);
  margin-bottom: 6px;
}

.tip-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.tip-row + .tip-row { margin-top: 3px; }

.tip-key {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  flex: none;
  transform: translateY(-3px);
}

.tip-val {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.tip-name { color: rgba(247, 246, 242, 0.72); }
.tip-note { margin-top: 6px; color: var(--yellow); font-size: 11.5px; white-space: normal; }

/* ---------- Table ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  margin-top: 16px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

caption {
  text-align: left;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--ink-secondary);
  border-bottom: 1px solid var(--rule);
}

th, td {
  text-align: right;
  padding: 9px 14px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-raised);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-secondary);
}

th[scope="row"], thead th:first-child { text-align: left; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tbody tr:hover td, tbody tr:hover th { background: rgba(59, 91, 245, 0.06); }

.flagged { color: var(--ink-muted); }

/* ---------- Footer ---------- */

footer {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 2px solid var(--ink);
  font-size: 13px;
  color: var(--ink-secondary);
}

footer h2 {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin: 0 0 10px;
  color: var(--ink);
}

footer ul { margin: 0 0 14px; padding-left: 18px; }
footer li { margin-bottom: 6px; }
footer a { color: var(--blue); }

.wordmark {
  font-weight: 900;
  font-stretch: 104%;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--blue);
  font-size: 15px;
}

@media (max-width: 700px) {
  .wrap { padding-inline: 16px; }
  .grid { grid-template-columns: 1fr; }
  .controls { position: static; }
  .tile-value { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .controls, .legend button { display: none; }
  .card { break-inside: avoid; }
}
