/* ===== CSS Variables & Themes ===== */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252542;
    --bg-card: #1e1e36;
    --bg-hover: #2a2a4a;
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0b8;
    --text-muted: #6a6a85;
    --accent: #7c5cfc;
    --accent-hover: #6b4ef0;
    --accent-light: rgba(124, 92, 252, 0.15);
    --accent-glow: rgba(124, 92, 252, 0.4);
    --success: #2ed573;
    --success-light: rgba(46, 213, 115, 0.15);
    --warning: #ffa502;
    --warning-light: rgba(255, 165, 2, 0.15);
    --danger: #ff4757;
    --danger-light: rgba(255, 71, 87, 0.15);
    --info: #54a0ff;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
    --radius: 12px;
    --radius-lg: 20px;
    --radius-sm: 8px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

[data-theme="light"] {
    --bg-primary: #f5f5fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f5;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f8;
    --text-primary: #1a1a2e;
    --text-secondary: #555570;
    --text-muted: #9999aa;
    --accent: #6b4ef0;
    --accent-hover: #5a3ee0;
    --accent-light: rgba(107, 78, 240, 0.1);
    --accent-glow: rgba(107, 78, 240, 0.25);
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.15);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12);
}

/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.logo-btn:hover { background: var(--bg-hover); }
.logo-icon { font-size: 24px; }

.header-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--font);
    transition: all var(--transition);
}

.header-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-label { display: inline; }

@media (max-width: 640px) {
    .btn-label { display: none; }
    .header-btn { padding: 8px 10px; }
    .logo-text { display: none; }
}

/* ===== Main Content ===== */
#main-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px 80px;
    min-height: calc(100vh - 60px);
}

/* ===== Hero / Home View ===== */
.hero {
    text-align: center;
    padding: 40px 20px;
}

.hero-title {
    font-size: clamp(28px, 5vw, 42px);
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), #b14ef0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
}

.hero-subtitle {
    font-size: clamp(15px, 3vw, 18px);
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 40px;
}

/* ===== Upload Zone ===== */
.upload-zone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 48px 32px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-card);
    position: relative;
    overflow: hidden;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
    transform: translateY(-2px);
}

.upload-zone.dragover {
    box-shadow: 0 0 30px var(--accent-glow);
}

.upload-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.upload-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.upload-hint {
    color: var(--text-muted);
    font-size: 14px;
}

.upload-formats {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.format-badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 20px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* ===== File List ===== */
.file-list { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }

.file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all var(--transition);
}

.file-item:hover { border-color: var(--border-strong); }

.file-icon { font-size: 28px; flex-shrink: 0; }

.file-info { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 12px; color: var(--text-muted); }

.file-status {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500;
    flex-shrink: 0;
}

.file-status.ready { background: var(--success-light); color: var(--success); }
.file-status.processing { background: var(--warning-light); color: var(--warning); }
.file-status.error { background: var(--danger-light); color: var(--danger); }

.file-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition);
}

.file-remove:hover { color: var(--danger); background: var(--danger-light); }

/* ===== Mode Selection ===== */
.section-title {
    font-size: 22px;
    font-weight: 700;
    margin: 32px 0 16px;
}

.mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 640px) {
    .mode-grid { grid-template-columns: 1fr; }
}

.mode-card {
    padding: 24px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.mode-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }

.mode-card.selected {
    border-color: var(--accent);
    background: var(--accent-light);
    box-shadow: 0 0 20px var(--accent-glow);
}

.mode-card-icon { font-size: 40px; margin-bottom: 12px; }
.mode-card-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.mode-card-desc { font-size: 13px; color: var(--text-secondary); }

/* ===== Options Panel ===== */
.options-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.option-row:last-child { border-bottom: none; }

.option-label { font-size: 15px; font-weight: 500; }
.option-desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.option-control { display: flex; align-items: center; gap: 8px; }

/* Number input */
.num-input {
    width: 70px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    text-align: center;
    font-family: var(--font);
}

.num-input:focus { outline: none; border-color: var(--accent); }

/* Select */
.select-input {
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    cursor: pointer;
}

.select-input:focus { outline: none; border-color: var(--accent); }

/* Toggle switch */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    cursor: pointer;
    transition: background var(--transition);
    border: 1px solid var(--border);
}

.toggle.on { background: var(--accent); }

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition);
}

.toggle.on::after { transform: translateX(20px); }

/* Checkbox grid for question types */
.qtype-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.qtype-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 14px;
    user-select: none;
}

.qtype-chip:hover { border-color: var(--border-strong); }
.qtype-chip.selected { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }

