:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eceee9;
  --text: #1b1f1c;
  --muted: #69716b;
  --line: #dde1db;
  --accent: #23825a;
  --accent-soft: #dcefe5;
  --on-accent: #ffffff;
  --protein: #c2572e;
  --carbs: #c6951d;
  --fat: #3f6fb5;
  --water: #2a8fb8;
  --danger: #c23b3b;
  --warn-soft: #fbf0d6;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .06);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111412;
    --surface: #1a1e1b;
    --surface-2: #242925;
    --text: #e9ece8;
    --muted: #949c95;
    --line: #2d332e;
    --accent: #45b386;
    --accent-soft: #1d3a2d;
    --on-accent: #08130d;
    --protein: #e07a50;
    --carbs: #e0b440;
    --fat: #6f9be0;
    --water: #4fb3dc;
    --danger: #e56262;
    --warn-soft: #3a3020;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

/* Kopfzeile */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 14px; }
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.datenav { display: flex; align-items: center; gap: 4px; }
.datenav .label { min-width: 120px; text-align: center; font-weight: 600; }
.datenav .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--surface);
  display: inline-grid; place-items: center; box-shadow: var(--shadow);
}
.icon-btn svg { width: 20px; height: 20px; }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Tagesübersicht */
.summary { display: grid; grid-template-columns: 128px 1fr; gap: 18px; align-items: center; }
.ring { position: relative; width: 128px; height: 128px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.ring .cap { font-size: 12px; color: var(--muted); }
.macros { display: grid; gap: 10px; }
.macro .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.macro .row b { font-weight: 600; }
.bar { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; transition: width .3s; }

/* Wasser */
.water { display: flex; align-items: center; gap: 12px; }
.water .amount { flex: 1; }
.water .amount b { font-size: 18px; }
.water .bar > span { background: var(--water); }
.chip-btn {
  border: 0; background: var(--surface-2); padding: 8px 12px; border-radius: 99px; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chip-btn.primary { background: var(--accent-soft); color: var(--accent); }

/* Mahlzeiten */
.meal .card-head { margin-bottom: 4px; }
.meal .kcal { font-weight: 600; }
.entry {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 0; border: 0; background: none;
  border-top: 1px solid var(--line); text-align: left;
}
.entry:first-of-type { border-top: 0; }
.entry .name { flex: 1; min-width: 0; }
.entry .name div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .name small { color: var(--muted); font-size: 13px; }
.entry .k { font-weight: 600; font-size: 15px; }
.meal-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.add-btn {
  flex: 1; border: 1.5px dashed var(--line); background: none; border-radius: 12px; padding: 10px; font-weight: 600; color: var(--accent);
}
.link-btn { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 10px 4px; }

/* Tab-Leiste */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--tabbar-h); }
.tabbar button {
  border: 0; background: none; display: grid; place-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding-top: 8px;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* Bottom-Sheet */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 18px);
  animation: up .2s ease-out;
}
.sheet .grip { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 0 0 12px; font-size: 18px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h3 { margin: 0; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

/* Formulare */
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 12px; outline: none;
  font-size: 16px; /* verhindert Zoom auf iOS */
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: none; min-height: 52px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.btn {
  border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 650; background: var(--surface-2); width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  color: inherit; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: none; color: var(--danger); }
.btn:disabled { opacity: .55; }
.btn svg { width: 20px; height: 20px; }
.row-btns { display: flex; gap: 8px; margin-top: 8px; }
.row-btns .btn { flex: 1; }

/* Hinzufügen */
.composer { position: relative; }
.composer textarea { padding-right: 56px; }
.composer .send {
  position: absolute; right: 6px; bottom: 6px; width: 40px; height: 40px; border-radius: 10px; border: 0;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
}
.composer .send svg { width: 20px; height: 20px; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 16px; }
.tool {
  border: 0; background: var(--surface-2); border-radius: 12px; padding: 12px 6px; display: grid; place-items: center; gap: 4px;
  font-size: 13px; font-weight: 600;
}
.tool svg { width: 22px; height: 22px; color: var(--accent); }
.list-title { font-size: 13px; color: var(--muted); margin: 6px 0 2px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.food-row {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.food-row .name { flex: 1; min-width: 0; }
.food-row .name div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.food-row small { color: var(--muted); font-size: 13px; }
.plus {
  width: 32px; height: 32px; border-radius: 99px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; flex: none;
}
.plus svg { width: 18px; height: 18px; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: 14px; }

.badge { display: inline-block; font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); vertical-align: 1px; }
.badge.db { background: var(--accent-soft); color: var(--accent); }
.badge.low { background: var(--warn-soft); color: var(--carbs); }

/* Vorschläge */
.sugg { display: grid; grid-template-columns: 1fr 92px 32px; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sugg .input { padding: 8px 10px; text-align: right; }
.sugg .x { border: 0; background: none; color: var(--muted); width: 32px; height: 32px; display: grid; place-items: center; }
.sugg .x svg { width: 18px; height: 18px; }
.note { background: var(--warn-soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 8px; }
.total-line { display: flex; justify-content: space-between; padding: 12px 0 4px; font-weight: 650; }

/* Menge */
.qty-big { display: flex; align-items: baseline; gap: 8px; }
.qty-big .input { font-size: 28px; font-weight: 700; text-align: center; padding: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 14px; }
.nutr { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; background: var(--surface-2); border-radius: 12px; padding: 10px 4px; margin-bottom: 14px; }
.nutr b { display: block; font-size: 18px; }
.nutr span { font-size: 12px; color: var(--muted); }

/* Scanner */
.scanner { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; margin-bottom: 12px; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 28% 12%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); }

/* Gewicht */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 20px; letter-spacing: -.01em; }
.stat span { font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid line { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 11px; }
.weight-row { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }

/* Toast & Laden */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 40;
  max-width: calc(100% - 32px); animation: up .2s ease-out;
}
.spinner { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 26px; color: var(--muted); }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 24px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

/* ---------- Training ---------- */
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; color: var(--muted); }
.thumb svg { width: 22px; height: 22px; }
.thumb.lg { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 14px; }
.active-card { background: var(--accent); color: var(--on-accent); display: flex; align-items: center; gap: 12px; }
.active-card .btn { width: auto; background: var(--on-accent); color: var(--accent); }
.plan-card { display: flex; align-items: center; gap: 12px; }
.plan-card .info { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 0; }
.plan-card .info b { display: block; font-size: 16px; }
.plan-card .info small { color: var(--muted); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.start-btn { border: 0; background: var(--accent); color: var(--on-accent); width: 44px; height: 44px; border-radius: 99px; display: grid; place-items: center; flex: none; }
.start-btn svg { width: 20px; height: 20px; margin-left: 2px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.section-title { font-size: 13px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; margin: 18px 4px 8px; }
.week { display: flex; gap: 6px; margin-top: 10px; }
.week span { flex: 1; height: 8px; border-radius: 99px; background: var(--surface-2); }
.week span.on { background: var(--accent); }

.wo-head { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(env(safe-area-inset-top) + 8px) 0 10px; margin: calc(-12px - env(safe-area-inset-top)) 0 4px; display: flex; align-items: center; gap: 10px; }
.wo-head .t { flex: 1; min-width: 0; }
.wo-head .t b { display: block; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wo-head .t span { font-size: 13px; color: var(--muted); }
.wo-head .btn { width: auto; padding: 10px 16px; }
.ex-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.ex-head .n { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 0; }
.ex-head .n b { display: block; font-size: 16px; }
.ex-head .n small { color: var(--muted); font-size: 13px; }
.ex-note { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 7px 10px; margin-bottom: 8px; }
.sets { display: grid; grid-template-columns: 26px 1fr 64px 52px 44px 40px; gap: 6px; align-items: center; }
.sets .h { font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .03em; text-align: center; }
.sets .h:nth-child(2) { text-align: left; }
.sets .no { text-align: center; font-weight: 650; color: var(--muted); }
.sets .prev { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sets input { width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px 4px; text-align: center; font-size: 16px; font-weight: 600; outline: none; }
.sets input:focus { border-color: var(--accent); }
.sets input::placeholder { color: var(--muted); font-weight: 400; opacity: .7; }
.sets .ok { width: 40px; height: 38px; border-radius: 9px; border: 0; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; }
.sets .ok svg { width: 18px; height: 18px; }
.sets .ok.on { background: var(--accent); color: var(--on-accent); }
.sets .row-done input { background: var(--accent-soft); border-color: transparent; }
.ex-actions { display: flex; gap: 8px; margin-top: 10px; }
.ex-actions .chip-btn { flex: 1; }

.rest {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 15;
  width: calc(100% - 32px); max-width: 528px; background: var(--text); color: var(--bg); border-radius: 16px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); overflow: hidden;
}
.rest .time { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; flex: 1; }
.rest .time small { font-size: 12px; font-weight: 500; opacity: .7; display: block; }
.rest button { border: 0; background: color-mix(in srgb, var(--bg) 18%, transparent); color: var(--bg); border-radius: 10px; padding: 8px 10px; font-weight: 650; font-size: 14px; }
.rest .prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width 1s linear; }

.pe-item { border-top: 1px solid var(--line); padding: 10px 0; }
.pe-item .top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.pe-item .top .n { flex: 1; min-width: 0; font-weight: 600; }
.pe-item .mini { width: 32px; height: 32px; border: 0; background: var(--surface-2); border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
.pe-item .mini svg { width: 16px; height: 16px; }
.pe-grid { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px; }
.pe-grid label { display: grid; gap: 3px; font-size: 11px; color: var(--muted); }
.pe-grid input, .pe-note { border: 1.5px solid var(--line); background: var(--surface); border-radius: 9px; padding: 7px 6px; font-size: 16px; text-align: center; width: 100%; outline: none; }
.pe-note { text-align: left; margin-top: 6px; font-size: 14px; }

.muscles { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin: 10px -16px 6px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.muscles::-webkit-scrollbar { display: none; }
.muscles .chip-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.ex-row { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ex-row .name { flex: 1; min-width: 0; }
.ex-row .name div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex-row small { color: var(--muted); font-size: 13px; }
.pr { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.frames { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
details summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
details ol { padding-left: 20px; margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- Fortschritt ---------- */
.checkin-due { display: flex; align-items: center; gap: 12px; border: 1.5px solid var(--accent); }
.subnav { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.subnav button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.subnav button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.m-row { display: grid; grid-template-columns: 1fr 96px 64px; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.m-row:first-of-type { border-top: 0; }
.m-row .lbl small { display: block; color: var(--muted); font-size: 12px; }
.m-row input { width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px; text-align: right; font-size: 16px; outline: none; }
.m-row input:focus { border-color: var(--accent); }
.m-row .delta { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 34px; display: block; }
.trend { display: grid; grid-template-columns: 1fr 110px 70px; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.trend:first-of-type { border-top: 0; }
.down { color: var(--accent); }
.up { color: var(--protein); }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-grid button { border: 0; padding: 0; background: var(--surface-2); border-radius: 10px; overflow: hidden; aspect-ratio: 3 / 4; position: relative; }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-grid span { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 99px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.compare figure { margin: 0; }
.compare img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 12px; background: var(--surface-2); display: block; }
.compare figcaption { text-align: center; font-size: 13px; color: var(--muted); margin-top: 4px; }
.photo-full { width: 100%; border-radius: 14px; display: block; margin-bottom: 12px; }
.scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin-top: 6px; }
.scale button { border: 0; background: var(--surface-2); border-radius: 8px; padding: 9px 0; font-weight: 650; font-size: 14px; }
.scale button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.q { padding: 12px 0; border-top: 1px solid var(--line); }
.q:first-of-type { border-top: 0; }
.q > div:first-child { font-weight: 600; }
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sum-grid > div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.sum-grid b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.sum-grid span { font-size: 12px; color: var(--muted); }
.sum-grid small { font-size: 12px; font-variant-numeric: tabular-nums; }
.ans { padding: 8px 0; border-top: 1px solid var(--line); }
.ans span { display: block; font-size: 13px; color: var(--muted); }
