/* ═══════════════════════════════════════════════════════════
   GCPI Research — Global Stylesheet  v2
   Fonts: Playfair Display (serif/titles) / DM Sans (UI/labels) / Georgia (body prose) / JetBrains Mono (data)
   ═══════════════════════════════════════════════════════════ */

/* ─── Design tokens ─────────────────────────────────────── */
:root {
  /* Colours — light */
  --text-primary:          #111111;
  --text-secondary:        #3d3d3d;
  --text-tertiary:         #6b6b6b;
  --border-heavy:          #111111;
  --border-mid:            #aaaaaa;
  --border-light:          #cccccc;
  --bg-primary:            #ffffff;
  --bg-secondary:          #f5f5f3;
  --bg-hover:              #eeeeec;
  --accent-green:          #2d5a0e;
  --accent-red:            #8b1a1a;

  /* Layout */
  --radius:                6px;
  --max-w:                 880px;
  --nav-h:                 120px;
  --page-px:               1.75rem;

  /* Type scale  (mirrors FT Metric scale) */
  --fs-xs:                 10px;
  --fs-sm:                 12px;
  --fs-base:               16px;   /* FT body: 16/24 */
  --fs-md:                 18px;   /* FT scale -1: 18/24 */
  --fs-lg:                 22px;   /* FT scale 2: 24/28 */
  --fs-xl:                 28px;   /* FT scale 3 */
  --fs-2xl:                36px;   /* FT scale 5: 32/40 */

  /* Font families */
  --font-serif:            'Playfair Display', 'Financier Display', Georgia, serif;
  --font-body:             Georgia, 'Times New Roman', serif;  /* FT article body = Georgia */
  --font-sans:             'DM Sans', 'Metric', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --font-mono:             'JetBrains Mono', 'Courier New', monospace;
}

/* Theme: FT */
[data-theme="ft"] {
  --text-primary:          #1a1208;
  --text-secondary:        #3f3320;
  --text-tertiary:         #7a6a52;
  --border-heavy:          #1a1208;
  --border-mid:            #a8906a;
  --border-light:          #c8b898;
  --bg-primary:            #FFF1E5;
  --bg-secondary:          #F7E4CF;
  --bg-hover:              #F0D8C0;
  --accent-green:          #234a0a;
  --accent-red:            #7a0c2e;
}

/* Theme: dark */
[data-theme="dark"] {
  --text-primary:          #eeecea;
  --text-secondary:        #b5b3af;
  --text-tertiary:         #808078;
  --border-heavy:          #eeecea;
  --border-mid:            #484846;
  --border-light:          #3a3a38;
  --bg-primary:            #111110;
  --bg-secondary:          #1a1a18;
  --bg-hover:              #222220;
  --accent-green:          #5e9e28;
  --accent-red:            #d85050;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --text-primary:        #eeecea;
    --text-secondary:      #b5b3af;
    --text-tertiary:       #808078;
    --border-heavy:        #eeecea;
    --border-mid:          #484846;
    --border-light:        #3a3a38;
    --bg-primary:          #111110;
    --bg-secondary:        #1a1a18;
    --bg-hover:            #222220;
    --accent-green:        #5e9e28;
    --accent-red:          #d85050;
  }
}

/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: var(--fs-base);
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* ─── Navigation (FT two-row style) ─────────────────────── */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-primary);
}

/* Top row: brand centered */
.nav-top {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.2rem var(--page-px) 1rem;
  border-bottom: 1px solid var(--border-mid);
}
.nav-brand {
  text-decoration: none;
}
.nav-brand-title {
  font-family: var(--font-serif);
  font-size: clamp(22px, 3.5vw, 36px);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-primary);
  white-space: nowrap;
  line-height: 1;
  display: block;
}

