/* Aussehen aller Seiten. Farben nur über die Variablen oben, hell und dunkel.
   Look „fein und ruhig“: keine Kästen, feine Linien, ein Akzent (Grün). */
:root {
  --grund: #fbfbf9;
  --flaeche: #ffffff;
  --feld: #f0f1ee;
  --text: #151816;
  --blass: #6b726d;
  --linie: #e5e7e3;
  --akzent: #1f7a4d;
  --akzent-text: #ffffff;
  --warn: #b3541e;
  --schlecht: #b3261e;
  --rund: 12px;
  --leiste: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --grund: #0e0f0e;
    --flaeche: #181a18;
    --feld: #1d201d;
    --text: #eceeec;
    --blass: #8d948f;
    --linie: #272a27;
    --akzent: #4fbf87;
    --akzent-text: #08140d;
    --warn: #e59a62;
    --schlecht: #f08a80;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; color-scheme: light dark; }
body {
  margin: 0;
  background: var(--grund);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
main { max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
body.angemeldet main { padding-bottom: calc(var(--leiste) + 28px + env(safe-area-inset-bottom)); }
a { color: var(--akzent); text-decoration: none; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }
p { margin: 8px 0; }
.klein { color: var(--blass); font-size: 14px; }
.fehler { color: var(--schlecht); font-weight: 600; }
.leer { color: var(--blass); font-size: 14px; text-align: center; padding: 18px 0 0; }
.sym { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Abschnitte: nur eine feine Linie, kein Kasten */
.abschnitt { padding: 18px 0; border-top: 1px solid var(--linie); }
.abschnitt h2 { margin-bottom: 4px; }
.schmal { max-width: 360px; margin: 12vh auto 0; }
.marke { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.marke .ring { width: 34px; height: 34px; }
.marke .ring circle { stroke-width: 14; }

/* Formulare */
label { display: block; font-size: 13px; color: var(--blass); margin-top: 12px; }
input, select {
  display: block; width: 100%; height: 46px; margin-top: 4px; padding: 0 12px;
  font: inherit; font-size: 16px; color: var(--text); background: var(--feld);
  border: 1px solid transparent; border-radius: var(--rund); appearance: none; -webkit-appearance: none;
}
input::placeholder { color: var(--blass); opacity: .8; }
input:focus, select:focus { outline: none; border-color: var(--akzent); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; }
button {
  font: inherit; font-weight: 600; color: var(--text); background: var(--feld);
  border: 1px solid transparent; border-radius: var(--rund); min-height: 44px; padding: 0 16px; cursor: pointer;
  transition: opacity .12s, transform .12s;
}
button:active, .leiste a:active, .kopf a:active { opacity: .6; }
button.haupt { display: block; width: 100%; height: 50px; margin-top: 16px; background: var(--akzent); color: var(--akzent-text); }
button.haupt:active { transform: scale(.985); opacity: .85; }
button.laeuft { opacity: .6; pointer-events: none; }
button.laeuft::after { content: ""; display: inline-block; width: 14px; height: 14px; margin-left: 10px; vertical-align: -2px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: dreh .7s linear infinite; }
.reihe { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.reihe.zwei { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.link-zeile { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.link-zeile input { margin: 0; font-size: 13px; }
.link-zeile button { flex: none; white-space: nowrap; }
.auswahl { position: relative; flex: 1; min-width: 0; }
.auswahl select { margin: 0; padding-right: 34px; }
.auswahl::after { content: "▾"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--blass); pointer-events: none; }
.konto { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Kopfzeile: steht in jeder Ansicht gleich, nichts springt */
.kopf { display: grid; grid-template-columns: 44px 1fr 44px 72px; align-items: center; gap: 4px; height: 56px; }
.kopf.einfach { display: flex; }
.kopf .pfeil { display: grid; place-items: center; height: 44px; border-radius: var(--rund); color: var(--text); }
.kopf .datum { text-align: center; line-height: 1.2; }
.kopf .datum b { display: block; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.kopf .datum span { font-size: 12px; color: var(--blass); font-variant-numeric: tabular-nums; }
.kopf .heute { display: grid; place-items: center; height: 36px; border-radius: 18px; background: var(--feld); color: var(--text); font-weight: 600; font-size: 14px; }
.kopf .heute.aus { color: var(--blass); pointer-events: none; opacity: .45; }

/* Tagesübersicht: Ring links, Zahlen rechts */
.summe { display: flex; align-items: center; gap: 18px; padding: 6px 0 18px; }
.ringfeld { position: relative; width: 118px; height: 118px; flex: none; }
.ring { display: block; width: 100%; height: 100%; }
.ring circle { fill: none; stroke-width: 8; }
.ring .spur { stroke: var(--linie); }
.ring .wert { stroke: var(--akzent); stroke-linecap: round; }
.ring.zu-viel .wert { stroke: var(--warn); }
.ringfeld .mitte { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; }
.ringfeld .mitte b { font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.ringfeld .mitte span { font-size: 12px; color: var(--blass); }
.ringfeld.drueber .mitte b, .ringfeld.drueber .mitte span { color: var(--warn); }
.zahlen { flex: 1; min-width: 0; }
.summe .gross { font-size: 14px; color: var(--blass); font-variant-numeric: tabular-nums; }
.summe .gross b { color: var(--text); font-weight: 600; }
.makros { display: grid; gap: 7px; margin-top: 8px; }
.makros div { display: grid; grid-template-columns: 1fr auto; font-size: 13px; }
.makros span { color: var(--blass); }
.makros b { font-weight: 500; font-variant-numeric: tabular-nums; }
.makros progress { grid-column: 1 / -1; }

progress.balken { display: block; width: 100%; height: 8px; margin-top: 8px; border: 0; border-radius: 4px; overflow: hidden; background: var(--linie); appearance: none; -webkit-appearance: none; }
progress.balken.duenn { height: 3px; margin-top: 4px; }
progress.balken::-webkit-progress-bar { background: var(--linie); }
progress.balken::-webkit-progress-value { background: var(--akzent); border-radius: 4px; }
progress.balken::-moz-progress-bar { background: var(--akzent); border-radius: 4px; }
.makros progress.balken::-webkit-progress-value { background: var(--text); }
.makros progress.balken::-moz-progress-bar { background: var(--text); }
progress.balken.zu-viel::-webkit-progress-value { background: var(--warn); }
progress.balken.zu-viel::-moz-progress-bar { background: var(--warn); }

/* Mahlzeiten: Überschrift mit Plus, darunter schlanke Zeilen */
.mahlzeit { border-top: 1px solid var(--linie); padding: 4px 0 6px; }
.mahlzeit h2 { display: flex; align-items: center; gap: 4px; height: 48px; }
.mahlzeit h2 span { margin-left: auto; font-weight: 400; font-size: 14px; color: var(--blass); font-variant-numeric: tabular-nums; }
.plus { display: grid; place-items: center; width: 44px; height: 44px; margin-right: -10px; padding: 0; background: none; color: var(--akzent); border-radius: 50%; }
.mahlzeit ul, .tage { list-style: none; margin: 0; padding: 0; }
.mahlzeit li { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.mahlzeit .was { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.mahlzeit .was b { display: block; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mahlzeit .was a.name { color: var(--text); min-width: 0; padding: 11px 0; }
.mahlzeit .was span { flex: none; font-size: 13px; color: var(--blass); font-variant-numeric: tabular-nums; }
.mahlzeit .kcal { font-variant-numeric: tabular-nums; }
.weg { display: grid; place-items: center; min-width: 44px; height: 44px; margin-right: -12px; padding: 0 10px; color: var(--blass); background: none; }
.weg .sym { width: 16px; height: 16px; }
.weg.sicher { margin-right: 0; min-height: 34px; height: 34px; font-size: 13px; color: var(--schlecht); border-color: var(--schlecht); }

/* Verlauf */
.schnitt { margin: 0 0 14px; font-size: 14px; color: var(--blass); }
.schnitt b { font-size: 24px; font-weight: 650; letter-spacing: -.02em; color: var(--text); font-variant-numeric: tabular-nums; }
.schnitt span { display: block; font-size: 13px; }
.tage li { border-top: 1px solid var(--linie); }
.tage a { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 10px; min-height: 52px; padding: 9px 0; color: var(--text); }
.tage .wert { font-size: 14px; color: var(--blass); font-variant-numeric: tabular-nums; }
.tage .wert b { font-size: 16px; font-weight: 500; color: var(--text); }
.tage progress { grid-column: 1 / -1; }
.tage .ohne a { min-height: 44px; padding: 0; color: var(--blass); }

/* Freunde: Name mit Haken, rechts die Streak, darunter der heutige Stand */
.freunde { list-style: none; margin: 8px 0 0; padding: 0; }
.freunde li { border-top: 1px solid var(--linie); }
.freunde a { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; min-height: 60px; padding: 10px 0; color: var(--text); }
.freunde .wer { display: flex; align-items: center; gap: 6px; min-width: 0; }
.freunde .wer b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.freunde .wer small { font-weight: 400; color: var(--blass); }
.freunde .haken { color: var(--akzent); display: grid; }
.freunde .haken .sym { width: 18px; height: 18px; stroke-width: 2.4; }
.freunde .stand { grid-column: 1 / -1; font-size: 14px; color: var(--blass); font-variant-numeric: tabular-nums; }
.freunde .stand b { font-weight: 500; color: var(--text); }
.freunde progress { grid-column: 1 / -1; }
.freunde .ohne .wer b { color: var(--blass); }
.streak { display: inline-flex; align-items: center; gap: 3px; color: var(--blass); font-variant-numeric: tabular-nums; }
.streak .sym { width: 18px; height: 18px; }
.streak b { font-weight: 600; }
.streak.an { color: var(--warn); }
.streak.an .sym { fill: currentColor; fill-opacity: .18; }
.freund-stand { display: flex; align-items: center; justify-content: space-between; margin: 0 0 6px; font-size: 14px; color: var(--blass); font-variant-numeric: tabular-nums; }
.freund-stand b { color: var(--text); font-weight: 600; }
#pop .mahlzeit h2 { height: 40px; }

/* Blatt (Pop-up): am Handy von unten. --sicht/--tastatur setzt app.js (sichtbare Höhe über der Tastatur). */
dialog.blatt {
  width: min(560px, 100%); max-width: 100%; max-height: calc(var(--sicht, 100dvh) - 20px);
  margin: auto auto var(--tastatur, 0px); padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  border: 0; border-radius: 18px 18px 0 0; background: var(--flaeche); color: var(--text); overflow-y: auto; overscroll-behavior: contain;
}
dialog.blatt::backdrop { background: rgba(0, 0, 0, .5); }
dialog.blatt[open] { animation: hoch .22s cubic-bezier(.2, .8, .2, 1); }
dialog.blatt[open]::backdrop { animation: ein .22s ease-out; }
@media (min-width: 620px) { dialog.blatt { margin: auto; border-radius: 18px; } }
.blatt-kopf { display: flex; align-items: center; justify-content: space-between; height: 48px; }
.blatt-kopf h2 { font-size: 18px; font-weight: 650; }
.zu { display: grid; place-items: center; width: 44px; height: 44px; margin-right: -10px; padding: 0; background: none; color: var(--blass); }

/* Blatt „Eintragen“: Kopf und Fuß stehen fest, nur die Liste in der Mitte scrollt */
#blatt { padding-left: 0; padding-right: 0; overflow: hidden; }
#blatt[open] { display: flex; }
#blatt.sucht { height: calc(var(--sicht, 100dvh) - 20px); }
#eintrag-form { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; }
#eintrag-form > * { margin-left: 16px; margin-right: 16px; }
.wahl { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; padding: 3px; border-radius: var(--rund); background: var(--feld); flex: none; }
.wahl label { margin: 0; }
.wahl input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.wahl span { display: grid; place-items: center; height: 36px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--blass); cursor: pointer; }
.wahl input:checked + span { background: var(--flaeche); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.wahl input:focus-visible + span { outline: 2px solid var(--akzent); }
.finden { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-top: 10px; scrollbar-width: none; }
.finden::-webkit-scrollbar { display: none; }
.such-zeile { display: flex; gap: 8px; position: sticky; top: -10px; z-index: 1; padding: 0 0 6px; background: var(--flaeche); }
.such-zeile input { margin: 0; }
.such-zeile.laedt input { background-image: linear-gradient(90deg, transparent, var(--akzent), transparent); background-size: 40% 2px; background-repeat: no-repeat; background-position: -40% 100%; animation: lauf .9s linear infinite; }
.scan-knopf { display: grid; place-items: center; width: 46px; height: 46px; padding: 0; flex: none; }
.liste-titel { margin: 8px 0 0; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--blass); }
.treffer { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 52px; padding: 6px 0; text-align: left; font-weight: 400; background: none; border-radius: 0; border-bottom: 1px solid var(--linie); }
.treffer b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.treffer span { flex: none; font-size: 13px; color: var(--blass); font-variant-numeric: tabular-nums; }
.finden:has(#neu[open]) .treffer-liste { display: none; }
.scan { position: relative; margin-top: 4px; border-radius: var(--rund); overflow: hidden; background: #000; }
.scan::after { content: ""; position: absolute; left: 12%; right: 12%; top: 15dvh; height: 2px; background: var(--akzent); opacity: .85; pointer-events: none; }
.scan video { display: block; width: 100%; height: 30dvh; object-fit: cover; }
.scan-fuss { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 6px 6px 12px; color: #fff; font-size: 14px; }
.scan-fuss button { background: rgba(255, 255, 255, .16); color: #fff; }
details { margin-top: 6px; }
summary { cursor: pointer; color: var(--akzent); font-weight: 600; padding: 12px 0; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "+ "; }
details[open] summary::before { content: "– "; }
.gewaehlt-feld { padding-top: 12px; flex: none; }
.gewaehlt { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 4px 12px 4px 14px; border-radius: var(--rund); background: var(--feld); }
.gewaehlt p { flex: 1; min-width: 0; margin: 0; font-weight: 600; }
.gewaehlt .zu { margin-right: -8px; }
.korrigieren { display: inline-block; padding: 10px 2px 2px; font-size: 14px; }
.blatt-fuss { flex: none; padding-top: 10px; border-top: 1px solid var(--linie); margin-top: 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; min-height: 38px; padding: 0 13px; border-radius: 19px; font-size: 14px; font-weight: 500; }
.chips button.an { background: var(--text); color: var(--grund); }
.menge-zeile { display: grid; grid-template-columns: 128px 1fr; align-items: end; gap: 14px; }
.menge-zeile label { margin-top: 8px; }
.vorschau { margin: 0; height: 46px; display: flex; align-items: center; font-size: 20px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
#blatt.sucht:not(:has(#neu[open])) .blatt-fuss { display: none; }
#blatt-fehler { flex: none; margin-top: 8px; margin-bottom: 0; font-size: 14px; }
.blatt-fuss button.haupt { margin-top: 12px; }
.quelle { text-align: center; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--linie); }

/* Hauptmenü unten (Daumen) */
.leiste { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; background: var(--grund); border-top: 1px solid var(--linie); padding-bottom: env(safe-area-inset-bottom); }
.leiste a { flex: 1; max-width: 190px; height: var(--leiste); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--blass); font-size: 11px; font-weight: 600; }
.leiste a.aktiv { color: var(--akzent); }

/* Meldung: unten über dem Menü, damit sie die Kopfzeile nicht verdeckt */
.toast { position: fixed; bottom: calc(var(--leiste) + 14px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 10; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 22px; background: var(--text); color: var(--grund); font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .22); animation: toast .25s cubic-bezier(.2, .8, .2, 1); }
.toast.schlecht { background: var(--schlecht); color: #fff; }

@keyframes hoch { from { transform: translateY(40px); opacity: 0; } }
@keyframes ein { from { opacity: 0; } }
@keyframes toast { from { transform: translate(-50%, 12px); opacity: 0; } }
@keyframes dreh { to { transform: rotate(360deg); } }
@keyframes lauf { to { background-position: 140% 100%; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, dialog.blatt[open]::backdrop { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
