:root {
  --bg: #eef3f7;
  --card: #ffffff;
  --ink: #0f1a24;
  --muted: #5b6b7a;
  --line: #dde5ec;
  --accent: #1d6fa5;
  --accent-ink: #ffffff;
  --accent-soft: #dcebf6;
  --ok: #2f8f63;
  --ok-soft: #e1f3ea;
  --soon: #b7790a;
  --soon-soft: #fbf0d9;
  --over: #c9384f;
  --over-soft: #fbe3e7;
  --shadow: 0 1px 2px rgba(15, 26, 36, .06), 0 4px 14px rgba(15, 26, 36, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e151c;
    --card: #17212b;
    --ink: #e7eef4;
    --muted: #93a4b4;
    --line: #26333f;
    --accent: #5aa9e0;
    --accent-ink: #08131c;
    --accent-soft: #1b3346;
    --ok: #5cc490;
    --ok-soft: #173327;
    --soon: #e6ac3c;
    --soon-soft: #3a2d12;
    --over: #f0708a;
    --over-soft: #3d1a22;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Kopf */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto; }
.top h1 { font-size: 22px; letter-spacing: -.02em; margin: 0; flex: 1; display: flex; align-items: center; gap: 8px; }
.top h1 svg { width: 24px; height: 24px; color: var(--accent); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

.search { margin-top: 10px; position: relative; }
.search input {
  width: 100%; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); padding: 0 12px 0 38px; outline: none;
}
.search input:focus { border-color: var(--accent); }
.search svg { position: absolute; left: 12px; top: 11px; width: 20px; height: 20px; color: var(--muted); }

.filters { display: flex; gap: 8px; overflow-x: auto; margin: 10px -16px 0; padding: 0 16px 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters select {
  flex: 0 0 auto; height: 34px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); padding: 0 28px 0 12px; font-size: 14px; max-width: 220px;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.filters select.active { border-color: var(--accent); background-color: var(--accent-soft); }

/* ---------- Zusammenfassung */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 6px; }
.stat {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 8px 10px; text-align: left; cursor: pointer;
}
.stat b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.soon b { color: var(--soon); }
.stat.over b { color: var(--over); }
.stat.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

.list-head { display: flex; justify-content: space-between; align-items: center; margin: 12px 2px 6px; font-size: 13px; color: var(--muted); }
.list-head select { border: none; background: none; color: var(--accent); font-size: 13px; padding: 0; }

/* ---------- Karten */
.list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 110px; }
.card {
  display: grid; grid-template-columns: 58px 1fr auto; gap: 12px; align-items: center;
  background: var(--card); border-radius: var(--radius); padding: 10px 12px 10px 10px;
  box-shadow: var(--shadow); cursor: pointer; border-left: 4px solid var(--ok);
  text-align: left; border-top: 0; border-right: 0; border-bottom: 0; width: 100%;
}
.card.soon { border-left-color: var(--soon); }
.card.over { border-left-color: var(--over); }
.thumb {
  width: 58px; height: 58px; border-radius: 10px; background: var(--accent-soft);
  object-fit: cover; display: grid; place-items: center; color: var(--accent); overflow: hidden;
}
.thumb svg { width: 26px; height: 26px; opacity: .7; }
.card .t { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .s { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .main { min-width: 0; }
.qty { font-weight: 600; font-variant-numeric: tabular-nums; }
.badge {
  font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 999px; white-space: nowrap;
  background: var(--ok-soft); color: var(--ok);
}
.badge.soon { background: var(--soon-soft); color: var(--soon); }
.badge.over { background: var(--over-soft); color: var(--over); }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

/* ---------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--over); }
.btn.small { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; }

.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 20;
  width: 60px; height: 60px; border-radius: 20px; border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px rgba(29, 111, 165, .4);
  display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; }

/* ---------- Sheet */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 14, 20, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 600px; max-height: 94vh; max-height: 94dvh;
  overflow-y: auto; border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out; overscroll-behavior: contain;
}
@media (min-width: 640px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 20px; max-height: 88vh; }
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.grip { width: 40px; height: 5px; background: var(--line); border-radius: 3px; margin: 2px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 20px; letter-spacing: -.01em; }

/* ---------- Formulare */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px 2px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); padding: 10px 12px; outline: none; font-size: 16px;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field small { display: block; font-size: 12px; color: var(--muted); margin: 4px 2px 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.qty-row { grid-template-columns: 1.3fr 1fr; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1; }

.photo-pick {
  display: grid; grid-template-columns: 110px 1fr; gap: 12px; align-items: center; margin-bottom: 14px;
}
.photo-pick .pv {
  width: 110px; height: 110px; border-radius: 14px; background: var(--accent-soft);
  object-fit: cover; display: grid; place-items: center; color: var(--accent); overflow: hidden;
}
.photo-pick .pv svg { width: 34px; height: 34px; opacity: .6; }
.photo-pick .pv img { width: 100%; height: 100%; object-fit: cover; }
.photo-pick .btns { display: flex; flex-direction: column; gap: 8px; }
.photo-pick label.btn { position: relative; }
.photo-pick input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- Detail */
.hero { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 16px; background: var(--accent-soft); display: block; margin-bottom: 12px; }
.facts { background: var(--card); border-radius: var(--radius); padding: 4px 14px; box-shadow: var(--shadow); }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.facts div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-weight: 500; }
.take {
  background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; box-shadow: var(--shadow);
}
.take h3 { margin: 0 0 8px; font-size: 15px; }
.take .tr { display: flex; gap: 8px; }
.take input { flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; font-size: 16px; }
.take .unit { align-self: center; color: var(--muted); min-width: 34px; }
.note-box { margin-top: 12px; padding: 12px 14px; background: var(--card); border-radius: var(--radius); white-space: pre-wrap; font-size: 15px; box-shadow: var(--shadow); }
.btn-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }

/* ---------- Einstellungen */
.section { margin: 18px 0; }
.section > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 4px 8px; font-weight: 600; }
.group { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.li {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; cursor: pointer;
}
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .sub { font-size: 13px; color: var(--muted); }
.li .cnt { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.li.loc { background: var(--accent-soft); font-weight: 600; }
.li.indent { padding-left: 30px; }
.li.add { color: var(--accent); font-weight: 600; }
.li svg { width: 18px; height: 18px; color: var(--muted); flex: 0 0 auto; }
.info { font-size: 14px; color: var(--muted); padding: 12px 14px; }
.info b { color: var(--ink); }

/* ---------- Login */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; text-align: center; }
.login svg { width: 54px; height: 54px; color: var(--accent); }
.login h1 { margin: 10px 0 20px; }
.login .field input { text-align: center; }
.login .btn { width: 100%; }
.err { color: var(--over); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* ---------- Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: all .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- Tags */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.chips:empty { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--accent);
  border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.tagtxt { color: var(--accent); }
.tagbar { margin-top: 8px; }
.tagbar .chip { flex: 0 0 auto; }
.chip small { color: var(--muted); font-weight: 400; margin-left: 2px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on small { color: inherit; opacity: .8; }
.chip.clear { color: var(--over); }
