:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f4f4f5;
  --ok: #15803d;
  --danger: #b91c1c;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --fg: #f5f5f5;
    --muted: #9ca3af;
    --line: #2a2a2a;
    --soft: #1c1c1c;
    --ok: #4ade80;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

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

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 32px);
  min-height: 100dvh;
}

h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }

input {
  font: inherit;
  color: inherit;
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  outline: none;
}
input:focus { border-color: var(--fg); }

.primary, .secondary {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  font-weight: 600;
  text-align: center;
}
.primary { background: var(--fg); color: var(--bg); }
.primary:disabled { opacity: 0.5; }
.primary.big { padding: 22px 14px; font-size: 18px; }
.secondary { border: 1px solid var(--line); width: auto; padding: 13px 18px; white-space: nowrap; }
.link { color: var(--muted); font-size: 14px; padding: 8px 4px; }
.link.danger { color: var(--danger); }

/* Login */
.login { display: grid; gap: 12px; padding-top: 18vh; }
.login h1 { font-size: 26px; margin-bottom: 2px; }
.login .muted { margin-bottom: 14px; }

.remember { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); padding: 2px 2px 6px; }
.remember input { width: 18px; height: 18px; padding: 0; accent-color: var(--fg); }

/* Kopfzeilen */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.bar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; margin: 0 -8px 16px; }
.bar h1 { font-size: 18px; text-align: center; }
.icon { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; }
.icon:active { background: var(--soft); }

/* Startseite */
.tiles { display: grid; gap: 10px; margin-top: 16px; }
.tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 18px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: left;
  font-weight: 550;
}
.tile:active { background: var(--soft); }
.badge {
  min-width: 30px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--soft);
  text-align: center;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* Listen */
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: var(--soft); border-radius: 12px; margin-bottom: 8px; }
.tab { padding: 9px; border-radius: 9px; font-size: 14px; font-weight: 550; color: var(--muted); }
.tab.on { background: var(--bg); color: var(--fg); }

.row { border-bottom: 1px solid var(--line); padding: 12px 0; }
.row-main { display: flex; align-items: center; gap: 12px; }
.row-info { flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left; }
.row-info strong { font-weight: 600; overflow-wrap: anywhere; }
.ean { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; color: var(--muted); }
.ean.big { font-size: 18px; color: var(--fg); letter-spacing: 0.04em; }
.qty { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.check {
  flex: none;
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  font-size: 20px;
  color: var(--muted);
}
.check:active { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.row.done .row-info strong { text-decoration: line-through; color: var(--muted); }
.row.done .check { border-color: transparent; background: var(--soft); }
.details { display: grid; gap: 6px; justify-items: start; padding-top: 8px; font-size: 14px; }
.details[hidden] { display: none; }
.empty { padding: 48px 0; text-align: center; color: var(--muted); }

/* Scannen */
.scan { display: grid; gap: 14px; }
.viewport { position: relative; aspect-ratio: 4 / 3; border-radius: 16px; overflow: hidden; background: #000; }
.viewport[hidden] { display: none; }
.viewport video { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame {
  position: absolute;
  inset: 28% 12%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
}
.inline { display: flex; gap: 8px; }

.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.stepper { display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; }
.stepper button { border: 1px solid var(--line); border-radius: 12px; font-size: 22px; }
.stepper button:active { background: var(--soft); }
.stepper input { text-align: center; font-weight: 650; font-size: 18px; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; font-size: 15px; }
.chip.on { background: var(--fg); border-color: var(--fg); color: var(--bg); }

/* Fotos */
[hidden] { display: none !important; }
.thumb { flex: none; width: 52px; height: 52px; border-radius: 10px; overflow: hidden; background: var(--soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; cursor: zoom-in; }
.photo-btn { width: 100%; cursor: pointer; }
.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.92);
}
.viewer img { max-width: 100%; max-height: 100dvh; object-fit: contain; }
.viewer .icon { position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 8px; color: #fff; font-size: 28px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
