:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2522;
  --muted: #6b7773;
  --line: #e1e7e4;
  --accent: #1f8a5b;
  --accent-soft: #e3f3eb;
  --warn: #b26a00;
  --warn-soft: #fff3df;
  --danger: #c0392b;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121715; --card: #1b2220; --text: #e6ece9; --muted: #95a39e; --line: #2c3633;
    --accent: #3dbb83; --accent-soft: #1d3a2d; --warn: #f0a83a; --warn-soft: #3a2d17; --danger: #ef6b5d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin-bottom: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85em; }
.muted { color: var(--muted); }

button, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost-danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 0; font-weight: 600; white-space: normal; text-align: left; }
input {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 9px 11px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--card); }
label { display: block; font-weight: 600; font-size: .85rem; margin: 12px 0 5px; }
.row { display: flex; gap: 8px; }
.hint { color: var(--muted); font-size: .82rem; margin: 8px 0 6px; }

/* ── Kopfzeile ── */
.top {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 32px; height: 32px; }
.brand h1 { font-size: 1.25rem; }
.progress { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 220px; }
.progress .bar { flex: 1; max-width: 320px; height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress .bar span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
#progress-text { color: var(--muted); font-size: .9rem; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Layout ── */
.layout {
  display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 20px;
  padding: 20px 24px; max-width: 1400px; margin: 0 auto; align-items: start;
}
/* min-width: 0 → Inhalte dürfen die Spalten nie breiter machen (sonst überlappen linke Spalte und Liste) */
.side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.row input { min-width: 0; flex: 1; }
.card-head h2 { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .top { padding: 12px 16px; gap: 12px; }
}

.scan-info p { margin: 0 0 8px; color: var(--muted); font-size: .88rem; }
.urls { display: grid; gap: 6px; }
.urls code { background: var(--accent-soft); padding: 6px 9px; border-radius: 6px; font-size: .9rem; user-select: all; overflow-wrap: anywhere; }

/* ── Reiter oben ── */
.views { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 2px; }
.views button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.views button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
body.view-products .lists-only { display: none !important; }
.layout[hidden] { display: none; }

/* ── Reiter „Produkte" ── */
.pview { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }
.pview[hidden] { display: none; }
.pview #pv-search { max-width: 340px; }
.ptable-wrap { overflow-x: auto; margin-top: 6px; }
.ptable { width: 100%; border-collapse: collapse; font-size: .92rem; }
.ptable th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ptable td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ptable tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.ptable .num { text-align: right; white-space: nowrap; }
.ptable .pname { font-weight: 600; min-width: 200px; overflow-wrap: anywhere; }
.ptable .pname .badge { margin-left: 8px; font-weight: 700; }
.ptable .mono { white-space: nowrap; }
.ptable .muted { white-space: nowrap; }
.ptable .acts { white-space: nowrap; text-align: right; }
.ptable .acts button { padding: 5px 10px; font-size: .85rem; margin-left: 4px; }
.ptable .acts .x { color: var(--danger); }
.ptable .pic { padding: 0; border: 0; background: none; border-radius: 8px; }
.ptable .pic:hover .thumb { outline: 2px solid var(--accent); }
.ptable td.empty { text-align: center; color: var(--muted); padding: 30px; }
@media (max-width: 860px) { .pview { padding: 16px; } }

/* ── Produkt-bearbeiten-Fenster ── */
.pdlg-photo { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.pdlg-photo[hidden], .pdlg-photo [hidden] { display: none; }
.pdlg-photo button { padding: 6px 12px; font-size: .88rem; }
.photo-btn.noimg { display: grid; place-items: center; cursor: default; color: var(--muted); }
.photo-btn.noimg[hidden] { display: none; }
.small-text { font-size: .82rem; margin-top: 2px; }
.check-label { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: .88rem; margin-top: 10px; }
.check-label input { width: auto; }
.dlg-actions .left { margin-right: auto; }

/* ── Meine Einkaufszettel ── */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
button.small { padding: 5px 11px; font-size: .88rem; }
.lists { display: grid; gap: 6px; max-height: 300px; overflow-y: auto; }
.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left;
  background: var(--bg); border-color: transparent; padding: 10px 12px; white-space: normal;
}
.list-row .ln { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.list-row .ls { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.list-row .ls.ok { color: var(--accent); font-weight: 600; }
.list-row.active { background: var(--accent-soft); border-color: var(--accent); }

/* ── Liste ── */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.list-head h2 { margin: 0; font-size: 1.25rem; overflow-wrap: anywhere; }
.list-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.list-actions button { padding: 6px 10px; font-size: .86rem; }
.tabs { display: inline-flex; background: var(--bg); border-radius: 9px; padding: 3px; margin-bottom: 6px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; color: var(--muted); }
.tabs button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .1); }
.tabs span { font-size: .8em; opacity: .8; margin-left: 2px; }

.item, .prod {
  display: grid; grid-template-columns: auto auto 1fr auto auto; align-items: center; gap: 12px;
  padding: 10px 4px; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--line); }
