/* -------- core.css -------- */
/* Variables pour les badges */
:root {
  --badge-d: clamp(44px, 5vw, 56px);
  --badge-img-scale: 0.82;
  --badge-offset: calc(var(--badge-d) * -0.25);
  --close-size: clamp(28px, 3.4vw, 42px);
  --topbtn: clamp(32px, 4vw, 48px); 
  --topbtn-gap: 10px;  
}

/* ===== Chat tuning via variables ===== */
:root{
  /* valeurs par défaut fallback */
  --bubble-radius: 14px;
  --bubble-pad-x: 14px;
  --bubble-pad-y: 10px;
  --bubble-gap-y: 8px;
  --bubble-maxw: 680px;
}

/* barre du bas (input + send) au-dessus des décos */
#chat-bar {
  position: relative;
  z-index: 70; /* > backgrounds/decors */
  display:flex; 
  gap:0.5rem; 
  width:100%;
  margin-top:0.5rem;
}
/* Grille 1fr / auto : messages prend la place, chat-bar reste en bas */
#chat-stack {
  display: grid;
  grid-template-rows: 1fr auto;
  z-index: 70;             /* au-dessus des décos */
  pointer-events: none;    /* le fond reste neutralisé… */
  padding:1rem;
  box-sizing:border-box;
  /* neutralise toute tentative de colonnes venue d'ailleurs */
  grid-template-columns: unset;  
}

/* …mais les éléments de chat doivent rester interactifs */
#chat-stack > #messages,
#chat-stack > #chat-bar {
  pointer-events: auto;
}

/* Conteneurs d’icônes lottie (structure) */
.lottie-container {
  position: absolute;
  transition: opacity 1s ease;
  overflow: hidden;
}
.lottie-container{
  transition: opacity 1.25s cubic-bezier(.22,.61,.36,1);
  will-change: opacity;
}

#lottie-zone {
  position: absolute;   /* le reste (width/height/z-index/…) est injecté par JS via JSON */
  display: block;
  overflow: hidden;     /* overflow peut être réactivé via JSON si besoin */
  visibility: hidden;
  z-index: 60;
}
#lottie-zone.is-ready { visibility: visible; }
/* État redimensionnable : on garde le comportement, l’activation vient du JSON (resizable.active) */
#lottie-zone.resizable-active {
  resize: both;
  overflow: hidden !important;
  border: 2px dashed #444;
  box-sizing: border-box;
}
#lottie-layer { 
  position: absolute; 
  inset: 0; 
  z-index: 60; 
}
/* Scrollbar des messages (confort) */
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb {
  background-color: transparent;
  border-radius: 8px;
  transition: background-color 0.3s ease;
  background: rgba(255,255,255,0.4);
}
#messages:hover::-webkit-scrollbar-thumb { 
  background-color: rgba(0, 0, 0, 0.3); 

}
#messages:hover::-webkit-scrollbar-thumb:hover { background-color: rgba(0, 0, 0, 0.5); }
/* Padding du flux pour éviter la coupe des badges */
#messages {
  padding-top:  calc(var(--badge-d) * 0.60);
  padding-left:  calc(var(--badge-d) * 0.72);
  padding-right: calc(var(--badge-d) * 0.72);
  line-height: 1.35;
}
/* indispensable pour que la zone scroll puisse vraiment rétrécir */
#messages { 
  min-height: 0; 
  z-index: 60;
  overflow-y:auto;
  overflow-x:hidden;
  min-height:0;
  overscroll-behavior:contain;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;  
}
/* === Bulles + badges avatar (chat UI) === */
.message-bubble {
  position: relative;
  border-radius: 14px;
  padding: 10px 14px;
  display: inline-block;            /* au lieu de w-fit */
  max-width: min(80vw, 680px);      /* bornes sûres */
  vertical-align: top;
  box-sizing: border-box;
  margin: 8px 0;                 /* espace vertical entre bulles */
  word-break: break-word;        /* coupe long mots */
  /* overflow-wrap: anywhere;        */
  white-space: pre-wrap;         /* garde les \n */
  z-index: 60;
}

@media (max-width: 600px) {
  .message-bubble {
    max-width: 72vw;
  }
  :root {
    --badge-d: 40px;              /* un peu plus petit */
    --badge-offset: calc(var(--badge-d) * -0.25);
  }  
}

