/* ESIC Chatbot — floating widget */

.esic-chatbot {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* ============ Bubble (closed state) ============ */
.esic-chatbot__bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #1A2C75 0%, #1F8FB0 50%, #5BD3A8 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(91, 211, 168, 0.45);
  transition: transform 0.25s, box-shadow 0.25s;
  position: relative;
  z-index: 2;
}
.esic-chatbot__bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 40px rgba(91, 211, 168, 0.55);
}
.esic-chatbot__bubble.is-open {
  background: #1e293b;
  transform: rotate(180deg) scale(0.9);
}
.esic-chatbot__bubble.is-open svg {
  transform: rotate(180deg);
}

.esic-chatbot__bubble-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #1A2C75, #5BD3A8);
  z-index: -1;
  animation: esic-chat-pulse 2.4s infinite;
  opacity: 0.5;
}
@keyframes esic-chat-pulse {
  0%   { transform: scale(1); opacity: 0.5; }
  70%  { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}
.esic-chatbot__bubble.is-open + .esic-chatbot__bubble-pulse,
.esic-chatbot__bubble.is-open ~ .esic-chatbot__bubble-pulse {
  display: none;
}

/* ============ Panel (open state) ============ */
.esic-chatbot__panel {
  position: absolute;
  bottom: 78px;
  right: 0;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 120px));
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 24px 64px -16px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  animation: esic-chat-slideup 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
/* Override : display:flex casse le [hidden] natif → on force la fermeture */
.esic-chatbot__panel[hidden] { display: none !important; }
@keyframes esic-chat-slideup {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ Header ============ */
.esic-chatbot__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #3FA682 100%);
  color: white;
  flex-shrink: 0;
}
.esic-chatbot__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.esic-chatbot__title {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.esic-chatbot__title strong {
  font-size: 0.95rem;
  font-weight: 700;
}
.esic-chatbot__title small {
  font-size: 0.72rem;
  opacity: 0.75;
  margin-top: 2px;
}
.esic-chatbot__close,
.esic-chatbot__clear {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.esic-chatbot__close:hover,
.esic-chatbot__clear:hover { background: rgba(255, 255, 255, 0.2); }
.esic-chatbot__clear { margin-right: 4px; }

/* ============ Messages ============ */
.esic-chatbot__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: #f8fafc;
}
.esic-chatbot__messages::-webkit-scrollbar { width: 6px; }
.esic-chatbot__messages::-webkit-scrollbar-track { background: transparent; }
.esic-chatbot__messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.esic-chatbot__msg {
  max-width: 86%;
  padding: 0.7rem 0.95rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  animation: esic-chat-pop 0.2s ease-out;
}
@keyframes esic-chat-pop {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.esic-chatbot__msg--bot {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  color: #0f172a;
  border-bottom-left-radius: 4px;
}
.esic-chatbot__msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1A2C75, #1F8FB0);
  color: white;
  border-bottom-right-radius: 4px;
}
.esic-chatbot__msg a {
  color: #5BD3A8;
  font-weight: 600;
  text-decoration: underline;
}
.esic-chatbot__msg--user a {
  color: #ffffff;
  text-decoration: underline;
}
.esic-chatbot__msg code {
  background: rgba(91, 211, 168, 0.1);
  color: #3FA682;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: ui-monospace, monospace;
}
.esic-chatbot__msg ul {
  margin: 0.4em 0;
  padding-left: 1.2em;
}
.esic-chatbot__msg ul li { margin: 0.2em 0; }

/* Typing indicator */
.esic-chatbot__msg--typing { padding: 0.85rem 1rem; }
.esic-chatbot__dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.esic-chatbot__dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: esic-chat-bounce 1.2s infinite ease-in-out;
}
.esic-chatbot__dots span:nth-child(2) { animation-delay: 0.2s; }
.esic-chatbot__dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes esic-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============ Input form ============ */
.esic-chatbot__form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 0.85rem 0.5rem;
  border-top: 1px solid #e2e8f0;
  background: #ffffff;
  flex-shrink: 0;
}
.esic-chatbot__form input {
  flex: 1;
  padding: 0.65rem 1rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 999px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.esic-chatbot__form input:focus { border-color: #5BD3A8; }
.esic-chatbot__send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #1A2C75, #1F8FB0);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}
.esic-chatbot__send:hover { transform: scale(1.05); }
.esic-chatbot__send:active { transform: scale(0.95); }

.esic-chatbot__footer {
  font-size: 0.7rem;
  color: #94a3b8;
  text-align: center;
  margin: 0;
  padding: 0 0.85rem 0.7rem;
  background: #ffffff;
  flex-shrink: 0;
}
.esic-chatbot__footer a {
  color: #5BD3A8;
  font-weight: 600;
}

/* ============ Quick replies ============ */
.esic-chatbot__quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0;
  padding: 0 0.25rem;
}
.esic-chatbot__qr {
  background: #fff;
  border: 1.5px solid #E2E8F0;
  color: #3FA682;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
  text-align: left;
  line-height: 1.3;
}
.esic-chatbot__qr:hover {
  background: linear-gradient(135deg, #1A2C75, #1F8FB0);
  color: #fff;
  border-color: transparent;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(91, 211, 168, 0.25);
}

/* ============ Tool indicator ============ */
.esic-chatbot__tool-indicator {
  align-self: flex-start;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.82rem;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px dashed #5BD3A8;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-style: italic;
  animation: esic-chat-pop 0.2s ease-out;
}

/* ============ Lead capture form ============ */
.esic-chatbot__lead-form {
  align-self: stretch;
  background: linear-gradient(135deg, #F8FAFC 0%, #F8FAFC 100%);
  border: 1.5px solid #8AE3C2;
  border-radius: 14px;
  padding: 1rem;
  margin: 0.5rem 0;
  animation: esic-chat-pop 0.3s ease-out;
}
.esic-chatbot__lead-form h4 {
  margin: 0 0 0.4rem;
  color: #3FA682;
  font-size: 1rem;
  font-weight: 700;
}
.esic-chatbot__lead-form p {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: #475569;
}
.esic-chatbot__lead-form input {
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.88rem;
  outline: none;
  font-family: inherit;
  box-sizing: border-box;
}
.esic-chatbot__lead-form input:focus { border-color: #5BD3A8; }
.esic-chatbot__lead-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.esic-chatbot__lead-cancel {
  flex: 0 0 auto;
  background: transparent;
  border: 1.5px solid #cbd5e1;
  color: #64748b;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
.esic-chatbot__lead-cancel:hover { background: #f1f5f9; }
.esic-chatbot__lead-submit {
  flex: 1;
  background: linear-gradient(135deg, #1A2C75, #1F8FB0, #5BD3A8);
  border: none;
  color: white;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s;
}
.esic-chatbot__lead-submit:hover { transform: translateY(-1px); }
.esic-chatbot__lead-success {
  text-align: center;
  padding: 1rem;
  color: #065f46;
  background: #d1fae5;
  border-radius: 8px;
  font-weight: 500;
}

/* ============ Responsive ============ */
@media (max-width: 640px) {
  .esic-chatbot { bottom: 16px; right: 16px; }
  .esic-chatbot__panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
    bottom: 76px;
  }
  /* Avoid clash with sticky mobile bar */
  body.has-sticky-bar .esic-chatbot { bottom: 80px; }
}

/* ─── RGPD checkbox + erreur form (depuis chatbot v1.3.0) ─── */
.esic-chatbot__rgpd {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  font-size: .78rem;
  color: #475569;
  line-height: 1.4;
  margin: .25rem 0;
  cursor: pointer;
}
.esic-chatbot__rgpd input[type="checkbox"] {
  margin-top: 2px;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  accent-color: #1A2C75;
  cursor: pointer;
}
.esic-chatbot__lead-error {
  padding: .5rem .75rem;
  background: #FEF2F2;
  border: 1px solid #FCA5A5;
  border-radius: 6px;
  color: #B91C1C;
  font-size: .82rem;
  font-weight: 500;
}
.esic-chatbot__lead-form {
  position: relative;
}
.esic-chatbot__lead-submit:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none !important;
}

/* ============================================================
 * Avatar Haci (image PNG) — bulle flottante + header chat
 * ============================================================ */

/* ─── Bulle flottante avec photo Haci ─── */
.esic-chatbot__bubble--avatar {
  background: #fff !important;
  padding: 0;
  overflow: hidden;
  border: 3px solid #fff;
  box-shadow: 0 8px 32px rgba(26, 44, 117, 0.35);
}
.esic-chatbot__bubble--avatar:hover {
  border-color: #5BD3A8;
}
.esic-chatbot__bubble-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
/* Petit badge "💬" en bas-droite de la bulle */
.esic-chatbot__bubble-badge {
  position: absolute;
  bottom: -3px;
  right: -3px;
  width: 24px;
  height: 24px;
  background: linear-gradient(135deg, #1A2C75 0%, #5BD3A8 100%);
  border: 2px solid #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  z-index: 3;
  line-height: 1;
}
/* Quand panel ouvert, on remplace l'image par une croix (X) */
.esic-chatbot__bubble--avatar.is-open {
  background: #1e293b !important;
  transform: rotate(0) scale(0.95);
  border-color: #1e293b;
}
.esic-chatbot__bubble--avatar.is-open .esic-chatbot__bubble-img,
.esic-chatbot__bubble--avatar.is-open .esic-chatbot__bubble-badge {
  display: none;
}
.esic-chatbot__bubble--avatar.is-open::before {
  content: "✕";
  color: #fff;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1;
}

/* ─── Avatar dans le header (image au lieu de l'emoji) ─── */
.esic-chatbot__avatar--img {
  background: rgba(255,255,255,0.1);
  padding: 0;
  position: relative;
  overflow: visible;
  border: 2px solid rgba(255,255,255,0.4);
}
.esic-chatbot__avatar--img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.esic-chatbot__avatar-status {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  background: #5BD3A8;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(91, 211, 168, 0.6);
}
.esic-chatbot__avatar-status::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: #5BD3A8;
  opacity: .4;
  animation: esic-haci-pulse 2s ease-out infinite;
  z-index: -1;
}
@keyframes esic-haci-pulse {
  0%   { transform: scale(1);   opacity: .5; }
  100% { transform: scale(2.2); opacity: 0;  }
}
