/* Add universal box-sizing for predictable height/padding calculations */
* {
    box-sizing: border-box;
}

/* Define default variables (Cream Theme) on the root */
:root {
    --color-primary-bg: #fefaf4;
    --color-secondary-bg: rgba(235, 226, 213);
    --color-content-bg: #ffffff;
    --color-text-primary: #2a2727;
    --color-text-secondary: #7a7a7a;
    --color-border-color: #c0c0c0;
    --color-action-success: #41B06E;
    --color-action-error: #D62828;
    --color-hover-light: #f5f0e4;
    --color-hover-lighter: #f1ede3;
    
    /* NEW SELECTION DEFAULTS */
    --color-selection-bg: #0F0E0E;
    --color-selection-text: #FFFFFF;
}

/* USE NEW VARIABLES FOR HIGHLIGHTING */
::selection {
    background: var(--color-selection-bg);
    color: var(--color-selection-text);
}

/* 1. Global Scrolling Prevention & Height Setup */
html, body {
    height: 100%;
    overflow: hidden; 
}

body {
    font-family: 'Work Sans', sans-serif;
    margin: 0;
    padding: 0; 
    background-color: var(--color-primary-bg); 
    color: var(--color-text-primary);         
    
    -webkit-tap-highlight-color: transparent; 
}

.app {
    display: flex;
    margin-top: 60px;
    height: calc(100vh - 60px); 
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background-color: var(--color-secondary-bg); 
    color: var(--color-text-primary);
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(97, 97, 97, 0.2);
    z-index: 1001; 
    display: flex;
    align-items: center;
    justify-content: space-between; 
}
.logo {
    font-size: 1.5em;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
}

/* Mobile Menu Toggle (Hidden by default on Desktop) */
.menu-toggle {
    display: none;
    font-size: 24px;
    padding: 5px;
    cursor: pointer;
    color: var(--color-text-primary);
    transition: color 0.1s; 
}

/* Active state for menu toggle (when pressed) */
.menu-toggle:active {
    color: var(--color-text-primary); /* Should use primary dark color for press feedback */
}


/* --- Sidebar Navigation --- */
.sidebar {
    width: 250px;
    background-color: var(--color-primary-bg); 
    
    border-right: 1px solid var(--color-border-color); 
    position: fixed;
    top: 60px; 
    height: calc(100vh - 60px); 
    
    overflow-y: hidden; 
    z-index: 999; 
    padding-top: 10px; 
}

.nav-menu {
    list-style: none;
    padding: 0 0 5px 0; /* FINE-TUNED: Controls spacing below the Settings button */
    margin: 0;
    
    display: flex;
    flex-direction: column;
    height: 100%; 
}

/* Wrapper for the main scrollable content */
.nav-content-top {
    flex-grow: 1; 
    overflow-y: auto; 
    padding-bottom: 10px; 
}


.nav-item {
    cursor: pointer;
    padding: 12px 20px;
    font-weight: 600;
    color: var(--color-text-primary); 
    transition: background-color 0.2s;
    user-select: none;
}

.nav-item:hover {
    background-color: var(--color-hover-light); 
}

/* Style to visually push and separate the settings item */
#settings-toggle {
    margin-top: auto; /* Ensures it sits at the bottom, growing the space above it */
    border-top: 1px solid var(--color-border-color);
}


.submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0; 
    overflow: hidden;
    transition: max-height 0.35s ease-in-out; 
    background-color: var(--color-primary-bg); 
}

.submenu-item {
    padding: 10px 20px 10px 40px;
    color: var(--color-text-primary);
    transition: background-color 0.2s;
    cursor: pointer;
    user-select: none;
}

.submenu-item:hover {
    background-color: var(--color-hover-lighter); 
    color: var(--color-text-primary); 
}

/* 2. Main Content becomes the dedicated scroll container */
.main-content {
    flex-grow: 1;
    margin-left: 250px;
    padding: 20px 30px 20px; 
    position: relative; 
    perspective: 1000px; 
    display: flex; 
    justify-content: center;
    align-items: flex-start; 
    height: 100%; 
    overflow-y: auto; 
    overflow-x: hidden; 
}

.list-container {
    width: 100%; 
    padding: 0; 
    z-index: 10;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out; 
}

.list-container.show {
    opacity: 1;
    visibility: visible;
}

.list-container h2 {
    margin-top: 0;
    border-bottom: 2px solid var(--color-text-primary); 
    padding-bottom: 10px;
    color: var(--color-text-primary); 
}

.list-item {
    padding: 15px 20px; 
    margin-bottom: 5px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s;
    font-weight: 600;
    display: flex; 
    align-items: center;
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis; 
}
.list-item > span {
    flex-shrink: 0; 
}
.list-item span:nth-child(2) {
    margin: 0 4px; 
}

.list-item:hover {
    background-color: var(--color-hover-light);
}

