/* ---------------------------------------------------------------------------
   main.css — All theming in one place. Colours are CSS variables so the chart
   (which references --series-color) and UI stay visually consistent.
   --------------------------------------------------------------------------- */

:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2330;
  --border: #2a3340;
  --border-soft: #222a35;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --text-faint: #66727f;
  --accent: #2dd4bf;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --danger: #f87171;
  --ok: #34d399;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #16202c 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Header / footer ----------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px 26px;
  flex-wrap: nowrap; /* eine Zeile → der Titel verkürzt (Ellipse), statt umzubrechen */
  padding: 12px 24px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
}
/* Erst auf Smartphone-Breite umbrechen/stapeln (sonst Ellipse statt Umbruch). */
@media (max-width: 640px) { .app-header { flex-wrap: wrap; } }
/* Sprungziele unter dem klebenden Header freihalten (scrollIntoView lässt Platz). */
html { scroll-padding-top: 104px; }
/* flex: 0 1 auto + min-width: 0 → der Titel verkürzt (Ellipse), bevor der Header umbricht. */
/* Die Marke (Emoji + Titel) scrollt nach oben — als Button erreichbar (cursor/focus). */
.brand { display: flex; align-items: center; gap: 11px; flex: 0 1 auto; min-width: 0; cursor: pointer; }
.brand > div { min-width: 0; }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 8px; }
.brand-mark { font-size: 38px; flex: none; filter: drop-shadow(0 2px 8px rgba(247, 113, 113, 0.4)); transition: transform 0.15s; }
.brand:hover .brand-mark { transform: scale(1.08); }
.app-header h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color 0.15s; }
.brand:hover h1 { color: #fff; }

.btn-reset {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-reset:hover { color: var(--text); border-color: var(--text-dim); }
/* real/nominal-Umschalter über „Zurücksetzen" — global, da er die ganze Rechnung betrifft. */
.header-actions { display: flex; flex-direction: column; align-items: stretch; gap: 8px; flex: none; }
/* Umschalter + Aktionspaare (Reset/Oben, Export/Import) untereinander, alle gleich breit → 2×3-Raster. */
.action-row { display: flex; gap: 8px; }
.action-row .btn-reset { flex: 1 1 0; text-align: center; white-space: nowrap; }
.header-actions .seg-group { display: flex; }
.header-actions .seg { flex: 1 1 0; text-align: center; }

.app-footer {
  padding: 18px 28px 28px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}
.app-footer strong { color: var(--text-dim); }
.app-footer p { margin: 0; }
.footer-brand { margin-top: 6px; }
.app-footer a { color: var(--accent); text-decoration: none; }
.app-footer a:hover, .app-footer a:focus { text-decoration: underline; }
.footer-note { margin-top: 4px; color: var(--text-faint); }

/* --- Layout -------------------------------------------------------------- */
.layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 22px;
  max-width: 1520px;
  margin: 0 auto;
}
.top-grid {
  display: grid;
  grid-template-columns: 268px 1fr; /* Eckdaten schmal → mehr Breite für den Chart */
  gap: 16px;
  align-items: stretch; /* Eckdaten-Panel und Chart-Box gleich hoch (nach dem höheren) */
  /* Oberer Bereich (Eckdaten + Chart) füllt den Viewport unter dem klebenden Header.
     Statischer Fallback; JS (syncLayout) setzt die EXAKTE Höhe = innerHeight − Header −
     padding/Luft → konsistent über Auflösungen/Geräte (reagiert auch auf mobile Browser-Chrome). */
  min-height: calc(100vh - 131px);
}
/* Eckdaten (nur im linken #controls-Panel): einspaltig + einzeilige Felder.
   Feste Input- UND Einheiten-Spalte → alle Eingaben bündig (unabhängig von Label-/Einheit-Länge). */
#controls .field-grid { grid-template-columns: 1fr; }
/* Zwei aufeinanderfolgende Feld-Gruppen (z.B. Szenarien-Anteile + „Dynamik bis")
   sollen denselben Abstand haben wie Felder INNERHALB einer Gruppe (row-gap 7px),
   sonst kleben die Boxen über die Grid-Grenze hinweg aneinander (0px-Lücke). */
#controls .field-grid + .field-grid { margin-top: 7px; }
/* Segment (z.B. Depotsteuer) gefolgt von einem Feld (Margin): sonst kleben sie aneinander. */
#controls .kv-seg + .field-grid { margin-top: 11px; }
#controls .field-grid .field {
  grid-template-columns: 1fr 80px 26px;
  grid-template-areas: 'label input unit';
  gap: 0 6px;
}
#controls .field-grid .field-unit { text-align: left; white-space: nowrap; }
.field-subhead {
  display: flex; align-items: center; gap: 4px;
  margin: 11px 0 5px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-faint);
}
@media (max-width: 900px) { .top-grid { grid-template-columns: 1fr; } }

