/* Copyright (C) 2026 Pathics (https://www.pathics.de) */
:root {
  --bg: #f4f6f3; --card: #ffffff; --text: #1b1f1c; --muted: #6a736c; --line: #e3e7e2;
  --accent: #2f7d4f; --accent-text: #ffffff; --accent-soft: #e2f0e6;
  --protein: #3d7fd1; --carbs: #d9952b; --fat: #c45a8a; --fiber: #6e8f3a; --sugar: #8a6cc9;
  --danger: #c43d3d; --over: #d0603a; --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816; --card: #1f2420; --text: #eef1ee; --muted: #9aa49c; --line: #2f3631;
    --accent: #4fb07a; --accent-text: #0d1a12; --accent-soft: #23382b;
    --protein: #6aa6ee; --carbs: #f0b354; --fat: #e283b0; --fiber: #9dc066; --sugar: #b79cf0;
    --danger: #ef6b6b; --over: #f08a5f; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}
main { max-width: 640px; margin: 0 auto; padding: 0 14px 120px; }
.loading { text-align: center; color: var(--muted); margin-top: 30vh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 17px; /* >=16px verhindert Zoom auf iOS */
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: 10px 0;
}
.topbar .title { flex: 1; text-align: center; }
.topbar .title small { display: block; font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; display: inline-flex;
  align-items: center; justify-content: center; color: var(--text);
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 24px; height: 24px; }

/* Karten */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }

