/* Kassen-App - modernes, dunkles Standard-Theme mit hellem Fallback */

:root {
  --bg: #0b1220;
  --bg-elev: #141d2f;
  --bg-elev2: #1c2740;
  --text: #eef2f9;
  --muted: #9aa8c0;
  --line: #26324a;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --ok: #16a34a;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 78px;
  --shadow: 0 18px 40px rgba(0, 0, 0, .45);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f1f5fa;
    --bg-elev: #ffffff;
    --bg-elev2: #eaeff8;
    --text: #0f172a;
    --muted: #5b6b85;
    --line: #d8e0ee;
    --shadow: 0 14px 32px rgba(15, 23, 42, .16);
  }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; touch-action: manipulation; }

body {
  height: 100vh;      /* Fallback fuer Browser ohne dvh-Unterstuetzung */
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

/* Kein Text-Auswaehlen / Callout beim langen Druecksen auf Bedienelementen */
button, .kachel, .schein {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

/* ------------------------------------------------------------------ Kopfzeile */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.brand-text { font-size: 17px; letter-spacing: .2px; }

.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 10px;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 17px; font-weight: 800;
}

.topbar-aktionen { display: flex; align-items: center; gap: 8px; }

.chip-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-elev2);
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
}
.chip-btn .icon { width: 18px; height: 18px; }
.chip-btn span { color: var(--muted); }
.chip-btn b { font-variant-numeric: tabular-nums; }
.chip-btn:active { transform: scale(.97); }

.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-elev2);
  color: var(--text); cursor: pointer;
  transition: transform .12s, background .12s;
}
.icon-btn:active { transform: scale(.95); }
.icon-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn:disabled { opacity: .4; cursor: default; }

/* ------------------------------------------------------------------ Editierleiste */

.editbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: calc(12px + var(--safe-t)) 14px 10px;
  background: var(--bg-elev2);
  border-bottom: 1px solid var(--line);
}
.editbar-hinweis {
  margin-right: auto;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--accent);
}

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

.btn-primary {
  padding: 14px 18px; border: 0; border-radius: 14px;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #fff; font: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform .1s, filter .12s;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .45; cursor: default; }
.btn-primary.gross { width: 100%; padding: 16px; }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: transparent;
  color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
}
.btn-ghost .icon { width: 18px; height: 18px; }
.btn-ghost:active { transform: scale(.97); }
.btn-ghost.gefahr { color: var(--danger); border-color: rgba(239, 68, 68, .45); }
.btn-ghost.breit { width: 100%; margin-top: 10px; }

/* ------------------------------------------------------------------ Produktraster */

.raster {
  overflow-y: auto;
  /* Die Kategoriebloecke ueber die volle Hoehe verteilen. Sind es zu viele
     Produkte, greift space-between nicht mehr und das Raster scrollt. */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 14px calc(20px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}

.kat-block { margin-bottom: 22px; }
.kat-block:last-child { margin-bottom: 6px; }

.kat-titel {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 10px;
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
}
.kat-punkt { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }

.kat-grid {
  display: grid;
  gap: 12px;
  /* Grundraster ohne JS; wird per JS exakt auf den Bildschirm gerechnet. */
  grid-template-columns: repeat(auto-fill, minmax(clamp(96px, 13vw, 176px), 1fr));
  grid-auto-rows: clamp(78px, 11vh, 140px);
}

/* Nach der Berechnung in app.js: Spalten und Zeilenhoehe fuellen die Flaeche.
   Zu viele Produkte -> Mindesthoehe, das Raster scrollt. */
#raster[data-layout="berechnet"] .kat-grid {
  grid-template-columns: repeat(var(--spalten), minmax(0, 1fr));
  grid-auto-rows: var(--reihe);
}

.kachel {
  position: relative;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  min-height: var(--tap); padding: 12px;
  border-radius: var(--radius);
  /* Farbton als Overlay (::before) statt color-mix(): color-mix() fehlt in
     aelteren Safari-Versionen (iPad < 16.2), dort fehlten die Kaesten ganz. */
  border: 1px solid var(--farbe, var(--line));
  background: var(--bg-elev);
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: transform .1s, background .12s;
}

