:root {
  --bg: #0a1628;
  --bg-2: #0f1f38;
  --bg-3: #152a4a;
  --line: #213a60;
  --text: #e6eefb;
  --muted: #8fa6c8;
  --faint: #5d7499;
  --accent: #22d3ee;
  --accent-2: #0ea5c6;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --htm: #e11d48;
  --ebs: #10b981;
  --other: #64748b;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  --sidebar-w: 340px;
  --detail-w: 400px;
  --top-h: 52px;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 4px; background: var(--accent); color: #000; padding: 6px 10px; border-radius: 6px; z-index: 3000; }
.skip:focus { left: 8px; }

/* ---------- Topbalk ---------- */
.topbar {
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0 calc(12px + env(safe-area-inset-left));
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(180deg, #0c1c34, #0a1628);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 1200;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand small { color: var(--accent); font-weight: 600; margin-left: 2px; }
.brand-mark { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 1.6; }
.brand-mark .blip { fill: var(--accent); stroke: none; }
.live { display: flex; align-items: center; gap: 8px; margin-left: auto; padding: 4px 10px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
.live .txt { overflow: hidden; text-overflow: ellipsis; }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.live.ok .dot { background: var(--ok); box-shadow: 0 0 0 0 rgba(52, 211, 153, .6); animation: pulse 2s infinite; }
.live.warn .dot { background: var(--warn); }
.live.bad .dot { background: var(--bad); }
.live.bad { border-color: var(--bad); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .55); } 70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }
@media (prefers-reduced-motion: reduce) { .live.ok .dot { animation: none; } }
.region select, .row2 select { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.icon-btn { background: transparent; border: 0; padding: 6px; border-radius: 8px; }
.icon-btn svg { width: 22px; height: 22px; stroke: var(--text); stroke-width: 2; fill: none; stroke-linecap: round; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr auto;
  height: calc(100vh - var(--top-h) - env(safe-area-inset-top));
  height: calc(100dvh - var(--top-h) - env(safe-area-inset-top));
  min-height: 0;
}
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.mapwrap { position: relative; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; background: #1b2a40; }
.detail { width: var(--detail-w); background: var(--bg-2); border-left: 1px solid var(--line); min-height: 0; overflow: auto; overscroll-behavior: contain; }
.detail[hidden] { display: none; }
.only-mobile { display: none; }
body.map-max .sidebar, body.map-max .detail { display: none; }
body.map-max .layout { grid-template-columns: 1fr; }

/* ---------- Tabs & panelen ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tabs button { flex: 1; background: none; border: 0; padding: 11px 4px; color: var(--muted); font-weight: 600; font-size: 13px; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent-2); color: #001018; font-size: 11px; line-height: 18px; text-align: center; }
.badge.warn { background: var(--warn); }
.panel { padding: 12px; overflow: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.panel[hidden] { display: none; }
.search input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
.search input::placeholder { color: var(--faint); }
.chips { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips legend { width: 100%; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.chips span { display: inline-block; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); font-size: 13px; user-select: none; }
.chips input:checked + span { border-color: var(--accent); color: var(--text); background: rgba(34, 211, 238, .12); }
.chips input:focus-visible + span { outline: 2px solid var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.count { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.count b { display: block; font-size: 18px; }
.count span { color: var(--muted); font-size: 11.5px; }
.count.htm { border-left: 3px solid var(--htm); }
.count.ebs { border-left: 3px solid var(--ebs); }
.count.other { border-left: 3px solid var(--other); }
.count.unk { border-left: 3px dashed var(--faint); }
.list-head { color: var(--muted); font-size: 12px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.list button.item { width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: left; background: var(--bg); border: 1px solid transparent; border-radius: 8px; padding: 7px 9px; }
.list button.item:hover, .list button.item.sel { border-color: var(--accent-2); }
.item .meta { min-width: 0; }
.item .t1, .item .t2 { display: block; }
.item .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t2 { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .side { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.alerts .alert { background: var(--bg); border: 1px solid var(--line); border-left: 3px solid var(--warn); border-radius: 8px; padding: 9px 10px; }
.alert h4 { margin: 0 0 4px; font-size: 13.5px; }
.alert p { margin: 4px 0; color: var(--muted); font-size: 12.5px; white-space: pre-line; }
.alert .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--bg-3); color: var(--muted); }

/* ---------- Lijnbadge ---------- */
.lb { display: inline-flex; align-items: center; justify-content: center; gap: 3px; min-width: 38px; height: 24px; padding: 0 6px; border-radius: 6px; font-weight: 800; font-size: 13px; background: var(--other); color: #fff; border: 2px solid transparent; }
.lb svg { width: 13px; height: 13px; fill: currentColor; flex: none; }
.lb.op-HTM { border-color: var(--htm); }
.lb.op-EBS { border-color: var(--ebs); }

/* ---------- Kaartbediening ---------- */
.map-controls { position: absolute; right: calc(10px + env(safe-area-inset-right)); top: 10px; z-index: 1000; display: flex; flex-direction: column; gap: 6px; }
.ctl { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: rgba(15, 31, 56, .94); display: grid; place-items: center; box-shadow: var(--shadow); }
.ctl svg { width: 21px; height: 21px; fill: none; stroke: var(--text); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ctl:hover { border-color: var(--accent); }
.ctl.busy svg { animation: spin 1s linear infinite; }
.ctl[aria-pressed="true"] { border-color: var(--accent); background: rgba(34, 211, 238, .18); }
@keyframes spin { to { transform: rotate(360deg); } }
.layers-menu { position: absolute; right: 62px; top: 10px; z-index: 1001; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; width: 260px; box-shadow: var(--shadow); }
.layers-menu h5 { margin: 4px 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.layers-menu label { display: flex; gap: 8px; align-items: flex-start; padding: 5px 2px; font-size: 13px; }
.layers-menu small { display: block; color: var(--faint); font-size: 11px; }
.banner { position: absolute; left: 50%; transform: translateX(-50%); top: 10px; z-index: 1002; max-width: min(640px, calc(100% - 80px)); background: #3b0d14; border: 1px solid var(--bad); color: #fee2e2; padding: 9px 12px; border-radius: var(--radius); box-shadow: var(--shadow); font-size: 13px; }
.banner.warn { background: #3a2a05; border-color: var(--warn); color: #fef3c7; }
.tile-warn { position: absolute; left: 10px; bottom: 28px; z-index: 1000; background: #3a2a05; color: #fef3c7; border: 1px solid var(--warn); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; }

/* Donkere variant van de PDOK-grijskaart (alleen CSS-filter; geen extra tegelverzoeken) */
.tiles-dark { filter: invert(1) hue-rotate(185deg) brightness(.92) contrast(.9) saturate(.6); }
.leaflet-container { font: inherit; background: #1b2a40; }
.leaflet-control-attribution { background: rgba(10, 22, 40, .8) !important; color: var(--muted) !important; font-size: 10.5px; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-control-zoom a { background: var(--bg-2) !important; color: var(--text) !important; border-color: var(--line) !important; }

/* ---------- Voertuigmarkers ---------- */
.vm-wrap { background: none; border: 0; }
.vm {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 2px;
  width: 44px; height: 22px; border-radius: 6px;
  background: var(--c, #475569); color: var(--tc, #fff);
  font-weight: 800; font-size: 11.5px; letter-spacing: -.2px;
  border: 2px solid var(--b, #0a1628);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .55);
  transition: transform .15s;
}
.vm svg { width: 11px; height: 11px; fill: currentColor; flex: none; }
.vm.op-HTM { --b: var(--htm); }
.vm.op-EBS { --b: var(--ebs); }
.vm.mode-tram { border-radius: 11px; }
.vm .hd { position: absolute; inset: -9px; pointer-events: none; }
.vm .hd::before { content: ""; position: absolute; left: 50%; top: -1px; transform: translateX(-50%); border: 5px solid transparent; border-bottom: 7px solid var(--accent); border-top: 0; }
.vm.stale { opacity: .45; filter: grayscale(.8); }
.vm.sel { transform: scale(1.25); box-shadow: 0 0 0 3px var(--accent), 0 2px 10px rgba(0, 0, 0, .6); z-index: 10; }
.mapwrap.feed-down .vm { filter: grayscale(1); opacity: .35; }
.vm.dot { width: 11px; height: 11px; border-radius: 50%; font-size: 0; border-width: 1.5px; }
.vm.dot svg, .vm.dot .hd { display: none; }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(59, 130, 246, .35); }

/* ---------- Detailpaneel ---------- */
.sheet-handle { display: none; }
.detail-inner { padding: 14px 14px calc(18px + env(safe-area-inset-bottom)); }
.dh { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.dh .lb { height: 34px; min-width: 52px; font-size: 17px; }
.dh h2 { margin: 0; font-size: 16px; line-height: 1.25; }
.dh .sub { color: var(--muted); font-size: 12.5px; }
.dh .x { margin-left: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 34px; flex: none; font-size: 18px; line-height: 1; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.btn { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; }
.btn[aria-pressed="true"] { border-color: var(--accent); background: rgba(34, 211, 238, .14); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.kpi { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.kpi b { display: block; font-size: 15px; }
.kpi > span { color: var(--muted); font-size: 11px; }
.late { color: var(--bad); }
.early { color: var(--warn); }
.ontime { color: var(--ok); }
.sec { margin: 12px 0 4px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); font-weight: 700; display: flex; align-items: center; gap: 6px; }
dl.f { display: grid; grid-template-columns: 42% 1fr; gap: 0; margin: 0; }
dl.f dt, dl.f dd { padding: 5px 0; border-bottom: 1px solid rgba(33, 58, 96, .6); margin: 0; font-size: 13px; }
dl.f dt { color: var(--muted); }
dl.f dd { word-break: break-word; }
.na { color: var(--faint); font-style: italic; }
.src { display: inline-block; font-size: 10px; padding: 0 5px; margin-left: 5px; border-radius: 4px; vertical-align: 1px; font-style: normal; }
.src.rt { background: rgba(34, 211, 238, .16); color: var(--accent); }
.src.st { background: rgba(148, 163, 184, .18); color: #cbd5e1; }
.src.kv { background: rgba(167, 139, 250, .18); color: #c4b5fd; }
.src.db { background: rgba(251, 191, 36, .16); color: #fcd34d; }
.src.nv { background: rgba(248, 113, 113, .16); color: #fca5a5; }
table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 4px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-2); }
table.t td { padding: 4px 4px; border-bottom: 1px solid rgba(33, 58, 96, .5); vertical-align: top; }
table.t tr.next td { background: rgba(34, 211, 238, .08); }
table.t tr.skip td { text-decoration: line-through; color: var(--faint); }
.problems { margin: 8px 0 0; padding-left: 18px; color: var(--warn); font-size: 12.5px; }
.diag-block { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 10px; font-size: 12.5px; }
.diag-block h4 { margin: 0 0 6px; font-size: 13px; }
.diag-block code { font-size: 11.5px; word-break: break-all; color: #a5f3fc; }
.ok-t { color: var(--ok); } .bad-t { color: var(--bad); } .warn-t { color: var(--warn); }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1300; }

/* ---------- Mobiel ---------- */
@media (max-width: 900px) {
  :root { --top-h: 50px; }
  .only-mobile { display: inline-grid; place-items: center; }
  .brand small { display: none; }
  .region select { max-width: 120px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(88vw, 360px); z-index: 1400;
    padding-top: env(safe-area-inset-top);
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow);
  }
  body.drawer-open .sidebar { transform: none; }
  .detail {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; z-index: 1250;
    max-height: 62dvh; max-height: 62vh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
    transition: max-height .2s ease;
  }
  .detail.expanded { max-height: calc(100dvh - var(--top-h) - 10px); }
  .sheet-handle { display: block; position: sticky; top: 0; height: 22px; background: var(--bg-2); z-index: 2; cursor: grab; touch-action: none; }
  .sheet-handle::after { content: ""; position: absolute; left: 50%; top: 8px; width: 42px; height: 5px; border-radius: 3px; background: var(--faint); transform: translateX(-50%); }
  .detail-inner { padding-top: 2px; }
  .map-controls .ctl { width: 44px; height: 44px; }
  .live { max-width: 40vw; }
  .banner { max-width: calc(100% - 76px); left: 10px; transform: none; }
}
@media (max-width: 380px) {
  .live .txt { display: none; }
}

/* ---------- Pro & reisplanner ---------- */
.pro-btn { background: linear-gradient(135deg, #22d3ee, #6366f1); color: #001018; border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 800; letter-spacing: .3px; }
.pro-btn.has { background: var(--bg-2); color: var(--accent); border: 1px solid var(--accent); }
.tabs .ti { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; vertical-align: -3px; }
.tabs button[data-tab="diag"] { flex: 0 0 48px; }
.plan-form { position: relative; display: flex; flex-direction: column; gap: 8px; }
.pf-row { display: flex; align-items: center; gap: 6px; }
.pf-row input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
.pf-dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; flex: none; }
.pf-dot.a { background: #22c55e; color: #00130a; }
.pf-dot.b { background: #f43f5e; color: #1b0006; }
.mini { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); display: grid; place-items: center; flex: none; }
.mini svg, .swap svg { width: 17px; height: 17px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.swap { align-self: center; width: 30px; height: 30px; margin: -6px 0; border-radius: 50%; border: 1px solid var(--line); background: var(--bg-3); display: grid; place-items: center; }
.suggest { list-style: none; margin: 0; padding: 4px; background: var(--bg); border: 1px solid var(--accent-2); border-radius: 8px; max-height: 260px; overflow: auto; }
.suggest button { width: 100%; text-align: left; background: none; border: 0; padding: 7px 8px; border-radius: 6px; display: flex; justify-content: space-between; gap: 8px; }
.suggest button:hover, .suggest button:focus-visible { background: var(--bg-3); }
.suggest span { color: var(--muted); font-size: 12px; flex: none; }
.btn.primary { background: var(--accent); color: #001018; border-color: var(--accent); font-weight: 700; }
.btn.big { padding: 10px 14px; font-size: 14px; }
.btn.sm { padding: 2px 8px; font-size: 12px; }
.plan-opt { grid-template-columns: 1fr !important; }
.chips-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 5px; }
.chips-row .lb { height: 22px; min-width: 32px; font-size: 12px; }
.chev { color: var(--faint); }
.walkchip { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; }
.wi { width: 14px; height: 14px; fill: currentColor; flex: none; }
.steps { list-style: none; margin: 4px 0 10px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.step { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
.step.walk { background: transparent; border-style: dashed; }
.step .wi { width: 18px; height: 18px; color: var(--muted); margin-top: 2px; }
.step .tl { margin-top: 4px; }
.step .tm { display: inline-block; min-width: 44px; font-variant-numeric: tabular-nums; font-weight: 700; }
.step .rt { margin: 5px 0; font-size: 12.5px; }
.ministops { margin: 6px 0 2px; padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 3px; animation: pulse 2s infinite; }
.pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: grid; place-items: center; font-weight: 800; font-size: 12px; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.pin-from { background: #22c55e; color: #00130a; }
.pin-to { background: #f43f5e; color: #1b0006; }
.modal-wrap { position: fixed; inset: 0; z-index: 2000; background: rgba(2, 8, 20, .7); display: grid; place-items: center; padding: 16px; }
.modal-wrap[hidden] { display: none; }
.modal { position: relative; width: min(460px, 100%); max-height: 90vh; overflow: auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 22px 20px 18px; box-shadow: var(--shadow); }
.modal .x { position: absolute; right: 12px; top: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 34px; font-size: 18px; }
.modal h3 { margin: 0 0 4px; font-size: 20px; }
.modal ul.feat { padding-left: 20px; margin: 10px 0; }
.modal ul.feat li { margin: 4px 0; }
.price { font-size: 28px; font-weight: 800; margin: 8px 0 2px; }
.keybox { font-family: ui-monospace, monospace; font-size: 17px; color: var(--accent); background: var(--bg); border: 1px dashed var(--accent-2); border-radius: 8px; padding: 10px; text-align: center; user-select: all; margin: 8px 0; word-break: break-all; }
.modal input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin: 6px 0; }
.modal .stack { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
@media (max-width: 900px) { .pro-btn { padding: 5px 10px; font-size: 13px; } .tabs button { font-size: 12px; } }
