:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1d1f22;
  --muted: #6b6f76;
  --line: #e6e3dc;
  --accent: #2f6f5e;
  --accent-soft: #e2efe9;
  --warn: #b5541c;
  --warn-soft: #fbeadf;
  --good: #2f7a4a;
  --kh: #c08a1e;
  --pr: #2f6f9e;
  --fe: #9a4f7a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b; --card: #1f2226; --text: #eceae4; --muted: #9a9ea6; --line: #2e3238;
    --accent: #6cc3a6; --accent-soft: #23392f; --warn: #f0a070; --warn-soft: #3a2a20; --good: #7fd19c;
    --kh: #e2b35a; --pr: #7fb3e0; --fe: #d495bb; --shadow: none; color-scheme: dark;
  }
}
* { 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, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
h1, h2 { margin: 0; font-weight: 650; }
h2 { font-size: 17px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--warn); margin: 8px 0 0; }

main { max-width: 560px; margin: 0 auto; padding: 0 16px 16px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-top: 14px; border: 1px solid var(--line);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.hint { font-size: 13px; color: var(--muted); }

/* Kopf mit Datum */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  max-width: 560px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top)) 12px 8px;
  background: var(--bg);
}
.icon-btn, .date-btn { background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; }
.icon-btn { font-size: 28px; width: 44px; height: 44px; border-radius: 12px; }
.icon-btn:active { background: var(--line); }
.date-btn { font-weight: 650; font-size: 17px; padding: 8px 12px; border-radius: 10px; }

/* Vitalwerte */
.vitals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 4px; }
.vital { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 6px; text-align: center; }
.vital b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.vital span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Check-in */
.ci-row { padding: 8px 0; border-top: 1px solid var(--line); }
.ci-row:first-child { border-top: 0; padding-top: 0; }
.ci-label { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button {
  font: inherit; font-size: 14px; padding: 9px 2px; border-radius: 10px; cursor: pointer;
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
}
.seg button.on { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg button.on { color: #10261e; } }
.seg button.on.bad { background: var(--warn); border-color: var(--warn); }

/* Summen */
.tot { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 8px; }
.tot .k { font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.tot .k b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.bar.kh i { background: var(--kh); } .bar.pr i { background: var(--pr); } .bar.fe i { background: var(--fe); }
.bar i.over { background: var(--warn); }

/* Einträge */
.slot-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 4px; text-transform: uppercase; letter-spacing: .04em; display: flex; justify-content: space-between; }
.entry { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.entry:first-of-type { border-top: 0; }
.entry .main { flex: 1; min-width: 0; }
.entry .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .sub { font-size: 12px; color: var(--muted); }
.entry .kcal { font-variant-numeric: tabular-nums; font-size: 14px; }
.del { background: none; border: 0; color: var(--muted); font-size: 20px; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; }
.del:active { background: var(--line); }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0 4px; }

/* Buttons & Formulare */
.btn {
  font: inherit; font-weight: 600; padding: 11px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10261e; } }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .5; }
.chip { font: inherit; font-size: 13px; font-weight: 600; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; }
.chip.ok { color: var(--good); }
.chip.bad { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
input, select {
  font: inherit; width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); margin-top: 6px;
}
/* iOS zoomt bei Eingabefeldern unter 16 px hinein – daher fest 16 px, auch innerhalb von <label> */
input, select, textarea { font-size: 16px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label { display: block; font-size: 14px; color: var(--muted); margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { margin-top: 6px; }
.row input { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; margin: 0; }

/* Listen */
.list { margin-top: 8px; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.item:first-child { border-top: 0; }
.item .main { flex: 1; min-width: 0; }
.item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 12px; color: var(--muted); }
.star { color: var(--kh); }

/* Tabs unten */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; max-width: 140px; background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px;
  padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tabs button span { font-size: 20px; line-height: 1.1; }
.tabs button.active { color: var(--accent); font-weight: 600; }

/* Bottom-Sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; box-shadow: 0 -4px 24px rgba(0,0,0,.15);
}
.sheet .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.slots { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 6px; scrollbar-width: none; }
.slots button { flex: none; }
.slots .chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .slots .chip.on { color: #10261e; } }
.subtabs { display: flex; gap: 6px; margin: 8px 0 2px; }
.portions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.preview { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; background: var(--bg); border-radius: 12px; padding: 10px 4px; margin-top: 12px; }
.preview b { display: block; font-variant-numeric: tabular-nums; }
.preview span { font-size: 11px; color: var(--muted); }
.meal-items .entry { padding: 6px 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card .logo { color: var(--accent); font-size: 36px; }
.login-card .btn { width: 100%; margin-top: 12px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px);
}

/* Zutaten-Editor */
.ing .entry { gap: 6px; }
.ing-g { width: 74px; flex: none; margin: 0; padding: 7px 8px; text-align: right; }
.ing-results { margin-top: 4px; }
.ing-results .btn { margin-top: 8px; font-size: 14px; }
.cook-btn { margin: 4px 0 6px; }

/* Einträge antippen zum Bearbeiten */
.entry .main.tap, .entry .kcal.tap { cursor: pointer; }
.entry-edit .amount { margin-top: 4px; }
