/* =============================================================================
   WP-37 — in-document navigation (static/viewer_nav.js). Loads AFTER style.css so
   it may override; it never restyles the functional pdf.js block, only ADDS to it.
   Every rule here is scoped to #viewer descendants / .vn-* classes.
   ============================================================================= */

/* --- 1. Highlight of the CITED verbatim passage ----------------------------
   The pdf.js glyph spans are already positioned over the rastered glyphs, so a
   background on the matched span is a glyph-tight mark. Text stays transparent
   and selectable; multiply keeps the ink dark under the wash. */
.textLayer span.vn-hl {
  background: rgba(255, 221, 0, .45);
  mix-blend-mode: multiply;
  border-radius: 1px;
}
/* Fallback: a HOLLOW outline at the stored text-block bounds (where, not which words). */
.vn-bbox {
  position: absolute;
  border: 2px solid rgba(214, 150, 0, .95);
  box-shadow: 0 0 0 3px rgba(255, 221, 0, .3);
  pointer-events: none;
  z-index: 1;
}

/* --- 5. Preview placeholder while pdf.js fetches/renders -------------------- */
.vn-preview {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; object-position: top center;
  z-index: 1; pointer-events: none; background: #fff;
}
#pageContainer.vn-previewing #pdfCanvas,
#pageContainer.vn-previewing .textLayer { visibility: hidden; }

/* --- Toolbar additions ------------------------------------------------------- */
.viewer-toolbar #vnTextBtn[aria-pressed="true"] {
  color: var(--accent); border-color: var(--accent); font-weight: 700;
}
.viewer-toolbar #vnFindBtn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.viewer-toolbar #vnPinBtn:disabled { opacity: .55; }
.viewer-toolbar button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- 4. Result strip --------------------------------------------------------- */
.vn-results {
  display: flex; align-items: center; gap: 8px; padding: 4px 16px;
  border-bottom: 1px solid var(--rule); background: var(--paper-sunken);
}
.vn-results[hidden] { display: none; }
.vn-results button {
  min-width: 44px; min-height: 44px; padding: 0 14px;
  font-size: 20px; line-height: 1; font-weight: 400;
}
.vn-result-label {
  flex: 1; text-align: center;
  font: 600 var(--fz-label)/1.3 var(--sans); letter-spacing: var(--ls-caps); text-transform: uppercase;
  color: var(--ink-3);
}
@media (min-width: 761px) {
  .vn-results { padding: 2px 16px; }
  .vn-results button { min-height: 32px; min-width: 36px; padding: 0 10px; font-size: 16px; }
}
/* Horizontal swipe = prev/next result: let the browser keep vertical scroll + pinch, hand us the X. */
.canvas-wrap.vn-swipe { touch-action: pan-y pinch-zoom; }
.vn-text.vn-swipe { touch-action: pan-y; }

/* --- 2. Text view: the EXTRACTED TEXT LAYER, reflowed ------------------------
   The canvas pane keeps its WIDTH in layout (app.js fit-width reads clientWidth)
   but collapses to zero height, so toggling back needs no re-render. */
