:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #f9f8f4;
  --ink: #1b2220;
  --muted: #5d6762;
  --line: #e2ded4;
  --brand: #14513d;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe8;
  --green: #1f7a4d;
  --green-soft: #e1f2e8;
  --amber: #a5650a;
  --amber-soft: #fbefd9;
  --red: #b33a2b;
  --red-soft: #fbe4df;
  --none: #6b7470;
  --none-soft: #eceae4;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(20 30 25 / 6%), 0 4px 14px rgb(20 30 25 / 5%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1714;
    --surface: #17211d;
    --surface-2: #1c2823;
    --ink: #e8eee9;
    --muted: #9aa8a1;
    --line: #2a3832;
    --brand: #5fbf93;
    --brand-ink: #0b1310;
    --brand-soft: #1d3a2e;
    --green: #6fd09e;
    --green-soft: #183327;
    --amber: #f0b45a;
    --amber-soft: #3a2d15;
    --red: #f08a7a;
    --red-soft: #3c1f1a;
    --none: #9aa8a1;
    --none-soft: #222d29;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0.35rem 0; }
small, .small { font-size: 0.82rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.good { color: var(--green); }
.bad { color: var(--red); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -0.01em; }
.gear { color: var(--muted); display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; }
.gear:hover { background: var(--surface); }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; box-shadow: var(--shadow);
}
.section { margin: 24px 4px 4px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* Hero */
.hero { padding: 20px 4px 8px; }
.hero .eyebrow { color: var(--muted); font-size: 0.85rem; margin: 0; }
.hero .big { font-size: 2.6rem; font-weight: 750; letter-spacing: -0.03em; margin: 0; font-variant-numeric: tabular-nums; color: var(--brand); }
.hero.empty { padding: 32px 4px 8px; }
.hero.empty h1 { font-size: 1.8rem; letter-spacing: -0.02em; }
.how ol { padding-left: 1.2rem; margin: 0; }
.how li { margin: 0.5rem 0; }

/* Alerts */
.alerts { display: grid; gap: 8px; margin: 8px 0; }
.alert { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--amber-soft); color: var(--ink); text-decoration: none; font-size: 0.92rem; }
.note { font-size: 0.85rem; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.note.warn { background: var(--amber-soft); border-color: transparent; }
.ok { color: var(--green); font-size: 0.9rem; }

/* Bill cards */
.list { display: grid; gap: 10px; margin-top: 12px; }
.bill {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--none);
  border-radius: var(--radius); padding: 14px 14px 14px 12px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
}
.bill.green { border-left-color: var(--green); }
.bill.amber { border-left-color: var(--amber); }
.bill.red { border-left-color: var(--red); }
.bill-icon { font-size: 1.5rem; text-align: center; }
.bill-main { display: grid; min-width: 0; }
.bill-name { font-weight: 650; }
.bill-sub { color: var(--muted); font-size: 0.82rem; }
.bill-line { font-size: 0.88rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { font-size: 0.72rem; font-weight: 650; padding: 4px 9px; border-radius: 999px; white-space: nowrap; background: var(--none-soft); color: var(--none); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: var(--red-soft); color: var(--red); }

.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--brand); color: var(--brand-ink); text-decoration: none; font-weight: 650;
  padding: 14px 20px; border-radius: 999px; box-shadow: 0 6px 20px rgb(20 81 61 / 35%);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--red); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.88rem; }
.btn.busy { opacity: 0.6; pointer-events: none; }
.btn.busy::after { content: '…'; }
.actions { display: flex; gap: 10px; justify-content: space-between; margin: 16px 0; }
.actions .primary { flex: 1; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }

/* Pages */
.page-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; margin: 4px 0 8px; }
.page-head h1 { margin: 0; font-size: 1.2rem; }
.back, .edit { text-decoration: none; font-weight: 600; padding: 6px 2px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile {
  display: grid; gap: 4px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink); font-weight: 600; box-shadow: var(--shadow);
}
.tile-icon { font-size: 1.6rem; }
.tile small { color: var(--muted); font-weight: 400; }

