/* FitDuo - Mobile-first, dunkel, grosse Touch-Flaechen (Bedienung im Gym) */

:root {
  --bg:        #0e1117;
  --surface:   #171b23;
  --surface-2: #1f242e;
  --line:      #2a303c;
  --text:      #e8ecf2;
  --muted:     #939cad;
  --accent:    #2f81f7;
  --ok:        #22c55e;
  --warn:      #f59e0b;
  --danger:    #ef4444;
  --radius:    14px;
  /* Sichere Bereiche des iPhone: Statusleiste/Dynamic Island oben,
     Home-Indikator unten, im Querformat zusätzlich die Notch seitlich. */
  --safe-t:    env(safe-area-inset-top, 0px);
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --safe-l:    env(safe-area-inset-left, 0px);
  --safe-r:    env(safe-area-inset-right, 0px);
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* Verhindert, dass iOS im Querformat die Schrift eigenmächtig vergrössert. */
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

/* Kein Doppeltipp-Zoom und keine 300 ms Verzögerung auf Bedienelementen -
   im Training zählt jeder Tap. */
button, .chip, .tab, .check, .step { touch-action: manipulation; }
body.no-scroll, body.in-session { overflow: hidden; }

h1, h2, h3, h4 { margin: 0 0 .3em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
p  { margin: 0 0 .6em; }
ol, ul { margin: .3em 0 .6em; padding-left: 1.25em; }
li { margin-bottom: .3em; }

.muted { color: var(--muted); }
.sm    { font-size: .82rem; }
.big   { font-size: 1.3rem; }
.right { text-align: right; }
.mt    { margin-top: .7rem; }
.mb    { margin-bottom: .8rem; }
.tight { margin-bottom: .2rem; }
.warn-text { color: var(--warn); }

/* ------------------------------------------------------------- Layout */
/* 100dvh statt 100vh: auf dem iPhone ist vh die Höhe MIT eingeblendeter
   Browserleiste und damit im Standalone-Modus zu gross. dvh gibt es ab
   iOS 16.4, die vh-Zeile davor bleibt als Rückfall für ältere Geräte. */
#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* Die Kopfzeile liegt im Standalone-Modus unter der Statusleiste bzw. der
   Dynamic Island - ohne das Einrücken oben wird sie davon überdeckt. */
#top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: calc(.7rem + var(--safe-t)) calc(1rem + var(--safe-r)) .7rem calc(1rem + var(--safe-l));
  background: rgba(14,17,23,.92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}

#view {
  flex: 1;
  padding: .9rem calc(.9rem + var(--safe-r)) calc(5.2rem + var(--safe-b)) calc(.9rem + var(--safe-l));
  max-width: 720px; width: 100%; margin: 0 auto;
}

#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: rgba(23,27,35,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  padding-left: var(--safe-l); padding-right: var(--safe-r);
}
.tab {
  appearance: none; border: 0; background: none; color: var(--muted);
  font-size: .7rem; font-family: inherit; padding: .5rem .1rem;
  cursor: pointer; border-top: 2px solid transparent;
  /* 46 px hoch: verlässlich mit dem Daumen zu treffen (Apple empfiehlt 44). */
  min-height: 46px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.tab.active { color: var(--text); border-top-color: var(--accent); }

.center-screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: calc(1.2rem + var(--safe-t)) calc(1.2rem + var(--safe-r))
           calc(1.2rem + var(--safe-b)) calc(1.2rem + var(--safe-l));
  max-width: 520px; margin: 0 auto;
}
.loader { color: var(--muted); }

/* -------------------------------------------------------------- Karten */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .95rem; margin-bottom: .8rem;
}
.card.accent { border-color: var(--accent); }
.card.warn   { border-color: var(--warn); }
.card-title  {
  font-size: .93rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: .6rem;
}

.hello { padding: .3rem .2rem 1rem; }
.hello h1 { margin-bottom: .1rem; }

.row { display: flex; align-items: center; }
.row.gap { gap: .6rem; }
.row.between { justify-content: space-between; }
.row.end { align-items: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }

/* ------------------------------------------------------------ Elemente */
.btn {
  appearance: none; font-family: inherit; font-size: .95rem; font-weight: 600;
  padding: .7rem 1rem; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  min-height: 44px; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost   { background: transparent; }
.btn.danger  { color: var(--danger); border-color: rgba(239,68,68,.4); }
.btn.block   { display: block; width: 100%; }
.btn.lg      { padding: .95rem; font-size: 1.05rem; }
.btn.sm      { padding: .45rem .7rem; font-size: .85rem; min-height: 0; }
.btn.back    { margin-bottom: .8rem; padding: .45rem .8rem; min-height: 0; }

.icon-btn {
  appearance: none; border: 0; background: none; color: var(--muted);
  font-size: 1.15rem; cursor: pointer; padding: .35rem .55rem;
  border-radius: 9px; line-height: 1; min-width: 40px; min-height: 40px;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn[disabled] { opacity: .3; }

.chip {
  appearance: none; font-family: inherit; font-size: .85rem;
  padding: .45rem .8rem; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  cursor: pointer;
}
.chip.active { border-color: var(--accent); color: var(--text); background: rgba(47,129,247,.12); }
.chip.swap { margin-bottom: .7rem; }
.plan-picker { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .7rem; }

.badge {
  background: var(--surface-2); border: 1px solid var(--line);
  padding: .25rem .6rem; border-radius: 999px; font-size: .82rem; white-space: nowrap;
}

.segmented { display: flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 3px; }
.seg {
  flex: 1; appearance: none; border: 0; background: none; color: var(--muted);
  font-family: inherit; font-size: .85rem; padding: .5rem .4rem;
  border-radius: 9px; cursor: pointer;
}
.seg.active { background: var(--surface); color: var(--text); }

.field { display: block; flex: 1; margin-bottom: .7rem; }
.field-label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
.field-hint  { display: block; font-size: .75rem; color: var(--muted); margin-top: .2rem; }

.input {
  width: 100%; font-family: inherit; font-size: 1rem;
  padding: .65rem .75rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  min-height: 44px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.input { resize: vertical; min-height: 70px; }
select.input { padding-right: 2rem; }
input[type=checkbox].cb { width: 22px; height: 22px; accent-color: var(--accent); }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: .95rem; flex: none;
}
.avatar.xs { width: 24px; height: 24px; font-size: .72rem; }

/* --------------------------------------------------------------- Listen */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .65rem 0; border-bottom: 1px solid var(--line);
  text-align: left; width: 100%;
}
.list-row:last-child { border-bottom: 0; }
.list-row.col { flex-direction: column; align-items: flex-start; gap: .15rem; }
.list-row.accent { color: var(--accent); }
button.list-row, .tappable {
  appearance: none; border-left: 0; border-right: 0; border-top: 0;
  background: none; color: inherit; font-family: inherit; font-size: 1rem; cursor: pointer;
}
.empty { text-align: center; color: var(--muted); padding: 1.4rem .5rem; }
.empty p { margin-bottom: .8rem; }
.bullets li { color: var(--muted); font-size: .88rem; }
.steps li { margin-bottom: .45rem; }

.stat { text-align: center; padding: .3rem 0; }
.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-value.big { font-size: 1.7rem; }
.stat-label { font-size: .75rem; color: var(--muted); }
.stat-sub { font-size: .72rem; color: var(--muted); }

.pbar { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: .3rem 0; }
.pbar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s ease; }
.pbar-fill.over { background: var(--danger); }

.macro { margin-bottom: .55rem; }
.macro-top { display: flex; justify-content: space-between; font-size: .82rem; }
.macro-label { color: var(--muted); }

.hint {
  background: var(--surface-2); border-left: 3px solid var(--muted);
  padding: .6rem .75rem; border-radius: 0 9px 9px 0;
  font-size: .85rem; color: var(--muted); margin: .7rem 0;
}
.hint.up { border-left-color: var(--ok); color: var(--text); }
.note { font-size: .85rem; color: var(--warn); }

.banner { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }

