/* ============================================================
   TOKENS
   ============================================================ */
:root {
  /* Light surface palette (mock-aligned) */
  --bg:          #eef1f4;
  --surface:     #ffffff;
  --surface2:    #f4f6f9;
  --border:      #d8e1e9;
  --border2:     #c4d0dc;

  /* Accent — dark navy from mock */
  --accent:      #003153;
  --accent-mid:  #6ba3c8;
  --accent-dim:  rgba(0,49,83,0.07);
  --accent-glow: rgba(0,49,83,0.18);

  /* Text */
  --text:        #12283a;
  --text-dim:    #5a7284;
  --text-muted:  #9db4c4;

  /* Status */
  --green:       #12855f;
  --yellow:      #b54708;
  --red:         #d92d20;
  --orange:      #e08040;

  --mono: 'IBM Plex Mono', monospace;
  --sans: 'IBM Plex Sans', sans-serif;

  --header-h: 60px;
  --filterbar-h: 56px;
  --left-w: 340px;
  --ai-panel-w: 380px;
  --card-radius: 14px;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input  { outline: none; border: none; font: inherit; background: none; color: var(--text); }
select { cursor: pointer; font: inherit; }

.hidden { display: none !important; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-box {
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 4px 24px rgba(0,49,83,0.08);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 0;
  margin-bottom: 8px;
}

.login-field-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  font-family: var(--mono);
}

#login-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  border-radius: 10px;
  transition: border-color 0.15s;
  font-family: var(--sans);
}
#login-input:focus { border-color: var(--accent); }

#login-btn {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  padding: 11px 0;
  border-radius: 999px;
  transition: opacity 0.15s;
  font-family: var(--mono);
}
#login-btn:hover { opacity: 0.88; }
#login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#login-error {
  font-size: 11px;
  color: var(--red);
  letter-spacing: 0.04em;
  min-height: 16px;
  font-family: var(--mono);
}

.login-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--sans);
}

/* ============================================================
   HEADER
   ============================================================ */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 500;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  line-height: 0;
}

.header-divider {
  color: var(--border2);
  font-size: 14px;
}

.wahlkreis-badge {
  font-size: 9.5px;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 11px;
  border-radius: 10px;
  font-family: var(--mono);
}

.wahlkreis-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}

.header-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  margin-left: auto;
}

.tab-btn {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  padding: 0 18px;
  height: var(--header-h);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  font-family: var(--mono);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.abmelden-btn {
  font-size: 10px;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  margin-left: 8px;
  flex-shrink: 0;
  transition: color 0.15s;
  font-family: var(--mono);
}
.abmelden-btn:hover { color: var(--text); }

/* ============================================================
   BODY LAYOUT
   ============================================================ */
#app { height: 100%; }

#body {
  display: flex;
  height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
  overflow: hidden;
}

/* Tab pane full-height containers */
.tab-pane {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ============================================================
   KARTE TAB — FILTER BAR
   ============================================================ */
#karte-filterbar {
  flex: 0 0 auto;
  height: var(--filterbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 24px;
  z-index: 20;
}

.filterbar-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filterbar-label {
  font: 600 9.5px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.filterbar-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.filterbar-select {
  appearance: none;
  -webkit-appearance: none;
  font: 500 13px var(--sans);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 30px 6px 12px;
  min-width: 220px;
  cursor: pointer;
  box-shadow: none;
  transition: border-color 0.15s;
}
.filterbar-select:focus { outline: none; border-color: var(--accent); }

.filterbar-chevron {
  position: absolute;
  right: 10px;
  color: var(--text-dim);
  pointer-events: none;
}

/* Erststimme / Zweitstimme pill segmented control */
.filterbar-seg {
  display: flex;
  gap: 3px;
  background: var(--surface2);
  border-radius: 10px;
  padding: 3px;
  border: 1px solid var(--border);
}

.fseg-btn {
  padding: 5px 13px;
  border-radius: 8px;
  font: 600 12px var(--sans);
  color: var(--text-dim);
  background: transparent;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(.4,0,.2,1);
}
.fseg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,49,83,0.1);
}

