/* ============================================================
   NEXA CHAT WIDGET — Identité éditoriale (crème + corail)
   Cohérent avec le design actuel de nexaservices.fr
   À inclure après le CSS principal du site.
   ============================================================ */

:root {
  /* Palette du widget — si tes variables principales existent déjà
     dans style.css avec d'autres noms, ces fallbacks prennent le relais. */
  --nexa-chat-cream:        var(--color-bg, #f8f2e4);
  --nexa-chat-cream-deep:   var(--color-bg-deep, #f1e9d6);
  --nexa-chat-ink:          var(--color-text, #1a1a1a);
  --nexa-chat-ink-muted:    var(--color-text-muted, #6b6357);
  --nexa-chat-coral:        var(--color-accent, #ef5440);
  --nexa-chat-coral-deep:   var(--color-accent-hover, #d83e2c);
  --nexa-chat-border:       var(--color-border, rgba(26, 26, 26, 0.12));
  --nexa-chat-border-soft:  rgba(26, 26, 26, 0.06);
  --nexa-chat-paper:        #fefcf6;
  --nexa-chat-shadow:
    0 1px 0 rgba(26, 26, 26, 0.04),
    0 18px 40px -12px rgba(26, 26, 26, 0.18),
    0 2px 8px -2px rgba(26, 26, 26, 0.06);
}

/* --- Bouton flottant (lanceur) ---------------------------------- */
.nexa-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--nexa-chat-ink);
  border: none;
  cursor: pointer;
  box-shadow:
    0 1px 0 rgba(26, 26, 26, 0.4),
    0 14px 30px -8px rgba(26, 26, 26, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--nexa-chat-cream);
  z-index: 9998;
  transition:
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.3s ease,
    background 0.2s ease,
    opacity 0.4s ease;
}
/* État initial avant apparition (opacity 0 → transition vers 1 au retrait de la classe) */
.nexa-chat-launcher--appearing {
  opacity: 0;
  transform: scale(0.4) translateY(20px);
}

/* Fond corail quand le panel est ouvert (indique visuellement "cliquer pour fermer") */
.nexa-chat-launcher[aria-expanded="true"] {
  background: var(--nexa-chat-coral);
}
.nexa-chat-launcher[aria-expanded="true"]:hover {
  background: var(--nexa-chat-coral-deep);
}

.nexa-chat-launcher:hover {
  transform: translateY(-3px) rotate(-4deg);
  background: var(--nexa-chat-coral);
  box-shadow:
    0 1px 0 rgba(26, 26, 26, 0.4),
    0 20px 36px -8px rgba(239, 84, 64, 0.55),
    0 0 0 8px rgba(239, 84, 64, 0.1);
}
.nexa-chat-launcher:focus-visible {
  outline: 2px solid var(--nexa-chat-coral);
  outline-offset: 4px;
}
.nexa-chat-launcher svg { width: 26px; height: 26px; }
.nexa-chat-launcher[aria-expanded="true"] .nexa-chat-icon-open { display: none; }
.nexa-chat-launcher[aria-expanded="false"] .nexa-chat-icon-close { display: none; }

/* Pulse discret au chargement, joue 2 fois puis stop */
.nexa-chat-launcher::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--nexa-chat-coral);
  opacity: 0;
  animation: nexa-pulse 2.4s ease-out 1.8s 2;
  pointer-events: none;
}
@keyframes nexa-pulse {
  0%   { transform: scale(0.9); opacity: 0.55; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* --- Panneau de chat -------------------------------------------- */
.nexa-chat-panel {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 140px);
  background: var(--nexa-chat-paper);
  border: 1px solid var(--nexa-chat-border-soft);
  border-radius: 20px;
  box-shadow: var(--nexa-chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--nexa-chat-ink);
}
.nexa-chat-panel[data-open="true"] {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header : touche éditoriale avec serif italique corail sur l'accent */
.nexa-chat-header {
  padding: 20px 22px 18px;
  border-bottom: 1px solid var(--nexa-chat-border-soft);
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(239, 84, 64, 0.06), transparent 60%),
    var(--nexa-chat-cream);
  position: relative;
}
.nexa-chat-header::after {
  content: "";
  position: absolute;
  left: 22px; right: 22px; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--nexa-chat-coral) 0%, transparent 40%);
  opacity: 0.5;
}
.nexa-chat-header h3 {
  margin: 0;
  font-family: 'Fraunces', 'Playfair Display', Georgia, serif;
  font-weight: 500;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  font-variation-settings: "opsz" 36, "SOFT" 50;
}
.nexa-chat-header h3 em {
  font-style: italic;
  color: var(--nexa-chat-coral);
  font-weight: 500;
}
.nexa-chat-header p {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--nexa-chat-ink-muted);
  display: flex;
  align-items: center;
  gap: 7px;
  letter-spacing: 0.01em;
}
.nexa-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2da567;
  box-shadow: 0 0 0 3px rgba(45, 165, 103, 0.18);
}

