:root {
  --accent: #0a5ca8;
  --accent-dark: #084a87;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1b232c;
  --muted: #687585;
  --line: #e2e7ee;
  --ja: #2166ac;
  --nein: #c0473b;
  --shadow: 0 1px 3px rgba(20, 35, 55, .08), 0 6px 24px rgba(20, 35, 55, .06);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; overflow: hidden; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 14px 22px; background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(20,35,55,.03);
  flex: none;
}
.kicker {
  font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--accent);
}
.topbar h1 { margin: 2px 0 0; font-size: 19px; font-weight: 650; letter-spacing: -.01em; }
.topbar-summary { display: flex; gap: 22px; flex-wrap: wrap; }
.stat { text-align: right; }
.stat-val { font-size: 20px; font-weight: 700; line-height: 1; }
.stat-val.ja { color: var(--ja); }
.stat-val.nein { color: var(--nein); }
.stat-lbl { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* ---------- Mode-Switch ---------- */
.mode-switch { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.mode-switch button {
  border: none; background: transparent; cursor: pointer; font: inherit;
  font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 14px; border-radius: 6px;
}
.mode-switch button.active { background: var(--accent); color: #fff; box-shadow: var(--shadow); }

.hidden { display: none !important; }

/* ---------- Galerie (Zusammenhänge) ---------- */
.gallery-view { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 26px 40px; }
.gallery-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.gallery-intro h2 { margin: 0 0 6px; font-size: 18px; font-weight: 680; letter-spacing: -.01em; }
.gallery-intro .hint { max-width: 760px; margin: 0; font-size: 13px; }
.ink-ja { color: var(--ja); font-weight: 700; }
.ink-nein { color: var(--nein); font-weight: 700; }
.thresh { flex: none; font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; cursor: pointer; }
.thresh input { accent-color: var(--accent); }

.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); gap: 16px; }
.gcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px; overflow: hidden;
  cursor: pointer; transition: box-shadow .12s, border-color .12s, transform .12s;
}
.gcard:hover { box-shadow: var(--shadow); border-color: #c7d4e3; transform: translateY(-2px); }
.gcard.anchor { border-color: var(--accent); border-width: 2px; cursor: default; }
.gcard.anchor:hover { transform: none; }
.gcard-map { display: block; width: 100%; height: auto; background: #fbfcfd; }
.gcard-foot { padding: 9px 12px 11px; border-top: 1px solid var(--line); }
.gcard-label { font-size: 12.5px; font-weight: 600; line-height: 1.3; min-height: 32px; }
.gcard-meta { display: flex; align-items: baseline; justify-content: space-between; margin-top: 6px; }
.gcard-r { font-size: 17px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.gcard-r2 { font-size: 11px; color: var(--muted); }
.gcard-strength { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 10px; }

/* ---------- Bürgerschaftswahl ---------- */
.bw-citywide, .bw-shares { display: flex; flex-direction: column; gap: 5px; }
.bw-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.bw-pname { width: 104px; flex: none; display: flex; align-items: center; gap: 6px; }
.bw-dot { width: 11px; height: 11px; border-radius: 2px; flex: none; }
.bw-track { flex: 1; height: 8px; background: #eef1f5; border-radius: 4px; overflow: hidden; }
.bw-fill { height: 100%; border-radius: 4px; }
.bw-val { width: 44px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.bw-winner { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 5px; color: #fff; }
.legend-cat { display: flex; align-items: center; gap: 7px; font-size: 12px; }

/* ---------- Doppelkarte ---------- */
.dual-view { flex: 1; min-height: 0; position: relative; }
.dual-panes { display: flex; height: 100%; }
.dual-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.dual-pane:first-child { border-right: 1px solid var(--line); }
.dual-head {
  flex: none; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px; min-height: 0;
}
.dual-title { font-size: 14px; font-weight: 650; }
.select-inline { max-width: 340px; }
.dual-legend .legend-steps { flex-direction: row; flex-wrap: wrap; gap: 4px 14px; }
.dual-map { flex: 1; background: #eaeef3; }
.dual-readout {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 1200;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow);
  padding: 10px 18px; display: flex; align-items: baseline; gap: 16px; font-size: 13px; white-space: nowrap;
  max-width: calc(100% - 32px); overflow: hidden; pointer-events: none;
}
.dual-readout strong { font-size: 15px; }
.dual-readout span { color: var(--muted); }
.leaflet-tooltip.dual-tip {
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); padding: 6px 9px;
}
.leaflet-tooltip.dual-tip .tip-sub { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; margin-top: 1px; }

/* ---------- Layout ---------- */
.layout { display: flex; flex: 1; min-height: 0; }
.panel {
  width: 340px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 4px 0;
}
.panel-block { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-label {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 7px;
}
.panel-h2 { margin: 0 0 4px; font-size: 14px; font-weight: 650; }
.hint { margin: 0 0 12px; font-size: 12px; color: var(--muted); line-height: 1.45; }

.select {
  width: 100%; padding: 9px 10px; font-size: 13px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 7px;
  appearance: none; cursor: pointer; font-family: inherit;
}
.select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,92,168,.12); }

/* ---------- Legend (diskrete Klassen) ---------- */
.legend { margin-top: 14px; }
.legend-steps { display: flex; flex-direction: column; gap: 3px; }
.legend-step { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--ink); }
.legend-swatch { width: 16px; height: 12px; border-radius: 2px; border: 1px solid rgba(0,0,0,.10); flex: none; }

/* ---------- Scatter ---------- */
.scatter-wrap { margin-top: 6px; background: #fbfcfd; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
#scatter { width: 100%; height: auto; display: block; }
.scatter-pt { fill: var(--accent); fill-opacity: .55; stroke: #fff; stroke-width: .5; cursor: pointer; transition: fill-opacity .1s; }
.scatter-pt:hover, .scatter-pt.active { fill-opacity: 1; fill: var(--accent-dark); }
.scatter-axis { stroke: #c7cfd9; stroke-width: 1; }
.scatter-grid { stroke: #eef1f5; stroke-width: 1; }
.scatter-reg { stroke: var(--nein); stroke-width: 1.6; stroke-dasharray: 4 3; }
.scatter-lbl { fill: var(--muted); font-size: 9px; }
.corr-readout { margin-top: 12px; font-size: 12.5px; line-height: 1.5; }
.corr-r { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.corr-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }

/* ---------- Search ---------- */
.search-results { margin-top: 8px; display: flex; flex-direction: column; gap: 2px; }
.search-item { padding: 6px 9px; font-size: 13px; border-radius: 6px; cursor: pointer; }
.search-item:hover { background: var(--bg); }

.panel-foot { padding: 16px 20px; font-size: 10.5px; color: var(--muted); line-height: 1.5; }

/* ---------- Map ---------- */
.map-wrap { position: relative; flex: 1; }
#map, #bwMap { position: absolute; inset: 0; background: #eaeef3; }
.leaflet-container { font: inherit; }

.info-card {
  position: absolute; left: 14px; bottom: 14px; z-index: 500;
  width: 290px; max-width: calc(100% - 28px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 14px 16px;
}
.info-empty { font-size: 12.5px; color: var(--muted); }
.info-close {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; pointer-events: auto;
}
.info-close:hover { background: var(--bg); color: var(--ink); }
.info-name { font-size: 16px; font-weight: 680; letter-spacing: -.01em; }
.info-bezirk { font-size: 11.5px; color: var(--muted); margin-bottom: 10px; }
.info-result { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.info-badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 5px; color: #fff; }
.info-badge.ja { background: var(--ja); }
.info-badge.nein { background: var(--nein); }
.bars { margin-bottom: 10px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 3px 0; }
.bar-key { width: 92px; color: var(--muted); flex: none; }
.bar-track { flex: 1; height: 8px; background: #eef1f5; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }
.bar-fill.ja { background: var(--ja); }
.bar-fill.nein { background: var(--nein); }
.bar-fill.bet { background: var(--accent); }
.bar-val { width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.info-grid { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; font-size: 12px; border-top: 1px solid var(--line); padding-top: 9px; }
.info-grid .k { color: var(--muted); }
.info-grid .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.info-current { background: rgba(10,92,168,.06); margin: 0 -6px; padding: 3px 6px; border-radius: 4px; }

/* ---------- Responsiv / Mobil ---------- */
@media (max-width: 860px) {
  body { overflow: auto; -webkit-text-size-adjust: 100%; }

  /* Topbar bricht um: Titel, dann scrollbare Modus-Leiste, dann Kennzahlen */
  .topbar { flex-wrap: wrap; align-items: flex-start; gap: 10px 16px; padding: 12px 16px; }
  .topbar-title { flex: 1 1 100%; }
  .topbar h1 { font-size: 17px; }
  .mode-switch { order: 2; width: 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .mode-switch::-webkit-scrollbar { display: none; }
  .mode-switch button { flex: 1 0 auto; white-space: nowrap; padding: 8px 14px; }
  .topbar-summary { order: 3; gap: 20px; }
  .stat { text-align: left; }

  /* Explorer und Bürgerschaft: Karte zuerst, Bedienpanel darunter */
  .layout { flex-direction: column; flex: none; height: auto; }
  .panel { width: 100%; border-right: none; border-top: 1px solid var(--line); overflow: visible; }
  .map-wrap { order: -1; height: 64vh; min-height: 320px; }

  /* Galerie */
  .gallery-view { flex: none; min-height: 0; height: auto; padding: 18px 16px 32px; }
  .gallery-head { flex-direction: column; gap: 10px; }

  /* Doppelkarte: zwei Karten gestapelt */
  .dual-view { flex: none; min-height: 0; height: auto; }
  .dual-panes { flex-direction: column; }
  .dual-pane:first-child { border-right: none; border-bottom: 1px solid var(--line); }
  .dual-map { height: 52vh; min-height: 300px; }
  .dual-head { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .dual-readout { left: 10px; right: 10px; bottom: 10px; transform: none; flex-wrap: wrap; gap: 4px 14px; justify-content: center; text-align: center; }

  /* Info-Karte als Bottom-Sheet; fängt keine Taps ab, damit die ganze Karte (auch dahinter) tippbar bleibt */
  .info-card { left: 8px; right: 8px; bottom: 8px; width: auto; max-width: none; max-height: 48%; overflow-y: auto; pointer-events: none; }
  .info-card:has(.info-empty) { display: none; }

  /* Touch-Targets etwas größer */
  .select { padding: 11px 12px; font-size: 14px; }
  .search-item { padding: 9px 10px; }
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 15px; }
  .kicker { font-size: 10px; }
  .topbar-summary { gap: 16px; }
  .stat-val { font-size: 17px; }
  .map-wrap { height: 60vh; }
  .gallery-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .gcard-label { font-size: 11.5px; min-height: 28px; }
  .dual-map { height: 48vh; }
}
