/*
  ===================================================================
  FICHIER CSS GLOBAL HARMONISÉ POUR LES TRAVAUX DIRIGÉS (TD) - MATHS
  Contient les styles pour les boîtes d'exercices, QCM, indices et corrections.
  ===================================================================
*/

:root {
  /* Couleurs principales (Maths = Physique/Chimie) */
  --primary-orange: #ff7b00;
  --secondary-yellow: #ffe066;

  /* Couleurs de texte */
  --text-primary: #222;
  --text-secondary: #555;

  /* Ombres */
  --shadow-light: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-medium: 0 8px 25px rgba(0, 0, 0, 0.15);

  /* Fond par défaut pour les TD */
  --background-solid-td: #fff2beff;

  /* Fond des boîtes de table des matières (si utilisé dans le TD) */
  --card-background: linear-gradient(145deg, hsl(46, 100%, 89%), #fff8cf);

  /* --- COULEURS DES BOÎTES D'EXERCICES --- */

  --color-qcm-bg: linear-gradient(145deg, #e8f5e9, #c8e6c9);
  /* Vert pâle (QCM) */
  --color-qcm-border: #4CAF50;

  --color-exo-bg: linear-gradient(145deg, #e3f2fd, #bbdefb);
  /* Bleu pâle (Exercice standard) */
  --color-exo-border: #2196F3;

  --color-extra-bg: linear-gradient(145deg, #fff3e0, #ffe0b2);
  /* Orange pâle (Exercice supplémentaire) */
  --color-extra-border: #ff9800;

  --color-hint-bg: #e1f5fe;
  /* Bleu très pâle (Indice) */
  --color-hint-border: #0288d1;

  --color-correct: #D32F2F;
  /* Rouge (Réponse QCM) */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ----------------------------------- */
/* Styles du Corps et du Conteneur Principal */
/* ----------------------------------- */
body {
  font-family: 'Poppins', sans-serif;
  background: var(--background-solid-td);
  color: var(--text-primary);
  margin: 0;
  text-align: center;
  padding: 0;
  line-height: 1.8;
}

.cours-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.content-wrapper {
  background: white;
  border-radius: 20px;
  padding: 50px;
  box-shadow: var(--shadow-light);
  margin-bottom: 40px;
  text-align: left;
}

.course-header {
  border: 3px double var(--primary-orange);
  padding: 20px;
  text-align: center;
  margin-bottom: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, #fff9e6, #ffffff);
}

.course-header h2 {
  font-size: 1.8rem;
  margin: 0;
  color: var(--text-primary);
}

.section-title {
  font-size: 2rem;
  color: var(--primary-orange);
  margin-top: 50px;
  margin-bottom: 25px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--primary-orange);
}


/* ----------------------------------- */
/* Boutons de Navigation */
/* ----------------------------------- */
.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary-orange), #ff9500);
  color: white;
  padding: 12px 24px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 4px 15px rgba(255, 123, 0, 0.3);
  transition: all 0.3s ease;
  margin: 0;
}

.btn-nav:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 123, 0, 0.4);
}

.navigation-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 40px;
}

/* Positionnement des boutons du bas */
.content-wrapper>.navigation-buttons:last-of-type {
  margin-top: 50px;
  margin-bottom: 0;
}


/* ----------------------------------- */
/* STYLES SPÉCIFIQUES AUX TD (EXERCICES) */
/* ----------------------------------- */

/* --- Sections Dépliables (pour regrouper les QCM ou les Exercices) --- */
details.collapsible-section {
  margin-bottom: 25px;
}

details.collapsible-section>summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
}

details.collapsible-section>summary::before {
  content: '▸';
  color: var(--primary-orange);
  font-size: 2rem;
  margin-right: 10px;
  display: inline-block;
  transition: transform 0.2s;
  transform-origin: center;
}

details.collapsible-section[open]>summary::before {
  transform: rotate(90deg);
}

