/* ============================================================
   Fitness Planner — mobile-first dark design system
   ============================================================ */

:root {
    color-scheme: dark;

    /* Surfaces & ink (aligned with validated dark chart chrome) */
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --border: rgba(255, 255, 255, 0.10);
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;

    /* Accent (UI chrome only — never a chart series color) */
    --accent: #a3e635;
    --accent-ink: #10160a;
    --accent-soft: rgba(163, 230, 53, 0.14);

    /* Chart series (validated dark categorical slots 1–3) */
    --series-1: #3987e5;   /* Cardio  */
    --series-2: #d95926;   /* Strength */
    --series-3: #199e70;   /* Flex    */

    /* Status */
    --good: #0ca30c;
    --warning: #fab219;
    --danger: #d03b3b;

    --radius: 16px;
    --radius-sm: 10px;
    --nav-height: 64px;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The `hidden` attribute only sets `display: none` from the UA stylesheet, so
   any author rule with a `display` beats it. Everything toggled through
   `el.hidden` here is flex, so without this they never actually hide. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    min-height: 100dvh;
}

/* ---------- App shell ---------- */

.app-shell {
    max-width: 480px;
    margin: 0 auto;
    /* The top inset matters once installed to the iOS home screen: the status
       bar is translucent there, so without it the header sits under the clock
       and the Dynamic Island. It resolves to 0 in a normal browser tab. */
    padding: calc(20px + env(safe-area-inset-top)) 16px calc(var(--nav-height) + 28px);
    min-height: 100dvh;
}

.app-shell.no-nav { padding-bottom: 32px; }

/* ---------- Typography ---------- */

h1 { font-size: 1.65rem; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 600; }

.page-header { margin-bottom: 20px; }
.page-header .eyebrow {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.page-header .sub { color: var(--ink-2); font-size: 0.9rem; margin-top: 4px; }

.text-muted { color: var(--muted); }
.text-soft { color: var(--ink-2); }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 12px;
}

/* ---------- Stat tiles ---------- */

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat-row.cols-3 { grid-template-columns: repeat(3, 1fr); }

.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}
.stat-tile .value { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.stat-tile .label { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

/* ---------- Pills & badges ---------- */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--ink-2);
}
.pill.success { background: rgba(12, 163, 12, 0.15); color: #4ade4a; }
.pill.warning { background: rgba(250, 178, 25, 0.15); color: var(--warning); }
.pill.danger  { background: rgba(208, 59, 59, 0.18);  color: #e66767; }
.pill.accent  { background: var(--accent-soft); color: var(--accent); }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 52px;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary {
    background: var(--surface-2);
    color: var(--ink);
    border: 1px solid var(--border);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Forms ---------- */

.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="number"] {
    width: 100%;
    min-height: 52px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font: inherit;
    font-size: 1rem;
}
.field input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: transparent;
}
.field .hint { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Choice chips (radio) */
.chip-group { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chip-group input[type="radio"] { position: absolute; opacity: 0; }
.chip {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.chip .chip-title { font-weight: 700; font-size: 0.92rem; }
.chip .chip-sub { font-size: 0.75rem; color: var(--muted); }
.chip-group input:checked + .chip {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.chip-group input:focus-visible + .chip { outline: 2px solid var(--accent); }

/* Range slider */
input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    min-height: 32px;
}
.range-value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--accent);
    min-width: 2ch;
    text-align: center;
}

/* ---------- Level switch ---------- */

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    gap: 4px;
    margin-bottom: 16px;
}
.segmented button,
.segmented a {
    border: none;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 10px 6px;
    border-radius: 7px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}
.segmented button.active,
.segmented a.active { background: var(--accent); color: var(--accent-ink); }

.segmented.cols-2 { grid-template-columns: repeat(2, 1fr); }

/* ---------- Exercise cards ---------- */

.category-block { margin-bottom: 18px; }
.category-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.category-dot { width: 10px; height: 10px; border-radius: 50%; }
.category-dot.cardio   { background: var(--series-1); }
.category-dot.strength { background: var(--series-2); }
.category-dot.flex     { background: var(--series-3); }

.exercise-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 8px;
    cursor: pointer;
    font: inherit;
    color: var(--ink);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.exercise-card .ex-info { flex: 1; min-width: 0; }
.exercise-card .ex-name { font-weight: 700; font-size: 0.95rem; }
.exercise-card .ex-meta { font-size: 0.78rem; color: var(--muted); }
.exercise-card .ex-kcal {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--ink-2);
    white-space: nowrap;
}
.exercise-card .check {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--grid);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.exercise-card .check svg { width: 14px; height: 14px; opacity: 0; stroke: var(--accent-ink); }
.exercise-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.exercise-card.selected .check { background: var(--accent); border-color: var(--accent); }
.exercise-card.selected .check svg { opacity: 1; }
.exercise-card.selected .ex-kcal { color: var(--accent); }

/* ---------- Sticky summary bar (workout builder) ---------- */

.summary-bar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--nav-height) + 10px);
    width: min(calc(100% - 24px), 456px);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    z-index: 40;
}
.summary-bar .totals { flex: 1; }
.summary-bar .totals .kcal { font-size: 1.25rem; font-weight: 800; }
.summary-bar .totals .count { font-size: 0.75rem; color: var(--muted); }
.summary-bar .btn { width: auto; min-height: 44px; padding: 10px 22px; font-size: 0.9rem; }

/* ---------- Progress ring ---------- */

.ring-wrap { display: flex; align-items: center; gap: 18px; }
.ring { transform: rotate(-90deg); }
.ring .track { stroke: var(--grid); }
.ring .fill {
    stroke: var(--accent);
    stroke-linecap: round;
    transition: stroke-dashoffset 0.6s ease;
}

