/* ========================================================================
   Claude-CAP — feuille de styles
   Mobile-first, thèmes clair/sombre, palette bleu électrique.
   ======================================================================== */

:root {
  --bleu: #0066CC;
  --bleu-dark: #004C99;
  --bleu-light: #E6F0FA;
  --jaune: #F5C518;
  --vert: #1FA463;
  --rouge: #D83A3A;
  --orange: #E07A1F;

  --bg: #FAFBFC;
  --bg-card: #FFFFFF;
  --bg-soft: #F2F4F7;
  --bg-input: #FFFFFF;
  --text: #14181F;
  --text-soft: #5C6470;
  --text-mute: #8C95A4;
  --border: #E1E5EB;
  --border-strong: #C8CDD6;
  --shadow: 0 1px 2px rgba(20,24,31,0.04), 0 4px 12px rgba(20,24,31,0.06);
  --shadow-strong: 0 8px 32px rgba(20,24,31,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --tap: 44px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;
}

[data-theme="sombre"] {
  --bg: #0F1318;
  --bg-card: #181E26;
  --bg-soft: #1F262F;
  --bg-input: #232B35;
  --text: #ECEEF1;
  --text-soft: #A8B0BB;
  --text-mute: #6F7886;
  --border: #2A323D;
  --border-strong: #3A444F;
  --bleu-light: #1A2A40;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 80px;
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--bleu); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.25; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.15rem; font-weight: 600; }
p { margin: 0 0 1em; }
code { font-family: var(--font-mono); font-size: 0.92em; background: var(--bg-soft); padding: 1px 5px; border-radius: 4px; }

/* ========== Topbar ========== */
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--bleu);
}
.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--bleu); outline-offset: 2px; }

/* ========== Tabs ========== */
.tabs {
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom, 0px));
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto;
  min-width: 64px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-mute);
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: 8px;
  transition: color 0.12s;
}
.tab-icon { font-size: 1.3rem; line-height: 1; }
.tab-label { white-space: nowrap; }
.tab.active { color: var(--bleu); }
.tab:hover { color: var(--text); }
.tab.active:hover { color: var(--bleu); }

@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .tabs {
    position: sticky;
    top: 56px;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
    max-width: 1100px;
    margin: 0 auto;
    justify-content: flex-start;
    gap: 4px;
    padding: 6px 16px;
  }
  .tab {
    flex: 0 0 auto;
    flex-direction: row;
    padding: 8px 14px;
    font-size: 0.9rem;
    gap: 6px;
  }
  .tab-icon { font-size: 1.05rem; }
  .tab.active { background: var(--bleu-light); }
}

/* ========== Layout ========== */
.app-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}
@media (min-width: 768px) { .app-content { padding: 24px; } }

.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-mute);
}

.page-header { margin-bottom: 20px; }
.page-header p { color: var(--text-soft); margin: 4px 0 0; }

/* ========== Cards ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.card-h h3 { margin: 0; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  background: var(--bleu);
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.12s, transform 0.05s;
}
.btn:hover { background: var(--bleu-dark); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border-strong); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-soft { background: var(--bleu-light); color: var(--bleu); }
.btn-soft:hover { background: var(--bleu-light); filter: brightness(0.96); }
.btn-success { background: var(--vert); }
.btn-success:hover { background: var(--vert); filter: brightness(0.92); }
.btn-danger { background: var(--rouge); }
.btn-danger:hover { background: var(--rouge); filter: brightness(0.92); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }

/* ========== Form fields ========== */
.field {
  display: block;
  margin-bottom: 12px;
}
.field > span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 4px;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="search"],
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--bleu);
  box-shadow: 0 0 0 3px rgba(0,102,204,0.18);
}
.field-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

/* ========== Dashboard ========== */
.dash-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 768px) { .dash-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .dash-grid { grid-template-columns: repeat(3, 1fr); } }

.stat-big { font-size: 2.2rem; font-weight: 800; color: var(--bleu); font-family: var(--font-mono); line-height: 1; }
.stat-label { color: var(--text-soft); font-size: 0.85rem; margin-top: 4px; }

.progress-bar {
  height: 8px;
  background: var(--bg-soft);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--bleu), #339FFF);
  transition: width 0.4s;
}

.radar-container { position: relative; aspect-ratio: 1; max-width: 320px; margin: 0 auto; }
.radar-container svg { width: 100%; height: 100%; }

.countdown {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.countdown-num { font-size: 2.5rem; font-weight: 800; color: var(--orange); font-family: var(--font-mono); }
.countdown-label { color: var(--text-soft); }

/* ========== Cours ========== */
.poles-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) { .poles-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .poles-grid { grid-template-columns: repeat(3, 1fr); } }

.pole-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  text-align: left;
  width: 100%;
}
.pole-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-strong); }
.pole-num {
  display: inline-block;
  background: var(--bleu-light);
  color: var(--bleu);
  font-weight: 700;
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}
.pole-card h3 { font-size: 1.05rem; }
.pole-card-meta { font-size: 0.8rem; color: var(--text-mute); margin-top: 8px; }

.lecon-list { list-style: none; padding: 0; margin: 16px 0 0; }
.lecon-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  margin-bottom: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.12s;
}
.lecon-item:hover { background: var(--bg-soft); }
.lecon-item.lu { border-left: 3px solid var(--vert); }
.lecon-checkmark { color: var(--vert); font-weight: 700; }
.lecon-titre { flex: 1; font-weight: 600; }
.lecon-meta { font-size: 0.8rem; color: var(--text-mute); }

