/**
 * PDF.js Viewer CSS
 *
 * Note: PDF.js viewer base styles are loaded dynamically via JavaScript in bootstrap.js
 * This file only contains custom overrides and layout styles
 */

/* Custom overrides for PDF viewer integration */

/* Ensure PDF toolbar and header are above the viewer */
/* z-index set to 0 to allow Shoelace popups to appear above it */
#pdf-toolbar {
  position: relative;
  z-index: 0;
}

#pdf-headerbar {
  position: relative;
  z-index: 0;
}

/* The wrapper contains the sidebar and viewer side by side */
.pdf-viewer-wrapper {
  flex: 1;
  display: flex;
  flex-direction: row;
  position: relative;
  overflow: hidden;
}

/* Sidebar container */
.sidebarContainer {
  width: 200px;
  min-width: 200px;
  background: #f5f5f5;
  border-right: 1px solid #ccc;
  overflow-y: auto;
  transition: margin-left 0.2s ease;
}

/* Hide sidebar when closed */
.sidebarContainer[hidden] {
  margin-left: -200px;
}

.sidebarContent {
  padding: 8px;
}

.thumbnailView {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Individual thumbnail styling */
.thumbnail {
  cursor: pointer;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 4px;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.thumbnail:hover {
  background-color: #e8e8e8;
  border-color: #999;
}

.thumbnail canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #ddd;
}

.thumbnail-label {
  text-align: center;
  font-size: 11px;
  color: #666;
  margin-top: 4px;
}

/* The viewer container should grow to fill remaining space */
#pdf-viewer-container {
  flex: 1;
  position: relative;
  overflow: auto;
}

/* The pdfViewerContainer needs absolute positioning within its parent */
.pdfViewerContainer {
  position: absolute !important;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
}

.pdfViewer {
  padding: 10px;
}

/* Override page styles - ensure proper stacking context for text/annotation layers */
.pdfViewer .page {
  margin: 10px auto;
  border: 1px solid #ccc;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  /* Don't override position, z-index, or dimensions - let PDF.js handle all positioning */
}

/* Text layer alignment fix
 * PDF.js text layer calculations assume content-box sizing.
 * Global box-sizing: border-box (from app.css) causes misalignment.
 * Reset to content-box for all PDF.js elements.
 * See: https://github.com/mozilla/pdf.js/issues/14176
 */
.pdfViewerContainer,
.pdfViewerContainer *,
.pdfViewerContainer *::before,
.pdfViewerContainer *::after {
  box-sizing: content-box;
}

/* Cursor tool modes */

/* Hand tool mode: change cursor to grab/grabbing and disable text selection */
.pdfViewerContainer.hand-tool-mode {
  cursor: grab;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

.pdfViewerContainer.hand-tool-mode:active {
  cursor: grabbing;
}

.pdfViewerContainer.hand-tool-mode .pdfViewer {
  cursor: grab;
}

.pdfViewerContainer.hand-tool-mode:active .pdfViewer {
  cursor: grabbing;
}

/* Disable text selection in hand tool mode */
.pdfViewerContainer.hand-tool-mode .textLayer {
  pointer-events: none;
}

/* Text selection mode: enable text cursor and selection (default behavior) */
.pdfViewerContainer.text-select-mode {
  cursor: default;
  -webkit-user-select: text;
  -moz-user-select: text;
  user-select: text;
}

.pdfViewerContainer.text-select-mode .textLayer {
  pointer-events: auto;
}

/* PDF.js Find Controller highlight styles */
.textLayer .highlight {
  background-color: rgba(255, 255, 0, 0.4);
  border-radius: 2px;
}

.textLayer .highlight.selected {
  background-color: rgba(255, 150, 0, 0.6);
}

.textLayer .highlight.appended {
  position: initial;
}

.textLayer .highlight.begin {
  border-radius: 2px 0 0 2px;
}

.textLayer .highlight.end {
  border-radius: 0 2px 2px 0;
}

.textLayer .highlight.middle {
  border-radius: 0;
}

/* Individual span highlight for matched terms */
.textLayer .span-highlight {
  position: absolute;
  background-color: rgba(255, 255, 0, 0.35);
  border-radius: 2px;
  pointer-events: none;
}

/* Cluster boundary (dashed outline around matched span group) */
.textLayer .cluster-highlight {
  position: absolute;
  background-color: transparent;
  border: 1.5px dashed rgba(255, 150, 0, 0.6);
  border-radius: 4px;
  pointer-events: none;
}
