/* ===========================
   Better — Modern & Polished
   =========================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #1a1d23;
    --text-secondary: #4a5068;
    --text-muted: #8892a4;
    --border: #e2e5ec;
    --border-light: #eef0f4;
    --primary: #4f6ef7;
    --primary-dark: #3b5ae0;
    --primary-light: #eef1fe;
    --primary-glow: rgba(79, 110, 247, 0.15);
    --success: #22c55e;
    --success-dark: #16a34a;
    --success-light: #dcfce7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --score-fill: #4f6ef7;
    --score-empty: #e8ebf0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08), 0 8px 32px rgba(0,0,0,0.06);
    --shadow-glow: 0 0 0 3px var(--primary-glow);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Dark mode overrides --- */
[data-theme="dark"] {
    --bg: #121418;
    --card-bg: #1a1d24;
    --text: #e8eaf0;
    --text-secondary: #a0a8ba;
    --text-muted: #6b7385;
    --border: #2a2e38;
    --border-light: #222630;
    --primary: #6b8aff;
    --primary-dark: #5a78f0;
    --primary-light: rgba(107, 138, 255, 0.12);
    --primary-glow: rgba(107, 138, 255, 0.2);
    --success: #34d399;
    --success-dark: #10b981;
    --success-light: rgba(52, 211, 153, 0.12);
    --danger: #f87171;
    --danger-light: rgba(248, 113, 113, 0.12);
    --warning: #fbbf24;
    --warning-light: rgba(251, 191, 36, 0.12);
    --score-fill: #6b8aff;
    --score-empty: #2a2e38;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2), 0 1px 3px rgba(0,0,0,0.15);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.25), 0 4px 16px rgba(0,0,0,0.15);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.3), 0 8px 32px rgba(0,0,0,0.2);
    color-scheme: dark;
}

