/* Result review page — visual language ported from v11-local's verification
   page (frontend/css/styles.css + components.css). Self-contained: this page
   does not load the lab's styles.css. */

:root {
  color-scheme: dark;
  --bg: #0b0d13;
  --surface: #12141c;
  --surface-2: #1a1d28;
  --surface-3: #222533;
  --border: #2a2d3a;
  --border-hover: #3a3d4a;
  --text: #e4e4e7;
  --text-muted: #8b8d98;
  --text-dim: #5a5c6a;
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-bg: rgba(99,102,241,0.12);
  --primary-border: rgba(99,102,241,0.25);
  --success: #34d399;
  --success-bg: rgba(52,211,153,0.12);
  --warning: #fbbf24;
  --warning-bg: rgba(251,191,36,0.12);
  --error: #f87171;
  --error-bg: rgba(248,113,113,0.12);
  --info: #60a5fa;
  --info-bg: rgba(96,165,250,0.12);
  --glass-bg: rgba(255,255,255,0.03);
  --glass-border: rgba(255,255,255,0.06);
  --bar-bg: rgba(18,20,28,0.85);
  --panel-bg: rgba(18,20,28,0.5);
  --panel-bg-strong: rgba(18,20,28,0.55);
  --hover-bg: rgba(255,255,255,0.02);
  --seg-divider: rgba(255,255,255,0.03);
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* Light palette — color values mirror the upload page (styles.css) so the
   two pages feel like one app. The two blocks below MUST stay identical:
   the first follows the operating-system setting when the user has not
   chosen, the second applies the user's explicit toggle choice
   (data-theme set by result.html/result.js, remembered in localStorage). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f7f8fb;
    --surface: #ffffff;
    --surface-2: #f1f4f8;
    --surface-3: #e8edf3;
    --border: #d9e1ea;
    --border-hover: #b9c7d6;
    --text: #1f2933;
    --text-muted: #657281;
    --text-dim: #8792a0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-bg: #eef2ff;
    --primary-border: #c7d2fe;
    --success: #16815c;
    --success-bg: #e7f6ef;
    --warning: #b7791f;
    --warning-bg: #fff6df;
    --error: #b42318;
    --error-bg: #fdebea;
    --info: #2563eb;
    --info-bg: #eaf2ff;
    --glass-bg: rgba(31,41,51,0.04);
    --glass-border: rgba(139,154,172,0.28);
    --bar-bg: rgba(255,255,255,0.85);
    --panel-bg: rgba(241,244,248,0.6);
    --panel-bg-strong: rgba(241,244,248,0.7);
    --hover-bg: rgba(31,41,51,0.03);
    --seg-divider: rgba(31,41,51,0.08);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f8;
  --surface-3: #e8edf3;
  --border: #d9e1ea;
  --border-hover: #b9c7d6;
  --text: #1f2933;
  --text-muted: #657281;
  --text-dim: #8792a0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-bg: #eef2ff;
  --primary-border: #c7d2fe;
  --success: #16815c;
  --success-bg: #e7f6ef;
  --warning: #b7791f;
  --warning-bg: #fff6df;
  --error: #b42318;
  --error-bg: #fdebea;
  --info: #2563eb;
  --info-bg: #eaf2ff;
  --glass-bg: rgba(31,41,51,0.04);
  --glass-border: rgba(139,154,172,0.28);
  --bar-bg: rgba(255,255,255,0.85);
  --panel-bg: rgba(241,244,248,0.6);
  --panel-bg-strong: rgba(241,244,248,0.7);
  --hover-bg: rgba(31,41,51,0.03);
  --seg-divider: rgba(31,41,51,0.08);
}

* { box-sizing: border-box; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Buttons (v11 .btn family) ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: var(--r-md);
  border: 1px solid transparent;
  font-family: inherit; font-size: 0.85rem; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: all 150ms;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); box-shadow: 0 0 16px rgba(99,102,241,0.15); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--border-hover); }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }

.s-select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-family: inherit; font-size: 0.8rem; padding: 5px 8px;
}
.s-select:hover { border-color: var(--border-hover); }

