/* ═══════════════════════════════════════════════════════════
   MBARIN IA — Styles CSS
   Version Python/Flask
   ═══════════════════════════════════════════════════════════ */

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

:root {
    --primary: #1a5e3a;
    --primary-light: #2d8a5e;
    --primary-dark: #134a2d;
    --secondary: #d4a017;
    --secondary-light: #f0c946;
    --danger: #ce1126;
    --bg: #f0f4f0;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-light: #6c757d;
    --radius: 14px;
    --shadow: 0 4px 20px rgba(0,0,0,0.07);
    --shadow-hover: 0 8px 30px rgba(0,0,0,0.13);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Flag Bar (drapeau guinéen) ── */
.flag-bar {
    height: 4px;
    background: linear-gradient(to right, var(--danger) 33%, var(--secondary) 33%, var(--secondary) 66%, var(--primary) 66%);
}

/* ── Navbar ── */
.navbar {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 15px rgba(0,0,0,0.15);
}
.navbar-left { display: flex; align-items: center; gap: 1rem; }
.navbar-brand {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 1.25rem; font-weight: 700; cursor: pointer;
}
.navbar-brand:hover { opacity: 0.9; }
.nav-right { display: flex; align-items: center; gap: 0.8rem; }
.nav-user {
    font-size: 0.88rem; opacity: 0.9;
    background: rgba(255,255,255,0.12);
    padding: 0.35rem 0.8rem; border-radius: 20px;
}

/* ── Buttons ── */
.btn {
    padding: 0.5rem 1.2rem; border: none; border-radius: 8px;
    cursor: pointer; font-size: 0.9rem; font-weight: 600;
    transition: all 0.2s ease;
    display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-outline { background: transparent; border: 2px solid rgba(255,255,255,0.7); color: white; }
.btn-outline:hover { background: rgba(255,255,255,0.15); border-color: white; }
.btn-primary { background: var(--secondary); color: var(--text); }
.btn-primary:hover { background: var(--secondary-light); }
.btn-green { background: var(--primary); color: white; }
.btn-green:hover { background: var(--primary-light); }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.btn-back { background: rgba(255,255,255,0.12); color: white; padding: 0.4rem 0.8rem; font-size: 0.85rem; border-radius: 8px; cursor: pointer; border: none; }
.btn-back:hover { background: rgba(255,255,255,0.25); }

/* ── Container ── */
.container { max-width: 1600px; margin: 0 auto; padding: 1.5rem 2rem; }

/* ── Auth Page ── */
.auth-page {
    display: flex; justify-content: center; align-items: center;
    min-height: calc(100vh - 64px); padding: 2rem;
    background: linear-gradient(135deg, #e8f5e9 0%, #f0f4f0 50%, #fff8e1 100%);
}
.auth-card {
    background: var(--card-bg); border-radius: 18px; padding: 2.5rem;
    width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}
.auth-logo { text-align: center; font-size: 3rem; margin-bottom: 0.5rem; }
.auth-card h2 { text-align: center; margin-bottom: 0.3rem; color: var(--primary); font-size: 1.5rem; }
.auth-card > p { text-align: center; color: var(--text-light); margin-bottom: 1.5rem; font-size: 0.95rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.3rem; font-weight: 600; font-size: 0.88rem; color: #444; }
.form-group input, .form-group select {
    width: 100%; padding: 0.7rem 1rem; border: 2px solid #e8e8e8;
    border-radius: 10px; font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s; background: #fafafa;
}
.form-group input:focus, .form-group select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,94,58,0.1); background: white;
}
.auth-card .btn-submit { width: 100%; padding: 0.85rem; font-size: 1rem; margin-top: 0.5rem; border-radius: 10px; }
.auth-toggle { text-align: center; margin-top: 1.2rem; color: var(--text-light); font-size: 0.9rem; }
.auth-toggle a { color: var(--primary); cursor: pointer; font-weight: 600; text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }
.error-msg {
    background: #fef2f2; color: var(--danger); padding: 0.6rem 1rem;
    border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem;
    text-align: center; border: 1px solid #fecaca;
}

/* ── Hero ── */
.hero { text-align: center; padding: 2.5rem 1rem 1rem; }
.hero h1 { font-size: 2.2rem; color: var(--primary); margin-bottom: 0.5rem; line-height: 1.3; }
.hero p { color: var(--text-light); font-size: 1.1rem; max-width: 600px; margin: 0 auto; line-height: 1.5; }

/* ── Stats Bar ── */
.stats-bar { display: flex; gap: 1rem; justify-content: center; margin: 1.5rem 0; flex-wrap: wrap; }
.stat-item {
    background: var(--card-bg); padding: 1rem 1.5rem; border-radius: var(--radius);
    box-shadow: var(--shadow); text-align: center; min-width: 150px;
    border-bottom: 3px solid var(--primary);
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.82rem; color: var(--text-light); margin-top: 0.2rem; }

/* ── Cards Grid ── */
.cards-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 1.2rem; margin-top: 1.5rem;
    max-width: 1000px; margin-left: auto; margin-right: auto;
}
@media (max-width: 800px) { .cards-grid { grid-template-columns: 1fr; max-width: 400px; } }
.card {
    background: var(--card-bg); border-radius: var(--radius); padding: 1.5rem;
    box-shadow: var(--shadow); cursor: pointer; transition: all 0.3s ease;
    border: 2px solid transparent; position: relative; overflow: hidden;
}
.card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(to right, var(--danger), var(--secondary), var(--primary));
    opacity: 0; transition: opacity 0.3s;
}
.card:hover { transform: translateY(-5px); box-shadow: var(--shadow-hover); border-color: var(--primary-light); }
.card:hover::before { opacity: 1; }
.card-icon { font-size: 2.8rem; margin-bottom: 0.8rem; }
.card h3 { color: var(--primary); margin-bottom: 0.4rem; font-size: 1.15rem; }
.card p { color: var(--text-light); font-size: 0.9rem; line-height: 1.4; }
.card-badge {
    display: inline-block; background: #e8f5e9; padding: 0.25rem 0.7rem;
    border-radius: 20px; font-size: 0.78rem; color: var(--primary);
    font-weight: 600; margin-top: 0.8rem;
}