.lecon-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
}
.lecon-content h2 { color: var(--bleu); }
.lecon-content h3 { margin-top: 24px; }
.lecon-content p, .lecon-content li { color: var(--text); }
.lecon-content ul, .lecon-content ol { padding-left: 22px; }
.lecon-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}
.lecon-content th, .lecon-content td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.lecon-content th { background: var(--bg-soft); font-weight: 600; }

.encart {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 16px 0;
  border-left: 4px solid;
}
.encart-astuce { background: rgba(0,102,204,0.07); border-color: var(--bleu); }
.encart-piege { background: rgba(216,58,58,0.07); border-color: var(--rouge); }
.encart-cap { background: rgba(245,197,24,0.12); border-color: var(--jaune); }
.encart-chantier { background: rgba(31,164,99,0.08); border-color: var(--vert); }
.encart strong { display: block; margin-bottom: 4px; }

.schema-frame {
  background: white;
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 16px 0;
  border: 1px solid var(--border);
  text-align: center;
}
.schema-frame svg { max-width: 100%; height: auto; }
.schema-caption { font-size: 0.85rem; color: var(--text-soft); margin-top: 8px; font-style: italic; }

[data-theme="sombre"] .schema-frame { background: #FAFBFC; }

.lecon-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ========== Quiz ========== */
.quiz-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-soft);
  font-size: 0.85rem;
  border: 1px solid transparent;
  cursor: pointer;
}
.chip.active { background: var(--bleu); color: white; }
.chip:hover { border-color: var(--bleu); }

.question-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
}
.question-meta { font-size: 0.8rem; color: var(--text-mute); margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.question-meta .pole-num { margin-bottom: 0; }
.question-enonce { font-size: 1.05rem; font-weight: 600; margin-bottom: 16px; }
.choix-list { display: flex; flex-direction: column; gap: 8px; }
.choix {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  cursor: pointer;
  text-align: left;
  font-size: 0.95rem;
  transition: background 0.12s, border-color 0.12s;
}
.choix:hover { background: var(--bg-soft); }
.choix.selected { border-color: var(--bleu); background: var(--bleu-light); }
.choix.correct { border-color: var(--vert); background: rgba(31,164,99,0.12); }
.choix.wrong { border-color: var(--rouge); background: rgba(216,58,58,0.10); }
.choix-letter {
  display: inline-block;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  background: var(--bg-soft);
  border-radius: 50%;
  font-weight: 700;
  margin-right: 10px;
  font-size: 0.85rem;
}
.choix.correct .choix-letter { background: var(--vert); color: white; }
.choix.wrong .choix-letter { background: var(--rouge); color: white; }

.explication {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--bleu-light);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  color: var(--text);
}
.explication strong { color: var(--bleu); }

.quiz-progress {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.quiz-result-summary {
  text-align: center;
  padding: 32px 20px;
}
.quiz-result-summary .stat-big { font-size: 3rem; }

/* ========== Flashcards ========== */
.flashcard {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 32px 20px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s;
  user-select: none;
}
.flashcard:hover { transform: scale(1.01); }
.flashcard-content {
  font-size: 1.3rem;
  font-weight: 600;
  max-width: 600px;
  white-space: pre-wrap;
}
.flashcard-side { font-size: 0.75rem; color: var(--text-mute); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }
.flashcard-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
}
.flashcard-actions .btn { flex: 1; max-width: 200px; }

.box-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 16px 0;
}
.box-stat {
  text-align: center;
  padding: 8px 4px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
}
.box-stat-num { font-weight: 700; font-size: 1.1rem; color: var(--bleu); font-family: var(--font-mono); }
.box-stat-lbl { font-size: 0.7rem; color: var(--text-soft); margin-top: 2px; }

/* ========== Exam ========== */
.exam-timer {
  position: sticky;
  top: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  margin: -16px -16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  font-family: var(--font-mono);
}
.exam-timer-display { font-size: 1.4rem; font-weight: 700; color: var(--bleu); }
.exam-timer-display.warning { color: var(--orange); }
.exam-timer-display.danger { color: var(--rouge); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ========== Glossaire ========== */
.glossaire-search { margin-bottom: 16px; }
.glossaire-letter {
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--bleu);
  margin-top: 24px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--bleu-light);
}
.glossaire-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.glossaire-term { font-weight: 700; }
.glossaire-def { color: var(--text-soft); font-size: 0.95rem; margin-top: 4px; }

/* ========== Cheatsheet ========== */
.cheatsheet { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 768px) { .cheatsheet { grid-template-columns: repeat(2, 1fr); } }
.cheatsheet h3 { color: var(--bleu); margin-top: 0; }
.cheatsheet table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.cheatsheet td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.cheatsheet td:first-child { font-weight: 600; color: var(--text-soft); }
.cheatsheet td:last-child { font-family: var(--font-mono); text-align: right; }

@media print {
  body { padding: 0; background: white; color: black; }
  .topbar, .tabs, .lecon-actions, .btn, .icon-btn { display: none !important; }
  .app-content { padding: 0; max-width: none; }
  .card, .pole-card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}

/* ========== Modal ========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-strong);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-body { padding: 20px; }

/* ========== Utilities ========== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-mute); }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-soft);
  color: var(--text-soft);
}
.badge-cap { background: var(--jaune); color: #5C4D00; }
.badge-debutant { background: var(--vert); color: white; }
.badge-intermediaire { background: var(--bleu); color: white; }
.badge-avance { background: var(--rouge); color: white; }

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg-card);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-strong);
  z-index: 200;
  font-size: 0.9rem;
  animation: toast-in 0.2s;
}
@keyframes toast-in {
  from { transform: translate(-50%, 12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

@media (min-width: 768px) {
  .toast { bottom: 24px; }
}
