:root {
  --ink: #1f2b24;
  --ink-2: #4a5a50;
  --muted: #6b7a70;
  --paper: #ffffff;
  --panel: #f5f6f2;
  --line: #d9ded5;
  --pine: #2e5a45;
  --pine-2: #244a38;
  --moss: #8ba46f;
  --steep: #9a8a78;
  --pin: #e0342b;
  --warn: #b45309;
  --bad: #b3261e;
  --good: #2e7d4f;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow: 0 1px 2px rgba(31, 43, 36, .08), 0 8px 24px rgba(31, 43, 36, .10);
  --top-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Schibsted Grotesk", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--panel);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--pine) 55%, white); outline-offset: 2px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.top {
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 18px; letter-spacing: -.01em; white-space: nowrap; }
.brand img { width: 34px; height: 34px; object-fit: contain; border-radius: var(--radius-s); }
.kw { flex: 0 1 260px; min-width: 140px; }
.kw input {
  width: 100%; height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
}
.kw input:focus { background: var(--paper); border-color: var(--pine); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--pine) 20%, transparent); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper);
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.chip.set { border-color: var(--pine); color: var(--pine); background: color-mix(in srgb, var(--pine) 8%, white); }
.filters-btn { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.settings-btn { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; }
.live-note { display: none; margin: 0 auto 0 12px; font-size: 12.5px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  height: 40px; padding: 0 16px; border-radius: var(--radius-s);
  border: 1px solid transparent; font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--pine); color: #fff; }
.btn.primary:hover { background: var(--pine-2); }
.btn.ghost { background: var(--paper); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink-2); }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--paper);
}
.icon-btn.close { border: none; font-size: 18px; color: var(--bad); background: transparent; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) min(760px, 48vw); height: calc(100dvh - var(--top-h)); }
.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
.map-tools { position: absolute; top: 12px; left: 12px; right: 64px; display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; z-index: 2; pointer-events: none; }
.map-tools > * { pointer-events: auto; }
.seg { display: flex; background: var(--paper); border-radius: var(--radius-s); box-shadow: var(--shadow); padding: 3px; }
.seg button { border: none; background: transparent; padding: 6px 10px; border-radius: 4px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }
#waterBtn.on { background: #1f7fe0; color: #fff; }
.bbox-toggle {
  position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--paper); padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow);
  font-weight: 600; font-size: 13px; display: flex; gap: 8px; align-items: center; z-index: 2; white-space: nowrap;
}
.bbox-toggle input { accent-color: var(--pine); width: 16px; height: 16px; }

.results { overflow-y: auto; background: var(--paper); border-left: 1px solid var(--line); padding: 16px 16px 40px; }
.results-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 14px; }
.results-head h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -.015em; }
.results-head p { margin: 2px 0 0; font-size: 14px; }
.sort { display: flex; flex-direction: column; font-size: 12px; font-weight: 600; color: var(--muted); gap: 2px; }
.sort select { height: 36px; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 0 8px; background: var(--paper); font-size: 14px; font-weight: 600; color: var(--ink); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; text-align: left; padding: 0;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-m);
  overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.card:hover, .card.hl { border-color: var(--ink-2); box-shadow: var(--shadow); }
