/* Kalaso – Mobile-First. Bedienung überwiegend einhändig am Handy,
   deshalb: große Touchflächen (min. 48 px), Aktionen im unteren Drittel,
   Zahlenfelder groß genug, um sie am Esstisch zu treffen. */

:root {
    color-scheme: light dark;

    --bg:          #f7f5f2;
    --surface:     #ffffff;
    --surface-2:   #f0ede8;
    --border:      #e0dbd3;
    --text:        #1b1a18;
    --text-muted:  #6d6a64;

    --kcal:        #3f7d58;   /* Kalorien */
    --protein:     #c2571f;   /* Eiweiß – die kritischere Zahl, deshalb der wärmere Ton */
    --danger:      #b3261e;
    --track:       #e4e0d9;

    --radius:      14px;
    --radius-lg:   20px;
    --tap:         48px;
    --gap:         12px;
    --shadow:      0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .05);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --tabbar-h: calc(60px + env(safe-area-inset-bottom, 0px));
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:         #15161a;
        --surface:    #1e2026;
        --surface-2:  #262931;
        --border:     #33373f;
        --text:       #eceef2;
        --text-muted: #9aa0ab;

        --kcal:       #6ec08c;
        --protein:    #f0925a;
        --danger:     #f2857c;
        --track:      #2e323a;
        --shadow:     0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.45;
    /* Vermeidet den Zoom-Sprung beim Fokussieren von Feldern auf iOS */
    -webkit-tap-highlight-color: transparent;
}

.page {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--tabbar-h) + 16px);
}

/* ---------- Typografie ---------- */

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }

.muted   { color: var(--text-muted); }
.small   { font-size: .82rem; }
.num     { font-variant-numeric: tabular-nums; }
.center  { text-align: center; }

/* ---------- Kopfzeile mit Datumsnavigation ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
}

.topbar__title { display: flex; flex-direction: column; align-items: center; }
.topbar__date  { font-size: 1.35rem; font-weight: 650; }

.iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--tap);
    min-height: var(--tap);
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font-size: 1.2rem;
    text-decoration: none;
    cursor: pointer;
}

.iconbtn[aria-disabled="true"] { opacity: .35; pointer-events: none; }

/* ---------- Karten ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: var(--gap);
    box-shadow: var(--shadow);
}

.card--flat { box-shadow: none; }

/* ---------- Fortschrittsbalken ----------
   Kalorien und Eiweiß sind bewusst gleich groß und gleich gewichtet.
   Eiweiß ist die kritischere Zahl und darf nicht als Nebeninfo wirken. */

.goals { display: grid; gap: 14px; }

.goal__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 6px;
}

.goal__label  { font-size: .9rem; font-weight: 600; }
.goal__values { font-size: .95rem; font-variant-numeric: tabular-nums; }
.goal__value  { font-size: 1.25rem; font-weight: 700; }
.goal__goal   { color: var(--text-muted); }

.bar {
    height: 14px;
    border-radius: 999px;
    background: var(--track);
    overflow: hidden;
}

.bar__fill {
    height: 100%;
    border-radius: 999px;
    transition: width .25s ease;
}

.bar__fill--kcal    { background: var(--kcal); }
.bar__fill--protein { background: var(--protein); }

.goal--kcal    .goal__value { color: var(--kcal); }
.goal--protein .goal__value { color: var(--protein); }

/* Sekundärwerte: Kohlenhydrate und Fett, klein gehalten */
.secondary {
    display: flex;
    gap: 18px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: .85rem;
    color: var(--text-muted);
}

.secondary b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Mahlzeitenliste ---------- */

.group { margin-top: 18px; }

.group__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 6px;
    padding: 0 4px;
}

.group__title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

.meal {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: inherit;
    text-decoration: none;
    min-height: var(--tap);
}

.meal__thumb {
    width: 44px; height: 44px;
    flex: 0 0 44px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--surface-2);
}

.meal__body  { flex: 1; min-width: 0; }
.meal__name  { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal__sub   { font-size: .8rem; color: var(--text-muted); }

.meal__nums  { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meal__kcal  { font-weight: 700; color: var(--kcal); }
.meal__prot  { font-size: .8rem; color: var(--protein); font-weight: 600; }

.empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 0 20px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--text);
    color: var(--bg);
    font: inherit;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}

