:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1d2320;
  --muted: #66706b;
  --line: #e1e4df;
  --accent: #14805c;
  --south: #f2c230;   --south-ink: #8a6400;
  --midlands: #8b5a3c; --midlands-ink: #633a23;
  --northwest: #32995c; --northwest-ink: #1c6639;
  --north: #f28923;   --north-ink: #a55009;
  font-family: ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input { font: inherit; }
[hidden] { display: none !important; }

.topbar {
  height: 60px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand h1 { margin: 0; font-size: 17px; line-height: 1.2; white-space: nowrap; }
.eyebrow { margin: 0; font-size: 11px; letter-spacing: .06em; color: var(--muted); }
.search { display: flex; flex: 1; max-width: 420px; }
.search input { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-right: 0; border-radius: 8px 0 0 8px; background: #fafbf9; }
.search input:focus { outline: 2px solid #9fd3bf; outline-offset: -1px; }
.search button { height: 36px; padding: 0 14px; border: 0; border-radius: 0 8px 8px 0; background: var(--ink); color: #fff; cursor: pointer; }
.uploads { margin-left: auto; display: flex; gap: 8px; }
.btn { height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b9c0ba; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { color: var(--muted); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; height: calc(100vh - 60px); }
.map-panel { position: relative; display: flex; flex-direction: column; min-width: 0; }
.map-toolbar { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3; display: flex; justify-content: space-between; pointer-events: none; }
.map-toolbar > * { pointer-events: auto; }
.crumbs, .zoom { display: flex; align-items: center; gap: 4px; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 10px; padding: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.crumb { border: 0; background: none; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.crumb:hover { background: #eef1ed; }
.crumb-sep { padding: 4px 10px 4px 0; font-weight: 600; }
.crumb-sep::before { content: "›"; color: var(--muted); margin-right: 8px; }
.zoom button { min-width: 32px; height: 30px; border: 0; background: none; border-radius: 6px; cursor: pointer; font-size: 15px; }
.zoom button:hover { background: #eef1ed; }
.zoom #zoom-reset { font-size: 13px; padding: 0 10px; }

.map-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #eaf0f2; cursor: grab; touch-action: none; }
.map-wrap.dragging { cursor: grabbing; }
.map { width: 100%; height: 100%; display: block; user-select: none; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 2; pointer-events: none; }

.area-base { stroke: none; }
.area-base.region-south { fill: rgb(242 194 48 / .26); }
.area-base.region-midlands { fill: rgb(139 90 60 / .22); }
.area-base.region-northwest { fill: rgb(50 153 92 / .22); }
.area-base.region-north { fill: rgb(242 137 35 / .24); }
.area-base.region-unmapped { fill: #dfe2df; }

.d { stroke: rgba(255,255,255,.75); stroke-width: .5; vector-effect: non-scaling-stroke; cursor: pointer; }
.d.off { fill: transparent; }
.d.off:hover { fill: rgba(0,0,0,.08); }
.d.on:hover { filter: brightness(1.12); }
.d.dim { opacity: .16; }
.d.sel { stroke: #111; stroke-width: 2.2; }

.ao { fill: none; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.ao.region-south { stroke: var(--south-ink); }
.ao.region-midlands { stroke: var(--midlands-ink); }
.ao.region-northwest { stroke: var(--northwest-ink); }
.ao.region-north { stroke: var(--north-ink); }
.ao.region-unmapped { stroke: #999; }
.ao.active { stroke: #111; stroke-width: 2.4; }

.lbl { font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; paint-order: stroke; stroke: rgba(255,255,255,.85); stroke-linejoin: round; fill: #1d2320; }
.lbl.dl { font-weight: 600; fill: #222; }

.tooltip { position: absolute; z-index: 5; pointer-events: none; background: rgba(24,28,26,.94); color: #fff; padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.55; max-width: 260px; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.tooltip b { font-size: 13px; }
.tooltip .muted { color: #b9c2bd; }

.map-legend { position: absolute; left: 12px; bottom: 12px; z-index: 3; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 12px; display: grid; gap: 4px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.legend-row b { font-weight: 600; }
.legend-row span { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.sw { width: 14px; height: 10px; border-radius: 2px; display: inline-block; border: 1.5px solid; }
.sw.region-south { background: rgb(242 194 48 / .35); border-color: var(--south-ink); }
.sw.region-midlands { background: rgb(139 90 60 / .3); border-color: var(--midlands-ink); }
.sw.region-northwest { background: rgb(50 153 92 / .3); border-color: var(--northwest-ink); }
.sw.region-north { background: rgb(242 137 35 / .32); border-color: var(--north-ink); }
.map-hint { position: absolute; right: 12px; bottom: 12px; margin: 0; z-index: 3; font-size: 11px; color: var(--muted); background: rgba(255,255,255,.85); padding: 4px 8px; border-radius: 6px; }

.side { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; display: grid; gap: 12px; align-content: start; }
.file-status { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.file-status > div { display: flex; gap: 8px; align-items: baseline; }
.file-status .ok { color: var(--accent); }
.file-status .err { color: #c0392b; }
.tag { flex: none; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: #eef1ed; color: var(--ink); }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.card h2 { margin: 2px 0 0; font-size: 18px; }
.region-pill { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.region-pill.region-south { background: rgb(242 194 48 / .25); color: var(--south-ink); }
.region-pill.region-midlands { background: rgb(139 90 60 / .2); color: var(--midlands-ink); }
.region-pill.region-northwest { background: rgb(50 153 92 / .2); color: var(--northwest-ink); }
.region-pill.region-north { background: rgb(242 137 35 / .22); color: var(--north-ink); }
.region-pill.region-unmapped { background: #eee; color: #666; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.stat { background: #f6f7f5; border-radius: 8px; padding: 8px 10px; }
.stat span { display: block; font-size: 11px; color: var(--muted); }
.stat strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv th { text-align: left; font-weight: 500; color: var(--muted); padding: 5px 8px 5px 0; width: 42%; vertical-align: top; }
.kv td { padding: 5px 0; font-variant-numeric: tabular-nums; word-break: break-word; }
.kv tr + tr th, .kv tr + tr td { border-top: 1px solid #f0f1ee; }
.sub { margin: 14px 0 6px; font-size: 13px; font-weight: 600; }
.dtable { width: 100%; border-collapse: collapse; font-size: 12px; }
.dtable th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 4px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.dtable td { white-space: nowrap; padding: 4px; border-bottom: 1px solid #f2f3f0; font-variant-numeric: tabular-nums; }
.dtable tr[data-district] { cursor: pointer; }
.dtable tr[data-district]:hover td { background: #f3f7f4; }
.dtable .num { text-align: right; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.dot.none { background: #e2e4e1; }
.scroll { max-height: 360px; overflow-y: auto; }
.segment-list { display: grid; gap: 2px; max-height: 340px; overflow-y: auto; }
.seg { display: grid; grid-template-columns: 14px 64px 1fr auto; gap: 8px; align-items: center; padding: 5px 6px; border: 0; background: none; border-radius: 6px; text-align: left; cursor: pointer; font-size: 12px; }
.seg:hover { background: #f3f5f2; }
.seg.active { background: #e7f3ed; }
.seg i { width: 14px; height: 14px; border-radius: 3px; }
.seg b { font-variant-numeric: tabular-nums; }
.seg span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg em { font-style: normal; color: var(--muted); }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }
.empty { color: var(--muted); font-size: 13px; margin: 0; }

@media (max-width: 900px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .uploads { margin-left: 0; flex-wrap: wrap; }
  .layout { display: block; height: auto; }
  .map-panel { height: 72vh; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .map-hint { display: none; }
}
