/* =================================
   CSS Variables & Theme
   ================================= */
:root {
  /* Colors - Floutel Brand (Magenta/Viola corporatiu) */
  --color-primary: #f2055d;
  --color-primary-hover: #d10450;
  --color-primary-light: #fed7e2;
  --color-primary-dark: #d10450;

  --color-success: #10b981;
  --color-success-light: #34d399;
  --color-error: #ef4444;
  --color-error-light: #fca5a5;
  --color-warning: #f59e0b;

  /* Backgrounds */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-dark: #0f172a;

  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  /* Borders */
  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Sizing */
  --max-width: 480px;
  --border-radius: 12px;
  --border-radius-lg: 16px;

  /* Animation */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* =================================
   Base Styles
   ================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #f2055d 0%, #7e055d 100%);
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height para móviles */
  color: var(--text-primary);
  line-height: 1.5;
}

/* =================================
   App Container
   ================================= */
.app-container {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* =================================
   Header
   ================================= */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: white;
}

.logo-icon {
  width: 32px;
  height: 32px;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
}

.security-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  color: white;
  font-size: 0.75rem;
  font-weight: 500;
}

.security-badge svg {
  width: 16px;
  height: 16px;
}

/* =================================
   Main Content
   ================================= */
.main-content {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
}

.verification-container {
  width: 100%;
  max-width: var(--max-width);
  background: var(--bg-primary);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

/* =================================
   Progress Steps
   ================================= */
.progress-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  position: relative;
}

/* Botón Volver en la cabecera de pasos */
.header-back-button {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.header-back-button:hover {
  background: var(--bg-primary);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.header-back-button svg {
  width: 18px;
  height: 18px;
}

.header-back-button.hidden {
  display: none;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.step-number {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
  transition: var(--transition-normal);
}

.step.active .step-number {
  background: var(--color-primary);
  color: white;
}

.step.completed .step-number {
  background: var(--color-success);
  color: white;
}

.step.completed .step-number::after {
  content: '✓';
}

.step-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.step.active .step-label {
  color: var(--text-primary);
}

.step-line {
  width: 60px;
  height: 2px;
  background: var(--border-light);
  margin: 0 0.5rem;
  margin-bottom: 1.5rem;
}

/* =================================
   Step Panels
   ================================= */
.step-content {
  position: relative;
}

.step-panel {
  display: none;
  padding: 2rem;
  animation: fadeIn 0.3s ease;
}

.step-panel.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

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

.title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

/* =================================
   Method Cards
   ================================= */
.method-cards {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.method-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--bg-secondary);
  border: 2px solid var(--border-light);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition-normal);
  text-align: left;
  width: 100%;
}

.method-card:hover {
  border-color: var(--color-primary);
  background: var(--bg-primary);
  box-shadow: var(--shadow-md);
}

.method-card.recommended {
  border-color: var(--color-primary-light);
  background: linear-gradient(135deg, #fdf2f8 0%, #fce7f3 100%);
}

.method-card.recommended:hover {
  border-color: var(--color-primary);
}

.method-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 12px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.method-icon svg {
  width: 32px;
  height: 32px;
}

.method-content {
  flex: 1;
}

.method-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: var(--color-primary);
  color: white;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: 4px;
  margin-bottom: 0.25rem;
}

.method-content h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.method-content p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.method-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* =================================
   Info Notice
   ================================= */
.info-notice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
}

.info-notice svg {
  width: 20px;
  height: 20px;
  color: var(--color-primary);
  flex-shrink: 0;
  margin-top: 2px;
}

.info-notice p {
  font-size: 0.813rem;
  color: var(--text-secondary);
  margin: 0;
}

/* =================================
   Buttons
   ================================= */
.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-normal);
}

.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.primary-button:active {
  transform: translateY(0);
}

.primary-button svg {
  width: 20px;
  height: 20px;
}

.secondary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-normal);
}

.secondary-button:hover {
  background: var(--bg-tertiary);
}

/* Estilos de .back-button movidos a .header-back-button en progress-steps */

/* =================================
   Certificate Panel
   ================================= */
.certificate-info {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
}

