:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1c1f1d;
  --muted: #7a827c;
  --line: #e4e7e3;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131513;
    --card: #1e211e;
    --text: #eef1ee;
    --muted: #8f978f;
    --line: #2c302c;
  }
}

/* Manuelle Wahl über den Toggle schlägt die Systemeinstellung */
:root[data-theme="dark"] {
  --bg: #131513;
  --card: #1e211e;
  --text: #eef1ee;
  --muted: #8f978f;
  --line: #2c302c;
}

:root[data-theme="light"] {
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1c1f1d;
  --muted: #7a827c;
  --line: #e4e7e3;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  -webkit-tap-highlight-color: transparent;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--green);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.titlebar h1 { margin-bottom: 0; color: var(--text); }

#back {
  flex: none;
  text-decoration: none;
  color: var(--green);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  padding: 0 10px 4px 0;
}

#theme-toggle {
  margin-left: auto;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#theme-toggle:active { background: var(--line); }

.offline-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

#add-form,
#new-list-form {
  display: flex;
  gap: 8px;
}

#add-input,
#new-list-input {
  flex: 1;
  font-size: 1.05rem;
  padding: 13px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  outline: none;
}

#add-input:focus,
#new-list-input:focus { border-color: var(--green); }

#add-form button,
#new-list-form button {
  width: 50px;
  border: none;
  border-radius: var(--radius);
  background: var(--green);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

#add-form button:active,
#new-list-form button:active { background: var(--green-dark); }

#suggestions {
  list-style: none;
  margin-top: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10);
}

#suggestions li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 13px 16px;
  font-size: 1rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

#suggestions li:last-child { border-bottom: none; }
#suggestions li:active { background: var(--bg); }
#suggestions li .kat { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
#suggestions li.new-item .kat { color: var(--green); }

main {
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 32px);
}

/* --- Listenauswahl (Läden) --- */
.lists { list-style: none; }

.lists li {
  display: flex;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.lists .open {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 4px 18px 16px;
  text-decoration: none;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  min-width: 0;
}

.lists .open:active { opacity: 0.6; }

.lists .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lists .count {
  flex: none;
  min-width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: var(--green);
  color: #fff;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0 8px;
}

.lists .count.all-done {
  background: none;
  border: 1.5px solid var(--line);
  color: var(--muted);
}

.lists .chevron {
  flex: none;
  color: var(--muted);
  font-size: 1.4rem;
  font-weight: 400;
}

.lists .delete {
  flex: none;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 18px 16px;
  cursor: pointer;
}

/* --- Artikel --- */
.items { list-style: none; }

.items li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 8px 9px 16px;
  margin-bottom: 8px;
  font-size: 1.05rem;
}

/* Nur wirklich neue Zeilen animieren — sonst flackert jede Neuzeichnung */
.items li.new,
.lists li.new {
  animation: pop-in 0.15s ease-out;
}

.items li.pending { opacity: 0.55; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.items .check {
  flex: none;
  width: 30px;
  height: 30px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: transparent;
  font-size: 0.95rem;
}

.items .check:active { border-color: var(--green); }

.items .name {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.items .label {
  overflow-wrap: anywhere;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.emoji {
  flex: none;
  width: 1.4em;
  text-align: center;
  font-size: 1.15em;
}

#suggestions .name {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stepper {
  flex: none;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
}

.stepper button {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.stepper button:active { background: var(--line); }

.stepper .qty {
  min-width: 20px;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.items .delete {
  flex: none;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 14px 10px;
  cursor: pointer;
}

li.checking {
  opacity: 0.4;
  transition: opacity 0.25s;
}

li.checking .check {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

#recent-section { margin-top: 28px; }

#recent-section h2 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.recent li {
  padding: 10px 16px;
  font-size: 0.95rem;
  color: var(--muted);
}

.recent .label { text-decoration: line-through; }

.recent .readd {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
}

/* --- Dialoge (Bestätigung, Zugangscode) --- */
dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  border: none;
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  width: min(calc(100vw - 48px), 360px);
  padding: 24px 20px 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  animation: dialog-in 0.18s ease-out;
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#confirm-title {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
}

#confirm-detail {
  margin-top: 8px;
  font-size: 0.92rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.dialog-actions button {
  flex: 1;
  padding: 13px 0;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#confirm-cancel {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
}

#confirm-ok {
  background: #dc2626;
  color: #fff;
}

#confirm-ok:active { background: #b91c1c; }

.dialog-actions button:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
#confirm-cancel:active { background: var(--line); }

/* --- Zugangscode-Dialog --- */
#auth-title {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}

.auth-hint {
  margin-top: 8px;
  font-size: 0.92rem;
  color: var(--muted);
  text-align: center;
}

#auth-form {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

#auth-form input {
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  padding: 13px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

#auth-form input:focus { border-color: var(--green); }

#auth-form button {
  border: none;
  border-radius: var(--radius);
  background: var(--green);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  padding: 0 18px;
  cursor: pointer;
}

#auth-form button:active { background: var(--green-dark); }

#auth-error {
  margin-top: 12px;
  font-size: 0.92rem;
  color: #dc2626;
  text-align: center;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 0;
  font-size: 1.05rem;
  line-height: 1.5;
}