.filterbar-reset {
  display: flex;
  align-items: center;
  gap: 6px;
  font: 500 12px var(--sans);
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px 4px;
  transition: color 0.15s;
  flex-shrink: 0;
}
.filterbar-reset:hover { color: var(--text); }

.filterbar-spacer { flex: 1; }

.filterbar-meta {
  font: 11px var(--mono);
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* ============================================================
   KARTE TAB — MAIN CONTENT
   ============================================================ */
#karte-main {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  gap: 10px;
  padding: 10px 10px 10px 0;
}

/* Map slot inside the card — fills the card height */
#map-slot-karte {
  flex: 1;
  min-height: 0;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

/* ============================================================
   RANKING PANEL
   ============================================================ */
#karte-ranking-panel {
  width: 220px;
  flex: 0 0 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,49,83,0.05);
}

.ranking-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ranking-title {
  font: 600 9.5px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.ranking-sub {
  font: 10px var(--sans);
  color: var(--text-muted);
}

.ranking-list {
  flex: 1;
  overflow-y: auto;
}

.ranking-empty {
  font: 11px var(--mono);
  color: var(--text-muted);
  padding: 14px;
}

.rs-row {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.rs-row:hover { background: var(--surface2); }
.rs-row--selected {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}

.rs-top {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
}

.rs-rank {
  font: 600 10px var(--mono);
  color: var(--text-muted);
  width: 16px;
  flex-shrink: 0;
  text-align: right;
}

.rs-id {
  font: 600 11.5px var(--mono);
  color: var(--accent);
  flex-shrink: 0;
}

.rs-name {
  font: 12px var(--sans);
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.rs-score {
  font: 600 11px var(--mono);
  color: var(--text);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.rs-bar-track {
  height: 3px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.rs-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  opacity: 0.55;
  transition: width 0.4s cubic-bezier(.16,1,.3,1);
}

.rs-tags { display: flex; gap: 4px; flex-wrap: wrap; }

.rs-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.rs-chip {
  font: 600 9px var(--mono);
  padding: 2px 5px;
  border-radius: 4px;
  letter-spacing: 0.03em;
}
.rs-chip--mob { background: rgba(0,49,83,0.08);  color: var(--accent); }
.rs-chip--ueb { background: rgba(18,133,95,0.09); color: var(--green); }
.rs-chip--ris { background: rgba(217,45,32,0.08); color: var(--red); }

/* ============================================================
   KARTE TAB — CARDS COLUMN
   ============================================================ */
#karte-cards {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 12px 20px 22px 24px;
}

/* Scope heading row */
.karte-scope-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.ksh-label {
  font: 600 9.5px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.ksh-id {
  font: 600 18px var(--mono);
  color: var(--text);
  letter-spacing: -0.01em;
}

.ksh-name {
  font: 500 14px var(--sans);
  color: var(--text-dim);
}

.ksh-wk {
  font: 600 15px var(--sans);
  color: var(--text);
  letter-spacing: -0.01em;
}

.ksh-all-note {
  font: 12px var(--sans);
  color: var(--text-muted);
}

.ksh-close {
  font-size: 20px;
  color: var(--text-dim);
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: auto;
  transition: color 0.12s, background 0.12s;
}
.ksh-close:hover { color: var(--text); background: var(--surface2); }

/* Card grid — 2-column */
.karte-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto;
  gap: 16px;
  min-width: 420px;
  align-items: start;
}

/* Card base */
.karte-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px 22px;
  box-shadow: 0 2px 10px rgba(0,49,83,0.05);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.karte-card--wide {
  grid-column: span 2;
}

#card-demo {
  min-height: 260px;
}

/* Map card — full width, fixed height, scrolls naturally with the page */
.karte-card--map {
  grid-column: span 2;
  padding: 16px 16px 12px;
  height: 340px;
}

.kc-label {
  font: 600 10px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-dim);
  text-transform: uppercase;
  flex-shrink: 0;
}

.kc-sublabel {
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.kc-placeholder {
  font: 11px var(--mono);
  color: var(--text-muted);
  padding: 16px 0;
}

.kc-empty {
  font: 12px var(--sans);
  color: var(--text-muted);
  padding: 12px 0;
}

/* ============================================================
   MAP — portable container + slots
   ============================================================ */

/* The portable div lives outside the tab panes and gets moved by JS */
#map-portable {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Slot base */
.map-slot {
  flex: 1;
  min-height: 0;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

/* Slot for other tabs — full remaining width after left panel */
.map-slot--other {
  flex: 1;
  border-radius: 0;
  border-left: 1px solid var(--border);
}

#map {
  width: 100%;
  height: 100%;
  background: #e8edf2;
}

.leaflet-control-attribution {
  background: rgba(13,21,32,0.82) !important;
  color: #5a7284 !important;
  font-family: var(--mono) !important;
  font-size: 9px !important;
  border-radius: 4px !important;
}
.leaflet-control-attribution a { color: var(--accent-mid) !important; }

.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text-dim) !important;
  border: 1px solid var(--border) !important;
  font-family: var(--mono) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--surface2) !important;
  color: var(--text) !important;
}

