/* Tokens. Shape rule: panels and inputs 10px, buttons 8px, chips and switches fully round. */
:root {
  --surface: #fbfbfa;
  --surface-2: #f2f3f1;
  --surface-3: #e8eae6;
  --ink: #1d2320;
  --ink-2: #4b544f;
  --ink-3: #7a837e;
  --line: #e1e4e0;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe8;
  --danger: #a33a2c;
  --shadow: 0 1px 2px rgb(29 35 32 / .06), 0 6px 20px rgb(29 35 32 / .08);
  --r-panel: 10px;
  --r-btn: 8px;
  --left-w: 304px;
  --right-w: 352px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  font-family: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #161a18;
    --surface-2: #1d2220;
    --surface-3: #262c29;
    --ink: #e7ebe8;
    --ink-2: #b3bbb6;
    --ink-3: #848d88;
    --line: #2c3330;
    --accent: #6cc49a;
    --accent-ink: #0f1a14;
    --accent-soft: #1f3329;
    --danger: #e0806f;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--surface); }
button, input, select { font: inherit; color: inherit; }
.mono, .num { font-family: "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Layout: left panel | map | right panel */
.app {
  display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  height: 100dvh;
  transition: grid-template-columns .28s var(--ease);
}
.app.no-left { grid-template-columns: 0 1fr var(--right-w); }
.app.no-right { grid-template-columns: var(--left-w) 1fr 0; }
.app.no-left.no-right { grid-template-columns: 0 1fr 0; }
.panel { background: var(--surface); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); }
.no-left .panel-left, .no-right .panel-right { border: 0; }
.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

/* Buttons */
.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center; flex: none;
  border: 1px solid transparent; border-radius: var(--r-btn); background: transparent;
  color: var(--ink-2); cursor: pointer; font-size: 17px;
  transition: background .15s, color .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active, .pill-btn:active { transform: scale(.97); }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--ink); cursor: pointer; font-weight: 500; box-shadow: var(--shadow);
}
.pill-btn i { font-size: 16px; color: var(--accent); }
.floating { position: absolute; z-index: 2; }
.icon-btn.floating { top: 12px; left: 12px; background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.right-open { top: 12px; right: 56px; }
.no-right .right-open { display: inline-flex; }
.right-open { display: none; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 12px 12px 16px; }
.brand > div { flex: 1; min-width: 0; }
.brand-mark { width: 32px; height: 32px; border-radius: var(--r-btn); display: grid; place-items: center;
              background: var(--accent); color: var(--accent-ink); font-size: 18px; flex: none; }
h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.brand p { margin: 0; font-size: 12px; color: var(--ink-3); }
h2 { font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 4px 8px; }

/* Search */
.search { position: relative; margin: 0 12px 12px; }
.search > i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); font-size: 16px; pointer-events: none; }
.search input {
  width: 100%; height: 38px; padding: 0 12px 0 34px; border-radius: var(--r-panel);
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
  transition: border-color .15s, background .15s;
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { border-color: var(--accent); background: var(--surface); }
#search-results {
  list-style: none; margin: 6px 0 0; padding: 4px; position: absolute; inset: 100% 0 auto; z-index: 10;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel);
  box-shadow: var(--shadow); max-height: 320px; overflow-y: auto;
}
#search-results:empty { display: none; }
#search-results li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#search-results li:hover, #search-results li[aria-selected="true"] { background: var(--accent-soft); }
#search-results small { color: var(--ink-3); text-align: right; }

/* Layer list */
.panel-scroll { flex: 1; overflow-y: auto; padding: 4px 12px 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.group { margin-bottom: 6px; }
.group-head {
  display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px 4px; border: 0;
  background: none; cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 12.5px; text-align: left;
}
.group-head i { font-size: 12px; transition: transform .2s var(--ease); }
.group.collapsed .group-head i { transform: rotate(-90deg); }
.group.collapsed .group-body { display: none; }
.group-head .count { margin-left: auto; font-weight: 500; color: var(--ink-3); font-size: 12px; }

.layer { border-radius: var(--r-btn); }
.layer-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px 6px 6px; border-radius: var(--r-btn); }
.layer-row:hover { background: var(--surface-2); }
.layer-name { flex: 1; min-width: 0; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer.dim .layer-name { color: var(--ink-3); }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.layer-row .icon-btn { width: 26px; height: 26px; font-size: 15px; }
.layer.open .layer-row .icon-btn { color: var(--accent); }
.layer-detail { padding: 4px 8px 12px 50px; display: none; }
.layer.open .layer-detail { display: block; }
.layer-desc { font-size: 12px; color: var(--ink-3); margin: 0 0 8px; }
.range { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.range input { flex: 1; accent-color: var(--accent); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }

/* Switch */
.switch { position: relative; width: 30px; height: 18px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line); transition: background .18s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .18s var(--ease); }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(12px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .12); }
.swatch.line { height: 3px; border-radius: 2px; box-shadow: none; }
.swatch.circle { border-radius: 50%; }

/* Basemap */
.panel-foot { padding: 12px 16px 14px; border-top: 1px solid var(--line); }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; gap: 3px; background: var(--surface-2); border-radius: var(--r-panel); }
.segmented button { border: 0; background: none; padding: 6px 4px; border-radius: 7px; cursor: pointer; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; justify-content: center; }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }

