/* ═══════════════════════════════════════════════════
   Design-Tokens  –  „Frischer Markt"-Palette
   ═══════════════════════════════════════════════════ */
:root {
  /* Farben */
  --bg:           #EDF4EF;
  --card:         #FFFFFF;
  --primary:      #2D6A4F;
  --primary-dk:   #1B4332;
  --accent:       #52B788;
  --accent-lt:    #D8F3DC;
  --text:         #1B2C2A;
  --text-muted:   #6B8F7E;
  --danger:       #E63946;
  --danger-bg:    #FFECEE;
  --checked-txt:  #9DB8B0;
  --border:       #C8DDD5;

  /* Abstände / Form */
  --r:    14px;    /* border-radius groß */
  --rs:    8px;    /* border-radius klein */
  --tap:  44px;    /* iOS-Mindestgröße für Touch-Ziele */
  --pad:  14px;

  /* Schatten */
  --sh:   0 2px 10px rgba(45,106,79,.10);
  --sh-lg:0 8px 30px rgba(45,106,79,.20);
}

/* ─── Reset ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
               Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ─── App-Rahmen ─────────────────────────────────── */
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header (Signatur: Verlaufsgradient) ─────────── */
.app-header {
  background: linear-gradient(
    135deg, var(--primary-dk) 0%, var(--primary) 55%, var(--accent) 100%
  );
  color: #fff;
  padding: calc(18px + env(safe-area-inset-top, 0px)) var(--pad) 18px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 3px 14px rgba(27,67,50,.28);
}

.app-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.4px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon { font-size: 28px; line-height: 1; }

/* ─── Eingabe-Bereich ────────────────────────────── */
.input-section {
  background: var(--card);
  margin: var(--pad) var(--pad) 0;
  border-radius: var(--r);
  box-shadow: var(--sh);
  padding: var(--pad);
  position: relative;
  z-index: 50;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.item-input {
  flex: 1;
  height: var(--tap);
  border: 2px solid var(--border);
  border-radius: var(--rs);
  padding: 0 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color .2s, background .2s;
  -webkit-appearance: none;
  appearance: none;
}

.item-input:focus     { border-color: var(--accent); background: #fff; }
.item-input::placeholder { color: var(--text-muted); }

.add-btn {
  flex-shrink: 0;
  width: var(--tap);
  height: var(--tap);
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--rs);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.add-btn:active { background: var(--primary-dk); transform: scale(.94); }
.add-btn:focus  { outline: none; }
.add-btn svg    { width: 22px; height: 22px; }

/* Foto-Zeile */
.photo-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 40px;
}

.photo-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border: 2px dashed var(--border);
  border-radius: var(--rs);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .2s, color .2s;
  -webkit-tap-highlight-color: transparent;
}

.photo-btn:active { border-color: var(--accent); color: var(--accent); }
.photo-btn svg    { width: 16px; height: 16px; flex-shrink: 0; }

.photo-preview {
  position: relative;
  display: flex;
  align-items: center;
}

.photo-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--rs);
  border: 2px solid var(--accent);
  display: block;
}

/* Schließen-Abzeichen (kleines ×) */
.badge-btn {
  position: absolute;
  top: -7px; right: -7px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Autocomplete ───────────────────────────────── */
.autocomplete {
  position: absolute;
  left: var(--pad); right: var(--pad);
  top: calc(var(--pad) + var(--tap) + 8px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--rs);
  box-shadow: 0 8px 24px rgba(0,0,0,.13);
  z-index: 200;
  overflow: hidden;
}

.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--bg);
  transition: background .1s;
  -webkit-tap-highlight-color: transparent;
}

.ac-item:last-child { border-bottom: none; }
.ac-item:active     { background: var(--accent-lt); }

.ac-thumb {
  width: 36px; height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}

.ac-placeholder {
  width: 36px; height: 36px;
  border-radius: 6px;
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.ac-name {
  flex: 1;
  font-size: 15px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ac-edit-btn {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  transition: background .1s;
  -webkit-tap-highlight-color: transparent;
}

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

/* ─── Listen-Bereich ─────────────────────────────── */
.list-main {
  flex: 1;
  padding: 10px var(--pad) calc(90px + env(safe-area-inset-bottom, 0px));
}

.item-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ─── Artikel-Karte ──────────────────────────────── */
.item-card {
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--sh);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 10px;
  transition: opacity .25s;
  position: relative;
  overflow: hidden;
  border-left: 3px solid var(--accent);
}

.item-card.checked {
  opacity: .57;
  border-left-color: var(--border);
}

/* Drag-Handle */
.drag-handle {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 3px;
  cursor: grab;
  flex-shrink: 0;
  opacity: .35;
  touch-action: none;
}

.drag-handle:active { cursor: grabbing; opacity: .7; }

.drag-handle span {
  display: block;
  width: 18px; height: 2px;
  background: var(--text-muted);
  border-radius: 2px;
}

/* Custom-Checkbox */
.cb-wrapper {
  position: relative;
  flex-shrink: 0;
  width: 28px; height: 28px;
}

.cb-wrapper input[type="checkbox"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
  margin: 0;
}

.cb-visual {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .22s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}

.cb-wrapper input:checked + .cb-visual {
  background: var(--accent);
  border-color: var(--accent);
}

.cb-visual::after {
  content: '';
  width: 10px; height: 6px;
  border-left:   2.5px solid #fff;
  border-bottom: 2.5px solid #fff;
  transform: rotate(-45deg) scale(0);
  transition: transform .15s cubic-bezier(.34,1.56,.64,1);
  margin-top: -2px;
}

.cb-wrapper input:checked + .cb-visual::after {
  transform: rotate(-45deg) scale(1);
}

/* Artikel-Inhalt */
.item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.item-name {
  flex: 1;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
  cursor: text;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: color .2s;
}

.item-card.checked .item-name {
  text-decoration: line-through;
  color: var(--checked-txt);
}

/* Inline-Edit */
.item-name-edit {
  flex: 1;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text);
  outline: none;
  background: #fff;
  min-width: 0;
}

