/* estilo.css */

:root {
  --verde: #3B5A2F;
  --verde-claro: #5C7A4A;
  --verde-palido: #E8F0E4;
  --tierra: #8B6347;
  --tierra-claro: #C4956A;
  --crema: #F7F3EE;
  --crema-oscuro: #EDE7DC;
  --texto: #2A2217;
  --texto-medio: #5A5144;
  --texto-suave: #8A7E72;
  --blanco: #FEFCF9;
  --borde: rgba(59,90,47,0.15);
  --sombra: 0 4px 24px rgba(42,34,23,0.08);
  --radio: 4px;
  --radio-lg: 8px;
}

* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
}

body { 
  font-family: 'Source Sans 3', sans-serif; 
  background: var(--crema); 
  color: var(--texto); 
  min-height: 100vh; 
  font-size: 16px; 
  line-height: 1.6; 
}

/* Cabecera / Header */
header {
  background: var(--verde);
  padding: 1.5rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--sombra);
}

.logo-area { 
  display: flex; 
  align-items: center; 
  gap: 1rem; 
}

.logo-icon { 
  width: 42px; 
  height: 42px; 
  background: var(--tierra-claro); 
  border-radius: 50%; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  font-size: 20px; 
}

.logo-text h1 { 
  font-family: 'Playfair Display', serif; 
  color: var(--crema); 
  font-size: 1.3rem; 
  font-weight: 600; 
  letter-spacing: 0.02em; 
}

.logo-text p { 
  color: rgba(247,243,238,0.65); 
  font-size: 0.78rem; 
  font-weight: 300; 
  letter-spacing: 0.08em; 
  text-transform: uppercase; 
}

.header-badge { 
  background: rgba(255,255,255,0.12); 
  border: 1px solid rgba(255,255,255,0.2); 
  color: var(--crema); 
  font-size: 0.75rem; 
  padding: 0.35rem 0.85rem; 
  border-radius: 20px; 
  letter-spacing: 0.04em; 
}

/* Contenedor central */
.container { 
  max-width: 960px; 
  margin: 0 auto; 
  padding: 2.5rem 1.5rem; 
}

/* Stepper (Pasos) */
.stepper { 
  display: flex; 
  align-items: center; 
  margin-bottom: 2.5rem; 
  background: var(--blanco); 
  border: 1px solid var(--borde); 
  border-radius: var(--radio-lg); 
  overflow: hidden; 
  box-shadow: var(--sombra); 
}

.step { 
  flex: 1; 
  display: flex; 
  align-items: center; 
  gap: 0.6rem; 
  padding: 1rem 1.2rem; 
  font-size: 0.82rem; 
  color: var(--texto-suave); 
  border-right: 1px solid var(--borde); 
}

.step:last-child { 
  border-right: none; 
}

.step.active { 
  background: var(--verde-palido); 
  color: var(--verde); 
}

.step.done { 
  background: var(--crema-oscuro); 
  color: var(--texto-medio); 
}

.step-num { 
  width: 24px; 
  height: 24px; 
  border-radius: 50%; 
  background: var(--crema-oscuro); 
  color: var(--texto-suave); 
  font-size: 0.75rem; 
  font-weight: 600; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  flex-shrink: 0; 
}

.step.active .step-num { 
  background: var(--verde); 
  color: white; 
}

.step.done .step-num {
  background: var(--verde);
  color: white;
  font-size: 0;
}

.step.done .step-num::after {
  content: "✓";
  font-size: 14px;
  font-weight: 700;
}

.step-label { 
  font-weight: 500; 
  white-space: nowrap; 
}

/* Paneles de navegación */
.panel { 
  display: none; 
  animation: fadeIn 0.3s ease; 
}

.panel.active { 
  display: block; 
}

@keyframes fadeIn { 
  from { opacity: 0; transform: translateY(8px); } 
  to { opacity: 1; transform: translateY(0); } 
}

/* Tarjetas (Cards) */
.card { 
  background: var(--blanco); 
  border: 1px solid var(--borde); 
  border-radius: var(--radio-lg); 
  padding: 2rem; 
  box-shadow: var(--sombra); 
  margin-bottom: 1.5rem; 
}

.card-title { 
  font-family: 'Playfair Display', serif; 
  font-size: 1.25rem; 
  color: var(--verde); 
  margin-bottom: 0.4rem; 
  font-weight: 600;
}

.card-subtitle { 
  font-size: 0.875rem; 
  color: var(--texto-suave); 
  margin-bottom: 1.5rem; 
  font-weight: 300; 
}

