:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1c2330; --muted: #667085; --line: #d9dee7;
  --accent: #1f6feb; --warn-bg: #fff4d6; --warn-ink: #6b4a00;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161d; --panel: #1b212b; --ink: #e6e9ef; --muted: #98a2b3; --line: #2f3846;
    --accent: #5b9bff; --warn-bg: #3a2f10; --warn-ink: #ffd98a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, sans-serif; display: flex; flex-direction: column; }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
h1 { font-size: 18px; margin: 0; }
#city { width: auto; font-weight: 600; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 8px; color: var(--muted); }
h3 { font-size: 12px; margin: 12px 0 6px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); } .small { font-size: 12px; margin: 4px 0; }
.badge { background: var(--warn-bg); color: var(--warn-ink); padding: 3px 10px; border-radius: 999px; font-size: 12px; }
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 320px 1fr; }
aside { overflow-y: auto; padding: 12px 16px; background: var(--panel); border-right: 1px solid var(--line); }
aside section { margin-bottom: 18px; }
select { width: 100%; padding: 6px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; }
label { display: block; margin: 8px 0 0; font-size: 13px; }
label.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
label.row input { grid-column: 1 / -1; width: 100%; }
output { color: var(--muted); font-variant-numeric: tabular-nums; }
.legend { height: 10px; border-radius: 5px; margin-top: 8px; }
.legend + .legend-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 12px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#right { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(260px, 1fr) minmax(180px, 38%); min-height: 0; min-width: 0; }
#map { min-height: 0; }
#panel { min-width: 0; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); background: var(--panel); }
.bar { display: flex; gap: 12px; align-items: center; padding: 6px 12px; }
button { background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; cursor: pointer; }
.tablewrap { overflow: auto; flex: 1; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 4px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel); cursor: pointer; font-size: 12px; color: var(--muted); }
th[aria-sort] { color: var(--ink); }
td:first-child, th:first-child { text-align: center; }
td.tagcell { text-align: left; white-space: normal; max-width: 260px; font-size: 12px; color: var(--muted); }
tbody tr { cursor: pointer; } tbody tr:hover { background: var(--bg); }
tr.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); }
#compare { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 1fr); gap: 8px; padding: 0 12px 8px; overflow-x: auto; }
#compare .card { border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 12px; }
#compare .card b { font-size: 14px; }
.pos { color: #1a7f37; } .neg { color: #cf222e; }
.leaflet-popup-content { font: 13px/1.4 system-ui, sans-serif; }
[hidden] { display: none !important; }
#sideToggle, #sideClose { display: none; }
#offlineBadge { display: none; }
html.offline #offlineBadge { display: inline-block; }
#install { background: var(--accent); border-color: var(--accent); color: #fff; }
header a { padding: 4px 0; }
header .actions { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
header .actions button { padding: 5px 14px; }
@media (max-width: 820px) {
  html, body { height: auto; min-height: 100%; }
  body { font-size: 15px; padding-bottom: env(safe-area-inset-bottom); }
  header { gap: 4px 12px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top));
           padding-left: calc(12px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right)); }
  h1 { font-size: 17px; }
  header a { padding: 6px 2px; font-size: 14px; }
  #install { min-height: 32px; padding: 2px 10px; font-size: 14px; }
  #sideToggle { display: inline-block; position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 1500; border-radius: 999px; padding: 8px 18px;
                background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.35); }
  aside.open ~ * #sideToggle, body:has(aside.open) #sideToggle { display: none; }
  #demo { flex-basis: 100%; font-size: 11px; padding: 2px 8px; }
  main { grid-template-columns: minmax(0, 1fr); }
  /* the controls become a bottom sheet over the map */
  aside { position: fixed; left: 0; right: 0; bottom: 0; z-index: 2000; max-height: 82dvh; overflow-y: auto; border: 0; border-top: 1px solid var(--line);
          border-radius: 14px 14px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.28); transform: translateY(105%); visibility: hidden;
          transition: transform .22s ease, visibility 0s .22s; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); }
  aside.open { transform: none; visibility: visible; transition: transform .22s ease; }
  #sideClose { display: block; position: sticky; top: 0; z-index: 1; width: 100%; margin: 0 0 8px; padding: 12px; border: 0; border-bottom: 1px solid var(--line);
               border-radius: 14px 14px 0 0; background: var(--panel); font-weight: 600; }
  #right { grid-template-rows: 56dvh auto; }
  #panel { border-top: 1px solid var(--line); }
  .tablewrap { max-height: none; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* keep # score price m2 EUR/m2 discount yield; drop comps, rooms, floor, year, days, tags */
  th:nth-child(2), td:nth-child(2), th:nth-child(n+10), td:nth-child(n+10), th:nth-child(7), td:nth-child(7) { display: none; }
  th, td { padding: 10px 8px; }
  td input[type=checkbox] { width: 22px; height: 22px; }
  select, input, button { font-size: 16px; min-height: 40px; }
  input[type=range] { min-height: 32px; }
  .chip { padding: 7px 12px; font-size: 13px; }
  .leaflet-control-zoom a { width: 36px; height: 36px; line-height: 36px; }
  .leaflet-popup-content { font-size: 14px; }
  .bar { flex-wrap: wrap; }
}
@media (display-mode: standalone) {
  header { padding-top: calc(8px + env(safe-area-inset-top)); }
}
