/* CSE Liquide Mittel - Design im Stil des CSE Orga Portals (Muster: CSE Radiatoren).
   Kopf GRUEN = Farb-Leitlinie der App-Familie: Finanzen gruen, Personendaten rot,
   Orga (z. B. Lager) gelb (Nutzer-Entscheid 2026-07-18). */

:root {
  color-scheme: light;   /* nativer Datumswaehler hell */
  --kopf: #0e6f0e;
  --blau: #005a9e;
  --blau-hell: #0078d4;
  --rot: #d13438;
  --orange: #ca5010;
  --gruen: #107c10;
  --grau: #8a8886;
  --hintergrund: #f3f2f1;
  --karte: #ffffff;
  --text: #201f1e;
  --text-leise: #605e5c;
  --rand: #e1dfdd;
  --schatten: 0 1px 4px rgba(0, 0, 0, .14);
  /* Diagramm-Serien (dataviz-validierte Palette, Reihenfolge = feste Zuordnung) */
  --s1: #2a78d6;  /* Ergebnis / Jahr aktuell */
  --s2: #1baf7a;  /* Kundenforderungen / Vorjahr */
  --s3: #eda100;  /* Lieferantenverbindlichkeiten */
  --s4: #008300;  /* Sparkasse Darmstadt */
  --s5: #4a3aa7;  /* Sparkasse Bensheim */
  --s6: #e34948;  /* VoBa Darmstadt/Mainz */
  --s7: #e87ba4;  /* Kontostände gesamt */
  --gitter: #e8e6e3;
  --nulllinie: #b8b6b3;
}
html[data-theme="dunkel"] {
  color-scheme: dark;    /* nativer Datumswaehler dunkel */
  --hintergrund: #1b1a19;
  --karte: #252423;
  --text: #f3f2f1;
  --text-leise: #a19f9d;
  --rand: #3b3a39;
  --schatten: 0 1px 5px rgba(0, 0, 0, .5);
  --s1: #3987e5; --s2: #199e70; --s3: #c98500; --s4: #008300;
  --s5: #9085e9; --s6: #e66767; --s7: #d55181;
  --gitter: #34322f;
  --nulllinie: #5c5a57;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="hell"]) {
    color-scheme: dark;
    --hintergrund: #1b1a19;
    --karte: #252423;
    --text: #f3f2f1;
    --text-leise: #a19f9d;
    --rand: #3b3a39;
    --schatten: 0 1px 5px rgba(0, 0, 0, .5);
    --s1: #3987e5; --s2: #199e70; --s3: #c98500; --s4: #008300;
    --s5: #9085e9; --s6: #e66767; --s7: #d55181;
    --gitter: #34322f;
    --nulllinie: #5c5a57;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--hintergrund);
  color: var(--text);
  font-size: 14px;
}

/* ---------- Kopf ---------- */
#kopf {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--kopf); color: white;
  position: sticky; top: 0; z-index: 20;
}
#kopf img { border-radius: 6px; }
#kopf-text { flex: 1; min-width: 0; }
#kopf h1 { margin: 0; font-size: 17px; font-weight: 600; }
#kopf-untertitel { font-size: 11px; opacity: .85; }
button {
  font-family: inherit; font-size: 13px; cursor: pointer;
  border-radius: 6px; border: 1px solid transparent;
}
button.primaer {
  background: var(--blau-hell); color: white; border: none;
  padding: 8px 14px; font-weight: 600;
}
button.primaer:hover { filter: brightness(1.1); }
button.primaer.gross { font-size: 15px; padding: 12px 22px; }
button.leise {
  background: rgba(255, 255, 255, .12); color: inherit;
  border: none; padding: 7px 10px;
}
#kopf button.leise { color: white; }
main button.leise, .popup button.leise {
  background: transparent; border: 1px solid var(--rand); color: var(--text);
}
button.leise:hover { filter: brightness(1.15); background: rgba(128, 128, 128, .15); }
button.leise.gefahr { color: var(--rot); border-color: var(--rot); }

