/* ==========================================================================
   CSS UBIHOME: OPTIMIZADO PARA CARGA COGNITIVA
   ========================================================================== */

/* Contenedor Principal (Consistencia Visual) */
#ubihome-form {
  display: flex;
  position: relative;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  min-height: 300px;
  /* Evita que el contenedor colapse al cambiar de paso */
}

/* Contenedor de los botones dentro del formulario */
.form-footer {
  display: flex;
  justify-content: space-between;
  /* Uno a la izquierda y otro a la derecha */
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
}

/* En móviles, los botones suelen ser más efectivos uno sobre otro o a ancho completo */
@media (max-width: 480px) {
  .form-footer {
    flex-direction: column-reverse;
    /* 'Siguiente' arriba de 'Atrás' para facilitar el pulgar */
  }

  .secondary,
  .primary {
    padding: 14px;
    width: 100%;
  }
}

.ubihome-container {
  margin: 2rem auto;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  background: #ffffff;
  padding: 2rem;
  max-width: 450px;
  font-family:
    "Inter",
    -apple-system,
    sans-serif;
}

/* 1. Barra de Progreso (Mapa Mental) */
.progress-container {
  margin-bottom: 1rem;
  border-radius: 10px;
  background: #e5e7eb;
  height: 6px;
  overflow: hidden;
}

.progress-bar {
  transition: width 0.4s ease-in-out;
  background-color: #399d57;
  height: 100%;
  background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, .2) 75%, transparent 75%, transparent);
}

.step-label {
  margin-bottom: 2rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* 2. Inputs y Etiquetas (Affordance) */
.field-container {
  position: relative;
  margin-bottom: 1.5rem;
}

.field-container label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.95rem;
}

.field-container input {
  transition: var(--transition);
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  background: var(--color-surface-soft);
  padding: 12px 16px;
  width: 100%;
  font-size: 1rem;
}

/* ESTADO: Focus (Reduce carga visual indicando dónde estás) */
.field-container input:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  border-color: var(--color-primary);
  background: #fff;
}

/* ESTADO: Error (Feedback inmediato) */
.field-container.has-error input {
  border-color: var(--color-danger);
  background: #fef2f2;
}

.inline-error {
  display: block;
  margin-top: 4px;
  color: var(--color-danger);
  font-size: 0.8rem;
}

/* 4. OTP Fields (Específico para Verificación) */
.otp-fields-container {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 2rem 0;
}

.otp-slot {
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  background: var(--color-surface-soft);
  width: 45px;
  height: 55px;
  font-weight: bold;
  font-size: 1.5rem;
  text-align: center;
}

.otp-slot:focus {
  border-color: var(--color-primary);
  background: #fff;
}

/* 5. Botones (Estados Activos Claros) */
.primary {
  transition: var(--transition);
  cursor: pointer;
  border: none;
  border-radius: 8px;
  background: var(--color-primary);
  padding: 14px;
  width: 100%;
  color: white;
  font-weight: 600;
}

.primary:disabled {
  cursor: not-allowed;
  background: #d1d5db;
}

.primary:not(:disabled):hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.primary:not(:disabled):active {
  transform: translateY(0);
}

/* Micro-animación para el código OTP incorrecto */
@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

.otp-error {
  animation: shake 0.2s ease-in-out 0s 2;
  border-color: var(--color-danger) !important;
}

/* Mobile First */
@media (max-width: 480px) {
  .ubihome-container {
    margin: 1rem;
    padding: 1.5rem;
  }

  .otp-slot {
    width: 40px;
    height: 50px;
  }
}

/* --- Cabecera del Formulario (Mapa Mental) --- */
.form-header {
  margin-bottom: 2rem;
  text-align: left;
}

.form-header h1 {
  margin-bottom: 0.5rem;
  color: var(--text-main);
  font-size: 1.5rem;
}

/* --- Estados de los Pasos (Control de Carga Cognitiva) --- */
.form-step {
  display: none;
  /* Oculto por defecto para no abrumar */
  animation: fadeIn 0.4s ease-out;
}

.form-step.active {
  display: block;
  /* Solo mostramos el paso actual */
}

