/* ============================================================
   DESIGN-SYSTEM v4 · MyFitnessPal-Stil
   Hell als Standard, Dunkel über body.dark (Knopf oben rechts)
   ============================================================ */
:root {
  --bg: #eef2f7;
  --bg2: #edf0f5;
  --card: #ffffff;
  --card2: #f1f4f9;
  --line: rgba(16, 24, 40, 0.08);
  --line2: rgba(16, 24, 40, 0.16);
  --text: #16202e;
  --muted: #69758a;
  --accent: #0a6cff;
  --accent2: #0a6cff;
  --green: #12b76a;
  --yellow: #d97706;
  --red: #e5484d;
  --protein: #f79009;   /* orange wie MFP */
  --carbs: #0da88f;     /* türkis wie MFP */
  --fat: #7a5af8;       /* violett wie MFP */
  --ok-bg: rgba(18, 183, 106, .12);  --ok-fg: #067647;
  --warn-bg: rgba(245, 158, 11, .16); --warn-fg: #b54708;
  --bad-bg: rgba(229, 72, 77, .12);  --bad-fg: #d92d20;
  --neutral-bg: rgba(105, 117, 138, .12); --neutral-fg: #5b6779;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .04);
  --topbar-bg: rgba(238, 242, 247, 0.88);
}
body.dark {
  --bg: #0b0e15;
  --bg2: #121722;
  --card: #161c2a;
  --card2: #1e2637;
  --line: rgba(255, 255, 255, 0.07);
  --line2: rgba(255, 255, 255, 0.14);
  --text: #f2f5fa;
  --muted: #7e8aa0;
  --accent: #3d7bfd;
  --accent2: #6f9dff;
  --green: #2fd67e;
  --yellow: #f5c445;
  --red: #f45b69;
  --protein: #f7a83c;
  --carbs: #2dd4bf;
  --fat: #a78bfa;
  --ok-bg: rgba(47, 214, 126, .13);  --ok-fg: #2fd67e;
  --warn-bg: rgba(245, 196, 69, .13); --warn-fg: #f5c445;
  --bad-bg: rgba(244, 91, 105, .13);  --bad-fg: #f45b69;
  --neutral-bg: rgba(126, 138, 160, .13); --neutral-fg: #7e8aa0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --topbar-bg: rgba(11, 14, 21, 0.85);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 12px;
  padding: 11px 13px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
body.dark input, body.dark select, body.dark textarea { background: var(--bg2); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
body.dark input[type="date"] { color-scheme: dark; }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }

#app { max-width: 560px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 400px; margin: 0 auto; }
.login-logo { width: 68px; height: 68px; border-radius: 20px; background: linear-gradient(135deg, var(--accent), #7c5cff); display: flex; align-items: center; justify-content: center; font-size: 32px; margin: 0 auto 16px; box-shadow: 0 8px 24px rgba(10,108,255,.3); }
.login-title { text-align: center; font-size: 23px; font-weight: 800; margin-bottom: 4px; letter-spacing: -0.01em; }
.login-sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 26px; }
.demo-box { background: var(--card); border: 1px dashed var(--line2); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); margin-top: 22px; }
.demo-box b { color: var(--text); }
.demo-box .demo-cred { cursor: pointer; color: var(--accent); font-weight: 600; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--topbar-bg); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: calc(14px + var(--safe-t)) 18px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.topbar .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar .tb-btns { display: flex; gap: 8px; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 16px; flex: none; color: var(--muted); box-shadow: var(--shadow); }
.icon-btn:active { transform: scale(.94); }

.content { flex: 1; padding: 4px 14px calc(150px + var(--safe-b)); }

/* ---------- Wochen-Punkte (wie MFP) ---------- */
.week-strip { display: flex; justify-content: space-between; padding: 2px 4px 12px; }
.wd { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 700; color: var(--muted); cursor: pointer; background: none; }
.wd .dot { width: 27px; height: 27px; border-radius: 50%; border: 2px solid var(--line2); display: flex; align-items: center; justify-content: center; font-size: 13px; color: transparent; background: var(--card); transition: all .15s; }
.wd.done .dot { background: var(--text); border-color: var(--text); color: var(--card); }
.wd.sel { color: var(--accent); }
.wd.sel .dot { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(10,108,255,.2); }
.wd.future { opacity: .4; cursor: default; }

/* ---------- Untere Leisten ---------- */
.bottom-dock { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; padding: 0 14px calc(10px + var(--safe-b)); max-width: 560px; margin: 0 auto; pointer-events: none; }
.food-search-bar {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 11px 16px; margin-bottom: 10px;
  color: var(--muted); font-size: 14px; box-shadow: 0 6px 20px rgba(16,24,40,.12);
  width: 100%;
}
.bottom-nav {
  pointer-events: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  display: flex; justify-content: space-around; align-items: center;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .16);
}
body.dark .bottom-nav { box-shadow: 0 12px 32px rgba(0,0,0,.45); }
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 1px; color: var(--muted); font-size: 10.5px; font-weight: 600; padding: 6px 12px; border-radius: 14px; min-width: 58px; }
.nav-item .ico { font-size: 19px; }
.nav-item.active { color: var(--accent); }
.nav-plus {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff; font-size: 26px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(10,108,255,.4);
  margin: -14px 4px 0;
}
.nav-plus:active { transform: scale(.94); }

