/* ===========================================================
   Lager – Apple/HIG-inspiriertes Design, Light + Dark, Touch
   =========================================================== */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", "Segoe UI", Roboto, sans-serif;

  --bg:        #f2f2f7;
  --bg-elev:   #ffffff;
  --card:      rgba(255, 255, 255, 0.85);
  --bar:       rgba(249, 249, 251, 0.78);
  --text:      #1c1c1e;
  --text-2:    #6e6e73;
  --sep:       rgba(60, 60, 67, 0.12);
  --accent:    #0a84ff;
  --accent-2:  #0071e3;
  --danger:    #ff3b30;
  --ok:        #34c759;
  --warn:      #ff9f0a;
  --radius:    16px;
  --radius-sm: 11px;
  --shadow:    0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  --tap:       48px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #000000;
    --bg-elev: #1c1c1e;
    --card:    rgba(28, 28, 30, 0.82);
    --bar:     rgba(22, 22, 24, 0.8);
    --text:    #f5f5f7;
    --text-2:  #98989d;
    --sep:     rgba(84, 84, 88, 0.4);
    --accent:  #0a84ff;
    --accent-2:#409cff;
    --shadow:  0 1px 3px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 17px;
  line-height: 1.4;
}

/* ---------- Buttons / Inputs ---------- */
.btn {
  appearance: none; border: none; cursor: pointer;
  min-height: var(--tap); padding: 0 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev); color: var(--text);
  font: inherit; font-weight: 590;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: var(--shadow);
  transition: transform .08s ease, filter .15s ease, opacity .15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(10,132,255,.35); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-block   { width: 100%; }
.btn-grow    { flex: 1; }
.btn-step    { font-size: 22px; font-weight: 600; min-width: 64px; flex: 0 0 auto; }

.btn-icon {
  appearance: none; border: none; background: transparent; cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%;
  font-size: 19px; color: var(--accent); display: grid; place-items: center;
}
.btn-icon:active { background: var(--sep); }

.input {
  width: 100%; min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--sep); border-radius: var(--radius-sm);
  background: var(--bg-elev); color: var(--text); font: inherit;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,132,255,.2); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--text-2); padding-left: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100svh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--bg-elev);
  border-radius: 22px; padding: 32px 26px; box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 2px; font-size: 26px; letter-spacing: -.02em; }
.login-sub { margin: 0 0 22px; color: var(--text-2); }
.login-card .field { text-align: left; }
.login-card .btn { margin-top: 6px; }
.login-err { color: var(--danger); min-height: 20px; margin: 12px 0 0; font-size: 14px; }

/* ---------- App-Gerüst ---------- */
#app { min-height: 100svh; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--sep);
}
.appbar-title { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.appbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip {
  font-size: 13px; color: var(--text-2);
  background: var(--sep); padding: 5px 11px; border-radius: 999px;
}

.view {
  flex: 1; width: 100%; max-width: 820px; margin: 0 auto;
  padding: 16px 16px calc(96px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px;
}

.card {
  background: var(--card);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border: 1px solid var(--sep);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}

/* ---------- Tab-Leiste ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 8px 8px calc(8px + var(--safe-b));
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--sep);
}
.tab {
  appearance: none; border: none; background: none; cursor: pointer;
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-2); font-size: 11px; font-weight: 600; padding: 4px 0;
}
.tab-ico { font-size: 22px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ---------- Scanner ---------- */
.video-wrap {
  position: relative; width: 100%; aspect-ratio: 4 / 3;
  background: #000; border-radius: var(--radius-sm); overflow: hidden;
}
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 18% 12%;
  border: 3px solid rgba(255,255,255,.9); border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.25);
}
.torch-btn {
  position: absolute; top: 10px; right: 10px;
  width: 44px; height: 44px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.45); color: #fff; font-size: 20px; cursor: pointer;
  display: grid; place-items: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.torch-btn:active { transform: scale(.94); }
.torch-btn.on { background: var(--warn); }
.scan-status { text-align: center; color: var(--text-2); font-size: 14px; margin-top: 12px; }
.scan-status.err { color: var(--danger); }
.manual-row { display: flex; gap: 8px; margin-top: 12px; }
.manual-row .input { flex: 1; }

/* ---------- Artikel-Karte (Scan) ---------- */
.art-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.art-name { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.art-meta { color: var(--text-2); font-size: 14px; margin-top: 2px; }
.art-menge { font-size: 44px; font-weight: 800; letter-spacing: -.03em; min-width: 64px; text-align: right; }
.art-menge.low, .list-qty.low { color: var(--warn); }
.book-row { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.amt { text-align: center; max-width: 90px; font-size: 20px; font-weight: 600; }
.form-title { font-size: 18px; font-weight: 700; margin-bottom: 14px; }

/* ---------- Liste ---------- */
.list-toolbar { display: flex; gap: 10px; align-items: center; }
.list-toolbar .input { flex: 1; }
.list { padding: 4px 0; }
.list-row, .hist-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--sep);
}
.list-row:last-child, .hist-row:last-child { border-bottom: none; }
.list-main, .hist-main { flex: 1; min-width: 0; }
.list-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.list-qty { font-size: 22px; font-weight: 700; min-width: 42px; text-align: right; }
.empty { text-align: center; color: var(--text-2); padding: 40px 0; }

/* ---------- Historie ---------- */
.hist-delta { font-size: 18px; font-weight: 700; min-width: 48px; text-align: right; }
.hist-delta.pos { color: var(--ok); }
.hist-delta.neg { color: var(--danger); }
.hist-after { font-size: 14px; color: var(--text-2); min-width: 40px; text-align: right; }

/* ---------- Modal ---------- */
.modal-ov {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(0,0,0,.4); padding: 20px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal {
  width: 100%; max-width: 420px; background: var(--bg-elev);
  border-radius: 20px; padding: 22px; box-shadow: var(--shadow);
  max-height: 90svh; overflow: auto;
}
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.modal-actions .spacer { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg);
  padding: 12px 20px; border-radius: 999px; font-size: 15px; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; transition: opacity .25s, transform .25s; z-index: 100;
  max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-err { background: var(--danger); color: #fff; }

/* ---------- Desktop ---------- */
@media (min-width: 720px) {
  .tabbar { top: 0; bottom: auto; border-top: none; border-bottom: 1px solid var(--sep);
            max-width: 820px; margin: 0 auto; justify-content: center; gap: 40px; }
  .tab { flex: 0 0 auto; flex-direction: row; font-size: 15px; }
  .tab-ico { font-size: 18px; }
  .appbar { max-width: 820px; margin: 0 auto; }
  .view { padding-bottom: 40px; padding-top: 8px; }
  .toast { bottom: 40px; }
}
