/*
 * Inline PDF viewer (material file page) — /js/pdf-viewer.js.
 *
 * Two halves:
 *   1. Our viewer chrome (.pdfviewer-*): toolbar, scroll box, page cards.
 *   2. The .textLayer block, carried over from pdf.js 6.2.108's
 *      web/pdf_viewer.css — the selectable-text overlay pdf.js positions on
 *      top of each canvas. Upstream writes it with native CSS nesting; it is
 *      FLATTENED here, because a browser new enough to run the pdf.js module
 *      but too old for nesting would otherwise drop position/color on the
 *      spans and paint garbled duplicate text over the canvas. Keep it in
 *      sync when upgrading /js/pdfjs/ (see VENDOR.md there); the variable
 *      names (--total-scale-factor & friends) are pdf.js's contract, not
 *      ours. Search/edit-mode rules were dropped, we use neither.
 *
 * JS sets --scale-factor on .pdfviewer-pages and --user-unit per page.
 */

.pdfviewer {
  overflow: hidden; /* clip page shadows to the rounded border */
}

.pdfviewer-toolbar {
  display: flex;
  flex-wrap: wrap; /* ~320px screens (or large text-size zoom): second row beats clipped buttons */
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}
.pdfviewer-toolbar .pdfviewer-zoomout {
  margin-left: auto;
}
/* The ‹ › − + glyph buttons: keep them square-ish and the glyphs centered. */
.pdfviewer-toolbar .btn {
  min-width: 2rem;
  line-height: 1;
}

.pdfviewer-body {
  display: flex;
  align-items: stretch;
}

.pdfviewer-pages {
  position: relative; /* offsetTop of pages is measured against this box */
  flex: 1 1 auto;
  min-width: 0;
  max-height: 75vh;
  overflow: auto;
  /* Reserve the scrollbar's track up front: without this, the first fit-width
     render makes the scrollbar appear, which narrows the box, which triggers
     a second fit at a slightly smaller zoom — every load rendered twice. */
  scrollbar-gutter: stable;
  background: #e9e7e4;
}

/* Page overview sidebar (thumbnails, toggled from the toolbar). */
.pdfviewer-thumbs {
  position: relative; /* thumb offsetTop is measured against this box */
  flex: 0 0 156px;
  max-height: 75vh;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 8px;
  border-right: 1px solid var(--bs-border-color, #dee2e6);
  background: #f1efec;
}
@media (max-width: 575.98px) {
  .pdfviewer-thumbs {
    flex-basis: 112px;
  }
}

.pdfviewer-thumb {
  display: block;
  width: 100%;
  margin: 0 0 10px;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
}
.pdfviewer-thumbframe {
  display: block;
  width: 100%;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.pdfviewer-thumbframe canvas {
  display: block;
  width: 100%;
  height: auto;
}
.pdfviewer-thumbnum {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  color: #6c757d;
  margin-top: 2px;
}
/* Active page: brand-red accent (an active-state marker, like the active
   pagination box — not link text, which must never be red). */
.pdfviewer-thumb.is-current .pdfviewer-thumbframe {
  outline: 2px solid #ec3013;
  outline-offset: 1px;
}
.pdfviewer-thumb.is-current .pdfviewer-thumbnum {
  color: #ec3013;
  font-weight: 600;
}

/* Fullscreen: the viewer root becomes the fullscreen element; the body row
   grows to fill the screen and the 75vh caps come off. Fit-width re-fits by
   itself via the ResizeObserver. */
.pdfviewer:fullscreen {
  display: flex;
  flex-direction: column;
  background: #fff;
}
.pdfviewer:fullscreen .pdfviewer-body {
  flex: 1 1 auto;
  min-height: 0;
}
.pdfviewer:fullscreen .pdfviewer-pages,
.pdfviewer:fullscreen .pdfviewer-thumbs {
  max-height: none;
}

.pdfviewer-loading {
  padding: 1rem;
  margin: 0;
}

.pdfviewer-page {
  /* pdf.js layer-sizing contract (mirrors the .page rule of its viewer):
     setLayerDimensions() sizes the text layer via these variables. */
  --user-unit: 1;
  --total-scale-factor: calc(var(--scale-factor) * var(--user-unit));
  --scale-round-x: 1px;
  --scale-round-y: 1px;

  position: relative;
  margin: 12px auto;
  background: #fff; /* documents stay paper-white in dark mode too */
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  direction: ltr;
}

.pdfviewer-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ------------------------------------------------------------------ *
 * pdf.js text layer — from pdfjs-dist 6.2.108 web/pdf_viewer.css,
 * flattened (see header comment).
 * ------------------------------------------------------------------ */

.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;
     -moz-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 span,
.textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  -webkit-user-select: text;
     -moz-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 span[role="img"] {
  -webkit-user-select: none;
     -moz-user-select: none;
          user-select: none;
  cursor: default;
}

.textLayer ::-moz-selection {
  background: rgba(0 0 255 / 0.25);
  background: color-mix(in srgb, AccentColor, transparent 50%);
  color: transparent;
}

.textLayer ::selection {
  background: rgba(0 0 255 / 0.25);
  background: color-mix(in srgb, AccentColor, transparent 50%);
  color: transparent;
}

.textLayer br::-moz-selection {
  background: 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;
     -moz-user-select: none;
          user-select: none;
}
