/* Shared styles for /trend/ and /trend/modular-analysis/.
   Tokens mirror the homepage (styles.css): dark first, light via prefers-color-scheme. */
:root {
  --bg: #0b0f14;
  --bg-soft: #11161d;
  --surface: #11161d;          /* chart surface (validated against) */
  --text: #e6ebf4;
  --muted: #a8b0c2;
  --faint: #7d869a;
  --brand: #6ee7ff;
  --accent: #9b8cff;
  --card: rgba(255, 255, 255, 0.05);
  --card-solid: #11161d;
  --border: rgba(255, 255, 255, 0.12);
  --grid: rgba(255, 255, 255, 0.08);
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  /* data-viz series (validated: scripts/validate_palette.js, dark surface #11161d) */
  --s1: #3987e5;   /* 1e9+7        */
  --s2: #d95926;   /* 998244353    */
  --s3: #199e70;   /* other fixed  */
  --s4: #c98500;   /* variable     */
  --seq-0: #11161d; --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #2a78d6; --seq-4: #5598e7; --seq-5: #9ec5f4;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --bg-soft: #ffffff;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #475569;
    --faint: #64748b;
    --brand: #0ea5e9;
    --accent: #7c3aed;
    --card: rgba(255, 255, 255, 0.85);
    --card-solid: #ffffff;
    --border: rgba(15, 23, 42, 0.10);
    --grid: rgba(15, 23, 42, 0.08);
    --shadow: 0 12px 28px rgba(15, 23, 42, 0.10);
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
    --seq-0: #ffffff; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #5598e7; --seq-4: #2a78d6; --seq-5: #184f95;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  line-height: 1.55;
  background: radial-gradient(1200px 800px at 10% -10%, rgba(110, 231, 255, 0.06), transparent 60%),
              radial-gradient(1200px 800px at 90% 10%, rgba(155, 140, 255, 0.08), transparent 60%),
              var(--bg);
  background-attachment: fixed;
}
a { color: var(--brand); }
a:hover { color: var(--accent); }
h1, h2, h3 { font-family: "Space Grotesk", Inter, system-ui, sans-serif; letter-spacing: 0.2px; line-height: 1.2; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* header (same pattern as homepage) */
.site-header { position: sticky; top: 0; z-index: 20; backdrop-filter: saturate(1.2) blur(12px);
  -webkit-backdrop-filter: saturate(1.2) blur(12px);
  background: linear-gradient(180deg, rgba(0,0,0,0.18), rgba(0,0,0,0.04)); border-bottom: 1px solid var(--border); }
@media (prefers-color-scheme: light) { .site-header { background: rgba(248, 250, 252, 0.82); } }
.site-header .container { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; }
.brand { font-family: "Space Grotesk", Inter, sans-serif; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand span { color: var(--brand); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.nav a { color: var(--text); text-decoration: none; padding: 7px 11px; border-radius: 10px; border: 1px solid transparent; font-size: 0.93rem; transition: all 160ms ease; }
.nav a:hover, .nav a.active { border-color: var(--border); background: var(--card); color: var(--text); }
.nav a.active { color: var(--brand); }

.hero { padding: 48px 0 20px; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); margin: 0; }
.hero .sub { color: var(--muted); font-size: 1.05rem; margin: 12px 0 0; max-width: 820px; }
.eyebrow { color: var(--brand); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600; margin-bottom: 10px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 1.15rem; margin: 0 0 4px; }
.card .desc { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin: 22px 0 8px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 0.82rem; }
.kpi .value { font-family: "Space Grotesk", Inter, sans-serif; font-size: 1.75rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .foot { color: var(--faint); font-size: 0.8rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin: 18px 0; }
.filters .f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.filters label { font-size: 0.76rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.filters select, .filters input[type=search], .btn {
  font: inherit; font-size: 0.92rem; color: var(--text); background: var(--card-solid);
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; min-height: 36px; max-width: 100%; }
.filters .check { flex-direction: row; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text); min-height: 36px; }
.btn { cursor: pointer; transition: border-color 150ms; }
.btn:hover { border-color: var(--brand); }
.match { color: var(--muted); font-size: 0.9rem; margin-left: auto; align-self: center; }

/* chart grid */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid .wide { grid-column: 1 / -1; }
@media (max-width: 860px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 520px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.toggle { font-size: 0.8rem; padding: 4px 9px; min-height: 0; border-radius: 8px; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.85rem; color: var(--muted); margin: 0 0 10px; }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data th, table.data td { padding: 7px 9px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; font-size: 0.8rem; position: sticky; top: 0; background: var(--card-solid); }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th[aria-sort="ascending"]::after { content: " ▲"; font-size: 0.7em; }
table.data th[aria-sort="descending"]::after { content: " ▼"; font-size: 0.7em; }
table.data td.wrap { white-space: normal; min-width: 180px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; border: 1px solid var(--border); white-space: nowrap; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--muted); font-size: 0.88rem; flex-wrap: wrap; }

/* heatmap */
table.heat td.cell { text-align: center; font-variant-numeric: tabular-nums; border-radius: 6px; border: 2px solid var(--card-solid); min-width: 64px; }
table.heat th { position: static; }

/* prose */
.prose { max-width: 860px; }
.prose p, .prose li { color: var(--text); }
.prose h2 { font-size: 1.5rem; margin: 44px 0 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.prose h3 { font-size: 1.12rem; margin: 26px 0 8px; }
.prose table.data td { white-space: normal; }
.callout { border-left: 3px solid var(--brand); background: var(--card); padding: 12px 16px; border-radius: 0 12px 12px 0; margin: 16px 0; }
.findings li { margin: 8px 0; }
figure { margin: 18px 0 26px; }
figcaption { color: var(--muted); font-size: 0.88rem; margin-top: 8px; }

.site-footer { border-top: 1px solid var(--border); margin-top: 48px; }
.site-footer .container { padding: 22px 20px; color: var(--muted); font-size: 0.88rem; }

/* hub cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin: 24px 0; }
.card-link { text-decoration: none; color: inherit; display: flex; }
.card-link .card { flex: 1; transition: transform 200ms ease, border-color 200ms ease; }
.card-link:hover .card { transform: translateY(-2px); border-color: var(--brand); }
.badge { display: inline-block; font-size: 0.75rem; color: var(--brand); border: 1px solid var(--border); padding: 3px 9px; border-radius: 999px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .site-header .container { flex-direction: column; align-items: flex-start; gap: 6px; padding: 10px 16px; }
  .nav { justify-content: flex-start; }
  .nav a { padding: 5px 8px; font-size: 0.86rem; }
  .hero { padding: 28px 0 12px; }
  .chart-box { height: 260px; }
  .chart-box.tall { height: 600px; }
  .match { margin-left: 0; width: 100%; }
  .filters .f { flex: 1 1 140px; }
  .filters select { width: 100%; }
}

/* print / PDF: force light, no chrome */
@media print {
  :root { --bg: #fff; --bg-soft: #fff; --surface: #fff; --text: #0f172a; --muted: #475569; --faint: #64748b;
    --card: #fff; --card-solid: #fff; --border: #d9dee7; --grid: #e5e9f0; --shadow: none; --brand: #0b6fa4;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
    --seq-0: #ffffff; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #5598e7; --seq-4: #2a78d6; --seq-5: #184f95; color-scheme: light; }
  body { background: #fff; font-size: 10.5pt; }
  .site-header, .site-footer .nav, .no-print, .toggle { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
  figure, table { break-inside: avoid; }
  .prose h2 { break-before: auto; break-after: avoid; }
  .chart-box { height: auto !important; }
  .chart-box canvas { max-width: 100%; }
  a { color: inherit; text-decoration: none; }
  .table-wrap { overflow: visible; }
  table.data th { position: static; }
}