.card .ph { position: relative; aspect-ratio: 16 / 10; background: #dfe4dc; }
.card .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .ph .noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.badge {
  position: absolute; top: 8px; left: 8px; padding: 3px 8px; border-radius: var(--radius-s);
  font-size: 12px; font-weight: 700; background: rgba(255,255,255,.94); color: var(--ink);
}
.badge.pending { background: var(--warn); color: #fff; }
.badge.off { background: var(--ink-2); color: #fff; }
.score {
  position: absolute; top: 8px; right: 8px; min-width: 40px; height: 40px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 999px; font-weight: 800; font-size: 15px;
  background: var(--paper); border: 3px solid var(--moss);
}
.score.mid { border-color: #d6a53a; }
.score.low { border-color: var(--bad); }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.price { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.price .cut { font-size: 13px; font-weight: 700; color: var(--good); margin-left: 6px; letter-spacing: 0; }
.facts { display: flex; flex-wrap: wrap; gap: 0 12px; font-size: 14px; }
.facts b { font-weight: 700; }
.addr { font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.terrain { margin-top: 6px; }
.strip { height: 8px; border-radius: 4px; overflow: hidden; display: flex; background: repeating-linear-gradient(135deg, var(--steep) 0 3px, color-mix(in srgb, var(--steep) 55%, white) 3px 6px); }
.strip i { display: block; background: var(--moss); }
.strip.unknown { background: var(--line); }
.terrain small { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.flags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.flag { font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: #f7e9e7; color: var(--bad); }
.flag.pos { background: #e8f1e3; color: #36582a; }
.flag.flood { background: #e4eef7; color: #1d4f7a; }
.more { display: block; margin: 20px auto 0; }
.near-toggle { margin-top: 6px; font-size: 13.5px; }
.near-head { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }
.near-head h2 { margin: 0; font-size: 18px; }
.near-head p { margin: 2px 0 0; font-size: 13.5px; }
.card.is-near .ph img { filter: saturate(.75); }
.miss { align-self: flex-start; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #fff3c2; color: #6b4e00; }
.pop em { display: block; font-style: normal; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 2px; }
.empty { padding: 40px 12px; text-align: center; color: var(--ink-2); }
.empty button { margin-top: 12px; }

.view-toggle { display: none; }

.scrim { position: fixed; inset: 0; background: rgba(20, 28, 23, .35); z-index: 40; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(440px, 100vw); z-index: 50;
  background: var(--paper); display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer-head, .dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2, .dlg-head h2 { margin: 0; font-size: 19px; }
.drawer-body { overflow-y: auto; padding: 4px 16px 24px; flex: 1; }
.drawer-foot { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.drawer-foot .primary { margin-left: auto; }

.fgroup { border-bottom: 1px solid var(--line); padding: 14px 0; }
.fgroup:last-child { border-bottom: none; }
.fgroup h3 { font-size: 15px; margin: 0 0 10px; }
.fgroup p.hint, .hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 10px; border: none; padding: 0; }
.field legend { padding: 0; margin-bottom: 4px; }
.field input:not([type=checkbox]), .field select, .field textarea {
  height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--paper);
  font-weight: 500; color: var(--ink); width: 100%;
}
.field textarea { height: auto; padding: 8px 10px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--pine); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--pine) 18%, transparent); }
.pills { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; width: fit-content; max-width: 100%; }
.pills label { position: relative; }
.pills input { position: absolute; opacity: 0; inset: 0; }
.pills span { display: block; padding: 8px 12px; font-size: 14px; font-weight: 600; border-right: 1px solid var(--line); cursor: pointer; color: var(--ink); }
.pills label:last-child span { border-right: none; }
.pills input:checked + span { background: var(--ink); color: #fff; }
.pills input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--pine) 55%, white); outline-offset: -3px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; }
.check input { accent-color: var(--pine); width: 17px; height: 17px; flex: none; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type=range] { flex: 1; accent-color: var(--pine); }
.range-row output { min-width: 56px; text-align: right; font-weight: 700; color: var(--ink); }

dialog { border: none; padding: 0; border-radius: var(--radius-l); box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(20, 28, 23, .45); }
.detail { width: min(980px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.settings { width: min(520px, calc(100vw - 32px)); }
.dlg-body { padding: 16px; }
.dlg-body h3 { font-size: 15px; margin: 18px 0 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.runs { font-size: 13px; }
.runs table { width: 100%; border-collapse: collapse; }
.runs td, .runs th { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
.runs .err { color: var(--bad); }

.d-top { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; background: var(--paper); padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.d-top .links { display: flex; gap: 8px; flex-wrap: wrap; }
.d-top a { font-weight: 600; font-size: 14px; color: var(--pine); text-decoration: none; padding: 8px 10px; border-radius: var(--radius-s); border: 1px solid var(--line); }
.d-top a:hover { border-color: var(--pine); }
.gallery { display: grid; grid-template-columns: 2fr 1fr; gap: 4px; height: 380px; background: #dfe4dc; }
.gallery .main { position: relative; overflow: hidden; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .side { display: grid; grid-template-rows: 1fr 1fr; gap: 4px; overflow: hidden; }
.gallery .nav { position: absolute; bottom: 10px; right: 10px; display: flex; gap: 6px; }
.gallery .nav button { background: rgba(255,255,255,.94); border: none; border-radius: var(--radius-s); padding: 6px 12px; font-weight: 700; }
.d-body { padding: 18px 16px 24px; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; }
.d-price { font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.d-addr { font-size: 16px; margin: 2px 0 12px; color: var(--ink-2); }
.d-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin: 0 0 16px; }
.d-facts div { background: var(--panel); border-radius: var(--radius-s); padding: 8px 10px; }
.d-facts dt { font-size: 12.5px; color: var(--muted); }
.d-facts dd { margin: 0; font-weight: 700; font-size: 16px; }
.d-desc { font-size: 15px; line-height: 1.6; max-width: 70ch; white-space: pre-line; }
.land { background: var(--panel); border-radius: var(--radius-m); padding: 14px; }
.land h3, .hist h3 { margin: 0 0 10px; font-size: 16px; }
.land .strip { height: 12px; margin-bottom: 6px; }
.land dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 12px 0 0; font-size: 14px; }
.land dt { color: var(--ink-2); }
.land dd { margin: 0; font-weight: 700; text-align: right; }
.land .note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.hist { margin-top: 16px; }
.land + .land, .panel + .panel, .land + .hist { margin-top: 16px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px; margin-top: 18px; scroll-margin-top: 70px; }
.land, .hist { scroll-margin-top: 70px; }
.panel h3 { margin: 0 0 10px; font-size: 16px; }
.panel dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 10px 0 0; font-size: 14px; }
.panel dt { color: var(--ink-2); }
.panel dd { margin: 0; font-weight: 600; text-align: right; }
.panel .note, .land .note { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.d-jump { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.d-jump a { font-size: 13px; font-weight: 600; color: var(--pine); text-decoration: none; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; }
.d-jump a:hover { border-color: var(--pine); }
.pay-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0 10px; }
.pay-exempt { grid-column: 1 / -1; margin-bottom: 8px; }
.pay-total { font-size: 28px; font-weight: 800; margin: 4px 0 8px; letter-spacing: -.02em; }
.pay-total span { font-size: 15px; font-weight: 600; color: var(--muted); }
.pay-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; }
.pay-list dt { display: flex; align-items: center; gap: 8px; }
.pay-list dt i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.est { width: 100%; border-collapse: collapse; font-size: 14px; }
.est td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.est td:nth-child(2) { font-weight: 700; text-align: right; }
.est td:nth-child(3) { text-align: right; font-size: 13px; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: #e8f1e3; color: #36582a; }
.va { margin: 0; padding-left: 18px; font-size: 14px; display: grid; gap: 6px; }
.links-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.links-row a { font-size: 13px; font-weight: 600; color: var(--pine); text-decoration: none; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--paper); }
.links-row a:hover { border-color: var(--pine); }
.risks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.risk { font-size: 12.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.risk.hi { background: #f7e0dc; color: var(--bad); }
.risk.mid { background: #faefd6; color: #8a5a06; }
.risk.lo { background: #e8f1e3; color: #36582a; }
.hist table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hist td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.hist td:last-child { text-align: right; font-weight: 700; }

.popover {
  position: fixed; z-index: 60; background: var(--paper); border-radius: var(--radius-m); box-shadow: var(--shadow);
  border: 1px solid var(--line); width: 300px; max-height: 60vh; overflow-y: auto; padding: 6px;
}
.popover .item { display: flex; align-items: center; gap: 6px; }
.popover .item button.load { flex: 1; text-align: left; background: none; border: none; padding: 10px; border-radius: var(--radius-s); font-weight: 600; }
.popover .item button.load:hover { background: var(--panel); }
.popover .item button.del { background: none; border: none; color: var(--bad); padding: 8px 10px; font-size: 14px; }
.popover .none { padding: 12px; color: var(--muted); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-s); font-weight: 600; font-size: 14px;
}

.maplibregl-popup-content { padding: 0; border-radius: var(--radius-m); overflow: hidden; box-shadow: var(--shadow); font-family: inherit; }
.pop { width: 230px; cursor: pointer; }
.pop img { width: 100%; height: 120px; object-fit: cover; display: block; background: #dfe4dc; }
.pop div { padding: 8px 10px; }
.pop b { font-size: 17px; }
.pop span { display: block; font-size: 13px; color: var(--ink-2); }

.map-wrap:fullscreen { width: 100vw; height: 100vh; background: #000; }
.map-wrap:fullscreen .bbox-toggle { bottom: 36px; }

@media (min-width: 1280px) {
  body.docked .drawer { top: var(--top-h); width: 360px; box-shadow: none; border-right: 1px solid var(--line); z-index: 15; }
  body.docked .layout { margin-left: 360px; grid-template-columns: minmax(0, 1fr) min(640px, 40vw); }
  body.docked .live-note { display: block; }
  body.docked #applyBtn { display: none; }
  body.docked .drawer-foot .btn { flex: 1 1 auto; }
  body.docked .cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

@media (max-width: 1100px) {
  .settings-btn span { display: none; }
  .settings-btn { width: 40px; padding: 0; justify-content: center; }
  .brand span { display: none; }
  .top-actions #saveBtn { display: none; }
}

@media (max-width: 820px) {
  :root { --top-h: 112px; }
  .top { flex-wrap: wrap; height: auto; min-height: var(--top-h); padding: 8px 16px; row-gap: 8px; }
  .kw { flex: 1 1 0; min-width: 0; order: 1; }
  .top-actions { gap: 6px; }
  .brand { order: 0; }
  .top-actions { order: 2; }
  .top-actions #savedBtn { height: 40px; padding: 0 12px; }
  .results-head { flex-direction: column; align-items: stretch; }
  .results-head h1 { font-size: 20px; }
  .filters-btn { order: 3; }
  .chips { order: 4; flex: 1 1 0; }
  .layout { grid-template-columns: 1fr; }
  .results { position: absolute; inset: var(--top-h) 0 0 0; z-index: 10; border-left: none; }
  body:not(.list) .results { display: none; }
  body.list .map-wrap { visibility: hidden; }
  .view-toggle { display: block; position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 30; border-radius: 999px; box-shadow: var(--shadow); padding: 0 22px; }
  .bbox-toggle { bottom: 80px; }
  .gallery { grid-template-columns: 1fr; height: 260px; }
  .gallery .side { display: none; }
  .d-body { grid-template-columns: 1fr; }
  .detail { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  .cards { grid-template-columns: 1fr; }
  .checks { grid-template-columns: 1fr; }
}

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