/* Bottom row: nav links + theme switcher */
.nav-bottom {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0;
  padding: 0 var(--page-px);
  border-bottom: 1px solid var(--border-light);
  position: relative;
}
.nav-links {
  display: flex;
  gap: 0;
  list-style: none;
  flex-wrap: nowrap;
}
.nav-links a {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  transition: color 0.15s;
  display: block;
  padding: 0.65rem 1rem;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.nav-links a:hover { color: var(--text-primary); }
.nav-links a.active {
  color: var(--text-primary);
  font-weight: 700;
  border-bottom: 2px solid var(--text-primary);
}
/* theme switcher floats to right */
.nav-bottom .theme-switcher {
  position: absolute;
  right: var(--page-px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ─── Page wrapper ───────────────────────────────────────── */
.page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 1.5rem var(--page-px) 5rem;
}

/* ─── Page header ────────────────────────────────────────── */
.page-header {
  padding: 1rem 0 1rem;
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--border-light);
}
.page-header-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.page-eyebrow {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.page-meta {
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  font-weight: 400;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
}
.page-title {
  font-family: var(--font-serif);
  font-size: var(--fs-2xl);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 0.55rem;
}
.page-subtitle {
  font-size: var(--fs-md);
  font-weight: 400;
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* ─── Section label & heading ────────────────────────────── */
.section-label {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding-top: 0;
  margin-bottom: 0.85rem;
}
.section-heading {
  font-family: var(--font-serif);
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.85rem;
  line-height: 1.25;
}
.section-gap { margin-top: 3.5rem; }

/* section-label inside a section-gap gets a top rule to separate sections */
.section-gap > .section-label {
  border-top: 1px solid var(--border-mid);
  padding-top: 0.7rem;
}

/* ─── Prose ──────────────────────────────────────────────── */
.prose {
  font-family: var(--font-body);   /* Georgia — same as FT article body */
  font-size: var(--fs-base);
  font-weight: 400;
  line-height: 1.85;
  color: var(--text-primary);
  margin-bottom: 1.2rem;
  max-width: 640px;
}
.prose em     { font-style: italic; }
.prose strong { font-weight: 700; }

/* ─── Headline metrics grid ──────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5px;
  background: var(--border-light);
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 2rem;
}
.metric-cell {
  background: var(--bg-primary);
  padding: 1.25rem 1.1rem;
}
.metric-label {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 0.4rem;
}
.metric-value {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.01em;
}
.metric-delta {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 400;
  margin-top: 5px;
  color: var(--text-tertiary);
}
.delta-up   { color: var(--accent-green); font-weight: 500; }
.delta-down { color: var(--accent-red);   font-weight: 500; }

/* ─── Chart ──────────────────────────────────────────────── */
.chart-block { margin: 2rem 0; }
.chart-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 0.7rem;
}
.chart-canvas-wrap { position: relative; width: 100%; }

/* ─── Two-column layout ──────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 270px;
  gap: 3rem;
  align-items: start;
}
.sidebar { display: flex; flex-direction: column; gap: 1.5rem; }

/* ─── Cards ──────────────────────────────────────────────── */
.card {
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.card-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-mid);
  padding-bottom: 0.55rem;
  margin-bottom: 0.85rem;
}

/* ─── Data table ─────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.data-table th {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  text-align: left;
  padding: 0 0 9px;
  border-bottom: 2px solid var(--border-mid);
}
.data-table th:last-child,
.data-table td:last-child { text-align: right; }
.data-table td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 14px;
}
.data-table td.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

/* ─── Inline code / formula ──────────────────────────────── */
.formula {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  margin: 1rem 0;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
  line-height: 1.7;
}
code {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  padding: 2px 6px;
}

/* ─── Info box ───────────────────────────────────────────── */
.info-box {
  background: var(--bg-secondary);
  border-left: 4px solid var(--border-mid);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1.1rem 1.3rem;
  margin: 1.5rem 0;
}
.info-box p {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.78;
  color: var(--text-secondary);
}
.info-box p + p { margin-top: 0.65rem; }
.info-box strong { font-weight: 600; color: var(--text-primary); }

/* ─── Download button ────────────────────────────────────── */
.dl-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 8px 16px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  cursor: pointer;
  white-space: nowrap;
}
.dl-btn:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
  background: var(--bg-hover);
}
.dl-btn-group { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1.1rem 0; }

/* ─── Risk bar ───────────────────────────────────────────── */
.risk-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
  gap: 0.5rem;
}
.risk-row:last-child { border-bottom: none; }
.risk-name {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-secondary);
  flex: 1;
}
.risk-bar-wrap { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.risk-bar-bg {
  width: 68px; height: 5px;
  background: var(--bg-secondary);
  border-radius: 3px; overflow: hidden;
}
.risk-bar-fill { height: 100%; border-radius: 3px; }
.risk-score {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 28px;
  text-align: right;
}

/* ─── Cite block ─────────────────────────────────────────── */
.cite-block {
  border-left: 4px solid var(--border-mid);
  padding: 0.85rem 1.1rem;
  margin: 1.1rem 0;
  background: var(--bg-secondary);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.cite-block pre {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─── Footer ─────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border-light);
  padding: 1.5rem var(--page-px);
  margin-top: 4rem;
}
.footer-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.footer-text {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
  line-height: 1.6;
  font-style: italic;
}

/* ─── Theme switcher ─────────────────────────────────────── */
.theme-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 1.5rem;
  flex-shrink: 0;
}
.theme-btn {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--border-mid);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s;
  position: relative;
  padding: 0;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-btn:hover { border-color: var(--text-secondary); transform: scale(1.12); }