/* Dark mode specific overrides for hardcoded colors */
[data-theme="dark"] .cal-day.score-zero { background: #1e2028; color: var(--text-muted); }
[data-theme="dark"] .cal-day.score-red { background: rgba(248,113,113,0.15); color: #fca5a5; }
[data-theme="dark"] .cal-day.score-amber { background: rgba(251,191,36,0.15); color: #fde68a; }
[data-theme="dark"] .cal-day.score-green { background: rgba(52,211,153,0.15); color: #6ee7b7; }
[data-theme="dark"] .cal-day.no-entry { background: var(--bg); }

[data-theme="dark"] .weekly-table .wk-green { background: rgba(52,211,153,0.15); color: #6ee7b7; }
[data-theme="dark"] .weekly-table .wk-amber { background: rgba(251,191,36,0.15); color: #fde68a; }
[data-theme="dark"] .weekly-table .wk-red { background: rgba(248,113,113,0.15); color: #fca5a5; }

[data-theme="dark"] .weekly-table .avg-col {
    background: rgba(107, 138, 255, 0.12);
    color: var(--primary);
}

[data-theme="dark"] .podium-hero {
    border-color: rgba(251,191,36,0.3);
    background: linear-gradient(135deg, rgba(251,191,36,0.08), var(--card-bg));
}

[data-theme="dark"] .podium-rank-badge.gold {
    background: linear-gradient(135deg, rgba(251,191,36,0.25), rgba(251,191,36,0.15));
    color: #fde68a;
    border-color: rgba(245,158,11,0.4);
    box-shadow: 0 2px 8px rgba(245,158,11,0.15);
}
[data-theme="dark"] .podium-rank-badge.silver {
    background: linear-gradient(135deg, rgba(148,163,184,0.2), rgba(148,163,184,0.1));
    color: #cbd5e1;
    border-color: rgba(148,163,184,0.3);
}
[data-theme="dark"] .podium-rank-badge.bronze {
    background: linear-gradient(135deg, rgba(249,115,22,0.25), rgba(249,115,22,0.15));
    color: #fdba74;
    border-color: rgba(249,115,22,0.4);
}

[data-theme="dark"] .standings-row:first-child {
    background: linear-gradient(135deg, rgba(251,191,36,0.08), rgba(251,191,36,0.04));
    border-color: rgba(251,191,36,0.2);
}

[data-theme="dark"] .stat-box {
    background: linear-gradient(135deg, var(--bg), var(--border));
}

[data-theme="dark"] .user-type-badge.adult {
    background: rgba(96,165,250,0.15);
    color: #93bbfd;
}
[data-theme="dark"] .user-type-badge.child {
    background: rgba(251,191,36,0.15);
    color: #fde68a;
}

[data-theme="dark"] .weight-month-cell.month-loss {
    background: rgba(52,211,153,0.1);
    border-color: rgba(52,211,153,0.2);
}
[data-theme="dark"] .weight-month-cell.month-gain {
    background: rgba(248,113,113,0.1);
    border-color: rgba(248,113,113,0.2);
}

[data-theme="dark"] .habit-impact-card.impact-good {
    background: rgba(52,211,153,0.08);
    border-color: rgba(52,211,153,0.2);
}
[data-theme="dark"] .habit-impact-card.impact-bad {
    background: rgba(248,113,113,0.08);
    border-color: rgba(248,113,113,0.2);
}

[data-theme="dark"] .flash {
    background: linear-gradient(135deg, rgba(52,211,153,0.15), rgba(52,211,153,0.1));
    border-color: rgba(52,211,153,0.25);
}

[data-theme="dark"] .auth-error {
    border-color: rgba(248,113,113,0.25);
}

[data-theme="dark"] .progress-ring-fill.gold-ring { stroke: #fbbf24; }
[data-theme="dark"] .progress-ring-fill.silver-ring { stroke: #cbd5e1; }
[data-theme="dark"] .progress-ring-fill.bronze-ring { stroke: #fb923c; }

[data-theme="dark"] .gold-medal .medal-num { color: #fbbf24; }
[data-theme="dark"] .silver-medal .medal-num { color: #cbd5e1; }
[data-theme="dark"] .bronze-medal .medal-num { color: #fb923c; }

/* Floating theme toggle for login/standalone pages */
.theme-toggle-float {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    z-index: 100;
    transition: all 0.2s ease;
}
.theme-toggle-float:hover {
    box-shadow: var(--shadow-md);
    transform: scale(1.08);
}

[data-theme="dark"] img { filter: brightness(0.92); }
[data-theme="dark"] img.avatar-img { filter: brightness(1); }

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    padding: 0 20px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
main {
    max-width: 900px;
    margin: 0 auto;
    padding-top: 24px;
    transition: margin 0.25s ease;
}

/* ====================== */
/*    Sidebar Rail + Expand */
/* ====================== */

/* --- Layout variables --- */
:root {
    --rail-width: 56px;
    --sidebar-width: 240px;
}

/* --- Mobile top bar (hidden on desktop) --- */
.topbar {
    display: none;  /* shown via media query on mobile */
    align-items: center;
    padding: 12px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
    gap: 12px;
}
.topbar-brand {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.5px;
    flex: 1;
}
.topbar-user { text-decoration: none; }
.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.hamburger:hover { background: var(--border-light); }
.hamburger span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: all 0.25s ease;
}

/* --- Overlay (mobile only, shown via media query) --- */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    display: none;  /* shown on mobile */
}

/* --- Sidebar: always visible as rail on desktop --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--rail-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border-light);
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-open .sidebar {
    width: var(--sidebar-width);
    box-shadow: var(--shadow-lg);
}

/* Header: toggle always visible, brand fades in */
.sidebar-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    min-height: 52px;
    gap: 10px;
}
/* Toggle comes first, always centered in the rail */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    flex-shrink: 0;
}
.sidebar-toggle:hover {
    background: var(--border-light);
    color: var(--text);
}
.sidebar-brand {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.5px;
    opacity: 0;
    white-space: nowrap;
    transition: opacity 0.15s ease;
}
.sidebar-open .sidebar-brand {
    opacity: 1;
}

/* Nav links */
.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 6px 6px;
    gap: 2px;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    transition: all var(--transition);
    white-space: nowrap;
}
.sidebar-nav a:hover {
    background: var(--border-light);
    color: var(--text);
}
.sidebar-nav a.active {
    background: var(--primary-light);
    color: var(--primary);
    position: relative;
}
.sidebar-nav a.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
}
.sidebar-icon {
    font-size: 18px;
    width: 24px;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-label {
    opacity: 0;
    transition: opacity 0.15s ease;
    overflow: hidden;
}
.sidebar-open .sidebar-label {
    opacity: 1;
}

/* Footer: user + logout */
.sidebar-footer {
    padding: 6px;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    transition: all var(--transition);
    white-space: nowrap;
}
.sidebar-user:hover {
    background: var(--border-light);
}
.sidebar-user.active {
    background: var(--primary-light);
    color: var(--primary);
    position: relative;
}
.sidebar-user.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
}
.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    white-space: nowrap;
}
.sidebar-logout:hover {
    background: var(--danger-light);
    color: var(--danger);
}

/* Theme toggle button in sidebar */
.sidebar-theme-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    width: 100%;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-align: left;
}
.sidebar-theme-toggle:hover {
    background: var(--border-light);
    color: var(--text);
}
/* Show/hide icons and labels based on current theme */
.theme-icon-dark,
.theme-label-dark { display: none; }
.theme-icon-light,
.theme-label-light { display: inline; }
[data-theme="dark"] .theme-icon-dark,
[data-theme="dark"] .theme-label-dark { display: inline; }
[data-theme="dark"] .theme-icon-light,
[data-theme="dark"] .theme-label-light { display: none; }

.nav-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

/* --- Desktop: body shifts right for sidebar --- */
@media (min-width: 601px) {
    body {
        padding-left: var(--rail-width);
        transition: padding-left 0.25s ease;
    }
    .sidebar-open body {
        padding-left: var(--sidebar-width);
    }
    .topbar { display: none; }
}

/* ====================== */
/*    Page Header          */
/* ====================== */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text);
}

/* ====================== */
/*    Date Navigation      */
/* ====================== */

.date-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    margin-bottom: 4px;
}
.date-nav a {
    text-decoration: none;
    color: var(--primary);
    font-size: 18px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    background: var(--card-bg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.date-nav a:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.date-nav .date-label {
    font-size: 17px;
    font-weight: 700;
    min-width: 200px;
    text-align: center;
    letter-spacing: -0.3px;
    color: var(--text);
}

/* ====================== */
/*    Score Badge           */
/* ====================== */

.score-area {
    text-align: center;
    margin-bottom: 16px;
}
.score-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 16px 24px;
    box-shadow: var(--shadow-sm);
}
.score-number {
    font-size: 32px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -1px;
}
.score-max {
    font-size: 16px;
    color: var(--text-muted);
    font-weight: 500;
}
.score-dots {
    display: flex;
    gap: 4px;
}
.score-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--score-empty);
    transition: all 0.3s ease;
}
.score-dot.filled {
    background: var(--score-fill);
    box-shadow: 0 0 6px var(--primary-glow);
}

/* Trend indicator */
.trend-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
}
.trend-indicator.trend-up {
    color: var(--success-dark);
    background: var(--success-light);
}
.trend-indicator.trend-down {
    color: var(--danger);
    background: var(--danger-light);
}
.trend-indicator.trend-flat {
    color: var(--text-muted);
    background: var(--border-light);
}
.trend-arrow { font-size: 15px; font-weight: 800; }
.trend-detail {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 4px;
}

