/* =========================================================
   MAIN DASHBOARD GRID
========================================================= */

.container {
    display: grid;

    grid-template-columns:
        minmax(0, 1fr)
        minmax(0, 1fr);

    grid-template-areas:
        "dashboard calendar"
        "habits    calendar"
        "stats     stats"
        "analytics category"
        "leaderboard favorites"
        "achievements activity";

    gap: 16px;

    align-items: stretch;
    grid-auto-rows: minmax(0, auto);
}

/* =========================================================
   GRID AREAS
========================================================= */

#dashboardSection {
    grid-area: dashboard;
}

#calendarSection {
    grid-area: calendar;
    min-width: 0;
    height: 100%;
}

#habitsSection {
    grid-area: habits;
}

#dashboardSection,
#calendarSection,
#habitsSection,
#analyticsSection,
#categorySection,
#leaderboardSection,
#favoritesSection,
#achievementSection,
#activitySection,
#dataSection,
#storageSection {
    min-width: 0;
}

#statisticsSection {
    grid-area: stats;
}

#analyticsSection {
    grid-area: analytics;
}

#categorySection {
    grid-area: category;
}

#leaderboardSection {
    grid-area: leaderboard;
}

#favoritesSection {
    grid-area: favorites;
}

#achievementSection {
    grid-area: achievements;
}

#activitySection {
    grid-area: activity;
}


#achievementSection,
#activitySection {
    position: relative;
    top: 18px;
}

#dataSection {
    grid-area: data;
}

#storageSection {
    grid-area: storage;
}

#quickActionsSection {
    grid-area: quick;
}


#analyticsSection .weeklyChart,
#categorySection #categoryChart,
#leaderboardSection .statisticsGrid,
#favoritesSection .favoriteHabits,
#achievementSection .achievementGallery,
#activitySection .activityFeed,
#dataSection .settingsButtons,
#storageSection .statCard {
    width: 100%;
}

#leaderboardSection .statisticsGrid,
#favoritesSection,
#activitySection,
#storageSection {
    height: 100%;
}

#leaderboardSection .statCard,
#favoritesSection .favoriteCard,
#activitySection .empty,
#storageSection .statCard {
    min-width: 0;
}

/* =========================================================
   DASHBOARD
========================================================= */

#dashboardSection {
    padding: 0;
}

.dashboard {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: 10px;
}

.dashboardCard {
    min-width: 0;

    padding: 18px 12px;

    text-align: center;
}

.dashboardIcon {
    width: 28px;
    height: 28px;

    margin: 0 auto 8px;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 15px;

    color: var(--primary);
}

.dashboardCard:nth-child(2) .dashboardIcon {
    color: var(--orange);
}

.dashboardCard:nth-child(3) .dashboardIcon {
    color: var(--green);
}

.dashboardCard:nth-child(4) .dashboardIcon {
    color: var(--purple);
}

.dashboardCard h2 {
    margin-bottom: 4px;

    font-size: 1.35rem;
}

.dashboardCard p {
    color: var(--text-light);

    font-size: 0.72rem;
}

/* =========================================================
   STATISTICS
========================================================= */

.statisticsGrid {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: 10px;
}

.statCard {
    min-width: 0;

    padding: 16px;
}

.statLabel {
    color: var(--text-light);

    font-size: 0.72rem;
}

.statValue {
    margin-top: 7px;

    font-size: 1.25rem;
    font-weight: 700;

    color: var(--text);
}

/* =========================================================
   WEEKLY CHART
========================================================= */

.weeklyChart {
    min-height: 180px;

    padding: 18px;

    display: flex;
    align-items: stretch;
}

.weeklyChart .empty {
    width: 100%;

    background: transparent;

    border: none;

    box-shadow: none;

    padding: 25px 10px;
}

/* If JavaScript creates bars */

.weekBar {
    flex: 1;

    display: flex;
    flex-direction: column;

    align-items: center;
    justify-content: flex-end;

    gap: 7px;
}

.weekBar .bar {
    width: min(30px, 65%);

    min-height: 4px;

    border-radius: 8px 8px 3px 3px;

    background: linear-gradient(
        180deg,
        #5b8cff,
        #2563eb
    );

    transition: height 0.4s ease;
}

.weekBar span {
    color: var(--text-light);

    font-size: 0.68rem;
}

/* =========================================================
   CATEGORY STATISTICS
========================================================= */

#categoryChart {
    grid-template-columns: 1fr;

    gap: 8px;

    min-height: 180px;
}

.categoryRow {
    display: flex;

    align-items: center;
    justify-content: space-between;

    padding: 11px 14px;

    background: var(--card);

    border: 1px solid var(--border);

    border-radius: 10px;

    font-size: 0.78rem;
}

.categoryRow strong {
    color: var(--primary);
}

/* =========================================================
   LEADERBOARDS
========================================================= */

#leaderboardSection .statisticsGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.leaderboard {
    display: flex;

    flex-direction: column;

    gap: 7px;

    margin-top: 12px;
}

.leaderboardRow {
    display: flex;

    align-items: center;
    justify-content: space-between;

    padding: 9px 11px;

    border-radius: 9px;

    background: var(--background);

    border: 1px solid var(--border);

    font-size: 0.75rem;
}

