/* Ernaehrungshelfer — mobile first.
   Farb-Tokens nach der validierten Referenz-Palette (light/dark je eigene
   Stufen, kein automatisches Umdrehen). */

:root {
  color-scheme: light;
  --flaeche:      #fcfcfb;   /* Karten */
  --seite:        #f9f9f7;   /* Seitenhintergrund */
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-3:        #898781;   /* Achsen, Labels */
  --gitter:       #e1e0d9;
  --linie:        #c3c2b7;
  --rand:         rgba(11, 11, 11, .10);
  --serie-1:      #2a78d6;
  --gut:          #0ca30c;
  --warnung:      #fab219;
  --kritisch:     #d03b3b;
  --gut-text:     #006300;
  --warnung-text: #9a6400;   /* dunkleres Amber, auf Hell lesbar */
  --radius:       14px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --flaeche:  #1a1a19;
    --seite:    #0d0d0d;
    --ink:      #ffffff;
    --ink-2:    #c3c2b7;
    --ink-3:    #898781;
    --gitter:   #2c2c2a;
    --linie:    #383835;
    --rand:     rgba(255, 255, 255, .10);
    --serie-1:  #3987e5;
    --gut-text: #0ca30c;
    --warnung-text: #fab219;   /* auf Dunkel ist das helle Amber gut lesbar */
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 0 76px;                /* Platz fuer die Navleiste */
  background: var(--seite);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--flaeche);
  border-bottom: 1px solid var(--rand);
  position: sticky;
  top: 0;
  z-index: 20;
}
.marke {
  font-weight: 650;
  font-size: 15px;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -.01em;
}

.inhalt { padding: 14px 16px 24px; max-width: 720px; margin: 0 auto; }

/* --- Navleiste unten --------------------------------------------------- */
.navleiste {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  /* minmax(0,1fr) statt 1fr: sonst darf keine Spalte unter ihre
     Inhaltsbreite schrumpfen und die Leiste laeuft rechts aus dem Bild. */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--flaeche);
  border-top: 1px solid var(--rand);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.navleiste a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 4px 8px;
  font-size: 11px;
  color: var(--ink-3);
  text-decoration: none;
}
.navleiste a.aktiv { color: var(--serie-1); font-weight: 600; }
.navleiste .ikon { font-size: 19px; line-height: 1; }

/* --- Karten ------------------------------------------------------------ */
.karte {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.karte h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* --- Hero-Zahl (kcal uebrig) ------------------------------------------- */
.hero { text-align: center; padding: 20px 14px 16px; }
.hero .zahl {
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.03em;
}
.hero .einheit { font-size: 20px; font-weight: 500; color: var(--ink-2); }
.hero .unterzeile { margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.hero.warnung .zahl { color: var(--warnung); }
.hero.kritisch .zahl { color: var(--kritisch); }

.fortschritt {
  height: 8px;
  border-radius: 999px;
  background: var(--gitter);
  overflow: hidden;
  margin: 14px 0 0;
}
.fortschritt > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--serie-1);
}
.fortschritt.warnung > i { background: var(--warnung); }
.fortschritt.kritisch > i { background: var(--kritisch); }

.hero-schnitt { margin-top: 10px; font-size: 13px; color: var(--ink-3); }
.hero-schnitt b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.hero-schnitt-info { margin-left: 3px; }

/* --- Streak-Badge ------------------------------------------------------ */
.streak {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin: -2px 0 12px;
  padding: 9px 12px;
  border: 1px solid var(--rand);
  border-radius: 999px;
  background: var(--flaeche);
  font-size: 14px;
}
.streak .flamme { font-size: 17px; line-height: 1; }
.streak b { font-variant-numeric: tabular-nums; }
.streak-meldung {
  text-align: center;
  font-size: 13px;
  color: var(--gut-text);
  margin: -6px 0 12px;
}

/* --- Wochenrueckblick --------------------------------------------------- */
.woche-zeile {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--ink-2);
}
.woche-zeile b { color: var(--ink); font-variant-numeric: tabular-nums; }
.woche-zeile .runter { color: var(--gut-text); }
.woche-zeile .rauf { color: var(--kritisch); }

