/* Layout: inputs stacked on the left like a worksheet, a sticky calculator
   "display" on the right, the area report full width underneath.
   Palette: "Deep Ocean", a single deliberate dark theme. */
:root {
  --abyss: #0B1D2A;         /* page */
  --deep: #12303F;          /* panels */
  --ocean: #1F8FBF;         /* primary actions */
  --lagoon: #4FD1C5;        /* highlights, good numbers */
  --foam: #E8F4F8;          /* text */

  --bg: var(--abyss);
  --surface: var(--deep);
  --field: #0E2533;
  --ink: var(--foam);
  --muted: #8FB2C2;
  --line: #21485B;
  --accent: var(--ocean);
  --accent-ink: #FFFFFF;
  --lcd: #08161F;
  --lcd-ink: var(--foam);
  --lcd-muted: #7FA6B8;
  --good: var(--lagoon);
  --warn: #F2C063;
  --bad: #FF8A8A;
  --lcd-good: var(--lagoon);
  --lcd-warn: #F2C063;
  --lcd-bad: #FF8A8A;
  --focus: var(--lagoon);

  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Public Sans", "Segoe UI", system-ui, sans-serif;
  --f-num: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: radial-gradient(1200px 500px at 15% -10%, rgba(31, 143, 191, 0.22), transparent 60%), var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 15px/1.5 var(--f-body);
  padding: env(safe-area-inset-top, 0px) 16px env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; margin: 0; }

/* Header */
.top {
  max-width: 1280px; margin: 0 auto; padding-block: 28px 20px;
  display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap;
}
.top h1 { font-size: clamp(1.7rem, 3.2vw, 2.4rem); letter-spacing: -0.02em; }
.top p { margin: 6px 0 0; color: var(--muted); max-width: 62ch; }

/* Main layout */
.layout {
  max-width: 1280px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 24px; align-items: start;
}
@media (max-width: 960px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.inputs { display: grid; gap: 16px; min-width: 0; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 20px; display: grid; gap: 14px;
}
.panel.quiet { background: transparent; }
.panel h2 { font-size: 1.15rem; }
.panel h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-family: var(--f-body); font-weight: 600; }
.note { margin: 0; color: var(--muted); font-size: 0.9rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 14px; }
.span2 { grid-column: span 2; }
@media (max-width: 460px) { .span2 { grid-column: auto; } .grid { grid-template-columns: minmax(0, 1fr); } }

.f { display: grid; gap: 5px; font-size: 0.82rem; font-weight: 600; color: var(--muted); align-content: start; min-width: 0; }
.f small { font-weight: 400; font-size: 0.78rem; line-height: 1.4; }
.f.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 500; font-size: 0.9rem; align-self: end; padding-bottom: 8px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }

input[type="text"], input[type="number"], input[type="password"], input[type="date"], select {
  font: 500 0.98rem var(--f-num); color: var(--ink);
  background: var(--field); border: 1px solid var(--line); border-radius: 7px;
  padding: 9px 10px; width: 100%; min-width: 0;
  font-variant-numeric: tabular-nums;
}
select { font-family: var(--f-body); }
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--ocean); width: 17px; height: 17px; margin: 0; }

