/* ═══════════════════════════════════════
   MOA — /styles/avatar.css  v6
═══════════════════════════════════════ */

/* ── Miniature fixe bas-droite ── */
.moa-mini {
  position: fixed;
  bottom: 20px; right: 20px;
  width: 68px; height: 68px;
  cursor: pointer;
  z-index: 500;
  transition: transform .2s;
}
.moa-mini:hover     { transform: scale(1.08); }
.moa-mini.actif img { border-color: #e07818; }
.moa-mini img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center top;
  border-radius: 50%;
  border: 3px solid #5587b7;
  box-shadow: 0 4px 16px rgba(0,0,0,.22);
  background: white;
  display: block;
  transition: border-color .3s;
}
.moa-badge {
  position: absolute;
  top: -4px; right: -4px;
  width: 22px; height: 22px;
  background: #e07818;
  border: 2px solid white;
  border-radius: 50%;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}

/* ── Layout cours avec Moa ── */
.cours-layout.moa-ouvert {
  display: flex !important;
  align-items: flex-start;
  gap: 20px;
}
.cours-layout.moa-ouvert .cours-toc  { display: none !important; }
.cours-layout.moa-ouvert .cours-main { flex: 1; min-width: 0; }

/* ── Panneau Moa (colonne droite) ── */
.moa-panel {
  display: none;
  width: 250px;
  flex-shrink: 0;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 20px;
  align-self: flex-start;
  background: white;
  border: 1px solid #d8e4f0;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  z-index: 100;
}
.moa-panel.visible { display: flex; }

/* Image / vidéo avatar */
.moa-media {
  width: 100%;
  height: 200px;
  border-radius: 10px;
  overflow: hidden;
  background: #eef3fa;
  flex-shrink: 0;
  position: relative;
}
/* Règles communes à l'image et à la vidéo */
.moa-media img,
.moa-media video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  transition: opacity .3s;
}

/* ── Protection contre le téléchargement des médias avatar ── */
.moa-media img,
.moa-media video,
.moa-mini img {
  -webkit-user-drag: none;
  user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;
}
/* Rétablir pointer-events sur la miniature elle-même (cliquable) */
.moa-mini { pointer-events: auto; }

/* Règles spécifiques uniquement à l'image (pour qu'elle rentre en entier) */
.moa-media img {
  object-fit: contain;
  object-position: center;
}

/* Règles spécifiques uniquement à la vidéo (on garde l'ancien comportement) */
.moa-media video {
  object-fit: cover;
  object-position: top;
  opacity: 0;
}

/* Règle spécifique pour forcer UNIQUEMENT cette vidéo à s'afficher en entier */
.moa-media video[src*="moa2vl.mp4"] {
  object-fit: contain !important;
}

.moa-media.joue video { opacity: 1; }
.moa-media.joue img   { opacity: 0; }

/* Header nom + boutons */
.moa-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.moa-nom {
  font-size: 13px; font-weight: 700;
  color: #1a2040;
}
.moa-header-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Bouton switch avatar */
.moa-switch {
  background: none; border: none;
  font-size: 15px; cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  color: #5587b7;
  transition: background .15s, transform .2s;
}
.moa-switch:hover {
  background: #eef3fa;
  transform: rotate(180deg);
}

