/* Ernährungsberater – Küchenwaage-Look: kühles Salbei-Papier, Basilikum-Grün, Makro-Farben */
@font-face { font-family: 'Bricolage'; src: url('../fonts/bricolage-grotesque-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Bricolage'; src: url('../fonts/bricolage-grotesque-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Bricolage'; src: url('../fonts/bricolage-grotesque-latin-800-normal.woff2') format('woff2'); font-weight: 800; font-display: swap; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Atkinson'; src: url('../fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --ink: #1d2b24;
  --ink-2: #4a5a51;
  --ink-3: #7b8a81;
  --bg: #edf1ec;
  --surface: #ffffff;
  --line: #d6ddd6;
  --basil: #2e5e3e;
  --basil-2: #3f7a53;
  --basil-soft: #dbe8dd;
  --protein: #3c6e9f;
  --carbs: #c98a12;
  --fat: #8c4a86;
  --kcal: #2e5e3e;
  --danger: #b3362c;
  --danger-soft: #f6dfdc;
  --ok: #2e7d4a;
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 64px;
  --font-display: 'Bricolage', 'Avenir Next', system-ui, sans-serif;
  --font-body: 'Atkinson', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e4ebe5; --ink-2: #b3c0b7; --ink-3: #85948a;
    --bg: #121a15; --surface: #1b251f; --line: #2c3a31;
    --basil: #7fbf8f; --basil-2: #96cfa4; --basil-soft: #24382a;
    --protein: #7eaedb; --carbs: #e5b54a; --fat: #c58bbf; --kcal: #7fbf8f;
    --danger: #ef8b80; --danger-soft: #3a2220; --ok: #7fcf96;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--basil); }
:focus-visible { outline: 3px solid var(--protein); outline-offset: 2px; border-radius: 4px; }

/* ---------- Gerüst */
.app { max-width: 600px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 12px) 18px 10px; display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-family: var(--font-display); font-weight: 800; font-size: 1.6rem; letter-spacing: -0.02em; margin: 0; flex: 1; line-height: 1.1; }
.topbar .back { border: 0; background: var(--surface); width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.view { padding: 4px 16px 16px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { max-width: 600px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--nav-h); }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-3); font-size: 0.75rem; position: relative;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--basil); font-weight: 700; }
.tabbar .dot { position: absolute; top: 8px; right: calc(50% - 18px); width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }

/* ---------- Bausteine */
.card { background: var(--surface); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 12px; }
.card.flat { background: transparent; padding: 4px 2px; }
.card h2, .section-title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; margin: 0 0 10px; letter-spacing: -0.01em; }
.section-title { margin: 22px 2px 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.section-title small { font-family: var(--font-body); font-weight: 400; font-size: 0.85rem; color: var(--ink-3); }
.muted { color: var(--ink-3); }
.small { font-size: 0.875rem; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stack > * + * { margin-top: 10px; }
.center { text-align: center; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--basil); color: #fff; font-weight: 700; text-decoration: none; white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .btn { color: #0f1a13; } }
.btn:disabled { opacity: 0.5; cursor: progress; }
.btn.secondary { background: var(--basil-soft); color: var(--basil); }
.btn.ghost { background: transparent; color: var(--basil); padding: 0 10px; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 0.875rem; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--basil-soft); }
.icon-btn svg { width: 20px; height: 20px; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 0.875rem; color: var(--ink-2); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--surface);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--basil); }
input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--basil); }

.seg { display: flex; background: var(--basil-soft); border-radius: 999px; padding: 4px; gap: 4px; margin-bottom: 14px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 12px; border-radius: 999px; cursor: pointer; color: var(--basil); font-weight: 700; white-space: nowrap; font-size: 0.9rem; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: var(--basil-soft); color: var(--basil); font-size: 0.8rem; font-weight: 700; }
.chip.warn { background: var(--danger-soft); color: var(--danger); }
.chip.plain { background: var(--bg); color: var(--ink-2); font-weight: 400; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 700; overflow-wrap: anywhere; }
.list a.rowlink { color: inherit; text-decoration: none; display: flex; gap: 12px; align-items: center; flex: 1; min-width: 0; }

