/* =========================================================================
   CHATBOT WIDGET - Rediseño Premium NovaTrack
   ========================================================================= */

/* Botón flotante (FAB) */
.chatbot-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #0A1628;
  color: #fff;
  border: 3px solid #01BBF8;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(1, 187, 248, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  z-index: 10000;
  animation: fabPulse 3s ease-in-out infinite;
  overflow: hidden;
  padding: 0;
}
.chatbot-fab img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@keyframes fabPulse {
  0%, 100% { box-shadow: 0 8px 25px rgba(1, 187, 248, 0.3); }
  50% { box-shadow: 0 8px 35px rgba(1, 187, 248, 0.5); }
}

.chatbot-fab:hover {
  transform: scale(1.1) translateY(-3px);
  box-shadow: 0 12px 30px rgba(1, 187, 248, 0.4);
  animation: none;
}

body.nt-chat-open .chatbot-fab {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

#scroll-top.scroll-top {
  display: none !important;
}

/* Contenedor del Chat */
.chatbot-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background-color: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(10, 22, 40, 0.15), 0 0 0 1px rgba(1, 187, 248, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.96);
  transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  z-index: 1000;
}

.chatbot-widget.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Cabecera del Chat · agente humano */
.chatbot-header {
  background: linear-gradient(135deg, #0A1628 0%, #142850 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(1, 187, 248, 0.2);
  gap: 10px;
  flex-shrink: 0;
}

.chatbot-agent {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chatbot-agent-photo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #01BBF8;
  box-shadow: 0 0 0 3px rgba(1, 187, 248, 0.2);
  flex-shrink: 0;
  background: #111;
}

.chatbot-agent-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.chatbot-agent-meta strong {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.chatbot-agent-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: #e8eef8;
  font-weight: 500;
}

.chatbot-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
  display: inline-block;
  flex-shrink: 0;
}

.chatbot-title {
  font-weight: 600;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Outfit', sans-serif;
}

.chatbot-title i {
  color: #01BBF8;
  font-size: 1.2rem;
}

.chatbot-close {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.chatbot-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Área de Mensajes */
.chatbot-messages {
  flex: 1;
  min-height: 0;
  padding: 12px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, #F8FAFC 0%, #FFFFFF 100%);
  -webkit-overflow-scrolling: touch;
}

/* Scrollbar personalizado */
.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: fadeInMsg 0.3s ease forwards;
}

.msg-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #0A1628;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid #01BBF8;
}
.msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.msg-bot, .msg-user {
  max-width: 78%;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.35;
  font-weight: 400;
}

.msg-bot {
  background-color: #ffffff;
  color: #111111;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(10, 22, 40, 0.06);
  border: 1px solid #E2E8F0;
}