details.collapsible-section>summary h2.section-title {
  margin-top: 0;
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

/* --- Conteneurs d'exercices (QCM, Exo standard, Exo supplémentaire) --- */
.qcm-box,
.exercice-box {
  padding: 25px;
  margin: 25px 0;
  border-radius: 10px;
  box-shadow: var(--shadow-light);
}

/* 1. Style QCM (Vert) */
.qcm-box {
  background: var(--color-qcm-bg);
  border-left: 5px solid var(--color-qcm-border);
}

/* 2. Style Exercice (Bleu) */
.exercice-box {
  background: var(--color-exo-bg);
  border-left: 5px solid var(--color-exo-border);
}

/* 3. Style Exercice Supplémentaire (Orange) */
.exercice-box.extra {
  background: var(--color-extra-bg);
  border-left: 5px solid var(--color-extra-border);
}

h3.exercice-title {
  font-size: 1.4rem;
  color: var(--text-primary);
  margin-top: 0;
  margin-bottom: 15px;
}

.exercice-enonce {
  margin-bottom: 20px;
}

.exercice-enonce ol {
  padding-left: 20px;
}

/* --- Listes d'options QCM --- */
.qcm-box p {
  margin-top: 0;
}

ul.qcm-options {
  list-style-type: none;
  padding-left: 0;
  margin: 20px 0;
}

ul.qcm-options li {
  margin: 8px 0;
  font-weight: 500;
}

.qcm-answer {
  color: var(--color-correct);
  font-weight: bold;
}


/* --- Dropdown d'Indice --- */
details.hint-dropdown {
  margin-top: 20px;
  margin-bottom: 10px;
}

details.hint-dropdown summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--color-hint-border);
  background: #f4faff;
  padding: 10px 15px;
  border-radius: 8px;
  border: 1px solid var(--color-hint-border);
  transition: background 0.3s;
  list-style: none;
}

details.hint-dropdown summary:hover {
  background: #eaf6ff;
}

details.hint-dropdown summary::before {
  content: '▸';
  color: var(--color-hint-border);
  font-size: 1.1rem;
  margin-right: 10px;
  display: inline-block;
  transition: transform 0.2s;
}

details[open].hint-dropdown>summary::before {
  transform: rotate(90deg);
}

.hint-content {
  background: #f0f9ff;
  padding: 20px;
  border-radius: 0 0 8px 8px;
  margin-top: -1px;
  border: 1px solid #bce3ff;
  border-top: 1px dashed #bce3ff;
  font-size: 0.95rem;
}

.hint-content p:first-child {
  margin-top: 0;
}

.hint-content p:last-child {
  margin-bottom: 0;
}


/* --- Dropdown de Correction --- */
details.correction-dropdown {
  margin-top: 20px;
}

details.correction-dropdown summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary-orange);
  background: #fffcf5;
  padding: 10px 15px;
  border-radius: 8px;
  border: 1px solid var(--secondary-yellow);
  transition: background 0.3s;
  list-style: none;
}

details.correction-dropdown summary:hover {
  background: #fff9e6;
}

details.correction-dropdown summary::before {
  content: '▸';
  color: var(--primary-orange);
  font-size: 1.1rem;
  margin-right: 10px;
  display: inline-block;
  transition: transform 0.2s;
}

details[open].correction-dropdown>summary::before {
  transform: rotate(90deg);
}

.correction-content {
  background: #fefefe;
  padding: 20px;
  border-radius: 0 0 8px 8px;
  margin-top: -1px;
  border: 1px solid #eee;
  border-top: 1px dashed var(--secondary-yellow);
  font-size: 0.95rem;
}

.correction-content p:first-child {
  margin-top: 0;
}

.correction-content p:last-child {
  margin-bottom: 0;
}


