:root {
  /* --- Palette (refined dark) --- */
  --bg: #0d0f13;
  --bg-elev: #181b21;
  --bg-elev-2: #232830;
  --separator: rgba(255,255,255,0.07);
  --text: #f5f6f8;
  --text-2: rgba(236,239,245,0.56);
  --text-3: rgba(236,239,245,0.32);

  --accent: #2ecf7a;          /* brand / primary actions */
  --accent-press: #28b86c;
  --green: #34d27b;           /* covered / done */
  --orange: #ffa724;          /* missing */
  --red: #ff4d40;             /* delete */
  --blue: #4aa3ff;            /* tags / links */

  --radius: 16px;
  --radius-sm: 11px;
  --tabbar-h: 60px;
  --topbar-h: 50px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* fluid type scale */
  --fs-title: 19px;
  --fs-row: 17px;
  --fs-sub: 13.5px;
  --fs-section: 12.5px;
  --fs-num: 19px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--fs-row);
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

/* ---------- Top bar ---------- */
#topbar {
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  background: rgba(13,15,19,0.82);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 0.5px solid var(--separator);
  position: sticky; top: 0; z-index: 10;
}
#leftAction { grid-column: 1; }
#screenTitle {
  grid-column: 2;
  margin: 0; text-align: center;
  font-size: var(--fs-title); font-weight: 700; letter-spacing: -0.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#rightAction { grid-column: 3; }
.icon-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; height: 44px; width: 52px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 25px; height: 25px; }
.icon-btn:active { opacity: 0.4; }
.icon-btn[hidden] { display: none; }
.icon-btn.dim { color: var(--text-3); }

/* ---------- Screen ---------- */
#screen {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(18,20,25,0.86);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 0.5px solid var(--separator);
  z-index: 20;
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-3); padding-top: 7px;
  transition: color .15s;
}
.tab-ico { width: 25px; height: 25px; }
.tab-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em; }
.tab.active { color: var(--accent); }

/* ---------- Bottom action bar ---------- */
#bottomAction {
  position: fixed;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px;
  padding: 10px 12px 12px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  z-index: 22;
}
#bottomAction[hidden] { display: none; }
#finishBtn {
  width: 100%; padding: 16px; border-radius: 14px;
  background: var(--accent); color: #04130b; border: none; cursor: pointer;
  font-size: 17px; font-weight: 700; letter-spacing: -0.01em;
  box-shadow: 0 4px 16px rgba(46,207,122,0.34);
}
#finishBtn:active { background: var(--accent-press); transform: scale(0.99); }
body.with-bottom-action #screen {
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 88px);
}

/* ---------- FAB ---------- */
#fab {
  position: fixed;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  right: max(18px, calc(50% - 320px + 18px));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #04130b; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(46,207,122,0.38), 0 2px 6px rgba(0,0,0,0.3);
  z-index: 25;
  transition: transform .12s, background .15s;
}
#fab svg { width: 26px; height: 26px; }
#fab:active { transform: scale(0.92); background: var(--accent-press); }
#fab[hidden] { display: none; }

/* ---------- Lists ---------- */
.section-title {
  font-size: var(--fs-section); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-2);
  padding: 22px 22px 8px;
}
.list { list-style: none; margin: 0; padding: 0; }
.list-group {
  background: var(--bg-elev);
  margin: 0 12px; border-radius: var(--radius);
  overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 16px; min-height: 56px;
  border-bottom: 0.5px solid var(--separator);
  position: relative;
}
.row:last-child { border-bottom: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-size: var(--fs-row); font-weight: 500; letter-spacing: -0.01em; }
.row .subtitle { font-size: var(--fs-sub); color: var(--text-2); margin-top: 2px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--text-2); }
.strike { text-decoration: line-through; color: var(--text-2); }
.chev { color: var(--text-3); display: flex; }
.chev svg { width: 18px; height: 18px; }

/* selection toggle */
.circle-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center; flex: 0 0 auto;
}
.sel-ic { width: 26px; height: 26px; color: var(--text-3); }

/* edit (pencil) button in shopping row */
.edit-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center; flex: 0 0 auto;
  color: var(--text-3);
}
.edit-btn svg { width: 20px; height: 20px; }
.edit-btn:active { opacity: 0.5; }

/* item / category emoji */
.emoji {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1;
  background: rgba(255,255,255,0.05);
}

/* badges */
.badge {
  font-size: 12.5px; font-weight: 700; padding: 4px 10px;
  border-radius: 999px; white-space: nowrap;
}
.badge-orange { color: var(--orange); background: rgba(255,167,36,0.16); }
.badge-green { color: var(--green); background: rgba(52,210,123,0.16); }

