/* ============================================
   CHATBOT — Widget de Asistente Al Peso
   ============================================ */

/* === Toggle Button === */
.chatbot-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  border: 2px solid rgba(var(--color-primary-rgb), 0.5);
  cursor: pointer;
  z-index: var(--z-chatbot);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-bg);
  box-shadow: 0 4px 25px rgba(var(--color-primary-rgb), 0.5);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  animation: chatbotPulse 2.5s ease-in-out infinite;
}

.chatbot-toggle::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(var(--color-primary-rgb), 0.3);
  animation: chatbotRing 2.5s ease-in-out infinite;
}

.chatbot-toggle:hover {
  transform: scale(1.12);
  box-shadow: 0 6px 35px rgba(var(--color-primary-rgb), 0.6);
  animation: none;
}

.chatbot-toggle:hover::after {
  animation: none;
  opacity: 0;
}

.chatbot-toggle.open {
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  animation: none;
  border-color: var(--color-border);
}

.chatbot-toggle.open::after {
  display: none;
}

/* Tooltip bubble */
.chatbot-toggle__tooltip {
  position: absolute;
  right: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-family: var(--font-body);
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  animation: tooltipAppear 0.5s 4s ease forwards;
}

.chatbot-toggle__tooltip::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  border-top: 1px solid var(--color-border);
}

.chatbot-toggle.open .chatbot-toggle__tooltip {
  display: none;
}

@keyframes tooltipAppear {
  from { opacity: 0; transform: translateY(-50%) translateX(8px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

@keyframes chatbotPulse {
  0%, 100% { box-shadow: 0 4px 25px rgba(var(--color-primary-rgb), 0.4); }
  50% { box-shadow: 0 4px 35px rgba(var(--color-primary-rgb), 0.7); }
}

@keyframes chatbotRing {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 0; }
}

.chatbot-toggle__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 22px;
  height: 22px;
  background: #ff3b30;
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 50%;
  border: 2px solid var(--color-bg);
  display: none;
  align-items: center;
  justify-content: center;
  animation: pulseGlow 2s infinite;
}

/* === Chat Window === */
.chatbot-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-xl);
  z-index: var(--z-chatbot);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);

  /* Hidden by default */
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.chatbot-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* === Header === */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-subtle);
}

.chatbot-header__info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot-header__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-body);
}

.chatbot-header__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.chatbot-header__status {
  font-size: 11px;
  color: #25D366;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chatbot-header__status::before {
  content: '';
  width: 6px;
  height: 6px;
  background: #25D366;
  border-radius: 50%;
}

.chatbot-header__close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

.chatbot-header__close:hover {
  color: var(--color-text);
}

/* === Messages === */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(var(--color-primary-rgb), 0.2);
  border-radius: 4px;
}

.chatbot-msg {
  display: flex;
  animation: msgAppear 0.3s ease-out;
}

.chatbot-msg--bot {
  justify-content: flex-start;
}

.chatbot-msg--user {
  justify-content: flex-end;
}

.chatbot-msg__bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
}

.chatbot-msg--bot .chatbot-msg__bubble {
  background: var(--color-surface);
  color: var(--color-text);
  border-bottom-left-radius: 4px;
}

.chatbot-msg--user .chatbot-msg__bubble {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: var(--color-bg);
  border-bottom-right-radius: 4px;
}

.chatbot-msg__bubble a {
  color: var(--color-primary-light);
  text-decoration: underline;
}

.chatbot-msg--user .chatbot-msg__bubble a {
  color: var(--color-bg);
}

.chatbot-msg__bubble strong {
  font-weight: 600;
}

/* Typing dots */
.chatbot-msg--typing .chatbot-msg__bubble {
  padding: 10px 18px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  font-size: 20px;
  line-height: 1;
  color: var(--color-primary);
  animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

@keyframes msgAppear {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Options === */
.chatbot-options {
  padding: 0 16px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chatbot-option {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  color: var(--color-primary);
  font-size: 12.5px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.chatbot-option:hover {
  background: rgba(var(--color-primary-rgb), 0.1);
  border-color: var(--color-primary);
  transform: translateY(-1px);
}

/* === Input Area === */
.chatbot-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
}

.chatbot-input {
  flex: 1;
  background: var(--color-bg);
  border: 1px solid var(--color-border-subtle);
  border-radius: 20px;
  padding: 8px 16px;
  color: var(--color-text);
  font-size: 13px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s;
}

.chatbot-input:focus {
  border-color: var(--color-primary);
}

.chatbot-input::placeholder {
  color: var(--color-text-dim);
}

.chatbot-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  border: none;
  color: var(--color-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.chatbot-send:hover {
  transform: scale(1.08);
}

/* === Mobile === */
@media (max-width: 480px) {
  .chatbot-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .chatbot-toggle {
    bottom: 16px;
    right: 16px;
  }

  .whatsapp-float {
    bottom: 90px !important;
    right: 16px !important;
  }
}

/* === Adjust WhatsApp button when chatbot exists === */
.whatsapp-float {
  bottom: 96px;
}
