/* FitFuel — Design
   Farben der Diagramme stammen aus einer geprüften kategorialen Palette:
   Slot 1 Kalorien, Slot 2 Eiweiß, Slot 3 Kohlenhydrate, Slot 4 Fett.
   Jeder farbige Wert trägt zusätzlich ein Textlabel, damit die Bedeutung
   nie allein von der Farbe abhängt. */

:root {
  color-scheme: light;

  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --surface-2:       #f2f1ee;
  --surface-3:       #e8e7e2;

  --text:            #0b0b0b;
  --text-2:          #52514e;
  --muted:           #898781;
  --grid:            #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, .10);
  --border-strong:   rgba(11, 11, 11, .18);

  --s1: #2a78d6;  /* Kalorien */
  --s2: #eb6834;  /* Eiweiß */
  --s3: #1baf7a;  /* Kohlenhydrate */
  --s4: #eda100;  /* Fett */
  --water: #2a78d6;

  --good:     #0ca30c;
  --good-text:#006300;
  --warning:  #fab219;
  --critical: #d03b3b;

  --radius:   16px;
  --radius-s: 10px;
  --shadow:   0 1px 2px rgba(11,11,11,.06), 0 8px 24px rgba(11,11,11,.06);

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --nav-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:          #0d0d0d;
    --surface:       #1a1a19;
    --surface-2:     #232322;
    --surface-3:     #2c2c2a;
    --text:          #ffffff;
    --text-2:        #c3c2b7;
    --muted:         #898781;
    --grid:          #2c2c2a;
    --baseline:      #383835;
    --border:        rgba(255,255,255,.10);
    --border-strong: rgba(255,255,255,.18);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --water: #3987e5;
    --good-text: #0ca30c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:          #0d0d0d;
  --surface:       #1a1a19;
  --surface-2:     #232322;
  --surface-3:     #2c2c2a;
  --text:          #ffffff;
  --text-2:        #c3c2b7;
  --muted:         #898781;
  --grid:          #2c2c2a;
  --baseline:      #383835;
  --border:        rgba(255,255,255,.10);
  --border-strong: rgba(255,255,255,.18);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --water: #3987e5;
  --good-text: #0ca30c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: env(safe-area-inset-bottom); }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .75rem; color: var(--text-2); }
a  { color: var(--s1); }

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

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
  padding: calc(.75rem + env(safe-area-inset-top)) 1rem .75rem;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.2rem; flex: 1; }
.topbar .sub { color: var(--muted); font-size: .8rem; font-weight: 400; display: block; }

.view {
  flex: 1;
  padding: 1rem;
  padding-bottom: calc(var(--nav-h) + 2rem + env(safe-area-inset-bottom));
  max-width: 760px; width: 100%; margin: 0 auto;
}
.view.wide { max-width: 1100px; }

/* --------------------------- Untere Navigation -------------------------- */

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  appearance: none; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; height: var(--nav-h); color: var(--muted);
  font-family: var(--font); font-size: .68rem; font-weight: 500;
  transition: color .15s;
}
.bottom-nav button svg { width: 22px; height: 22px; }
.bottom-nav button.active { color: var(--s1); }
.bottom-nav button:active { transform: scale(.94); }

.nav-cam {
  position: relative;
}
.nav-cam .cam-circle {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--s1); color: #fff;
  display: grid; place-items: center;
  margin-top: -14px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--s1) 45%, transparent);
}
.nav-cam .cam-circle svg { width: 24px; height: 24px; }

/* -------------------------------- Karten -------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card.tight { padding: .75rem; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .75rem;
}
.card-head h2, .card-head h3 { margin: 0; }

.section-title {
  font-size: .75rem; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  margin: 1.5rem 0 .6rem;
}
.section-title:first-child { margin-top: 0; }

/* ------------------------------ Bedienung ------------------------------- */

.btn {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .7rem 1.1rem; border-radius: var(--radius-s);
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font-family: var(--font); font-size: .92rem; font-weight: 600;
  transition: transform .1s, filter .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--s1); border-color: var(--s1); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--critical); color: var(--critical); }
.btn.block { width: 100%; }
.btn.sm { padding: .45rem .7rem; font-size: .82rem; }
.btn.icon { padding: .5rem; width: 38px; height: 38px; }
.btn svg { width: 18px; height: 18px; }