.pill {
  font-weight: 600; padding: 8px 13px; border-radius: 10px;
  background: var(--bg-elev-2); border: none; color: var(--text);
  font-size: 15px; cursor: pointer; font-variant-numeric: tabular-nums;
  min-width: 48px;
}
.pill:active { opacity: 0.6; }

.qty { font-variant-numeric: tabular-nums; }

/* empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--text-2);
  height: 62vh; gap: 12px; padding: 0 44px;
}
.empty .ico {
  width: 92px; height: 92px; border-radius: 26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 46px; background: var(--bg-elev);
}
.empty .et { font-size: 21px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.empty .ed { font-size: 15px; max-width: 260px; }

/* coverage checkmark cell */
.ck { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; color: var(--green); }
.ck svg { width: 21px; height: 21px; }

/* expand chevron */
.exp { color: var(--text-3); display: flex; flex: 0 0 auto; transition: transform .2s; }
.exp svg { width: 18px; height: 18px; }
.exp.open { transform: rotate(90deg); }

/* ingredient sub-row */
.subrow {
  background: rgba(255,255,255,0.022);
  padding-left: 22px;
}

/* recipe tags */
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.tag {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: rgba(74,163,255,0.16); color: var(--blue);
}

/* ---------- Segmented filter (recipes) ---------- */
.segment {
  display: flex; gap: 4px; margin: 14px 12px 4px;
  background: var(--bg-elev); border-radius: 12px; padding: 4px;
}
.segment button {
  flex: 1; border: none; cursor: pointer; padding: 9px 8px;
  border-radius: 9px; background: none; color: var(--text-2);
  font-size: 14.5px; font-weight: 600;
}
.segment button.on { background: var(--bg-elev-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.25); }

/* ---------- Category section header (shopping) ---------- */
.cat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 22px 8px;
}
.cat-dot {
  width: 22px; height: 22px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.cat-name {
  font-size: var(--fs-section); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-2);
}

/* ---------- Progress bar ---------- */
.progress-wrap { padding: 4px 22px 2px; }
.progress-top {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px;
}
.progress-top .lbl { font-size: var(--fs-section); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-2); }
.progress-top .cnt { font-size: 13px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.progress-track { height: 7px; border-radius: 999px; background: var(--bg-elev-2); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s ease; }

/* ---------- Swipe-to-delete cell ---------- */
.swipe-cell { position: relative; overflow: hidden; border-bottom: 0.5px solid var(--separator); }
.swipe-cell:last-child { border-bottom: none; }
.swipe-content {
  position: relative; background: var(--bg-elev);
  transform: translateX(0); touch-action: pan-y; z-index: 1;
}
.swipe-content.row { border-bottom: none; }
.swipe-delete {
  position: absolute; top: 0; right: 0; height: 100%;
  width: 92px; border: none; cursor: pointer;
  background: var(--red); color: #fff; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; z-index: 0;
}
.del-btn {
  background: rgba(255,77,64,0.16); color: var(--red); border: none; cursor: pointer;
  font-size: 13.5px; font-weight: 600; padding: 6px 12px; border-radius: 9px;
}

/* ---------- Modal / Sheet ---------- */
#modalHost { position: fixed; inset: 0; z-index: 100; }
#modalHost[hidden] { display: none; }
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: flex-end; justify-content: center;
}
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.55); animation: fade .2s ease; }
.sheet {
  position: relative; width: 100%; max-width: 640px;
  background: #15181e;
  border-radius: 20px 20px 0 0;
  max-height: 92vh; max-height: 92dvh;
  display: flex; flex-direction: column;
  animation: slideUp .3s cubic-bezier(.2,.85,.25,1);
  padding-bottom: var(--safe-bottom);
}
@keyframes slideUp { from { transform: translateY(100%);} to { transform: translateY(0);} }
@keyframes fade { from { opacity: 0;} to { opacity: 1;} }

