/* Design-Basis: helle Fläche, weiße Karten, ein Akzentgrün, System-Font, runde Ecken. */
:root {
  --bg: #FAFAF8;
  --card: #FFFFFF;
  --ink: #1C1C1A;
  --muted: #74746E;
  --line: #E7E7E0;
  --accent: #1B6B4A;
  --accent-soft: #E7F0EB;
  --danger: #B3402A;
  --radius: 16px;
  --radius-s: 12px;
  --shadow: 0 1px 2px rgba(25, 25, 15, .05), 0 8px 24px rgba(25, 25, 15, .07);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(140px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

h1 { font-size: 1.5rem; margin: 8px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }

.sub { color: var(--muted); font-size: .9rem; margin: 0 0 16px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

/* Formulare */
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 5px; }

input[type="email"], input[type="password"], input[type="text"],
input[type="number"], input[type="datetime-local"], select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: #fff;
  font: inherit;
  color: inherit;
  appearance: none;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2374746E' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 13px 16px;
  margin-top: 16px;
  border: 0;
  border-radius: var(--radius-s);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s ease, transform .05s ease;
}
.btn:active { transform: scale(.99); filter: brightness(1.08); }
.btn[disabled] { opacity: .55; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 500; }

.linkbtn {
  background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline;
}

.error {
  background: #FBEDE9;
  color: var(--danger);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  font-size: .9rem;
  margin-top: 14px;
}

.notice {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  font-size: .9rem;
  margin: 10px 0;
}

/* Kopfzeile */
.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }

/* Tages-Summen (bis zu 8 Kacheln, 4 pro Reihe) */
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.totals .tot {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 6px;
  text-align: center;
}
.tot .v { font-weight: 700; font-size: 1.05rem; }
.tot .v.over { color: var(--danger); }   /* Obergrenze überschritten */
.tot .v.met { color: var(--accent); }    /* Untergrenze (z. B. Ballaststoffe) erreicht */
.tot .k { color: var(--muted); font-size: .7rem; margin-top: 2px; }

/* Mahlzeiten-Liste */
.entry { display: flex; gap: 12px; }
.entry .time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 46px; padding-top: 2px; }
.entry .body { flex: 1; min-width: 0; }
.entry .item-line { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.entry .item-line .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .item-line .m { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.entry .body, .entry .time { cursor: pointer; }
.entry .del {
  background: none; border: 0; color: var(--muted);
  font-size: 1.1rem; cursor: pointer; padding: 0 2px; align-self: flex-start;
}
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* Kamera-FAB (sitzt über der Tab-Leiste) */
.fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(74px + env(safe-area-inset-bottom));
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  box-shadow: 0 6px 20px rgba(27, 107, 74, .4);
  cursor: pointer;
}
.fab:active { transform: scale(.96); }

/* Sekundärer Button über dem FAB: manueller Eintrag ohne Foto */
.fab2 {
  position: fixed;
  right: calc(max(20px, env(safe-area-inset-right)) + 6px);
  bottom: calc(146px + env(safe-area-inset-bottom));
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.fab2:active { transform: scale(.96); }

/* Analyse / Entwurf */
.preview {
  width: 100%;
  border-radius: var(--radius);
  display: block;
  max-height: 280px;
  object-fit: cover;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 10px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; color: var(--muted); padding: 24px 0; }

.item-row { border-top: 1px solid var(--line); padding: 12px 0 10px; }
.item-row:first-child { border-top: 0; padding-top: 0; }
.item-head { display: flex; gap: 8px; }
.item-head input { flex: 1; }
.item-head .rm { background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 0 4px; }
.macro-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.macro-grid .mg { text-align: center; }
.macro-grid input { padding: 9px 6px; text-align: center; }
.macro-grid .k { font-size: .7rem; color: var(--muted); margin-top: 3px; }
.macro-grid .rov {
  padding: 9px 6px;
  font-weight: 600;
  background: var(--accent-soft);
  border-radius: var(--radius-s);
  font-variant-numeric: tabular-nums;
}
.conf { font-size: .75rem; color: var(--muted); margin-top: 6px; }
.conf .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot.high { background: #2E9E6B; } .dot.medium { background: #D9A322; } .dot.low { background: #C75C45; }

.row2 { display: flex; gap: 10px; }
.row2 .btn { flex: 1; }

/* Onboarding-Wizard */
.dots { display: flex; gap: 6px; margin: 2px 0 14px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background .2s; }
.dots span.on { background: var(--accent); }

.opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: #fff;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.opt .t { font-weight: 600; }
.opt .s { color: var(--muted); font-size: .85rem; margin-top: 2px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg .opt { text-align: center; margin-top: 0; }

.checkrow { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); }
.checkrow:first-of-type { border-top: 0; }
.checkrow input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
.checkrow label { margin: 0; color: var(--ink); font-size: 1rem; }

/* Untere Tab-Leiste */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, .94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 4px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 5;
}
.tabbar .inner { display: flex; max-width: 480px; margin: 0 auto; }
.tabbar button {
  flex: 1;
  background: none;
  border: 0;
  font: inherit;
  font-size: .85rem;
  color: var(--muted);
  padding: 10px 8px;
  cursor: pointer;
}
.tabbar button.active { color: var(--accent); font-weight: 700; }

/* Fortschrittsringe (Heute) */
.rings { display: grid; gap: 8px; }
.ringtile {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 2px 9px;
  text-align: center;
}
.ring { position: relative; width: 62px; height: 62px; margin: 0 auto; }
.ring svg { width: 100%; height: 100%; display: block; }
.ring .rv {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem;
  font-variant-numeric: tabular-nums;
}
.rk { font-size: .72rem; font-weight: 600; margin-top: 6px; }
.rt { font-size: .64rem; color: var(--muted); margin-top: 1px; min-height: .8em; }

/* Statistik */
.seg3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #EFEFE9;
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}
.seg3 button {
  border: 0; background: none;
  padding: 8px; border-radius: 9px;
  font: inherit; font-size: .85rem; color: var(--muted);
  cursor: pointer;
}
.seg3 button.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.periodnav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 12px 0;
  font-size: .9rem; color: var(--muted);
}
.periodnav .pn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.05rem; color: var(--ink);
  cursor: pointer;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit; font-size: .8rem;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.card svg { width: 100%; height: auto; display: block; }

/* Zweites Foto (Nährwerttabelle) */
.thumbrow {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: .9rem;
}
.thumb {
  width: 76px; height: 76px;
  object-fit: cover;
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
}
