/* ==========================================================================
   Buchführung – Stylesheet
   Farblogik: grün = Einnahmen, rot = Ausgaben, blau = Navigation/Aktionen
   ========================================================================== */

:root {
  --grund: #f2f4f7;
  --flaeche: #ffffff;
  --flaeche-leise: #f7f8fa;
  --rand: #dfe3e8;
  --rand-stark: #c3cad3;

  --text: #1c2430;
  --text-leise: #5d6875;

  --blau: #1f6feb;
  --blau-dunkel: #1a5ac4;
  --gruen: #1f8b4c;
  --gruen-hell: #e8f5ed;
  --rot: #c0392f;
  --rot-hell: #fbecea;
  --gelb-hell: #fdf5e2;
  --gelb-rand: #e0b64a;

  --radius: 10px;
  --radius-klein: 7px;
  --schatten: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);

  --breite-schmal: 40rem;
  --breite-normal: 52rem;
  --breite-breit: 78rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grund: #14181e;
    --flaeche: #1c222a;
    --flaeche-leise: #232a34;
    --rand: #333c48;
    --rand-stark: #45505f;

    --text: #e8ecf1;
    --text-leise: #a3aebb;

    --blau: #4c8dff;
    --blau-dunkel: #6ba0ff;
    --gruen: #45b877;
    --gruen-hell: #1b3427;
    --rot: #e8695c;
    --rot-hell: #3a2220;
    --gelb-hell: #332d1c;
    --gelb-rand: #9a7b31;

    --schatten: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--grund);
  -webkit-text-size-adjust: 100%;
}

/* --- Kopfleiste ---------------------------------------------------------- */

.kopfleiste {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1.25rem;
  padding: .75rem 1.25rem;
  background: var(--flaeche);
  border-block-end: 1px solid var(--rand);
  position: sticky;
  inset-block-start: 0;
  z-index: 10;
}

.kopfleiste-marke {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.kopfleiste-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  flex: 1;
}

.kopfleiste-nav a {
  padding: .4rem .7rem;
  border-radius: var(--radius-klein);
  color: var(--text-leise);
  text-decoration: none;
  font-size: .95rem;
  white-space: nowrap;
}

.kopfleiste-nav a:hover { background: var(--flaeche-leise); color: var(--text); }

.kopfleiste-nav a.aktiv {
  background: var(--blau);
  color: #fff;
  font-weight: 600;
}

.kopfleiste-logout {
  color: var(--text-leise);
  text-decoration: none;
  font-size: .95rem;
  padding: .4rem .7rem;
  border: 1px solid var(--rand);
  border-radius: var(--radius-klein);
}

.kopfleiste-logout:hover { border-color: var(--rand-stark); color: var(--text); }

/* --- Grundlayout --------------------------------------------------------- */

.container {
  inline-size: 100%;
  max-inline-size: var(--breite-normal);
  margin: 1.5rem auto;
  padding: 1.75rem;
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  box-shadow: var(--schatten);
}

.container.schmal { max-inline-size: var(--breite-schmal); }
.container.breit  { max-inline-size: var(--breite-breit); }

h1, h2, h3 {
  margin-block: 0 .75rem;
  line-height: 1.25;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; margin-block-start: 2rem; }
h2:first-of-type { margin-block-start: 0; }
h3 { font-size: 1.02rem; color: var(--text-leise); }

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

:focus-visible {
  outline: 2px solid var(--blau);
  outline-offset: 2px;
}

/* --- Formulare ----------------------------------------------------------- */

label {
  display: block;
  margin-block: 1rem .35rem;
  font-weight: 600;
  font-size: .93rem;
}

label:first-of-type { margin-block-start: 0; }

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
  inline-size: 100%;
  padding: .6rem .7rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--flaeche);
  border: 1px solid var(--rand-stark);
  border-radius: var(--radius-klein);
}

input[type="file"] { padding: .45rem; background: var(--flaeche-leise); }

input:focus, select:focus, textarea:focus {
  border-color: var(--blau);
  outline: 2px solid color-mix(in srgb, var(--blau) 30%, transparent);
  outline-offset: 0;
}