/* -------------------------------------------------------------- Charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid   { stroke: var(--line); stroke-width: 1; }
.chart-axis   { fill: var(--muted); font-size: 11px; }
.chart-empty  { fill: var(--muted); font-size: 13px; }
.chart-line   { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: .55; }
.chart-avg    { fill: none; stroke: var(--text); stroke-width: 2.5; stroke-linejoin: round; }
.chart-area   { fill: var(--accent); opacity: .08; }
.chart-target { stroke: var(--ok); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-dot    { fill: var(--accent); }
.chart-bar    { fill: var(--accent); opacity: .8; }
.chart-bar.dim { opacity: .25; }

.ring { width: 100%; height: 100%; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--accent); transition: stroke-dasharray .4s ease; }
.ring-fg.over { stroke: var(--danger); }
.ring-wrap { position: relative; width: 132px; flex: none; }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.ring-value { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.ring-label { font-size: .7rem; color: var(--muted); }
.balance { display: flex; align-items: center; gap: 1rem; }
.macros { flex: 1; min-width: 0; }

/* ------------------------------------------------------------- Training */
.train-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .9rem; gap: 1rem; }
.week-dots { text-align: right; }
.dots { display: flex; gap: 5px; justify-content: flex-end; margin-bottom: .3rem; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.dot.on { background: var(--ok); border-color: var(--ok); }

#session-host {
  position: fixed; inset: 0; z-index: 60; background: var(--bg);
  display: none; flex-direction: column;
}
#session-host.open { display: flex; }
.session-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(.6rem + var(--safe-t)) calc(.7rem + var(--safe-r)) .6rem calc(.7rem + var(--safe-l));
  border-bottom: 1px solid var(--line); flex: none;
}
.session-title { text-align: center; }
.session-prog { height: 3px; background: var(--surface-2); flex: none; }
.session-prog-fill { height: 100%; background: var(--ok); transition: width .3s ease; }
.session-body {
  flex: 1; overflow-y: auto;
  padding: 1rem calc(.9rem + var(--safe-r)) 1.5rem calc(.9rem + var(--safe-l));
  max-width: 720px; width: 100%; margin: 0 auto;
}
.session-foot {
  display: flex; gap: .7rem;
  padding: .8rem calc(.9rem + var(--safe-r)) calc(.8rem + var(--safe-b)) calc(.9rem + var(--safe-l));
  border-top: 1px solid var(--line); flex: none;
  max-width: 720px; width: 100%; margin: 0 auto;
}
.session-foot .btn { flex: 1; }

.ex-head { display: flex; gap: .8rem; align-items: flex-start; margin-bottom: .8rem; }
.ex-num {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--accent);
}
.ex-num.sm { width: 26px; height: 26px; font-size: .8rem; border-radius: 8px; }