/* ---------- Anmeldung ---------- */
#anmeldung { display: flex; justify-content: center; padding: 60px 16px; }
.anmelde-karte {
  background: var(--karte); border-radius: 12px; box-shadow: var(--schatten);
  padding: 36px 40px; text-align: center; max-width: 420px;
}
.anmelde-karte h2 { margin: 14px 0 6px; }
.anmelde-karte p { color: var(--text-leise); }
.hinweis { color: var(--text-leise); font-size: 12px; }

/* ---------- Hauptbereich ---------- */
#haupt { max-width: none; margin: 0 auto; padding: 14px 24px 60px; }
#demo-banner {
  background: #fff4ce; color: #605100; border: 1px solid #f2e29b;
  border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px;
}

/* Kennzahlen */
#kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px; margin-bottom: 14px;
}
.kpi {
  background: var(--karte); border-radius: 10px; box-shadow: var(--schatten);
  padding: 12px 14px; border-top: 4px solid var(--grau);
}
.kpi .zahl { font-size: 22px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi .label { font-size: 12px; color: var(--text-leise); margin-top: 2px; }
.kpi[data-farbe="rot"]    { border-top-color: var(--rot); }
.kpi[data-farbe="orange"] { border-top-color: var(--orange); }
.kpi[data-farbe="blau"]   { border-top-color: var(--blau-hell); }
.kpi[data-farbe="gruen"]  { border-top-color: var(--gruen); }
.kpi .delta { font-size: 12px; font-weight: 600; }
.delta.plus { color: var(--gruen); }
.delta.minus { color: var(--rot); }

/* ---------- Karten-Blöcke (Diagramm, Tabelle) ---------- */
.karte-block {
  background: var(--karte); border-radius: 10px; box-shadow: var(--schatten);
  padding: 14px 16px; margin-bottom: 14px;
}
.block-kopf { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.block-kopf h2 { margin: 0; font-size: 15px; }

/* Diagramm-Steuerung */
#chart-steuer { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--rand); background: var(--karte); color: var(--text);
  border-radius: 14px; padding: 4px 12px; font-size: 12px; cursor: pointer;
}
.chip.aktiv { background: var(--blau-hell); color: white; border-color: var(--blau-hell); }
/* Serien-Chips: Farbpunkt traegt die Identitaet, Text bleibt Textfarbe */
.chip.serie { display: inline-flex; align-items: center; gap: 6px; }
.chip.serie .punkt {
  width: 10px; height: 10px; border-radius: 3px; background: var(--grau); flex: none;
}
.chip.serie:not(.aktiv) { opacity: .55; }
.chip.serie.aktiv { background: var(--karte); color: var(--text); border-color: var(--text-leise); }

/* Diagramm */
#chart-wrap { position: relative; }
#chart-box svg { display: block; width: 100%; height: auto; }
.gitterlinie { stroke: var(--gitter); stroke-width: 1; }
.nulllinie { stroke: var(--nulllinie); stroke-width: 1.4; }
.achse-text { fill: var(--text-leise); font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }
.serien-linie { fill: none; stroke-width: 2; }
.serien-label { fill: var(--text); font-size: 11px; font-weight: 600; font-family: inherit; }
.kreuz-linie { stroke: var(--nulllinie); stroke-width: 1; stroke-dasharray: 3 3; }
#chart-tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--karte); border: 1px solid var(--rand); border-radius: 8px;
  box-shadow: var(--schatten); padding: 8px 10px; font-size: 12px;
  min-width: 170px; max-width: 260px;
}
#chart-tooltip .tt-titel { font-weight: 600; margin-bottom: 4px; }
#chart-tooltip .tt-zeile { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
#chart-tooltip .tt-name { display: inline-flex; align-items: center; gap: 5px; color: var(--text-leise); }
#chart-tooltip .tt-punkt { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
#chart-tooltip .tt-wert { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Tabelle */
#tabelle-scroll { overflow-x: auto; max-height: 430px; overflow-y: auto; }
#tabelle { border-collapse: collapse; width: 100%; font-size: 13px; }
#tabelle th {
  text-align: right; padding: 6px 10px; font-size: 11px; color: var(--text-leise);
  border-bottom: 1px solid var(--rand); position: sticky; top: 0; background: var(--karte);
  white-space: nowrap;
}
#tabelle th:first-child, #tabelle td:first-child { text-align: left; }
#tabelle td {
  padding: 6px 10px; border-bottom: 1px solid var(--gitter);
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
#tabelle tbody tr { cursor: pointer; }
#tabelle tbody tr:hover { background: rgba(128, 128, 128, .08); }
#tabelle .woche { font-weight: 600; color: var(--blau-hell); }
#tabelle .neg { color: var(--rot); font-weight: 600; }
#tabelle .notiz-punkt { color: var(--text-leise); cursor: help; }
/* Abschluss-Status (v1.2.0) */
#tabelle td.status { text-align: center; cursor: help; }
#tabelle .status-ok { color: var(--gruen); font-weight: 700; }
#tabelle .status-offen { color: var(--text-leise); }
#tabelle tbody tr.auto-zeile { background: rgba(202, 80, 16, .14); }
#tabelle tbody tr.auto-zeile:hover { background: rgba(202, 80, 16, .22); }
/* Lückenfüllung (kopierte Vorwochenwerte): dezent, keine Warnfarbe */
#tabelle .status-kopie { color: var(--text-leise); font-size: 15px; }
#tabelle tbody tr.kopie-zeile td:not(.status) { opacity: .62; }
#tabelle tbody tr.kopie-zeile:hover td:not(.status) { opacity: 1; }
#tabelle .btn-zeile-abschluss { font-size: 11px; padding: 2px 8px; white-space: nowrap; }