/* Tarjetas Dinámicas de Viajeros (Múltiples) */
.tarjeta-viajero {
  border: 1px solid var(--borde);
  border-radius: var(--radio-lg);
  padding: 2rem;
  background: var(--blanco);
  margin-bottom: 2rem;
  box-shadow: var(--sombra);
}

.tarjeta-viajero-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  border-bottom: 1px dashed var(--borde);
  padding-bottom: 0.8rem;
}

.tarjeta-viajero-titulo {
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  color: var(--verde);
  font-size: 1.15rem;
}

.btn-eliminar {
  background: none;
  border: none;
  color: #993C1D;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-eliminar:hover {
  color: #ff0000;
}

/* Grid de carga del DNI */
.dni-grid { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 1.5rem; 
  margin-bottom: 1.5rem; 
}

.dni-upload { 
  border: 2px dashed var(--borde); 
  border-radius: var(--radio-lg); 
  padding: 1.5rem; 
  text-align: center; 
  cursor: pointer; 
  transition: all 0.2s; 
  background: var(--crema); 
  position: relative; 
  min-height: 160px; 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: center; 
}

.dni-upload:hover { 
  border-color: var(--verde-claro); 
  background: var(--verde-palido); 
}

.dni-upload.loaded { 
  border-color: var(--tierra-claro); 
  border-style: solid; 
  background: #FDF6EF; 
}

.dni-upload input[type=file] { 
  position: absolute; 
  inset: 0; 
  opacity: 0; 
  cursor: pointer; 
  width: 100%; 
  height: 100%; 
}

.dni-icon { 
  font-size: 2.2rem; 
  margin-bottom: 0.5rem; 
}

.dni-label { 
  font-size: 0.82rem; 
  font-weight: 600; 
  color: var(--texto-medio); 
  text-transform: uppercase; 
  letter-spacing: 0.06em; 
  margin-bottom: 0.25rem; 
}

.dni-hint { 
  font-size: 0.75rem; 
  color: var(--texto-suave); 
}

.dni-preview { 
  max-width: 100%; 
  max-height: 110px; 
  border-radius: 4px; 
  object-fit: contain; 
  display: none; 
  margin-bottom: 0.5rem; 
}

/* Progreso del OCR */
.ocr-progress { 
  display: none; 
  margin-bottom: 1.5rem; 
}

.ocr-progress.active { 
  display: block; 
}

.ocr-step { 
  display: flex; 
  align-items: center; 
  gap: 0.75rem; 
  padding: 0.6rem 0.85rem; 
  border-radius: var(--radio); 
  font-size: 0.85rem; 
  margin-bottom: 0.5rem; 
  transition: all 0.2s; 
  background: var(--crema-oscuro); 
  color: var(--texto-suave); 
}

.ocr-step.running { 
  background: #EEF4FF; 
  color: #185FA5; 
  border: 1px solid #B5D4F4; 
}

.ocr-step.done { 
  background: var(--verde-palido); 
  color: var(--verde); 
  border: 1px solid rgba(59,90,47,0.2); 
}

.ocr-step.error { 
  background: #FAECE7; 
  color: #993C1D; 
  border: 1px solid rgba(216,90,48,0.3); 
}

.spinner { 
  width: 16px; 
  height: 16px; 
  border: 2px solid rgba(24,95,165,0.25); 
  border-top-color: #185FA5; 
  border-radius: 50%; 
  animation: spin 0.7s linear infinite; 
  flex-shrink: 0; 
}

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

.step-icon { 
  width: 16px; 
  height: 16px; 
  flex-shrink: 0; 
  text-align: center; 
  font-size: 14px; 
  line-height: 16px; 
}

/* Raw MRZ Debug */
.mrz-raw { 
  font-family: monospace; 
  font-size: 0.78rem; 
  background: #1E2A1A; 
  color: #A8C795; 
  padding: 0.6rem 1rem; 
  border-radius: var(--radio); 
  letter-spacing: 0.08em; 
  word-break: break-all; 
  margin-top: 0.75rem; 
  display: none; 
}

/* Estilo de los campos (Inputs/Selects) */
.field { 
  display: flex; 
  flex-direction: column; 
  gap: 0.35rem; 
}

.field label { 
  font-size: 0.8rem; 
  font-weight: 600; 
  color: var(--texto-medio); 
  text-transform: uppercase; 
  letter-spacing: 0.06em; 
}

.field input, .field select { 
  background: var(--crema); 
  border: 1px solid var(--borde); 
  border-radius: var(--radio); 
  padding: 0.6rem 0.85rem; 
  font-family: 'Source Sans 3', sans-serif; 
  font-size: 0.9rem; 
  color: var(--texto); 
  outline: none; 
  transition: border-color 0.2s, box-shadow 0.2s; 
  width: 100%; 
}

