/* ==========================================================================
   Gesundheit — Design-Grundlage
   Orientiert an iOS / Apple Health: Grouped-Background, Karten, wenige Akzente.
   ========================================================================== */

/* --- Farb-Token: Light ---------------------------------------------------- */
:root {
  --bg:            #f2f2f7;
  --card:          #ffffff;
  --card-2:        #f2f2f7;
  --sep:           rgba(60, 60, 67, 0.20);
  --sep-strong:    rgba(60, 60, 67, 0.29);
  --label:         #1c1c1e;
  --label-2:       rgba(60, 60, 67, 0.60);
  --label-3:       rgba(60, 60, 67, 0.32);
  --fill:          rgba(120, 120, 128, 0.16);
  --fill-2:        rgba(120, 120, 128, 0.24);
  --bar-track:     rgba(120, 120, 128, 0.18);
  --chrome:        rgba(249, 249, 249, 0.86);
  --shadow:        0 1px 2px rgba(0, 0, 0, 0.04);

  --weight:        #007aff;
  --food:          #ff9500;
  --sport:         #34c759;
  --protein:       #ff3b30;
  --fat:           #a2845e;
  --carb:          #34c759;
  --fiber:         #30b0c7;
  --streak:        #ff6b2c;
  --warn:          #ff9500;
  --danger:        #ff3b30;

  --radius:        12px;
  --radius-lg:     16px;
  --gutter:        16px;
  --tabbar-h:      calc(50px + env(safe-area-inset-bottom));

  color-scheme: light;
}

/* --- Farb-Token: Dark ----------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #000000;
    --card:        #1c1c1e;
    --card-2:      #2c2c2e;
    --sep:         rgba(84, 84, 88, 0.48);
    --sep-strong:  rgba(84, 84, 88, 0.65);
    --label:       #ffffff;
    --label-2:     rgba(235, 235, 245, 0.60);
    --label-3:     rgba(235, 235, 245, 0.30);
    --fill:        rgba(120, 120, 128, 0.24);
    --fill-2:      rgba(120, 120, 128, 0.36);
    --bar-track:   rgba(120, 120, 128, 0.32);
    --chrome:      rgba(22, 22, 24, 0.88);
    --shadow:      none;

    --weight:      #0a84ff;
    --food:        #ff9f0a;
    --sport:       #30d158;
    --protein:     #ff453a;
    --fat:         #ac8e68;
    --carb:        #30d158;
    --fiber:       #40c8e0;
    --streak:      #ff7a3d;
    --warn:        #ff9f0a;
    --danger:      #ff453a;

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:            #000000;
  --card:          #1c1c1e;
  --card-2:        #2c2c2e;
  --sep:           rgba(84, 84, 88, 0.48);
  --sep-strong:    rgba(84, 84, 88, 0.65);
  --label:         #ffffff;
  --label-2:       rgba(235, 235, 245, 0.60);
  --label-3:       rgba(235, 235, 245, 0.30);
  --fill:          rgba(120, 120, 128, 0.24);
  --fill-2:        rgba(120, 120, 128, 0.36);
  --bar-track:     rgba(120, 120, 128, 0.32);
  --chrome:        rgba(22, 22, 24, 0.88);
  --shadow:        none;

  --weight:        #0a84ff;
  --food:          #ff9f0a;
  --sport:         #30d158;
  --protein:       #ff453a;
  --fat:           #ac8e68;
  --carb:          #30d158;
  --fiber:         #40c8e0;
  --streak:        #ff7a3d;
  --warn:          #ff9f0a;
  --danger:        #ff453a;

  color-scheme: dark;
}

/* --- Basis ---------------------------------------------------------------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 17px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

body.no-tabbar { --tabbar-h: 0px; }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }

button, input, select, textarea { font: inherit; color: inherit; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* --- Layout --------------------------------------------------------------- */
#view {
  padding: 0 var(--gutter);
  padding-top: calc(8px + env(safe-area-inset-top));
  padding-bottom: calc(var(--tabbar-h) + 28px);
  max-width: 640px;
  margin: 0 auto;
}

.page-title {
  font-size: 34px;
  line-height: 1.12;
  margin: 12px 0 18px;
}

.page-title .sub {
  display: block;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--label-2);
  margin-top: 2px;
}

.section-head {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--label-2);
  margin: 26px 4px 8px;
}

.section-head:first-child { margin-top: 4px; }

/* Einheiten in Überschriften bleiben klein geschrieben — sonst wird aus "g" ein "G". */
.section-head .einheit-klein { text-transform: none; }

/* --- Karte ---------------------------------------------------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card.tight { padding: 0; overflow: hidden; }

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

.card-head h2 {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-head h2 .mehr { color: var(--label-3); display: flex; }

.card-link {
  font-size: 15px;
  color: var(--weight);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}

/* --- Listenzeilen --------------------------------------------------------- */
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 11px 16px;
  background: none;
  border: 0;
  border-bottom: 0.5px solid var(--sep);
  text-align: left;
  color: inherit;
  font-size: 17px;
  text-decoration: none;
  cursor: pointer;
}

