/* ===== Colores (claro y oscuro según el celular) ===== */
:root {
  --fondo: #f4f3f0;
  --superficie: #ffffff;
  --texto: #1f1f1f;
  --suave: #6b6b6b;
  --borde: #e1dfda;
  --acento: #d6362d;
  --acento-texto: #ffffff;
  --fondo-visor: #d9d7d2;
  --barra: rgba(255, 255, 255, 0.94);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #121212;
    --superficie: #1e1e1e;
    --texto: #ececec;
    --suave: #a3a3a3;
    --borde: #2f2f2f;
    --acento: #ef5a50;
    --fondo-visor: #2a2a2a;
    --barra: rgba(30, 30, 30, 0.94);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.icono {
  width: 48px; height: 48px; flex: none;
  border: 0; border-radius: 50%;
  background: transparent;
  display: grid; place-items: center;
}
.icono svg { width: 24px; height: 24px; fill: currentColor; }
.icono:active { background: var(--borde); }

/* ===== Recientes ===== */
.inicio {
  max-width: 720px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
}
.barra-inicio { min-height: 56px; display: flex; align-items: center; }
.barra-inicio h1 { margin: 0; font-size: 1.4rem; }
.abrir {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%;
  min-height: 56px;
  border: 0; border-radius: 16px;
  background: var(--acento); color: var(--acento-texto);
  font-weight: 600; font-size: 1.05rem;
}
.abrir svg { width: 24px; height: 24px; fill: currentColor; }
.grupo { margin: 24px 4px 8px; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--suave); }
.recientes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.fila-reciente {
  display: flex; align-items: stretch;
  border: 1px solid var(--borde); border-radius: 14px;
  background: var(--superficie);
  overflow: hidden;
}
.reciente {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  text-align: left;
  padding: 12px 4px 12px 16px;
}
.reciente:active { background: var(--fondo); }
.reciente .nombre { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reciente .detalle { display: block; font-size: 0.85rem; color: var(--suave); margin-top: 2px; }
.fila-reciente .quitar {
  width: 48px; flex: none;
  border: 0; background: transparent;
  color: var(--suave); font-size: 1.5rem; line-height: 1;
}
.vacio { text-align: center; color: var(--suave); margin: 40px 16px; }
.espacio { text-align: center; color: var(--suave); font-size: 0.8rem; margin-top: 20px; }

/* ===== Visor ===== */
.visor {
  position: fixed; inset: 0;
  overflow: auto;
  background: var(--fondo-visor);
  touch-action: pan-x pan-y;      /* el pellizco lo maneja la app, no el navegador */
  overscroll-behavior: contain;
  outline: none;
}
.paginas { position: relative; padding-bottom: 88px; }
.pagina {
  position: relative;
  margin: 0 auto 8px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  --user-unit: 1;
  --total-scale-factor: calc(var(--scale-factor, 1) * var(--user-unit));
  --scale-round-x: 1px;
  --scale-round-y: 1px;
}
.lienzo { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.barra-visor {
  position: fixed; top: 0; left: 0; right: 0;
  padding-top: env(safe-area-inset-top);
  background: var(--barra);
  border-bottom: 1px solid var(--borde);
  transition: transform 0.2s ease;
  z-index: 5;
}
.fila-normal, .fila-buscar { display: flex; align-items: center; gap: 2px; min-height: 56px; padding: 0 4px; max-width: 900px; margin: 0 auto; }
.nombre-doc { flex: 1; min-width: 0; margin: 0 4px; font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fila-buscar input {
  flex: 1; min-width: 0;
  height: 40px;
  border: 1px solid var(--borde); border-radius: 20px;
  background: var(--superficie);
  padding: 0 14px;
  outline: none;
}
.fila-buscar input:focus { border-color: var(--acento); }
.conteo { min-width: 44px; text-align: center; font-size: 0.85rem; color: var(--suave); font-variant-numeric: tabular-nums; }

.indicador {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  min-width: 88px; min-height: 44px;
  padding: 0 18px;
  border: 0; border-radius: 22px;
  background: rgba(20, 20, 20, 0.82); color: #fff;
  font-weight: 600; font-variant-numeric: tabular-nums;
  transition: opacity 0.2s ease;
  z-index: 5;
}
.sin-barras .barra-visor { transform: translateY(-100%); }
.sin-barras .indicador { opacity: 0; pointer-events: none; }

.cargando {
  position: fixed; left: 50%; top: 45%;
  transform: translate(-50%, -50%);
  margin: 0; padding: 12px 20px;
  border-radius: 12px;
  background: rgba(20, 20, 20, 0.85); color: #fff;
  z-index: 20;
}

/* ===== Diálogos ===== */
.dialogo {
  width: min(92vw, 380px);
  border: 0; border-radius: 18px;
  padding: 20px;
  background: var(--superficie); color: var(--texto);
}
.dialogo::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialogo h2 { margin: 0 0 12px; font-size: 1.1rem; }
.dialogo .info { margin: 0 0 12px; color: var(--suave); font-size: 0.9rem; }
.dialogo input {
  width: 100%; height: 48px;
  border: 1px solid var(--borde); border-radius: 12px;
  background: var(--fondo);
  padding: 0 14px; font-size: 1.1rem;
}
.acciones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.acciones button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px; background: transparent; font-weight: 600; }
.acciones .principal { background: var(--acento); color: var(--acento-texto); }

/* ===== Aviso inferior ===== */
.aviso {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  min-height: 48px;
  padding: 10px 10px 10px 16px;
  border-radius: 12px;
  background: #2b2b2b; color: #f2f2f2;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  z-index: 30;
}
.aviso button { margin-left: auto; border: 0; background: transparent; color: #ff8a80; font-weight: 700; padding: 8px 10px; }

/* ===== Capa de texto de PDF.js (copiada de pdf_viewer.css de PDF.js 6.5, Apache-2.0) ===== */
.textLayer {
  color-scheme: only light;
  position: absolute;
  text-align: initial;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  letter-spacing: normal;
  word-spacing: normal;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
  z-index: 0;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}
.textLayer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  -webkit-user-select: text;
  user-select: text;
}
.textLayer > :not(.markedContent),
.textLayer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1;
  --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.textLayer .markedContent { display: contents; }
.textLayer ::selection { background: rgba(0, 0, 255, 0.25); color: transparent; }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}
.textLayer.selecting .endOfContent { top: 0; }
[data-main-rotation="90"] { transform: rotate(90deg) translateY(-100%); }
[data-main-rotation="180"] { transform: rotate(180deg) translate(-100%, -100%); }
[data-main-rotation="270"] { transform: rotate(270deg) translateX(-100%); }

/* Resultados de búsqueda */
.textLayer mark.resaltado {
  color: transparent;
  background: rgba(255, 196, 0, 0.45);
  border-radius: 2px;
  padding: 0;
}
.textLayer mark.elegido { background: rgba(255, 110, 0, 0.6); }