/* Lower area: vehicle & pension cards in three columns (Gemeinsam/Person A/Person B). */
.vehicles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 1100px) { .vehicles { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px) { .vehicles { grid-template-columns: 1fr; } }

/* Compact 2-up field grid: label + unit on top, input below. */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 10px; }
.field-grid .field { /* 2-zeilig (Default, z.B. Eckdaten): Label+Einheit oben, Input unten — lange Labels werden nicht abgeschnitten */
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'label unit' 'input input';
  gap: 1px 4px;
  margin: 0;
  align-items: center;
}
.veh-card .field-grid .field { /* 1-zeilig in den Vehikel-Karten (kompakt, kurze Labels) */
  grid-template-columns: 1fr 86px auto;
  grid-template-areas: 'label input unit';
  gap: 0 5px;
}
.field-grid .field-label { grid-area: label; font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-grid .field-unit { grid-area: unit; font-size: 10px; }
.field-grid .field input[type='number'], .field-grid .field input[type='text'] { grid-area: input; width: 100%; padding: 5px 7px; font-size: 12.5px; }
.field-grid .info { width: 13px; height: 13px; font-size: 8.5px; margin-left: 3px; }

/* --- Control panel ------------------------------------------------------- */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 4px 14px 12px;
  box-shadow: var(--shadow);
}
/* Linke Schiene als Flex-Spalte: Eckdaten oben, Export/Import darunter,
   die beiden Sprung-Links unten an den Boden geheftet (→ bündig mit der Chart-Unterkante). */
.side-rail { display: flex; flex-direction: column; }

/* Eckdaten-Reiter: die Control-Gruppen liegen auf Tabs, damit die Leiste in den
   Viewport passt (nur eine Gruppe sichtbar). */