/* --- Pistas de Campo (Field Hints) --- */
.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Micro-animación para entrada de pasos */
@keyframes fadeIn {
  from {
    transform: translateY(10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ==========================================================================
   MEDIA QUERIES - RESPONSIVE DESIGN (SaaS Marketplace)
   ========================================================================== */

@media (max-width: 768px) {

  /* Ajuste del contenedor principal */
  .ubihome-container {
    margin: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    padding: 1.5rem;
  }

  /* Títulos más pequeños para no ocupar toda la pantalla */
  .form-header h1 {
    font-size: 1.25rem;
  }

  /* Botones a ancho completo para facilitar el clic táctil */
  .form-footer {
    display: flex;
    flex-direction: column-reverse;
    /* 'Siguiente' arriba de 'Atrás' */
    gap: 12px;
  }

  .primary,
  .secondary {
    padding: 16px;
    /* Más área de toque según leyes de UX móvil */
    width: 100%;
    font-size: 1rem;
  }

  /* Roles en una sola columna para evitar textos apretados */
  .role-cards {
    grid-template-columns: 1fr;
  }

  /* Ajuste de inputs OTP para que no se desborden */
  .otp-fields-container {
    gap: 6px;
  }

  .otp-slot {
    width: 100%;
    /* Se adaptan al espacio disponible */
    max-width: 45px;
    height: 50px;
    font-size: 1.25rem;
  }

  /* Banner de restricción más compacto */
  .status-banner {
    padding: 10px;
  }

  .banner-text {
    font-size: 0.8rem;
    line-height: 1.2;
  }

  .banner-btn {
    padding: 6px 10px;
    font-size: 0.75rem;
  }
}

/* Ajuste para pantallas extra pequeñas (iPhone SE / etc) */
@media (max-width: 360px) {
  .otp-slot {
    max-width: 38px;
    height: 45px;
  }
}

/* Contenedor fijo */
#ubihome-notifications {
  display: flex;
  position: fixed;
  top: 20px;
  right: 20px;
  flex-direction: column;
  gap: 10px;
  z-index: 10001;
}

.toast-notification {
  display: flex;
  align-items: center;
  gap: 12px;

  transform: translateX(0);
  opacity: 1;

  animation: slideInRight 0.3s ease-out;

  transition:
    opacity 0.4s ease,
    transform 0.4s ease;

  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  border-left: 4px solid #10b981;
  border-radius: 8px;
  background: #ffffff;
  padding: 12px 20px;
  min-width: 280px;
  color: #1f2937;
}

.toast-notification.fade-out {
  transform: translateX(40px);
  opacity: 0;
}

.toast-icon {
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background: #10b981;
  width: 20px;
  height: 20px;
  color: white;
  font-weight: bold;
  font-size: 12px;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Contenedor del Paso 2 */
#step-2 .field-container {
  margin-bottom: 1.5rem;
}

/* Lista de Requisitos de Contraseña */
.password-rules {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 0.75rem;
  padding: 0;
  list-style: none;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  color: #9ca3af;
  /* Gris suave por defecto */
  font-size: 0.85rem;
}

/* Iconos de estado para las reglas */
.rule-item::before {
  content: "○";
  /* Círculo vacío */
  font-weight: bold;
}

/* Estado de Regla Cumplida (JS activará esta clase) */
.rule-item.is-valid {
  color: #10b981;
  /* Verde Success */
}

.rule-item.is-valid::before {
  transform: scale(1.1);
  -webkit-transform: scale(1.1);
  -moz-transform: scale(1.1);
  -ms-transform: scale(1.1);
  -o-transform: scale(1.1);
  box-shadow: 0 0 8px oklab(0.7 -0.14 0.04 / 0.35);
  border-radius: 100%;
  background: oklab(0.71 -0.13 0.12 / 0.14);
  width: 20px;
  height: 20px;
  content: "✓";
}

.role-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  /* Dos columnas */
  gap: 15px;
  margin-top: 10px;
}

.role-cards .card {
  position: relative;
  cursor: pointer;
}

/* Escondemos el radio button original */
.role-cards input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* El diseño de la tarjeta */
.card-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  background: #ffffff;
  padding: 15px;
  text-align: center;
}

.card-icon {
  margin-bottom: 8px;
  font-size: 1.5rem;
}

.card-text strong {
  display: block;
  color: #1f2937;
  font-size: 0.95rem;
}

.card-text span {
  color: #6b7280;
  font-size: 0.75rem;
}

/* --- ESTADOS DE LA TARJETA --- */

/* Hover: Feedback sutil */
.role-cards .card:hover .card-content {
  transform: translateY(-2px);
  border-color: #d1d5db;
}

/* SELECCIONADO: La tarjeta brilla */
.role-cards input[type="radio"]:checked+.card-content {
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
  border-color: #389d57;
  /* Azul Ubihome */
  background-color: #dde7dd;
}

/* Indicador visual de "check" dentro de la tarjeta activa */
.role-cards input[type="radio"]:checked+.card-content::after {
  display: flex;
  position: absolute;
  top: 10px;
  right: 10px;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background: #389d57;
  width: 18px;
  height: 18px;
  content: "✓";
  color: white;
  font-size: 10px;
}

/* Botón Secundario (Atrás) */
.secondary {
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.3s ease;
  cursor: pointer;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background-color: transparent;
  padding: 12px 24px;
  color: var(--text-muted);
  /* Un gris profesional */
  font-weight: 500;
  font-size: 0.95rem;
  font-family: "Inter", sans-serif;
}

/* Efecto Hover */
.secondary:hover {
  border-color: #d1d5db;
  background-color: #f9fafb;
  color: var(--text-main);
}

