:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface2: #efede7; --text: #1d2420; --muted: #66706a; --line: #e3e0d8;
  --accent: #1f8a5b; --accent-ink: #ffffff; --accent-soft: #dff2e7;
  --veg: #1f8a5b; --meat: #c8581f; --veg-soft: #dff2e7; --meat-soft: #fbe6d8;
  --kcal: #6b7a90; --p: #1f8a5b; --c: #d79a1f; --f: #8a63c9;
  --ok: #1f8a5b; --near: #d79a1f; --low: #cf4b3f; --none: #c9c6bd;
  --shadow: 0 1px 2px rgba(20,30,25,.06), 0 4px 14px rgba(20,30,25,.06);
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --surface: #1b211e; --surface2: #242c28; --text: #eaf0ec; --muted: #9aa8a0; --line: #2d3732;
    --accent: #3fc287; --accent-ink: #08130d; --accent-soft: #1c3a2c;
    --veg: #3fc287; --meat: #f0905a; --veg-soft: #1c3a2c; --meat-soft: #432a1c;
    --kcal: #93a3bb; --p: #3fc287; --c: #e8b345; --f: #b494ee;
    --ok: #3fc287; --near: #e8b345; --low: #ef6d61; --none: #46504a; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121614; --surface: #1b211e; --surface2: #242c28; --text: #eaf0ec; --muted: #9aa8a0; --line: #2d3732;
  --accent: #3fc287; --accent-ink: #08130d; --accent-soft: #1c3a2c;
  --veg: #3fc287; --meat: #f0905a; --veg-soft: #1c3a2c; --meat-soft: #432a1c;
  --kcal: #93a3bb; --p: #3fc287; --c: #e8b345; --f: #b494ee;
  --ok: #3fc287; --near: #e8b345; --low: #ef6d61; --none: #46504a; --shadow: none;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior-y: none; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; touch-action: manipulation; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.app { max-width: 680px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }

/* Kopf */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 22px; flex: 1; letter-spacing: -.01em; }
.top .sub { font-size: 13px; color: var(--muted); display: block; font-weight: 500; margin-top: 2px; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 20px; }
.iconbtn:active { transform: scale(.96); }
main { padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 12px; }

/* Navigation (unten, Daumen-Reichweite) */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav-in { max-width: 680px; margin: 0 auto; display: grid; grid-template-columns: repeat(6, 1fr); height: var(--nav-h); }
.nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); }
.nav button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button[aria-current="page"] { color: var(--accent); }

