/* ============================================
   AVISPA SOLUTIONS — Chat Widget
   ============================================ */

.avispa-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Toggle button ── */
@keyframes avispa-pulse {
  0%, 100% { box-shadow: 0 4px 24px rgba(0, 0, 0, 0.28), 0 0 0 0 rgba(34, 81, 255, 0.55); }
  60%       { box-shadow: 0 4px 24px rgba(0, 0, 0, 0.28), 0 0 0 14px rgba(34, 81, 255, 0); }
}

.avispa-chat-toggle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #001f5b;
  border: 2px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.avispa-chat-widget:not(.open) .avispa-chat-toggle {
  animation: avispa-pulse 2.8s ease-in-out infinite;
}

.avispa-chat-toggle:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.38);
  animation: none;
}

.avispa-chat-toggle .icon-chat { width: 26px; height: 26px; }
.avispa-chat-toggle .icon-close { width: 24px; height: 24px; }
.avispa-chat-toggle .icon-chat,
.avispa-chat-toggle .icon-close {
  position: absolute;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.avispa-chat-toggle .icon-chat  { opacity: 1; transform: scale(1); }
.avispa-chat-toggle .icon-close { opacity: 0; transform: scale(0.7); }
.avispa-chat-widget.open .icon-chat  { opacity: 0; transform: scale(0.7); }
.avispa-chat-widget.open .icon-close { opacity: 1; transform: scale(1); }

/* Unread badge */
.avispa-chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 16px;
  height: 16px;
  background: #e53e3e;
  border-radius: 50%;
  border: 2px solid white;
  display: none;
}
.avispa-chat-badge.visible { display: block; }

/* ── Panel ── */
.avispa-chat-panel {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  height: 560px;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.avispa-chat-widget.open .avispa-chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ── */
.avispa-chat-header {
  background: #001f5b;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  flex-shrink: 0;
}
.avispa-chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.avispa-chat-header-avatar img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}
.avispa-chat-header-info {
  flex: 1;
  min-width: 0;
}
.avispa-chat-header-name {
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.avispa-chat-header-status {
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  font-weight: 400;
  margin-top: 1px;
}
.avispa-chat-header-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.avispa-chat-header-close:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}
.avispa-chat-header-close svg {
  width: 17px;
  height: 17px;
}

/* ── Messages ── */
.avispa-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f6f8fc;
  scroll-behavior: smooth;
}
.avispa-chat-messages::-webkit-scrollbar { width: 4px; }
.avispa-chat-messages::-webkit-scrollbar-track { background: transparent; }
.avispa-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.13);
  border-radius: 2px;
}

.avispa-message {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: avispa-msg-in 0.18s ease;
}
@keyframes avispa-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.avispa-message--bot  { align-self: flex-start; }
.avispa-message--user { align-self: flex-end; }

.avispa-message-bubble {
  padding: 9px 13px;
  border-radius: 13px;
  font-size: 13.5px;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
}
.avispa-message--bot .avispa-message-bubble {
  background: #ffffff;
  color: #1a2340;
  border: 1px solid #e2e8f4;
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.avispa-message--user .avispa-message-bubble {
  background: #001f5b;
  color: #ffffff;
  border-bottom-right-radius: 3px;
}

/* Consultation CTA appended to a bot message */
.avispa-chat-cta {
  margin-top: 8px;
}
.avispa-chat-cta a {
  display: inline-block;
  background: #001f5b;
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 7px;
  text-decoration: none;
  letter-spacing: 0.01em;
  transition: background 0.15s;
}
.avispa-chat-cta a:hover { background: #002d85; }

/* ── Typing indicator ── */
.avispa-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid #e2e8f4;
  border-radius: 13px;
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  animation: avispa-msg-in 0.18s ease;
}
.avispa-typing span {
  width: 6px;
  height: 6px;
  background: #001f5b;
  border-radius: 50%;
  opacity: 0.35;
  animation: avispa-dot 1.3s infinite;
}
.avispa-typing span:nth-child(2) { animation-delay: 0.18s; }
.avispa-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes avispa-dot {
  0%, 55%, 100% { opacity: 0.35; transform: translateY(0); }
  27%            { opacity: 1;    transform: translateY(-3px); }
}

/* ── Input area ── */
.avispa-chat-input-area {
  padding: 10px 12px;
  border-top: 1px solid #e8edf6;
  background: #ffffff;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.avispa-chat-input {
  flex: 1;
  border: 1px solid #d4dbed !important;
  border-radius: 9px;
  padding: 8px 11px;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 108px;
  color: #1a2340 !important;
  background: #f6f8fc !important;
  transition: border-color 0.15s, background 0.15s;
  overflow-y: auto;
}
.avispa-chat-input:focus {
  border-color: #001f5b !important;
  background: #ffffff !important;
  color: #1a2340 !important;
}
.avispa-chat-input::placeholder { color: #9daabf !important; }

.avispa-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: #001f5b;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  transition: background 0.15s, opacity 0.15s;
}
.avispa-chat-send:hover:not(:disabled) { background: #002d85; }
.avispa-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.avispa-chat-send svg {
  width: 15px;
  height: 15px;
  fill: #ffffff;
}

/* ── Footer ── */
.avispa-chat-footer {
  text-align: center;
  padding: 5px 14px 7px;
  font-size: 10px;
  color: #a0aec0;
  background: #ffffff;
  border-top: 1px solid #f0f3f9;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .avispa-chat-widget {
    bottom: 16px;
    right: 16px;
  }
  .avispa-chat-panel {
    width: calc(100vw - 32px);
    height: calc(100dvh - 108px);
    bottom: 80px;
    right: 0;
  }
}