/* Right panel */
.right-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 12px; border-bottom: 1px solid var(--line); }
.tabs { flex: 1; display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--r-panel); }
.tabs button { flex: 1; border: 0; background: none; padding: 6px 8px; border-radius: 7px; cursor: pointer; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; justify-content: center; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }
.tab-body { flex: 1; overflow-y: auto; padding: 16px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
.field select { height: 36px; padding: 0 10px; border-radius: var(--r-panel); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }

.scope-switch { margin-bottom: 16px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; margin-bottom: 18px; }
.kpi { background: var(--surface); padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--ink-3); }
.kpi .value { font-size: 20px; font-weight: 500; letter-spacing: -.02em; margin-top: 2px; }
.kpi .value small { font-size: 12px; color: var(--ink-3); font-weight: 400; margin-left: 3px; }
.scope { font-size: 12px; color: var(--ink-3); margin: -8px 0 14px; display: flex; gap: 6px; align-items: center; }

.note { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--ink-2);
        background: var(--surface-2); border-radius: var(--r-panel); padding: 9px 11px; margin: 0 0 14px; }
.note i { color: var(--accent); font-size: 15px; margin-top: 1px; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.bar-row { display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 10px; align-items: center; padding: 7px 8px; border-radius: var(--r-btn); cursor: default; }
.bar-row:hover { background: var(--surface-2); }
.bar-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-name b { font-weight: 600; margin-right: 4px; }
.bar-val { text-align: right; color: var(--ink-2); font-size: 12.5px; }
.bar-track { grid-column: 2 / 4; height: 6px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; transition: width .35s var(--ease); }
.bar-row .pct { color: var(--ink-3); margin-left: 6px; }

/* Detail tab */
.detail-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
.detail-head .swatch { width: 14px; height: 14px; margin-top: 3px; }
.detail-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.detail-head p { margin: 2px 0 0; color: var(--ink-3); font-size: 12px; }
.code-card { background: var(--accent-soft); border-radius: var(--r-panel); padding: 10px 12px; margin-bottom: 14px; }
.code-card .code { font-size: 18px; font-weight: 500; }
.code-card .desc { color: var(--ink-2); font-size: 12.5px; }
.attrs { margin: 0; display: grid; grid-template-columns: minmax(96px, auto) 1fr; }
.attrs dt, .attrs dd { padding: 6px 0; border-bottom: 1px solid var(--line); margin: 0; font-size: 12.5px; }
.attrs dt { color: var(--ink-3); padding-right: 12px; }
.attrs dd { word-break: break-word; }
.actions { display: flex; gap: 8px; margin-top: 16px; }
.btn { height: 34px; padding: 0 14px; border-radius: var(--r-btn); border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:active { transform: scale(.98); }

.empty { text-align: center; padding: 40px 12px; color: var(--ink-3); }
.empty i { font-size: 30px; color: var(--ink-3); display: block; margin-bottom: 10px; }
.empty p { margin: 0 auto; max-width: 30ch; }
.error { color: var(--danger); }

/* API key dialog */
.key-dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(380px, calc(100vw - 32px));
              background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.key-dialog::backdrop { background: rgb(15 20 18 / .45); backdrop-filter: blur(2px); }
.key-dialog form { padding: 24px; display: grid; gap: 12px; }
.key-dialog h2 { font-size: 16px; color: var(--ink); }
.key-dialog p { margin: 0; font-size: 13px; }
.key-dialog .field { margin: 4px 0 0; }
.key-dialog input { height: 38px; padding: 0 12px; border-radius: var(--r-panel); border: 1px solid var(--line);
                    background: var(--surface-2); color: var(--ink); font-family: "Geist Mono", monospace; }
.key-dialog input:focus { outline: none; border-color: var(--accent); }
.key-dialog .btn { justify-content: center; height: 38px; }

/* Loading skeletons */
.skeleton-row, .sk { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; border-radius: var(--r-btn); animation: shimmer 1.2s linear infinite; }
.skeleton-row { height: 30px; margin: 6px 0; }
.sk { height: 14px; margin: 10px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Status chip */
.status { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 2;
          background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px;
          padding: 3px 10px; font-size: 11.5px; box-shadow: var(--shadow); white-space: nowrap; }

/* MapLibre controls in theme */
.maplibregl-ctrl-group { background: var(--surface) !important; border-radius: var(--r-btn) !important; box-shadow: var(--shadow) !important; border: 1px solid var(--line); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line) !important; }
@media (prefers-color-scheme: dark) { .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); } }
.maplibregl-ctrl-attrib { font-size: 10.5px; }
.maplibregl-ctrl-scale { background: rgb(255 255 255 / .8); border-color: #555; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Narrow screens: map on top, panels become sheets */
@media (max-width: 760px) {
  .app, .app.no-left, .app.no-right, .app.no-left.no-right { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .map-wrap { grid-area: 1 / 1; }
  .panel { position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; max-height: 62dvh; border: 0;
           border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
           transition: transform .28s var(--ease); }
  .no-left .panel-left, .no-right .panel-right { transform: translateY(105%); }
  .right-open { right: 12px; top: auto; bottom: 44px; }
  .status { bottom: auto; top: 12px; }
}
