:root {
  --bg: #101613;
  --card: #1a231e;
  --card2: #232e27;
  --text: #e8f0ea;
  --muted: #93a89b;
  --accent: #4cc38a;
  --accent-dim: #2a5c44;
  --red: #e5726d;
  --orange: #e0a458;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
header {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
}
header h1 { font-size: 1.15rem; }
header span { color: var(--muted); font-size: .85rem; }
main { padding: 0 12px; max-width: 640px; margin: 0 auto; }

.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card-title { font-weight: 600; font-size: .95rem; margin-bottom: 8px; display: block; }
.card-title-row { margin: 14px 4px 8px; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 8px; line-height: 1.4; }

/* --- Tagesnavigation --- */
.date-nav {
  display: flex; justify-content: center; align-items: center; gap: 18px;
  margin: 4px 0 12px;
}
.date-nav button {
  background: var(--card); color: var(--text); border: none;
  width: 34px; height: 34px; border-radius: 50%; font-size: 1.1rem;
}
#day-label { font-weight: 600; min-width: 130px; text-align: center; }

/* --- Bilanz --- */
.balance-row { display: flex; justify-content: space-around; align-items: center; }
.metric { text-align: center; }
.metric-val { display: block; font-size: 1.25rem; font-weight: 700; }
.metric.big .metric-val { font-size: 1.9rem; }
.metric-label { color: var(--muted); font-size: .75rem; }
.pos { color: var(--red); }
.neg { color: var(--accent); }
.target-bar {
  height: 8px; background: var(--card2); border-radius: 4px; margin: 14px 0 6px;
  overflow: hidden;
}
.target-fill { height: 100%; background: var(--accent); width: 0; border-radius: 4px; transition: width .4s; }
.target-fill.over { background: var(--red); }
.target-text { color: var(--muted); font-size: .8rem; text-align: center; }
.macros { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.chip {
  background: var(--card2); border-radius: 20px; padding: 4px 12px;
  font-size: .8rem; color: var(--muted);
}
.chip b { color: var(--text); }

/* --- Mahlzeiten --- */
.meal {
  display: flex; gap: 12px; align-items: center;
  background: var(--card); border-radius: var(--radius);
  padding: 10px; margin-bottom: 8px;
}
.meal img {
  width: 54px; height: 54px; object-fit: cover; border-radius: 10px;
  background: var(--card2);
}
.meal .no-photo {
  width: 54px; height: 54px; border-radius: 10px; background: var(--card2);
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.meal-info { flex: 1; min-width: 0; }
.meal-name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-sub { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.meal-kcal { font-weight: 700; white-space: nowrap; }
.meal-kcal small { color: var(--muted); font-weight: 400; }
.meal .del { background: none; border: none; color: var(--muted); font-size: 1rem; padding: 6px; }
.badge-draft { color: var(--orange); font-size: .72rem; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; font-size: .9rem; }

/* --- Buttons --- */
.btn {
  background: var(--card2); color: var(--text); border: none;
  border-radius: var(--radius); padding: 13px 16px; font-size: .95rem; font-weight: 600;
}
.btn.primary { background: var(--accent); color: #08130d; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.add-row { display: flex; gap: 10px; margin: 14px 0; }
.add-row .btn { flex: 1; }

/* --- Chart --- */
#chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; justify-content: center; margin-top: 8px; font-size: .78rem; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot-in { background: var(--accent); }
.dot-out { background: var(--orange); }
.avg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.avg-grid .metric { background: var(--card2); border-radius: 10px; padding: 10px; }

/* --- Formulare --- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); }
input, select, textarea {
  background: var(--card2); color: var(--text); border: 1px solid #31413a;
  border-radius: 10px; padding: 10px; font-size: 16px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
#mfa-row { margin-top: 10px; }

/* --- Bottom-Nav --- */
nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: #0c110e; border-top: 1px solid #1e2a23;
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 8px 0 6px; font-size: 1.15rem; display: flex; flex-direction: column;
  align-items: center; gap: 2px;
}
nav button span { font-size: .65rem; }
nav button.active { color: var(--accent); }

/* --- Modal --- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-body {
  background: var(--card); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; padding: 16px;
  max-height: 88vh; overflow-y: auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head span { font-weight: 700; }
.modal-head button { background: none; border: none; color: var(--muted); font-size: 1.2rem; padding: 4px 8px; }
.preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; background: var(--card2); }
.spinner-box { text-align: center; padding: 30px 10px; color: var(--muted); }
.spinner {
  width: 34px; height: 34px; border: 3px solid var(--card2); border-top-color: var(--accent);
  border-radius: 50%; margin: 0 auto 14px; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.items-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin: 10px 0; }
.items-table td { padding: 5px 4px; border-bottom: 1px solid #24312a; }
.items-table td:last-child { text-align: right; white-space: nowrap; }
.items-table .menge { color: var(--muted); font-size: .78rem; }
.totals { display: flex; justify-content: space-between; font-weight: 700; padding: 8px 4px; }
.question { margin: 10px 0; }
.question p { font-size: .88rem; margin-bottom: 6px; }
.uncertainty { font-size: .78rem; color: var(--orange); margin-top: 4px; }

/* --- Markdown --- */
.md h1, .md h2, .md h3 { margin: 14px 0 6px; font-size: 1rem; color: var(--accent); }
.md p { margin: 6px 0; font-size: .88rem; line-height: 1.5; }
.md ul, .md ol { margin: 6px 0 6px 20px; font-size: .88rem; line-height: 1.5; }
.md strong { color: var(--text); }

.activity { display: flex; justify-content: space-between; font-size: .85rem; padding: 4px 0; }
.activity span:last-child { color: var(--muted); }
#garmin-day { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
