:root {
  --grund: #f4f7f5;
  --karte: #ffffff;
  --text: #17201c;
  --blass: #5f6d67;
  --linie: #dfe6e2;
  --akzent: #1f8a5b;
  --akzent-hell: #e3f3eb;
  --akzent-text: #ffffff;
  --gefahr: #c43d3d;
  --gefahr-hell: #fbe9e9;
  --warn: #9a6700;
  --warn-hell: #fff4d6;
  --gut: #1f8a5b;
  --plan: #7a8ad6;
  --ki: #6f4cc9;
  --ki-hell: #efe9fb;
  --schatten: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .05);
  --rund: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --grund: #0f1513;
    --karte: #18201d;
    --text: #e8eeeb;
    --blass: #93a39c;
    --linie: #2a3531;
    --akzent: #3cbf85;
    --akzent-hell: #17372a;
    --akzent-text: #06140e;
    --gefahr: #ff7b7b;
    --gefahr-hell: #3a1d1d;
    --warn: #f0c36a;
    --warn-hell: #3a2f14;
    --gut: #3cbf85;
    --plan: #96a3ef;
    --ki: #b49cff;
    --ki-hell: #2a2240;
    --schatten: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--grund);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
[hidden] { display: none !important; }
.laden { text-align: center; color: var(--blass); margin-top: 40vh; }

/* ---- Grundgerüst ---------------------------------------------------------- */
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
#app.einstieg { padding: max(24px, env(safe-area-inset-top)) 16px 32px; }
.einstieg-kopf { display: flex; align-items: center; gap: 12px; margin: 8px 0 18px; }
.einstieg-kopf h1 { font-size: 1.5rem; line-height: 1.2; }
.logo { width: 44px; height: 44px; border-radius: 12px; }
.unter-titel { color: var(--blass); margin: -8px 0 16px; }

#app.haupt { padding: env(safe-area-inset-top) 0 calc(76px + env(safe-area-inset-bottom)); }
main { padding: 12px 16px 96px; }
.seitentitel { font-size: 1.45rem; margin: 6px 0 12px; }
.unterkopf { display: flex; align-items: center; gap: 8px; margin: 2px 0 12px; }
.unterkopf h1 { font-size: 1.25rem; }
.zurueck { background: none; border: 0; color: var(--akzent); font-weight: 600; padding: 8px 6px 8px 0; cursor: pointer; }
.offline { background: var(--warn-hell); color: var(--warn); font-size: .85rem; padding: 6px 16px; text-align: center; }

.menue {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--karte) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--linie);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.menue button {
  flex: 1; max-width: 120px; background: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .72rem; color: var(--blass); padding: 4px 0;
}
.menue button.an { color: var(--akzent); font-weight: 600; }
.icon svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Karten, Felder, Knöpfe ------------------------------------------------ */
.karte { background: var(--karte); border-radius: var(--rund); box-shadow: var(--schatten); padding: 16px; margin-bottom: 12px; border: 1px solid var(--linie); }
.feld { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.feld-name { font-size: .85rem; font-weight: 600; color: var(--blass); display: flex; align-items: center; gap: 6px; }
input:not([type=checkbox]):not([type=range]):not([type=file]), select {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--linie); border-radius: 12px; background: var(--grund);
  font-size: 16px; /* iOS zoomt sonst */
}
input:focus, select:focus { outline: 2px solid var(--akzent); outline-offset: 0; border-color: transparent; }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--blass) 50%), linear-gradient(135deg, var(--blass) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 32px; }
.zeile2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }

.knopf {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--linie); background: var(--karte); font-weight: 600;
}
.knopf:disabled { opacity: .5; cursor: not-allowed; }
.knopf.primaer { background: var(--akzent); color: var(--akzent-text); border-color: var(--akzent); }
.knopf.gefahr { background: var(--gefahr); color: #fff; border-color: var(--gefahr); }
.knopf.gross { width: 100%; min-height: 52px; font-size: 1.05rem; margin-top: 6px; }
.knopf.breit { width: 100%; margin: 4px 0 12px; }
.knopf.klein { min-height: 40px; padding: 8px 12px; font-size: .92rem; }
.knopf.ki { background: var(--ki-hell); color: var(--ki); border-color: transparent; white-space: nowrap; }
.link { background: none; border: 0; padding: 0; color: var(--akzent); font-weight: 600; cursor: pointer; font-size: inherit; }

.info {
  width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--blass); background: none;
  color: var(--blass); font: italic 600 12px/1 Georgia, serif; padding: 0; cursor: pointer; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
}

