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

:root {
    --bg-color: #0f0f13;
    --sidebar-bg: rgba(25, 25, 35, 0.7);
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent-color: #ff7417;
    --accent-hover: #bc5206;
    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
}

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

html,
body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* Sidebar Styling */
.sidebar {
    width: 300px;
    height: 100%;
    background: var(--sidebar-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-right: var(--glass-border);
    padding: 2rem 0 0.5rem 0;
    /* Reduced bottom padding */
    /* Remove horizontal padding from main sidebar, move to scroll container or children */
    display: flex;
    flex-direction: column;
    box-shadow: var(--glass-shadow);
    z-index: 10;
    flex-shrink: 0;
    /* Prevents sidebar from squishing when content loads */
}

.brand {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
    padding: 0 2rem;
    /* Add padding here since sidebar padding was removed */
    color: var(--text-primary);
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-subtitle {
    padding: 0 2rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-weight: 400;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0 2rem;
    /* Restore padding for the scrollable area */
}

.sidebar-footer {
    padding: 1rem 2rem 0.5rem 2rem;
    /* No bottom padding here */
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0.5;
    text-align: left;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: auto;
    font-weight: 300;
}

.sidebar-footer a {
    color: inherit;
    text-decoration: none;
    transition: opacity 0.2s, color 0.2s;
}

.sidebar-footer a:hover {
    opacity: 1;
    color: var(--accent-color);
}

/* Custom Scrollbar for sidebar container */
.sidebar-scroll::-webkit-scrollbar {
    width: 6px;
}

.sidebar-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.menu-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-weight: 600;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
    margin-top: 1.5rem;
    pointer-events: none;
    /* Ensure not clickable */
}

/* Specific adjustment for the first label if needed, though scroll container padding handles top spacing */
.sidebar-scroll .menu-label:first-child {
    margin-top: 0;
}

.course-list {
    list-style: none;
    /* Removed flex: 1 and overflow-y: auto to allow natural flow */
}

/* Updated Menu Items Styling */
.course-item {
    margin-bottom: 0.25rem;
}

.course-item-container {
    display: flex;
    align-items: flex-start;
    /* Better alignment for multi-line text */
    gap: 0.5rem;
    padding-right: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.course-item-container:hover {
    background: rgba(255, 255, 255, 0.05);
}

.course-link {
    flex: 1;
    display: block;
    padding: 0.6rem 0.5rem;
    border-radius: 6px 0 0 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    /* Allow text wrapping */
    white-space: normal;
    word-break: break-word;
}

.course-link:hover {
    /* Background is handled by container hover now */
    color: var(--text-primary);
    padding-left: 0.75rem;
}

.course-link.active {
    background: rgba(255, 81, 1, 0.5);
    color: var(--accent-color);
    border-left: 3px solid var(--accent-color);
    padding-left: 0.75rem;
}

.course-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    opacity: 0.4;
    cursor: pointer;
    background: transparent;
    border: none;
    font-size: 1rem;
}

.course-item-container:hover .course-action-btn {
    opacity: 0.8;
}

.course-action-btn:hover {
    opacity: 1 !important;
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
    transform: scale(1.1);
}

/* Loading Animation for Course Items */
.course-item-container.loading {
    position: relative;
    overflow: hidden;
}

.course-item-container.loading::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    background: rgba(255, 116, 23, 0.4);
    /* More visible orange */
    transform: scaleX(0);
    transform-origin: left;
    animation: fill-loading 0.5s ease-out forwards;
}

@keyframes fill-loading {
    to {
        transform: scaleX(1);
    }
}

.course-item-container.success {
    background: rgba(76, 175, 80, 0.1) !important;
    transition: background 0.5s ease;
}

.course-item-container.error {
    background: rgba(244, 67, 54, 0.1) !important;
    transition: background 0.5s ease;
}

/* Folder / Submenu Styling */
.folder-header {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 500;
    transition: background 0.2s;
    border-radius: 6px;
    user-select: none;
}

