/* =====================================================================
   Kellervorrat – Stylesheet
   Mobile-first, große Touch-Flächen, automatischer Dark Mode.
   Farben nur über die Variablen in :root ändern.
   ===================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --text: #15181d;
  --text-2: #5b6270;
  --border: #d9dde3;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --danger: #d1242f;
  --danger-bg: #fde8e8;
  --warn: #c25e00;
  --warn-bg: #fff1e0;
  --ok: #1a7f37;
  --ok-bg: #e3f5e8;
  --low: #8250df;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 14px rgba(0, 0, 0, .06);
  --radius: 14px;
  --nav-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1a1d23;
    --surface-2: #252932;
    --text: #eef0f3;
    --text-2: #a3aab6;
    --border: #333844;
    --primary: #4d93ff;
    --primary-text: #0b1020;
    --danger: #ff6b6b;
    --danger-bg: #3a1a1c;
    --warn: #ffa94d;
    --warn-bg: #3a2812;
    --ok: #57d37a;
    --ok-bg: #16301f;
    --low: #b69cff;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
[hidden] { display: none !important; }

/* ---------- App-Gerüst ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  min-height: 58px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 21px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Sync-Status: Punkt + Kurztext oben rechts (antippbar → Details) */
.sync {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 6px; border: none; background: transparent; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--ok); }
.syncing .dot { background: var(--primary); animation: pulse 1s infinite; }
.offline .dot { background: var(--warn); }
.error .dot, .auth .dot { background: var(--danger); }
.sync.offline { color: var(--warn); }
.sync.error, .sync.auth { color: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

/* Farbige Statusleiste unter der Kopfzeile mit vollem Text */
.syncbar {
  flex-basis: 100%; display: flex; align-items: center; gap: 8px; margin: 2px -4px 0; padding: 8px 12px;
  border: none; border-radius: 10px; font: inherit; font-size: 15px; font-weight: 650; text-align: left; cursor: pointer;
  background: var(--surface-2); color: var(--text);
}
.syncbar .text { flex: 1; }
.syncbar.offline { background: var(--warn-bg); color: var(--warn); }
.syncbar.error, .syncbar.auth { background: var(--danger-bg); color: var(--danger); }
.syncbar.syncing { background: var(--surface-2); color: var(--primary); }
.syncbar.synced { background: var(--ok-bg); color: var(--ok); }
.syncline { display: flex; align-items: center; gap: 10px; font-weight: 650; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.syncline.offline { background: var(--warn-bg); color: var(--warn); }
.syncline.error, .syncline.auth { background: var(--danger-bg); color: var(--danger); }
.syncline.synced { background: var(--ok-bg); color: var(--ok); }

/* Hinweis „Neue Version verfügbar – neu laden“ */
.updatebar {
  position: fixed; left: 8px; right: 8px; top: calc(env(safe-area-inset-top, 0px) + 8px); z-index: 60;
  max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px; border-radius: 14px; background: var(--primary); color: var(--primary-text);
  box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 650; font-size: 16px;
}
.updatebar .grow { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync:focus:not(:focus-visible), .syncbar:focus:not(:focus-visible) { outline: none; }
.updatebar .btn.primary { background: var(--primary-text); color: var(--primary); border-color: transparent; }
.updatebar .iconbtn { color: var(--primary-text); }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-weight: 600; max-width: 360px; }

main { flex: 1; padding: 12px 12px calc(var(--nav-h) + var(--safe-bottom) + 90px); max-width: 760px; width: 100%; margin: 0 auto; }

/* ---------- Untere Navigation ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: 1fr 1fr 84px 1fr 1fr;
  height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--text-2); font-size: 13px; font-weight: 600; position: relative;
}
.bottomnav a.active { color: var(--primary); }
.bottomnav a svg { width: 26px; height: 26px; }
/* Mittlerer Platz: heute „Neu“, später „Scannen“ */
.bottomnav .center { display: flex; align-items: center; justify-content: center; }
.bottomnav .center a {
  width: 62px; height: 62px; margin-top: -22px; border-radius: 50%;
  background: var(--primary); color: var(--primary-text); box-shadow: var(--shadow);
}
.bottomnav .center a svg { width: 30px; height: 30px; }
.navbadge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.section-title { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 18px 4px 8px; display: flex; justify-content: space-between; }
.muted { color: var(--text-2); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.empty { text-align: center; color: var(--text-2); padding: 40px 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { background: var(--danger-bg); border-color: transparent; color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 15px; }
.btn:disabled { opacity: .4; }
.iconbtn { width: 48px; height: 48px; border-radius: 12px; border: none; background: transparent; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text); }
.iconbtn svg { width: 24px; height: 24px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=number], input[type=password], input[type=date], select, textarea {
  width: 100%; min-height: 50px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-size: 17px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 15px; cursor: pointer; }
.chip.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 44px; border: none; border-radius: 9px; background: transparent; font-weight: 600; cursor: pointer; }
.seg button.active { background: var(--surface); box-shadow: var(--shadow); color: var(--primary); }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 8px; font-size: 13px; font-weight: 700; }
.tag.expired { background: var(--danger-bg); color: var(--danger); }
.tag.soon { background: var(--warn-bg); color: var(--warn); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.low { background: var(--surface-2); color: var(--low); }

/* ---------- Produktliste ---------- */
.filters { position: sticky; top: var(--top-h, 58px); z-index: 10; background: var(--bg); padding: 4px 0 2px; margin: -4px 0 4px; }
.filters .row { margin-bottom: 8px; }
.plist { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.pitem { display: flex; align-items: center; gap: 6px; padding: 10px 8px 10px 0; border-bottom: 1px solid var(--border); position: relative; }
.pitem:last-child { border-bottom: none; }
.pitem::before { content: ""; width: 5px; align-self: stretch; border-radius: 0 4px 4px 0; background: transparent; }
.pitem.expired::before { background: var(--danger); }
.pitem.soon::before { background: var(--warn); }
.pitem .info { flex: 1; min-width: 0; padding: 2px 4px 2px 8px; cursor: pointer; }
.pitem .name { font-weight: 650; font-size: 17px; overflow: hidden; text-overflow: ellipsis; }
.pitem .meta { font-size: 13.5px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 2px; }
.pitem.expired .name { color: var(--danger); }
.pitem.soon .name { color: var(--warn); }
.qtybox { display: flex; align-items: center; gap: 4px; }
.qty { min-width: 52px; text-align: center; font-weight: 750; font-size: 20px; line-height: 1.1; }
.qty small { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.pm { width: 52px; height: 52px; border-radius: 14px; border: none; font-size: 28px; font-weight: 700; cursor: pointer; background: var(--surface-2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; }
.pm.plus { background: var(--primary); color: var(--primary-text); }
.pm:disabled { opacity: .3; }
.pm:active { transform: scale(.94); }
.lowicon { color: var(--low); display: inline-flex; }
.lowicon svg { width: 16px; height: 16px; }

/* ---------- Listen allgemein ---------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.li { display: flex; align-items: center; gap: 10px; padding: 12px 14px; min-height: 60px; border-bottom: 1px solid var(--border); }
.li:last-child { border-bottom: none; }
a.li { color: inherit; text-decoration: none; }
.li .title { font-weight: 600; }
.li .sub { font-size: 14px; color: var(--text-2); }
.li.done .title { text-decoration: line-through; color: var(--text-2); }
.check { width: 30px; height: 30px; flex: none; accent-color: var(--primary); }

/* ---------- Toast / Rückgängig ---------- */
.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); z-index: 50;
  max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 16px; border-radius: 14px; background: #23272f; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: toastin .18s ease-out;
}
.toast .msg { flex: 1; font-size: 15.5px; }
.toast .btn { background: transparent; border: none; color: #8ab8ff; min-height: 44px; }
.toast.error { background: #6e1b1b; }
@keyframes toastin { from { transform: translateY(20px); opacity: 0; } }

/* ---------- Dialoge ---------- */
dialog {
  border: none; border-radius: 20px; padding: 0; width: min(520px, calc(100vw - 24px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog .dhead { padding: 18px 18px 6px; font-size: 19px; font-weight: 700; }
dialog .dbody { padding: 8px 18px; max-height: 65vh; overflow: auto; }
dialog .dactions { display: flex; gap: 10px; padding: 12px 18px 18px; justify-content: flex-end; flex-wrap: wrap; }
dialog .dactions .btn { flex: 1; }

/* ---------- Login ---------- */
.center-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.center-screen .logo { width: 96px; height: 96px; margin-bottom: 12px; }
.center-screen h1 { margin: 0 0 6px; }
.center-screen form, .center-screen .members { width: 100%; max-width: 360px; margin-top: 20px; }
.pin { text-align: center; font-size: 28px !important; letter-spacing: .3em; }
.err { color: var(--danger); min-height: 24px; margin: 8px 0; font-weight: 600; }

/* ---------- Detail ---------- */
.bigstock { font-size: 40px; font-weight: 800; line-height: 1; }
.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15.5px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }
.batchrow { display: grid; grid-template-columns: 1fr 1.3fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.batchrow input { min-height: 46px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (min-width: 700px) {
  main { padding-top: 18px; }
}

/* Icons in Knöpfen und Listen */
.ic { display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ic svg { width: 22px; height: 22px; }
.li > .ic svg { color: var(--text-2); }
