:root {
  color-scheme: light dark;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --text: #1c1f1d;
  --muted: #6b726e;
  --border: #e2e5e0;
  --accent: #2e7d5b;
  --accent-contrast: #ffffff;
  --danger: #c0392b;
  --done: #9aa29d;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121413;
    --surface: #1d201e;
    --text: #e8ebe9;
    --muted: #9aa29d;
    --border: #2c302d;
    --accent: #4fb487;
    --accent-contrast: #0d1f16;
    --danger: #ff6b5e;
    --done: #6b726e;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
}

body {
  font: 17px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

svg {
  display: block;
}

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: calc(env(safe-area-inset-top) + 0.25rem) calc(env(safe-area-inset-right) + 0.75rem) 0.25rem
    calc(env(safe-area-inset-left) + 0.25rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.2rem;
  font-weight: 650;
}

.icon-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: none;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--border);
}

.icon-btn svg {
  width: 26px;
  height: 26px;
}

.status {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--danger);
}

/* ---------- Burger-Menü ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(0 0 0 / 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: min(80vw, 300px);
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 0.75rem) 0 calc(env(safe-area-inset-bottom) + 0.75rem)
    env(safe-area-inset-left);
  background: var(--surface);
  box-shadow: 2px 0 20px rgb(0 0 0 / 0.25);
  transform: translateX(-105%);
  transition: transform 0.22s ease;
}

.drawer.open {
  transform: none;
}

.drawer-title {
  padding: 0.5rem 1.25rem 1rem;
  font-size: 1.3rem;
  font-weight: 700;
}

.drawer a,
.drawer button {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-height: 56px;
  margin: 0 0.5rem;
  padding: 0 0.9rem;
  border: 0;
  border-radius: 12px;
  background: none;
  color: inherit;
  font-size: 1.05rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.drawer a svg {
  width: 24px;
  height: 24px;
  flex: none;
}

.drawer a[aria-current='page'] {
  color: var(--accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.drawer .spacer {
  flex: 1;
}

.drawer .logout {
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .drawer,
  .backdrop {
    transition: none;
  }
}

/* ---------- Inhalt ---------- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem calc(env(safe-area-inset-right) + 1rem) calc(env(safe-area-inset-bottom) + 2.5rem)
    calc(env(safe-area-inset-left) + 1rem);
}

h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 2rem 0.25rem 0.6rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.view > h2:first-child {
  margin-top: 0.25rem;
}

.badge {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.add-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.add-form input {
  flex: 1;
  min-width: 0;
  height: 52px;
  padding: 0 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-size: 17px; /* ≥ 16px verhindert Auto-Zoom auf iOS */
}

.add-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.add-form button {
  width: 52px;
  height: 52px;
  flex: none;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
}

.add-form button:active {
  filter: brightness(0.9);
}

/* ---------- Listen ---------- */
.list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.item {
  display: flex;
  align-items: center;
  min-height: 56px;
  border-top: 1px solid var(--border);
}

.list > li:first-child {
  border-top: 0;
}

.item.removing {
  opacity: 0.4;
}

.check {
  width: 56px;
  height: 56px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  cursor: pointer;
}

.check span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 2px solid var(--muted);
  border-radius: 50%;
  transition: background 0.15s, border-color 0.15s;
}

.check svg {
  width: 16px;
  height: 16px;
  color: var(--accent-contrast);
  opacity: 0;
}

.item.done .check span {
  border-color: var(--accent);
  background: var(--accent);
}

.item.done .check svg {
  opacity: 1;
}

.text {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 0;
  overflow-wrap: anywhere;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.item.done .text {
  color: var(--done);
  text-decoration: line-through;
}

.act {
  width: 48px;
  height: 56px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.act svg {
  width: 20px;
  height: 20px;
}

.act.del:active {
  color: var(--danger);
}

.edit-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 0.6rem;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  font-size: 17px;
}

.empty {
  padding: 1.1rem 1rem;
  color: var(--muted);
  text-align: center;
}

.secondary {
  width: 100%;
  min-height: 48px;
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.secondary:disabled {
  opacity: 0.45;
  cursor: default;
}

.hint {
  margin: 0.6rem 0.25rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 1.25rem);
  z-index: 40;
  max-width: calc(100vw - 2rem);
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  transform: translateX(-50%);
}

/* ---------- Login ---------- */
.login-page {
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-box {
  width: 100%;
  max-width: 360px;
  padding: 0;
  text-align: center;
}

.login-logo {
  border-radius: 18px;
}

.login-box h1 {
  margin: 0.75rem 0 1.5rem;
  font-size: 1.6rem;
}

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  text-align: left;
}

.login-box label {
  color: var(--muted);
  font-size: 0.9rem;
}

.login-box input[type='password'] {
  height: 52px;
  padding: 0 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font-size: 17px;
}

.login-box input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.primary {
  height: 52px;
  margin-top: 0.4rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  cursor: pointer;
}

.primary:disabled {
  opacity: 0.6;
}

.error {
  margin: 0.25rem 0 0;
  color: var(--danger);
  text-align: center;
}

/* ---------- Vorschläge ---------- */
.suggestions {
  display: flex;
  gap: 0.5rem;
  margin: -0.25rem -1rem 0.75rem;
  padding: 0 1rem 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.suggestions::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  min-height: 40px;
  padding: 0 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
}

.chip:active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

/* ---------- Kategorie-Gruppen ---------- */
.list > .group {
  padding: 0.55rem 1rem 0.35rem;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 60%, var(--surface));
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.03em;
}