/* ─── Top bar (v11 .report-topbar) ─── */
.report-topbar {
  padding: 10px 20px 8px;
  background: var(--bar-bg);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.report-topbar-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.topbar-spacer { flex: 1; }
.staff-completion-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.report-title { font-size: 1rem; font-weight: 600; }
.report-file-indicator {
  font-size: 0.85rem; color: var(--text-muted); font-weight: 500;
}
.check-progress-pill {
  display: inline-flex; align-items: center;
  padding: 3px 12px; border-radius: 100px;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  font-size: 0.75rem; color: var(--text-muted);
}
.check-progress-pill.all-checked {
  background: var(--success-bg); border-color: var(--success); color: var(--success);
}
.download-group {
  display: flex;
  gap: 6px;
  align-items: center;
  max-width: min(42vw, 560px);
  min-width: 0;
}
.download-group .s-select {
  min-width: 0;
  max-width: 280px;
}
.download-group #downloadArtifact,
.download-group #driveUploadBtn {
  flex-shrink: 0;
}

.report-status-row {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-top: 6px;
  font-size: 0.75rem; color: var(--text-dim);
}
.report-status-row a { color: var(--primary); }

.report-status-row[hidden],
.report-issues-panel[hidden],
.download-group[hidden],
.staff-completion-actions[hidden] {
  display: none;
}
.status-ok { color: var(--success); }
.status-bad { color: var(--error); }

/* ─── Two-pane body (v11 .report-body) ─── */
.report-body {
  display: flex; flex: 1; min-height: 0;
  position: relative;
}

/* ─── Issues sidebar (v11 .report-issues-panel) ─── */
.report-issues-panel {
  width: 280px; flex-shrink: 0;
  background: var(--panel-bg);
  border-right: 1px solid var(--glass-border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.issues-panel-header {
  padding: 14px 16px; font-size: 0.88rem; font-weight: 600;
  border-bottom: 1px solid var(--glass-border);
  display: flex; align-items: center; gap: 8px;
}
#issuesPanel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#issuesPanel[hidden] { display: none; }
.issues-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 100px; font-size: 0.7rem; font-weight: 600;
  background: var(--surface-3); color: var(--text-muted);
}
.issues-top-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text-muted); font-family: inherit; font-size: 0.7rem;
  padding: 2px 8px; cursor: pointer;
}
.issues-top-btn:hover { border-color: var(--border-hover); color: var(--text); }

