/* ── Reset & Base ────────────────────────────────────────────── */
:root {
    --bg:          #0f1117;
    --surface:     #1a1d27;
    --surface2:    #222534;
    --border:      rgba(255,255,255,.08);
    --accent:      #4ade80;
    --accent-dim:  #16a34a;
    --warn:        #fb923c;
    --danger:      #f87171;
    --text:        #e8eaf0;
    --muted:       #7c7f8e;
    --nav-h:       60px;
    --safe-top:    env(safe-area-inset-top,    0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); }

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    /* Statusleiste / Dynamic Island oben */
    padding-top: var(--safe-top);
    /* Bottom Nav + Home Indicator unten */
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100dvh;
    padding: 0 0 1rem;
}

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem .75rem;
    display: flex;
    align-items: center;
    gap: .75rem;
}
.page-header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    flex: 1;
    letter-spacing: -.01em;
}
.page-header .date-badge {
    font-size: .78rem;
    color: var(--muted);
    white-space: nowrap;
}

/* ── Bottom Navigation ───────────────────────────────────────── */
/* Hintergrund läuft volle Breite bis zum Rand */
.bottom-nav-bg {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-h) + var(--safe-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 199;
}
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: var(--nav-h);
    /* Inhalt sitzt oberhalb des Home Indicators */
    margin-bottom: var(--safe-bottom);
    display: flex;
    z-index: 200;
}
.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .2rem;
    color: var(--muted);
    text-decoration: none;
    font-size: .68rem;
    font-weight: 500;
    transition: color .15s;
    padding: .5rem 0;
}
.bottom-nav__item i { font-size: 1.4rem; line-height: 1; }
.bottom-nav__item.active { color: var(--accent); }
.bottom-nav__item:active { opacity: .7; }

/* ── Cards ───────────────────────────────────────────────────── */
.kt-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1rem 1.25rem;
    margin: 0 1rem .75rem;
}

/* ── Kalorienzähler (Donut + Zahl) ──────────────────────────── */
.kcal-ring-wrap {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.25rem 1.25rem;
    margin: .75rem 1rem 0;
    background: var(--surface);
    border-radius: 20px;
    border: 1px solid var(--border);
}
.kcal-ring { position: relative; width: 96px; height: 96px; flex-shrink: 0; }
.kcal-ring svg { transform: rotate(-90deg); }
.kcal-ring__track { fill: none; stroke: var(--surface2); stroke-width: 9; }
.kcal-ring__bar   { fill: none; stroke: var(--accent);   stroke-width: 9;
                     stroke-linecap: round;
                     transition: stroke-dashoffset .6s cubic-bezier(.4,0,.2,1); }
