/* Widget del chatbot: copiado tal cual de content/page/index_index.php:403-1148 del legacy (CSS en línea). */
/* === ESTILOS BASE DEL WIDGET === */
* {
  box-sizing: border-box;
}

#incalake-widget {
  position: fixed;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* === BOTÓN FLOTANTE === */
.widget-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--inca-azul), var(--inca-azul-700));
  border-radius: 50%;
  box-shadow: 0 4px 20px rgba(13, 142, 227, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  transition: all 0.3s ease;
  z-index: 10001;
}

.widget-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(13, 142, 227, 0.5);
}

.widget-button svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.3s ease;
}

.widget-button.open svg {
  transform: rotate(180deg);
}

/* === VENTANA DEL CHAT === */
.widget-container {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: min(380px, calc(100vw - 40px));
  /* Se adapta al ancho de la pantalla */
  height: min(600px, calc(100vh - 120px));
  /* Se adapta a la altura de la pantalla */
  max-width: 420px;
  /* Límite máximo */
  max-height: 700px;
  /* Límite máximo */
  background: white;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 10000;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.widget-container.show {
  display: flex;
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* === HEADER === */
.widget-header {
  background: linear-gradient(135deg, var(--inca-azul), var(--inca-azul-700));
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  /* Evita que se comprima */
}

.header-info {
  flex: 1;
  min-width: 0;
  /* Permite que el contenido se ajuste */
}

.widget-header h3 {
  margin: 0;
  font-size: clamp(14px, 3vw, 16px);
  /* Fuente adaptable */
  font-weight: 600;
}

.widget-header .subtitle {
  font-size: clamp(10px, 2.5vw, 12px);
  opacity: 0.9;
  margin-top: 2px;
}

.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.contact-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: white;
  text-decoration: none;
  font-size: clamp(9px, 2vw, 11px);
  padding: 4px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  transition: background-color 0.2s;
  white-space: nowrap;
}

.contact-link:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  text-decoration: none;
}

.contact-link svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
  flex-shrink: 0;
}

.close-btn {
  background: none;
  border: none;
  color: white;
  font-size: clamp(50px, 4vw, 24px);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s;
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* === FORMULARIO DE BIENVENIDA === */
.welcome-form {
  padding: clamp(20px, 4vw, 30px) 20px;
  text-align: center;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow-y: auto;
}

.welcome-form h4 {
  color: #333;
  margin-bottom: 8px;
  font-size: clamp(16px, 3.5vw, 18px);
  font-weight: 600;
}

.welcome-form p {
  color: #666;
  margin-bottom: 20px;
  font-size: clamp(13px, 2.8vw, 14px);
  line-height: 1.4;
}

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: #333;
  font-size: clamp(12px, 2.5vw, 13px);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: clamp(13px, 2.8vw, 14px);
  transition: border-color 0.2s;
  min-height: 44px;
  /* Tamaño mínimo para touch */
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--inca-azul);
}

.phone-group {
  display: flex;
  gap: 8px;
}

.phone-group select {
  width: min(120px, 35%);
  flex-shrink: 0;
}

.phone-group input {
  flex: 1;
  min-width: 0;
}

/* === CAPTCHA === */
.captcha-group {
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  margin-bottom: 16px;
}

.captcha-question {
  font-weight: 500;
  color: #333;
  margin-bottom: 8px;
  font-size: clamp(13px, 2.8vw, 14px);
}

.captcha-input {
  width: min(80px, 25%) !important;
  text-align: center;
  font-size: clamp(14px, 3vw, 16px);
  font-weight: bold;
}

.start-btn {
  width: 100%;
  padding: 12px;
  min-height: 44px;
  background: linear-gradient(135deg, var(--inca-azul), var(--inca-azul-700));
  color: white;
  border: none;
  border-radius: 8px;
  font-size: clamp(13px, 2.8vw, 14px);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.start-btn:hover {
  transform: translateY(-2px);
}

.start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* === ÁREA DEL CHAT === */
.chat-area {
  display: none;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  /* Permite que se comprima */
}

.chat-area.active {
  display: flex;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Permite scroll cuando es necesario */
}

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

.chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 2px;
}