/* Zone des messages */
.nexa-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--nexa-chat-paper);
  scrollbar-width: thin;
  scrollbar-color: var(--nexa-chat-border) transparent;
}
.nexa-chat-messages::-webkit-scrollbar { width: 6px; }
.nexa-chat-messages::-webkit-scrollbar-thumb {
  background: var(--nexa-chat-border);
  border-radius: 3px;
}

.nexa-msg {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: nexa-msg-in 0.25s ease-out;
}
@keyframes nexa-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.nexa-msg--bot {
  background: var(--nexa-chat-cream-deep);
  color: var(--nexa-chat-ink);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}
.nexa-msg--user {
  background: var(--nexa-chat-coral);
  color: #fefcf6;
  align-self: flex-end;
  border-bottom-right-radius: 5px;
}
.nexa-msg--error {
  background: rgba(217, 62, 44, 0.08);
  border: 1px solid rgba(217, 62, 44, 0.22);
  color: var(--nexa-chat-coral-deep);
  align-self: flex-start;
  font-size: 13px;
}

/* Indicateur de frappe */
.nexa-typing {
  display: flex;
  gap: 5px;
  padding: 13px 16px;
  background: var(--nexa-chat-cream-deep);
  border-radius: 16px;
  border-bottom-left-radius: 5px;
  align-self: flex-start;
  width: fit-content;
}
.nexa-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--nexa-chat-ink-muted);
  animation: nexa-bounce 1.3s ease-in-out infinite;
}
.nexa-typing span:nth-child(2) { animation-delay: 0.15s; }
.nexa-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes nexa-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* Zone de saisie */
.nexa-chat-input {
  padding: 14px;
  border-top: 1px solid var(--nexa-chat-border-soft);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--nexa-chat-cream);
}
.nexa-chat-input textarea {
  flex: 1;
  background: var(--nexa-chat-paper);
  border: 1px solid var(--nexa-chat-border);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--nexa-chat-ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  resize: none;
  max-height: 100px;
  min-height: 42px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.nexa-chat-input textarea:focus {
  outline: none;
  border-color: var(--nexa-chat-coral);
  box-shadow: 0 0 0 3px rgba(239, 84, 64, 0.15);
}
.nexa-chat-input textarea::placeholder {
  color: var(--nexa-chat-ink-muted);
  font-style: italic;
}

.nexa-chat-send {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--nexa-chat-ink);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--nexa-chat-cream);
  transition: background 0.18s ease, transform 0.18s ease;
  flex-shrink: 0;
}
.nexa-chat-send:hover:not(:disabled) {
  background: var(--nexa-chat-coral);
  transform: translateY(-1px);
}
.nexa-chat-send:focus-visible {
  outline: 2px solid var(--nexa-chat-coral);
  outline-offset: 2px;
}
.nexa-chat-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.nexa-chat-send svg { width: 18px; height: 18px; }

/* Mention discrète RGPD */
.nexa-chat-footer {
  padding: 10px 14px 12px;
  font-size: 10px;
  letter-spacing: 0.02em;
  color: var(--nexa-chat-ink-muted);
  text-align: center;
  background: var(--nexa-chat-cream);
  border-top: 1px solid var(--nexa-chat-border-soft);
}
.nexa-chat-footer a {
  color: var(--nexa-chat-ink-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.nexa-chat-footer a:hover {
  color: var(--nexa-chat-coral);
}

/* Honeypot anti-bot — invisible mais présent dans le DOM */
.nexa-chat-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Responsive mobile */
@media (max-width: 480px) {
  .nexa-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 88px;
    height: calc(100vh - 108px);
    border-radius: 18px;
  }
  .nexa-chat-launcher {
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
  }
  .nexa-chat-header h3 { font-size: 18px; }
}

/* Markdown rendu dans les bulles */
.nexa-msg strong { font-weight: 600; }
.nexa-msg em { font-style: italic; }
.nexa-msg code {
  background: rgba(26, 26, 26, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.92em;
}
.nexa-msg--user code { background: rgba(255, 255, 255, 0.2); }

/* Respect du prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .nexa-chat-launcher,
  .nexa-chat-panel,
  .nexa-msg,
  .nexa-chat-send,
  .nexa-typing span,
  .nexa-chat-launcher::before {
    animation: none !important;
    transition: none !important;
  }
}
