:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e2e5ea;
  --ink: #16191f;
  --muted: #5d6573;
  --brand: #1f5eff;
  --brand-ink: #ffffff;
  --brand-soft: #e7eeff;
  --ok: #15803d;
  --ok-soft: #e3f5ea;
  --warn: #b45309;
  --warn-soft: #fdf1e1;
  --bad: #b91c1c;
  --bad-soft: #fde8e8;
  --code-bg: #0f172a;
  --code-ink: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --line: #2a303b;
    --ink: #e8ebf0;
    --muted: #9aa3b2;
    --brand: #6b93ff;
    --brand-ink: #0b1020;
    --brand-soft: #1c2745;
    --ok: #4ade80;
    --ok-soft: #13291c;
    --warn: #fbbf24;
    --warn-soft: #2d2410;
    --bad: #f87171;
    --bad-soft: #2e1616;
    --code-bg: #0a0d12;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #161a21; --surface-2: #1d222b; --line: #2a303b; --ink: #e8ebf0; --muted: #9aa3b2;
  --brand: #6b93ff; --brand-ink: #0b1020; --brand-soft: #1c2745; --ok: #4ade80; --ok-soft: #13291c;
  --warn: #fbbf24; --warn-soft: #2d2410; --bad: #f87171; --bad-soft: #2e1616; --code-bg: #0a0d12;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88em; }
[hidden] { display: none !important; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--brand); white-space: nowrap; letter-spacing: -0.01em; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { white-space: nowrap; color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-weight: 500; }
.topbar nav a:hover { background: var(--surface-2); color: var(--ink); }
.topbar nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.status { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; height: calc(100vh - 56px); }
.panel { background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; padding: 16px; }
.mapwrap { position: relative; }
#map { position: absolute; inset: 0; background: var(--surface-2); z-index: 0; } /* eigen stacking context: Leaflet-knoppen niet over de topbar */

/* Tabs & forms */
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius); margin-bottom: 14px; }
.tabs button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 8px; border-radius: 7px; font: inherit; font-weight: 600; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.form { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid2 > * { min-width: 0; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.input {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.input.big { padding: 11px 12px; font-size: 16px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--brand-soft); color: var(--brand); }
.seg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -2px; }
.btn {
  font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.row { display: flex; align-items: center; gap: 10px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.coords { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted); }

/* API bar */
.apibar {
  display: flex; align-items: center; gap: 8px; margin: 16px 0 4px;
  background: var(--code-bg); color: var(--code-ink); border-radius: 8px; padding: 6px 6px 6px 10px;
}
.apibar .method { font: 700 11px ui-monospace, Menlo, monospace; color: #86efac; }
.apibar code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
.apibar .icon {
  border: 0; background: rgb(255 255 255 / 8%); color: var(--code-ink); width: 28px; height: 28px;
  border-radius: 6px; cursor: pointer; display: grid; place-items: center; text-decoration: none; font-size: 14px; flex: none;
}
.apibar .icon:hover { background: rgb(255 255 255 / 16%); }

/* Results */
.results-head { color: var(--muted); font-size: 13px; margin: 12px 2px 6px; min-height: 1em; }
.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.results li button {
  width: 100%; text-align: left; font: inherit; color: inherit; background: transparent;
  border: 1px solid transparent; border-radius: 8px; padding: 9px 10px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
}
.results li button:hover { background: var(--surface-2); }
.results li button.active { background: var(--brand-soft); border-color: var(--brand); }
.results .name { font-weight: 600; }
.results .sub { color: var(--muted); font-size: 13px; grid-column: 1; }
.results .side { grid-row: 1 / span 2; grid-column: 2; align-self: center; display: flex; gap: 4px; align-items: center; }
.dist { font: 600 12px ui-monospace, Menlo, monospace; color: var(--muted); }
.more { width: 100%; margin-top: 8px; }
.empty { color: var(--muted); padding: 16px 4px; }
.error { color: var(--bad); background: var(--bad-soft); padding: 10px 12px; border-radius: 8px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  text-transform: lowercase; white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.mode { background: var(--brand-soft); color: var(--brand); }

/* Detail */
.detail {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: min(420px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  overflow-y: auto; z-index: 500; padding: 18px;
}
.detail h2 { margin: 0 32px 2px 0; font-size: 20px; letter-spacing: -0.01em; }
.detail .close {
  position: absolute; top: 12px; right: 12px; border: 0; background: var(--surface-2); color: var(--ink);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 16px;
}
.detail .badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 4px; }
.detail h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 20px 0 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); }
.chip.yes { background: var(--ok-soft); color: var(--ok); }
.chip.no { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
.linklist { list-style: none; margin: 0; padding: 0; }
.linklist button {
  width: 100%; display: flex; justify-content: space-between; gap: 8px; text-align: left; font: inherit; color: inherit;
  background: none; border: 0; border-top: 1px solid var(--line); padding: 8px 2px; cursor: pointer;
}
.linklist button:hover { color: var(--brand); }
.linklist small { color: var(--muted); }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 18px; }
details.raw pre {
  background: var(--code-bg); color: var(--code-ink); padding: 12px; border-radius: 8px; overflow: auto; max-height: 360px; font-size: 12px;
}

/* Leaflet */
.leaflet-container { font: inherit; }
.marker-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--brand); border: 2px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 40%); }
.marker-dot.expired { background: #9aa3b2; }
.marker-dot.active { width: 20px; height: 20px; background: #f43f5e; }
.marker-me { width: 16px; height: 16px; border-radius: 50%; background: #0ea5e9; border: 3px solid #fff; box-shadow: 0 0 0 6px rgb(14 165 233 / 25%); }

/* Mobile */
@media (max-width: 800px) {
  .topbar { gap: 8px; padding: 0 16px; }
  .topbar nav a { padding: 6px 8px; }
  .status { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .panel { border-right: 0; overflow: visible; order: 1; min-width: 0; }
  .mapwrap { order: 0; height: 42vh; min-height: 260px; border-bottom: 1px solid var(--line); }
  .detail { position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 75vh; border-radius: 14px 14px 0 0; z-index: 1100; }
}
@media (max-width: 420px) {
  .brand-text { display: none; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .tabs button { padding: 8px 4px; font-size: 14px; }
}
