/* =========================================
   DASHBOARD SPECIFIC GLOBALS
   ========================================= */
body.dashboard-page {
    height: 100vh;
    overflow: hidden; /* Prevents full page scroll, making it feel like an app */
    display: flex;
    flex-direction: column;
}

/* Minimal Dashboard Navigation */
.dashboard-nav { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 1rem 2rem; background: rgba(255, 255, 255, 0.92); 
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); 
    border-bottom: 1px solid rgba(14, 165, 233, 0.2); flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

body.dark-mode .dashboard-nav {
    background: #0a0800;
    border-bottom-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

.dashboard-nav .logo span { color: var(--theme-color); }

.back-btn { 
    display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1.5rem; border-radius: 50px; 
    font-size: 0.9rem; font-weight: 500; text-decoration: none; 
    background: rgba(14, 165, 233, 0.1); color: var(--text-main); 
    border: 1px solid rgba(14, 165, 233, 0.2); transition: 0.3s; 
}
.back-btn:hover { background: var(--theme-color); color: white; border-color: transparent; }

body.dark-mode .back-btn {
    background: rgba(255, 223, 0, 0.05);
    border-color: rgba(255, 223, 0, 0.15);
}

body.dark-mode .back-btn:hover {
    background: #ffd700;
    color: #0a0800;
}

/* =========================================
   DASHBOARD LAYOUT
   ========================================= */
.dashboard {
    display: flex; flex: 1; padding: 1.5rem; gap: 1.5rem; 
    max-width: 1800px; margin: 0 auto; width: 100%; height: calc(100vh - 70px);
}

/* LEFT: PDF PREVIEW PANE */
.preview-pane {
    flex: 1; /* Takes up 65-70% of screen */
    background:white; backdrop-filter: blur(24px); border: 1px solid rgba(14, 165, 233, 0.2); 
    border-radius: 20px; display: flex; flex-direction: column; overflow: hidden; 
    box-shadow: 0 20px 40px rgba(0,0,0,0.08); transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.preview-header {
    padding: 1rem 1.5rem; border-bottom: 1px solid rgba(14, 165, 233, 0.15); 
    display: flex; justify-content: space-between; align-items: center; background: rgba(14, 165, 233, 0.05);
}
.preview-title { 
    font-size: 1.1rem; font-weight: 600; color: var(--theme-color); 
    display: flex; align-items: center; gap: 0.5rem; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}

.header-actions { display: flex; gap: 1rem; align-items: center; }

.download-btn {
    padding: 0.5rem 1.2rem; background: var(--theme-color); color: white; text-decoration: none; 
    border-radius: 8px; font-size: 0.85rem; font-weight: 600; transition: 0.2s; pointer-events: none; opacity: 0.5;
}
.download-btn.active { pointer-events: auto; opacity: 1; }
.download-btn.active:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(14, 165, 233, 0.2); }

.iframe-container { flex: 1; width: 100%; position: relative; background: #faf9f6; }
iframe { width: 100%; height: 100%; border: none; }

.preview-placeholder {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; 
    justify-content: center; align-items: center; color: var(--text-muted); background: #faf9f6; z-index: 10; transition: opacity 0.3s;
}
.preview-placeholder h2 { color: var(--text-main); margin-top: 1rem; font-weight: 500;}

/* RIGHT: FILE TREE DIRECTORY */
.file-tree {
    width: 400px; /* Fixed width sidebar */
    background: white; backdrop-filter: blur(24px); border: 1px solid rgba(14, 165, 233, 0.2); 
    border-radius: 20px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.08);
}

.tree-header { padding: 1.5rem; border-bottom: 1px solid rgba(14, 165, 233, 0.15); background: rgba(14, 165, 233, 0.05); flex-shrink: 0; }
.tree-header h2 { font-size: 1.3rem; font-weight: 600; color: var(--text-heading); display: flex; align-items: center; gap: 0.5rem; }
.tree-header p { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.3rem; }

.tree-content { padding: 1rem; overflow-y: auto; flex: 1; }

/* Accordion Files */
details.year-group { margin-bottom: 0.5rem; background: white; border: 1px solid rgba(14, 165, 233, 0.15); border-radius: 12px; overflow: hidden; }
details.year-group > summary { 
    padding: 1rem; font-weight: 600; color: var(--text-main); cursor: pointer; list-style: none; 
    display: flex; justify-content: space-between; align-items: center; background: white; transition: 0.2s;
}
details.year-group > summary:hover { background: rgba(14, 165, 233, 0.12); color: var(--theme-color); }
details.year-group > summary::-webkit-details-marker { display: none; }
details.year-group > summary::after { content: '+'; font-size: 1.2rem; color: var(--theme-color); transition: 0.3s; }
details.year-group[open] > summary::after { content: '−'; }

.session-group { padding: 0.5rem 1rem 1rem; border-left: 2px solid rgba(14, 165, 233, 0.2); margin: 0.5rem 1rem; }
.session-title { font-size: 0.85rem; color: var(--theme-color); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; margin-bottom: 0.8rem; display: flex; align-items: center; gap: 0.5rem;}

.paper-link {
    display: flex; justify-content: space-between; align-items: center; padding: 0.7rem 1rem; 
    margin-bottom: 0.4rem; background: rgba(14, 165, 233, 0.05); border-radius: 8px; cursor: pointer; transition: 0.2s; border: 1px solid transparent;
}
.paper-link:hover { background: rgba(14, 165, 233, 0.12); border-color: rgba(14, 165, 233, 0.2); transform: translateX(5px); }
.paper-link.active-paper { background: rgba(14, 165, 233, 0.15); border-color: var(--theme-color); }

.paper-name { font-size: 0.9rem; font-weight: 500; color: var(--text-main); }
.badges { display: flex; gap: 0.4rem; }
.badge { font-size: 0.7rem; font-weight: 700; padding: 0.2rem 0.5rem; border-radius: 4px; }
.badge-qp { background: rgba(14, 165, 233, 0.15); color: var(--accent-blue); }
.badge-ms { background: rgba(14, 165, 233, 0.2); color: var(--theme-color); }

/* =========================================
   MOBILE POPUP MODAL
   ========================================= */
@media (max-width: 900px) {
    body.dashboard-page { overflow-y: auto; height: auto; }
    .dashboard { flex-direction: column; height: auto; padding: 1rem; }
    .file-tree { width: 100%; order: 2; height: calc(100vh - 100px); border-radius: 16px; }
    
    /* Convert Preview Pane into a hidden Popup Modal */
    .preview-pane {
        position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
        z-index: 9999; border-radius: 0; border: none;
        background: rgba(240, 245, 253, 0.98); 
        transform: translateY(100%); 
    }
    .preview-pane.active-modal { transform: translateY(0); }

    .mobile-close { display: flex !important; }
    .preview-title { max-width: 50%; font-size: 0.9rem; }
    .header-actions { gap: 0.5rem; }
    .download-btn { padding: 0.5rem 0.8rem; }
}

/* =========================================
   DARK MODE DASHBOARD STYLES
   ========================================= */

body.dark-mode .dashboard-nav {
    background: #0a0800;
    border-bottom-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

body.dark-mode .back-btn {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
    color: #cbd5e1;
}

body.dark-mode .back-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

body.dark-mode .preview-pane {
    background: linear-gradient(135deg, rgba(30, 58, 138, 0.3) 0%, rgba(45, 90, 150, 0.3) 100%);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.9);
}

body.dark-mode .preview-header {
    border-bottom-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
}

body.dark-mode .preview-title {
    color: #fff;
}

body.dark-mode .iframe-container {
    background: #000;
}

body.dark-mode .preview-placeholder {
    background: #000;
    color: #64748b;
}

body.dark-mode .preview-placeholder h2 {
    color: #cbd5e1;
}

body.dark-mode .file-tree {
    background: linear-gradient(135deg, rgba(30, 58, 138, 0.3) 0%, rgba(45, 90, 150, 0.3) 100%);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.9);
}