.cert-icon-large {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 16px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.cert-icon-large svg {
  width: 48px;
  height: 48px;
}

.cert-instructions h4 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.cert-instructions ul {
  list-style: none;
  padding: 0;
}

.cert-instructions li {
  font-size: 0.813rem;
  color: var(--text-secondary);
  padding: 0.25rem 0;
  padding-left: 1.25rem;
  position: relative;
}

.cert-instructions li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--color-success);
  font-weight: bold;
}

.status-message {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  margin-top: 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  color: var(--text-secondary);
}

.status-message.hidden {
  display: none;
}

/* =================================
   Document Substeps
   ================================= */
.doc-substeps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding: 0 0.5rem;
  overflow: visible; /* Permitir que el box-shadow del indicator sea visible */
}

.substep {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-top: 4px; /* Espacio para el box-shadow del indicator */
}

.substep-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border-light);
  transition: var(--transition-normal);
}

.substep.active .substep-indicator {
  background: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

.substep.completed .substep-indicator {
  background: var(--color-success);
}

.substep.active {
  color: var(--text-primary);
  font-weight: 500;
}

/* =================================
   Camera Container
   ================================= */
.capture-panel {
  display: none;
}

.capture-panel.active {
  display: block;
}

.camera-container {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: var(--border-radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
  max-height: 450px;
}

.camera-container.selfie-mode {
  aspect-ratio: 3 / 4;
  max-height: 450px;
  min-height: 320px;
  margin: 0 auto 1.5rem auto;
  width: 100%;
  max-width: 360px;
}

.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  pointer-events: none;
}

/* Preview de captura (imagen fija tras capturar) */
.capture-preview {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: center;
}

.capture-preview img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.capture-preview.hidden {
  display: none;
}

/* Preview de documentos (DNI) - mantener proporciones sin distorsión */
#frontPreview img,
#backPreview img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* En móvil portrait, hacer el documento más grande */
@media (max-width: 768px) and (orientation: portrait) {
  #frontPreview,
  #backPreview {
    padding: 0.5rem;
  }

  #frontPreview img,
  #backPreview img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  }
}

/* Preview de selfie - puede usar más espacio */
#selfiePreview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* =================================
   Face Frame con Silueta SVG
   ================================= */
.face-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  pointer-events: none;
}

.face-silhouette {
  width: 100%;
  height: 100%;
}

.face-silhouette .face-outline {
  stroke: var(--color-primary);
  transition: stroke 0.3s ease, filter 0.3s ease;
}

.face-silhouette .face-overlay-rect {
  transition: fill 0.3s ease;
}

/* Texto de instrucción debajo de la silueta */
.face-instruction {
  position: absolute;
  bottom: 4%;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  color: white;
  font-size: 0.875rem;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  z-index: 20;
}

/* Liveness frame no muestra instrucción (tiene su propio challenge text) */
.liveness-frame .face-instruction {
  display: none;
}

/* Estado: cara detectada correctamente posicionada */
.face-frame.face-detected .face-outline {
  stroke: #22c55e;
  filter: drop-shadow(0 0 8px rgba(34, 197, 94, 0.5));
}

.face-frame.face-detected .face-overlay-rect {
  fill: rgba(34, 197, 94, 0.15);
}

.face-frame.face-detected .face-instruction {
  content: 'Posición correcta';
  color: #22c55e;
}

/* Cambiar texto cuando cara detectada - usando JS */

/* Estado de éxito para retos de liveness - marco verde */
.face-frame.challenge-success .face-outline {
  stroke: #22c55e;
  filter: drop-shadow(0 0 12px rgba(34, 197, 94, 0.6));
}

.face-frame.challenge-success .face-overlay-rect {
  fill: rgba(34, 197, 94, 0.2);
}

/* Selfie: controles ocultos hasta auto-captura completada */
.selfie-controls.hidden {
  display: none !important;
}

/* Estados de distancia de la cara */
.face-frame.face-too-close .face-outline {
  stroke: #f59e0b;
  filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.5));
}

.face-frame.face-too-close .face-overlay-rect {
  fill: rgba(245, 158, 11, 0.15);
}

.face-frame.face-too-close .face-instruction {
  color: #f59e0b;
}

.face-frame.face-too-far .face-outline {
  stroke: #f59e0b;
  filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.5));
}

.face-frame.face-too-far .face-overlay-rect {
  fill: rgba(245, 158, 11, 0.15);
}

.face-frame.face-too-far .face-instruction {
  color: #f59e0b;
}

