/* ─── Design tokens — Apple HIG-flavored: grouped light/dark, one accent blue,
   soft cards, generous whitespace. Vendor dot colors are the dataviz-skill-
   validated categorical triplet (re-checked against these exact card
   surfaces) — those don't move with theme, only the chrome does. ─── */

:root {
  color-scheme: light;
  --page:            #f2f2f7;   /* systemGroupedBackground */
  --surface:         #ffffff;   /* card surface — where data marks render */
  --surface-raised:  #f5f5f7;   /* inset fields, segmented track */
  --text-primary:    #1d1d1f;
  --text-secondary:  #6e6e73;
  --text-muted:      #a1a1a6;
  --divider:         rgba(0, 0, 0, 0.08);
  --accent:          #0071e3;
  --accent-tint:     rgba(0, 113, 227, 0.12);
  --good:            #34c759;
  --good-tint:       rgba(52, 199, 89, 0.14);
  --neutral-tint:    rgba(110, 110, 115, 0.12);
  --shadow-card:     0 1px 2px rgba(0,0,0,0.04), 0 8px 24px -6px rgba(0,0,0,0.08);

  --v-anthropic:     #2a78d6;
  --v-google:        #eb6834;
  --v-openai:        #1baf7a;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:            #000000;
    --surface:         #1c1c1e;
    --surface-raised:  #2c2c2e;
    --text-primary:    #f5f5f7;
    --text-secondary:  #98989d;
    --text-muted:      #6e6e73;
    --divider:         rgba(255, 255, 255, 0.09);
    --accent:          #2997ff;
    --accent-tint:     rgba(41, 151, 255, 0.16);
    --good:            #32d74b;
    --good-tint:       rgba(50, 215, 75, 0.16);
    --neutral-tint:    rgba(152, 152, 157, 0.16);
    --shadow-card:     0 1px 2px rgba(0,0,0,0.3), 0 12px 28px -8px rgba(0,0,0,0.55);

    --v-anthropic:     #3987e5;
    --v-google:        #d95926;
    --v-openai:        #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #000000;
  --surface:         #1c1c1e;
  --surface-raised:  #2c2c2e;
  --text-primary:    #f5f5f7;
  --text-secondary:  #98989d;
  --text-muted:      #6e6e73;
  --divider:         rgba(255, 255, 255, 0.09);
  --accent:          #2997ff;
  --accent-tint:     rgba(41, 151, 255, 0.16);
  --good:            #32d74b;
  --good-tint:       rgba(50, 215, 75, 0.16);
  --neutral-tint:    rgba(152, 152, 157, 0.16);
  --shadow-card:     0 1px 2px rgba(0,0,0,0.3), 0 12px 28px -8px rgba(0,0,0,0.55);

  --v-anthropic:     #3987e5;
  --v-google:        #d95926;
  --v-openai:        #199e70;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 56px 24px 90px;
}

/* ─── Header ─── */

header.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 32px;
}
header.top h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
header.top p {
  margin: 0;
  color: var(--text-secondary);
  max-width: 58ch;
  font-size: 0.98rem;
}
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  flex-shrink: 0;
  transition: color 0.15s ease;
}
.theme-toggle:hover { color: var(--accent); }

/* ─── Filter bar ─── */

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 28px;
  margin-bottom: 28px;
}
.filter-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter-label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: var(--surface-raised);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 7px 14px 7px 10px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chip[aria-pressed="false"] { opacity: 0.55; }
.chip[aria-pressed="true"] { background: var(--vchip-tint, var(--accent-tint)); color: var(--text-primary); }

/* Apple-style segmented control: rounded track, filled pill on the active segment */
.segmented {
  display: inline-flex;
  background: var(--surface-raised);
  border-radius: 9px;
  padding: 2px;
  gap: 1px;
}
.segmented button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 14px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 7px;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ─── Vendor cards ─── */

.vendor {
  margin-bottom: 20px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  padding: 24px 26px 10px;
}

