/* AI Assistant Styles */
:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --dark-bg: #1f2937;
    --light-bg: #f9fafb;
    --card-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--light-bg);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Main Container */
.ai-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Sidebar Header with User Info */
.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: white;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.user-details {
    flex: 1;
}

.user-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.user-role {
    font-size: 0.75rem;
    opacity: 0.9;
}

.logout-btn {
    padding: 0.5rem;
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.25rem;
    transition: all 0.3s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    width: 100%;
    padding: 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

/* Sidebar Menu */
.sidebar-menu {
    display: flex;
    flex-direction: column;
    padding: 1rem 0;
    flex: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    cursor: pointer;
    transition: all 0.3s;
    border-left: 3px solid transparent;
}

.menu-icon {
    font-size: 1.5rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.menu-item:hover {
    background: var(--light-bg);
}

.menu-item.active {
    background: linear-gradient(90deg, #eef2ff, transparent);
    border-left-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 600;
}

.menu-item.active .menu-icon {
    transform: scale(1.1);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.content-section {
    display: none;
}

.content-section.active {
    display: block;
}

.content-section h1 {
    font-size: 2rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

/* Welcome Card */
.welcome-card {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 2rem;
    border-radius: 12px;
    margin-bottom: 2rem;
}

.welcome-card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    font-size: 2.5rem;
}

.stat-info h3 {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.stat-info p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
}

.card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.card h3 {
    margin-bottom: 1rem;
    font-size: 1.125rem;
}

/* Assessment Section */
.assessment-intro {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.intro-content h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.intro-content ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.intro-content ul li {
    margin: 0.5rem 0;
}

.test-info {
    display: flex;
    gap: 2rem;
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: 8px;
}

.test-info span {
    font-weight: 500;
}

.subject-selection {
    margin-top: 2rem;
}

.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.subject-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.subject-checkbox:hover {
    border-color: var(--primary-color);
    background: #eef2ff;
}

.subject-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
}

.subject-checkbox input[type="checkbox"]:checked + span {
    color: var(--primary-color);
    font-weight: 600;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 1rem;
}

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

.btn-primary:hover {
    background: #4f46e5;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #7c3aed;
}

/* Learning Path */
.learning-path-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.path-item {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-left: 4px solid var(--primary-color);
}

.path-item.completed {
    border-left-color: var(--success-color);
    opacity: 0.8;
}

.path-item.in-progress {
    border-left-color: var(--warning-color);
}

.path-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.path-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.path-status {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
}

.path-status.not-started {
    background: #f3f4f6;
    color: var(--text-secondary);
}

.path-status.in-progress {
    background: #fef3c7;
    color: #92400e;
}

.path-status.completed {
    background: #d1fae5;
    color: #065f46;
}

.progress-bar {
    height: 8px;
    background: var(--light-bg);
    border-radius: 4px;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.5s ease;
}

/* Tests Section */
.tests-filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.tests-filters select {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
}

.tests-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.test-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s;
}

.test-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.test-card h4 {
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.test-meta {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* AI Chat Section - Clean 1-Column Layout */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 190px);
    max-width: 950px;
    margin: 0 auto;
    width: 100%;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    min-height: 0;
}

.chat-welcome-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0 0.5rem 0;
}

.suggest-btn {
    padding: 0.45rem 0.9rem;
    border: 1px solid #c7d2fe;
    background: #eef2ff;
    color: #4338ca;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
}

.suggest-btn:hover {
    background: #e0e7ff;
    border-color: #6366f1;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.2);
}

.chat-input {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background: #ffffff;
}

.chat-input textarea {
    flex: 1;
    min-height: 48px;
    max-height: 120px;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    resize: none;
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    background: #f8fafc;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
}

.chat-input textarea:focus {
    background: #ffffff;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

#sendChatBtn {
    height: 48px;
    padding: 0 1.4rem;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: #ffffff;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 3px 10px rgba(79, 70, 229, 0.25);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#sendChatBtn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(79, 70, 229, 0.35);
}

#sendChatBtn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
}

#cancelStreamBtn {
    height: 48px;
    padding: 0 1rem;
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
    border-radius: 12px;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#cancelStreamBtn:hover {
    background: #fecaca;
}

