:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dce0e8;
  --text: #171a20;
  --muted: #666e7d;
  --accent: #0f766e;
  --accent-soft: #d7efec;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --danger-soft: #fbe4e2;
  --warn: #8a5a00;
  --warn-soft: #fdf0d5;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 4px 16px rgba(16, 20, 30, .05);
  --radius: 14px;
  --tap: 44px;
  --nav-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101318;
    --surface: #191d24;
    --surface-2: #212630;
    --border: #2c323d;
    --text: #e9ecf1;
    --muted: #9aa3b2;
    --accent: #2dd4bf;
    --accent-soft: #16302f;
    --accent-text: #04211e;
    --danger: #ff8a80;
    --danger-soft: #3a1f1d;
    --warn: #f2c14e;
    --warn-soft: #352b12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
body.selecting { padding-bottom: calc(var(--nav-h) + 76px + env(safe-area-inset-bottom)); }
body.no-nav { padding-bottom: 0; }

#app { max-width: 720px; margin: 0 auto; }

/* --- Kopfzeile ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 12px 0;
}
.topbar-row {
  display: flex; align-items: center; gap: 8px;
  min-height: 52px; max-width: 720px; margin: 0 auto;
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; font-weight: 650; letter-spacing: -.01em; }
.topbar .sub { font-size: .78rem; color: var(--muted); font-weight: 400; display: block; }

main { padding: 12px; max-width: 720px; margin: 0 auto; }

/* --- Bedienelemente ----------------------------------------------------- */
button, .btn {
  font: inherit; font-weight: 550;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  text-decoration: none;
  transition: filter .12s, background .12s;
}
button:active, .btn:active { filter: brightness(.94); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--danger-soft); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; border-radius: 9px; }
.btn-icon { min-width: var(--tap); padding: 8px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > * { flex: 1 1 0; min-width: 120px; }
.btn-row svg { width: 17px; height: 17px; }

input, select, textarea {
  font: inherit; width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
textarea { min-height: 84px; resize: vertical; }
label { display: block; font-size: .82rem; color: var(--muted); margin: 0 0 5px 2px; font-weight: 550; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

/* --- Karten ------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; font-weight: 650; }

/* --- Suche und Filter --------------------------------------------------- */
.search { position: relative; margin-bottom: 10px; }
.search input { padding-left: 40px; border-radius: 12px; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 36px; padding: 6px 14px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted);
  font-size: .87rem; font-weight: 550; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* --- Artikelliste ------------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 8px; }
a { color: var(--accent); }
.item {
  display: flex;
  color: inherit; text-decoration: none; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; text-align: left; width: 100%;
  box-shadow: var(--shadow); min-height: 68px;
}
.thumb {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 10px; object-fit: cover;
  background: var(--surface-2); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 650; overflow: hidden;
}
.item-body { flex: 1; min-width: 0; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { font-size: .8rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.item-total { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.item-total small { display: block; font-size: .7rem; color: var(--muted); font-weight: 500; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); border-radius: 6px;
  padding: 1px 7px; font-size: .76rem; color: var(--muted); font-weight: 550;
}
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }

/* --- Detailansicht ------------------------------------------------------ */
.hero { display: flex; gap: 14px; align-items: flex-start; }
.hero-img {
  width: 108px; height: 108px; flex: 0 0 108px; border-radius: 12px;
  object-fit: cover; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.hero h2 { margin: 0 0 4px; font-size: 1.3rem; letter-spacing: -.015em; }
.hero .btn-row > * { min-width: 0; font-size: .8rem; white-space: nowrap; }

.stock-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--border);
}
.stock-row:last-child { border-bottom: 0; }
.stock-name { font-weight: 550; }
.stock-qty { font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stock-qty small { font-size: .75rem; color: var(--muted); font-weight: 500; margin-left: 3px; }

/* --- Mengensteller ------------------------------------------------------ */
.stepper { display: flex; align-items: stretch; gap: 8px; }
.stepper button { flex: 0 0 52px; font-size: 1.35rem; font-weight: 400; }
.stepper input { text-align: center; font-size: 1.15rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* --- Historie ----------------------------------------------------------- */
.move { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.move:last-child { border-bottom: 0; }
.move-icon {
  flex: 0 0 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--muted); font-size: .95rem;
}
.move-in { background: var(--accent-soft); color: var(--accent); }
.move-out { background: var(--danger-soft); color: var(--danger); }
.move-body { flex: 1; min-width: 0; font-size: .9rem; }
.move-meta { font-size: .76rem; color: var(--muted); margin-top: 2px; }

/* --- Navigation --------------------------------------------------------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: .68rem; font-weight: 600;
}
.nav a[aria-current="page"] { color: var(--accent); }
.nav svg { width: 22px; height: 22px; }

/* --- Zustaende ---------------------------------------------------------- */
.empty { text-align: center; color: var(--muted); padding: 44px 20px; }
.empty svg { opacity: .35; margin-bottom: 10px; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 11px; padding: 10px 12px; font-size: .88rem; margin-bottom: 12px; }
.hint { font-size: .82rem; color: var(--muted); margin: 6px 2px 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 999px; font-size: .88rem; font-weight: 550;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 60;
  animation: rise .2s ease-out;
  max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

/* --- Login -------------------------------------------------------------- */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { width: 100%; max-width: 360px; }
.login .logo {
  width: 58px; height: 58px; border-radius: 16px; background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
}
.login h1 { text-align: center; font-size: 1.35rem; margin: 0 0 22px; }

/* --- Dialog ------------------------------------------------------------- */
dialog {
  border: 0; border-radius: 18px 18px 0 0; padding: 0;
  background: var(--surface); color: var(--text);
  width: 100%; max-width: 560px; margin: auto auto 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(8, 10, 14, .5); backdrop-filter: blur(2px); }
.sheet { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet h3 { margin: 0 0 14px; font-size: 1.08rem; }
.sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--border); margin: 9px auto 4px; }

@media (min-width: 640px) {
  dialog { border-radius: 18px; margin: auto; }
  main { padding: 18px 12px 32px; }
}

.spinner {
  width: 22px; height: 22px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.nowrap { white-space: nowrap; }

/* --- Farbcodes ---------------------------------------------------------- */
.dot {
  display: inline-block; flex: 0 0 auto;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--dot); border: 1px solid rgba(0, 0, 0, .18);
  vertical-align: -2px;
}

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 40px; height: 40px; min-height: 40px; padding: 0;
  border-radius: 50%; background: var(--dot);
  border: 2px solid var(--border);
}
.swatch[aria-pressed="true"] {
  border-color: var(--text);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--text);
}
.swatch-none { background: var(--surface-2); color: var(--muted); font-size: 1.1rem; }

/* Farbring um das Vorschaubild, damit die Farbe in der Liste sofort auffaellt. */
.thumb-color { box-shadow: inset 0 0 0 3px var(--dot); padding: 3px; background: var(--dot); }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: block; }
.thumb-letter { font-size: 1.1rem; font-weight: 650; }
.thumb-color .thumb-letter { color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .35); }