.vendor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.vendor-head .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.vendor-head h2 { font-size: 1.08rem; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.vendor-source { color: var(--text-muted); font-size: 0.82rem; margin: 0 0 18px; }
.vendor-source a { color: var(--text-muted); text-decoration: underline; }

/* stat row — Apple Health-style big numbers, divided by hairlines, no boxed tiles */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 20px;
  border-top: 1px solid var(--divider);
  border-bottom: 1px solid var(--divider);
}
.kpi-tile {
  padding: 14px 12px;
  border-right: 1px solid var(--divider);
}
.kpi-tile:last-child { border-right: none; }
.kpi-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi-sub { font-size: 0.72rem; color: var(--text-secondary); margin-top: 2px; }

.forecast-note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--surface-raised);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 18px;
}
.forecast-label { font-weight: 600; color: var(--text-primary); }
.forecast-caveat { color: var(--text-muted); }

/* timeline (dot strip, one row, svg) */
.timeline-wrap { margin-bottom: 14px; overflow-x: auto; }
.timeline-wrap svg { display: block; }
.tl-dot { cursor: pointer; } /* app.js: svg <g> per timeline event */
.tl-dot circle:first-child { filter: drop-shadow(0 1px 2px rgba(0,0,0,0.18)); }
.tl-dot:hover circle:first-child, .tl-dot:focus circle:first-child { filter: drop-shadow(0 2px 4px rgba(0,0,0,0.28)) brightness(1.1); }
.tl-axis-label { fill: var(--text-muted); font-size: 10px; }

/* tooltip */
#tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.8rem;
  max-width: 280px;
  box-shadow: var(--shadow-card);
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 20;
}
#tooltip.show { opacity: 1; }
#tooltip .tt-date { color: var(--text-muted); font-size: 0.72rem; margin-bottom: 3px; }
#tooltip .tt-text { color: var(--text-primary); }

/* ─── Events list (styled as an Apple list, not a data grid) ─── */

details.events-details summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 500;
  margin: 26px 4px 12px;
  list-style: none;
}
details.events-details summary::-webkit-details-marker { display: none; }
details.events-details summary::before { content: "▸ "; color: var(--text-muted); }
details.events-details[open] summary::before { content: "▾ "; }

table.events {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
/* visually hidden, not display:none — keeps column headers in the a11y tree */
table.events thead th {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
table.events td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--divider);
  vertical-align: top;
}
table.events tr:last-child td { border-bottom: none; }
table.events td.date { color: var(--text-secondary); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.events td:first-child { white-space: nowrap; color: var(--text-secondary); font-size: 0.8rem; }
table.events .vendor-swatch { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; }

/* ─── Pace calculator ─── */

.calc {
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  padding: 26px 28px 28px;
  margin: 36px 0;
}
.calc h2 { margin: 0 0 8px; font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; }
.calc p.lede { color: var(--text-secondary); margin: 0 0 24px; max-width: 66ch; font-size: 0.88rem; }

.calc-body { display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap; }

.ring-wrap { position: relative; width: 140px; height: 140px; flex-shrink: 0; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-raised); stroke-width: 10; }
.ring-track-inner { stroke: var(--surface-raised); }
.ring-arc { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.4s ease, stroke 0.3s ease; }
.ring-arc-target { stroke: var(--accent); }
.ring-arc-actual { stroke: var(--text-muted); stroke-dasharray: 0 1000; }
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-figure { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ring-figure .ring-unit { font-size: 1.05rem; color: var(--text-secondary); font-weight: 500; margin-left: 1px; }
.ring-caption { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

.calc-fields { flex: 1; min-width: 260px; }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.field label { display: block; font-size: 0.74rem; color: var(--text-muted); margin-bottom: 5px; }
.field select, .field input {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: none;
  background: var(--surface-raised);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.88rem;
}
.field select:focus, .field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.calc-detail { color: var(--text-primary); font-size: 0.88rem; margin: 4px 0 6px; }
.calc-formula { color: var(--text-muted); font-size: 0.76rem; margin: 0; }

/* ─── Footer ─── */

footer {
  margin-top: 40px;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding-top: 18px;
  border-top: 1px solid var(--divider);
}
footer p { margin: 0 0 6px; }
footer a { color: var(--text-muted); text-decoration: underline; }

@media (max-width: 640px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .kpi-tile:nth-child(2) { border-right: none; }
  header.top { flex-direction: column; }
  .calc-body { flex-direction: column; align-items: center; }
  .calc-fields { width: 100%; }
}
