:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1f2421;
  --muted: #6b716d;
  --line: #e3e1da;
  --accent: #2f7d4f;
  --accent-soft: #e3f1e8;
  --warn: #a5560b;
  --warn-soft: #fbeedd;
  --danger: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161917;
    --card: #1f2421;
    --text: #e8ebe8;
    --muted: #9aa29d;
    --line: #313733;
    --accent: #5fbf85;
    --accent-soft: #1e3427;
    --warn: #f0b36a;
    --warn-soft: #3a2a17;
    --danger: #ff8a80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161917;
  --card: #1f2421;
  --text: #e8ebe8;
  --muted: #9aa29d;
  --line: #313733;
  --accent: #5fbf85;
  --accent-soft: #1e3427;
  --warn: #f0b36a;
  --warn-soft: #3a2a17;
  --danger: #ff8a80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
main, .login, .top, .foot { max-width: 560px; margin: 0 auto; padding: 0 16px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-top: 16px; flex-wrap: wrap; }
h1 { font-size: 1.5rem; margin: 0; }
.status { font-size: .8rem; padding: 2px 8px; border-radius: 99px; color: var(--muted); }
.status.ok { background: var(--accent-soft); color: var(--accent); }
.status.warn { background: var(--warn-soft); color: var(--warn); }

.add { position: sticky; top: 0; z-index: 2; display: flex; gap: 8px; padding: 12px 0; background: var(--bg); }
.add input {
  flex: 1; min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.add button {
  width: 52px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 1.6rem; line-height: 1;
}

.group h2, .done h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 6px; font-weight: 600; }
.items { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.item { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.tick {
  flex: none; width: 52px; border: 0; background: none; display: grid; place-items: center;
}
.tick::before {
  content: ""; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--muted);
}
.is-done .tick::before { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--card); }
.label {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; text-align: left;
  border: 0; background: none; padding: 14px 14px 14px 0;
}
.name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.qty { flex: none; font-variant-numeric: tabular-nums; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 2px 8px; font-size: .9rem; }
.pin { flex: none; font-size: .8rem; }
.is-done .name { text-decoration: line-through; color: var(--muted); }
.is-done .qty { background: none; color: var(--muted); }

.done { margin-top: 8px; }
.done-head { display: flex; align-items: baseline; justify-content: space-between; }
.link { border: 0; background: none; color: var(--accent); padding: 8px 4px; text-decoration: underline; }
.empty { color: var(--muted); text-align: center; margin: 40px 0; }
.error { color: var(--danger); }

.login { text-align: center; margin-top: 48px; }
.login-form { display: grid; gap: 12px; max-width: 360px; margin: 0 auto; }
.login-form input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); width: 100%; text-align: center; }
#login-code { font-size: 1.4rem; letter-spacing: .2em; font-variant-numeric: tabular-nums; }
.primary { border: 0; border-radius: 12px; background: var(--accent); color: #fff; padding: 12px 18px; font-weight: 600; }
.danger { border: 0; background: none; color: var(--danger); padding: 12px 4px; }

.foot { color: var(--muted); font-size: .8rem; display: flex; gap: 8px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; padding-top: 24px; padding-bottom: 24px; }

/* Dialog: auf dem Handy als Blatt von unten */
.sheet {
  border: 0; padding: 0; width: 100%; max-width: 560px; background: var(--card); color: var(--text);
  border-radius: 16px; margin: auto auto 0; max-height: 90vh;
}
@media (min-width: 600px) { .sheet { margin: auto; } }
.sheet::backdrop { background: rgb(0 0 0 / .4); }
.sheet form { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.sheet-name { font-size: 1.25rem; font-weight: 600; border: 0; border-bottom: 1px solid var(--line); padding: 6px 0; background: none; width: 100%; }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
legend { font-size: .85rem; color: var(--muted); margin-bottom: 6px; padding: 0; }
.chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 12px 0; min-width: 48px; font-variant-numeric: tabular-nums; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.qty-row { display: flex; gap: 6px; }
.qty-row input, select { flex: 1; min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); width: 100%; }
.qty-row .chip { padding: 0 14px; }
.check { display: flex; gap: 8px; align-items: center; font-size: .95rem; }
.check input { width: 20px; height: 20px; }
.sheet-actions { display: flex; gap: 8px; align-items: center; }
.sheet-actions .spacer { flex: 1; }
#sheet-cancel { border: 1px solid var(--line); background: none; border-radius: 12px; padding: 12px 14px; }
