/* ============================================================
   S&P 500 P/E Report — styles
   Alternating dark / light-blue sections, Inter typography.
   ============================================================ */

:root {
  /* Dark blue section */
  --dark-bg: #0b2545;
  --dark-bg-2: #0e2c54;
  --dark-fg: #eef4fb;
  --dark-muted: #a9c2e0;
  --dark-card: #12345f;
  --dark-border: #21497e;

  /* Light blue section */
  --light-bg: #e8f1fb;
  --light-fg: #0b2545;
  --light-muted: #3f5a7d;
  --light-border: #c2d8f0;

  /* Accents */
  --accent: #2f80ed;       /* line */
  --high: #ff8a5c;         /* 80th pct — warm */
  --low: #38c9a4;          /* 20th pct — cool */

  --radius: 16px;
  --maxw: 1080px;
  --prose: 720px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  color: var(--light-fg);
  background: var(--light-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; letter-spacing: -0.02em; }
h1 { font-size: clamp(2rem, 5vw, 3.25rem); font-weight: 800; }
h2 { font-size: clamp(1.5rem, 3.5vw, 2.25rem); font-weight: 700; }
p { margin: 0 0 1.1em; }
a { color: var(--accent); }

/* ---- Layout ---- */
.section { padding: clamp(3rem, 7vw, 6rem) 1.5rem; }
.wrap { max-width: var(--maxw); margin: 0 auto; }
.wrap--prose { max-width: var(--prose); }

.section--dark {
  background: linear-gradient(180deg, var(--dark-bg), var(--dark-bg-2));
  color: var(--dark-fg);
}
.section--light { background: var(--light-bg); color: var(--light-fg); }

.section--dark a { color: #8ec2ff; }

.section-lead {
  font-size: 1.05rem;
  max-width: 62ch;
  margin-bottom: 2rem;
}
.section--dark .section-lead { color: var(--dark-muted); }
.section--light .section-lead { color: var(--light-muted); }

/* ---- Skip link / a11y ---- */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: #fff; color: #0b2545; padding: 0.6rem 1rem;
  border-radius: 0 0 8px 0; z-index: 100; font-weight: 600;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid #8ec2ff;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---- Header ---- */
.page-header { padding-bottom: clamp(2rem, 5vw, 4rem); text-align: left; }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--high);
  margin-bottom: 0.75rem;
}
.subtitle { font-size: 1.15rem; color: var(--dark-muted); max-width: 60ch; margin-bottom: 0; }

/* ---- Chart ---- */
.chart-figure { margin: 0; }
#chart-container { width: 100%; }
#chart-container svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart-caption {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--dark-muted);
}

/* D3 elements */
.axis text { fill: var(--dark-muted); font-size: 12px; }
.axis line, .axis path { stroke: var(--dark-border); }
.grid line { stroke: rgba(255,255,255,0.06); }
.grid path { stroke: none; }
.pe-line { fill: none; stroke: var(--accent); stroke-width: 1.8; }
.ref-line.high { stroke: var(--high); }
.ref-line.low { stroke: var(--low); }
.ref-line { stroke-width: 1.5; stroke-dasharray: 6 4; }
.ref-label { font-size: 12px; font-weight: 600; }
.ref-label.high { fill: var(--high); }
.ref-label.low { fill: var(--low); }
.focus-dot { fill: #fff; stroke: var(--accent); stroke-width: 2; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: #06182f;
  color: #eef4fb;
  border: 1px solid var(--dark-border);
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.12s ease;
  white-space: nowrap;
  z-index: 10;
}
.tooltip .tt-date { color: var(--dark-muted); }
.tooltip .tt-val { font-weight: 700; font-size: 1rem; }
.tooltip .tt-est { color: var(--high); font-size: 0.75rem; }

/* Legend */
.legend {
  display: flex; flex-wrap: wrap; gap: 1.25rem;
  margin-top: 1.25rem; font-size: 0.9rem; color: var(--dark-muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.5rem; }
.swatch { width: 20px; height: 3px; border-radius: 2px; display: inline-block; }
.swatch--line { background: var(--accent); }
.swatch--high { background: var(--high); }
.swatch--low  { background: var(--low); }

/* inline tags in prose */
.tag { font-weight: 600; }
.tag--high { color: var(--high); }
.tag--low { color: var(--low); }

/* ---- Key stats: 4 square cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}
.stat-card {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--dark-card);
  border: 1px solid var(--dark-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--accent);
}
.stat-card[data-stat="p80"]::before { background: var(--high); }
.stat-card[data-stat="p20"]::before { background: var(--low); }
.stat-card[data-stat="median"]::before { background: var(--dark-muted); }

.stat-label {
  font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em;
  font-weight: 600; color: var(--dark-muted); margin: 0;
}
.stat-value {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 800; margin: 0; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-sub { font-size: 0.85rem; color: var(--dark-muted); margin: 0; }

/* ---- Data & citations ---- */
.meta-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.5rem;
  margin: 0 0 1.5rem;
}
.meta-list dt { font-weight: 700; color: var(--light-fg); }
.meta-list dd { margin: 0; color: var(--light-muted); }
.note { font-size: 0.92rem; color: var(--light-muted); }
code {
  background: #d6e6f8; padding: 0.1em 0.4em; border-radius: 6px;
  font-size: 0.9em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.data-table-wrap { margin-top: 1.5rem; }
.data-table-wrap summary {
  cursor: pointer; font-weight: 600; padding: 0.75rem 1rem;
  background: #fff; border: 1px solid var(--light-border); border-radius: 10px;
}
.data-table-wrap summary:hover { border-color: var(--accent); }
.table-scroll {
  max-height: 420px; overflow: auto; margin-top: 1rem;
  border: 1px solid var(--light-border); border-radius: 10px; background: #fff;
}
#data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
#data-table caption { text-align: left; padding: 0.75rem 1rem; color: var(--light-muted); font-size: 0.85rem; }
#data-table th, #data-table td { padding: 0.5rem 1rem; text-align: right; }
#data-table th:first-child, #data-table td:first-child { text-align: left; }
#data-table thead th {
  position: sticky; top: 0; background: #eef5fd; z-index: 1;
  border-bottom: 2px solid var(--light-border);
}
#data-table tbody tr:nth-child(even) { background: #f5f9fe; }
#data-table td { font-variant-numeric: tabular-nums; }
.est-mark { color: #b5651d; font-weight: 700; }

.footer { padding-top: 2rem; padding-bottom: 2rem; font-size: 0.9rem; color: var(--light-muted); }

/* ---- Responsive ---- */
@media (max-width: 820px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 460px) {
  body { font-size: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { aspect-ratio: auto; min-height: 150px; }
  .meta-list { grid-template-columns: 1fr; gap: 0.1rem 0; }
  .meta-list dd { margin-bottom: 0.75rem; }
}

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