.thumb.ph { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; text-transform: uppercase; }
.info { min-width: 0; }
.name { font-weight: 600; overflow-wrap: anywhere; }
.sub { color: var(--muted); font-size: .82rem; }
.note { color: var(--text); }
.check {
  width: 30px; height: 30px; padding: 0; border-radius: 50%; border: 2px solid var(--line);
  color: transparent; font-weight: 700;
}
.check:hover { border-color: var(--accent); color: var(--accent); }
.item.done .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.item.partial .check { border-color: var(--warn); }
.item.done .name { text-decoration: line-through; color: var(--muted); }
.item.done .thumb { opacity: .55; }
.qty { display: grid; gap: 4px; justify-items: center; min-width: 70px; border: 0; background: none; padding: 4px; }
.qty b { font-size: 1.1rem; }
.mini { display: block; width: 56px; height: 5px; border-radius: 9px; background: var(--line); overflow: hidden; }
.mini span { display: block; height: 100%; background: var(--accent); }
.item.partial .mini span { background: var(--warn); }
.row-actions { display: flex; gap: 4px; }
.row-actions button { padding: 5px 8px; border-color: transparent; background: none; }
.row-actions button:hover { border-color: var(--line); }
.empty { color: var(--muted); padding: 30px 8px; text-align: center; }
.empty.small { padding: 14px 4px; font-size: .88rem; }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 99px; }
.ok-b { background: var(--accent-soft); color: var(--accent); }
.warn-b { background: var(--warn-soft); color: var(--warn); }

/* ── Produkte ── */
#prod-search { margin-bottom: 6px; }
.products { max-height: 420px; overflow-y: auto; }
.prod { grid-template-columns: auto 1fr auto auto; gap: 10px; padding: 8px 0; }
.prod .thumb { width: 36px; height: 36px; }
.prod .name { font-weight: 500; font-size: .9rem; }
.prod button { padding: 4px 10px; }
.prod .pic { padding: 0; border: 0; background: none; border-radius: 8px; }
.prod .pic:hover .thumb { outline: 2px solid var(--accent); }
.thumb.cam { font-size: 1rem; background: var(--bg); border: 1px dashed var(--muted); }
.prod button[data-act="add"] { color: var(--accent); font-weight: 700; }
.prod .x { border-color: transparent; background: none; color: var(--muted); }

/* ── Mengen-Fenster ── */
dialog {
  border: 0; border-radius: 16px; padding: 22px; width: min(440px, calc(100vw - 32px));
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .3);
}
dialog::backdrop { background: rgb(10 20 15 / .45); }
.dlg-head { display: flex; gap: 14px; align-items: center; }
.dlg-pic img, .photo-btn { width: 84px; height: 84px; border-radius: 10px; flex: none; }
.dlg-pic img { display: block; object-fit: contain; background: #fff; border: 1px solid var(--line); }
.photo-btn { border: 2px dashed var(--muted); background: var(--bg); font-size: .78rem; font-weight: 600; padding: 4px; white-space: normal; line-height: 1.3; }
.dlg-pic [hidden], .small-link[hidden] { display: none; }
.photo-btn:hover { border-color: var(--accent); color: var(--accent); }
.small-link { font-size: .82rem; padding: 2px 0; }
.dlg-head h3 { font-size: 1.1rem; margin-bottom: 4px; }
.warn { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 11px; font-size: .85rem; margin-top: 12px; }
.web-link { display: inline-block; margin-top: 8px; color: var(--accent); font-weight: 600; font-size: .9rem; text-decoration: none; }
.web-link:hover { text-decoration: underline; }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; }
.stepper button { font-size: 1.5rem; padding: 4px; font-weight: 600; }
.stepper input { text-align: center; font-size: 1.7rem; font-weight: 700; padding: 6px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick button { padding: 4px 11px; font-size: .88rem; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 500;
  box-shadow: 0 8px 30px rgb(0 0 0 / .25); max-width: calc(100vw - 32px);
}
#toast.ok { background: var(--accent); color: #fff; }
#toast.err { background: var(--danger); color: #fff; }

/* ── Druck ── */
.print-only { display: none; }
@media print {
  @page { margin: 15mm; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .no-print, dialog, #toast { display: none !important; }
  .print-only { display: block; }
  #print-area h1 { font-size: 20pt; margin-bottom: 2mm; }
  #print-area .meta { color: #555; margin: 0 0 6mm; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th { text-align: left; font-size: 9pt; color: #555; border-bottom: 1.5pt solid #000; padding: 2mm; }
  #print-area td { border-bottom: .5pt solid #bbb; padding: 3mm 2mm; vertical-align: top; }
  #print-area tr { break-inside: avoid; }
  #print-area .box { font-size: 15pt; width: 8mm; line-height: 1; }
  #print-area .n { font-weight: 700; white-space: nowrap; width: 22mm; }
  #print-area .mono { font-family: Consolas, monospace; font-size: 9pt; color: #555; }
}