/* Tageszusammenfassung */
.kcal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.kcal-big { font-size: 30px; font-weight: 700; }
.kcal-big span { font-size: 15px; font-weight: 400; color: var(--muted); }
.remaining { text-align: right; font-size: 14px; color: var(--muted); }
.remaining b { display: block; font-size: 20px; color: var(--text); }
.remaining.over b { color: var(--over); }
.bar { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .3s; }
.bar.over > i { background: var(--over); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.macros.five { grid-template-columns: repeat(3, 1fr); }
.macro .label { font-size: 13px; color: var(--muted); }
.macro .val { font-size: 15px; font-weight: 600; }
.macro .bar { height: 6px; margin-top: 4px; }
.macro.protein .bar > i { background: var(--protein); }
.macro.carbs .bar > i { background: var(--carbs); }
.macro.fat .bar > i { background: var(--fat); }
.macro.fiber .bar > i { background: var(--fiber); }
.macro.sugar .bar > i { background: var(--sugar); }
.macro .bar.over > i { background: var(--over); }
.incomplete-hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* Mahlzeiten */
.meal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.meal-head .kcal { color: var(--muted); font-size: 14px; }
.entry {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.entry:last-of-type { border-bottom: 0; }
.entry .main { flex: 1; min-width: 0; }
.entry .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .sub { font-size: 13px; color: var(--muted); }
.entry .kcal { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.meal-actions { display: flex; gap: 8px; margin-top: 8px; }
.meal-actions button {
  flex: 1; padding: 10px; border-radius: 12px; background: var(--accent-soft); color: var(--accent);
  font-weight: 600; font-size: 15px;
}
.meal-actions button.secondary { background: transparent; color: var(--muted); font-weight: 500; }

.fab {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  box-shadow: 0 6px 20px rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; z-index: 10;
}
.fab svg { width: 32px; height: 32px; }
.fab:active { transform: scale(.95); }

/* Suche */
.search-wrap { position: sticky; top: 64px; z-index: 4; background: var(--bg); padding-bottom: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 8px 14px; border-radius: 99px; background: var(--card); border: 1px solid var(--line);
  font-size: 15px; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 4px 6px; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .pick { flex: 1; min-width: 0; text-align: left; padding: 12px 14px; min-height: 56px; }
.item .pick:active { background: var(--line); }
.item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.star { width: 52px; height: 56px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.star.on { color: #e3a21a; }
.star svg { width: 22px; height: 22px; }
.status { padding: 14px; color: var(--muted); font-size: 14px; text-align: center; }
.status.error { color: var(--danger); }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--muted); margin-left: 4px; vertical-align: 1px; }

/* Buttons */
.btn {
  display: block; width: 100%; padding: 14px; border-radius: 14px; background: var(--accent);
  color: var(--accent-text); font-weight: 600; font-size: 17px; text-align: center; margin-top: 14px;
}
.btn:active { filter: brightness(.95); }
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Bottom Sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; max-height: 92vh; overflow-y: auto; animation: up .18s ease-out;
}
.sheet .grip { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { margin-bottom: 2px; }
.amount-row { display: flex; gap: 10px; align-items: stretch; margin-top: 12px; }
.amount-row input { font-size: 26px; font-weight: 600; text-align: center; flex: 1; }
.amount-row .unit { display: flex; align-items: center; color: var(--muted); font-size: 17px; min-width: 40px; }
.preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; text-align: center; }
.preview div { background: var(--bg); border-radius: 10px; padding: 8px 4px; }
.preview b { display: block; font-size: 17px; }
.preview span { font-size: 12px; color: var(--muted); }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

/* Formulare */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.portion-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.portion-row input:first-child { flex: 2; }
.portion-row input:nth-child(2) { flex: 1; }
.form-error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 1em; }
.auth { max-width: 380px; margin: 12vh auto 0; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 12px; }
.auth h1 { text-align: center; margin-bottom: 4px; }
.auth p { text-align: center; }
.user-list { margin: 0; padding: 0; list-style: none; }
.user-list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-list li:last-child { border-bottom: 0; }

/* Toast */
#toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: 90vw; text-align: center;
}
#toast.show { opacity: .95; }
#toast.error { background: var(--danger); color: #fff; }

[hidden] { display: none !important; }

/* Barcode */
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; }
.scan-btn {
  flex: none; width: 52px; border-radius: 12px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.scan-btn svg { width: 26px; height: 26px; }
.fab-secondary {
  position: fixed; right: calc(max(18px, env(safe-area-inset-right)) + 76px); bottom: calc(28px + env(safe-area-inset-bottom));
  width: 52px; height: 52px; border-radius: 50%; background: var(--card); color: var(--accent);
  box-shadow: 0 4px 14px rgba(0,0,0,.2); display: flex; align-items: center; justify-content: center; z-index: 10;
}
.fab-secondary svg { width: 26px; height: 26px; }
.scanner {
  position: fixed; inset: 0; z-index: 25; background: #000; color: #fff; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.scanner-top { display: flex; align-items: center; padding: 8px 10px; }
.scanner-top h2 { flex: 1; text-align: center; }
.scanner-top .icon-btn { color: #fff; font-size: 22px; }
.scanner-view { position: relative; flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.scanner-view video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame {
  position: absolute; left: 10%; right: 10%; top: 50%; height: 34%; transform: translateY(-50%);
  border: 3px solid rgba(255,255,255,.9); border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35);
}
.scanner-bottom { background: var(--card); color: var(--text); padding: 14px 16px 18px; border-radius: 20px 20px 0 0; margin-top: auto; }
.scanner-status { margin: 0 0 4px; text-align: center; color: var(--muted); min-height: 1.4em; }
.scanner-status.error { color: var(--danger); }
.scanner-manual { display: flex; gap: 8px; margin-top: 10px; align-items: stretch; }
.scanner-manual input { flex: 1; }
.scanner-manual .btn { width: auto; margin: 0; padding: 0 20px; }
label.btn { color: var(--accent-text); cursor: pointer; }
label.btn.ghost { color: var(--accent); }
.scanner-hint { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #cfd6d0; text-align: center; padding: 20px; }
.scanner-hint svg { width: 120px; height: 120px; opacity: .8; }
.chip.active .muted { color: inherit; opacity: .75; }

/* Rezepte */
textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font: inherit; font-size: 16px; color: inherit; resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.recipe-row { display: flex; align-items: center; gap: 12px; }
.recipe-row .main { flex: 1; min-width: 0; display: block; }
.recipe-row .name, .recipe-row .sub { display: block; }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; background: var(--line); }
.thumb.ph { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.thumb.ph svg { width: 24px; height: 24px; }
.sub.warn, .incomplete-hint.warn { color: var(--over); }
.hero { width: 100%; max-height: 240px; object-fit: cover; border-radius: var(--radius); margin-bottom: 12px; display: block; }
.clip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 18px; }
.instructions { white-space: pre-wrap; margin: 8px 0 0; }
.entry.ing { align-items: flex-start; }
.entry .name { white-space: normal; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--line); }
.dot.ok { background: var(--accent); }
.dot.suggest { background: var(--carbs); }
.dot.warn { background: var(--over); }
.dot.ignored { background: var(--muted); }
.sub.ok { color: var(--accent); }
.sub.ignored { font-style: italic; }
.sticky-action {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent); max-width: 640px; margin: 0 auto;
}
.sticky-action .btn { margin: 0; }
.ing-results { margin-top: 8px; max-height: 38vh; overflow-y: auto; }
.pick.chosen { background: var(--accent-soft); }
.chip { color: inherit; }

/* Einkaufsliste */
.sticky-action.row { display: flex; gap: 10px; }
.sticky-action.row .btn { flex: 1; }
.sticky-action.row .btn.ghost { background: var(--card); box-shadow: var(--shadow); border: 1px solid var(--line); }
.servings-row { display: flex; align-items: center; justify-content: center; gap: 24px; margin: 14px 0 6px; }
.round-btn { width: 48px; height: 48px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 26px; font-weight: 600; }
.servings-val { text-align: center; min-width: 80px; }
.servings-val b { display: block; font-size: 28px; }
.shop-list { margin-top: 10px; max-height: 42vh; overflow-y: auto; }
.shop-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; margin: 0; color: var(--text); font-size: 16px; }
.shop-item input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); margin: 0; }
.shop-item .main { flex: 1; min-width: 0; }
.shop-item .name, .shop-item .sub { display: block; }
.shop-item.off .name { text-decoration: line-through; color: var(--muted); }
.ok-text { color: var(--accent); }
.error-text { color: var(--danger); }

