/* ================================================================
   ClerkCheck — Search Page Styles
   Three-panel layout: left sidebar (search/docs/results),
   right panel (PDF viewer), drag-and-drop upload overlay
   ================================================================ */

/* ── Search Layout ────────────────────────────────────────────── */
.search-layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Left Panel ───────────────────────────────────────────────── */
.left-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  min-height: 0;
}

/* Search Bar */
.search-bar {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-form {
  display: flex;
  gap: var(--space-sm);
}

.search-input {
  flex: 1;
  height: 40px;
  padding: 0 var(--space-md);
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--duration), box-shadow var(--duration);
}

.search-input:focus {
  outline: none;
  border-color: var(--gold-400);
  box-shadow: var(--shadow-gold);
}

.search-input::placeholder {
  color: var(--text-3);
}

.search-input:disabled {
  background: var(--bg);
  color: var(--text-3);
  cursor: not-allowed;
}

.search-submit {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--navy-800);
  color: #fff;
  border-radius: var(--radius-sm);
  transition: background var(--duration);
}

.search-submit:hover:not(:disabled) {
  background: var(--navy-700);
}

.search-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Document List */
.doc-section {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  max-height: 240px;
  display: flex;
  flex-direction: column;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-lg);
  flex-shrink: 0;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.btn-add-pdfs {
  font-size: 11px;
  font-weight: 600;
  color: var(--gold-600);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: background var(--duration), color var(--duration);
}

.btn-add-pdfs:hover {
  background: var(--gold-50);
  color: var(--gold-700);
}

.doc-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  cursor: pointer;
  transition: background var(--duration);
}

.doc-item:hover {
  background: var(--surface-hover);
}

.doc-item.active {
  background: var(--gold-50);
  border-left: 2px solid var(--gold-500);
  padding-left: calc(var(--space-lg) - 2px);
}

.doc-status {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  font-size: 12px;
}

.doc-status.ready {
  color: var(--green-600);
}

.doc-status.indexing {
  color: var(--gold-500);
}

.doc-status .spinner,
.doc-status .spinner-small {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--gold-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.doc-status.failed {
  color: var(--red-600);
}

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

.doc-info {
  flex: 1;
  min-width: 0;
}

.doc-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: 11px;
  color: var(--text-3);
}

.doc-remove {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--text-3);
  font-size: 14px;
  opacity: 0;
  transition: opacity var(--duration), color var(--duration), background var(--duration);
}

.doc-item:hover .doc-remove {
  opacity: 1;
}

.doc-remove:hover {
  color: var(--red-600);
  background: var(--red-100);
}

.doc-empty {
  padding: var(--space-lg);
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

/* Search Results */
.results-section {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}

.results-section .section-header {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  border-bottom: 1px solid var(--border);
}

.result-item {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--duration);
}

.result-item:hover {
  background: var(--surface-hover);
}

.result-item.active {
  background: var(--gold-50);
  border-left: 3px solid var(--gold-500);
  padding-left: calc(var(--space-lg) - 3px);
}

.result-score {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 22px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold-700);
  background: var(--gold-100);
  border: 1px solid var(--gold-200);
  border-radius: 999px;
}

.result-body {
  flex: 1;
  min-width: 0;
}

.result-source {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 2px;
}

.result-source .page-num {
  color: var(--text-3);
  font-weight: 400;
}

.result-snippet {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result-snippet-full {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
}

.result-snippet mark,
.result-snippet-full mark {
  background: var(--gold-100);
  color: var(--text-1);
  font-weight: 600;
  border-radius: 2px;
  padding: 0 1px;
}

.result-expand {
  background: none;
  border: none;
  color: var(--gold-600, #b8923e);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.result-expand:hover {
  opacity: 0.7;
}

.results-empty {
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

/* Session Timer */
.session-timer {
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-lg);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-3);
  background: var(--bg);
}

.session-timer.warning {
  color: var(--gold-700);
  background: var(--gold-50);
}

/* ── Right Panel (PDF Viewer) ─────────────────────────────────── */
.right-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  min-height: 0;
}

.viewer-container {
  flex: 1;
  overflow: auto;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: var(--space-lg);
}

.viewer-canvas-wrapper {
  position: relative;
  box-shadow: var(--shadow-lg);
  background: #fff;
}

.viewer-canvas-wrapper canvas {
  display: block;
}

