:root {
    /* Light Mode (Default) */
    --primary-color: #007aff;
    --primary-gradient: linear-gradient(135deg, #007aff 0%, #5ac8fa 100%);
    --background-color: #f2f2f7;
    --card-bg-color: #ffffff;
    --text-color: #1c1c1e;
    --text-light-color: #8a8a8e;
    --protein-color: #ff3b30;
    --carbs-color: #ff9500;
    --fat-color: #5856d6;
    --border-color: #e5e5ea;
}

body {
    font-family: 'Kanit', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    padding-bottom: 100px;
}

/* --- Page Layout --- */
.page {
    display: none;
}
.page.active {
    display: block;
}
.main-container {
    padding: 1rem;
}

/* --- Auth Page Styles --- */
.auth-body {
    background-color: var(--background-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}
.auth-card {
    background: var(--card-bg-color);
    padding: 2.5rem;
    border-radius: 1.5rem;
    box-shadow: 0 10px 40px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border-color);
}
.auth-card .form-control {
    padding: 0.8rem 1.2rem;
    border-radius: 0.75rem;
    background-color: #f2f2f7;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    transition: all 0.3s ease;
}
.auth-card .form-control:focus {
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
    border-color: var(--primary-color);
    background-color: #fff;
}
.divider {
    text-align: center;
    margin: 1.5rem 0;
    color: #ccc;
    display: flex;
    align-items: center;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}
.divider span {
    padding: 0 1rem;
}
.social-login {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.btn-social-google {
    background-color: #fff;
    color: #444;
    border: 1px solid var(--border-color);
}
.btn-social-facebook {
    background-color: #1877F2;
    color: #fff;
}

/* --- Home Page Styles --- */
.header-date-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.date-picker {
    font-weight: 600;
    font-size: 1.2rem;
}
.main-calorie-card {
    background-color: var(--card-bg-color);
    border-radius: 1.5rem;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.05);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}
.calorie-donut-chart {
    position: relative;
    width: 180px;
    height: 180px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    background: conic-gradient(var(--primary-color) 0deg, var(--border-color) 0deg);
    transition: background 0.5s;
}
.calorie-donut-chart::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    background: var(--card-bg-color);
    border-radius: 50%;
}
.calorie-info {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
}
.calorie-remaining {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
}
.calorie-summary {
    display: flex;
    justify-content: space-around;
    margin-top: 1.5rem;
}
.macro-card {
    background: var(--card-bg-color);
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.04);
    text-align: center;
    border: 1px solid var(--border-color);
}
.progress {
    height: 8px;
    border-radius: 4px;
    background-color: var(--border-color);
}
.log-list .list-group-item, .list-group .list-group-item-action {
    border-radius: 0.75rem !important;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
    background-color: #fff;
}

/* --- Diary Page Styles (FIXED) --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.25rem; /* Reduced gap */
    text-align: center;
    align-items: center;
}
.calendar-day-name {
    font-weight: 600;
    color: var(--text-light-color);
    font-size: 0.8rem; /* Adjusted font size */
}
.calendar-day {
    padding: 0;
    cursor: pointer;
    border-radius: 50%;
    position: relative;
    transition: background-color 0.2s;
    aspect-ratio: 1 / 1; /* Make it a responsive square */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem; /* Adjusted font size */
}
.calendar-day:hover {
    background-color: #e9f5ff;
}
.calendar-day.today {
    background: var(--primary-gradient);
    color: white;
    font-weight: 700;
}
.activity-dot {
    position: absolute;
    bottom: 15%; /* Adjusted position */
    left: 50%;
    transform: translateX(-50%);
    width: 5px; /* Adjusted size */
    height: 5px; /* Adjusted size */
    background: var(--primary-gradient);
    border-radius: 50%;
}
.calendar-day.today .activity-dot {
    background-color: white;
}

/* --- Bottom Nav & FAB --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -5px 30px rgba(0,0,0,0.05);
    border-top: 1px solid var(--border-color);
    z-index: 1000;
}
.nav-item {
    text-align: center;
    color: var(--text-light-color);
    font-size: 0.7rem;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.3s ease;
}
.nav-item.active {
    color: var(--primary-color);
    font-weight: 600;
}
.nav-item i {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 2px;
}
.fab {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    background: var(--primary-gradient);
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    box-shadow: 0 8px 20px rgba(0, 122, 255, 0.3);
    border: 3px solid white;
    z-index: 1001;
    cursor: pointer;
    transition: transform 0.3s ease;
}
.fab:hover {
    transform: translateX(-50%) scale(1.1);
}

/* --- General Components --- */
.modal-content {
    border-radius: 1.5rem;
    border: none;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}
.btn-primary {
    background: var(--primary-gradient);
    border: none;
    transition: all 0.3s ease;
}
.btn-primary:hover {
    box-shadow: 0 5px 15px rgba(0, 122, 255, 0.3);
    transform: translateY(-2px);
}

/* --- Dark Mode Styles --- */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #121212;
        --card-bg-color: #1e1e1e;
        --text-color: #e0e0e0;
        --text-light-color: #9e9e9e;
        --border-color: #2d2d2d;
    }

    .auth-body {
        background: var(--background-color);
    }

    .auth-card .form-control {
        background-color: #2c2c2e;
        border-color: #3a3a3a;
        color: var(--text-color);
    }

    .auth-card .form-control:focus {
        background-color: #3a3a3a;
    }
    
    .log-list .list-group-item, .list-group .list-group-item-action {
        background-color: var(--card-bg-color);
        border-color: var(--border-color);
    }
      
    .bottom-nav {
        background: rgba(30, 30, 30, 0.8);
        border-top-color: var(--border-color);
    }

    .fab {
        border-color: #2c2c2e;
    }

    .modal-content {
        background-color: var(--card-bg-color);
        color: var(--text-color);
    }

    .modal-header, .modal-footer {
        border-color: var(--border-color);
    }

    .btn-close {
        filter: invert(1) grayscale(100%) brightness(200%);
    }

    .calendar-day:hover {
        background-color: #2c2c2e;
    }
}

/* --- Loading Overlay Styles --- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
.loading-overlay.visible {
    opacity: 1;
    visibility: visible;
}
