/* -------------------------------------------
   MCQ Nation - Main Stylesheet (Final Version)
   ------------------------------------------- */

/* --- 1. Root Variables (Vibrant Palette) --- */
:root {
    --primary-color: #007bff; /* Blue */
    --secondary-color: #28a745; /* Green */
    --vibrant-red: #e74c3c; /* Strong Red for alerts/register */
    --light-gray: #f8f9fa; /* Light Background */
    --light-blue: #e7f1ff; /* Light Blue for category headers/hero */
    --dark-text: #343a40; /* Dark Gray Text */
    --border-color: #dee2e6;
    --shadow: 0 4px 15px rgba(0,0,0,0.08);
}

/* --- 2. Basic Reset & Setup --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--light-gray); 
    color: var(--dark-text);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    width: 90%;
    max-width: 1100px;
    margin: 0 auto;
}

/* --- 3. Header & Navigation --- */
.main-header {
    background: #fff;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.main-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    /* --- CRITICAL FIX --- */
    position: relative; /* Anchors the absolute menu position relative to the header bar */
    /* --- END CRITICAL FIX --- */
}
.main-header .logo img { max-height: 50px; }
.main-nav {
    display: flex;
    align-items: center;
    gap: 15px;
}
.main-nav a {
    text-decoration: none;
    color: #555;
    font-weight: 600;
    padding: 0.5rem;
}
/* Mobile Menu Toggle Button (Hamburger) */
.menu-toggle {
    display: none; 
    font-size: 1.8rem;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--dark-text);
}

/* --- 4. Buttons & Actions --- */
.btn {
    display: inline-block;
    width: 100%;
    padding: 0.85rem;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    transition: background-color 0.2s;
}
.btn:hover { background: #0056b3; }

.btn-sm {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    width: auto;
    font-weight: 500;
}
.main-nav a.btn { font-size: 1rem; padding: 0.5rem 1rem; }
.main-nav a.btn-logout { background: var(--vibrant-red); }

.btn-secondary { background-color: var(--secondary-color); }
.btn-secondary:hover { background-color: #1e7e34; }
.btn-warning { background-color: #ffc107; color: var(--dark-text); }
.btn-warning:hover { background-color: #e0a800; }
.btn-info { background-color: #0275d8; }
.btn-info:hover { background-color: #025aa5; }
.btn-owned { background: #6c757d; cursor: not-allowed; }

/* --- 5. Main Content & Footer --- */
.main-content {
    flex: 1;
    padding: 2rem 0;
    position: relative; /* Set stacking context for content */
    z-index: 1;
}
.main-footer {
    background: var(--dark-text);
    color: #f1f1f1;
    padding: 2rem 0;
    text-align: center;
    margin-top: auto;
}
.footer-links { margin-bottom: 1rem; }
.footer-links a { color: #fff; text-decoration: none; margin: 0 10px; }
.footer-links a:hover { text-decoration: underline; }

/* --- 6. Forms & Messages --- */
.form-wrapper {
    max-width: 450px;
    margin: 2rem auto;
    background: #fff;
    padding: 2.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.form-control {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
}
.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 1rem;
    border: 1px solid #f5c6cb;
    border-radius: 5px;
    margin-bottom: 1rem;
    list-style: none;
}

/* --- 7. Homepage & Grid Styles --- */
.hero {
    text-align: center;
    padding: 3rem 1rem; 
    background: var(--light-blue); 
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}
.hero h1 { font-size: 2.5rem; margin-bottom: 1rem; color: var(--dark-text); }
.hero p { font-size: 1.2rem; color: #555; margin-bottom: 2rem; }

.category-grid-container { padding-bottom: 3rem; }
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}
.category-card {
    display: block;
    background: var(--primary-color); 
    color: #fff; 
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    text-align: center;
    text-decoration: none;
    font-size: 1.1rem;
    border-bottom: 3px solid #fff;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}
.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
    background: #0056b3; 
}

/* --- 8. Accordion / Collapsible Styles (Browse Page) --- */
details {
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    overflow: hidden; 
    border: 1px solid var(--border-color);
}
/* TOP LEVEL - CATEGORY Header */
.category-accordion > summary {
    background-color: var(--light-blue); 
    padding: 1.2rem 1.5rem;
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 600;
}
.category-accordion > summary:hover { background-color: #dbeaff; }
summary::marker { display: none; }
summary:before {
    content: '▶';
    font-size: 0.8em;
    margin-right: 10px;
    transition: transform 0.2s;
}
details[open] > summary:before { transform: rotate(90deg); }

/* Content Area inside Category */
.accordion-content {
    padding: 1.5rem;
    background-color: #fff; 
}

/* NESTED LEVEL - COURSE Header */
.accordion-content > details {
    box-shadow: none;
    border: 1px solid var(--border-color);
    margin-bottom: 1rem;
}
.accordion-content > details > summary {
    font-size: 1.1rem;
    font-weight: 600; 
    background: var(--light-gray); 
}
.accordion-content > details > summary:hover { background: #e9ecef; }
.course-content { padding: 0; }

/* INNERMOST LEVEL - SEMESTER Header */
.course-content > details > summary {
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: 1.05rem;
    background: #fff;
    padding: 1rem 0.5rem;
    border-bottom: 1px solid #eee;
}
.course-content > details:last-child > summary { border-bottom: none; }
.course-content > details > summary:hover { background: var(--light-gray); }

.semester-content {
    padding: 1rem;
    background: #fafafa;
    border-top: 1px solid var(--border-color);
}
.semester-price {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-left: auto;
    padding-left: 20px;
}

/* Subject Item (Row) */
.subject-item {
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    padding: 0.8rem 0;
    border-bottom: 1px solid #eee;
}
.subject-item:last-child { border-bottom: none; }
.subject-item span { max-width: 60%; }

.subject-actions {
    display: flex; 
    gap: 8px; 
    align-items: center;
}

/* --- 9. Mobile Responsiveness (Screen size <= 768px) --- */
@media (max-width: 768px) {
    /* Show/Hide Menu */
    .menu-toggle { display: block; }
    .main-nav {
        display: none; 
        flex-direction: column;
        width: 100%;
        position: absolute;
        top: 100%; /* CRITICAL FIX: Starts menu below header bar */
        left: 0;
        z-index: 100;
        
        max-height: 80vh; 
        overflow-y: auto;
        
        background: #fff;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 4px 5px rgba(0,0,0,0.05);
        padding-bottom: 10px;
    }
    .main-nav.active { display: flex; }
    .main-nav a { padding: 12px 20px; width: 100%; border-bottom: 1px solid var(--light-gray); font-size: 1.05rem; }
    
    /* Adjust button inside mobile menu */
    .main-nav a.btn { margin: 10px 20px; width: calc(100% - 40px); }

    /* Fix Subject/Button Alignment */
    .subject-item { flex-direction: column; align-items: flex-start; gap: 8px; }
    .subject-item span { max-width: 100%; }
    .subject-actions { width: 100%; justify-content: flex-end; }
    .subject-actions .btn-sm { flex: 1; }
}

@media (max-width: 480px) {
    /* Stack action buttons if screen is very small */
    .subject-actions { flex-direction: column; }
    .subject-actions .btn-sm { width: 100%; }
}