/* ===== CSS Reset & Root Variables ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color Palette */
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-tertiary: #1a1a25;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-card-hover: rgba(255, 255, 255, 0.06);
    --bg-glass: rgba(17, 17, 24, 0.85);
    --bg-input: rgba(255, 255, 255, 0.05);

    --text-primary: #f0f0f5;
    --text-secondary: #9494a8;
    --text-muted: #5a5a6e;

    --accent-primary: #6366f1;
    --accent-secondary: #a855f7;
    --accent-tertiary: #06b6d4;
    --accent-gradient: linear-gradient(135deg, #6366f1, #a855f7);
    --accent-gradient-2: linear-gradient(135deg, #a855f7, #06b6d4);

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-focus: rgba(99, 102, 241, 0.4);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);

    /* Subject Colors */
    --clr-daa: #f97316;
    --clr-dbms: #3b82f6;
    --clr-m4: #10b981;
    --clr-mp: #ef4444;
    --clr-sepm: #a855f7;
    --clr-general: #6366f1;

    /* Layout */
    --sidebar-width: 320px;
    --topbar-height: 60px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

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

/* ===== Ambient Background ===== */
.ambient-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.15;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: var(--accent-primary);
    top: -15%;
    right: -10%;
    animation-delay: 0s;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: var(--accent-secondary);
    bottom: -10%;
    left: -10%;
    animation-delay: -7s;
}

.orb-3 {
    width: 300px;
    height: 300px;
    background: var(--accent-tertiary);
    top: 50%;
    left: 40%;
    animation-delay: -14s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -50px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(50px, 30px) scale(1.02); }
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-subtle);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-slow);
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    box-shadow: var(--shadow-glow);
}

.logo-title {
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.logo-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.sidebar-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

/* Search */
.search-container {
    position: relative;
    padding: 16px 20px 12px;
}

.search-icon {
    position: absolute;
    left: 34px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition-fast);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--border-focus);
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Stats */
.stats-bar {
    display: flex;
    gap: 16px;
    padding: 8px 20px 16px;
}

.stat {
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-number {
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

/* Subject List */
.subject-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 12px 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
}

.views-counter img {
    height: 20px;
    border-radius: 4px;
}

.subject-list::-webkit-scrollbar {
    width: 4px;
}

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

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

.subject-group {
    margin-bottom: 8px;
}

.subject-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
    user-select: none;
    position: relative;
}

.subject-header:hover {
    background: var(--bg-card-hover);
}

.subject-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 8px currentColor;
}

.subject-name {
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    flex: 1;
}

.subject-count {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 20px;
    background: var(--bg-input);
    color: var(--text-muted);
}

.subject-chevron {
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.subject-group.expanded .subject-chevron {
    transform: rotate(90deg);
}

.subject-files {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-slow);
}

.subject-group.expanded .subject-files {
    max-height: 2000px;
}

/* Subcategory */
.subcategory-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 34px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    user-select: none;
}

.subcategory-header:hover {
    background: var(--bg-card-hover);
}

.subcategory-name {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    flex: 1;
    text-transform: capitalize;
}

.subcategory-chevron {
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.subcategory.expanded .subcategory-chevron {
    transform: rotate(90deg);
}

.subcategory-files {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-slow);
}

.subcategory.expanded .subcategory-files {
    max-height: 2000px;
}

/* File Items */
.file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 8px 34px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    margin: 1px 0;
}

.file-item.sub-file {
    padding-left: 50px;
}

.file-item:hover {
    background: var(--bg-card-hover);
    transform: translateX(3px);
}

.file-item.active {
    background: rgba(99, 102, 241, 0.12);
    border-left: 2px solid var(--accent-primary);
}

.file-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: white;
}

.file-name {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.file-item:hover .file-name {
    color: var(--text-primary);
}

.file-item.active .file-name {
    color: var(--text-primary);
    font-weight: 500;
}

.file-size {
    font-size: 0.65rem;
    color: var(--text-muted);
    flex-shrink: 0;
    font-weight: 500;
}

.btn-dl {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all var(--transition-fast);
}

.file-item:hover .btn-dl {
    opacity: 1;
}

.btn-dl:hover {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-primary);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    height: 100vh;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
}

/* Welcome Screen */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.welcome-card {
    text-align: center;
    max-width: 500px;
    animation: fadeInUp 0.6s ease-out;
}

