/* Farb- und Formensprache bewusst identisch zum Fahrtenbuch, zum AV-Rechner und
   zum Testbild-Generator, damit die eigenen Tools als eine Familie erkennbar
   bleiben. Anders als das Fahrtenbuch wird dieses Werkzeug am Schreibtisch
   bedient: Navigation oben, Liste als Tabelle. Auf dem Handy klappt die
   Tabelle zu Karten zusammen. */
:root {
  --bg: #f4f5f7;
  --flaeche: #ffffff;
  --flaeche-2: #f8f9fb;
  --rand: #d6d9de;
  --rand-stark: #b3b8c0;
  --text: #1f2328;
  --leise: #6b727c;
  --primaer: #2f6fb5;
  --primaer-text: #ffffff;
  --gefahr: #c0392b;
  --ok-bg: #eef6ee;
  --ok-rand: #7fae7f;
  --ok-text: #2c6e2c;
  --warn-bg: #fdf3e3;
  --warn-rand: #e0b054;
  --warn-text: #8a6b2a;
  --fehler-bg: #fdecea;
  --fehler-rand: #d9534f;
  --schatten: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d21;
    --flaeche: #24272c;
    --flaeche-2: #1f2226;
    --rand: #3a3f46;
    --rand-stark: #50565e;
    --text: #e6e8ea;
    --leise: #9aa1aa;
    --primaer: #4b8fd6;
    --gefahr: #e06c5f;
    --ok-bg: #21301f;
    --ok-rand: #4d7a4d;
    --ok-text: #8fc98f;
    --warn-bg: #3a2f1c;
    --warn-rand: #8a6b2a;
    --warn-text: #e0b054;
    --fehler-bg: #3a2320;
    --fehler-rand: #a4453f;
    --schatten: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

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

.versteckt { display: none !important; }
.leise { color: var(--leise); }
.klein { font-size: 0.83rem; }
.luecke { flex: 1; }
.nowrap { white-space: nowrap; }
.rechts { text-align: right; }

/* ---------- Kopf mit Navigation ---------- */

.kopf {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 8px 16px;
  background: var(--flaeche);
  border-bottom: 1px solid var(--rand);
}
.kopf h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
}
.navi { display: flex; gap: 4px; }
.navi a {
  text-decoration: none;
  color: var(--leise);
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.92rem;
}
.navi a:hover { background: var(--flaeche-2); color: var(--text); }
.navi a[aria-current="page"] { color: var(--primaer); background: var(--flaeche-2); font-weight: 700; }

/* ---------- Grundelemente ---------- */

input,
select,
textarea,
button {
  font: inherit;
  color: var(--text);
}

input,
select,
textarea {
  background: var(--flaeche);
  border: 1px solid var(--rand-stark);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
  min-height: 40px;
}
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primaer);
  outline-offset: -1px;
  border-color: var(--primaer);
}
input[readonly] { background: var(--flaeche-2); color: var(--leise); }
input.zahl { text-align: right; font-variant-numeric: tabular-nums; }

label.feld {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--leise);
}
label.feld .pflicht { color: var(--gefahr); font-weight: 700; }
label.feld .zusatz { font-weight: 400; }