.folder-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.folder-icon {
    font-size: 0.7rem;
    margin-right: 0.5rem;
    transition: transform 0.3s ease;
    color: var(--text-secondary);
}

.folder-header.open .folder-icon {
    transform: rotate(90deg);
    color: var(--accent-color);
}

.submenu {
    list-style: none;
    padding-left: 1rem;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    margin-left: 0.75rem;
    margin-top: 0.25rem;
}

/* Scrollbar for sidebar */
.course-list::-webkit-scrollbar {
    width: 6px;
}

.course-list::-webkit-scrollbar-track {
    background: transparent;
}

.course-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

/* Main Content Area */
.main-content {
    flex: 1;
    height: 100%;
    position: relative;
    background-image: radial-gradient(circle at top right, #1f1f2e 0%, #0f0f13 40%);
    display: flex;
    flex-direction: column;
}

#pdf-container {
    flex: 1;
    width: 100%;
    height: 100%;
    padding: 0;
    background: #1a1a1a;
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
}

.empty-state h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.9rem;
    max-width: 400px;
    line-height: 1.5;
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 19, 0.95);
    backdrop-filter: blur(15px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.login-box {
    background: rgba(30, 30, 40, 0.8);
    padding: 3rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    text-align: center;
    width: 100%;
    max-width: 400px;
}

.login-box h2 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-weight: 600;
}

.login-box p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.login-box input {
    width: 100%;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.login-box input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.login-box button {
    width: 100%;
    padding: 1rem;
    background: var(--accent-color);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.login-box button:hover {
    background: var(--accent-hover);
}

.error-msg {
    color: #ff4757;
    margin-top: 1rem;
    font-size: 0.85rem;
}

/* Class Selection Buttons */
#class-selection {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 1.5rem;
}

.loading-data {
    grid-column: 1 / -1;
    margin-bottom: 1rem !important;
}

.login-spinner {
    grid-column: 1 / -1;
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

.class-button {
    padding: 1.2rem 1rem;
    background: rgba(255, 116, 23, 0.1);
    border: 2px solid rgba(255, 116, 23, 0.3);
    border-radius: 12px;
    color: var(--accent-color);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.class-button:hover {
    background: rgba(255, 116, 23, 0.2);
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 116, 23, 0.3);
}

.class-button:active {
    transform: translateY(0);
}

/* Prof Button - Special styling */
.prof-button {
    grid-column: 1 / -1;
    /* Prend toute la largeur */
    background: transparent !important;
    border: none !important;
    border-top: 1px solid rgba(255, 255, 255, 0.05) !important;
    color: rgba(255, 116, 23, 0.5) !important;
    font-size: 0.8rem !important;
    padding: 0.6rem 1rem !important;
    margin-top: 1rem;
    text-transform: none !important;
    letter-spacing: 0.3px !important;
    font-weight: 400 !important;
    border-radius: 0 !important;
}

.prof-button:hover {
    background: rgba(255, 116, 23, 0.05) !important;
    color: rgba(255, 116, 23, 0.8) !important;
    transform: none !important;
    box-shadow: none !important;
}

/* Secondary Button (Back button) */
.secondary-button {
    width: 100%;
    padding: 0.8rem;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 0.5rem;
}

.secondary-button:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
}

#password-section {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Switch Class Button */
.switch-class-button {
    width: 100%;
    padding: 0.6rem 2rem;
    margin: -1.5rem 0 2.5rem 0;
    background: transparent;
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.75rem;
    font-weight: 400;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: none;
    letter-spacing: 0.5px;
}

.switch-class-button:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
    padding-left: 2.1rem;
}


/* Mobile PDF Viewer Styling */
#mobile-pdf-container {
    flex: 1;
    display: none;
    flex-direction: column;
    background: #1a1a1a;
    height: 100%;
    overflow: hidden;
}

#mobile-viewer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem;
    background: rgba(25, 25, 35, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
}

#mobile-viewer-controls button {
    padding: 0.5rem 1rem;
    background: var(--accent-color);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
}

#page-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.mobile-center-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#fullscreen-btn {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    padding: 0.4rem 0.6rem !important;
    font-size: 1.1rem !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: white;
}