#map-loader {
  position: absolute;
  inset: 0;
  background: rgba(13,21,32,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  pointer-events: none;
}
.loader-ring {
  width: 24px; height: 24px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent-mid);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   PROGNOSE CARD
   ============================================================ */
.prognose-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pb-row {
  display: grid;
  grid-template-columns: 50px 1fr 52px 58px;
  align-items: center;
  gap: 10px;
}

.pb-label {
  font: 600 12.5px var(--sans);
  text-align: right;
}

.pb-track-wrap { position: relative; }

.pb-track {
  height: 18px;
  background: var(--surface2);
  border-radius: 8px;
  overflow: visible;
  position: relative;
}

.pb-fill {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  border-radius: 8px;
  opacity: 0.72;
  transition: width 0.4s cubic-bezier(.16,1,.3,1);
}

/* CI band: slightly taller, sits behind the fill */
.pb-ci-band {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 8px;
  border-radius: 4px;
  opacity: 0.2;
  pointer-events: none;
}

/* Forecast mean tick — a vertical line */
.pb-fc-tick {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 2.5px;
  border-radius: 2px;
  opacity: 0.9;
  pointer-events: none;
  transform: translateX(-50%);
}

.pb-pct {
  font: 600 12.5px var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.pb-fc-val {
  font: 500 11px var(--mono);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.prognose-meta {
  font: 11px var(--sans);
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.5;
}

.prognose-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.pl-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font: 11px var(--sans);
  color: var(--text-dim);
}

.pl-dot {
  width: 10px;
  height: 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

.pl-tick {
  width: 2.5px;
  height: 12px;
  border-radius: 2px;
  background: var(--text-dim);
  flex-shrink: 0;
}

/* ============================================================
   TURNOUT CARD
   ============================================================ */
.turnout-headline {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.turnout-val {
  font: 600 32px/1 var(--mono);
  color: var(--text);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.turnout-delta {
  font: 600 12.5px var(--mono);
  font-variant-numeric: tabular-nums;
  margin-left: 10px;
}
.turnout-delta.pos { color: var(--green); }
.turnout-delta.neg { color: var(--red); }

.turnout-sub {
  font: 11px var(--sans);
  color: var(--text-muted);
  margin-top: 3px;
}

.turnout-chart { margin-top: 4px; flex: 1; min-height: 0; overflow: visible; }
.turnout-chart svg { height: 100%; max-height: 120px; width: 100%; display: block; overflow: visible; }

/* ============================================================
   SCORES CARD
   ============================================================ */
.scores-headline {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.scores-main-label {
  font: 11.5px var(--sans);
  color: var(--text-dim);
  flex: 1;
}

.scores-main-val {
  font: 600 28px/1 var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.scores-main-bar { margin-top: 4px; }

.scores-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.scores-sub-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.scores-sub-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.scores-sub-label {
  font: 11.5px var(--sans);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 5px;
}

.score-info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font: 600 8px/1 var(--sans);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.score-info-icon:hover,
.score-info-icon.active {
  background: var(--accent-mid);
  color: var(--surface);
}

.score-info-box {
  display: none;
  font: 11px/1.5 var(--sans);
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 4px;
  grid-column: 1 / -1;
}
.score-info-box.visible {
  display: block;
}

.scores-sub-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scores-sub-track {
  flex: 1;
  height: 5px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}

.scores-sub-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(.16,1,.3,1);
}
.scores-sub-fill.negative { background: var(--red); }

.scores-sub-val {
  font: 600 11px var(--mono);
  color: var(--text);
  min-width: 24px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.scores-cat-pill {
  font: 500 9px var(--mono);
  letter-spacing: 0.05em;
  text-transform: lowercase;
  padding: 1px 5px;
  border-radius: 999px;
  border: 1px solid currentColor;
  opacity: 0.85;
  white-space: nowrap;
}
.scores-cat-pill.cat-hoch    { color: var(--green); }
.scores-cat-pill.cat-mittel  { color: var(--yellow); }
.scores-cat-pill.cat-niedrig { color: var(--red); }

.scores-gegner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.scores-gegner-label { font: 10px var(--mono); letter-spacing: 0.06em; color: var(--text-dim); }
.scores-gegner-val { font: 600 14px var(--sans); }

.scores-conf { margin-top: 10px; }

/* Aggregate (wahlkreis-level) scores */
.scores-agg-list { display: flex; flex-direction: column; gap: 10px; }
.scores-agg-row { padding: 4px 0; }
.scores-agg-top {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}
.scores-agg-id { font: 600 12.5px var(--mono); color: var(--text); }
.scores-agg-val {
  font: 600 12px var(--mono);
  color: var(--accent);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}
.scores-agg-track {
  height: 4px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}
.scores-agg-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  opacity: 0.6;
  transition: width 0.4s cubic-bezier(.16,1,.3,1);
}
.scores-agg-hint {
  font: 10.5px var(--sans);
  color: var(--text-muted);
  margin-top: 10px;
}

/* ============================================================
   DEMOGRAPHIE CARD — rich version
   ============================================================ */

/* Fallback grid (used when signal matching yields nothing) */
/* Fallback grid (used when no signals match) */
.demo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.demo-cell {
  padding: 11px 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.demo-cell-label { font: 500 11.5px var(--sans); color: var(--text-dim); line-height: 1.3; }
.demo-cell-val   { font: 600 17px/1 var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
.demo-cell-unit  { font: 500 11px var(--sans); color: var(--text-muted); }
.demo-bar-track  { height: 4px; background: var(--border); border-radius: 999px; overflow: hidden; }
.demo-bar-fill   { height: 100%; background: var(--accent-mid); border-radius: 999px; transition: width 0.4s cubic-bezier(.16,1,.3,1); }

/* ── Shared bar primitives ── */
.demo-bar-track-outer {
  height: 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.demo-bar-fill-outer {
  height: 100%;
  border-radius: 999px;
  opacity: 0.8;
  transition: width 0.45s cubic-bezier(.16,1,.3,1);
}

/* ── Age stacked bar ── */
.demo-age-bar {
  display: flex;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
  gap: 1px;
  background: var(--border);
}
.demo-age-seg {
  height: 100%;
  flex-shrink: 0;
  transition: width 0.45s cubic-bezier(.16,1,.3,1);
}
.demo-age-seg:first-child { border-radius: 6px 0 0 6px; }
.demo-age-seg:last-child  { border-radius: 0 6px 6px 0; }

/* ── Triptych layout ── */
.demo-triptych {
  display: flex;
  gap: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.demo-tp-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 4px 22px 4px 4px;
  overflow: hidden;
}
.demo-tp-panel:first-child { padding-left: 0; }
.demo-tp-panel:last-child  { padding-right: 0; }

.demo-tp-divider {
  width: 1px;
  background: var(--border);
  margin: 0 22px 0 0;
  flex-shrink: 0;
  align-self: stretch;
}

.demo-tp-title {
  font: 600 9px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 12px;
  flex-shrink: 0;
}

/* Big single value (migration total) */
.demo-tp-big-val {
  font: 600 22px/1 var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-bottom: 3px;
}
.demo-tp-desc {
  font: 11px/1.3 var(--sans);
  color: var(--text-muted);
  margin-bottom: 2px;
}

/* Row list used in alter legend + haushalt */
.demo-tp-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow: hidden;
}
.demo-tp-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}
.demo-tp-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: center;
}
.demo-tp-label {
  font: 500 11px var(--sans);
  color: var(--text-dim);
  flex: 1;
  min-width: 0;
  line-height: 1.3;
  /* allow wrapping so nothing is cut off */
  white-space: normal;
  word-break: break-word;
}
.demo-tp-val {
  font: 600 11px var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  align-self: center;
}
.demo-tp-empty {
  font: 11px var(--sans);
  color: var(--text-muted);
}

/* ============================================================
   AI INSIGHT PANEL (right)
   ============================================================ */
#karte-ai-panel {
  width: var(--ai-panel-w);
  flex: 0 0 var(--ai-panel-w);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,49,83,0.05);
}

.ai-panel-header {
  flex: 0 0 auto;
  padding: 18px 22px;
  background: var(--accent);
  border-radius: var(--card-radius) var(--card-radius) 0 0;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
}
.ai-panel-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(175,219,245,0.22), transparent 60%);
  pointer-events: none;
}

.ai-panel-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  position: relative;
}