button,
a.knopf {
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--rand-stark);
  background: var(--flaeche);
  padding: 8px 14px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 500;
  text-decoration: none;
  color: var(--text);
  font-size: 0.92rem;
}
button:hover:not(:disabled), a.knopf:hover { border-color: var(--primaer); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primaer, a.knopf.primaer {
  background: var(--primaer);
  color: var(--primaer-text);
  border-color: var(--primaer);
  font-weight: 600;
}
button.gefahr { color: var(--gefahr); }
button.gefahr:hover:not(:disabled) { border-color: var(--gefahr); background: var(--fehler-bg); }
button.schlicht { border-color: transparent; background: transparent; }
button.schlicht:hover:not(:disabled) { background: var(--flaeche-2); border-color: var(--rand); }
button.klein, a.knopf.klein { min-height: 32px; padding: 4px 10px; font-size: 0.82rem; }

/* ---------- Aufbau ---------- */

.inhalt {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.inhalt.schmal { max-width: 900px; }

.karte {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 12px;
  box-shadow: var(--schatten);
}
.karte-kopf {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--rand);
  font-weight: 600;
  font-size: 0.92rem;
}
.karte-kopf .zusatz { font-weight: 400; color: var(--leise); font-size: 0.82rem; }
.karte-koerper { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.raster { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.raster.zwei { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.spanne-2 { grid-column: span 2; }

.werkzeugleiste {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}
.werkzeugleiste > label.feld { flex: 0 1 150px; }
.werkzeugleiste > label.feld.breit { flex: 1 1 220px; }

.titelzeile { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.titelzeile h2 { margin: 0; font-size: 1.25rem; }

/* ---------- Kennzahlen ---------- */

.kennzahlen { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kennzahl {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--schatten);
}
.kennzahl .wert { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kennzahl .bezeichnung { font-size: 0.8rem; color: var(--leise); }

/* ---------- Belegliste ---------- */

table.liste { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.liste th {
  text-align: left;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--leise);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rand);
  white-space: nowrap;
}
table.liste td { padding: 10px 12px; border-bottom: 1px solid var(--rand); vertical-align: top; }
table.liste tbody tr { cursor: pointer; }
table.liste tbody tr:hover { background: var(--flaeche-2); }
table.liste tbody tr:last-child td { border-bottom: none; }
table.liste .betrag { text-align: right; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.liste .nummer { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.liste .beschreibung { color: var(--leise); font-size: 0.82rem; }
table.liste tr.storniert td { color: var(--leise); }
table.liste tr.storniert .betrag { text-decoration: line-through; }

.merker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--flaeche-2);
  border: 1px solid var(--rand);
  white-space: nowrap;
  font-weight: 500;
}
.merker.storniert { color: var(--gefahr); border-color: var(--fehler-rand); background: var(--fehler-bg); }
.merker.warnung { color: var(--warn-text); border-color: var(--warn-rand); background: var(--warn-bg); }
.merker.geaendert { color: var(--leise); }

.leer {
  padding: 36px 16px;
  text-align: center;
  color: var(--leise);
}

@media (max-width: 760px) {
  table.liste thead { display: none; }
  table.liste, table.liste tbody, table.liste tr, table.liste td { display: block; width: 100%; }
  table.liste tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--rand);
  }
  table.liste td { padding: 0; border: none; }
  table.liste td.spalte-datum, table.liste td.spalte-zahlung { display: none; }
  table.liste td.spalte-empfaenger { grid-column: 1 / -1; }
  table.liste td.spalte-status { grid-column: 1 / -1; }
}

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

.positionen { display: flex; flex-direction: column; gap: 8px; }
.position {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 90px 130px 120px 40px;
  gap: 8px;
  align-items: end;
}
.position .nr { padding-bottom: 10px; color: var(--leise); font-weight: 600; text-align: right; }
.position .summe {
  padding: 9px 4px;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.position .weg { min-height: 40px; padding: 0; }
.position label.feld { gap: 3px; }
.position:not(:first-child) label.feld > span.beschriftung { display: none; }

.gesamt {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 14px;
  padding-top: 10px;
  border-top: 2px solid var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
  .position {
    grid-template-columns: 1fr 1fr;
    padding: 10px;
    border: 1px solid var(--rand);
    border-radius: 10px;
  }
  .position .nr { display: none; }
  .position .feld-beschreibung { grid-column: 1 / -1; }
  .position:not(:first-child) label.feld > span.beschriftung { display: inline; }
  .spanne-2 { grid-column: auto; }
}

.nummernvorschau {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--flaeche-2);
  border: 1px dashed var(--rand-stark);
}
.nummernvorschau .wert { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.nummernvorschau .bezeichnung { font-size: 0.75rem; color: var(--leise); }

.aktionsleiste {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

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

.hinweis {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--rand);
  background: var(--flaeche-2);
  font-size: 0.87rem;
}
.hinweis.warnung { background: var(--warn-bg); border-color: var(--warn-rand); color: var(--warn-text); }
.hinweis.fehler { background: var(--fehler-bg); border-color: var(--fehler-rand); color: var(--gefahr); }
.hinweis.ok { background: var(--ok-bg); border-color: var(--ok-rand); color: var(--ok-text); }
.hinweis ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Detailansicht ---------- */

.detail { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 980px) { .detail { grid-template-columns: 1fr; } }

.vorschau {
  width: 100%;
  border: none;
  display: block;
  min-height: 600px;
  border-radius: 12px;
  background: #fff;
}

.verlauf { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; font-size: 0.85rem; }
.verlauf li { border-left: 3px solid var(--rand-stark); padding-left: 10px; }
.verlauf .wann { color: var(--leise); font-size: 0.78rem; }
.verlauf .was { font-weight: 600; }
.verlauf .details { color: var(--leise); font-size: 0.8rem; overflow-wrap: anywhere; }

/* ---------- Rückmeldung ---------- */

.meldung {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  font-size: 0.9rem;
}
.meldung.fehler { background: var(--gefahr); color: #fff; }

/* ---------- Dialog ---------- */

dialog {
  border: 1px solid var(--rand);
  border-radius: 12px;
  background: var(--flaeche);
  color: var(--text);
  padding: 0;
  width: min(460px, calc(100vw - 32px));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0; font-size: 1.05rem; }