.field input:focus, .field select:focus { 
  border-color: var(--verde-claro); 
  box-shadow: 0 0 0 3px rgba(59,90,47,0.1); 
  background: var(--blanco); 
}

/* ⚠️ COLOR INDICATIVO PARA CAMPOS RELLENADOS CON OCR */
.field input.ocr-filled { 
  border-color: var(--tierra-claro); 
  background: #FDF6EF; 
}

.field.full { 
  grid-column: 1 / -1; 
}

.req::after { 
  content: ' *'; 
  color: #D85A30; 
}

/* Secciones internas del formulario */
.form-section { 
  margin-bottom: 1.5rem; 
}

.form-section-title { 
  font-size: 0.75rem; 
  font-weight: 600; 
  text-transform: uppercase; 
  letter-spacing: 0.1em; 
  color: var(--tierra); 
  margin-bottom: 1rem; 
  padding-bottom: 0.5rem; 
  border-bottom: 1px solid var(--crema-oscuro); 
}

.form-grid { 
  display: grid; 
  grid-template-columns: repeat(3, 1fr); 
  gap: 1rem; 
}

.form-grid .f-full { 
  grid-column: 1 / -1; 
}

.form-grid .f-two { 
  grid-column: span 2; 
}

/* Botones */
.btn { 
  display: inline-flex; 
  align-items: center; 
  gap: 0.5rem; 
  padding: 0.7rem 1.5rem; 
  border-radius: var(--radio); 
  font-family: 'Source Sans 3', sans-serif; 
  font-size: 0.9rem; 
  font-weight: 600; 
  cursor: pointer; 
  transition: all 0.15s; 
  border: none; 
  letter-spacing: 0.03em; 
}

.btn-primary { 
  background: var(--verde); 
  color: white; 
}

.btn-primary:hover { 
  background: var(--verde-claro); 
}

.btn-primary:active { 
  transform: scale(0.98); 
}

.btn-primary:disabled { 
  background: var(--crema-oscuro); 
  color: var(--texto-suave); 
  cursor: not-allowed; 
  transform: none; 
}

.btn-secondary { 
  background: transparent; 
  color: var(--verde); 
  border: 1px solid var(--verde); 
}

.btn-secondary:hover { 
  background: var(--verde-palido); 
}

.btn-row { 
  display: flex; 
  gap: 0.75rem; 
  align-items: center; 
  margin-top: 1.5rem; 
  flex-wrap: wrap; 
}

/* Alertas */
.alert { 
  padding: 0.85rem 1.1rem; 
  border-radius: var(--radio); 
  font-size: 0.85rem; 
  margin-bottom: 1rem; 
}

.alert-info { 
  background: #EEF4FF; 
  border: 1px solid #B5D4F4; 
  color: #185FA5; 
}

.alert-warn { 
  background: #FAEEDA; 
  border: 1px solid rgba(186,117,23,0.3); 
  color: #854F0B; 
}

.alert-ok { 
  background: var(--verde-palido); 
  border: 1px solid rgba(59,90,47,0.25); 
  color: var(--verde); 
}

/* Tablas del Resumen */
.resumen-tabla { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 0.875rem; 
}

.resumen-tabla td { 
  padding: 0.55rem 0; 
  border-bottom: 1px solid var(--crema-oscuro); 
  vertical-align: top; 
}

.resumen-tabla td:first-child { 
  color: var(--texto-suave); 
  width: 40%; 
  font-size: 0.8rem; 
  text-transform: uppercase; 
  letter-spacing: 0.05em; 
  padding-right: 1rem; 
}

.resumen-tabla td:last-child { 
  font-weight: 500; 
}

/* Caja de Captcha */
.captcha-card { 
  background: var(--crema-oscuro); 
  border: 1px solid var(--borde); 
  border-radius: var(--radio-lg); 
  padding: 1.5rem; 
  margin-top: 1.5rem; 
}

/* Pantalla final de Éxito / Resultado */
.result-box { 
  text-align: center; 
  padding: 3rem 2rem; 
}

.result-icon { 
  font-size: 3.5rem; 
  margin-bottom: 1rem; 
  display: block; 
}

.result-title { 
  font-family: 'Playfair Display', serif; 
  font-size: 1.6rem; 
  margin-bottom: 0.5rem; 
}

.result-msg { 
  color: var(--texto-suave); 
  font-size: 0.9rem; 
  max-width: 400px; 
  margin: 0 auto 2rem; 
}