/* Thumbnail */
.item-thumb {
  width: 46px; height: 46px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.item-thumb:active { opacity: .75; transform: scale(.96); }

/* Löschen-Button */
.item-delete-btn {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border: none;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}

.item-delete-btn:active { background: #ffc9cc; }

/* ─── Abschnitt „Bereits im Korb" ────────────────── */
.checked-section { margin-top: 18px; }

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .9px;
  color: var(--text-muted);
  padding: 0 4px 8px;
}

/* ─── Leer-Zustand ───────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}

.empty-icon { font-size: 60px; margin-bottom: 18px; line-height: 1; }
.empty-state p { font-size: 16px; line-height: 1.7; }

/* ─── Footer ─────────────────────────────────────── */
.footer-actions {
  margin-top: 22px;
  display: flex;
  justify-content: center;
}

.remove-checked-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 26px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1.5px solid rgba(230,57,70,.22);
  border-radius: 100px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}

.remove-checked-btn:active { background: #ffc9cc; }
.remove-checked-btn svg    { width: 16px; height: 16px; }

/* ═══ Lightbox ════════════════════════════════════ */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.88);
  border: none; cursor: pointer;
}

.lightbox-inner {
  position: relative;
  max-width: 92vw;
  max-height: 86vh;
  z-index: 1;
}

.lightbox-inner img {
  max-width: 100%;
  max-height: 86vh;
  object-fit: contain;
  border-radius: var(--r);
  display: block;
}

.lightbox-close {
  position: absolute;
  top: -14px; right: -14px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.9);
  border: none; font-size: 15px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  -webkit-tap-highlight-color: transparent;
}

/* ═══ Modal – Bottom Sheet ════════════════════════ */
.modal {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: flex-end; justify-content: center;
}

.modal-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.48);
  border: none; cursor: pointer;
}

.modal-card {
  position: relative;
  background: var(--card);
  border-radius: var(--r) var(--r) 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 560px;
  box-shadow: 0 -4px 32px rgba(0,0,0,.16);
  z-index: 1;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.modal-input {
  width: 100%;
  height: var(--tap);
  border: 2px solid var(--border);
  border-radius: var(--rs);
  padding: 0 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  margin-bottom: 14px;
  background: var(--bg);
  -webkit-appearance: none; appearance: none;
}

.modal-input:focus { border-color: var(--accent); background: #fff; }

.modal-photo-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.sugg-photo-preview {
  position: relative;
  flex-shrink: 0;
}

.sugg-photo-preview img {
  width: 58px; height: 58px;
  object-fit: cover;
  border-radius: var(--rs);
  border: 2px solid var(--accent);
  display: block;
}

.modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ─── Buttons ─────────────────────────────────────── */
.btn {
  height: var(--tap);
  padding: 0 18px;
  border-radius: var(--rs);
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active   { opacity: .72; }
.btn-primary  { background: var(--primary);    color: #fff; }
.btn-danger   { background: var(--danger-bg);  color: var(--danger); margin-right: auto; }
.btn-ghost    { background: var(--bg);         color: var(--text-muted); }

/* ═══ Toast ═══════════════════════════════════════ */
#toast-container {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  z-index: 2000;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 22px;
  border-radius: 100px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.22);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .22s, transform .22s;
  white-space: nowrap;
}

.toast.show    { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--primary); }
.toast.error   { background: var(--danger);  }

/* ═══ Sortable ════════════════════════════════════ */
.sortable-ghost {
  opacity: .38;
  background: var(--accent-lt) !important;
}

.sortable-drag {
  opacity: .92;
  box-shadow: var(--sh-lg) !important;
}

/* ═══ Utility ════════════════════════════════════ */
.hidden { display: none !important; }

/* ═══ Desktop-Zentrierung ════════════════════════ */
@media (min-width: 580px) {
  .modal-card {
    border-radius: var(--r);
    margin-bottom: 15vh;
    width: calc(100% - 40px);
  }
}

/* ═══ Reduzierte Bewegung ════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