/* Bouton fermer */
.moa-close {
  background: none; border: none;
  font-size: 15px; color: #bbb;
  cursor: pointer; padding: 2px 5px;
  border-radius: 4px;
}
.moa-close:hover { color: #555; background: #f0f0f0; }

/* Boutons action */
.moa-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.mb {
  padding: 8px 4px;
  border: none; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  color: white; cursor: pointer;
  transition: opacity .15s;
  font-family: inherit;
}
.mb:hover      { opacity: .83; }
.mb-lire       { background: #5587b7; }
.mb-detail     { background: #a3612a; }
.mb-autre      { background: #30506e; }
.mb-stop       { background: #9fa1a2; grid-column: span 2; }
.mb-demander   { background: #1a7a4a; grid-column: span 2; }
.mb-demander.actif { background: #145c38; }

/* ── Boutons mode exercice ── */
.mb-ex-intro      { background: #5587b7; }
.mb-ex-correction { background: #1a7a4a; }
.mb-ex-autre      { background: #30506e; }
.mb-ex-stop       { background: #9fa1a2; grid-column: span 2; }

/* État */
.moa-etat {
  font-size: 11px; color: #5587b7;
  min-height: 14px; text-align: center;
}

/* Texte explicatif */
.moa-texte {
  display: none;
  background: #f0f6ff;
  border-left: 3px solid #5587b7;
  border-radius: 0 8px 8px 0;
  padding: 8px 10px;
  font-size: 12px; line-height: 1.6;
  color: #1a2040;
}

/* ── Bouton Écouter dans chaque section ── */
.moa-section-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 12px;
  padding: 5px 14px;
  background: #eef3fa;
  border: 1px solid #c8d8ee;
  border-radius: 20px;
  font-size: 12px; font-weight: 600;
  color: #5587b7; cursor: pointer;
  font-family: inherit;
  transition: background .15s;
}
.moa-section-btn:hover { background: #d8e8f8; }

/* ── Zone chat ── */
.moa-chat {
  border-top: 1px solid #d8e4f0;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.moa-chat-messages {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 0;
}
.moa-msg {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.5;
  max-width: 90%;
  word-break: break-word;
}
.moa-msg-eleve {
  background: #dbeafe;
  color: #1e3a5f;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}
.moa-msg-moa {
  background: #f0fdf4;
  color: #14532d;
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}
.moa-msg.loading {
  color: #888;
  font-style: italic;
  background: #f5f5f5;
}
.moa-chat-input-wrap {
  display: flex;
  gap: 5px;
  align-items: flex-end;
}
.moa-chat-input {
  flex: 1;
  border: 1px solid #c8d8ee;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  resize: none;
  line-height: 1.4;
}
.moa-chat-input:focus {
  outline: none;
  border-color: #5587b7;
}
.moa-chat-send {
  padding: 6px 10px;
  background: #5587b7;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.moa-chat-send:hover { opacity: .85; }

/* ══════════════════════════════════════
   OVERLAY FIGURE
══════════════════════════════════════ */
.moa-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.moa-overlay.visible { display: flex; }
.moa-overlay-box {
  background: white;
  border-radius: 16px;
  padding: 16px;
  width: min(560px, 96vw);
  max-height: 92vh;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.moa-overlay-close {
  align-self: flex-end;
  padding: 5px 14px;
  background: #e07818; color: white;
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.moa-overlay-close:hover { opacity: .85; }
.moa-overlay-box iframe {
  width: 100%;
  height: calc(92vh - 80px);
  min-height: 480px;
  border: none;
  border-radius: 8px;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .moa-mini  { bottom: 14px; right: 14px; width: 56px; height: 56px; }
  .moa-panel {
    position: fixed;
    bottom: 90px; right: 8px;
    width: 230px; z-index: 400;
    max-height: 80vh;
  }
  .cours-layout.moa-ouvert { display: block !important; }
  .moa-overlay-box iframe  { height: calc(90vh - 60px); min-height: 380px; }
}
/* Conteneur Moa sur pages exercices/activité */
.moa-conteneur-exo {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 250px;
  z-index: 400;
}
.moa-conteneur-exo .moa-panel {
  position: relative;
  top: auto;
  width: 100%;
  max-height: calc(100vh - 40px);
}
/* ── Bouton Écouter dans les cartes exercice ── */
.btn-ex-ecouter {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  background: #eef3fa;
  border: 1px solid #c8d8ee;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: #5587b7;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}
.btn-ex-ecouter:hover {
  background: #d8e8f8;
  border-color: #5587b7;
}

/* ── Figures SVG dans les exercices ── */
.ex-figure {
  text-align: center;
  margin: 12px 0;
}
.ex-figure svg {
  max-width: 360px;
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}
/* ── Panneau hors page cours (exercices, activité) ── */
body:not(.cours-page) .moa-panel.visible {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 250px;
  max-height: calc(100vh - 40px);
  z-index: 400;
}

/* ── Compense le zoom navigateur : la miniature et la vidéo Moa
   gardent leur taille même si l'élève fait Ctrl+ / Ctrl- ────── */
.moa-mini {
  transform: scale(var(--moa-zoom-counter, 1));
  transform-origin: bottom right;
  transition: transform 0.15s ease;
}

.moa-media {
  transform: scale(var(--moa-zoom-counter, 1));
  transform-origin: top center;
  transition: transform 0.15s ease;
}

/* Avatar Moa toujours au-dessus des bandeaux de page (cours, brevet, exercices, etc.) */
.moa-panel,
.moa-mini,
.moa-overlay {
  z-index: 9999 !important;
}