:root {
    --bg: #f1f5f9;
    --card: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --brand: #16a34a;
    --brand-d: #15803d;
    --brand-l: #dcfce7;
    --accent: #0f172a;
    --danger: #ef4444;
    --kcal: #16a34a;
    --protein: #6366f1;
    --carbs: #f59e0b;
    --fat: #ec4899;
    --radius: 18px;
    --shadow: 0 1px 3px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.05);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --header-h: 52px;
    --tabbar-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

body { min-height: 100vh; }

a { color: var(--brand-d); text-decoration: none; }

/* ---------- Header ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255,255,255,.85);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
    padding-top: var(--safe-top);
}
.app-header-inner {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
}
.brand { font-weight: 700; font-size: 19px; letter-spacing: -.02em; }
.header-link { color: var(--muted); display: flex; }

/* ---------- Main ---------- */
.app-main {
    max-width: 560px;
    margin: 0 auto;
    padding: 14px 14px calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
}
.app-main.centered {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.bottom-space { height: 8px; }

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 14px;
}
.list-title {
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.list-sub, .list-title .badge { font-weight: 600; color: var(--muted); font-size: 13px; }
.page-title { font-size: 22px; margin: 4px 2px 16px; }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%;
    padding: 14px 18px;
    border-radius: 14px;
    border: none;
    font-size: 16px; font-weight: 600;
    cursor: pointer;
    transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:disabled { background: #cbd5e1; }
.btn-ghost { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select {
    font: inherit;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background-color: #fff;
    color: var(--ink);
    width: 100%;
    appearance: none;
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-l); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%2364748b' stroke-width='2' d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* ---------- Flash ---------- */
.flash {
    padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 14px; font-weight: 500;
}
.flash-ok { background: var(--brand-l); color: var(--brand-d); }
.flash-err { background: #fee2e2; color: #b91c1c; }

/* ---------- Auth ---------- */
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card h1 { margin: 12px 0 4px; font-size: 26px; }
.auth-card form { margin-top: 22px; text-align: left; }
.auth-logo img { border-radius: 22px; box-shadow: var(--shadow); }
.plain { background: linear-gradient(160deg, #ecfdf5, #f1f5f9); }

/* ---------- Date nav ---------- */
.date-nav {
    display: flex; align-items: center; justify-content: space-between;
    margin: 2px 4px 14px;
}
.date-arrow {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; color: var(--ink); background: var(--card); box-shadow: var(--shadow);
}
.date-arrow.disabled { opacity: .35; pointer-events: none; }
.date-label { text-align: center; font-weight: 700; font-size: 17px; }
.date-label small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }

/* ---------- Kalorien-Ring ---------- */
.kcal-card { display: flex; flex-direction: column; align-items: center; padding: 22px 16px; }
.ring-wrap { position: relative; width: 180px; height: 180px; }
.ring { width: 180px; height: 180px; }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--brand); stroke-width: 12; stroke-linecap: round; transition: stroke-dasharray .6s ease; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center strong { font-size: 34px; font-weight: 800; letter-spacing: -.03em; }
.ring-center span { font-size: 13px; color: var(--muted); }
.kcal-legend { display: flex; gap: 18px; margin-top: 16px; }
.kcal-legend div { display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--muted); gap: 2px; }
.kcal-legend b { font-size: 15px; color: var(--ink); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-eat { background: var(--brand); } .dot-goal { background: var(--line); } .dot-sport { background: var(--carbs); }

/* ---------- Makros ---------- */
.macros { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.macro { padding: 12px; margin: 0; }
.macro-top { display: flex; flex-direction: column; gap: 2px; }
.macro-top span { font-size: 12px; color: var(--muted); }
.macro-top b { font-size: 16px; }
.macro-bar { height: 6px; background: var(--bg); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.macro-fill { display: block; height: 100%; border-radius: 4px; }
.m-p { background: var(--protein); } .m-c { background: var(--carbs); } .m-f { background: var(--fat); }
.macro small { font-size: 11px; color: var(--muted); }

/* ---------- Stats row ---------- */
.stats-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { margin: 0; padding: 14px 8px; text-align: center; display: flex; flex-direction: column; gap: 2px; align-items: center; }
.stat-ico { font-size: 20px; }
.stat b { font-size: 17px; }
.stat span:last-child { font-size: 11px; color: var(--muted); }

/* ---------- Lists / rows ---------- */
.list-card { padding-bottom: 6px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.list-card .row:first-of-type, .card > .row:first-of-type { border-top: none; }
.row-thumb { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; flex: none; }
.row-main { flex: 1; min-width: 0; }
.row-main b { display: block; font-size: 15px; }
.row-main small { color: var(--muted); font-size: 12px; }
.row-del { background: none; border: none; color: var(--muted); font-size: 16px; padding: 8px; width: auto; cursor: pointer; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 40px 10px; }
.empty p { color: var(--muted); margin-bottom: 16px; }
.empty .btn { margin-bottom: 10px; }

/* ---------- Upload ---------- */
.photo-drop { display: block; cursor: pointer; }
.photo-placeholder {
    border: 2px dashed var(--line); border-radius: 16px;
    padding: 44px 16px; text-align: center; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    background: var(--bg);
}
#photoPreview { width: 100%; border-radius: 16px; display: block; }
.manual-card summary { font-weight: 600; cursor: pointer; padding: 4px 0; }
.manual-card form { margin-top: 14px; }

/* ---------- Confirm / food items ---------- */
.confirm-img { width: 100%; border-radius: 14px; margin-top: 10px; }
.note { background: #fffbeb; border-radius: 10px; padding: 8px 10px; }
.food-item-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.food-name { font-weight: 700; }
.food-remove { flex: none; flex-direction: row; align-items: center; gap: 4px; font-size: 12px; }
.food-remove input { width: auto; }
.amount-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.amount-label { font-size: 13px; }
.amount-ctrl { display: flex; align-items: center; gap: 8px; }
.amount-input { width: 84px; text-align: center; font-weight: 600; }
.step-btn { width: 40px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 22px; cursor: pointer; flex: none; padding: 0; }
.nutri-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.nutri { background: var(--bg); border-radius: 12px; padding: 10px 6px; text-align: center; }
.nutri b { display: block; font-size: 16px; }
.nutri.kcal { background: var(--brand-l); color: var(--brand-d); }
.nutri span { font-size: 11px; color: var(--muted); }
.nutri.kcal span { color: var(--brand-d); }
.confirm-total { display: flex; align-items: center; justify-content: space-between; font-size: 17px; }
.confirm-total b { font-size: 20px; color: var(--brand-d); }
.confirm-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

/* ---------- History ---------- */
.segmented { display: flex; background: var(--card); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); margin-bottom: 14px; }
.seg { flex: 1; text-align: center; padding: 9px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg.active { background: var(--brand); color: #fff; }
.chart-card canvas { width: 100% !important; }

/* ---------- Settings ---------- */
.sport-type-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.sport-type-row:first-of-type { border-top: none; }
.sport-type-row.add { border-top: 1px solid var(--line); padding-top: 12px; }
.st-name { flex: 1; }
.st-kpm { width: 92px; flex: none; }
.icon-btn { width: 42px; height: 44px; flex: none; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 17px; cursor: pointer; padding: 0; }
.icon-btn.add-btn { background: var(--brand); color: #fff; border: none; }
.icon-btn.danger { color: var(--danger); }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 700; }
.badge.ok { background: var(--brand-l); color: var(--brand-d); }
.badge.warn { background: #fef3c7; color: #b45309; }
.account-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.account-card .btn { width: auto; }

/* ---------- FAB-Auswahl (Essen | Sport, 50/50) ---------- */
.fab-sheet { position: fixed; inset: 0; z-index: 90; display: none; }
.fab-sheet.show { display: block; }
.fab-sheet-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(2px); }
.fab-split {
    position: absolute; left: 0; right: 0;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 78px);
    display: flex; gap: 12px; padding: 0 14px;
    max-width: 560px; margin: 0 auto;
    animation: sheetUp .18s ease;
}
.fab-choice {
    flex: 1; background: var(--card); color: var(--ink);
    border-radius: 20px; padding: 26px 12px;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    box-shadow: var(--shadow); text-align: center;
}
.fab-choice:active { transform: scale(.97); }
.fab-choice b { font-size: 18px; }
.fab-choice span { font-size: 12px; color: var(--muted); }
.choice-food svg { color: var(--fat); }
.choice-sport svg { color: var(--brand); }
.fab-cancel {
    position: absolute; left: 14px; right: 14px; max-width: 532px; margin: 0 auto;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
    padding: 14px; border: none; border-radius: 14px;
    background: var(--card); color: var(--ink); font-weight: 600; font-size: 16px;
    box-shadow: var(--shadow); cursor: pointer; animation: sheetUp .18s ease;
}
@keyframes sheetUp { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Sprach-/Beschreibungsfeld ---------- */
.voice-field { position: relative; }
textarea {
    font: inherit; width: 100%;
    padding: 13px 54px 13px 14px;
    border: 1px solid var(--line); border-radius: 12px;
    background-color: #fff; color: var(--ink);
    resize: vertical; min-height: 78px;
}
textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-l); }
.mic-btn {
    position: absolute; right: 8px; bottom: 8px;
    width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--line); background: var(--bg); color: var(--ink);
    display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.mic-btn.listening { background: var(--danger); color: #fff; border-color: var(--danger); animation: micpulse 1s infinite; }
@keyframes micpulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

/* ---------- Verarbeitungs-Overlay ---------- */
.overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(15,23,42,.55);
    backdrop-filter: blur(3px);
    display: none; align-items: center; justify-content: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.overlay.show { display: flex; }
.overlay-box {
    background: var(--card); color: var(--ink);
    border-radius: 20px; padding: 28px 34px;
    display: flex; flex-direction: column; align-items: center; gap: 16px;
    box-shadow: var(--shadow); max-width: 80%;
}
.overlay-box p { margin: 0; font-weight: 600; text-align: center; }
.spinner {
    width: 42px; height: 42px; border-radius: 50%;
    border: 4px solid var(--line); border-top-color: var(--brand);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tabbar ---------- */
.tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255,255,255,.92);
    backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--line);
    display: flex; align-items: stretch;
    max-width: 560px; margin: 0 auto;
}
.tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 600; position: relative;
}
.tab.active { color: var(--brand-d); }
.tab-fab {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--brand); color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 18px rgba(22,163,74,.4);
    margin-top: -22px;
}
.tab:nth-child(3) { color: #fff; }

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220; --card: #131c2e; --ink: #e8edf5; --muted: #8b97ab;
        --line: #24304a; --brand-l: #14311f; --accent: #e8edf5;
    }
    .app-header, .tabbar { background: rgba(19,28,46,.9); }
    input, select, textarea { background-color: #0f1828; }
    .plain { background: linear-gradient(160deg, #0b1220, #0f1a12); }
    select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%238b97ab' stroke-width='2' d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); }
}