/* Text layer for selection + highlights */
.viewer-text-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  opacity: 0.25;
  line-height: 1;
}

.viewer-text-layer span {
  position: absolute;
  white-space: pre;
  transform-origin: 0% 0%;
  color: transparent;
}

.viewer-text-layer ::selection {
  background: rgba(184, 146, 62, 0.3);
}

/* Highlight overlay */
.viewer-highlight-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.highlight-rect {
  position: absolute;
  background: rgba(255, 230, 0, 0.25);
  border-radius: 2px;
  mix-blend-mode: multiply;
}

/* Viewer empty state */
.viewer-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  text-align: center;
  padding: var(--space-2xl);
}

.viewer-empty-icon {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-md);
  color: var(--text-3);
  opacity: 0.4;
}

.viewer-empty-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  color: var(--navy-800);
  margin-bottom: var(--space-xs);
}

.viewer-empty-desc {
  font-size: 14px;
  color: var(--text-3);
}

/* Viewer toolbar */
.viewer-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.toolbar-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: color var(--duration), background var(--duration);
}

.toolbar-btn:hover:not(:disabled) {
  color: var(--text-1);
  background: var(--bg-warm);
}

.toolbar-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.page-indicator {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}

.page-input {
  width: 40px;
  height: 28px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.page-input:focus {
  outline: none;
  border-color: var(--gold-400);
  box-shadow: var(--shadow-gold);
}

.zoom-display {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  min-width: 36px;
  text-align: center;
}

/* ── Drag-and-Drop Overlay ────────────────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 20, 38, 0.6);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

.drop-overlay-inner {
  background: var(--surface);
  border: 3px dashed var(--gold-500);
  border-radius: var(--radius-lg);
  padding: var(--space-3xl) var(--space-2xl);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.drop-overlay-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-md);
  color: var(--gold-500);
}

.drop-overlay-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 500;
  color: var(--navy-800);
  margin-bottom: var(--space-xs);
}

.drop-overlay-desc {
  font-size: 14px;
  color: var(--text-2);
}

/* Upload zone within viewer empty state */
.viewer-upload-hint {
  margin-top: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-3);
  cursor: pointer;
  transition: border-color var(--duration), background var(--duration);
}

.viewer-upload-hint:hover {
  border-color: var(--gold-400);
  background: var(--gold-50);
}

/* File validation errors */
.upload-errors {
  padding: var(--space-sm) var(--space-lg);
  flex-shrink: 0;
  font-size: 12px;
  color: var(--red-600);
  background: var(--red-100);
  border-radius: var(--radius-sm);
  white-space: pre-line;
}

.upload-error {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--red-100);
  border: 1px solid rgba(184, 58, 46, 0.15);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--red-600);
  margin-bottom: var(--space-xs);
  animation: fadeUp 0.3s var(--ease-out);
}

/* Loading spinner for viewer */
.viewer-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  gap: var(--space-md);
}

.viewer-loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--gold-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.viewer-loading-text {
  font-size: 13px;
  color: var(--text-3);
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .search-layout {
    grid-template-columns: 1fr;
  }

  .right-panel {
    display: none;
  }

  .left-panel {
    border-right: none;
  }

  .result-source .page-ref {
    font-style: italic;
    color: var(--text-3);
  }
}

@media (max-width: 600px) {
  .search-bar {
    padding: var(--space-sm) var(--space-md);
  }

  .section-header {
    padding: var(--space-sm) var(--space-md);
  }

  .doc-item {
    padding: var(--space-sm) var(--space-md);
  }

  .result-item {
    padding: var(--space-sm) var(--space-md);
  }

  .session-timer {
    padding: var(--space-sm) var(--space-md);
  }
}

/* ── Scrollbar styling ────────────────────────────────────────── */
.doc-list::-webkit-scrollbar,
.results-section::-webkit-scrollbar,
.viewer-container::-webkit-scrollbar {
  width: 4px;
}

.doc-list::-webkit-scrollbar-track,
.results-section::-webkit-scrollbar-track,
.viewer-container::-webkit-scrollbar-track {
  background: transparent;
}

.doc-list::-webkit-scrollbar-thumb,
.results-section::-webkit-scrollbar-thumb,
.viewer-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.doc-list::-webkit-scrollbar-thumb:hover,
.results-section::-webkit-scrollbar-thumb:hover,
.viewer-container::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}