.chat-actions {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.action-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.action-btn:hover {
    background: var(--light-bg);
    border-color: var(--primary-color);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-content.large {
    max-width: 900px;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.close:hover {
    color: var(--danger-color);
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.9);
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive */
@media (max-width: 1024px) {
    .dashboard-grid,
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
    
    .chat-container {
        grid-template-columns: 1fr;
    }
    
    .chat-sidebar {
        max-height: 300px;
    }
}

@media (max-width: 768px) {
    .ai-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .sidebar-header {
        padding: 1rem;
    }
    
    .user-name {
        font-size: 0.875rem;
    }
    
    .mobile-menu-toggle {
        display: block;
    }
    
    .sidebar-menu {
        display: none;
        padding: 0;
    }
    
    .sidebar-menu.active {
        display: flex;
    }
    
    .menu-item {
        border-left: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1rem 1.5rem;
    }
    
    .menu-item.active {
        background: #eef2ff;
        border-left: 4px solid var(--primary-color);
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .content-section h1 {
        font-size: 1.5rem;
    }
    
    .welcome-card {
        padding: 1.5rem;
    }
    
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .card {
        padding: 1rem;
    }
    
    .chat-container {
        height: calc(100vh - 200px);
    }
    
    .chat-messages {
        padding: 1rem;
    }
    
    .message {
        max-width: 90%;
    }
    
    .tests-filters {
        flex-direction: column;
    }
    
    .tests-grid {
        grid-template-columns: 1fr;
    }
    
    .subject-checkbox {
        padding: 0.75rem;
        font-size: 0.875rem;
    }
}

@media (max-width: 480px) {
    .sidebar-header {
        padding: 0.75rem;
    }
    
    .user-avatar {
        width: 40px;
        height: 40px;
    }
    
    .user-name {
        font-size: 0.8rem;
    }
    
    .logout-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    .main-content {
        padding: 0.75rem;
    }
    
    .content-section h1 {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }
    
    .stat-icon {
        font-size: 2rem;
    }
    
    .stat-info h3 {
        font-size: 1.5rem;
    }
    
    .btn-primary,
    .btn-secondary {
        padding: 0.625rem 1.25rem;
        font-size: 0.875rem;
    }
    
    .modal-content {
        padding: 1rem;
        width: 95%;
    }
}

/* Chat Styles */
.chat-container {
    display: flex;
    height: calc(100vh - 120px);
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.chat-sidebar {
    width: 300px;
    background: #f8fafc;
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    overflow-y: auto;
}

.chat-sidebar h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.topic-list {
    margin-bottom: 2rem;
}

.topic-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.topic-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
}

.topic-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.suggested-questions h4 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.suggest-btn {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    line-height: 1.4;
}

.suggest-btn:hover {
    background: var(--light-bg);
    border-color: var(--primary-color);
}

.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.message {
    display: flex;
    margin-bottom: 0.5rem;
    animation: fadeInUp 0.25s ease-out;
    width: 100%;
}

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

.message-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.bot-message {
    align-self: flex-start;
    max-width: 85%;
}

.bot-message .message-avatar {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    margin-right: 0.85rem;
}

.bot-message .message-content {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-radius: 18px 18px 18px 4px;
    padding: 1.1rem 1.35rem;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
    text-align: left;
}

.bot-message .message-content p {
    color: #1e293b;
    line-height: 1.65;
}

.user-message {
    flex-direction: row-reverse;
    align-self: flex-end;
    max-width: 80%;
    margin-left: auto;
}

.user-message .message-avatar {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: white;
    margin-left: 0.85rem;
    margin-right: 0;
}

.user-message .message-content {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: #ffffff !important;
    border-radius: 18px 18px 4px 18px;
    padding: 0.95rem 1.35rem;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.25);
    text-align: left;
}

.user-message .message-content p {
    color: #ffffff !important;
    line-height: 1.6;
}

.message-content {
    flex: 1;
    position: relative;
    max-width: 100%;
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 0;
    font-size: 0.95rem;
}

.message-content::before {
    display: none !important;
}

/* Stream content div — the live text area during streaming */
.stream-content {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
    line-height: 1.65;
    color: #1e293b;
    font-size: 0.95rem;
    min-width: 0;
}

/* Typing Indicator Animation */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0;
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6366f1;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.35;
    }
    40% {
        transform: scale(1.15);
        opacity: 1;
    }
}

.typing-text {
    font-size: 0.85rem;
    color: #6366f1;
    font-weight: 500;
}

/* Message Content Formatting */
.message-content p {
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul, 
.message-content ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.message-content strong {
    font-weight: 600;
    color: var(--primary-color);
}

.user-message .message-content strong {
    color: rgba(255,255,255,0.9);
}

.message-content code {
    background: var(--light-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--danger-color);
}

.user-message .message-content code {
    background: rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.9);
}

.message-content pre {
    background: var(--dark-bg);
    color: white;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.message-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1rem;
    margin: 0.75rem 0;
    font-style: italic;
    color: var(--text-secondary);
}

.message-content h3, 
.message-content h4 {
    color: var(--primary-color);
    margin: 1rem 0 0.5rem 0;
    font-weight: 600;
}

.user-message .message-content h3,
.user-message .message-content h4 {
    color: rgba(255,255,255,0.9);
}

/* Math & Science Formulas */
.math-block {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0.9rem 0;
    padding: 0.85rem 1.25rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1.15rem;
    font-family: 'Cambria Math', 'Times New Roman', serif;
    font-style: italic;
    color: #1e293b;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.02);
}

.math-inline {
    font-family: 'Cambria Math', 'Times New Roman', serif;
    font-style: italic;
    font-size: 1.05em;
    padding: 0 0.2rem;
    color: #4338ca;
    font-weight: 600;
}

.math-frac {
    display: inline-flex;
    flex-direction: column;
    vertical-align: middle;
    text-align: center;
    margin: 0 0.35rem;
    font-size: 0.95em;
    line-height: 1.1;
}

.math-frac .num {
    border-bottom: 1.5px solid currentColor;
    padding-bottom: 2px;
}

.math-frac .den {
    padding-top: 2px;
}

/* Markdown Tables */
.table-container {
    overflow-x: auto;
    margin: 1rem 0;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.markdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: white;
}

.markdown-table th {
    background: #f1f5f9;
    color: #334155;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid #cbd5e1;
    font-weight: 600;
    text-align: left;
}

.markdown-table td {
    padding: 0.65rem 0.85rem;
    border-top: 1px solid #f1f5f9;
    color: #1e293b;
}

.markdown-table tr:nth-child(even) td {
    background: #f8fafc;
}

.message-content .formula {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    padding: 0.75rem;
    border-radius: 8px;
    font-family: 'Times New Roman', serif;
    text-align: center;
    margin: 0.75rem 0;
}

.message-content .highlight {
    background: linear-gradient(120deg, #a8edea 0%, #fed6e3 100%);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-weight: 500;
}

.message-content .step-number {
    display: inline-block;
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 24px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-right: 0.5rem;
}

.message-content .definition {
    background: #f0f9ff;
    border-left: 4px solid #0ea5e9;
    padding: 0.75rem;
    border-radius: 0 8px 8px 0;
    margin: 0.75rem 0;
    font-style: italic;
}

.message-content .example {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    padding: 0.75rem;
    border-radius: 8px;
    margin: 0.75rem 0;
}

.message-content .example::before {
    content: "💡 Ví dụ: ";
    font-weight: 600;
    color: var(--success-color);
}

.message-content .warning {
    background: #fffbeb;
    border: 1px solid #fed7aa;
    padding: 0.75rem;
    border-radius: 8px;
    margin: 0.75rem 0;
}

.message-content .warning::before {
    content: "⚠️ Lưu ý: ";
    font-weight: 600;
    color: var(--warning-color);
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.4rem;
}

.user-message .message-timestamp {
    color: rgba(255, 255, 255, 0.75);
    text-align: right;
}

.bot-message .message-timestamp {
    color: #94a3b8;
    text-align: left;
}

.chat-actions {
    padding: 0.75rem 1.25rem;
    background: #ffffff;
    display: flex;
    gap: 0.75rem;
    border-top: 1px solid #f1f5f9;
}

.action-btn {
    padding: 0.45rem 0.9rem;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.action-btn:hover {
    background: #eef2ff;
    border-color: #6366f1;
    color: #4338ca;
}

/* Mobile responsive for chat */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 80px);
        padding: 0 0.5rem;
    }
    
    .chat-messages {
        padding: 1rem;
    }
    
    .bot-message,
    .user-message {
        max-width: 92%;
    }
    
    .chat-input {
        padding: 0.75rem 1rem;
    }
    
    .chat-actions {
        padding: 0.5rem 1rem 0.75rem;
        flex-wrap: wrap;
    }
}