body.dark-mode .tree-header {
    border-bottom-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
}

body.dark-mode .tree-header h2 {
    color: #f0f9ff;
}

body.dark-mode .tree-header p {
    color: #64748b;
}

body.dark-mode details.year-group {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode details.year-group > summary {
    background: rgba(255, 255, 255, 0.06);
    color: #cbd5e1;
}

body.dark-mode details.year-group > summary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

body.dark-mode details.year-group > summary::after {
    color: #fff;
}

body.dark-mode .session-group {
    border-left-color: rgba(255, 255, 255, 0.15);
}

body.dark-mode .session-title {
    color: #fff;
}


body.dark-mode .session-content{
    background: rgba(4, 3, 32, 0.67);;
}


body.dark-mode .paper-link {
    background: rgba(255, 255, 255, 0.04);
    border-color: transparent;
}

body.dark-mode .paper-link:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

body.dark-mode .paper-link.active-paper {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

body.dark-mode .paper-name {
    color: #cbd5e1;
}

body.dark-mode .badge-qp {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

body.dark-mode .badge-ms {
    background: rgba(17, 15, 15, 0.18);
    color: hsl(from var(--theme-color) h 100% 70%);
}

@media (max-width: 900px) {
    body.dark-mode .preview-pane.active-modal {
        background: #0a0800;
    }
}

/* =========================================
   CLONED TREE OVERLAY (FILE SELECTORS)
   ========================================= */
.panel-selector-overlay {
    position: absolute; inset: 0; background: var(--bg-primary); z-index: 5;
    display: flex; flex-direction: column; padding: 2rem; overflow-y: auto;
}
.panel-selector-overlay .selector-header h3 { color: var(--text-heading); margin-bottom: 0.5rem; }
.panel-selector-overlay .selector-header p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }

.cloned-tree-container {
    flex: 1; overflow-y: auto; background: rgba(14, 165, 233, 0.03);
    border: 1px solid rgba(14, 165, 233, 0.15); border-radius: 12px;
    margin-top: 1rem; padding: 0;
}
.cloned-tree-container .tree-content { padding: 1rem; height: auto; }

body.dark-mode .panel-selector-overlay { background: #0a0800; }
body.dark-mode .cloned-tree-container { background: rgba(0, 0, 0, 0.2); border-color: rgba(255, 255, 255, 0.1); }

/* =========================================
   PDF LOADING STATE
   ========================================= */
.pdf-loader {
    position: absolute; inset: 0; z-index: 10;
    background: var(--glass-bg); backdrop-filter: blur(10px);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: opacity 0.3s ease;
}

.pdf-loader .spinner {
    width: 40px; height: 40px; margin-bottom: 1rem;
    border: 4px solid rgba(14, 165, 233, 0.2);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.pdf-loader p {
    color: var(--text-main); font-weight: 500; font-size: 0.95rem;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

body.dark-mode .pdf-loader { background: rgba(10, 8, 0, 0.8); }
body.dark-mode .pdf-loader p { color: #cbd5e1; }


/* =========================================
   AUTO-PAIR TOGGLE BUTTON
   ========================================= */
.active-pair {
    background: rgba(16, 185, 129, 0.1) !important;
    color: #10b981 !important;
    border-color: rgba(16, 185, 129, 0.3) !important;
}

body.dark-mode .active-pair {
    background: rgba(16, 185, 129, 0.15) !important;
    color: #34d399 !important;
}


/* =========================================
   MOBILE UI OVERRIDES (Cleaner Split Screen)
   ========================================= */
@media (max-width: 1024px) {
    /* Hide the Auto-Pair button */
    #auto-pair-btn {
        display: none !important;
    }
    
    /* Hide the ENTIRE header on the Bottom Pane */
    #pane-2-wrapper .preview-header {
        display: none !important;
    }

    /* Force the Top and Bottom selection menus to stretch down 100% of the screen */
    #panel-1-selector, #panel-2-selector {
        position: absolute !important;
        top: 60px !important; /* Start right beneath the top header */
        left: 0 !important;
        right: 0 !important;
        height: calc(100vh - 60px) !important; /* Stretch all the way down */
        z-index: 9999 !important;
        background-color: #0b1120 !important; /* Solid dark background */
        overflow-y: auto !important;
    }
}

/* =========================================
   HEADER ICONS & RED CLOSE BUTTONS
   ========================================= */
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 0;
    background: rgba(14, 165, 233, 0.1); color: var(--text-main);
    border: 1px solid rgba(14, 165, 233, 0.2); border-radius: 8px;
    font-size: 1.1rem; cursor: pointer; transition: 0.2s; text-decoration: none;
}

.icon-btn:hover { 
    background: rgba(14, 165, 233, 0.2); color: var(--accent-blue); 
    transform: translateY(-2px);
}

body.dark-mode .icon-btn { 
    background: rgba(255, 255, 255, 0.08); color: #cbd5e1; border-color: rgba(255, 255, 255, 0.1); 
}

body.dark-mode .icon-btn:hover { 
    background: rgba(255, 255, 255, 0.15); color: #fff; 
}

/* Red Close Buttons */
.close-icon-btn {
    background: rgba(239, 68, 68, 0.08) !important; color: #ef4444 !important; border-color: rgba(239, 68, 68, 0.2) !important;
}
.close-icon-btn:hover {
    background: rgba(239, 68, 68, 0.15) !important; color: #dc2626 !important;
}

body.dark-mode .close-icon-btn {
    background: rgba(239, 68, 68, 0.15) !important; color: #f87171 !important; border-color: rgba(239, 68, 68, 0.3) !important;
}
body.dark-mode .close-icon-btn:hover {
    background: rgba(239, 68, 68, 0.25) !important; color: #fca5a5 !important;
}

/* =========================================
   SUBTLE FULLSCREEN & SPLIT LAYOUT
   ========================================= */
.preview-pane { flex-direction: row; transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.pane-wrapper { display: flex; flex-direction: column; width: 100%; height: 100%; transition: width 0.3s ease; }
.split-hidden { display: none !important; }

/* The Pop-up Modal State */
.preview-pane.is-fullscreen {
    position: fixed; top: 2vh; left: 2vw; width: 96vw; height: 96vh; z-index: 10000;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(14, 165, 233, 0.4);
    border-radius: 20px;
}

/* Background Blur Overlay */
.preview-pane.is-fullscreen::before {
    content: ''; position: fixed; top: -2vh; left: -2vw; width: 100vw; height: 100vh;
    background: rgba(2, 9, 26, 0.6); backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px);
    z-index: -1;
}

/* Active Split Panes */
.preview-pane.is-split #pane-1-wrapper { width: 50%; border-right: 1px solid rgba(14, 165, 233, 0.2); }
.preview-pane.is-split #pane-2-wrapper { width: 50%; display: flex !important; }

/* Visibility toggles based on state */
.is-split .hide-in-split { display: none !important; }
.split-only-btn { display: none !important; }
.is-split .split-only-btn { display: inline-flex !important; }
.mobile-close { display: none !important; } /* Only show on mobile queries */

/* =========================================
   RESPONSIVE OVERRIDES
   ========================================= */
/* Mobile Devices */
@media (max-width: 1024px) {
    .preview-pane.is-fullscreen { 
        flex-direction: column !important; top: 0; left: 0; width: 100vw; height: 100vh; border-radius: 0; border: none; 
    }
    
    .preview-pane.is-split #pane-1-wrapper {
        width: 100% !important; height: 50% !important; border-right: none !important; border-bottom: 2px solid rgba(14, 165, 233, 0.3) !important;
    }
    
    .preview-pane.is-split #pane-2-wrapper { width: 100% !important; height: 50% !important; }
    .preview-pane.is-fullscreen .preview-header { padding: 0.5rem 0.8rem; }
    .preview-pane.is-fullscreen .preview-title { font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 35%; }
    .mobile-close { display: inline-flex !important; }
}

/* Small Laptops (Auto-Zoom Out) */
@media (min-width: 1025px) and (max-width: 1440px) {
    html { font-size: 14px; } /* Scales down all rem-based units automatically */
    
    .dashboard { padding: 1rem; gap: 1rem; }
    .file-tree { width: 320px; } /* Prevents the sidebar from squishing */
    .subject-hub-nav { padding: 15px; gap: 10px; }
    .subject-hub-item { padding: 12px 8px; }
}