:root {
  --bg: #14181c;
  --surface: #1d2329;
  --surface-2: #262d35;
  --text: #eef2f5;
  --muted: #93a1ad;
  --accent: #4caf7d;
  --accent-press: #3d9268;
  --danger: #e5675f;
  --border: #2c343d;
  --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #eef1f4;
    --text: #1a2027;
    --muted: #667381;
    --accent: #2e9e6b;
    --accent-press: #268059;
    --danger: #d64c43;
    --border: #e0e5ea;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}
.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 14px calc(96px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; accent-color: var(--accent); }

/* Topbar – festes 3-Spalten-Raster: links | mitte (zentriert) | rechts.
   So bleibt der Titel/das Datum immer exakt mittig, egal wie breit die Seiten sind. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 8px;
  padding: calc(18px + env(safe-area-inset-top)) 0 12px;
  background: linear-gradient(var(--bg) 82%, transparent);
}
.topbar > :first-child { justify-self: start; }
.topbar > :last-child  { justify-self: end; }
.daynav { display: flex; align-items: center; justify-content: center; gap: 16px; }
/* SVG-Chevrons: exakt im viewBox zentriert -> immer mittig in der Button-Box. */
.chev { display: block; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px;
  border: none; background: var(--surface); color: var(--text);
  border-radius: 12px; font-size: 20px; line-height: 1;
}
.icon-btn.placeholder { visibility: hidden; }
.daylabel { text-align: center; min-width: 0; }
.daylabel .date { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.today-link { display: inline-block; font-size: 12px; color: var(--accent); margin-top: 2px; }

/* Menü */
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; right: 0; top: 48px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px; min-width: 200px;
  display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
}
.menu-pop a, .menu-pop button {
  text-align: left; padding: 11px 12px; border-radius: 9px;
  background: none; border: none; color: var(--text); width: 100%; font-size: 15px;
}
.menu-pop a:active, .menu-pop button:active { background: var(--surface-2); }

/* Tagessumme */
.summary { text-align: center; padding: 26px 0 18px; }
.kcal-total { font-size: 56px; font-weight: 700; letter-spacing: -1px; }
.kcal-unit { color: var(--muted); font-size: 14px; }

/* Einträge */
.entries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: var(--radius); padding: 14px 12px 14px 16px;
}
.entry-label { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-kcal { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.entry-kcal::after { content: " kcal"; font-weight: 400; font-size: 12px; }
.del {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
  border: none; background: var(--surface-2); color: var(--muted); font-size: 15px;
}
.del:active { background: var(--danger); color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty.small { padding: 16px; }

/* FAB */
.fab {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 300;
  box-shadow: 0 10px 24px rgba(0,0,0,.4);
  z-index: 30;
}
.fab:active { background: var(--accent-press); }

/* Karten & Formulare */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; margin-top: 14px;
}
/* Alle Feld-Labels einheitlich: klein & gedämpft, egal wie tief verschachtelt. */
.card > label, .form > label,
#fixed-block > label, #composed-block > label,
.grid2 label, .grid3 label {
  display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin: 0 0 6px;
}
input[type=text], input[type=number], input[type=search], input[type=password], select {
  width: 100%; padding: 13px 12px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 11px;
  -webkit-appearance: none; appearance: none;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.inline { display: flex; gap: 8px; }
.inline input[type=number] { flex: 0 0 34%; }
.inline input[type=text] { flex: 1; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 8px; }

button.primary {
  width: 100%; margin-top: 14px; padding: 14px;
  background: var(--accent); color: #fff; border: none; border-radius: 11px;
  font-weight: 600; font-size: 16px;
}
button.primary:active { background: var(--accent-press); }
.inline button.primary { width: auto; margin-top: 0; padding: 0 18px; }
button.secondary {
  margin-top: 10px; padding: 11px 14px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 11px;
}

.macros { margin-top: 12px; }
.macros summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 6px 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }

/* "oder"-Trenner */
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 20px 4px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Schnellauswahl-Chips */
.quickpick { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 9px 14px; font-size: 14px;
}
.chip span { color: var(--muted); font-size: 12px; margin-left: 4px; }
.chip:active { background: var(--accent); color: #fff; border-color: transparent; }

/* Mahlzeit-Suche */
.mealpicklist { margin-top: 10px; }
.mealpick { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mealpick button {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 11px; padding: 12px 14px; text-align: left;
}
.mealpick button:active { background: var(--accent); color: #fff; border-color: transparent; }
.mp-name { font-weight: 500; }
.mp-k { color: var(--muted); font-size: 13px; }

/* Verwaltungslisten – gleiche „Karte mit Löschen innen“-Optik wie die Tagesliste. */
.manage-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.manage-list li {
  display: flex; align-items: center;
  background: var(--surface); border-radius: var(--radius);
}
.manage-list li.empty {
  display: block; background: transparent; color: var(--muted);
  text-align: center; padding: 24px 16px;
}
.manage-list .del { margin-right: 10px; }
.ml-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; justify-content: center;
  padding: 14px 8px 14px 16px;
}
.ml-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ml-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Mahlzeit-Editor */
#fixed-block, #composed-block { margin-top: 16px; }
.modeswitch { display: flex; gap: 8px; margin: 16px 0 0; }
.modeswitch label {
  flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 11px; font-size: 14px;
}
.comp-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.comp-row select { flex: 1; }
.comp-row input { flex: 0 0 90px; }

/* Kalender */
.calendar { margin-top: 8px; }
.cal-weekhead { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 5px; }
.cal-weekhead span { text-align: center; color: var(--muted); font-size: 12px; }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 5px; }
.cal-day {
  aspect-ratio: 1 / 1; background: var(--surface); border-radius: 11px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 1px solid transparent;
}
.cal-day .d { font-size: 14px; }
.cal-day .t { font-size: 10px; color: var(--accent); font-variant-numeric: tabular-nums; }
.cal-day.out { opacity: .35; }
.cal-day.has { border-color: var(--border); }
.cal-day.today { outline: 2px solid var(--accent); }

/* Login */
.login { max-width: 320px; margin: 16vh auto 0; text-align: center; padding: 0 16px; }
.login-logo { font-size: 48px; }
.login h1 { font-weight: 700; margin: 6px 0 26px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login .primary { margin-top: 0; }
.error { color: var(--danger); font-size: 14px; margin: 0; }