/* ---------- Charts & bars ---------- */

.chart-box { position: relative; width: 100%; height: 220px; }

.hbar-row { display: grid; grid-template-columns: 88px 1fr 56px; align-items: center; gap: 10px; margin-bottom: 10px; }
.hbar-row .hbar-label { font-size: 0.82rem; color: var(--ink-2); font-weight: 600; }
.hbar-track { background: var(--grid); border-radius: 4px; height: 10px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 4px; min-width: 2px; }
.hbar-row .hbar-value { font-size: 0.82rem; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- History list ---------- */

.session-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--grid);
}
.session-row:last-child { border-bottom: none; }
.session-row .s-date { flex: 1; }
.session-row .s-date .d { font-weight: 700; font-size: 0.92rem; }
.session-row .s-date .m { font-size: 0.78rem; color: var(--muted); }
.session-row .s-kcal { font-weight: 800; color: var(--accent); white-space: nowrap; }

/* ---------- Bottom navigation ---------- */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(20, 20, 19, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    z-index: 50;
}
.bottom-nav .nav-item {
    flex: 1;
    max-width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
}
.bottom-nav .nav-item svg { width: 24px; height: 24px; }
.bottom-nav .nav-item.active { color: var(--accent); }

/* ---------- Done screen ---------- */

.done-hero { text-align: center; padding: 40px 0 24px; }
.done-hero .done-check {
    width: 92px;
    height: 92px;
    margin: 0 auto 18px;
    border-radius: 50%;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.done-hero .done-check svg { width: 44px; height: 44px; stroke: var(--accent); }
.done-hero .kcal-big { font-size: 3rem; font-weight: 800; letter-spacing: -0.03em; }
.done-hero .kcal-unit { font-size: 1rem; color: var(--muted); font-weight: 600; }

@keyframes pop {
    0% { transform: scale(0.4); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ---------- Profile ---------- */

.avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 800;
}

/* ---------- Utility ---------- */

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Food catalogue ---------- */

.food-search {
    width: 100%;
    min-height: 46px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font: inherit;
    margin-bottom: 12px;
}
.food-search:focus { outline: none; border-color: var(--accent); }

.cat-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 12px;
    scrollbar-width: none;
}
.cat-scroll::-webkit-scrollbar { display: none; }
.cat-scroll button {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--ink-2);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}
.cat-scroll button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.food-card {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.food-card:active { transform: scale(0.99); }
.food-card .f-info { flex: 1; min-width: 0; }
.food-card .f-name { font-weight: 700; font-size: 0.92rem; }
.food-card .f-meta { font-size: 0.76rem; color: var(--muted); }
.food-card .f-kcal { font-weight: 800; color: var(--accent); font-size: 0.9rem; white-space: nowrap; }

.food-empty { text-align: center; color: var(--muted); font-size: 0.86rem; padding: 28px 0; }

/* ---------- Portion sheet ---------- */

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 55; }

.food-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.45);
}
.food-sheet .sheet-name { font-size: 1.05rem; font-weight: 800; }
.food-sheet select,
.food-sheet input[type="text"] {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font: inherit;
}
.food-sheet select:focus,
.food-sheet input:focus { outline: none; border-color: var(--accent); }
.food-sheet .sheet-kcal { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.food-sheet .sheet-macros { font-size: 0.78rem; color: var(--muted); }

/* ---------- Today's intake list ---------- */

.intake-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.intake-row:last-child { border-bottom: none; }
.intake-row .i-info { flex: 1; min-width: 0; }
.intake-row .i-name { font-weight: 600; font-size: 0.88rem; }
.intake-row .i-meta { font-size: 0.74rem; color: var(--muted); }
.intake-row .i-kcal { font-weight: 800; color: var(--accent); font-size: 0.88rem; white-space: nowrap; }
.intake-row .i-del {
    min-height: 36px;
    padding: 6px 8px;
    background: none;
    border: none;
    color: var(--muted);
    font: inherit;
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
}
.intake-row .i-del:hover { color: var(--danger); }

/* Two-segment budget meter: the track holds an in-budget and an overage part,
   so the split renders as one continuous bar with a single outer radius. */
.hbar-track.split { display: flex; }
.hbar-track.split .hbar-fill { border-radius: 0; min-width: 0; }

/* ---------- Macro split ---------- */

/* Label above the bar, not beside it: no fixed column width fits "Protein",
   "Kohlenhydrate" and "Węglowodany" alike. */
.macro-line { margin-bottom: 14px; }
.macro-line:last-of-type { margin-bottom: 4px; }
.macro-line .m-name { font-size: 0.82rem; font-weight: 600; color: var(--ink-2); }
.macro-line .m-value { font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Quick log ---------- */

.quick-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
}
.quick-scroll::-webkit-scrollbar { display: none; }
.quick-chip {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-height: 48px;
    max-width: 150px;
    padding: 8px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.quick-chip:active { transform: scale(0.98); }
.quick-chip .q-name {
    font-size: 0.82rem;
    font-weight: 700;
    max-width: 122px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.quick-chip .q-kcal { font-size: 0.72rem; font-weight: 700; color: var(--accent); }

/* ---------- Meals & entry selection ---------- */

/* Inline action button inside a row, against the full-width .btn default. */
.btn-inline {
    width: auto;
    min-height: 36px;
    padding: 7px 14px;
    font-size: 0.8rem;
}

.intake-row .i-pick {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
    cursor: pointer;
}

.save-meal {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.save-meal input[type="text"] {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    padding: 9px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font: inherit;
    font-size: 0.88rem;
}
.save-meal input[type="text"]:focus { outline: none; border-color: var(--accent); }
