:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --line: #e2e0d8;
  --text: #1c2324;
  --muted: #5f6b6c;
  --brand: #0f3d3e;
  --brand-ink: #ffffff;
  --accent: #c98a0a;
  --good: #1f7a4d;
  --warn: #a45a00;
  --bad: #b3261e;
  --chip-l: 92%;
  --chip-ink-l: 26%;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 14px;
  --nav-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1415;
    --surface: #171e1f;
    --surface-2: #1e2728;
    --line: #2b3536;
    --text: #e8ecec;
    --muted: #97a4a5;
    --brand: #7fc8c0;
    --brand-ink: #0b2223;
    --accent: #f2c14e;
    --good: #5cc58f;
    --warn: #f0a547;
    --bad: #ff8a80;
    --chip-l: 22%;
    --chip-ink-l: 82%;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1415; --surface: #171e1f; --surface-2: #1e2728; --line: #2b3536; --text: #e8ecec; --muted: #97a4a5;
  --brand: #7fc8c0; --brand-ink: #0b2223; --accent: #f2c14e; --good: #5cc58f; --warn: #f0a547; --bad: #ff8a80;
  --chip-l: 22%; --chip-ink-l: 82%; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); }
h1 { font-size: 26px; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.app { min-height: 100dvh; }
main {
  padding: calc(env(safe-area-inset-top) + 16px) max(16px, env(safe-area-inset-right)) calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px) max(16px, env(safe-area-inset-left));
  max-width: 1180px;
  margin: 0 auto;
  outline: none;
}
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.nav .brand { display: none; }
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 10.5px; font-weight: 600;
}
.nav a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--brand); }
.nav a.extra { display: none; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 220px 1fr; }
  .nav {
    position: sticky; top: 0; inset: auto; height: 100dvh; flex-direction: column; justify-content: flex-start; gap: 2px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line); background: var(--surface);
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 14.5px; padding: 10px 12px; border-radius: 10px; }
  .nav a.active { background: var(--surface-2); }
  .nav a.extra { display: flex; }
  .nav a.more { display: none; }
  main { padding: 32px 36px 48px; }
}

/* ---------- building blocks ---------- */
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.head p { margin: 4px 0 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: grid; gap: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.tight { padding: 12px 14px; }
.section { margin: 26px 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: 600 14px var(--font); padding: 10px 14px; border-radius: 10px; cursor: pointer; min-height: 42px;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); padding-inline: 8px; }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.field { display: grid; align-content: start; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; }
input, select, textarea {
  font: 16px var(--font); /* 16px stops iOS zoom-on-focus */
  color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); }
.form .wide { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 220px; width: auto; }