.sheet-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 16px 16px; border-bottom: 0.5px solid var(--separator);
}
.sheet-bar .st { text-align: center; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.sheet-bar button { background: none; border: none; color: var(--accent); font-size: 17px; cursor: pointer; }
.sheet-bar .confirm { font-weight: 700; justify-self: end; }
.sheet-bar .cancel { justify-self: start; }
.sheet-bar button:disabled { color: var(--text-3); cursor: default; }
.sheet-body { overflow-y: auto; padding: 6px 0 20px; }

.form-section { margin-top: 18px; }
.form-section > .lbl {
  font-size: var(--fs-section); text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-2); font-weight: 600; padding: 0 22px 7px;
}
.form-group { background: var(--bg-elev-2); margin: 0 12px; border-radius: var(--radius-sm); overflow: hidden; }
.field {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 0.5px solid var(--separator);
}
.field:last-child { border-bottom: none; }
.field label { color: var(--text-2); min-width: 64px; }
.field input, .field select, .field textarea {
  flex: 1; background: none; border: none; color: var(--text);
  font-size: var(--fs-row); font-family: inherit; outline: none; width: 100%;
}
.field textarea { resize: none; line-height: 1.45; }
.field select { -webkit-appearance: none; appearance: none; }
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; font-size: 15px; padding: 8px 14px; border-radius: 999px;
  background: rgba(46,207,122,0.12); color: var(--text); border: none; cursor: pointer; white-space: nowrap;
}
.chip.sel { background: rgba(46,207,122,0.32); }

.btn-row { padding: 15px 16px; color: var(--accent); cursor: pointer; font-size: var(--fs-row); font-weight: 500; }
.btn-row:active { opacity: 0.5; }

/* ---------- Ordner / Gruppen ---------- */
.folder-cell {
  background: var(--bg-elev);
  margin: 0 12px; border-radius: var(--radius);
  border-bottom: none;
}
.folder-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; min-height: 56px;
  background: var(--bg-elev); border-radius: var(--radius);
  cursor: pointer;
}
.folder-ico { display: flex; flex: 0 0 auto; color: var(--accent); }
.folder-ico svg { width: 22px; height: 22px; }
.folder-name { font-size: var(--fs-row); font-weight: 600; letter-spacing: -0.01em; }
.folder-count {
  font-size: 13px; font-weight: 600; color: var(--text-2);
  background: var(--bg-elev-2); border-radius: 999px;
  min-width: 24px; text-align: center; padding: 2px 8px;
}
.folder-edit {
  background: none; border: none; cursor: pointer; padding: 0;
  display: flex; color: var(--text-3); flex: 0 0 auto;
}
.folder-edit svg { width: 18px; height: 18px; }
.folder-empty {
  margin: 8px 12px 0; padding: 18px; border-radius: var(--radius);
  border: 1.5px dashed var(--separator); text-align: center;
  color: var(--text-3); font-size: 14px;
}

/* Drag-Handle in Rezeptzeilen */
.drag-handle {
  background: none; border: none; cursor: grab; padding: 4px;
  display: flex; flex: 0 0 auto; color: var(--text-3);
  touch-action: none;
}
.drag-handle svg { width: 20px; height: 20px; }
.drag-handle:active { cursor: grabbing; }

/* Drag-Ghost (folgt dem Finger/Cursor) */
.drag-ghost {
  position: fixed; z-index: 300; left: 0; top: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
  background: var(--accent); color: #04130b;
  font-weight: 700; font-size: 15px;
  padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
body.dragging { cursor: grabbing; user-select: none; }
body.dragging #screen { overflow: hidden; }

/* Drop-Ziel hervorheben */
.drop-hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.folder-head.drop-hover, .cat-head.drop-hover {
  background: rgba(46,207,122,0.16); border-radius: var(--radius);
}
.folder-empty.drop-hover { border-color: var(--accent); color: var(--accent); background: rgba(46,207,122,0.08); }

/* ---------- Lock screen ---------- */
body.locked { overflow: hidden; }
#lockScreen {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.lock-card {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.lock-emoji {
  width: 84px; height: 84px; border-radius: 24px;
  background: var(--bg-elev);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; margin-bottom: 22px;
}
.lock-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.lock-sub { font-size: 15px; color: var(--text-2); margin-top: 6px; margin-bottom: 26px; }
#lockInput {
  width: 100%; padding: 15px 16px; border-radius: 13px;
  background: var(--bg-elev-2); border: 1.5px solid transparent;
  color: var(--text); font-size: 17px; font-family: inherit; outline: none;
  text-align: center;
}
#lockInput:focus { border-color: var(--accent); }
#lockInput::placeholder { color: var(--text-3); }
.lock-error { color: var(--red); font-size: 14px; margin-top: 12px; font-weight: 500; }
.lock-btn {
  width: 100%; margin-top: 16px; padding: 15px; border-radius: 13px;
  background: var(--accent); color: #04130b; border: none; cursor: pointer;
  font-size: 17px; font-weight: 700;
}
.lock-btn:active { background: var(--accent-press); }