/* Forms */
.form .card h2 { margin-bottom: 10px; }
.field { display: grid; gap: 4px; margin: 10px 0; }
.field > span { font-size: 0.88rem; font-weight: 600; }
.field small { color: var(--muted); }
.input-wrap { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.input-wrap:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input-wrap i { font-style: normal; color: var(--muted); padding: 0 10px; font-size: 0.88rem; white-space: nowrap; }
input, select { font: inherit; color: var(--ink); }
.input-wrap input { border: 0; background: transparent; padding: 11px 12px; width: 100%; min-width: 0; outline: none; }
.input-wrap i + input { padding-left: 0; }
select, .quote-form input, input[type='search'] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
}
.row2, .row3 { display: grid; gap: 10px; }
.row2 { grid-template-columns: 1fr 1fr; }
.row3 { grid-template-columns: repeat(3, 1fr); }
.seg { border: 0; padding: 0; margin: 12px 0; }
.seg legend { font-size: 0.88rem; font-weight: 600; margin-bottom: 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg legend { width: 100%; }
.seg label { flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 0.88rem; cursor: pointer;
}
.seg input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.check { display: flex; gap: 10px; align-items: center; margin: 10px 0; font-size: 0.93rem; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.scan { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--brand-soft); border-color: transparent; }
.scan { flex-wrap: wrap; }
.scan p { font-size: 0.85rem; margin: 2px 0 0; }
.scan-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.picked { padding: 10px 12px; border-radius: 10px; background: var(--brand-soft); margin: 8px 0; }
.picked small { color: var(--muted); display: block; }
.results { display: grid; gap: 6px; margin: 6px 0; }
.result { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font: inherit; color: var(--ink); cursor: pointer; display: grid; }
.result small { color: var(--muted); }

/* Detail */
.summary { border-radius: var(--radius); padding: 18px; margin: 8px 0 4px; background: var(--none-soft); }
.summary.green { background: var(--green-soft); }
.summary.amber { background: var(--amber-soft); }
.summary.red { background: var(--red-soft); }
.summary .big { font-size: 1.8rem; font-weight: 750; letter-spacing: -0.02em; margin: 8px 0 4px; font-variant-numeric: tabular-nums; }
.summary .big small { font-size: 0.95rem; font-weight: 500; color: var(--muted); }
.meta { font-size: 0.8rem; color: var(--muted); margin: 8px 4px; }
.split { display: flex; gap: 16px; align-items: center; }
.score {
  --s: 5; flex: none; width: 76px; height: 76px; border-radius: 50%; display: grid; place-content: center; text-align: center;
  background: conic-gradient(var(--brand) calc(var(--s) * 10%), var(--line) 0);
  position: relative;
}
.score::before { content: ''; position: absolute; inset: 7px; border-radius: 50%; background: var(--surface); }
.score b, .score small { position: relative; }
.score b { font-size: 1.5rem; line-height: 1; }
.score small { color: var(--muted); font-size: 0.7rem; }
.toggles { margin: 4px 4px 8px; }
.toggles .check { margin: 6px 0; font-size: 0.88rem; }
.seg-inline { display: flex; gap: 6px; }
.pill { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font: inherit; font-size: 0.85rem; color: var(--ink); cursor: pointer; }
.pill.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.offers { display: grid; gap: 10px; }
.offer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.offer.current { border-color: var(--brand); }
.offer-head { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: start; }
.offer-head div:nth-child(2) { display: grid; min-width: 0; }
.offer-head div:nth-child(2) span { color: var(--muted); font-size: 0.88rem; }
.rank { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.price { text-align: right; font-weight: 750; font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price em { display: block; }
.price small.sub { display: block; }
.price small { font-weight: 500; font-size: 0.75rem; color: var(--muted); }
.price em { font-style: normal; font-size: 0.82rem; font-weight: 650; }
.price em.good { color: var(--green); }
.price em.bad { color: var(--red); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px 38px; }
.tag { font-size: 0.75rem; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.tag.you { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
details { margin: 10px 0 0 38px; }
summary { cursor: pointer; color: var(--brand); font-size: 0.88rem; font-weight: 600; }
.kv { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.kv td { padding: 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv td:last-child { text-align: right; }
.kv caption { text-align: left; font-size: 0.78rem; color: var(--muted); padding-top: 6px; }
.kv small { color: var(--muted); display: block; }

.script pre { white-space: pre-wrap; font: inherit; font-size: 0.92rem; margin: 0 0 12px; }
.quotes { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.quotes th { text-align: left; font-size: 0.75rem; color: var(--muted); font-weight: 600; padding: 4px 0; }
.quotes td { padding: 8px 4px 8px 0; border-top: 1px solid var(--line); }
.quotes td small { display: block; color: var(--muted); }
.quotes tr.you td { font-weight: 650; }
.x { border: 0; background: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.quote-form { display: grid; gap: 8px; margin-top: 12px; }
.checklist h3 { margin-top: 10px; font-size: 0.85rem; color: var(--muted); }
.reminders .btn { margin: 4px 6px 4px 0; }

.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--line); }
.chart .bar.now { fill: var(--brand); }
.chart .bar.quote { fill: var(--green); }
.chart rect { fill: var(--line); }
.chart rect.now { fill: var(--brand); }
.chart rect.quote { fill: var(--green); }
.chart .bar-val { font-size: 11px; fill: var(--ink); font-weight: 600; }
.chart .bar-lbl { font-size: 11px; fill: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 0.9rem;
  opacity: 0; transition: 0.25s; z-index: 20; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body:not([data-view='home']) .fab { display: none; }
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

/* Home screen groups */
.group { display: grid; gap: 10px; }
.group + .group { margin-top: 14px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 4px 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.group-save { text-transform: none; letter-spacing: 0; font-size: 0.85rem; font-weight: 650; color: var(--red); }
