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

:root {
    --accent: #3b82f6;
    --recording: #ef4444;
    --border: #334155;
    --correct: #22c55e;
    --incorrect: #ef4444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* --- Top bar --- */

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px;
    background: #1e293b;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.header-info { display: flex; align-items: baseline; gap: 12px; min-width: 0; flex-wrap: wrap; }
.header-info h1 { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topic-name { font-size: 14px; color: #94a3b8; }
.header-meta { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.progress-badge { background: #3b82f6; color: white; padding: 3px 10px; border-radius: 10px; font-size: 12px; font-weight: 600; }

/* --- Split-panel layout --- */

.layout { flex: 1; display: flex; min-height: 0; }

.voice-panel { flex: 1 1 60%; display: flex; flex-direction: column; min-width: 0; }

#chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#chat-area::-webkit-scrollbar { width: 6px; }
#chat-area::-webkit-scrollbar-track { background: transparent; }
#chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.context-panel {
    width: 380px;
    flex-shrink: 0;
    background: #1e293b;
    border-left: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
}
.context-panel h2 { font-size: 16px; margin-bottom: 12px; color: #94a3b8; }

/* --- Topic outline --- */

#topic-outline p { font-size: 14px; line-height: 1.6; margin-bottom: 10px; }
#topic-duration { color: #94a3b8; font-size: 13px; }
#topic-quiz-count { color: #94a3b8; font-size: 13px; }
.hint { color: #64748b; font-style: italic; font-size: 13px; margin-top: 16px; }

/* --- Messages --- */

.message { padding: 12px 16px; border-radius: 16px; max-width: 80%; word-wrap: break-word; }
.message-user { background: #1e3a5f; align-self: flex-end; border: 1px solid #2563eb; }
.message-assistant { background: #1e293b; align-self: flex-start; border: 1px solid var(--border); }
.message-text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.message-timing { font-size: 11px; color: #64748b; margin-top: 6px; font-variant-numeric: tabular-nums; }
.message-delay { font-size: 11px; color: #f59e0b; font-weight: 600; margin-bottom: 4px; }

.replay-btn {
    display: inline-flex;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    margin-top: 6px;
    color: #94a3b8;
    transition: all 0.15s;
}
.replay-btn:hover { border-color: var(--accent); color: #e2e8f0; }

/* --- Call / session summary card --- */

.call-summary { background: #1e293b; border: 2px solid var(--accent); border-radius: 12px; padding: 20px; margin-top: 20px; align-self: stretch; }
.call-summary h3 { margin-bottom: 12px; color: var(--accent); }
.call-summary p { margin-bottom: 8px; font-size: 14px; line-height: 1.5; }
.close-btn { margin-top: 16px; padding: 8px 20px; background: var(--accent); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; }
.close-btn:hover { opacity: 0.85; }

/* --- Quiz panel --- */

.quiz-progress { font-size: 13px; color: #94a3b8; margin-bottom: 16px; font-variant-numeric: tabular-nums; }

.quiz-question-text { font-size: 15px; line-height: 1.5; font-weight: 600; margin-bottom: 16px; }

.quiz-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.quiz-option-btn {
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #0f172a;
    color: #e2e8f0;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.quiz-option-btn:hover:not(:disabled) { border-color: var(--accent); background: #16233b; }
.quiz-option-btn:disabled { cursor: not-allowed; opacity: 0.85; }
.quiz-option-btn.selected { border-color: var(--accent); }
.quiz-option-btn.correct { border-color: var(--correct); background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.quiz-option-btn.incorrect { border-color: var(--incorrect); background: rgba(239, 68, 68, 0.15); color: #f87171; }

.quiz-feedback {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.5;
}
.quiz-feedback.correct { background: rgba(34, 197, 94, 0.12); border: 1px solid var(--correct); color: #bbf7d0; }
.quiz-feedback.incorrect { background: rgba(239, 68, 68, 0.12); border: 1px solid var(--incorrect); color: #fecaca; }
.quiz-feedback p { margin-top: 4px; color: #cbd5e1; }

.quiz-next-btn {
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.quiz-next-btn:hover { opacity: 0.85; }

.quiz-or-divider {
    text-align: center; color: #64748b; font-size: 12px; margin: 12px 0 8px;
    display: flex; align-items: center; gap: 12px;
}
.quiz-or-divider::before, .quiz-or-divider::after {
    content: ""; flex: 1; height: 1px; background: #334155;
}

.quiz-mic-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 12px; border-radius: 10px;
    background: #1e293b; border: 1px dashed #475569; color: #94a3b8;
    font-size: 14px; cursor: pointer; transition: all 0.2s;
}
.quiz-mic-btn:hover:not(:disabled) { border-color: var(--accent); color: #e2e8f0; }
.quiz-mic-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.quiz-mic-btn.recording {
    border-color: var(--recording); color: var(--recording);
    animation: quiz-pulse 1s ease-in-out infinite;
}
@keyframes quiz-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.quiz-voice-transcript {
    font-size: 13px; color: #94a3b8; margin-bottom: 10px; padding: 8px 12px;
    background: #1e293b; border-radius: 8px;
}
.quiz-voice-transcript em { color: #e2e8f0; }
.quiz-voice-transcript strong { color: var(--accent); }

/* --- Results screen --- */

.results-card {
    border-radius: 14px;
    padding: 24px;
    text-align: center;
    border: 2px solid var(--border);
    margin-bottom: 16px;
}
.results-card.results-pass { border-color: var(--correct); }
.results-card.results-fail { border-color: var(--incorrect); }
.results-card h3 { font-size: 20px; margin-bottom: 8px; }
.results-pass h3 { color: var(--correct); }
.results-fail h3 { color: var(--incorrect); }
.results-score { font-size: 36px; font-weight: 700; margin-bottom: 16px; }
.results-card p { font-size: 13px; line-height: 1.6; margin-bottom: 8px; text-align: left; }

/* --- Footer / controls --- */

footer { padding: 16px 20px; background: #1e293b; border-top: 1px solid var(--border); text-align: center; flex-shrink: 0; }
.controls { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 8px; }

.record-btn {
    width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--accent); cursor: pointer;
    background: transparent; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.record-btn:hover:not(:disabled) { background: rgba(59, 130, 246, 0.15); }
.record-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.record-icon { width: 24px; height: 24px; background: var(--accent); border-radius: 50%; transition: all 0.2s; }

.record-btn.recording { border-color: var(--recording); animation: pulse 1s infinite; }
.record-btn.recording .record-icon { background: var(--recording); border-radius: 4px; width: 20px; height: 20px; }

.record-btn.processing { border-color: #94a3b8; cursor: not-allowed; opacity: 0.6; }
.record-btn.processing .record-icon { background: #94a3b8; animation: spin 1s linear infinite; }

.record-btn.streaming { border-color: var(--accent); }
.record-btn.streaming .record-icon { animation: pulse-icon 1.5s ease-in-out infinite; }

.record-btn.playing { border-color: var(--accent); opacity: 0.6; }

@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes pulse-icon { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.stop-btn {
    width: 40px; height: 40px; border-radius: 50%; border: 2px solid #f59e0b; background: transparent;
    color: #f59e0b; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.stop-btn:hover { background: rgba(245, 158, 11, 0.15); }
.hidden { display: none !important; }

#record-status { font-size: 13px; color: #94a3b8; min-height: 16px; margin-bottom: 12px; }

.footer-actions { display: flex; align-items: center; justify-content: center; gap: 12px; }

.footer-btn {
    padding: 10px 24px; border: none; border-radius: 8px; font-size: 14px; cursor: pointer;
    font-weight: 600; transition: opacity 0.15s;
}
.footer-btn:hover:not(:disabled) { opacity: 0.85; }
.footer-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.end-session-btn { background: var(--recording); color: white; }
.reschedule-btn { background: #374151; color: white; }

/* --- Modal --- */

.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.7);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-content { background: #1e293b; border-radius: 16px; padding: 32px; max-width: 480px; width: 90%; }
.modal-content h2 { margin-bottom: 8px; }
.modal-content p { color: #94a3b8; margin-bottom: 16px; }

#reschedule-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #0f172a;
    color: #e2e8f0;
    font-size: 14px;
    margin-bottom: 20px;
}

.modal-actions { display: flex; gap: 8px; }
.confirm-btn {
    flex: 1; padding: 10px 16px; background: var(--accent); color: white; border: none;
    border-radius: 6px; cursor: pointer; font-weight: 600;
}
.confirm-btn:hover { opacity: 0.85; }

.cancel-btn {
    flex: 1; padding: 10px 16px; background: transparent; border: 1px solid #475569;
    color: #94a3b8; border-radius: 6px; cursor: pointer;
}
.cancel-btn:hover { border-color: #94a3b8; color: #e2e8f0; }

/* --- Health dot --- */

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-ok { background: #22c55e; }
.dot-error { background: #ef4444; }
.dot-unknown { background: #94a3b8; }

.error { color: #ef4444; }
.loading { color: #94a3b8; font-style: italic; }

/* --- Responsive --- */

@media (max-width: 900px) {
    .layout { flex-direction: column; }
    .context-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); max-height: 45vh; }
}

@media (max-width: 480px) {
    .header-info { flex-direction: column; align-items: flex-start; gap: 2px; }
    .footer-actions { flex-direction: column; }
    .footer-btn { width: 100%; }
}
