/**
 * ============================================================================
 * CLASS RESOURCES - STYLESHEET
 * ============================================================================
 *
 * A modern, responsive stylesheet for the Class Resources web application.
 * Features a clean design with collapsible folders, fixed header/footer,
 * and mobile-optimized layouts.
 *
 * Author: Amitendu Bikash Dhusiya
 * Project: Class Resources - BCA 6th Semester
 *
 * Table of Contents:
 * 1. CSS Variables (Theme Colors)
 * 2. Base Styles & Reset
 * 3. Layout Components (Header, Footer, Container)
 * 4. Category Cards
 * 5. File List & Items
 * 6. Collapsible Folders
 * 7. Status Messages
 * 8. Mobile Responsive Styles
 * ============================================================================
 */

/* ==========================================================================
   1. CSS VARIABLES - Theme Colors & Design Tokens
   ========================================================================== */
:root {
    /* Background Colors */
    --bg-color: #F3F4F6;
    --card-bg: #FFFFFF;
    --folder-bg: #F9FAFB;
    --folder-header-bg: #FAFAFA;
    --folder-header-hover: #F3F4F6;
    --nested-list-bg: #FFFFFF;

    /* Text Colors */
    --text-primary: #111827;
    --text-secondary: #6B7280;

    /* Accent Colors */
    --accent-color: #4F46E5;
    --accent-light: #E0E7FF;

    /* Border & Dividers */
    --border-color: #E5E7EB;

    /* File Type Icon Colors */
    --icon-pdf: #EF4444;      /* Red - PDF files */
    --icon-word: #2563EB;     /* Blue - Word documents */
    --icon-code: #10B981;     /* Green - Code files */
    --icon-zip: #F59E0B;      /* Orange - Archive files */
    --icon-default: #9CA3AF;  /* Gray - Unknown types */

    /* Glassmorphism Headers/Footers */
    --header-footer-bg: rgba(255, 255, 255, 0.95);

    /* Button Colors */
    --btn-bg: #FFFFFF;
}

:root[data-theme="dark"] {
    /* Background Colors */
    --bg-color: #0F172A;
    --card-bg: #1E293B;
    --folder-bg: #0F172A;
    --folder-header-bg: #151E2E;
    --folder-header-hover: #242F41;
    --nested-list-bg: #1E293B;

    /* Text Colors */
    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;

    /* Accent Colors */
    --accent-color: #818CF8;
    --accent-light: #312E81;

    /* Border & Dividers */
    --border-color: #334155;

    /* File Type Icon Colors */
    --icon-pdf: #F87171;
    --icon-word: #60A5FA;
    --icon-code: #34D399;
    --icon-zip: #FBBF24;
    --icon-default: #9CA3AF;

    /* Glassmorphism Headers/Footers */
    --header-footer-bg: rgba(15, 23, 42, 0.9);

    /* Button Colors */
    --btn-bg: #1E293B;
}

/* ==========================================================================
   2. BASE STYLES & CSS RESET
   ========================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    overflow-y: scroll;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-color);
}

/* Custom scrollbar styling for Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
    border: 2px solid var(--bg-color);
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-secondary);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;

    /* Padding accounts for fixed header and footer */
    padding-top: 160px;     /* Space for fixed header */
    padding-bottom: 100px;  /* Space for fixed footer */

    min-height: 100vh;
}

/* ==========================================================================
   3. LAYOUT COMPONENTS
   ========================================================================== */

/* Container - Centered content wrapper */
.container { max-width: 800px; margin: 0 auto; padding: 0 20px; }

/* ---------- Fixed Header ---------- */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;

    /* Frosted glass effect */
    background: var(--header-footer-bg);
    backdrop-filter: blur(10px);

    border-bottom: 1px solid var(--border-color);
    padding: 25px 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    transition: all 0.3s ease;
}

/* Header Content - Flex layout for icon and title */
.header-content { display: flex; align-items: center; gap: 20px; }