.theme-btn.active { border-color: var(--text-primary); border-width: 2.5px; }
.theme-btn::after {
  content: '';
  width: 13px; height: 13px;
  border-radius: 50%;
  display: block;
}
.theme-btn[data-t="light"]::after { background: #f8f8f8; border: 1px solid #bbb; }
.theme-btn[data-t="ft"]::after    { background: #FFF1E5; border: 1px solid #bfaa8a; }
.theme-btn[data-t="dark"]::after  { background: #111110; border: 1px solid #555; }
.theme-btn[title]:hover::before {
  content: attr(title);
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--text-tertiary);
  pointer-events: none;
}

/* ─── Smooth theme transition ────────────────────────────── */
body, .site-nav, .page-header, .metrics-grid, .metric-cell,
.card, .data-table td, .data-table th, .info-box,
.cite-block, .formula, .section-label {
  transition: background-color 0.22s ease, color 0.22s ease,
              border-color 0.22s ease;
}

/* ─── Ordered list in methodology ───────────────────────── */
ol.prose-list {
  font-family: var(--font-body);
  font-size: var(--fs-base);
  font-weight: 400;
  line-height: 1.85;
  color: var(--text-primary);
  padding-left: 1.5rem;
  max-width: 640px;
}
ol.prose-list li { margin-bottom: 0.55rem; }
ol.prose-list strong { font-weight: 700; }

/* ─── Floating Table of Contents ────────────────────────── */
/*
 * Layout pattern:
 *   <div class="page-with-toc">
 *     <main class="page"> … </main>
 *     <aside class="toc-aside" id="toc-aside"></aside>
 *   </div>
 *
 * JS (toc.js) auto-populates the aside from h2[id] / h2.section-heading[id]
 * and uses IntersectionObserver to highlight the active item.
 */
.page-with-toc {
  display: block;  /* main content just centers normally */
}

.toc-aside {
  --toc-w: 140px;
  width: var(--toc-w);
  position: fixed;
  top: calc(var(--nav-h) + 2.5rem);
  /* sit just outside the right edge of the content column */
  left: calc(50% + var(--max-w) / 2 + 1rem);
  max-height: calc(100vh - var(--nav-h) - 5rem);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 2rem 0;
  scrollbar-width: none;
  z-index: 10;
}
.toc-aside::-webkit-scrollbar { display: none; }

.toc-aside .toc-title {
  font-family: var(--font-sans);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 0.8rem;
}

.toc-aside ol {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--border-light);
}

.toc-aside ol li {
  position: relative;
}

.toc-aside ol li a {
  display: block;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-tertiary);
  padding: 3px 0 3px 12px;
  transition: color 0.15s;
  text-decoration: none;
}

.toc-aside ol li a:hover {
  color: var(--text-secondary);
}

/* active item: left accent + bold */
.toc-aside ol li.toc-active > a {
  color: var(--text-primary);
  font-weight: 500;
}
.toc-aside ol li.toc-active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--text-primary);
  border-radius: 1px;
}

/* sub-items (h3) indented */
.toc-aside ol ol {
  margin-left: 12px;
  border-left: none;
}
.toc-aside ol ol li a {
  font-size: 9.5px;
  padding: 2px 0 2px 10px;
}

/* Only show TOC on wide viewports */
@media (max-width: 1100px) {
  .toc-aside { display: none; }
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 860px) {
  .nav-links     { gap: 1rem; }
  .nav-links a   { font-size: 12px; letter-spacing: 0.02em; }
}
@media (max-width: 720px) {
  :root { --page-px: 1.1rem; }
  .metrics-grid  { grid-template-columns: repeat(2, 1fr); }
  .two-col       { grid-template-columns: 1fr; }
  .page-title    { font-size: var(--fs-xl); }
  .page-subtitle { font-size: var(--fs-base); }
  .nav-links     { gap: 0.8rem; }
  .nav-brand-sub { display: none; }
}
@media (max-width: 540px) {
  .nav-links li:nth-child(n+5) { display: none; }
  .theme-switcher { margin-left: 0.75rem; }
  .metrics-grid  { grid-template-columns: 1fr 1fr; }
}