.face-frame.face-not-centered .face-outline {
  stroke: #ef4444;
  filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.5));
}

.face-frame.face-not-centered .face-overlay-rect {
  fill: rgba(239, 68, 68, 0.1);
}

.face-frame.face-not-centered .face-instruction {
  color: #ef4444;
}

/* Estado: cara no frontal (girada, mirando arriba/abajo, inclinada) */
.face-frame.face-not-frontal .face-outline {
  stroke: #f59e0b;
  filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.5));
}

.face-frame.face-not-frontal .face-overlay-rect {
  fill: rgba(245, 158, 11, 0.15);
}

.face-frame.face-not-frontal .face-instruction {
  color: #f59e0b;
}

/* Estado: ojos cerrados - más visible para captar atención */
.face-frame.eyes-closed .face-outline {
  stroke: #ef4444;
  filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.6));
  animation: pulse-eyes 0.8s ease-in-out infinite;
}

.face-frame.eyes-closed .face-overlay-rect {
  fill: rgba(239, 68, 68, 0.2);
}

.face-frame.eyes-closed .face-instruction {
  color: #ef4444;
  font-weight: 600;
  font-size: 1rem;
}

@keyframes pulse-eyes {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.5)); }
  50% { filter: drop-shadow(0 0 12px rgba(239, 68, 68, 0.8)); }
}

.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Mode mirror (Front/Back/Selfie) */
.camera-container.mirror-mode video,
.camera-container.mirror-mode .capture-preview img,
.selfie-mode video,
.selfie-mode .capture-preview img {
  transform: scaleX(-1) !important;
}

/* =================================
   Viewfinder & Animations
   ================================= */

.document-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  aspect-ratio: 85.6 / 53.98; /* Proporciones exactas de DNI/tarjeta de crédito */
  max-height: 70%;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  pointer-events: none;
  z-index: 5;
}

/* En móvil portrait, el DNI se captura en horizontal dentro de pantalla vertical */
/* Mantener proporciones exactas de tarjeta de crédito */
@media (max-width: 768px) and (orientation: portrait) {
  .document-frame {
    /* En portrait, el ancho del frame debe ser menor para que quepa bien */
    /* y el aspect-ratio calculará la altura correcta automáticamente */
    width: 90%;
    max-width: 340px; /* Limitar ancho máximo para mantener proporciones */
    max-height: none; /* No limitar altura, dejar que aspect-ratio la calcule */
  }
}

.document-frame::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 2px solid transparent;
  background:
    linear-gradient(to right, white 4px, transparent 4px) 0 0,
    linear-gradient(to bottom, white 4px, transparent 4px) 0 0,
    linear-gradient(to left, white 4px, transparent 4px) 100% 0,
    linear-gradient(to bottom, white 4px, transparent 4px) 100% 0,
    linear-gradient(to left, white 4px, transparent 4px) 100% 100%,
    linear-gradient(to top, white 4px, transparent 4px) 100% 100%,
    linear-gradient(to right, white 4px, transparent 4px) 0 100%,
    linear-gradient(to top, white 4px, transparent 4px) 0 100%;
  background-repeat: no-repeat;
  background-size: 40px 40px;
}

/* Indicador de enfoque automático */
.focus-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  border: 3px solid var(--color-primary);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 15;
}

.focus-indicator.active {
  opacity: 1;
  animation: focusPulse 0.5s ease-out;
}

.focus-indicator span {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

/* Esquinas del indicador de enfoque */
.focus-indicator::before,
.focus-indicator::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--color-primary);
  border-style: solid;
}

.focus-indicator::before {
  top: -3px;
  left: -3px;
  border-width: 3px 0 0 3px;
  border-radius: 8px 0 0 0;
}

.focus-indicator::after {
  bottom: -3px;
  right: -3px;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 8px 0;
}

