/* Colorful Academic Course Viewer */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=Poppins:wght@300;400;500;600;700&family=Inter:wght@400;500&display=swap');

:root {
    --primary: #5fa8d3; /* Softened blue */
    --primary-dark: #3d5a6a;
    --secondary: #e07a5f; /* Softened orange */
    --accent: #d4a574;
    --bg-app: #f9f7f2;
    --bg-content: #fffdfa;
    --text-main: #4a5568;
    --sidebar-width: 340px;
    --topbar-height: 80px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-app);
    height: 100vh;
    overflow: hidden;
}

#app-container {
    display: flex;
    height: 100vh;
}

/* Colorful Sidebar */
.course-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-content);
    border-right: 2px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 100;
}

.sidebar-header {
    padding: 3rem 2rem;
    background: linear-gradient(135deg, var(--primary-dark) 0%, #1a7fa0 100%);
    color: white;
    border-bottom: 5px solid var(--secondary);
}

.sidebar-header h2 {
    font-family: 'DM Serif Display', serif;
    font-size: 1.8rem;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
}

.progress-container {
    margin-top: 1rem;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--secondary);
    width: 0%;
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.unit-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 2rem;
}

.back-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}

.back-link:hover {
    color: var(--secondary);
    transform: translateX(-5px);
}

.unit-header {
    padding: 2rem 2rem 1rem;
    font-weight: 800;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--primary);
    letter-spacing: 2.5px;
}

.topic-item {
    padding: 1.2rem 2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 15px;
    color: #4a5568;
    border-left: 6px solid transparent;
}

.topic-item:hover {
    background-color: #f0f9ff;
    color: var(--primary);
}

.topic-item.active {
    background-color: #e0f2fe;
    color: var(--primary-dark);
    border-left-color: var(--secondary);
    font-weight: 700;
}

.topic-item.completed i {
    color: #2e7d32; /* Green for completed */
}

.topic-item i {
    color: var(--primary);
    font-size: 1.1rem;
}

/* Main Content Layout */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-app);
    min-width: 0; /* Prevents flex items from overflowing */
}

.top-bar {
    width: 100%;
    height: var(--topbar-height);
    background: var(--bg-content);
    border-bottom: 4px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 3rem;
    z-index: 50;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.logo {
    font-family: 'DM Serif Display', serif;
    font-size: 1.6rem; /* Slightly reduced from 1.8rem */
    color: var(--primary);
    white-space: nowrap; /* Prevent logo text from wrapping */
}

.logo span { color: var(--secondary); }

/* Sidebar Toggle & Close - Professional Positioning */
#sidebar-toggle {
    display: none;
    background: var(--primary-light);
    border: none;
    color: var(--primary);
    width: 45px;
    height: 45px;
    border-radius: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

#sidebar-toggle:hover {
    background: var(--primary);
    color: white;
}

#sidebar-close {
    display: none;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

#sidebar-close:hover {
    background: var(--secondary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 20px;
    background: #f0f9ff;
    border-radius: 50px;
    border: 2px solid var(--primary);
}

.user-profile i {
    font-size: 1.6rem;
    color: var(--primary);
}

#user-name {
    font-weight: 700;
    color: var(--primary-dark);
}

/* Gamification Stats */
.gamification-stats {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-right: 15px;
    padding-right: 15px;
    border-right: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: 0.85rem;
}

.stat-item.streak { color: #e07a5f; }
.stat-item.streak i {
    animation: flamePulse 1.5s infinite ease-in-out;
}

@keyframes flamePulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.2); opacity: 1; filter: drop-shadow(0 0 5px #e07a5f); }
}

.stat-item.level { color: #d4a574; }

.xp-container {
    width: 80px;
    height: 8px;
    background: #edf2f7;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}

.xp-fill {
    height: 100%;
    background: linear-gradient(90deg, #5fa8d3 0%, #3d5a6a 100%);
    width: 0%;
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Content Rendering */
.scroll-container {
    flex: 1;
    overflow-y: auto;
    padding: 5rem 3rem;
    background-image: 
        radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 30px 30px;
}

.lesson-content {
    background: var(--bg-content);
    padding: 5rem 6rem;
    border-radius: 30px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.08);
    max-width: 1100px;
    margin: 0 auto 5rem;
    border-top: 10px solid var(--primary);
}

.lesson-content h1 {
    color: var(--primary-dark);
    font-size: 3.5rem;
    margin-bottom: 3.5rem;
}

.lesson-content h2 {
    color: var(--primary);
    font-size: 2.2rem;
    margin-top: 5rem;
    margin-bottom: 2rem;
    border-bottom: 4px solid var(--bg-app);
}

.lesson-content p {
    font-family: 'Inter', sans-serif;
    font-size: 1.2rem;
    color: var(--text-reading);
    margin-bottom: 2.5rem;
    line-height: 1.9;
}

.lesson-content ul, .lesson-content ol {
    margin-bottom: 2.5rem;
    padding-left: 2.5rem;
}

.lesson-content li {
    margin-bottom: 1.2rem;
    font-size: 1.15rem;
    color: var(--text-reading);
}

.lesson-content img {
    max-width: 90%;
    border-radius: 15px;
    margin: 4rem auto;
    display: block;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.08);
}

.lesson-content table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 4rem 0;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    background: var(--bg-content);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
}

.lesson-content th {
    background-color: #f8fafc;
    color: var(--primary-dark);
    font-weight: 700;
    text-align: left;
    padding: 1.5rem;
    border-bottom: 2px solid #e2e8f0;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 1px;
}

.lesson-content td {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-reading);
    font-size: 1.05rem;
    transition: var(--transition);
}

