/* ─── VARIABLES ──────────────────────────────────────────────────────────── */
:root {
  --navy: #0d2137;
  --blue: #1a6494;
  --sky: #2980b9;
  --sea: #1abc9c;
  --gold: #f39c12;
  --red: #e74c3c;
  --green: #27ae60;
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --muted: #7f8c8d;
  --border: #dce3ea;
  --nav-h: 64px;
  --header-h: 56px;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(13,33,55,.1);
  --shadow-lg: 0 8px 32px rgba(13,33,55,.15);
}

/* ─── RESET & BASE ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: var(--nav-h);
  line-height: 1.5;
}
h1, h2, h3 { line-height: 1.2; }
button { font-family: inherit; cursor: pointer; border: none; }
input { font-family: inherit; }
a { color: var(--sky); text-decoration: none; }
strong { font-weight: 600; }

/* ─── HEADER ─────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--navy);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.lang-switcher { display: flex; gap: 6px; }
.lang-btn { background: none; border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; padding: 2px 7px; font-size: 1rem; cursor: pointer; opacity: 0.6; transition: all 0.2s; }
.lang-btn:hover, .lang-btn.active { opacity: 1; border-color: rgba(255,255,255,0.6); background: rgba(255,255,255,0.1); }
.app-header h1 {
  color: white; font-size: 1.1rem; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.app-header h1 span.icon { font-size: 1.3rem; }
.header-score {
  background: var(--gold); color: var(--navy);
  border-radius: 20px; padding: 3px 10px;
  font-size: 0.8rem; font-weight: 700;
  min-width: 44px; text-align: center;
}

/* ─── BOTTOM NAV ─────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  height: var(--nav-h);
  background: var(--navy);
  display: flex; align-items: stretch;
  border-top: 1px solid rgba(255,255,255,.1);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; color: rgba(255,255,255,.5);
  background: none; font-size: 0.65rem; font-weight: 500;
  letter-spacing: .03em; transition: color .2s;
  min-height: 44px; padding: 4px 2px 0;
}
.nav-btn .nav-icon { font-size: 1.4rem; line-height: 1; }
.nav-btn.active { color: var(--gold); }
.nav-btn:active { opacity: .7; }

/* ─── PAGES ──────────────────────────────────────────────────────────────── */
.page { display: none; padding: 16px; max-width: 600px; margin: 0 auto; }
.page.active { display: block; }