.guide { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .8rem; }
.guide > summary { padding: .75rem .9rem; cursor: pointer; font-weight: 600; font-size: .9rem; list-style: none; }
.guide > summary::-webkit-details-marker { display: none; }
.guide > summary::after { content: '▾'; float: right; color: var(--muted); }
.guide[open] > summary::after { content: '▴'; }
.guide-body { padding: 0 .9rem .8rem; font-size: .9rem; }
.guide-body h4 { margin: .7rem 0 .2rem; font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.mistakes li { color: var(--warn); }

.sets { display: flex; flex-direction: column; gap: .5rem; margin-top: .3rem; }
.set-row {
  display: flex; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: .5rem .6rem;
}
.set-row.done { border-color: var(--ok); background: rgba(34,197,94,.06); }
.set-no { font-size: .75rem; color: var(--muted); width: 1.2rem; flex: none; text-align: center; }
.set-field { display: flex; align-items: center; gap: .2rem; flex: 1; min-width: 0; }
.set-field .input { text-align: center; padding: .5rem .2rem; min-height: 40px; }
.set-field .unit { font-size: .7rem; color: var(--muted); flex: none; }
.step {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); width: 34px; height: 40px; border-radius: 9px;
  font-size: 1.1rem; cursor: pointer; flex: none; line-height: 1;
}
.btn.ok {
  flex: none; width: 52px; padding: .5rem; min-height: 40px;
  background: var(--surface-2); font-size: .9rem;
}
.btn.ok.done { background: var(--ok); border-color: var(--ok); color: #06210f; }

.rest {
  position: absolute; inset: 0; z-index: 5;
  background: rgba(14,17,23,.94); display: flex; align-items: center; justify-content: center;
}
.rest-box { text-align: center; padding: 2rem; }
.rest-num { font-size: 4.5rem; font-weight: 700; line-height: 1; margin: .4rem 0; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ Ernaehrung */
.daynav {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .3rem .4rem; margin-bottom: .8rem;
}
.daynav-label {
  appearance: none; border: 0; background: none; color: inherit;
  font-family: inherit; text-align: center; flex: 1; cursor: pointer; padding: .35rem;
}
.slot-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .5rem; gap: .6rem; }
.slot-head .card-title { margin-bottom: .1rem; }
.slot-sum { text-align: right; flex: none; }

/* Kategorie-Chips im Lebensmittel-Dialog: waagrecht scrollbar, nie umbrechend */
.cat-chips {
  display: flex; gap: .4rem; overflow-x: auto;
  padding: .7rem 0 .3rem; scrollbar-width: none;
}
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chips .chip { flex: none; white-space: nowrap; }

/* Mahlzeit antippen = Menge korrigieren */
.meal-main {
  flex: 1; min-width: 0; text-align: left; appearance: none; border: 0;
  background: none; color: inherit; font-family: inherit; font-size: 1rem;
  cursor: pointer; padding: 0;
}

.food-results { max-height: 52vh; overflow-y: auto; margin-top: .2rem; }
.food-cat {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: .6rem 0 .25rem; position: sticky; top: 0;
  background: var(--surface);
}
.food-row {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  width: 100%; text-align: left; appearance: none; border: 0;
  border-bottom: 1px solid var(--line); background: none; color: inherit;
  font-family: inherit; font-size: 1rem; padding: .6rem 0; cursor: pointer;
}
.plus { color: var(--accent); font-size: 1.3rem; font-weight: 700; }
.preview { background: var(--surface-2); border-radius: 11px; padding: .6rem; margin: .5rem 0; }

/* --------------------------------------------------------------- Einkauf */
.shop-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem 0; border-bottom: 1px solid var(--line);
}
.shop-row:last-child { border-bottom: 0; }
.shop-row.done .shop-main strong { text-decoration: line-through; color: var(--muted); }
.shop-main {
  flex: 1; min-width: 0; text-align: left; appearance: none; border: 0;
  background: none; color: inherit; font-family: inherit; font-size: 1rem;
  cursor: pointer; padding: 0;
}
.check {
  width: 28px; height: 28px; border-radius: 8px; flex: none; cursor: pointer;
  border: 2px solid var(--line); background: transparent; color: #06210f;
  font-size: .9rem; font-weight: 700; line-height: 1;
}
.check.on { background: var(--ok); border-color: var(--ok); }

/* ----------------------------------------------------------------- Login */
.login { max-width: 420px; margin: 0 auto; padding: 3rem 1.2rem; width: 100%; }
.brand { text-align: center; margin-bottom: 2rem; }
.brand h1 { font-size: 1.9rem; letter-spacing: -.02em; }
.profiles { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.profile {
  appearance: none; font-family: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  padding: 1.4rem .8rem; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--surface); color: var(--text);
}
.profile:active { transform: scale(.98); }
.profile-avatar {
  width: 56px; height: 56px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700;
}
.profile-avatar.lg { width: 72px; height: 72px; font-size: 2rem; margin: 0 auto .8rem; }
.pin-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; }
.pin-box .input { text-align: center; font-size: 1.5rem; letter-spacing: .3em; margin-bottom: .6rem; }
.err-msg { color: var(--danger); font-size: .85rem; min-height: 1.2em; text-align: center; margin: 0 0 .5rem; }

/* ----------------------------------------------------------------- Modal */
.modal-back {
  position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .18s ease;
}
.modal-back.in { opacity: 1; }
.modal {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  transform: translateY(14px); transition: transform .18s ease;
}
.modal-back.in .modal { transform: none; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1rem .5rem; flex: none;
}
.modal-head h3 { margin: 0; }
.modal-body { padding: 0 1rem 1rem; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; gap: .6rem;
  padding: .8rem calc(1rem + var(--safe-r)) calc(.8rem + var(--safe-b)) calc(1rem + var(--safe-l));
  border-top: 1px solid var(--line); flex: none;
}
.modal-foot .btn { flex: 1; }

@media (min-width: 560px) {
  .modal-back { align-items: center; }
  .modal { border-radius: var(--radius); }
}

/* ---------------------------------------------------------------- Toasts */
#toasts {
  position: fixed; bottom: calc(5rem + var(--safe-b)); left: 0; right: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
  pointer-events: none; padding: 0 1rem;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--line);
  padding: .6rem 1rem; border-radius: 999px; font-size: .88rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  animation: toast-in .2s ease; max-width: 100%;
}
.toast.ok  { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }
.toast.out { opacity: 0; transition: opacity .4s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