/* ====================== */
/*    Cards                */
/* ====================== */

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}
.card:hover {
    box-shadow: var(--shadow-md);
}
.card h2 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ====================== */
/*    Form Controls        */
/* ====================== */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}
.form-group input[type="number"],
.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    font-weight: 500;
    width: 100%;
    background: var(--card-bg);
    color: var(--text);
    transition: all var(--transition);
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}
.form-group.credited input,
.form-group.credited select {
    border-color: var(--success);
    background: var(--success-light);
}

/* ====================== */
/*    Toggle Switches      */
/* ====================== */

.checkbox-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    border: 1.5px solid transparent;
}
.checkbox-group:hover {
    background: var(--border-light);
}

/* Hide native checkbox, keep it accessible */
.checkbox-group input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* Toggle track */
.toggle-track {
    position: relative;
    width: 40px;
    height: 24px;
    min-width: 40px;
    background: var(--border);
    border-radius: 12px;
    transition: background 0.25s ease;
    cursor: pointer;
    flex-shrink: 0;
}
/* Toggle knob */
.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
/* Checked state */
.checkbox-group input[type="checkbox"]:checked ~ .toggle-track {
    background: var(--primary);
}
.checkbox-group input[type="checkbox"]:checked ~ .toggle-track::after {
    transform: translateX(16px);
}
/* Focus ring for keyboard accessibility */
.checkbox-group input[type="checkbox"]:focus-visible ~ .toggle-track {
    box-shadow: var(--shadow-glow);
}

.checkbox-group label {
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
}

/* Credited (earned) state */
.checkbox-group.credited {
    background: var(--success-light);
    border-color: var(--success);
}
.checkbox-group.credited label {
    color: var(--success-dark);
    font-weight: 600;
}
.checkbox-group.credited input[type="checkbox"]:checked ~ .toggle-track {
    background: var(--success);
}

/* Credit indicator */
.credit-indicator {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--score-empty);
    margin-left: 4px;
    transition: all 0.3s ease;
}
.credit-indicator.earned {
    background: var(--success);
    box-shadow: 0 0 4px rgba(34,197,94,0.4);
}

