:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #f1efea; --border: #e4e1da; --text: #1d1b18; --muted: #6b665d; --faint: #9a948a;
  --accent: #d9482b; --accent-ink: #ffffff; --accent-soft: #fbe7e1; --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7;
  --err: #b91c1c; --err-soft: #fee2e2; --link: #1d4ed8; --shadow: 0 1px 2px rgba(20, 16, 10, .06), 0 4px 16px rgba(20, 16, 10, .05);
  --hi: #16a34a; --med: #d97706; --lo: #94a3b8; --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311; --surface: #1c1b18; --surface-2: #25231f; --border: #34312b; --text: #efece6; --muted: #a8a197; --faint: #7a746a;
    --accent: #f06a4b; --accent-ink: #1a0d09; --accent-soft: #3a1f18; --ok: #4ade80; --ok-soft: #143222; --warn: #fbbf24; --warn-soft: #3a2c0c;
    --err: #f87171; --err-soft: #3b1515; --link: #93b4ff; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 1000; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.top .spacer { flex: 1; }
.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--err); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }

/* layout */
.layout { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; padding: 20px 24px 40px; max-width: 1600px; margin: 0 auto; }
.panel { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 78px; align-self: start; max-height: calc(100vh - 96px); overflow-y: auto; padding-right: 2px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card h2 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .num { width: 18px; height: 18px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; font-size: 11px; letter-spacing: 0; }
main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* city search */
.search { position: relative; }
.search input { width: 100%; padding: 10px 12px 10px 36px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); outline: none; font-size: 15px; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { position: absolute; left: 11px; top: 12px; color: var(--faint); }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); z-index: 20; max-height: 340px; overflow-y: auto; }
.suggest div { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.suggest div:hover, .suggest div.on { background: var(--surface-2); }
.suggest b { font-weight: 600; }
.suggest small { color: var(--muted); display: block; }
.suggest .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 20px; padding: 1px 7px; align-self: center; white-space: nowrap; }
.suggest .none { color: var(--muted); cursor: default; }
.picked { margin-top: 10px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; background: var(--accent-soft); }
.picked b { display: block; font-size: 15px; }
.picked small { color: var(--muted); display: block; }
.picked .x { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; }

