/* ==========================================================================
   macros – helles, frisches Design mit Salbei-Mint-Akzent
   ========================================================================== */

:root {
  --bg: #F6F8F6;
  --card: #FFFFFF;
  --ink: #1E262B;
  --ink-soft: #55636B;
  --mint: #59A98C;
  --mint-deep: #47997B;
  --mint-soft: #E4F2EC;
  --line: #E3E9E5;
  --track: #EDF2EF;
  /* Kräftiger und dunkler als das Fett-Sandgelb, damit "über dem Ziel"
     nicht mit der Fett-Grundfarbe verwechselt wird. */
  --over: #B3652F;
  --m-protein: #3E8F72;
  --m-carbs: #85C6AA;
  --m-fat: #E0B473;
  --danger: #CC5F55;
  --danger-soft: #FAEDEA;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(30, 38, 43, 0.05), 0 8px 24px rgba(30, 38, 43, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  min-height: 100dvh;
}

button {
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.mt { margin-top: 12px; }

/* ---------- Layout ---------- */

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px calc(48px + env(safe-area-inset-bottom));
}

.center-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ---------- Wortmarke & Kopfzeile ---------- */

.wordmark {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -1px;
}

.wordmark.small { font-size: 22px; letter-spacing: -0.5px; }
.wordmark .dot { color: var(--mint); }

.app-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  margin-bottom: 10px;
}

.page-title { font-size: 18px; font-weight: 800; }
.head-spacer { width: 40px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 18px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 15.5px;
  transition: transform 0.1s ease, filter 0.15s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary {
  background: var(--mint);
  color: #fff;
  box-shadow: 0 6px 16px rgba(71, 153, 123, 0.25);
}

.btn-block { width: 100%; margin-top: 6px; }
.btn-ghost { background: var(--track); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: var(--danger-soft); color: var(--danger); margin-top: 10px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.icon-btn.subtle { background: transparent; box-shadow: none; }
.icon-btn.danger { color: var(--danger); }

.link-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  color: var(--mint-deep);
  font-weight: 600;
  font-size: 14.5px;
  text-align: center;
}

.fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--mint);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(71, 153, 123, 0.4);
  transition: transform 0.15s ease;
  z-index: 20;
}

.fab:active { transform: scale(0.94); }

/* ---------- Formularfelder ---------- */

.field { display: block; margin-bottom: 12px; }

.field > span,
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}

input::placeholder { color: #9AA7AD; }

input:focus {
  outline: 2px solid var(--mint);
  outline-offset: 0;
  border-color: transparent;
}

.macro-inputs,
.goal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

.hint {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.45;
  margin: 2px 0 12px;
}

/* ---------- Login ---------- */

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 24px;
  padding: 30px 26px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card form { text-align: left; margin-top: 22px; }

.auth-sub { color: var(--ink-soft); font-size: 14.5px; margin-top: 2px; }

.auth-msg {
  min-height: 20px;
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.auth-msg.error { color: var(--danger); font-weight: 600; }
.auth-msg.info { color: var(--mint-deep); font-weight: 600; }

/* ---------- Tagesnavigation ---------- */

.day-nav {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 0 16px;
}

.day-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-top: 8px;
}

.day-label { font-weight: 800; font-size: 18px; }

.today-pill {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--mint-soft);
  color: var(--mint-deep);
  font-size: 13px;
  font-weight: 700;
}

/* ---------- Zusammenfassung ---------- */

.summary {
  background: var(--card);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 20px;
}

#summary-bars { display: grid; gap: 20px; }

.kcal-line { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }

.kcal-num { font-size: 38px; font-weight: 800; letter-spacing: -1px; }
.kcal-goal { color: var(--ink-soft); font-weight: 600; font-size: 14px; }

.kcal-hint { margin-top: 9px; font-size: 13.5px; font-weight: 600; color: var(--mint-deep); }
.kcal-hint.over { color: var(--over); }

.macro-grid { display: grid; gap: 13px; }

.macro-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 14px;
}

.macro-name { font-weight: 700; }
.macro-vals { color: var(--ink-soft); font-size: 13.5px; }
.macro-vals b { color: var(--ink); font-size: 14.5px; }

.bar {
  height: 10px;
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
}

.bar-lg { height: 14px; }

.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--mint), var(--mint-deep));
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.22, 0.8, 0.36, 1);
}

/* Die Makrobalken tragen exakt die Farben aus dem Kreisdiagramm.
   Kalorien sind die Summe der drei und bekommen deshalb einen neutralen
   Schieferton – so ist der Balken nie mit Protein zu verwechseln. */