/* ── Breadcrumb ── */
.breadcrumb { display: flex; align-items: center; gap: 0.5rem; padding: 0.8rem 2rem; font-size: 0.9rem; flex-wrap: wrap;
    position: sticky; top: 50px; z-index: 30; background: var(--bg); border-bottom: 1px solid #e0e4e0; margin: 0 -2rem; }
.breadcrumb a { color: var(--primary); text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: #ccc; }
.breadcrumb .current { color: var(--text-light); font-weight: 500; }

/* ── Section Header ── */
.section-header { margin-bottom: 1.2rem; }
.section-header h2 { font-size: 1.4rem; color: var(--primary); margin-bottom: 0.3rem; }
.section-header p { color: var(--text-light); font-size: 0.95rem; }

/* ── Year Filter ── */
.year-filter { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.year-btn {
    padding: 0.5rem 1.1rem; border: 2px solid #e0e0e0; border-radius: 25px;
    background: white; cursor: pointer; font-weight: 600; font-size: 0.9rem; transition: all 0.2s;
}
.year-btn.active, .year-btn:hover { border-color: var(--primary); background: var(--primary); color: white; }

/* ── Question List ── */
.question-item {
    background: var(--card-bg); border-radius: var(--radius); padding: 1.2rem 1.5rem;
    margin-bottom: 0.8rem; box-shadow: var(--shadow); cursor: pointer; transition: all 0.2s;
    display: flex; justify-content: space-between; align-items: center;
    border-left: 4px solid transparent;
}
.question-item:hover { transform: translateX(4px); border-left-color: var(--primary); box-shadow: var(--shadow-hover); }
.question-title { font-weight: 600; margin-bottom: 0.2rem; color: var(--text); }
.question-meta { font-size: 0.85rem; color: var(--text-light); display: flex; gap: 0.8rem; align-items: center; }
.question-meta .year-tag {
    background: #e8f5e9; color: var(--primary); padding: 0.15rem 0.5rem;
    border-radius: 6px; font-weight: 600; font-size: 0.8rem;
}
.question-arrow { font-size: 1.3rem; color: var(--primary); }

/* ── Study Page ── */
.study-layout { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 950px) { .study-layout { grid-template-columns: 1fr; } }
.study-panel { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); overflow-y: auto; display: flex; flex-direction: column; max-height: calc(100vh - 105px); position: sticky; top: 95px; }
.study-panel:last-child .chat-messages { flex: 1; height: auto; }
.study-panel::-webkit-scrollbar { width: 10px; }
.study-panel::-webkit-scrollbar-track { background: #f0f0f0; }
.study-panel::-webkit-scrollbar-thumb { background: #b0b0b0; border-radius: 5px; }
.study-panel::-webkit-scrollbar-thumb:hover { background: var(--primary); }
.panel-header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white; padding: 0.9rem 1.2rem; font-weight: 600; font-size: 0.95rem;
    display: flex; align-items: center; gap: 0.5rem;
    flex-shrink: 0; position: sticky; top: 0; z-index: 20;
}
.panel-body { padding: 0; }
.pdf-viewer { width: 100%; height: 80vh; min-height: 600px; border: none; display: block; }
.pdf-actions {
    padding: 0.8rem 1.2rem; display: flex; gap: 0.8rem; align-items: center;
    background: #f5f7f5; border-top: 1px solid #e0e4e0;
}
.pdf-actions a, .pdf-actions button {
    background: linear-gradient(135deg, var(--secondary), var(--secondary-light));
    color: var(--text); border: none; padding: 0.5rem 1rem; border-radius: 8px;
    cursor: pointer; font-weight: 600; font-size: 0.85rem; text-decoration: none; transition: all 0.2s;
}
.pdf-actions a:hover, .pdf-actions button:hover { transform: scale(1.02); box-shadow: 0 3px 10px rgba(212,160,23,0.3); }

/* ── PDF Tabs ── */
.pdf-tabs { display: flex; background: #f5f7f5; border-bottom: 2px solid #e0e4e0; }
.pdf-tab {
    flex: 1; padding: 0.75rem 1rem; text-align: center; font-weight: 600; font-size: 0.9rem;
    cursor: pointer; border: none; background: transparent; color: var(--text-light);
    transition: all 0.2s; border-bottom: 3px solid transparent;
}
.pdf-tab:hover { color: var(--primary); background: #e8f5e9; }
.pdf-tab.active { color: var(--primary); border-bottom-color: var(--primary); background: white; }
.pdf-tab.corrige-tab.active { color: var(--secondary); border-bottom-color: var(--secondary); }
.no-corrige {
    display: flex; align-items: center; justify-content: center;
    height: 300px; color: var(--text-light); font-size: 1rem;
    text-align: center; padding: 2rem;
}

/* ── Chat Vertical Resizer ── */
.chat-v-resizer {
    height: 6px; cursor: row-resize; background: #e0e4e0;
    transition: background 0.2s; position: relative; z-index: 10;
}
.chat-v-resizer:hover, .chat-v-resizer:active { background: var(--primary); }

/* ── Chat ── */
.chat-messages {
    height: auto; min-height: 120px; max-height: calc(100vh - 320px); overflow-y: scroll; padding: 1rem 2rem;
    display: flex; flex-direction: column; gap: 1rem; background: #fafbfa; flex: 1;
    justify-content: flex-start; align-items: flex-start;
}
.chat-messages::-webkit-scrollbar { width: 10px; }
.chat-messages::-webkit-scrollbar-track { background: #f0f0f0; border-radius: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: #b0b0b0; border-radius: 5px; min-height: 40px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: var(--primary); }
.chat-messages.has-messages { justify-content: flex-start; align-items: stretch; min-height: 300px; max-height: calc(100vh - 320px); }
.chat-msg {
    max-width: 85%; padding: 0.8rem 1rem; border-radius: 14px;
    line-height: 1.55; font-size: 0.9rem; white-space: pre-wrap;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.chat-msg.user {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white; align-self: flex-end; border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
    background: white; align-self: flex-start; border-bottom-left-radius: 4px;
    border: 1px solid #e8e8e8;
}
.chat-msg .katex { font-size: 1.05em; }
.chat-msg .katex-display { margin: 0.5em 0; overflow-x: auto; }
.chat-suggestions { display: flex; gap: 0.4rem; flex-wrap: wrap; padding: 0.5rem 1rem; background: #fafbfa; }
.suggestion-chip {
    background: #e8f5e9; border: 1px solid #c8e6c9; border-radius: 20px;
    padding: 0.3rem 0.75rem; font-size: 0.8rem; cursor: pointer;
    color: var(--primary); font-weight: 500; transition: all 0.2s;
}
.suggestion-chip:hover { background: var(--primary); color: white; border-color: var(--primary); }
.chat-input-area {
    display: flex; gap: 0.5rem; padding: 0.8rem 1rem;
    border-top: 2px solid var(--bg); background: white;
}
.chat-input-area input {
    flex: 1; padding: 0.7rem 1rem; border: 2px solid #e8e8e8;
    border-radius: 10px; font-size: 0.95rem; background: #fafafa;
}
.chat-input-area input:focus { outline: none; border-color: var(--primary); background: white; }
.chat-input-area button {
    background: var(--primary); color: white; border: none;
    padding: 0.7rem 1.2rem; border-radius: 10px; cursor: pointer;
    font-weight: 600; transition: all 0.2s;
}
.chat-input-area button:hover { background: var(--primary-light); }

/* ── AI Loading ── */
.ai-loading { display: flex; align-items: center; gap: 0.5rem; padding: 0.8rem 1rem; color: var(--text-light); font-size: 0.85rem; }
.typing-dots span {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: var(--primary); animation: blink 1.4s infinite both; margin: 0 1px;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.3; } 40% { opacity: 1; } }

/* ── Quiz ── */
.quiz-container { padding: 1.2rem; background: #fafbfa; min-height: 400px; display: flex; flex-direction: column; }
.quiz-setup { text-align: center; padding: 2rem 1rem; }
.quiz-setup h3 { color: var(--primary); font-size: 1.2rem; margin-bottom: 0.5rem; }
.quiz-setup p { color: var(--text-light); font-size: 0.9rem; margin-bottom: 1.5rem; }
.timer-options { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; margin-bottom: 1.5rem; }
.timer-option {
    padding: 0.6rem 1.2rem; border: 2px solid #e0e0e0; border-radius: 10px;
    cursor: pointer; font-size: 0.9rem; font-weight: 600; background: white;
    transition: all 0.2s; color: var(--text);
}
.timer-option:hover { border-color: var(--primary); color: var(--primary); }
.timer-option.selected { border-color: var(--primary); background: var(--primary); color: white; }
.quiz-start-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white; border: none; padding: 0.8rem 2.5rem; border-radius: 12px;
    font-size: 1rem; font-weight: 700; cursor: pointer; transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(26,94,58,0.3);
}
.quiz-start-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(26,94,58,0.4); }
.quiz-start-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.quiz-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1rem; padding-bottom: 0.8rem; border-bottom: 2px solid #e8e8e8;
}
.quiz-progress { font-size: 0.85rem; color: var(--text-light); font-weight: 600; }
.quiz-timer { display: flex; align-items: center; gap: 0.4rem; font-weight: 700; font-size: 1.1rem; color: var(--primary); }
.quiz-timer.warning { color: var(--secondary); }
.quiz-timer.danger { color: var(--danger); animation: pulse 0.5s ease infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.5; } }
.quiz-timer-bar { width: 100%; height: 5px; background: #e0e0e0; border-radius: 3px; margin-bottom: 1rem; overflow: hidden; }
.quiz-timer-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 1s linear, background 0.3s; }
.quiz-timer-fill.warning { background: var(--secondary); }
.quiz-timer-fill.danger { background: var(--danger); }
.quiz-score-badge {
    background: var(--primary); color: white; padding: 0.25rem 0.7rem;
    border-radius: 15px; font-size: 0.8rem; font-weight: 600;
}
.quiz-question-text {
    font-size: 1rem; line-height: 1.6; margin-bottom: 1.2rem; padding: 1rem;
    background: white; border-radius: 12px; border: 1px solid #e8e8e8;
}
.quiz-question-text .katex { font-size: 1.05em; }
.quiz-question-text .katex-display { margin: 0.5em 0; overflow-x: auto; }
.quiz-answers { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }
.quiz-answer {
    display: flex; align-items: flex-start; gap: 0.8rem; padding: 0.9rem 1rem;
    border: 2px solid #e0e0e0; border-radius: 12px; cursor: pointer;
    transition: all 0.2s; background: white; font-size: 0.9rem; line-height: 1.5;
}
.quiz-answer:hover:not(.disabled) { border-color: var(--primary); background: #e8f5e9; }
.quiz-answer .answer-letter {
    flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
    background: #e8e8e8; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem; color: #555;
}
.quiz-answer.selected { border-color: var(--primary); background: #e8f5e9; }
.quiz-answer.selected .answer-letter { background: var(--primary); color: white; }
.quiz-answer.correct { border-color: var(--primary); background: #e8f5e9; }
.quiz-answer.correct .answer-letter { background: var(--primary); color: white; }
.quiz-answer.wrong { border-color: var(--danger); background: #fce4e7; }
.quiz-answer.wrong .answer-letter { background: var(--danger); color: white; }
.quiz-answer.disabled { cursor: default; opacity: 0.85; }
.quiz-answer .katex { font-size: 1em; }
.quiz-feedback { padding: 0.8rem 1rem; border-radius: 10px; font-size: 0.9rem; margin-bottom: 1rem; font-weight: 500; }
.quiz-feedback.correct { background: #e8f5e9; color: var(--primary-dark); border: 1px solid #c8e6c9; }
.quiz-feedback.wrong { background: #fce4e7; color: #8b1a2b; border: 1px solid #f5c6cb; }
.quiz-feedback.timeout { background: #fff8e1; color: #856404; border: 1px solid #ffeeba; }
.quiz-next-btn {
    background: var(--primary); color: white; border: none; padding: 0.6rem 1.5rem;
    border-radius: 10px; font-size: 0.9rem; font-weight: 600; cursor: pointer;
    align-self: flex-end; transition: all 0.2s;
}
.quiz-next-btn:hover { background: var(--primary-light); }
.quiz-results { text-align: center; padding: 1.5rem 1rem; }
.quiz-results h3 { font-size: 1.3rem; color: var(--primary); margin-bottom: 0.5rem; }
.quiz-score-circle {
    width: 120px; height: 120px; border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    margin: 1rem auto; font-weight: 700; font-size: 2rem; border: 6px solid;
}
.quiz-score-circle.excellent { border-color: var(--primary); color: var(--primary); background: #e8f5e9; }
.quiz-score-circle.good { border-color: var(--secondary); color: #856404; background: #fff8e1; }
.quiz-score-circle.poor { border-color: var(--danger); color: var(--danger); background: #fce4e7; }
.quiz-score-circle small { font-size: 0.7rem; font-weight: 500; }
.quiz-level { font-size: 1.1rem; font-weight: 600; margin: 0.5rem 0 1rem; }
.quiz-results-detail { display: flex; justify-content: center; gap: 1.5rem; margin-bottom: 1.5rem; font-size: 0.9rem; }
.quiz-results-detail span { display: flex; align-items: center; gap: 0.3rem; }
.quiz-retry-btn {
    background: var(--primary); color: white; border: none; padding: 0.7rem 2rem;
    border-radius: 10px; font-weight: 600; cursor: pointer; font-size: 0.95rem; transition: all 0.2s;
}
.quiz-retry-btn:hover { background: var(--primary-light); }

/* ── Footer ── */
.footer { text-align: center; padding: 1.5rem; color: var(--text-light); font-size: 0.85rem; margin-top: 2rem; }

/* ── Loading & Empty ── */
.loading { text-align: center; padding: 3rem; color: var(--text-light); }
.spinner {
    width: 40px; height: 40px; border: 4px solid #e0e0e0;
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 3rem; color: var(--text-light); }
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