.kachel::before {
  content: "";
  position: absolute; inset: 0; z-index: 0;
  border-radius: inherit;
  background: var(--farbe, transparent);
  opacity: .22;
  pointer-events: none;
}

.kachel > * { position: relative; z-index: 1; }

.kachel:active { transform: scale(.96); }
.kachel-name { font-size: 15px; font-weight: 600; line-height: 1.25; word-break: break-word; }
.kachel-preis { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

.kachel-badge {
  position: absolute; top: -8px; right: -8px; z-index: 2;
  display: grid; place-items: center;
  min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700; box-shadow: var(--shadow);
}

.kachel-edit {
  position: absolute; right: 9px; bottom: 9px;
  width: 18px; height: 18px; opacity: .6;
}

.kachel-inaktiv { opacity: .5; }

.kachel-neu {
  justify-content: center; align-items: center; gap: 6px;
  border-style: dashed; border-color: rgba(37, 99, 235, .6);
  background: transparent; color: var(--accent); font-weight: 700;
}
.kachel-neu::before { display: none; }
.kachel-neu .icon { width: 26px; height: 26px; }

.leer {
  padding: 40px 20px; text-align: center;
  color: var(--muted); font-size: 15px; line-height: 1.5;
}

/* ------------------------------------------------------------------ Untere Leiste */

.bottom {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
}

.bottom-summe { display: flex; flex-direction: column; align-items: flex-end; min-width: 0; line-height: 1.15; }
.bottom-label {
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.bottom-wert { font-size: 24px; font-variant-numeric: tabular-nums; }

@media (max-width: 400px) {
  .bottom { gap: 8px; }
  .bottom-wert { font-size: 20px; }
  .bottom .btn-primary { padding: 14px 12px; }
}

/* ------------------------------------------------------------------ Sheets */

.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(4, 8, 16, .6); }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; flex-direction: column;
  max-height: 92vh;
  max-height: 92dvh;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
  animation: sheet-rein .18s ease-out;
}