/* Severity filter pills (v11 .issue-filter-bar) */
.issue-filter-bar {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px;
  border-bottom: 1px solid var(--glass-border);
}
.fix-suggestions-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--glass-border);
  min-width: 0;
}
.fix-suggestions-count {
  font-size: 0.72rem; color: var(--text-muted); flex: 1 1 100%;
  min-width: 0;
}
.fix-suggestions-bar .btn {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}
#acceptAllFixesBtn:disabled {
  opacity: 0.55; cursor: default;
}
.issue-filter-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 100px;
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); font-family: inherit; font-size: 0.72rem; font-weight: 500;
  cursor: pointer; transition: all 150ms; white-space: nowrap; flex: 0 0 auto;
}
.issue-filter-pill[data-severity="high"] { color: var(--error); border-color: rgba(248,113,113,0.3); }
.issue-filter-pill[data-severity="medium"] { color: var(--warning); border-color: rgba(251,191,36,0.3); }
.issue-filter-pill[data-severity="low"] { color: var(--info); border-color: rgba(96,165,250,0.3); }
.issue-filter-pill:hover { border-color: var(--border-hover); }
.issue-filter-pill.active { background: var(--primary-bg); border-color: var(--primary-border); color: var(--primary); }
.issue-filter-pill.active[data-severity="high"] { background: var(--error-bg); border-color: var(--error); color: var(--error); }
.issue-filter-pill.active[data-severity="medium"] { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.issue-filter-pill.active[data-severity="low"] { background: var(--info-bg); border-color: var(--info); color: var(--info); }
.filter-dot { width: 8px; height: 8px; border-radius: 50%; }
.filter-dot.err { background: var(--error); }
.filter-dot.warn { background: var(--warning); }
.filter-dot.info { background: var(--info); }
.issues-tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}
.issues-tab.active { color: var(--text); }
.glossary-term-location { width: 100%; text-align: left; }
button.issue-sidebar-item.glossary-term-location {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
button.issue-sidebar-item.glossary-term-location:hover {
  background: var(--glass-bg);
  border-color: var(--glass-border);
}
.glossary-term-group details {
  border-bottom: 1px solid var(--glass-border);
}
.glossary-term-summary {
  display: grid;
  gap: 3px;
  padding: 10px;
  cursor: pointer;
}
.glossary-term-title,
.glossary-term-meta {
  min-width: 0;
  overflow-wrap: anywhere;
}
.glossary-term-title {
  font-size: 0.86rem;
}
.glossary-pair-rows {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.glossary-pair-row {
  display: grid;
  grid-template-columns: minmax(84px, max-content) minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  min-width: 0;
}
.glossary-pair-label {
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}
.glossary-pair-value {
  min-width: 0;
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}
.glossary-term-meta {
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}
.glossary-occurrence-list {
  margin: 0;
  padding: 0 8px 10px 18px;
}
.glossary-occurrence {
  margin: 0 0 10px;
}
.glossary-term-controls {
  display: grid;
  gap: 8px;
  padding: 8px 0 0;
}
.glossary-control-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  align-items: center;
}
.glossary-helper-row {
  padding: 8px 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
}
.glossary-status-ok {
  border-color: rgba(52,211,153,0.35);
  background: rgba(52,211,153,0.1);
}
.glossary-status-ok .glossary-control-label,
.glossary-status-ok .glossary-muted {
  color: var(--success);
}
.glossary-status-attention {
  border-color: rgba(251,191,36,0.38);
  background: rgba(251,191,36,0.12);
}
.glossary-status-attention .glossary-control-label,
.glossary-status-attention .glossary-muted {
  color: var(--warning);
}
.glossary-control-label {
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}
.glossary-applied-value,
.glossary-muted {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.8rem;
}
.glossary-option-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.glossary-control-btn {
  white-space: normal;
  text-align: left;
}
.glossary-applied-edit-input,
.glossary-custom-input {
  min-width: 0;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
  color: var(--text);
  background: var(--panel);
}
.glossary-applied-edit-input:focus,
.glossary-custom-input:focus,
.glossary-term-summary:focus-visible,
.glossary-control-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.issues-panel-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; margin: 0; list-style: none; }
.issues-panel-list li.issue-sidebar-item.selected {
  background: var(--primary-bg); border-color: var(--primary-border);
}
.issues-panel-list li.issue-sidebar-item {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 10px; border-radius: var(--r-md); cursor: pointer;
  border: 1px solid transparent;
}
.issues-panel-list li.issue-sidebar-item:hover {
  background: var(--glass-bg); border-color: var(--glass-border);
}
.issues-panel-list li.issue-empty {
  padding: 14px 10px; font-size: 0.8rem; color: var(--text-dim);
}
.issue-sidebar-dot {
  width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0;
}
.issue-sidebar-dot.err { background: var(--error); }
.issue-sidebar-dot.warn { background: var(--warning); }
.issue-sidebar-dot.info { background: var(--info); }
.issue-sidebar-dot.resolved { background: var(--success); }
.issue-sidebar-body { flex: 1; min-width: 0; }
.issue-sidebar-origin {
  display: block; font-size: 0.66rem; font-weight: 700;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em;
}
.review-mode-note {
  color: var(--info); font-weight: 600;
}
.issue-sidebar-type { font-size: 0.85rem; font-weight: 600; text-transform: capitalize; }
.issue-sidebar-excerpt {
  font-size: 0.8rem; color: var(--text-dim); margin-top: 2px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.issue-sidebar-actions { display: flex; gap: 6px; margin-top: 6px; }
.issue-sidebar-state {
  font-size: 0.7rem; color: var(--success); font-weight: 600; text-transform: uppercase;
}
.issues-panel-footer {
  padding: 12px 16px; border-top: 1px solid var(--glass-border);
  display: flex; flex-direction: column; gap: 8px;
}
.issues-panel-footer .text-dim { font-size: 0.75rem; color: var(--text-muted); }
.issues-panel-footer textarea {
  width: 100%; resize: vertical;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-family: inherit; font-size: 0.8rem; padding: 6px 8px;
}
.issues-panel-footer .field-label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.75rem; color: var(--text-muted); font-weight: 500;
}