.row:last-child { border-bottom: 0; }
.row:active { background: var(--fill); }
.row.static { cursor: default; }
.row.static:active { background: none; }

.row-main { flex: 1; min-width: 0; }
.row-title { display: block; }
.row-sub {
  display: block;
  font-size: 13px;
  color: var(--label-2);
  margin-top: 1px;
}
.row-value { color: var(--label-2); white-space: nowrap; }
.row-chevron { color: var(--label-3); flex: none; }

.row.day-nav {
  flex: 0 0 56px;
  justify-content: center;
  border-bottom: 0;
  color: var(--weight);
}

.row.day-nav:disabled { color: var(--label-3); cursor: default; }
.row.day-nav:disabled:active { background: none; }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--label-2);
  font-size: 15px;
}

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 13px 20px;
  border: 0;
  border-radius: var(--radius);
  background: var(--weight);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

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

.btn.secondary { background: var(--fill-2); color: var(--label); }
.btn.tinted { background: color-mix(in srgb, var(--c, var(--weight)) 15%, transparent); color: var(--c, var(--weight)); }
.btn.ghost { background: none; color: var(--weight); font-weight: 500; min-height: 44px; }
.btn.destructive { background: none; color: var(--danger); }
.btn + .btn { margin-top: 8px; }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-top: 0; }

/* --- Formulare ------------------------------------------------------------ */
.field { margin-bottom: 16px; }

.field > label {
  display: block;
  font-size: 15px;
  font-weight: 500;
  color: var(--label-2);
  margin-bottom: 6px;
}

.field .hint {
  font-size: 13px;
  color: var(--label-2);
  margin-top: 6px;
  line-height: 1.35;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  background: var(--card-2);
  border: 0.5px solid var(--sep);
  border-radius: var(--radius);
  font-size: 17px;
  appearance: none;
}

textarea { min-height: 96px; line-height: 1.4; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--weight);
  outline-offset: -1px;
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Satz-Zeile beim Krafttraining: Nr. | kg | × | Wdh. | entfernen */
.satz {
  display: grid;
  grid-template-columns: 22px 1fr 14px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.satz input { min-height: 48px; text-align: center; padding: 12px 6px; }
.satz-nr { color: var(--label-2); font-size: 15px; text-align: center; }
.satz-mal { color: var(--label-2); text-align: center; }

.satz-weg {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  background: var(--fill);
  color: var(--label-2);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.satz-weg:active { background: var(--fill-2); }

/* Uebungsblock innerhalb einer Krafteinheit */
.block-kopf {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.block-kopf select { flex: 1; font-weight: 600; }

.block-weg {
  flex: none;
  width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius);
  background: var(--fill);
  color: var(--label-2);
  cursor: pointer;
}

.block-weg:active { background: var(--fill-2); }
.block-hinweis:empty { display: none; }

/* Segmentierte Auswahl (Geschlecht, Aktivitaet, Theme) */
.segments { display: flex; flex-wrap: wrap; gap: 8px; }

.segments.stack { flex-direction: column; }

.seg {
  flex: 1 1 auto;
  min-height: 48px;
  padding: 11px 14px;
  background: var(--card-2);
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.segments:not(.stack) .seg { text-align: center; }

.seg[aria-pressed="true"] {
  border-color: var(--weight);
  background: color-mix(in srgb, var(--weight) 12%, transparent);
  font-weight: 600;
}

.seg .seg-sub {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: var(--label-2);
  margin-top: 1px;
}

/* --- Kennzahl / grosser Wert ---------------------------------------------- */
.metric { display: flex; align-items: baseline; gap: 6px; }
.metric .value { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.metric .unit { font-size: 17px; color: var(--label-2); font-weight: 500; }

.metric-sub { font-size: 15px; color: var(--label-2); margin-top: 6px; }

/* --- Status-Pille --------------------------------------------------------- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  background: var(--fill);
  color: var(--label-2);
}

.status .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.status.ok      { color: var(--sport);   background: color-mix(in srgb, var(--sport) 14%, transparent); }
.status.neutral { color: var(--label-2); background: var(--fill); }
.status.attention { color: var(--warn);  background: color-mix(in srgb, var(--warn) 14%, transparent); }

/* --- Fortschrittsbalken (Makros) ------------------------------------------ */
.bars { display: grid; gap: 14px; }

.bar-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 15px;
  margin-bottom: 6px;
}

.bar-label .name { font-weight: 500; }
.bar-label .figure { color: var(--label-2); font-size: 14px; }

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

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--c, var(--weight));
  width: 0;
  transition: width 0.45s cubic-bezier(0.22, 0.7, 0.3, 1);
}

.bar-fill.over {
  background: repeating-linear-gradient(115deg,
    var(--c), var(--c) 7px,
    color-mix(in srgb, var(--c) 50%, transparent) 7px,
    color-mix(in srgb, var(--c) 50%, transparent) 14px);
}

/* Makro-Kurzuebersicht auf der Startseite */
.makro-gitter {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 18px;
  margin-top: 16px;
}

.makro-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--label-2);
  margin-top: 2px;
}

