/* ------------------------------------------------------------------
   Design-Tokens
   Akzentfarbe (Buttons, aktive Elemente): --accent, Text darauf: --accent-ink.
   Fortschritt: --good (im Ziel), --over (Ziel überschritten).
------------------------------------------------------------------- */
:root {
  --accent: #6FB5FF;
  --accent-ink: #08182B;
  --good: #5CCF95;
  --over: #FF6B6B;
  --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);

  --bg: #0E0F10;
  --card: #1C1D1F;
  --card-raised: #242528;
  --period: #FF7AAE;
  --border: rgba(255, 255, 255, 0.06);
  --track: rgba(255, 255, 255, 0.08);

  --text: #F2F2F3;
  --text-2: #A1A1A6;
  --text-3: #6C6C72;
  --danger: #FF6B6B;

  --radius: 20px;
  --radius-sm: 14px;
  --gutter: 16px;
  --tap: 44px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 0px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          system-ui, "Helvetica Neue", Arial, sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body.is-locked { overflow: hidden; }

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

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }

/* ------------------------------------------------------------------
   Layout
------------------------------------------------------------------- */
#app {
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

.view { min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(var(--safe-top) + 12px) calc(var(--gutter) + var(--safe-right)) 8px calc(var(--gutter) + var(--safe-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(140%) blur(20px);
  backdrop-filter: saturate(140%) blur(20px);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-3);
}

.title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px calc(var(--gutter) + var(--safe-right)) 0 calc(var(--gutter) + var(--safe-left));
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  flex: none;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.accent {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}
.icon-btn.accent svg { stroke-width: 2.4; }
.icon-btn:active { transform: scale(0.94); }

/* Markierung für Tage mit Einträgen (Monatskalender) */
.day-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: transparent;
}

/* ------------------------------------------------------------------
   Kalorien-Bogen
------------------------------------------------------------------- */
.calories {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 16px 12px 14px;
}

.cal-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  align-self: end;
  padding-bottom: 4px;
  min-height: var(--tap);
}
button.cal-side { border-radius: var(--radius-sm); }
.cal-side .value {
  font-size: 19px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.cal-side .label {
  font-size: 12px;
  color: var(--text-2);
}
.cal-side .sub {
  font-size: 11px;
  color: var(--text-3);
}

.ring {
  --ring-size: min(44vw, 176px);
  position: relative;
  width: var(--ring-size);
  aspect-ratio: 1;
  /* Der 270°-Bogen ist unten offen – Leerraum unter dem Bogen einsparen */
  margin-bottom: calc(var(--ring-size) * -0.1);
}
.ring svg {
  width: 100%;
  height: 100%;
  display: block;
}
.ring .track,
.ring .progress {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}
.ring .track { stroke: var(--track); }
.ring .progress {
  stroke: var(--good);
  transition: stroke-dasharray 0.5s cubic-bezier(.2,.7,.2,1);
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 6px;
}
.ring-value {
  font-size: clamp(30px, 9.5vw, 38px);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.ring-label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-2);
}
.ring-goal {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-3);
}

/* ------------------------------------------------------------------
   Nährwerte
------------------------------------------------------------------- */
.summary { padding: 0; }
.nutrients {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  gap: 12px 14px;
  margin: 0 16px;
  padding: 12px 0 14px;
  border-top: 1px solid var(--border);
}
.nutrient {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  text-align: center;
}
.nutrient-name {
  max-width: 100%;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nutrient-val {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  white-space: nowrap;
}
.nutrient-val strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.nutrient .bar {
  width: 100%;
  height: 5px;
}
.bar {
  height: 6px;
  border-radius: 4px;
  background: var(--track);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--good);
  transition: width 0.5s cubic-bezier(.2,.7,.2,1);
}
.ring.is-over .progress { stroke: var(--over); }
.ring.is-over .ring-label { color: var(--over); }
.is-over > .bar > span,
.bar.is-over > span { background: var(--over); }
.nutrient.is-over .nutrient-val strong { color: var(--over); }