/* ---------- Bearbeiten-Dialog (Bottom Sheet) ---------- */
.sheet {
  width: min(100vw, 520px);
  max-width: 100vw;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: 1.25rem 1rem calc(env(safe-area-inset-bottom) + 1rem);
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
}

@media (min-width: 600px) {
  .sheet {
    margin: auto;
    border-radius: 20px;
  }
}

.sheet::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.sheet h3 {
  margin: 0 0 0.9rem;
  font-size: 1.1rem;
}

.sheet input[name='text'] {
  width: 100%;
  height: 50px;
  padding: 0 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  font-size: 17px;
}

.sheet input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.sheet-label {
  margin: 1rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.cat-option {
  min-height: 46px;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}

.cat-option[aria-checked='true'] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  font-weight: 600;
}

.link-btn {
  margin-top: 0.9rem;
  padding: 0.5rem 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
}

.sheet-actions {
  display: flex;
  flex-direction: row-reverse; /* Speichern rechts, steht im DOM aber zuerst */
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.sheet-actions button {
  flex: 1;
  margin: 0;
  height: 50px;
}

/* ---------- Toast mit Aktion ---------- */
.toast {
  /* Zentrieren ohne translate, sonst ist die Breite auf 50 % begrenzt */
  left: 0;
  right: 0;
  width: fit-content;
  margin: 0 auto;
  transform: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-right: 0.6rem;
}

.toast-btn {
  flex: none;
  min-height: 36px;
  padding: 0 0.8rem;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 70%, var(--bg));
  color: var(--bg);
  font-weight: 650;
  cursor: pointer;
}

/* ---------- Menge auf der Einkaufsliste ---------- */
.text .amount {
  color: var(--muted);
  font-size: 0.88em;
  white-space: nowrap;
}

.text .amount::before {
  content: '· ';
}

/* ---------- Dialog-Formulare allgemein ---------- */
.sheet {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet.tall {
  max-height: 94dvh;
}

.sheet input[type='text'],
.sheet input[type='number'],
.sheet textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  font-size: 17px;
}

.sheet input[type='text'],
.sheet input[type='number'] {
  height: 50px;
}

.sheet input.short {
  width: 8rem;
}

.sheet textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.45;
}

.sheet textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.sheet label.sheet-label {
  display: block;
}

.amount-input {
  margin-top: 0.5rem;
}

.sheet-hint {
  margin: -0.5rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.sheet .error {
  margin: 0.75rem 0 0;
}

/* ---------- Rezeptliste ---------- */
.recipe-list > li {
  border-top: 1px solid var(--border);
}

.recipe-card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.85rem 1rem;
  color: inherit;
  text-decoration: none;
}

.recipe-card:active {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.recipe-card strong {
  font-size: 1.05rem;
  font-weight: 600;
}

.recipe-card span {
  color: var(--muted);
  font-size: 0.85rem;
}

#recipe-search::-webkit-search-cancel-button {
  cursor: pointer;
}

/* ---------- Rezept-Detail ---------- */
.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.recipe-title {
  margin: 0.25rem 0.1rem 0.2rem;
  color: var(--text);
  font-size: 1.5rem;
  letter-spacing: 0;
  text-transform: none;
}

.recipe-meta {
  margin: 0 0.1rem 1rem;
  color: var(--muted);
}

.primary.wide {
  width: 100%;
  font-size: 1.05rem;
}

.primary.wide:disabled {
  opacity: 0.5;
}

.section-label {
  margin: 1.5rem 0.25rem 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ingredient {
  display: flex;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--border);
}

.ing-amount {
  flex: none;
  width: 5.5rem;
  color: var(--muted);
  text-align: right;
  overflow-wrap: anywhere;
}

.ing-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.recipe-notes {
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.recipe-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.5rem;
}

.recipe-actions .secondary {
  flex: 1;
  margin: 0;
}

.secondary.danger {
  color: var(--danger);
}

/* ---------- Zutaten-Auswahl ---------- */
.choices {
  margin-top: 0.25rem;
}

.choices > li {
  border-top: 1px solid var(--border);
}

.choice {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 54px;
  padding: 0.4rem 1rem 0.4rem 0.75rem;
  cursor: pointer;
}

.choice input {
  width: 24px;
  height: 24px;
  flex: none;
  accent-color: var(--accent);
}

.choice .ing-amount {
  width: 4.5rem;
  text-align: left;
}

.choice.off .ing-amount,
.choice.off .ing-name {
  color: var(--done);
  text-decoration: line-through;
}

.choice small {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
}

/* ---------- Rezept-Import per Link ---------- */
.sheet-label.first {
  margin-top: 0;
}

.url-row {
  display: flex;
  gap: 0.5rem;
}

.url-row input {
  flex: 1;
  min-width: 0;
}

.url-row .secondary {
  width: auto;
  flex: none;
  min-width: 5.5rem;
  height: 50px;
  min-height: 0;
  margin: 0;
  padding: 0 1rem;
  font-weight: 600;
}

.url-hint {
  margin: 0.4rem 0 0;
  font-size: 0.82rem;
}

.source-link {
  display: inline-block;
  margin: -0.6rem 0.1rem 1rem;
  color: var(--accent);
  font-size: 0.9rem;
  text-decoration: none;
}