/* Credit-earned animation */
.credit-pop {
    animation: creditPop 0.45s cubic-bezier(0.2, 0, 0.2, 1);
}
@keyframes creditPop {
    0%   { transform: scale(1); box-shadow: 0 0 0 0 rgba(34,197,94,0); }
    30%  { transform: scale(1.03); box-shadow: 0 0 0 6px rgba(34,197,94,0.25); }
    60%  { transform: scale(0.98); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ====================== */
/*    Goal Widget          */
/* ====================== */

/* ====================== */
/*    Input with Add Btn   */
/* ====================== */

.input-with-add {
    display: flex;
    gap: 8px;
    align-items: center;
}
.field-value {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 20px;
    font-family: inherit;
    font-weight: 700;
    background: var(--bg);
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.form-group.credited .field-value {
    border-color: var(--success);
    background: var(--success-light);
    color: var(--success-dark);
}
.add-btn {
    padding: 10px 16px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.add-btn:hover {
    background: var(--primary);
    color: white;
}

/* ====================== */
/*    Quick-Add Sheet       */
/* ====================== */

.qa-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}
.qa-sheet {
    background: var(--card-bg);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 28px 24px 32px;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.15);
    width: 100%;
    max-width: 480px;
    position: relative;
    animation: sheetUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
}
@keyframes sheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.qa-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--border-light);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    line-height: 1;
}
.qa-close:hover {
    background: var(--border);
    color: var(--text);
}
.qa-label {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 20px;
}
.qa-input {
    display: block;
    width: 160px;
    margin: 0 auto 20px;
    padding: 12px 0;
    border: none;
    border-bottom: 3px solid var(--primary);
    font-size: 48px;
    font-family: inherit;
    font-weight: 800;
    color: var(--text);
    text-align: center;
    background: transparent;
    letter-spacing: -1px;
}
.qa-input:focus {
    outline: none;
}
.qa-input::placeholder {
    color: var(--border);
}
.qa-equation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 24px;
    font-variant-numeric: tabular-nums;
}
.qa-num {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 28px;
}
.qa-num-add {
    color: var(--primary);
}
.qa-num-result {
    font-size: 24px;
    font-weight: 800;
    color: var(--text);
}
.qa-op {
    font-size: 16px;
    font-weight: 600;
    color: var(--border);
}
.qa-submit {
    display: block;
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: -0.01em;
}
.qa-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--primary-glow);
}
.qa-submit:active {
    transform: translateY(0);
}
.qa-current-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 20px;
}
.qa-current-label span {
    color: var(--text-secondary);
    font-weight: 700;
}
.qa-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}
.qa-option {
    display: block;
    width: 100%;
    padding: 14px;
    background: var(--bg);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}
.qa-option:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}
.qa-option-active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
    box-shadow: var(--shadow-glow);
}

@media (min-width: 601px) {
    .qa-overlay {
        align-items: center;
    }
    .qa-sheet {
        border-radius: var(--radius-xl);
        max-width: 360px;
        animation: sheetPop 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }
    @keyframes sheetPop {
        from { opacity: 0; transform: scale(0.95); }
        to { opacity: 1; transform: scale(1); }
    }
}

/* ====================== */
/*    Goal Widget          */
/* ====================== */

.goal-widget {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}
.goal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.goal-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    font-weight: 700;
}
.goal-numbers {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}
.goal-bar {
    height: 8px;
    background: var(--score-empty);
    border-radius: 4px;
    overflow: hidden;
}
.goal-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    border-radius: 4px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.goal-fill.goal-met {
    background: linear-gradient(90deg, var(--success), var(--success-dark));
}
.goal-form {
    display: flex;
    align-items: center;
    gap: 8px;
}
.goal-input {
    width: 80px;
    padding: 7px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    transition: all var(--transition);
}
.goal-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}
.goal-btn {
    padding: 7px 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}
.goal-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--primary-glow);
}
.goal-btn-cancel {
    background: var(--border-light);
    color: var(--text-secondary);
}
.goal-btn-cancel:hover {
    background: var(--border);
    box-shadow: none;
}
.goal-edit-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 4px;
    transition: all var(--transition);
    margin-left: 4px;
    vertical-align: middle;
}
.goal-edit-btn:hover {
    color: var(--primary);
    background: var(--primary-light);
}
.goal-edit-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

/* ====================== */
/*    Toast / Snackbar     */
/* ====================== */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    padding: 10px 24px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    z-index: 1100;
    pointer-events: none;
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}
.toast.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.toast-saving {
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.toast.toast-success {
    background: var(--success);
    color: white;
}
.toast.toast-error {
    background: var(--danger);
    color: white;
}
.toast-icon {
    font-size: 16px;
    line-height: 1;
}

/* ====================== */
/*    Empty States         */
/* ====================== */

.empty-state {
    text-align: center;
    padding: 32px 16px;
}
.empty-state-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.7;
}
.empty-state-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}
.empty-state-desc {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.5;
}
.empty-state-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: all var(--transition);
}
.empty-state-action:hover {
    background: var(--primary);
    color: white;
}

/* ====================== */
/*    Notes Textarea       */
/* ====================== */

.notes-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    font-weight: 400;
    line-height: 1.6;
    resize: vertical;
    background: var(--card-bg);
    color: var(--text);
    transition: all var(--transition);
}
.notes-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}
.notes-input::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

/* ====================== */
/*    Buttons              */
/* ====================== */

.save-area {
    text-align: center;
    margin: 24px 0;
}
.btn-save {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 12px 36px;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: -0.01em;
    box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--primary-glow);
}
.btn-save:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px var(--primary-glow);
}

/* ====================== */
/*    Streak Panel         */
/* ====================== */

