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

/* ═══════════════════════════════════════════
   DESIGN TOKENS — LIGHT THEME (default)
   ═══════════════════════════════════════════ */
:root {
    /* Background */
    --bg-page: #f0f2f5;
    --bg-glass: rgba(255,255,255,0.55);
    --bg-glass-hover: rgba(255,255,255,0.7);
    --bg-elevated: #ffffff;
    --bg-inset: #e8eaed;
    --bg-overlay: rgba(0,0,0,0.4);

    /* Borders */
    --border-decorative: rgba(0,0,0,0.10);
    --border-input: #7e828a;
    --border-focus: #006B4E;

    /* Text */
    --text-primary: #1a1d24;
    --text-secondary: #4a4e56;
    --text-tertiary: #696d76;
    --text-inverse: #ffffff;

    /* Semantic colours */
    --color-success: #006B4E;
    --color-success-dim: rgba(0,107,78,0.12);
    --color-danger: #A12040;
    --color-danger-dim: rgba(161,32,64,0.1);
    --color-info: #2A4FA8;
    --color-info-dim: rgba(42,79,168,0.1);
    --color-warning: #7A4B00;
    --color-warning-dim: rgba(122,75,0,0.08);

    /* Accent */
    --accent: #006B4E;
    --accent-hover: #005540;
    --accent-dim: rgba(0,107,78,0.12);
    --accent-on: #ffffff;
    --accent-btn-bg: #008060;
    --accent-btn-hover: #006B4E;

    /* Typography scale */
    --font-display: 'Outfit', sans-serif;
    --font-body: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --text-4xl: 2.25rem;
    --text-3xl: 1.875rem;
    --text-2xl: 1.5rem;
    --text-xl: 1.25rem;
    --text-lg: 1.125rem;
    --text-base: 1rem;
    --text-sm: 0.875rem;
    --text-xs: 0.75rem;
    --text-2xs: 0.6875rem;

    --leading-tight: 1.2;
    --leading-normal: 1.5;
    --leading-relaxed: 1.7;

    --weight-light: 300;
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --weight-bold: 700;

    /* Spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-7: 28px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;
    --space-20: 80px;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-focus: 0 0 0 3px rgba(0,107,78,0.2);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
    --transition-slow: 0.35s ease;

    /* Layout */
    --content-max: 1100px;
    --sidebar-width: 260px;
}

/* ═══════════════════════════════════════════
   DARK THEME OVERRIDES
   ═══════════════════════════════════════════ */
[data-theme="dark"] {
    --bg-page: #0a0e1a;
    --bg-glass: rgba(255,255,255,0.06);
    --bg-glass-hover: rgba(255,255,255,0.1);
    --bg-elevated: #131722;
    --bg-inset: #0d1120;
    --bg-overlay: rgba(0,0,0,0.6);

    --border-decorative: rgba(255,255,255,0.10);
    --border-input: #606472;
    --border-focus: #00E5A0;

    --text-primary: #e8eaed;
    --text-secondary: #b0b4bc;
    --text-tertiary: #828690;
    --text-inverse: #0a0e1a;

    --color-success: #00E5A0;
    --color-success-dim: rgba(0,229,160,0.15);
    --color-danger: #FF6B8A;
    --color-danger-dim: rgba(255,107,138,0.15);
    --color-info: #5B8DEF;
    --color-info-dim: rgba(91,141,239,0.15);
    --color-warning: #FFB84D;
    --color-warning-dim: rgba(255,184,77,0.12);

    --accent: #00E5A0;
    --accent-hover: #00C98C;
    --accent-dim: rgba(0,229,160,0.15);
    --accent-on: #0a0e1a;
    --accent-btn-bg: #00E5A0;
    --accent-btn-hover: #00C98C;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 2px 12px rgba(0,0,0,0.2);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.25);
    --shadow-focus: 0 0 0 3px rgba(0,229,160,0.25);
}

/* ═══════════════════════════════════════════
   BASE STYLES
   ═══════════════════════════════════════════ */
body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ═══ ACCESSIBILITY ═══ */
.skip-link {
    position: absolute;
    top: -100px;
    left: var(--space-4);
    background: var(--accent);
    color: var(--accent-on);
    padding: var(--space-3) var(--space-6);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    font-weight: var(--weight-semibold);
    font-size: var(--text-sm);
    z-index: 200;
    text-decoration: none;
    transition: top var(--transition-fast);
}
.skip-link:focus { top: 0; }