.kcal-ring__bar.warn   { stroke: var(--warn); }
.kcal-ring__bar.danger { stroke: var(--danger); }
.kcal-ring__center {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
}
.kcal-ring__num  { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.kcal-ring__unit { font-size: .65rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.kcal-stats { flex: 1; display: flex; flex-direction: column; gap: .4rem; }
.kcal-stat-row { display: flex; justify-content: space-between; align-items: baseline; }
.kcal-stat-label { font-size: .8rem; color: var(--muted); }
.kcal-stat-val   { font-size: .95rem; font-weight: 600; }
.kcal-remaining  { font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.kcal-remaining.warn   { color: var(--warn); }
.kcal-remaining.danger { color: var(--danger); }

/* ── Makro-Balken ────────────────────────────────────────────── */
.macro-bars { margin: 0 1rem .75rem; }
.macro-bar-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; }
.macro-bar-label { font-size: .75rem; color: var(--muted); width: 56px; flex-shrink: 0; }
.macro-bar-track { flex: 1; height: 6px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.macro-bar-fill  { height: 100%; border-radius: 99px; transition: width .5s; }
.macro-bar-val   { font-size: .75rem; font-weight: 600; width: 44px; text-align: right; flex-shrink: 0; }
.bar-eiweiss { background: #60a5fa; }
.bar-fett    { background: var(--warn); }
.bar-kh      { background: #a78bfa; }

/* ── Mahlzeit-Sektionen ──────────────────────────────────────── */
.meal-section { margin: 0 0 .5rem; }
.meal-header {
    display: flex; align-items: center; gap: .5rem;
    padding: .6rem 1.25rem;
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .07em;
}
.meal-header .meal-kcal { margin-left: auto; color: var(--text); font-weight: 700; }

.entry-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    transition: background .12s;
}
.entry-item:first-of-type { border-top: 1px solid var(--border); }
.entry-item:active { background: var(--surface2); }
.entry-icon {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--surface2); display: flex; align-items: center;
    justify-content: center; font-size: 1.1rem; flex-shrink: 0;
}
.entry-name  { font-size: .9rem; font-weight: 600; line-height: 1.2; }
.entry-meta  { font-size: .75rem; color: var(--muted); }
.entry-kcal  { margin-left: auto; font-size: 1rem; font-weight: 700; flex-shrink: 0; }
.entry-delete { color: var(--danger); background: none; border: none; padding: .25rem .4rem;
                font-size: 1.1rem; opacity: .5; flex-shrink: 0; }
.entry-delete:active { opacity: 1; }

/* ── Scanner ────────────────────────────────────────────────── */
.scanner-wrap {
    position: relative;
    margin: 1rem;
    border-radius: 20px;
    overflow: hidden;
    background: #000;
    aspect-ratio: 1;
}
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-overlay {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}
.scanner-frame {
    width: 65%; aspect-ratio: 1;
    border: 2.5px solid var(--accent);
    border-radius: 12px;
    box-shadow: 0 0 0 2000px rgba(0,0,0,.5);
}
.scanner-laser {
    position: absolute;
    top: 50%; left: 17.5%;
    width: 65%; height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    animation: laser 2s ease-in-out infinite;
    border-radius: 2px;
}
@keyframes laser { 0%,100% { opacity: .3; transform: scaleY(1); }
                   50%       { opacity: 1;  transform: scaleY(1.5); } }

.scan-btn {
    display: block; width: calc(100% - 2rem);
    margin: .75rem 1rem; padding: 1rem;
    background: var(--accent); color: #000;
    border: none; border-radius: 14px;
    font-size: 1rem; font-weight: 700;
    text-align: center; cursor: pointer;
    transition: opacity .15s, transform .1s;
}
.scan-btn:active { opacity: .85; transform: scale(.98); }
.scan-btn.secondary {
    background: var(--surface2); color: var(--text);
}
.scan-btn i { margin-right: .4rem; }

/* ── Produkt-Karte nach Scan ────────────────────────────────── */
.product-found {
    margin: 0 1rem 1rem;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 16px;
    overflow: hidden;
    display: none;
}
.product-found.visible { display: block; }
.product-found__head {
    background: rgba(74,222,128,.1);
    padding: .75rem 1rem;
    display: flex; align-items: center; gap: .6rem;
}
.product-found__name { font-weight: 700; font-size: .95rem; line-height: 1.2; }
.product-found__src  { font-size: .7rem; color: var(--muted); }
.product-found__body { padding: 1rem; }
.product-macros {
    display: grid; grid-template-columns: repeat(4,1fr);
    gap: .5rem; margin-bottom: 1rem;
}
.macro-chip { background: var(--surface2); border-radius: 10px; padding: .5rem .25rem; text-align: center; }
.macro-chip__val  { font-size: 1.05rem; font-weight: 700; display: block; }
.macro-chip__lab  { font-size: .65rem; color: var(--muted); }

.menge-row { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.menge-row label { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.menge-input {
    flex: 1; background: var(--surface2);
    border: 1px solid var(--border); border-radius: 10px;
    color: var(--text); font-size: 1rem; padding: .5rem .75rem;
    text-align: right;
}
.menge-unit { font-size: .85rem; color: var(--muted); }

/* ── Vision Upload ───────────────────────────────────────────── */
.vision-area {
    margin: 0 1rem 1rem;
    border: 2px dashed var(--border);
    border-radius: 16px;
    padding: 2rem 1rem;
    text-align: center;
    display: none;
}
.vision-area.visible { display: block; }
.vision-area i { font-size: 2.5rem; color: var(--muted); margin-bottom: .5rem; }
#imgPreview { max-width: 100%; border-radius: 10px; margin-top: 1rem; display: none; }

/* ── Manuelles Formular ─────────────────────────────────────── */
.kt-form { margin: 0 1rem; }
.kt-form .form-label { font-size: .82rem; color: var(--muted); margin-bottom: .25rem; }
.kt-form .form-control, .kt-form .form-select {
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text); border-radius: 12px; padding: .65rem .9rem;
}
.kt-form .form-control:focus, .kt-form .form-select:focus {
    background: var(--surface2); border-color: var(--accent);
    color: var(--text); box-shadow: 0 0 0 3px rgba(74,222,128,.15);
}
.kt-form .form-select option { background: var(--surface2); }

/* ── Verlauf ────────────────────────────────────────────────── */
.history-day {
    margin-bottom: 1rem;
}
.history-day__header {
    display: flex; justify-content: space-between; align-items: center;
    padding: .5rem 1.25rem;
    font-size: .82rem; color: var(--muted); font-weight: 600;
    text-transform: uppercase; letter-spacing: .06em;
}
.history-day__kcal { color: var(--accent); font-size: .9rem; }

/* ── Utilities ───────────────────────────────────────────────── */
.section-pad { padding: .75rem 1.25rem; }
.text-accent { color: var(--accent) !important; }
.toast-container { z-index: 9999; }
.spinner-accent { color: var(--accent); }

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--muted);
}
.empty-state i { font-size: 3rem; display: block; margin-bottom: 1rem; opacity: .4; }
.empty-state p { font-size: .9rem; }

/* ── html5-qrcode Overrides ──────────────────────────────────── */
#qr-reader {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    background: #000;
}
#qr-reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}
/* Alle eigenen UI-Elemente der Library ausblenden */
#qr-reader__dashboard,
#qr-reader__status_span,
#qr-reader__camera_selection,
#qr-reader__filescan_input,
#qr-reader img {
    display: none !important;
}

/* ── Makro-Label Fix ─────────────────────────────────────────── */
.macro-bar-label {
    font-size: .75rem;
    color: var(--muted);
    width: 52px;
    min-width: 52px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Aktivitätskalorien Badge ────────────────────────────────── */
.aktiv-badge {
    display: inline-flex; align-items: center; gap: .35rem;
    background: rgba(74,222,128,.12); border: 1px solid rgba(74,222,128,.3);
    color: var(--accent); border-radius: 20px;
    font-size: .78rem; font-weight: 600;
    padding: .25rem .75rem; margin-top: .4rem;
}

/* ── Profil-Seite ────────────────────────────────────────────── */
.profil-section-title {
    font-size: .72rem; font-weight: 700; letter-spacing: .08em;
    text-transform: uppercase; color: var(--muted);
    padding: .75rem 1.25rem .25rem;
}
.profil-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: .85rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.profil-row:first-of-type { border-top: 1px solid var(--border); }
.profil-row__label { font-size: .88rem; color: var(--muted); }
.profil-row__val   { font-size: .95rem; font-weight: 700; }
.profil-row__val.accent { color: var(--accent); }

/* ── Gewicht-Chart ───────────────────────────────────────────── */
.weight-chart-wrap {
    margin: 0 1rem .75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1rem;
    overflow: hidden;
}