/* chips + toggles */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 20px; padding: 5px 11px; cursor: pointer; user-select: none; background: var(--surface); }
.chip input { display: none; }
.chip:has(input:checked) { background: var(--text); color: var(--bg); border-color: var(--text); }
.row { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.row:first-of-type { border-top: 0; padding-top: 2px; }
.row .txt { flex: 1; min-width: 0; }
.row .txt b { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row .txt small { color: var(--muted); display: block; font-size: 12.5px; }
.badge { font-size: 11px; font-weight: 500; border-radius: 20px; padding: 1px 7px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.budget { display: flex; align-items: center; gap: 6px; margin-top: 5px; font-size: 12.5px; color: var(--muted); }
.budget input { width: 76px; padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.switch { position: relative; width: 36px; height: 21px; flex: none; margin-top: 1px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 20px; background: var(--border); cursor: pointer; transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 15px; height: 15px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(15px); }
.switch input:disabled + span { opacity: .45; cursor: not-allowed; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.hint a { font-weight: 500; }

/* map */
#map { height: 340px; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); background: var(--surface-2); z-index: 1; }
.leaflet-popup-content { font-size: 13px; line-height: 1.45; }
.tiles { filter: saturate(.55) contrast(.95); }
@media (prefers-color-scheme: dark) {
  .tiles { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.4); }
  .leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
}
.leaflet-popup-content b { font-size: 14px; }

/* welcome */
.welcome h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -.02em; }
.welcome p { color: var(--muted); margin: 0 0 14px; max-width: 70ch; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.steps div { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.steps b { display: block; margin-bottom: 3px; }
.steps small { color: var(--muted); }

/* progress */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat small { color: var(--muted); font-size: 12px; }
.stat .pct { color: var(--faint); font-size: 12px; margin-left: 4px; font-weight: 400; }
.stages { display: flex; flex-direction: column; }
.stage { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 7px 0; border-top: 1px solid var(--border); }
.stage:first-child { border-top: 0; }
.stage .ico { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; margin-top: 1px; background: var(--surface-2); color: var(--faint); }
.stage.done .ico { background: var(--ok-soft); color: var(--ok); }
.stage.error .ico { background: var(--err-soft); color: var(--err); }
.stage.warn .ico { background: var(--warn-soft); color: var(--warn); }
.stage.warn .det { color: var(--warn); }
.stage.running .ico { border: 2px solid var(--accent-soft); border-top-color: var(--accent); background: none; animation: spin .8s linear infinite; }
.stage.skipped { opacity: .6; }
.stage .lbl { font-weight: 550; }
.stage .det { color: var(--muted); font-size: 12.5px; word-break: break-word; }
.stage.error .det { color: var(--err); }
.bar { height: 4px; border-radius: 4px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s; }
@keyframes spin { to { transform: rotate(360deg); } }
.head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.head h3 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.head .sub { color: var(--muted); font-size: 13px; }
.head .spacer { flex: 1; }
.state { font-size: 12px; font-weight: 600; border-radius: 20px; padding: 2px 9px; }
.state.running { background: var(--accent-soft); color: var(--accent); }
.state.done { background: var(--ok-soft); color: var(--ok); }
.state.error { background: var(--err-soft); color: var(--err); }
.state.cancelled { background: var(--surface-2); color: var(--muted); }
.state.interrupted { background: var(--warn-soft); color: var(--warn); }
details.log summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 10px; }
details.log pre { background: var(--surface-2); border-radius: 8px; padding: 10px; font-size: 11.5px; max-height: 240px; overflow: auto; white-space: pre-wrap; margin: 8px 0 0; }
.errbox { background: var(--err-soft); color: var(--err); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }

/* results */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; min-width: 180px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.toolbar select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 10px; cursor: pointer; border-left: 1px solid var(--border); font-size: 13px; }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--text); color: var(--bg); }
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 8px 10px; white-space: nowrap; position: sticky; top: 0; }
td { padding: 8px 10px; border-top: 1px solid var(--border); vertical-align: top; }
tr.lead { cursor: pointer; }
tr.lead:hover td { background: var(--surface-2); }
td .n { font-weight: 600; }
td:first-child { min-width: 190px; }
td:nth-child(2) { min-width: 170px; }
td small { color: var(--muted); display: block; }
td.nowrap { white-space: nowrap; }
td small.approx { color: var(--warn); }
.soc { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.soc a { font-size: 11px; font-weight: 600; border-radius: 5px; padding: 1px 5px; background: var(--surface-2); color: var(--muted); }
.soc a:hover { text-decoration: none; color: var(--text); }
.pill { font-size: 11.5px; font-weight: 600; border-radius: 20px; padding: 2px 8px; white-space: nowrap; }
.pill.High { background: var(--ok-soft); color: var(--ok); }
.pill.Medium { background: var(--warn-soft); color: var(--warn); }
.pill.Low { background: var(--surface-2); color: var(--muted); }
.pill.v-ok { background: var(--ok-soft); color: var(--ok); }
.pill.v-likely { background: var(--warn-soft); color: var(--warn); }
.pill.v-no { background: var(--err-soft); color: var(--err); }
.pill.v-na { background: var(--surface-2); color: var(--muted); }
.more { text-align: center; padding: 12px; color: var(--muted); }
.empty { color: var(--muted); padding: 30px; text-align: center; }
.filepath { color: var(--muted); font-size: 12.5px; margin-top: 10px; word-break: break-all; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(10, 8, 5, .45); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal .card { width: min(620px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.modal .sub { color: var(--muted); margin: 0 0 14px; }
.field { margin-bottom: 14px; }
.field label { font-weight: 600; display: block; margin-bottom: 2px; }
.field small { color: var(--muted); display: block; margin-bottom: 6px; }
.field .inrow { display: flex; gap: 6px; }
.field input { flex: 1; width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.field .msg { font-size: 12.5px; margin-top: 5px; }
.field .msg.ok { color: var(--ok); }
.field .msg.bad { color: var(--err); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.hist { display: flex; flex-direction: column; }
.hist button { text-align: left; border: 0; border-top: 1px solid var(--border); background: none; padding: 10px 4px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.hist button:first-child { border-top: 0; }
.hist button:hover { background: var(--surface-2); }
.hist .when { color: var(--muted); font-size: 12.5px; margin-left: auto; white-space: nowrap; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 9px; z-index: 3000; box-shadow: var(--shadow); }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .panel { position: static; max-height: none; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .top { padding: 12px 16px; }
  .brand small { display: none; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top .btn span { display: none; }
}