.ai-panel-title {
  font: 600 13.5px var(--sans);
  color: #fff;
  letter-spacing: -0.01em;
  position: relative;
}
.ai-panel-sub {
  font: 11.5px/1.4 var(--sans);
  color: rgba(255,255,255,0.6);
  margin-top: 2px;
  position: relative;
}

.ai-selection-chips {
  flex: 0 0 auto;
  padding: 12px 18px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.ai-chips-label {
  font: 600 9px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 7px;
}

.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ai-chip {
  font: 500 11.5px var(--sans);
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 11px;
}

.ai-chip--scope {
  color: var(--accent);
  background: rgba(0,49,83,0.06);
  border-color: rgba(0,49,83,0.22);
}

.ai-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
}

.ai-panel-footer {
  flex: 0 0 auto;
  padding: 14px 18px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.ai-generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 13px;
  cursor: pointer;
  color: #fff;
  font: 600 13px var(--sans);
  box-shadow: 0 4px 14px rgba(0,49,83,0.28);
  transition: all 0.2s cubic-bezier(.4,0,.2,1);
}
.ai-generate-btn:hover { opacity: 0.9; }
.ai-generate-btn:disabled { cursor: default; }

.ai-panel-footnote {
  font: 10.5px var(--sans);
  letter-spacing: 0.03em;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

/* AI body states */
.ai-body-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 20px 16px;
}

