/* Buchhaltung — Oberfläche */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --grün: #2e6e4e;
  --grün-dunkel: #24573e;
  --grün-hell: #eaf3ee;
  --grau: #5f6b66;
  --linie: #dde4e0;
  --hintergrund: #f4f6f5;
  --rot: #b3372f;
  --orange: #b06a00;
  --blau: #1f5f8b;
  --radius: 8px;
}
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14.5px;
  color: #21302a;
  background: var(--hintergrund);
}

#layout { display: flex; min-height: 100vh; }

/* --- Navigation --- */
#sidebar {
  width: 220px; flex-shrink: 0;
  background: linear-gradient(180deg, #274d3b, #1d3b2d);
  color: #e7efe9; padding: 14px 10px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
#sidebar .logo { font-size: 19px; font-weight: 700; padding: 6px 10px 16px; letter-spacing: .3px; }
#sidebar a {
  display: block; color: #d7e4db; text-decoration: none;
  padding: 8px 10px; border-radius: 6px; margin-bottom: 2px;
}
#sidebar a:hover { background: rgba(255,255,255,.08); color: #fff; }
#sidebar a.aktiv { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav-gruppe { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #93ab9c; padding: 14px 10px 4px; }

/* --- Inhalt --- */
#inhalt { flex: 1; padding: 22px 28px; max-width: 1300px; }
h1 { font-size: 22px; margin-bottom: 4px; }
h2 { font-size: 17px; margin: 18px 0 8px; }
.untertitel { color: var(--grau); margin-bottom: 18px; }