/* Bausteine */
.card { background: var(--surface); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.bold { font-weight: 700; }
.h2 { font-size: 17px; font-weight: 700; }
.sp { height: 4px; }
.btn { min-height: 44px; padding: 0 16px; border-radius: 12px; background: var(--surface2); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--low); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 999px; background: var(--surface2); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip[aria-pressed="true"], .chip.on { background: var(--accent); color: var(--accent-ink); }
.chip.veg { background: var(--veg-soft); color: var(--veg); }
.chip.meat { background: var(--meat-soft); color: var(--meat); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { min-height: 40px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); padding: 0 6px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.veg { background: var(--veg-soft); color: var(--veg); }
.badge.meat { background: var(--meat-soft); color: var(--meat); }
.badge.warn { background: color-mix(in srgb, var(--near) 22%, transparent); color: var(--near); }
.badge.bad { background: color-mix(in srgb, var(--low) 18%, transparent); color: var(--low); }
.badge.gray { background: var(--surface2); color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--none); flex: none; }
.dot.ok { background: var(--ok); } .dot.near { background: var(--near); } .dot.low { background: var(--low); } .dot.none { background: var(--none); }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty b { color: var(--text); display: block; font-size: 17px; margin-bottom: 4px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=search], select, textarea {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; width: 100%; font-size: 16px; color: var(--text);
}
textarea { padding: 10px 12px; min-height: 64px; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fgrid.three { grid-template-columns: repeat(3, 1fr); }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

/* Makro-Balken */
.bars { display: grid; gap: 8px; }
.bar .lab { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 3px; }
.bar .lab b { font-weight: 700; }
.track { height: 9px; border-radius: 99px; background: var(--surface2); overflow: hidden; position: relative; }
.fill { height: 100%; width: 100%; transform-origin: left; border-radius: 99px; background: var(--kcal); transition: transform .3s; }
.fill.p { background: var(--p); } .fill.c { background: var(--c); } .fill.f { background: var(--f); }
.fill.over { opacity: .65; }
.bars.compact { grid-template-columns: 1fr 1fr; gap: 6px 14px; }

/* Mahlzeiten */
.meal { display: grid; gap: 8px; }
.meal-h { display: flex; gap: 10px; align-items: flex-start; }
.meal-h .t { flex: 1; min-width: 0; }
.meal-h .lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.meal-h .name { font-size: 17px; font-weight: 700; }
.pp { border-top: 1px solid var(--line); padding-top: 8px; display: grid; gap: 6px; }
.pp.skipped .nm, .pp.skipped .mac { text-decoration: line-through; opacity: .5; }
.stepper { display: inline-flex; align-items: center; background: var(--surface2); border-radius: 10px; }
.stepper button { width: 36px; height: 36px; font-size: 20px; font-weight: 700; }
.stepper span { min-width: 44px; text-align: center; font-weight: 700; font-size: 14px; }
.mac { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mac b { color: var(--text); }
.lockon { color: var(--accent); }

/* Kalender */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding: 2px 0; }
.cal button.day { min-width: 0; padding: 0; aspect-ratio: 1 / 1.05; border-radius: 12px; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-weight: 600; font-size: 15px; border: 2px solid transparent; }
.cal.week button.day { aspect-ratio: auto; min-height: 84px; }
.cal button.day.today { border-color: var(--accent); }
.cal button.day.out { opacity: .4; }
.cal button.day.sel { background: var(--accent-soft); }
.cal .pdot { width: 12px; height: 12px; border-radius: 50%; background: var(--none); }
.cal .pdot.ok { background: var(--ok); } .cal .pdot.near { background: var(--near); } .cal .pdot.low { background: var(--low); }
.cal .pdot.plan { background: transparent; border: 2px solid var(--ok); }
.cal .cnt { font-size: 11px; color: var(--muted); font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.stat { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat > div { background: var(--surface2); border-radius: 12px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 600; }

/* Rezepte */
.rcard { display: flex; gap: 10px; align-items: center; text-align: left; width: 100%; }
.rcard .nm { font-weight: 700; }
.fav { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; flex: none; }
.fav.on { color: var(--low); }
.ing li, .steps li { margin: 3px 0; }
.ing { list-style: none; padding: 0; margin: 0; }
.ing li { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--line); padding: 4px 0; font-size: 15px; }
.ing li span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.steps { padding-left: 22px; margin: 0; }
.steps li.v { margin-left: -12px; list-style-position: inside; background: var(--veg-soft); border-radius: 8px; padding: 6px 8px; }
.steps li.m { margin-left: -12px; list-style-position: inside; background: var(--meat-soft); border-radius: 8px; padding: 6px 8px; }
.steps li .tag { font-weight: 800; font-size: 12px; margin-right: 6px; }
.steps li.v .tag { color: var(--veg); } .steps li.m .tag { color: var(--meat); }
table.calc { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.calc th, table.calc td { text-align: right; padding: 4px 3px; border-bottom: 1px solid var(--line); }
table.calc th:first-child, table.calc td:first-child { text-align: left; }
table.calc tr.sum td { font-weight: 800; border-top: 2px solid var(--text); }
details summary { cursor: pointer; font-weight: 600; min-height: 36px; display: flex; align-items: center; }

/* Einkauf */
.shop-i { display: flex; align-items: center; gap: 12px; min-height: 48px; border-bottom: 1px solid var(--line); }
.shop-i:last-child { border: 0; }
.shop-i.done .nm { text-decoration: line-through; color: var(--muted); }
.shop-i .am { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }

/* Sheet */
.scrim { position: fixed; inset: 0; background: rgba(10,14,12,.5); z-index: 50; animation: fade .18s; }
.sheet { position: fixed; z-index: 51; left: 0; right: 0; bottom: 0; max-height: 92dvh; background: var(--bg); border-radius: 22px 22px 0 0; display: flex; flex-direction: column; animation: up .22s cubic-bezier(.2,.8,.2,1); max-width: 680px; margin: 0 auto; }
.sheet-h { padding: 8px 16px 10px; display: flex; align-items: center; gap: 10px; }
.sheet-h::before { content: ""; position: absolute; left: 50%; top: 6px; width: 38px; height: 4px; border-radius: 4px; background: var(--line); transform: translateX(-50%); }
.sheet-h h2 { flex: 1; font-size: 19px; padding-top: 10px; }
.sheet-b { overflow: auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.dock { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 10; }
.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); max-width: 90vw; }
.warnline { font-size: 12px; color: var(--near); font-weight: 600; }
.badline { font-size: 12px; color: var(--low); font-weight: 600; }
.linkbtn { text-align: left; font-weight: 700; font-size: 17px; color: var(--text); padding: 0; min-height: 28px; display: block; }
.linkbtn:active { color: var(--accent); }
.rcard { padding: 0; }
.card[data-a], button.card { width: 100%; }

.pp .row { flex-wrap: wrap; }
.card .row > .h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .row.head { flex-wrap: wrap; row-gap: 6px; }
main { min-width: 0; }
main > *, .card > *, .sheet-b > * { min-width: 0; }
[style*="display:grid"], .bars, .meal, .pp { grid-template-columns: minmax(0, 1fr); }
.bars.compact, .fgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fgrid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.seg button { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { max-width: 100%; }