.streak-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.streak-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    font-size: 14px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.streak-item:hover {
    background: var(--border-light);
}
.streak-item .label {
    color: var(--text-secondary);
    font-weight: 500;
}
.streak-item .value {
    font-weight: 700;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.streak-item .value.active {
    color: var(--success);
}

/* ====================== */
/*    Summary Stats        */
/* ====================== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}
.stat-box {
    text-align: center;
    padding: 20px 16px;
    background: linear-gradient(135deg, var(--bg), var(--border-light));
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-box:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-box .stat-value {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}
.stat-box .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
    margin-top: 4px;
}

/* ====================== */
/*    Trailing Avg Table   */
/* ====================== */

.trailing-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.trailing-table th,
.trailing-table td {
    padding: 10px 12px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
}
.trailing-table tbody tr {
    transition: background var(--transition);
}
.trailing-table tbody tr:hover {
    background: var(--border-light);
}
.trailing-table tbody tr:not(:last-child) td {
    border-bottom: 1px solid var(--border-light);
}
.trailing-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
}
.trailing-table th:first-child { text-align: left; }
.trailing-table td:first-child {
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
}
.trailing-table td:not(:first-child) {
    font-variant-numeric: tabular-nums;
}
.trailing-table thead th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 12px;
    font-weight: 700;
}

/* Activity Summary record columns */
.record-col {
    color: var(--text-muted);
    font-weight: 400 !important;
}
.trailing-table thead th.record-col {
    color: var(--text-muted);
    opacity: 0.8;
}
.record-note {
    text-align: right;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}

/* ====================== */
/*    Weekly Table         */
/* ====================== */

.weekly-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}
.weekly-table th,
.weekly-table td {
    padding: 8px 10px;
    text-align: center;
}
.weekly-table tbody tr {
    transition: background var(--transition);
}
.weekly-table tbody tr:hover {
    background: var(--border-light);
}
.weekly-table tbody tr:not(:last-child) td {
    border-bottom: 1px solid var(--border-light);
}
.weekly-table th {
    color: var(--text-muted);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 12px;
}
.weekly-table td:first-child {
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
}
.weekly-table td:not(:first-child) {
    font-variant-numeric: tabular-nums;
}
.weekly-table .no-data { color: var(--text-muted); }
.weekly-table .avg-col {
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), #f0f3ff);
    border-radius: var(--radius-sm);
    color: var(--primary);
}
.weekly-table .wk-green { background: #dcfce7; color: #065f46; font-weight: 700; }
.weekly-table .wk-amber { background: #fef3c7; color: #92400e; font-weight: 700; }
.weekly-table .wk-red { background: #fee2e2; color: #9b1c1c; font-weight: 700; }

/* Weekly notes */
.weekly-notes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.weekly-note {
    display: grid;
    grid-template-columns: 48px 1fr;
    grid-template-rows: auto auto;
    column-gap: 12px;
    row-gap: 2px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border: 1px solid var(--border-light);
    align-items: start;
}
.weekly-note-day {
    grid-column: 1;
    grid-row: 1;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
}
.weekly-note .score-green-badge,
.weekly-note .score-amber-badge,
.weekly-note .score-red-badge {
    grid-column: 1;
    grid-row: 2;
    justify-self: center;
}
.weekly-note-text {
    grid-column: 2;
    grid-row: 1 / -1;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}
.weekly-note-link {
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}
.weekly-note-link:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}
.show-more-btn {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 10px;
    background: none;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.show-more-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

/* ====================== */
/*    Monthly Calendar     */
/* ====================== */

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 24px;
}
.cal-header {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    padding: 8px 0;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.cal-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    transition: all var(--transition);
    border: 1.5px solid transparent;
}
.cal-day:hover {
    border-color: var(--primary);
    transform: scale(1.05);
    box-shadow: var(--shadow-sm);
}
.cal-day .day-num { font-weight: 600; }
.cal-day .day-score {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 1px;
}
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.empty:hover { border-color: transparent; transform: none; box-shadow: none; }

/* Heat map colors — percentage-based tiers */
.cal-day.score-zero { background: #f8f9fa; color: var(--text-muted); }
.cal-day.score-red { background: #fde8e8; color: #9b1c1c; }
.cal-day.score-amber { background: #fef3c7; color: #92400e; }
.cal-day.score-green { background: #a7f3d0; color: #065f46; }
.cal-day.no-entry { background: var(--bg); }

/* ====================== */
/*    Chart                */
/* ====================== */

.chart-container {
    position: relative;
    height: 250px;
    margin-top: 16px;
}

/* ====================== */
/*    Range Selector       */
/* ====================== */

/* ====================== */
/*    Weight Month Grid    */
/* ====================== */
.weight-month-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}
.weight-month-cell {
    text-align: center;
    padding: 14px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    background: var(--border-light);
}
.weight-month-cell.month-loss {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.2);
}
.weight-month-cell.month-gain {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.2);
}
.weight-month-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.weight-month-value {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-muted);
}
.month-loss .weight-month-value { color: var(--success); }
.month-gain .weight-month-value { color: var(--danger); }
.weight-month-count {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ====================== */
/*    Habit Impact Cards   */
/* ====================== */
.habit-impact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.habit-impact-card {
    text-align: center;
    padding: 16px 10px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border-light);
    background: var(--bg);
}
.habit-impact-card.impact-good {
    background: rgba(34, 197, 94, 0.06);
    border-color: rgba(34, 197, 94, 0.25);
}
.habit-impact-card.impact-bad {
    background: rgba(239, 68, 68, 0.06);
    border-color: rgba(239, 68, 68, 0.25);
}
.impact-icon {
    font-size: 24px;
    margin-bottom: 6px;
}
.impact-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.impact-delta {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-muted);
}
.impact-good .impact-delta { color: var(--success); }
.impact-bad .impact-delta { color: var(--danger); }
.impact-count {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ====================== */
/*    Flash Messages       */
/* ====================== */

.flash {
    background: linear-gradient(135deg, var(--success-light), #d1fae5);
    color: var(--success-dark);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    border: 1px solid rgba(34,197,94,0.2);
    animation: slideDown 0.3s ease, fadeOut 3s 1s forwards;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOut {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; }
}

/* ====================== */
/*    Auth / Login Page    */
/* ====================== */

.auth-container {
    max-width: 440px;
    margin: 60px auto;
    padding: 0 16px;
}
.auth-logo {
    display: block;
    width: 72px;
    height: 72px;
    margin: 0 auto 12px;
    border-radius: 18px;
}
.auth-title {
    font-size: 36px;
    font-weight: 800;
    text-align: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
    letter-spacing: -1px;
}
.auth-section-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    letter-spacing: 0.02em;
}
.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
    font-weight: 500;
    font-size: 15px;
}
.auth-form {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow-lg);
}
.auth-form .form-group {
    margin-bottom: 16px;
}
.auth-form .form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.02em;
}
.auth-form .form-group input,
.auth-form .form-group select {
    width: 100%;
    padding: 11px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    font-weight: 500;
    background: var(--card-bg);
    color: var(--text);
    transition: all var(--transition);
}
.auth-form .form-group input:focus,
.auth-form .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}
.auth-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    border: 1px solid rgba(239,68,68,0.2);
}

