/* Bouton de chat (étape 7, docs/guide-contenu.md) : remplace Chaty, réglé comme Haris l'avait fait.
   Couche 1050 : au-dessus de la page, sous la liste plein écran des pays du champ téléphone (1060), la galerie
   photo des tours (2000), le menu mobile (9998) et la bannière cookies (2147483000). */
.arb-chat {
  --arb-vert: #609476; /* vert des boutons du site */
  --arb-vert-fonce: #4f7d63;
  --arb-whatsapp: #25d366;
  --arb-texte: #252119;
  --arb-marge: 25px;
  --arb-taille: 54px;
  position: fixed;
  right: calc(var(--arb-marge) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--arb-marge) + env(safe-area-inset-bottom, 0px));
  z-index: 1050;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: Manrope, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--arb-texte);
  pointer-events: none; /* seuls les éléments visibles reçoivent les clics */
}
.arb-chat *, .arb-chat *::before, .arb-chat *::after { box-sizing: border-box; }
.arb-chat > * { pointer-events: auto; }
.arb-chat [hidden] { display: none !important; }
.arb-chat button, .arb-chat a { -webkit-tap-highlight-color: transparent; }
.arb-chat :focus { outline: none; }
.arb-chat :focus-visible { box-shadow: 0 0 0 3px #fff, 0 0 0 5px #02131b; }

/* Ronds : bouton principal, WhatsApp, Instagram */
.arb-chat__rond {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--arb-taille);
  height: var(--arb-taille);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(2, 19, 27, .25);
  transition: transform .15s ease, background-color .15s ease;
}
.arb-chat__rond:hover { transform: scale(1.06); }
.arb-chat__rond svg { display: block; pointer-events: none; }
.arb-chat__bouton { background: var(--arb-vert); }
.arb-chat__bouton:hover { background: var(--arb-vert-fonce); }
.arb-chat__bouton .arb-chat__croix { display: none; }
.arb-chat[data-etat="ouvert"] .arb-chat__bouton .arb-chat__bulle-icone,
.arb-chat[data-etat="whatsapp"] .arb-chat__bouton .arb-chat__bulle-icone { display: none; }
.arb-chat[data-etat="ouvert"] .arb-chat__bouton .arb-chat__croix,
.arb-chat[data-etat="whatsapp"] .arb-chat__bouton .arb-chat__croix { display: block; }
.arb-chat__canal--whatsapp { background: var(--arb-whatsapp); }
.arb-chat__canal--instagram { background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285aeb 90%); }

/* Bas : étiquette et bouton principal */
.arb-chat__bas { display: flex; align-items: center; gap: 12px; }
.arb-chat__etiquette {
  padding: 9px 16px;
  border-radius: 999px;
  background: #fff;
  color: var(--arb-texte);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(2, 19, 27, .18);
}
.arb-chat[data-etat="ouvert"] .arb-chat__etiquette,
.arb-chat[data-etat="whatsapp"] .arb-chat__etiquette,
.arb-chat.arb-sans-etiquette .arb-chat__etiquette { display: none; } /* chat déjà ouvert pendant la visite (chat.js) */

/* Canaux empilés au-dessus du bouton */
.arb-chat__canaux { display: flex; flex-direction: column; align-items: center; gap: 12px; width: var(--arb-taille); }

/* Noms au survol (ordinateur) : WhatsApp, Instagram, Close */
@media (hover: hover) and (pointer: fine) {
  .arb-chat [data-bulle]::before {
    content: attr(data-bulle);
    position: absolute;
    right: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 12px;
    border-radius: 8px;
    background: #fff;
    color: var(--arb-texte);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(2, 19, 27, .18);
    opacity: 0;
    visibility: hidden;
    transition: opacity .12s ease;
    pointer-events: none;
  }
  .arb-chat [data-bulle]:hover::before { opacity: 1; visibility: visible; }
  .arb-chat[data-etat="ferme"] .arb-chat__bouton::before { display: none; } /* fermé : l'étiquette suffit */
}

