/* Farbrollen nach validierter Palette; Dunkelmodus als eigene Stufen, nicht als Umkehrung. */
:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --plane: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;          /* Reihe 1 */
  --s2: #eb6834;          /* Reihe 2 */
  --pos: #2a78d6;         /* divergierendes Paar: Zufluss */
  --neg: #e34948;         /* divergierendes Paar: Abfluss */
  --mid: #f0efec;
  --good: #006300;
  --critical: #d03b3b;
  --warning: #fab219;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface: #1a1a19;
    --plane: #0d0d0d;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5;
    --s2: #d95926;
    --pos: #3987e5;
    --neg: #e66767;
    --mid: #383835;
    --good: #0ca30c;
    --critical: #d03b3b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a19;
  --plane: #0d0d0d;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --s1: #3987e5;
  --s2: #d95926;
  --pos: #3987e5;
  --neg: #e66767;
  --mid: #383835;
  --good: #0ca30c;
  --critical: #d03b3b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--s1); }

/* --- Kopfzeile ---------------------------------------------------------- */

header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.kopf {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 16px;
}

.kopf h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 650;
  white-space: nowrap;
}

.kopf .luecke { flex: 1; }

#name {
  font-size: 15px;
  font-weight: 600;
  min-width: 220px;
  flex: 1 1 220px;
}

/* --- Kennzahlenleiste --------------------------------------------------- */

.kennzahlen {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--border);
  border-top: 1px solid var(--border);
}

.kachel {
  background: var(--surface);
  padding: 8px 14px 10px;
}

.kachel .beschriftung {
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.kachel .wert {
  font-size: 21px;
  font-weight: 620;
  margin-top: 2px;
  color: var(--ink);
}

.kachel .zusatz {
  font-size: 12px;
  color: var(--ink-2);
}

.kachel .wert.gut { color: var(--good); }
.kachel .wert.schlecht { color: var(--critical); }

/* --- Grundraster -------------------------------------------------------- */

main {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}

.spalte { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.karte {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.karte > h2 {
  font-size: 13px;
  font-weight: 620;
  margin: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--ink-2);
  letter-spacing: 0.01em;
}

.karte > .inhalt { padding: 12px 14px 14px; }

/* --- Formular ----------------------------------------------------------- */

details.gruppe { border-bottom: 1px solid var(--border); }
details.gruppe:last-of-type { border-bottom: 0; }

details.gruppe > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

details.gruppe > summary::-webkit-details-marker { display: none; }

details.gruppe > summary::before {
  content: "›";
  display: inline-block;
  transition: transform 0.12s;
  color: var(--ink-muted);
  font-size: 16px;
}

details.gruppe[open] > summary::before { transform: rotate(90deg); }

.felder {
  padding: 4px 14px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
}

.feld { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.feld.breit { grid-column: 1 / -1; }

.feld > label {
  font-size: 11.5px;
  color: var(--ink-2);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.feld > label .einheit { color: var(--ink-muted); }

input[type="number"], input[type="text"], select {
  width: 100%;
  padding: 6px 8px;
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: 6px;
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--s1);
  outline-offset: 1px;
}

.schalter {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
}

.schalter input { accent-color: var(--s1); width: 15px; height: 15px; }

.hinweistext {
  grid-column: 1 / -1;
  font-size: 11.5px;
  color: var(--ink-muted);
  margin: -2px 0 2px;
}

/* --- Schaltflächen ------------------------------------------------------ */

button {
  font: inherit;
  font-size: 13px;
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--plane);
  color: var(--ink);
  cursor: pointer;
}

button:hover { border-color: var(--axis); }

button.wichtig {
  background: var(--s1);
  border-color: var(--s1);
  color: #fff;
}

button.klein { padding: 3px 7px; font-size: 12px; }

/* --- Grafiken ----------------------------------------------------------- */

.diagramm { width: 100%; display: block; }

.legende {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 8px;
}

.legende span { display: inline-flex; align-items: center; gap: 5px; }

.legende i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.diagramme {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
}

/* --- Tabellen ----------------------------------------------------------- */

.tabellenrahmen { overflow-x: auto; }

table {
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  width: 100%;
  white-space: nowrap;
}

th, td {
  padding: 4px 9px;
  text-align: right;
  border-bottom: 1px solid var(--grid);
}

th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--ink-2);
  font-weight: 600;
  text-align: right;
  z-index: 1;
}

th:first-child, td:first-child { text-align: left; }
tbody tr:hover td { background: var(--mid); }
td.negativ { color: var(--critical); }

/* --- Hinweise ----------------------------------------------------------- */

.hinweise { display: flex; flex-direction: column; gap: 8px; }

.hinweis {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--plane);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: 5px;
  padding: 7px 10px;
}

.hinweis .zeichen { color: var(--warning); font-weight: 700; line-height: 1.4; }

/* --- Szenarienliste ----------------------------------------------------- */

.szenarienliste { display: flex; flex-direction: column; gap: 6px; }

.szenariozeile {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.szenariozeile .titel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.szenariozeile .zahl { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.szenariozeile input[type="checkbox"] { accent-color: var(--s1); }

.leer { color: var(--ink-muted); font-size: 13px; }

/* --- Druck -------------------------------------------------------------- */

@media print {
  :root { --surface: #fff; --plane: #fff; --ink: #000; --ink-2: #333; }
  header { position: static; }
  .keindruck, .karte.formular { display: none !important; }
  main { grid-template-columns: 1fr; padding: 0; }
  .karte { border: 1px solid #ccc; break-inside: avoid; }
  table { font-size: 9px; }
}

/* --- Modellwahl --------------------------------------------------------- */

.modellwahl { display: flex; gap: 0; }

.modellwahl button {
  border-radius: 0;
  margin-left: -1px;
  white-space: nowrap;
}

.modellwahl button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.modellwahl button:last-child { border-radius: 0 6px 6px 0; }

.modellwahl button.gewaehlt {
  background: var(--s1);
  border-color: var(--s1);
  color: #fff;
  position: relative;
  z-index: 1;
}

/* --- Wohnungstabelle ---------------------------------------------------- */

#wohnungen td { padding: 3px 6px; }

#wohnungen input[type="number"],
#wohnungen input[type="text"] {
  padding: 3px 6px;
  font-size: 13px;
  min-width: 70px;
}

#wohnungen input[type="text"] { min-width: 100px; }
#wohnungen input[type="checkbox"] { accent-color: var(--s1); width: 15px; height: 15px; }
#wohnungen td:first-child { text-align: left; }
#wohnungen tbody tr:hover td { background: transparent; }
#wohnungen .verkauft td { background: color-mix(in srgb, var(--s2) 8%, transparent); }

td .marke {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--mid);
  color: var(--ink-2);
}

/* Öffentlicher Betrieb: keine Ablage. */
.nur-oeffentlich { display: none; }
.oeffentlich .nur-oeffentlich { display: block; }
.oeffentlich .nur-lokal { display: none; }

/* --- Schnellrechnung ------------------------------------------------------ */

.hinweisbox {
  background: var(--plane);
  border: 1px solid var(--border);
  border-left: 3px solid var(--s1);
  border-radius: 5px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink-2);
}

.hinweisbox p { margin: 0 0 6px; }

.annahmenliste {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
  font-size: 11.5px;
  color: var(--ink-muted);
}

.annahmenliste li b { color: var(--ink-2); font-weight: 600; }

@media (max-width: 480px) {
  .annahmenliste { grid-template-columns: 1fr; }
}
