/* ============================================================================
   GIT Study Assistant - Premium World-Class Styling
   A unified, glassmorphism-based design system for a multi-page experience.
   ============================================================================ */

/* 1. Design Tokens & Variables */
:root {
    /* Base Palette - Deep Medical Dark */
    --bg-primary: #050508;
    --bg-secondary: #0a0a0f;
    /* Slightly lighter for cards */
    --bg-tertiary: #13131f;

    /* Glass Effect Tokens */
    --glass-bg: rgba(255, 255, 255, 0.02);
    --glass-bg-hover: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-border-light: rgba(255, 255, 255, 0.1);
    --glass-shadow: rgba(0, 0, 0, 0.2);
    --glass-blur: 20px;

    /* Brand Accents - Refined Medical */
    --accent-primary: #38bdf8;
    /* Sky Blue */
    --accent-secondary: #6366f1;
    /* Indigo */
    --accent-tertiary: #e879f9;
    /* Orchid */
    --accent-glow: rgba(56, 189, 248, 0.1);
    /* Primary Glow */

    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    /* Neutral Zinc */
    --text-tertiary: #71717a;
    --text-highlight: #e4e4e7;

    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Space Grotesk', var(--font-sans);

    /* Spacing */
    --nav-height: 80px;
    --section-spacing: 6rem;
}

/* 2. Reset & Global Styles */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Animated Background Gradient (Fixed) */
.fixed-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: -1;
    background: radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.05), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(56, 189, 248, 0.05), transparent 25%);
    pointer-events: none;
}

/* 3. Navigation Bar (Common) */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--nav-height);
    background: rgba(5, 5, 8, 0.7);
    /* Translucent */
    backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--glass-border);
    z-index: 1000;
    transition: all 0.3s ease;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text-primary);
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.25rem;
}

.nav-logo svg {
    width: 32px;
    height: 32px;
}

.nav-links {
    display: flex;
    gap: 1.25rem;
    list-style: none;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.2s;
    position: relative;
    padding: 0.5rem 0;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-primary);
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent-primary);
    box-shadow: 0 0 8px var(--accent-primary);
}

.nav-cta {
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
    color: white;
    padding: 0.5rem 1.1rem;
    border-radius: 99px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.8rem;
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
    /* Prevent wrapping */
}

.nav-cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

/* 4. Page Layouts */
.main-wrapper {
    padding-top: var(--nav-height);
    min-height: 100vh;
}

/* --- HOME PAGE --- */
.hero-section {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: auto;
    padding: 1rem 1.5rem 0;
    position: relative;
    overflow: hidden;
}

.hero-content {
    max-width: 800px;
    z-index: 10;
    animation: fadeInUp 0.8s ease-out;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 99px;
    color: #a5b4fc;
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
}

.hero-title {
    font-family: var(--font-heading);
    font-size: clamp(1.8rem, 4vw, 3rem);
    line-height: 1.1;
    margin-bottom: 0.5rem;
    color: #ffffff;
}

.hero-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.hero-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.btn-secondary {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--glass-bg-hover);
}

/* Features Section */
.features-section {
    padding: 3rem 1.5rem 6rem;
    /* Reduced top padding to move it up */
    max-width: 1200px;
    margin: 0 auto;
}

.section-header {
    text-align: center;
    margin-bottom: 4rem;
}

.section-title {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.feature-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 2rem;
    border-radius: 20px;
    transition: transform 0.3s;
}

.feature-card:hover {
    transform: translateY(-5px);
    background: var(--glass-bg-hover);
    border-color: var(--glass-border-light);
}

.feature-icon {
    width: 60px;
    height: 60px;
    background: rgba(56, 189, 248, 0.07);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
    font-size: 1.75rem;
}

.feature-card h3 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.feature-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* --- TOPICS PAGE --- */
.topics-header {
    padding: 4rem 1.5rem 2rem;
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

.topics-grid-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.topic-card {
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    text-decoration: none;
    display: block;
}

.topic-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-primary);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

.topic-image {
    height: 140px;
    width: 100%;
    background: linear-gradient(45deg, #13131f, #1e1e2e);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.topic-image svg {
    width: 50px;
    height: 50px;
    opacity: 0.5;
}

.topic-content {
    padding: 1.5rem;
}

.topic-tag {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-secondary);
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: block;
}