/* --- Styles utilitaires (Tables, etc.) --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 25px 0;
  background: white;
  box-shadow: var(--shadow-light);
  border-radius: 10px;
  overflow: hidden;
}

table th {
  background: var(--primary-orange);
  color: white;
  padding: 15px;
  text-align: center;
  font-weight: 600;
}

table td {
  padding: 12px;
  text-align: center;
  border: 1px solid #e0e0e0;
}

table tr:nth-child(even) {
  background: #fafafa;
}

hr {
  border: 0;
  border-top: 2px dashed #e0e0e0;
  margin: 25px 0;
}

/* ----------------------------------- */
/* Responsive (Mobile) */
/* ----------------------------------- */
@media (max-width: 768px) {
  body {
    font-size: 0.95rem;
  }

  .content-wrapper {
    padding: 20px;
    /* Reduced padding */
    text-align: left;
    overflow-x: hidden;
  }

  .course-header {
    padding: 15px;
  }

  .course-header h2 {
    font-size: 1.4rem;
  }

  .section-title,
  details.collapsible-section>summary h2.section-title {
    font-size: 1.4rem;
    /* Smaller section titles */
  }

  details.collapsible-section>summary::before {
    font-size: 1.4rem;
  }

  /* Exercise boxes mobile adjustments */
  .qcm-box,
  .exercice-box {
    padding: 15px;
    /* Reduced padding */
    margin: 20px 0;
    overflow-x: auto;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  h3.exercice-title {
    font-size: 1.2rem;
  }

  .navigation-buttons {
    flex-direction: row;
    gap: 10px;
  }

  .btn-nav {
    width: 100%;
    /* Full width for easier tapping */
    justify-content: center;
    max-width: none;
    padding: 12px 15px;
    font-size: 0.9rem;
  }

  /* Amélioration mobile pour les tables */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    max-width: 100%;
  }

  /* Ensure math/formulas don't overflow */
  .exercice-enonce,
  .qcm-options,
  .correction-content,
  .hint-content {
    overflow-x: auto;
    max-width: 100%;
  }

  /* Ensure images don't overflow (except header logo) */
  img:not(.logo) {
    max-width: 100% !important;
    height: auto !important;
  }

  /* Only apply overflow to block display equations, not inline math */
  mjx-container[display="true"] {
    overflow-x: auto !important;
    max-width: 100% !important;
  }
}

@media (max-width: 480px) {
  .content-wrapper {
    padding: 15px;
  }

  .section-title {
    font-size: 1.3rem;
  }
}

/* ----------------------------------- */
/* NOUVEAU TEMPLATE EXERCICES (Piments & Listes) */
/* ----------------------------------- */

/* Indicateur de difficulté (Piments) */
.difficulty-indicator {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 10px;
  cursor: help;
  /* Indique qu'il y a une info au survol */
  vertical-align: middle;
}

.pepper {
  font-size: 1.2rem;
  filter: grayscale(100%);
  /* Par défaut gris */
  opacity: 0.4;
  transition: all 0.3s ease;
}

.pepper.active {
  filter: grayscale(0%);
  /* Couleur normale */
  opacity: 1;
  transform: scale(1.1);
}

/* Listes personnalisées (Indices & Corrections) */
.hint-content ul,
.correction-content ul {
  list-style-type: none;
  /* On enlève les puces rondes */
  padding-left: 10px;
}

.hint-content ul li,
.correction-content ul li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 8px;
}

.hint-content ul li::before,
.correction-content ul li::before {
  content: '■';
  /* Carré */
  color: var(--primary-orange);
  font-size: 0.8em;
  position: absolute;
  left: 0;
  top: 4px;
}

/* Variante avec tirets si besoin */
.hint-content ul.dashed li::before,
.correction-content ul.dashed li::before {
  content: '—';
}

/* Encadrement des résultats */
.result-box {
  display: inline-block;
  border: 2px solid var(--color-correct);
  padding: 5px 10px;
  border-radius: 6px;
  background-color: #fff5f5;
  font-weight: bold;
  margin-top: 5px;
}

/* Si on utilise MathJax \boxed{}, on peut aussi styliser le conteneur autour si besoin, 
   mais \boxed{} fait déjà le travail en LaTeX. 
   On ajoute une classe utilitaire pour les phrases de conclusion. */
.final-answer {
  border-left: 4px solid var(--color-correct);
  background-color: rgba(211, 47, 47, 0.05);
  padding: 10px;
  margin-top: 10px;
  border-radius: 0 4px 4px 0;
}

/* --- Graphiques --- */
.graph-container {
  width: 100%;
  height: 400px;
  margin: 20px 0;
  display: flex;
  justify-content: center;
  /* Centré sur PC */
}

@media (max-width: 768px) {
  .graph-container {
    display: block;
    /* Comme avant sur mobile */
    overflow-x: auto;
  }
}