.qtype-check {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 2px solid var(--border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.qtype-chip.selected .qtype-check {
    background: var(--accent);
    border-color: var(--accent);
}

.qtype-chip.selected .qtype-check::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

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

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

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }

.btn-ghost {
    background: none;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

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

.btn-lg { padding: 16px 32px; font-size: 17px; }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; }

/* ===== Loading Spinner ===== */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-lg { width: 48px; height: 48px; border-width: 3px; }

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

/* ===== Loading View ===== */
.loading-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.loading-title { font-size: 20px; font-weight: 600; margin-top: 24px; margin-bottom: 8px; }
.loading-text { color: var(--text-secondary); font-size: 15px; max-width: 400px; }

.loading-steps { margin-top: 24px; display: flex; flex-direction: column; gap: 8px; text-align: left; }

.loading-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-muted);
    transition: all var(--transition);
}

.loading-step.active { color: var(--text-primary); background: var(--accent-light); }
.loading-step.done { color: var(--success); }

.loading-step-icon { width: 20px; text-align: center; }
.loading-step.active .loading-step-icon .spinner { width: 16px; height: 16px; border-width: 2px; }
.loading-step.done .loading-step-icon::before { content: '✓'; }

/* ===== Quiz View ===== */
.quiz-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.quiz-progress-info { font-size: 14px; color: var(--text-secondary); }
.quiz-progress-info strong { color: var(--text-primary); }

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 24px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #b14ef0);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.question-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 20px;
    animation: fadeInUp 0.4s ease;
}

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

.question-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.question-number {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.question-type-badge {
    flex-shrink: 0;
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-mc { background: var(--info); color: white; }
.badge-ms { background: #9b59b6; color: white; }
.badge-text { background: var(--warning); color: white; }
.badge-fill { background: var(--success); color: white; }
.badge-tf { background: #e67e22; color: white; }

.question-text {
    font-size: 17px;
    line-height: 1.7;
    flex: 1;
}

.question-image {
    margin: 16px 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    text-align: center;
}

.question-image img, .question-image svg {
    max-width: 100%;
    border-radius: var(--radius-sm);
    background: white;
    padding: 8px;
}

/* Answer options */
.answer-options { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.answer-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
}

.answer-option:hover { border-color: var(--border-strong); background: var(--bg-hover); }

.answer-option.selected {
    border-color: var(--accent);
    background: var(--accent-light);
}

.answer-option.correct {
    border-color: var(--success);
    background: var(--success-light);
}

.answer-option.incorrect {
    border-color: var(--danger);
    background: var(--danger-light);
}

.option-marker {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-strong);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    transition: all var(--transition);
}

.answer-option.selected .option-marker {
    border-color: var(--accent);
    background: var(--accent);
    color: white;
}

.answer-option.correct .option-marker {
    border-color: var(--success);
    background: var(--success);
    color: white;
}

.answer-option.incorrect .option-marker {
    border-color: var(--danger);
    background: var(--danger);
    color: white;
}

.checkbox-marker { border-radius: 4px !important; }

.option-text { flex: 1; font-size: 15px; }

/* Text input */
.text-answer-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font);
    transition: border var(--transition);
    resize: vertical;
    min-height: 50px;
}

.text-answer-input:focus { outline: none; border-color: var(--accent); }
.text-answer-input.correct { border-color: var(--success); background: var(--success-light); }
.text-answer-input.incorrect { border-color: var(--danger); background: var(--danger-light); }
.text-answer-input.partial { border-color: var(--warning); background: var(--warning-light); }

/* Fill in the blanks */
.fill-blank-input {
    display: inline-block;
    min-width: 120px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font);
    margin: 0 4px;
    transition: border var(--transition);
}

.fill-blank-input:focus { outline: none; border-color: var(--accent); }
.fill-blank-input.correct { border-color: var(--success); }
.fill-blank-input.incorrect { border-color: var(--danger); }
.fill-blank-input.partial { border-color: var(--warning); }

/* Explanation */
.explanation-box {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-left: 3px solid var(--info);
    border-radius: var(--radius-sm);
    font-size: 14px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.explanation-title { font-weight: 700; margin-bottom: 6px; color: var(--info); }

/* Question footer with doubt button */
.question-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.doubt-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font);
    transition: all var(--transition);
}

.doubt-btn:hover { border-color: var(--accent); color: var(--accent); }

.points-display { font-size: 13px; color: var(--text-muted); }
.points-display strong { color: var(--text-primary); }

/* ===== Results View ===== */
.results-hero {
    text-align: center;
    padding: 40px 20px;
}

