/**
 * KOS KLIMA KI-Portal – Werkzeug "Halbfertige Arbeiten" (Wizard und Prüfmasken).
 *
 * Die Grundbausteine (Karte, Schrittleiste, Dateiablage, Felder, Hinweise, Tabellen)
 * stammen aus liquiditaet.css und werden bewusst geteilt – beide Werkzeuge sehen gleich
 * aus. Hier stehen nur die eigenen Bausteine: Vormonat, Kennzahlen, Filterleiste, Prüftabelle
 * mit Korrekturfeldern und die Berichtskarten. Farben und Formen über die Portal-Variablen
 * (:root in index.html).
 *
 * Schmale Bildschirme: Die Prüftabelle wird zur Kartenliste – je Auftrag eine Karte mit
 * beschrifteten Werten und gut bedienbaren Eingabefeldern; nichts scrollt waagerecht.
 */

.hfa-inner { max-width: 1280px; }

/* ---------- Fest stehende Kopfbereiche der Prüfmaske ----------
   Kennzahlen, Filterleiste und Spaltenköpfe bleiben beim Blättern untereinander stehen.
   Bezug ist der Scrollbereich .liq-wrap; dessen Innenabstand oben (24 px, schmal 16 px)
   gleicht --hfa-oben aus, damit die Bereiche bündig am oberen Rand stehen. Die Höhen der
   Ebenen misst hfa.js (hfaFixierungMessen) und setzt sie an der Karte. */
.hfa-inner .liq-card { --hfa-oben: -24px; }