.btn {
  font: 600 0.92rem var(--f-body); border-radius: 7px; padding: 9px 16px; cursor: pointer;
  border: 1px solid var(--accent); white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #2AA0D2; }
.btn.ghost:hover { border-color: var(--lagoon); color: var(--lagoon); }
.btn.primary:disabled { opacity: 0.6; cursor: progress; }
.btn.ghost { background: transparent; color: var(--foam); border-color: var(--line); }
.link { background: none; border: 0; padding: 0; color: var(--lagoon); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }

.seg { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: fit-content; max-width: 100%; }
.seg label { display: flex; align-items: center; gap: 7px; padding: 8px 14px; cursor: pointer; font-size: 0.9rem; border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }

.hint { color: var(--muted); }
.hint:empty { display: none; }
.status { margin: 0; font-size: 0.88rem; padding: 9px 12px; border-radius: 7px; background: var(--field); border-left: 3px solid var(--line); }
.status[data-tone="good"] { border-left-color: var(--good); }
.status[data-tone="warn"] { border-left-color: var(--warn); }
.status[data-tone="bad"] { border-left-color: var(--bad); }

/* Results display */
.results { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 12px); display: grid; gap: 14px; min-width: 0; }
@media (max-width: 960px) { .results { position: static; } }
.display {
  background: linear-gradient(160deg, var(--deep) 0%, var(--lcd) 70%); border: 1px solid var(--line); color: var(--lcd-ink); border-radius: 14px; padding: 18px;
  display: grid; gap: 14px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.verdict { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill { font: 700 0.95rem var(--f-display); padding: 3px 10px; border-radius: 999px; margin-right: 4px; }
.pill[data-tone="good"] { background: var(--lcd-good); color: var(--lcd); }
.pill[data-tone="warn"] { background: var(--lcd-warn); color: var(--lcd); }
.pill[data-tone="bad"] { background: var(--lcd-bad); color: var(--lcd); }
.chip { font: 0.75rem var(--f-num); padding: 2px 7px; border-radius: 5px; border: 1px solid var(--lcd-muted); color: var(--lcd-muted); }
.chip[data-ok="true"] { color: var(--lcd-good); border-color: var(--lcd-good); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
.tile { display: grid; gap: 2px; padding: 12px; border-radius: 9px; background: rgba(31, 143, 191, 0.10); border: 1px solid rgba(79, 209, 197, 0.12); min-width: 0; }
.tile dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--lcd-muted); }
.tile dd { margin: 0; font: 600 clamp(1.25rem, 2.6vw, 1.6rem)/1.2 var(--f-num); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile dd[data-tone="good"] { color: var(--lcd-good); }
.tile dd[data-tone="warn"] { color: var(--lcd-warn); }
.tile dd[data-tone="bad"] { color: var(--lcd-bad); }
.tile span { font-size: 0.74rem; color: var(--lcd-muted); }

.breakdown { min-width: 0; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.breakdown details { border-bottom: 1px solid var(--line); }
.breakdown details:last-child { border-bottom: 0; }
.breakdown summary {
  cursor: pointer; padding: 11px 16px; font: 600 0.95rem var(--f-display);
  display: flex; justify-content: space-between; gap: 10px;
}
.breakdown summary b { font: 600 0.88rem var(--f-num); color: var(--muted); }
.breakdown table { width: 100%; border-collapse: collapse; margin: 0 0 8px; font-size: 0.86rem; }
.breakdown th { text-align: left; font-weight: 400; color: var(--muted); padding: 4px 16px; }
.breakdown td { text-align: right; padding: 4px 16px; font-family: var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 460px) { .breakdown td { white-space: normal; } .breakdown th, .breakdown td { padding-inline: 12px; } }
tr.sub th, tr.sub td { border-top: 1px dashed var(--line); }
tr.total th, tr.total td { border-top: 1px solid var(--muted); font-weight: 600; color: var(--ink); }
.pos td { color: var(--good); }
.neg td { color: var(--bad); }
td.pos { color: var(--good); }
td.neg { color: var(--bad); }

/* Area report */
.area { max-width: 1280px; margin: 28px auto 0; display: grid; gap: 12px; }
.area h2 { font-size: 1.4rem; }
.area-meta { margin: 0; color: var(--muted); }
.area-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 960px) { .area-grid { grid-template-columns: minmax(0, 1fr); } }
.scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; max-height: 520px; overflow-y: auto; }
.stats, .comps { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.stats caption, .comps caption { text-align: left; padding: 12px 14px 6px; font: 600 1rem var(--f-display); }
.stats th, .stats td, .comps th, .comps td { padding: 6px 14px; text-align: left; border-top: 1px solid var(--line); }
.stats td, .comps td:last-child, .comps td:first-child { font-family: var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats thead th, .comps thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.stats tr.mine { background: rgba(79, 209, 197, 0.10); }
.muted { color: var(--muted); }
.fine { font-size: 0.78rem; color: var(--muted); margin: 0; max-width: 90ch; }

.foot { max-width: 1280px; margin: 32px auto 0; padding-block: 16px 32px; border-top: 1px solid var(--line); font-size: 0.82rem; color: var(--muted); }

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

/* Rent evidence */
textarea {
  font: 0.9rem/1.45 var(--f-body); color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 7px; padding: 9px 10px; width: 100%; resize: vertical;
}
textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.row.wrap { flex-wrap: wrap; align-items: center; }
.links { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.links-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-right: 2px; }
.links a {
  font-size: 0.85rem; font-weight: 600; color: var(--lagoon); text-decoration: none;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px;
}
.links a:hover { border-color: var(--lagoon); }
.links a::after { content: " ↗"; font-weight: 400; }
.comps-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.comps-summary { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.86rem; color: var(--muted); }
.comps-summary b { color: var(--ink); font-family: var(--f-num); }
.file { position: relative; overflow: hidden; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.comps.saved:empty { display: none; }
.comps.saved tr.old td { color: var(--muted); }
.comps.saved tr.mine td:first-child { box-shadow: inset 3px 0 0 var(--lagoon); }
.comps small { font-size: 0.72rem; color: var(--muted); }
.comps .tag { border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.comps.preview input, .comps.preview select { font-size: 0.85rem; padding: 6px 7px; min-width: 70px; }
.comps.preview input[data-f="address"] { min-width: 180px; }
.comps.preview input[data-f="date"] { min-width: 130px; }
.comps.preview input[type="checkbox"] { min-width: 0; }
.comps.preview .narrow { width: 64px; min-width: 64px; }
.cur-in { display: flex; align-items: center; gap: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
#parsePreview { display: grid; gap: 10px; }
#compsPanel .scroll { max-height: 360px; }
.scroll:has(> .comps.saved:empty) { display: none; }
.panel > * { min-width: 0; }
.panel { grid-template-columns: minmax(0, 1fr); } .inputs { grid-template-columns: minmax(0, 1fr); }
.scroll { position: relative; }

/* Phone: results sit below the form, so keep the key numbers pinned to the bottom. */
.mini { display: none; }
@media (max-width: 960px) {
  .mini {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--lcd); color: var(--lcd-ink); text-decoration: none;
    border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.4);
  }
  .mini span { display: grid; min-width: 0; }
  .mini small { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--lcd-muted); }
  .mini b { font: 600 0.95rem var(--f-num); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mini b[data-tone="good"] { color: var(--lcd-good); }
  .mini b[data-tone="warn"] { color: var(--lcd-warn); }
  .mini b[data-tone="bad"] { color: var(--lcd-bad); }
  .foot { padding-bottom: 90px; }
  .results { scroll-margin-top: 12px; }
}

.top h1 { background: linear-gradient(90deg, var(--foam), var(--lagoon)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pill[data-tone] { color: var(--abyss); }

/* Property news */
.news { display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.tabs { display: flex; gap: 2px; background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.tabs button {
  font: 600 0.8rem var(--f-body); color: var(--muted); background: none; border: 0;
  padding: 5px 10px; border-radius: 6px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--ocean); color: #fff; }
.tabs button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.news-list { list-style: none; margin: 0; padding: 0; display: grid; }
.news-list li { display: grid; gap: 2px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.news-list li:last-child { border-bottom: 0; }
.news-list a { color: var(--ink); text-decoration: none; font-weight: 500; line-height: 1.35; }
.news-list a:hover { color: var(--lagoon); text-decoration: underline; }
.news-list span { font-size: 0.76rem; color: var(--muted); }
.tag.local { font-weight: 600; color: var(--abyss); background: var(--lagoon); border-radius: 4px; padding: 0 5px; margin-right: 6px; font-size: 0.7rem; }
.news-foot { justify-content: space-between; }
.news-foot .fine a { color: var(--lagoon); }
.comps.by-area th[scope="row"] { font-family: var(--f-num); font-weight: 600; white-space: nowrap; }
.comps.by-area td { font-family: var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.comps.by-area tr.mine { background: rgba(79, 209, 197, 0.10); }
.comps.by-area .tag { margin-left: 6px; font-family: var(--f-body); }
.comps-summary b.pos { color: var(--good); }
.comps-summary b.neg { color: var(--bad); }

/* Strategy picker and comparison */
.strategy-pick { max-width: 420px; }
.strategy-pick select { font: 600 1rem var(--f-body); border-color: var(--ocean); background: var(--field); }
.scroll-x { overflow-x: auto; }
.breakdown table.compare thead th { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; padding-block: 6px; }
.breakdown table.compare thead th:not(:first-child) { text-align: right; }
.breakdown table.compare tbody th { color: var(--ink); font-weight: 500; white-space: nowrap; }
.breakdown table.compare tr[data-pick] { cursor: pointer; }
.breakdown table.compare tr[data-pick]:hover, .breakdown table.compare tr[data-pick]:focus-visible { background: rgba(31, 143, 191, 0.12); outline: none; }
.breakdown table.compare tr.mine { background: rgba(79, 209, 197, 0.12); }
.breakdown table.compare tr.mine th { box-shadow: inset 3px 0 0 var(--lagoon); }
.breakdown table.compare tfoot td { text-align: left; white-space: normal; }
.breakdown table.compare .tag { margin-left: 4px; }
.panel > div[data-strategy]:not(.grid) { display: grid; gap: 14px; }
.breakdown table.compare th, .breakdown table.compare td { padding-inline: 8px; }
.breakdown table.compare th:first-child, .breakdown table.compare td:first-child { padding-left: 16px; }
.breakdown table.compare tfoot td { font-family: var(--f-body); padding: 6px 16px 4px; }

/* Extra bedroom payoff */
.payoff { display: grid; gap: 8px; background: var(--field); border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; }
.payoff-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.payoff-head b { font: 600 1rem var(--f-display); }
.payoff-head span { font-size: 0.8rem; color: var(--muted); }
.payoff table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.payoff th { text-align: left; font-weight: 600; color: var(--muted); padding: 5px 10px 5px 0; white-space: nowrap; vertical-align: top; }
.payoff td { padding: 5px 0; vertical-align: top; }
.payoff td:last-child { text-align: right; font-family: var(--f-num); white-space: nowrap; padding-left: 10px; }
.payoff td.pos { color: var(--good); }
.payoff td.neg { color: var(--bad); }
.payoff-verdict { margin: 0; font-weight: 600; padding-left: 10px; border-left: 3px solid var(--warn); }
.payoff-verdict[data-good="true"] { border-left-color: var(--good); }

/* Online saving */
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sync-btn { display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot[data-tone="good"] { background: var(--lagoon); box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.2); }
.dot[data-tone="busy"] { background: var(--ocean); animation: pulse 1s ease-in-out infinite; }
.dot[data-tone="bad"] { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.35; } }
.sync-panel {
  max-width: 1280px; margin: 0 auto 20px; display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--ocean); border-radius: 10px; padding: 18px 20px;
}
.sync-panel h2 { font-size: 1.15rem; }
.sync-panel p, .sync-panel ol { margin: 0; max-width: 75ch; }
.sync-panel ol { padding-left: 20px; display: grid; gap: 4px; }
.sync-panel a { color: var(--lagoon); }
.sync-panel code { font-family: var(--f-num); font-size: 0.85em; }
.sync-panel #syncSetup, .sync-panel #syncConnected { display: grid; gap: 12px; }
.sync-panel #syncSetup[hidden], .sync-panel #syncConnected[hidden] { display: none; }
.sync-panel input { flex: 1; min-width: 0; max-width: 420px; }
#syncMsg:empty { display: none; }
