/* Tokens: the dataviz reference palette (validated), light and dark. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --accent-track: #cde2fb;
  --deemph: #c9c8c0;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-text: #b42f2f;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 2px 8px rgba(11, 11, 11, 0.04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "Arial Hebrew", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --accent-track: #184f95;
    --deemph: #4b4a46;
    --good-text: #0ca30c;
    --critical-text: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #9a988f;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: rgba(57, 135, 229, 0.14);
  --accent-track: #184f95;
  --deemph: #4b4a46;
  --good-text: #0ca30c;
  --critical-text: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 22px; }
p { margin: 0 0 8px; }
a { color: var(--accent-ink); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 17px; }
.brand-mark { width: 24px; height: 24px; color: var(--accent); }
.freshness {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 3px 10px; font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.banner {
  margin: 0; padding: 8px 16px; font-size: 14px; text-align: center;
  background: color-mix(in srgb, var(--warning) 22%, var(--page)); color: var(--ink);
}

main { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin: 0 0 12px;
}
.card-title { font-size: 17px; font-weight: 650; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center-note { text-align: center; color: var(--muted); padding: 32px 12px; }
.warn-text { color: var(--critical-text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-weight: 600; text-decoration: none; color: var(--ink); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.wide { width: 100%; margin-top: 8px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; width: 44px; height: 44px; cursor: pointer; color: var(--ink-2); }

/* Fields */
.field { margin: 12px 0 0; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-label { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 4px; }
select, input[type="search"] {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--axis); background: var(--surface); color: var(--ink);
}
input[type="search"] { font-size: 17px; }
.slider-field { margin-top: 14px; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
.slider-head output { font-weight: 650; }
input[type="range"] { width: 100%; height: 36px; accent-color: var(--accent); margin: 2px 0 0; }

.segmented {
  display: flex; gap: 4px; padding: 3px; margin-top: 4px;
  background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border);
}
.segmented button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent;
  font-size: 14px; color: var(--ink-2); cursor: pointer; padding: 6px 4px;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 650; box-shadow: var(--shadow); }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 44px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { width: 44px; height: 26px; border-radius: 13px; background: var(--axis); position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(-18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

details.more { margin-top: 12px; }
details.more > summary, details.table-view > summary { cursor: pointer; color: var(--accent-ink); font-size: 15px; min-height: 32px; }

.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 6; inset-inline: 0; top: calc(100% + 4px);
  max-height: 50vh; overflow: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.14);
}
.combo-list button {
  display: flex; justify-content: space-between; width: 100%; min-height: 44px;
  padding: 10px 14px; border: 0; background: transparent; text-align: start; cursor: pointer;
}
.combo-list button:hover, .combo-list button[aria-selected="true"] { background: var(--accent-wash); }
.combo-list .count { color: var(--muted); font-size: 14px; }

.chip-row, .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px;
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 14px; color: var(--ink); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.model { font-weight: 650; }

/* Hero figure */
.hero { text-align: center; padding: 20px 16px; }
.hero-label { color: var(--ink-2); font-size: 15px; }
.hero-value { font-size: 52px; font-weight: 700; line-height: 1.1; margin: 4px 0 8px; letter-spacing: -0.5px; }
.hero-sub { font-size: 16px; color: var(--ink); }
.source { display: inline-block; font-size: 13px; color: var(--ink-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; margin-inline-start: 6px; }

/* Action lists: compromises, upgrades, alternatives */
.action-list { list-style: none; margin: 0; padding: 0; }
.action-list li + li { border-top: 1px solid var(--grid); }
.action-list button {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 12px 2px; border: 0; background: transparent; text-align: start; cursor: pointer; min-height: 52px;
}
.action-list .what { font-weight: 600; }
.action-list .why { color: var(--muted); font-size: 14px; grid-column: 1; }
.action-list .amount { grid-row: 1 / span 2; grid-column: 2; font-weight: 700; font-size: 17px; }
.amount.save { color: var(--good-text); }
.amount.cost { color: var(--ink-2); }

/* Charts */
.chart-card { margin: 0 0 12px; }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .value-label { fill: var(--ink); font-size: 12px; font-weight: 650; }
.chart .bar { fill: var(--deemph); cursor: pointer; transition: fill .12s; }
.chart .bar.selected { fill: var(--accent); }
.chart .bar:hover, .chart .bar:focus { fill: var(--accent-ink); outline: none; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-wash); stroke: none; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .marker { stroke: var(--ink-2); stroke-width: 1; }
.table-view table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 14px; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { text-align: start; padding: 4px 6px; border-bottom: 1px solid var(--grid); }
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 240px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 10px; font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,.16);
}
.tooltip strong { display: block; font-size: 15px; }