*:focus-visible {
    outline: 3px solid var(--border-focus);
    outline-offset: 2px;
}
*:focus:not(:focus-visible) { outline: none; }

.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ═══ LAYOUT ═══ */
.container {
    position: relative;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-12) var(--space-8);
}

/* ═══ BUTTONS ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: var(--font-body);
    font-weight: var(--weight-semibold);
    font-size: var(--text-sm);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    min-height: 44px;
    padding: var(--space-3) var(--space-5);
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary {
    background: var(--accent-btn-bg);
    color: var(--accent-on);
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
    background: var(--accent-btn-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.btn-primary:active {
    transform: translateY(0);
    box-shadow: none;
}
.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border-input);
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--bg-glass-hover); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-dim); }
.btn-disabled,
.btn:disabled,
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
.btn svg {
    display: inline-block;
    vertical-align: middle;
    margin: 0 4px;
}
.btn-danger {
    background: var(--color-danger);
    color: var(--text-inverse);
    box-shadow: var(--shadow-sm);
}
.btn-danger:hover { opacity: 0.9; }
.btn-sm { min-height: 36px; padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }
.btn-lg { min-height: 52px; padding: var(--space-4) var(--space-8); font-size: var(--text-base); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* ═══ FORM INPUTS ═══ */
.form-field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.form-label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-primary); }
.form-label-req::after { content: ' *'; color: var(--color-danger); }
.form-hint { font-size: var(--text-xs); color: var(--text-tertiary); }
.form-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-base);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    min-height: 44px;
}
.form-input::placeholder { color: var(--text-tertiary); }
.form-input:hover { border-color: var(--text-secondary); }
.form-input:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
    outline: none;
}
.form-input-mono { font-family: var(--font-mono); font-size: var(--text-lg); }
.form-field-error .form-input { border-color: var(--color-danger); }
.form-field-error .form-input:focus {
    box-shadow: 0 0 0 3px rgba(161,32,64,0.15);
}
[data-theme="dark"] .form-field-error .form-input:focus {
    box-shadow: 0 0 0 3px rgba(255,107,138,0.2);
}
.form-error {
    font-size: var(--text-xs);
    color: var(--color-danger);
    font-weight: var(--weight-medium);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}
.form-error svg { width: 14px; height: 14px; flex-shrink: 0; }
.form-field-success .form-input { border-color: var(--color-success); }
.form-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-inset);
}
.form-textarea { min-height: 100px; resize: vertical; line-height: var(--leading-normal); }
.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23696d76' stroke-width='2.5' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-10);
}
[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23828690' stroke-width='2.5' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* Checkbox & Radio */
.form-check {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 44px;
    cursor: pointer;
}
.form-check-input {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-input);
    border-radius: var(--radius-sm);
    appearance: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    background: var(--bg-elevated);
    position: relative;
}
.form-check-input[type="radio"] { border-radius: var(--radius-full); }
.form-check-input:checked {
    background: var(--accent);
    border-color: var(--accent);
}
.form-check-input:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.form-check-input[type="checkbox"]:checked::after {
    width: 6px;
    height: 10px;
    border: 2px solid var(--accent-on);
    border-top: none;
    border-left: none;
    transform: translate(-50%, -60%) rotate(45deg);
}
.form-check-input[type="radio"]:checked::after {
    width: 8px;
    height: 8px;
    background: var(--accent-on);
    border-radius: var(--radius-full);
}
.form-check-label { font-size: var(--text-sm); cursor: pointer; }

/* Toggle */
.form-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 44px;
    cursor: pointer;
}
.toggle-track {
    width: 44px;
    height: 24px;
    border-radius: var(--radius-full);
    background: var(--bg-inset);
    border: 2px solid var(--border-input);
    position: relative;
    transition: all var(--transition-fast);
    cursor: pointer;
    flex-shrink: 0;
}
.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    background: var(--text-tertiary);
    transition: all var(--transition-fast);
}
.toggle-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-input:checked + .toggle-track {
    background: var(--accent);
    border-color: var(--accent);
}
.toggle-input:checked + .toggle-track::after {
    transform: translateX(20px);
    background: var(--accent-on);
}
.toggle-input:focus-visible + .toggle-track {
    outline: 3px solid var(--border-focus);
    outline-offset: 2px;
}
.toggle-label { font-size: var(--text-sm); }