.btn--block  { display: flex; width: 100%; }
.btn--big    { min-height: 58px; font-size: 1.05rem; }
.btn--ghost  { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* Der wichtigste Button der App bleibt beim Scrollen über der Tableiste stehen */
.fab-wrap {
    position: sticky;
    bottom: calc(var(--tabbar-h) + 10px);
    margin-top: 20px;
    padding-top: 8px;
}

/* ---------- Formulare ---------- */

.field { margin-bottom: 14px; }

label.field__label {
    display: block;
    margin-bottom: 6px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
}

input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="datetime-local"],
select, textarea {
    width: 100%;
    min-height: var(--tap);
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    /* 16px verhindert den automatischen Zoom beim Fokus auf iOS */
    font: inherit;
    font-size: 16px;
}

input[type="number"] { font-variant-numeric: tabular-nums; }

textarea { min-height: 80px; resize: vertical; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
.btn:focus-visible, .iconbtn:focus-visible, a:focus-visible {
    outline: 2px solid var(--protein);
    outline-offset: 2px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

/* Segmentierte Auswahl für den Mahlzeitentyp – vier große Flächen statt eines Selects */
.segmented {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 4px;
}

.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented label {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border-radius: 10px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}

.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + label { outline: 2px solid var(--protein); outline-offset: 2px; }

/* ---------- Erfassen: die drei Einstiege ---------- */

.tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 16px;
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 4px;
}

.tabs__btn {
    min-height: 46px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-weight: 650;
    cursor: pointer;
}

.tabs__btn.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Favoritenliste: ein Tap = Mahlzeit gespeichert */
.fav {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px;
    margin-bottom: 8px;
    min-height: 62px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.fav:disabled { opacity: .6; }
.fav__body { flex: 1; min-width: 0; }
.fav__name { font-weight: 650; }
.fav__meta { font-size: .8rem; color: var(--text-muted); }
.fav__nums { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* ---------- Items im Erfassungsdialog ---------- */

.item {
    padding: 12px;
    margin-bottom: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.item__top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.item__name { flex: 1; }

.item__row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: end;
}

.item__nums {
    display: flex;
    gap: 14px;
    margin-top: 8px;
    font-size: .82rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.item__nums b { color: var(--text); font-weight: 650; }

.conf {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.conf--high   { background: color-mix(in srgb, var(--kcal) 18%, transparent);    color: var(--kcal); }
.conf--medium { background: color-mix(in srgb, var(--protein) 18%, transparent); color: var(--protein); }
.conf--low    { background: color-mix(in srgb, var(--danger) 18%, transparent);  color: var(--danger); }

.remove {
    min-width: 40px; min-height: 40px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}

.remove:hover { color: var(--danger); }

/* ---------- Ladezustand der Bildanalyse ---------- */

.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 36px 16px; text-align: center; }

.spinner {
    width: 38px; height: 38px;
    border: 3px solid var(--track);
    border-top-color: var(--protein);
    border-radius: 50%;
    animation: spin .9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 2.4s; }
    .bar__fill { transition: none; }
}

.preview {
    width: 100%;
    max-height: 240px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-bottom: 12px;
}

/* ---------- Meldungen ---------- */

.notice {
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: .9rem;
    margin-bottom: var(--gap);
}

.notice--error { border-color: var(--danger); color: var(--danger); background: transparent; }
.notice--ok    { border-color: var(--kcal);   color: var(--kcal);   background: transparent; }

/* ---------- Gewicht ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.stat__value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat__label { font-size: .75rem; color: var(--text-muted); }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart__grid  { stroke: var(--border); stroke-width: 1; }
.chart__raw   { fill: var(--text-muted); opacity: .35; }   /* Einzelmessungen schwach im Hintergrund */
.chart__trend { fill: none; stroke: var(--protein); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart__goal  { stroke: var(--kcal); stroke-width: 1.5; stroke-dasharray: 5 5; fill: none; }
.chart__label { fill: var(--text-muted); font-size: 10px; font-family: var(--font); }

/* ---------- Tableiste ---------- */

.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tabbar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 60px;
    color: var(--text-muted);
    text-decoration: none;
}

.tabbar__item.is-active { color: var(--text); }
.tabbar__icon  { font-size: 1.15rem; line-height: 1; }
.tabbar__label { font-size: .68rem; font-weight: 600; }

/* ---------- Bestätigungsdialog ---------- */

.confirm {
    border: 0;
    border-radius: var(--radius-lg);
    padding: 0;
    background: var(--surface);
    color: var(--text);
    max-width: 340px;
    width: calc(100% - 40px);
}

.confirm::backdrop { background: rgba(0, 0, 0, .5); }
.confirm__box     { padding: 20px; }
.confirm__text    { margin: 0 0 18px; }
.confirm__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

[hidden] { display: none !important; }

/* ---------- Login ---------- */

.login { display: flex; min-height: 80vh; flex-direction: column; justify-content: center; }
.login__logo { font-size: 2rem; font-weight: 700; text-align: center; margin-bottom: 4px; letter-spacing: -.02em; }
