:root {
    /* Sleek Light Palette (Default) */
    --bg-gradient: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%);
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(255, 255, 255, 0.6);
    --text-main: #334e68;
    --text-muted: #627d98;
    --primary-color: #10b981; /* Emerald Green */
    --primary-hover: #059669;
    --accent-color: #06b6d4; /* Cyan */
    --danger-color: #ef4444;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.05);

    /* Inputs */
    --input-bg: #f0f4f8;
    --input-border: #d9e2ec;
    --input-text: #334e68;

    /* History List Scrollbar */
    --scrollbar-track: rgba(0, 0, 0, 0.05);
    --scrollbar-thumb: rgba(16, 185, 129, 0.3);

    /* Chart Colors */
    --chart-tooltip-bg: rgba(255, 255, 255, 0.9);
    --chart-tooltip-text: #334e68;
    --chart-grid: rgba(0, 0, 0, 0.05);
}

body.dark-theme {
    /* Sleek Dark Palette */
    --bg-gradient: linear-gradient(135deg, #121212 0%, #1a1a2e 100%);
    --card-bg: rgba(30, 30, 46, 0.7);
    --card-border: rgba(255, 255, 255, 0.05);
    --text-main: #e0e0e0;
    --text-muted: #8b8b99;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);

    /* Inputs */
    --input-bg: #1a1a24;
    --input-border: #2a2a35;
    --input-text: #ffffff;

    /* History List Scrollbar */
    --scrollbar-track: rgba(0, 0, 0, 0.2);
    --scrollbar-thumb: #3a3a4a;

    /* Chart Colors */
    --chart-tooltip-bg: rgba(30, 30, 46, 0.9);
    --chart-tooltip-text: #e0e0e0;
    --chart-grid: rgba(255, 255, 255, 0.05);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
    background-attachment: fixed;
    transition: background 0.5s ease, color 0.5s ease;
}

.app-container {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

/* Typography */
h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-main);
}
body.dark-theme h1 {
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-main);
}

/* Section Headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    margin-bottom: 0;
}

.history-toggle-container {
    padding: 0.3rem 0.8rem;
}

.history-toggle-container .toggle-label {
    font-size: 0.85rem;
}

.collapsible-content {
    max-height: 600px;
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.4s ease;
    opacity: 1;
}

.collapsible-content.collapsed {
    max-height: 0;
    opacity: 0;
}

/* Header & Toggles */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.controls-container {
    display: flex;
    gap: 1rem;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    background: var(--card-bg);
    padding: 0.5rem 1rem;
    border-radius: 30px;
    backdrop-filter: blur(12px);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.toggle-label {
    font-weight: 600;
    color: var(--text-main);
    user-select: none;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--input-bg);
    transition: .4s;
    border: 1px solid var(--input-border);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
body.dark-theme .slider:before {
    box-shadow: none;
}

input:checked + .slider {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Glassmorphism Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 20px;
    border: 1px solid var(--card-border);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.1);
}
body.dark-theme .card:hover {
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.7);
    border-color: rgba(16, 185, 129, 0.2);
}

/* Forms */
#weightForm {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-end;
}

.input-group {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

input[type="date"],
input[type="number"] {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: 2px solid var(--input-border);
    background: var(--input-bg);
    color: var(--input-text);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease, color 0.3s ease;
}

input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

body.dark-theme input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.7;
    cursor: pointer;
}

/* Buttons */
.btn-primary {
    padding: 0.9rem 2rem;
    border: none;
    border-radius: 12px;
    background: var(--primary-color);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}
body.dark-theme .btn-primary {
    color: #000;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* Empty Chart State */
.chart-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: var(--text-muted);
    text-align: center;
    gap: 1rem;
}

.chart-empty-state svg {
    opacity: 0.5;
}

.chart-empty-state p {
    font-size: 1rem;
    font-weight: 500;
}

