/* FitTrack - Modern Light/Dark CSS */
:root {
    --accent:   #22c55e;
    --accent2:  #16a34a;
    --blue:     #3b82f6;
    --orange:   #f97316;
    --red:      #ef4444;
    --purple:   #8b5cf6;
    --radius:   14px;
    --nav-h:    64px;
    --trans:    .2s ease;
}

/* ---- LIGHT MODE ---- */
:root, [data-theme="light"] {
    --bg:       #f4f6f9;
    --bg2:      #ffffff;
    --bg3:      #eef0f4;
    --card:     #ffffff;
    --border:   #e2e6ed;
    --text:     #0f1923;
    --muted:    #6b7a90;
    --shadow:   0 2px 12px rgba(0,0,0,.07);
    --shadow-lg:0 8px 32px rgba(0,0,0,.10);
}

/* ---- DARK MODE ---- */
[data-theme="dark"] {
    --bg:       #0d1117;
    --bg2:      #161b22;
    --bg3:      #1c2330;
    --card:     #161b22;
    --border:   #2d3748;
    --text:     #e6edf3;
    --muted:    #7d8590;
    --shadow:   0 2px 12px rgba(0,0,0,.3);
    --shadow-lg:0 8px 32px rgba(0,0,0,.5);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:       #0d1117;
        --bg2:      #161b22;
        --bg3:      #1c2330;
        --card:     #161b22;
        --border:   #2d3748;
        --text:     #e6edf3;
        --muted:    #7d8590;
        --shadow:   0 2px 12px rgba(0,0,0,.3);
        --shadow-lg:0 8px 32px rgba(0,0,0,.5);
    }
}

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

html { -webkit-text-size-adjust: 100%; touch-action: pan-y; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    font-size: 15px;
    line-height: 1.6;
    overflow-x: hidden;
    padding-bottom: env(safe-area-inset-bottom);
    transition: background var(--trans), color var(--trans);
}

/* =====================
   LAYOUT
   ===================== */
.app-wrapper { display: flex; min-height: 100vh; }

.main {
    flex: 1;
    width: 100%;
    max-width: 100vw;
    padding: 16px 16px calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
    overflow-x: hidden;
}

/* =====================
   BOTTOM NAV
   ===================== */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    justify-content: space-around;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 15px 0;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 0;
    flex: 1;
    cursor: pointer;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .02em;
    border: none;
    background: none;
    transition: color var(--trans);
    -webkit-tap-highlight-color: transparent;
    min-height: var(--nav-h);
}

.nav-item .icon { font-size: 22px; line-height: 1; }
.nav-item.active { color: var(--accent); }

/* SIDEBAR (desktop) */
.sidebar { display: none; }

/* =====================
   PAGE
   ===================== */
.page { display: none; }
.page.active { display: block; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-top: 4px;
}

.page-title { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }

/* =====================
   THEME TOGGLE
   ===================== */
.theme-toggle {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg2);
    color: var(--muted);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px;
    transition: all var(--trans);
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}
.theme-toggle:active { transform: scale(.92); }

/* =====================
   STATS GRID
   ===================== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: var(--radius) var(--radius) 0 0;
}

.stat-cal::before  { background: var(--accent); }
.stat-prot::before { background: var(--blue); }
.stat-carb::before { background: var(--orange); }
.stat-fat::before  { background: var(--purple); }

.stat-label { font-size: 11px; color: var(--muted); margin-bottom: 2px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 24px; font-weight: 800; line-height: 1.1; letter-spacing: -.5px; }
.stat-sub   { font-size: 11px; color: var(--muted); margin-top: 2px; }

.stat-cal  .stat-value { color: var(--accent); }
.stat-prot .stat-value { color: var(--blue); }
.stat-carb .stat-value { color: var(--orange); }
.stat-fat  .stat-value { color: var(--purple); }

/* =====================
   PROGRESS BAR
   ===================== */
.progress-bar {
    height: 4px;
    background: var(--bg3);
    border-radius: 99px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    border-radius: 99px;
    transition: width .6s cubic-bezier(.4,0,.2,1);
}

.fill-green  { background: var(--accent); }
.fill-blue   { background: var(--blue); }
.fill-orange { background: var(--orange); }
.fill-purple { background: var(--purple); }
.fill-over   { background: var(--red); }

/* =====================
   DATE NAV
   ===================== */
.date-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 8px;
    box-shadow: var(--shadow);
}

.date-nav button {
    background: var(--bg3);
    border: none;
    color: var(--text);
    border-radius: 9px;
    padding: 7px 13px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    transition: background var(--trans);
}

.date-nav button:active { background: var(--border); }

.date-display {
    font-size: 14px;
    font-weight: 700;
    flex: 1;
    text-align: center;
    letter-spacing: -.2px;
}