#leaderboardSection .empty {
    padding: 20px 10px;

    background: transparent;

    border: none;

    box-shadow: none;
}

/* =========================================================
   ACHIEVEMENTS
========================================================= */

.achievementGallery {
    display: grid;

    grid-template-columns:
        repeat(auto-fit, minmax(150px, 1fr));

    gap: 10px;
}

.achievementCard {
    padding: 15px;

    text-align: center;
}

.achievementCardIcon {
    font-size: 25px;

    color: var(--yellow);

    margin-bottom: 8px;
}

.achievementCard h3 {
    font-size: 0.8rem;
}

.achievementCard p {
    margin-top: 4px;

    color: var(--text-light);

    font-size: 0.7rem;
}

.achievementCard.locked {
    opacity: 0.45;
}

.achievementCard.unlocked {
    border-color: var(--yellow);
}

/* =========================================================
   ACTIVITY
========================================================= */

.activityFeed {
    display: flex;

    flex-direction: column;

    gap: 8px;
}

.activityRow {
    padding: 11px 13px;

    display: flex;
    align-items: center;

    gap: 10px;

    font-size: 0.76rem;
}

.activityRow i {
    color: var(--green);
}

/* =========================================================
   DATA MANAGEMENT
========================================================= */

.settingsButtons {
    display: flex;

    flex-wrap: wrap;

    gap: 10px;
}

.settingsButtons button {
    min-height: 38px;

    padding: 9px 14px;

    border: 1px solid var(--border);

    border-radius: 9px;

    background: var(--card);

    color: var(--text);

    font-size: 0.75rem;

    transition: 0.2s;
}

.settingsButtons button:hover {
    transform: translateY(-2px);

    border-color: var(--primary);

    color: var(--primary);
}

#resetButton {
    border-color: rgba(239, 68, 68, 0.45);

    color: var(--red);
}

#resetButton:hover {
    background: var(--red);

    color: white;
}

/* =========================================================
   STORAGE
========================================================= */

#storageSection .statCard {
    display: flex;

    align-items: center;

    gap: 15px;

    min-height: 92px;
}

#storageSection .statLabel {
    flex: 1;
}

#storageSection .statValue {
    margin: 0;
}

/* =========================================================
   QUICK ACTIONS
========================================================= */

#quickActionsSection {
    padding-top: 2px;
}

/* =========================================================
   REMOVE HEATMAP
========================================================= */

/*
   Your old HTML still contains #heatmapSection.
   This hides it so you don't have to remove the HTML
   immediately.
*/

#heatmapSection {
    display: none !important;
}

/* =========================================================
   REMOVE OLD LOADING ELEMENT
========================================================= */

#loadingScreen {
    display: none !important;
}

/* =========================================================
   ACHIEVEMENT POPUP
========================================================= */

#achievementContainer {
    position: fixed;

    top: 20px;
    right: 20px;

    display: flex;
    flex-direction: column;

    gap: 10px;

    z-index: 9999;

    pointer-events: none;
}

.achievementPopup {
    min-width: 290px;

    padding: 14px;

    display: flex;
    align-items: center;

    gap: 12px;

    background: var(--card);

    border: 1px solid var(--border);

    border-radius: 14px;

    box-shadow: 0 15px 35px rgba(0,0,0,.15);

    transform: translateX(120%);

    opacity: 0;

    transition: 0.3s ease;
}

.achievementPopup.show {
    transform: translateX(0);

    opacity: 1;
}

.achievementIcon {
    width: 42px;
    height: 42px;

    flex-shrink: 0;

    border-radius: 12px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--yellow);

    color: white;
}

.achievementContent h4 {
    font-size: 0.82rem;

    margin-bottom: 3px;
}

.achievementContent p {
    color: var(--text-light);

    font-size: 0.72rem;
}

/* =========================================================
   DARK MODE
========================================================= */

body.dark .categoryBadge {
    background: rgba(96, 165, 250, 0.12);
}

body.dark .calendarDay {
    background: #162032;
}

body.dark .badge {
    background: #162032;
}

/* =========================================================
   TABLET
========================================================= */

@media (max-width: 1050px) {

    .container {
        grid-template-columns:
            minmax(0, 1fr)
            minmax(0, 1fr);
    }

    .dashboard {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

    .statisticsGrid {
        grid-template-columns:
            repeat(3, minmax(0, 1fr));
    }

}

/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 800px) {

    .container {
        display: flex;

        flex-direction: column;

        gap: 22px;
    }

    .dashboard {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

    .statisticsGrid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

    #leaderboardSection .statisticsGrid {
        grid-template-columns: 1fr;
    }

    .sectionDivider {
        display: none;
    }

}

@media (max-width: 500px) {

    .dashboard {
        grid-template-columns: 1fr 1fr;
    }

    .statisticsGrid {
        grid-template-columns: 1fr;
    }

    .dashboardCard {
        padding: 15px 8px;
    }

    .dashboardCard h2 {
        font-size: 1.2rem;
    }

    .settingsButtons {
        flex-direction: column;
    }

    .settingsButtons button {
        width: 100%;
    }

}

#dataSection, #storageSection, #quickActionsSection {
    display: none !important;
}
