/* CAS PDF viewer wrapper — positions the pdfjs container correctly */
.pdf-viewer-wrapper {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.pdf-viewer-wrapper .pdf-viewer-container {
  position: absolute;
  top: 34px; /* below toolbar (33px + 1px border) */
  left: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
  background: var(--surface-inset);
}

/* Grab cursor + non-selectable text only when pan is bound to the left mouse button.
   When pan is on right/middle, the left-click stays available for text selection
   so the cursor falls back to PDF.js defaults (text "|" over text, default elsewhere). */
.pdf-viewer-wrapper .pdf-viewer-container.pan-grab {
  cursor: grab;
}

.pdf-viewer-wrapper .pdf-viewer-container.pan-grab:active {
  cursor: grabbing;
}

.pdf-viewer-wrapper .pdf-viewer-container.pan-grab .textLayer {
  cursor: grab;
  user-select: none;
}

.pdf-viewer-wrapper .pdf-viewer-container.pan-grab:active .textLayer {
  cursor: grabbing;
}

/* Add margin to first page so canvas is visible around the document */
.pdf-viewer-wrapper .pdfViewer .page:first-child {
  margin-top: 10px;
}

.pdf-viewer-wrapper .pdfViewer .page {
  /* Keep pdfjs's default `margin: 0 auto 10px` so narrow pages stay centered
     inside .pdfViewer. Overriding with explicit margin-left/right makes pages
     left-align, which then conflicts with the centered scrollLeft below and
     pushes narrow first pages off the viewport's left edge in multi-page PDFs
     with mixed widths. */
  /* Clip annotations with garbage coordinates (e.g. a textAnnotation placed at
     left: 475%) so they can't expand the horizontal scroll area and push the
     initial centered view off the actual PDF. */
  overflow: clip;
}

.pdf-viewer-wrapper .pdf-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

/* ── Toolbar ─────────────────────────────────────────────────────── */

.pdf-toolbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 12px;
  height: 33px;
  background: var(--surface-secondary);
  border-bottom: 1px solid var(--border-default);
  font-size: 12px;
}

.pdf-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.pdf-toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s, color 0.1s;
}

.pdf-toolbar-btn:hover {
  background: var(--surface-hover);
  color: var(--text-body);
}

.pdf-toolbar-search {
  flex: 1;
  position: relative;
  min-width: 0;
}

.pdf-toolbar-search-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.pdf-toolbar-search-input {
  width: 100%;
  padding: 2px 8px 2px 26px;
  border: 1px solid var(--border-default);
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--text-body);
  font-size: 12px;
  outline: none;
  transition: border-color 0.1s;
}

.pdf-toolbar-search-input:focus {
  border-color: var(--tint);
}

.pdf-toolbar-search-input::placeholder {
  color: var(--text-muted);
}

.pdf-toolbar-regex-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid transparent;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-family: monospace;
  font-weight: 600;
  padding: 1px 4px;
  line-height: 1;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.pdf-toolbar-regex-toggle:hover {
  color: var(--text-secondary);
  background: var(--surface-hover);
}

.pdf-toolbar-regex-toggle.active {
  color: var(--tint);
  border-color: var(--tint);
  background: color-mix(in srgb, var(--tint) 10%, transparent);
}

.pdf-toolbar-search:has(.pdf-toolbar-regex-toggle) .pdf-toolbar-search-input {
  padding-right: 32px;
}

/* PDF.js built-in find highlights */
.textLayer .highlight {
  --highlight-bg-color: rgba(252, 245, 95, 0.25);
  --highlight-selected-bg-color: rgba(252, 235, 50, 0.4);
  border-radius: 0;
  outline: 3px solid rgba(220, 210, 0, 0.7);
}

.selected.highlight {
  outline-color: rgba(190, 180, 0, 0.85);
}

/* Regex search highlights */
.pdf-regex-highlight {
  color: transparent;
  background: rgba(252, 245, 95, 0.25);
  outline: 3px solid rgba(220, 210, 0, 0.7);
}

.pdf-regex-highlight.current {
  background: rgba(252, 235, 50, 0.4);
  outline-color: rgba(190, 180, 0, 0.85);
}

/* ── Field bounding box overlays ──────────────────────────────── */

.field-overlay-container {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 4;
}

/* One layer per PDF page. Zooming only rewrites this element's transform, so all the
   boxes on the page move and scale in the same frame as the page itself instead of being
   re-laid-out one by one. */
.field-overlay-page {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.field-box {
  position: absolute;
  /* Het vlak is exact de gemeten inkt van de waarde. De rand staat er met outline OMHEEN in plaats
     van als border erin: een outline telt niet mee in de maat, dus hij vreet een kader van een paar
     pixels hoog niet dicht en de lucht (outline-offset) verandert niets aan wat het vlak aanwijst.
     --fb-border en --fb-lucht groeien mee met de zoom (gezet door _positionFieldOverlays), zodat een
     kader op een ingezoomde pagina niet als haarlijntje overblijft. */
  outline: var(--fb-border, 1px) solid transparent;
  outline-offset: var(--fb-lucht, 1px);
  border-radius: var(--r-xs);
  pointer-events: auto;
  cursor: pointer;
  z-index: 3;
  transition: background 0.15s, outline-color 0.15s, box-shadow 0.15s;
}

.field-box[data-category="chemical"]   { outline-color: rgba(22, 163, 74, 0.7); }
.field-box[data-category="mechanical"] { outline-color: rgba(147, 51, 234, 0.7); }
.field-box[data-category="qmp"]        { outline-color: rgba(234, 88, 12, 0.7); }
.field-box[data-category="identity"]   { outline-color: rgba(37, 99, 235, 0.7); }
.field-box[data-category="other"]      { outline-color: rgba(220, 38, 127, 0.7); }

.field-box:hover {
  outline-width: calc(var(--fb-border, 1px) * 2);
}

.field-box.active {
  outline-color: rgba(220, 180, 0, 1);
  background: rgba(255, 220, 0, 0.35);
  outline-width: calc(var(--fb-border, 1px) * 2);
  box-shadow: 0 0 8px 2px rgba(255, 200, 0, 0.5);
  z-index: 5;
}

.field-box-fuzzy {
  outline-style: dashed;
}

