/* ---------- Chatbot WhatsApp ---------- */

.hce-chat {
  --wa-green: #25d366;
  --wa-dark: #075e54;
  --wa-teal: #128c7e;
  --wa-bubble-out: #d9fdd3;
  --wa-bubble-in: #ffffff;
  --wa-wall: #efeae2;
  --wa-text: #111b21;
  --wa-muted: #667781;
  --wa-link: #128c7e;
  font-family: var(--font-body);
}

@media (prefers-color-scheme: dark) {
  .hce-chat {
    --wa-bubble-out: #005c4b;
    --wa-bubble-in: #202c33;
    --wa-wall: #0b141a;
    --wa-text: #e9edef;
    --wa-muted: #8696a0;
    --wa-link: #53d3c4;
  }
}

/* Bouton flottant */
.hce-chat-launcher {
  border: 0;
  cursor: pointer;
  color: #fff;
  padding: 0;
}

.hce-chat-launcher > span:not(.hce-chat-badge) {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease, opacity 0.2s ease;
}

.hce-chat-launcher-close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.hce-chat-launcher-close svg { width: 24px; height: 24px; }
.hce-chat.is-open .hce-chat-launcher-open { opacity: 0; transform: rotate(90deg); }
.hce-chat.is-open .hce-chat-launcher-close { opacity: 1; transform: rotate(0); }

.hce-chat-launcher::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--wa-green);
  z-index: -1;
  animation: hce-chat-pulse 2.4s ease-out infinite;
}

.hce-chat.is-open .hce-chat-launcher::before,
.hce-chat.is-quiet .hce-chat-launcher::before { animation: none; opacity: 0; }

.hce-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #e53935;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  border: 2px solid #fff;
}

.hce-chat-badge[hidden] { display: none; }

/* Bulle d'accroche */
.hce-chat-teaser {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 70;
  max-width: 260px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px 14px 4px 14px;
  box-shadow: var(--shadow-lg);
  padding: 14px 34px 14px 16px;
  font-size: 0.9rem;
  line-height: 1.45;
  cursor: pointer;
  animation: hce-chat-in 0.35s ease;
}

.hce-chat-teaser p { margin: 0; }

.hce-chat-teaser-close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: 0;
  background: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

/* Fenêtre de discussion */
.hce-chat-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 75;
  width: 370px;
  height: min(600px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: var(--wa-wall);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  animation: hce-chat-in 0.25s ease;
}

.hce-chat-panel[hidden],
.hce-chat-teaser[hidden] { display: none; }

.hce-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px 12px 14px;
  background: var(--wa-dark);
  color: #fff;
  flex-shrink: 0;
}

.hce-chat-avatar { position: relative; flex-shrink: 0; }

.hce-chat-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: contain;
  background: #fff;
  padding: 4px;
}

.hce-chat-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--wa-green);
  border: 2px solid var(--wa-dark);
}

.hce-chat-dot.is-away { background: #f4b400; }

.hce-chat-id { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.hce-chat-id b { font-size: 0.98rem; }
.hce-chat-id span { font-size: 0.76rem; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hce-chat-icon-btn {
  border: 0;
  background: transparent;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.85;
  flex-shrink: 0;
}

.hce-chat-icon-btn:hover { background: rgba(255, 255, 255, 0.12); opacity: 1; }
.hce-chat-icon-btn svg { width: 18px; height: 18px; }

.hce-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overscroll-behavior: contain;
}

.hce-chat-day {
  align-self: center;
  font-size: 0.72rem;
  color: var(--wa-muted);
  background: var(--wa-bubble-in);
  padding: 4px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

/* Messages */
.hce-msg {
  max-width: 86%;
  padding: 7px 10px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--wa-text);
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  white-space: pre-line;
  overflow-wrap: anywhere;
  animation: hce-chat-in 0.2s ease;
}

.hce-msg.bot { align-self: flex-start; background: var(--wa-bubble-in); border-top-left-radius: 2px; }
.hce-msg.user { align-self: flex-end; background: var(--wa-bubble-out); border-top-right-radius: 2px; }
.hce-msg b { font-weight: 700; }

.hce-msg time {
  position: absolute;
  right: 8px;
  bottom: 3px;
  font-size: 0.66rem;
  color: var(--wa-muted);
}

.hce-msg.user time::after { content: " ✓✓"; color: #53bdeb; }

.hce-msg-links { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; white-space: normal; }

.hce-msg-links a {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(18, 140, 126, 0.09);
  color: var(--wa-link);
  font-weight: 600;
  font-size: 0.84rem;
  text-decoration: none;
}

.hce-msg-links a:hover { background: rgba(18, 140, 126, 0.18); }
.hce-msg-links a.is-wa { background: var(--wa-green); color: #fff; text-align: center; }
.hce-msg-links a.is-wa:hover { background: #1ebe5b; }

.hce-typing {
  align-self: flex-start;
  background: var(--wa-bubble-in);
  border-radius: 10px;
  border-top-left-radius: 2px;
  padding: 12px 14px;
  display: flex;
  gap: 4px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.hce-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wa-muted);
  animation: hce-typing 1.2s infinite ease-in-out;
}

.hce-typing span:nth-child(2) { animation-delay: 0.15s; }
.hce-typing span:nth-child(3) { animation-delay: 0.3s; }

/* Réponses rapides */
.hce-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 12px 8px;
  flex-shrink: 0;
  max-height: 96px;
  overflow-y: auto;
}

.hce-chat-chips:empty { display: none; }

.hce-chat-chips button {
  border: 1px solid var(--wa-link);
  background: var(--wa-bubble-in);
  color: var(--wa-link);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.hce-chat-chips button:hover { background: var(--wa-link); color: var(--wa-bubble-in); }

/* Zone de saisie */
.hce-chat-form {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  background: var(--wa-wall);
  flex-shrink: 0;
}

.hce-chat-form input {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 16px; /* évite le zoom automatique sur iOS */
  font-family: inherit;
  background: var(--wa-bubble-in);
  color: var(--wa-text);
  outline: none;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.hce-chat-form input:focus { box-shadow: 0 0 0 2px var(--wa-teal); }

.hce-chat-form button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--wa-teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.hce-chat-form button:hover { background: var(--wa-dark); }
.hce-chat-form button svg { width: 20px; height: 20px; }

.hce-chat-handoff {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: var(--wa-green);
  color: #fff;
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  flex-shrink: 0;
}

.hce-chat-handoff:hover { background: #1ebe5b; color: #fff; }
.hce-chat-handoff svg { width: 18px; height: 18px; }

@keyframes hce-chat-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes hce-typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes hce-chat-pulse { 0% { transform: scale(1); opacity: 0.55; } 100% { transform: scale(1.6); opacity: 0; } }

/* Mobile : plein écran */
@media (max-width: 600px) {
  .hce-chat-panel {
    inset: 0;
    width: auto;
    height: 100%;
    border-radius: 0;
  }

  .hce-chat.is-open .hce-chat-launcher { display: none; }
  .hce-chat-teaser { right: 16px; bottom: 80px; max-width: calc(100vw - 100px); }
}

@media (prefers-reduced-motion: reduce) {
  .hce-chat-launcher::before,
  .hce-typing span,
  .hce-chat-panel,
  .hce-msg,
  .hce-chat-teaser { animation: none; }
}
