/* ==========================================================================
   IT LAND — Chat visiteur
   S'appuie sur les tokens de theme.css (--primary, --surface, --border…).
   Aucune couleur en dur qui ne soit deja dans la charte.
   ========================================================================== */

#chat-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 880;          /* sous l'en-tete (900) : il ne doit jamais le recouvrir */
  font-family: var(--font-body, system-ui, sans-serif);
}

/* ------------------------------------------------------------- Lanceur */
.chat-lanceur {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 13px 20px;
  border: 0;
  border-radius: var(--r-pill, 999px);
  background: var(--grad-primary, linear-gradient(135deg, #0d96d2, #37a9e1));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-primary, 0 10px 26px rgba(13, 150, 210, .28));
  transition: transform var(--t, .22s), box-shadow var(--t, .22s);
}
.chat-lanceur:hover { transform: translateY(-2px); }
.chat-lanceur:focus-visible { outline: 3px solid var(--primary-300, #6ec8f2); outline-offset: 3px; }
.chat-lanceur .chat-ico-fermer { display: none; }

#chat-widget.est-ouvert .chat-lanceur { padding: 13px; }
#chat-widget.est-ouvert .chat-lanceur-txt { display: none; }
#chat-widget.est-ouvert .chat-ico-ouvrir { display: none; }
#chat-widget.est-ouvert .chat-ico-fermer { display: block; }

/* Pastille de message non lu */
.chat-pastille {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--danger, #dc2626);
  border: 2px solid #fff;
}
.chat-lanceur { position: relative; }

/* ------------------------------------------------------------- Panneau */
.chat-panneau {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  width: min(370px, calc(100vw - 40px));
  max-height: min(560px, calc(100dvh - 130px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e9f2);
  border-radius: var(--r-lg, 18px);
  box-shadow: var(--shadow-lg, 0 18px 46px rgba(13, 150, 210, .12));
}
.chat-panneau[hidden] { display: none; }

.chat-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  background: var(--grad-primary, linear-gradient(135deg, #0d96d2, #37a9e1));
  color: #fff;
}
.chat-entete strong { display: block; font-size: 15.5px; }
.chat-sous-titre { display: block; font-size: 12.5px; opacity: .92; margin-top: 2px; }
.chat-reduire {
  background: rgba(255, 255, 255, .18);
  border: 0;
  border-radius: 8px;
  color: #fff;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-reduire:hover { background: rgba(255, 255, 255, .3); }

/* ------------------------------------------------------------- Fil */
.chat-fil {
  flex: 1;
  min-height: 150px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: var(--bg, #f4f8fc);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bulle {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  /* Le corps est insere en texte : ces deux regles evitent qu'une longue URL
     collee par un visiteur ne fasse deborder le panneau. */
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.chat-bulle.de-visiteur {
  align-self: flex-end;
  background: var(--primary, #0d96d2);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.chat-bulle.de-admin,
.chat-bulle.de-systeme {
  align-self: flex-start;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e9f2);
  color: var(--text, #243244);
  border-bottom-left-radius: 5px;
}
.chat-bulle.de-systeme {
  background: var(--primary-050, #e7f5fc);
  border-color: transparent;
  color: var(--muted, #5a6879);
  font-size: 13.5px;
  align-self: stretch;
  max-width: 100%;
}
.chat-meta {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  opacity: .72;
}

/* ------------------------------------------------------------- Saisie */
.chat-form {
  border-top: 1px solid var(--border, #e2e9f2);
  padding: 12px;
  background: var(--surface, #fff);
}
.chat-identite { display: flex; flex-direction: column; gap: 7px; margin-bottom: 9px; }
.chat-champ,
.chat-zone {
  width: 100%;
  border: 1px solid var(--border, #e2e9f2);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text, #243244);
  background: var(--surface, #fff);
}
.chat-champ:focus,
.chat-zone:focus { outline: 2px solid var(--primary-300, #6ec8f2); outline-offset: 1px; }

.chat-saisie { display: flex; align-items: flex-end; gap: 8px; }
.chat-zone { resize: none; max-height: 120px; line-height: 1.45; }
.chat-envoyer {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: var(--primary, #0d96d2);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.chat-envoyer:hover { background: var(--primary-600, #007daf); }
.chat-envoyer:disabled { opacity: .5; cursor: not-allowed; }

.chat-erreur {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--danger, #dc2626);
}

/* Piege a robots : hors ecran, jamais masque par display:none (certains
   robots ignorent les champs ainsi caches). */
.chat-pot-de-miel {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ------------------------------------------------------------- Mobile */
@media (max-width: 560px) {
  #chat-widget { right: 12px; bottom: 12px; }
  .chat-panneau {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 110px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-lanceur { transition: none; }
  .chat-lanceur:hover { transform: none; }
}

/* ------------------------------------------------- Notifications (visiteur) */
.chat-entete-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.chat-son {
  background: rgba(255, 255, 255, .18);
  border: 0;
  border-radius: 8px;
  color: #fff;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.chat-son:hover { background: rgba(255, 255, 255, .3); }
.chat-son:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Une seule des deux icones est visible : l'etat se lit sans texte. */
.chat-son .chat-ico-muet { display: none; }
#chat-widget.est-muet .chat-son .chat-ico-son { display: none; }
#chat-widget.est-muet .chat-son .chat-ico-muet { display: block; }
#chat-widget.est-muet .chat-son { opacity: .72; }
