:root {
  color-scheme: light dark;
  --bg: #fbf8f5;
  --fg: #2a1f22;
  --muted: #7a6a6e;
  --accent: #5b1a2b;
  --accent-fg: #ffffff;
  --card: #ffffff;
  --line: #e6dcdf;
  --ok: #2e7d32;
  --err: #b3261e;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171214;
    --fg: #f1e9eb;
    --muted: #a8979c;
    --accent: #c0485f;
    --card: #221a1d;
    --line: #3a2f33;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--accent);
  color: var(--accent-fg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { color: inherit; text-decoration: none; font-weight: 600; font-size: 1.1rem; }

.nav { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; font-size: 0.95rem; }
.nav a { color: inherit; text-decoration: none; opacity: 0.9; }
.nav a.active { text-decoration: underline; opacity: 1; }

.app { flex: 1; padding: 16px; max-width: 720px; width: 100%; margin: 0 auto; }

.footer {
  padding: 8px 16px calc(var(--safe-bottom) + 8px);
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

h1, h2 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 8px; line-height: 1.45; }

label { display: block; font-size: 0.9rem; margin: 10px 0 4px; color: var(--muted); }

input, button {
  font: inherit;
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
}

button {
  margin-top: 14px;
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: default; }

.error { color: var(--err); font-size: 0.9rem; margin-top: 8px; }
.hint { color: var(--muted); font-size: 0.85rem; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 10px; }
.table th, .table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; }
.table a { color: var(--accent); }
a { color: var(--accent); }

/* ---------- Phase 1: Keller ---------- */

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row h1 { margin: 0; }
.row input[type="search"] { flex: 1; min-width: 0; }
.row select { width: auto; max-width: 60%; }
.actions { margin-top: 10px; font-size: 0.9rem; }
.actions .inline { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-size: 0.9rem; }
.actions .inline input { width: auto; }
.toolbar form { margin-top: 10px; }

button.small, .button { margin-top: 0; width: auto; padding: 8px 14px; font-size: 0.9rem; }
.button { display: inline-block; background: var(--accent); color: var(--accent-fg); border-radius: var(--radius); text-decoration: none; }

.layout { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 760px) {
  .layout { grid-template-columns: 220px 1fr; align-items: start; }
  .app { max-width: 960px; }
}

.facets { display: flex; flex-direction: column; gap: 6px; }
.facet { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px; }
.facet summary { cursor: pointer; font-size: 0.9rem; font-weight: 600; padding: 6px 0; list-style: none; }
.facet summary::-webkit-details-marker { display: none; }
.facet summary::before { content: "▸ "; color: var(--muted); }
.facet[open] summary::before { content: "▾ "; }
.facet ul { list-style: none; margin: 0 0 6px; padding: 0; max-height: 240px; overflow: auto; }
.facet li label { display: flex; align-items: center; gap: 8px; margin: 2px 0; padding: 4px 0; font-size: 0.9rem; color: var(--fg); cursor: pointer; }
.facet li input { width: auto; margin: 0; }
.facet li span:first-of-type { flex: 1; }
.facet .count { color: var(--muted); font-size: 0.8rem; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: block; text-decoration: none; color: inherit; margin: 0; border-left: 4px solid var(--line); }
.item:active { opacity: 0.8; }
.type-red { border-left-color: #8b1a2b; }
.type-white { border-left-color: #d9c36a; }
.type-rose { border-left-color: #e8a0b0; }
.type-sparkling { border-left-color: #c9b36a; }
.type-sweet { border-left-color: #c47a1d; }
.type-fortified { border-left-color: #5c3a21; }
.item-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; margin-bottom: 4px; }
.badge { background: var(--line); border-radius: 999px; padding: 2px 8px; font-size: 0.75rem; }
.bottles { font-weight: 600; }
.item-title { font-weight: 600; }
.item-name { margin: 0; }
.year { color: var(--muted); margin-left: 6px; }
.muted { color: var(--muted); }
.item-meta { font-size: 0.85rem; color: var(--muted); margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.rating { color: var(--fg); font-weight: 600; }
.warn { color: #b05a00; font-weight: 600; }

.facts th { width: 110px; }
.grid2, .grid3 { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr 1fr; } }
select, textarea { font: inherit; width: 100%; padding: 11px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); color: var(--fg); }
.sub { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 8px; }
.sub button { width: auto; display: inline-block; }
.sub a { margin-left: 10px; }
h2.section { margin-top: 16px; }
.more summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; margin-top: 10px; }

.stock-row, .rating-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.stock-row:first-of-type, .rating-row:first-of-type { border-top: 0; }
.stock-actions { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; white-space: nowrap; }
.stock-actions button { margin: 0; }

.tree { list-style: none; padding: 0; margin: 0 0 10px; }
.tree li { padding: 6px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tree li a:first-child { font-weight: 500; }
.tree .depth-1 { padding-left: 18px; }
.tree .depth-2 { padding-left: 36px; }
.tree .depth-3 { padding-left: 54px; }
.tree .depth-4 { padding-left: 72px; }

/* ---------- Offline / Sync ---------- */
.banner { background: #fff3e0; color: #6b3d00; border: 1px solid #f0c48a; border-radius: var(--radius); padding: 8px 12px; font-size: 0.9rem; margin: 0 0 10px; }
@media (prefers-color-scheme: dark) { .banner { background: #3a2a10; color: #f5d9a8; border-color: #6b4a1a; } }
.banner a { color: inherit; }
.footer a { color: inherit; }

/* ---------- Scanner ---------- */
.camera { position: relative; width: 100%; aspect-ratio: 4 / 3; background: #000; border-radius: var(--radius); overflow: hidden; margin: 8px 0; }
.camera video { width: 100%; height: 100%; object-fit: cover; }
.camera-frame { position: absolute; left: 10%; right: 10%; top: 35%; bottom: 35%; border: 2px solid rgba(255,255,255,0.8); border-radius: 8px; pointer-events: none; }
.qty { width: 70px; display: inline-block; padding: 6px 8px; margin-left: 6px; }
button.secondary { background: var(--card); color: var(--accent); }

/* ---------- Fotos ---------- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px; }
label.button { margin: 8px 0; color: var(--accent-fg); cursor: pointer; padding: 10px 16px; }
label.link { display: inline; color: var(--accent); text-decoration: underline; cursor: pointer; margin: 0; font-size: inherit; }
.photo-preview { display: block; max-width: 100%; max-height: 50vh; border-radius: var(--radius); margin: 8px 0; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.photos img { width: 96px; height: 128px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
label.button.small { margin: 0; padding: 8px 14px; font-size: 0.9rem; }
#camera-tools select { max-width: 100%; padding: 8px 10px; }
#camera-tools input[type="range"] { width: 130px; padding: 0; }

/* ---------- Keller teilen ---------- */
.stock-actions select { width: auto; padding: 6px 8px; font-size: 0.85rem; }
