/* upload.css — Upload modal + extraction-results panel + doc-viewer.
   Verbatim port of legacy app-upload-compare.css (.du-*, .nlp-*,
   .lab-upload-area) plus doc-viewer-specific .dv-* rules from legacy
   doc-viewer integration. Tokens.css aliases the legacy variables back to
   the current theme. */

/* ===== FILE HEADER ===== */
.du-file-header {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-subtle);
  border-radius: 6px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.du-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.du-file-counter { font-weight: 400; color: var(--text-light); font-size: 0.85rem; }

/* ===== DROP ZONE + FILE LIST ===== */
.lab-upload-area {
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-subtle);
  transition: border-color 0.15s, background 0.15s;
}
.lab-upload-area:hover, .lab-upload-area.dragover {
  border-color: var(--primary);
  background: var(--bg-hover);
}
.file-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}
.file-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 4px;
  background: var(--bg-surface);
}
.file-list .file-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; overflow: hidden; }
.file-list .file-info span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .file-size { color: var(--text-light); font-size: 0.75rem; flex-shrink: 0; }
.du-file-remove {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.du-file-remove:hover { color: var(--error); }

/* ===== PER-FILE EXTRACTION CHECKBOX ===== */
.du-file-extract {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--text-light);
  white-space: nowrap;
  cursor: pointer;
  margin-right: 0.5rem;
  flex-shrink: 0;
}
.du-file-extract input[type="checkbox"] { width: 14px; height: 14px; margin: 0; }
.du-file-extract input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.4; }

/* ===== SAVE-ONLY PANEL ===== */
.du-save-only-info {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 0.75rem 0;
}
.du-save-only-info p { margin: 0.3rem 0; font-size: 0.9rem; }

/* ===== PROGRESS STAGES ===== */
.hr-progress-stages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 1rem 0;
}
.hr-stage {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-light);
  transition: all 0.2s;
}
.hr-stage.active {
  border-color: var(--primary);
  color: var(--text);
  background: var(--bg-subtle);
}
.hr-stage.completed {
  color: var(--text);
  background: var(--bg-subtle);
}
.hr-stage-indicator {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
  position: relative;
}
.hr-stage.active .hr-stage-indicator {
  border-color: var(--primary);
  animation: hr-stage-pulse 1.2s infinite;
}
.hr-stage.completed .hr-stage-indicator {
  border-color: var(--primary);
  background: var(--primary);
}
.hr-stage.completed .hr-stage-indicator::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  width: 4px;
  height: 8px;
  border: solid var(--text-inverted);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
@keyframes hr-stage-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(10, 110, 92, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(10, 110, 92, 0); }
}

.du-dialog, .erw-dialog { max-width: 720px; }

/* Side-by-side doc preview needs a wider dialog. The wizard
   (`.rw-dialog`) toggles `.rw-split` on `.rw-content-row` when the user
   opens the doc preview from either the summary or param-page view. The
   upload-modal no longer renders extraction surfaces (single-renderer
   invariant — see CLAUDE.md §6); rule kept on `.du-dialog` is harmless
   but unused. min(...) keeps the dialog from overflowing narrow viewports. */
.rw-dialog:has(.rw-content-row.rw-split) {
  max-width: min(95vw, 1100px);
}

.nlp-ai-text { font-size: 0.78rem; color: var(--text-light); margin-bottom: 6px; }
.nlp-extract-warning { color: var(--error); font-size: 0.85rem; }
.nlp-throttle-notice { color: var(--warning); font-size: 0.82rem; margin: 6px 0; }

/* L1 sub-panels */
.nlp-l1-panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  overflow: hidden;
  border-left: 3px solid var(--border);
}
.nlp-l1-header {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
}
.nlp-l1-body { padding: 4px 10px 6px; background: var(--bg-subtle); }