/* ============================================================
   PREMIUM TEST MODAL & QUESTION UI
   ============================================================ */
#testModal .modal-content {
    max-width: 820px;
    width: 95%;
    border-radius: 20px;
    padding: 2.25rem;
    background: #ffffff;
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(226, 232, 240, 0.8);
}

.test-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.test-title-badge {
    font-size: 1.3rem;
    font-weight: 800;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.test-progress-info {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary-color);
    background: #eef2ff;
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
}

.test-progress-bar-container {
    height: 8px;
    background: #f1f5f9;
    border-radius: 9999px;
    overflow: hidden;
    margin-bottom: 1.25rem;
}

.test-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%);
    border-radius: 9999px;
    transition: width 0.35s ease;
}

/* Palette chuyển câu nhanh */
.question-palette-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0.65rem 0.85rem;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    overflow-x: auto;
}

.palette-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    margin-right: 0.25rem;
}

.question-palette {
    display: flex;
    gap: 0.4rem;
    flex-wrap: nowrap;
}

.palette-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1.5px solid #cbd5e1;
    background: #ffffff;
    color: #475569;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.palette-btn:hover {
    border-color: #6366f1;
    color: #6366f1;
    background: #eef2ff;
}

.palette-btn.current {
    background: #6366f1;
    border-color: #4f46e5;
    color: #ffffff;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.palette-btn.answered:not(.current) {
    background: #ecfdf5;
    border-color: #10b981;
    color: #047857;
}