.segment { display: flex; background: var(--grund); border: 1px solid var(--linie); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.feld .segment { margin-bottom: 0; }
.segment button { flex: 1; border: 0; background: none; border-radius: 9px; min-height: 38px; cursor: pointer; font-size: .92rem; color: var(--blass); padding: 4px 6px; }
.segment button.an { background: var(--karte); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.meldung { border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; font-size: .92rem; }
.meldung.fehler { background: var(--gefahr-hell); color: var(--gefahr); }
.meldung.warnung, .meldung.hinweis { background: var(--warn-hell); color: var(--warn); }
.meldung.gut { background: var(--akzent-hell); color: var(--akzent); }
.gut { color: var(--gut); }
.schlecht { color: var(--gefahr); }
.leer { color: var(--blass); text-align: center; margin: 12px 0 18px; }
.fussnote { color: var(--blass); font-size: .8rem; text-align: center; margin-top: 18px; }

.haken { display: flex; align-items: center; gap: 8px; min-height: 46px; margin-bottom: 14px; cursor: pointer; font-size: .95rem; }
.haken input { width: 20px; height: 20px; accent-color: var(--akzent); }

/* ---- Wahlkarten (Speicherort) ---------------------------------------------- */
.wahlkarten { display: grid; gap: 12px; }
.wahlkarte { text-align: left; background: var(--karte); border: 2px solid var(--linie); border-radius: var(--rund); padding: 14px 16px; cursor: pointer; }
.wahlkarte.an { border-color: var(--akzent); }
.wahlkarte strong { font-size: 1.08rem; }
.vorteile { list-style: none; padding: 0; margin: 8px 0 0; font-size: .92rem; }
.vorteile li { padding-left: 22px; position: relative; margin: 3px 0; }
.vorteile li::before { position: absolute; left: 2px; font-weight: 700; }
.vorteile .plus::before { content: "+"; color: var(--gut); }
.vorteile .minus::before { content: "–"; color: var(--gefahr); }

/* ---- Kennzahlen ------------------------------------------------------------ */
.kennzahlen { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.karte.kennzahlen { margin-bottom: 12px; }
.kennzahlen > div { background: var(--grund); border-radius: 12px; padding: 9px 11px; display: flex; flex-direction: column; }
.kennzahlen span { font-size: .78rem; color: var(--blass); display: flex; align-items: center; gap: 5px; }
.kennzahlen b { font-size: 1.08rem; }

/* ---- Heute ---------------------------------------------------------------- */
.tagesleiste { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 12px; }
.pfeil { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--linie); background: var(--karte); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.pfeil:disabled { opacity: .3; }
.tag-titel { text-align: center; display: flex; flex-direction: column; }
.tag-titel strong { font-size: 1.3rem; }
.tag-titel span { color: var(--blass); font-size: .88rem; }

.ring-karte { display: flex; flex-direction: column; align-items: center; padding: 18px 16px 14px; }
.ring-box { position: relative; width: 190px; height: 190px; }
.ring svg { width: 190px; height: 190px; }
.ring-grund { fill: none; stroke: var(--akzent-hell); stroke-width: 12; }
.ring-wert { fill: none; stroke: var(--akzent); stroke-width: 12; stroke-linecap: round; transition: stroke-dasharray .5s; }
.ring.ueber .ring-wert { stroke: var(--gefahr); }
.ring.ueber .ring-grund { stroke: var(--gefahr-hell); }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-text strong { font-size: 2.4rem; line-height: 1; font-variant-numeric: tabular-nums; }
.ring-text span { color: var(--blass); font-size: .9rem; margin-top: 4px; }
.ring-box:has(.ueber) .ring-text strong { color: var(--gefahr); }
.ring-unter { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; color: var(--blass); font-size: .92rem; }
.bonus { color: var(--akzent); font-weight: 600; }
.hinweis-karte p { margin: 0 0 12px; }

.abschnitt-kopf { display: flex; align-items: center; gap: 8px; margin: 18px 2px 8px; }
.abschnitt-kopf h2 { font-size: 1.02rem; }
.abschnitt-kopf .summe { margin-left: auto; color: var(--blass); font-size: .9rem; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.klein { flex-wrap: wrap; overflow: visible; padding-bottom: 4px; }
.chip { flex: none; border: 1px solid var(--linie); background: var(--karte); border-radius: 999px; padding: 8px 13px; cursor: pointer; font-size: .92rem; white-space: nowrap; }
.chip small { color: var(--blass); }
.chips.tempo { flex-wrap: wrap; align-items: center; overflow: visible; margin-top: 4px; }
.chips.tempo > span { color: var(--blass); font-size: .85rem; }

.liste { padding: 4px 0; }
.liste .zeile {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--linie); padding: 11px 16px; min-height: 52px;
  cursor: pointer;
}
.liste .zeile:last-child { border-bottom: 0; }
.zeile .zeit { color: var(--blass); font-size: .85rem; width: 42px; flex: none; font-variant-numeric: tabular-nums; }
.zeile .was { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.zeile .was strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.zeile .was small { color: var(--blass); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zeile .kcal { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.zeile .pfeil-rechts { color: var(--blass); font-size: 1.3rem; }
.zeile.benutzer { flex-wrap: wrap; cursor: default; }
.zeile.benutzer .haken { margin: 0; min-height: 0; font-size: .85rem; }
.marke-ki { font-size: .68rem; font-weight: 700; background: var(--ki-hell); color: var(--ki); border-radius: 6px; padding: 2px 5px; }
.marke-fav { color: #d59a00; font-size: .9rem; }
.x-klein { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--linie); background: var(--karte); cursor: pointer; font-size: 1.1rem; line-height: 1; flex: none; }

.fab {
  position: fixed; z-index: 15; right: max(16px, calc(50vw - 264px)); bottom: calc(86px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--akzent); color: var(--akzent-text); font-size: 2.1rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(31, 138, 91, .4);
}

/* ---- Eintrag-Dialog --------------------------------------------------------- */
.kcal-zeile { display: flex; gap: 8px; }
.kcal-zeile input { flex: 1; min-width: 0; }
.kcal-eingabe { font-size: 1.25rem !important; font-weight: 700; font-variant-numeric: tabular-nums; }
.ki-hinweis { font-size: .88rem; color: var(--blass); margin: -6px 0 12px; }
.ki-hinweis:empty { display: none; }
.ki-hinweis .meldung { margin: 6px 0 0; }
.gesperrt { color: var(--warn); }
.frage-box { background: var(--ki-hell); border-radius: 12px; padding: 12px; margin-bottom: 14px; }
.frage { margin: 0 0 8px; font-weight: 600; color: var(--ki); }
.frage-antwort { display: flex; gap: 8px; margin-top: 4px; }
.frage-antwort input { flex: 1; min-width: 0; background: var(--karte) !important; }
.foto-zeile { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.bild-vorschau { position: relative; }
.bild-vorschau img { width: 76px; height: 76px; object-fit: cover; border-radius: 12px; display: block; }
.bild-vorschau .x-klein { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; font-size: .95rem; }

/* ---- Ziel ----------------------------------------------------------------- */
.regler { margin: 6px 0 16px; }
.regler-kopf { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.regler-kopf span { font-weight: 600; color: var(--blass); font-size: .9rem; }
.regler-wert { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.regler-zeile { display: flex; align-items: center; gap: 8px; }
.stufe { width: 38px; height: 38px; flex: none; border-radius: 50%; border: 1px solid var(--linie); background: var(--grund); font-size: 1.2rem; cursor: pointer; line-height: 1; }
input[type=range] { flex: 1; min-width: 0; accent-color: var(--akzent); height: 30px; }
input[type=range].blass { opacity: .35; }
.ergebnis-gross { display: flex; flex-direction: column; margin-bottom: 12px; }
.ergebnis-gross span { color: var(--blass); }
.ergebnis-gross strong { font-size: 1.7rem; line-height: 1.15; color: var(--akzent); }
.stand-kopf { display: flex; align-items: baseline; gap: 10px; }
.stand-kopf strong { font-size: 1.3rem; }
.stand-kopf span { color: var(--blass); }
.stand p { margin: 6px 0 0; font-size: .92rem; }

/* ---- Gewicht / Diagramm ------------------------------------------------------ */
.kg-eingabe { font-size: 1.25rem !important; font-weight: 700; }
.gewicht-form .knopf { width: 100%; }
.diagramm-box { width: 100%; overflow: hidden; touch-action: pan-y; margin-top: 4px; }
.diagramm { display: block; width: 100%; height: auto; }
.diagramm .raster { stroke: var(--linie); stroke-width: 1; }
.diagramm .achse { fill: var(--blass); font-size: 11px; }
.diagramm .serie { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.diagramm .serie.ist { stroke: var(--akzent); }
.diagramm .serie.plan { stroke: var(--plan); stroke-dasharray: 6 5; stroke-width: 2; }
.diagramm .serie.prognose { stroke: var(--akzent); stroke-dasharray: 2 0; }
.diagramm .punkt { fill: var(--karte); stroke: var(--akzent); stroke-width: 2; }
.diagramm .linie.ziel { stroke: var(--warn); stroke-dasharray: 3 4; stroke-width: 1.5; }
.diagramm .linien-text { font-size: 11px; fill: var(--warn); font-weight: 600; }
.diagramm .marke-kreis { fill: var(--akzent); stroke: var(--karte); stroke-width: 2; }
.diagramm .marke-schild { fill: var(--text); }
.diagramm .marke-text { fill: var(--karte); font-size: 12px; font-weight: 600; }
.legende { display: flex; gap: 14px; justify-content: center; font-size: .8rem; color: var(--blass); margin-top: 6px; }
.legende span::before { content: ""; display: inline-block; width: 16px; height: 0; border-top: 3px solid; vertical-align: middle; margin-right: 5px; }
.legende .l-ist::before { border-color: var(--akzent); }
.legende .l-plan::before { border-color: var(--plan); border-top-style: dashed; }
.legende .l-ziel::before { border-color: var(--warn); border-top-style: dotted; }

/* ---- Dialog ---------------------------------------------------------------- */
.dialog-hinter {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 14, 11, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: einblenden .18s ease-out;
}
.dialog-hinter.weg { opacity: 0; transition: opacity .18s; }
.dialog {
  background: var(--karte); width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column;
  border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom);
  animation: hochfahren .22s ease-out;
}
@media (min-width: 620px) {
  .dialog-hinter { align-items: center; }
  .dialog { border-radius: 20px; max-height: 86vh; }
}
.dialog-kopf { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 6px; }
.dialog-kopf h2 { font-size: 1.15rem; }
.dialog .x { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--grund); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.dialog-inhalt { padding: 8px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dialog-inhalt p { margin-top: 0; }
.dialog-fuss { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px 14px; border-top: 1px solid var(--linie); flex-wrap: wrap; }
.dialog-fuss .links { margin-right: auto; }
@keyframes einblenden { from { opacity: 0; } }
@keyframes hochfahren { from { transform: translateY(40px); opacity: .6; } }

/* ---- Hinweis unten ----------------------------------------------------------- */
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 520px); width: max-content;
  background: var(--text); color: var(--karte); border-radius: 14px; padding: 11px 14px;
  font-size: .92rem; display: flex; gap: 12px; align-items: center; transition: all .2s;
}
.toast.sichtbar { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.fehler { background: var(--gefahr); color: #fff; }
.toast-knopf { background: none; border: 0; color: var(--akzent-hell); font-weight: 700; cursor: pointer; padding: 4px; white-space: nowrap; }

@media (max-width: 360px) {
  .zeile2 { grid-template-columns: 1fr; }
  .ring-box, .ring svg { width: 160px; height: 160px; }
}