/* ------------------------------------------------------------------
   Mahlzeiten
------------------------------------------------------------------- */
.meals {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.block-title {
  margin: 0 4px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.meals-card { padding: 0 16px; }
.meal {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
}
.meal:last-child { border-bottom: 0; }
.meal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
}
.meal-toggle {
  flex: 1;
  min-width: 0;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}
.meal-toggle:disabled { cursor: default; opacity: 1; }
.meal-ring {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--text-2);
}
.meal-ring svg:first-child {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.meal-ring circle {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
}
.meal-ring .track { stroke: var(--track); }
.meal-ring .progress {
  stroke: var(--good);
  transition: stroke-dasharray 0.5s cubic-bezier(.2,.7,.2,1);
}
.meal.is-over .meal-ring .progress { stroke: var(--over); }
.meal-ring > svg:last-child {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.meal-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.meal-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
}
.meal-chev {
  color: var(--text-3);
  font-size: 17px;
  line-height: 1;
  transition: transform 0.2s;
}
.meal-toggle[aria-expanded="true"] .meal-chev { transform: rotate(90deg); }
.meal-kcal {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  white-space: nowrap;
}
.meal-kcal strong {
  color: var(--text);
  font-weight: 600;
}
.meal.is-over .meal-kcal strong { color: var(--over); }
.meal-preview {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meal .entry-list {
  margin: 0 0 8px 58px;
}

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}
.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  border-bottom: 1px solid var(--border);
}
.entry:last-child { border-bottom: 0; }
.entry-main {
  flex: 1;
  min-width: 0;
}
.entry-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-meta {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.entry-kcal {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}
.entry-del {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  color: var(--text-3);
  margin-right: -10px;
}
.entry-del svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ------------------------------------------------------------------
   Menü (Burger oben rechts)
------------------------------------------------------------------- */
.topbar-actions { display: flex; gap: 8px; }

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.45);
}
.menu {
  position: fixed;
  z-index: 26;
  top: calc(var(--safe-top) + 64px);
  right: calc(var(--gutter) + var(--safe-right));
  width: min(260px, calc(100vw - 2 * var(--gutter)));
  padding: 6px;
  display: flex;
  flex-direction: column;
  background: var(--card-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  transform-origin: top right;
  animation: menu-in 0.16s ease-out;
}
@keyframes menu-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: none; }
}
.tab {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  text-align: left;
}
.tab + .tab { border-top: 1px solid var(--border); border-radius: 0; }
.tab:active { background: rgba(255, 255, 255, 0.06); }
.tab svg {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--text-2);
}
.tab.is-active, .tab.is-active svg { color: var(--accent); }

/* Datum im Tagebuch: öffnet den Kalender */
.date-btn {
  display: block;
  text-align: left;
  color: inherit;
  min-width: 0;
}
.date-btn .title { display: flex; align-items: center; gap: 4px; }
.date-caret {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--text-3);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------
   Bottom-Sheet
------------------------------------------------------------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sheet-backdrop.is-open { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  max-height: calc(100dvh - var(--safe-top) - 24px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(.2,.8,.2,1);
}
.sheet.is-open { transform: translateY(0); }
.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--track);
  margin: 8px auto 0;
  flex: none;
}
.sheet-body {
  overflow-y: auto;
  padding: 12px calc(var(--gutter) + var(--safe-right)) calc(var(--safe-bottom) + 20px) calc(var(--gutter) + var(--safe-left));
  -webkit-overflow-scrolling: touch;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
  margin-bottom: 12px;
}
.sheet-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.sheet-close {
  min-height: var(--tap);
  padding: 0 4px;
  color: var(--text-2);
  font-size: 15px;
}

/* Segmentierte Auswahl */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  margin-bottom: 14px;
  background: var(--bg);
  border-radius: 12px;
}
.segmented button {
  min-height: 34px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
.segmented button.is-active {
  background: var(--card-raised);
  color: var(--text);
}

/* Formular-Elemente */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field > span {
  font-size: 12px;
  color: var(--text-2);
}
.input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.input::placeholder { color: var(--text-3); }

.input-unit {
  position: relative;
}
.input-unit .input { padding-right: 52px; text-align: right; }
.input-unit::after {
  content: attr(data-unit);
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 15px;
  pointer-events: none;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 600;
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.35; }
.btn.secondary {
  background: var(--card-raised);
  color: var(--text);
}
.btn.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
}