/* chips */
.chip {
  --h: 180;
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 600;
  background: hsl(var(--h) 55% var(--chip-l)); color: hsl(var(--h) 60% var(--chip-ink-l)); border: 1px solid transparent; white-space: nowrap;
}
.chip.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: hsl(var(--h) 60% 45%); }
.chip.plain { background: var(--surface-2); color: var(--muted); }
button.chip { cursor: pointer; font-family: var(--font); min-height: 32px; padding: 4px 12px; }
button.chip[aria-pressed="false"] { background: transparent; border-color: var(--line); color: var(--muted); }
button.chip[aria-pressed="false"].dot::before { opacity: 0.5; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
@media (min-width: 900px) { .chips { flex-wrap: wrap; overflow: visible; } }

.badge { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.good { color: var(--good); background: color-mix(in srgb, var(--good) 13%, transparent); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.badge.brand { color: var(--brand); background: color-mix(in srgb, var(--brand) 13%, transparent); }

/* KPIs */
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 8px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }

/* market */
.city { margin-top: 28px; }
.city > h2 { font-size: 21px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.hood { margin-top: 14px; }
.hood-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sale { display: grid; gap: 8px; border-left: 4px solid hsl(var(--h, 180) 55% 50%); }
.sale .price { font-size: 21px; font-weight: 750; font-variant-numeric: tabular-nums; }
.sale .addr { font-weight: 600; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.facts b { color: var(--text); font-weight: 650; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12.5px; }
.sources a { text-decoration: none; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); }
.sources a.unverified { color: var(--warn); }
details > summary { cursor: pointer; font-weight: 600; color: var(--brand); padding: 6px 0; list-style-position: inside; }
.news { display: grid; gap: 4px; }
.news a.title { font-weight: 650; text-decoration: none; color: var(--text); }

/* timeline */
.timeline { display: grid; gap: 0; }
.tl { display: grid; grid-template-columns: 92px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.tl:last-child { border-bottom: 0; }
.tl .kind { font-weight: 650; }
.tl.sale .kind { color: var(--good); }
.tl.rental .kind { color: #6b5bd2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tl.rental .kind { color: #b4a9ff; } }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 700; }
td.r, th.r { text-align: right; }

/* calculator */
.calc { display: grid; gap: 16px; }
@media (min-width: 1000px) { .calc { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; } .calc .results { position: sticky; top: 24px; } }
.total { font-size: 40px; font-weight: 780; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; margin: 14px 0 10px; background: var(--surface-2); }
.bar span { display: block; min-width: 3px; }
.legend { display: grid; gap: 6px; }
.legend div { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; font-size: 14px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.legend .v { font-variant-numeric: tabular-nums; font-weight: 650; }
.src-note { font-size: 12px; color: var(--muted); margin-top: 3px; font-weight: 500; }
.src-note a { color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--muted); font: 600 14px var(--font); padding: 9px 12px; cursor: pointer; min-height: 42px; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* jobs + toast + dialog */
.jobs { position: fixed; z-index: 30; right: max(12px, env(safe-area-inset-right)); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); display: grid; gap: 8px; width: min(380px, calc(100vw - 24px)); }
@media (min-width: 900px) { .jobs { bottom: 20px; } }
.job { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: 0 8px 30px rgb(0 0 0 / 0.14); font-size: 13px; }
.job .t { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.job .p { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 40; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translate(-50%, -150%); transition: transform 0.25s; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; max-width: calc(100vw - 32px); }
.toast.show { transform: translate(-50%, 0); }
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog .dlg { padding: 18px; display: grid; gap: 14px; max-height: 85dvh; overflow: auto; }

/* more menu */
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.tile { display: grid; grid-template-columns: 40px 1fr; gap: 4px 12px; align-items: center; text-decoration: none; color: inherit; }
.tile svg { grid-row: span 2; width: 28px; height: 28px; fill: none; stroke: var(--brand); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; justify-self: center; }
.tile b { font-size: 16px; }
.tile span { color: var(--muted); font-size: 13px; }

/* copy blocks (listing kit, outreach) */
.copyblock { display: grid; gap: 6px; }
.copyblock .text { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 12px; font-size: 14.5px; }
.copyblock .head2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
mark.fh { background: color-mix(in srgb, var(--bad) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
mark.fh.review { background: color-mix(in srgb, var(--warn) 25%, transparent); }
.thumbs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.thumbs img { height: 72px; width: auto; border-radius: 8px; flex: none; border: 2px solid transparent; }
.thumbs img.cover { border-color: var(--accent); }

/* open house sign-in (kiosk) */
body.kiosk .nav, body.kiosk .jobs { display: none; }
body.kiosk main { padding-bottom: calc(env(safe-area-inset-bottom) + 24px); max-width: 720px; }
.kiosk-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.kiosk-head h1 { font-size: 30px; }
.qr { background: #fff; padding: 8px; border-radius: 12px; width: 132px; flex: none; text-align: center; color: #333; font-size: 11px; font-weight: 600; }
.qr svg { width: 116px; height: 116px; display: block; }
.big-form input, .big-form select, .big-form textarea { font-size: 18px; min-height: 52px; }
.big-form .btn { min-height: 54px; font-size: 17px; justify-content: center; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; }
.choice label { flex: 1 1 120px; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; border: 1px solid var(--line); border-radius: 10px; font-weight: 600; color: var(--text); background: var(--surface); cursor: pointer; padding: 6px 10px; text-align: center; }
.choice input { width: auto; min-height: 0; }
.choice label:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, var(--surface)); }
.thanks { text-align: center; padding: 60px 16px; }
.thanks h1 { font-size: 34px; }

/* printable client pages (net sheet, CMA) */
.print-only { display: none; }

@media print {
  .print-only { display: block; }
  .nav, .jobs, .toast, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .calc { grid-template-columns: 1fr 1fr; }
}