.empty { text-align: center; padding: 28px 16px; color: var(--ink-2); }
.empty p { margin: 0 0 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 100; max-width: 92vw;
  font-size: 0.925rem; box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Bottom-Sheet */
.sheet-back { position: fixed; inset: 0; background: rgb(10 20 14 / 0.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 600px; max-height: 92dvh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  animation: up 0.22s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; margin: 0 0 14px; }
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

/* ---------- Die Waage: Rest-Budget-Anzeige (Signatur-Element) */
.budget { padding: 18px 16px 16px; }
.budget .head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.budget .big { font-family: var(--font-display); font-weight: 800; font-size: 3.4rem; line-height: 0.9; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.budget .big.over { color: var(--danger); }
.budget .unit { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; color: var(--ink-2); }
.budget .sub { color: var(--ink-2); font-size: 0.9rem; text-align: right; }

.scale { margin: 0 0 14px; }
.scale:last-child { margin-bottom: 0; }
.scale .lbl { display: flex; justify-content: space-between; font-size: 0.875rem; margin-bottom: 5px; }
.scale .lbl b { font-weight: 700; }
.scale .lbl .val { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.scale .track { position: relative; height: 14px; border-radius: 7px; background: var(--bg); overflow: visible; }
.scale .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 7px; background: var(--c); transition: width 0.4s ease; }
.scale .band { position: absolute; top: -3px; bottom: -3px; border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); background: repeating-linear-gradient(135deg, transparent 0 3px, color-mix(in srgb, var(--ink) 16%, transparent) 3px 5px); border-radius: 2px; opacity: 0.55; }
.scale .tick { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--ink); }
.scale.ok .lbl .val::after { content: ' ✓'; color: var(--ok); font-weight: 700; }
.scale.over .fill { background: repeating-linear-gradient(135deg, var(--c) 0 6px, color-mix(in srgb, var(--c) 70%, #fff) 6px 9px); }
.scale.compact { margin-bottom: 8px; }
.scale.compact .track { height: 8px; }
.scale.compact .band { top: -2px; bottom: -2px; }

.macro-dots { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.85rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.macro-dots span::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 5px; vertical-align: 1px; }

/* ---------- Mahlzeiten-Tagebuch */
.meal-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 2px 4px; }
.meal-head h3 { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; margin: 0; }
.meal-head .kc { color: var(--ink-3); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.entry .kcal { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }

.fab {
  position: fixed; right: max(16px, calc(50% - 284px)); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 15;
  height: 56px; padding: 0 22px 0 18px; border-radius: 28px; border: 0; background: var(--basil); color: #fff; font-weight: 700;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 8px 22px rgb(30 70 45 / 0.35); cursor: pointer;
}
@media (prefers-color-scheme: dark) { .fab { color: #0f1a13; } }
.fab svg { width: 22px; height: 22px; }

/* ---------- Rezepte */
.recipe-card { display: block; text-decoration: none; color: inherit; }
.recipe-card .name { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; line-height: 1.25; margin: 0 0 6px; }
.recipe-card .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.recipe-hero { padding: 6px 2px 14px; }
.recipe-hero h2 { font-family: var(--font-display); font-weight: 800; font-size: 1.75rem; line-height: 1.1; letter-spacing: -0.02em; margin: 0 0 10px; }
.times { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.times div { background: var(--bg); border-radius: var(--radius); padding: 8px 10px; }
.times b { display: block; font-family: var(--font-display); font-size: 1.15rem; white-space: nowrap; }
.recipe-hero .chip.plain { background: var(--surface); }
.times span { font-size: 0.8rem; color: var(--ink-2); }
.ing-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ing-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ing-table td.g { text-align: right; font-weight: 700; white-space: nowrap; width: 1%; padding-right: 12px; }
.ing-table td.k { text-align: right; color: var(--ink-3); font-size: 0.85rem; white-space: nowrap; width: 1%; }
.steps { padding-left: 1.3em; margin: 0; }
.steps li { margin-bottom: 8px; padding-left: 4px; }
.nut-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.925rem; }
.nut-table th, .nut-table td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.nut-table th:first-child, .nut-table td:first-child { text-align: left; }
.nut-table th { font-weight: 700; color: var(--ink-2); font-size: 0.8rem; }
.nut-table td { white-space: nowrap; }
.nut-table td:first-child { white-space: normal; }
.nut-table td.bad { color: var(--danger); font-weight: 700; }
.nut-table td.good { color: var(--ok); }

/* ---------- Wochenplan */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.week-nav b { font-family: var(--font-display); font-size: 1.05rem; }
.day { background: var(--surface); border-radius: var(--radius-lg); padding: 12px 14px; margin-bottom: 10px; }
.day.today { box-shadow: inset 0 0 0 2px var(--basil); }
.day header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.day header h3 { font-family: var(--font-display); font-weight: 700; margin: 0; font-size: 1.05rem; }
.slot-row { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-top: 1px dashed var(--line); }
.slot-row:first-of-type { border-top: 0; }
.slot-row .slot { width: 82px; flex-shrink: 0; color: var(--ink-3); font-size: 0.85rem; padding-top: 3px; }
.slot-row .items { flex: 1; min-width: 0; }
.plan-item { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.plan-item a { color: inherit; font-weight: 700; text-decoration: none; overflow-wrap: anywhere; }
.plan-item .who { font-size: 0.78rem; color: var(--ink-3); }
.add-slot { border: 1.5px dashed var(--line); background: transparent; border-radius: var(--radius-sm); color: var(--ink-3); padding: 3px 10px; cursor: pointer; font-size: 0.85rem; }

/* ---------- Einkauf */
.shop li.checked .title { text-decoration: line-through; color: var(--ink-3); font-weight: 400; }
.shop .amt { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Verlauf */
.week-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.week-table th, .week-table td { padding: 8px 3px; text-align: right; border-bottom: 1px solid var(--line); }
.week-table th:first-child, .week-table td:first-child { text-align: left; }
.week-table th { color: var(--ink-2); font-size: 0.78rem; font-weight: 700; }
.week-table tfoot td { font-weight: 700; border-bottom: 0; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-family: var(--font-display); font-weight: 800; font-size: 1.45rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.8rem; color: var(--ink-2); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal div { aspect-ratio: 1; border-radius: 8px; background: var(--bg); display: grid; place-items: center; font-size: 0.8rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.cal .ok { background: var(--basil); color: #fff; font-weight: 700; }
.cal .off { background: color-mix(in srgb, var(--carbs) 35%, var(--surface)); color: var(--ink); }
.cal .pad { background: transparent; }
@media (prefers-color-scheme: dark) { .cal .ok { color: #0f1a13; } }
.prose { line-height: 1.6; }
.prose p { margin: 0 0 10px; }
.prose ul { padding-left: 1.2em; margin: 0 0 10px; }

/* ---------- Tickets & Claude-Chat */
.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; background: var(--surface); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .by { font-size: 0.75rem; color: var(--ink-3); margin-bottom: 2px; white-space: normal; }
.msg.mine { align-self: flex-end; background: var(--basil-soft); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.internal { align-self: stretch; max-width: none; background: transparent; border: 1.5px dashed var(--carbs); }
.ai-panel { background: var(--ink); color: var(--bg); border-radius: var(--radius-lg); padding: 14px; margin-top: 14px; }
.ai-panel h2 { color: var(--bg); display: flex; align-items: center; gap: 8px; }
.ai-panel .msg { background: color-mix(in srgb, var(--bg) 10%, var(--ink)); color: var(--bg); }
.ai-panel .msg.mine { background: color-mix(in srgb, var(--bg) 22%, var(--ink)); }
.ai-panel .msg .by { color: color-mix(in srgb, var(--bg) 60%, var(--ink)); }
.ai-panel textarea { background: color-mix(in srgb, var(--bg) 8%, var(--ink)); border-color: color-mix(in srgb, var(--bg) 25%, var(--ink)); color: var(--bg); min-height: 70px; }
.ai-panel .btn.secondary { background: color-mix(in srgb, var(--bg) 18%, var(--ink)); color: var(--bg); }
.draft { background: var(--surface); color: var(--ink); border-radius: var(--radius); padding: 10px 12px; margin-top: 8px; white-space: pre-wrap; }
.draft .row { margin-top: 8px; }
.status { font-size: 0.75rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--bg); color: var(--ink-2); white-space: nowrap; }
.status.offen { background: var(--danger-soft); color: var(--danger); }
.status.in_bearbeitung { background: color-mix(in srgb, var(--protein) 18%, var(--surface)); color: var(--protein); }
.status.wartet { background: color-mix(in srgb, var(--carbs) 22%, var(--surface)); color: var(--ink); }
.unread-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }

/* ---------- Login */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.auth .brand { font-family: var(--font-display); font-weight: 800; font-size: 2.6rem; line-height: 0.95; letter-spacing: -0.035em; margin: 0 0 8px; }
.auth .brand span { display: block; color: var(--basil); }
.auth p.lead { color: var(--ink-2); margin: 0 0 26px; }

.spinner { width: 22px; height: 22px; border: 3px solid var(--basil-soft); border-top-color: var(--basil); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 30px; color: var(--ink-2); }

.scanner video { width: 100%; border-radius: var(--radius); background: #000; aspect-ratio: 4/3; object-fit: cover; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; background: var(--bg); padding: 8px 10px; border-radius: var(--radius-sm); overflow-wrap: anywhere; }