.msg-user {
  background: linear-gradient(135deg, #01BBF8, #0098CC);
  color: #ffffff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(1, 187, 248, 0.2);
}

/* Inputs y Botón de enviar */
.chatbot-input {
  display: flex;
  padding: 14px 16px;
  background-color: #fff;
  border-top: 1px solid #E2E8F0;
  gap: 10px;
  flex-shrink: 0;
  align-items: center;
}

.chatbot-input input,
.chatbot-input textarea {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid #CBD5E1;
  border-radius: 24px;
  outline: none;
  font-size: 16px; /* evita zoom iOS al enfocar */
  font-family: 'Inter', sans-serif;
  transition: border-color 0.2s, box-shadow 0.2s;
  color: #1e293b;
  background: #F8FAFC;
}

.chatbot-input textarea {
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.35;
  border-radius: 18px;
  overflow-y: auto;
}

.chatbot-input input::placeholder,
.chatbot-input textarea::placeholder {
  color: #94A3B8;
}

.chatbot-input input:focus,
.chatbot-input textarea:focus {
  border-color: #01BBF8;
  box-shadow: 0 0 0 3px rgba(1, 187, 248, 0.1);
  background: #FFFFFF;
}

.chatbot-input button {
  background: linear-gradient(135deg, #01BBF8, #0098CC);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.chatbot-input button:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(1, 187, 248, 0.3);
}

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

/* Indicador de escribiendo... */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 5px 10px;
  align-items: center;
  background-color: transparent;
  box-shadow: none;
  border: none;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: linear-gradient(135deg, #01BBF8, #0098CC);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Responsive chatbot — tamaño fijo (no se agranda al abrir el teclado) */
@media (max-width: 640px) {
  .chatbot-widget {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 12px;
    width: auto;
    max-width: none;
    /* svh = viewport estable; el teclado NO debe redimensionar el chat */
    height: 420px;
    max-height: min(420px, calc(100svh - 24px));
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(10, 22, 40, 0.28);
  }

  body.nt-chat-open {
    overflow: hidden;
  }

  .chatbot-fab {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: calc(14px + env(safe-area-inset-right, 0px));
    width: 56px;
    height: 56px;
  }

  .chatbot-header {
    padding-top: 12px;
  }

  .chatbot-input {
    padding: 10px 12px;
    padding-bottom: 10px;
  }

  .chatbot-input button {
    flex-shrink: 0;
  }

  .chat-chips {
    width: 100%;
    max-width: none;
    padding-left: 40px;
  }

  .chat-lead-form {
    padding-left: 0;
  }

  .nt-lead-card {
    width: calc(100vw - 24px);
    max-height: calc(100svh - 24px);
    overflow: auto;
    padding: 20px 14px 16px;
  }
}

@media (max-width: 480px) {
  .chatbot-widget {
    left: 8px;
    right: 8px;
    bottom: 10px;
    height: 390px;
    max-height: min(390px, calc(100svh - 20px));
  }

  .chatbot-fab {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    width: 54px;
    height: 54px;
  }
}

.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: calc(100% - 36px);
  max-width: 280px;
  padding: 0 0 2px 36px;
  align-self: flex-start;
}

.chat-chips button {
  width: auto;
  max-width: 100%;
  text-align: center;
  white-space: nowrap;
  border: 1px solid #D9E2EC;
  background: #fff;
  color: #334155;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: none;
}

.chat-chips button:hover {
  background: #F0FBFF;
  border-color: #01BBF8;
  color: #0077A3;
}

.chat-lead-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 0 0 4px 36px;
}

.chat-lead-form input,
.chat-lead-form select,
.chat-lead-form textarea {
  width: 100%;
  border: 1px solid #d7e3ee;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 0.85rem;
  color: #111;
  font-family: inherit;
  background: #fff;
}

.chat-lead-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-lead-form button {
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #01BBF8 0%, #0098CC 100%);
  color: #fff;
  font-weight: 700;
  padding: 11px 12px;
  cursor: pointer;
}

.chat-lead-form .chat-lead-wa {
  background: #25D366;
}

.chat-wa {
  display: inline-flex;
  align-self: flex-start;
  margin: 0 0 4px 36px;
  background: #25D366;
  color: #fff !important;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
}

.nt-lead-modal {
  position: fixed;
  inset: 0;
  z-index: 30000;
  background: rgba(10, 22, 40, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.nt-lead-modal.open {
  display: flex;
}

.nt-lead-card {
  position: relative;
  width: min(520px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  padding: 28px 28px 24px;
  box-shadow: 0 24px 60px rgba(10, 22, 40, 0.28);
}

.nt-lead-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: #F1F5F9;
  color: #0A1628;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.nt-lead-card h3 {
  margin: 0 32px 6px 0;
  font-size: 1.25rem;
  color: #0A1628;
}

.nt-lead-sub {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: #334155;
}

.nt-lead-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.nt-lead-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #0A1628;
}

.nt-lead-form label span {
  font-weight: 400;
  color: #64748B;
}

.nt-lead-form input,
.nt-lead-form select,
.nt-lead-form textarea {
  width: 100%;
  border: 1px solid #D7E3EE;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  color: #111;
  font-family: inherit;
  background: #fff;
}

.nt-lead-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.nt-lead-form button {
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #01BBF8 0%, #0098CC 100%);
  color: #fff;
  font-weight: 700;
  padding: 13px 14px;
  font-size: 0.95rem;
  cursor: pointer;
}

.nt-lead-form .chat-lead-wa {
  background: #25D366;
}

body.nt-lead-open {
  overflow: hidden;
}

@media (max-width: 480px) {
  .nt-lead-card {
    padding: 22px 16px 18px;
  }
}