/* ---------- Popups ---------- */
.popup-hintergrund {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.popup-hintergrund[hidden] { display: none; }
.popup {
  background: var(--karte); border-radius: 12px; box-shadow: 0 6px 30px rgba(0, 0, 0, .35);
  width: 100%; max-width: 760px; max-height: 92vh;
  display: flex; flex-direction: column;
}
.popup-kopf {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--rand);
}
.popup-kopf h2 { margin: 0; font-size: 16px; }
.popup-inhalt { padding: 14px 18px; overflow-y: auto; }
.popup-fuss {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--rand);
}
.popup-fuss .hinweis { flex: 1; }
.ergebnis-vorschau { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Formular */
.form-abschnitt { margin-bottom: 6px; }
.form-abschnitt h3 {
  font-size: 13px; color: var(--blau-hell); border-bottom: 1px solid var(--rand);
  padding-bottom: 4px; margin: 14px 0 10px;
}
.form-abschnitt:first-child h3 { margin-top: 0; }
.form-raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.feld { display: flex; flex-direction: column; gap: 3px; }
.feld label { font-size: 12px; color: var(--text-leise); }
.feld input, .feld select, .feld textarea {
  font-family: inherit; font-size: 14px; padding: 7px 10px;
  border: 1px solid var(--feld-rand, var(--rand)); border-radius: 6px;
  background: var(--hintergrund); color: var(--text);
}
.feld input:focus, .feld select:focus, .feld textarea:focus { outline: 2px solid var(--feld-aktiv, #d9a300); }
.feld.breit { grid-column: 1 / -1; }
.feld .wert-hinweis { font-size: 11px; color: var(--text-leise); }
.form-hilfszeile { display: flex; justify-content: flex-end; margin-bottom: 4px; }
.form-hilfszeile button { font-size: 12px; }

#fuss { text-align: center; padding: 12px; color: var(--text-leise); font-size: 11px; }

/* Hilfe-Popup (v1.2.1) */
.hilfe-text h3 { font-size: 13px; color: var(--blau-hell); margin: 14px 0 6px; }
.hilfe-text h3:first-child { margin-top: 0; }
.hilfe-text ol, .hilfe-text ul { margin: 0 0 8px; padding-left: 20px; }
.hilfe-text li { margin-bottom: 6px; }
.hilfe-text p { margin: 6px 0; }

@media (max-width: 640px) {
  #kopf h1 { font-size: 15px; }
  .kpi .zahl { font-size: 18px; }
}

/* ---------- Druck / PDF (v1.1.0) ----------
   Erzwingt helles Design (auch bei aktivem Dark Mode), blendet Bedienelemente
   aus und laesst die Tabelle komplett ausrollen. */
#druck-kopf { display: none; }
@page { size: A4 landscape; margin: 12mm; }
@media print {
  html, html:not([data-theme="hell"]), html[data-theme="dunkel"] {
    --hintergrund: #ffffff; --karte: #ffffff; --text: #201f1e; --text-leise: #605e5c;
    --rand: #c8c6c4; --schatten: none;
    --s1: #2a78d6; --s2: #1baf7a; --s3: #eda100; --s4: #008300;
    --s5: #4a3aa7; --s6: #e34948; --s7: #e87ba4;
    --gitter: #e1dfdd; --nulllinie: #8a8886;
  }
  body { background: white; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #kopf, #fuss, #demo-banner, #chart-steuer, .popup-hintergrund, #tabelle-info { display: none !important; }
  #druck-kopf {
    display: block !important;
    font-size: 16px; font-weight: 700; margin: 0 0 10px;
  }
  #haupt { max-width: none; padding: 0; }
  .karte-block, .kpi { box-shadow: none; border: 1px solid var(--rand); break-inside: avoid; }
  #chart-karte { break-inside: avoid; }
  #chart-tooltip { display: none !important; }
  #tabelle-scroll { max-height: none; overflow: visible; }
  #tabelle th { position: static; }
  #tabelle tbody tr:hover { background: none; }
}

/* ---------- Knopf-Farb-Konvention (Haus-Regel 2026-08-20) ----------
   Gruen = bestaetigen/speichern, Rot-Umriss = abbrechen, Rot gefuellt = loeschen.
   Neutrale Hauptaktionen (Anmelden, Neu, Suchen) bleiben bewusst blau.
   Der Mehrfach-Selektor sorgt dafuer, dass die Regel eine vorhandene
   .leise-/.primaer-Regel sicher schlaegt; Rot wird im Dunkeln aufgehellt. */
button.speichern, main button.speichern, .popup button.speichern {
  background: #107c10; color: #fff; border: 1.5px solid #107c10; font-weight: 600;
}
button.speichern:hover, main button.speichern:hover, .popup button.speichern:hover { background: #0b5c0b; }
button.speichern:disabled { opacity: .55; cursor: default; }
button.abbrechen, main button.abbrechen, .popup button.abbrechen {
  background: transparent; color: #d13438; border: 1.5px solid #d13438; font-weight: 600;
}
button.abbrechen:hover, main button.abbrechen:hover, .popup button.abbrechen:hover { background: rgba(209, 52, 56, .12); }
button.gefahr, main button.gefahr, .popup button.gefahr {
  background: #d13438; color: #fff; border: 1.5px solid #d13438; font-weight: 600;
}
button.gefahr:hover { filter: brightness(1.08); }
html[data-theme="dunkel"] button.abbrechen { color: #ea6a6d; border-color: #ea6a6d; }
html[data-theme="dunkel"] button.gefahr { background: #ea6a6d; border-color: #ea6a6d; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="hell"]) button.abbrechen { color: #ea6a6d; border-color: #ea6a6d; }
  html:not([data-theme="hell"]) button.gefahr { background: #ea6a6d; border-color: #ea6a6d; }
}