/* Phase 5: Export */
.check-row { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; font-weight: 400; }
.check-row input { width: 22px; height: 22px; min-height: 0; margin: 0; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.export-grid .btn { margin: 0; text-align: center; text-decoration: none; display: flex; align-items: center; justify-content: center; }

/* Phase 5: Statistik */
.day-links { display: flex; gap: 8px; margin-top: 14px; }
.day-links button { flex: 1; padding: 10px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 15px; }
.stat-chips { padding: 12px 16px 0; }
.stat-nav { display: flex; justify-content: space-between; padding: 8px 16px 0; }
.stat-nav button { display: flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 600; padding: 8px 4px; }
.stat-nav button:disabled { opacity: .35; }
.stat-nav svg { width: 18px; height: 18px; }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart rect { fill: var(--accent); }
.chart rect.over { fill: var(--over); }
.chart text { font-size: 10px; fill: var(--muted); }
.chart .goal { stroke: var(--text); stroke-width: 1; stroke-dasharray: 4 3; opacity: .5; }
.chart .goal-label { font-size: 10px; fill: var(--text); opacity: .7; }
.stat-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat-facts b { display: block; font-size: 26px; }
.stat-facts span { font-size: 12px; color: var(--muted); }
.stat-table { display: flex; flex-direction: column; }
.stat-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; padding: 11px 0; border-top: 1px solid var(--line); text-align: left; width: 100%; }
.stat-row:first-child { border-top: 0; }
.stat-row span:not(:first-child) { text-align: right; }

/* Phase 5: Wochenplan */
.plan-day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.plan-day.past { opacity: .7; }
.plan-day .meal-head h2 { font-size: 17px; }
.plan-add { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; }
.plan-add svg { width: 20px; height: 20px; }
.plan-empty { margin: 6px 0 2px; }
#plan-add-sheet input[type=search] { margin-top: 8px; }
#pl-body { padding-bottom: 84px; }

/* Phase 5: Vorschlaege */
.sg-remaining { font-size: 17px; margin: 4px 0 6px; }
.idea { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.idea h3 { margin: 0 0 4px; font-size: 17px; }
.idea .btn { margin-top: 10px; }
.pre { white-space: pre-line; }
.day-links button { font-size: 14px; padding: 10px 4px; }