#viewer.vn-textmode #canvasWrap {
  flex: 0 0 0; height: 0; min-height: 0; overflow: hidden;
  padding-top: 0; padding-bottom: 0; visibility: hidden;
}
.vn-text { flex: 1; min-height: 0; overflow: auto; background: var(--paper); color: var(--ink); }
.vn-text[hidden] { display: none; }
.vn-text-head {
  position: sticky; top: 0; z-index: 1;
  padding: 10px 16px; background: var(--paper-sunken); border-bottom: 1px solid var(--rule);
}
.vn-text-title { font: 600 var(--fz-ui)/1.4 var(--sans); color: var(--ink); overflow-wrap: anywhere; }
.vn-text-note { margin-top: 2px; font: var(--fz-meta)/1.4 var(--sans); }
.vn-text-ocr { margin-top: 6px; color: var(--accent); font: 700 var(--fz-label)/1.4 var(--sans); }
.vn-text-ocr::before { content: "▲ "; }
.vn-text-loading, .vn-text > .warn, .vn-text > .muted { padding: 14px 16px; }
.vn-text-body {
  max-width: 70ch; margin: 0 auto; padding: 14px 16px 24px;
  font: 16.5px/1.6 var(--serif);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.vn-text-body mark.vn-hl { background: rgba(255, 221, 0, .55); color: inherit; padding: 0 1px; }
/* AI description (if any): BELOW the text, under the ochre banner, italic + the AI rule —
   the same treatment card() gives .snippet.ai-described. Never set like the text above. */
.vn-ai { max-width: 70ch; margin: 0 auto; padding: 0 16px 28px; }
.vn-ai .ai-banner { margin-bottom: 8px; }
.vn-ai-text {
  margin: 0; font: italic 15px/1.55 var(--sans); color: var(--ink-2);
  border-left: 3px solid var(--ai); padding-left: 10px; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* --- 3. Find drawer ----------------------------------------------------------- */
/* Desktop Search two-pane: #viewer must be a containing block for the side panel. Scoped so the
   mobile `position:fixed` overlay and the WP-33 `main.tl-mode #viewer{position:absolute}` are untouched. */
@media (min-width: 761px) {
  main:not(.tl-mode) #viewer { position: relative; }
}
.vn-drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(380px, 100%);
  z-index: 60; display: flex; flex-direction: column; min-height: 0;
  background: var(--paper-raised); border-left: 1px solid var(--rule-strong);
  box-shadow: -4px 0 16px rgba(0, 0, 0, .15);
}
.vn-drawer[hidden] { display: none; }
.vn-drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--rule); background: var(--paper-sunken);
}
.vn-drawer-title { font: 600 var(--fz-ui)/1.3 var(--sans); color: var(--ink); }
.vn-drawer-head button { min-width: 44px; min-height: 44px; padding: 0 12px; font-size: 16px; }
.vn-drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 12px 16px 24px; }
.vn-find-form, .vn-goto-form { display: flex; gap: 8px; align-items: center; margin: 0 0 10px; }
.vn-find-form input, .vn-goto-form input {
  flex: 1; min-width: 0; min-height: 44px; font-size: 16px; /* >=16px: no iOS focus-zoom */
}
.vn-find-form button, .vn-goto-form button { min-height: 44px; padding: 0 16px; }
.vn-goto-form { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule); flex-wrap: wrap; }
.vn-goto-form label { flex: 1 1 100%; font: 600 var(--fz-label)/1.4 var(--sans); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--ink-3); }
.vn-goto-status { font: var(--fz-meta)/1.4 var(--sans); min-height: 1.4em; }
.vn-find-results .warn, .vn-find-results .muted { font-size: var(--fz-body); }
.vn-find-page { margin: 0 0 10px; }
.vn-find-page-head {
  font: 11.5px/1.6 var(--mono); letter-spacing: .02em; color: var(--ink-3);
  border-bottom: 1px solid var(--rule-strong); padding-bottom: 2px; margin-bottom: 4px;
}
.vn-hit {
  display: block; width: 100%; text-align: left; min-height: 44px;
  margin: 0; padding: 8px 8px 8px 10px; border: 0; border-bottom: 1px solid var(--rule);
  background: transparent; color: var(--ink); cursor: pointer; border-radius: 0;
  font: var(--fz-body)/1.45 var(--serif);
}
.vn-hit:hover, .vn-hit:focus-visible { background: var(--paper-sunken); outline: none; }
.vn-hit .badge.ai { display: inline-block; margin-bottom: 4px; }
.vn-hit-snippet {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.vn-hit.ai-described .vn-hit-snippet {
  font-style: italic; border-left: 3px solid var(--ai); padding-left: 8px;
}
.vn-section-title {
  margin: 18px 0 6px; padding-top: 14px; border-top: 1px solid var(--rule);
  font: 600 var(--fz-label)/1.4 var(--sans); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--ink-3);
}
.vn-outline[hidden] { display: none; }
.vn-outline-list { list-style: none; margin: 0; padding: 0; }
.vn-outline-list .vn-outline-list { padding-left: 14px; border-left: 1px solid var(--rule); }
.vn-outline-item {
  display: flex; justify-content: space-between; gap: 10px; width: 100%; min-height: 44px;
  margin: 0; padding: 8px 6px; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0;
  background: transparent; color: var(--ink); text-align: left; cursor: pointer;
  font: var(--fz-ui)/1.4 var(--sans);
}
.vn-outline-item:hover, .vn-outline-item:focus-visible { background: var(--paper-sunken); outline: none; }
.vn-outline-item:disabled { cursor: default; color: var(--ink-3); }
.vn-outline-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.vn-outline-page { flex: 0 0 auto; font: 11.5px/1.6 var(--mono); color: var(--ink-3); white-space: nowrap; }

/* Mobile: the drawer is a bottom sheet over the full-screen viewer overlay. */
@media (max-width: 760px) {
  .vn-drawer {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto;
    max-height: 72vh; max-height: 72dvh;
    border-left: 0; border-top: 1px solid var(--rule-strong);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .25);
  }
  .vn-drawer-body { padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
  .vn-text-body { padding: 12px 16px 24px; font-size: 17px; }
  .vn-text-head { padding: 8px 14px; }
  .viewer-toolbar .vn-sep { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .vn-text, .vn-drawer-body, .canvas-wrap { scroll-behavior: auto; }
}