@keyframes sheet-rein {
  from { opacity: .3; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 760px) {
  .sheet {
    width: min(600px, 92vw);
    left: 0; right: 0; bottom: 20px;
    margin-inline: auto;
    border-radius: 22px;
    border: 1px solid var(--line);
    max-height: 86vh;
    max-height: 86dvh;
  }
}

.sheet-kopf {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.sheet-kopf h2 { margin: 0; font-size: 17px; }

.sheet-body { flex: 1; overflow-y: auto; padding: 16px; }
.sheet-fuss { padding: 12px 16px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); }

/* Waehrend einer laufenden Anfrage (z. B. Abschluss) keine Eingaben annehmen,
   damit nichts unbemerkt verworfen wird. */
.sheet[aria-busy="true"] { pointer-events: none; }
.sheet[aria-busy="true"] .sheet-body,
.sheet[aria-busy="true"] .sheet-fuss { opacity: .55; }

.sheet-abschnitt {
  margin: 22px 0 10px;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
}

.hinweis { margin: 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.hinweis.fehler { margin-top: 6px; color: var(--danger); }

/* Kassenzähler */

.kassenzeilen { display: grid; gap: 8px; }

.kassenzeile {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm); background: var(--bg-elev2);
}
.kassenzeile span { font-size: 14px; color: var(--muted); }
.kassenzeile strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.kassenzeile-rueck strong { font-size: 28px; color: var(--ok); }
.kassenzeile-rueck.negativ strong { color: var(--danger); }
.kassenzeile-rueck.neutral strong { color: var(--muted); }

/* Schein-Kacheln */

.scheine { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 12px; }

.schein {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 80px; border-radius: var(--radius);
  border: 1px solid rgba(22, 163, 74, .45);
  background: rgba(22, 163, 74, .16);
  color: var(--text); font: inherit; font-weight: 700; font-size: 19px;
  font-variant-numeric: tabular-nums; cursor: pointer; user-select: none;
  touch-action: manipulation; transition: transform .1s;
}
.schein:active { transform: scale(.96); }
.schein span { font-size: 11px; font-weight: 600; color: var(--muted); }

.schein-badge {
  position: absolute; top: -8px; right: -8px; z-index: 1;
  display: grid; place-items: center;
  min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px;
  background: var(--ok); color: #fff; font-size: 13px; font-weight: 700;
}

/* Positionen */

.positionen { display: grid; gap: 6px; list-style: none; margin: 0; padding: 0; }
.positionen:empty::after {
  content: "Noch keine Positionen.";
  padding: 12px; border-radius: var(--radius-sm); background: var(--bg-elev2);
  color: var(--muted); font-size: 14px;
}

.position {
  display: grid; grid-template-columns: 1fr auto auto auto auto;
  align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm); background: var(--bg-elev2);
}
.position-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.position-menge { min-width: 32px; text-align: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.position-summe { min-width: 66px; text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; }
.position .icon-btn { width: 34px; height: 34px; border-radius: 10px; }
.position .icon-btn .icon { width: 16px; height: 16px; }

/* Formulare */

.form { display: grid; gap: 14px; }

.feld { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.feld > span { font-weight: 600; }

.feld input[type="text"], .feld select, .form-inline input {
  width: 100%; padding: 12px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg-elev2); color: var(--text); font: inherit; font-size: 16px;
}

.feld-reihe { grid-auto-flow: column; align-items: center; justify-content: space-between; }
.reihenfolge { display: flex; align-items: center; gap: 10px; }
.reihenfolge output { min-width: 26px; text-align: center; font-size: 15px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

.schalter { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text); }
.schalter input { width: 20px; height: 20px; accent-color: var(--accent); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 34px; height: 34px; padding: 0; border-radius: 10px;
  border: 2px solid transparent; cursor: pointer;
}
.swatch.aktiv { border-color: var(--text); }

.form-aktionen { display: flex; gap: 10px; margin-top: 4px; }
.form-aktionen .btn-primary { flex: 1; }

.form-inline { display: flex; gap: 8px; }
.form-inline input { flex: 1; }
.form-inline .btn-primary { padding: 12px 14px; font-size: 15px; white-space: nowrap; }

/* Kategorien-Verwaltung */

.kat-liste { display: grid; gap: 8px; list-style: none; margin: 14px 0 0; padding: 0; }
.kat-eintrag {
  display: grid; grid-template-columns: auto 1fr auto auto auto;
  align-items: center; gap: 8px;
  padding: 8px; border-radius: var(--radius-sm); background: var(--bg-elev2);
}
.kat-eintrag input {
  width: 100%; padding: 9px 11px; font-size: 15px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--text); font-family: inherit;
}
.kat-eintrag .icon-btn { width: 36px; height: 36px; border-radius: 10px; }
.kat-eintrag .icon-btn .icon { width: 17px; height: 17px; }

/* Statistik */

.segment { display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: var(--bg-elev2); }
.segment button {
  flex: 1; padding: 10px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.segment button.aktiv { background: var(--accent); color: #fff; }

.stat-karten { display: grid; grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); gap: 10px; margin-top: 16px; }
.stat-karte { padding: 14px; border-radius: var(--radius-sm); background: var(--bg-elev2); }
.stat-karte span { display: block; font-size: 12px; color: var(--muted); }
.stat-karte strong { font-size: 22px; font-variant-numeric: tabular-nums; }

.stat-liste { display: grid; gap: 6px; list-style: none; margin: 10px 0 0; padding: 0; }
.stat-zeile {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 10px; background: var(--bg-elev2); font-size: 14px;
}
.stat-zeile b { font-variant-numeric: tabular-nums; }

/* Toast */

.toast {
  position: fixed; left: 50%; z-index: 60;
  bottom: calc(100px + var(--safe-b));
  transform: translateX(-50%);
  max-width: min(92vw, 440px);
  padding: 12px 16px; border-radius: 14px;
  background: var(--bg-elev2); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px; text-align: center;
  animation: toast-rein .16s ease-out;
}
.toast.ok { border-color: rgba(22, 163, 74, .6); }
.toast.fehler { border-color: rgba(239, 68, 68, .6); }

@keyframes toast-rein {
  from { opacity: 0; }
  to { opacity: 1; }
}