.btn-today {
    font-size: 12px !important;
    font-weight: 600 !important;
    color: var(--accent) !important;
    background: rgba(34,197,94,.1) !important;
    padding: 6px 10px !important;
}

/* =====================
   MEAL SECTIONS
   ===================== */
.meal-sections { display: flex; flex-direction: column; gap: 10px; }

.meal-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.meal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 16px;
}

.meal-type-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: -.1px;
}

.meal-type-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-breakfast { background: var(--orange); }
.dot-lunch     { background: var(--accent); }
.dot-dinner    { background: var(--blue); }
.dot-snack     { background: var(--purple); }

.meal-kcal {
    font-size: 13px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-add-meal {
    background: var(--accent);
    border: none;
    color: #fff;
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity var(--trans);
}
.btn-add-meal:active { opacity: .8; }

.meal-items { padding: 0 16px 12px; }

.meal-item {
    display: flex;
    align-items: center;
    padding: 9px 0;
    border-top: 1px solid var(--border);
    gap: 10px;
}

.meal-item-name {
    flex: 1;
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
}

.meal-item-name > div:first-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.meal-item-meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 1px;
}

.meal-item-qty  { font-size: 12px; color: var(--muted); white-space: nowrap; font-weight: 500; }
.meal-item-kcal { font-size: 14px; font-weight: 800; color: var(--accent); white-space: nowrap; min-width: 38px; text-align: right; }

.btn-remove {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--trans);
}
.btn-remove:active { color: var(--red); }

.empty {
    text-align: center;
    padding: 16px 0 8px;
    color: var(--muted);
    font-size: 13px;
}

/* =====================
   MODAL (bottom sheet)
   ===================== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 500;
    display: none;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 22px 22px 0 0;
    width: 100%;
    max-width: 600px;
    /* PEŁNA WYSOKOŚĆ - od dołu do góry ekranu */
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-handle {
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 12px auto 4px;
    flex-shrink: 0;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 18px 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -.2px;
}

.modal-close {
    width: 30px; height: 30px;
    border-radius: 50%;
    border: none;
    background: var(--bg3);
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    -webkit-tap-highlight-color: transparent;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 18px calc(16px + env(safe-area-inset-bottom));
}

/* =====================
   FORMS
   ===================== */
.form-group { margin-bottom: 12px; }

.form-label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.form-input, .form-select {
    width: 100%;
    background: var(--bg3);
    border: 1.5px solid transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 11px 13px;
    font-size: 16px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color var(--trans), background var(--trans);
}

.form-input:focus, .form-select:focus {
    border-color: var(--accent);
    background: var(--bg2);
}

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7a90' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    padding-right: 34px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 12px;
    padding: 13px 18px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity var(--trans), transform var(--trans);
    -webkit-tap-highlight-color: transparent;
    letter-spacing: -.1px;
}

.btn:active { opacity: .8; transform: scale(.98); }
.btn-primary   { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1.5px solid var(--border); }
.btn-full { width: 100%; }

/* =====================
   SEARCH
   ===================== */
.search-wrapper { position: relative; margin-bottom: 10px; }
.search-input { padding-left: 40px !important; }
.search-icon {
    position: absolute; left: 13px; top: 50%;
    transform: translateY(-50%);
    color: var(--muted); font-size: 15px;
    pointer-events: none;
}

.search-results {
    max-height: 220px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    background: var(--bg2);
    display: none;
    margin-bottom: 10px;
    box-shadow: var(--shadow-lg);
}

.search-results.open { display: block; }

.search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    gap: 10px;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--trans);
}

.search-item:last-child { border-bottom: none; }
.search-item:active { background: var(--bg3); }

.search-item-name { font-size: 14px; font-weight: 600; }
.search-item-sub  { font-size: 11px; color: var(--muted); margin-top: 1px; }
.search-item-kcal { font-size: 13px; color: var(--accent); font-weight: 800; white-space: nowrap; flex-shrink: 0; }

/* =====================
   SCANNER
   ===================== */
.scanner-wrap {
    position: relative;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 10px;
}

#scanner-video {
    width: 100%;
    display: block;
    /* WYŻSZY SKANER */
    min-height: 300px;
    max-height: 380px;
    object-fit: cover;
}

.scanner-frame-wrap {
    position: absolute; inset: 0;
    pointer-events: none;
    display: flex; align-items: center; justify-content: center;
}

.scanner-frame {
    width: 75%;
    max-width: 300px;
    height: 130px;
    position: relative;
}

