/* nfcaltrack – Farben als Variablen, Hell/Dunkel wie nflist/nftravel:
   System-Voreinstellung, data-theme am <html> überschreibt.
   Je Makro eine Farbe, überall in der App gleich (KONZEPT §5.6). */
:root {
  --bg: #f6f7f9;
  --flaeche: #ffffff;
  --flaeche-2: #eef0f3;
  --text: #16181d;
  --leise: #5d636e;
  --rand: #e1e4e9;
  --akzent: #16a34a;
  --akzent-text: #ffffff;
  --warn: #ea580c;
  --gefahr: #dc2626;
  --protein: #2563eb;
  --carbs: #d97706;
  --fat: #db2777;
  --ring-grund: #e5e7eb;
  --schatten: 0 1px 2px rgb(0 0 0 / .05), 0 6px 20px rgb(0 0 0 / .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d; --flaeche: #1e2128; --flaeche-2: #262a32; --text: #e9eaee; --leise: #9aa1ad;
    --rand: #2d313a; --akzent: #22c55e; --akzent-text: #0b1a10; --warn: #fb923c; --gefahr: #f87171;
    --protein: #60a5fa; --carbs: #fbbf24; --fat: #f472b6; --ring-grund: #2d313a;
    --schatten: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181d; --flaeche: #1e2128; --flaeche-2: #262a32; --text: #e9eaee; --leise: #9aa1ad;
  --rand: #2d313a; --akzent: #22c55e; --akzent-text: #0b1a10; --warn: #fb923c; --gefahr: #f87171;
  --protein: #60a5fa; --carbs: #fbbf24; --fat: #f472b6; --ring-grund: #2d313a;
  --schatten: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* iOS-Home-Screen-App mit black-translucent: ist die Seite kürzer als der
   Bildschirm, rechnet Safari die Höhe ohne Statusleiste und die feste
   Tab-Leiste rutscht um diesen Betrag nach oben. Mindesthöhe inkl. Statusleiste
   behebt das. */
html { -webkit-text-size-adjust: 100%; min-height: calc(100% + env(safe-area-inset-top)); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--akzent); }
h2 { font-size: 1.25rem; margin: .2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

/* --- Kopf --- */
.kopf {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .5rem;
  padding: calc(.45rem + env(safe-area-inset-top)) .75rem .45rem;
  background: var(--flaeche); border-bottom: 1px solid var(--rand);
}
.marke { display: flex; align-items: center; gap: .45rem; font-weight: 650; color: var(--text); text-decoration: none; }
.punkt { width: .7rem; height: .7rem; border-radius: 50%; background: var(--akzent); }
.offline-badge { margin-left: auto; font-size: .75rem; background: var(--warn); color: #fff; padding: .1rem .45rem; border-radius: 1rem; }

.inhalt { max-width: 40rem; margin: 0 auto; padding: .75rem 1rem 6rem; }

/* --- Tab-Leiste unten (wie eine App) --- */
:root { --tabs-h: 3.6rem; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--flaeche); border-top: 1px solid var(--rand);
}
.tabs a {
  flex: 1; max-width: 10rem; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
  color: var(--leise); text-decoration: none; font-size: .72rem;
  -webkit-tap-highlight-color: transparent;
}
.tabs svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.aktiv { color: var(--akzent); font-weight: 600; }
/* Mit Tab-Leiste: Inhalt, „+“ und Meldungen darüber. */
body:has(.tabs:not([hidden])) { padding-bottom: 0; }
body:has(.tabs:not([hidden])) .inhalt { padding-bottom: calc(var(--tabs-h) + 6rem + env(safe-area-inset-bottom)); }
body:has(.tabs:not([hidden])) .fab { bottom: calc(var(--tabs-h) + 1rem + env(safe-area-inset-bottom)); }
body:has(.tabs:not([hidden])) .toast { bottom: calc(var(--tabs-h) + 5.5rem + env(safe-area-inset-bottom)); }

/* --- Karten und Formulare --- */
.karte {
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: 1rem;
  padding: 1rem; margin: 0 0 .9rem; box-shadow: var(--schatten);
}
.karte.schmal { max-width: 26rem; margin: 2rem auto; }
.karte.deaktiviert { opacity: .7; }
details.karte > summary { cursor: pointer; list-style: none; }
details.karte > summary::-webkit-details-marker { display: none; }
details.karte > summary h3 { display: inline; }
details.karte > summary::after { content: '+'; float: right; color: var(--leise); font-size: 1.2rem; line-height: 1; }
details.karte[open] > summary::after { content: '−'; }
details.karte[open] > summary { margin-bottom: .6rem; }

.formular { display: flex; flex-direction: column; gap: .7rem; }
.feld { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--leise); }
.feld > span:first-child { font-weight: 550; }
.raster2, .raster3 { display: grid; gap: .6rem; grid-template-columns: 1fr 1fr; }
.raster3 { grid-template-columns: 1fr 1fr 1fr; }

input, select, textarea, button, .knopf {
  font: inherit; color: var(--text); border-radius: .65rem;
}
input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--rand); background: var(--bg);
  font-size: 16px; /* iOS zoomt sonst beim Fokus */
}
textarea { resize: vertical; min-height: 5rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--akzent); outline-offset: -1px; }
button, .knopf {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .55rem .9rem; border: 1px solid var(--rand); background: var(--flaeche-2);
  cursor: pointer; text-decoration: none; font-size: .95rem; min-height: 2.5rem;
}
button:disabled { opacity: .5; cursor: default; }
button.primaer, .knopf.primaer { background: var(--akzent); color: var(--akzent-text); border-color: transparent; font-weight: 600; }
button.gefahr { color: var(--gefahr); }
button.leicht { background: transparent; }
button.breit { width: 100%; }
.knopfreihe { display: flex; flex-wrap: wrap; gap: .5rem; }
.knopfreihe.klein button { padding: .3rem .55rem; min-height: 2rem; font-size: .85rem; }
.chip { padding: .3rem .7rem; min-height: 2rem; border-radius: 1rem; font-size: .85rem; }
.schritte { display: flex; flex-wrap: wrap; gap: .4rem; }
.haken { display: flex; gap: .6rem; align-items: flex-start; font-size: .9rem; }
.haken input { margin-top: .25rem; width: 1.1rem; height: 1.1rem; flex: none; }
.zeile-form { display: flex; gap: .5rem; }
.zeile-form input { flex: 1; }
.link-feld { font-family: ui-monospace, monospace; font-size: .8rem !important; }

