/**
 * Workify WhatsApp Widget Styles
 * Estilos minimalistas con fondo blanco y colores #162447
 */

/* Widget principal flotante */
.whatsapp-widget {
  position: fixed;
  bottom: 75px !important;
  right: 75px !important;
  z-index: 9999;
  font-family: "Arimo", sans-serif;
  pointer-events: none; /* Evita interferir con el layout */
  width: 0;
  height: 0;
  overflow: visible;
}

.whatsapp-widget-button {
  width: 60px;
  height: 60px;
  background: #ffffff;
  border: 2px solid #162447;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(22, 36, 71, 0.15);
  position: relative;
  pointer-events: auto; /* Permite interacción solo en el botón */
}

.whatsapp-widget-button:hover {
  background: #162447;
  color: #ffffff;
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(22, 36, 71, 0.25);
}

.whatsapp-widget-button svg {
  width: 28px;
  height: 28px;
  color: #162447;
  transition: color 0.3s ease;
}

.whatsapp-widget-button:hover svg {
  color: #ffffff;
}

/* Tooltip */
.whatsapp-widget-tooltip {
  position: absolute;
  right: 70px;
  top: 50%;
  transform: translateY(-50%);
  background: #162447;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(22, 36, 71, 0.2);
}

.whatsapp-widget-tooltip::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-left-color: #162447;
}

.whatsapp-widget-button:hover .whatsapp-widget-tooltip {
  opacity: 1;
  visibility: visible;
}

/* Animación de éxito */
.whatsapp-widget-button.whatsapp-success {
  background: #25d366;
  border-color: #25d366;
  animation: successPulse 0.6s ease-in-out;
}

.whatsapp-widget-button.whatsapp-success svg {
  color: #ffffff;
}

@keyframes successPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

/* Modal de challenge */
.whatsapp-challenge-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  font-family: "Arimo", sans-serif;
}

.challenge-modal-overlay {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.challenge-modal-content {
  background: #ffffff;
  border-radius: 12px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(22, 36, 71, 0.2);
  border: 1px solid #e0e0e0;
}

.challenge-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid #f0f0f0;
  text-align: center;
}

.challenge-header h3 {
  color: #162447;
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 8px 0;
}

.challenge-header p {
  color: #666;
  font-size: 16px;
  margin: 0;
  line-height: 1.4;
}

.challenge-body {
  padding: 24px;
}

.challenge-instruction {
  text-align: center;
  margin-bottom: 24px;
}

.challenge-instruction p {
  color: #162447;
  font-size: 18px;
  margin: 0;
  line-height: 1.4;
}

.challenge-instruction strong {
  color: #162447;
  font-weight: 700;
  background: #f8f9fa;
  padding: 2px 8px;
  border-radius: 4px;
}

/* Grid del challenge */
.challenge-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

.challenge-cell {
  width: 80px;
  height: 80px;
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: #162447;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.challenge-cell:hover {
  background: #e9ecef;
  border-color: #162447;
}

.challenge-cell.selected {
  background: #25d366;
  border-color: #25d366;
  color: #ffffff;
  transform: scale(0.95);
}