.topic-title {
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.topic-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* --- CHAT PAGE (Adapted) --- */
.chat-layout {
    display: flex;
    height: calc(100vh - var(--nav-height));
    margin-top: var(--nav-height);
    /* Override main-wrapper */
}

.chat-sidebar {
    width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-primary);
}

.chat-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    scroll-behavior: smooth;
}

.chat-input-area {
    padding: 1.5rem 2rem 2rem;
    background: linear-gradient(to top, var(--bg-primary) 80%, transparent);
}

/* Chat Input Styling */
.input-box-wrapper {
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    transition: border 0.2s;
}

.input-box-wrapper:focus-within {
    border-color: var(--accent-primary);
}

textarea.chat-input {
    width: 100%;
    background: transparent;
    border: none;
    color: white;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
}

.send-button {
    background: var(--accent-primary);
    color: #000;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.send-button:hover {
    transform: scale(1.05);
}

/* --- ABOUT PAGE --- */
.about-hero {
    text-align: center;
    padding: 5rem 1.5rem;
    background: linear-gradient(to bottom, transparent, var(--bg-secondary));
}

.about-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    color: var(--text-secondary);
}

.about-content h2 {
    color: var(--text-primary);
    margin-top: 3rem;
    margin-bottom: 1rem;
    font-family: var(--font-heading);
}

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

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

/* Responsive */
@media (max-width: 768px) {

    /* Responsive NavBar that scrolls horizontally instead of hiding */
    .nav-links {
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        gap: 1rem;
        padding-bottom: 0.5rem;
        width: 100%;
        -webkit-overflow-scrolling: touch;
        border-top: 1px solid var(--glass-border);
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        order: 3;
    }

    .nav-links::-webkit-scrollbar {
        height: 2px;
    }

    .nav-links::-webkit-scrollbar-thumb {
        background: var(--accent-primary);
    }

    .navbar {
        position: absolute !important;
    }
    
    .nav-container {
        flex-wrap: wrap;
        padding: 0.5rem 1rem;
        height: auto;
    }

    .hero-title {
        font-size: 2.5rem;
    }

    .features-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
   MISSING CHAT STYLES (Restored)
   ============================================================================ */

/* Welcome Section */
.welcome-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-top: 8vh;
    animation: fadeInUp 0.5s ease-out;
}

.welcome-icon {
    width: 120px;
    height: 120px;
    margin: 0 auto 2rem;
    padding: 2rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    box-shadow: 0 0 50px var(--accent-glow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-icon svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 10px rgba(0, 229, 255, 0.5));
}

.welcome-section h2 {
    font-family: var(--font-heading);
    font-size: 2rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-section p {
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto;
}

/* Quick Action Buttons (Sidebar) */
/* New Chat Button */
.new-chat-btn {
    width: 100%;
    padding: 1rem;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    border-radius: 12px;
    color: #000;
    font-weight: 700;
    font-family: var(--font-heading);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(0, 229, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.new-chat-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 229, 255, 0.5);
    filter: brightness(1.1);
}

.new-chat-btn:active {
    transform: translateY(1px);
}

.quick-action-btn {
    width: 100%;
    padding: 1rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    border-radius: 12px;
    text-align: left;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-sans);
}

.quick-action-btn:hover {
    background: var(--glass-bg-hover);
    border-color: var(--accent-primary);
    color: var(--text-primary);
    transform: translateX(3px);
}

/* Chat History List - Premium Styling */
#chatHistoryList {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 40vh;
    overflow-y: auto;
    padding-right: 0.25rem;
    margin-bottom: 1rem;
}

#chatHistoryList::-webkit-scrollbar {
    width: 4px;
}

#chatHistoryList::-webkit-scrollbar-track {
    background: transparent;
}

#chatHistoryList::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 4px;
}

#chatHistoryList::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0.01) 100%);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.history-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 3px;
    background: linear-gradient(180deg, var(--accent-primary), var(--accent-secondary));
    opacity: 0;
    transition: opacity 0.3s;
}

.history-item:hover {
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.08) 0%, rgba(124, 58, 237, 0.05) 100%);
    border-color: rgba(0, 229, 255, 0.3);
    transform: translateX(4px);
    box-shadow: 0 4px 20px rgba(0, 229, 255, 0.1);
}

.history-item:hover::before {
    opacity: 1;
}