@keyframes focusPulse {
  0% {
    transform: translate(-50%, -50%) scale(1.3);
    opacity: 0.5;
  }
  50% {
    transform: translate(-50%, -50%) scale(0.95);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

.camera-instruction {
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 100%;
  text-align: center;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  font-weight: 600;
  font-size: 1rem;
  padding: 0 1rem;
  z-index: 10;
}

.flip-animation-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  color: white;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

.flip-icon {
  width: 120px;
  height: 80px;
  margin-bottom: 2rem;
  perspective: 1000px;
}

.flip-card {
  width: 100%;
  height: 100%;
  background: white;
  border-radius: 8px;
  position: relative;
  transform-style: preserve-3d;
  animation: flipCard 3s infinite ease-in-out;
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  font-weight: bold;
  font-size: 12px;
}

.flip-card-front {
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
}

.flip-card-back {
  background: linear-gradient(135deg, #cbd5e1 0%, #94a3b8 100%);
  transform: rotateY(180deg);
}

@keyframes flipCard {
  0% {
    transform: rotateY(0deg);
  }

  40% {
    transform: rotateY(180deg);
  }

  60% {
    transform: rotateY(180deg);
  }

  100% {
    transform: rotateY(0deg);
  }
}

/* =================================
   Capture Controls
   ================================= */
.capture-controls {
  display: flex;
  gap: 1rem;
}

/* Botones dentro de capture-controls comparten espacio equitativamente */
.capture-controls .secondary-button,
.capture-controls .primary-button {
  flex: 1;
  width: auto;
}

.capture-button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-normal);
}

.capture-button:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.capture-button:disabled,
.capture-button.disabled {
  background: #6b7280;
  cursor: not-allowed;
  opacity: 0.7;
}

.capture-button:disabled:hover,
.capture-button.disabled:hover {
  background: #6b7280;
}

.capture-icon {
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  position: relative;
}

.capture-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  background: var(--color-primary);
  border-radius: 50%;
}

/* =================================
   Liveness Challenge
   ================================= */
.liveness-challenge {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: 90%;
  z-index: 20;
  text-align: center;
  background: rgba(0, 0, 0, 0.5);
  padding: 0.5rem;
  border-radius: 8px;
}

.challenge-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  transition: color 0.3s ease, filter 0.3s ease, transform 0.3s ease;
}

.challenge-icon.completed {
  color: #22c55e;
  filter: drop-shadow(0 2px 8px rgba(34, 197, 94, 0.5));
  transform: scale(1.1);
}

.challenge-icon svg {
  width: 100%;
  height: 100%;
}

#challengeText {
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  margin: 0;
  white-space: nowrap;
  transition: color 0.3s ease;
}

#challengeText.completed {
  color: #22c55e;
}

/* Countdown en botón */
.countdown-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  font-weight: 700;
  font-size: 1rem;
  margin-right: 0.5rem;
}

#startLiveness {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.liveness-progress {
  margin-bottom: 1rem;
}

.progress-bar {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  width: 0%;
  transition: width 0.3s ease;
}

/* =================================
   Result Panel
   ================================= */
.result-content {
  display: none;
  text-align: center;
  padding: 2rem 0;
}

.result-content.success,
.result-content.error,
.result-content.loading {
  display: block;
}

.result-content.hidden {
  display: none !important;
}

.result-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 1.5rem;
}

.success-icon {
  color: var(--color-success);
}

.error-icon {
  color: var(--color-error);
}

.result-content h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.result-content p {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.verified-data {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
  text-align: left;
}

.verified-data .data-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
}

.verified-data .data-row:last-child {
  border-bottom: none;
}

.verified-data .data-label {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.verified-data .data-value {
  font-weight: 500;
  text-align: right;
  max-width: 60%;
}

.verified-data .data-value-success {
  color: var(--color-success);
  font-weight: 600;
}

.verified-data .data-value-warning {
  color: var(--color-warning);
  font-weight: 600;
}

.verified-data .data-value-error {
  color: var(--color-error);
  font-weight: 600;
}

/* =================================
   Verification Checks
   ================================= */
.verification-checks {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
}

.verification-check {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.verification-check .check-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.verification-check .check-icon svg {
  width: 100%;
  height: 100%;
  display: none;
}

/* Pending state */
.verification-check[data-status="pending"] .icon-pending {
  display: block;
  stroke: var(--text-muted);
}

/* Loading state */
.verification-check[data-status="loading"] .icon-loading {
  display: block;
  stroke: var(--color-primary);
  animation: spin 1s linear infinite;
}

/* Done state */
.verification-check[data-status="done"] .icon-done {
  display: block;
  stroke: var(--color-success);
}

.verification-check .check-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.verification-check[data-status="loading"] .check-label {
  color: var(--text-primary);
  font-weight: 500;
}

.verification-check[data-status="done"] .check-label {
  color: var(--color-success);
  font-weight: 500;
}

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

/* =================================
   Loading Spinner
   ================================= */
.spinner,
.loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-spinner.large {
  width: 48px;
  height: 48px;
  margin: 0 auto 1.5rem;
}

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

/* =================================
   Footer
   ================================= */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.813rem;
}

.footer-legal {
  margin-top: 0.5rem;
}

.footer-legal a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: var(--transition-fast);
}