.challenge-cell.wrong {
  background: #ff4444;
  border-color: #ff4444;
  color: #ffffff;
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Barra de progreso */
.challenge-progress {
  margin-bottom: 24px;
  text-align: center;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: #25d366;
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  color: #162447;
  font-size: 14px;
  font-weight: 600;
}

/* Botones de acción */
.challenge-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.challenge-btn {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px;
}

.challenge-btn.primary {
  background: #162447;
  color: #ffffff;
}

.challenge-btn.primary:hover:not(:disabled) {
  background: #0f1a3a;
  transform: translateY(-1px);
}

.challenge-btn.primary:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

.challenge-btn.secondary {
  background: #f8f9fa;
  color: #162447;
  border: 2px solid #e0e0e0;
}

.challenge-btn.secondary:hover {
  background: #e9ecef;
  border-color: #162447;
}

/* Mensaje de error */
.challenge-error {
  text-align: center;
  margin-top: 16px;
  padding: 12px;
  background: #fff5f5;
  border: 1px solid #ffebee;
  border-radius: 6px;
}

.challenge-error p {
  color: #ff4444;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

/* Asegurar que el widget no afecte el layout del body */
body {
  overflow-x: hidden; /* Previene scroll horizontal */
}

/* Responsive Design */
@media (max-width: 768px) {
  .whatsapp-widget {
    bottom: 15px;
    right: 15px;
  }

  .whatsapp-widget-button {
    width: 55px;
    height: 55px;
  }

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

  .whatsapp-widget-tooltip {
    right: 60px;
    font-size: 13px;
    padding: 6px 10px;
  }

  .challenge-modal-content {
    margin: 10px;
    max-height: calc(100vh - 20px);
  }

  .challenge-header {
    padding: 20px 20px 16px;
  }

  .challenge-header h3 {
    font-size: 20px;
  }

  .challenge-header p {
    font-size: 14px;
  }

  .challenge-body {
    padding: 20px;
  }

  .challenge-instruction p {
    font-size: 16px;
  }

  .challenge-grid {
    gap: 10px;
    max-width: 270px;
  }

  .challenge-cell {
    width: 70px;
    height: 70px;
    font-size: 20px;
  }

  .challenge-actions {
    flex-direction: column;
    align-items: center;
  }

  .challenge-btn {
    width: 100%;
    max-width: 200px;
  }
}

@media (max-width: 480px) {
  .whatsapp-widget {
    bottom: 10px;
    right: 10px;
    /* Asegurar que no cause overflow */
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

  .whatsapp-widget-button {
    width: 50px;
    height: 50px;
  }

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

  .whatsapp-widget-tooltip {
    display: none; /* Ocultar tooltip en móviles muy pequeños */
  }

  /* Asegurar que el tooltip no cause overflow en pantallas pequeñas */
  .whatsapp-widget-tooltip {
    max-width: calc(100vw - 80px);
    right: 60px;
    word-wrap: break-word;
    white-space: normal;
  }

  .challenge-grid {
    gap: 8px;
    max-width: 240px;
  }

  .challenge-cell {
    width: 60px;
    height: 60px;
    font-size: 18px;
  }

  .challenge-header h3 {
    font-size: 18px;
  }

  .challenge-instruction p {
    font-size: 14px;
  }
}

/* Animaciones de entrada */
@keyframes slideInUp {
  from {
    transform: translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.whatsapp-widget-button {
  animation: slideInUp 0.5s ease-out;
}

/* Estados de carga */
.challenge-btn.loading {
  position: relative;
  color: transparent;
}

.challenge-btn.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* Mejoras de accesibilidad */
.challenge-cell:focus {
  outline: 2px solid #162447;
  outline-offset: 2px;
}

.challenge-btn:focus {
  outline: 2px solid #162447;
  outline-offset: 2px;
}

/* Modo oscuro (opcional) */
@media (prefers-color-scheme: dark) {
  .challenge-modal-content {
    background: #1a1a1a;
    border-color: #333;
  }

  .challenge-header h3 {
    color: #ffffff;
  }

  .challenge-header p {
    color: #ccc;
  }

  .challenge-instruction p {
    color: #ffffff;
  }

  .challenge-instruction strong {
    background: #333;
    color: #ffffff;
  }

  .challenge-cell {
    background: #333;
    border-color: #555;
    color: #ffffff;
  }

  .challenge-cell:hover {
    background: #444;
  }

  .progress-text {
    color: #ffffff;
  }

  .challenge-btn.secondary {
    background: #333;
    color: #ffffff;
    border-color: #555;
  }

  .challenge-btn.secondary:hover {
    background: #444;
  }
}