.ident {
  font-weight: 500; color: var(--muted); font-size: .85rem;
  background: var(--surface-2); border-radius: 5px; padding: 0 5px;
}
/* "Wer hat wann bewegt" steht einzeilig unter dem Namen. */
.item-meta.one-line { flex-wrap: nowrap; overflow: hidden; }
.item-place { font-size: .84rem; font-weight: 600; text-align: right; flex: 0 0 auto; max-width: 34%; }

/* --- Mehrfachauswahl ---------------------------------------------------- */
.checkbox {
  flex: 0 0 22px; width: 22px; height: 22px; border-radius: 7px;
  border: 2px solid var(--border); display: flex; align-items: center; justify-content: center;
  color: var(--accent-text);
}
.checkbox.on { background: var(--accent); border-color: var(--accent); }
.item-selected { border-color: var(--accent); background: var(--accent-soft); }

.actionbar {
  position: fixed; left: 8px; right: 8px;
  bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom));
  z-index: 40; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: 0 6px 26px rgba(0, 0, 0, .18);
  max-width: 704px; margin: 0 auto;
}
.actionbar .btn-row { flex: 1; }
.actionbar .btn-row > * { min-width: 0; }

/* --- Standortkarte ------------------------------------------------------ */
.place-card { text-align: center; }
.place { font-size: 1.6rem; font-weight: 700; margin: 2px 0 6px; letter-spacing: -.02em; }

/* --- Benachrichtigungen ------------------------------------------------- */
.bell { position: relative; flex: 0 0 auto; color: var(--muted); }
.bell .badge {
  position: absolute; top: 4px; right: 2px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: .66rem; font-weight: 700; line-height: 17px; text-align: center;
  border: 2px solid var(--bg); box-sizing: content-box;
}
.move.unread { background: var(--accent-soft); border-radius: 10px; padding-left: 8px; padding-right: 8px; }
.move .move-icon svg { width: 17px; height: 17px; }