/* Listen im Sheet */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 8px 0;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.list li:last-child .list-item { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item .meta {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.list-item .chev {
  color: var(--text-3);
  font-size: 20px;
}
.list-empty {
  padding: 24px 0;
  text-align: center;
  color: var(--text-3);
  font-size: 15px;
}

/* Portions-Detail */
.detail-kcal {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 4px 0 14px;
}
.detail-kcal .big {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.detail-grid div {
  background: var(--bg);
  border-radius: 12px;
  padding: 10px;
}
.detail-grid b {
  display: block;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.detail-grid small {
  font-size: 11px;
  color: var(--text-3);
}

/* Barcode */
.scanner {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
  margin-bottom: 12px;
}
.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner::after {
  content: "";
  position: absolute;
  inset: 28% 12%;
  border: 2px solid var(--accent);
  border-radius: 12px;
  pointer-events: none;
}
.hint {
  font-size: 13px;
  color: var(--text-3);
  margin: 8px 0 12px;
}
.row {
  display: flex;
  gap: 8px;
}
.row > * { flex: 1; }

/* ------------------------------------------------------------------
   Monatskalender
------------------------------------------------------------------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.month-nav .month-label {
  font-size: 16px;
  font-weight: 600;
}
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
}
.month-grid .dow {
  font-size: 12px;
  color: var(--text-3);
  padding: 6px 0;
}
.mday {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  aspect-ratio: 1;
  min-height: var(--tap);
  border-radius: 50%;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.mday.is-today .day-num { color: var(--accent); font-weight: 700; }
.mday.is-selected { background: var(--card-raised); box-shadow: inset 0 0 0 1.5px var(--accent); }
.mday.is-outside { visibility: hidden; }

/* Tagebuch-Kalender: Status pro Tag wie bei Yazio */
.diary-grid .mday {
  position: relative;
  aspect-ratio: auto;
  min-height: 58px;
  border-radius: var(--radius-sm);
  justify-content: flex-start;
  padding-top: 6px;
  gap: 4px;
}
.day-mark {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
}
.day-mark svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.day-mark.is-ok { background: var(--good); }
.day-mark.is-ok svg { stroke: #0B2418; }
.day-mark.is-over { background: var(--over); }
.day-mark.is-over svg { stroke: #2A0B0B; }
.day-num { position: relative; line-height: 1.2; }
/* Tropfen hängt am Datum, nicht am Zellenrand */
.day-drop {
  position: absolute;
  top: 0;
  left: calc(100% + 2px);
  width: 9px;
  height: 9px;
  color: var(--period);
  pointer-events: none;
}
.day-drop svg { width: 100%; height: 100%; fill: currentColor; stroke: none; display: block; }
.day-drop.is-predicted svg { fill: none; stroke: currentColor; stroke-width: 2.4; }
.day-drop.inline { position: static; display: inline-block; vertical-align: -1px; margin-right: 5px; }

.cycle-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-2);
}
.cycle-legend .lg {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
}
.lg.ok { background: var(--good); }
.lg.over { background: var(--over); }
.lg.period { background: var(--period); }
.lg.predicted { box-shadow: inset 0 0 0 1.5px var(--period); }

/* ------------------------------------------------------------------
   Zyklus
------------------------------------------------------------------- */
.cycle-hero { display: flex; flex-direction: column; gap: 4px; }
.cycle-hero p { margin: 0; }
.cycle-eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--period);
}
.cycle-big {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.cycle-big.is-late { color: var(--period); }
.cycle-hero .btn { margin-top: 12px; }
.cycle-hero .btn svg { fill: currentColor; stroke: none; }
.cycle-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.cycle-stats .stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
}
.cycle-stats .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cycle-stats .label { font-size: 11px; color: var(--text-2); }
.cday {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 40px;
  margin: 2px;
  border-radius: 50%;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.cday.is-outside { visibility: hidden; }
.cday.is-today { font-weight: 700; box-shadow: inset 0 0 0 1.5px var(--text-3); }
.cday.is-period { background: var(--period); color: #2B0717; font-weight: 600; }
.cday.is-predicted { box-shadow: inset 0 0 0 1.5px var(--period); color: var(--period); }
.cday:active { transform: scale(0.92); }
.cycle-history { padding: 4px 16px; }
.cycle-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  font-size: 15px;
}
.cycle-row + .cycle-row { border-top: 1px solid var(--border); }
.cycle-row .meta { color: var(--text-2); font-size: 13px; text-align: right; }
.cycle-history .btn { margin: 8px 0 12px; }

/* ------------------------------------------------------------------
   Einstellungen
------------------------------------------------------------------- */
.section-title {
  margin: 12px 4px 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-3);
}
.section-note {
  margin: -4px 4px 0;
  font-size: 12px;
  color: var(--text-3);
}
.settings-card { padding: 4px 18px; }
.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row > label,
.setting-row > .label {
  flex: 1;
  min-width: 0;
  font-size: 15px;
}
.setting-row .input-unit { width: 132px; flex: none; }
.setting-row .input { min-height: 40px; font-size: 16px; }
.setting-row.is-off .label { color: var(--text-3); }

.setting-row > .switch,
.switch {
  position: relative;
  width: 51px;
  height: 31px;
  flex: none;
}
.switch input {
  position: absolute;
  inset: -6px;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: var(--track);
  transition: background 0.2s;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }

.reorder {
  display: flex;
  flex: none;
}
.reorder button {
  width: 36px;
  height: var(--tap);
  display: grid;
  place-items: center;
  color: var(--text-2);
}
.reorder button:disabled { color: var(--track); }
.reorder svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.setting-row.nutrient-setting {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "label switch"
    "goal  reorder";
  gap: 10px 12px;
  padding: 12px 0;
}
.nutrient-setting .label { grid-area: label; font-size: 15px; font-weight: 500; }
.nutrient-setting .switch { grid-area: switch; }
.nutrient-setting .goal { grid-area: goal; width: 132px; }
.nutrient-setting .reorder { grid-area: reorder; margin-right: -8px; }

/* Gerichte & eigene Produkte: Zeilen mit Wischen zum Löschen */
.swipe-row {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}
/* Rot nur beim Wischen, damit an den Ecken im Ruhezustand nichts durchscheint */
.swipe-row.is-swiping,
.swipe-row.is-open { background: var(--danger); }
.swipe-action {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.swipe-action svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.swipe-content {
  position: relative;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.25s cubic-bezier(.2,.8,.2,1);
}
.swipe-row.is-open .swipe-content { border-radius: var(--radius) 0 0 var(--radius); }
.lib-main {
  min-height: 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 10px 16px;
  text-align: left;
}
.lib-main .name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-main .meta {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.swipe-hint { text-align: center; margin-top: 2px; }
.lib-rows { display: flex; flex-direction: column; gap: 8px; }
.lib-rows .btn { margin-top: 2px; }

.empty-card { text-align: center; padding: 28px 16px; }
.empty-card p { margin: 0; }

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

/* Daten & Hinweise */
.data-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 18px;
}
label.btn { cursor: pointer; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--card-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Gestapelte Inhalte im Sheet */
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stack > .segmented,
.stack .field { margin-bottom: 0; }
.stack .list { margin: -4px 0; }
.sheet-body .btn + .btn { margin-top: 10px; }
.hint[hidden] { display: none; }

/* Nährwerttabelle */
.label-table {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 12px;
}
.label-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
}
.label-row:last-child { border-bottom: 0; }
.label-row > span {
  flex: 1;
  font-size: 15px;
}
.label-row.is-sub > span {
  padding-left: 14px;
  color: var(--text-2);
  font-size: 14px;
}
.label-row .input-unit { width: 120px; flex: none; }
.label-row .input {
  min-height: 38px;
  background: var(--card);
}
.row .field { min-width: 0; }

/* Zutatenliste */
.ingredient-list {
  margin-bottom: 10px;
}
.ingredient-list:empty { display: none; }

/* Einstellungen: Werte, Auswahl */
.setting-row .value {
  font-size: 15px;
  color: var(--text-2);
}
.setting-row .value.strong {
  color: var(--text);
  font-weight: 600;
}
.segmented.inline {
  margin: 0;
  flex: none;
  width: 180px;
}
.select {
  width: auto;
  max-width: 60%;
  min-height: 40px;
  padding: 0 34px 0 12px;
  font-size: 16px;
  text-align: right;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.meal .icon-btn {
  width: 40px;
  height: 40px;
}

/* Längere Einheiten brauchen mehr Platz rechts */
.input-unit[data-unit="Jahre"] .input,
.input-unit[data-unit="Port."] .input { padding-right: 64px; }
.input-unit[data-unit="Schritte"] .input,
.input-unit[data-unit="Portionen"] .input { padding-right: 96px; }

/* Hinweis auf geschätzte Werte */
.notice {
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
}

/* Tagebuch: horizontales Wischen wechselt den Tag, vertikal wird gescrollt */
#view-diary { touch-action: pan-y; overflow-x: clip; }
#view-diary .content,
#view-diary .topbar-row > div { will-change: transform; }

/* Foto der Nährwerttabelle */
.photo-scan {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.photo-scan .btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}
.photo-scan .hint { margin: 0; }
.btn.is-busy {
  opacity: 0.6;
  pointer-events: none;
}

.btn svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

/* Nährwerte in engen Spalten: Kurzform, ohne Einheit */
.nutrient-name .short { display: none; }
.nutrients[data-cols="4"] .nutrient-name .full,
.nutrients[data-cols="4"] .unit { display: none; }
.nutrients[data-cols="4"] .nutrient-name .short { display: inline; }
@media (max-width: 380px) {
  .nutrients { gap: 12px 10px; }
  .nutrient-name .full { display: none; }
  .nutrient-name .short { display: inline; }
  .nutrients .unit { display: none; }
  .nutrient-val { font-size: 11px; }
  .nutrient-val strong { font-size: 14px; }
}

/* ------------------------------------------------------------------
   Analyse
------------------------------------------------------------------- */
.topbar-spacer { width: var(--tap); flex: none; }
#view-analysis .topbar-row { justify-content: flex-start; }
#view-analysis .title { flex: 1; }
#an-back:not([hidden]) ~ .title { text-align: center; font-size: 18px; }
#an-back[hidden] ~ .topbar-spacer { display: none; }
.an-period { margin: 10px 0 0; }

.an-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.an-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.an-eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-3);
}
.an-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.an-value small {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-2);
}
.an-sub {
  font-size: 13px;
  color: var(--text-2);
}
.an-more {
  align-self: flex-start;
  min-height: var(--tap);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

/* Diagramm */
.an-chart { min-height: 190px; }
.chart-wrap { position: relative; }
.chart { display: block; max-width: 100%; overflow: visible; }
.chart .grid { stroke: var(--track); stroke-width: 1; }
.chart .axis {
  fill: var(--text-3);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.chart .bar-mark { fill: var(--good); }
.chart .bar-mark.is-over { fill: var(--over); }
.chart .goal { stroke: var(--text-2); stroke-width: 1.5; }
.chart .goal-label {
  fill: var(--text-2);
  font-size: 10px;
  font-weight: 600;
}
.chart .hit {
  fill: transparent;
  cursor: pointer;
  outline: none;
}
.chart .hit.is-active { fill: rgba(255, 255, 255, 0.05); }
.chart-tip {
  position: absolute;
  top: -6px;
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--card-raised);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  white-space: nowrap;
}
.chart-tip strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.chart-tip span { font-size: 11px; color: var(--text-2); }

/* Makroverteilung */
.an-macros { display: flex; flex-direction: column; gap: 14px; }
.stack-bar {
  display: flex;
  gap: 2px;
  height: 12px;
}
.stack-bar span:first-child { border-radius: 6px 0 0 6px; }
.stack-bar span:last-child { border-radius: 0 6px 6px 0; }
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}
.legend .grow { flex: 1; }
.legend .num { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 13px; }
.legend strong.num { color: var(--text); font-size: 14px; min-width: 42px; text-align: right; }
.an-macros .hint { margin: 0; }

/* Listen */
.an-list { padding: 0 16px; }
.an-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 10px 0;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.an-row:last-child { border-bottom: 0; }
.an-row .grow {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.an-row-title { font-size: 15px; font-weight: 500; }
.an-row-sub { font-size: 12px; color: var(--text-3); }
.an-row .bar { height: 4px; max-width: 160px; }
.an-row-val {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.an-row-val small { font-size: 12px; font-weight: 400; color: var(--text-3); }
.an-row .chev { color: var(--text-3); font-size: 20px; }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot.is-good { background: var(--good); }
.dot.is-over { background: var(--over); }
.goal-key {
  display: inline-block;
  width: 14px;
  height: 0;
  margin: 0 5px 3px 0;
  border-top: 1.5px solid var(--text-2);
  vertical-align: middle;
}

textarea.input.cycle-paste {
  height: auto;
  min-height: 120px;
  padding: 12px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  line-height: 1.5;
}
