/* =====================================================================
   BALCÓN DE SERVICIOS - VISOR DE PDFS ELEGANTE Y RESPONSIVE (PDF.JS)
   ===================================================================== */

/* Contenedor Modal de Pantalla Completa con Desenfoque */
.bl-visor-pdf-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 999999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  animation: blVisorFadeIn .2s ease-out;
}

@keyframes blVisorFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Tarjeta Principal del Visor */
.bl-visor-pdf-card {
  width: 95%;
  max-width: 1160px;
  height: 94vh;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
  position: relative;
  transition: all .2s ease;
}

/* Modo Pantalla Completa Expandida */
.bl-visor-pdf-card.fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  border-radius: 0 !important;
  border: none !important;
}

/* Barra Superior de Herramientas */
.bl-visor-pdf-toolbar {
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: #f8fafc;
  z-index: 10;
  user-select: none;
}

.bl-visor-pdf-titulo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 240px;
}

.bl-visor-pdf-icono {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(26, 163, 224, 0.15);
  color: #38bdf8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.bl-visor-pdf-titulo {
  font-size: 13.5px;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.bl-visor-pdf-subtitulo {
  font-size: 11px;
  color: #94a3b8;
  margin: 0;
}

/* Grupo de Controles de Zoom y Páginas */
.bl-visor-pdf-controles {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.bl-visor-pdf-btn-group {
  display: inline-flex;
  align-items: center;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.bl-visor-btn {
  background: transparent;
  color: #cbd5e1;
  border: none;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .15s ease;
  line-height: 1;
}

.bl-visor-btn:hover {
  background: #334155;
  color: #ffffff;
}

.bl-visor-btn:active {
  transform: scale(0.96);
}

.bl-visor-btn-primario {
  background: #0284c7;
  color: #ffffff;
}
.bl-visor-btn-primario:hover {
  background: #0369a1;
  color: #ffffff;
}

.bl-visor-btn-exito {
  background: #059669;
  color: #ffffff;
}
.bl-visor-btn-exito:hover {
  background: #047857;
  color: #ffffff;
}

.bl-visor-btn-peligro {
  background: #ef4444;
  color: #ffffff;
}
.bl-visor-btn-peligro:hover {
  background: #dc2626;
  color: #ffffff;
}

.bl-visor-pagina-pill {
  font-size: 11.5px;
  font-weight: 700;
  color: #e2e8f0;
  padding: 4px 8px;
  white-space: nowrap;
}

/* Área de Visualización y Lienzo de Documentos */
.bl-visor-pdf-canvas-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  background: #090d16;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

/* Cada página renderizada como hoja de papel */
.bl-visor-pagina-box {
  margin-bottom: 20px;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  background: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform .15s ease;
}

.bl-visor-pagina-box canvas {
  display: block;
  max-width: 100%;
  height: auto !important;
  border-radius: 4px;
}

/* Spinner / Estado de Carga */
.bl-visor-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #f8fafc;
  padding: 40px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.bl-visor-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: blVisorSpin 0.8s linear infinite;
}

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

/* Responsive Móvil y Tablet */
@media (max-width: 768px) {
  .bl-visor-pdf-backdrop {
    padding: 0;
  }
  .bl-visor-pdf-card {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    border-radius: 0 !important;
    border: none !important;
  }
  .bl-visor-pdf-toolbar {
    padding: 8px 12px;
    gap: 8px;
  }
  .bl-visor-pdf-titulo-wrap {
    flex: 1 1 100%;
  }
  .bl-visor-pdf-controles {
    width: 100%;
    justify-content: space-between;
  }
  .bl-visor-btn span.lbl-txt {
    display: none;
  }
  .bl-visor-btn {
    padding: 7px 10px;
    font-size: 13px;
  }
  .bl-visor-pdf-canvas-wrap {
    padding: 12px 6px;
  }
  .bl-visor-pagina-box {
    margin-bottom: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  }
}

/* =====================================================================
   MÓDULO DE ESTAMPADO DE FIRMA ELECTRÓNICA Y DESPACHO DOCUMENTAL
   ===================================================================== */

/* Botón Destacado de Firma en la Barra Superior */
.bl-visor-btn-firmar {
  background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%) !important;
  color: #ffffff !important;
  box-shadow: 0 2px 10px rgba(124, 58, 237, 0.4);
  font-weight: 700 !important;
  letter-spacing: 0.3px;
}
.bl-visor-btn-firmar:hover {
  background: linear-gradient(135deg, #6d28d9 0%, #4338ca 100%) !important;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.6);
  transform: translateY(-1px);
}
.bl-visor-btn-firmar.activo {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.4);
  animation: blPulseFirma 1.5s infinite;
}

@keyframes blPulseFirma {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* Barra flotante indicadora de "Modo Estampado Activo" */
.bl-visor-modo-estampa-bar {
  display: none;
  background: linear-gradient(90deg, #1e1b4b 0%, #312e81 100%);
  border-bottom: 2px solid #818cf8;
  color: #e0e7ff;
  padding: 10px 18px;
  font-size: 13px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 15;
  animation: blSlideDown .25s ease-out;
}
@keyframes blSlideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.bl-visor-modo-estampa-bar .bl-modo-txt {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}
.bl-visor-modo-estampa-bar .bl-modo-badge {
  background: #4f46e5;
  color: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.5px;
}

/* Modo interactivo sobre las páginas del visor */
.bl-modo-estampa-activo .bl-visor-pagina-box {
  cursor: crosshair !important;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.5) !important;
}

/* Sello Anclado en la página */
.bl-visor-sello-ancla {
  position: absolute;
  width: 193px;
  height: 50px;
  background: rgba(79, 70, 229, 0.18);
  border: 2px dashed #4f46e5;
  border-radius: 6px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  padding: 4px 8px;
  gap: 8px;
  color: #1e1b4b;
  font-family: inherit;
  font-size: 10px;
  line-height: 1.15;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.35);
  pointer-events: none;
  z-index: 5;
  animation: blPopIn .2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes blPopIn {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.bl-visor-sello-ancla .sello-qr-placeholder {
  width: 38px;
  height: 38px;
  background: #ffffff;
  border: 1px solid #c7d2fe;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4f46e5;
  font-size: 20px;
  flex-shrink: 0;
}
.bl-visor-sello-ancla .sello-txt-preview {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.bl-visor-sello-ancla .sello-txt-preview strong {
  font-size: 10.5px;
  color: #312e81;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.bl-visor-sello-ancla .sello-txt-preview span {
  font-size: 8.5px;
  color: #4338ca;
}

/* =====================================================================
   MODAL DE DESPACHO Y FIRMA ELECTRÓNICA (OVERLAY DENTRO DEL VISOR)
   ===================================================================== */
.bl-visor-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 30, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  overflow-y: auto;
  animation: blVisorFadeIn .2s ease-out;
}

.bl-visor-modal-dialog {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 16px;
  width: 100%;
  max-width: 820px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #f8fafc;
}

.bl-visor-modal-header {
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bl-visor-modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 10px;
}
.bl-visor-modal-title i {
  color: #818cf8;
}

.bl-visor-modal-body {
  padding: 22px;
  overflow-y: auto;
  max-height: 74vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Secciones del Formulario */
.bl-seccion-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bl-seccion-titulo {
  font-size: 13.5px;
  font-weight: 700;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.bl-seccion-titulo span {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bl-seccion-titulo i {
  color: #38bdf8;
}

/* Indicadores de coordenadas */
.bl-coords-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  background: #0f172a;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #334155;
}
.bl-coord-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bl-coord-label {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 600;
  text-transform: uppercase;
}
.bl-coord-val {
  font-size: 13.5px;
  font-weight: 700;
  color: #f8fafc;
}

/* Selectores y Campos */
.bl-campo-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bl-campo-label {
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
}
.bl-campo-desc {
  font-size: 11px;
  color: #94a3b8;
  margin-top: -3px;
}

.bl-input-dark {
  background: #0f172a !important;
  border: 1px solid #334155 !important;
  color: #f8fafc !important;
  border-radius: 8px !important;
  padding: 8px 12px !important;
  font-size: 13px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  outline: none !important;
  transition: border-color .15s ease;
}
.bl-input-dark:focus {
  border-color: #818cf8 !important;
  box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.25) !important;
}

/* Lista dinámica de firmantes */
.bl-firmantes-lista {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bl-firmante-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px 14px;
  gap: 12px;
}
.bl-firmante-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.bl-firmante-nombre {
  font-size: 13px;
  font-weight: 700;
  color: #f8fafc;
}
.bl-firmante-cargo {
  font-size: 11px;
  color: #94a3b8;
}

.bl-badge-rol {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.bl-badge-firmado {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Caja de Estado de Certificado */
.bl-cert-box {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.bl-cert-ico {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.bl-cert-ico.inactivo {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.bl-visor-modal-footer {
  background: #1e293b;
  border-top: 1px solid #334155;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===== Panel lateral de firma electronica ===== */
.bl-visor-cuerpo { flex: 1; display: flex; min-height: 0; align-items: stretch; justify-content: flex-start; overflow: hidden; }
.bl-visor-cuerpo .bl-visor-pdf-canvas-wrap { flex: 1; min-width: 0; }
.bl-firma-panel { display: none; width: 360px; flex: none; background: #111827; border-left: 1px solid #334155; color: #e2e8f0; flex-direction: column; min-height: 0; }
.bl-con-panel-firma .bl-firma-panel { display: flex; }
.bl-fp-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 14px 16px; border-bottom: 1px solid #1f2937; }
.bl-fp-cab h3 { margin: 0; font-size: 15px; font-weight: 800; color: #f8fafc; display: flex; gap: 8px; align-items: center; }
.bl-fp-cab small { color: #94a3b8; font-size: 12px; font-family: ui-monospace, monospace; }
.bl-fp-cuerpo { flex: 1; overflow: auto; padding: 4px 16px 12px; }
.bl-fp-cuerpo section { padding: 12px 0; border-bottom: 1px solid #1f2937; display: grid; gap: 8px; }
.bl-fp-cuerpo section:last-child { border-bottom: 0; }
.bl-fp-cuerpo h4 { margin: 0; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: #94a3b8; font-weight: 800; }
.bl-fp-cuerpo h4 small { text-transform: none; letter-spacing: 0; font-weight: 500; }
.bl-fp-pasos { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bl-fp-pasos li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; background: #1e293b; }
.bl-fp-pasos li.yo { outline: 1px solid #6366f1; }
.bl-fp-pasos li i { margin-top: 2px; } .bl-fp-pasos .ok { color: #34d399; } .bl-fp-pasos .err { color: #f87171; } .bl-fp-pasos .pend { color: #fbbf24; }
.bl-fp-pasos span { display: grid; min-width: 0; } .bl-fp-pasos strong { font-size: 13px; } .bl-fp-pasos small { font-size: 11.5px; color: #94a3b8; }
.bl-fp-aviso { margin: 4px 0 0; font-size: 12.5px; background: #1e293b; border-radius: 10px; padding: 9px 11px; color: #cbd5e1; line-height: 1.45; }
.bl-fp-ubic { margin: 0; font-size: 13px; font-weight: 700; }
.bl-fp-ayuda { color: #94a3b8; font-size: 11.5px; }
.bl-fp-cert { display: flex; gap: 10px; align-items: center; background: #1e293b; border-radius: 10px; padding: 9px 11px; }
.bl-fp-cert i { color: #fbbf24; font-size: 18px; } .bl-fp-cert.ok i { color: #34d399; }
.bl-fp-cert span { display: grid; min-width: 0; } .bl-fp-cert strong { font-size: 13px; } .bl-fp-cert small { font-size: 11.5px; color: #94a3b8; }
.bl-fp-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.bl-fp-chips:empty { display: none; }
.bl-fp-chip { display: inline-flex; align-items: center; gap: 6px; background: #1e293b; border: 1px solid #334155; border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px; }
.bl-fp-chip button { background: none; border: 0; color: #94a3b8; cursor: pointer; padding: 0 4px; }
.bl-fp-chip button:hover { color: #f87171; }
.bl-fp-pie { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid #1f2937; background: #0f172a; }
.bl-fp-pie .bl-visor-btn-firmar { padding: 9px 18px; }
.bl-firma-panel .bl-input-dark { width: 100%; box-sizing: border-box; }
.bl-firma-panel .bl-bus-lista { color: #0f172a; }
.bl-visor-btn-pulso { animation: blPulsoFirma 1.6s ease-in-out infinite; }
@keyframes blPulsoFirma { 0%, 100% { box-shadow: 0 0 0 0 rgba(124, 58, 237, .55); } 50% { box-shadow: 0 0 0 7px rgba(124, 58, 237, 0); } }
@media (prefers-reduced-motion: reduce) { .bl-visor-btn-pulso { animation: none; } }
.bl-visor-sello-ancla { cursor: grab; touch-action: none; min-width: 0; pointer-events: auto; }   /* la regla base lo dejaba sin eventos: no se podia arrastrar */
.bl-visor-sello-ancla:active { cursor: grabbing; }
@media (max-width: 860px) {
  .bl-visor-cuerpo { flex-direction: column; }
  .bl-firma-panel { width: auto; max-height: 55%; border-left: 0; border-top: 1px solid #334155; }
}

/* Copia firmada como anexo del documento o tramite de donde se abrio (ficha) */
.bl-fp-adjuntar { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0 10px; font-size: 13px; background: #14532d; color: #dcfce7; border-radius: 10px; padding: 9px 11px; cursor: pointer; line-height: 1.4; }
.bl-fp-adjuntar input { margin-top: 3px; accent-color: #22c55e; }