.history-item.active {
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.15) 0%, rgba(124, 58, 237, 0.1) 100%);
    border-color: var(--accent-primary);
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.2), inset 0 0 20px rgba(0, 229, 255, 0.05);
}

.history-item.active::before {
    opacity: 1;
}

.history-item span:first-child {
    font-size: 1.1rem;
    filter: grayscale(0.3);
    transition: filter 0.3s, transform 0.3s;
}

.history-item:hover span:first-child {
    filter: grayscale(0);
    transform: scale(1.1);
}

.history-item span:nth-child(2) {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.3s;
}

.history-item:hover span:nth-child(2),
.history-item.active span:nth-child(2) {
    color: var(--text-primary);
}

.delete-chat-btn {
    opacity: 0;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(255, 100, 100, 0.1);
    color: #ff6b6b;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-item:hover .delete-chat-btn {
    opacity: 1;
}

.delete-chat-btn:hover {
    background: rgba(255, 100, 100, 0.25);
    color: #ff4757;
    transform: scale(1.1);
}

/* Sidebar Section Headers */
.sidebar-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-tertiary);
    margin-bottom: 0.75rem;
    padding-left: 0.5rem;
    font-weight: 600;
}

/* Message Content & Tables */
.message-content {
    line-height: 1.6;
    font-size: 0.95rem;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    overflow-x: auto;
}

.message-content table {
    display: block;
    width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9em;
}

.message-content th,
.message-content td {
    border: 1px solid var(--glass-border);
    padding: 0.75rem;
    text-align: left;
    min-width: 120px;
}

.message-content th {
    background: rgba(255, 255, 255, 0.05);
    color: var(--accent-primary);
    font-weight: 600;
}

.message-content tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.message-content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--glass-border);
}

.message-content code {
    font-family: 'Fira Code', monospace;
    font-size: 0.85em;
    color: var(--accent-secondary);
}

/* Chat Messages */
.message {
    margin-bottom: 1.5rem;
    display: flex;
    gap: 1rem;
    animation: fadeInUp 0.3s ease-out;
    max-width: 85%;
}

.message.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message.assistant {
    margin-right: auto;
}

.message-content {
    padding: 1rem 1.5rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.6;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    /* Ensure it doesn't overflow parent */
    /* Add min-width to prevent squishing too much */
    min-width: 0;
}