/* ═══ BADGES ═══ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    padding: 3px var(--space-3);
    border-radius: var(--radius-sm);
}
.badge svg { width: 12px; height: 12px; }
.badge-success { background: var(--color-success-dim); color: var(--color-success); }
.badge-danger { background: var(--color-danger-dim); color: var(--color-danger); }
.badge-info { background: var(--color-info-dim); color: var(--color-info); }
.badge-warning { background: var(--color-warning-dim); color: var(--color-warning); }
.badge-neutral { background: var(--bg-inset); color: var(--text-secondary); }

/* ═══ ALERTS ═══ */
.alert {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
}
.alert svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.alert-content { flex: 1; }
.alert-title { font-weight: var(--weight-semibold); margin-bottom: var(--space-1); }
.alert-success {
    background: var(--color-success-dim);
    color: var(--color-success);
    border: 1px solid var(--color-success);
}
.alert-danger {
    background: var(--color-danger-dim);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}
.alert-info {
    background: var(--color-info-dim);
    color: var(--color-info);
    border: 1px solid var(--color-info);
}
.alert-warning {
    background: var(--color-warning-dim);
    color: var(--color-warning);
    border: 1px solid var(--color-warning);
}

/* ═══ CARDS ═══ */
.card {
    background: var(--bg-glass);
    border: 1px solid var(--border-decorative);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    backdrop-filter: blur(16px);
    margin-bottom: var(--space-4);
}

.glass {
    background: var(--bg-glass);
    border: 1px solid var(--border-decorative);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(16px);
}

.card h2 {
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    margin-bottom: var(--space-4);
    color: var(--text-primary);
}

/* ═══ MESSAGE STATES ═══ */
.loading, .success, .error {
    padding: var(--space-4);
    border-radius: var(--radius-md);
    margin: var(--space-2) 0;
}

.loading {
    background: var(--bg-inset);
    color: var(--text-secondary);
    text-align: center;
}

.success {
    background: var(--color-success-dim);
    color: var(--color-success);
    border: 1px solid var(--color-success);
}

.error {
    background: var(--color-danger-dim);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}

/* ═══ TOPBAR ═══ */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-10);
    gap: var(--space-4);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
}

.brand-glyph {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-success), var(--color-info));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.brand-text {
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.brand-text span { color: var(--accent); }

.topbar-nav {
    display: flex;
    gap: 2px;
    background: var(--bg-glass);
    border: 1px solid var(--border-decorative);
    border-radius: var(--radius-md);
    padding: 3px;
    backdrop-filter: blur(16px);
}

.topbar-nav a {
    text-decoration: none;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-tertiary);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.topbar-nav a:hover {
    color: var(--text-secondary);
    background: rgba(255,255,255,0.04);
}

.topbar-nav a.active {
    background: var(--bg-glass);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--color-danger), var(--color-warning));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--weight-bold);
    font-size: var(--text-xs);
    color: white;
    cursor: pointer;
}

/* ═══ PROFILE DROPDOWN ═══ */
.nav-profile-wrapper { position: relative; }

.profile-nav {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    flex-direction: column;
    gap: 2px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-decorative);
    border-radius: var(--radius-md);
    padding: 6px;
    min-width: 160px;
    z-index: 200;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
}

.profile-nav.open { display: flex; }

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast), color var(--transition-fast);
    font-size: 16px;
    font-weight: var(--weight-medium);
    display: block;
    width: 100%;
    text-align: left;
}

.nav-link:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.nav-link-button {
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
}

.nav-link-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.nav-divider {
    border: none;
    border-top: 1px solid var(--border-decorative);
    margin: 4px 8px;
}

/* ═══ BOTTOM NAV (MOBILE) ═══ */
.bottom-nav { display: none; }