/* Facts */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 4px 0 8px; font-size: 15px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; }
.note { border-inline-start: 3px solid var(--accent); padding: 4px 10px; margin: 8px 0; font-size: 15px; }
.note .kind { font-size: 12px; color: var(--ink-2); display: block; }

/* Listing cards */
.list-count { margin: 4px 4px 8px; }
.listing-list, .model-cards, .review-list { list-style: none; margin: 0; padding: 0; }
.listing { padding: 14px; }
.listing-top { display: flex; gap: 12px; align-items: flex-start; }
.listing-thumb { width: 92px; height: 70px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; }
.listing-main { flex: 1; min-width: 0; }
.listing-title { font-weight: 650; font-size: 16px; }
.listing-trim { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score {
  flex: none; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  font-weight: 700; font-size: 16px; background: var(--accent-wash); color: var(--accent-ink);
  border: 2px solid var(--accent);
}
.score.low { border-color: var(--deemph); background: var(--surface-2); color: var(--ink-2); }
.price-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.price { font-size: 22px; font-weight: 700; }
.delta { font-size: 14px; font-weight: 600; }
.delta.cheap { color: var(--good-text); }
.delta.dear { color: var(--critical-text); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.flags { list-style: none; margin: 8px 0 0; padding: 0; }
.flag { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin-top: 4px; }
.flag-icon { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; margin-top: 1px; }
.flag.warn .flag-icon { background: var(--critical); }
.flag.good .flag-icon { background: var(--good); }
.flag.info .flag-icon { background: var(--muted); }
.listing details { margin-top: 8px; }
.listing summary { cursor: pointer; color: var(--accent-ink); font-size: 14px; min-height: 32px; }
.checklist { margin: 6px 0 0; padding-inline-start: 20px; font-size: 14px; }
.parts { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 8px; align-items: center; font-size: 13px; margin: 8px 0; }

/* Meters */
.meter { height: 8px; border-radius: 4px; background: var(--accent-track); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter.empty { background: var(--surface-2); }

/* Model cards */
.model-card .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.model-card .name { font-size: 18px; font-weight: 650; }
.model-card .entry { font-weight: 650; }
.model-card .entry.over { color: var(--muted); font-weight: 500; }
.model-card .dims { display: grid; grid-template-columns: auto 1fr 28px; gap: 6px 10px; align-items: center; margin: 10px 0; font-size: 14px; }
.model-card .dims .num { text-align: end; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.model-card .actions { display: flex; gap: 8px; }
.model-card .actions .btn { flex: 1; }

.review-list li { padding: 10px 0; border-top: 1px solid var(--grid); }
.review-list .who { font-size: 13px; color: var(--muted); }
.review-list .actions { display: flex; gap: 8px; margin-top: 6px; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel { background: var(--page); width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--page); padding-top: 8px; }
.recalls { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.recalls li { padding: 8px 0; border-top: 1px solid var(--grid); }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 60px; border: 0; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.tabbar svg { width: 26px; height: 26px; }
.tabbar button[aria-current="page"] { color: var(--accent-ink); font-weight: 650; }

.login-card { text-align: center; padding: 24px 18px; }
.login-card .btn { margin-top: 8px; }
.explain { margin: 12px 4px; }

@media (min-width: 900px) {
  main { padding-top: 20px; }
  .hero-value { font-size: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (forced-colors: active) {
  .chart .bar.selected { fill: Highlight; }
  .meter > span { background: Highlight; }
}