.kopfzeile { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.kopfzeile .aktionen { display: flex; gap: 8px; flex-wrap: wrap; }
/* Haftende Kopfzeile: bleibt beim Scrollen mit Titel, Firma, Datum und Knöpfen sichtbar */
.kopfzeile-haftend {
  position: sticky; top: 0; z-index: 10;
  background: var(--hintergrund);
  padding: 10px 0;
  margin-top: -22px;           /* gleicht das Seiten-Padding oben aus */
  border-bottom: 1px solid var(--linie);
}

/* --- Karten & Tabellen --- */
.karte {
  background: #fff; border: 1px solid var(--linie); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px;
}
.kacheln { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kachel { background: #fff; border: 1px solid var(--linie); border-radius: var(--radius); padding: 14px 16px; }
.kachel .wert { font-size: 22px; font-weight: 700; margin-top: 2px; }
.kachel .label { color: var(--grau); font-size: 13px; }

table.liste { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--linie); border-radius: var(--radius); overflow: hidden; }
table.liste th {
  text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--grau); background: #fafcfb; border-bottom: 2px solid var(--linie); padding: 9px 10px;
}
table.liste td { padding: 8px 10px; border-bottom: 1px solid var(--linie); vertical-align: top; }
table.liste tr:last-child td { border-bottom: none; }
table.liste tbody tr:hover { background: var(--grün-hell); cursor: pointer; }
table.liste tbody tr.keine-hand:hover { cursor: default; background: none; }
td.zahl, th.zahl { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* Klickbare Spaltentitel: Klick sortiert die Liste nach dieser Spalte */
table.liste th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
table.liste th[data-sort]:hover { color: var(--grün); }
table.liste th.sort-aktiv { color: var(--grün); }
/* Favoriten-Stern: markierte Rechnungen stehen in der Liste immer zuoberst */
td.fav-zelle { width: 26px; padding-right: 0; }
.fav-stern { cursor: pointer; color: #b8c2bc; font-size: 16px; line-height: 1; }
.fav-stern:hover { color: var(--orange); }
.fav-stern.aktiv { color: #e0a800; }

/* --- Status-Badges --- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.entwurf       { background: #eceff1; color: #546e7a; }
.badge.offen         { background: #fff3e0; color: var(--orange); }
.badge.teilbezahlt   { background: #e3f2fd; color: var(--blau); }
.badge.bezahlt       { background: #e8f5e9; color: var(--grün); }
.badge.ueberfaellig  { background: #fdecea; color: var(--rot); }
.badge.uneinbringlich{ background: #efebe9; color: #6d4c41; }
.badge.storniert     { background: #eceff1; color: #90a4ae; text-decoration: line-through; }
.badge.angenommen    { background: #e8f5e9; color: var(--grün); }
.badge.abgelehnt     { background: #fdecea; color: var(--rot); }
.badge.mahnung       { background: #fdecea; color: var(--rot); }
.badge.aktiv         { background: #e8f5e9; color: var(--grün); }
.badge.inaktiv       { background: #eceff1; color: #90a4ae; }

/* --- Formulare --- */
.formular { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.feld { display: flex; flex-direction: column; gap: 4px; }
.feld.breit { grid-column: 1 / -1; }
.feld label { font-size: 12.5px; font-weight: 600; color: var(--grau); }
input, select, textarea {
  font: inherit; padding: 7px 9px; border: 1px solid #c3cdc8; border-radius: 6px; background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(46,110,78,.35); border-color: var(--grün); }
input.zahl { text-align: right; }
textarea { resize: vertical; min-height: 60px; }

/* --- Buttons --- */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid #c3cdc8; background: #fff; color: #21302a;
  padding: 7px 14px; border-radius: 6px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: #f0f4f2; }
button.primaer, .btn.primaer { background: var(--grün); border-color: var(--grün); color: #fff; font-weight: 600; }
button.primaer:hover, .btn.primaer:hover { background: var(--grün-dunkel); }
button.gefahr { color: var(--rot); border-color: #e2b4b0; }
button.gefahr:hover { background: #fdecea; }
button.klein { padding: 3px 9px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.suchzeile { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.suchzeile input[type=search] { max-width: 280px; }
.suchzeile select { width: auto; }

/* --- Positionstabelle im Rechnungsformular --- */
table.positionen { width: 100%; border-collapse: collapse; }
table.positionen th { text-align: left; font-size: 12px; color: var(--grau); padding: 4px 6px; }
table.positionen td { padding: 3px 4px; vertical-align: top; }
/* Trennlinie zwischen den Positionen */
table.positionen tbody tr:not(:first-child) td { border-top: 1px solid var(--linie); padding-top: 8px; }
table.positionen input, table.positionen textarea { padding: 5px 7px; }
table.positionen textarea { min-height: 34px; }
/* Spaltenbreiten: Text soll den meisten Platz bekommen */
table.positionen th:nth-child(1) { width: 34px; }
table.positionen th:nth-child(2) { width: 64px; }
table.positionen th:nth-child(3) { width: 74px; }
table.positionen th:nth-child(4) { width: 120px; }
table.positionen th:nth-child(5) { width: auto; min-width: 220px; }
table.positionen th:nth-child(6) { width: 92px; }
table.positionen th:nth-child(7) { width: 64px; }
table.positionen th:nth-child(8) { width: 80px; }
table.positionen th:nth-child(9) { width: 58px; }
table.positionen td:nth-child(8) { text-align: right; font-variant-numeric: tabular-nums; padding-top: 9px; }

/* --- Toasts --- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast {
  background: #21302a; color: #fff; padding: 10px 16px; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); animation: toast-ein .2s ease-out; max-width: 420px;
}
.toast.fehler { background: var(--rot); }
@keyframes toast-ein { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- Modal --- */
.modal-hintergrund {
  position: fixed; inset: 0; background: rgba(15,25,20,.45); display: flex;
  align-items: center; justify-content: center; z-index: 900; padding: 20px;
}
.modal {
  background: #fff; border-radius: 10px; padding: 20px; max-width: 560px; width: 100%;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.modal h2 { margin-top: 0; }
.modal .modal-aktionen { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.leer { text-align: center; color: var(--grau); padding: 40px 10px; }
.hinweis { background: #fff8e1; border: 1px solid #f0e0a0; border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; }
a { color: var(--blau); }
.rechts { text-align: right; }
.text-rot { color: var(--rot); }
.text-grau { color: var(--grau); }
.mono { font-variant-numeric: tabular-nums; }

@media print {
  #sidebar, .kopfzeile .aktionen, .suchzeile, #toasts { display: none !important; }
  #inhalt { padding: 0; }
}

/* --- Menü-Knopf (nur auf schmalen Bildschirmen sichtbar) --- */
#menue-knopf {
  display: none;
  position: fixed; top: 10px; left: 10px; z-index: 300;
  width: 44px; height: 44px; padding: 0;
  justify-content: center; align-items: center;
  font-size: 22px; border-radius: 10px;
  background: #274d3b; color: #fff; border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
#menue-schleier {
  display: none; position: fixed; inset: 0;
  background: rgba(15,25,20,.45); z-index: 190;
}

/* --- Hochformat / schmale Bildschirme (iPhone & Co.) --- */
@media (max-width: 760px) {
  #menue-knopf { display: flex; }

  /* Seitenleiste als aufklappbares Menü */
  #sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 200;
    width: 240px; transform: translateX(-105%);
    transition: transform .2s ease-out;
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
    padding-top: max(14px, env(safe-area-inset-top));
  }
  body.menue-offen #sidebar { transform: translateX(0); }
  body.menue-offen #menue-schleier { display: block; }
  #sidebar a { padding: 12px 10px; font-size: 16px; }

  /* Inhalt: Platz für den Menü-Knopf, weniger Rand */
  #inhalt { padding: 12px 10px 90px; max-width: none; }
  #inhalt > div > .kopfzeile:first-child,
  #inhalt > div > .kopfzeile-haftend { padding-left: 52px; }
  .kopfzeile-haftend { position: static; margin-top: 0; }
  h1 { font-size: 19px; }

  /* Tabellen: seitlich wischbar statt gequetscht */
  .karte { padding: 12px; overflow-x: auto; }
  #li-tabelle { overflow-x: auto; }
  #li-tabelle table.liste { min-width: 620px; }
  table.positionen { min-width: 700px; }

  /* Formulare einspaltig, grössere Berührflächen */
  .formular { grid-template-columns: 1fr; }
  button, .btn { padding: 10px 14px; }
  .suchzeile input[type=search] { max-width: none; flex: 1; }
  .kacheln { grid-template-columns: 1fr 1fr; }
}