/* Estado activo/clic */
.secondary:active {
  transform: translateY(1px);
  background-color: #f3f4f6;
}

/* Manejo de la visibilidad (evita saltos de layout) */
#btn-back {
  transition:
    opacity 0.3s ease,
    visibility 0.3s;
}

/* El spinner que se insertará vía JS */
.spinner {
  display: inline-block;
  vertical-align: middle;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Estado deshabilitado del botón */
.primary:disabled {
  opacity: 0.7;
  filter: grayscale(0.2);
  cursor: not-allowed;
}

.resend-logic {
  margin-top: 1.5rem;
  font-size: 0.9rem;
  text-align: center;
}

#resend-timer {
  color: var(--text-muted);
}

#timer-count {
  color: var(--primary-color);
  font-weight: 600;
}

/* El botón de acción estilo link */
.link-btn {
  transition: opacity 0.3s;
  cursor: pointer;
  border: none;
  background: none;
  padding: 5px;
  color: var(--primary-color);
  font-weight: 600;
  text-decoration: underline;
}

.link-btn:hover {
  opacity: 0.8;
}

/* Animación de vibración para error en OTP */
.otp-error-shake {
  animation: shakeOTP 0.4s ease-in-out;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
  border-color: #ef4444 !important;
}

@keyframes shakeOTP {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  50% {
    transform: translateX(5px);
  }

  75% {
    transform: translateX(-5px);
  }
}

.input-wrapper {
  display: flex;
  position: relative;
  align-items: center;
}

.input-wrapper input {
  padding-right: 45px;
  /* Deja espacio para que el texto no choque con el ojo */
  width: 100%;
}

.toggle-password-btn {
  display: flex;
  position: absolute;
  right: 12px;
  justify-content: center;
  align-items: center;
  transition: color 0.2s ease;
  cursor: pointer;
  margin: 0;
  border: none;
  background: none;
  padding: 0;
  height: 100%;
  color: #64748b;
  /* Un gris suave */
}

.toggle-password-btn:hover {
  color: #2563eb;
  /* El azul de VivaSV al pasar el mouse */
}

.toggle-password-btn:focus {
  outline: none;
  /* Quitamos el borde de enfoque por defecto */
}

.toggle-password-btn svg {
  width: 20px;
  height: 20px;
  transition: transform 0.2s ease;
}

.toggle-password-btn:active svg {
  transform: scale(0.9);
}

/* Estilo para el aviso de cuenta pendiente */
.field-container.has-warning .inline-error {
  border-left: 4px solid #d97706;
  border-radius: 4px;
  background-color: #fef3c7;
  padding: 8px;
  color: #d97706;
  /* Naranja/Ámbar */
  font-size: 0.85rem;
}

.field-container.has-warning input {
  border-color: #d97706;
}

.otp-slot:focus {
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
  border-color: #2563eb;
}

/* Animación cuando se llenan automáticamente */
.otp-slot {
  transition: all 0.2s ease;
}

/* =========================================
   ESTADOS DE ÉXITO (Success State)
   ========================================= */

/* 1. El borde del input cambia a verde */
.field-container.has-success input {
  border-color: #10b981 !important;
  /* Verde Esmeralda */
  background-color: #f0fdf4;
  /* Un fondo verde muy sutil */
}

/* 2. Opcional: El label también puede cambiar de color */
.field-container.has-success label {
  color: #059669;
}

/* 3. Icono de "Check" (Opcional si usas Dashicons o SVG) */
/* Este código añade un check al final del input si tienes el contenedor en position:relative */
.field-container.has-success {
  position: relative;
}

.field-container.has-success::after {
  position: absolute;
  top: 70%;
  right: 15px;
  transform: translateY(-50%);
  pointer-events: none;
  /* Para que no interfiera con el click */
  content: "✓";
  color: #10b981;
  font-weight: bold;
  font-size: 1.2rem;
}

/* 4. Animación de pulso rápido para feedback */
.field-container.has-success input {
  animation: pulseSuccess 0.3s ease-in-out;
}

@keyframes pulseSuccess {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
  }

  70% {
    box-shadow: 0 0 0 5px rgba(16, 185, 129, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* Spinner para el estado de carga */
.field-container.is-loading {
  position: relative;
}

.field-container.is-loading::after {
  position: absolute;
  top: 50%;
  right: 12px;
  animation: spin 0.6s linear infinite;
  margin-top: -9px;
  border: 2px solid #e5e7eb;
  border-top-color: #2563eb;
  /* Azul carga */
  border-radius: 50%;
  width: 18px;
  height: 18px;
  content: "";
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Animación de Sacudida (Shake) */
@keyframes shakeError {

  0%,
  100% {
    transform: translateX(0);
  }

  20%,
  60% {
    transform: translateX(-8px);
  }

  40%,
  80% {
    transform: translateX(8px);
  }
}

.shake-animation {
  animation: shakeError 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
  border-color: #ef4444 !important;
  /* Rojo feedback */
}