/* Icon Box - Styled container for graduation cap icon */
.icon-box {
    width: 50px; height: 50px;
    background: var(--accent-light);
    color: var(--accent-color);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    transition: all 0.3s ease;
}

/* Header Typography */
header h1 { font-size: 1.5rem; font-weight: 700; transition: font-size 0.3s ease; }
header p { color: var(--text-secondary); margin-top: 2px; font-size: 0.9rem; }

/* ---------- Loading State ---------- */
.loading-state { text-align: center; padding: 40px; color: var(--text-secondary); }

/* ==========================================================================
   4. CATEGORY CARDS
   ========================================================================== */
/* Category Card - Main container for each section */
.category-card {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    margin-bottom: 30px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

/* Card Header - Contains section title and download button */
.card-header {
    background: var(--card-bg);
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Header Title - Icon + section name */
.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-title i { color: var(--accent-color); }
.header-title h2 { font-size: 1.1rem; font-weight: 600; }

/* ---------- Download All Button ---------- */
.download-btn {
    background-color: var(--btn-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;  /* Prevent text wrapping */
}

/* Download Button Hover State */
.download-btn:hover {
    background-color: var(--folder-bg);
    color: var(--accent-color);
    border-color: var(--accent-color);
}

/* Download Button Disabled State (during zipping) */
.download-btn:disabled { opacity: 0.7; cursor: not-allowed; }

/* ==========================================================================
   5. FILE LIST & ITEMS
   ========================================================================== */
.file-list { list-style: none; }

/* Individual File Item */
.file-item { border-bottom: 1px solid var(--border-color); }
.file-item:last-child { border-bottom: none; }

/* File Item Link - Clickable area */
.file-item a {
    display: flex; justify-content: space-between; align-items: center;
    text-decoration: none; padding: 16px 24px;
    transition: background 0.2s ease; color: var(--text-primary);
}
.file-item a:hover { background-color: var(--folder-bg); }

/* File Info - Icon and name container */
.file-info {
    display: flex; align-items: center; gap: 12px;
    overflow: hidden;  /* Prevent overflow on long names */
}
.file-info span {
    font-weight: 500; font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;  /* Truncate long file names with ... */
    max-width: 90%;
}

/* ---------- File Type Icons ---------- */
.file-icon { font-size: 1.2rem; width: 24px; text-align: center; flex-shrink: 0; }

/* Icon Colors by File Type */
.fa-file-pdf { color: var(--icon-pdf); }
.fa-file-word { color: var(--icon-word); }
.fa-file-code { color: var(--icon-code); }
.fa-file-zipper { color: var(--icon-zip); }
.fa-file { color: var(--icon-default); }

/* Download Action Icon - Always visible */
.action-icon {
    color: var(--text-secondary);
    opacity: 1;
    transition: color 0.2s ease;
    flex-shrink: 0;
}
.file-item a:hover .action-icon {
    color: var(--accent-color);
}

/* ==========================================================================
   6. COLLAPSIBLE FOLDERS
   ========================================================================== */
/* Folder Group Container */
.folder-group { border-bottom: 1px solid var(--border-color); }

/* Folder Header - Clickable area to toggle folder */
.folder-header {
    background-color: var(--folder-header-bg);
    padding: 14px 24px;
    cursor: pointer;
    user-select: none;
    display: flex; justify-content: space-between; align-items: center;
    transition: background 0.2s;
}
.folder-header:hover { background-color: var(--folder-header-hover); }

/* Folder Name - Icon and label */
.folder-name {
    display: flex; align-items: center; gap: 10px;
    font-weight: 600; color: var(--text-secondary); font-size: 0.9rem;
}

/* Folder Icon - Transition for color change */
.folder-icon { transition: color 0.2s ease; }

/* ---------- Chevron Toggle Animation ---------- */
/* Arrow points down when closed, rotates up (-180deg) when open */
.chevron {
    font-size: 0.8rem;
    color: #9CA3AF;
    transition: transform 0.3s ease, color 0.2s ease;
}

/* Rotate chevron when folder is open (down → up) */
/* Using direct child combinator (>) to only affect the folder's own header, not nested folders */
.folder-group.is-open > .folder-header .chevron {
    transform: rotate(-180deg);
    color: var(--accent-color);
}

/* Folder header styling when open */
/* Using direct child combinator (>) to only affect the folder's own header */
.folder-group.is-open > .folder-header {
    background-color: var(--folder-header-hover);
    color: var(--text-primary);
}

/* Folder icon color change when open */
.folder-group.is-open > .folder-header .folder-icon {
    color: var(--accent-color);
}

/* ---------- Nested File List ---------- */
.nested-list {
    list-style: none;
    display: none;  /* Hidden by default */
    background: var(--nested-list-bg);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

/* Show nested list when folder is open */
.folder-group.is-open > .nested-list { display: block; }

/* Indentation for nested items (visual hierarchy) */
.nested-list .file-item a, .nested-list .folder-header { padding-left: 48px; }
.nested-list .nested-list .file-item a { padding-left: 72px; }

/* ==========================================================================
   7. STATUS MESSAGES
   ========================================================================== */
/* Status Message - Empty state or error messages */
.status-msg { padding: 24px; text-align: center; color: var(--text-secondary); font-style: italic; font-size: 0.9rem; }
.status-msg.error { color: var(--icon-pdf); }

/* ---------- Fixed Footer ---------- */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;

    /* Frosted glass effect (matches header) */
    background-color: var(--header-footer-bg);
    backdrop-filter: blur(10px);

    border-top: 1px solid var(--border-color);
    padding: 15px 0;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.02);
    z-index: 1000;
}

/* Footer Content Layout */
.footer-content { display: flex; justify-content: space-between; align-items: center; }
footer p { color: var(--text-secondary); font-size: 0.85rem; font-weight: 500; }
footer i { color: #f43f5e; margin: 0 2px; }  /* Heart icon color */

/* Last Updated Badge */
.last-updated {
    background-color: var(--bg-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

/* ---------- Theme Toggle Button ---------- */
.theme-toggle {
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background-color: var(--folder-bg);
    color: var(--accent-color);
    border-color: var(--accent-color);
}

/* ==========================================================================
   8. MOBILE RESPONSIVE STYLES
   ========================================================================== */
@media (max-width: 600px) {

    /* ---------- Body Adjustments ---------- */
    /* Reduced padding for smaller fixed header/footer on mobile */
    body {
        padding-top: 120px;
        padding-bottom: 90px;
    }

    /* ---------- Compact Header ---------- */
    header { padding: 15px 0; }

    .icon-box {
        width: 40px; height: 40px;
        font-size: 1rem;
        border-radius: 10px;
    }

    header h1 { font-size: 1.25rem; }
    header p { display: none; }  /* Hide subtitle to save space */

    .theme-toggle {
        width: 36px;
        height: 36px;
        font-size: 0.95rem;
    }

    /* ---------- Compact Footer ---------- */
    .footer-content {
        flex-direction: column;
        gap: 5px;
    }
    footer p { font-size: 0.75rem; }

    /* ---------- Card Adjustments ---------- */
    .category-card { margin-bottom: 20px; }

    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 15px;
    }

    /* Full-width download button on mobile */
    .download-btn {
        width: 100%;
        justify-content: center;
        padding: 10px;  /* Larger touch target */
    }

    /* ---------- Compact File Lists ---------- */
    .file-item a { padding: 14px 15px; }
    .folder-header { padding: 14px 15px; }

    /* Reduced indentation for nested items on mobile */
    .nested-list .file-item a, .nested-list .folder-header { padding-left: 30px; }
    .nested-list .nested-list .file-item a { padding-left: 45px; }

    /* Always show download icon on mobile (no hover on touch devices) */
    .action-icon {
        opacity: 1;
        color: var(--text-secondary);
    }
}