.bar-fill.fill-kcal    { background: linear-gradient(90deg, #55707C, #41545E); }
.bar-fill.fill-protein { background: linear-gradient(90deg, #4FA184, var(--m-protein)); }
.bar-fill.fill-carbs   { background: linear-gradient(90deg, #96D0B8, var(--m-carbs)); }
.bar-fill.fill-fat     { background: linear-gradient(90deg, #E9C289, var(--m-fat)); }

/* Zuletzt, damit "über dem Ziel" jede Grundfarbe überschreibt. */
.bar-fill.over { background: linear-gradient(90deg, #D08A4F, var(--over)); }

/* ---------- Kreisdiagramm ---------- */

/* Umschalter der Zusammenfassung: nur Symbole, kompakt oben rechts. */
.seg-icons {
  justify-self: end;
  align-self: start;
  padding: 3px;
  gap: 3px;
  /* Zieht den Inhalt darunter wieder heran, damit der kleine Umschalter
     nicht eine ganze Zeile Höhe verbraucht. */
  margin-bottom: -12px;
}

.seg-icons button {
  flex: 0 0 auto;
  width: 40px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.donut-wrap {
  position: relative;
  width: 208px;
  max-width: 72%;
  margin: 2px auto 0;
}

.donut { display: block; width: 100%; height: auto; transform: rotate(-90deg); }

.donut-track { fill: none; stroke: var(--track); stroke-width: 13; }

.donut-seg {
  fill: none;
  stroke-width: 13;
  stroke-dasharray: 0 999;
  transition: stroke-dasharray 0.6s cubic-bezier(0.22, 0.8, 0.36, 1),
              stroke-dashoffset 0.6s cubic-bezier(0.22, 0.8, 0.36, 1);
}

#seg-protein { stroke: var(--m-protein); }
#seg-carbs { stroke: var(--m-carbs); }
#seg-fat { stroke: var(--m-fat); }

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1px;
}

.donut-kcal { font-size: 32px; font-weight: 800; letter-spacing: -1px; line-height: 1.1; }
.donut-goal { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }
.donut-pct { font-size: 12.5px; color: var(--mint-deep); font-weight: 700; margin-top: 3px; }
.donut-pct.over { color: var(--over); }

.donut-legend { display: grid; gap: 9px; margin-top: 18px; }

.legend-row {
  display: grid;
  grid-template-columns: 11px 1fr auto auto;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
}

.legend-dot { width: 11px; height: 11px; border-radius: 50%; }
.legend-name { font-weight: 700; }
.legend-val { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.legend-pct { font-weight: 700; min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

.donut-empty { text-align: center; color: var(--ink-soft); font-size: 14px; margin-top: 16px; }
.donut-note { margin-top: 14px; font-size: 12px; color: var(--ink-soft); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .donut-seg { transition: none; }
}

/* ---------- Einträge ---------- */

.entry-list { display: grid; gap: 10px; }

/* ---------- Mahlzeiten ---------- */

.meals { display: grid; gap: 22px; margin-top: 24px; }

.meal-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 9px;
}

.meal-title { font-size: 15.5px; font-weight: 700; }
.meal-sum { font-size: 13px; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }

.meal-add {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  color: var(--mint-deep);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.meal-add:active { background: var(--mint-soft); border-color: var(--mint); }

.seg-meal button { font-size: 12.5px; padding: 8px 2px; }

.entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 16px;
  box-shadow: var(--shadow);
  text-align: left;
}

.entry:active { filter: brightness(0.98); }

.entry-main { display: grid; gap: 1px; min-width: 0; }
.entry-name { font-weight: 700; overflow-wrap: anywhere; }
.entry-sub { font-size: 12.5px; color: var(--ink-soft); }

.entry-side { display: grid; gap: 1px; text-align: right; flex-shrink: 0; }
.entry-kcal { font-weight: 800; font-size: 14.5px; color: var(--mint-deep); }
.entry-pcf { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--ink-soft);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.empty span { font-weight: 400; font-size: 14px; }

.empty-inline { color: var(--ink-soft); font-size: 14px; padding: 6px 0; }

/* ---------- Einstellungen ---------- */

.card {
  background: var(--card);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }

.account-mail { color: var(--ink-soft); font-size: 14.5px; margin-bottom: 4px; overflow-wrap: anywhere; }

/* Errechnetes Kalorienziel */

.calc-box {
  background: var(--mint-soft);
  border-radius: 14px;
  padding: 13px 16px;
  margin: 2px 0 16px;
}

.calc-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.calc-label { font-weight: 700; font-size: 14.5px; }

.calc-value { color: var(--mint-deep); font-weight: 700; font-size: 13.5px; white-space: nowrap; }
.calc-value b { font-size: 23px; font-weight: 800; letter-spacing: -0.5px; }

.calc-formula { margin-top: 5px; font-size: 12.5px; color: var(--ink-soft); }

.calc-hint { margin: -2px 0 10px; }
.calc-hint.manual { color: var(--mint-deep); font-weight: 600; }

.fav-manage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.fav-manage-row:last-child { border-bottom: 0; padding-bottom: 2px; }
.fav-manage-info { display: grid; gap: 1px; min-width: 0; }
.fav-manage-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ---------- KI-Assistent ---------- */

.head-actions { display: flex; gap: 8px; }

.budget-box {
  background: var(--card);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.budget-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 9px;
}

.budget-label { font-size: 13.5px; color: var(--ink-soft); }
.budget-label b { color: var(--ink); font-weight: 700; }
.budget-kcal { font-size: 19px; font-weight: 800; white-space: nowrap; }
.budget-kcal.over { color: var(--over); }

.budget-macros { display: flex; flex-wrap: wrap; gap: 7px; }

textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
  margin-bottom: 10px;
}

textarea:focus { outline: 2px solid var(--mint); border-color: transparent; }

.photo-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.photo-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  color: var(--mint-deep);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.photo-name { font-size: 13px; color: var(--ink-soft); overflow-wrap: anywhere; flex: 1; min-width: 0; }

.link-btn.inline { display: inline; width: auto; margin: 0; font-size: 13px; color: var(--danger); }

.ai-summary {
  background: var(--mint-soft);
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 14px;
  line-height: 1.5;
  margin-top: 16px;
}

.ai-results { display: grid; gap: 12px; margin-top: 14px; }

.ai-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
}

.ai-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 9px;
}

.ai-card-name { font-weight: 700; overflow-wrap: anywhere; }
.ai-card-meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }

.fit-badge {
  flex-shrink: 0;
  font-size: 11.5px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.fit-gut { background: var(--mint-soft); color: var(--mint-deep); }
.fit-mittel { background: #FBF0DF; color: #8A6224; }
.fit-schlecht { background: var(--danger-soft); color: var(--danger); }

.ai-note { font-size: 13.5px; line-height: 1.5; color: var(--ink-soft); margin: 10px 0 12px; }

.ai-details { margin: 4px 0 12px; }
.ai-details summary { font-size: 13.5px; font-weight: 600; color: var(--mint-deep); cursor: pointer; }
.ai-details ul, .ai-details ol { margin: 9px 0 0 18px; font-size: 13.5px; line-height: 1.6; }

.btn-sm { padding: 9px 16px; font-size: 14px; width: 100%; }

.planned-chip {
  display: inline-block;
  background: var(--track);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 7px;
  vertical-align: middle;
}

/* ---------- Modale ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(23, 32, 28, 0.4);
  z-index: 50;
}

.modal {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 88dvh;
  overflow-y: auto;
  animation: sheet-in 0.25s ease;
}

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 22px; }
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-head h2 { font-size: 18px; font-weight: 800; }

#confirm-modal { align-items: center; padding: 24px; z-index: 60; }

.modal-sm { max-width: 340px; border-radius: 20px; }

.confirm-text { font-weight: 600; line-height: 1.45; margin-bottom: 18px; }

.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }

/* ---------- Tabs / Segmente ---------- */

.segmented {
  display: flex;
  background: var(--track);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.segmented button {
  flex: 1;
  padding: 9px 6px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--ink-soft);
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* ---------- Favoriten im Eintrag-Modal ---------- */

.fav-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 250px;
  overflow-y: auto;
}

.fav-row {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 2px;
  background: #fff;
}

.fav-row.selected { border-color: var(--mint); background: var(--mint-soft); }

.fav-name { font-weight: 700; overflow-wrap: anywhere; }
.fav-sub { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- USDA-Suche ---------- */

.search-row { display: flex; gap: 8px; margin-bottom: 4px; }
.search-row input { flex: 1; min-width: 0; }

.btn-search { flex-shrink: 0; padding: 12px 18px; margin: 0; }

.usda-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px 8px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
}

.usda-state.error { color: var(--danger); font-weight: 600; }

.spinner-sm { width: 18px; height: 18px; border-width: 2.5px; flex-shrink: 0; }

.fav-detail {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.fav-detail-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}

#fav-detail-name,
#usda-detail-name { font-weight: 800; overflow-wrap: anywhere; }

#fav-detail-sub,
#usda-detail-sub { font-size: 12.5px; color: var(--ink-soft); }

.preview-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 14px;
}

.chip {
  background: var(--mint-soft);
  color: var(--mint-deep);
  font-weight: 700;
  font-size: 13px;
  padding: 5px 11px;
  border-radius: 999px;
}

.chip.muted { background: var(--track); color: var(--ink-soft); font-weight: 500; }

/* ---------- Toast & Spinner ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 100px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  max-width: min(90vw, 480px);
  text-align: center;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--track);
  border-top-color: var(--mint);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
  .modal { animation: none; }
  .spinner { animation-duration: 1.6s; }
}