.lesson-content tr:last-child td {
    border-bottom: none;
}

.lesson-content tr:nth-child(even) {
    background-color: rgba(95, 168, 211, 0.03); /* Extremely subtle brand-blue tint */
}

.lesson-content tr:hover td {
    background-color: rgba(95, 168, 211, 0.06);
}

.quiz-section {
    background: white;
    padding: 5rem 6rem;
    border-radius: 30px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.08);
    max-width: 1100px;
    margin: 0 auto 8rem;
    border-top: 10px solid var(--secondary);
}

.quiz-section h3 {
    color: var(--secondary);
    font-size: 2.5rem;
    margin-bottom: 3.5rem;
}

.quiz-section h4 {
    font-family: 'DM Serif Display', serif;
    font-size: 2rem;
    color: var(--primary-dark);
    margin-bottom: 2.5rem;
    padding-bottom: 1.2rem;
    border-bottom: 1px solid #eee;
}

.quiz-question {
    background: #fffcfc;
    border: 2px solid #ffebeb;
    padding: 3rem;
    border-radius: 20px;
    margin-bottom: 4rem;
}

.quiz-question p {
    font-size: 1.3rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 2.5rem;
    line-height: 1.6;
}

/* Quiz Table Styling */
.quiz-question table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 2rem 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    background: var(--bg-content);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.02);
}

.quiz-question th {
    background-color: #f8fafc;
    color: var(--primary-dark);
    font-weight: 700;
    text-align: left;
    padding: 1rem 1.2rem;
    border-bottom: 2px solid #e2e8f0;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

.quiz-question td {
    padding: 0.8rem 1.2rem;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-reading);
    font-size: 1rem;
}

.quiz-question tr:last-child td {
    border-bottom: none;
}

.quiz-question tr:nth-child(even) {
    background-color: rgba(95, 168, 211, 0.02);
}

.options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.option-label {
    display: flex;
    align-items: flex-start;
    gap: 1.2rem;
    padding: 1.2rem 1.8rem;
    background: var(--bg-content);
    border: 2px solid #e2e8f0;
    border-radius: 15px;
    cursor: pointer;
    transition: var(--transition);
}

.option-label:hover {
    border-color: var(--secondary);
    background: #fffafa;
    transform: translateX(8px);
}

.option-input {
    width: 20px;
    height: 20px;
    margin-top: 4px; /* Align with first line of text */
    accent-color: var(--secondary);
    flex-shrink: 0;
}

.option-text {
    font-family: 'Inter', sans-serif;
    font-size: 1.05rem;
    color: var(--text-reading);
    flex: 1;
}

.option-text p {
    margin: 0; /* Remove paragraph margins from marked.parse */
}

.btn-primary {
    background: linear-gradient(135deg, var(--secondary) 0%, #ff7676 100%);
    padding: 1.5rem 4rem;
    font-size: 1.3rem;
    box-shadow: 0 10px 30px rgba(254, 63, 64, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-3px);
    box-shadow: 0 15px 35px rgba(254, 63, 64, 0.3);
}

/* Placeholder State */
.placeholder-state {
    text-align: center;
    padding: 10rem 2rem;
    color: var(--text-muted);
}

.placeholder-state i {
    font-size: 5rem;
    margin-bottom: 2rem;
    color: var(--primary);
    opacity: 0.2;
}

.placeholder-state h3 {
    font-family: 'DM Serif Display', serif;
    font-size: 2.2rem;
    color: var(--text-muted);
    opacity: 0.5;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }

/* Mobile Responsiveness - Professional Adaptations */
@media (max-width: 1024px) {
    #sidebar-toggle { display: flex; }
    
    .course-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        box-shadow: 20px 0 50px rgba(0,0,0,0.15);
        transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
    }
    
    .course-sidebar.active {
        left: 0;
    }

    #sidebar-close {
        display: flex;
    }

    .top-bar {
        padding: 0 1.5rem;
    }

    .gamification-stats {
        margin-right: 0;
        padding-right: 0;
        border-right: none;
        margin-bottom: 0; /* Course viewer has more space in top bar usually */
        display: none; /* Hide stats on mobile top bar to avoid crowding */
    }
}