.footer-legal a:hover {
  color: white;
  text-decoration: underline;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 0.5rem;
}

.footer-links a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: var(--transition-fast);
}

.footer-links a:hover {
  color: white;
}

/* =================================
   Utilities
   ================================= */
.hidden {
  display: none !important;
}

/* =================================
   Responsive
   ================================= */
@media (max-width: 520px) {
  /* Forzar altura fija del viewport para que todo quepa sin scroll */
  body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .app-container {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .main-content {
    flex: 1;
    padding: 0.25rem;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .verification-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    max-height: 100%;
    overflow: hidden;
  }

  .step-content {
    flex: 1;
    overflow: auto;
    min-height: 0;
  }

  .step-panel {
    padding: 0.75rem;
  }

  /* Solo aplicar flexbox cuando el panel está activo */
  #step2DocPanel.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    padding: 0.5rem;
  }

  .title {
    font-size: 1rem;
    margin-bottom: 0.15rem;
  }

  .subtitle {
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
  }

  .method-card {
    padding: 0.75rem;
  }

  .method-icon {
    width: 44px;
    height: 44px;
  }

  .certificate-info {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .progress-steps {
    padding: 0.5rem;
    flex-shrink: 0;
    padding-left: 2.5rem; /* Espacio para botón volver */
  }

  .header-back-button {
    width: 28px;
    height: 28px;
    left: 0.4rem;
  }

  .header-back-button svg {
    width: 14px;
    height: 14px;
  }

  .step-line {
    width: 25px;
  }

  .step-label {
    display: none;
  }

  .step-number {
    width: 26px;
    height: 26px;
    font-size: 0.8rem;
  }

  /* Doc verification flow - flexbox para distribuir espacio */
  .doc-verification-flow {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
  }

  /* Solo el capture-panel activo se muestra con flex */
  .capture-panel.active {
    display: flex;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
  }

  /* Camera containers - ocupan el espacio disponible */
  .camera-container {
    flex: 1;
    min-height: 120px;
    max-height: 45vh;
    margin-bottom: 0.5rem;
    aspect-ratio: auto;
  }

  .camera-container.selfie-mode {
    flex: 1;
    min-height: 150px;
    max-height: 50vh;
    max-width: 280px;
    margin: 0 auto 0.5rem auto;
    aspect-ratio: 3 / 4;
  }

  /* Doc substeps más compactos */
  .doc-substeps {
    margin-bottom: 0.5rem;
    padding: 0;
    flex-shrink: 0;
  }

  .substep {
    font-size: 0.65rem;
  }

  .substep-indicator {
    width: 10px;
    height: 10px;
  }

  /* Progress bar más compacto */
  .liveness-progress {
    margin-bottom: 0.35rem;
    flex-shrink: 0;
  }

  /* CRÍTICO: Botones siempre visibles - nunca se encogen */
  .capture-controls {
    gap: 0.4rem;
    flex-shrink: 0;
    margin-top: auto;
    padding-top: 0.25rem;
  }

  .capture-button,
  .primary-button,
  .secondary-button {
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    min-height: 42px;
    flex-shrink: 0;
  }

  .capture-button .capture-icon {
    width: 20px;
    height: 20px;
  }

  /* Footer compacto y siempre visible */
  .footer {
    padding: 0.5rem;
    font-size: 0.65rem;
    flex-shrink: 0; /* No permitir que se encoja */
  }

  .footer p {
    margin: 0;
    line-height: 1.3;
  }

  .footer-legal {
    margin-top: 0.15rem;
  }

  /* Header más compacto y fijo */
  .header {
    padding: 0.5rem 1rem;
    flex-shrink: 0; /* No permitir que se encoja */
  }

  .security-badge {
    padding: 0.35rem 0.75rem;
    font-size: 0.65rem;
  }

  /* Liveness challenge position */
  .liveness-challenge {
    bottom: 5px;
    gap: 0.25rem;
    padding: 0.35rem;
  }

  .challenge-icon {
    width: 36px;
    height: 36px;
  }

  #challengeText {
    font-size: 0.75rem;
  }

  /* ===== Pantalla de resultado (verificación final) compacta ===== */
  .result-content {
    padding: 1.5rem 0;
  }

  .result-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 1rem;
  }

  .result-content h2 {
    font-size: 1.25rem;
    margin-bottom: 0.35rem;
  }

  .result-content p {
    font-size: 0.85rem;
    margin-bottom: 1rem;
  }

  .verified-data {
    padding: 1rem;
    margin-bottom: 1rem;
  }

  .verified-data .data-row {
    padding: 0.35rem 0;
    font-size: 0.85rem;
  }

  .verified-data .data-label {
    font-size: 0.75rem;
  }

  .verified-data .data-value {
    font-size: 0.85rem;
    max-width: 55%;
  }

  /* Loading spinner más pequeño */
  .loading-spinner.large {
    width: 40px;
    height: 40px;
    margin-bottom: 1rem;
  }
}