/* Fenêtre WhatsApp */
.arb-chat__fenetre {
  width: 330px;
  max-width: calc(100vw - 2 * var(--arb-marge));
  overflow: hidden;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 34px rgba(2, 19, 27, .28);
}
.arb-chat__entete { display: flex; align-items: center; gap: 12px; padding: 14px 12px 14px 16px; background: var(--arb-vert); color: #fff; }
.arb-chat__avatar {
  flex: none;
  width: 48px;
  height: 48px;
  overflow: hidden;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--arb-vert-fonce);
}
.arb-chat__avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.arb-chat__titres { flex: 1; min-width: 0; }
.arb-chat__nom { font-weight: 700; font-size: 16px; line-height: 1.25; }
.arb-chat__titre { font-size: 13px; line-height: 1.3; opacity: .9; }
.arb-chat__fermer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.arb-chat__fermer:hover { background: rgba(255, 255, 255, .16); }
.arb-chat__corps { padding: 18px 16px 22px; background: #efe7dd; }
.arb-chat__message {
  position: relative;
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 0 10px 10px 10px;
  background: #fff;
  color: var(--arb-texte);
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-line;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .08);
}
.arb-chat__message::before { /* pointe de la bulle */
  content: "";
  position: absolute;
  top: 0;
  left: -8px;
  border-top: 10px solid #fff;
  border-left: 8px solid transparent;
}
.arb-chat__envoi { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-top: 1px solid #e6dccd; background: #fff; }
.arb-chat__champ {
  flex: 1;
  min-width: 0;
  height: 42px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid #ddd3c4;
  border-radius: 999px;
  background: #fff;
  color: var(--arb-texte);
  font: inherit;
  font-size: 16px; /* 16 px : pas de zoom automatique sur iPhone */
}
.arb-chat__champ::placeholder { color: #8a8174; }
.arb-chat__champ:focus-visible { box-shadow: none; border-color: var(--arb-vert); outline: 2px solid var(--arb-vert); outline-offset: 0; }
.arb-chat__envoyer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--arb-vert);
  color: #fff;
  cursor: pointer;
}
.arb-chat__envoyer:hover { background: var(--arb-vert-fonce); }

/* Mobile */
@media screen and (max-width: 767px) {
  .arb-chat { --arb-marge: 16px; --arb-taille: 52px; gap: 10px; }
  .arb-chat__canaux { gap: 10px; }
  .arb-chat__etiquette { padding: 8px 14px; font-size: 13.5px; }
}

