:root {
  --bg: #f4f1ea;
  --flaeche: #fffdf8;
  --text: #1f2328;
  --leise: #6b6f76;
  --linie: #e2ddd2;
  --akzent: #2f5d50;
  --akzent-text: #ffffff;
  --gruen: #2e8b57;
  --orange: #d9822b;
  --rot: #c8402f;
  --gruen-bg: #dff1e6;
  --orange-bg: #fbe8d0;
  --rot-bg: #f9dcd7;
  --schatten: 0 1px 2px rgba(0, 0, 0, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --flaeche: #202327;
    --text: #e8e6e1;
    --leise: #9a9ea6;
    --linie: #32363c;
    --akzent: #6fbfa5;
    --akzent-text: #10201b;
    --gruen: #5fc48b;
    --orange: #f0a04b;
    --rot: #f0705f;
    --gruen-bg: #1d3a2a;
    --orange-bg: #45311a;
    --rot-bg: #4a231e;
    --schatten: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--leise); margin: 1.4rem 0 .4rem; font-weight: 600; }

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 84px);
  min-height: 100vh;
}
.kopf { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.kopf .aktionen { display: flex; gap: 8px; }

#banner {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px;
  background: var(--orange-bg); color: var(--text);
  font-size: .85rem; text-align: center;
}
#banner:not([hidden]) + #app { padding-top: 14px; }

/* Navigation */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--flaeche) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--linie);
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
}
#tabs[hidden] { display: none; }
#tabs button {
  flex: 1; max-width: 120px; background: none; border: 0; padding: 4px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--leise); font-size: .68rem;
}
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.aktiv { color: var(--akzent); font-weight: 600; }

/* Bedienelemente */
.knopf {
  border: 1px solid var(--linie); background: var(--flaeche); border-radius: 10px;
  padding: 9px 14px; min-height: 42px; box-shadow: var(--schatten);
}
.knopf.haupt { background: var(--akzent); border-color: var(--akzent); color: var(--akzent-text); font-weight: 600; }
.knopf.gefahr { color: var(--rot); }
.knopf.klein { padding: 5px 10px; min-height: 34px; font-size: .9rem; }
.knopf:disabled, .rund:disabled { opacity: .4; cursor: default; }
input[type=text], input[type=search], input[type=password], input[type=number], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--linie); background: var(--flaeche); border-radius: 10px;
  padding: 9px 12px; min-height: 42px;
}
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: .82rem; color: var(--leise); margin: 12px 0 4px; }
.zeile-felder { display: flex; gap: 10px; }
.zeile-felder > * { flex: 1; min-width: 0; }
.mit-knopf { display: flex; gap: 8px; }
.mit-knopf input { flex: 1; }