.message-bubble--right .avatar-badge { left: auto; right: var(--badge-offset); }
/* Réserve d’espace pour le badge */
.message-bubble--left  { padding-left:  calc(var(--badge-d) * 0.88 + 12px); }
.message-bubble--right { padding-right: calc(var(--badge-d) * 0.88 + 12px); }
.message-bubble .text{
  overflow-wrap: anywhere;      /* évite les débordements (URLs longues, etc.) */
  word-break: break-word;
}
/* Badge circulaire qui prend la couleur de la bulle via --bubble-bg */
.avatar-badge {
  position: absolute;
  top: var(--badge-offset);
  left: var(--badge-offset);
  width: var(--badge-d);
  height: var(--badge-d);
  border-radius: 50%;
  background: var(--bubble-bg, #ffffff);
  display: grid;
  place-items: center;
  box-shadow:
    0 0 0 calc(var(--badge-d) * 0.06) var(--bubble-bg, #ffffff),
    0 6px 16px rgba(0,0,0,.18);
  z-index: 60;
}
.avatar-badge img {
  width: calc(var(--badge-d) * var(--badge-img-scale));
  height: calc(var(--badge-d) * var(--badge-img-scale));
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* Animation par défaut de gradient : dispo si le JSON demande "animationName: gradientMove" */
@keyframes gradientMove {
  0%   { background-position: 0%   50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0%   50%; }
}

/* ===== Close bubble ===== */
:root{
  --close-size: clamp(28px, 3.4vw, 42px);
}
#closeChat{
  position:absolute; top:.5rem; right:.75rem;
  width:var(--close-size); height:var(--close-size);
  display:grid; place-items:center;
  font-size:calc(var(--close-size) * .55);
  line-height:1; font-weight:700;
  color:#111;
  background: rgba(255,255,255,.28);
  backdrop-filter: blur(6px);
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(0,0,0,.18), inset 0 0 0 1px rgba(255,255,255,.55);
  cursor:pointer; 
  /* user-select:none; */
  z-index: 911;
  transition: transform .18s ease, background .18s ease, color .18s ease, box-shadow .18s ease;
}
#closeChat:hover{
  transform: scale(1.06);
  background: rgba(255,255,255,.42);
  color:#000;
}
#closeChat:active{
  transform: scale(.98);
}

/* ===== BARRE DE CHAT : éviter le rognage à droite ===== */

/* Comportement par défaut */
#chat-bar {
  display: flex;
  /* align-items: center; */
  align-items: flex-end;
  gap: 0.5rem;
  width: 100%;
}

/* L'input : prend toute la place dispo, peut rétrécir */
#chat-bar #chat-input {
  flex: 1 1 auto;   /* grandit ET rétrécit */
  min-width: 0;     /* important pour permettre un vrai shrink */
}

/* Le bouton Envoyer : peut aussi rétrécir légèrement */
#sendBtn {
  flex: 0 1 auto;           /* shrink autorisé */
  white-space: nowrap;      /* "Envoyer" reste sur une seule ligne */
}

/* Très petits écrans : on réduit un peu tailles et padding */
@media (max-width: 420px) {
  #chat-stack {
    padding-inline: 0.5rem; /* un peu moins de marge à gauche/droite */
  }

  #chat-bar {
    gap: 0.4rem;
  }

  #chat-bar #chat-input {
    padding: 0.35rem 0.5rem;  /* écrase les px-3/py-2 de Tailwind */
    font-size: 0.85rem;
  }

  #sendBtn {
    padding: 0.3rem 0.45rem;  /* bouton plus compact */
    font-size: 0.8rem;
    max-width: 30%;           /* évite qu'il s'accapare toute la ligne */
  }
}

/* Ultra étroit : si vraiment il n'y a plus la place, on préfère WRAP plutôt que rogner */
@media (max-width: 340px) {
  #chat-bar {
    flex-wrap: wrap;
  }

  #chat-bar #chat-input {
    flex: 1 1 100%;
    order: 1;
  }

  #sendBtn {
    order: 2;
    align-self: flex-end;
  }
}
/* NEW affichage images & sources */
/* Images insérées par les fiches de connaissance */
.message-images-row {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.message-image-thumb {
  max-width: 30vw;  
  max-height: 30vh;
  border-radius: 0.75rem;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.18);
  object-fit: cover;
}

/* Sur mobile : l’image peut prendre toute la largeur de la bulle */
@media (max-width: 640px) {
  .message-image-thumb {
    max-width: 100%;
  }
}

.message-sources {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  opacity: 0.85;
}

.message-source-line a {
  text-decoration: underline;
}