/* Points « en train d'écrire » : affichés par chat.js seulement quand les animations sont permises. */
.arb-ecrit { display: none; }
/* Message d'accueil pendant les points « en train d'écrire » : caché à l'écran, lisible par un lecteur d'écran. */
.arb-chat__message.arb-attente {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* =====================================================================
   Animations (validées par Haris le 20/10, d'après la démo) : seulement si le visiteur n'a pas demandé à réduire
   les animations. Ressort : cubic-bezier(.34,1.56,.64,1) ; sortie douce : cubic-bezier(.2,.8,.2,1).
   ===================================================================== */
@media (prefers-reduced-motion: no-preference) {

  /* Arrivée à chaque chargement : le bouton apparaît en douceur, puis l'étiquette glisse (classe arb-arrive) */
  .arb-chat.arb-arrive .arb-chat__bouton { animation: arbArrive .6s cubic-bezier(.34,1.56,.64,1) 1s backwards; }
  .arb-chat.arb-arrive .arb-chat__etiquette { animation: arbGlisse .55s cubic-bezier(.34,1.56,.64,1) 1.3s backwards; }
  .arb-chat[data-etat="ferme"]:not(.arb-arrive) .arb-chat__etiquette { animation: arbGlisse .45s cubic-bezier(.34,1.56,.64,1) .12s backwards; }
  @keyframes arbArrive { from { opacity: 0; transform: scale(.4) rotate(-25deg); filter: blur(6px); } }
  @keyframes arbGlisse { from { opacity: 0; transform: translateX(22px) scale(.9); filter: blur(4px); } }

  /* Survol de l'ensemble étiquette + bouton */
  .arb-chat__rond { transition: transform .35s cubic-bezier(.34,1.56,.64,1), box-shadow .3s ease, background-color .2s ease !important; }
  .arb-chat__etiquette { transition: transform .35s cubic-bezier(.34,1.56,.64,1), box-shadow .3s ease; }
  @media (hover: hover) and (pointer: fine) {
    .arb-chat[data-etat="ferme"] .arb-chat__bas:hover .arb-chat__bouton { transform: translateY(-3px) scale(1.08) !important; box-shadow: 0 12px 28px rgba(2,19,27,.34) !important; }
    .arb-chat[data-etat="ferme"] .arb-chat__bas:hover .arb-chat__etiquette { transform: translate(-4px,-3px); box-shadow: 0 10px 24px rgba(2,19,27,.22); }
    .arb-chat[data-etat="ferme"] .arb-chat__bas:hover .arb-chat__bulle-icone { animation: arbBalance .7s ease; }
  }

  /* Icône : la bulle se change en croix (rotation fondue) */
  .arb-chat__bouton .arb-chat__bulle-icone, .arb-chat__bouton .arb-chat__croix { display: block !important; position: absolute; top: 50%; left: 50%; transition: transform .45s cubic-bezier(.34,1.56,.64,1), opacity .2s ease; }
  .arb-chat__bouton .arb-chat__bulle-icone { transform: translate(-50%,-50%) rotate(0) scale(1); opacity: 1; }
  .arb-chat__bouton .arb-chat__croix { transform: translate(-50%,-50%) rotate(-135deg) scale(.4); opacity: 0; }
  .arb-chat:not([data-etat="ferme"]) .arb-chat__bouton .arb-chat__bulle-icone { transform: translate(-50%,-50%) rotate(135deg) scale(.4); opacity: 0; }
  .arb-chat:not([data-etat="ferme"]) .arb-chat__bouton .arb-chat__croix { transform: translate(-50%,-50%) rotate(0) scale(1); opacity: 1; }
  @keyframes arbBalance { 0%,100% { transform: translate(-50%,-50%) rotate(0); } 20% { transform: translate(-50%,-50%) rotate(-14deg) scale(1.08); } 45% { transform: translate(-50%,-50%) rotate(11deg); } 70% { transform: translate(-50%,-50%) rotate(-6deg); } }

  /* Pression au clic (petit rebond) */
  .arb-chat__rond:active, .arb-chat[data-etat] .arb-chat__bas:hover .arb-chat__bouton:active { transform: scale(.9) !important; transition-duration: .1s !important; }
  .arb-chat .arb-pression { animation: arbPression .5s cubic-bezier(.34,1.56,.64,1); }
  @keyframes arbPression { 0% { transform: scale(.88); } 100% { transform: scale(1); } }

  /* Ouverture : WhatsApp et Instagram jaillissent du bouton */
  .arb-chat__canaux { position: relative; }
  .arb-chat .arb-chat__canaux .arb-chat__rond { animation: arbJaillit .6s cubic-bezier(.34,1.56,.64,1) backwards; }
  .arb-chat .arb-chat__canaux .arb-chat__rond:nth-child(2) { animation-delay: .03s; }
  .arb-chat .arb-chat__canaux .arb-chat__rond:nth-child(1) { animation-delay: .11s; }
  @keyframes arbJaillit { 0% { opacity: 0; transform: translateY(var(--d, 60px)) scale(.2) rotate(-60deg); filter: blur(8px); } 60% { opacity: 1; filter: blur(0); } }
  .arb-chat__canaux .arb-chat__rond:nth-child(1) { --d: 124px; }
  .arb-chat__canaux .arb-chat__rond:nth-child(2) { --d: 62px; }

  /* Survol de WhatsApp et Instagram */
  @media (hover: hover) and (pointer: fine) {
    .arb-chat__canal:hover { transform: translateY(-3px) scale(1.12) !important; box-shadow: 0 12px 26px rgba(2,19,27,.32) !important; }
    .arb-chat__canal:hover svg { animation: arbBalanceIcone .7s ease; }
    .arb-chat [data-bulle]::before { transform: translate(14px,-50%) scale(.9) !important; transition: opacity .2s ease, transform .4s cubic-bezier(.34,1.56,.64,1) !important; }
    .arb-chat [data-bulle]:hover::before { transform: translate(0,-50%) scale(1) !important; }
  }
  @keyframes arbBalanceIcone { 0%,100% { transform: none; } 25% { transform: rotate(-14deg) scale(1.1); } 55% { transform: rotate(10deg); } 80% { transform: rotate(-5deg); } }

  /* Fenêtre WhatsApp : s'ouvre depuis le bouton, puis « en train d'écrire » */
  .arb-chat .arb-chat__fenetre { transform-origin: calc(100% - 27px) calc(100% + 40px); animation: arbFenetre .55s cubic-bezier(.34,1.56,.64,1) backwards; }
  @keyframes arbFenetre { from { opacity: 0; transform: scale(.3); filter: blur(10px); } 50% { filter: blur(0); } }
  .arb-chat__fenetre .arb-chat__avatar { animation: arbPop .5s cubic-bezier(.34,1.56,.64,1) .18s backwards; }
  .arb-chat__fenetre .arb-chat__titres { animation: arbGlisse .45s cubic-bezier(.34,1.56,.64,1) .24s backwards; }
  .arb-chat__fenetre .arb-chat__envoi { animation: arbMonte .45s cubic-bezier(.2,.8,.2,1) .3s backwards; }
  @keyframes arbMonte { from { opacity: 0; transform: translateY(12px); } }
  .arb-ecrit { display: none; align-items: center; gap: 5px; padding: 13px 14px; background: #fff; border-radius: 0 10px 10px 10px; box-shadow: 0 1px 1px rgba(0,0,0,.08); animation: arbPop .35s cubic-bezier(.34,1.56,.64,1) backwards; transform-origin: top left; }
  .arb-ecrit span { width: 7px; height: 7px; border-radius: 50%; background: #9a9184; animation: arbPoint 1s ease-in-out infinite; }
  .arb-ecrit span:nth-child(2) { animation-delay: .15s; }
  .arb-ecrit span:nth-child(3) { animation-delay: .3s; }
  @keyframes arbPoint { 0%,60%,100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
  .arb-pop { animation: arbPop .45s cubic-bezier(.34,1.56,.64,1) backwards; transform-origin: top left; }
  @keyframes arbPop { from { opacity: 0; transform: translateY(8px) scale(.6); } }

  /* Bouton d'envoi */
  .arb-chat__envoyer { transition: transform .3s cubic-bezier(.34,1.56,.64,1), background-color .15s ease; }
  .arb-chat__envoyer:hover { transform: scale(1.1) rotate(-8deg); }
  .arb-chat__envoyer:active { transform: scale(.88); }
  .arb-part svg { animation: arbPart .6s cubic-bezier(.2,.8,.2,1); }
  @keyframes arbPart { 0% { transform: none; opacity: 1; } 40% { transform: translate(20px,-8px) rotate(-10deg); opacity: 0; } 41% { transform: translate(-14px,6px); opacity: 0; } 100% { transform: none; opacity: 1; } }

  /* Fermeture : le même mouvement à l'envers (classe arb-sortie, posée par chat.js pendant 280 ms) */
  .arb-sortie .arb-chat__canaux .arb-chat__rond { animation: arbRentre .26s cubic-bezier(.2,.8,.2,1) forwards !important; }
  .arb-sortie .arb-chat__canaux .arb-chat__rond:nth-child(2) { animation-delay: .05s !important; }
  @keyframes arbRentre { to { opacity: 0; transform: translateY(var(--d, 60px)) scale(.2) rotate(-60deg); filter: blur(6px); } }
  .arb-sortie .arb-chat__fenetre { animation: arbFenetreSort .25s cubic-bezier(.2,.8,.2,1) forwards !important; }
  @keyframes arbFenetreSort { to { opacity: 0; transform: scale(.4); filter: blur(8px); } }
  .arb-sortie .arb-chat__bouton .arb-chat__croix { transform: translate(-50%,-50%) rotate(-135deg) scale(.4) !important; opacity: 0 !important; }
  .arb-sortie .arb-chat__bouton .arb-chat__bulle-icone { transform: translate(-50%,-50%) rotate(0) scale(1) !important; opacity: 1 !important; }
}

@media (prefers-reduced-motion: reduce) {
  .arb-chat *, .arb-chat *::before { animation: none !important; transition: none !important; }
}