@media (max-width: 640px) {
    .container { padding-bottom: calc(72px + 24px); }
    .topbar-nav { display: none; }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        height: 72px;
        background: var(--bg-elevated);
        backdrop-filter: blur(20px);
        border-top: 1px solid var(--border-decorative);
        box-shadow: var(--shadow-lg);
        padding: 8px 8px env(safe-area-inset-bottom, 8px);
        justify-content: space-around;
        align-items: center;
    }

    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        text-decoration: none;
        color: var(--text-tertiary);
        font-size: 0.62rem;
        font-weight: var(--weight-medium);
        padding: 6px 10px;
        border-radius: var(--radius-md);
        transition: color var(--transition-fast);
        min-width: 52px;
    }

    .bottom-nav a svg { width: 20px; height: 20px; }
    .bottom-nav a.active { color: var(--accent); }
}

/* ═══ GOAL SELECTOR ═══ */
.goal-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
    width: 100%;
}

.goal-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-3);
    background: var(--bg-glass);
    border: 2px solid var(--border-decorative);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-body);
    color: var(--text-tertiary);
}

.goal-option:hover {
    background: var(--bg-glass-hover);
    transform: translateY(-2px);
}

.goal-option.active { background: var(--color-success-dim); border-color: var(--color-success); }
.goal-option[data-goal="lose"].active { background: var(--color-danger-dim); border-color: var(--color-danger); color: var(--color-danger); }
.goal-option[data-goal="maintain"].active { background: var(--color-info-dim); border-color: var(--color-info); color: var(--color-info); }
.goal-option[data-goal="gain"].active { background: var(--color-success-dim); border-color: var(--color-success); color: var(--color-success); }

.goal-option[data-goal="lose"].active .goal-arrow { stroke: var(--color-danger); }
.goal-option[data-goal="maintain"].active .goal-arrow { stroke: var(--color-info); }
.goal-option[data-goal="gain"].active .goal-arrow { stroke: var(--color-success); }

.goal-arrow { width: 48px; height: 48px; stroke: currentColor; }
.goal-label { font-size: var(--text-sm); font-weight: var(--weight-semibold); }

@media (max-width: 768px) {
    .goal-selector { grid-template-columns: 1fr; }
}

/* ═══ SYNC PROGRESS ═══ */
.sync-progress {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-5);
    background: var(--color-success-dim);
    border: 1px solid var(--color-success);
    border-radius: var(--radius-md);
    margin: var(--space-2) 0;
}

.sync-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-success-dim);
    border-top-color: var(--color-success);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.sync-message { flex: 1; text-align: left; }
.sync-message strong { display: block; color: var(--color-success); font-size: var(--text-sm); margin-bottom: 4px; }
.sync-message p { margin: 0; color: var(--text-secondary); font-size: var(--text-xs); line-height: 1.4; }

/* ═══ PROFILE DETAILS ═══ */
.profile-details {
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-4) var(--space-6);
    align-items: baseline;
}

.profile-details dt {
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    text-align: right;
}

.profile-details dd {
    margin: 0;
    padding: 0;
    font-size: var(--text-base);
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .profile-details {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .profile-details dt { text-align: left; margin-top: var(--space-3); }
    .profile-details dt:first-of-type { margin-top: 0; }
}

/* ═══ STATUS BADGES ═══ */
.status-badge {
    display: inline-block;
    padding: 4px var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
}

.status-badge.status-connected { background: var(--color-success-dim); color: var(--color-success); }
.status-badge.status-disconnected { background: var(--color-danger-dim); color: var(--color-danger); }

/* ═══ PROFILE GRIDS ═══ */
.profile-top-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.profile-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin-top: var(--space-3);
}

@media (max-width: 768px) {
    .profile-top-grid { grid-template-columns: 1fr; }
}

/* ═══ DATA TABLE ═══ */
.data-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
    gap: var(--space-3);
}

.data-toolbar-actions {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.data-table thead th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-decorative);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border-decorative);
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover { background: var(--accent-dim); }
.data-table tbody td { padding: var(--space-3) var(--space-4); vertical-align: middle; }

.form-check-input {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-input);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.form-check-input:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.form-check-input:indeterminate {
    background: var(--accent);
    border-color: var(--accent);
}

.mono { font-family: var(--font-mono); font-weight: var(--weight-medium); }

/* ═══ LOG ENTRY PAGE ═══ */
.log-page {
    max-width: 480px;
    margin: 0 auto;
    padding-bottom: var(--space-16);
}