/* Rogi ramki */
.scanner-frame::before,
.scanner-frame::after,
.scanner-frame > span::before,
.scanner-frame > span::after {
    content: '';
    position: absolute;
    width: 24px; height: 24px;
    border-color: #22c55e;
    border-style: solid;
}
.scanner-frame::before  { top:0; left:0;  border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.scanner-frame::after   { top:0; right:0; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.scanner-frame > span::before { bottom:0; left:0;  border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.scanner-frame > span::after  { bottom:0; right:0; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

/* Linia skanowania */
.scanner-line {
    position: absolute;
    left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, #22c55e, transparent);
    animation: scan 2s ease-in-out infinite;
    top: 50%;
}

@keyframes scan {
    0%, 100% { top: 15%; opacity: 1; }
    50% { top: 85%; opacity: .7; }
}

.scanner-shadow {
    position: absolute; inset: 0;
    box-shadow: inset 0 0 0 9999px rgba(0,0,0,.45);
    pointer-events: none;
}

#scanner-status {
    position: absolute;
    bottom: 10px; left: 0; right: 0;
    text-align: center;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-shadow: 0 1px 6px rgba(0,0,0,.9);
    letter-spacing: -.1px;
}

#scanner-canvas { display: none; }

/* =====================
   MACRO BOX
   ===================== */
.macro-box {
    background: var(--bg3);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 14px;
}

.macro-box-title {
    font-size: 11px;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: 12px;
}

/* =====================
   WEIGHT PAGE
   ===================== */
.weight-input-big {
    font-size: 36px !important;
    font-weight: 800 !important;
    text-align: center !important;
    color: var(--accent) !important;
    letter-spacing: -1px !important;
}

.weight-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.weight-table th {
    text-align: left;
    padding: 8px 10px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    border-bottom: 1.5px solid var(--border);
}

.weight-table td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--border);
}

.weight-table tr:last-child td { border-bottom: none; }

.bmi-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 700;
}

.bmi-under  { background: rgba(59,130,246,.12); color: var(--blue); }
.bmi-normal { background: rgba(34,197,94,.12);  color: var(--accent); }
.bmi-over   { background: rgba(249,115,22,.12); color: var(--orange); }
.bmi-obese  { background: rgba(239,68,68,.12);  color: var(--red); }

/* =====================
   CHARTS
   ===================== */
.chart-wrapper {
    position: relative;
    height: 200px;
    margin-top: 10px;
}

/* =====================
   CARDS
   ===================== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: 12px;
}

/* =====================
   SETTINGS
   ===================== */
.settings-section { margin-bottom: 24px; }

.settings-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* =====================
   TOAST
   ===================== */
.toast {
    position: absolute;
    top: 24px;
    left: 16px; right: 16px;
    background: var(--text);
    color: var(--bg);
    border-radius: 12px;
    padding: 13px 16px;
    font-size: 14px;
    font-weight: 600;
    z-index: 9999;
    transform: translateY(20px);
    opacity: 0;
    transition: all .28s cubic-bezier(.34,1.56,.64,1);
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 480px;
    margin: 0 auto;
    box-shadow: var(--shadow-lg);
}

.toast.show { transform: translateY(0); opacity: 1; }

.toast.success { background: var(--accent); color: #fff; }
.toast.error   { background: var(--red);    color: #fff; }
.toast.info    { background: var(--blue);   color: #fff; }

/* =====================
   DESKTOP (≥ 768px)
   ===================== */
@media (min-width: 768px) {
    body { padding-bottom: 0; }
    .bottom-nav { display: none; }

    .sidebar {
        display: flex;
        flex-direction: column;
        width: 230px;
        background: var(--card);
        border-right: 1px solid var(--border);
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 100;
    }

    .sidebar-logo {
        padding: 24px 20px 20px;
        font-size: 19px;
        font-weight: 800;
        color: var(--accent);
        letter-spacing: -.5px;
        display: flex;
        align-items: center;
        gap: 8px;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-logo span { color: var(--text); }

    .sidebar-nav {
        flex: 1;
        padding: 12px;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .sidebar-bottom {
        padding: 12px;
        border-top: 1px solid var(--border);
    }

    .sidebar .nav-item {
        flex-direction: row;
        justify-content: flex-start;
        gap: 10px;
        padding: 10px 14px;
        border-radius: 10px;
        font-size: 14px;
        min-height: unset;
        color: var(--muted);
        letter-spacing: normal;
    }

    .sidebar .nav-item .icon { font-size: 18px; width: 22px; text-align: center; }
    .sidebar .nav-item:hover { background: var(--bg3); color: var(--text); }
    .sidebar .nav-item.active { background: rgba(34,197,94,.1); color: var(--accent); }

    .main {
        margin-left: 230px;
        padding: 28px 32px;
        max-width: calc(900px + 230px);
    }

    .stats-grid { grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 20px; }
    .stat-value { font-size: 28px; }
    .form-row { grid-template-columns: 1fr 1fr; }

    .modal-overlay { align-items: center; }

    .modal {
        border-radius: 20px;
        max-width: 500px;
        height: auto;
        max-height: 90vh;
    }

    .modal-body { padding: 16px 22px 22px; }

    .modal-handle { display: none; }

    .toast { top: 24px; left: auto; right: 28px; max-width: 340px; }
}
