:root {
  color-scheme: dark;
  --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #242422; --line: #383835;
  --text-primary: #fff; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
  --accent: #3987e5; --good: #0ca30c; --warning: #fab219; --critical: #d03b3b; --impact: #c8461a; --water: #1e6ee6;
  --radius: 12px; --panel-w: 420px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", "Nirmala UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--surface-0); color: var(--text-primary); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#map { position: fixed; inset: 0; right: var(--panel-w); }

.topbar { position: fixed; top: 12px; left: 12px; right: calc(var(--panel-w) + 12px); display: flex; gap: 12px; align-items: center; z-index: 5; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { display: flex; gap: 10px; align-items: center; background: var(--surface-1); border: 1px solid var(--line); padding: 8px 14px; border-radius: var(--radius); box-shadow: 0 6px 24px #0008; }
.brand .logo { font-size: 22px; color: var(--impact); }
.brand strong { display: block; font-size: 16px; }
.brand small { color: var(--text-secondary); font-size: 12px; }
.basemap { display: flex; background: var(--surface-1); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.basemap button { border: 0; background: none; padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--text-secondary); }
.basemap button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.layers { position: fixed; left: 12px; bottom: 16px; display: flex; flex-wrap: wrap; gap: 6px; z-index: 5; max-width: calc(100vw - var(--panel-w) - 24px); }
.layers button { background: var(--surface-1); border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; font-size: 13px; color: var(--text-secondary); box-shadow: 0 4px 16px #0006; }
.layers button[aria-pressed="true"] { border-color: var(--accent); color: #fff; background: #1c5cab; }
.legend { position: fixed; left: 12px; bottom: 62px; z-index: 5; background: var(--surface-1); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12px; color: var(--text-secondary); min-width: 220px; }
.legend .r { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.legend .sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.hint { position: fixed; top: 76px; left: 12px; z-index: 6; background: var(--warning); color: #111; padding: 8px 12px; border-radius: 8px; font-weight: 600; }

.panel { position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-w); background: var(--surface-1); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card h3 { margin: 0 0 8px; font-size: 14px; }
.card h4 { margin: 12px 0 4px; font-size: 13px; }
.card p { color: var(--text-secondary); font-size: 13px; margin: 6px 0; }
.row { display: flex; gap: 8px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
label { font-size: 12px; color: var(--text-secondary); display: flex; flex-direction: column; gap: 3px; }
input, select { background: var(--surface-1); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
select { flex: 1; min-width: 0; }
.ghost, .btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; color: var(--text-primary); text-decoration: none; }
.primary { width: 100%; margin-top: 8px; background: var(--impact); border: 0; border-radius: 8px; padding: 9px; font-weight: 600; }
.primary:disabled { opacity: .45; cursor: default; }
.bbox { font-size: 12px; color: var(--text-muted); font-family: ui-monospace, monospace; }
.progress { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.progress .bar { height: 6px; background: var(--surface-1); border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--impact); transition: width .4s; }
#pastRuns { margin-top: 8px; font-size: 12px; color: var(--text-muted); }
#pastRuns a { color: var(--accent); cursor: pointer; margin-right: 8px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tile { background: var(--surface-1); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--text-secondary); }
.tile.crit { border-left: 4px solid var(--critical); } .tile.warn { border-left: 4px solid var(--warning); }
.tabs { display: flex; gap: 4px; margin: 12px 0 8px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 6px 8px; font-size: 13px; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: #fff; border-bottom-color: var(--impact); }
.list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.list li { padding: 6px 4px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.list li:hover { background: var(--surface-1); }
.list small { color: var(--text-muted); }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--critical); color: #fff; white-space: nowrap; }
.pill.warn { background: var(--warning); color: #111; }

.chat { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.msg { padding: 8px 10px; border-radius: 10px; white-space: pre-wrap; line-height: 1.4; }
.msg.user { background: #1c5cab; align-self: flex-end; max-width: 85%; }
.msg.bot { background: var(--surface-1); border: 1px solid var(--line); }
.msg .meta { display: block; margin-top: 6px; font-size: 11px; color: var(--text-muted); }
.msg .meta.ok { color: #5cc95c; } .msg .meta.bad { color: var(--warning); }
.suggest { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.suggest button { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--text-secondary); }
#askForm { display: flex; gap: 6px; }
#askForm input { flex: 1; }
#askForm button { background: var(--accent); border: 0; border-radius: 8px; padding: 6px 12px; }
.attrib { font-size: 10px; color: var(--text-muted); line-height: 1.4; margin-top: auto; }
.basis { font-size: 12px; color: var(--text-secondary); }
.basis code { font-size: 11px; color: var(--text-muted); word-break: break-all; }
@media (max-width: 800px) {
  :root { --panel-w: 100vw; }
  #map { right: 0; bottom: 50vh; }
  .panel { top: 50vh; width: 100%; }
  .topbar, .layers { right: 12px; max-width: none; }
}
