/* ==========================================================================
   Visor de documentos PDF (SitiosWeb) — visor.js
   Colores: las variables del diseño del sitio (--navy, --grad, --font), más blanco y negro.
   Si el diseño no las define (sitios anteriores al editor), se usan los valores de respaldo de cada var().
   ========================================================================== */
.swv {
  position: fixed; inset: 0; z-index: 2147483000;
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  /* La columna nunca pasa del ancho de la pantalla (un título largo no debe ensanchar el visor) */
  grid-template-columns: minmax(0, 1fr);
  width: 100%; max-width: 100vw; overflow: hidden;
  background: color-mix(in srgb, var(--navy, #19203B) 88%, #000);
  color: #fff; font-family: var(--font, system-ui, sans-serif);
  opacity: 0; transition: opacity .22s ease;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.swv.on { opacity: 1; }
html.swv-abierto, html.swv-abierto body { overflow: hidden; }

/* Barra superior */
.swv-bar {
  position: relative; z-index: 2; min-width: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px clamp(12px, 3vw, 28px);
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--navy, #19203B) 92%, #fff);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .08), 0 10px 30px rgba(0, 0, 0, .25);
  transform: translateY(-8px); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
.swv.on .swv-bar { transform: none; }
.swv-info { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.swv-ico {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--grad, linear-gradient(135deg, #1F3154, #0A7B9C)); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.swv-ico svg { width: 22px; height: 22px; }
.swv-txt { min-width: 0; flex: 1 1 auto; overflow: hidden; }
.swv-t { margin: 0; font-weight: 700; font-size: 1rem; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swv-sub { margin: 2px 0 0; display: flex; align-items: center; gap: 10px; font-size: .8rem; color: rgba(255, 255, 255, .72); white-space: nowrap; }
.swv-lock {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px 1px 6px; border-radius: 99px;
  background: rgba(255, 255, 255, .1); color: rgba(255, 255, 255, .88); font-size: .74rem;
}
.swv-lock[hidden] { display: none; }
.swv-lock svg { width: 12px; height: 12px; }

.swv-acc { display: flex; align-items: center; gap: 8px; flex: none; }
.swv-zoom { display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, .07); }
.swv-pct { min-width: 46px; text-align: center; font-size: .82rem; font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, .85); }

.swv svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.swv-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 38px; height: 38px; padding: 0 9px; border: 0; border-radius: 10px;
  background: transparent; color: #fff; font: inherit; font-size: .88rem; font-weight: 700;
  text-decoration: none; cursor: pointer; transition: background-color .18s, transform .18s;
}
.swv-btn svg { width: 20px; height: 20px; flex: none; }
.swv-btn:hover { background: rgba(255, 255, 255, .12); }
.swv-btn:active { transform: scale(.94); }
.swv-btn:disabled { opacity: .35; cursor: default; background: transparent; transform: none; }
.swv-btn:focus-visible, .swv-accion:focus-visible, .swv-scroll:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.swv-btn[hidden] { display: none; }
.swv-bajar { padding: 0 14px; background: var(--grad, linear-gradient(135deg, #1F3154, #0A7B9C)); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2); }
.swv-bajar:hover { background: var(--grad, linear-gradient(135deg, #1F3154, #0A7B9C)); filter: brightness(1.12); }
.swv-cerrar { background: rgba(255, 255, 255, .1); }

/* Avance de carga en el borde inferior de la barra */
.swv-carga { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; overflow: hidden; }
.swv-carga i { display: block; height: 100%; background: var(--grad, linear-gradient(135deg, #1F3154, #0A7B9C)); transform: scaleX(0); transform-origin: left; transition: transform .3s ease; }
.swv[data-estado="cargando"] .swv-carga i { transform: scaleX(.08); }

/* Páginas */
.swv-scroll {
  position: relative; overflow: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y;
}
.swv-pages {
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  width: max-content; min-width: 100%;
  padding: 24px 24px calc(96px + env(safe-area-inset-bottom));
  box-sizing: border-box;
}
.swv-page {
  position: relative; flex: none; background: #fff; border-radius: 4px; overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25), 0 18px 40px rgba(0, 0, 0, .3);
}
/* Mientras se dibuja: brillo suave sobre la hoja */
.swv-page::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(0, 0, 0, .045) 50%, transparent 70%) 0 0 / 220% 100%;
  animation: swv-brillo 1.3s linear infinite;
}
.swv-page.ok::before { display: none; }
.swv-page canvas { display: block; width: 100%; height: 100%; animation: swv-entra .3s ease both; }
@keyframes swv-brillo { to { background-position: -220% 0; } }
@keyframes swv-entra { from { opacity: 0; } }

/* Cargando / error */
.swv-estado {
  position: absolute; inset: 64px 0 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  padding: 24px; text-align: center; pointer-events: none;
}
.swv-estado p { margin: 0; max-width: 34ch; color: rgba(255, 255, 255, .85); line-height: 1.5; }
.swv[data-estado="listo"] .swv-estado { display: none; }
.swv[data-estado="error"] .swv-estado { pointer-events: auto; }
.swv-anillo {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .15); border-top-color: #fff;
  animation: swv-gira .8s linear infinite;
}
@keyframes swv-gira { to { transform: rotate(360deg); } }
.swv-alerta { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: rgba(255, 255, 255, .1); }
.swv-alerta svg { width: 28px; height: 28px; }
.swv-accion {
  margin-top: 4px; padding: 11px 20px; border: 0; border-radius: 99px; cursor: pointer;
  background: #fff; color: var(--navy, #19203B); font: inherit; font-weight: 700;
}

/* Navegación flotante de páginas */
.swv-nav {
  position: absolute; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 2;
  display: flex; align-items: center; gap: 4px; padding: 5px;
  border-radius: 99px; background: color-mix(in srgb, var(--navy, #19203B) 80%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(255, 255, 255, .1);
  transform: translateX(-50%);
}
.swv-nav[hidden] { display: none; }
.swv-nav .swv-btn { border-radius: 99px; }
.swv-num { min-width: 64px; text-align: center; font-size: .9rem; font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, .8); }
.swv-num b { color: #fff; }

/* Aviso breve (ej. al intentar imprimir) */
.swv-aviso {
  position: absolute; left: 50%; top: 84px; z-index: 3; margin: 0; max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px; background: #fff; color: var(--navy, #19203B); font-size: .9rem; font-weight: 700;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .3);
  opacity: 0; transform: translate(-50%, -6px); transition: opacity .2s, transform .2s;
}
.swv-aviso.on { opacity: 1; transform: translate(-50%, 0); }

/* Celular: barra compacta; el zoom se hace pellizcando o con doble toque */
@media (max-width: 640px) {
  .swv-bar { gap: 8px; padding-left: 10px; padding-right: 8px; }
  .swv-ico { width: 34px; height: 34px; border-radius: 10px; }
  .swv-ico svg { width: 19px; height: 19px; }
  /* En celular el título puede ocupar dos renglones */
  .swv-t { font-size: .9rem; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
  .swv-sub { font-size: .76rem; gap: 8px; }
  .swv-zoom, .swv-full { display: none; }
  .swv-bajar span { display: none; }
  .swv-bajar { padding: 0; width: 38px; }
  .swv-pages { gap: 10px; padding: 8px 8px calc(84px + env(safe-area-inset-bottom)); }
  .swv-page { border-radius: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .swv, .swv-bar, .swv-carga i, .swv-aviso { transition: none; }
  .swv-page::before, .swv-page canvas { animation: none; }
}

/* Sin impresión mientras el visor está abierto */
@media print {
  html.swv-abierto body { display: none !important; }
}

/* Página propia del visor (cuando el enlace se abre directo) */
.swv-solo { margin: 0; min-height: 100vh; background: color-mix(in srgb, var(--navy, #19203B) 88%, #000); font-family: var(--font, system-ui, sans-serif); }
.swv-fin {
  min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 16px;
  padding: 24px; text-align: center; color: #fff;
}
.swv-fin h1 { margin: 0; font-size: clamp(1.4rem, 4vw, 2rem); }
.swv-fin p { margin: 0; max-width: 40ch; color: rgba(255, 255, 255, .8); line-height: 1.55; }
.swv-fin .swv-accion { text-decoration: none; }