/* ─── Document column (v11 .report-doc) ─── */
.report-doc {
  flex: 1; padding: 28px 36px 40vh;
  overflow-y: auto;
  min-height: 0;
}
.report-doc-inner { max-width: 860px; }

/* Document segments (v11 .doc-seg) */
.doc-seg { margin-bottom: 8px; position: relative; padding: 6px 0; }
.doc-seg + .doc-seg { border-top: 1px solid var(--seg-divider); }

.doc-seg-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 3px;
}
.doc-seg-type {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted);
}
.pairing-status-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--warning);
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 0.72rem;
  font-weight: 700;
}
.doc-seg-spacer { flex: 1; }

.doc-seg-original {
  /* Brighter than v11's text-dim: the owner reads this to verify, so it
     must clear the 4.5:1 contrast bar (text-dim only manages ~2.9:1). */
  font-size: 0.9rem; color: var(--text-muted); line-height: 1.7;
  margin-bottom: 6px;
  padding-left: 12px; border-left: 2px solid var(--glass-border);
  white-space: pre-wrap;
}

.doc-seg-chinese-context {
  margin: 0 0 6px 12px;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
}
.doc-seg-chinese-context > span {
  display: block;
  margin-bottom: 2px;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.doc-seg-translated {
  font-size: 1rem; color: var(--text); line-height: 1.8;
  cursor: text; padding: 8px 10px; border-radius: var(--r-md);
  border: 1px solid transparent;
  transition: all 150ms;
  white-space: pre-wrap;
}
.doc-seg-translated:hover {
  background: var(--hover-bg);
  border-color: var(--glass-border);
}

.doc-seg.has-issue { border-left: 3px solid var(--warning); padding-left: 12px; margin-left: -15px; }
.doc-seg.has-error { border-left: 3px solid var(--error); padding-left: 12px; margin-left: -15px; }

.doc-seg.unit-checked .doc-seg-head .doc-seg-type { color: var(--success); }

.seg-check-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 100px;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border);
  font-family: inherit; font-size: 0.72rem; font-weight: 500;
  cursor: pointer; transition: all 150ms;
}
.seg-check-btn:hover { border-color: var(--border-hover); color: var(--text-muted); }
.seg-check-btn.on {
  background: var(--success-bg); border-color: var(--success); color: var(--success);
}
.seg-check-btn.reject-selected {
  background: var(--error-bg); border-color: var(--error); color: var(--error);
  font-weight: 700;
}

.issue-badge {
  display: inline-flex; align-items: center;
  padding: 1px 8px; border-radius: 100px;
  font-family: inherit; font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  cursor: pointer; border: 1px solid var(--glass-border);
  background: var(--glass-bg); color: var(--text-muted);
}
.issue-badge.err { background: var(--error-bg); color: var(--error); border-color: rgba(248,113,113,0.3); }
.issue-badge.warn { background: var(--warning-bg); color: var(--warning); border-color: rgba(251,191,36,0.3); }
.issue-badge.info { background: var(--info-bg); color: var(--info); border-color: rgba(96,165,250,0.3); }

.evidence-highlight {
  background: rgba(251,191,36,0.25); color: inherit; border-radius: 3px; padding: 0 2px;
}

/* Inline edit (v11 .doc-seg-edit + .doc-edit-actions) */
.doc-seg-edit {
  width: 100%; min-height: 90px; resize: vertical;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--primary-border); border-radius: var(--r-md);
  font-family: inherit; font-size: 1rem; line-height: 1.8; padding: 8px 10px;
}
.doc-seg-edit:focus { outline: none; border-color: var(--primary); }
.doc-edit-actions { display: flex; gap: 6px; margin-top: 6px; }
.doc-edit-btn {
  padding: 4px 14px; border-radius: var(--r-md); border: none;
  font-family: inherit; font-size: 0.78rem; font-weight: 500; cursor: pointer;
}
.doc-edit-btn.save { background: var(--primary); color: #fff; }
.doc-edit-btn.save:hover { background: var(--primary-hover); }
.doc-edit-btn.cancel { background: none; color: var(--text-dim); border: 1px solid var(--border); }
.doc-edit-btn.cancel:hover { background: var(--surface-2); }

/* Issue navigation flash (v11 .highlight-flash) */
.doc-seg.highlight-flash { animation: segFlash 0.6s ease-in-out 2; }
.doc-seg.glossary-term-highlight { box-shadow: 0 0 0 2px var(--primary); }
@keyframes segFlash {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: 0 0 0 2px var(--primary); }
}