/* Pantallas muy pequeñas (altura < 700px) - ajustes adicionales */
@media (max-height: 700px) and (max-width: 520px) {
  /* Camera aún más pequeña para caber en pantallas bajas */
  .camera-container {
    max-height: 38vh;
    min-height: 100px;
  }

  .camera-container.selfie-mode {
    max-height: 42vh;
    min-height: 120px;
    max-width: 180px;
  }

  /* Textos más compactos */
  .title {
    font-size: 0.9rem;
  }

  .subtitle {
    font-size: 0.7rem;
    margin-bottom: 0.3rem;
  }

  /* Botones aún más compactos */
  .capture-button,
  .primary-button,
  .secondary-button {
    padding: 0.45rem 0.6rem;
    font-size: 0.78rem;
    min-height: 36px;
  }

  /* Progress steps ultra compactos */
  .progress-steps {
    padding: 0.35rem;
    padding-left: 2rem;
  }

  .header-back-button {
    width: 24px;
    height: 24px;
    left: 0.25rem;
  }

  .header-back-button svg {
    width: 12px;
    height: 12px;
  }

  .step-number {
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
  }

  .step-line {
    width: 20px;
  }

  /* Header/Footer más compactos */
  .header {
    padding: 0.35rem 0.75rem;
  }

  .footer {
    padding: 0.25rem 0.5rem;
    font-size: 0.55rem;
  }

  /* Doc substeps más pequeños */
  .substep {
    font-size: 0.55rem;
  }

  .substep-indicator {
    width: 8px;
    height: 8px;
  }

  /* Liveness más compacto */
  .liveness-challenge {
    bottom: 3px;
    padding: 0.25rem;
  }

  .challenge-icon {
    width: 32px;
    height: 32px;
  }

  #challengeText {
    font-size: 0.7rem;
  }

  /* ===== Pantalla de resultado (verificación final) más compacta ===== */
  .result-content {
    padding: 1rem 0;
  }

  .result-icon {
    width: 50px;
    height: 50px;
    margin: 0 auto 0.75rem;
  }

  .result-content h2 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
  }

  .result-content p {
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
  }

  .verified-data {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .verified-data .data-row {
    padding: 0.3rem 0;
    font-size: 0.8rem;
  }

  .verified-data .data-label {
    font-size: 0.7rem;
  }

  .verified-data .data-value {
    font-size: 0.8rem;
  }

  /* Loading spinner más pequeño */
  .loading-spinner.large {
    width: 36px;
    height: 36px;
    margin-bottom: 0.75rem;
  }

  /* Botones de error apilados verticalmente */
  #errorResult .primary-button,
  #errorResult .secondary-button {
    margin-bottom: 0.35rem;
  }

  #errorResult .secondary-button {
    margin-bottom: 0;
  }
}

/* =================================
   Modal de error de cámara
   ================================= */
.camera-error-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1rem;
  box-sizing: border-box;
}

