/* ─────────────────────────────────────────────────────────────────────────
   viewer.css — el visor seguro (R-03 documento, R-04 mensaje), /visor.

   Pantalla completa, oscura en los dos temas (el visor no sigue el tema: el
   documento es lo único que se ve). Las medidas son las de las vistas del
   diseño, design/views/recipient/recipient-03-visor-*.html y
   recipient-04-visor-mensaje.html (estilos en línea), y sus reglas [data-tf]
   son los :hover de aquí.

   Colores: los del visor, que el diseño fija igual en claro y en oscuro
   (theme.css: --viewer-*; los que faltan, aquí, como --tf-vw-*). El papel es
   blanco siempre.

   Estados (data-tf-state en .tf-vw, los pone static/js/pages/viewer.js):
     waiting · loading · ready · offline · ending · closing · ended
   «offline» y «closing» ocultan el contenido AL MOMENTO (sin transición);
   «ending» lo difumina y lo apaga en 1 s (R-03-destruyendose).

   Corte: 760 px, el del visor del prototipo (narrow = ancho < 760), no los
   720 del resto de pantallas: por debajo, la barra compacta, sin miniaturas,
   y las páginas, las aperturas y el zoom abajo.
   ───────────────────────────────────────────────────────────────────────── */

.tf-vw {
  --tf-vw-bg: var(--viewer-bg, #0b111a);
  --tf-vw-bar: var(--viewer-bar, #121b27);
  --tf-vw-control: var(--viewer-control, #1c2735);
  --tf-vw-line: var(--viewer-line, #223043);
  --tf-vw-ink: var(--viewer-ink, #e6edf5);
  --tf-vw-muted: var(--viewer-muted, #9cadc1);
  --tf-vw-rail: #0f1620;
  --tf-vw-verified: #8fb0ff;
  --tf-vw-current: #7fa6ff;
  --tf-vw-file-ink: #c8d3e0;
  --tf-vw-card: #161f2b;
  --tf-vw-card-line: #263344;
  --tf-vw-warn: #f79009;
  --tf-vw-warn-fill: #2e2312;
  --tf-vw-warn-line: #5a4219;
  --tf-vw-ok: #12b76a;
  --tf-vw-paper: #ffffff;
  --tf-vw-paper-ink: #16263a;
  --tf-vw-thumb-head: #cfd8e3;
  --tf-vw-thumb-line: #e2e9f0;
  --tf-vw-wm-paper: var(--viewer-watermark, rgba(22, 38, 58, .12));
  --tf-vw-wm-card: var(--viewer-watermark-dark, rgba(230, 237, 245, .07));
  --focus: color-mix(in srgb, #8fb0ff 55%, transparent);

  position: fixed;
  inset: 0;
  z-index: 0;
  display: flex;
  flex-direction: column;
  background: var(--tf-vw-bg);
  color: var(--tf-vw-ink);
  color-scheme: dark;
  font-size: 14px;
  line-height: 1.5;
  text-align: start;
  /* SECURITY (A4): nada se selecciona ni se arrastra (los manejadores de
     guards.js lo cortan también). */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}
.tf-vw * { -webkit-user-drag: none; }
.tf-vw button { font-family: inherit; }

/* ── La barra ─────────────────────────────────────────────────────────── */

.tf-vw-bar {
  /* Pegada arriba (aquí no se mueve: el visor no desplaza la página): así la
     carcasa (zt/bare.html, data-zt-sticky) la cuenta en --zt-sticky-h y sus
     avisos salen debajo, no encima de «Cerrar». Sólo cuenta lo fijo o pegado. */
  position: sticky;
  top: 0;
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-height: 56px;
  padding-block: 8px;
  padding-inline: 16px 10px;
  background: var(--tf-vw-bar);
  border-bottom: 1px solid var(--tf-vw-line);
}

.tf-vw-mark { flex-shrink: 0; }

.tf-vw-head {
  display: flex;
  flex-direction: column;
  min-width: 230px;
  flex: 1 1 auto;
}
/* El título es contenido (dir="auto": un nombre latino en una interfaz en
   árabe va de izquierda a derecha y se corta por su final), pero se alinea
   con la línea de debajo, al principio de la interfaz (match-parent;
   Chromium sólo entiende -webkit-match-parent). */
.tf-vw-title {
  font-size: 14px;
  line-height: 19px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: start;
  text-align: -webkit-match-parent;
  text-align: match-parent;
}
.tf-vw-from {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--tf-vw-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Como el diseño: la línea se corta (sin puntos suspensivos) cuando no cabe. */
.tf-vw-from-text { flex-shrink: 0; }
.tf-vw-from[data-verified="false"] .tf-vw-verified { display: none; }
.tf-vw-verified { color: var(--tf-vw-verified); }
.tf-vw-file {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  font-size: 12px;
  line-height: 17px;
  color: var(--tf-vw-file-ink);
  white-space: nowrap;
}
.tf-vw-file-text { overflow: hidden; text-overflow: ellipsis; }

.tf-vw-tools { display: flex; align-items: center; gap: 2px; }
.tf-vw-pager { display: contents; }

/* Los botones de icono de la barra: 40 × 40, sin fondo (h1…h6 del diseño). */
.tf-vw-btn {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--tf-vw-ink);
  cursor: pointer;
}
.tf-vw-btn:hover:not(:disabled) { background: var(--tf-vw-control); }
/* El diseño pinta el botón desactivado igual (sólo deja de responder). */
.tf-vw-btn:disabled { cursor: default; }
.tf-vw-btn--44 { width: 44px; height: 44px; }

.tf-vw-page-label {
  min-width: 52px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.tf-vw-zoom-label {
  min-width: 46px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.tf-vw-sep { width: 1px; height: 20px; flex-shrink: 0; background: var(--tf-vw-line); }
.tf-vw-sep--tools { margin: 0 6px; }
.tf-vw-sep--close { margin: 0 4px; }

.tf-vw-chips { display: flex; align-items: center; gap: 6px; }
.tf-vw-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--tf-vw-control);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tf-vw-chip > .tf-icon { color: var(--tf-vw-muted); }
/* Menos de una hora: ámbar (texto en tinta, como todos los avisos de TFP). */
.tf-vw-chip--warn { background: var(--tf-vw-warn-fill); box-shadow: inset 0 0 0 1px var(--tf-vw-warn-line); }
.tf-vw-chip--warn > .tf-icon { color: var(--tf-vw-warn); }

.tf-vw-conn { gap: 7px; }
.tf-vw-conn .tf-pulse::before,
.tf-vw-conn .tf-pulse::after { background: var(--tf-vw-ok); }
.tf-vw-conn-spin {
  color: var(--tf-vw-warn);
  border-color: var(--tf-vw-warn);
  border-right-color: transparent;
}
.tf-vw-conn-spin { display: none; }
.tf-vw[data-tf-state="offline"] .tf-vw-conn .tf-pulse { display: none; }
.tf-vw[data-tf-state="offline"] .tf-vw-conn-spin { display: inline-block; }

/* «Cerrar» (escritorio): texto en 700, 38 px de alto. */
.tf-vw-close {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding-inline: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--tf-vw-ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.tf-vw-close:hover { background: var(--tf-vw-control); }
/* Sin encoger: su ::before le da 44 × 44 para el dedo (por debajo de 760 px). */
.tf-vw-close-icon { margin-inline-start: -8px; flex-shrink: 0; }

.tf-vw-narrow-only { display: none; }

/* ── El cuerpo: miniaturas y escenario ───────────────────────────────── */

/* El aviso de un documento de ver una vez, bajo la barra (el del mensaje va en su tarjeta). */
.tf-vw-doc-once {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--tf-vw-warn-fill);
  border-bottom: 1px solid var(--tf-vw-warn-line);
  font-size: 14px;
  line-height: 20px;
  text-align: center;
}
.tf-vw-doc-once > .tf-icon { color: var(--tf-vw-warn); }
.tf-vw[data-tf-kind="document"][data-tf-once="true"][data-tf-state="ready"] .tf-vw-doc-once { display: flex; }

.tf-vw-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

.tf-vw-thumbs {
  width: 168px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px 14px;
  border-inline-end: 1px solid var(--tf-vw-line);
  background: var(--tf-vw-rail);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tf-vw-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--tf-vw-muted);
  cursor: pointer;
}
.tf-vw-thumb[aria-current="true"] { color: var(--tf-vw-ink); }
/* La miniatura es una hoja esquemática, como en el diseño (una barra de
   título y cuatro líneas), nunca la página pintada: SECURITY (A6), una
   miniatura legible sería una copia de la página sin marca de agua. */
.tf-vw-thumb-paper {
  position: relative;
  box-sizing: border-box;
  width: 110px;
  aspect-ratio: 210 / 297;
  background: var(--tf-vw-paper);
  border-radius: 2px;
  outline: 2px solid transparent;
  outline-offset: 3px;
  padding: 12% 10%;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: hidden;
  flex-shrink: 0;
}
.tf-vw-thumb[aria-current="true"] .tf-vw-thumb-paper { outline-color: var(--tf-vw-current); }
.tf-vw-thumb-bar {
  flex-shrink: 0;
  height: 3px;
  width: 100%;
  border-radius: 2px;
  background: var(--tf-vw-thumb-line);
}
.tf-vw-thumb-bar--head { height: 4px; width: 60%; background: var(--tf-vw-thumb-head); }
.tf-vw-thumb-bar--first { margin-top: 4px; }
.tf-vw-thumb-bar--92 { width: 92%; }
.tf-vw-thumb-bar--96 { width: 96%; }
.tf-vw-thumb-bar--70 { width: 70%; }
.tf-vw-thumb-n { font-size: 12px; font-variant-numeric: tabular-nums; }

/* El escenario: la hoja centrada (margin-inline: auto, para poder desplazarse
   hasta el borde cuando el zoom la hace más ancha que la pantalla). */
.tf-vw-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: auto;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  padding: 24px 12px;
  /* Sin zoom, el gesto de lado es de la página (deslizar pasa de página) y
     el navegador sólo desplaza de arriba abajo; con zoom (o en el mensaje),
     en las dos direcciones. Pellizcar lo lleva doc-view.js, no el navegador. */
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.tf-vw-stage[data-tf-zoomed],
.tf-vw[data-tf-kind="message"] .tf-vw-stage { touch-action: pan-x pan-y; }
.tf-vw[data-tf-kind="message"] .tf-vw-stage { padding: 28px 14px; }
/* El escenario se enfoca al abrir (para desplazarlo con el teclado): sin
   anillo entonces; con él cuando se llega con el tabulador. */
.tf-vw-stage:focus { outline: none; }
.tf-vw-stage:focus-visible { outline: 2px solid var(--tf-vw-current); outline-offset: -2px; }
.tf-vw-stage[data-tf-quiet-focus]:focus-visible { outline: none; }

.tf-vw-loading {
  margin: auto;
  align-self: center;
  display: grid;
  place-items: center;
  color: var(--tf-vw-muted);
}
.tf-vw-loading-spin { width: 24px; height: 24px; }
.tf-vw[data-tf-state="loading"] .tf-vw-loading,
.tf-vw[data-tf-state="waiting"] .tf-vw-loading { display: grid; }
.tf-vw:not([data-tf-state="loading"]):not([data-tf-state="waiting"]) .tf-vw-loading { display: none; }

/* La hoja: papel blanco, su sombra, y la marca de agua encima. */
.tf-vw-page {
  position: relative;
  flex-shrink: 0;
  margin-inline: auto;
  background: var(--tf-vw-paper);
  color: var(--tf-vw-paper-ink);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px rgba(0, 0, 0, .35);
  overflow: hidden;
  text-align: start;
}
.tf-vw-page > canvas { display: block; }
/* Un texto en la hoja (TXT): sus márgenes y su letra crecen con el zoom.
   overflow: clip (no hidden): la hoja recorta igual, pero no es un contenedor
   de desplazamiento, y la franja de la marca de agua (sticky) se pega al
   escenario, que es el que se desplaza. */
.tf-vw-page--text { padding: 9% 8%; overflow: clip; }
/* La franja de la marca de un texto (doc-view.js, paintBand): del alto de lo
   que se ve, pegada arriba al desplazarse; sus márgenes negativos la sacan a
   los de la hoja y le quitan el sitio que ocuparía. Recorta su capa girada. */
.tf-vw-wm-band { position: sticky; top: 0; z-index: 2; overflow: hidden; pointer-events: none; }
.tf-vw-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }

/* Lo que se difumina o se oculta: la hoja, las miniaturas, el mensaje. */
.tf-vw-page,
.tf-vw-msg {
  filter: none;
  opacity: 1;
  transition: filter 1s ease, opacity 1s ease;
}
/* Retirado (410/403/401): se difumina y se apaga en 1 s, luego se borra. */
.tf-vw[data-tf-state="ending"] .tf-vw-page,
.tf-vw[data-tf-state="ending"] .tf-vw-msg,
.tf-vw[data-tf-state="ended"] .tf-vw-page,
.tf-vw[data-tf-state="ended"] .tf-vw-msg { filter: blur(14px); opacity: 0; }
/* Sin conexión, y al cerrar mientras contesta 35: oculto al momento
   (SECURITY-CHECKLIST D3; lo que se pidió cerrar no se queda a la vista). */
.tf-vw[data-tf-state="offline"] .tf-vw-page,
.tf-vw[data-tf-state="offline"] .tf-vw-msg,
.tf-vw[data-tf-state="resuming"] .tf-vw-page,
.tf-vw[data-tf-state="resuming"] .tf-vw-msg,
.tf-vw[data-tf-state="closing"] .tf-vw-page,
.tf-vw[data-tf-state="closing"] .tf-vw-msg { filter: blur(18px); opacity: 0; transition: none; }

/* La marca de agua: en mosaico, a −30°, encima de todo lo de la hoja y sin
   recibir el puntero (SECURITY-CHECKLIST A6). La pinta watermark.js. */
.tf-vw-wm {
  position: absolute;
  inset: -60%;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  transform: rotate(-30deg);
  pointer-events: none;
}
.tf-vw-wm > span { font-weight: 500; white-space: nowrap; }
.tf-vw-wm--paper > span { color: var(--tf-vw-wm-paper); }
.tf-vw-wm--card { gap: 30px 40px; }
.tf-vw-wm--card > span { font-size: 11px; color: var(--tf-vw-wm-card); }

/* ── R-04 · el mensaje ───────────────────────────────────────────────── */

.tf-vw-msg {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 640px;
  margin-inline: auto;
  background: var(--tf-vw-card);
  border: 1px solid var(--tf-vw-card-line);
  border-radius: 18px;
  padding: 26px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.tf-vw-msg > :not(.tf-vw-wm) { position: relative; z-index: 1; }
.tf-vw-msg-once {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--tf-vw-warn-fill);
  border: 1px solid var(--tf-vw-warn-line);
  font-size: 14px;
  line-height: 20px;
}
.tf-vw-msg-once > .tf-icon { color: var(--tf-vw-warn); }
.tf-vw-msg-from { font-size: 12.5px; color: var(--tf-vw-muted); }
.tf-vw-msg-subject { margin: 0; font-size: 22px; line-height: 29px; font-weight: 700; letter-spacing: -0.2px; overflow-wrap: anywhere; }
.tf-vw-msg-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 16px;
  line-height: 26px;
  color: var(--tf-vw-ink);
  overflow-wrap: anywhere;
}
.tf-vw-msg-body p,
.tf-vw-msg-body ul { margin: 0; }
.tf-vw-msg-body ul { padding: 0; padding-inline-start: 20px; }
.tf-vw-msg-body a { color: var(--tf-vw-verified); text-decoration: underline; }
.tf-vw-msg-note {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--tf-vw-card-line);
  font-size: 12px;
  color: var(--tf-vw-muted);
}

/* ── «Sin conexión» (R-03-sin-conexion) ──────────────────────────────── */

.tf-vw-offline {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}
.tf-vw-offline-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 340px;
}
.tf-vw-offline-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--tf-vw-warn-fill);
  border: 1px solid var(--tf-vw-warn-line);
  color: var(--tf-vw-warn);
  display: grid;
  place-items: center;
  font-family: "Material Symbols Rounded";
  font-weight: 300;
  font-size: 28px;
  line-height: 1;
  font-feature-settings: "liga";
}
.tf-vw-offline-title { font-size: 17px; font-weight: 700; }
.tf-vw-offline-text { font-size: 13.5px; line-height: 20px; color: var(--tf-vw-muted); }
.tf-vw-offline-retry {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--tf-vw-control);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.tf-vw-spin-warn { color: var(--tf-vw-warn); }
/* «Reintentar ahora»: discreto, como «Cerrar» (el final «Sin conexión» lo
   lleva igual). No está en la vista R-03-sin-conexion: cuelga debajo del
   bloque, sin moverlo de donde lo pone el diseño. */
.tf-vw-retry {
  position: absolute;
  top: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  white-space: nowrap;
  padding-inline: 10px 14px;
  border: 1px solid var(--tf-vw-line);
  border-radius: 10px;
  background: transparent;
  color: var(--tf-vw-ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.tf-vw-retry:hover:not(:disabled) { background: var(--tf-vw-control); }
.tf-vw-retry:disabled { opacity: .6; cursor: default; }

/* ── La barra de abajo (sólo a 760 px o menos, sólo el documento) ────── */

.tf-vw-bottom {
  flex-shrink: 0;
  display: none;
  flex-direction: column;
  background: var(--tf-vw-bar);
  border-top: 1px solid var(--tf-vw-line);
}
.tf-vw-swipe-hint { text-align: center; font-size: 11.5px; color: var(--tf-vw-muted); padding-top: 6px; }
.tf-vw-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 54px;
  padding: 0 8px;
}
.tf-vw-bottom-pager { display: flex; align-items: center; }
.tf-vw-page-label--bottom { font-size: 13.5px; }
.tf-vw-bottom-end { display: flex; align-items: center; gap: 2px; }

/* ── Por tipo de contenido ───────────────────────────────────────────── */

/* El mensaje: ni herramientas, ni aperturas, ni barra de abajo (R-04). */
.tf-vw[data-tf-kind="message"] .tf-vw-tools,
.tf-vw[data-tf-kind="message"] .tf-vw-opens,
.tf-vw[data-tf-kind="message"] .tf-vw-bottom { display: none !important; }
/* Una imagen o un texto: una sola hoja, sin páginas ni miniaturas. */
.tf-vw:not([data-tf-format="pdf"]) [data-tf-thumbs-toggle],
.tf-vw:not([data-tf-format="pdf"]) .tf-vw-pager,
.tf-vw:not([data-tf-format="pdf"]) .tf-vw-bottom-pager,
.tf-vw:not([data-tf-format="pdf"]) .tf-vw-swipe-hint { display: none; }
.tf-vw:not([data-tf-format="pdf"]) .tf-vw-bottom-row { justify-content: flex-end; }
.tf-vw[data-tf-thumbs-open="false"] .tf-vw-thumbs { display: none; }

/* ── Móvil: 760 px o menos ───────────────────────────────────────────── */

@media (max-width: 759.98px) {
  .tf-vw-bar { flex-wrap: nowrap; }
  .tf-vw-mark,
  .tf-vw-tools,
  .tf-vw-chips > .tf-vw-opens,
  .tf-vw-sep--close,
  .tf-vw-close,
  .tf-vw-thumbs,
  .tf-vw-wide-only { display: none !important; }
  .tf-vw-narrow-only { display: inline; }
  .tf-vw-head { min-width: 0; }
  /* Desde un fichero: la línea corta en lugar de «De Marta Ruiz…». */
  .tf-vw[data-tf-via="file"] .tf-vw-from { display: none; }
  .tf-vw-bottom { display: flex; }
  /* 44 px para el dedo (el diseño dibuja la «×» de 40). */
  .tf-vw-close-icon::before { content: ""; position: absolute; inset: -2px; }
}
@media (min-width: 760px) {
  .tf-vw-close-icon,
  .tf-vw-bottom { display: none !important; }
}

/* ── Sin movimiento: el último fotograma ──────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .tf-vw-page,
  .tf-vw-msg { transition: none; }
}

/* ── SECURITY (A5): al imprimir, nada; sólo la nota ─────────────────── */
.tf-vw-print-note { display: none; }
@media print {
  .tf-vw { position: static; background: #ffffff; color: #16263a; }
  .tf-vw > :not(.tf-vw-print-note) { display: none !important; }
  .tf-vw-print-note { display: block !important; margin: 48px 24px; font-size: 14px; text-align: center; }
  .tf-sprite { display: none !important; }
}
