:root {
  --bg: #f3f4f6;
  --karte: #ffffff;
  --text: #111827;
  --leise: #6b7280;
  --linie: #e5e7eb;
  --blau: #1565c0;
  --gruen: #2e7d32;
  --gruen-hell: #e8f5e9;
  --rot: #c62828;
  --rot-hell: #ffebee;
  --orange: #ef6c00;
  --orange-hell: #fff3e0;
  --gelb-hell: #fff8e1;
  --knopf: #eef0f3;
  --schatten: 0 1px 3px rgba(0, 0, 0, .12);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --karte: #1a1d23;
    --text: #e8eaed;
    --leise: #9aa0a6;
    --linie: #2c3038;
    --blau: #64a8f0;
    --gruen: #43a047;
    --gruen-hell: #1b2e1d;
    --rot: #ef5350;
    --rot-hell: #3a1d1d;
    --orange: #ffa040;
    --orange-hell: #33261a;
    --gelb-hell: #2f2a1a;
    --knopf: #262a31;
    --schatten: 0 1px 3px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, .knopf {
  font: inherit;
  color: inherit;
}

button, .knopf {
  border: 1px solid var(--linie);
  background: var(--knopf);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 600;
  touch-action: manipulation;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .45; cursor: default; transform: none; }
button.gruen { background: var(--gruen); border-color: var(--gruen); color: #fff; }
button.rot { color: var(--rot); }
button.gross { width: 100%; min-height: 56px; font-size: 1.15rem; }
button.link { background: none; border: none; color: var(--blau); padding: 4px 8px; min-height: 0; }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--linie);
  border-radius: 10px;
  background: var(--karte);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--blau); outline-offset: 1px; }
input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; }
input[type=color] { padding: 2px; width: 48px; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 10px 0; }
label > input, label > select { margin-top: 4px; font-weight: 400; font-size: 1rem; }

h1, h2, h3 { margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin-top: 18px; }
h3 { font-size: 1rem; }