.camera-error-content {
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 2rem;
  max-width: 450px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease-out;
  border-top: 4px solid var(--color-primary);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.camera-error-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.camera-error-content h3 {
  color: var(--color-primary);
  margin: 0 0 1rem 0;
  font-size: 1.5rem;
}

.camera-error-message {
  color: var(--text-primary);
  text-align: left;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.camera-error-message p {
  margin: 0 0 0.75rem 0;
}

.camera-error-message ol,
.camera-error-message ul {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.camera-error-message li {
  margin-bottom: 0.5rem;
}

.camera-error-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.camera-error-buttons .btn {
  min-width: 140px;
}

.camera-retry-btn {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(242, 5, 93, 0.3);
}

.camera-retry-btn:hover {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, #a50440 100%);
  box-shadow: 0 4px 12px rgba(242, 5, 93, 0.4);
  transform: translateY(-1px);
}

.camera-reload-btn {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.camera-reload-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.browser-icon {
  display: inline-block;
  font-size: 1.1em;
  vertical-align: middle;
}

/* =================================
   Processing Indicator for Document Preview
   ================================= */
.processing-indicator {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: white;
  font-size: 1rem;
  font-weight: 500;
  z-index: 100;
  border-radius: var(--border-radius);
}

/* Asegurar que capture-preview puede contener elementos posicionados */
.capture-preview {
  position: absolute;
  /* Ya definido arriba, pero asegurar que puede ser contenedor */
}

.processing-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* =================================
   Glare Error Overlay
   ================================= */
.glare-error-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(180, 50, 50, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 110;
  border-radius: var(--border-radius);
}

.glare-error-content {
  text-align: center;
  padding: 1rem;
  color: white;
  max-width: 95%;
}

.glare-error-icon {
  display: none;
}

.glare-error-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.glare-error-message {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.glare-error-hint {
  font-size: 0.8rem;
  opacity: 0.9;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  margin-top: 0.25rem;
  line-height: 1.3;
}

/* Quality error overlay (borrosidad, documento incompleto) */
.quality-error-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(180, 40, 40, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 110;
  border-radius: var(--border-radius);
  padding: 0.5rem;
}

.quality-error-content {
  text-align: center;
  padding: 1rem;
  color: white;
  max-width: 95%;
}

.quality-error-icon {
  display: none;
}

.quality-error-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.quality-error-message {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.quality-error-hint {
  font-size: 0.8rem;
  opacity: 0.9;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  margin-top: 0.25rem;
  line-height: 1.3;
}

/* =================================
   Zoom Guide for Document Capture (PC Webcam)
   ================================= */
.zoom-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 33.33%;
  height: 33.33%;
  border: 3px dashed rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  pointer-events: none;
  z-index: 20;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.zoom-guide::before {
  content: 'Centra el DNI aquí';
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.zoom-guide::after {
  content: 'Zoom 3x al capturar';
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary);
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* Esquinas de la guía de zoom */
.zoom-guide .corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--color-primary);
  border-style: solid;
}

.zoom-guide .corner.tl {
  top: -3px;
  left: -3px;
  border-width: 3px 0 0 3px;
  border-radius: 4px 0 0 0;
}

.zoom-guide .corner.tr {
  top: -3px;
  right: -3px;
  border-width: 3px 3px 0 0;
  border-radius: 0 4px 0 0;
}

.zoom-guide .corner.bl {
  bottom: -3px;
  left: -3px;
  border-width: 0 0 3px 3px;
  border-radius: 0 0 0 4px;
}

.zoom-guide .corner.br {
  bottom: -3px;
  right: -3px;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 4px 0;
}

/* Ocultar en móvil */
@media (max-width: 768px) {
  .zoom-guide {
    display: none;
  }
}

/* =================================
   Real-time 2x Zoom for Document Capture (PC Webcam)
   El zoom hace que el usuario naturalmente aleje el documento
   para que quepa en el recuadro, resultando en texto más nítido
   ================================= */
.camera-container.zoom-mode {
  overflow: hidden;
}

/* Transición suave del zoom (efecto fade de 1s a 2x) */
.camera-container video {
  transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.camera-container.zoom-mode video {
  transform: scale(2) !important;
  transform-origin: center center;
}

/* Combinar mirror + zoom (documentos en PC) */
.camera-container.mirror-mode.zoom-mode video {
  transform: scaleX(-1) scale(2) !important;
  transform-origin: center center;
}

/* Desactivar zoom en móvil (cámaras móviles enfocan mejor de cerca) */
@media (max-width: 768px) {
  .camera-container.zoom-mode video,
  .camera-container.mirror-mode.zoom-mode video {
    transform: scaleX(-1) !important;
  }
}