#fullscreen-btn:active {
    background: rgba(255, 255, 255, 0.1) !important;
    transform: scale(0.95);
}

#pdf-canvas-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    position: relative;
    /* For loader positioning */
}

.pdf-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 10;
    background: rgba(18, 18, 18, 0.8);
    padding: 20px;
    border-radius: 12px;
    backdrop-filter: blur(5px);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.pdf-loader p {
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

#pdf-canvas {
    max-width: 100%;
    height: auto !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    background: white;
    display: block;
    margin: 0 auto;
    user-select: none;
    touch-action: pan-y;
    /* Only allow vertical scrolling, horizontal is handled by swipe script */
}

/* Sidebar Toggle Styles */
.sidebar {
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.sidebar.closed {
    margin-left: -300px;
}

.sidebar-toggle-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
    z-index: 20;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.sidebar-toggle-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-toggle-open {
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    background: var(--sidebar-bg);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-left: none;
    border-radius: 0 12px 12px 0;
    padding: 1rem 0.5rem;
    color: var(--accent-color);
    font-size: 1rem;
    cursor: pointer;
    z-index: 900;
    /* Below login overlay (1000) but above content */
    transition: left 0.3s ease, opacity 0.3s;
    opacity: 0;
    pointer-events: none;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.3);
}

.sidebar-toggle-open:hover {
    padding-right: 0.8rem;
    background: rgba(40, 40, 50, 0.9);
}

/* Show open button when sidebar is closed */
.sidebar-toggle-open.visible {
    opacity: 1;
    pointer-events: auto;
    left: 0;
    animation: slideFromTop 0.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideFromTop {
    from {
        top: 0;
        opacity: 0.5;
        transform: translateY(0);
    }

    to {
        top: 20%;
        opacity: 1;
        transform: translateY(-50%);
    }
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
    .sidebar {
        width: 100vw;
        min-width: 100vw;
        /* Enforce full width even if content tries to push it */
        border-right: none;
        padding-top: 4rem;
        /* More space for the close button on mobile */
    }

    .sidebar.closed {
        margin-left: -100vw;
    }

    .brand {
        font-size: 1.3rem;
        padding: 0 1.5rem;
    }

    .brand-subtitle {
        font-size: 0.8rem;
        padding: 0 1.5rem;
        margin-bottom: 1.5rem;
    }

    .sidebar-scroll {
        padding: 0 1.5rem;
    }

    .menu-label {
        font-size: 0.7rem;
        letter-spacing: 1px;
    }

    .course-link {
        font-size: 0.85rem;
        padding: 0.8rem 0.5rem;
        /* Slightly larger hit area for fingers */
    }

    .sidebar-footer {
        padding: 1rem 1.5rem 1rem 1.5rem;
        font-size: 0.75rem;
        /* Actually a tiny bit larger for readability */
    }

    .sidebar-toggle-close {
        top: 1.5rem;
        right: 1.5rem;
        width: 40px;
        height: 40px;
        font-size: 2rem;
        background: rgba(255, 255, 255, 0.05);
        /* Better visibility */
    }

    .sidebar-toggle-open {
        padding: 1.5rem 0.8rem;
        font-size: 1.2rem;
        border-radius: 0 16px 16px 0;
    }

    /* Login Box Centering */
    .login-overlay {
        left: 0;
        top: 0;
        width: 100vw;
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
        /* Prevent any internal content from triggering scroll */
    }

    .login-box {
        padding: 2rem 1.5rem;
        width: 90%;
        max-width: 400px;
        margin: 0;
        /* Let flexbox handle centering */
        box-sizing: border-box;
    }

    #class-selection {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }
}

/* --- Global Loading Overlay (Premium & Centered) --- */
.loader-overlay {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 19, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 5000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s ease;
}

.loader-overlay .loader-content {
    background: rgba(30, 30, 40, 0.9);
    padding: 3.5rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    width: 90%;
    max-width: 400px;
}

.loader-overlay .spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top: 5px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loader-overlay p {
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    margin: 0;
}