@media (max-width: 768px) {
    .log-page {
        padding-bottom: 120px; /* Extra padding on mobile for bottom nav */
    }
}

.log-hero {
    text-align: center;
    margin-bottom: var(--space-8);
}

.log-hero-title {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-3);
}

.log-date-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    background: var(--bg-glass);
    border: 1px solid var(--border-decorative);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-body);
    font-weight: var(--weight-medium);
    min-height: 36px;
}

.log-date-button:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
}

.log-date-button svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.log-date-picker {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.log-big-input {
    font-family: var(--font-mono);
    font-size: var(--text-4xl);
    text-align: center;
    padding: var(--space-6);
    border: 2px solid var(--border-input);
}

.log-big-input:focus {
    border-color: var(--border-focus);
}

.log-unit-select {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
    margin-top: var(--space-3);
    margin-bottom: var(--space-6);
}

.unit-btn {
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-tertiary);
    background: transparent;
    cursor: pointer;
    min-height: 36px;
    transition: all var(--transition-fast);
}

.unit-btn:hover {
    background: var(--bg-inset);
}

.unit-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.log-meta {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* ═══ DELETE CONFIRMATION PAGE ═══ */
.delete-entries-list {
    max-height: 400px;
    overflow-y: auto;
}

.delete-entry-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-decorative);
    font-size: var(--text-sm);
}

.delete-entry-item:last-child {
    border-bottom: none;
}

.delete-entry-date {
    color: var(--text-secondary);
}

.delete-entry-weight {
    font-size: var(--text-base);
    color: var(--color-danger);
    font-weight: var(--weight-semibold);
}

/* ═══ SUCCESS PAGE ═══ */
.success-icon {
    background: var(--color-success-dim);
}

.success-icon svg {
    color: var(--color-success);
}

.success-summary {
    text-align: center;
    margin: var(--space-6) 0;
    padding: var(--space-6);
    background: var(--bg-glass);
    border: 1px solid var(--border-decorative);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(16px);
}

.success-weight {
    font-size: var(--text-4xl);
    font-weight: var(--weight-bold);
    color: var(--color-success);
    margin-bottom: var(--space-2);
}

.success-weight .mono {
    font-family: var(--font-mono);
}

.success-time {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* ═══ ONBOARDING COMPONENTS ═══ */
.onboard-page {
    max-width: 520px;
    margin: 0 auto;
    text-align: center;
    padding: var(--space-6) 0;
}

.onboard-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-xl);
    background: var(--accent-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-6);
}

.onboard-icon svg {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.onboard-title {
    font-size: var(--text-3xl);
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-3);
}

.onboard-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    flex-wrap: wrap;
}

/* ═══ BULK UPLOAD PAGE ═══ */
.supported-formats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.format-item {
    padding: var(--space-4);
    background: var(--bg-inset);
    border-radius: var(--radius-md);
}

.format-item strong {
    display: block;
    margin-bottom: var(--space-2);
    color: var(--text-primary);
    font-size: var(--text-sm);
}

.format-item p {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    margin: 0;
}

.code-block {
    font-size: var(--text-xs);
    background: var(--bg-elevated);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    color: var(--text-secondary);
}

.import-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.import-stat {
    padding: var(--space-4);
    background: var(--bg-glass);
    border: 1px solid var(--border-decorative);
    border-radius: var(--radius-lg);
    text-align: center;
}

.import-stat-value {
    font-family: var(--font-mono);
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: var(--accent);
    margin-bottom: var(--space-2);
}

.import-stat-label {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.import-results {
    max-width: 400px;
    margin: var(--space-6) auto;
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-decorative);
}

.result-item:last-child {
    border-bottom: none;
}

.result-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.result-value {
    font-family: var(--font-mono);
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
}

.result-value.success {
    color: var(--color-success);
}

.result-value.error {
    color: var(--color-danger);
}

/* ═══════════════════════════════════════════
   PROFILE PAGE
   ═══════════════════════════════════════════ */
.profile-header {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    margin-bottom: var(--space-8);
}

.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, var(--color-danger), var(--color-warning));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--weight-bold);
    font-size: var(--text-xl);
    color: white;
    flex-shrink: 0;
}

.profile-info {
    flex: 1;
}

