/* styles.css — the default look of the built-in viewer.
 *
 * Every colour, radius and spacing is a CSS custom property on the root
 * element, so a host app can retheme the viewer without touching the JS:
 *
 *   .my-viewer { --wpdf-accent: #6ee7b7; --wpdf-bg: #0b0f19; }
 *
 * The `theme` option in JS writes the same variables inline, which wins over
 * these defaults without needing a stylesheet.
 */

.wpdf-root {
  --wpdf-bg: #525659;
  --wpdf-toolbar-bg: #323639;
  --wpdf-toolbar-fg: #f1f3f4;
  --wpdf-toolbar-border: rgba(255, 255, 255, 0.08);
  --wpdf-page-bg: #ffffff;
  --wpdf-page-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  --wpdf-accent: #8ab4f8;
  --wpdf-accent-fg: #202124;
  --wpdf-muted: #9aa0a6;
  --wpdf-radius: 6px;
  --wpdf-gap: 8px;
  --wpdf-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --wpdf-highlight: rgba(255, 214, 0, 0.35);
  --wpdf-link-hover: rgba(30, 120, 255, 0.14);
  --wpdf-link-ring: rgba(30, 120, 255, 0.45);

  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--wpdf-bg);
  color: var(--wpdf-toolbar-fg);
  font-family: var(--wpdf-font);
  position: relative;
}

/* toolbar */
.wpdf-toolbar {
  display: flex;
  align-items: center;
  gap: var(--wpdf-gap);
  padding: 6px 10px;
  background: var(--wpdf-toolbar-bg);
  border-bottom: 1px solid var(--wpdf-toolbar-border);
  color: var(--wpdf-toolbar-fg);
  font-size: 13px;
  flex: 0 0 auto;
  user-select: none;
}
.wpdf-toolbar--hidden { display: none; }
.wpdf-toolbar__spacer { flex: 1 1 auto; }
.wpdf-toolbar__group { display: flex; align-items: center; gap: 4px; }
.wpdf-toolbar__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40ch;
  color: var(--wpdf-toolbar-fg);
  opacity: 0.9;
}
.wpdf-button {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1;
  padding: 5px 8px;
  border-radius: calc(var(--wpdf-radius) - 2px);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.wpdf-button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }
.wpdf-button:active:not(:disabled) { background: rgba(255, 255, 255, 0.16); }
.wpdf-button:focus-visible { outline: 2px solid var(--wpdf-accent); outline-offset: 1px; }
.wpdf-button:disabled { opacity: 0.4; cursor: default; }
.wpdf-button--active { background: color-mix(in srgb, var(--wpdf-accent) 25%, transparent); }
.wpdf-input {
  width: 4ch;
  text-align: center;
  font: inherit;
  color: inherit;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--wpdf-toolbar-border);
  border-radius: calc(var(--wpdf-radius) - 2px);
  padding: 4px 2px;
}
.wpdf-select {
  font: inherit;
  color: inherit;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--wpdf-toolbar-border);
  border-radius: calc(var(--wpdf-radius) - 2px);
  padding: 4px 6px;
}

/* body: thumbnail rail + viewport */
.wpdf-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  min-width: 0;
}

.wpdf-thumbs {
  flex: 0 0 auto;
  width: 152px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.18);
  border-right: 1px solid var(--wpdf-toolbar-border);
  scrollbar-width: thin;
}
.wpdf-thumbs[hidden] { display: none; }

.wpdf-thumb {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  line-height: 0;
}
.wpdf-thumb:hover { border-color: rgba(255, 255, 255, 0.25); }
.wpdf-thumb--active { border-color: var(--wpdf-accent); }
.wpdf-thumb:focus-visible { outline: 2px solid var(--wpdf-accent); outline-offset: 1px; }

