:root {
  --bg: #0f1411;
  --card: #171e1a;
  --card-2: #1e2823;
  --line: #2a352e;
  --txt: #e8f0ea;
  --muted: #8aa093;
  --green: #4ade80;
  --green-dim: #2f9e5e;
  --amber: #fbbf24;
  --red: #f87171;
  --fat: #f59e0b;
  --protein: #60a5fa;
  --carb: #f87171;
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--txt);
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 560px;
  margin: 0 auto;
}
.muted { color: var(--muted); font-size: 0.82rem; }
code { background: var(--card-2); padding: 1px 5px; border-radius: 5px; font-size: 0.8em; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(15,20,17,0.92);
  backdrop-filter: blur(12px);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 12px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.logo { font-size: 1.9rem; }
.brand h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.datenav { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.datenav button {
  background: var(--card-2); color: var(--txt); border: 1px solid var(--line);
  border-radius: 11px; font-size: 1.1rem; height: 38px; width: 44px; cursor: pointer;
}
.datebtn { flex: 1; width: auto !important; font-size: 0.92rem !important; font-weight: 600; }
.datenav button:active { transform: scale(0.96); }

/* Layout */
main { padding: 14px 16px 8px; display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.card-head h2 { font-size: 0.95rem; font-weight: 650; }

/* Ziel & Motivation */
.goal { background: linear-gradient(160deg, #1b2a20 0%, #171e1a 70%); }
.goal-top { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; }
.goal-now .num { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.02em; }
.goal-now .u { font-size: 1rem; color: var(--muted); margin-left: 4px; }
.goal-badge { text-align: right; display: flex; flex-direction: column; }
.goal-badge .big { font-size: 1.5rem; font-weight: 750; color: var(--green); line-height: 1; }
.goal-badge .muted { font-size: 0.72rem; }
.goal-track {
  position: relative; height: 14px; border-radius: 8px;
  background: var(--card-2); margin: 26px 0 8px; overflow: visible;
}
.goal-fill {
  height: 100%; border-radius: 8px; width: 0%;
  background: linear-gradient(90deg, var(--green-dim), var(--green));
  transition: width 0.8s ease;
}
.goal-track .marker {
  position: absolute; top: -20px; font-size: 0.7rem; color: var(--muted); white-space: nowrap;
}
.goal-track .marker.start { left: 0; }
.goal-track .marker.end { right: 0; }
.goal-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; text-align: center; }
.goal-stats > div { display: flex; flex-direction: column; gap: 1px; }
.goal-stats .k { font-size: 1.05rem; font-weight: 700; }
.goal-stats .muted { font-size: 0.68rem; }
.goal-msg { margin-top: 14px; text-align: center; font-size: 0.78rem; line-height: 1.4; }

/* Makro-Ringe */
.rings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ring { position: relative; aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring circle.bg { stroke: var(--card-2); }
.ring circle.fg { stroke: var(--green); stroke-linecap: round; transition: stroke-dashoffset 0.6s ease, stroke 0.3s; }
.ring.keto circle.fg { stroke: var(--carb); }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.ring-center .val { font-size: 0.95rem; font-weight: 700; line-height: 1; }
.ring-center .lbl { font-size: 0.6rem; color: var(--muted); margin-top: 2px; }
.ring-center .sub { font-size: 0.55rem; color: var(--muted); }
.ring.over circle.fg { stroke: var(--red); }
.ring.keto.ok circle.fg { stroke: var(--green); }

/* Heute noch übrig */
.remain-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.remain-list li { display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 10px; }
.remain-list .rl { font-size: 0.8rem; color: var(--muted); }
.remain-track { height: 8px; border-radius: 5px; background: var(--card-2); overflow: hidden; }
.remain-track i { display: block; height: 100%; border-radius: 5px; transition: width 0.5s ease; }
.remain-val { font-size: 0.92rem; font-weight: 700; white-space: nowrap; text-align: right; }
.remain-val small { font-weight: 500; color: var(--muted); font-size: 0.72rem; }
.remain-val.done { color: var(--green); }
.remain-val.over { color: var(--red); }
.remain-tip { margin-top: 14px; font-size: 0.82rem; line-height: 1.45; }

/* Vorschlag-Button + Box */
.suggest-btn {
  margin-top: 14px; width: 100%; padding: 12px; border-radius: 11px;
  border: 1px solid var(--green-dim); background: rgba(74,222,128,0.10);
  color: var(--green); font-size: 0.88rem; font-weight: 650; cursor: pointer;
}
.suggest-btn:active { transform: scale(0.98); }
.suggest-btn:disabled { opacity: 0.6; }
.suggest-box { margin-top: 12px; }
.suggest-box[hidden] { display: none; }
.suggest-headline { font-size: 0.9rem; font-weight: 600; margin-bottom: 10px; line-height: 1.4; }
.suggest-item {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; margin-bottom: 8px;
}
.suggest-item .t { font-size: 0.9rem; font-weight: 650; }
.suggest-item .w { font-size: 0.78rem; color: var(--muted); margin: 3px 0 6px; line-height: 1.4; }
.suggest-item .m { font-size: 0.72rem; color: var(--muted); }
.suggest-item .m b { color: var(--txt); font-weight: 600; }
.suggest-err { font-size: 0.82rem; color: #fca5a5; margin-bottom: 8px; }
.suggest-recalc {
  width: 100%; margin-top: 4px; padding: 9px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card-2); color: var(--muted);
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.suggest-recalc:active { transform: scale(0.98); }

/* Wochenübersicht */
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 14px; }
.week-day { text-align: center; }
.week-day .bar-wrap { height: 56px; display: flex; align-items: flex-end; justify-content: center; }
.week-day .bar {
  width: 60%; min-height: 3px; border-radius: 4px 4px 0 0; background: var(--green); transition: height 0.4s;
}
.week-day .bar.over { background: var(--red); }
.week-day .bar.empty { background: var(--line); }
.week-day .dl { font-size: 0.62rem; color: var(--muted); margin-top: 4px; }
.week-day .dot { display: block; width: 7px; height: 7px; border-radius: 50%; margin: 4px auto 0; background: var(--line); }
.week-day .dot.ok { background: var(--green); }
.week-day .dot.bad { background: var(--red); }
.week-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.week-stats > div { background: var(--card-2); border-radius: 11px; padding: 10px 12px; }
.week-stats .v { font-size: 1.05rem; font-weight: 700; }
.week-stats .l { font-size: 0.7rem; color: var(--muted); }

/* Keto-Status */
.keto-status { display: flex; gap: 14px; align-items: center; }
.keto-badge {
  flex-shrink: 0; width: 64px; height: 64px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; background: var(--card-2); border: 1px solid var(--line);
}
.keto-badge.in { background: rgba(74,222,128,0.14); border-color: var(--green-dim); }
.keto-badge.out { background: rgba(248,113,113,0.12); border-color: var(--red); }
.keto-detail { flex: 1; min-width: 0; }
.keto-detail strong { font-size: 0.95rem; }
.macrobar {
  display: flex; height: 10px; border-radius: 6px; overflow: hidden;
  margin: 10px 0 8px; background: var(--card-2);
}
.macrobar i { display: block; height: 100%; }
.macrobar-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.76rem; color: var(--muted); }
.macrobar-legend b { color: var(--txt); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.dot.fat, i.fat { background: var(--fat); }
.dot.protein, i.protein { background: var(--protein); }
.dot.carb, i.carb { background: var(--carb); }

/* Mahlzeiten */
.meals { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.meals li { display: flex; gap: 12px; align-items: center; }
.meal-ico {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 11px; background: var(--card-2);
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.meal-main { flex: 1; min-width: 0; }
.meal-main .t { font-size: 0.9rem; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-main .m { font-size: 0.74rem; color: var(--muted); }
.meal-kcal { font-size: 0.85rem; font-weight: 650; white-space: nowrap; }
.empty { text-align: center; padding: 18px 0; }

.foot { text-align: center; padding: 18px 16px 28px; font-size: 0.72rem; }
.footlink { color: var(--muted); text-decoration: underline; }

/* Login */
.login { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.login[hidden] { display: none; }
.login-box { width: 100%; max-width: 340px; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.login-logo { font-size: 3rem; }
.login-box h2 { font-size: 1.3rem; font-weight: 700; }
.login-box input { text-align: center; }
.login-box .msg { text-align: center; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: none; z-index: 30;
  background: var(--green); color: #06140c; font-size: 2rem; font-weight: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45); cursor: pointer; line-height: 1;
}
.fab:active { transform: scale(0.93); }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(2px); }
.sheet-panel {
  position: relative; width: 100%; max-width: 560px; background: var(--card);
  border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: none;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto; animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grip { width: 40px; height: 4px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 10px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--muted); font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.tab.active { background: rgba(74,222,128,0.14); border-color: var(--green-dim); color: var(--txt); }
.tabpane[hidden] { display: none; }

.photo-drop {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 120px; border: 2px dashed var(--line); border-radius: 14px;
  color: var(--muted); cursor: pointer; overflow: hidden; margin-bottom: 12px; padding: 8px;
}
.photo-drop img { max-width: 100%; max-height: 240px; border-radius: 10px; }

textarea, input[type=text], input[type=number], select {
  width: 100%; background: var(--card-2); border: 1px solid var(--line); color: var(--txt);
  border-radius: 11px; padding: 12px; font-size: 16px; font-family: inherit; resize: none;
}
textarea { margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: stretch; }
.row select { flex: 1; }
button.primary {
  background: var(--green); color: #06140c; border: none; border-radius: 11px;
  padding: 12px 16px; font-size: 0.92rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
button.primary:active { transform: scale(0.97); }
button.primary:disabled { opacity: 0.5; }
button.primary.block { width: 100%; margin-top: 14px; padding: 14px; }

.est { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.est-name input { font-size: 1.05rem; font-weight: 650; padding: 10px; }
.est-meta { margin: 8px 0 12px; }
.est-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.est-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 0.74rem; color: var(--muted); }
.est-grid input { font-weight: 650; }

/* Bewertung */
.review { margin-top: 14px; padding: 12px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); }
.review[hidden] { display: none; }
.review-head { display: flex; align-items: center; gap: 10px; }
.review-score { font-size: 1rem; white-space: nowrap; letter-spacing: 1px; }
.review-verdict { font-size: 0.84rem; line-height: 1.35; }
.review-tips { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.review-tips li { font-size: 0.8rem; color: var(--muted); padding-left: 20px; position: relative; line-height: 1.4; }
.review-tips li::before { content: "💡"; position: absolute; left: 0; }
.review-tips:empty { display: none; }

.wlabel { display: block; font-size: 0.85rem; color: var(--muted); }
.wlabel .row { margin-top: 8px; align-items: center; }
.wlabel .unit { font-size: 1rem; color: var(--muted); }

.msg { margin-top: 12px; font-size: 0.82rem; padding: 10px 12px; border-radius: 10px; }
.msg[hidden] { display: none; }
.msg.err { background: rgba(248,113,113,0.14); color: #fca5a5; }
.msg.ok { background: rgba(74,222,128,0.14); color: var(--green); }
.msg.load { background: var(--card-2); color: var(--muted); }

@media (max-width: 360px) {
  .ring-center .val { font-size: 0.82rem; }
}