/* === MENSAJES === */
.message-row {
  display: flex;
  margin-bottom: 12px;
  align-items: flex-start;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.bot {
  justify-content: flex-start;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-right: 8px;
}

.message-row.user .avatar {
  order: 2;
  margin-right: 0;
  margin-left: 8px;
}

.message-content {
  max-width: min(80%, 280px);
  /* Limita el ancho máximo */
  padding: 12px 16px;
  border-radius: 12px;
  font-size: clamp(13px, 2.8vw, 14px);
  line-height: 1.4;
  word-wrap: break-word;
  word-break: break-word;
  /* Mejora el ajuste de texto */
}

.message-row.user .message-content {
  background: linear-gradient(135deg, var(--inca-azul), var(--inca-azul-700));
  color: white;
}

.message-row.bot .message-content {
  background: #f5f5f5;
  color: #333;
}

.message-content a {
  color: var(--inca-azul);
  text-decoration: underline;
}

.message-content a::after {
  content: " ↗";
  font-size: 0.8em;
  opacity: 0.7;
}

/* === FORMULARIO DE ENTRADA === */
.chat-input {
  padding: 16px 20px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
  /* No se comprime */
}

.chat-input input {
  flex: 1;
  padding: 12px;
  min-height: 44px;
  border: 2px solid #e0e0e0;
  border-radius: 20px;
  font-size: clamp(13px, 2.8vw, 14px);
  max-height: 80px;
  resize: none;
}

.chat-input input:focus {
  outline: none;
  border-color: var(--inca-azul);
}

.send-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  background: linear-gradient(135deg, var(--inca-azul), var(--inca-azul-700));
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.send-btn:hover {
  transform: scale(1.1);
}

.send-btn svg {
  width: 16px;
  height: 16px;
  fill: white;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chat-input input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.connection-status {
  position: fixed;
  bottom: 90px;
  right: 30px;
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 12px;
  z-index: 10002;
}

.connection-status.connected {
  background: #4CAF50;
  color: white;
}

.connection-status.disconnected {
  background: #F44336;
  color: white;
}

/* === RESPONSIVE BREAKPOINTS === */

/* Pantallas muy pequeñas (hasta 320px) */
@media (max-width: 320px) {
  .widget-container {
    width: calc(100vw - 20px);
    height: min(calc(100vh - 70px), 600px);
    /* También más alto aquí */
    right: 10px;
    bottom: 65px;
    /* Más cerca del borde */
  }

  .widget-button {
    right: 15px;
    bottom: 65px;
    /* Ajustado para coincidir */
    width: 50px;
    height: 50px;
  }

  .contact-links {
    flex-direction: column;
    gap: 4px;
  }
}

/* Pantallas pequeñas (321px - 480px) */
@media (max-width: 480px) {
  .widget-container {
    width: calc(100vw - 30px);
    height: min(calc(100vh - 80px), 650px);
    /* Más alto: de 100px a 80px de margen */
    bottom: 70px;
    /* Más cerca del borde: de 80px a 70px */
  }

  .widget-button {
    bottom: 70px;
    /* Ajustado para coincidir */
    right: 20px;
  }

  .contact-links {
    gap: 6px;
  }

  .contact-link {
    font-size: 10px;
    padding: 3px 5px;
  }

  .phone-group {
    flex-direction: column;
  }

  .phone-group select {
    width: 100%;
  }
}

/* Pantallas medianas (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
  .widget-container {
    width: min(400px, calc(100vw - 60px));
    height: min(650px, calc(100vh - 140px));
  }
}

/* Pantallas grandes (769px - 1279px) */
@media (min-width: 769px) and (max-width: 1279px) {
  .widget-container {
    width: 350px;
    height: 520px;
  }
}

/* Pantallas medianas-grandes (1025px - 1279px) - excluyendo 1280-1400 que ya tiene su propia regla */
@media (min-width: 1025px) and (max-width: 1279px) {
  .widget-container {
    width: 360px;
    height: 540px;
  }
}

/* Pantallas extra grandes (1401px+) */
@media (min-width: 1401px) {
  .widget-container {
    width: 420px;
    height: 650px;
    max-height: 700px;
  }
}

/* Resoluciones 1366x768, 1280x720 y similares */
@media (min-width: 1280px) and (max-width: 1400px) and (min-height: 720px) and (max-height: 800px) {
  .widget-container {
    width: 320px;
    height: 480px;
    bottom: 70px;
  }

  .widget-button {
    width: 50px;
    height: 50px;
    bottom: 15px;
    right: 15px;
  }

  .widget-button svg {
    width: 24px;
    height: 24px;
  }

  .widget-header {
    padding: 12px 16px;
  }

  .widget-header h3 {
    font-size: 14px;
  }

  .widget-header .subtitle {
    font-size: 11px;
  }

  .contact-link {
    font-size: 9px;
    padding: 3px 5px;
  }

  .welcome-form {
    padding: 20px 16px;
  }

  .welcome-form h4 {
    font-size: 16px;
  }

  .welcome-form p {
    font-size: 13px;
  }

  .form-group input,
  .form-group select {
    padding: 10px;
    font-size: 13px;
    min-height: 40px;
  }

  .form-group label {
    font-size: 12px;
  }

  .captcha-question {
    font-size: 13px;
  }

  .captcha-input {
    font-size: 14px;
  }

  .start-btn {
    padding: 10px;
    font-size: 13px;
    min-height: 40px;
  }

  .chat-messages {
    padding: 16px;
  }

  .message-content {
    padding: 10px 12px;
    font-size: 13px;
  }

  .avatar {
    width: 28px;
    height: 28px;
  }

  .chat-input {
    padding: 12px 16px;
  }

  .chat-input input {
    padding: 10px;
    font-size: 13px;
    min-height: 40px;
  }

  .send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }

  .send-btn svg {
    width: 14px;
    height: 14px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .widget-container {
    height: calc(100vh - 40px);
    bottom: 20px;
  }

  .welcome-form {
    padding: 15px 20px;
  }

  .form-group {
    margin-bottom: 12px;
  }
}

/* Pantallas de alta densidad (retina) */
@media (-webkit-min-device-pixel-ratio: 2) {
  .widget-button {
    box-shadow: 0 2px 10px rgba(13, 142, 227, 0.4);
  }

  .widget-container {
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
  }
}

/* === ESTADOS DE CARGA === */
.loading {
  font-style: italic;
  opacity: 0.7;
}

.error-message {
  color: #e74c3c;
  font-size: clamp(12px, 2.5vw, 13px);
}

@media (max-width: 768px) {
  .widget-button.hide-on-mobile {
    display: none !important;
  }
}

/* === ANIMACIONES === */
@keyframes bounce {

  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }

  40% {
    transform: translateY(-10px);
  }

  60% {
    transform: translateY(-5px);
  }
}

.widget-button.notification {
  animation: bounce 2s infinite;
}

/* === MEJORAS DE ACCESIBILIDAD === */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