/* ---------- Aufträge mit Kosten über dem Auftragswert (Prüfung im Projekt) ---------- */
.hfa-verlust {
  border: 2px solid var(--danger);
  border-radius: var(--radius-sm);
  background: #fdf1f1;
  padding: 10px 14px;
  margin: 6px 0 8px;
  color: var(--gray-800);
}
.hfa-verlust-kopf { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.hfa-verlust-kopf strong { color: var(--danger); font-size: 14px; }
.liq-card .hfa-verlust p { margin: 4px 0 6px; color: var(--gray-800); font-size: 13px; }
.hfa-verlust ul { margin: 0; padding-left: 18px; font-size: 13px; max-height: 190px; overflow-y: auto; }
.hfa-verlust li { padding: 1px 0; }
.hfa-verlust-betrag { color: var(--danger); font-weight: 600; white-space: nowrap; }

/* ---------- Vergleich mit dem Vormonat ---------- */
.hfa-vormonat {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 10px 14px 8px;
  margin: 4px 0 4px;
}
.hfa-vormonat-titel { font-size: 13px; font-weight: 600; color: var(--navy); margin-bottom: 4px; }
.hfa-vormonat-felder { grid-template-columns: repeat(auto-fill, minmax(200px, 260px)); margin-bottom: 4px; }
.hfa-vormonat-vorschlag {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  font-size: 13px;
  color: var(--gray-600);
  margin: 2px 0 6px;
}

/* ---------- Kennzahlen ---------- */
.hfa-kacheln {
  position: sticky;
  top: var(--hfa-oben);
  z-index: 4;
  background: var(--white);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  padding: 12px 0 8px;
  margin-bottom: 4px;
}
.hfa-kachel {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  min-width: 0;
}
.hfa-kachel-titel { font-size: 12px; color: var(--gray-600); }
.hfa-kachel-wert {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.hfa-kachel.is-negativ { border-left-color: var(--danger); }
.hfa-kachel.is-negativ .hfa-kachel-wert { color: var(--danger); }

/* ---------- Filter ---------- */
.hfa-filterleiste {
  position: sticky;
  top: calc(var(--hfa-oben) + var(--hfa-kacheln-hoehe, 0px));
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  background: var(--white);
  padding: 8px 0 10px;
}
.hfa-suche {
  flex: 1 1 240px;
  min-width: 0;
  padding: 8px 11px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  outline: none;
}
.hfa-suche:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.hfa-filterknoepfe { display: flex; flex-wrap: wrap; gap: 6px; }
.hfa-filter {
  border: 1px solid var(--gray-200);
  background: var(--white);
  color: var(--gray-600);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 600;
}
.hfa-filter:hover { border-color: var(--accent); color: var(--navy); }
.hfa-filter.is-aktiv { background: var(--navy); border-color: var(--navy); color: var(--white); }
.hfa-filter-zahl { opacity: .75; margin-left: 2px; }
.hfa-treffer { margin-left: auto; }

/* ---------- Prüftabelle ----------
   Kein eigener Scrollbereich (overflow): Er wäre der Bezug der fest stehenden Spaltenköpfe,
   und die blieben dann nicht stehen. Ob die Tabelle passt, hängt vom Platz neben der
   Seitenleiste ab, nicht von der Fensterbreite – deshalb schaltet eine Container-Abfrage
   auf die Kartenliste um (siehe unten). */
.hfa-tabelle {
  container: hfa-tabelle / inline-size;
  margin-bottom: 6px;
  /* Beim Springen zur Tabelle nicht unter den fest stehenden Kopfbereichen verschwinden */
  scroll-margin-top: calc(var(--hfa-kacheln-hoehe, 0px) + var(--hfa-filter-hoehe, 0px));
}
/* separate statt collapse: nur so trägt die Tabelle selbst Rahmen und Rundung */
.hfa-pruef {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.hfa-pruef th, .hfa-pruef td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--gray-100);
  text-align: left;
  vertical-align: top;
}
.hfa-pruef thead th {
  position: sticky;
  top: calc(var(--hfa-oben) + var(--hfa-kacheln-hoehe, 0px) + var(--hfa-filter-hoehe, 0px));
  background: var(--gray-50);
  box-shadow: inset 0 -1px 0 var(--gray-200);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .2px;
  color: var(--gray-600);
  vertical-align: bottom;
  z-index: 2;
}
.hfa-pruef thead th:first-child { border-top-left-radius: var(--radius-sm); }
.hfa-pruef thead th:last-child { border-top-right-radius: var(--radius-sm); }
.hfa-pruef .liq-zahl { text-align: right; font-variant-numeric: tabular-nums; }
.hfa-pruef td.liq-zahl { white-space: nowrap; }
/* Zusatzzeilen („2 Rechnungen", „davon … abgezogen") umbrechen – sonst verbreitern sie die Spalte */
.hfa-pruef td.liq-zahl > .liq-hint { white-space: normal; }
.hfa-pruef td > .liq-hint { display: block; }
.hfa-auftrag strong { white-space: nowrap; }
.hfa-kunde { min-width: 150px; }
.hfa-kunde > span:first-child { color: var(--gray-800); font-weight: 500; }
.hfa-betont { font-weight: 700; color: var(--navy); }
.hfa-eingabe input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  outline: none;
  font-size: 13.5px;
}
.hfa-eingabe input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.hfa-korrektur { min-width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
.hfa-kommentar-zelle { min-width: 160px; }
.hfa-auffaellig { list-style: none; padding: 0; margin: 4px 0 0; }
.hfa-auffaellig li {
  display: inline-block;
  font-size: 11.5px;
  line-height: 1.35;
  color: #7a4d0b;
  background: #fdf6ec;
  border-radius: 4px;
  padding: 1px 6px;
  margin: 2px 4px 0 0;
}

.hfa-auffaellig li.is-stark { color: var(--white); background: var(--danger); font-weight: 600; }
.hfa-zeile.is-verlust td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
/* Aus dem Vormonat übernommen, Aufmaß bzw. Wert aus Lieferung seither geändert */
.hfa-zeile.is-seit-vormonat td { background: #fff7e6; }
.hfa-zeile.is-seit-vormonat td:first-child { box-shadow: inset 4px 0 0 var(--warning); }

/* ---------- Rechnungsvorschläge ---------- */
.hfa-pruef td.hfa-text > .liq-hint { display: block; }
.hfa-verantwortliche { margin: 4px 0 6px; }
.hfa-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent-dark);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.hfa-link:hover { text-decoration: underline; }
.hfa-anweisungen { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; width: 100%; margin-top: 4px; }
/* Markierung „zur Rechnung" und Rechnungsbetrag mit Kommentar untereinander (eine Spalte) */
.hfa-pruef .hfa-auswahl { width: 30px; padding-right: 0; text-align: center; vertical-align: top; }
.hfa-auswahl input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent-dark); cursor: pointer; }
.hfa-eingabe-kompakt { min-width: 150px; }
.hfa-eingabe-kompakt input + input { margin-top: 4px; }
.hfa-zeile.is-markiert td { background: #f1f7fc; }

/* ---------- Vormonat übernehmen (Schritt 1) ---------- */
.hfa-fortschreibung { border-top: 1px solid var(--gray-200); margin-top: 18px; padding-top: 4px; }
.hfa-fortschreibung-wahl { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin-top: 6px; }
.hfa-fortschreibung-wahl select {
  flex: 1 1 320px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 13.5px;
}

/* Voller Hinweistext für Screenreader (sichtbar ist die Kurzform, der Text steht im Tooltip) */
.hfa-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.hfa-zeile.is-negativ td { background: #fdf1f1; }
.hfa-zeile.is-negativ .hfa-betont, .hfa-zeile.is-negativ .liq-zahl { color: var(--danger); }
.hfa-zeile.is-korrigiert .hfa-korrektur { border-color: var(--accent-dark); background: var(--accent-light); }
.hfa-zeile.is-geaendert td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.hfa-zeile.is-fehler td { background: #fdf1f1; }
.hfa-zeile.is-fehler .hfa-kommentar, .hfa-zeile.is-fehler .hfa-korrektur { border-color: var(--danger); }

.hfa-details { margin: 4px 0 12px; }
.hfa-details summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent-dark);
  padding: 6px 0;
}
.hfa-details .liq-tabelle { max-height: 420px; overflow: auto; border: 1px solid var(--gray-200); border-radius: var(--radius-sm); }

/* ---------- Aktionen ---------- */
.hfa-aktionen-rechts { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.hfa-stichtag { max-width: 420px; }

/* ---------- Berichte ---------- */
.hfa-berichte { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-top: 8px; }
.hfa-bericht-karte {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--gray-50);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.hfa-bericht-kopf { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.hfa-bericht-kopf strong { color: var(--navy); font-size: 15px; }
.hfa-bericht-knoepfe { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.hfa-bericht-knoepfe a.btn { text-decoration: none; }
.hfa-warn { color: #7a4d0b; }

/* ---------- schmale Bildschirme ---------- */
@media (max-width: 860px) {
  .hfa-inner .liq-card { --hfa-oben: -16px; }
  .hfa-treffer { margin-left: 0; width: 100%; }
}
/* Telefone und niedrige Fenster: Die Kennzahlen nähmen fest stehend zu viel Höhe ein – dort
   bleibt nur die Filterleiste stehen */
@media (max-width: 860px), (max-height: 640px) {
  .hfa-kacheln { position: static; }
  .hfa-filterleiste { top: var(--hfa-oben); }
  .hfa-pruef thead th { top: calc(var(--hfa-oben) + var(--hfa-filter-hoehe, 0px)); }
}

/* Karten statt Tabelle, sobald der Platz für alle Spalten samt Eingabefeldern nicht reicht
   (Tablets, Telefone, Laptops mit Seitenleiste). Die Schwelle ist die gemessene Mindestbreite
   der Bilanz-Tabelle (rund 1.100 px bei sechsstelligen Beträgen) mit Reserve für
   siebenstellige – bei neuen Spalten neu messen. */
@container hfa-tabelle (max-width: 1150px) {
  .hfa-pruef { border: 0; }
  .hfa-pruef, .hfa-pruef tbody { display: block; }
  .hfa-pruef thead { display: none; }
  .hfa-pruef tr.hfa-zeile {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 2px 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--white);
  }
  .hfa-pruef tr.hfa-zeile[hidden] { display: none; }
  .hfa-pruef td { border: 0; padding: 3px 0; background: none !important; min-width: 0; }
  .hfa-pruef td::before {
    content: attr(data-label);
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--gray-400);
  }
  .hfa-pruef td.liq-zahl { text-align: left; }
  .hfa-auftrag, .hfa-kunde, .hfa-kommentar-zelle, .hfa-eingabe-kompakt { grid-column: 1 / -1; }
  .hfa-pruef td.hfa-auswahl { grid-column: 1 / -1; width: auto; text-align: left; }
  .hfa-pruef td.hfa-auswahl::before { display: inline; margin-right: 8px; }
  .hfa-eingabe-kompakt { min-width: 0; }
  .hfa-zeile.is-markiert { border-color: var(--accent) !important; background: #f1f7fc !important; }
  .hfa-auftrag::before, .hfa-kunde::before { display: none !important; }
  .hfa-auftrag strong { font-size: 15px; color: var(--navy); }
  .hfa-auftrag .liq-hint { display: inline !important; margin-left: 8px; }
  .hfa-kunde { min-width: 0; }
  .hfa-kommentar-zelle { min-width: 0; }
  .hfa-eingabe input { padding: 9px 10px; font-size: 16px; }   /* 16 px: kein Zoom beim Fokus auf iOS */
  .hfa-korrektur { text-align: left; }
  .hfa-zeile.is-negativ { border-color: #f3c7c7 !important; background: #fdf1f1 !important; }
  .hfa-zeile.is-geaendert { box-shadow: inset 3px 0 0 var(--warning); }
  .hfa-zeile.is-geaendert td:first-child { box-shadow: none; }
  .hfa-zeile.is-fehler { border-color: var(--danger) !important; }
  .hfa-zeile.is-verlust { border-left: 4px solid var(--danger) !important; }
  .hfa-zeile.is-verlust td:first-child { box-shadow: none; }
  .hfa-zeile.is-seit-vormonat { border-left: 4px solid var(--warning) !important; background: #fff7e6 !important; }
  .hfa-zeile.is-seit-vormonat td:first-child { box-shadow: none; }
}
@media (max-width: 520px) {
  .hfa-aktionen-rechts { width: 100%; }
  .hfa-aktionen-rechts .btn { flex: 1 1 auto; justify-content: center; }
  .hfa-kacheln { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hfa-kachel-wert { font-size: 15px; }
  .hfa-bericht-knoepfe .btn { flex: 1 1 auto; justify-content: center; }
}