/* ---------- Karten ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h3 {
  font-size: 13px; font-weight: 700; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center;
  color: var(--text);
}
.card h3 .more { font-size: 12.5px; color: var(--accent); font-weight: 700; }
.sec-title { font-size: 16px; font-weight: 800; margin: 16px 2px 10px; display: flex; justify-content: space-between; align-items: baseline; letter-spacing: -0.01em; }
.sec-title .more { font-size: 12.5px; color: var(--accent); font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

/* ---------- Kalorien-Karte (wie MFP) ---------- */
.cal-big { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 9px; }
.cal-big .cb-main { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.cal-big .cb-main small { font-size: 14px; color: var(--muted); font-weight: 600; }
.cal-big .cb-left { font-size: 13px; color: var(--muted); font-weight: 600; }
.bar { height: 8px; border-radius: 4px; background: var(--bg2); overflow: hidden; }
.bar.slim { height: 5px; }
.bar > div { height: 100%; border-radius: 4px; transition: width .4s ease; }

/* ---------- Makro-Spalten (wie MFP) ---------- */
.macro-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.mc .mc-name { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.mc .mc-val { font-size: 14px; font-weight: 800; margin-bottom: 5px; }
.mc .mc-val small { font-size: 11.5px; color: var(--muted); font-weight: 600; }

/* ---------- Mahlzeiten-Karten (wie MFP Diary) ---------- */
.meal-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.meal-top { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.meal-ico { width: 38px; height: 38px; border-radius: 12px; background: var(--card2); display: flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.meal-info { flex: 1; min-width: 0; }
.meal-info .m-name { font-weight: 700; font-size: 14.5px; }
.meal-info .m-sum { font-size: 12px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-info .m-macros { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.log-btn { flex: none; background: rgba(10,108,255,.1); color: var(--accent); font-weight: 700; font-size: 13px; padding: 8px 16px; border-radius: 999px; }
body.dark .log-btn { background: rgba(61,123,253,.15); }
.log-btn:active { transform: scale(.96); }
.meal-menu { color: var(--muted); font-size: 17px; padding: 4px 6px; flex: none; }
.meal-items { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
.food-item { display: flex; justify-content: space-between; align-items: center; padding: 7px 0 7px 10px; border-left: 2px solid var(--line); margin: 4px 0 4px 4px; gap: 8px; }
.food-item .f-name { font-size: 13.5px; font-weight: 600; }
.food-item .f-sub { font-size: 11.5px; color: var(--muted); }
.food-item .f-kcal { font-size: 13.5px; font-weight: 700; flex: none; }
.food-item .f-del { color: var(--muted); font-size: 14px; padding: 4px 6px; flex: none; }
.food-item .f-del:active { color: var(--red); }

/* ---------- Kacheln ---------- */
.tile-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px; cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 3px; min-height: 88px;
}
.tile:active { transform: scale(.98); }
.tile .t-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.tile .t-val { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.tile .t-val small { font-size: 12px; font-weight: 600; color: var(--muted); }
.tile .t-lbl { font-size: 11px; color: var(--muted); }
.tile .bar { margin-top: auto; }
.tile .t-add { background: rgba(10,108,255,.1); color: var(--accent); font-weight: 800; font-size: 13px; padding: 3px 10px; border-radius: 999px; }
body.dark .tile .t-add { background: rgba(61,123,253,.15); }

.water-quick { display: flex; gap: 8px; }
.water-quick button {
  flex: 1; padding: 10px 0; border-radius: 11px;
  background: rgba(13,168,143,.1); border: 1px solid rgba(13,168,143,.3);
  color: var(--carbs); font-weight: 700; font-size: 13px;
}
.water-quick button:active { transform: scale(.96); }

/* ---------- Buttons ---------- */
.btn {
  display: block; width: 100%; text-align: center;
  background: var(--accent); color: #fff; font-weight: 700;
  padding: 13px; border-radius: 13px; font-size: 15px;
  box-shadow: 0 4px 14px rgba(10,108,255,.25);
}
.btn:active { transform: scale(0.985); }
.btn.secondary { background: var(--card2); color: var(--text); border: 1px solid var(--line2); box-shadow: none; }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--red); box-shadow: none; }
.btn.small { padding: 8px 14px; font-size: 13.5px; width: auto; display: inline-block; border-radius: 10px; }
.btn:disabled { opacity: 0.45; }

/* ---------- Listen / Badges / Stats ---------- */
.list-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 10px; font-size: 14px; }
.list-item:last-child { border-bottom: none; }
.avatar { width: 42px; height: 42px; border-radius: 14px; background: linear-gradient(135deg, var(--accent), #7c5cff); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; flex: none; color: #fff; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; display: inline-block; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge.neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.stat { background: var(--card2); border-radius: 12px; padding: 11px 12px; }
.stat .s-val { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.stat .s-lbl { font-size: 11px; color: var(--muted); margin-top: 1px; }
.stat .s-val small { font-size: 12px; font-weight: 600; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .15s ease; }
body.dark .modal-overlay { background: rgba(4, 6, 11, .72); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 22px 22px 0 0; padding: 8px 18px calc(24px + var(--safe-b));
  max-height: 92vh; overflow-y: auto; animation: slideUp .22s cubic-bezier(.2,.9,.3,1);
}
body.dark .modal { background: var(--bg2); border-top: 1px solid var(--line2); }
.modal::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line2); margin: 4px auto 10px; }
@keyframes slideUp { from { transform: translateY(48px); opacity: .5; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.modal-close { font-size: 20px; color: var(--muted); padding: 4px 8px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; background: var(--card2); padding: 4px; border-radius: 12px; margin-bottom: 12px; border: 1px solid var(--line); }
.tab { flex: 1; text-align: center; padding: 8px 4px; border-radius: 9px; font-size: 12.5px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
body.dark .tabs { background: var(--bg2); }
body.dark .tab.active { background: var(--card2); }

/* ---------- Suche ---------- */
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input { flex: 1; }
.search-result { padding: 11px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 7px; cursor: pointer; box-shadow: var(--shadow); }
.search-result:active { background: var(--card2); }
.search-result .r-name { font-weight: 700; font-size: 13.5px; }
.search-result .r-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* ---------- Scanner / Chart / Fotos / Skala ---------- */
#scanner-video { width: 100%; border-radius: 14px; background: #000; aspect-ratio: 4/3; object-fit: cover; }
.scan-hint { text-align: center; font-size: 13px; color: var(--muted); margin: 10px 0; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg text { fill: var(--muted); }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.photo-grid img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; }
.photo-add { aspect-ratio: 3/4; border: 2px dashed var(--line2); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 24px; cursor: pointer; }
.scale-row { display: flex; gap: 7px; }
.scale-row button { flex: 1; padding: 10px 0; border-radius: 10px; background: var(--card2); border: 1px solid var(--line2); font-weight: 700; font-size: 13.5px; }
.scale-row button.sel { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: calc(150px + var(--safe-b)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: var(--text); color: var(--card); padding: 10px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600; box-shadow: 0 10px 28px rgba(16,24,40,.3); animation: slideUp .2s ease; max-width: 90%; }
.toast.err { background: var(--red); color: #fff; }

/* ---------- Sonstiges ---------- */
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; }
.spacer { height: 10px; }
.divider { height: 1px; background: var(--line); margin: 13px 0; }
.empty { text-align: center; color: var(--muted); padding: 26px 12px; font-size: 13.5px; }
.empty .e-ico { font-size: 30px; display: block; margin-bottom: 8px; opacity: .8; }
.feedback-box { background: rgba(10,108,255,.07); border: 1px solid rgba(10,108,255,.25); border-radius: 12px; padding: 11px 13px; margin-top: 10px; font-size: 13.5px; }
.feedback-box .fb-head { font-size: 11px; color: var(--accent); font-weight: 700; margin-bottom: 3px; text-transform: uppercase; letter-spacing: .05em; }
.week-dots { display: flex; gap: 4px; }
.week-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--bg2); border: 1px solid var(--line2); }
.week-dots span.on { background: var(--green); border-color: var(--green); }

/* ---------- Coach ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.kpi { background: var(--card2); border-radius: 10px; padding: 7px 4px; text-align: center; }
.kpi-v { font-size: 12.5px; font-weight: 800; }
.kpi-l { font-size: 9.5px; color: var(--muted); }
.kpi-warn { box-shadow: inset 0 0 0 1px rgba(229,72,77,.5); }
.kpi-warn .kpi-v { color: var(--red); }
.client-card { transition: border-color .15s; }
.client-card:active { border-color: var(--accent); }
.wk-row { display: grid; grid-template-columns: 1.4fr 0.9fr 0.8fr 1fr 1fr 0.7fr 0.6fr; gap: 4px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 12px; }
.wk-row:last-child { border-bottom: none; }
.wk-head { color: var(--muted); font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; }

@media (min-width: 900px) {
  #app.wide { max-width: 860px; }
  #app.wide .bottom-dock { max-width: 860px; }
}