.field { margin-bottom: .9rem; }
.field label {
  display: block; font-size: .82rem; font-weight: 600;
  color: var(--text-2); margin-bottom: .35rem;
}
.field .hint { font-size: .76rem; color: var(--muted); margin-top: .3rem; }

input, select, textarea {
  width: 100%; padding: .7rem .8rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-s);
  background: var(--surface-2); color: var(--text);
  font-family: var(--font); font-size: 1rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--s1); outline-offset: 1px; border-color: transparent;
}
textarea { min-height: 80px; resize: vertical; }
input[type="range"] { padding: 0; background: none; accent-color: var(--s1); }

.row { display: flex; gap: .6rem; }
.row > * { flex: 1; }
.row.tight { gap: .4rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }

.chip-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  appearance: none; cursor: pointer;
  padding: .45rem .8rem; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text-2); font-family: var(--font); font-size: .84rem; font-weight: 550;
}
.chip.active { background: var(--s1); border-color: var(--s1); color: #fff; }

/* ------------------------- Werte und Statistiken ------------------------ */

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: .5rem; }
.stat {
  background: var(--surface-2); border-radius: var(--radius-s);
  padding: .7rem; text-align: center;
}
.stat .val { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.stat .lbl { font-size: .72rem; color: var(--muted); margin-top: .15rem; }
.stat .sub { font-size: .7rem; color: var(--muted); }

.hero-num { font-size: 2.6rem; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.hero-unit { font-size: .9rem; color: var(--muted); font-weight: 500; }

/* Makro-Balken: jeder trägt sein eigenes Textlabel, die Farbe ist Beiwerk. */
.macro-bar { margin-bottom: .7rem; }
.macro-bar:last-child { margin-bottom: 0; }
.macro-bar .top {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .82rem; margin-bottom: .3rem;
}
.macro-bar .name { font-weight: 600; display: flex; align-items: center; gap: .4rem; }
.macro-bar .dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.macro-bar .nums { color: var(--text-2); font-variant-numeric: tabular-nums; }
.macro-bar .track {
  height: 8px; background: var(--surface-3);
  border-radius: 4px; overflow: hidden;
}
.macro-bar .fill { height: 100%; border-radius: 4px; transition: width .4s ease; }

/* ------------------------------ Listen ---------------------------------- */

.list { display: flex; flex-direction: column; gap: 1px; background: var(--border); border-radius: var(--radius-s); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem .8rem; background: var(--surface);
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 550; font-size: .93rem; }
.list-item .meta { font-size: .78rem; color: var(--muted); }
.list-item .value { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; white-space: nowrap; }
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { background: var(--surface-2); }

.meal-group { margin-bottom: 1rem; }
.meal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 .2rem .4rem;
}
.meal-head .name { font-weight: 650; font-size: .95rem; }
.meal-head .kcal { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }

.empty {
  text-align: center; padding: 2rem 1rem; color: var(--muted);
}
.empty svg { width: 40px; height: 40px; opacity: .4; margin-bottom: .5rem; }

/* ------------------------------ Diagramme ------------------------------- */

.chart-wrap { position: relative; width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: .8rem;
  font-size: .78rem; color: var(--text-2); margin-top: .5rem;
}
.chart-legend .item { display: flex; align-items: center; gap: .35rem; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 3px; }

.ring-wrap { display: flex; align-items: center; gap: 1rem; }
.ring-center { text-align: center; }

/* ------------------------------- Foto ----------------------------------- */

.photo-drop {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 2rem 1rem; text-align: center; cursor: pointer;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.photo-drop:hover, .photo-drop.over { border-color: var(--s1); background: color-mix(in srgb, var(--s1) 8%, var(--surface-2)); }
.photo-drop svg { width: 44px; height: 44px; color: var(--s1); margin-bottom: .5rem; }

.photo-preview { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; }
.photo-preview img { width: 100%; display: block; max-height: 340px; object-fit: cover; }

.analyzing { text-align: center; padding: 2rem 1rem; }
.analyzing .spinner { margin: 0 auto 1rem; }

.confidence {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .25rem .6rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600;
  background: var(--surface-3); color: var(--text-2);
}
.confidence.hoch    { background: color-mix(in srgb, var(--good) 18%, var(--surface)); color: var(--good-text); }
.confidence.mittel  { background: color-mix(in srgb, var(--warning) 22%, var(--surface)); color: var(--text); }
.confidence.niedrig { background: color-mix(in srgb, var(--critical) 16%, var(--surface)); color: var(--critical); }

.photo-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: .5rem; }
.photo-thumbs .thumb { position: relative; border-radius: var(--radius-s); overflow: hidden; aspect-ratio: 1; cursor: pointer; }
.photo-thumbs .thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumbs .thumb .kcal {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  color: #fff; font-size: .72rem; font-weight: 600; padding: .6rem .4rem .3rem; text-align: center;
}

/* ------------------------------- Training -------------------------------- */

.ex-item {
  background: var(--surface-2); border-radius: var(--radius-s);
  padding: .7rem .8rem; margin-bottom: .5rem;
}
.ex-item .head { display: flex; align-items: center; gap: .5rem; }
.ex-item .head .name { font-weight: 600; flex: 1; }
.ex-item .scheme { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ex-item .instructions { font-size: .78rem; color: var(--muted); margin-top: .35rem; }

.set-row { display: grid; grid-template-columns: 34px 1fr 1fr 38px; gap: .4rem; align-items: center; margin-bottom: .4rem; }
.set-row .no { font-size: .8rem; color: var(--muted); text-align: center; font-weight: 600; }
.set-row input { padding: .5rem; text-align: center; font-size: .9rem; }

.day-tabs { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .4rem; margin-bottom: .75rem; }
.day-tabs .chip { white-space: nowrap; }

/* ---------------------------- Rückmeldungen ------------------------------ */

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom));
  z-index: 200; display: flex; flex-direction: column; gap: .5rem;
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--s1);
  border-radius: var(--radius-s); padding: .7rem .9rem;
  box-shadow: var(--shadow); font-size: .88rem;
  animation: toast-in .25s ease;
}
.toast.error { border-left-color: var(--critical); }
.toast.success { border-left-color: var(--good); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,.5); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); width: min(100%, 560px);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.1rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: sheet-up .25s cubic-bezier(.2,.8,.3,1);
}
@keyframes sheet-up { from { transform: translateY(30px); } }
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius); }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.modal-head h2 { margin: 0; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--s1);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.boot {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1.2rem;
}
.boot-logo { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }

/* ------------------------------ Anmeldung ------------------------------- */

.auth-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  justify-content: center; padding: 1.5rem;
  max-width: 440px; margin: 0 auto;
}
.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo .name { font-size: 2rem; font-weight: 700; letter-spacing: -.03em; }
.auth-logo .tag { color: var(--muted); font-size: .9rem; }
.auth-switch { text-align: center; margin-top: 1rem; font-size: .88rem; color: var(--text-2); }
.auth-switch button {
  background: none; border: 0; color: var(--s1); cursor: pointer;
  font-family: var(--font); font-size: inherit; font-weight: 600; padding: 0;
}

.error-box {
  background: color-mix(in srgb, var(--critical) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent);
  color: var(--critical); padding: .7rem .9rem;
  border-radius: var(--radius-s); font-size: .87rem; margin-bottom: 1rem;
}
.info-box {
  background: color-mix(in srgb, var(--s1) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--s1) 30%, transparent);
  padding: .7rem .9rem; border-radius: var(--radius-s);
  font-size: .85rem; color: var(--text-2); margin-bottom: 1rem;
}

/* ------------------------------ Onboarding ------------------------------ */

.steps { display: flex; gap: .3rem; margin-bottom: 1.5rem; }
.steps .step { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-3); }
.steps .step.done { background: var(--s1); }

.choice-grid { display: grid; gap: .5rem; }
.choice {
  display: flex; align-items: center; gap: .75rem; cursor: pointer;
  padding: .85rem; border-radius: var(--radius-s);
  border: 1px solid var(--border-strong); background: var(--surface-2);
  text-align: left; font-family: var(--font); color: var(--text);
}
.choice.active { border-color: var(--s1); background: color-mix(in srgb, var(--s1) 10%, var(--surface-2)); }
.choice .t { font-weight: 600; font-size: .95rem; }
.choice .d { font-size: .8rem; color: var(--muted); }

table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th, table.data td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

.badge {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .72rem; font-weight: 600; background: var(--surface-3); color: var(--text-2);
}
.badge.admin { background: color-mix(in srgb, var(--s1) 20%, var(--surface)); color: var(--s1); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