.nlp-l1-panel[data-l1="document"]    { border-left-color: #2196a6; }
.nlp-l1-panel[data-l1="condition"]   { border-left-color: #e74c3c; }
.nlp-l1-panel[data-l1="medication"]  { border-left-color: #8e44ad; }
.nlp-l1-panel[data-l1="procedure"]   { border-left-color: #e67e22; }
.nlp-l1-panel[data-l1="allergy"]     { border-left-color: var(--warning); }
.nlp-l1-panel[data-l1="laboratory"]  { border-left-color: #3498db; }
.nlp-l1-panel[data-l1="vital-signs"] { border-left-color: var(--success); }
.nlp-l1-panel[data-l1="immunization"]{ border-left-color: #1abc9c; }
.nlp-l1-panel[data-l1="imaging"]     { border-left-color: #95a5a6; }
.nlp-l1-panel[data-l1="appointment"] { border-left-color: var(--primary); }

[data-theme="dark"] .nlp-l1-header {
  background: rgba(52, 211, 153, 0.12);
}

.nlp-l2-group { margin-left: 4px; margin-bottom: 2px; }
.nlp-l2-header { font-size: 0.78rem; font-weight: 500; color: var(--text-light); margin: 3px 0 1px; }

.nlp-param-item { font-size: 0.78rem; margin-left: 12px; line-height: 1.4; }
.nlp-param-item.excluded { opacity: 0.35; text-decoration: line-through; }
.nlp-param-check {
  width: 12px !important;
  height: 12px;
  margin: 0;
  cursor: pointer;
  vertical-align: middle;
  accent-color: var(--primary);
}
.nlp-param-val { color: var(--primary); font-weight: 500; }
/* needs-curation (transient §5.4 marker): resolver could not code this auto-
   extracted item; surface its label in red so the user curates it. */
.nlp-param-needs-curation { color: var(--error); font-weight: 600; }
.nlp-needs-curation-count { margin: 0.25rem 0 0.5rem; font-size: 0.85rem; color: var(--text-light); }
.nlp-param-date { color: var(--text-light); font-size: 0.72rem; }
.nlp-param-note { color: var(--text-light); font-style: italic; font-size: 0.72rem; }

/* ===== DOC VIEWER ===== */
.dv-zoom-bar {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
}
.dv-zoom-btn {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.dv-zoom-btn:hover { background: var(--bg-hover); }
.dv-zoom-level { font-size: 11px; color: var(--text-light); min-width: 36px; text-align: center; }

.dv-viewport {
  overflow: auto;
  cursor: grab;
  background: var(--bg-subtle);
  border-radius: 4px;
}
.dv-viewport.grabbing { cursor: grabbing; }
/* Zoom is driven by --dv-zoom (set on .dv-content-inner by doc-viewer.js).
   Image: width grows with zoom so the viewport's overflow:auto produces a
   horizontal scrollbar past 100%. Text and markdown: font-size scales —
   content reflows within viewport width, no horizontal scroll needed. */
.dv-content-inner { --dv-zoom: 1; }
.dv-image { max-width: 100%; display: block; }
.dv-image-zoomable {
  width: calc(100% * var(--dv-zoom, 1));
  max-width: none;
  height: auto;
}
.dv-text {
  margin: 0;
  padding: 0 6px 6px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: calc(12px * var(--dv-zoom, 1));
  white-space: pre-wrap;
  word-break: break-word;
}
.md-viewer { padding: 0 6px 6px; font-size: calc(1em * var(--dv-zoom, 1)); }
.md-viewer h2 {
  margin: 0.6em 0 0.2em;
  font-size: 1.15em;
  color: var(--color-primary);
}
.md-viewer h3 {
  margin: 0.5em 0 0.15em;
  font-size: 1.02em;
  font-weight: 600;
  color: var(--color-accent);
  padding-left: 1.5em;
}
.md-viewer h4 { margin: 0.4em 0 0.1em; font-size: 0.95em; font-weight: 600; }
.md-viewer .cp-section { padding-left: 0; }
.md-viewer .vr-section { padding-left: 1.5em; }
.md-viewer ul { padding-left: 1.5em; margin: 0.2em 0; }
.md-viewer ul ul { padding-left: 1.5em; }
.md-viewer li { margin: 0.1em 0; }
.dv-loading {
  text-align: center;
  padding: 24px;
  color: var(--text-light);
  font-size: 0.85rem;
}
.dv-error {
  padding: 16px;
  color: var(--error);
  text-align: center;
  font-size: 0.85rem;
}
.spinner-sm {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spinner-rot 0.8s linear infinite;
}
@keyframes spinner-rot {
  to { transform: rotate(360deg); }
}

@media (max-width: 768px) {
  .du-dialog, .erw-dialog { max-width: 95vw; }
}

/* ── Document viewer overlay (from document-actions.js) ────────────── */
.doc-viewer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 5000;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}
.doc-viewer-overlay.active { display: flex; }
.doc-viewer-modal {
  background: var(--white);
  border-radius: 12px;
  width: 100%;
  max-width: 900px;
  height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px var(--shadow-lg);
  overflow: hidden;
}
.doc-viewer-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--gray-100);
  background: var(--gray-50);
  flex-shrink: 0;
}
.doc-viewer-title {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 1rem;
}
.doc-viewer-hdr-btns {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}
.doc-viewer-body {
  flex: 1;
  overflow: hidden;
  padding: 0.75rem 1rem;
}
.doc-summary-card {
  background: var(--gray-50);
  border: 1px solid var(--gray-100);
  border-radius: 8px;
  padding: 0.75rem;
}
.doc-summary-detailed {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
}