.list-item.copied {
    background-color: var(--color-action-success); 
    color: var(--color-content-bg); 
}

.subject {
    font-style: italic;
    color: var(--color-text-secondary); 
    margin-left: 5px;
}

/* New Style for image container */
.image-container {
    margin-top: 15px;
    margin-bottom: 20px;
    border: 1px solid var(--color-border-color);
    padding: 10px;
    background-color: var(--color-content-bg);
    border-radius: 4px;
    text-align: center;
}

.image-container img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}


/* ==================================== */
/* --- DOWNLOAD ITEM STYLES (Used by Lessons & Schedules) --- */
/* ==================================== */

.download-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px; 
    margin-bottom: 8px;
    border-radius: 4px;
    background-color: var(--color-content-bg); 
    border: 1px solid var(--color-border-color); 
    transition: background-color 0.15s;
}

.download-item:hover {
    background-color: var(--color-hover-light);
}

.preview-block {
    flex-grow: 1;
    text-decoration: none; 
    color: inherit;
    display: flex; 
    padding-right: 15px;
}

.file-info {
    flex-grow: 1;
}

.file-link {
    font-weight: 700;
    color: var(--color-text-primary); 
    display: block;
    font-size: 1.1em;
}

.file-meta {
    display: none; 
}

.actions {
    display: flex;
    align-items: center; 
    gap: 10px;
    min-width: 140px; 
    flex-shrink: 0; 
}

.action-button {
    padding: 8px 15px;
    border: 1px solid var(--color-text-primary); 
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 600;
    background-color: var(--color-content-bg); 
    color: var(--color-text-primary);
    text-align: center;
    transition: background-color 0.2s, color 0.2s;
}

.action-button.download-button {
    border-color: var(--color-action-success); 
    color: var(--color-action-success);
}

.action-button.pdf-button {
    border-color: var(--color-action-error); 
    color: var(--color-action-error);
}

.action-button:hover {
    background-color: var(--color-text-primary);
    color: var(--color-content-bg);
}

.action-button.download-button:hover {
    background-color: var(--color-action-success);
    color: var(--color-content-bg);
    border-color: var(--color-action-success);
}

.action-button.pdf-button:hover {
    background-color: var(--color-action-error);
    color: var(--color-content-bg);
    border-color: var(--color-action-error);
}


/* --- SCHEDULE OVERRIDE: FORCE WHITE BACKGROUND & FIXED TEXT COLOR --- */

/* Force ALL text inside schedules to the default primary color */
.schedule-display, 
.schedule-display * {
    color: #2a2727; 
}

/* Ensure secondary text areas (like file meta info, though hidden) don't inherit a random color */
.schedule-display .file-meta,
.schedule-display .subject {
    color: #7a7a7a; /* Keep secondary text slightly muted */
}

/* Force white background */
.schedule-display .image-container,
.schedule-display .download-item {
    background-color: #ffffff;
}

/* H2 Border */
.schedule-display h2 {
    border-bottom: 2px solid #2a2727;
}

/* Button overrides for appearance */
.schedule-display .action-button {
    background-color: #ffffff;
    border-color: #2a2727; /* Standard button border */
    color: #2a2727; /* Standard button text */
}

/* Re-apply theme colors for specific button styles (Download/Error), but keep text white on hover */
.schedule-display .action-button.download-button {
    border-color: var(--color-action-success); 
    color: var(--color-action-success);
}
.schedule-display .action-button.pdf-button {
    border-color: var(--color-action-error); 
    color: var(--color-action-error);
}

/* Ensure hover state still works correctly */
.schedule-display .action-button:hover {
    /* Standard button hover: dark background, white text */
    background-color: #2a2727;
    color: #ffffff;
}
.schedule-display .action-button.download-button:hover {
    background-color: var(--color-action-success);
    color: #ffffff; 
}
.schedule-display .action-button.pdf-button:hover {
    background-color: var(--color-action-error);
    color: #ffffff; 
}

/* --- B3 3D Follower Styles --- */
#b3-follower {
    position: absolute;
    font-size: 15em; 
    font-weight: 900;
    color: var(--color-secondary-bg); 
    pointer-events: none; 
    z-index: 1; 

    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
    transition: transform 0.2s ease-out, opacity 0.5s; 
}

#b3-follower.hide {
    opacity: 0;
}
#b3-follower.show {
    opacity: 1;
}

/* --- Settings Specific Styles --- */

/* Theme Grid Layout */
.theme-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.theme-card {
    border: 2px solid var(--color-border-color);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
    /* Removed default background color, now set via inline JS */
    user-select: none;
}