/* Question Content Box */
.question-card-body {
    background: #ffffff;
    margin-bottom: 1.5rem;
}

.question-meta-tags {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.subject-tag {
    padding: 0.25rem 0.65rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.subject-tag.physics { background: #e0e7ff; color: #4338ca; }
.subject-tag.chemistry { background: #fae8ff; color: #86198f; }
.subject-tag.biology { background: #dcfce7; color: #15803d; }
.subject-tag.general_science { background: #ffedd5; color: #c2410c; }

.topic-tag {
    font-size: 0.8rem;
    color: #64748b;
    background: #f1f5f9;
    padding: 0.25rem 0.65rem;
    border-radius: 6px;
    font-weight: 500;
}

.question-text-box {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.6;
    color: #0f172a;
    margin-bottom: 1.25rem;
}

/* Option Cards (Danh sách đáp án đẹp mắt) */
.options-stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.option-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1rem 1.25rem;
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    position: relative;
}

.option-card:hover {
    border-color: #a5b4fc;
    background: #f8faff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.08);
}

.option-card.selected {
    border-color: #6366f1;
    background: #f5f3ff;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.16);
}

/* Ẩn native radio, thay bằng badge chữ cái A, B, C, D */
.option-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.option-letter-badge {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 10px;
    background: #f1f5f9;
    color: #475569;
    font-weight: 800;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border: 1px solid #e2e8f0;
}

.option-card:hover .option-letter-badge {
    background: #e0e7ff;
    color: #4338ca;
    border-color: #c7d2fe;
}

.option-card.selected .option-letter-badge {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
    border-color: #4338ca;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.option-text-content {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 600;
    color: #334155;
    line-height: 1.5;
}

.option-card.selected .option-text-content {
    color: #1e1b4b;
}

.option-check-circle {
    width: 22px;
    height: 22px;
    min-width: 22px;
    border-radius: 50%;
    border: 2px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    background: #ffffff;
}

.option-card.selected .option-check-circle {
    border-color: #6366f1;
    background: #6366f1;
}

.option-check-circle::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ffffff;
    opacity: 0;
    transition: opacity 0.2s;
}

.option-card.selected .option-check-circle::after {
    opacity: 1;
}

/* Essay / Short answer */
.essay-textarea-wrap textarea {
    width: 100%;
    min-height: 140px;
    padding: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.6;
    outline: none;
    transition: all 0.2s;
}

.essay-textarea-wrap textarea:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

/* Action Controls Bar */
.test-action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1.5rem;
    margin-top: 1rem;
    border-top: 1px solid #f1f5f9;
    flex-wrap: wrap;
    gap: 1rem;
}

.nav-test-btn {
    padding: 0.75rem 1.6rem;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
}

.nav-test-btn.prev {
    background: #f1f5f9;
    color: #475569;
}

.nav-test-btn.prev:hover:not(:disabled) {
    background: #e2e8f0;
    color: #1e293b;
}

.nav-test-btn.prev:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.nav-test-btn.next {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.nav-test-btn.next:hover {
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35);
    transform: translateY(-1px);
}

.nav-test-btn.submit {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.nav-test-btn.submit:hover {
    box-shadow: 0 6px 18px rgba(16, 185, 129, 0.35);
    transform: translateY(-1px);
}