/* Statistics Panel */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:hover {
    transform: scale(1.02);
    border-color: rgba(16, 185, 129, 0.3);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-value.positive {
    color: var(--primary-color);
}

.stat-value.negative {
    color: var(--danger-color);
}

/* Goal Setting */
.goal-section {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.goal-section label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.goal-input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 200px;
}

.goal-input-group input {
    flex: 1;
    padding: 0.6rem 1rem;
    border-radius: 12px;
    border: 2px solid var(--input-border);
    background: var(--input-bg);
    color: var(--input-text);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.goal-input-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.goal-unit {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.btn-goal {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 10px;
    background: var(--accent-color);
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
}

.btn-goal:hover {
    background: #0891b2;
    transform: translateY(-1px);
}

.btn-goal-clear {
    background: transparent;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.btn-goal-clear:hover {
    background: var(--danger-color);
    color: white;
}

/* Data Actions */
.data-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--card-border);
}

.btn-secondary {
    padding: 0.7rem 1.2rem;
    border: 1px solid var(--input-border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.9rem;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-secondary:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

/* Backup Reminder */
.backup-reminder {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.5rem;
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 500;
}

.btn-dismiss {
    background: transparent;
    border: 1px solid var(--input-border);
    color: var(--text-muted);
    border-radius: 8px;
    padding: 0.3rem 0.8rem;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.btn-dismiss:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* History List */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* Custom Scrollbar */
.history-list::-webkit-scrollbar {
    width: 8px;
}
.history-list::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 4px;
}
.history-list::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}
.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.history-item:hover {
    transform: scale(1.01);
    border-color: rgba(16, 185, 129, 0.3);
}

.history-date {
    font-weight: 600;
    color: var(--text-muted);
}

.history-weight {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
}

.btn-delete {
    background: transparent;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn-delete:hover {
    background: var(--danger-color);
    color: white;
}

/* ── Custom Date Picker ── */
.custom-date-wrapper {
    position: relative;
    width: 100%;
}

.date-display-input {
    width: 100%;
    padding: 0.8rem 2.8rem 0.8rem 1rem;
    border-radius: 12px;
    border: 2px solid var(--input-border);
    background: var(--input-bg);
    color: var(--input-text);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease, color 0.3s ease;
}

.date-display-input:focus,
.date-display-input.open {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.cal-icon {
    position: absolute;
    right: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: auto; /* FIX: was none, now clickable */
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: color 0.2s ease;
}

.cal-icon:hover {
    color: var(--primary-color);
}

.custom-calendar {
    display: none;
    position: absolute;
    z-index: 9999;
    width: 300px;
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: var(--shadow), 0 16px 48px rgba(0,0,0,0.15);
    padding: 1rem;
    transition: background 0.3s ease, border-color 0.3s ease;
}

body.dark-theme .custom-calendar {
    box-shadow: var(--shadow), 0 16px 48px rgba(0,0,0,0.6);
    border-color: rgba(16, 185, 129, 0.15);
}

.custom-calendar.open {
    display: block;
    animation: calFadeIn 0.2s ease;
}

@keyframes calFadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.cal-month-year {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-main);
    display: flex;
    gap: 0.4rem;
}

.cal-nav {
    background: transparent;
    border: 1px solid var(--input-border);
    color: var(--text-main);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    font-family: 'Outfit', sans-serif;
}

.cal-nav:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    margin-bottom: 0.4rem;
}

.cal-weekdays span {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.3rem 0;
}

.cal-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}

.cal-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-main);
    border: 1px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    font-family: 'Outfit', sans-serif;
}

.cal-day:hover {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--primary-color);
}

.cal-day.today {
    border-color: var(--accent-color);
    color: var(--accent-color);
    font-weight: 700;
}

.cal-day.selected {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
    font-weight: 700;
}

body.dark-theme .cal-day.selected {
    color: #000;
}

.cal-day.empty {
    cursor: default;
}

.cal-day.empty:hover {
    background: transparent;
    border-color: transparent;
}

/* Accessibility Focus */
.cal-day:focus,
.cal-nav:focus,
.btn-delete:focus,
.btn-primary:focus,
.btn-secondary:focus,
.btn-goal:focus,
.btn-goal-clear:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    body {
        padding: 1rem;
    }

    h1 {
        font-size: 1.8rem;
    }

    h2 {
        font-size: 1.2rem;
    }

    .card {
        padding: 1.25rem;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .controls-container {
        width: 100%;
        justify-content: space-between;
    }

    .toggle-container {
        padding: 0.4rem 0.8rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .chart-container,
    .chart-empty-state {
        height: 220px;
    }

    .history-item {
        padding: 0.8rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .history-date {
        width: 100%;
        font-size: 0.85rem;
    }

    .custom-calendar {
        width: calc(100vw - 2rem);
        left: 1rem !important;
        right: 1rem;
    }

    .goal-section {
        flex-direction: column;
        align-items: stretch;
    }

    .goal-input-group {
        width: 100%;
    }

    .data-actions {
        justify-content: center;
    }
}

@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .controls-container {
        flex-direction: column;
        width: 100%;
    }

    .toggle-container {
        justify-content: center;
    }
}

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

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


/* ── BMI Badge ── */
.bmi-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-left: 0.5rem;
}

.bmi-underweight {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.bmi-normal {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.bmi-overweight {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.bmi-obese {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Chart toggle */
.chart-toggle-container {
    padding: 0.3rem 0.8rem;
}

.chart-toggle-container .toggle-label {
    font-size: 0.85rem;
    min-width: 3.5rem;
    text-align: center;
}

/* BMI Reference Bands on Chart */
.chart-bmi-bands {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 0;
}


/* ── Height Input (cm / ft+in) ── */
.height-input-wrapper {
    width: 100%;
}

.height-ft-in {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
}

.height-ft-in input {
    flex: 1;
    padding: 0.8rem 0.6rem;
    border-radius: 12px;
    border: 2px solid var(--input-border);
    background: var(--input-bg);
    color: var(--input-text);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    outline: none;
    text-align: center;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease, color 0.3s ease;
}

.height-ft-in input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.height-separator {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-muted);
    user-select: none;
}

/* ── Footer ── */
.app-footer {
    text-align: center;
    padding: 1.5rem 0 0.5rem;
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.app-footer p {
    margin: 0;
}

.app-footer span[role="img"],
.app-footer span[style*="color"] {
    font-size: 1rem;
    line-height: 1;
}

/* Date format toggle */
.date-format-toggle-container {
    padding: 0.3rem 0.8rem;
}

.date-format-toggle-container .toggle-label {
    font-size: 0.85rem;
    min-width: 1.5rem;
    text-align: center;
}

