/* HealthTracker – Modern Health-App Theme (mobile-first, Dark Mode automatisch) */

:root {
    /* Flächen */
    --bg: #eef1f4;
    --bg-2: #e7ebf0;
    --card: #ffffff;
    --card-2: #f7f9fb;
    --line: #e4e8ed;
    --line-strong: #d4dae1;

    /* Text */
    --ink: #131b24;
    --ink-soft: #44515f;
    --muted: #7c8896;

    /* Akzent (frisches Emerald/Teal mit Verlauf) */
    --accent: #0fb08a;
    --accent-2: #0aa3a6;
    --accent-ink: #ffffff;
    --accent-soft: rgba(15, 176, 138, 0.12);
    --accent-grad: linear-gradient(135deg, #12b98c 0%, #0a9fb0 100%);

    /* Status */
    --danger: #d64545;
    --danger-soft: #fdeceb;
    --ok: #0fb08a;
    --ok-soft: #e3f6ef;
    --info: #2f6fed;
    --info-soft: #e9f0fe;

    /* Form */
    --radius: 18px;
    --radius-sm: 12px;
    --radius-pill: 999px;
    --tabbar-h: 64px;
    --shadow-sm: 0 1px 2px rgba(20, 30, 45, 0.06), 0 1px 3px rgba(20, 30, 45, 0.05);
    --shadow-md: 0 6px 18px rgba(20, 30, 45, 0.08), 0 2px 6px rgba(20, 30, 45, 0.05);
    --shadow-accent: 0 8px 20px rgba(15, 176, 138, 0.30);
    --ring: 0 0 0 3px var(--accent-soft);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1217;
        --bg-2: #0a0e12;
        --card: #161d24;
        --card-2: #1c252e;
        --line: #26313b;
        --line-strong: #313e4a;

        --ink: #eaf0f5;
        --ink-soft: #b8c4ce;
        --muted: #8593a0;

        --accent: #1bc79a;
        --accent-2: #16b6bd;
        --accent-soft: rgba(27, 199, 154, 0.16);
        --accent-grad: linear-gradient(135deg, #18c79a 0%, #12b3c4 100%);

        --danger: #f06a6a;
        --danger-soft: #2c1a1a;
        --ok-soft: #12281f;
        --info-soft: #15233f;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
        --shadow-accent: 0 8px 20px rgba(27, 199, 154, 0.22);
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background:
        radial-gradient(1200px 600px at 100% -10%, var(--accent-soft), transparent 60%),
        var(--bg);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--accent-2); }

/* ---------- App-Bar ---------- */
.appbar {
    position: sticky; top: 0; z-index: 20;
    height: 56px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 18px;
    background: color-mix(in srgb, var(--card) 82%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line);
}
.appbar__brand {
    font-weight: 800; font-size: 1.12rem; letter-spacing: -0.02em;
    display: flex; align-items: center; gap: 8px;
}
.appbar__brand::before {
    content: ""; width: 18px; height: 18px; border-radius: 6px;
    background: var(--accent-grad); box-shadow: var(--shadow-accent);
}
.btn-link {
    background: none; border: 0; cursor: pointer;
    color: var(--muted); font-size: .92rem; font-weight: 600;
    padding: 8px 10px; border-radius: var(--radius-sm);
    transition: background .15s ease, color .15s ease;
}
.btn-link:hover { color: var(--ink); background: var(--card-2); }

/* ---------- Content ---------- */
.content {
    max-width: 720px; margin: 0 auto;
    padding: 20px 16px calc(var(--tabbar-h) + 28px);
    animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Bottom-Tabs ---------- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    height: var(--tabbar-h);
    display: flex; gap: 4px; padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--card) 88%, transparent);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--line);
}
.tabbar__link {
    flex: 1; display: flex; align-items: center; justify-content: center;
    text-decoration: none; color: var(--muted);
    font-size: .82rem; font-weight: 600;
    border-radius: 14px;
    transition: color .15s ease, background .15s ease, transform .1s ease;
}
.tabbar__link:active { transform: scale(.96); }
.tabbar__link.is-active { color: var(--accent-ink); background: var(--accent-grad); box-shadow: var(--shadow-accent); }

/* ---------- Karten ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}
.section-title {
    font-size: .78rem; margin: 0 0 14px;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: .08em; font-weight: 700;
}

/* ---------- Formulare ---------- */
label { display: block; font-weight: 600; margin-bottom: 7px; color: var(--ink-soft); }
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }

input[type=number], input[type=text], input[type=email],
input[type=password], input[type=time], input[type=date], textarea {
    width: 100%; padding: 14px 15px; font-size: 1.02rem;
    color: var(--ink); background: var(--card-2);
    border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus {
    outline: none; border-color: var(--accent);
    background: var(--card); box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
::placeholder { color: var(--muted); opacity: .8; }
.field__error { color: var(--danger); font-size: .85rem; margin-top: 6px; font-weight: 600; }
.field-hint { display: block; color: var(--muted); font-size: .8rem; margin-top: 6px; }

/* ---------- Pills (Skalen) ---------- */
.pillrow { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
    flex: 1 1 52px; min-width: 46px; padding: 13px 0; text-align: center;
    border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    background: var(--card-2); color: var(--ink-soft);
    font-size: 1rem; font-weight: 700; cursor: pointer;
    transition: transform .08s ease, background .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.pill:hover { border-color: var(--line-strong); }
.pill:active { transform: scale(.94); }
.pill.is-selected {
    background: var(--accent-grad); color: var(--accent-ink);
    border-color: transparent; box-shadow: var(--shadow-accent);
}

/* ---------- Toggles ---------- */
.toggle { display: flex; align-items: center; gap: 12px; }
.toggle input[type=checkbox] {
    width: 24px; height: 24px; accent-color: var(--accent);
    cursor: pointer; flex: none;
}
.toggle label { margin: 0; color: var(--ink); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%; padding: 16px; font-size: 1.06rem; font-weight: 700;
    color: var(--accent-ink); background: var(--accent-grad);
    border: 0; border-radius: 14px; cursor: pointer;
    box-shadow: var(--shadow-accent);
    transition: transform .1s ease, filter .15s ease, box-shadow .15s ease;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-accent), var(--ring); }
.btn--ghost {
    background: var(--card); color: var(--accent-2);
    border: 1.5px solid var(--accent); box-shadow: none;
}

/* Sticky-Speicherleiste schwebt über den Tabs */
.save-bar {
    position: sticky; bottom: calc(var(--tabbar-h) + 10px);
    padding-top: 10px; margin-top: 4px;
}
.save-bar .btn { box-shadow: var(--shadow-accent), var(--shadow-md); }

/* ---------- Flash-Meldungen ---------- */
.flash {
    padding: 13px 15px; border-radius: var(--radius-sm); margin-bottom: 16px;
    font-weight: 600; border: 1px solid transparent;
    display: flex; align-items: center; gap: 10px;
}
.flash::before { font-size: 1.05rem; }
.flash--ok { background: var(--ok-soft); color: #0c7a5c; border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash--ok::before { content: "✓"; }
.flash--info { background: var(--info-soft); color: #2152b8; border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.flash--info::before { content: "ℹ"; }
.flash--error { background: var(--danger-soft); color: #b3322f; border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash--error::before { content: "!"; }
@media (prefers-color-scheme: dark) {
    .flash--ok { color: #4fd9b0; }
    .flash--info { color: #8fb4ff; }
    .flash--error { color: #f59b9b; }
}

/* ---------- Stat-Tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
    position: relative; overflow: hidden;
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 16px;
    box-shadow: var(--shadow-sm);
}
.tile::after {
    content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
    background: var(--accent-grad);
}
.tile__value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; color: var(--ink); }
.tile__label { color: var(--muted); font-size: .82rem; font-weight: 600; margin-top: 2px; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th {
    color: var(--muted); font-weight: 700; font-size: .74rem;
    text-transform: uppercase; letter-spacing: .05em;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--card-2); }
td a { font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }

/* ---------- Diagramme ---------- */
canvas { max-width: 100%; }

/* ---------- Auth (Login / Install) ---------- */
.auth {
    display: flex; min-height: 100vh; min-height: 100dvh;
    align-items: center; justify-content: center; padding: 20px;
    background:
        radial-gradient(900px 500px at 50% -10%, var(--accent-soft), transparent 65%),
        var(--bg);
}
.auth__card {
    width: 100%; max-width: 380px;
    background: var(--card); border: 1px solid var(--line);
    border-radius: 22px; padding: 28px 24px;
    box-shadow: var(--shadow-md);
    animation: rise .35s ease both;
}
.auth__brand {
    text-align: center; margin: 0 0 22px;
    font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em;
    display: flex; align-items: center; justify-content: center; gap: 10px;
}
.auth__brand::before {
    content: ""; width: 26px; height: 26px; border-radius: 9px;
    background: var(--accent-grad); box-shadow: var(--shadow-accent);
}
.auth__card .btn { margin-top: 4px; }
.auth__card p { color: var(--ink-soft); }

/* ---------- Dashboard-Trend: Zeitraum + Metrik-Auswahl ---------- */
.trend-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 3px; gap: 2px; }
.seg__btn {
    border: 0; background: none; cursor: pointer;
    color: var(--muted); font-weight: 700; font-size: .82rem;
    padding: 6px 12px; border-radius: var(--radius-pill);
    transition: background .15s ease, color .15s ease;
}
.seg__btn.is-active { background: var(--accent-grad); color: var(--accent-ink); box-shadow: var(--shadow-accent); }

.metric-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.metric-chip {
    display: inline-flex; align-items: center; gap: 7px; margin: 0;
    padding: 7px 12px; font-size: .9rem; font-weight: 600; color: var(--ink-soft);
    background: var(--card-2); border: 1.5px solid var(--line); border-radius: var(--radius-pill);
    cursor: pointer; user-select: none;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.metric-chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.metric-chip__dot { width: 11px; height: 11px; border-radius: 50%; background: var(--chip, var(--accent)); opacity: .35; transition: opacity .15s ease; flex: none; }
.metric-chip:has(input:checked) { border-color: var(--chip, var(--accent)); color: var(--ink); background: color-mix(in srgb, var(--chip, var(--accent)) 12%, var(--card)); }
.metric-chip:has(input:checked) .metric-chip__dot { opacity: 1; }
.metric-chip:has(input:focus-visible) { box-shadow: var(--ring); }
.trend-empty { text-align: center; color: var(--muted); padding: 28px 0; }

/* Reduzierte Bewegung respektieren */
@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