.auth-leaderboard-link {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
}
.auth-leaderboard-link a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: opacity var(--transition);
}
.auth-leaderboard-link a:hover {
    opacity: 0.7;
}

/* ====================== */
/*    User Select (Login)  */
/* ====================== */

.user-select-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 10px;
    margin-bottom: 8px;
}
.user-card {
    cursor: pointer;
}
.user-card input[type="radio"] {
    display: none;
}
.user-card-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    transition: all var(--transition);
    background: var(--card-bg);
}
.user-card input[type="radio"]:checked + .user-card-inner {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 4px var(--primary-glow);
}
.user-card:hover .user-card-inner {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 20px;
    font-weight: 800;
    box-shadow: 0 4px 12px var(--primary-glow);
}
.user-card-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
}
.user-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
}
.user-type-badge {
    font-size: 10px;
    padding: 2px 10px;
    border-radius: 20px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.user-type-badge.adult {
    background: #dbeafe;
    color: #1e40af;
}
.user-type-badge.child {
    background: var(--warning-light);
    color: #92400e;
}

/* ====================== */
/*    Avatar Images        */
/* ====================== */

/* Make img avatars match the existing span avatar circles */
img.nav-avatar,
img.avatar-img.nav-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

img.user-avatar,
img.avatar-img.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 12px var(--primary-glow);
}

img.podium-avatar,
img.avatar-img.podium-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

img.lb-avatar,
img.avatar-img.lb-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
}

/* Avatar upload on edit form */
.avatar-upload-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.avatar-upload-area {
    display: flex;
    align-items: center;
    gap: 20px;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--border-light);
    flex-shrink: 0;
}

.avatar-preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 28px;
    font-weight: 800;
    flex-shrink: 0;
}

.avatar-upload-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.avatar-file-input {
    display: none;
}

.avatar-upload-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}
.avatar-upload-btn:hover {
    background: var(--primary);
    color: white;
}

.avatar-upload-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

/* ====================== */
/*    Badges               */
/* ====================== */

.badge-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.badge-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 10px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--bg), var(--border-light));
    border: 1px solid var(--border-light);
    min-width: 76px;
    cursor: default;
    transition: all var(--transition);
}
.badge-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}
.badge-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light), #dce3fe);
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 2px 8px var(--primary-glow);
}
.badge-name {
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    color: var(--text-secondary);
    line-height: 1.2;
}

/* ====================== */
/*    Awards               */
/* ====================== */

