/* Lefa – mobile-first Stylesheet. Primär für iPhone (Safari, PWA standalone). */

:root {
  --bg: #f2f5f3;
  --surface: #ffffff;
  --text: #1a2420;
  --text-muted: #66736d;
  --border: #e2e8e4;
  --accent: #0d9b6c;
  --accent-contrast: #ffffff;
  --danger: #d34a4a;
  --warn: #d99a26;
  --ok: #0d9b6c;
  --radius: 14px;
  --tabbar-height: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101613;
    --surface: #1a231e;
    --text: #e6ede9;
    --text-muted: #93a09a;
    --border: #2a352f;
    --accent: #2fbd8b;
    --accent-contrast: #08130e;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

/* Kopfzeile */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  padding: calc(env(safe-area-inset-top) + 10px) 20px 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Inhalt */
.content {
  padding: 8px 16px calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 24px);
  max-width: 640px;
  margin: 0 auto;
}

/* Untere Tab-Navigation */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.65rem;
  -webkit-tap-highlight-color: transparent;
}

.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }

/* Karten */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 650;
}

.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.card-link:active { background: color-mix(in srgb, var(--surface) 92%, var(--accent)); }

.card-grid { display: flex; flex-direction: column; }

.muted { color: var(--text-muted); }
.muted, p { line-height: 1.45; }
p { margin: 0.35em 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn:active { filter: brightness(0.92); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* Formulare */
label { display: block; font-size: 0.85rem; font-weight: 600; margin: 12px 0 4px; }

input, select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

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

/* Hinweise / Fehlermeldungen */
.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin: 10px 0;
}

.alert-error {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

/* Fasten-Timer-Ring */
.center { text-align: center; }

.ring-wrap {
  position: relative;
  width: min(65vw, 250px);
  margin: 10px auto 18px;
}

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

.ring-bg { fill: none; stroke: var(--border); stroke-width: 12; }

.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease;
}

.ring.done .ring-fg {
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 60%, transparent));
}

.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.ring-time {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Statistik-Kacheln */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}

.stat-value { font-size: 1.2rem; font-weight: 700; }
.stat-name { font-size: 0.66rem; color: var(--text-muted); margin-top: 2px; }

/* Listen */
.list { list-style: none; margin: 0; padding: 0; }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: none; padding-bottom: 0; }

.small { font-size: 0.8rem; }

/* Toast-Meldungen */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 10px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  max-width: 86vw;
}

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

/* Zucker-Fortschrittsbalken */
.big { font-size: 1.5rem; font-weight: 700; }

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

.link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 0.9rem; }

.progress {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin: 8px 0 4px;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--ok);
  transition: width 0.3s;
}

.progress.over-target .progress-fill { background: var(--warn); }
.progress.over-limit .progress-fill { background: var(--danger); }

.progress-marker {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--text-muted);
  opacity: 0.7;
}

.entry-right { display: flex; align-items: center; gap: 10px; }
.entry-amount { font-weight: 650; font-variant-numeric: tabular-nums; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 8px;
}

.icon-btn:active { background: var(--border); }

/* Segmentierte Umschalter (7/30 Tage) */
.segmented {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 12px;
}

.segment {
  flex: 1;
  text-align: center;
  padding: 8px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.segment.active { background: var(--accent); color: var(--accent-contrast); }

/* SVG-Chart */
.chart-wrap { overflow: hidden; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; }
.chart .bar-green { fill: var(--ok); }
.chart .bar-yellow { fill: var(--warn); }
.chart .bar-red { fill: var(--danger); }
.chart .line-target { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .line-limit { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 5 4; }

.legend { display: flex; gap: 16px; margin-top: 8px; }
.legend-dash { display: inline-block; width: 18px; height: 0; border-top: 2px dashed var(--text-muted); vertical-align: middle; margin-right: 4px; }
.legend-limit { border-top-color: var(--danger); }

.stat-row-2 { grid-template-columns: repeat(2, 1fr); }

/* Inline-Editor in der Fasten-Historie */
.edit-row {
  list-style: none;
  padding: 10px 12px 14px;
  margin: 4px 0 8px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* Kamera-Scanner */
#camera-area {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin: 10px 0;
  background: #000;
}

#camera-video {
  width: 100%;
  max-height: 55vh;
  display: block;
  object-fit: cover;
}

.scan-line {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 2px;
  background: color-mix(in srgb, var(--accent) 85%, white);
  box-shadow: 0 0 10px var(--accent);
  animation: scanline 2.2s ease-in-out infinite;
}

@keyframes scanline {
  0%, 100% { transform: translateY(-34px); }
  50% { transform: translateY(34px); }
}

/* Suchtreffer */
.search-hit {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.thumb {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  flex-shrink: 0;
}

.thumb-empty { background: var(--border); }

/* Produktkarte */
.product-head { display: flex; gap: 14px; align-items: flex-start; }

.product-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  flex-shrink: 0;
}

.reasons { margin: 10px 0; padding-left: 20px; color: var(--text-muted); }
.reasons li { margin: 2px 0; }

.nutrients { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 0.92rem; }
.nutrients th { text-align: left; font-size: 0.8rem; color: var(--text-muted); padding: 6px 0; }
.nutrients td { padding: 6px 0; border-top: 1px solid var(--border); }
.nutrients .num { text-align: right; font-variant-numeric: tabular-nums; }
.nutrients .row-highlight td { font-weight: 700; color: var(--accent); }

.portion { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 4px; }

/* Ampel-Badges (Gesundheits-Einschätzung, ab M6) */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 650;
}

.badge-green { background: color-mix(in srgb, var(--ok) 15%, var(--surface)); color: var(--ok); }
.badge-yellow { background: color-mix(in srgb, var(--warn) 15%, var(--surface)); color: var(--warn); }
.badge-red { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }
.badge-gray { background: color-mix(in srgb, var(--text-muted) 15%, var(--surface)); color: var(--text-muted); }
