/* MacScope — one stylesheet, no framework. Tokens first, then layout, then components. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #6f6e69;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: #e8f1fc;
  --good: #006300;
  --critical: #d03b3b;
  --warning-wash: #fff6df;
  --warning-ink: #7a5600;

  /* data series */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --band: rgba(42, 120, 214, 0.14);

  /* diverging: cheaper (blue) ← neutral → pricier (red) */
  --div-n3: #256abf;
  --div-n2: #5598e7;
  --div-n1: #9ec5f4;
  --div-0: #ebeae6;
  --div-p1: #f2c4c2;
  --div-p2: #e8817e;
  --div-p3: #c93a3a;
  --map-stroke: #fcfcfb;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px -12px rgba(11, 11, 11, 0.12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --wrap: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #a3a29a;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: #16263a;
    --good: #0ca30c;
    --critical: #e66767;
    --warning-wash: #2c2410;
    --warning-ink: #f3c860;
    --series-1: #3987e5;
    --series-2: #d95926;
    --band: rgba(57, 135, 229, 0.2);
    --div-0: #5e5d58;
    --map-stroke: #1a1a19;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --ink-3: #a3a29a;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: #16263a;
  --good: #0ca30c;
  --critical: #e66767;
  --warning-wash: #2c2410;
  --warning-ink: #f3c860;
  --series-1: #3987e5;
  --series-2: #d95926;
  --band: rgba(57, 135, 229, 0.2);
  --div-0: #5e5d58;
  --map-stroke: #1a1a19;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
}

/* ---- base -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 128px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 var(--font);
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.4em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.9rem, 1.2rem + 2.6vw, 3rem); font-weight: 750; letter-spacing: -0.025em; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 0.8em; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
svg { display: block; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.wrap { width: min(100% - 2rem, var(--wrap)); margin-inline: auto; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; z-index: 100; background: var(--surface); padding: 0.5rem 1rem; border-radius: var(--radius-sm); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* ---- top bar ----------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner { display: flex; align-items: center; gap: 1.5rem; height: 60px; }
.brand { display: flex; align-items: center; gap: 0.55rem; color: var(--ink); text-decoration: none; font-size: 1.1rem; letter-spacing: -0.01em; }
.brand b { color: var(--accent); font-weight: 750; }
.brand__mark { width: 28px; height: 28px; }
.nav { display: flex; gap: 0.25rem; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 0.4rem 0.7rem; border-radius: 999px; font-size: 0.92rem; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; flex: none; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ---- hero -------------------------------------------------------------- */
.hero { display: grid; grid-template-columns: 1.5fr 1fr; gap: 2rem; align-items: end; padding: 3rem 0 1.5rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.75rem; font-weight: 650; color: var(--accent-ink); margin-bottom: 0.6rem; }
#hero-product { color: var(--accent); }
.lede { font-size: 1.08rem; color: var(--ink-2); max-width: 60ch; }
.notice { display: flex; gap: 0.75rem; padding: 1rem 1.1rem; border-radius: var(--radius); background: var(--warning-wash); color: var(--ink); font-size: 0.9rem; border: 1px solid color-mix(in srgb, var(--warning-ink) 25%, transparent); }
.notice svg { flex: none; width: 20px; height: 20px; fill: none; stroke: var(--warning-ink); stroke-width: 2; stroke-linecap: round; margin-top: 2px; }
.notice strong { color: var(--warning-ink); }