.score-circle {
    width: 160px;
    height: 160px;
    margin: 0 auto 24px;
    position: relative;
}

.score-circle svg { transform: rotate(-90deg); }

.score-circle-bg {
    fill: none;
    stroke: var(--bg-tertiary);
    stroke-width: 8;
}

.score-circle-fill {
    fill: none;
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 1.5s ease;
}

.score-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.score-value { font-size: 36px; font-weight: 800; }
.score-max { font-size: 16px; color: var(--text-muted); }

.results-title { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.results-message { font-size: 16px; color: var(--text-secondary); margin-bottom: 32px; }

.results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Review answers */
.review-section { margin-top: 32px; }

.review-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
}

.review-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.review-status {
    font-size: 20px;
}

.review-answer { font-size: 14px; margin-top: 8px; }
.review-correct { color: var(--success); }
.review-incorrect { color: var(--danger); }
.review-partial { color: var(--warning); }
.review-your-answer { color: var(--text-secondary); margin-top: 4px; }

/* ===== Chat / AI Tutor ===== */
.chat-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 420px;
    max-width: 100%;
    height: 600px;
    max-height: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius) 0 0 0;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 200;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

@media (max-width: 640px) {
    .chat-panel { width: 100%; height: 100%; border-radius: 0; }
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.chat-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.chat-title-icon { font-size: 20px; }

.chat-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.chat-close:hover { color: var(--text-primary); background: var(--bg-hover); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    animation: fadeIn 0.3s ease;
}

.chat-message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
}

.chat-message.ai {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.chat-message.system {
    align-self: center;
    background: var(--accent-light);
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    max-width: 95%;
}

.chat-typing {
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    display: flex;
    gap: 4px;
}

.chat-typing span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

.chat-input-area {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    resize: none;
    min-height: 40px;
    max-height: 120px;
}

.chat-input:focus { outline: none; border-color: var(--accent); }

.chat-send {
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: background var(--transition);
    flex-shrink: 0;
}

.chat-send:hover { background: var(--accent-hover); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Settings Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden { display: none; }

.modal-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 560px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.3s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
}

.modal-title { font-size: 18px; font-weight: 700; }

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    position: sticky;
    bottom: 0;
    background: var(--bg-secondary);
}

/* Settings form */
.setting-group { margin-bottom: 20px; }

.setting-label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
}

.setting-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
}

.setting-input:focus { outline: none; border-color: var(--accent); }

.setting-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.setting-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
}

.setting-link:hover { text-decoration: underline; }

.api-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
}

.api-status.ok { background: var(--success-light); color: var(--success); }
.api-status.no { background: var(--danger-light); color: var(--danger); }

/* Provider cards */
.provider-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

@media (max-width: 480px) { .provider-grid { grid-template-columns: 1fr; } }

.provider-card {
    padding: 14px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.provider-card:hover { border-color: var(--border-strong); }
.provider-card.selected { border-color: var(--accent); background: var(--accent-light); }

.provider-name { font-weight: 600; font-size: 14px; }
.provider-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow);
    animation: toastIn 0.3s ease;
    max-width: 90vw;
}

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

.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--danger); color: white; }
.toast.info { background: var(--info); color: white; }
.toast.warning { background: var(--warning); color: white; }

/* ===== History View ===== */
.history-list { display: flex; flex-direction: column; gap: 10px; }

.history-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.history-item:hover { border-color: var(--border-strong); background: var(--bg-hover); }

.history-score {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.history-score.high { background: var(--success-light); color: var(--success); }
.history-score.mid { background: var(--warning-light); color: var(--warning); }
.history-score.low { background: var(--danger-light); color: var(--danger); }

.history-info { flex: 1; min-width: 0; }
.history-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 12px; color: var(--text-muted); }

.history-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* ===== Utility ===== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-20 { margin-top: 20px; }
.mt-40 { margin-top: 40px; }
.mb-20 { margin-bottom: 20px; }

/* Rendered content (markdown/latex) */
.rendered-content { line-height: 1.7; }
.rendered-content p { margin-bottom: 8px; }
.rendered-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
}
.rendered-content pre {
    background: var(--bg-tertiary);
    padding: 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 10px 0;
}
.rendered-content pre code { background: none; padding: 0; }
.rendered-content img { max-width: 100%; border-radius: var(--radius-sm); }
.rendered-content table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.rendered-content th, .rendered-content td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.rendered-content th { background: var(--bg-tertiary); }
.rendered-content ul, .rendered-content ol { margin-left: 20px; margin-bottom: 8px; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
