:root {
  --bg: #f7f6f2; --surface: #ffffff; --surface-2: #f0eee8; --text: #1d2321; --muted: #5f6b67; --border: #dcd8ce;
  --accent: #2f6f5e; --accent-text: #ffffff;
  --buy: #1f7a4d; --buy-bg: #e3f3ea; --maybe: #8a5a00; --maybe-bg: #fbf0d9; --no: #a3322b; --no-bg: #f8e3e1;
  --info: #2f5f8a; --info-bg: #e3edf7;
  --radius: 10px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151918; --surface: #1d2321; --surface-2: #252c2a; --text: #e8ece9; --muted: #9aa6a1; --border: #34403c;
    --accent: #5fb59b; --accent-text: #0e1513;
    --buy: #6fd3a0; --buy-bg: #183326; --maybe: #f0c060; --maybe-bg: #3a2f17; --no: #f08a80; --no-bg: #3d1f1c;
    --info: #8dbbe6; --info-bg: #1b2a38; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151918; --surface: #1d2321; --surface-2: #252c2a; --text: #e8ece9; --muted: #9aa6a1; --border: #34403c;
  --accent: #5fb59b; --accent-text: #0e1513;
  --buy: #6fd3a0; --buy-bg: #183326; --maybe: #f0c060; --maybe-bg: #3a2f17; --no: #f08a80; --no-bg: #3d1f1c;
  --info: #8dbbe6; --info-bg: #1b2a38; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--accent); }
.brand svg { width: 26px; height: 26px; }
.brand span { color: var(--text); }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; }
@media (max-width: 640px) { .tabs { order: 3; flex-basis: 100%; } }

main { max-width: 1180px; margin: 0 auto; padding: 16px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }

.btn { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 4px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.notice { background: var(--info-bg); color: var(--text); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.notice strong { color: var(--info); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 12px; }
.filters label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input[type=number], input[type=text], input[type=search], select { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; min-width: 0; }
input[type=number] { width: 110px; }
.field input, .field select { color: var(--text); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); margin: 2px 12px 2px 0; }

.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border-radius: 999px; padding: 3px 10px; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; }
.chip.on { border-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.card:hover { box-shadow: var(--shadow); }
.card .addr { font-weight: 600; }
.card .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.card .facts { color: var(--muted); font-size: 13px; }
.card .nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; font-size: 13px; }
.card .nums div span { display: block; color: var(--muted); font-size: 12px; }
.card .nums div b { font-variant-numeric: tabular-nums; }

.badge { display: inline-block; font-weight: 700; font-size: 12px; padding: 3px 9px; border-radius: 999px; letter-spacing: .02em; white-space: nowrap; }
.badge.BUY { color: var(--buy); background: var(--buy-bg); }
.badge.MAYBE { color: var(--maybe); background: var(--maybe-bg); }
.badge.NO { color: var(--no); background: var(--no-bg); }
.badge.new { color: var(--info); background: var(--info-bg); }
.badge.sample { color: var(--muted); background: var(--surface-2); }
.pos { color: var(--buy); } .neg { color: var(--no); }

.drawer { position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / .45); display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer .sheet { background: var(--bg); width: min(920px, 100%); height: 100%; overflow-y: auto; padding: 16px; }
.sheet header { display: flex; justify-content: space-between; gap: 12px; align-items: start; margin-bottom: 12px; }
.verdict { border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.verdict.BUY { background: var(--buy-bg); } .verdict.MAYBE { background: var(--maybe-bg); } .verdict.NO { background: var(--no-bg); }
.verdict .big { font-size: 22px; font-weight: 800; }
.verdict.BUY .big { color: var(--buy); } .verdict.MAYBE .big { color: var(--maybe); } .verdict.NO .big { color: var(--no); }
.verdict p { margin: 6px 0 0; font-size: 16px; }

.controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.controls .field input, .controls .field select { width: 100%; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.kpi > span { display: block; font-size: 12px; color: var(--muted); }
.kpi b { font-size: 18px; font-variant-numeric: tabular-nums; }

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.r, th.r { text-align: right; }
td input[type=number] { width: 120px; text-align: right; }
.table-wrap { overflow-x: auto; }
.overridden { color: var(--accent); font-weight: 600; }

.flags { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.flags li { padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.flags .danger { background: var(--no-bg); } .flags .warn { background: var(--maybe-bg); } .flags .info { background: var(--info-bg); }

.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .zero { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .l1 { stroke: var(--accent); fill: none; stroke-width: 2.5; }
.chart .l2 { stroke: var(--info); fill: none; stroke-width: 2; stroke-dasharray: 6 4; }
.chart .goal { stroke: var(--maybe); stroke-dasharray: 2 3; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-right: 6px; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .two { grid-template-columns: 1fr; } }
details > summary { cursor: pointer; font-weight: 600; margin: 4px 0; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 30; }
.toast[hidden] { display: none; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.coverage summary { cursor: pointer; }
.coverage ul { margin: 4px 0 10px; padding-left: 18px; }
.coverage li { margin: 2px 0; }
.badge.water { color: var(--info); background: var(--info-bg); }
.badge.near { color: var(--muted); background: var(--surface-2); font-weight: 600; }
.viewtoggle { display: flex; gap: 0; margin-left: auto; }
.viewtoggle .btn { border-radius: 0; }
.viewtoggle .btn:first-child { border-radius: 8px 0 0 8px; }
.viewtoggle .btn:last-child { border-radius: 0 8px 8px 0; }
.map { height: min(70vh, 640px); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 8px; z-index: 0; }
.leaflet-popup-content { font: 13px/1.4 system-ui, sans-serif; }
.cardlinks { display: flex; gap: 12px; font-size: 13px; padding: 6px 14px 0; margin-top: -4px; }
.card .row > span { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.cardwrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; padding-bottom: 10px; }
.cardwrap:hover { box-shadow: var(--shadow); }
.cardwrap .card { border: 0; background: none; flex: 1; }
.cardwrap .card:hover { box-shadow: none; }

/* Multi-select area picker */
.multi { position: relative; }
.multi summary { list-style: none; cursor: pointer; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 28px 7px 9px; color: var(--text); font-size: 14px; min-width: 160px; max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.multi summary::-webkit-details-marker { display: none; }
.multi summary::after { content: '▾'; position: absolute; right: 9px; color: var(--muted); }
.multi-menu { position: absolute; z-index: 1000; top: calc(100% + 4px); left: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-height: 340px; overflow-y: auto; width: max-content; max-width: min(340px, calc(100vw - 32px)); }
.multi-menu .check { display: flex; margin: 4px 0; }
.multi-menu .check .small { margin-left: auto; padding-left: 10px; }
.multi-actions { display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); margin-bottom: 4px; padding-bottom: 4px; }