/* ---- product picker ---------------------------------------------------- */
.picker-bar { position: sticky; top: 60px; z-index: 15; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(12px); padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.picker { position: relative; display: flex; gap: 0.4rem; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
.picker::-webkit-scrollbar, .nav::-webkit-scrollbar { display: none; }
.chip {
  flex: none; scroll-snap-align: start;
  padding: 0.45rem 0.9rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); cursor: pointer; font-size: 0.9rem; white-space: nowrap;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.chip:hover { color: var(--ink); border-color: var(--axis); }
.chip[aria-checked="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* ---- KPIs -------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.75rem; padding: 1.5rem 0 0.5rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }
.kpi__label { font-size: 0.8rem; color: var(--ink-2); margin: 0 0 0.25rem; }
.kpi__value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.kpi__hint { font-size: 0.8rem; color: var(--ink-3); margin: 0.2rem 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi__hint a { color: inherit; }
.kpi--skeleton { height: 104px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- sections & cards ------------------------------------------------- */
.section { padding: 2rem 0 0.5rem; }
.section__head { margin-bottom: 1rem; }
.section__head p { margin: 0; }
.section__head--row { display: flex; justify-content: space-between; align-items: end; gap: 1rem; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); min-width: 0; }
.card--flush { padding: 0; overflow: hidden; }
.card__head { margin-bottom: 0.75rem; }
.card__head p { margin: 0; font-size: 0.9rem; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }

/* ---- map --------------------------------------------------------------- */
.map-layout { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1rem; }
.map { aspect-ratio: 1 / 0.96; width: 100%; }
.map svg { width: 100%; height: 100%; }
.map path { stroke: var(--map-stroke); stroke-width: 0.6; stroke-linejoin: round; cursor: pointer; transition: opacity 120ms; }
.map path:hover { stroke: var(--ink); stroke-width: 1.4; }
.map path.is-selected { stroke: var(--ink); stroke-width: 2; }
.map.has-selection path:not(.is-selected) { opacity: 0.55; }
.map path.is-empty { fill: transparent; stroke: var(--axis); stroke-dasharray: 2 2; cursor: default; }
.div-0 { fill: var(--div-n3); background: var(--div-n3); }
.div-1 { fill: var(--div-n2); background: var(--div-n2); }
.div-2 { fill: var(--div-n1); background: var(--div-n1); }
.div-3 { fill: var(--div-0); background: var(--div-0); }
.div-4 { fill: var(--div-p1); background: var(--div-p1); }
.div-5 { fill: var(--div-p2); background: var(--div-p2); }
.div-6 { fill: var(--div-p3); background: var(--div-p3); }
.map .is-hover-raise { paint-order: stroke; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; font-size: 0.8rem; color: var(--ink-2); margin-top: 0.75rem; }
.legend__scale { display: flex; gap: 2px; }
.legend__swatch { width: 34px; height: 10px; border-radius: 3px; }
.legend__key { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend__line { width: 18px; height: 2px; border-radius: 2px; }
.legend__band { width: 18px; height: 10px; border-radius: 3px; background: var(--band); }
.legend--inline { margin-top: 0.25rem; }

.dept-panel h3 { font-size: 1.1rem; margin-bottom: 0.1rem; }
.dept-panel .stat-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin: 1rem 0; }
.stat-list dt { font-size: 0.78rem; color: var(--ink-2); }
.stat-list dd { margin: 0; font-size: 1.15rem; font-weight: 650; }
.mini-rank { list-style: none; padding: 0; margin: 0.25rem 0 1rem; display: grid; gap: 0.2rem; }
.mini-rank li { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.9rem; padding: 0.3rem 0.5rem; border-radius: 6px; }
.mini-rank button { all: unset; cursor: pointer; display: flex; justify-content: space-between; width: 100%; gap: 0.5rem; }
.mini-rank li:hover { background: var(--surface-2); }
.delta { font-variant-numeric: tabular-nums; font-weight: 600; }
.delta--down { color: var(--accent-ink); }
.delta--up { color: var(--critical); }
.link-btn { all: unset; cursor: pointer; color: var(--accent-ink); font-size: 0.9rem; text-decoration: underline; text-underline-offset: 2px; }

/* ---- charts ------------------------------------------------------------ */
.chart { width: 100%; position: relative; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line--mean { stroke: var(--series-1); }
.chart .line--median { stroke: var(--series-2); }
.chart .band { fill: var(--band); }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .dot--mean { fill: var(--series-1); }
.chart .dot--median { fill: var(--series-2); }
.line-key--mean { background: var(--series-1); }
.line-key--median { background: var(--series-2); }
.chart .bar { fill: var(--series-1); }
.chart .bar.is-hover { fill: var(--accent-ink); }
.chart .bar-marker { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 3 3; }
.chart .bar-marker-label { fill: var(--ink-2); font-weight: 600; }
.chart .hit { fill: transparent; cursor: crosshair; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); box-shadow: var(--shadow);
  border-radius: 10px; padding: 0.55rem 0.7rem; font-size: 0.82rem; min-width: 140px; max-width: 260px;
}
.tooltip strong { display: block; margin-bottom: 0.2rem; }
.tooltip .row { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.tooltip .row span:first-child { color: var(--ink-2); display: inline-flex; align-items: center; gap: 0.35rem; }
.tooltip .key { width: 10px; height: 2px; border-radius: 2px; display: inline-block; }

/* ---- toolbar ----------------------------------------------------------- */
.toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; border: 1px solid var(--border); }
.segmented button { border: 0; background: transparent; padding: 0.35rem 0.8rem; border-radius: 999px; cursor: pointer; color: var(--ink-2); font-size: 0.88rem; }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }

/* ---- rankings ---------------------------------------------------------- */
.ranking { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.ranking li { display: grid; grid-template-columns: 2.25rem 1fr auto; align-items: center; gap: 0.75rem; padding: 0.7rem 1.1rem; border-top: 1px solid var(--border); counter-increment: rank; }
.ranking li:first-child { border-top: 0; }
.ranking li::before { content: counter(rank); font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; text-align: right; }
.ranking li.empty { display: block; color: var(--ink-2); padding: 1.25rem; }
.ranking li.empty::before { content: none; }
.ranking .name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .sub { display: block; font-size: 0.82rem; color: var(--ink-2); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.ranking .price { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.ranking .price small { display: block; font-weight: 400; color: var(--ink-2); font-size: 0.78rem; }
.badge { display: inline-block; font-size: 0.7rem; font-weight: 650; padding: 0.1rem 0.45rem; border-radius: 999px; vertical-align: 1px; margin-left: 0.35rem; }
.badge--real { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.badge--best { background: var(--accent); color: #fff; }
.ranking--near li.is-best { background: var(--accent-wash); }
.ranking a { color: inherit; text-decoration: none; }
.ranking a:hover .name { text-decoration: underline; }

/* ---- nearby ------------------------------------------------------------ */
.near-layout { display: grid; grid-template-columns: 340px 1fr; gap: 1rem; align-items: start; }
.near-form { display: grid; gap: 1rem; }
.or { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.8rem; }
.or::before, .or::after { content: ""; height: 1px; background: var(--border); flex: 1; }

/* ---- forms ------------------------------------------------------------- */
.field { display: grid; gap: 0.35rem; font-size: 0.88rem; color: var(--ink-2); }
.field span { display: flex; justify-content: space-between; gap: 0.5rem; }
.field output { color: var(--ink); font-variant-numeric: tabular-nums; }
.field input, .field select {
  width: 100%; padding: 0.6rem 0.75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--page); color: var(--ink); font-size: 1rem;
}
.field input[type="range"] { padding: 0; accent-color: var(--accent); border: 0; background: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.65rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn[disabled] { opacity: 0.6; cursor: progress; }

.contrib { display: grid; grid-template-columns: 1fr 1.6fr; gap: 1.5rem; align-items: center; }
.contrib__form { display: grid; grid-template-columns: 2fr 1.4fr 1fr auto; gap: 0.75rem; align-items: end; }
.contrib__form .small { grid-column: 1 / -1; margin: 0; min-height: 1.3em; }
.is-error { color: var(--critical); }
.is-ok { color: var(--good); }

/* ---- table ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th, .table td { padding: 0.75rem 1.1rem; text-align: right; border-top: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
.table thead th { border-top: 0; font-size: 0.78rem; color: var(--ink-2); font-weight: 600; background: var(--surface-2); }
.table th:first-child, .table td:first-child { text-align: left; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-current { background: var(--accent-wash); }
.range-bar { display: inline-block; vertical-align: middle; width: 110px; height: 6px; border-radius: 3px; background: var(--surface-2); position: relative; margin-left: 0.5rem; }
.range-bar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; background: var(--series-1); }

/* ---- prose & footer ---------------------------------------------------- */
.prose p { color: var(--ink-2); font-size: 0.95rem; }
.footer { margin-top: 3rem; border-top: 1px solid var(--border); padding: 1.5rem 0 2.5rem; font-size: 0.85rem; color: var(--ink-2); }
.footer__inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.footer p { margin: 0; }

/* ---- responsive -------------------------------------------------------- */
@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .map-layout, .grid-2, .near-layout, .contrib { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; padding-top: 2rem; }
}
@media (max-width: 720px) {
  html { scroll-padding-top: 116px; }
  .nav { display: none; }
  .topbar__inner { justify-content: space-between; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpis .kpi:first-child { grid-column: 1 / -1; }
  .kpi__value { font-size: 1.45rem; }
  .grid-3 { grid-template-columns: 1fr; gap: 0.5rem; }
  .contrib__form { grid-template-columns: 1fr 1fr; }
  .contrib__form .field:first-child { grid-column: 1 / -1; }
  .contrib__form .btn { grid-column: 1 / -1; }
  .ranking li { padding: 0.65rem 0.9rem; gap: 0.6rem; grid-template-columns: 1.6rem 1fr auto; }
  .card { padding: 1rem; }
  .card--flush { padding: 0; }
  .legend__swatch { width: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (forced-colors: active) {
  .map path { stroke: CanvasText; }
}