.awards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}
.award-item {
    text-align: center;
    padding: 16px 12px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--bg), var(--border-light));
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}
.award-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.award-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 6px;
}
.award-user {
    font-size: 16px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.award-value {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 2px;
}

/* ====================== */
/*    Leaderboard          */
/* ====================== */

/* --- Podium: shared avatar --- */
.lb-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 14px;
    font-weight: 800;
}
.podium-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-weight: 800;
}
.podium-avatar.large { width: 40px; height: 40px; font-size: 18px; }
.podium-avatar.small { width: 32px; height: 32px; font-size: 14px; }
.podium-avatar.muted {
    background: var(--border);
    color: var(--text-muted);
}

/* --- Rank badge --- */
.podium-rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
    background: var(--border-light);
    color: var(--text-muted);
    border: 2px solid transparent;
}
.podium-rank-badge.gold {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
    border-color: #f59e0b;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}
.podium-rank-badge.silver {
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    color: #374151;
    border-color: #94a3b8;
}
.podium-rank-badge.bronze {
    background: linear-gradient(135deg, #fed7aa, #fdba74);
    color: #9a3412;
    border-color: #f97316;
}

/* --- 1st place hero card --- */
.podium-hero {
    border-color: #fde68a;
    background: linear-gradient(135deg, #fffbeb, #ffffff);
    box-shadow: 0 2px 12px rgba(245, 158, 11, 0.1);
}

/* --- Streak fire animation --- */
.streak-fire {
    font-size: 22px;
    display: inline-block;
    animation: firePulse 1.2s ease-in-out infinite;
}
.streak-fire.small { font-size: 16px; }
@keyframes firePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* --- Progress ring (SVG) --- */
.progress-ring-container {
    position: relative;
    width: 72px;
    height: 72px;
    margin: 8px auto;
}
.progress-ring-container.small {
    width: 72px;
    height: 72px;
    margin: 8px auto;
}
.progress-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.progress-ring-bg {
    fill: none;
    stroke: var(--score-empty);
    stroke-width: 6;
}
.progress-ring-fill {
    fill: none;
    stroke: var(--primary);
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dasharray 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-ring-fill.gold-ring { stroke: #f59e0b; }
.progress-ring-fill.silver-ring { stroke: #94a3b8; }
.progress-ring-fill.bronze-ring { stroke: #f97316; }
.progress-ring-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
}
.progress-ring-text.small { font-size: 16px; }

/* --- Improvement arrow --- */
.podium-improvement {
    font-size: 12px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
}
.podium-improvement.small { font-size: 11px; padding: 2px 8px; }
.podium-improvement.up { color: var(--success-dark); background: var(--success-light); }
.podium-improvement.down { color: var(--danger); background: var(--danger-light); }
.podium-improvement.flat { color: var(--text-muted); background: var(--border-light); }

/* --- Habit dots --- */
.podium-habit-dots {
    display: flex;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 4px 0;
}
.habit-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
}
.habit-dot.hit { background: var(--success); box-shadow: 0 0 4px rgba(34,197,94,0.3); }
.habit-dot.partial { background: var(--warning); }
.habit-dot.miss { background: var(--border); }

/* --- Day score row --- */
.podium-days-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    width: 100%;
    margin: 4px 0;
}
.podium-days-row.compact { gap: 3px; }
.pd-day {
    text-align: center;
    padding: 6px 2px;
    border-radius: 6px;
    background: var(--border-light);
}
.pd-day.no-data { opacity: 0.3; }
.pd-day-label {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
}
.pd-day-score {
    font-size: 15px;
    font-weight: 800;
    color: var(--text);
    margin-top: 1px;
}

/* --- Podium footer --- */
.podium-footer {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    width: 100%;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}
.podium-footer.compact { gap: 10px; font-size: 11px; }

/* --- Podium grid --- */
.podium-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.podium-card { padding: 16px; }
.podium-card-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}
.podium-card-top {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}
.podium-card-user {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}
.podium-card-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}

/* --- Inactive users --- */
.podium-inactive { padding: 16px 24px; }
.inactive-users {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.inactive-user {
    display: flex;
    align-items: center;
    gap: 8px;
}
.inactive-name {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 600;
}

/* --- Category Champions --- */
.champions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}
.champion-card {
    text-align: center;
    padding: 16px 10px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--bg), var(--border-light));
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}
.champion-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.champion-icon { font-size: 28px; margin-bottom: 4px; }
.champion-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 4px;
}
.champion-user {
    font-size: 15px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.champion-value {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 2px;
}

/* --- Badge Showcase --- */
.badge-total-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 20px;
    margin-left: 6px;
    vertical-align: middle;
    text-transform: none;
    letter-spacing: 0;
}
.badge-achievement-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
}
.badge-achievement {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}
.badge-achievement:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    border-color: var(--border);
}
.badge-achievement-icon {
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
}
.badge-achievement-info {
    min-width: 0;
}
.badge-achievement-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}
.badge-achievement-desc {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    line-height: 1.3;
    margin-top: 1px;
}