.ref-box { 
  display: inline-block; 
  background: var(--verde-palido); 
  border: 1px solid rgba(59,90,47,0.25); 
  border-radius: var(--radio); 
  padding: 0.75rem 1.5rem; 
  font-family: monospace; 
  font-size: 0.9rem; 
  color: var(--verde); 
  margin-bottom: 1.5rem; 
  letter-spacing: 0.05em; 
}

footer { 
  text-align: center; 
  padding: 2rem; 
  font-size: 0.78rem; 
  color: var(--texto-suave); 
  border-top: 1px solid var(--borde); 
  margin-top: 2rem; 
}

/* Responsivo para móviles */
@media (max-width: 640px) {
  .dni-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; } /* Colapsa a 1 columna en móviles */
  header { padding: 1rem; }
  .header-badge { display: none; }
  .stepper { display: none; } /* Oculta la barra de pasos en pantallas pequeñas */
}

/* 🔎 ESTILOS PARA EL DESPLEGABLE CON BUSCADOR DINÁMICO */
.custom-select-wrapper {
  position: relative;
  width: 100%;
}

.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--crema);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 0.6rem 0.85rem;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.9rem;
  color: var(--texto);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
}

.custom-select-trigger:hover {
  border-color: var(--verde-claro);
  background: var(--blanco);
}

.custom-select-trigger::after {
  content: "▼";
  font-size: 0.7rem;
  color: var(--texto-suave);
  margin-left: 0.5rem;
  transition: transform 0.2s;
}

.custom-select-wrapper.open .custom-select-trigger::after {
  transform: rotate(180deg);
}

.custom-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: var(--radio-lg);
  margin-top: 5px;
  box-shadow: var(--sombra);
  z-index: 999;
  display: none;
  max-height: 280px;
  overflow: hidden;
  animation: fadeIn 0.15s ease;
}

.custom-select-wrapper.open .custom-dropdown-menu {
  display: flex;
  flex-direction: column;
}

.custom-search-input {
  width: calc(100% - 16px) !important;
  margin: 8px !important;
  padding: 8px 12px !important;
  border: 1px solid var(--borde) !important;
  border-radius: var(--radio) !important;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  box-sizing: border-box;
}

.custom-search-input:focus {
  border-color: var(--verde-claro) !important;
  box-shadow: 0 0 0 2px rgba(92, 122, 74, 0.15) !important;
}

.custom-options-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 180px;
  overflow-y: auto;
}

.custom-option {
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--texto);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.custom-option:hover {
  background: var(--crema-oscuro);
}

.custom-option.selected {
  background: var(--verde-palido);
  color: var(--verde);
  font-weight: 600;
}

/* Validación de campos */
.campo-error {
  border-color: #e74c3c !important;
  background-color: #fff9f9 !important;
  box-shadow: 0 0 0 2px rgba(231,76,60,0.15) !important;
}

.alerta-errores {
  background: #fff5f5;
  border: 1px solid #e74c3c;
  border-radius: var(--radio);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  color: #c0392b;
  font-size: 0.85rem;
  line-height: 1.5;
}

.alerta-errores strong {
  display: block;
  margin-bottom: 0.4rem;
}

.alerta-errores ul {
  margin: 0.25rem 0 0 1.25rem;
}

.alerta-errores li {
  margin-bottom: 0.2rem;
}

/* Botón copiar datos del titular */
.btn-copiar-titular {
  background: transparent;
  border: 1px solid var(--tierra-claro);
  color: var(--tierra);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radio);
  font-size: 0.78rem;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-copiar-titular:hover {
  background: var(--tierra-claro);
  color: var(--blanco);
}

/* Spinner de carga inicial */
.spinner-grande {
  width: 40px;
  height: 40px;
  border: 3px solid var(--verde-palido);
  border-top-color: var(--verde);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

/* Toast de autoguardado */
#toast-guardado {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--verde);
  color: var(--crema);
  padding: 0.55rem 1.1rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 9998;
  pointer-events: none;
}

#toast-guardado.visible {
  opacity: 1;
  transform: translateY(0);
}

/* CSS de impresión */
@media print {
  header, .stepper, footer, #cookie-banner,
  .btn-row, .captcha-card, .ocr-progress,
  .dni-upload, #errores-panel1, #errores-panel2,
  #toast-guardado { display: none !important; }

  body { background: white !important; }

  .container { padding: 0.5rem !important; max-width: 100% !important; }

  .card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    padding: 1rem !important;
    break-inside: avoid;
  }

  .panel { display: none !important; }
  .panel.active { display: block !important; }

  .resumen-tabla td { padding: 0.4rem 0.6rem !important; }

  .result-box { border: 1px solid #ccc !important; box-shadow: none !important; }

  a { color: inherit !important; text-decoration: none !important; }
}