.rail-tabs { display: flex; gap: 4px; margin-bottom: 4px; }
.rail-tab {
  flex: 1 1 0; min-width: 0; padding: 6px 4px; border: 1px solid var(--border-soft);
  background: var(--bg-elev-2); color: var(--text-dim); border-radius: 8px;
  font-size: 11.5px; font-weight: 600; cursor: pointer; transition: all 0.12s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rail-tab:hover { color: var(--text); border-color: var(--border); }
.rail-tab--active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.rail-tabpanel { display: flex; flex-direction: column; }
.rail-tabpanel .control-group:first-child { padding-top: 4px; }
/* Erläuterungstext am Fuß eines Tabs (nutzt den freien Platz in der Leiste). Kein
   eigener Rahmen — die border-bottom der darüberliegenden Gruppe ist der Trenner
   (sonst doppelte Linie). */
.rail-note {
  margin: 12px 2px 2px;
  font-size: 11.5px; line-height: 1.48; color: var(--text-faint);
}
/* Veranlagung: drei Optionen → bei Bedarf umbrechen statt überquellen. */
.kv-seg--wrap { flex-wrap: wrap; }
/* Export/Import + Sprung-Links bilden EINEN Block am unteren Rand der Schiene:
   das auto-Margin sitzt ÜBER Export/Import, der freie Platz fällt also zwischen
   Eckdaten-Inhalt und diesen Block — nicht zwischen die beiden Button-Reihen. */
.rail-extras { display: flex; gap: 8px; margin-top: auto; }
.rail-extras .btn-reset { flex: 1 1 0; text-align: center; }
/* Zwei Sprung-Links nebeneinander (spart vertikalen Platz, damit die Schiene in
   den Viewport passt); der dekorative ↓-Pfeil entfällt im schmalen Zwei-Spalter. */
.rail-nav { display: flex; gap: 8px; margin-top: 8px; }
.rail-nav .more-settings { margin: 0; flex: 1 1 0; min-width: 0; justify-content: center; }
.rail-nav .more-settings .ms-label { min-width: 0; overflow: hidden; }
.rail-nav .more-settings-arrow, .rail-nav .more-settings .ms-icon { display: none; }
.control-group { padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.control-group:last-child { border-bottom: none; }
.control-group h3 {
  margin: 0 0 9px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.hint { margin: 8px 0 0; font-size: 11px; color: var(--text-faint); line-height: 1.4; }
.more-settings {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; margin: 12px 0 0; padding: 9px 11px;
  font: inherit; font-size: 12px; font-weight: 600; text-align: left; cursor: pointer;
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid var(--border); border-radius: 8px;
  transition: border-color .15s, background .15s;
}
.more-settings:hover, .more-settings:focus { border-color: var(--accent); outline: none; }
.more-settings-arrow { font-size: 14px; line-height: 1; animation: more-settings-bob 1.6s ease-in-out infinite; }
@keyframes more-settings-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) { .more-settings-arrow { animation: none; } }
.ms-label { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.ms-icon { width: 15px; height: 15px; flex: none; }

/* Each person-group is a card-column inside the 3-col .vehicles grid. */
.person-group {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 13px 14px;
  box-shadow: var(--shadow);
  border-bottom: 1px solid var(--border-soft);
}
.person-group h3 { margin-bottom: 11px; }

/* --- (i) info tooltip ---------------------------------------------------- */
.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: 6px; vertical-align: middle;
  border: 1px solid var(--border); border-radius: 50%;
  font-size: 9.5px; font-style: normal; font-weight: 700; line-height: 1;
  color: var(--text-faint); cursor: help; user-select: none;
  position: relative; transition: color 0.15s, border-color 0.15s;
}
.info:hover, .info:focus { color: var(--accent); border-color: var(--accent); outline: none; }

/* The tooltip itself is a single JS-managed element (tooltip.js) so it can be
   clamped to the viewport — no CSS ::after that overflows at the screen edges. */
.tooltip-pop {
  display: none; position: fixed; z-index: 100;
  max-width: 260px; background: #05080c; color: var(--text); text-align: left;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font-size: 12px; font-weight: 400; line-height: 1.45;
  box-shadow: var(--shadow); pointer-events: none;
}

/* --- Stresstest presets -------------------------------------------------- */
.preset-row { display: flex; flex-wrap: wrap; gap: 7px; }
.btn-preset {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 999px; padding: 6px 12px;
  font-size: 12.5px; cursor: pointer; transition: all 0.14s;
}
.btn-preset:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-preset--active {
  border-color: var(--accent); color: #0b0f14; background: var(--accent); font-weight: 600;
}
.btn-preset--active:hover { color: #0b0f14; background: var(--accent); }

/* Grid keeps every input box on the same vertical line, regardless of label width. */
.field { display: grid; grid-template-columns: 1fr 112px 24px; align-items: center; gap: 10px; margin-bottom: 9px; }
.field-label { font-size: 13.5px; color: var(--text-dim); }
.field input[type='number'], .field input[type='text'] { width: 100%; }
.field input[type='text'] { text-align: right; } /* money inputs align like the numbers */
.field-unit { color: var(--text-faint); font-size: 12px; text-align: left; }

input[type='number'], input[type='text'] {
  color-scheme: dark; /* native Spin-Buttons (hoch/runter) hell rendern statt schwarz-auf-dunkel */
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 9px;
  font-size: 13.5px;
  font-family: var(--font);
  width: 108px;
  text-align: right;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type='text'] { text-align: left; }
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type='number']::-webkit-inner-spin-button { opacity: 0.75; }

/* --- Person grouping ----------------------------------------------------- */
.person-group h3 { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.person-note { font-size: 11px; text-transform: none; letter-spacing: normal; color: var(--text-faint); font-weight: 400; }
.person-head .person-name-input {
  background: transparent; border: none; border-bottom: 1px dashed var(--border-soft);
  color: var(--text-dim); font: inherit; font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; padding: 0 1px 1px; width: 9ch; min-width: 6ch; text-align: left;
}
.person-head .person-name-input:hover { border-bottom-color: var(--border); }
.person-head .person-name-input:focus { outline: none; border-bottom-color: var(--accent); color: var(--text); }
.person-head .person-birth-input {
  background: var(--bg-elev-2); border: 1px solid var(--border-soft); border-radius: 4px;
  color: var(--text-dim); font: inherit; font-size: 11px; width: 6ch; padding: 1px 2px; margin: 0 1px; text-align: left;
}
.person-head .person-birth-input:focus { outline: none; border-color: var(--accent); }
.kv-card .veh-head { display: flex; align-items: center; justify-content: space-between; }
.kv-seg { display: inline-flex; gap: 2px; background: var(--bg-elev-2); border: 1px solid var(--border-soft); border-radius: 7px; padding: 2px; }
.kv-opt { background: transparent; border: none; color: var(--text-dim); font-size: 11px; font-weight: 600; padding: 2px 10px; border-radius: 5px; cursor: pointer; transition: all 0.12s; }
.kv-opt:hover { color: var(--text); }
.kv-opt--active { background: var(--accent); color: #0b0f14; }
.kv-opt--active:hover { color: #0b0f14; }

/* Haushalt → Kinder: Stepper (−/Anzahl/+) + Geburtsjahr-Liste. */
.kid-stepper { display: flex; align-items: center; gap: 8px; margin: 2px 0 4px; }
.step-btn { width: 26px; height: 26px; padding: 0; line-height: 1; font-size: 16px; font-weight: 700;
  background: var(--bg-elev-2); color: var(--text-dim); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; transition: all 0.12s; }
.step-btn:hover { color: var(--text); border-color: var(--accent); }
.kid-count { min-width: 18px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }
.kid-unit { color: var(--text-faint); font-size: 12px; }
.kid-years { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 2px; }
.kid-year { width: 58px; padding: 4px 6px; font-size: 12px; text-align: center;
  background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border-soft); border-radius: 6px; }
.kid-year:focus { outline: none; border-color: var(--accent); }
.payout-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 10px; }
/* Auszahlung + Ziel nebeneinander: Label je ÜBER dem Schalter → beide Schalter
   passen auch in schmalen Karten auf eine Zeile (kein Umbruch). */
.payout-dual { display: flex; align-items: flex-start; gap: 14px; margin: 2px 0 12px; flex-wrap: nowrap; }
.payout-col { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.payout-col .kv-seg { width: 100%; }
.payout-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); }
.kv-row { display: flex; gap: 14px; align-items: center; }
.kv-row > .field-grid { flex: 1; min-width: 0; grid-template-columns: 1fr; }
.kv-row .toggle { white-space: nowrap; margin-bottom: 0; }
/* KV-Feld einzeilig (Label · Eingabe · €), damit es mit dem Schalter auf einer Höhe sitzt. */
.kv-row .field { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: 'label input unit'; align-items: center; gap: 0 6px; }
.kv-row .field-label { white-space: nowrap; }

/* --- Vehicle cards ------------------------------------------------------- */
.veh-card {
  background: var(--bg-elev-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 9px 10px; margin-bottom: 9px;
}
.veh-card:last-child { margin-bottom: 0; }
.veh-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; cursor: default; }
.veh-head--toggle { cursor: pointer; }
.veh-head .toggle { margin-bottom: 0; }  /* im Kopf vertikal zentrieren (sonst ~6px nach oben versetzt) */
.veh-name { font-size: 13px; font-weight: 600; flex: 1; }
.veh-tag {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px;
}
.veh-card--linked { } /* (kein Sonder-Rahmen mehr — alle Vehikel-Karten einheitlich) */
.veh-hint { margin: 7px 0 2px; font-size: 11px; color: var(--text-faint); line-height: 1.35; }
.veh-card--off { opacity: 0.5; }
.lev-block { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--border-soft); }
.lev-toggle { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.lev-toggle-label { font-size: 12.5px; color: var(--text-dim); }
.lev-block--on { margin-bottom: 0; }
.lev-block .field { margin-top: 9px; }
.lev-eff { margin: 8px 0 0; }
.veh-card--off .field { pointer-events: none; }
.veh-card--off .veh-head--toggle { pointer-events: auto; opacity: 1; }
.veh-card .field:last-child { margin-bottom: 0; }
.switch { display: inline-flex; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

/* --- Segmented real/nominal toggle --------------------------------------- */
.seg-group { display: inline-flex; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg {
  background: transparent; border: none; color: var(--text-dim); white-space: nowrap;
  padding: 5px 11px; font-size: 12.5px; border-radius: 6px; cursor: pointer; transition: all 0.14s;
}
.seg--active { background: var(--accent); color: #08110f; font-weight: 600; }

/* --- Scenario rows ------------------------------------------------------- */
.scn-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.scn-label { flex: 1; min-width: 0; padding: 6px 8px; font-size: 13px; }
.scn-amount { width: 84px; }
.scn-unit { color: var(--text-faint); font-size: 12px; }
.stream-fixed { font-size: 12px; color: var(--text-faint); align-self: center; white-space: nowrap; }

/* --- Income / lump rows -------------------------------------------------- */
.stream-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 0; transition: opacity 0.15s;
  border-top: 1px solid var(--border-soft);
}
.stream-row:first-of-type { border-top: none; }
.stream-row--off { opacity: 0.5; }
.stream-toggle { margin-top: 2px; }
.stream-body { flex: 1; min-width: 0; }
.stream-label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text); }
.stream-fields { display: flex; gap: 14px; }
.mini-field { display: inline-flex; align-items: center; gap: 5px; }
.mini-suffix { font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.mini-num { width: 78px; padding: 5px 7px; font-size: 12.5px; }

/* --- Toggle switches ----------------------------------------------------- */
.toggle { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; cursor: pointer; }
.toggle-label { font-size: 13.5px; color: var(--text-dim); }
.toggle input, .stream-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider {
  position: relative; width: 38px; height: 22px; background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: 999px; flex: none; transition: background 0.15s;
}
.slider::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  background: var(--text-dim); border-radius: 50%; transition: transform 0.16s, background 0.16s;
}
.slider--sm { width: 32px; height: 19px; }
.slider--sm::after { width: 13px; height: 13px; }
input:checked + .slider, .stream-toggle input:checked + .slider {
  background: var(--accent); border-color: var(--accent);
}
input:checked + .slider::after { transform: translateX(16px); background: #0b0f14; }
.slider--sm + ::after { }
input:checked + .slider--sm::after { transform: translateX(13px); }
.stream-toggle { display: inline-flex; cursor: pointer; }

/* --- Stage (right column) ------------------------------------------------ */
.stage { display: flex; flex-direction: column; gap: 18px; }
.stage > .chart-card { flex: 1; } /* Chart-Box füllt die (gestreckte) Höhe */

/* KPIs are inline header stats (Basisfall / +Hausverkauf / Ohne vvGmbH). */
.kpis { display: flex; flex: 1 1 auto; justify-content: flex-end; gap: 0; min-width: 0; flex-wrap: wrap; }
.kpi {
  display: flex; flex-direction: column; justify-content: center;
  padding: 2px 18px; border-left: 1px solid var(--border-soft);
}
.kpi:first-child { border-left: none; }
.kpi--primary { box-shadow: inset 2px 0 0 var(--accent); }
.kpi--erbe { box-shadow: inset 2px 0 0 #c084fc; }
.kpi--erbe .kpi-reach-big { color: #c084fc; }
.kpi--house { box-shadow: inset 2px 0 0 #34d399; }
.kpi--house .kpi-reach-big { color: #34d399; }
.kpi-title { order: 1; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); display: flex; align-items: center; }
.kpi-reach { display: contents; }
.kpi-reach-big { order: 2; font-size: 20px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; margin-top: 1px; }
.kpi--primary .kpi-reach-big { color: var(--accent); }
.kpi-value { order: 3; font-size: 11px; color: var(--text-dim); margin-top: 1px; }
.kpi-reach-sub { order: 4; font-size: 10.5px; color: var(--text-faint); }
@media (max-width: 1000px) { .kpis { justify-content: flex-start; } }
/* Smartphone: die vier Kacheln als kompaktes 2×2-Raster statt unregelmäßigem Umbruch.
   .kpi-value (Beschreibung) und .kpi-reach-sub (Reichweite-Detail) entfallen — jede Kachel
   bleibt ein knapper Zweizeiler (Titel + Headline). Spart maximal vertikalen Platz. */
@media (max-width: 640px) {
  .kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 0; flex: 1 1 100%; width: 100%; }
  .kpi { padding: 3px 12px; }
  .kpi:nth-child(odd) { border-left: none; }
  .kpi-value, .kpi-reach-sub { display: none; }
  .kpi-title { font-size: 9.5px; }
  .kpi-reach-big { font-size: 18px; }
  /* Umschalter + Reset/Oben in EINER Zeile (volle Breite, je 50 %) statt gestapelt. */
  .header-actions { flex-direction: row; align-items: center; flex-wrap: nowrap; gap: 6px; flex: 1 1 100%; }
  .header-actions .seg-group, .header-actions .action-row { flex: 1 1 0; min-width: 0; }
  .header-actions .seg, .header-actions .btn-reset { font-size: 12px; padding-left: 9px; padding-right: 9px; }
}

/* Erst wenn Marke + vier KPI-Kacheln + Aktionen NICHT mehr in eine Zeile passen
   (~1380px; die „150k"-Reihe mit Reichweite-Untertiteln ist mit ~768px am breitesten),
   bekommt der KPI-Streifen eine eigene volle Zeile unter Marke + Aktionen. Darüber
   bleibt alles einzeilig (nowrap; der Titel kürzt notfalls per Ellipse). */
@media (max-width: 1380px) {
  .app-header { flex-wrap: wrap; }
  .header-actions { margin-left: auto; }
  .kpis { order: 1; flex-basis: 100%; justify-content: flex-start; }
  html { scroll-padding-top: 180px; }
}
/* Im mittleren Band stehen die Aktionen in EINER kompakten Zeile (Umschalter +
   Buttons nebeneinander) → Zeile 1 bleibt flach, der KPI-Streifen sitzt knapp
   darunter. Auf dem Smartphone (≤640px) stapeln sie wieder (eigener Block unten). */
@media (min-width: 641px) and (max-width: 1380px) {
  .header-actions { flex-direction: row; align-items: center; }
}

/* --- Chart card ---------------------------------------------------------- */
.chart-card {
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 18px 20px 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; /* SVG füllt die Resthöhe (Viewport-füllend) */
}
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.chart-head h2 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }
.chart-sub { margin: 3px 0 10px; font-size: 12.5px; color: var(--text-faint); }
/* SORR-Stresstest-Umschalter + Erfolgs-Badge (rechts im Chart-Kopf). */
/* Button oben, SORR-Ergebnistext einzeilig direkt darunter (rechtsbündig). */
.chart-head-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
#sorr-toggle { border: 1px solid var(--border); }
#sorr-toggle:hover { color: var(--text); border-color: var(--text-dim); }
#sorr-toggle[aria-pressed="true"] { background: var(--accent); color: #08110f; font-weight: 600; border-color: var(--accent); }
.sorr-badge { font-size: 12px; color: var(--text-dim); text-align: right; white-space: nowrap; }
.sorr-badge strong { color: var(--accent); font-variant-numeric: tabular-nums; }
/* flex-basis 0 → der SVG füllt die Resthöhe der Karte, statt mit seiner intrinsischen
   (viewBox-)Aspekthöhe die Karte über die Fold-Höhe hinaus aufzublähen. */
.chart { width: 100%; flex: 1 1 0; min-height: 320px; display: block; }

/* --- Chart SVG internals ------------------------------------------------- */
.grid-line { stroke: var(--border-soft); stroke-width: 1; }
.grid-line--v { stroke-dasharray: 2 5; opacity: 0.6; }
.grid-zero { stroke: var(--border); stroke-width: 1.5; }
.event-line { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 2 4; opacity: 0.3; }
.event-label { fill: var(--text-dim); font-size: 8.5px; opacity: 0.85; font-family: var(--font); }

/* --- Cashflow-Tabelle (ganze Breite, nominal) ---------------------------- */
.cashflow-card { background: var(--bg-elev); border: 1px solid var(--border-soft); border-radius: 14px; padding: 18px 20px 8px; }
.cf-head h2 { font-size: 16px; margin: 0 0 2px; }
.cf-scroll { overflow-x: auto; margin-top: 12px; }
.cf-table { width: 100%; border-collapse: collapse; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.cf-table th, .cf-table td { padding: 3px 9px; text-align: right; white-space: nowrap; }
.cf-table thead th { color: var(--text-dim); font-weight: 600; border-bottom: 1px solid var(--border); }
.cf-grp { text-align: center !important; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; padding-bottom: 1px !important; }
.cf-ein { color: var(--accent); }
.cf-sonst { color: #c084fc; } /* Sonstige Zuflüsse (Erbe, Hausverkauf) */
.cf-aus { color: #7fd1c3; }  /* laufende Einnahmen (Renten, Barista, bAV) */
.cf-ent { color: #f0a868; }  /* Entnahmen (aus vvGmbH / Privatdepot) */
.cf-saldog { color: #93a4b8; } /* Saldo-Gruppe (Topfstände Jahresende) */
.cf-saldo { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.cf-yr { text-align: left !important; color: var(--text-dim); }
.cf-sep { border-left: 1px solid var(--border); }
.cf-z { color: var(--text-faint); }
.cf-anspar .cf-yr:first-child { box-shadow: inset 3px 0 0 var(--accent); }            /* Ansparphase (teal) */
.cf-barista .cf-yr:first-child { box-shadow: inset 3px 0 0 #e0c44c; }                  /* Barista-Brücke (gelb) */
.cf-rente .cf-yr:first-child { box-shadow: inset 3px 0 0 rgba(240, 168, 104, 0.85); }  /* Vollrente (orange) */
.cf-net { font-weight: 600; color: var(--text) !important; }
.cf-table tbody tr:hover td { background: var(--bg-elev-2); }
.tick { fill: var(--text-faint); font-size: 11px; font-family: var(--font); }
.tick-y { text-anchor: end; }
.tick-x { text-anchor: middle; }
.axis-title { fill: var(--text-faint); font-size: 11.5px; text-anchor: middle; font-family: var(--font); }

.series-line { fill: none; stroke: var(--series-color); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; opacity: 0.75; }
.series-area { fill: var(--series-color); opacity: 0.12; }
.series--highlight .series-line { stroke-width: 3.5; opacity: 1; }
.series--overlay .series-line { stroke-dasharray: 6 4; opacity: 0.9; }
.series--overlay .series-area { display: none; }
.series-dot { fill: var(--series-color); stroke: var(--bg-elev); stroke-width: 2; }
.series-dot--ok { fill: var(--ok); }
.series-marker-label { fill: var(--text); font-size: 12px; font-weight: 650; text-anchor: middle; font-family: var(--font); }
.series--highlight .series-marker-label { font-size: 13px; }
/* SORR-Fächer: leiser p10–p90-Kontext + kräftiger p25–p75-Korridor + Median (gestrichelt),
   in der Szenario-Farbe. Fokus aufs Mittelfeld, nicht auf die Tails. */
.fan-band-outer { fill: var(--fan-color, var(--accent)); opacity: 0.07; }
.fan-band { fill: var(--fan-color, var(--accent)); opacity: 0.2; }
.fan-median { fill: none; stroke: var(--fan-color, var(--accent)); stroke-width: 2.5; stroke-dasharray: 7 4; opacity: 0.95; }
/* Im SORR-Modus keine Linien-Flächenfüllung (würde den Fächer als 3. Schicht überlagern). */
.has-fan .series-area { display: none; }

/* --- Legend -------------------------------------------------------------- */
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.legend-item {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-elev-2); border: 1px solid var(--border-soft);
  border-radius: 999px; padding: 6px 13px 6px 10px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.legend-item:hover { border-color: var(--border); }
.legend-item--active { border-color: var(--accent); background: var(--accent-soft); }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend-swatch--dash { height: 3px; align-self: center; }
.legend-item--overlay { cursor: default; opacity: 0.9; }
.legend-text { display: flex; flex-direction: column; line-height: 1.25; }
.legend-name { font-size: 13px; color: var(--text); font-weight: 500; }
.legend-sub { font-size: 11.5px; color: var(--text-dim); }
.legend-item--active .legend-name,
.legend-item--active .legend-sub { color: var(--text); }

/* --- Theme-Variante: ein ungewöhnlich kinderreicher Haushalt (ein Dutzend plus
   fünf) lässt das UI in moorige Grüntöne kippen. Rein kosmetischer Variablen-
   Override über ein data-Attribut — keinerlei Rechen-Logik betroffen. Layer um
   Layer, wie bei einer Zwiebel. -------------------------------------------------- */
body[data-theme="swamp"] {
  --bg: #18230f;
  --bg-elev: #1f2e12;
  --bg-elev-2: #28391a;
  --border: #3e5424;
  --border-soft: #324419;
  --text: #edf4da;
  --text-dim: #aec08c;
  --text-faint: #7c8f56;
  --accent: #8bc34a;
  --accent-soft: rgba(139, 195, 74, 0.16);
  --ok: #9ccc65;
  --danger: #cd8a3a;
  background: radial-gradient(1100px 560px at 80% -10%, #33491d 0%, var(--bg) 55%);
}
body[data-theme="swamp"] .brand-mark { filter: drop-shadow(0 2px 9px rgba(139, 195, 74, 0.5)); }