.pflicht { font-weight: 400; color: var(--text-leise); }

.feld-hinweis {
  margin-block: .35rem 0;
  font-size: .86rem;
  color: var(--text-leise);
}

.checkbox-zeile {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  font-weight: 400;
  margin-block: 1rem;
}

.checkbox-zeile input { inline-size: auto; margin-block-start: .2rem; }

/* --- Knöpfe -------------------------------------------------------------- */

button, .btn-primaer, .btn-sekundaer, .btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-klein);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background-color .15s ease, border-color .15s ease;
}

button, .btn-primaer {
  display: block;
  inline-size: 100%;
  margin-block-start: 1.5rem;
  padding: .8rem 1rem;
  color: #fff;
  background: var(--blau);
  border: 1px solid transparent;
}

button:hover, .btn-primaer:hover { background: var(--blau-dunkel); }
button:disabled { opacity: .6; cursor: default; }

.btn-einnahme { background: var(--gruen); }
.btn-einnahme:hover { background: color-mix(in srgb, var(--gruen) 85%, #000); }

.btn-ausgabe, .btn-gefahr { background: var(--rot); }
.btn-ausgabe:hover, .btn-gefahr:hover { background: color-mix(in srgb, var(--rot) 85%, #000); }

.btn-sekundaer {
  display: inline-block;
  padding: .45rem .8rem;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  background: var(--flaeche);
  border: 1px solid var(--rand-stark);
}

.btn-sekundaer:hover { background: var(--flaeche-leise); }

/* Altbestand: einzelner zentrierter Knopf auf Nebenseiten */
.btn {
  display: inline-block;
  padding: .6rem 1.1rem;
  color: #fff;
  background: var(--blau);
  border: 1px solid transparent;
}
.btn:hover { background: var(--blau-dunkel); }
.übersicht { background: var(--blau); }
.einnahmen { background: var(--gruen); }
.ausgaben  { background: var(--rot); }

/* --- Schnellaktionen (Startseite) ---------------------------------------- */

.aktionen {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: .75rem;
  margin-block-end: 2rem;
}

.aktion {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: #fff;
}

.aktion-titel  { font-weight: 700; font-size: 1.05rem; }
.aktion-hinweis { font-size: .86rem; opacity: .85; }

.aktion-einnahme { background: var(--gruen); }
.aktion-ausgabe  { background: var(--rot); }
.aktion:hover    { filter: brightness(.93); }

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

.summenleiste {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: .75rem;
  margin-block: 1rem 1.5rem;
}

.summe {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: .8rem .9rem;
  background: var(--flaeche-leise);
  border: 1px solid var(--rand);
  border-radius: var(--radius-klein);
}

.summe-label {
  font-size: .82rem;
  color: var(--text-leise);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.summe-wert {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summe-einnahme { border-inline-start: 3px solid var(--gruen); }
.summe-ausgabe  { border-inline-start: 3px solid var(--rot); }
.summe-saldo    { border-inline-start: 3px solid var(--blau); }

/* --- Kleinunternehmer-Grenze --------------------------------------------- */

.grenze { margin-block: 1.5rem; }

.grenze-kopf {
  display: flex;
  justify-content: space-between;
  font-size: .86rem;
  color: var(--text-leise);
  margin-block-end: .35rem;
}

.grenze-balken {
  block-size: .5rem;
  background: var(--flaeche-leise);
  border: 1px solid var(--rand);
  border-radius: 999px;
  overflow: hidden;
}

.grenze-fuellung {
  block-size: 100%;
  background: var(--gruen);
  transition: inline-size .3s ease;
}

.grenze-fuellung.kritisch { background: var(--gelb-rand); }

/* --- Meldungen ----------------------------------------------------------- */

.success-message, .error-message, .hinweis, .warnung {
  margin-block: 1rem;
  padding: .7rem .9rem;
  border-radius: var(--radius-klein);
  border: 1px solid;
  font-size: .93rem;
}

.success-message { color: var(--gruen); background: var(--gruen-hell); border-color: var(--gruen); font-weight: 600; }
.error-message   { color: var(--rot);   background: var(--rot-hell);   border-color: var(--rot);   font-weight: 600; }
.hinweis         { color: var(--text);  background: var(--flaeche-leise); border-color: var(--rand); }
.warnung         { color: var(--text);  background: var(--gelb-hell);  border-color: var(--gelb-rand); }

.warnliste { font-size: .9rem; color: var(--text-leise); }

/* --- Filterleiste -------------------------------------------------------- */

.filterleiste {
  display: flex;
  flex-direction: column;
  gap: .9rem;
  padding: 1rem;
  margin-block-end: 1.25rem;
  background: var(--flaeche-leise);
  border: 1px solid var(--rand);
  border-radius: var(--radius-klein);
}

.filter-reiter { display: flex; flex-wrap: wrap; gap: .3rem; }

.reiter {
  padding: .4rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--rand-stark);
  background: var(--flaeche);
  color: var(--text);
  text-decoration: none;
  font-size: .9rem;
}

.reiter:hover { border-color: var(--blau); }
.reiter.aktiv { background: var(--blau); border-color: var(--blau); color: #fff; font-weight: 600; }

.filter-felder {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .7rem;
}

.filter-feld {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  margin: 0;
  font-weight: 500;
  font-size: .82rem;
  color: var(--text-leise);
}

.filter-feld input, .filter-feld select { inline-size: auto; min-inline-size: 9rem; }
.filter-feld.wachsend { flex: 1; min-inline-size: 11rem; }
.filter-feld.wachsend input { inline-size: 100%; }

.filter-felder button {
  inline-size: auto;
  margin: 0;
  padding: .6rem 1.1rem;
}

.filter-aktionen {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding-block-start: .3rem;
  border-block-start: 1px solid var(--rand);
}

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

.tabelle-rahmen {
  overflow-x: auto;              /* nur die Tabelle scrollt, nicht die Seite */
  border: 1px solid var(--rand);
  border-radius: var(--radius-klein);
}

table {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: .93rem;
}

thead th {
  position: sticky;
  inset-block-start: 0;
  background: var(--flaeche-leise);
  text-align: start;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-leise);
  padding: .6rem .75rem;
  border-block-end: 1px solid var(--rand);
  white-space: nowrap;
}

tbody td { padding: .6rem .75rem; border-block-end: 1px solid var(--rand); vertical-align: top; }
tbody tr:last-child td { border-block-end: none; }
tbody tr:hover { background: var(--flaeche-leise); }

tfoot th {
  padding: .6rem .75rem;
  text-align: start;
  border-block-start: 2px solid var(--rand-stark);
  font-size: .93rem;
}

.rechts { text-align: end; }
.leer { padding: 1.5rem; text-align: center; color: var(--text-leise); }

.betrag {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 600;
}

.betrag.negativ { color: var(--rot); }

.belegnummer {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88rem;
  font-weight: 600;
  white-space: nowrap;
}

.art-marke {
  display: inline-block;
  padding: .08rem .4rem;
  margin-inline-start: .3rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .02em;
  vertical-align: middle;
}

.art-einnahme  { background: var(--gruen-hell); color: var(--gruen); }
.art-ausgabe   { background: var(--rot-hell);   color: var(--rot); }
.art-storno    { background: var(--gelb-hell);  color: var(--gelb-rand); }
.art-storniert { background: var(--flaeche-leise); color: var(--text-leise); }

.zeile-storniert td { opacity: .6; }
.zeile-storniert .belegnummer { text-decoration: line-through; }
.zeile-storno { background: color-mix(in srgb, var(--gelb-hell) 45%, transparent); }

.kategorie   { display: block; font-weight: 600; }
.bezeichnung { display: block; font-size: .88rem; color: var(--text-leise); }
.nebeninfo   { display: block; font-size: .82rem; color: var(--text-leise); }

.storno-link { font-size: .86rem; color: var(--rot); white-space: nowrap; }

.monat-leer td { color: var(--text-leise); }

/* --- Belegvorschauen ----------------------------------------------------- */

.belege-zelle { display: flex; gap: .35rem; }

.beleg-kachel {
  display: block;
  inline-size: 2.6rem;
  block-size: 2.6rem;
  border: 1px solid var(--rand);
  border-radius: var(--radius-klein);
  overflow: hidden;
  background: var(--flaeche-leise);
  flex: none;
}

.beleg-kachel img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;      /* Hochkant-Screenshots werden beschnitten statt gequetscht */
  display: block;
}

.beleg-kachel:hover { border-color: var(--blau); }

.beleg-pdf {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  color: var(--rot);
  text-decoration: none;
}

.kein-beleg { color: var(--text-leise); }

/* --- Listen und Datenblätter --------------------------------------------- */

.liste { list-style: none; margin: 0; padding: 0; }

.liste li {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .55rem 0;
  border-block-end: 1px solid var(--rand);
}

.liste li:last-child { border-block-end: none; }
.liste-text { flex: 1; min-inline-size: 0; }

.rang {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  border-radius: 50%;
  background: var(--flaeche-leise);
  border: 1px solid var(--rand);
  font-size: .8rem;
  font-weight: 700;
  flex: none;
}

.datenblatt {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .4rem 1rem;
  margin-block: 1rem;
  padding: 1rem;
  background: var(--flaeche-leise);
  border: 1px solid var(--rand);
  border-radius: var(--radius-klein);
}

.datenblatt dt { font-size: .85rem; color: var(--text-leise); }
.datenblatt dd { margin: 0; font-weight: 600; }

.spalten-zwei {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1.5rem;
}

.spalten-zwei table { border: 1px solid var(--rand); border-radius: var(--radius-klein); }

/* --- Rückmeldung nach dem Absenden --------------------------------------- */

.form-feedback { margin-block-start: 1rem; }

/* --- Mobil: Tabellen als Karten ------------------------------------------ */

@media (max-width: 46rem) {
  .container { margin: .75rem; padding: 1.1rem; inline-size: auto; }

  .kopfleiste { padding: .6rem .8rem; }
  .kopfleiste-nav { order: 3; inline-size: 100%; }

  .tabelle-rahmen { border: none; overflow-x: visible; }

  table.buchungen, table.buchungen tbody, table.buchungen tr, table.buchungen td {
    display: block;
    inline-size: 100%;
  }

  table.buchungen thead { display: none; }

  table.buchungen tr {
    margin-block-end: .75rem;
    background: var(--flaeche);
    border: 1px solid var(--rand);
    border-inline-start: 3px solid var(--rand-stark);
    border-radius: var(--radius-klein);
    padding: .3rem .2rem;
  }

  table.buchungen tr.zeile-einnahme { border-inline-start-color: var(--gruen); }
  table.buchungen tr.zeile-ausgabe  { border-inline-start-color: var(--rot); }

  table.buchungen td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: .35rem .7rem;
    border-block-end: none;
    text-align: end;
  }

  /* Beschriftung kommt aus dem data-label der Zelle – sie kann dadurch nicht
     mehr aus dem Tritt geraten, wenn sich die Spaltenreihenfolge ändert. */
  table.buchungen td::before {
    content: attr(data-label);
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-leise);
    text-align: start;
    flex: none;
  }

  table.buchungen td:empty { display: none; }
  table.buchungen td[data-label="Beleg"] { border-block-end: 1px solid var(--rand); padding-block-end: .5rem; }
  table.buchungen .belege-zelle { justify-content: flex-end; }

  .filter-feld, .filter-feld input, .filter-feld select { inline-size: 100%; }
  .filter-felder button { inline-size: 100%; }

  .summe-wert { font-size: 1.1rem; }
}

@media (max-width: 30rem) {
  .summenleiste { grid-template-columns: 1fr 1fr; }
}

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

@media print {
  .kopfleiste, .filterleiste, .storno-link, .aktionen { display: none; }
  .container { box-shadow: none; border: none; max-inline-size: none; margin: 0; }
  body { background: #fff; }
}
