/* =========================================================
   PDF excerpter — layers over pdf.js-rendered pages.

   Global (not scoped) CSS on purpose: pdfExcerptor.js builds the whole page
   subtree imperatively, so those elements never carry Blazor's scope
   attribute and a scoped stylesheet would not match them.
   ========================================================= */

.pdf-viewport {
    height: 100%;
    overflow-y: auto;
    overflow-x: auto;
    background: var(--muted);
    padding: 12px 0;
}

/* One rendered page: canvas + text layer + annotation layer, stacked.
   The sheet is white in every theme — it represents paper, and the PDF's own
   marks are authored against a white background. Theming it would make dark
   text vanish. Only the surround (.pdf-viewport) follows the theme. */
.pdf-page {
    position: relative;
    margin: 0 auto 12px auto;
    background: #ffffff;
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);
}

/* -------- Text layer ----------------------------------------------------
   Transparent positioned spans sitting exactly over the rasterized glyphs.
   They are what makes native browser text selection work on a canvas.

   pdf.js sizes each span with `calc(var(--scale-factor) * Npx)`; that variable
   is set per page in renderPage(). Without it the spans collapse and text is
   effectively unselectable. */
.pdf-text-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    line-height: 1;
    pointer-events: auto;
    /* Full opacity: the spans are individually transparent, so dimming the
       whole layer only dims the ::selection highlight. */
    opacity: 1;
    forced-color-adjust: none;
    cursor: text;
}

.pdf-text-layer span,
.pdf-text-layer br {
    color: transparent;
    position: absolute;
    white-space: pre;
    transform-origin: 0% 0%;
    /* Give thin glyph boxes a usable hit area — dragging across a line of text
       shouldn't require pixel-accurate aim. */
    pointer-events: auto;
}

/* pdf.js appends this sentinel to anchor selection past the last glyph. */
.pdf-text-layer .endOfContent {
    position: absolute;
    inset: 100% 0 0;
    cursor: default;
    user-select: none;
    display: block;
}

.pdf-text-layer ::selection {
    background: color-mix(in srgb, var(--primary) 45%, transparent);
}

/* -------- Annotation layer ---------------------------------------------
   Holds excerpt overlays and the region marquee. Transparent to pointer
   events in text mode so clicks reach the text layer underneath. */
.pdf-annotation-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Region mode inverts that: the annotation layer captures the drag, and the
   text layer stops intercepting so a drag doesn't select text instead. */
.pdf-region-mode .pdf-annotation-layer {
    pointer-events: auto;
    cursor: crosshair;
}

.pdf-region-mode .pdf-text-layer {
    pointer-events: none;
    user-select: none;
}

/* -------- Region marquee ------------------------------------------------ */
.pdf-region-select {
    position: absolute;
    border: 2px dashed var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    pointer-events: none;
    z-index: 10;
}

/* The drag is finished and the excerpt is awaiting confirmation in the
   inspector. The box stays on the page so the preview in the side panel is
   visibly tied to a spot in the document; the pulse marks it as not-yet-saved
   and distinguishes it from a committed excerpt overlay. */
.pdf-region-pending {
    border-style: solid;
    background: color-mix(in srgb, var(--primary) 18%, transparent);
    animation: pdf-region-pending-pulse 1.6s ease-in-out infinite;
}

@keyframes pdf-region-pending-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
    .pdf-region-pending { animation: none; }
}

/* -------- Excerpt overlays ---------------------------------------------
   Inline border-color / background come from the excerpt's own color, set by
   the JS; only layout and interaction live here. */
.pdf-excerpt-overlay {
    position: absolute;
    border: 2px solid;
    border-radius: 2px;
    cursor: pointer;
    pointer-events: auto;
    z-index: 5;
}

div.pdf-excerpt-overlay:hover {
    box-shadow: 0 0 8px rgb(0 0 0 / 0.25);
}

.pdf-excerpt-polygon {
    transition: fill-opacity 0.15s ease, stroke-opacity 0.15s ease, stroke-width 0.15s ease;
}

svg.pdf-excerpt-overlay:hover .pdf-excerpt-polygon {
    fill-opacity: 0.35;
    stroke-opacity: 1;
    stroke-width: 2.5;
}

/* The excerpt currently selected in the inspector. */
div.pdf-excerpt-overlay-active {
    box-shadow: 0 0 0 2px var(--ring);
}

svg.pdf-excerpt-overlay-active .pdf-excerpt-polygon {
    fill-opacity: 0.32;
    stroke-opacity: 1;
    stroke-width: 2.5;
}