.wahl { display: flex; gap: 6px; background: var(--linie); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.wahl button {
  flex: 1; border: 0; background: none; border-radius: 9px; padding: 7px 4px; min-height: 36px;
  font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wahl button.aktiv { background: var(--flaeche); font-weight: 600; box-shadow: var(--schatten); }

.filter { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.filter input[type=search] { flex: 1; }
.chip {
  border: 1px solid var(--linie); background: var(--flaeche); border-radius: 999px;
  padding: 7px 12px; min-height: 38px; font-size: .88rem; white-space: nowrap;
}
.chip.aktiv { background: var(--orange-bg); border-color: var(--orange); }

/* Listen */
.liste { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 14px; overflow: hidden; box-shadow: var(--schatten); }
.eintrag { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--linie); }
.eintrag:first-child { border-top: 0; }
.eintrag .haupt { flex: 1; min-width: 0; background: none; border: 0; padding: 0; text-align: left; }
.eintrag .name { font-weight: 500; overflow-wrap: anywhere; }
.eintrag .inhalt { color: var(--leise); font-weight: 400; }
.eintrag .sub { font-size: .82rem; color: var(--leise); }
.eintrag.zwei { flex-wrap: wrap; row-gap: 6px; }
.eintrag.zwei .haupt { flex-basis: 100%; }
.eintrag.zwei .zaehler { margin-left: auto; }
/* Zustand als Farbe der ganzen Zeile plus Randstreifen und Wort (auch ohne Rot-Grün-Sehen lesbar). */
.eintrag.umbruch { flex-wrap: wrap; row-gap: 4px; }
.eintrag.gruen { background: var(--gruen-bg); }
.eintrag.orange { background: var(--orange-bg); box-shadow: inset 4px 0 0 var(--orange); }
.eintrag.rot { background: var(--rot-bg); box-shadow: inset 6px 0 0 var(--rot); }
.zustand { font-weight: 700; text-transform: uppercase; font-size: .72rem; letter-spacing: .05em; color: var(--text); }
.eintrag .rund:not(.haken) { background: var(--flaeche); }

.fuell { flex: 0 0 100%; display: flex; align-items: center; gap: 10px; margin: 0; font-size: .82rem; color: var(--leise); }
.fuell input { flex: 1; min-width: 0; height: 30px; accent-color: var(--akzent); padding: 0; border: 0; background: none; min-height: 0; }
.fuell output { min-width: 3.4em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.fuell.niedrig input { accent-color: var(--rot); }
.fuell.niedrig output { color: var(--rot); }
body.offline .fuell input { pointer-events: none; }

.zaehler { display: flex; align-items: center; gap: 2px; flex: none; }
.zaehler .menge { min-width: 2.2em; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.05rem; }
.rund {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--linie); background: var(--bg);
  font-size: 1.3rem; line-height: 1; display: grid; place-items: center; padding: 0;
}
.haken { background: var(--akzent); color: var(--akzent-text); border-color: var(--akzent); margin-left: 6px; font-size: 1.1rem; }

.leer { color: var(--leise); text-align: center; padding: 28px 12px; }
.hinweis { font-size: .85rem; color: var(--leise); margin: 6px 2px; }

/* Übersichtstabelle */
.tabelle { width: 100%; border-collapse: collapse; background: var(--flaeche); border: 1px solid var(--linie); border-radius: 14px; overflow: hidden; }
.tabelle-rahmen { border-radius: 14px; overflow: hidden; border: 1px solid var(--linie); box-shadow: var(--schatten); }
.tabelle-rahmen .tabelle { border: 0; border-radius: 0; }
.tabelle th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--leise); font-weight: 600; padding: 8px 4px; }
.tabelle th:first-child, .tabelle td:first-child { text-align: left; padding-left: 12px; }
.tabelle td { border-top: 1px solid var(--linie); padding: 6px 4px; text-align: center; }
.tabelle tr.gruppe td { background: var(--bg); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--leise); font-weight: 600; padding: 6px 12px; text-align: left; }
.tabelle td .name { overflow-wrap: anywhere; }
.zelle {
  min-width: 46px; min-height: 34px; border-radius: 8px; border: 0; background: none; padding: 4px 6px;
  font-variant-numeric: tabular-nums; font-weight: 600;
}
.zelle small { font-weight: 400; color: var(--leise); }
.zelle small.proz { display: block; font-size: .68rem; line-height: 1.1; }
.zelle.gruen { background: var(--gruen-bg); }
.zelle.orange { background: var(--orange-bg); box-shadow: inset 0 0 0 1.5px var(--orange); }
.zelle.rot { background: var(--rot-bg); box-shadow: inset 0 0 0 2.5px var(--rot); }
.zelle.keins { color: var(--leise); font-weight: 400; }

/* Einstellungen */
.karte { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 14px; padding: 12px; box-shadow: var(--schatten); margin-bottom: 10px; }
.karte .titelzeile { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.karte .titelzeile strong { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.marken { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.marke { border: 1px solid var(--linie); background: var(--bg); border-radius: 999px; padding: 4px 10px; font-size: .88rem; min-height: 32px; }
.verlauf .eintrag { align-items: flex-start; }
.verlauf .zurueck { text-decoration: line-through; color: var(--leise); }

/* Dialog */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 40px);
  background: var(--flaeche); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { padding: 18px; }
dialog h3 { margin: 0 0 4px; font-size: 1.15rem; }
dialog .fuss { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
dialog .fuss .links { margin-right: auto; }
dialog .auswahl { max-height: 44vh; overflow-y: auto; margin-top: 10px; border: 1px solid var(--linie); border-radius: 12px; }
dialog .auswahl button { display: block; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--linie); padding: 10px 12px; }
dialog .auswahl button:first-child { border-top: 0; }
.meldung { color: var(--rot); font-size: .9rem; margin-top: 10px; min-height: 1.2em; }

/* Anmeldung */
.anmeldung { max-width: 340px; margin: 18vh auto 0; text-align: center; }
.anmeldung img { width: 84px; height: 84px; border-radius: 20px; }
.anmeldung form { margin-top: 18px; display: grid; gap: 10px; }

/* Scanner */
#scanner { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; }
#scanner[hidden] { display: none; }
#scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-rahmen { position: absolute; left: 8%; right: 8%; top: 32%; height: 22%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
.scan-leiste { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 16px calc(env(safe-area-inset-bottom) + 16px); display: grid; gap: 10px; text-align: center; }
.scan-leiste p { margin: 0; }
.scan-leiste form { display: flex; gap: 8px; }
.scan-leiste input { flex: 1; background: rgba(255, 255, 255, .95); color: #111; border: 0; border-radius: 10px; padding: 9px 12px; min-height: 42px; }
.scan-leiste button { border-radius: 10px; border: 0; min-height: 42px; padding: 0 16px; background: #fff; color: #111; }

/* Toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(env(safe-area-inset-bottom) + 78px);
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px;
  display: flex; gap: 14px; align-items: center; max-width: calc(100vw - 24px); font-size: .92rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
#toast[hidden] { display: none; }
#toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; padding: 4px; }

body.offline .nur-online { display: none !important; }
body.offline .rund, body.offline .zelle, body.offline .eintrag .haupt { pointer-events: none; }
body.offline .zaehler .rund { visibility: hidden; }