/* Segmentierte Auswahl (Slots, Darstellung) */
.segment { display: flex; background: var(--flaeche-2); border-radius: .7rem; padding: .2rem; gap: .2rem; }
.segment label { flex: 1; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span {
  display: block; text-align: center; padding: .4rem .2rem; border-radius: .5rem; cursor: pointer;
  font-size: .85rem; color: var(--leise);
}
.segment input:checked + span { background: var(--flaeche); color: var(--text); font-weight: 600; box-shadow: var(--schatten); }
.segment input:focus-visible + span { outline: 2px solid var(--akzent); }

.leise { color: var(--leise); }
.klein { font-size: .82rem; }
.mitte { text-align: center; }
.fehlertext { color: var(--gefahr); margin: 0; }
.hinweis { background: var(--flaeche-2); border-left: 3px solid var(--warn); padding: .5rem .7rem; border-radius: .4rem; font-size: .9rem; }
.leer-hinweis { padding: 1rem 0; }
.unsichtbar { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }

.seitenkopf { display: flex; flex-direction: column; gap: .1rem; margin-bottom: .6rem; }
.zurueck { font-size: .9rem; text-decoration: none; }

/* --- Startseite --- */
.datumsleiste { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .7rem; }
.datumsleiste .datum { flex: 1; background: transparent; border: none; font-weight: 650; font-size: 1.05rem; position: relative; }
.rund { width: 2.5rem; height: 2.5rem; border-radius: 50%; padding: 0; font-size: 1.4rem; line-height: 1; }

.uebersicht { display: grid; grid-template-columns: minmax(9rem, 11rem) 1fr; gap: 1rem; align-items: center; touch-action: pan-y; }
@media (max-width: 26rem) { .uebersicht { grid-template-columns: 1fr; justify-items: center; } .makros { width: 100%; } }
.ring { position: relative; width: 100%; max-width: 11rem; aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; }
.ring circle { fill: none; stroke-width: 11; stroke-linecap: round; }
.ring .ring-grund { stroke: var(--ring-grund); }
.ring .ring-bogen { stroke: var(--akzent); transition: stroke-dasharray .4s ease; }
.ring .ring-ueber { stroke: var(--warn); }
.ring.ueber .ring-bogen { stroke: color-mix(in srgb, var(--akzent) 55%, var(--warn)); }
.ring-text {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; line-height: 1.15;
}
.ring-text strong { font-size: 1.9rem; font-variant-numeric: tabular-nums; }
.ring.ueber .ring-text strong { color: var(--warn); }

.makros { display: flex; flex-direction: column; gap: .7rem; }
.makro-kopf { display: flex; gap: .4rem; align-items: baseline; font-size: .85rem; }
.makro-name { font-weight: 600; }
.makro-zahl { color: var(--leise); font-variant-numeric: tabular-nums; }
.makro-rest { margin-left: auto; color: var(--leise); }
.makro-rest.ueber { color: var(--warn); }
.balken { height: .55rem; background: var(--ring-grund); border-radius: 1rem; overflow: hidden; margin-top: .2rem; }
.balken-fuell { height: 100%; border-radius: 1rem; transition: width .4s ease; }
.makro-protein .balken-fuell, .mini-protein { background: var(--protein); }
.makro-carbs .balken-fuell, .mini-carbs { background: var(--carbs); }
.makro-fat .balken-fuell, .mini-fat { background: var(--fat); }

.slot { margin-bottom: .9rem; }
.slot-kopf { display: flex; justify-content: space-between; align-items: baseline; padding: 0 .2rem .3rem; }
.slot-kopf h3 { margin: 0; font-size: .95rem; }

.liste { list-style: none; margin: 0; padding: 0; }
.slot .liste, .treffer { background: var(--flaeche); border: 1px solid var(--rand); border-radius: .9rem; overflow: hidden; }
.treffer:empty { display: none; }
.treffer { margin-top: .6rem; }
.zeile { position: relative; border-bottom: 1px solid var(--rand); overflow: hidden; }
.zeile:last-child { border-bottom: none; }
.karte .liste .zeile { padding: .1rem 0; }
.zeile-inhalt {
  position: relative; display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem;
  background: var(--flaeche); transition: transform .15s ease; touch-action: pan-y;
}
.karte > .liste .zeile-inhalt { padding-left: 0; padding-right: 0; }
.zeile-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.zeile-titel { overflow: hidden; text-overflow: ellipsis; }
.zeile-kcal { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.zeile-kcal::after { content: ' kcal'; font-weight: 400; color: var(--leise); font-size: .8rem; }
.klickbar, .wischbar .zeile-inhalt { cursor: pointer; }
.zeile-loeschen {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: flex-end;
  padding-right: 1rem; background: var(--gefahr); color: #fff; font-weight: 600;
}
.zeile.wischt .zeile-loeschen, .zeile.weg .zeile-loeschen { display: flex; }
.zeile.weg { opacity: .3; }

.woche { display: grid; grid-template-columns: repeat(7, 1fr); gap: .35rem; padding: .7rem; }
.woche-tag { flex-direction: column; background: transparent; border: none; padding: .2rem 0; min-height: 0; gap: .2rem; border-radius: .5rem; }
.woche-tag.aktiv { background: var(--flaeche-2); }
.woche-saeule { position: relative; width: 60%; height: 4rem; background: var(--ring-grund); border-radius: .3rem; overflow: hidden; }
.woche-fuell { position: absolute; bottom: 0; left: 0; right: 0; background: var(--akzent); }
.woche-fuell.ueber { background: var(--warn); }
.woche-ziel { position: absolute; left: -10%; right: -10%; height: 2px; background: var(--text); opacity: .5; }

.mini { display: flex; height: .35rem; border-radius: 1rem; overflow: hidden; background: var(--ring-grund); width: 100%; }

.fab {
  position: fixed; right: max(1.2rem, calc(50vw - 19rem)); bottom: calc(1.2rem + env(safe-area-inset-bottom));
  width: 3.6rem; height: 3.6rem; border-radius: 50%; font-size: 2rem; line-height: 1;
  background: var(--akzent); color: var(--akzent-text); border: none; box-shadow: 0 6px 20px rgb(0 0 0 / .25);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; z-index: 5;
}

/* --- Ziel-Regler --- */
.regler-kopf { display: flex; justify-content: space-between; }
.regler-wert { font-weight: 400; font-variant-numeric: tabular-nums; }
.regler { width: 100%; }
.regler-protein { accent-color: var(--protein); }
.regler-carbs { accent-color: var(--carbs); }
.regler-fat { accent-color: var(--fat); }

/* --- Dialog --- */
.dlg {
  border: 1px solid var(--rand); border-radius: 1rem; padding: 0; background: var(--flaeche); color: var(--text);
  width: min(30rem, calc(100vw - 1.5rem)); max-height: calc(100dvh - 2rem);
}
.dlg::backdrop { background: rgb(0 0 0 / .45); }
.dlg form { display: flex; flex-direction: column; max-height: calc(100dvh - 2rem); }
.dlg h3 { padding: 1rem 1rem 0; margin: 0 0 .6rem; }
.dlg-rumpf { padding: 0 1rem; overflow: auto; }
.dlg menu { display: flex; gap: .5rem; justify-content: flex-end; padding: .8rem 1rem; margin: 0; flex-wrap: wrap; }
.dlg menu .gefahr { margin-right: auto; }
.vorschau { font-variant-numeric: tabular-nums; margin: 0; }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom)); transform: translate(-50%, 1rem);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: .8rem; opacity: 0;
  transition: opacity .2s, transform .2s; z-index: 50; display: flex; gap: .8rem; align-items: center;
  max-width: calc(100vw - 2rem); margin: 0;
}
.toast.zeigen { opacity: 1; transform: translate(-50%, 0); }
.toast.fehler { background: var(--gefahr); color: #fff; }
.toast-aktion { background: transparent; color: inherit; border: 1px solid currentColor; min-height: 0; padding: .2rem .6rem; }

/* --- Prüfansicht (KI-Vorschlag, Mahlzeit bearbeiten) --- */
.pruefung { display: flex; flex-direction: column; gap: .7rem; margin-top: .8rem; }
.pruef-liste { display: flex; flex-direction: column; gap: .5rem; }
.pruef-zeile { border: 1px solid var(--rand); border-radius: .8rem; padding: .55rem .7rem; background: var(--bg); display: flex; flex-direction: column; gap: .25rem; }
.pruef-zeile.ungenau { border-style: dashed; }
.pruef-kopf { display: flex; align-items: center; gap: .4rem; }
.pruef-name {
  flex: 1; justify-content: flex-start; text-align: left; background: transparent; border: none; padding: 0; min-height: 0;
  font-weight: 600; gap: .4rem;
}
.stift { color: var(--leise); font-weight: 400; font-size: .85rem; }
.klein-knopf { min-height: 0; padding: .2rem .5rem; border: none; color: var(--leise); }
.pruef-werte { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.gramm-feld { display: flex; align-items: center; gap: .3rem; }
.gramm-feld input.gramm { width: 5.5rem !important; padding: .35rem .5rem !important; text-align: right; }
.pruef-kcal { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.mini-segment span { padding: .2rem .55rem; font-size: .8rem; }
.annahme { color: var(--leise); font-style: italic; }
.quelle { display: inline-block; padding: 0 .4rem; border-radius: .4rem; font-size: .75rem; margin-right: .3rem; }
.quelle-bls { background: color-mix(in srgb, var(--akzent) 18%, transparent); color: var(--text); }
.quelle-ki { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--text); }
.quelle-eigen { background: color-mix(in srgb, var(--protein) 18%, transparent); color: var(--text); }
.pruef-summe { display: flex; flex-direction: column; gap: .1rem; padding: .5rem .2rem; border-top: 1px solid var(--rand); }
.pruef-aktionen { display: flex; flex-direction: column; gap: .6rem; background: var(--flaeche-2); border-radius: .8rem; padding: .8rem; }
.einrueckung { padding-left: 1.7rem; }
.transkript { background: var(--flaeche-2); padding: .5rem .7rem; border-radius: .6rem; margin: 0; }
.eigen summary { cursor: pointer; color: var(--akzent); font-size: .9rem; margin: .4rem 0; }
.ki-karte textarea { font-size: 1.05rem; }

/* --- Mahlzeiten --- */
.seitenkopf.zeilig { flex-direction: row; justify-content: space-between; align-items: center; }
.mahlzeiten { display: flex; flex-direction: column; margin-top: .7rem; }
.mahlzeit-karte { display: flex; flex-direction: column; gap: .5rem; padding: .8rem 1rem; }
.mahlzeit-link { color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: .35rem; }
.mahlzeit-kopf { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.mahlzeit-kopf h3 { margin: 0; }
.mahlzeit-karte p { margin: 0; }
.stern { color: var(--carbs); }
.essen-knopf { align-self: flex-start; min-height: 2.1rem; padding: .3rem .8rem; font-size: .88rem; }
.haken.mittig { align-items: center; padding-top: 1.4rem; }

/* --- Mikrofon --- */
.mikro-box { display: flex; flex-direction: column; gap: .2rem; }
.mikro.aktiv { background: var(--gefahr); color: #fff; border-color: transparent; animation: puls 1.2s infinite; }
.mikro-zeit { font-variant-numeric: tabular-nums; font-size: .8rem; }
@keyframes puls { 50% { box-shadow: 0 0 0 .4rem color-mix(in srgb, var(--gefahr) 30%, transparent); } }

/* --- Mela-Import --- */
.rezept-zeile { cursor: pointer; }
.rezept-zeile input[type=checkbox] { width: 1.1rem; height: 1.1rem; flex: none; }
.rezept-bild { width: 2.6rem; height: 2.6rem; object-fit: cover; border-radius: .4rem; flex: none; }

/* KI-Essensvorschlag (Startseite) */
.fortschritt { display: flex; flex-direction: column; gap: .4rem; margin: .8rem 0; }
.fortschritt-kopf { display: flex; align-items: center; gap: .5rem; }
.fortschritt-balken { height: .4rem; background: var(--ring-grund); border-radius: 1rem; overflow: hidden; }
.fortschritt-fuell { height: 100%; width: 0; background: var(--akzent); border-radius: 1rem; transition: width .25s linear; }
.kreisel {
  width: 1rem; height: 1rem; flex: none; border-radius: 50%;
  border: 2px solid var(--ring-grund); border-top-color: var(--akzent); animation: drehen .8s linear infinite;
}
@keyframes drehen { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .kreisel { animation-duration: 2.4s; } }

/* Vorschlag als runder Knopf links unten, gelb mit Stern und Fragezeichen. */
.fab.fab-vorschlag {
  right: auto; left: max(1.2rem, calc(50vw - 19rem));
  background: #facc15; color: #422006; padding: 0;
}
.fab-vorschlag svg { width: 2.4rem; height: 2.4rem; }
/* Stern gefüllt, Fragezeichen gelb ausgespart – feste Farben, damit es in
   Hell und Dunkel gleich kräftig ist (die Theme-Variablen greifen hier nicht). */
.fab.fab-vorschlag .stern { fill: #422006; stroke: #422006; stroke-width: 1; stroke-linejoin: round; }
.fab.fab-vorschlag .stern-frage { fill: #facc15; font: 800 9px system-ui, -apple-system, sans-serif; }

/* „+“-Knopf: Symbol als SVG, genau mittig. */
.fab { padding: 0; }
.fab-plus svg { width: 1.7rem; height: 1.7rem; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