.message.user .message-content {
    background: var(--accent-primary);
    color: #000;
    /* Black text on bright cyan for contrast */
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.message.assistant .message-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar svg {
    width: 20px;
    height: 20px;
}

/* Typing Indicator */
.typing-dots {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--glass-bg);
    border-radius: 1rem;
    width: fit-content;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* ============================================================================
   SIDEBAR ACCORDION & TOPIC EXPLORER
   ============================================================================ */

.sidebar-section {
    margin-bottom: 1rem;
}

.sidebar-toggle {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    border-radius: 12px;
    color: #000;
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.sidebar-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px var(--accent-glow);
}

.toggle-icon {
    font-size: 0.8rem;
}

.sidebar-accordion {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.topic-group {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    overflow: hidden;
}

.topic-header {
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.topic-header:hover {
    background: var(--glass-bg-hover);
}

.topic-arrow {
    color: var(--accent-primary);
    font-weight: bold;
}

.topic-questions {
    padding: 0 0.5rem 0.5rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.topic-question-btn {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
}

.topic-question-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
    transform: translateX(5px);
}

.sidebar-divider {
    border: none;
    border-top: 1px solid var(--glass-border);
    margin: 1rem 0;
}

.sidebar-header h4 {
    font-family: var(--font-heading);
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.sidebar-header p {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-bottom: 0.75rem;
}

.faq-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 300px;
    overflow-y: auto;
}

.faq-btn {
    font-size: 0.8rem !important;
    padding: 0.7rem !important;
}

/* ============================================================================
   ANIMATED BACKGROUND FOR CHAT AREA
   ============================================================================ */

.chat-main {
    position: relative;
    overflow: hidden;
}

.chat-main::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 10%;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    border-radius: 50%;
    opacity: 0.1;
    animation: floatOrb 15s ease-in-out infinite;
    pointer-events: none;
}

.chat-main::after {
    content: '';
    position: absolute;
    bottom: 10%;
    right: 5%;
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(124, 58, 237, 0.3) 0%, transparent 70%);
    border-radius: 50%;
    opacity: 0.15;
    animation: floatOrb 20s ease-in-out infinite reverse;
    pointer-events: none;
}

@keyframes floatOrb {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    50% {
        transform: translate(30px, -30px) scale(1.1);
    }
}

/* --- MOBILE PORTRAIT OPTIMIZATION & PARITY --- */
@media screen and (max-width: 768px) {
    body {
        overflow-x: hidden;
        width: 100vw;
    }

    .main-wrapper {
        padding-top: calc(var(--nav-height) + 40px);
    }

    /* Prevent wrapped multi-line navbar from overlapping content */
    .topics-header,
    .progress-header {
        padding-top: 1rem !important;
    }
    
    .facts-hero,
    .atlas-hero {
        padding-top: calc(var(--nav-height) + 40px) !important;
    }

    .quiz-dashboard {
        margin-top: calc(var(--nav-height) + 40px) !important;
    }

    /* Fix Module Tabs Overflow on Mobile */
    .module-tabs, 
    .topics-module-switch {
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        justify-content: flex-start;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        margin-left: 0;
        margin-right: 0;
        border-radius: 12px;
    }
    
    .module-tabs::-webkit-scrollbar,
    .topics-module-switch::-webkit-scrollbar {
        height: 3px;
    }
    .module-tabs::-webkit-scrollbar-thumb,
    .topics-module-switch::-webkit-scrollbar-thumb {
        background: rgba(255,255,255,0.2);
    }
    
    .tab-btn, .topics-mod-btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
    }

    .hero-title {
        font-size: 2.2rem !important;
        word-break: break-word;
        padding: 0 1rem;
    }

    .hero-buttons {
        flex-direction: column;
        width: 100%;
        padding: 0 1.5rem;
    }

    .hero-buttons .btn {
        width: 100%;
        justify-content: center;
    }

    .features-section {
        padding: 1rem 1rem 4rem;
    }
    
    /* Ensure grids stack on mobile */
    .topics-grid-container {
        grid-template-columns: 1fr !important;
        padding: 1rem;
    }
    
    .obj-container .books-grid {
        grid-template-columns: 1fr !important;
    }

    /* Progress Page Specific Fixes */
    .progress-stats-grid,
    .perf-grid {
        grid-template-columns: 1fr !important;
    }
    
    .stat-card h3 {
        font-size: 1rem;
    }
    .stat-value {
        font-size: 2rem;
    }
    .quiz-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }
    .quiz-score {
        align-self: flex-start;
    }

    .topic-card {
        margin-bottom: 1rem;
    }

    /* Chat App Layout - Full Width on Mobile with Drawer */
    .chat-layout {
        flex-direction: column;
        height: calc(100vh - 120px);
        min-height: calc(100vh - 120px);
        margin-top: 120px;
        overflow: hidden;
        position: relative;
    }

    .chat-sidebar {
        position: absolute;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100%;
        background: var(--bg-primary);
        z-index: 1000;
        transition: left 0.3s ease;
        border-right: 1px solid var(--glass-border);
        padding-bottom: 2rem;
        overflow-y: auto;
        display: flex !important;
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }
    
    .chat-sidebar.open {
        left: 0;
    }
    
    /* Overlay for when sidebar is open on mobile */
    .chat-sidebar-overlay {
        display: none;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        backdrop-filter: blur(2px);
    }
    
    .chat-sidebar-overlay.open {
        display: block;
    }

    .chat-main {
        width: 100%;
        flex: 1;
        max-height: 100%;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .chat-messages-area {
        padding: 1rem 0.5rem;
    }

    .message {
        max-width: 95%;
    }

    .chat-input-area {
        padding: 0.75rem;
        border-top: 1px solid var(--glass-border);
    }
    
    .chat-input-wrapper {
        padding: 0.5rem 1rem;
    }

    /* Fix table overflows in AI responses */
    .message-content table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Quiz Layout Rewrite for Mobile Parity */
    .quiz-container {
        flex-direction: column !important;
        height: auto;
        display: flex;
    }

    #quizSidebar {
        width: 100% !important;
        max-width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--glass-border);
        max-height: 250px;
        overflow-y: auto;
    }

    .quiz-main {
        width: 100% !important;
        padding: 1rem !important;
    }

    /* Hide extra unneeded university logos on mobile to save space, keeping primary branding */
    .university-logos {
        display: none !important;
    }
}