:root {
  --bg: #f3f6f3; --card: #ffffff; --text: #1b2a1b; --muted: #5d6f5d;
  --accent: #2e7d32; --accent-soft: #e3f1e3; --line: #d8e2d8; --cat-bg: #eaefea;
  --done: #9aa89a; --danger: #c62828; --shadow: 0 1px 3px rgba(0,0,0,.12);
  --tile: 104px; --cat-min: 72px; --headh: 64px; --dockh: 70px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101510; --card: #1a221a; --text: #e6efe6; --muted: #9db09d;
    --accent: #66bb6a; --accent-soft: #223a23; --line: #2a362a; --cat-bg: #161d16;
    --done: #6d7d6d; --danger: #ef5350; --shadow: 0 1px 3px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* Kopf */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 8px) 14px 8px; border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 10px; }
.top h1 { margin: 0; font-size: 1.3rem; flex: 1; }
.icon-btn { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  width: 44px; height: 44px; font-size: 1.2rem; box-shadow: var(--shadow); }

main { padding: 10px 14px calc(var(--dockh) + 24px); max-width: 900px; margin: 0 auto; }

/* Bereiche */
section { margin: 14px 0; }
.sec-head { position: sticky; top: var(--headh); z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: 6px 0; font-weight: 700; font-size: 1.02rem; }
.catalog .sec-head { background: var(--cat-bg); margin: 0 -10px; padding: 6px 10px; }
.sec-head .count { margin-left: auto; font-weight: 500; color: var(--muted); font-size: .88rem; }

/* Einkaufszettel */
.list-box { background: var(--accent-soft); border: 2px solid var(--accent); border-radius: 20px; padding: 8px 12px 12px; margin-top: 8px; }
.list-box .sec-head { position: static; background: transparent; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr)); gap: 10px; }

/* Katalog: deutlich abgesetzt, kleinere Kacheln */
.catalog { margin-top: 22px; background: var(--cat-bg); border-radius: 20px 20px 0 0; padding: 0 10px 8px; }
body.has-list .catalog { margin-top: 30px; border-top: 4px solid var(--line); }
.catalog-label { display: flex; align-items: center; gap: 10px; padding: 14px 4px 4px; color: var(--muted);
  font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.catalog-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.catalog section { margin: 8px 0 14px; }
.cat-grid { grid-template-columns: repeat(auto-fill, minmax(var(--cat-min), 1fr)); gap: 8px; }
.cat-grid .tile { border-radius: 14px; border-width: 2px; padding: 3px; gap: 2px; }
.cat-grid .tile .emo { font-size: 1.75rem; }
.cat-grid .tile .nm { font-size: .68rem; line-height: 1.1; }
.cat-grid .tile.on::after { top: 1px; right: 5px; font-size: .8rem; }
.cat-grid .tile .ed { width: 22px; height: 22px; font-size: .7rem; top: 2px; left: 2px; }

.tile { position: relative; aspect-ratio: 1 / 1; border-radius: 18px; border: 2px solid var(--line);
  background: var(--card); box-shadow: var(--shadow); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; padding: 6px; text-align: center; }
.tile .emo { font-size: 2.3rem; line-height: 1; }
.tile .nm { font-size: .82rem; line-height: 1.15; overflow-wrap: anywhere; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 100%; }
.tile.on { border-color: var(--accent); background: var(--accent-soft); }
.tile.on::after { content: "✓"; position: absolute; top: 4px; right: 8px; color: var(--accent); font-weight: 800; }
.tile.done { opacity: .55; border-style: dashed; }
.tile.done .nm { text-decoration: line-through; color: var(--done); }
.tile .x, .tile .ed { position: absolute; border-radius: 50%; border: 0; background: rgba(0,0,0,.08); line-height: 1; padding: 0; color: var(--text); }
.tile .x { top: 4px; right: 4px; width: 28px; height: 28px; font-size: .9rem; }
.tile .ed { top: 4px; left: 4px; width: 28px; height: 28px; font-size: .9rem; display: flex; align-items: center; justify-content: center; }
.tile.on.has-x::after { display: none; }

.btn { background: var(--accent); color: #fff; border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 600; min-height: 46px; }
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.btn.wide { width: 100%; margin-top: 10px; }

/* Untere Leiste: Suche und Neuanlage */
.dock { position: fixed; left: 0; right: 0; bottom: var(--kb, 0px); z-index: 20; background: var(--bg);
  border-top: 1px solid var(--line); padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px); box-shadow: 0 -4px 14px rgba(0,0,0,.12); }
.dock > * { max-width: 900px; margin-left: auto; margin-right: auto; }
.search { width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 1rem; }
.search:focus { outline: 2px solid var(--accent); }
.addbox { background: var(--card); border: 2px dashed var(--accent); border-radius: 16px; padding: 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 8px; }
.addrow { display: flex; gap: 8px; }
.addrow select { flex: 3; } .addrow .field { flex: 2; }
select, .field { width: 100%; padding: 11px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); min-width: 0; }

.empty { color: var(--muted); padding: 8px 2px; }
.offline { background: #fff3cd; color: #5b4500; border-radius: 12px; padding: 8px 12px; margin: 8px 0; font-size: .9rem; }
@media (prefers-color-scheme: dark) { .offline { background: #3f3300; color: #ffe08a; } }

/* Anmeldung */
.login { max-width: 380px; margin: 14vh auto 0; padding: 24px 20px; text-align: center; }
.login .logo { font-size: 3.5rem; }
.login h1 { margin: 6px 0 18px; }
.login form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.err { color: var(--danger); min-height: 1.3em; font-size: .92rem; }

dialog { border: 0; border-radius: 20px; background: var(--card); color: var(--text); padding: 18px; width: min(92vw, 420px); box-shadow: 0 10px 40px rgba(0,0,0,.4); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 12px; font-size: 1.15rem; }
dialog .row { display: flex; gap: 10px; margin-top: 14px; }
dialog .row .btn { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--dockh) + 20px); transform: translateX(-50%);
  background: #263326; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .92rem; opacity: 0;
  pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 50; }
#toast.show { opacity: 1; }
