/* Viewer Container */
.viewer-container {
  height: 100%;
  width: 100%;
  overflow: auto;
  padding: 24px;
  min-width: 0;
  box-sizing: border-box;
  overflow-anchor: none;
  position: relative;
}

.pages-wrapper {
  position: relative;
  width: 100%;
  min-height: 100%;
  min-width: 0;
}

.pages-content {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  transform-origin: top left;
}

/* PDF Page */
.pdf-page {
  background-color: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px var(--shadow);
  margin-bottom: 24px;
  position: relative;
  border-radius: 4px;
  margin-left: auto;
  margin-right: auto;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Placeholder state - fixed dimensions for instant layout */
.pdf-page.placeholder {
  background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
  border: 2px dashed var(--border);
}

.page-debug-number {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 20;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.78);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.pdf-page.placeholder .page-debug-number,
.pdf-page.loading .page-debug-number {
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-primary);
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.pdf-page.placeholder .loading-spinner {
  display: none;
}

/* Loading state */
.pdf-page.loading {
  background: linear-gradient(135deg, #f0f4ff 0%, #e8ecf4 100%);
  border: 2px solid var(--primary-color);
}

.pdf-page.loading .loading-spinner {
  display: block;
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-top: 16px;
}

.page-pending-message {
  margin-top: 12px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

/* Loaded state */
.pdf-page.loaded {
  border: none;
  justify-content: flex-start;
  align-items: flex-start;
}

.pdf-page.loaded .page-image {
  display: block;
  max-width: none;
  min-width: 0;
  height: auto;
}

/* Error state */
.pdf-page.error {
  background-color: #fff5f5;
  border: 2px solid #ff6b6b;
}

.pdf-page.error .error-content {
  text-align: center;
}

.pdf-page.error .error-content span {
  display: block;
  color: #e03131;
  margin-bottom: 12px;
  font-weight: 500;
}

.page-error-detail {
  display: block;
  margin-top: 4px;
  opacity: 0.7;
  font-size: 11px;
  word-break: break-all;
}

.pdf-page.error .error-content button {
  padding: 8px 20px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}

.pdf-page.error .error-content button:hover {
  background-color: var(--primary-hover);
}

.page-container {
  position: relative;
  display: inline-block;
}

/* Page loader */
.page-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  min-height: 400px;
}

.loader-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loader-text {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Page error */
.page-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  min-height: 400px;
}

.error-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.error-text {
  font-size: 16px;
  color: #e03131;
  margin-bottom: 16px;
  font-weight: 500;
}

.retry-btn {
  padding: 8px 24px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.retry-btn:hover {
  background-color: var(--primary-hover);
}

.retry-btn:active {
  transform: scale(0.98);
}

.page-image {
  display: block;
  max-width: none;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* OCR Text Overlay */
.ocr-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.ocr-text-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: auto;
  overflow: clip;
}

body.text-layer-disabled .ocr-text-layer {
  display: none;
}

/* Line-level text for selection/copy */
.ocr-line {
  position: absolute;
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  color: transparent;
  white-space: pre;
  overflow: visible;
  cursor: text;
  z-index: 2;
}

.ocr-line-word {
  position: absolute;
  display: inline-block;
  box-sizing: border-box;
  color: transparent;
  white-space: pre;
  transform-origin: left center;
  overflow: visible;
}

.ocr-line-compact {
  display: inline-block;
  white-space: pre;
  transform-origin: left center;
}

/* Keep drag hit-testing inside the OCR text layer between positioned lines. */
.ocr-selection-end {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  cursor: default;
  user-select: none;
}

.ocr-text-layer.selecting .ocr-selection-end {
  top: 0;
}

/* Word-level elements for interaction */
.ocr-word {
  position: absolute;
  pointer-events: none;
  user-select: none;
  transition: background-color 0.15s ease;
  z-index: 1;
}

/* Enable word interaction only in selection mode */
body.selection-mode .ocr-word {
  pointer-events: auto;
  cursor: pointer;
  z-index: 3;
}

body.selection-mode .ocr-text-layer {
  pointer-events: none;
}

body.selection-mode .ocr-line {
  pointer-events: none;
  user-select: none;
}

/* Highlight OCR word on hover when selection mode is active */
body.selection-mode .ocr-word:hover {
  background-color: rgba(33, 150, 243, 0.15);
}

.ocr-word.search-highlight {
  background-color: rgba(255, 235, 59, 0.4);
}

.ocr-word.search-highlight.current {
  background-color: rgba(255, 152, 0, 0.5);
}

/* Unified selection box that encompasses all selected words */
.unified-selection-box {
  position: absolute;
  background-color: rgba(33, 150, 243, 0.1);
  border: 2px solid #2196f3;
  pointer-events: none;
  border-radius: 2px;
  box-sizing: border-box;
  z-index: 2;
}

/* Drawing selection box during rectangle drag */
.drawing-selection-box {
  position: absolute;
  background-color: rgba(33, 150, 243, 0.1);
  border: 2px dashed #2196f3;
  pointer-events: none;
  border-radius: 2px;
  box-sizing: border-box;
  z-index: 10;
}

.ocr-line::selection {
  background: rgba(0, 102, 204, 0.3);
  color: transparent;
}

.ocr-line span::selection {
  background: rgba(0, 102, 204, 0.3);
  color: transparent;
}

/* Redaction Box */
/* Search Highlight */
.search-highlight {
  background-color: var(--search-highlight) !important;
}

.search-highlight.current {
  background-color: rgba(255, 87, 34, 0.6) !important;
  outline: 2px solid #ff5722;
}

@media (max-width: 768px) {
  .viewer-container {
    padding: 16px;
  }
}