.welcome-icon {
    margin-bottom: 24px;
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.05); }
}

.welcome-title {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 12px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 32px;
}

.quick-subjects {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.quick-btn {
    padding: 10px 20px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    backdrop-filter: blur(10px);
}

.quick-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-focus);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

/* ===== PDF Viewer ===== */
.pdf-viewer {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.viewer-topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.btn-back:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-focus);
}

.viewer-title {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.btn-control {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.btn-control:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.zoom-level,
.page-info {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
    user-select: none;
}

.control-divider {
    width: 1px;
    height: 24px;
    background: var(--border-subtle);
    margin: 0 4px;
}

/* PDF Canvas */
.pdf-canvas-container {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
    cursor: grab;
}

.pdf-canvas-container:active {
    cursor: grabbing;
}

.pdf-canvas-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.pdf-canvas-container::-webkit-scrollbar-track {
    background: transparent;
}

.pdf-canvas-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.pages-wrapper {
    display: flex;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
}

.pages-wrapper canvas {
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-sm);
    image-rendering: auto;
}

.btn-control.active {
    background: rgba(99, 102, 241, 0.2);
    color: var(--accent-primary);
}

/* Image Viewer */
.image-viewer {
    max-width: 100%;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    object-fit: contain;
    transition: transform 0.2s ease;
}

/* PPT Viewer (iframe) */
.ppt-viewer {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius-sm);
    background: #1a1a25;
    position: absolute;
    inset: 0;
}

.pdf-canvas-container {
    position: relative;
}

/* PPT Fallback */
.ppt-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
}

.fallback-card {
    text-align: center;
    padding: 48px 40px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(20px);
    max-width: 400px;
}

.fallback-card h3 {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 20px 0 8px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.fallback-card p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 6px;
}

.fallback-hint {
    color: var(--text-muted) !important;
    font-size: 0.78rem !important;
    margin-bottom: 24px !important;
}

.fallback-btn {
    padding: 12px 28px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--accent-gradient);
    color: white;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-glow);
}

.fallback-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 40px rgba(99, 102, 241, 0.3);
}

/* File type badges */
.file-icon.ppt {
    background: rgba(249, 115, 22, 0.15) !important;
    color: #f97316 !important;
}

.file-icon.doc {
    background: rgba(59, 130, 246, 0.15) !important;
    color: #3b82f6 !important;
}

.file-icon.img {
    background: rgba(16, 185, 129, 0.15) !important;
    color: #10b981 !important;
}

/* Bottom Bar */
.viewer-bottombar {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* Loading Spinner */
.loading-spinner {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding-top: 100px;
}

.loading-spinner.visible {
    display: flex;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border-subtle);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner p {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 90;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Page Turn Slide Animations */
@keyframes slideOutLeft {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-60px); opacity: 0; }
}

@keyframes slideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(60px); opacity: 0; }
}

@keyframes slideInRight {
    from { transform: translateX(60px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideInLeft {
    from { transform: translateX(-60px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    /* Floating toggle button for mobile */
    .mobile-toggle {
        position: fixed;
        top: 14px;
        left: 14px;
        z-index: 80;
        width: 42px;
        height: 42px;
        border-radius: var(--radius-md);
        background: var(--bg-glass);
        backdrop-filter: blur(20px);
        border: 1px solid var(--border-subtle);
        color: var(--text-primary);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: var(--transition-fast);
    }

    .mobile-toggle:hover {
        background: var(--bg-card-hover);
    }

    .viewer-controls {
        gap: 2px;
    }

    .control-divider {
        display: none;
    }

    .zoom-level,
    .page-info {
        min-width: 40px;
        font-size: 0.7rem;
    }

    .btn-back span {
        display: none;
    }

    .viewer-topbar {
        padding: 0 12px;
        gap: 8px;
    }

    #btnTwoPage,
    #btnFullscreen {
        display: none !important;
    }

    .viewer-title {
        font-size: 0.75rem;
        max-width: 120px;
    }

    .pdf-canvas-container {
        padding: 8px;
    }

    .welcome-screen {
        padding: 16px;
    }

    .welcome-card {
        padding: 0;
    }

    .welcome-title {
        font-size: 1.4rem;
    }
}

@media (max-width: 480px) {
    .quick-btn {
        padding: 8px 14px;
        font-size: 0.72rem;
    }
}