.laden, .leer { color: var(--leise); padding: 12px 0; }
.hinweis { color: var(--leise); font-size: .9rem; margin: 4px 0 10px; }
.fehlertext { color: var(--rot); font-weight: 600; }
.versteckt { display: none; }
.warnung { background: var(--gelb-hell); border: 1px solid #f0c000; border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.warnung a { color: var(--blau); font-weight: 600; }

/* ---------- Rahmen ---------- */

.seite { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.kopf {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--blau); color: #fff;
}
@media (prefers-color-scheme: dark) { .kopf { background: #13304f; } }
.kopf .titel { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.kopf .titel strong { font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kopf .titel small { opacity: .85; }
.menu-knopf { background: rgba(255, 255, 255, .15); border: none; color: #fff; font-size: 1.3rem; min-width: 44px; }
.status { font-size: .8rem; padding: 4px 10px; border-radius: 999px; white-space: nowrap; background: rgba(255, 255, 255, .15); }
.status.offline { background: var(--orange); color: #fff; }

.inhalt { padding: 12px; width: 100%; max-width: 1200px; margin: 0 auto; }
.inhalt.schmal { max-width: 640px; }

.karte { background: var(--karte); border-radius: var(--radius); box-shadow: var(--schatten); padding: 14px; margin: 10px 0; }

.hinter { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 50; }
.menue {
  position: absolute; top: 0; left: 0; bottom: 0; width: min(320px, 85vw);
  background: var(--karte); padding: 16px; padding-top: max(16px, env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
}
.menu-wer { display: flex; flex-direction: column; padding: 4px 8px 12px; border-bottom: 1px solid var(--linie); margin-bottom: 8px; }
.menu-wer small { color: var(--leise); }
.menu-link { display: flex; justify-content: flex-start; background: none; border: none; color: var(--text); text-decoration: none; padding: 12px 8px; border-radius: 8px; font-weight: 600; min-height: 44px; }
.menu-link:hover { background: var(--knopf); }
.menu-info { color: var(--leise); font-size: .85rem; padding: 12px 8px; margin-top: auto; }
.abmelden { color: var(--rot); }

.meldung {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 100;
  max-width: 90vw; box-shadow: 0 4px 14px rgba(0, 0, 0, .3); transition: opacity .5s;
}
.meldung.fehler { background: var(--rot); }
.meldung.weg { opacity: 0; }

/* ---------- Anmeldung ---------- */

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-karte { background: var(--karte); border-radius: 18px; box-shadow: var(--schatten); padding: 24px; width: min(400px, 100%); text-align: center; }
.login-karte label { text-align: left; }
.login-karte .logo { font-size: 3rem; }
.login-karte .unter { color: var(--leise); margin-top: -4px; }
.login-karte button { margin-top: 10px; }

/* ---------- Spieltage ---------- */

.spieltag { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spieltag.aktiv { outline: 2px solid var(--blau); }
.sp-info { flex: 1; min-width: 200px; display: flex; flex-direction: column; }
.sp-info small { color: var(--leise); }
.sp-knoepfe, .knopfreihe { display: flex; gap: 8px; flex-wrap: wrap; }
.zwei { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sp-titelzeile { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.sp-titelzeile h2 { margin: 0; }
.sp-titelzeile small { color: var(--leise); }

/* ---------- Kasse ---------- */

.kasse-seite { height: 100vh; height: 100dvh; overflow: hidden; }
.kasse { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 380px; }
.waren { min-height: 0; display: flex; flex-direction: column; padding: 10px; gap: 10px; overflow: hidden; }

.kategorien { display: flex; gap: 8px; overflow-x: auto; flex-shrink: 0; padding-bottom: 2px; }
.chip { border-radius: 999px; border-width: 2px; padding: 8px 16px; white-space: nowrap; background: var(--karte); }
.chip.aktiv { background: var(--text); color: var(--bg); border-color: var(--text) !important; }

.raster {
  flex: 1; overflow-y: auto; align-content: start;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px;
}
.ware {
  position: relative; min-height: 92px; flex-direction: column; gap: 4px;
  border: none; box-shadow: var(--schatten); padding: 10px 8px; text-align: center;
}
.ware .name { font-size: 1.02rem; font-weight: 700; line-height: 1.2; }
.ware .preis { font-size: .9rem; font-weight: 600; opacity: .85; }
.ware .anzahl {
  position: absolute; top: -6px; right: -6px; min-width: 28px; height: 28px; padding: 0 6px;
  border-radius: 999px; background: var(--rot); color: #fff; font-size: .95rem;
  display: grid; place-items: center; box-shadow: var(--schatten);
}

.pfand-leiste { display: flex; gap: 8px; align-items: center; overflow-x: auto; flex-shrink: 0; background: var(--orange-hell); border-radius: var(--radius); padding: 8px; }
.pfand-titel { font-weight: 700; white-space: nowrap; }
.pfand-zurueck { background: #ffb74d; border-color: #f59e0b; color: #111; white-space: nowrap; flex-direction: column; gap: 0; line-height: 1.1; }

.korb {
  background: var(--karte); border-left: 1px solid var(--linie);
  display: flex; flex-direction: column; padding: 12px; gap: 10px; min-height: 0;
}
.korb-kopf { display: flex; align-items: center; justify-content: space-between; }
.korb-kopf strong { font-size: 1.1rem; flex: 1; }
.positionen { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; min-height: 60px; }
.pos { display: grid; grid-template-columns: 40px 28px 40px 1fr auto; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--linie); }
.pos .menge { text-align: center; font-weight: 700; }
.pos .text { line-height: 1.2; text-align: left; }
.pos .betrag { font-variant-numeric: tabular-nums; font-weight: 600; }
.pos.art-pfand .text { color: var(--orange); }
.pos.art-pfandzurueck .text, .pos.art-pfandzurueck .betrag { color: var(--blau); }
.mini { min-height: 40px; min-width: 40px; padding: 0; font-size: 1.2rem; }
.mini-text { min-height: 34px; padding: 4px 10px; font-size: .85rem; }

.summe { font-size: 1.7rem; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.summe.negativ { color: var(--blau); }
.gegeben { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.gegeben label { margin: 0; }
.gegeben input { font-size: 1.4rem; text-align: right; background: var(--gruen-hell); }
.schnell { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.schnell button { padding: 6px 2px; background: var(--gruen-hell); }
.rueckgeld { min-height: 1.6em; text-align: right; font-size: 1.3rem; font-weight: 800; }
.rueckgeld.ok { color: var(--gruen); }
.rueckgeld.fehlt { color: var(--rot); }
.bezahlt { background: var(--gruen); border-color: var(--gruen); color: #fff; min-height: 64px; font-size: 1.35rem; }

.korb-leiste, .nur-handy { display: none; }

.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 80; display: grid; place-items: center; padding: 20px; }
.overlay-box { background: var(--karte); border-radius: 20px; padding: 28px; width: min(420px, 100%); text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .4); }
.ov-titel { font-size: 1.3rem; color: var(--leise); font-weight: 700; }
.ov-wert { font-size: 3.6rem; font-weight: 900; color: var(--gruen); margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.ov-info { color: var(--leise); margin-bottom: 18px; }

/* Handy: Warenkorb als ausklappbares Feld unten */
@media (max-width: 760px) {
  .kasse { grid-template-columns: 1fr; }
  .waren { padding-bottom: 76px; }
  .raster { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .ware { min-height: 84px; }
  .ware .name { font-size: .95rem; }
  .korb {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    max-height: 88dvh; border-radius: 18px 18px 0 0; border-left: none;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, .25);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    transform: translateY(105%); transition: transform .2s ease-out;
  }
  .korb.offen { transform: none; }
  .nur-handy { display: inline-flex; }
  .korb-leiste {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    justify-content: space-between; align-items: center;
    background: var(--gruen); color: #fff; font-weight: 700; font-size: 1.1rem;
    padding: 14px 18px; padding-bottom: max(14px, env(safe-area-inset-bottom)); cursor: pointer;
  }
  .zwei { grid-template-columns: 1fr; gap: 0; }
}

/* ---------- Übersicht ---------- */

.kacheln { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 12px 0; }
.kachel { background: var(--karte); border-radius: var(--radius); box-shadow: var(--schatten); padding: 14px; border-left: 6px solid var(--leise); display: flex; flex-direction: column; }
.kachel small { color: var(--leise); font-weight: 600; }
.kachel strong { font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.kachel span { color: var(--leise); font-size: .85rem; }
.kachel.gruen { border-color: var(--gruen); } .kachel.gruen strong { color: var(--gruen); }
.kachel.orange { border-color: var(--orange); } .kachel.orange strong { color: var(--orange); }
.kachel.blau { border-color: var(--blau); } .kachel.blau strong { color: var(--blau); }

.kassensturz label { max-width: 260px; }
.differenz { font-size: 1.2rem; font-weight: 800; }
.differenz.ok { color: var(--gruen); }
.differenz.fehlt { color: var(--rot); }
.differenz.mehr { color: var(--orange); }

.tabellen { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 10px; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--linie); vertical-align: top; }
th { color: var(--leise); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
td.zahl { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.zwischensumme td { font-weight: 700; background: var(--bg); }
tr.storniert td { color: var(--leise); text-decoration: line-through; }
tr.storniert td:last-child { text-decoration: none; }
.pos-text { min-width: 180px; }
.scroll { overflow-x: auto; }
.balken-zelle { width: 40%; }
.balken { display: block; height: 12px; border-radius: 6px; background: var(--blau); min-width: 2px; }

/* ---------- Artikel bearbeiten ---------- */

.edit-liste { display: flex; flex-direction: column; gap: 8px; }
.edit-zeile {
  display: grid; align-items: center; gap: 8px;
  grid-template-columns: 70px minmax(160px, 2fr) 90px minmax(110px, 1fr) minmax(130px, 1fr) 48px auto;
  padding: 6px; border-radius: 10px; background: var(--bg);
}
.edit-zeile.pfand { grid-template-columns: minmax(160px, 1fr) 110px auto; }
.edit-zeile.inaktiv { opacity: .55; }
.edit-zeile .check { display: flex; align-items: center; gap: 6px; margin: 0; font-size: .85rem; }
.e-preis { text-align: right; }
.e-knoepfe { display: flex; gap: 4px; }
.speicher-leiste { position: sticky; bottom: 0; padding: 10px 0 max(10px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }

@media (max-width: 760px) {
  .edit-zeile { grid-template-columns: 1fr 132px; }
  .edit-zeile .check { grid-column: 1 / -1; }
  .edit-zeile .e-knoepfe { justify-content: flex-end; }
  .edit-zeile.pfand { grid-template-columns: 1fr 90px 44px; }
}