.wpdf-thumb__canvas {
  display: block;
  min-height: 60px;
  border-radius: 2px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.wpdf-thumb__canvas canvas { display: block; width: 100%; height: auto; }

.wpdf-thumb__num {
  position: absolute;
  left: 4px;
  bottom: 4px;
  padding: 1px 5px;
  border-radius: 8px;
  font-size: 10px;
  line-height: 1.4;
  font-family: var(--wpdf-font);
  color: #f1f3f4;
  background: rgba(0, 0, 0, 0.62);
}

/* print sheet: detached from the viewer, filled page by page, then discarded */
.wpdf-print { display: none; }
@media print {
  body.wpdf-printing > *:not(.wpdf-print) { display: none !important; }
  body.wpdf-printing .wpdf-print { display: block !important; }
  .wpdf-print__page {
    page-break-after: always;
    break-after: page;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .wpdf-print__page:last-child { page-break-after: auto; break-after: auto; }
  .wpdf-print__page canvas { width: 100%; height: auto; }
  @page { margin: 8mm; }
}

/* viewport */
.wpdf-viewport {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;   /* a flex item defaults to min-width:auto, so a wide page
                     would stretch the viewport and feed fit-width a growing
                     width: the scale ran away to the 8x clamp */
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  scroll-behavior: smooth;
}
.wpdf-viewport--continuous {
  flex-direction: column;
  align-items: center;
  gap: 16px;
  /* the single-page layout centres its one page with justify-content; a column
     of pages centred that way overflows *above* the scroll origin, so page 1
     becomes unreachable and the scrollbar reports no overflow at all */
  justify-content: flex-start;
}

.wpdf-page {
  position: relative;
  background: var(--wpdf-page-bg);
  box-shadow: var(--wpdf-page-shadow);
  border-radius: 2px;
  line-height: 0;
  flex: 0 0 auto;
}
.wpdf-page__canvas { display: block; border-radius: 2px; }

/* The turning layer: canvas, text layer, links and highlights share one
   transform, so a rotated view keeps every layer on top of its glyph. Only the
   children turn — the page box itself stays axis-aligned, which is what the
   selection overlay (painted in screen coordinates) relies on. */
.wpdf-page__turn {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* Transparent text layer: the canvas paints, these spans carry the characters
   so selection, copy and the browser's find-in-page work. */
.wpdf-page__text { position: absolute; inset: 0; }

.wpdf-textlayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  white-space: pre;            /* keep the separator text nodes from collapsing */
  color: transparent;          /* separators are plain text nodes */
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}
.wpdf-textlayer span {
  position: absolute;
  white-space: pre;
  color: transparent;
  transform-origin: 0 0;
  user-select: text;
  -webkit-user-select: text;
}
.wpdf-textlayer ::selection,
.wpdf-textlayer ::-moz-selection {
  /* painted by .wpdf-selection instead: one rect per line, not per glyph run */
  background: transparent;
  color: transparent;
}

/* Selection highlight drawn by the viewer: uniform per line, over the canvas
   and under the link layer. */
.wpdf-selection {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
}
.wpdf-selection i {
  position: absolute;
  background: rgba(64, 132, 244, 0.32);
  border-radius: 2px;
}
.wpdf-page__overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  line-height: normal;
}
/* Link annotations sit above the bitmap and below nothing else: transparent
   until hovered or focused, so the page still reads as one image. */
.wpdf-link {
  position: absolute;
  display: block;
  border-radius: 2px;
  cursor: pointer;
  outline: none;
  /* the layer is inert so highlights and the selection overlay cannot eat
     clicks; the anchors themselves have to opt back in or every link is dead */
  pointer-events: auto;
}
.wpdf-link:hover,
.wpdf-link:focus-visible {
  background: var(--wpdf-link-hover, rgba(30, 120, 255, 0.14));
  box-shadow: 0 0 0 1px var(--wpdf-link-ring, rgba(30, 120, 255, 0.45));
}

.wpdf-highlight {
  position: absolute;
  background: var(--wpdf-highlight);
  border-radius: 2px;
  mix-blend-mode: multiply;
}

/* Annotation marks: the page bitmap already shows the note icon or the stamp, so
   the mark itself is only a hit target — a hover ring says it can be opened. */
.wpdf-annot {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 3px;
  cursor: pointer;
  outline: none;
  pointer-events: auto;
}
.wpdf-annot:hover,
.wpdf-annot:focus-visible,
.wpdf-annot[aria-expanded="true"] {
  background: var(--wpdf-link-hover, rgba(30, 120, 255, 0.14));
  box-shadow: 0 0 0 1px var(--wpdf-link-ring, rgba(30, 120, 255, 0.45));
}

/* The comment bubble. It lives outside the turning layer so its text stays
   upright when the page is rotated, and it is clamped to the page box. */
.wpdf-annot__popup {
  position: absolute;
  z-index: 5;
  max-width: min(320px, 92%);
  padding: 8px 10px;
  border-radius: var(--wpdf-radius, 6px);
  background: #fffbe6;
  color: #1f1f1f;
  border: 1px solid #e5d78a;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
}
.wpdf-annot__popup[hidden] { display: none; }
.wpdf-annot__author {
  display: block;
  font-weight: 600;
  margin-bottom: 2px;
}
.wpdf-annot__meta {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: #6b6350;
}

.wpdf-page__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wpdf-muted);
  font-size: 12px;
  background: color-mix(in srgb, var(--wpdf-page-bg) 90%, #000 10%);
}

/* status + overlays */
.wpdf-status {
  flex: 0 0 auto;
  font-size: 12px;
  padding: 4px 10px;
  color: var(--wpdf-muted);
  background: var(--wpdf-toolbar-bg);
  border-top: 1px solid var(--wpdf-toolbar-border);
  display: flex;
  gap: 12px;
  align-items: center;
}
.wpdf-status--hidden { display: none; }
.wpdf-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--wpdf-bg) 70%, transparent);
  color: var(--wpdf-toolbar-fg);
  font-size: 14px;
  text-align: center;
  padding: 24px;
  z-index: 2;
}
.wpdf-overlay--error { color: #ffb4ab; }
/* the element carries `hidden` when there is nothing to show; the flex display
   above would otherwise win over the UA [hidden] rule */
.wpdf-overlay[hidden] { display: none; }
.wpdf-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: wpdf-spin 0.8s linear infinite;
  display: inline-block;
  margin-right: 8px;
  vertical-align: -4px;
}
@keyframes wpdf-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .wpdf-spinner { animation-duration: 2.4s; }
  .wpdf-viewport { scroll-behavior: auto; }
}

/* dark page variant: useful for night modes without touching the wasm output */
.wpdf-root--invert .wpdf-page__canvas { filter: invert(1) hue-rotate(180deg); }