/* ─── CARDS ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.card-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.card-icon { font-size: 1.5rem; }
.card-title { font-size: 1rem; font-weight: 600; }
.card-subtitle { font-size: 0.8rem; color: var(--muted); }

/* ─── DASHBOARD ──────────────────────────────────────────────────────────── */
.welcome-banner {
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: white; border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
  position: relative; overflow: hidden;
}
.welcome-banner::before {
  content: '⚓'; position: absolute; right: -10px; top: -10px;
  font-size: 5rem; opacity: .1;
}
.welcome-banner h2 { font-size: 1.2rem; margin-bottom: 4px; }
.welcome-banner p { font-size: 0.85rem; opacity: .85; }
.welcome-banner .exam-badge {
  display: inline-block; background: var(--gold); color: var(--navy);
  border-radius: 20px; padding: 3px 10px; font-size: 0.75rem;
  font-weight: 700; margin-top: 10px;
}

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; text-align: center;
}
.stat-card .stat-val { font-size: 1.8rem; font-weight: 700; color: var(--blue); line-height: 1; }
.stat-card .stat-label { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.stat-card .stat-icon { font-size: 1.5rem; margin-bottom: 4px; }

.section-title { font-size: 0.9rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 16px 0 8px; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-btn {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; text-align: center; border: 2px solid transparent;
  transition: all .2s; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.quick-btn:active { transform: scale(.97); }
.quick-btn .qb-icon { font-size: 1.8rem; }
.quick-btn .qb-label { font-size: 0.8rem; font-weight: 600; color: var(--text); }
.quick-btn.primary { border-color: var(--gold); background: #fff9f0; }

/* ─── PROGRESS BARS ──────────────────────────────────────────────────────── */
.progress-bar-wrap { background: var(--border); border-radius: 99px; height: 8px; overflow: hidden; }
.progress-bar-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--sky), var(--sea));
  transition: width .5s ease;
}
.progress-text { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

/* ─── FLASHCARDS ─────────────────────────────────────────────────────────── */
.theme-list { display: flex; flex-direction: column; gap: 10px; }
.theme-item {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; display: flex; align-items: center; gap: 12px;
}
.theme-item:active { opacity: .8; }
.theme-item-icon { font-size: 1.8rem; flex-shrink: 0; }
.theme-item-info { flex: 1; min-width: 0; }
.theme-item-title { font-weight: 600; font-size: 0.95rem; }
.theme-item-progress { font-size: 0.75rem; color: var(--muted); }
.theme-item-arrow { color: var(--border); font-size: 1.2rem; }

/* Flashcard flip */
.flashcard-container { perspective: 1000px; margin: 16px 0; }
.flashcard {
  position: relative; width: 100%;
  min-height: 220px; cursor: pointer;
  transform-style: preserve-3d; transition: transform .4s ease;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; width: 100%; min-height: 220px;
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flashcard-front {
  background: linear-gradient(135deg, var(--blue), var(--sky));
  color: white; font-size: 1.1rem; font-weight: 600; text-align: center;
}
.flashcard-back {
  background: var(--card-bg); color: var(--text);
  transform: rotateY(180deg); font-size: 0.9rem; line-height: 1.6;
  text-align: left;
}
.flashcard-back strong { color: var(--blue); }

.flashcard-hint { text-align: center; font-size: 0.8rem; color: var(--muted); margin-bottom: 12px; }
.flashcard-controls {
  display: flex; gap: 10px; margin-top: 12px;
}
.btn-know { flex: 1; background: var(--green); color: white; border-radius: var(--radius); padding: 12px; font-size: 0.9rem; font-weight: 600; }
.btn-review { flex: 1; background: var(--red); color: white; border-radius: var(--radius); padding: 12px; font-size: 0.9rem; font-weight: 600; }
.btn-back { background: none; color: var(--sky); font-size: 0.9rem; padding: 8px 0; font-weight: 500; }

.card-counter { text-align: center; font-size: 0.85rem; color: var(--muted); padding: 8px 0; }

/* ─── EXERCICES ──────────────────────────────────────────────────────────── */
.exercise-type-list { display: flex; flex-direction: column; gap: 10px; }
.exercise-type-item {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; display: flex; align-items: center; gap: 12px;
}
.eti-icon { font-size: 1.8rem; flex-shrink: 0; }
.eti-info { flex: 1; }
.eti-title { font-weight: 600; font-size: 0.95rem; }
.eti-desc { font-size: 0.78rem; color: var(--muted); }
.eti-badge {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  padding: 2px 7px; border-radius: 99px; flex-shrink: 0;
}
.eti-badge.fondamental { background: #ffeaa7; color: #b7950b; }
.eti-badge.facile { background: #d5f5e3; color: #1e8449; }
.eti-badge.moyen { background: #d6eaf8; color: #1a5276; }
.eti-badge.difficile { background: #fadbd8; color: #922b21; }

.exercise-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.exercise-statement { font-size: 0.9rem; line-height: 1.7; margin-bottom: 20px; padding: 14px; background: #f8fbff; border-radius: 8px; border-left: 3px solid var(--sky); }
.exercise-statement strong { color: var(--navy); }

.field-group { margin-bottom: 14px; }
.field-group label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 5px; color: var(--text); }
.field-row { display: flex; gap: 8px; align-items: center; }
.field-input {
  flex: 1; border: 2px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 1rem; outline: none;
  transition: border-color .2s;
}
.field-input:focus { border-color: var(--sky); }
.field-input.correct { border-color: var(--green); background: #f0fff4; }
.field-input.incorrect { border-color: var(--red); background: #fff5f5; }
.field-input.revealed { border-color: var(--gold); background: #fffdf0; }
.field-feedback { font-size: 0.8rem; margin-top: 3px; }
.field-feedback.ok { color: var(--green); }
.field-feedback.ko { color: var(--red); }

.btn-check {
  width: 100%; background: var(--blue); color: white;
  border-radius: var(--radius); padding: 14px; font-size: 1rem; font-weight: 600;
  margin-top: 4px; transition: background .2s;
}
.btn-check:active { background: var(--navy); }
.btn-hint { background: none; color: var(--muted); font-size: 0.82rem; padding: 6px 0; }
.btn-hint:hover { color: var(--sky); }

.steps-panel { margin-top: 16px; background: #f8fbff; border-radius: 8px; padding: 14px; display: none; }
.steps-panel.visible { display: block; }
.steps-panel h4 { font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.step-item { font-size: 0.88rem; line-height: 1.7; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.step-item:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.step-item strong { color: var(--navy); }

.result-banner {
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
  font-size: 0.9rem; font-weight: 600; text-align: center;
}
.result-banner.success { background: #d5f5e3; color: var(--green); }
.result-banner.partial { background: #fef9e7; color: #b7950b; }
.result-banner.error { background: #fadbd8; color: #922b21; }

.btn-next {
  width: 100%; background: var(--sea); color: white;
  border-radius: var(--radius); padding: 14px; font-size: 1rem; font-weight: 600;
  margin-top: 12px;
}

/* ─── EXAMEN ─────────────────────────────────────────────────────────────── */
.exam-intro { text-align: center; }
.exam-intro .big-icon { font-size: 4rem; margin-bottom: 12px; }
.exam-intro h2 { font-size: 1.2rem; margin-bottom: 8px; }
.exam-intro p { font-size: 0.87rem; color: var(--muted); margin-bottom: 6px; }
.exam-rules { background: #f8fbff; border-radius: var(--radius); padding: 14px; margin: 16px 0; text-align: left; }
.exam-rules li { font-size: 0.85rem; margin-bottom: 6px; list-style: none; padding-left: 0; }
.exam-rules li::before { content: '✓ '; color: var(--green); font-weight: 700; }

.btn-start-exam {
  width: 100%; background: linear-gradient(135deg, var(--gold), #e67e22);
  color: white; border-radius: var(--radius); padding: 16px;
  font-size: 1.05rem; font-weight: 700; box-shadow: var(--shadow);
}

.exam-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: white; border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px;
}
.exam-q-indicator { font-size: 0.85rem; opacity: .8; }
.exam-timer {
  font-size: 1.1rem; font-weight: 700; color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.exam-timer.warning { color: #ff7675; }

.exam-progress-dots { display: flex; gap: 8px; margin-bottom: 14px; justify-content: center; }
.exam-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border); transition: background .3s;
}
.exam-dot.current { background: var(--sky); transform: scale(1.3); }
.exam-dot.done { background: var(--green); }
.exam-dot.failed { background: var(--red); }

.btn-next-q {
  width: 100%; background: var(--blue); color: white;
  border-radius: var(--radius); padding: 14px; font-size: 1rem; font-weight: 600;
  margin-top: 12px; display: none;
}
.btn-next-q.visible { display: block; }

/* Résultats examen */
.exam-results { text-align: center; }
.exam-score-circle {
  width: 100px; height: 100px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  margin: 16px auto;
}
.exam-score-circle.perfect { background: linear-gradient(135deg, #27ae60, #1abc9c); }
.exam-score-circle.pass { background: linear-gradient(135deg, #f39c12, #e67e22); }
.exam-score-circle.fail { background: linear-gradient(135deg, #e74c3c, #c0392b); }
.exam-score-circle .score-num { font-size: 2.2rem; font-weight: 800; color: white; line-height: 1; }
.exam-score-circle .score-den { font-size: 0.9rem; color: rgba(255,255,255,.8); }

.exam-q-results { text-align: left; margin: 16px 0; }
.exam-q-result {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; background: var(--card-bg); border-radius: 8px;
  margin-bottom: 8px; font-size: 0.87rem;
}
.exam-q-result .qr-icon { font-size: 1.2rem; }
.exam-q-result.pass-q { border-left: 3px solid var(--green); }
.exam-q-result.fail-q { border-left: 3px solid var(--red); }

/* ─── COURS ──────────────────────────────────────────────────────────────── */
.courses-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.course-btn {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 6px;
}
.course-btn .cb-icon { font-size: 2rem; }
.course-btn .cb-label { font-size: 0.82rem; font-weight: 600; }
.course-btn.recording { background: #fff5f5; border: 2px solid var(--red); }
.course-btn.recording .cb-label { color: var(--red); }

.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 28px 20px; text-align: center; margin-bottom: 12px;
  transition: border-color .2s, background .2s;
}
.upload-zone.drag-over { border-color: var(--sky); background: #f0f8ff; }
.upload-zone .uz-icon { font-size: 2.5rem; margin-bottom: 8px; }
.upload-zone p { font-size: 0.85rem; color: var(--muted); }
.upload-zone input { display: none; }
.upload-zone .uz-select { color: var(--sky); font-weight: 600; cursor: pointer; }

.processing-block { background: #f8fbff; border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.processing-block .pb-title { font-weight: 600; margin-bottom: 8px; }
.processing-block .pb-status { font-size: 0.85rem; color: var(--muted); }

.meeting-item {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 10px;
}
.meeting-item .mi-title { font-weight: 600; margin-bottom: 4px; }
.meeting-item .mi-meta { font-size: 0.78rem; color: var(--muted); }
.meeting-item .mi-expand { color: var(--sky); font-size: 0.82rem; margin-top: 8px; cursor: pointer; }
.meeting-transcript { display: none; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.meeting-transcript.open { display: block; }
.summary-block { background: #f8fbff; border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.summary-block h3 { font-size: 0.85rem; margin-bottom: 6px; }
.summary-block li { font-size: 0.82rem; margin-bottom: 4px; }
.seg { font-size: 0.82rem; margin-bottom: 6px; }
.seg-time { color: var(--muted); font-size: 0.72rem; margin-right: 6px; font-variant-numeric: tabular-nums; }

/* ─── RECORDING UI ───────────────────────────────────────────────────────── */
.recording-panel {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; text-align: center;
}
.rec-indicator {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--red); margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  animation: pulse 1.2s infinite;
}
.rec-indicator .ri-icon { font-size: 1.5rem; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,.4); }
  50% { box-shadow: 0 0 0 12px rgba(231,76,60,0); }
}
#rec-timer { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 16px; color: var(--navy); }
.rec-title-input {
  width: 100%; border: 2px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 0.9rem; margin-bottom: 12px; outline: none;
}
.rec-title-input:focus { border-color: var(--sky); }
.btn-stop-rec {
  background: var(--red); color: white; border-radius: var(--radius);
  padding: 12px 28px; font-size: 1rem; font-weight: 600;
}

/* ─── UTILITAIRES ────────────────────────────────────────────────────────── */
.muted { color: var(--muted); font-size: 0.85rem; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.chip {
  display: inline-block; background: var(--bg); border: 1px solid var(--border);
  border-radius: 99px; padding: 3px 10px; font-size: 0.75rem;
}
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .es-icon { font-size: 3rem; margin-bottom: 8px; }

/* Toasts */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 10px); left: 50%; transform: translateX(-50%);
  background: var(--navy); color: white; padding: 10px 20px; border-radius: 99px;
  font-size: 0.85rem; font-weight: 500; z-index: 999;
  opacity: 0; transition: opacity .3s;
  white-space: nowrap; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ─── RESPONSIVE DESKTOP ─────────────────────────────────────────────────── */
@media (min-width: 640px) {
  .bottom-nav { max-width: 600px; left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; }
  .app-header { max-width: 600px; margin: 0 auto; left: 50%; right: auto; transform: translateX(-50%); width: 100%; position: sticky; }
  body { max-width: 600px; margin: 0 auto; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .quick-actions { grid-template-columns: repeat(4, 1fr); }
}