/* Issue detail drawer (v11 .issue-detail-panel, right side) */
.issue-detail-panel {
  width: 340px; flex-shrink: 0;
  background: var(--panel-bg-strong);
  border-left: 1px solid var(--glass-border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.issue-detail-panel[hidden] { display: none; }
.issue-detail-header {
  padding: 14px 16px; font-size: 0.88rem; font-weight: 600;
  border-bottom: 1px solid var(--glass-border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.issue-detail-close {
  background: none; border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text-muted); font-family: inherit; font-size: 0.75rem;
  width: 24px; height: 24px; cursor: pointer; line-height: 1;
}
.issue-detail-close:hover { border-color: var(--border-hover); color: var(--text); }
.issue-detail-body { flex: 1; overflow-y: auto; padding: 14px 16px; font-size: 0.85rem; }
.issue-detail-row { margin-bottom: 14px; }
.issue-detail-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); margin-bottom: 4px;
}
.issue-detail-text { color: var(--text); line-height: 1.6; white-space: pre-wrap; }
.issue-evidence {
  padding: 8px 10px; border-radius: var(--r-md);
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  line-height: 1.6; white-space: pre-wrap;
}
.issue-evidence.fix { border-color: rgba(52,211,153,0.35); color: var(--success); }
.issue-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.issue-detail-resolved {
  color: var(--success); font-weight: 600; font-size: 0.8rem; text-transform: uppercase;
}

/* Edit affordance: chip in the block header + hover pencil on the text */
.seg-edit-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 100px;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
  font-family: inherit; font-size: 0.72rem; font-weight: 500;
  cursor: pointer; transition: all 150ms;
}
.seg-edit-btn:hover { border-color: var(--primary-border); color: var(--primary); }
.doc-seg-translated::after {
  content: " ✎"; opacity: 0; color: var(--text-muted);
  transition: opacity 150ms;
}
.doc-seg-translated:hover::after { opacity: 0.7; }

/* Completion banner: the page hands you the next step */
.completion-banner {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 18px; margin-bottom: 22px;
  background: var(--success-bg);
  border: 1px solid rgba(52,211,153,0.35);
  border-radius: var(--r-lg);
}
.completion-banner[hidden] { display: none; }
.completion-banner-text { flex: 1; min-width: 220px; color: var(--success); font-weight: 500; }