#chat-input {
  flex: 1 1 auto;
  max-height: 160px;        /* hauteur max avant scroll interne */
  min-height: 40px;
  padding: 0.6rem 0.75rem;
  border-radius: 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: rgba(15, 23, 42, 0.8);
  color: #f9fafb;
  resize: none;             /* pas de handle manuel, on gère en JS */
  overflow-y: auto;         /* scroll interne si texte très long */
  overflow-x: hidden;
  line-height: 1.3;
  font-size: 0.95rem;
  box-sizing: border-box;
}

#chat-input::placeholder {
  color: rgba(148, 163, 184, 0.9);
}

#sendBtn {
  flex: 0 0 auto;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  color: white;
  background: #111827; /* ajusté ensuite par applyChatTheme */
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#interactiveHint.is-visible{ opacity:1; transform: translateY(-1px); }
#interactiveHint.is-hidden{ opacity:0; }


#chatTopControls{
  position: absolute;
  top: calc(.5rem + 44px + 10px);;
  right: 0.75rem;

  bottom: 5.75rem;

  display: flex;
  gap: 10px;
  align-items: center;
  flex-direction: column;
  z-index: 910;
}

/* icônes nues (pas de pastille) */
#chatTopControls #audioToggle,
#chatTopControls #interactiveHint{
  width: var(--topbtn);
  height: var(--topbtn);
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chatTopControls #audioToggle img,
#chatTopControls #interactiveHint img{
  width: 100%;
  height: 100%;
  display: block;
}

/* Cache totalement le bouton audio quand il n'y a pas de musique */
#chatTopControls #audioToggle.is-hidden{
  display: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* hint non cliquable */
#chatTopControls #interactiveHint{ pointer-events: none; }

/* close garde son style */
#chatTopControls #closeChat{ position: static !important; }

#lottie-zone.transparent-shell { background: transparent !important; box-shadow: none !important; border: none !important; }

/* Bouton timer */
#chatTopControls #animTimer{
  width: var(--topbtn);
  height: var(--topbtn);
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin: 0 !important;

  display: flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  pointer-events: auto; /* IMPORTANT: cliquable */
}
/* Disque “camembert” */
#animTimer .timerDisc{
  width: 100%;
  height: 100%;
  border-radius: 999px;
  position: relative;

  /* variable de progression (1 → 0) */
  --p: 1;

  /* Camembert : plein au début, se vide ensuite */
  background:
    conic-gradient(
      #ffffff calc(var(--p) * 1turn),
      #000000 0
    );

  /* Option: un anneau fin autour (look plus “UI”) */
  outline: 2px solid #ffffff;
  outline-offset: -2px;
}

/* X au centre */
#animTimer .timerDisc .timerX{
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0.95;
}

/* petit effet hover (facultatif, pas de blink) */
#animTimer:hover .timerDisc{
  outline-color: rgba(255,255,255,0.45);
}
#animTimer.is-hidden{
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#animTimer.is-visible{
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ===== Slot vidéo top (activé uniquement si #lottie-zone a la classe) ===== */
:root{
  --top-video-h: 0px;     /* fallback */
  --top-video-gap: 12px;  /* petit espace entre vidéo et messages */
}

/* 1) Réserve d’espace au niveau du conteneur NON scroll (sanctuarisé) */
#lottie-zone.top-video-slot #chat-stack{
  padding-top: calc(1rem + var(--top-video-h) + var(--top-video-gap));
}

/* 2) #messages garde juste le padding badge (comme avant) */
#lottie-zone.top-video-slot #messages{
  padding-top: calc(var(--badge-d) * 0.60);
}

/* pousse le bloc multibot vers le bas */
#chatTopControls .chatTopSpacer{
  flex: 1 1 auto;
}

/* conteneur bas */
#chatTopMultibotControls{
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

/* boutons multibot (textuels) dans la colonne */
#chatTopControls .chatTopMultibotBtn{
  width: clamp(92px, 10vw, 128px);
  min-height: var(--topbtn);
  padding: 8px 10px;

  border-radius: 14px;
  border: none;
  cursor: pointer;

  font-size: 12px;
  line-height: 1.1;
  font-weight: 700;
  text-align: center;

  color: #111;
  background: rgba(255,255,255,.28);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 22px rgba(0,0,0,.18), inset 0 0 0 1px rgba(255,255,255,.55);
}
#chatTopControls .chatTopMultibotBtn:active{
  transform: scale(.98);
}