@media (max-width: 768px) {
    .lesson-content, .quiz-section {
        padding: 3rem 1.5rem;
    }
    
    .lesson-content h1 { font-size: 2.5rem; }
    .logo { font-size: 1.4rem; }
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 95;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Reusable Modal & Overlay Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-content {
    background: white;
    padding: 40px;
    border-radius: 24px;
    max-width: 500px;
    width: 100%;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
    animation: modalFadeIn 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}
@keyframes modalFadeIn {
    from { opacity: 0; transform: translateY(20px); scale: 0.95; }
    to { opacity: 1; transform: translateY(0); scale: 1; }
}
.modal-icon {
    font-size: 4rem;
    margin-bottom: 25px;
}
.modal-title {
    font-family: 'DM Serif Display', serif;
    font-size: 2rem;
    color: var(--primary-dark);
    margin-bottom: 15px;
}
.modal-text {
    color: var(--text-main);
    margin-bottom: 30px;
    line-height: 1.7;
    font-size: 1.05rem;
}
.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}
.modal-btn {
    padding: 12px 30px;
    border-radius: 50px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    font-family: 'Poppins', sans-serif;
    font-size: 0.95rem;
}
.modal-btn-primary {
    background: var(--primary);
    color: white;
}
.modal-btn-secondary {
    background: #edf2f7;
    color: #4a5568;
}
.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

/* AI Study Buddy Styles */
.ai-chat-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1000;
}

.ai-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(95, 168, 211, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: var(--transition);
}

.ai-fab:hover {
    transform: scale(1.1) rotate(5deg);
}

.ai-prompt {
    position: absolute;
    bottom: 80px;
    right: 0;
    background: white;
    padding: 12px 20px;
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-dark);
    white-space: nowrap;
    border: 1px solid #edf2f7;
    animation: promptBounce 2s infinite ease-in-out;
    pointer-events: none;
    z-index: 999;
}

.ai-prompt::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 25px;
    width: 15px;
    height: 15px;
    background: white;
    transform: rotate(45deg);
    border-right: 1px solid #edf2f7;
    border-bottom: 1px solid #edf2f7;
}

@keyframes promptBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.ai-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.15);
    display: none; /* Hidden by default */
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    animation: modalFadeIn 0.3s ease;
}

.ai-chat-window.active {
    display: flex;
}

.ai-chat-header {
    padding: 20px;
    background: var(--primary-dark);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-status {
    font-size: 0.7rem;
    opacity: 0.8;
}

#ai-close-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #f8fafc;
}

.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 15px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.ai-bot {
    align-self: flex-start;
    background: white;
    color: var(--text-main);
    border-bottom-left-radius: 2px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    border: 1px solid #edf2f7;
    padding: 16px 20px 16px 24px; /* Enhanced left padding */
    animation: messageReveal 0.4s ease-out;
}

@keyframes messageReveal {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border-bottom-right-radius: 2px;
    box-shadow: 0 4px 15px rgba(95, 168, 211, 0.2);
    padding: 12px 18px;
}

.ai-chat-input {
    padding: 15px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    background: white;
}

#ai-input {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid #edf2f7;
    border-radius: 25px;
    outline: none;
    font-family: inherit;
    font-size: 0.9rem;
    transition: var(--transition);
}

#ai-input:focus {
    border-color: var(--primary);
    background: white;
}

#ai-send-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

#ai-send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.ai-chat-footer {
    padding: 8px 20px;
    background: #f1f5f9;
    font-size: 0.75rem;
    color: #64748b;
    text-align: center;
    border-top: 1px solid #e2e8f0;
}

/* Typing Indicator Animation */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #cbd5e0;
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 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 typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Markdown styling inside chat */
.ai-message p { margin-bottom: 8px; }
.ai-message p:last-child { margin-bottom: 0; }
.ai-message code { background: #eee; padding: 2px 4px; border-radius: 4px; }

/* Typing animation placeholder */
.ai-typing {
    font-style: italic;
    font-size: 0.8rem;
    color: #888;
}

.btn-flashcards {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: var(--transition);
    font-size: 0.95rem;
}

.btn-flashcards:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(95, 168, 211, 0.2);
}