.makro-name span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

/* --- Chart ---------------------------------------------------------------- */
.chart { width: 100%; height: auto; aspect-ratio: 340 / 190; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--sep); stroke-width: 0.5; }
.chart .axis-label { fill: var(--label-2); font-size: 11px; }
.chart .trend-line { fill: none; stroke: var(--weight); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart .trend-area { fill: var(--weight); opacity: 0.10; }
.chart .goal-line { stroke: var(--label-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .raw-dot { fill: var(--label-3); }
.chart .end-dot { fill: var(--weight); stroke: var(--card); stroke-width: 2.5; }

/* --- Fortschrittsring ----------------------------------------------------- */
.ring { width: 92px; height: 92px; flex: none; overflow: visible; }

.ring-fill { transition: stroke-dashoffset 0.9s cubic-bezier(0.22, 0.7, 0.3, 1); }

.ring-wert {
  fill: var(--label);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.ring-sub { fill: var(--label-2); font-size: 12px; }

/* --- Erfolgs-Kachel ------------------------------------------------------- */
.kachel {
  display: flex;
  align-items: center;
  gap: 18px;
}

.kachel-text { flex: 1; min-width: 0; }

.kachel-zahl {
  display: flex;
  align-items: baseline;
  gap: 7px;
  line-height: 1;
}

.kachel-zahl .gross {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -0.035em;
  background: linear-gradient(135deg, var(--streak), color-mix(in srgb, var(--streak) 45%, var(--food)));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.kachel-zahl .einheit { font-size: 16px; font-weight: 600; color: var(--label-2); }
.kachel-sub { font-size: 13px; color: var(--label-2); margin-top: 5px; }

.kachel-flamme {
  font-size: 26px;
  line-height: 1;
  filter: saturate(1.1);
  animation: flackern 3.4s ease-in-out infinite;
}

@keyframes flackern {
  0%, 100% { transform: rotate(-3deg) scale(1); }
  50%      { transform: rotate(3deg) scale(1.08); }
}

/* --- Wochenpunkte --------------------------------------------------------- */
.woche { display: flex; gap: 6px; margin-top: 14px; }

.woche-tag {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.woche-punkt {
  width: 100%;
  height: 26px;
  border-radius: 7px;
  background: var(--bar-track);
  transition: background 0.3s ease;
}

.woche-tag.aktiv .woche-punkt {
  background: var(--c, var(--streak));
}

.woche-tag.heute .woche-punkt {
  box-shadow: inset 0 0 0 2px var(--label-3);
}

.woche-tag.heute.aktiv .woche-punkt {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c, var(--streak)) 55%, var(--label));
}

.woche-buchstabe { font-size: 11px; color: var(--label-2); }
.woche-tag.heute .woche-buchstabe { color: var(--label); font-weight: 600; }

/* --- Tab-Bar -------------------------------------------------------------- */
#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--chrome);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep-strong);
  z-index: 50;
}

body.no-tabbar #tabbar { display: none; }

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: 0;
  color: var(--label-2);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
}

.tab svg { width: 25px; height: 25px; }
.tab[aria-current="page"] { color: var(--weight); }

/* --- Modal / Sheet -------------------------------------------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.2s ease;
}

.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 8px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  animation: slide-up 0.28s cubic-bezier(0.22, 0.7, 0.3, 1);
}

.sheet-grip {
  width: 36px;
  height: 5px;
  border-radius: 999px;
  background: var(--label-3);
  margin: 6px auto 14px;
}

.sheet h2 { font-size: 22px; margin-bottom: 16px; }

@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

/* --- Toast ---------------------------------------------------------------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px);
  transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--label);
  color: var(--bg);
  font-size: 15px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 200;
}

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

/* --- Hinweis-Banner ------------------------------------------------------- */
.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 14px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  font-size: 15px;
  line-height: 1.35;
  margin-bottom: 12px;
}

.notice.plain { background: var(--fill); }
.notice .notice-body { flex: 1; }
.notice strong { font-weight: 600; }
.notice .btn { margin-top: 10px; min-height: 44px; }

.fineprint {
  font-size: 13px;
  line-height: 1.45;
  color: var(--label-2);
  margin: 4px 4px 0;
}

/* --- Onboarding-Schritte -------------------------------------------------- */
.steps { display: flex; gap: 5px; margin: 4px 0 18px; }
.step-dot { flex: 1; height: 4px; border-radius: 999px; background: var(--fill-2); }
.step-dot.done { background: var(--weight); }

/* --- Einblenden ----------------------------------------------------------- */
.fade-in { animation: fade-in 0.32s cubic-bezier(0.22, 0.7, 0.3, 1) both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } }

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