.image-review-panel {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.image-review-empty { color: var(--text-muted); font-size: 0.82rem; }
.image-review-head {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  margin-bottom: 10px;
}
.image-review-head strong { display: block; font-size: 0.9rem; }
.image-review-head span { display: block; color: var(--text-muted); font-size: 0.75rem; }
.image-review-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.image-review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.image-section {
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
  background: var(--glass-bg);
  margin-bottom: 8px;
}
.image-section:last-child { margin-bottom: 0; }
.image-section > summary {
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.image-section[open] > summary { border-bottom: 1px solid var(--glass-border); }
.image-section > .image-review-grid { padding: 10px; }
.image-review-card {
  display: flex; flex-direction: column; min-width: 0;
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 10px; background: var(--surface-2);
}
.image-review-card.degraded { border-color: var(--warning); }
.image-review-card-head {
  display: flex; gap: 8px; justify-content: space-between;
  font-size: 0.78rem; color: var(--text); margin-bottom: 8px;
}
.image-review-card-head > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.image-status { color: var(--text-muted); white-space: nowrap; }
.image-pair {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  width: 100%; border: 0; padding: 0; background: transparent;
  color: inherit; cursor: zoom-in;
}
.image-pair:focus-visible,
.image-enlarge-control:focus-visible,
.image-lightbox-close:focus-visible,
.image-lightbox-nav-button:focus-visible,
.image-section > summary:focus-visible,
.image-ocr > summary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.image-pair span {
  min-height: 92px; display: flex; flex-direction: column;
  justify-content: center; gap: 5px; border: 1px solid var(--border);
  border-radius: var(--r-sm); background: var(--surface); overflow: hidden;
}
.image-pair:hover span { border-color: var(--border-hover); }
.image-pair img {
  width: 100%; height: 92px; object-fit: contain; background: #fff;
}
.image-pair small { color: var(--text-muted); font-size: 0.68rem; padding: 0 6px 6px; }
.image-placeholder { padding: 8px; text-align: center; }
.image-enlarge-control {
  align-self: flex-end;
  margin-top: 7px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: zoom-in;
}
.image-enlarge-control:hover { border-color: var(--primary-border); color: var(--primary); }
.image-location {
  margin-top: 8px;
  padding: 5px 8px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
  background: var(--glass-bg);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.image-pairs,
.image-detail-pairs {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.image-pairs { margin-top: 8px; }
.image-pair-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 7px;
  align-items: stretch;
  min-width: 0;
}
.image-pair-source,
.image-pair-target {
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.image-pair-source {
  background: var(--surface-3);
  color: var(--text-muted);
}
.image-pair-target {
  background: var(--primary-bg);
  border-color: var(--primary-border);
  color: var(--text);
  font-weight: 600;
}
.image-pair-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 700;
}
.image-pairs-more {
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: 600;
  text-align: right;
}
.image-decision-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
/* Rescue controls sit under the decision, quieter than it: they are the remedy
   for a bad regeneration, not the reviewer's main act. */
.image-rescue-row {
  display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; align-items: center;
}
.image-rescue-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}
.image-rescue-btn:hover:not(:disabled) { border-color: var(--primary-border); color: var(--primary); }
.image-rescue-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.image-rescue-btn:disabled { opacity: 0.55; cursor: progress; }
.image-regen-count { color: var(--text-dim); font-size: 0.7rem; font-weight: 600; }
.image-ocr {
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
  background: var(--glass-bg);
}
.image-ocr > summary {
  padding: 8px 10px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.image-ocr[open] > summary { border-bottom: 1px solid var(--glass-border); }
.image-ocr-text {
  max-height: min(30vh, 280px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.image-ocr-note {
  padding: 9px 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
  background: var(--glass-bg);
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.image-lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.image-lightbox-content {
  width: min(1400px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  border: 1px solid var(--border-hover);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: 0 20px 60px var(--bg);
}
.image-lightbox-content:focus { outline: none; }
.image-lightbox-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}
.image-lightbox-heading { min-width: 0; }
.image-lightbox-title {
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.image-lightbox-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.75rem;
}
.image-lightbox-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
}
.image-lightbox-close:hover { border-color: var(--border-hover); color: var(--text); }
.image-lightbox-close svg,
.image-lightbox-nav-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.image-lightbox-nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.image-lightbox-nav-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: max-content;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.image-lightbox-nav-button:first-child { justify-self: start; }
.image-lightbox-nav-button:last-child { justify-self: end; }
.image-lightbox-nav-button:hover:not(:disabled) { border-color: var(--primary-border); color: var(--primary); }
.image-lightbox-nav-button:disabled { opacity: 0.45; cursor: default; }
.image-lightbox-counter {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.image-detail-grid,
.image-lightbox-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}
.image-lightbox-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.image-lightbox-label {
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.image-lightbox-col img {
  width: 100%;
  height: 58vh;
  min-height: 240px;
  max-height: 680px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.image-detail-empty,
.image-lightbox-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 240px;
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  text-align: center;
  overflow-wrap: anywhere;
}
.image-lightbox-details {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--glass-border);
}
.image-lightbox-details .issue-detail-row { margin-bottom: 0; }

@media (max-width: 900px) {
  .image-review-head { align-items: flex-start; flex-direction: column; }
  .image-pair-row { grid-template-columns: 1fr; }
  .image-pair-arrow { min-height: 18px; }
  .image-lightbox-overlay { align-items: stretch; padding: 0; }
  .image-lightbox-content {
    width: 100%;
    max-height: 100vh;
    padding: 14px;
    border-radius: 0;
  }
  .image-lightbox-pair { grid-template-columns: 1fr; }
  .image-lightbox-col img { height: 38vh; min-height: 180px; }
}
/* Save feedback toast */
#saveToast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  padding: 9px 16px; border-radius: var(--r-md);
  background: var(--surface-3); border: 1px solid var(--border);
  font-size: 0.82rem; font-weight: 500;
  transition: opacity 200ms;
}
#saveToast[hidden] { display: none; }
#saveToast.ok { color: var(--success); border-color: rgba(52,211,153,0.4); }
#saveToast.bad { color: var(--error); border-color: rgba(248,113,113,0.5); }

@media (prefers-reduced-motion: reduce) {
  .doc-seg.highlight-flash { animation: none; box-shadow: 0 0 0 2px var(--primary); }
  .btn, .seg-check-btn, .seg-edit-btn, .doc-seg-translated, #saveToast { transition: none; }
}

/* Phone / narrow screens: stack the layout, restore page scrolling */
@media (max-width: 900px) {
  body { overflow: auto; height: auto; display: block; }
  .report-topbar { position: sticky; top: 0; z-index: 50; }
  .report-body { flex-direction: column; height: auto; }
  .report-doc { order: 1; height: auto; overflow: visible; padding: 18px 16px 20vh; }
  .report-issues-panel {
    order: 2; width: 100%; height: auto;
    border-right: none; border-top: 1px solid var(--glass-border);
  }
  .issues-panel-list { max-height: 40vh; }
}

/* Whole-document flow: untranslated stretches fold into context groups */
.doc-context-group {
  margin: 6px 0;
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  background: var(--glass-bg);
}

.doc-context-group.expanded {
  border-style: solid;
}

.doc-context-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.84rem;
  font-family: var(--font-sans);
  text-align: left;
}

.doc-context-toggle:hover {
  color: var(--text);
}

.doc-context-caret {
  color: var(--text-dim);
}

.doc-context-count {
  white-space: nowrap;
}

.doc-context-preview {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.doc-context-content {
  padding: 2px 14px 10px;
  border-top: 1px dashed var(--border);
}

.doc-context-line {
  padding: 3px 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* v5 change-list review rows */
.change-list-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  background: var(--glass-bg);
}

.change-list-tool,
.change-row-action {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.change-list-tool:hover,
.change-row-action:hover { border-color: var(--primary-border); color: var(--primary); }
.change-row-action.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.change-row-action:disabled { opacity: 0.5; cursor: default; }

.unplaced-counter,
.attention-counter {
  margin-left: auto;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.unplaced-counter { background: var(--warning-bg); color: var(--warning); }
.attention-counter { background: var(--error-bg); color: var(--error); }

.change-row-footer,
.renumber-details,
.location-picker,
.manual-anchor-preview,
.attention-message {
  margin: 8px 0 0 12px;
  padding: 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  background: var(--glass-bg);
}

.foundation-current { color: var(--text-muted); line-height: 1.6; white-space: pre-wrap; }
.foundation-current > span,
.manual-anchor-preview > span {
  display: block;
  margin-bottom: 3px;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}
.change-row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.insertion-neighbors {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.insertion-neighbors > div {
  padding: 8px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}
.insertion-neighbors span {
  display: block;
  margin-bottom: 3px;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.change-choice-card {
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid var(--warning);
  border-radius: var(--r-md);
  background: var(--surface);
}
.change-choice-card.needs-attention { border-color: var(--error); }

.location-candidates { display: grid; gap: 6px; margin: 8px 0; }
.location-candidate {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.location-candidate.selected { border-color: var(--primary); background: var(--primary-bg); }
.location-candidate strong { color: var(--text); font-size: 0.78rem; }
.location-candidate span { font-size: 0.75rem; line-height: 1.45; }

.renumber-items { display: grid; gap: 6px; margin-top: 8px; }
.renumber-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.renumber-item.excluded { opacity: 0.55; text-decoration: line-through; }
.renumber-before,
.renumber-after { min-width: 0; overflow-wrap: anywhere; }

.doc-context-line.editable { cursor: text; border-radius: var(--r-sm); }
.doc-context-line.editable:hover { background: var(--hover-bg); color: var(--text); }
.doc-context-line.editing { padding: 8px 0; }

@media (max-width: 900px) {
  .unplaced-counter,
  .attention-counter { margin-left: 0; }
  .renumber-item { grid-template-columns: 1fr; }
  .insertion-neighbors { grid-template-columns: 1fr; }
}