.profile-name {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-1);
}

.profile-meta {
    font-size: 16px;
    color: var(--text-secondary);
}

.profile-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
    margin-bottom: var(--space-8);
}

.profile-stat {
    padding: var(--space-4);
    text-align: center;
}

.profile-stat-value {
    font-family: var(--font-mono);
    font-size: var(--text-2xl);
    font-weight: var(--weight-medium);
    margin-bottom: var(--space-1);
}

.profile-stat-label {
    font-size: 16px;
    color: var(--text-tertiary);
}

/* ═══════════════════════════════════════════
   PAGE HEADERS
   ═══════════════════════════════════════════ */
.page-title {
    font-size: var(--text-3xl);
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-2);
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
}

@media (min-width: 640px) {
    .page-title {
        font-size: var(--text-4xl);
    }

    .page-subtitle {
        font-size: 16px;
        margin-bottom: var(--space-8);
    }
}

.card-title {
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    margin-bottom: var(--space-2);
}

.card-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
}

@media (min-width: 640px) {
    .card-title {
        font-size: var(--text-2xl);
    }

    .card-desc {
        font-size: 16px;
    }
}

/* ═══════════════════════════════════════════
   CHARTS PAGE
   ═══════════════════════════════════════════ */
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-4);
    margin-top: var(--space-6);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-decorative);
}

@media (min-width: 640px) {
    .chart-legend {
        gap: var(--space-6);
        flex-wrap: nowrap;
    }
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 14px;
    color: var(--text-secondary);
}

@media (min-width: 640px) {
    .legend-item {
        font-size: 16px;
    }
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-line-with-dot,
.legend-line-dashed {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.legend-line-with-dot svg,
.legend-line-dashed svg {
    display: block;
}

.view-toggle {
    display: flex;
    gap: var(--space-1);
    background: var(--bg-inset);
    padding: 3px;
    border-radius: var(--radius-md);
    width: 100%;
}

.view-toggle-btn {
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-weight: var(--weight-semibold);
    font-size: 13px;
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    font-family: var(--font-body);
    min-height: 32px;
    flex: 1;
}

@media (min-width: 640px) {
    .view-toggle-btn {
        padding: var(--space-1) var(--space-3);
        font-size: 14px;
    }
}

.view-toggle-btn:hover {
    color: var(--text-primary);
}

.view-toggle-btn.active {
    background: var(--bg-elevated);
    color: var(--text-primary);
    box-shadow: var(--shadow-xs);
}

.chart-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.chart-header .card-title {
    margin-bottom: 0;
}

.chart-header .card-desc {
    margin-bottom: 0;
    order: 3;
}

.chart-controls {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    width: 100%;
}

.chart-nav-buttons {
    display: flex;
    gap: var(--space-2);
    width: 100%;
}

.chart-nav-buttons .btn {
    flex: 1;
    font-size: 13px;
}

@media (min-width: 640px) {
    .chart-nav-buttons .btn {
        font-size: 14px;
    }
}

.charts-page-wrapper {
    margin: 0;
}

@media (min-width: 768px) {
    .charts-page-wrapper {
        margin: 0 auto;
    }
}

.charts-page-header {
    padding: 0 var(--space-4);
}

@media (min-width: 768px) {
    .charts-page-header {
        padding: 0;
    }
}

.chart-card {
    padding: var(--space-4) 0;
    background: transparent;
    border: none;
    border-radius: 0;
    margin-bottom: 0;
}

@media (min-width: 768px) {
    .chart-card {
        padding: var(--space-6) 0;
        background: var(--bg-glass);
        border: 1px solid var(--border-decorative);
        border-radius: var(--radius-xl);
        backdrop-filter: blur(16px);
        margin-bottom: var(--space-4);
    }
}

.chart-header {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
    padding-bottom: var(--space-2);
}

@media (min-width: 768px) {
    .chart-header {
        padding-left: var(--space-6);
        padding-right: var(--space-6);
        padding-bottom: 0;
    }
}

.chart-container-wrapper {
    position: relative;
    height: 300px;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}

@media (min-width: 768px) {
    .chart-container-wrapper {
        height: 400px;
        padding-left: var(--space-6);
        padding-right: var(--space-6);
    }
}

.chart-legend {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
}

@media (min-width: 768px) {
    .chart-legend {
        padding-left: var(--space-6);
        padding-right: var(--space-6);
    }
}

.chart-no-data {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--text-secondary);
}

@media (min-width: 768px) {
    .chart-no-data {
        padding: var(--space-8) var(--space-6);
    }
}

/* Desktop layout - horizontal */
@media (min-width: 768px) {
    .chart-header {
        gap: var(--space-3);
    }

    .chart-controls {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .view-toggle {
        width: auto;
    }

    .view-toggle-btn {
        flex: 0 0 auto;
    }

    .chart-nav-buttons {
        width: auto;
    }

    .chart-nav-buttons .btn {
        flex: 0 0 auto;
    }
}

/* ═══════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════ */

.toast-container {
    position: fixed;
    bottom: calc(72px + var(--space-4)); /* above bottom nav (72px) */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    z-index: 9999;
    pointer-events: none;
    width: max-content;
    max-width: calc(100vw - var(--space-8));
}

.toast {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-lg);
    font-size: 15px;
    font-weight: var(--weight-medium);
    font-family: var(--font-body);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: auto;
    white-space: nowrap;
    backdrop-filter: blur(12px);
}

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

.toast-success {
    background: var(--color-success-dim);
    color: var(--color-success);
    border: 1px solid var(--color-success);
}

.toast-error {
    background: var(--color-danger-dim);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}

.toast-info {
    background: var(--color-info-dim);
    color: var(--color-info);
    border: 1px solid var(--color-info);
}

@media (min-width: 768px) {
    .toast-container {
        bottom: var(--space-6);
    }
}

/* ═══════════════════════════════════════════
   SETTINGS PAGE
   ═══════════════════════════════════════════ */
.settings-page-header {
    max-width: 640px;
    margin: 0 auto;
    margin-bottom: var(--space-8);
}

.settings-page-title {
    font-size: var(--text-4xl);
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-2);
}