.theme-card:hover {
    /* Apply current theme's primary text color to border on hover */
    border-color: var(--color-text-primary);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.theme-card img {
    width: 100%;
    max-height: 150px; 
    object-fit: cover;
    display: block;
    margin: 0 auto 10px auto; /* Center image */
    border-radius: 4px;
}

.theme-card span {
    font-weight: 600;
    /* Color is now set via inline JS */
    display: block; 
    text-align: left; /* Aligns text left */
    padding-left: 5px; /* Indentation */
}


/* ==================================== */
/* --- SCROLLBAR CUSTOMIZATION (Webkit) --- */
/* ==================================== */

/* Scrollbar for the main content area */
.main-content::-webkit-scrollbar {
    width: 8px; /* Make it thin */
}
.main-content::-webkit-scrollbar-track {
    background: var(--color-primary-bg); 
}
.main-content::-webkit-scrollbar-thumb {
    background-color: var(--color-border-color); 
    border-radius: 0; 
}
.main-content::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-text-secondary); 
}

/* Scrollbar for the menu content (nav-content-top) */
.nav-content-top::-webkit-scrollbar {
    width: 8px; 
}
.nav-content-top::-webkit-scrollbar-track {
    background: var(--color-primary-bg); 
}
.nav-content-top::-webkit-scrollbar-thumb {
    background-color: var(--color-border-color); 
    border-radius: 0; 
}
.nav-content-top::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-text-secondary); 
}


/* ==================================== */
/* --- RESPONSIVENESS (MAX-WIDTH 900px) --- */
/* ==================================== */

@media (max-width: 900px) {
    
    /* 1. Layout adjustment for mobile */
    .app {
        margin-top: 50px;
        height: calc(100vh - 50px);
    }
    
    .header {
        height: 50px;
        padding: 0 15px;
        justify-content: flex-start; 
    }
    .logo {
        font-size: 1.3em;
    }
    
    .menu-toggle {
        display: block;
        margin-left: auto; 
        order: 2; 
        font-size: 28px;
        line-height: 1;
        padding: 5px;
        color: var(--color-text-primary);
        transition: color 0.1s;
        margin-right: 20px; 
    }
    
    .menu-toggle:active {
        color: var(--color-text-primary); 
        background-color: rgba(0, 0, 0, 0.05); 
    }


    /* 2. Sidebar Transformation (Overlay Menu) */
    .sidebar {
        width: 70vw; 
        max-width: 300px;
        top: 50px;
        height: calc(100vh - 50px);
        
        transform: translateX(-100%);
        transition: transform 0.35s ease-in-out;
        z-index: 999; /* Lower z-index slightly for safety */
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        /* If content overflows in mobile, the whole menu must scroll */
        overflow-y: auto; 
    }
    
    .app.sidebar-open .sidebar {
        transform: translateX(0);
    }
    
    /* For mobile view, we want the whole nav-menu to scroll if the items push it over height. 
       We temporarily disable flex-grow on nav-content-top so scrolling works for the whole sidebar. */
    .nav-menu {
        /* Padding bottom is still respected for the 5px lift */
        height: auto; /* Allow the content to define the height */
        min-height: 100%;
    }
    .nav-content-top {
        flex-grow: 0; 
        padding-bottom: 0;
    }
    
    /* When the whole sidebar scrolls on mobile, we don't want the settings separator on top of scrolling content */
    #settings-toggle {
        margin-top: 0; 
        border-top: none; 
        /* Re-adding separation specifically below the dynamic modules */
        border-top: 1px solid var(--color-border-color);
    }


    /* 3. Main Content Adjustment (Gap increase) */
    .main-content {
        margin-left: 0; 
        padding: 15px 15px 20px; 
    }

    /* 4. List items for Emails (Teachers) */
    .list-item {
        display: block; 
        white-space: normal; 
        line-height: 1.3;
    }

    .list-item > span {
        display: block;
        flex-shrink: 1;
        margin: 0;
        color: inherit; 
        font-style: normal;
    }

    .list-item span:nth-child(2) {
        display: none; 
    }
    
    .subject {
        display: block;
        font-style: italic;
        color: var(--color-text-secondary);
        margin-top: 2px; 
        font-weight: 400; 
    }


    /* 5. Download Item adjustments (Stacking) */
    .download-item {
        flex-direction: column; 
        align-items: flex-start;
        padding: 10px 15px;
    }

    .preview-block {
        padding-right: 0;
        width: 100%;
        margin-bottom: 10px;
    }

    .file-link {
        font-size: 1em;
    }

    .actions {
        margin-top: 0;
        width: 100%;
        justify-content: space-between;
    }

    .action-button {
        flex-grow: 1;
        margin: 0 5px;
    }
    /*
    /* 6. B3 Follower */
    #b3-follower {
        font-size: 10em; 
    }
    
    /* Settings layout adjustment for mobile */
    .theme-selection-grid {
        grid-template-columns: 1fr; 
        gap: 15px;
    }
    
    .theme-card img {
        max-height: 120px;
    }
}