.ai-idle-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.ai-idle-title {
  font: 600 14.5px var(--sans);
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.ai-idle-desc {
  font: 12.5px/1.6 var(--sans);
  color: var(--text-dim);
  max-width: 260px;
  margin: 0;
}

.ai-generating {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 20px;
  text-align: center;
}

.ai-gen-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-mid);
  border-radius: 50%;
  animation: ai-spin 0.8s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

.ai-gen-label {
  font: 600 12.5px var(--sans);
  color: var(--text);
}

.ai-gen-sub {
  font: 11px/1.5 var(--sans);
  color: var(--text-muted);
  max-width: 200px;
}

.ai-error {
  font: 12px var(--sans);
  color: var(--red);
  padding: 10px 0;
}

.ai-stream-text {
  font: 13px/1.65 var(--sans);
  color: var(--text);
  white-space: pre-wrap;
}

.ai-cursor {
  color: var(--accent);
  animation: blink 1s step-start infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.ai-section {
  margin-bottom: 16px;
}
.ai-section:last-child { margin-bottom: 0; }

.ai-section-title {
  font: 600 9px var(--mono);
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 7px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}

.ai-section-body {
  font: 12.5px/1.6 var(--sans);
  color: var(--text);
}
.ai-section-body p { margin: 0; }

.ai-list {
  margin: 0;
  padding-left: 16px;
}
.ai-list li { margin-bottom: 4px; font-size: 12.5px; }

.ai-theme-list { display: flex; flex-direction: column; gap: 7px; }
.ai-theme-card {
  padding: 9px 12px;
  background: var(--surface2);
  border-left: 2px solid var(--accent);
  border-radius: 0 8px 8px 0;
}
.ai-theme-title { font: 600 12px var(--sans); color: var(--text); margin-bottom: 3px; }
.ai-theme-reasoning { font: 11px/1.45 var(--sans); color: var(--text-dim); }

.ai-copy-block {
  font: 12.5px/1.6 var(--sans);
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

/* Headline */
.ai-headline {
  font: 600 13.5px/1.45 var(--sans);
  color: var(--text);
  padding: 12px 14px;
  background: var(--accent-dim);
  border-left: 3px solid var(--accent-mid);
  border-radius: 0 8px 8px 0;
  margin-bottom: 10px;
}

/* Confidence + tags row */
.ai-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.ai-conf-badge {
  font: 600 9.5px var(--mono);
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
}
.conf-high  { background: #d4edd4; color: #2a6a2a; }
.conf-mid   { background: #fff3cc; color: #7a5a00; }
.conf-low   { background: #fde8e8; color: #8a2020; }
.ai-tag-party {
  font: 11.5px var(--sans);
  color: var(--text-dim);
  padding: 3px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
}

/* Empfehlungen */
.ai-empfehlung {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.ai-empfehlung:last-child { margin-bottom: 0; }
.ai-empf-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.ai-empf-prio {
  font: 700 10px var(--mono);
  color: var(--surface);
  background: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.ai-empf-kanal {
  font: 600 12px var(--sans);
  color: var(--text);
}
.ai-empf-meta {
  font: 11.5px/1.45 var(--sans);
  color: var(--text-dim);
  margin-top: 6px;
  display: flex;
  gap: 5px;
}
.ai-empf-meta-label {
  font: 600 9.5px var(--mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Vermeiden */
.ai-vermeiden {
  font: 12.5px/1.5 var(--sans);
  color: #7a3a2a;
  background: #fdf0ec;
  border: 1px solid #f0c0b0;
  border-radius: 8px;
  padding: 9px 12px;
}

/* Kernbotschaft */
.ai-kernbotschaft {
  font: 600 13px/1.4 var(--sans);
  color: var(--accent);
  font-style: italic;
  margin-bottom: 8px;
}
.ai-themen-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.ai-thema-chip {
  font: 11px var(--sans);
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 9px;
}

/* Reel block */
.ai-reel-block {
  font-size: 12px;
  line-height: 1.7;
}
.ai-reel-sep {
  color: var(--text-muted);
  margin: 0 4px;
}

/* Hinweise */
.ai-hinweise {
  margin: 0;
  padding-left: 14px;
  color: var(--text-muted);
  font: 11px/1.5 var(--sans);
}
.ai-hinweise li { margin-bottom: 3px; }

/* ============================================================
   OTHER TABS — left panel layout
   ============================================================ */
#tab-other {
  flex-direction: row;
}

#left-panel {
  width: var(--left-w);
  min-width: var(--left-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  flex-shrink: 0;
}

/* Wahlen tab gets a wider left panel — 50% of viewport */
#tab-other.tab--wahlen #left-panel {
  width: 50%;
  min-width: 320px;
  max-width: 780px;
}

/* Wahlen vintage dropdown row */
.wahlen-vintage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

/* Two-section scroll container */
.wahlen-two-sections {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
}

.wahlen-section {
  padding: 14px 18px;
}

.wahlen-section-label {
  font: 600 9px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-transform: uppercase;
}

.wahlen-section-divider {
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
}

/* Wahlbeteiligung block inside sozialstruktur */
.wsoz-block {
  margin-bottom: 16px;
}
.wsoz-block:last-child { margin-bottom: 0; }

.wsoz-block-title {
  font: 600 9px var(--mono);
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.wsoz-btg-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.wsoz-btg-val {
  font: 600 22px var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.wsoz-btg-sub {
  font: 10px var(--sans);
  color: var(--text-dim);
}
.wsoz-btg-track {
  height: 5px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
}
.wsoz-btg-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(.16,1,.3,1);
}

.wahlen-loading {
  padding: 16px;
  color: var(--text-dim);
  font-size: 11px;
}

.lp-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.lp-header {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--surface);
}

.prefix-label {
  font: 600 9.5px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ============================================================
   SHARED SCORE / BADGE COMPONENTS
   ============================================================ */
.sb-tag {
  display: inline-block;
  font: 9px var(--mono);
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
}

.rank-badge {
  display: inline-block;
  font: 500 10px var(--mono);
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
  flex-shrink: 0;
}
.rank-badge.rank-top {
  color: var(--accent);
  border-color: rgba(0,49,83,0.35);
  background: var(--accent-dim);
}

.confidence-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: 10px var(--mono);
  text-transform: capitalize;
}
.confidence-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}
.confidence-pill.conf-hoch .confidence-dot   { background: var(--green); }
.confidence-pill.conf-mittel .confidence-dot { background: var(--yellow); }
.confidence-pill.conf-niedrig .confidence-dot{ background: var(--red); }
.confidence-pill.conf-hoch   { color: var(--green); }
.confidence-pill.conf-mittel { color: var(--yellow); }
.confidence-pill.conf-niedrig{ color: var(--red); }

/* mini bar used in prio & other tabs */
.mini-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mini-bar-track {
  flex: 1;
  height: 5px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.mini-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}
.mini-bar-fill.negative { background: var(--red); }
.mini-bar-value {
  font: 10px var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 30px;
  text-align: right;
}
.mini-bar-empty { color: var(--text-muted); font-size: 11px; }

/* ============================================================
   PLACEHOLDER BANNER (shared)
   ============================================================ */
.placeholder-banner {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 2px solid var(--text-muted);
  padding: 12px 16px;
  border-radius: 8px;
  margin: 12px 16px;
}
.placeholder-title {
  font: 600 9.5px var(--mono);
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.placeholder-status { color: var(--text-muted); }
.placeholder-body { font: 11px/1.6 var(--sans); color: var(--text-dim); }
.rohdaten-banner { border-left-color: var(--yellow); margin-bottom: 0; }

/* ============================================================
   WAHLEN TAB
   ============================================================ */
#wahlen-content {
  overflow-y: auto;
  flex: 1;
  padding: 16px;
}

.election-year-block { margin-bottom: 24px; }
.election-year-header {
  font: 9.5px var(--mono);
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.party-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.party-name {
  font: 11px var(--sans);
  width: 52px;
  flex-shrink: 0;
  text-align: right;
  font-weight: 600;
}
.bar-group { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.bar-track {
  height: 6px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.bar-fill { height: 100%; border-radius: 2px; transition: width 0.4s ease; }
.bar-pct { font: 11px var(--mono); color: var(--text); width: 42px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.bar-delta { font: 10px var(--mono); width: 36px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.bar-delta.pos { color: var(--green); }
.bar-delta.neg { color: var(--red); }
.turnout-divider { margin: 8px 0; border: none; border-top: 1px solid var(--border); }
.bar-legend { display: flex; gap: 16px; margin-top: 8px; font: 10px var(--sans); color: var(--text-dim); }
.legend-dot { display: inline-block; width: 8px; height: 2px; border-radius: 1px; vertical-align: middle; margin-right: 4px; }

.toggle-btn {
  font: 10px var(--mono);
  letter-spacing: 0.08em;
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 6px;
  transition: color 0.12s, border-color 0.12s;
}
.toggle-btn:hover { color: var(--text); border-color: var(--accent); }

/* Forecast section (used in Wahlen tab) */
.forecast-section {
  padding: 14px 0 6px;
  border-top: 1px solid var(--border);
  margin-bottom: 16px;
}
.forecast-ci-badge {
  display: inline-block;
  font: 8px var(--mono);
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}
.forecast-erst-grid { display: flex; flex-direction: column; gap: 0; margin-top: 8px; }
.forecast-erst-row {
  display: grid;
  grid-template-columns: 38px 44px 1fr;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  gap: 6px;
  opacity: 0.5;
}
.forecast-erst-row:last-child { border-bottom: none; }
.forecast-erst-row.is-main, .forecast-erst-row.is-rival { opacity: 1; }
.forecast-erst-label { font: 500 10px var(--mono); }
.forecast-erst-mean { font: 11px var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.forecast-erst-ci { font: 9px var(--mono); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.rp-section-title {
  font: 600 9.5px var(--mono);
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   DATENRAUM TAB
   ============================================================ */
.datenraum-seg {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.seg-btn {
  font: 500 9.5px var(--mono);
  letter-spacing: 0.09em;
  color: var(--text-dim);
  padding: 10px 16px;
  border-bottom: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { color: var(--text); border-bottom-color: var(--accent); }

.datenraum-search-row {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.datenraum-search-row input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 6px 10px;
  font: 11px var(--sans);
  border-radius: 8px;
  color: var(--text);
  transition: border-color 0.15s;
}
.datenraum-search-row input:focus { border-color: var(--accent); }

#datenraum-content { overflow-y: auto; flex: 1; }

.datenraum-section { border-bottom: 1px solid var(--border); }
.datenraum-section-header {
  font: 9.5px var(--mono);
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 9px 16px;
  background: var(--surface2);
}
.datenraum-row {
  display: grid;
  grid-template-columns: 1fr 80px 60px 80px;
  padding: 5px 16px;
  font: 10px var(--mono);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  align-items: center;
}
.datenraum-row:last-child { border-bottom: none; }
.datenraum-row .dr-label { color: var(--text); font-size: 11px; font-family: var(--sans); }
.datenraum-row .dr-value { color: var(--accent); text-align: right; font-weight: 600; }
.datenraum-row .dr-unit  { color: var(--text-muted); font-size: 9px; }
.datenraum-row .dr-id    { color: var(--text-muted); font-size: 9px; overflow: hidden; text-overflow: ellipsis; }

.datenraum-kv { padding: 12px 16px; }
.datenraum-kv-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font: 11px var(--sans);
  gap: 12px;
}
.datenraum-kv-row:last-child { border-bottom: none; }
.dkv-key { color: var(--text-dim); font: 10px var(--mono); }
.dkv-val { color: var(--text); text-align: right; }
.dkv-warn { color: var(--yellow); }
.dkv-ok   { color: var(--green); }