/* --- Standings rank number --- */
.standings-rank {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-muted);
    min-width: 28px;
}
.standings-winrate {
    font-weight: 700;
    color: var(--primary);
}
.standings-weeks {
    margin-left: 6px;
    color: var(--text-muted);
}
.standings-badges {
    margin-left: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
}

/* --- Award emoji --- */
.award-emoji {
    font-size: 32px;
    margin-bottom: 6px;
}

/* --- Section divider --- */
.section-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 28px 0 16px;
}
.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.section-divider-text {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ====================== */
/*    Users/Members Table  */
/* ====================== */

/* Reuse trailing-table styles for member management table */

/* ====================== */
/*    All-Time Standings   */
/* ====================== */

.standings-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.standings-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--bg), var(--border-light));
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}
.standings-row:first-child {
    background: linear-gradient(135deg, #fffbeb, #fef3c7);
    border-color: #fde68a;
}
.standings-row:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.standings-user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 130px;
}
.standings-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}
.standings-medals {
    display: flex;
    gap: 12px;
    flex: 1;
}
.medal-count {
    display: flex;
    align-items: center;
    gap: 4px;
}
.medal-icon {
    font-size: 20px;
    line-height: 1;
}
.medal-num {
    font-size: 18px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.5px;
}
.gold-medal .medal-num { color: #b45309; }
.silver-medal .medal-num { color: #4b5563; }
.bronze-medal .medal-num { color: #c2410c; }
.no-medals {
    color: var(--text-muted);
    font-size: 16px;
}
.standings-detail {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

/* ====================== */
/*    Responsive           */
/* ====================== */

@media (max-width: 600px) {
    body {
        padding: 0 14px;
        margin-left: 0;  /* no rail offset on mobile */
        max-width: 900px;
    }
    /* Mobile: show topbar, hide rail, use overlay drawer */
    .topbar { display: flex; }
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar-open .sidebar {
        transform: translateX(0);
        width: var(--sidebar-width);
    }
    .sidebar-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }
    .sidebar-overlay { display: block; }
    .sidebar-brand { opacity: 1; }
    .sidebar-label { opacity: 1; }

    .streak-grid { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .date-nav .date-label { font-size: 15px; min-width: auto; }
    .page-header h1 { font-size: 20px; }
    .score-badge { padding: 10px 16px; }
    .score-number { font-size: 26px; }
    .card { padding: 18px; }
    .auth-form { padding: 22px; }
    .checkbox-row { gap: 6px; }
    .checkbox-group { padding: 8px 12px; }
    .standings-row { flex-wrap: wrap; gap: 8px; }
    .standings-user { min-width: auto; }
    .standings-detail { width: 100%; }
    .podium-row { grid-template-columns: 1fr; }
    .champions-grid { grid-template-columns: repeat(2, 1fr); }
    .badge-achievement-grid { grid-template-columns: 1fr 1fr; }
}

/* ====================== */
/*    Scrollbar Styling    */
/* ====================== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ====================== */
/*    Selection Highlight  */
/* ====================== */

::selection {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* ====================== */
/*    Profile Links        */
/* ====================== */

.profile-link {
    color: inherit;
    text-decoration: none;
    transition: color 0.15s;
}
.profile-link:hover {
    color: var(--primary);
}
.back-link {
    font-size: 14px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
}
.back-link:hover {
    color: var(--primary);
}
.badge-overflow {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    border: 2px dashed var(--border);
    border-radius: 12px;
    transition: all 0.15s;
}
.badge-overflow:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* ====================== */
/*    Notes Analysis       */
/* ====================== */

.section-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin: -8px 0 16px 0;
}

/* Low-score outliers ("What Happened?") */
.note-outliers {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.note-outlier {
    display: block;
    padding: 12px 16px;
    background: var(--danger-light);
    border-left: 4px solid var(--danger);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.1s, box-shadow 0.15s;
}
.note-outlier:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.note-outlier-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.note-outlier-date {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.note-outlier-text {
    font-size: 14px;
    color: var(--text);
    line-height: 1.5;
}

/* Score badges */
.score-red-badge {
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--danger);
    color: #fff;
}
.score-amber-badge {
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--warning);
    color: #fff;
}
.score-green-badge {
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--success);
    color: #fff;
}

/* Monthly notes digest */
.monthly-notes-digest {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border-light);
    border-radius: 10px;
    overflow: hidden;
}
.note-digest-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 14px;
    background: var(--card-bg);
    text-decoration: none;
    color: inherit;
    transition: background 0.1s;
}
.note-digest-item:hover {
    background: var(--bg);
}
.note-digest-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 42px;
    flex-shrink: 0;
}
.note-digest-date {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.note-digest-score {
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
}
.note-digest-text {
    font-size: 14px;
    color: var(--text);
    line-height: 1.5;
    padding-top: 1px;
}
