:root {
  --gruen: #1f7a5a; --gruen-hell: #e3f1eb; --flaeche: #f4f6f8; --karte: #fff; --text: #1d2329; --grau: #66707a;
  --linie: #d9dee3; --warn: #b86e00; --warn-hell: #fff4e0; --rot: #b3261e; --plus: #1b8a3a; --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --flaeche: #15191d; --karte: #1f252b; --text: #e6e9ec; --grau: #9aa4ae; --linie: #333b43; --gruen-hell: #1d3a30; --warn-hell: #3a2c12; --rot: #ff8a80; --plus: #5fd38a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--flaeche); color: var(--text);
  display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--linie); background: var(--karte); border-radius: 8px; padding: .55em .9em; cursor: pointer; min-height: 44px; }
button.haupt { background: var(--gruen); border-color: var(--gruen); color: #fff; }
button.gefahr { color: var(--rot); border-color: var(--rot); }
button.symbol { border: none; background: none; font-size: 1.4rem; padding: 0 .5rem; min-width: 44px; }
button:disabled { opacity: .35; cursor: default; }
input, select, textarea { width: 100%; border: 1px solid var(--linie); border-radius: 8px; padding: .55em .7em; background: var(--karte); min-height: 44px; }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; word-break: break-all; }
a { color: var(--gruen); }
.klein { font-size: .85rem; color: var(--grau); }
.einheit { font-size: .75em; color: var(--grau); margin-left: .3em; font-weight: normal; }

.kopf { display: flex; align-items: center; gap: .3rem; padding: .4rem .5rem; padding-top: calc(.4rem + env(safe-area-inset-top));
  background: var(--gruen); color: #fff; position: sticky; top: 0; z-index: 2; }
.kopf h1 { font-size: 1.15rem; margin: 0 .3rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kopf button.symbol { color: #fff; }
.sync { font-size: 1.1rem; padding: 0 .4rem; cursor: pointer; user-select: none; }
.sync.ok { color: #9ff0c8; } .sync.offen { color: #ffd27a; } .sync.fehler { color: #ffb4ab; font-weight: bold; }
.sync.lokal, .sync.laeuft { color: #cfe; }

.hinweis-band { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .4rem .8rem; padding: .45rem .8rem;
  background: var(--warn-hell); color: var(--text); border-bottom: 2px solid var(--warn); font-size: .92rem; text-align: center; }
.hinweis-band[hidden] { display: none; }
.hinweis-band button { min-height: 36px; padding: .3em .8em; border-color: var(--warn); }
main { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; max-width: 1100px; margin: 0 auto; padding: .7rem; }

.karten { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.karte { display: flex; flex-direction: column; gap: .2rem; background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius);
  padding: .9rem 1rem; text-decoration: none; color: inherit; }
.karte strong { font-size: 1.1rem; }
.leer { text-align: center; padding: 2rem 1rem; color: var(--grau); }

.werkzeug { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.tabelle-rahmen { flex: 1; min-height: 8rem; overflow: auto; background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); }
table.tab { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.tab th, .tab td { padding: .5rem .7rem; border-bottom: 1px solid var(--linie); text-align: left; white-space: nowrap; }
.tab th { position: sticky; top: 0; background: var(--karte); font-size: .85rem; color: var(--grau); z-index: 1; }
.tab th .einheit { display: block; margin: 0; }
.tab td.dezimal, .tab td.differenz, .tab td.formel, .tab th.dezimal, .tab th.differenz, .tab th.formel { text-align: right; }
.tab td.ber { color: var(--grau); }
.tab td.differenz { color: var(--text); font-weight: 600; }
.tab tbody tr[data-id] { cursor: pointer; }
.tab tbody tr[data-id]:hover, .tab tbody tr[data-id]:focus { background: var(--gruen-hell); outline: none; }
.tab tr.warn { background: var(--warn-hell); }
.tab tr.wechsel td { border-top: 2px dashed var(--grau); }
.tab td.hinweis { width: 2rem; text-align: center; color: var(--warn); }
.tab td.leer { white-space: normal; }

.fuss { margin-top: .6rem; background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); padding: .6rem .8rem; }
.zeitraum { display: flex; align-items: center; justify-content: center; gap: .3rem; font-weight: 600; }
.zeitraum button.symbol { color: var(--gruen); }
.fuss-werte { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin: .3rem 0; }
.fuss-wert { display: flex; flex-direction: column; }
.fuss-wert span { font-size: .85rem; color: var(--grau); }
.fuss-wert b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.fuss-wert small { font-size: .75rem; color: var(--grau); }
.fuss-wert.fehler b { color: var(--rot); }
.fuss-wert.plus b { color: var(--plus); }
.fuss-wert.minus b { color: var(--rot); }
.params { display: flex; flex-wrap: wrap; gap: .3rem 1rem; border-top: 1px solid var(--linie); padding-top: .4rem; }

dialog { border: none; border-radius: var(--radius); padding: 0; width: min(560px, 94vw); max-height: 92vh; background: var(--karte); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { display: flex; flex-direction: column; gap: .7rem; padding: 1rem 1.1rem; }
dialog h2 { margin: 0; font-size: 1.2rem; }
.dlg-inhalt { display: flex; flex-direction: column; gap: .7rem; }
.dlg-inhalt label { display: flex; flex-direction: column; gap: .25rem; }
.dlg-inhalt label.haken { flex-direction: row; align-items: center; gap: .5rem; }
.dlg-inhalt label.haken input { width: auto; min-height: 0; }
.knoepfe { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.fehler { color: var(--rot); margin: 0; }
.feldfehler { color: var(--rot); min-height: 0; }
fieldset { border: 1px solid var(--linie); border-radius: 8px; padding: .6rem .8rem; display: flex; flex-direction: column; gap: .5rem; margin: 0; }
fieldset.auswahl label { flex-direction: row; align-items: flex-start; gap: .6rem; }
fieldset.auswahl input { width: auto; min-height: 0; margin-top: .35rem; }
.wertzeile { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem; align-items: end; }
.spaltenzeile { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; }
.menue { display: flex; flex-direction: column; gap: .5rem; }
.menue button { text-align: left; }

.meldung { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: 92vw;
  background: #2d3339; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, .25); z-index: 10; }
.meldung.warnung { background: var(--warn); }

/* Handy: Zeilen als Karten */
@media (max-width: 640px) {
  main { padding: .5rem; }
  .tab thead { display: none; }
  .tab, .tab tbody, .tab tr, .tab td { display: block; width: 100%; }
  .tab tbody tr[data-id] { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; padding: .5rem .7rem; border-bottom: 1px solid var(--linie); position: relative; }
  .tab td { border: none; padding: .1rem 0; text-align: left !important; white-space: normal; }
  .tab td[data-titel]::before { content: attr(data-titel); display: block; font-size: .7rem; color: var(--grau); }
  .tab td.hinweis { position: absolute; right: .5rem; top: .4rem; width: auto; }
  .fuss-werte { grid-template-columns: 1fr 1fr; }
  .fuss-wert b { font-size: 1.1rem; }
}