/* --- Makro-Balken ------------------------------------------------------ */
.makros { display: grid; gap: 10px; }
.makro .zeile {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 4px;
}
.makro .zeile b { color: var(--ink); font-weight: 600; }
.makro .zeile b.kritisch { color: var(--kritisch); }
.makro .zeile b.warnung { color: var(--warnung-text); }
.makro .zeile b.gut { color: var(--gut-text); }
.makro .bar { height: 6px; border-radius: 999px; background: var(--gitter); overflow: hidden; }
.makro .bar > i { display: block; height: 100%; border-radius: 999px; background: var(--serie-1); }
.makro .bar > i.kritisch { background: var(--kritisch); }
.makro .bar > i.warnung { background: var(--warnung); }
.makro .bar > i.gut { background: var(--gut); }
.makro-sub {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--ink-3);
}
.makro-sub .kritisch { color: var(--kritisch); }
.makro-sub .warnung { color: var(--warnung-text); }
.makro-sub .gut { color: var(--gut-text); }
.makro-schnitt { color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* --- Mahlzeiten -------------------------------------------------------- */
.mahlzeit + .mahlzeit { margin-top: 12px; }
.mahlzeit .titel {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 8px;
}
.mahlzeit .titel h3 { margin: 0; font-size: 15px; font-weight: 600; }
.mahlzeit .titel .kcal { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mahlzeit-schnitt {
  display: block;
  font-size: 11px;
  color: var(--ink-3);
  text-align: right;
}

/* --- Flüssigkeit ------------------------------------------------------- */
.wasser .titel {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 8px;
}
.wasser .titel h2 { margin: 0; }
.wasser-wert { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.wasser-wert b { color: var(--ink); }
.wasser .bar { height: 6px; border-radius: 999px; background: var(--gitter); overflow: hidden; margin-bottom: 12px; }
.wasser .bar > i { display: block; height: 100%; border-radius: 999px; background: var(--serie-1); }
.wasser-schnitt { display: block; margin: -4px 0 10px; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.wasser-chips .chip { padding: 8px 12px; font-size: 13px; }
.wasser-chips .chip.minus { color: var(--ink-3); }

/* Checkbox-Zeile (z.B. "Zählt als Flüssigkeit") */
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 14px;
  font-size: 14px;
  color: var(--ink-2);
  cursor: pointer;
}
.check input { width: 20px; height: 20px; flex: 0 0 auto; }

.eintrag {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--gitter);
}
.eintrag:first-of-type { border-top: 0; }
.eintrag .txt { flex: 1; min-width: 0; }
.eintrag .name {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.eintrag .menge {
  display: inline-flex; align-items: center;
  min-height: 34px; margin: -8px 0;   /* Touch-Ziel, Zeilenhoehe bleibt kompakt */
  border: 0; background: none; padding: 0;
  font: inherit; font-size: 12px; color: var(--ink-3);
  cursor: pointer; text-align: left;
}
.eintrag .menge:hover, .eintrag .menge:active { color: var(--ink-2); }
.eintrag .wert { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--ink-2); }
.eintrag .weg {
  border: 0; background: none; cursor: pointer;
  color: var(--ink-3); font-size: 20px; line-height: 1;
  padding: 6px 4px; min-width: 34px;   /* Touch-Ziel */
}

.leer { color: var(--ink-3); font-size: 14px; padding: 6px 0; }

/* --- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
  padding: 11px 16px;
  border-radius: 11px;
  border: 1px solid var(--rand);
  background: var(--flaeche);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
}
.btn.voll { width: 100%; }
.btn.primaer { background: var(--serie-1); border-color: var(--serie-1); color: #fff; }
.btn.klein { min-height: 38px; padding: 7px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btn-reihe { display: flex; gap: 8px; flex-wrap: wrap; }
/* min-width:0 — ohne das schrumpfen Flex-Kinder nie unter ihren Text und
   lange Beschriftungen schieben die ganze Seite ueber den Rand. */
.btn-reihe > * { flex: 1 1 0; min-width: 0; }

/* --- Formulare --------------------------------------------------------- */
label { display: block; font-size: 13px; color: var(--ink-2); margin: 0 0 5px; }
input, select {
  width: 100%;
  /* Datums- und Zahlenfelder bringen in manchen Browsern eine eigene
     Mindestbreite mit — die sprengt sonst das Zwei-Spalten-Raster. */
  min-width: 0;
  max-width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--seite);
  border: 1px solid var(--linie);
  border-radius: 10px;
}
input:focus, select:focus { outline: 2px solid var(--serie-1); outline-offset: 1px; }
.feld { margin-bottom: 12px; }
.feld-reihe { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hinweis { font-size: 12.5px; color: var(--ink-3); margin-top: 5px; }

/* --- Datums-Kopf ------------------------------------------------------- */
.datumszeile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.datumszeile a {
  color: var(--ink-2); text-decoration: none;
  padding: 8px 12px; border-radius: 9px;
  border: 1px solid var(--rand); background: var(--flaeche);
}
.datumszeile .d { font-weight: 600; }

/* --- Trefferliste ------------------------------------------------------ */
.treffer { list-style: none; margin: 0; padding: 0; }
.treffer li { border-top: 1px solid var(--gitter); }
.treffer li:first-child { border-top: 0; }
.treffer button {
  width: 100%;
  display: block;
  text-align: left;
  background: none; border: 0;
  padding: 11px 2px;
  font: inherit; color: var(--ink);
  cursor: pointer;
}
.treffer .name { font-size: 15px; }
.treffer .meta { font-size: 12.5px; color: var(--ink-3); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--rand);
  background: var(--seite);
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit; font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  min-height: 40px;
  max-width: 100%;
  text-align: left;
  overflow-wrap: anywhere;
}
.chip .k { color: var(--ink-3); font-size: 12.5px; }

/* --- Tabs -------------------------------------------------------------- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs button {
  flex: 0 0 auto;
  border: 1px solid var(--rand);
  background: var(--flaeche);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit; font-size: 14px;
  cursor: pointer;
  min-height: 38px;
}
.tabs button.aktiv { background: var(--serie-1); border-color: var(--serie-1); color: #fff; font-weight: 600; }

/* --- Dialog ------------------------------------------------------------ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.blatt {
  background: var(--flaeche);
  width: 100%; max-width: 520px;
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
}
.blatt h3 { margin: 0 0 4px; font-size: 17px; }
.blatt .sub { color: var(--ink-3); font-size: 13px; margin: 0 0 14px; }

/* --- Diagramm ---------------------------------------------------------- */
.diagramm { width: 100%; display: block; touch-action: pan-y; }
.diagramm .gitterlinie { stroke: var(--gitter); stroke-width: 1; }
.diagramm .achse       { stroke: var(--linie); stroke-width: 1; }
.diagramm .tick        { fill: var(--ink-3); font-size: 11px; }
.diagramm .roh         { fill: var(--ink-3); opacity: .45; }
.diagramm .trend       { fill: none; stroke: var(--serie-1); stroke-width: 2;
                         stroke-linecap: round; stroke-linejoin: round; }
.diagramm .zielband    { stroke: var(--gut); stroke-width: 1.5; stroke-dasharray: 5 4; }
.diagramm .zielbeschriftung { fill: var(--gut-text); font-size: 11px; font-weight: 600; }
.diagramm .fadenkreuz  { stroke: var(--linie); stroke-width: 1; }
.diagramm .marker      { fill: var(--serie-1); stroke: var(--flaeche); stroke-width: 2; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .13);
  white-space: nowrap;
  z-index: 10;
}
.tooltip[hidden] { display: none; }
.tooltip .t-d { color: var(--ink-3); }
.tooltip b { font-variant-numeric: tabular-nums; }

.diagramm-huelle { position: relative; }

/* --- Statistik-Kacheln ------------------------------------------------- */
.kacheln { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.kachel { text-align: center; }
.kachel .k-wert { font-size: 21px; font-weight: 650; letter-spacing: -.02em; }
.kachel .k-titel { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.kachel .runter { color: var(--gut-text); }
.kachel .rauf   { color: var(--kritisch); }

/* --- Tabelle ----------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; table-layout: auto; }
th, td {
  text-align: left; padding: 8px 4px;
  border-bottom: 1px solid var(--gitter);
  overflow-wrap: anywhere;          /* lange Produktnamen umbrechen lassen */
}
th { font-size: 12px; color: var(--ink-3); font-weight: 600; }
td.z, th.z { text-align: right; font-variant-numeric: tabular-nums; }

.meldung {
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--rand);
}
.meldung.warn { border-color: var(--warnung); }
.meldung.fehler { border-color: var(--kritisch); color: var(--kritisch); }

/* --- Scanner ----------------------------------------------------------- */
#scanner { width: 100%; border-radius: 12px; overflow: hidden; background: #000; }
#scanner video, #scanner canvas { width: 100%; display: block; }
