/* =========================================================================
   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.gt-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;
  text-align: left;
  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);
  z-index: 10001;
}

/* 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;
  text-align: left;
}

.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;
  text-align: left;
}

/* 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;
  text-align: left;
}

.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;
  text-align: left;
}

.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.gt-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-contact-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: auto;
  max-width: 260px;
  margin: 0 0 2px 36px;
  padding: 0;
}
.chat-contact-hint {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: #5b6b82;
  line-height: 1.25;
}
.chat-contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-contact-actions button {
  flex: 0 0 auto;
  min-height: 0;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 0.78rem;
  line-height: 1.2;
  cursor: pointer;
  border: 1px solid transparent;
}
.chat-contact-actions button.chat-lead-wa {
  background: #25D366;
  border-color: #1da851;
  color: #fff;
}
.chat-contact-actions button.chat-lead-wa:hover {
  background: #1ebe57;
  border-color: #1aa34c;
  color: #fff;
}
.chat-contact-actions button.chat-lead-mail {
  background: #012970;
  border-color: #012970;
  color: #fff;
}
.chat-contact-actions button.chat-lead-mail:hover {
  background: #023e8a;
  color: #fff;
}

.chat-action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #01BBF8;
  color: #0A1628;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  background: #fff;
}

.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(1, 41, 112, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}
.nt-lead-modal.open { display: flex; }
.nt-lead-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: min(640px, calc(100vh - 28px));
  max-height: min(640px, calc(100dvh - 28px));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(1, 41, 112, 0.28);
  box-sizing: border-box;
}
.nt-lead-brand {
  position: relative;
  top: auto;
  z-index: 2;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 12px 16px;
  background: #000000;
  border-bottom: 2px solid #01BBF8;
}
.nt-lead-brand img {
  height: 42px;
  width: auto;
  max-width: min(240px, 72%);
  object-fit: contain;
  object-position: left center;
  display: block;
}
.nt-lead-brand .nt-lead-lockup {
  max-width: min(240px, 72%);
}
.nt-lead-brand .gt-lockup__name {
  font-size: 1.2rem;
}
.nt-lead-brand .gt-lockup__tagline {
  font-size: 0.625rem;
  letter-spacing: 0.08em;
}
.nt-lead-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
.nt-lead-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 16px 16px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}
.nt-lead-body::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}
.nt-lead-card h3 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  color: #012970;
}
.nt-lead-sub {
  margin: 0 0 12px;
  font-size: 0.82rem;
  line-height: 1.35;
  color: #5b6b82;
}
.nt-lead-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nt-lead-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #012970;
}
.nt-lead-form label span {
  font-weight: 500;
  color: #64748B;
}
.nt-lead-form input,
.nt-lead-form select,
.nt-lead-form textarea {
  width: 100%;
  border: 1px solid #D7E3EE;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px; /* evita zoom iOS */
  color: #111;
  font-family: inherit;
  background: #fff;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: none;
}
.nt-lead-form select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23012970' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
.nt-lead-form input:focus,
.nt-lead-form select:focus,
.nt-lead-form textarea:focus {
  border-color: #01BBF8;
  box-shadow: 0 0 0 3px rgba(1, 187, 248, 0.18);
}
.nt-lead-form textarea {
  min-height: 72px;
  resize: vertical;
}
.nt-flag {
  width: 22px;
  height: 16px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(1, 41, 112, 0.12);
  flex: 0 0 auto;
}
.nt-phone-row {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.nt-phone-prefix {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid #D7E3EE;
  border-radius: 10px;
  background: #F1F8FF;
  color: #012970;
  font-weight: 800;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
}
.nt-phone-prefix:hover,
.nt-phone-prefix[aria-expanded="true"] {
  border-color: #01BBF8;
  box-shadow: 0 0 0 3px rgba(1, 187, 248, 0.15);
}
.nt-phone-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid #012970;
  opacity: 0.7;
  margin-left: 2px;
}
.nt-country-picker {
  margin-top: 8px;
  border: 1px solid #D7E3EE;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(1, 41, 112, 0.12);
  max-height: 220px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.nt-country-list {
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 2px;
}
.nt-country-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 10px 10px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  color: #012970;
  font-weight: 600;
}
.nt-country-opt:hover,
.nt-country-opt.on {
  background: #e7f7ff;
}
.nt-lead-form > .nt-lead-actions button.nt-phone-prefix,
.nt-lead-form button.nt-phone-prefix {
  flex: 0 0 auto;
  background: #F1F8FF;
  color: #012970;
  padding: 0 10px;
}
.nt-phone-row input[name="phone_local"] {
  flex: 1;
  min-width: 0;
}
.nt-phone-row input[name="dial_other"] {
  width: 72px;
  flex: 0 0 72px;
  padding-left: 8px;
  padding-right: 8px;
}
.nt-lead-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.nt-lead-form > .nt-lead-actions {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin-top: 6px;
  padding-top: 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(255,255,255,0), #fff 22%);
}
.nt-lead-form button {
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #01BBF8 0%, #0098CC 100%);
  color: #fff;
  font-weight: 700;
  padding: 12px 14px;
  font-size: 0.92rem;
  cursor: pointer;
  flex: 1 1 140px;
}
.nt-lead-form .chat-lead-wa {
  background: #25D366;
}
.nt-lead-form .nt-lead-via-mail {
  background: linear-gradient(135deg, #012970 0%, #023e8a 100%);
}
.nt-lead-confirm {
  margin-top: 4px;
  padding: 12px;
  border-radius: 12px;
  background: #eef6ff;
  border: 1px solid #9ad8f0;
}
.nt-lead-confirm-text {
  margin: 0 0 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #012970;
  line-height: 1.35;
}
.nt-lead-confirm .nt-lead-actions { margin: 0; position: static; background: none; padding: 0; }
.nt-lead-confirm-yes { background: #012970 !important; color: #fff !important; }
.nt-lead-confirm-no {
  background: #fff !important;
  color: #012970 !important;
  border: 1px solid #c5d4ee !important;
}
body.nt-lead-open { overflow: hidden; }
@media (min-width: 640px) {
  .nt-lead-modal {
    padding: 20px;
  }
  .nt-lead-card {
    max-height: min(88vh, 680px);
    max-height: min(88dvh, 680px);
  }
  .nt-lead-brand img { height: 40px; max-width: min(220px, 70%); }
  .nt-lead-body { padding: 14px 20px 18px; }
}

@media (max-width: 639px) {
  .nt-lead-modal {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
  .nt-lead-card {
    width: 100%;
    max-width: none;
    max-height: calc(100vh - 24px);
    max-height: calc(100svh - 24px);
    max-height: calc(100dvh - 24px);
    border-radius: 16px;
  }
  .nt-lead-brand {
    padding: 10px 12px;
  }
  .nt-lead-brand img {
    height: 36px;
    max-width: min(200px, 68%);
  }
  .nt-lead-body {
    padding: 10px 14px 12px;
  }
  .nt-lead-card h3 {
    font-size: 1.05rem;
    margin-bottom: 2px;
  }
  .nt-lead-sub {
    margin: 0 0 8px;
    font-size: 0.78rem;
  }
  .nt-lead-form {
    gap: 6px;
  }
  .nt-lead-form input,
  .nt-lead-form select,
  .nt-lead-form textarea {
    padding: 9px 11px;
  }
  .nt-lead-form textarea {
    min-height: 60px;
    max-height: 90px;
  }
  .nt-lead-form button {
    padding: 11px 12px;
    font-size: 0.9rem;
    flex: 1 1 100%;
  }
  .nt-lead-confirm {
    padding: 10px;
  }
}
