:root {
  color-scheme: light;
  --bg: #f6f7f9; --card: #fff; --text: #1d2430; --muted: #6b7280; --border: #e3e6eb;
  --accent: #1f6feb; --btn: #1f6feb; --good: #15803d; --warn: #b45309; --bad: #b91c1c;
  --input-bg: #fff; --thumb-bg: #eee; --grid: rgba(0, 0, 0, .1);
  --badge-bg: #eef2ff; --badge-fg: #3730a3; --muted-bg: #f3f4f6;
  --good-bg: #dcfce7; --warn-bg: #fef3c7; --bad-bg: #fee2e2; --pending-bg: #fffbeb;
  --row-good: #f0fdf4; --row-alt: #f9fafb;
  --on-bg: #fef3c7; --on-border: #f59e0b; --on-fg: #92400e; --danger-border: #fca5a5;
  --tile-filter: none;
}
/* Dark palette: data-theme="dark" forces it, "auto" follows the phone/OS setting. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b; --card: #18202b; --text: #e5e7eb; --muted: #9ca3af; --border: #2d3846;
  --accent: #58a6ff; --btn: #2563eb; --good: #4ade80; --warn: #fbbf24; --bad: #f87171;
  --input-bg: #10161e; --thumb-bg: #252e3a; --grid: rgba(255, 255, 255, .1);
  --badge-bg: #1e2a4a; --badge-fg: #a5b4fc; --muted-bg: #252e3a;
  --good-bg: #0f2e1c; --warn-bg: #33270b; --bad-bg: #3b1414; --pending-bg: #2a2310;
  --row-good: #10261a; --row-alt: #1d2632;
  --on-bg: #3a2c0a; --on-border: #b45309; --on-fg: #fcd34d; --danger-border: #7f1d1d;
  --tile-filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9);
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg: #0f141b; --card: #18202b; --text: #e5e7eb; --muted: #9ca3af; --border: #2d3846;
    --accent: #58a6ff; --btn: #2563eb; --good: #4ade80; --warn: #fbbf24; --bad: #f87171;
    --input-bg: #10161e; --thumb-bg: #252e3a; --grid: rgba(255, 255, 255, .1);
    --badge-bg: #1e2a4a; --badge-fg: #a5b4fc; --muted-bg: #252e3a;
    --good-bg: #0f2e1c; --warn-bg: #33270b; --bad-bg: #3b1414; --pending-bg: #2a2310;
    --row-good: #10261a; --row-alt: #1d2632;
    --on-bg: #3a2c0a; --on-border: #b45309; --on-fg: #fcd34d; --danger-border: #7f1d1d;
    --tile-filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9);
  }
}
.leaflet-tile-pane { filter: var(--tile-filter); }
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header.top { background: #111827; color: #fff; padding: .6rem 1rem; display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
header.top a { color: #e5e7eb; }
header.top a.active { color: #fff; font-weight: 600; }
header.top .brand { font-weight: 700; color: #fff; margin-right: 1rem; }
header.top form { margin-left: auto; }
main { padding: 1rem; max-width: 1400px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.filters { display: flex; flex-wrap: wrap; gap: .5rem .8rem; align-items: end; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
input, select, button { font: inherit; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg); color: var(--text); }
input[type=number] { width: 7.5rem; }
button, .btn { cursor: pointer; background: var(--btn); color: #fff; border-color: var(--btn); padding: .35rem .7rem; border-radius: 6px; display: inline-block; }
button.secondary, .btn.secondary { background: var(--card); color: var(--text); border-color: var(--border); }
button.small { padding: .15rem .45rem; font-size: 12px; }
button.on { background: var(--on-bg); border-color: var(--on-border); color: var(--on-fg); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .4rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.st-interesting { background: var(--row-good); }
tr.st-ignored { opacity: .55; }
tr.inactive td { color: var(--muted); }
.thumb { width: 72px; height: 54px; object-fit: cover; border-radius: 4px; background: var(--thumb-bg); }
.badge { display: inline-block; padding: 0 .4rem; border-radius: 999px; font-size: 12px; background: var(--badge-bg); color: var(--badge-fg); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.muted { background: var(--muted-bg); color: var(--muted); }
.good { color: var(--good); font-weight: 600; }
.bad { color: var(--bad); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pager { display: flex; gap: .5rem; align-items: center; margin-top: .8rem; }
#map, .map { height: 420px; border-radius: 8px; isolation: isolate; }
#map.big { height: calc(100vh - 140px); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
.desc { white-space: pre-wrap; max-height: 360px; overflow: auto; }
.actions { display: inline-flex; gap: .3rem; flex-wrap: wrap; }
.errors { background: var(--bad-bg); color: var(--bad); padding: .5rem .8rem; border-radius: 6px; }
.ok { background: var(--good-bg); color: var(--good); padding: .5rem .8rem; border-radius: 6px; }
p.warn, div.warn { background: var(--warn-bg); color: var(--warn); padding: .5rem .8rem; border-radius: 6px; }
p.warn a, div.warn a { color: inherit; font-weight: 600; }
.stop-all { display: block; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 6px; }
.stop-all input, .source-list input { width: 1.2rem; height: 1.2rem; vertical-align: middle; }
.source-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 6px; }
.source-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .2rem .8rem; padding: .5rem .7rem; }
.source-list li + li { border-top: 1px solid var(--border); }
.source-list li.off > label { color: var(--muted); }
.login { max-width: 360px; margin: 10vh auto; }
.login label { display: block; margin-bottom: .6rem; }
.login input { width: 100%; }
.hood-list { columns: 4 200px; max-height: 340px; overflow: auto; border: 1px solid var(--border); padding: .5rem; border-radius: 6px; }
.hood-list label { display: block; break-inside: avoid; }
.legend { background: var(--card); padding: .4rem .6rem; border-radius: 6px; line-height: 1.6; font-size: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; margin-right: 4px; border-radius: 2px; vertical-align: middle; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-box { position: relative; height: 260px; }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; margin: .6rem 0; }
.facts div { background: var(--bg); border-radius: 6px; padding: .4rem .6rem; }
.facts span { display: block; font-size: 12px; color: var(--muted); }
.facts b { font-size: 16px; }
.detail-title { margin-top: 0; }
.detail-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
img.hero { max-width: 100%; border-radius: 6px; display: block; margin-bottom: .6rem; }
.filter-panel > summary { cursor: pointer; font-weight: 600; list-style: none; }
.filter-panel > summary::-webkit-details-marker { display: none; }
.filter-panel > summary::after { content: "▾"; float: right; color: var(--muted); }
.filter-panel[open] > summary { margin-bottom: .6rem; }
.filter-panel[open] > summary::after { content: "▴"; }
.filter-buttons { display: flex; gap: .5rem; }
header.top nav.tabs { display: flex; gap: 1.2rem; }
header.top nav.tabs .ico { display: none; }
.only-sm { display: none; }
tr.district td { font-weight: 600; background: var(--row-alt); }
.center { text-align: center; }
.stack label { display: block; margin-bottom: .6rem; }
.stack input, .stack select { width: 100%; max-width: 360px; display: block; }
button.danger { background: var(--card); color: var(--bad); border-color: var(--danger-border); }
code.secret { display: inline-block; font-size: 1.1em; font-weight: 700; letter-spacing: .05em; background: var(--input-bg); color: var(--text); border: 1px dashed var(--border); padding: .1rem .4rem; border-radius: 4px; user-select: all; }
.dot { display: inline-block; min-width: 1.1rem; padding: 0 .25rem; border-radius: 999px; background: #dc2626; color: #fff; font-size: 11px; line-height: 1.1rem; text-align: center; }
.account { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; }
.section-title { font-size: 1rem; color: var(--muted); margin: 1.4rem 0 .6rem; }
#password summary { cursor: pointer; }
.user-list { list-style: none; margin: 0; padding: 0; }
.user-list li { padding: .7rem 0; border-top: 1px solid var(--border); }
.user-list li.u-pending { background: var(--pending-bg); margin: 0 -1rem; padding: .7rem 1rem; }
.user-list li.u-disabled .u-head b { color: var(--muted); text-decoration: line-through; }
.u-head { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.u-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.inline-form .grow { flex: 1 1 220px; }
.inline-form .grow input { width: 100%; }
.filter-card, .card[id] { scroll-margin-top: 4rem; }
.filter-card > summary { cursor: pointer; list-style: none; display: flex; flex-direction: column; gap: .15rem; }
.filter-card > summary::-webkit-details-marker { display: none; }
.filter-card > summary .filter-title::after { content: "▾"; float: right; color: var(--muted); }
.filter-card[open] > summary { margin-bottom: .6rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.filter-card[open] > summary .filter-title::after { content: "▴"; }
.filter-card.off .filter-title b { color: var(--muted); }
details.hoods { margin: .8rem 0; }
details.hoods > summary { cursor: pointer; margin-bottom: .4rem; }
.theme-switch { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; max-width: 420px; }
.theme-switch button { min-height: 2.6rem; }
@media (max-width: 760px) { .hide-sm { display: none; } }

/* ---------------------------------------------------------------- mobile */
@media (max-width: 760px) {
  body { font-size: 15px; }
  /* 16px inputs stop iOS Safari from zooming in on focus */
  input, select, button, .btn { font-size: 16px; }
  .only-sm { display: inline; }
  main { padding: .6rem .6rem 1rem; }
  body.with-nav main { padding-bottom: calc(4.6rem + env(safe-area-inset-bottom)); }
  .card { padding: .8rem; margin-bottom: .7rem; border-radius: 10px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.05rem; }

  header.top { position: sticky; top: 0; z-index: 1100; padding: .5rem .8rem; padding-top: calc(.5rem + env(safe-area-inset-top)); gap: .6rem; }
  header.top .brand { margin-right: 0; }
  header.top nav.tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100; gap: 0;
    background: #111827; border-top: 1px solid #374151;
    padding-bottom: env(safe-area-inset-bottom);
  }
  header.top nav.tabs a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 3.6rem; font-size: 11px; color: #9ca3af; text-decoration: none; position: relative;
  }
  header.top nav.tabs a .ico { display: block; font-size: 20px; line-height: 1.3; }
  header.top nav.tabs a.active { color: #fff; background: #1f2937; }

  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
  .filters label { font-size: 13px; min-width: 0; }
  .filters input[type=number], .filters select { width: 100%; min-height: 2.6rem; }
  .filters label.check { justify-content: center; min-height: 2.6rem; color: var(--text); }
  .filters label.check input { width: 1.2rem; height: 1.2rem; vertical-align: middle; }
  .filter-buttons { grid-column: 1 / -1; }
  .filter-buttons > * { flex: 1; text-align: center; min-height: 2.8rem; display: flex; align-items: center; justify-content: center; }

  /* listing table becomes a stack of cards */
  table.listings, table.listings tbody { display: block; }
  table.listings thead { display: none; }
  table.listings tr {
    display: grid; grid-template-columns: 96px repeat(3, minmax(0, 1fr)); gap: .25rem .6rem;
    grid-template-areas: "img title title title" "img hood hood hood" "price area m2 pct" "score seen act act";
    padding: .7rem 0; border-bottom: 1px solid var(--border);
  }
  table.listings tr.st-interesting { background: var(--row-good); margin: 0 -.8rem; padding: .7rem .8rem; }
  table.listings td { padding: 0; border: 0; min-width: 0; text-align: left; }
  table.listings td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
  table.listings .c-img { grid-area: img; }
  table.listings .c-title { grid-area: title; }
  table.listings .c-title a.title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  table.listings .c-title br { display: none; }
  table.listings .c-hood { grid-area: hood; font-size: 13px; color: var(--muted); }
  table.listings .c-price { grid-area: price; }
  table.listings .c-area { grid-area: area; }
  table.listings .c-m2 { grid-area: m2; }
  table.listings .c-pct { grid-area: pct; }
  table.listings .c-score { grid-area: score; }
  table.listings .c-seen { grid-area: seen; }
  table.listings .c-act { grid-area: act; justify-self: end; align-self: end; }
  table.listings .c-empty { grid-column: 1 / -1; }
  table.listings .thumb { width: 96px; height: 72px; border-radius: 6px; }

  .actions { gap: .4rem; }
  .actions button.small { font-size: 18px; min-width: 2.5rem; min-height: 2.5rem; padding: .2rem .5rem; }
  .actions.labeled { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
  .actions.labeled button.small { font-size: 14px; }
  .detail-actions .btn { width: 100%; text-align: center; padding: .65rem; }
  .facts { grid-template-columns: 1fr 1fr; }

  .pager { justify-content: space-between; }
  .pager .btn { padding: .55rem .8rem; }
  dl.kv { gap: .15rem .8rem; }
  .desc { max-height: none; }
  #map, .map { height: 300px; }
  #map.big { height: calc(100dvh - 21rem); min-height: 300px; }
  .chart-box { height: 220px; }
  .hood-list { columns: 1; max-height: 50vh; }
  .hood-list label { padding: .3rem 0; }
  .hood-list input { width: 1.2rem; height: 1.2rem; vertical-align: middle; }
  .login { margin: 6vh auto; }
  .login input { min-height: 2.8rem; }
  .login button { width: 100%; min-height: 2.8rem; }
  table.sticky-first td:first-child, table.sticky-first th:first-child { position: sticky; left: 0; background: var(--card); }
  table.sticky-first tr.district td:first-child { background: var(--row-alt); }
  table.compact-sm th, table.compact-sm td { padding: .35rem .3rem; font-size: 13px; }
  .filters label.wide { grid-column: 1 / -1; }
  .stack input, .stack select { max-width: none; min-height: 2.8rem; }
  .user-list li.u-pending { margin: 0 -.8rem; padding: .7rem .8rem; }
  .u-actions button.small { font-size: 14px; min-height: 2.4rem; padding: .2rem .6rem; }
  header.top nav.tabs .dot { position: absolute; top: .35rem; left: calc(50% + .55rem); }
}
