:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --text: #1c1f1d;
  --muted: #5f6661;
  --line: #e3e6e1;
  --hover: #f1f3ef;
  --accent: #0b7a4b;
  --sbahn: #0b8a57;
  --regional: #d0342c;
  --fern: #4b3b8f;
  --none: #9aa19c;
  --shadow: 0 10px 30px rgba(20, 30, 25, .16), 0 2px 6px rgba(20, 30, 25, .08);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141715;
    --panel: #1c201e;
    --text: #e8ebe8;
    --muted: #a0a8a3;
    --line: #2e3431;
    --hover: #262b28;
    --accent: #3ec48a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141715;
  --panel: #1c201e;
  --text: #e8ebe8;
  --muted: #a0a8a3;
  --line: #2e3431;
  --hover: #262b28;
  --accent: #3ec48a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

/* !important: Google Maps setzt inline position:relative */
#map { position: fixed !important; inset: 0; }

/* ---------------------------------------------------------------- Panel */
.panel {
  position: fixed;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: 348px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 10;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
h1 { font-size: 18px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }

.panel-body { overflow-y: auto; padding: 12px 16px 16px; flex: 1; }
.block { padding: 12px 0; border-bottom: 1px solid var(--line); }
.block:last-of-type { border-bottom: 0; }
.block-head { display: flex; justify-content: space-between; align-items: baseline; }

.icon-btn {
  display: none;
  border: 0; background: transparent; color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 12.5px; padding: 0; }
.link-btn:hover { text-decoration: underline; }

.notice {
  background: #fff4d6; color: #5a4300; border: 1px solid #f0d58a;
  border-radius: 10px; padding: 9px 11px; font-size: 12.5px; margin-bottom: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .notice { background: #3a3116; color: #f3dd9b; border-color: #5c4d1f; }
}
.notice code { font-size: 12px; }

/* ---------------------------------------------------------------- Suche */
.search { position: relative; }
.search input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; z-index: 5;
}
.search-results li {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  padding: 7px 9px; border-radius: 7px; cursor: pointer;
}
.search-results li[aria-selected="true"], .search-results li:hover { background: var(--hover); }
.search-results .cats { display: flex; gap: 3px; flex-shrink: 0; }

/* ---------------------------------------------------------------- Ebenen */
.layers { display: grid; gap: 2px; }
.layer {
  display: grid; grid-template-columns: auto 22px 1fr auto; gap: 8px; align-items: center;
  padding: 6px 6px; border-radius: 8px; cursor: pointer; user-select: none;
}
.layer:hover { background: var(--hover); }
.layer input { margin: 0; accent-color: var(--accent); width: 15px; height: 15px; }
.layer .count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.swatch-line { height: 4px; border-radius: 2px; }
.swatch-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--none); background: var(--panel); justify-self: center; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------------------------------------------------------------- Linien */
.lines .group { margin-bottom: 10px; }
.lines .group-title { font-size: 12.5px; color: var(--text); margin: 2px 0 6px; cursor: pointer; font-weight: 550; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  --c: var(--accent);
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 2px 9px 2px 4px; font: inherit; font-size: 12px; cursor: pointer;
  white-space: nowrap;
}
.chip .tag {
  background: var(--c); color: #fff; border-radius: 999px; padding: 1px 7px;
  font-weight: 650; font-size: 11.5px; min-width: 26px; text-align: center;
}
.chip .net { color: var(--muted); font-size: 11px; }
.chip:hover { background: var(--hover); }
.chip.active { border-color: var(--c); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 35%, transparent); }
.chip.static { cursor: default; }

/* ---------------------------------------------------------------- Details */
.details h3 { margin: 0 0 2px; font-size: 16px; }
.details .meta { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }
.details .neighbors { list-style: none; margin: 0; padding: 0; }
.details .neighbors li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer;
}
.details .neighbors li:hover { background: var(--hover); }
.details .neighbors .km { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; white-space: nowrap; }
.details .sub-h { font-size: 12px; color: var(--muted); margin: 10px 0 5px; }
.details .close { float: right; }

/* ---------------------------------------------------------------- Footer */
.foot { padding-top: 12px; color: var(--muted); font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.stat { background: var(--bg); border-radius: 8px; padding: 7px 8px; }
.stat b { display: block; color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.src { margin: 0; }
.src a { color: inherit; }

/* ---------------------------------------------------------------- Karte: Canvas + Tooltip */
.net-canvas { position: absolute; pointer-events: none; }
.map-tooltip {
  position: fixed; left: 0; top: 0; z-index: 20; pointer-events: none;
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 7px 10px;
  font-size: 12.5px;
  line-height: 1.4;
  max-width: 280px;
}
.map-tooltip b { font-size: 13px; }
.map-tooltip .tt-lines { color: var(--muted); margin-top: 2px; }

/* ---------------------------------------------------------------- Mobil */
@media (max-width: 700px) {
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    max-height: 55vh;
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel-head { padding: 12px 16px 10px; }
  .icon-btn { display: inline-flex; }
  .panel.collapsed .panel-body { display: none; }
  .panel:not(.collapsed) .icon-btn svg { transform: rotate(180deg); }
}