.settings-page-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
}

.settings-grid {
    display: grid;
    gap: var(--space-6);
    max-width: 640px;
    margin: 0 auto;
}

.settings-section-title {
    font-size: var(--text-2xl);
    font-weight: var(--weight-semibold);
    margin-bottom: var(--space-2);
}

.settings-section-desc {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: var(--space-5);
}

.settings-section-title.danger {
    color: var(--color-danger);
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--border-decorative);
    min-height: 56px;
}

.settings-row:last-child {
    border-bottom: none;
}

.settings-row-info {
    flex: 1;
}

.settings-row-label {
    font-size: 16px;
    font-weight: var(--weight-medium);
    margin-bottom: 4px;
    color: var(--text-primary);
}

.settings-row-desc {
    font-size: 16px;
    color: var(--text-tertiary);
}

.theme-selector,
.unit-selector {
    display: flex;
    gap: var(--space-2);
    background: var(--bg-inset);
    padding: 3px;
    border-radius: var(--radius-md);
}

.theme-option,
.unit-option {
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-weight: var(--weight-semibold);
    font-size: 16px;
    color: var(--text-tertiary);
    background: transparent;
    border: none;
    font-family: var(--font-body);
    min-height: 36px;
}

.theme-option:hover,
.unit-option:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.theme-option.active,
.unit-option.active {
    background: var(--bg-glass);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.settings-row .btn {
    min-width: 140px;
    white-space: nowrap;
    font-size: 16px;
}

#saveMessage {
    margin-top: var(--space-4);
}

@media (max-width: 768px) {
    .settings-row {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .settings-row .btn,
    .theme-selector,
    .unit-selector {
        width: 100%;
    }

    .settings-row-info {
        width: 100%;
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    z-index: 1001;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
    .profile-stats {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 480px) {
    .profile-header {
        flex-direction: column;
        text-align: center;
    }

    .settings-row {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .settings-row .btn {
        width: 100%;
    }
}

@media (max-width: 640px) {
    .container {
        padding: var(--space-6) var(--space-4);
        padding-bottom: 100px; /* Extra padding for bottom nav on mobile */
    }
    .onboard-actions { flex-direction: column; }
    .data-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }
    .data-toolbar-actions {
        width: 100%;
        flex-direction: column;
    }
    .data-toolbar-actions .btn {
        width: 100%;
    }
}
