/* mango-mvp styles */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e2e5ea;
  --line-strong: #cfd4dc;
  --accent: #2f8fd0;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --green: #2e8b57;
  --due: #d8a200;
  --box: rgba(47, 143, 208, 0.7);
  --box-fill: rgba(47, 143, 208, 0.12);
  --box-sel: #c0392b;
  --box-ocr: #8e44ad;
  --box-ocr-fill: rgba(142, 68, 173, 0.14);
  --sidebar-w: 300px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
/* Text size preference (Preferences -> Display): every UI font size is in rem. */
html { font-size: calc(14px * var(--ui-scale, 1)); }
/* Form controls default to the UA's 13.33px; keep that size but let it scale. */
button, input, select, textarea { font-size: 0.9524rem; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 1rem;
  overflow: hidden;
}

#app { display: flex; height: 100vh; width: 100vw; }

/* ---- panes ---- */
.pane { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  font-weight: 600; flex: 0 0 auto; gap: 10px;
}
.pane-head-right { display: flex; align-items: center; gap: 8px; }
.count { color: var(--muted); font-weight: 500; background: var(--bg); border-radius: 10px; padding: 1px 8px; }

/* ---- foldable document list ---- */
.pane-list {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--line);
  transition: margin-left 0.18s ease;
}
#app.collapsed .pane-list { margin-left: calc(-1 * var(--sidebar-w)); }
.reopen-btn {
  position: fixed; left: 6px; top: 10px; z-index: 40;
  display: none; width: 30px; height: 30px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer;
}
#app.collapsed .reopen-btn { display: inline-flex; align-items: center; justify-content: center; }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px;
  width: 26px; height: 26px; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--bg); }

.doc-list { list-style: none; margin: 0; padding: 6px 0 6px 6px; overflow-y: auto; flex: 1 1 auto; }
.doc-item {
  display: flex; gap: 8px; align-items: flex-start; padding: 8px 3px 8px 10px;
  border-radius: 0; cursor: pointer; border-left: 3px solid transparent; position: relative;
}
.doc-item:hover { background: var(--bg); }
.doc-item.selected { background: #e8f2fb; border-left-color: var(--accent); }
.doc-meta { flex: 1 1 auto; min-width: 0; }
/* Filename over up to two lines (status is the icon on the left). */
.doc-name {
  font-weight: 600; line-height: 1.3; overflow: hidden; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
/* Stage indicators: a tall Metadata bar + a square Text Retrieval block of the
   same height holding the quality circles (P S / M O). */
.doc-item { align-items: center; min-height: 52px; }
.step-chips { display: inline-flex; gap: 4px; flex: 0 0 auto; height: 42px; }
.step-chip {
  height: 100%; border-radius: 4px; box-sizing: border-box;
  border: 1px solid var(--line-strong); background: transparent;
}
.step-chip-md { width: 10px; }
.step-chip-q {
  width: 42px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  place-items: center; padding: 2px;
}
.qmini {
  width: 16px; height: 16px; border-radius: 50%; display: inline-flex; align-items: center;
  justify-content: center; font-size: 0.6429rem; font-weight: 700; color: #1d2733;
  background: #c8ced6; border: 1px solid rgba(0,0,0,0.15); line-height: 1;
}
.doc-status-icon.ready-mark { color: var(--accent); }
.doc-status-icon.idle-mark { color: var(--muted); }
.qmini[data-level="ok"] { background: #2fb36a; color: #fff; }
.qmini[data-level="warn"] { background: #f0b429; }
.qmini[data-level="bad"] { background: #e5484d; color: #fff; }
.qmini[data-level="na"] { background: #e6e9ed; color: #9aa3ad; }
.step-chip.stage-complete,
.step-chip.stage-text { background: var(--green); border-color: var(--green); }
.step-chip.stage-arranged { background: #b7e4c7; border-color: #7dcea0; }
.step-chip.stage-due { background: var(--due); border-color: var(--due); }
.step-chip.stage-pending { background: transparent; }
.doc-del {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 0.8571rem; padding: 2px 4px; border-radius: 6px; opacity: 0;
}
.doc-item:hover .doc-del,
.extract-item:hover .doc-del { opacity: 1; }
.doc-del:hover { background: #f7d7d2; color: var(--danger); }
.doc-status-icon { flex: 0 0 auto; margin-top: 1px; }
.doc-status-icon.tick { color: var(--green); }
.doc-status-icon.err-mark { color: var(--danger); }
.prog { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.prog-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.2s ease; }
.prog-fill.indeterminate { width: 40%; animation: indet 1.1s infinite ease-in-out; }
@keyframes indet { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.spinner {
  display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line-strong);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* The whole document listing is the drop zone; the import button sits at its
   bottom, directly above "Document Table View". */
.drop-zone { position: relative; flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.drop-zone.drag-over { background: #eef4ff; }
.drop-zone-overlay {
  position: absolute; inset: 6px; border: 2px dashed var(--accent); border-radius: 10px;
  background: rgba(238, 244, 255, 0.85); color: var(--accent); font-weight: 700;
  display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 5;
}
.drop-hint { flex: 0 0 auto; padding: 8px 8px 14px; color: var(--muted); text-align: center; position: relative; }
.import-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; text-align: center;
  border: 1.5px dashed var(--line-strong); border-radius: 10px; background: var(--panel);
  padding: 8px 10px; cursor: pointer; color: var(--ink); font: inherit;
}
.import-btn:hover { border-color: var(--accent); background: #f3f8fd; }
.import-btn-text { line-height: 1.25; font-size: 0.9286rem; }
.drop-emoji { font-size: 2rem; flex: 0 0 auto; }
.drop-zone.is-empty .drop-hint { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: flex-start; }
.drop-zone.is-empty .drop-hint::before { content: ""; flex: 3 1 0; min-height: 0; }
.drop-zone.is-empty .drop-hint::after { content: ""; flex: 1 1 0; min-height: 0; }
.import-pickers { display: flex; gap: 6px; margin-top: 6px; }
.import-picker-btn {
  flex: 1 1 0; font-size: 1rem; font-weight: 600; line-height: 1.2;
  padding: 8px 10px; cursor: pointer; color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel);
}
.import-picker-btn:hover { border-color: var(--accent); background: #f3f8fd; }
.doc-folder-hint { color: var(--muted); font-size: 0.7857rem; }

/* ---- main ---- */
.main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.step-head { gap: 14px; flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: -0.02em; flex: 0 0 auto; }
.brand span { color: var(--accent); }
.step-tabs { display: flex; gap: 6px; flex: 0 1 auto; align-items: center; }
.step-btn {
  --step-bg: var(--panel);
  --step-edge: var(--line);
  --chev: 0.72em;
  box-sizing: content-box;
  border: 1px solid var(--step-edge); background: var(--step-bg); border-radius: 8px;
  height: 2.15em; padding: 0 12px; display: inline-flex; align-items: center;
  white-space: nowrap;
  cursor: pointer; font-weight: 600; color: var(--ink);
}
/* Every step but the last ends in a point, so the row reads left to right. */
.step-btn:not(:last-child) {
  position: relative;
  border-right: none;
  border-radius: 8px 0 0 8px;
  padding-right: 6px;
  margin-right: var(--chev);
}
.step-btn:not(:last-child)::before,
.step-btn:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 100%;
  width: 0; height: 0;
  border-style: solid;
}
.step-btn:not(:last-child)::before {
  top: -1px;
  border-width: calc(1.075em + 1px) 0 calc(1.075em + 1px) var(--chev);
  border-color: transparent transparent transparent var(--step-edge);
}
.step-btn:not(:last-child)::after {
  top: 0;
  border-width: 1.075em 0 1.075em calc(var(--chev) - 1.5px);
  border-color: transparent transparent transparent var(--step-bg);
}
.step-btn[data-dropdown] { padding-left: 6px; }
.step-btn:hover { --step-bg: var(--bg); background: var(--step-bg); }
.step-btn.active {
  --step-edge: var(--accent);
  --step-bg: #e8f2fb;
  background: var(--step-bg);
  border-color: var(--step-edge);
}
.step-btn.stage-due { box-shadow: inset 0 -3px 0 var(--due); }
.step-btn.stage-complete { box-shadow: inset 0 -3px 0 var(--green); --step-bg: #e3f5ea; background: var(--step-bg); }
.step-btn.stage-complete.active { --step-bg: #e8f2fb; background: var(--step-bg); }
.step-btn:disabled { opacity: 0.5; cursor: default; }

.step-body { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; }
.step-section { flex: 1 1 auto; min-height: 0; width: 100%; overflow: auto; padding: 16px; }
.step-section-flush { padding: 0; overflow: hidden; }
.step-empty { color: var(--muted); padding: 40px; text-align: center; }

/* ---- workbench ---- */
#wb { display: flex; height: 100%; min-height: 0; }
#wb-left {
  flex: 1 1 50%; min-width: 0; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); position: relative;
}
#wb-tools { border-bottom: 1px solid var(--line); background: var(--panel); flex: 0 0 auto; }
.wb-tool-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap; }
.retrieve-status { color: var(--muted); font-size: 0.8571rem; }
.engine-label-wrap { color: var(--muted); font-size: 0.8571rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 360px; }
.engine-label { color: var(--ink); font-weight: 600; }
/* Status text + language picker, pinned to the top-right of the document view. */
.wb-tool-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
/* Second tool row: engine on the left (truncated before the buttons), Preload AI
   then AI / CPU status on the right. */
.wb-tool-row2 { padding-top: 0; padding-bottom: 8px; min-height: 18px; flex-wrap: nowrap; }
.wb-tool-row2 .engine-label-wrap { flex: 1 1 auto; min-width: 0; max-width: none; }
.wb-tool-row2 .sys-status-group { flex: 0 0 auto; }
/* Language: its own section in the top-right corner, not in line with the buttons. */
.wb-lang-section { align-self: flex-start; padding-left: 10px; border-left: 1px solid var(--line); }
.sys-status-group { gap: 14px; }
.sys-status { display: inline-flex; align-items: baseline; gap: 4px; font-size: 0.8571rem; }
.sys-status > b { color: var(--ink); font-weight: 700; }
.sys-st { font-size: 0.7857rem; font-weight: 600; padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
.sys-st.st-ready { color: #1b6e3a; background: #eaf8ef; }
.sys-st.st-busy { color: #8a5a00; background: #fff4d6; }
.sys-st.st-error { color: var(--danger); background: #fdecea; }
.sys-st.st-idle { color: #35507a; background: #eef3fb; }
.sys-st.st-off { color: var(--muted); background: #f0f0f0; }
.lang-picker { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8571rem; color: var(--muted); }
.lang-picker select { /* legacy select, replaced by .lang-btn */
  font: inherit; font-weight: 700; color: var(--ink); padding: 2px 4px;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--panel); cursor: pointer;
}
.lang-picker select:disabled { opacity: 0.5; cursor: default; }

/* retrieval progress bar (Full retrieval) */
.retrieve-progress { display: flex; align-items: center; gap: 8px; flex: 1 1 220px; min-width: 180px; }
.retrieve-progress-track {
  flex: 1 1 auto; height: 8px; border-radius: 6px; background: var(--line-strong);
  overflow: hidden; position: relative;
}
.retrieve-progress-fill {
  height: 100%; width: 0%; background: var(--accent); border-radius: 6px;
  transition: width 0.25s ease;
}
.retrieve-progress-fill.indeterminate {
  width: 40% !important; position: absolute;
  animation: retrieve-indeterminate 1.1s ease-in-out infinite;
}
@keyframes retrieve-indeterminate {
  0% { left: -40%; } 100% { left: 100%; }
}
.retrieve-progress-label { font-size: 0.8571rem; color: var(--ink); white-space: nowrap; }
.retrieve-cancel-btn {
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--danger);
  border-radius: 6px; width: 22px; height: 22px; line-height: 1; cursor: pointer;
  font-size: 0.8571rem; flex: 0 0 auto; padding: 0;
}
.retrieve-cancel-btn:hover { background: #f7d7d2; }
.parsing-panel {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 12px; border-top: 1px dashed var(--line); background: #fafbfc;
}
.parsing-panel .picker-wide { grid-column: 1 / -1; }
.parsing-panel .picker-toggle { grid-column: 1 / -1; color: var(--ink); font-weight: 600; }

.wb-pages { flex: 1 1 auto; overflow: auto; padding: 14px; background: #eceef1; }
.wb-page { position: relative; margin: 0 auto 14px; background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,0.12); max-width: 900px; }
/* Preview zoom (ui_extras.js): the page width grows, overlays stay in percent. */
.wb-pages.is-zoomed .wb-page { max-width: none; width: calc(min(100%, 900px) * var(--zoom, 1)); }
.wb-page-img { display: block; width: 100%; height: auto; }
/* Until its image arrives a page keeps a page-shaped height (A4, or the ratio
   of the first loaded page) and hides its boxes, which would otherwise
   collapse into thin lines on a 0-px-high page. */
.wb-page.is-loading { aspect-ratio: var(--page-ratio, 1 / 1.414); }
.wb-page.is-loading .wb-page-img { position: absolute; inset: 0; height: 100%; opacity: 0; }
.wb-page.is-loading .wb-overlay { visibility: hidden; }
/* Before the first page is ready only the loader is visible. */
.wb-pages.is-loading > .wb-page { visibility: hidden; }
.wb-preview-loading { max-width: 360px; margin: 0 auto; }
.wb-preview-loading .placeholder { padding-bottom: 12px; }
.wb-overlay { position: absolute; inset: 0; }
.wb-box {
  position: absolute; border: 1.5px solid var(--box); background: var(--box-fill);
  cursor: pointer; border-radius: 2px; transition: background 0.1s ease;
}
.wb-box:hover { background: rgba(47,143,208,0.24); }
.wb-box.selected { border-color: var(--box-sel); background: rgba(192,57,43,0.22); box-shadow: 0 0 0 2px rgba(192,57,43,0.35); }
.wb-box.ocr { border-color: var(--box-ocr); background: var(--box-ocr-fill); }
.wb-box.draw { border: 2px dashed var(--box-ocr); background: rgba(142,68,173,0.10); }
.wb-box.temp { border-style: dashed; pointer-events: none; animation: ocr-temp-pulse 1s ease-in-out infinite; }
@keyframes ocr-temp-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
/* Spellcheck: red line along the bottom edge of an unknown word's box in the
   preview (clicks pass to the paragraph box). */
.wb-word-unknown {
  position: absolute; pointer-events: none; height: 2px; margin-top: -1px;
  background: var(--danger); border-radius: 1px;
}
/* Word boxes of the selected paragraph: estimated (pseudo) and joined words. */
.wb-word-mark { position: absolute; pointer-events: none; border-radius: 2px; }
.wb-word-mark.pseudo { border: 1.5px dashed #e67e22; background: rgba(230,126,34,0.15); }
.wb-word-mark.joined { border: 1px solid #2980b9; background: rgba(41,128,185,0.10); }
.wb-draw-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(31,36,48,0.9); color: #fff; padding: 6px 12px; border-radius: 8px; font-size: 0.8571rem;
}

/* ---- "OCR selection" spotlight mode ---- */
.ocr-dim { position: fixed; inset: 0; background: rgba(15,23,42,0.5); z-index: 400; }
body.ocr-selecting #wb-left {
  z-index: 500; box-shadow: 0 0 0 3px var(--accent); border-radius: 4px;
}
body.ocr-selecting #wb-pages { cursor: crosshair; }
.ocr-cancel-btn { color: var(--danger); }
.ocr-cancel-btn:hover { background: #f7d7d2; }
.btn.btn-go { background: var(--green); color: #fff; border-color: var(--green); }
.btn.btn-go:hover { filter: brightness(0.96); background: var(--green); }

#wb-right { flex: 1 1 50%; min-width: 0; display: flex; flex-direction: column; }
/* Submit Full Set progress strip at the bottom of the right panel. */
.submit-progress {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  margin: 0; padding: 8px 12px; border-top: 1px solid var(--line);
  background: #f4faf6;
}
.submit-progress[hidden] { display: none !important; }
.submit-progress-track {
  flex: 1 1 auto; height: 8px; border-radius: 6px; background: var(--line-strong);
  overflow: hidden; position: relative;
}
.submit-progress-fill {
  height: 100%; width: 0%; background: var(--green); border-radius: 6px;
  transition: width 0.25s ease;
}
.submit-progress-fill.indeterminate {
  width: 40% !important; position: absolute;
  animation: retrieve-indeterminate 1.1s ease-in-out infinite;
}
.submit-progress-label {
  flex: 0 0 auto; font-size: 0.8571rem; font-weight: 600;
  color: var(--green); white-space: nowrap;
}
.wb-section { display: flex; flex-direction: column; min-height: 0; }
#wb-main-section { flex: 2 1 0; min-height: 90px; }
.wb-ocr-section { flex: 1 1 0; min-height: 0; }

/* draggable divider between Main Text and OCR selected */
.wb-resizer {
  flex: 0 0 6px; height: 6px; cursor: row-resize; background: var(--line-strong);
  position: relative; transition: background 0.12s ease;
}
.wb-resizer::before {
  content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 34px; height: 2px; border-radius: 2px; background: var(--muted); opacity: 0.6;
}
.wb-resizer:hover, .wb-resizer.dragging { background: var(--accent); }

/* minimized OCR section: only its header remains visible */
.wb-ocr-section.collapsed { flex: 0 0 auto !important; min-height: 0; }
.wb-ocr-section.collapsed .wb-fields { display: none; }
.wb-min-btn { font-size: 0.8571rem; line-height: 1; padding: 3px 7px; }
#wb-right.ocr-collapsed .wb-resizer { display: none; }
.wb-section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; flex: 0 0 auto;
}
.wb-section-title { font-weight: 700; }
.wb-section-title-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.wb-icon-btn { font-size: 1.0714rem; line-height: 1; padding: 3px 8px; }
.wb-section-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* A visually separate button group inside a section header (left side, after Reset). */
.wb-head-group {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 6px; padding-left: 10px; border-left: 1px solid var(--line-strong);
}

.wb-fields { flex: 1 1 auto; overflow: auto; padding: 10px 12px; }
.wb-empty { color: var(--muted); padding: 20px; text-align: center; }
.wb-field {
  border: 1px solid transparent; border-radius: 7px; padding: 6px 10px; margin: 4px 0;
  cursor: pointer; position: relative; white-space: pre-wrap; word-break: break-word;
  background: var(--panel); user-select: none;
}
.wb-field:hover { background: var(--bg); }
.wb-field.selected { border-color: var(--box-sel); background: rgba(192,57,43,0.07); }
.wb-field.editing { cursor: text; user-select: text; background: #fffef4; border-color: var(--accent); }
.wb-field[contenteditable="true"] { outline: none; }
.wb-field.dragging { opacity: 0.5; }
.wb-field.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.wb-field.drop-after { box-shadow: 0 2px 0 var(--accent); }
/* Hover tools (split / merge up / merge down), shown like the extract "Main"
 * button: only on hover, covering just the text behind them. */
.wb-field-tools {
  display: none; position: absolute; top: 2px; right: 4px; bottom: 2px; z-index: 2;
  align-items: center; gap: 2px; padding-left: 4px;
  background: var(--bg); border-radius: 4px; white-space: nowrap;
}
.wb-field:hover .wb-field-tools { display: flex; }
.wb-field.selected .wb-field-tools { background: #f9ecea; }
.wb-field.editing .wb-field-tools, .wb-field.dragging .wb-field-tools { display: none; }
.wb-tool-merge { display: inline-flex; flex-direction: column; gap: 0; }
.wb-tool-btn {
  border: none; background: transparent; padding: 1px 4px; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 1.0714rem; line-height: 1; border-radius: 3px;
}
.wb-tool-btn:hover { color: var(--ink); background: rgba(0,0,0,0.07); }
.wb-tool-split svg { width: 1.7143rem; height: 1.7143rem; display: block; }
/* table / image bubbles */
.wb-table { border-collapse: collapse; width: 100%; font-size: 0.92em; white-space: normal; }
.wb-table td { border: 1px solid var(--line-strong); padding: 2px 6px; vertical-align: top; }
.wb-field-img { display: block; max-width: 100%; max-height: 220px; border: 1px solid var(--line); border-radius: 4px; }
.wb-field-img-name { display: block; font-size: 0.7857rem; color: var(--muted); margin-top: 2px; }
/* split pop-up: larger text, crosshair, caret at the snapped word boundary */
.split-text {
  position: relative; font-size: 1.4286rem; line-height: 1.7; white-space: pre-wrap; word-break: break-word;
  cursor: crosshair; user-select: none; max-height: 60vh; overflow: auto; padding: 8px 4px;
}
.split-caret { position: absolute; width: 2px; background: var(--danger); pointer-events: none; }
/* OCR selection mode (Texts / Tables / Images) */
.ocr-mode-toggle button { padding: 4px 10px; font-size: 0.8571rem; }
.wb-field-title { font-size: 1.3em; font-weight: 800; }
.wb-field-heading { font-size: 1.12em; font-weight: 700; }
.wb-field-list-item { padding-left: 22px; }
.wb-field-list-item::before { content: "\2022"; position: absolute; left: 10px; color: var(--muted); }
.wb-field-table-row { font-family: ui-monospace, monospace; font-size: 0.8571rem; background: #f8f9fb; }
.wb-field .unknown { text-decoration: underline wavy var(--danger); text-underline-offset: 2px; }
.wb-field:empty:not(.editing)::before { content: "Empty - double-click to type"; color: var(--muted); font-style: italic; }

/* Spellcheck right-click menu (Replace + Add, inline). */
.wb-ctx-menu {
  position: fixed; z-index: 2000; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.18); padding: 6px;
  display: flex; align-items: center; gap: 6px;
}
.wb-ctx-label { font-size: 0.8571rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.wb-ctx-input {
  width: 160px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 5px 7px;
  font: inherit; color: var(--ink); background: var(--panel); outline: none;
}
.wb-ctx-input:focus { border-color: var(--accent); }
.wb-ctx-add {
  border: 1px solid var(--line-strong); background: var(--bg); padding: 5px 10px;
  border-radius: 6px; cursor: pointer; font: 600 0.8571rem inherit; color: var(--ink); white-space: nowrap;
}
.wb-ctx-add:hover { background: var(--panel); border-color: var(--accent); }

.marquee { position: fixed; border: 1px solid var(--accent); background: rgba(47,143,208,0.12); z-index: 50; pointer-events: none; }

/* ---- buttons / inputs ---- */
.btn {
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(0.96); background: var(--accent); }
.btn-ghost { background: transparent; }
.btn-mini { padding: 4px 8px; font-size: 0.8571rem; font-weight: 600; }
.btn-stage-due.is-active,
.btn-stage-due.is-arrangement.is-active { background: var(--due); color: #fff; border-color: var(--due); }
.btn-stage-due.is-arrangement.is-active:hover { filter: brightness(0.96); background: var(--due); }
.btn-stage-complete.is-active { background: var(--green); color: #fff; border-color: var(--green); }

.picker { display: flex; flex-direction: column; gap: 4px; font-size: 0.8571rem; color: var(--muted); }
.picker span { font-weight: 600; }
.picker-block { display: flex; }
.picker select, .picker input {
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 6px 8px;
  font: inherit; color: var(--ink); background: var(--panel);
}
.gc-toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 0.8571rem; cursor: pointer; }

/* md/html formatting toggle (parsing panel) */
.fmt-toggle { justify-content: space-between; }
.fmt-switch { display: inline-flex; align-items: center; gap: 7px; }
.fmt-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.fmt-opt { font-weight: 600; font-size: 0.7857rem; color: var(--muted); letter-spacing: 0.02em; }
.fmt-track {
  position: relative; width: 34px; height: 18px; border-radius: 10px;
  background: var(--line-strong); transition: background 0.15s ease; flex: 0 0 auto;
}
.fmt-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.15s ease;
}
.fmt-switch input:checked + .fmt-track { background: var(--box); }
.fmt-switch input:checked + .fmt-track::after { transform: translateX(16px); }

/* ---- bottom bar ---- */
/* Two halves that line up with the left (preview) and right (text) panes. */
.step-shared-bar {
  display: flex; align-items: center; gap: 0; flex-wrap: nowrap;
  padding: 10px 0; border-top: 1px solid var(--line); background: var(--panel); flex: 0 0 auto;
}
/* Buttons never shrink or overlap: when space runs out the right half grows
 * leftward past the pane divider, shrinking the left half and pushing Notes
 * (right end of the left half) towards Instructions. */
.bar-half { display: flex; align-items: center; gap: 8px; padding: 0 14px; }
.bar-half-left { flex: 1 1 0; min-width: max-content; }
.bar-half-left .bar-notes { margin-left: auto; }
.bar-half-right {
  flex: 0 1 auto; min-width: var(--bar-right, 50%); box-sizing: border-box;
  justify-content: space-between; gap: 8px 12px; border-left: 1px solid var(--line);
}
.bar-group { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.bar-submit, .bar-right { flex: 1 0 auto; min-width: max-content; }
.bar-right { justify-content: flex-end; }
/* Outside Step 2 the submit group keeps its space but is invisible. */
.bar-submit.is-off { visibility: hidden; }
.step-shared-bar .btn { white-space: nowrap; }
.saved-info { color: var(--muted); font-size: 0.8571rem; white-space: nowrap; }
.btn-stage-complete.is-final { background: var(--green); color: #fff; border-color: var(--green); }
.btn-stage-complete.is-final:hover { filter: brightness(0.96); }
.btn-full-submit { background: var(--green); border-color: var(--green); }
.btn-full-submit:hover { background: var(--green); filter: brightness(0.96); }
/* Submit buttons glow when the working text differs from the submitted state. */
.bar-submit .btn.is-dirty { box-shadow: 0 0 0 2px rgba(224,168,0,0.45); }

/* ---- notes ---- */
.notes-wrap { position: relative; }
.notes-popup {
  position: fixed; width: 320px; background: var(--panel);
  border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.15); z-index: 30;
}
.notes-popup-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 600; }
.notes-close { border: none; background: transparent; cursor: pointer; color: var(--muted); }
.notes-area { width: 100%; height: 130px; border: none; padding: 10px; resize: vertical; font: inherit; outline: none; border-radius: 0 0 10px 10px; }

/* ---- instructions ---- */
.instructions-wrap { position: relative; }
.instructions-popup { width: 340px; }
.instructions-body { margin: 0; padding: 10px 12px 12px 28px; font-size: 0.9286rem; line-height: 1.5; color: var(--ink); }
.instructions-body li { margin: 4px 0; }
.instructions-body kbd {
  display: inline-block; padding: 0 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 4px; background: var(--panel); font: 600 0.8571rem ui-monospace, monospace; color: var(--ink);
}

/* While box-select is armed (B key), show a crosshair over selectable areas. */
body.wb-box-select .wb-fields,
body.wb-box-select .wb-field,
body.wb-box-select #wb-pages,
body.wb-box-select .wb-box { cursor: crosshair; }

/* ---- modals ---- */
.modal { position: fixed; inset: 0; background: rgba(15,20,30,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-card { background: var(--panel); border-radius: 12px; width: 460px; max-width: 92vw; max-height: 84vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-wide { width: 720px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.modal-x { border: none; background: transparent; cursor: pointer; font-size: 1.1429rem; color: var(--muted); }
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-list { overflow-y: auto; padding: 8px 16px; flex: 1 1 auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }

.unknown-row, .suggest-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--line); }
.suggest-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: start; }
.suggest-before { color: var(--danger); text-decoration: line-through; }
.suggest-after { color: var(--green); }
.unknown-word { flex: 1 1 auto; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.unknown-card { width: 620px; }
.unknown-head-actions { display: inline-flex; align-items: center; gap: 6px; }
.unknown-hint { padding: 8px 20px 0; color: var(--muted); font-size: 0.8571rem; line-height: 1.4; }
.unknown-cols { display: flex; gap: 10px; padding: 8px 20px 4px; color: var(--muted); font-size: 0.7857rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.unknown-cols span:first-child { flex: 1 1 auto; }
.unknown-cols span:last-child, .unknown-dict { flex: 0 0 120px; display: flex; justify-content: center; }
.unknown-fix { flex: 1 1 auto; min-width: 0; padding: 4px 8px; border: 1px solid transparent; border-radius: 6px; font: inherit; font-weight: 600; background: transparent; }
.unknown-fix:hover { border-color: var(--line); }
.unknown-fix:focus { border-color: var(--accent); background: var(--panel); outline: none; }
.unknown-row.is-corrected .unknown-fix { border-color: var(--accent); background: #e8f2fb; }
.unknown-was { color: var(--muted); font-size: 0.7857rem; white-space: nowrap; }
.unknown-was:empty { display: none; }
/* "Show all unknown": line-break chapter above the unknown words */
.lb-section { border-bottom: 2px solid var(--line); }
.lb-head { display: flex; align-items: center; gap: 8px; padding: 10px 20px 0; font-weight: 700; }
.lb-head-unknown { display: none; }
.lb-section:not([hidden]) ~ .lb-head-unknown { display: flex; }
.lb-count { color: var(--muted); font-weight: 400; font-size: 0.8571rem; }
.lb-list { max-height: 34vh; flex: 0 1 auto; }
.lb-row { display: flex; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--line); }
.lb-parts { display: inline-flex; align-items: center; flex: 0 0 auto; }
.lb-chip { padding: 2px 7px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; font-size: 0.9286rem; }
.lb-chip.left { border-radius: 6px 0 0 6px; border-right-style: dashed; }
.lb-chip.right { border-radius: 0 6px 6px 0; border-left: none; }
.lb-arrow { color: var(--muted); flex: 0 0 auto; }
.lb-fix { flex: 1 1 auto; min-width: 0; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-weight: 600; color: var(--green); background: transparent; }
.lb-fix:focus { border-color: var(--accent); outline: none; }
.lb-meta { color: var(--muted); font-size: 0.7857rem; white-space: nowrap; }
.lb-badge { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px; background: #e8f2fb; color: var(--accent); }
.lb-row .unknown-dict { flex: 0 0 120px; }
.lb-foot { display: flex; justify-content: flex-end; padding: 6px 16px 10px; }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: 0 0 auto; }
.switch input { display: none; }
.switch .track { position: absolute; inset: 0; background: var(--line-strong); border-radius: 22px; transition: 0.15s; }
.switch .track::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* segmented toggle (AI/VLM, Local/Hosted) */
.ai-row { display: flex; gap: 12px; flex-wrap: wrap; }
.seg-toggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg-toggle button { border: none; background: var(--panel); padding: 6px 12px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg-toggle button.active { background: var(--accent); color: #fff; }
.ai-status { display: flex; align-items: center; gap: 10px; min-height: 20px; }
.ai-status-text { color: var(--muted); font-size: 0.8571rem; }
.ai-status-text.error { color: var(--danger); }

/* ===================== Step 2 right-side tabs ===================== */
/* Arrangement | Post-processing | Raw XML/TEI, switched by workbench2b.js. */
.wb-right-tabrow {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 8px 10px 0; flex: 0 0 auto; flex-wrap: wrap;
}
.wb-right-tabs { flex: 0 0 auto; align-self: flex-start; }
/* "Save text as: txt md json xml" - local downloads, visible in every right tab. */
.wb-tabrow-right { display: flex; flex-direction: column; align-items: stretch; gap: 2px; flex: 1 1 auto; min-width: 0; }
.wb-tabrow-line { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.wb-tabrow-line .quality-dots { margin-left: auto; }
.text-stats { align-self: flex-end; font-size: 0.7857rem; color: var(--muted); white-space: nowrap; }
.text-stats b { color: var(--ink); font-weight: 600; }
/* structured quality pop-up */
.qd { line-height: 1.5; }
.qd p { margin: 0 0 8px; }
.qd-summary { font-weight: 600; color: var(--ink); }
.qd-title { margin: 12px 0 4px; font-size: 0.9286rem; }
.qd-list { margin: 0; padding-left: 18px; }
.qd-list li { margin: 2px 0; }
.qd-help { margin-top: 14px !important; font-size: 0.8571rem; color: var(--muted); }
/* Text-quality indicators: four traffic-light dots + language pill. */
.quality-dots { display: inline-flex; align-items: center; gap: 8px; }
.qdot {
  display: inline-flex; align-items: center; gap: 4px; border: 0; background: none;
  padding: 2px 3px; font-size: 0.7857rem; font-weight: 700; letter-spacing: .02em;
  color: var(--muted); cursor: pointer; border-radius: 4px;
}
.qdot:hover { background: #eef1f5; }
.qdot i { width: 10px; height: 10px; border-radius: 50%; background: #c8ced6; display: inline-block; }
.qdot[data-level="ok"] i { background: #2fb36a; }
.qdot[data-level="warn"] i { background: #f0b429; }
.qdot[data-level="bad"] i { background: #e5484d; }
.qdot[data-level="na"] i { background: #c8ced6; }
.qdot[data-level="na"] { color: #9aa3ad; }
.qlang {
  font-size: 0.7857rem; font-weight: 700; padding: 2px 6px; border-radius: 4px;
  background: #1f2937; color: #fff; letter-spacing: .04em;
}
.quality-detail { white-space: pre-line; text-align: left; }
.save-as-group { display: inline-flex; align-items: center; gap: 4px; }
.save-as-label { font-size: 0.8571rem; font-weight: 600; color: var(--muted); margin-right: 2px; }
.save-as-btn { font-family: ui-monospace, monospace; padding: 4px 7px; }
/* Light-green highlight when a tab within Step 2 is marked complete. */
.wb-right-tabs button.stage-complete { background: #e3f5ea; color: var(--green); }
.wb-right-tabs button.stage-complete.active { background: var(--accent); color: #fff; box-shadow: inset 0 -3px 0 var(--green); }
.gate-msg { margin: 4px 2px 2px; font-size: 1rem; line-height: 1.5; }
.wb-right-tab { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#post-main-section { flex: 1 1 auto; min-height: 0; }
.wb-post-status-row { padding: 2px 12px; flex: 0 0 auto; }
.wb2-maintext { background: #fff; }

/* Post-processing editable blocks: keep a comfortable editing feel */
#postMainText .wb2-md-block[contenteditable="true"] { outline: none; cursor: text; }
#postMainText .wb2-md-block[contenteditable="true"]:focus { background: #f4f8ff; border-radius: 6px; }
#postMainText .wb2-md-block.wb2-focus { box-shadow: 0 0 0 2px var(--accent); border-radius: 6px; }
.wb2-edit-box {
  width: 100%; min-height: 60px; resize: vertical; font-family: var(--font);
  font-size: 1rem; line-height: 1.5; padding: 6px 8px;
  border: 1px solid var(--accent); border-radius: 6px;
}

/* Raw XML/TEI read-only view */
.wb-raw-tei {
  flex: 1 1 auto; overflow: auto; margin: 0; padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8571rem;
  line-height: 1.5; background: #0f1420; color: #d7e0ee; white-space: pre;
}

/* Accept/Reject/Edit context menu (mirrors the spellcheck word menu) */
.wb2-change-menu {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  padding: 6px; min-width: 300px; max-width: 90vw; width: 300px;
}
.wb2-change-row { display: flex; align-items: flex-start; gap: 6px; }
.wb2-change-input {
  flex: 1 1 auto; width: auto; resize: none; overflow-y: auto;
  min-height: 30px; max-height: 260px; line-height: 1.4; white-space: pre-wrap;
}
.wb2-change-reject { align-self: flex-start; }
.wb2-ctx-btn {
  border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer;
  padding: 4px 10px; border-radius: 6px; font-weight: 600; font-size: 0.8571rem;
}
.wb2-ctx-btn.ok { color: #0f6c2e; border-color: #9ad0aa; }
.wb2-ctx-btn.no { color: #a11212; border-color: #e3a5a5; }
.wb2-ctx-btn:hover { filter: brightness(0.97); }

/* Show all recommendations modal rows */
.wb2-rec-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px;
}
.wb2-rec-diff { flex: 1 1 auto; line-height: 1.6; white-space: pre-wrap; }
.wb2-rec-acts { flex: 0 0 auto; display: flex; gap: 6px; }

/* page-transition markers (2a field list, 2b markdown + main) */
.wb-page-marker {
  display: flex; align-items: center; gap: 10px; margin: 14px 2px 8px;
  color: var(--muted); font-size: 0.7857rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; user-select: none;
}
.wb-page-marker::before, .wb-page-marker::after {
  content: ""; flex: 1 1 auto; height: 1px; background: repeating-linear-gradient(
    90deg, var(--line-strong) 0 6px, transparent 6px 12px);
}
.wb-page-marker-label {
  background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 1px 10px;
}

/* formatted markdown blocks (left view + right main) */
.wb2-md-block { margin: 0 0 8px; padding: 2px 2px; line-height: 1.6; white-space: pre-wrap; position: relative; }
.wb2-md-title { font-size: 1.35em; font-weight: 800; margin-top: 4px; }
.wb2-md-h { font-weight: 700; }
.wb2-md-h1 { font-size: 1.3em; } .wb2-md-h2 { font-size: 1.18em; }
.wb2-md-h3 { font-size: 1.08em; } .wb2-md-h4, .wb2-md-h5, .wb2-md-h6 { font-size: 1em; }
.wb2-md-li { padding-left: 20px; }
.wb2-md-li::before { content: "\2022"; position: absolute; left: 4px; color: var(--muted); }
.wb2-md-row { font-family: ui-monospace, monospace; font-size: 0.8571rem; background: #f8f9fb; }
#postMainText .wb2-md-block { border-radius: 6px; }
#postMainText .wb2-md-block.wb2-has-changes { background: #fbfdf9; }
/* Selected paragraph: same red as .wb-field.selected in the Arrangement tab. */
#postMainText .wb2-md-block.selected { box-shadow: 0 0 0 1px var(--box-sel); background: rgba(192,57,43,0.07); }

/* ---- tracked-change marks (jsdiff + CriticMarkup styling) ---- */
ins.chg { background: #d7f4dd; color: #0f6c2e; text-decoration: none; border-radius: 3px; padding: 0 1px; }
del.chg { background: #fde0e0; color: #a11212; text-decoration: line-through; border-radius: 3px; padding: 0 1px; }
.space-removed {
  color: #c026d3; font-weight: 700; border-bottom: 2px dotted #c026d3;
  padding: 0 1px; cursor: help;
}
.para-break {
  color: #1d4ed8; font-weight: 700; background: #dbeafe; border-radius: 3px;
  padding: 0 3px; margin: 0 1px; cursor: help;
}

/* rework results (Edit Segment panel) */
.wb2-rework-row { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.wb2-rework-row.changed { border-color: #9ad0aa; background: #f6fdf8; }
.wb2-rework-diff { line-height: 1.6; white-space: pre-wrap; }

/* Supportive comments/keywords field in the AI modal */
.ai-supportive {
  width: 100%; resize: vertical; min-height: 56px; font-family: var(--font);
  font-size: 0.9286rem; padding: 8px 10px; border: 1px solid var(--line-strong);
  border-radius: 8px;
}

/* ---- misc ---- */
.placeholder { color: var(--muted); padding: 30px; text-align: center; }
.drop-overlay { position: fixed; inset: 0; background: rgba(47,143,208,0.15); display: flex; align-items: center; justify-content: center; z-index: 200; }
.drop-overlay-inner { background: var(--panel); padding: 20px 30px; border-radius: 12px; font-weight: 700; border: 2px dashed var(--accent); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1f2430; color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 9999; box-shadow: 0 8px 24px rgba(0,0,0,0.25); }
.toast.ok { background: #1e7a46; }
.toast.error { background: var(--danger); }
.hidden { display: none !important; }
/* The `hidden` attribute must beat class-based display rules (e.g. .modal/.drop-overlay
   set display:flex, which otherwise outranks the UA [hidden] rule and shows them on load). */
[hidden] { display: none !important; }

/* ---- Interpretation / Analysis (Step 3) ---- */
#an { display: flex; height: 100%; min-height: 0; }
#an-left {
  flex: 1 1 55%; min-width: 0; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); position: relative;
}
#an-tools { border-bottom: 1px solid var(--line); background: var(--panel); flex: 0 0 auto; }
.an-pane { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.an-fields { flex: 1 1 auto; overflow: auto; padding: 10px 12px; }
/* Field takes 3/4, the summary sits in the remaining 1/4 gutter on the right. */
.an-field-wrap {
  width: 100%; max-width: 100%; margin: 6px 0;
  display: flex; align-items: flex-start; gap: 10px;
}
.an-field-wrap .wb-field { margin: 0; flex: 0 0 75%; max-width: 75%; }
.an-field-wrap.an-topic-hl .wb-field {
  background: #e8e8e8; border-color: #9a9a9a;
  box-shadow: inset 0 0 0 1px #9a9a9a;
}
.an-field-wrap.selected .wb-field { border-color: var(--box-sel); background: rgba(192,57,43,0.07); }
.an-field-wrap.an-analyzed { cursor: pointer; }
.an-field-wrap.an-analyzed .wb-field { cursor: pointer; }
.an-summary {
  flex: 1 1 25%; min-width: 0; display: flex; flex-direction: column;
  align-items: flex-start; gap: 4px; padding-top: 2px;
}
.an-summary-type {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.7857rem; font-weight: 700;
  background: #eef1f4; border: 1px solid var(--line-strong); color: var(--muted);
}
.an-summary-type.type-pre { background: #f3e8ff; border-color: #c4a8e8; color: #5b2d8e; }
.an-summary-type.type-op { background: #e8f8ef; border-color: #9ad0aa; color: #1e7a46; }
.an-summary-count { font-size: 0.7857rem; color: var(--muted); font-weight: 600; }
.an-bubbles { display: flex; flex-wrap: wrap; gap: 5px; padding: 6px 0 0; }
.an-bubble {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: #e8f2fb; border: 1px solid #b7d4ea; font-size: 0.7857rem;
  font-weight: 600; color: #1a4a6e; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.an-bubble.type-pre { background: #f3e8ff; border-color: #c4a8e8; color: #5b2d8e; }
.an-bubble.type-op { background: #e8f8ef; border-color: #9ad0aa; color: #1e7a46; }
/* Certainty % on the type badge and tag bubbles (same size, muted). */
.an-pct { font-size: inherit; font-weight: 400; opacity: 0.65; font-variant-numeric: tabular-nums; }

#an-right { flex: 1 1 45%; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.an-edit-body { flex: 1 1 auto; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.an-edit-seg {
  display: flex; flex-direction: column; border-bottom: 1px solid var(--line);
  padding: 10px 12px; gap: 8px;
}
.an-para-text {
  font-size: 0.9286rem; line-height: 1.5; color: var(--ink); white-space: pre-wrap;
  background: #fafbfc; border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 10px; max-height: 220px; overflow: auto;
}
.an-edit-placeholder .an-placeholder-body {
  border: 1px dashed var(--line-strong); border-radius: 7px;
  padding: 12px; text-align: center; background: #fafbfc;
}
.an-edit-placeholder:last-child { border-bottom: none; }
.an-edit-seg-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
.an-edit-seg-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.an-type-switch {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.8571rem; font-weight: 600;
  cursor: pointer; user-select: none;
}
.an-type-switch input {
  position: absolute; opacity: 0; width: 0; height: 0;
}
.an-type-switch .fmt-track { background: #9b59b6; }
.an-type-switch input:checked + .fmt-track { background: var(--green); }
.an-type-switch input:checked + .fmt-track::after { transform: translateX(16px); }
.an-type-opt { color: var(--muted); }
.an-type-switch:not(:has(input:checked)) .an-type-opt[data-side="pre"],
.an-type-switch:has(input:checked) .an-type-opt[data-side="op"] { color: var(--ink); }
.an-type-switch-modal { margin-bottom: 12px; }

.an-hint { font-size: 0.8571rem; color: var(--muted); margin: 0; }
.an-filter-body { display: grid; grid-template-columns: 1fr; gap: 16px; max-height: 60vh; }
.an-filter-col h4 { margin: 0 0 4px; }
.an-filter-list {
  max-height: 48vh; overflow: auto; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px;
}
.an-filter-item {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px;
  border-radius: 6px; cursor: pointer; font-size: 0.9286rem;
}
.an-filter-item:hover { background: var(--bg); }
.an-filter-item.inactive { color: #999; }
.an-class-list {
  max-height: 55vh; overflow: auto; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px;
}
.an-class-group { margin-bottom: 10px; }
.an-class-group-title {
  font-size: 0.7857rem; font-weight: 700; text-transform: uppercase;
  color: var(--muted); padding: 4px 6px;
}
.an-class-item {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px;
  border-radius: 6px; cursor: pointer; font-size: 0.9286rem;
}
.an-class-item:hover { background: var(--bg); }
.an-class-item input { flex: 0 0 auto; }
.an-preview-box.selected { border-color: var(--box-sel); background: rgba(192,57,43,0.22); }

@media (max-width: 900px) {
  #an { flex-direction: column; }
  #an-left, #an-right { flex: 1 1 auto !important; }
  .pane-splitter[data-split="an"] { display: none; }
  .an-field-wrap { width: 100%; max-width: 100%; }
}

/* ===================== Section 1: Metadata Extraction ===================== */
#md { display: flex; height: 100%; min-height: 0; }
#md-left {
  flex: 1 1 50%; min-width: 0; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); position: relative;
}
#md-tools { border-bottom: 1px solid var(--line); background: var(--panel); flex: 0 0 auto; }
#md-pages { flex: 1 1 auto; overflow: auto; padding: 14px; background: #eceef1; }
#md-right { flex: 1 1 50%; min-width: 0; display: flex; flex-direction: column; }
#md-meta-section { flex: 1 1 0; min-height: 120px; }
/* Left panel switch: Document Preview | Parsing results */
#md-results-pane { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
#md-results-pane[hidden], #md-pages[hidden] { display: none; }
.md-left-tabs button { white-space: nowrap; }

.md-form {
  flex: 1 1 auto; overflow: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.md-field { display: flex; flex-direction: column; gap: 3px; }
.md-field-label { font-size: 0.8571rem; font-weight: 600; color: var(--muted); }
.md-input {
  width: 100%; box-sizing: border-box; padding: 6px 8px; font: inherit;
  border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; color: var(--ink);
  resize: vertical;
}
.md-input:focus { outline: none; border-color: var(--accent); }
.md-input:disabled { background: #f2f4f6; color: var(--muted); cursor: not-allowed; }
.md-input.md-input-readonly { background: #f2f4f6; color: var(--muted); cursor: default; }
.md-form-disabled .md-field-label { color: var(--muted); }
.md-field.md-drop-hover .md-input {
  border-color: var(--accent); background: #eef4ff; box-shadow: 0 0 0 2px rgba(80,130,255,0.18);
}
.md-result { cursor: grab; position: relative; }
.md-result .wb-field-tools { cursor: default; }
.md-result.dragging { opacity: 0.5; }
/* Parse-result boxes in the Section 1 preview are drag sources too. */
.md-src-box[draggable="true"] { cursor: grab; }
body.md-box-select #md-pages, body.md-box-select #md-pages .wb-box { cursor: crosshair; }
.md-src-box.dragging { opacity: 0.4; }
.md-drag-ghost {
  position: fixed; top: -1000px; left: -1000px; max-width: 320px; margin: 0;
  border-color: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,0.18);
}

/* Language field (Tagify bubbles). Side padding leaves room to click left /
 * right of the bubbles. */
.md-lang-field .tagify {
  --tags-border-color: var(--line-strong); --tags-hover-border-color: var(--line-strong);
  --tags-focus-border-color: var(--accent); --tag-bg: #e6eefb; --tag-hover: #d6e3f8;
  --tag-text-color: var(--ink); --tag-pad: 0.25em 0.55em;
  width: 100%; box-sizing: border-box; border-radius: 6px; background: #fff;
  padding: 2px 14px; min-height: 32px; cursor: text;
}
.md-lang-field .tagify__tag:first-child .tagify__tag-text { font-weight: 700; }
.md-lang-field .tagify__tag:first-child { --tag-bg: #d3e4fb; }
.md-lang-field.md-drop-hover .tagify {
  border-color: var(--accent); background: #eef4ff; box-shadow: 0 0 0 2px rgba(80,130,255,0.18);
}
.md-lang-dropdown .md-lang-sub { color: var(--muted); font-size: 0.8571rem; }
.md-lang-row { display: flex; gap: 6px; align-items: stretch; }
.md-lang-row .tagify, .md-lang-row .md-lang-input { flex: 1 1 auto; min-width: 0; }
.md-lang-row .md-lang-status { flex: 0 0 auto; width: auto; max-height: 41px; resize: none; cursor: pointer; }

/* Section 2: Language button + language pop-up */
.lang-btn {
  font: inherit; font-weight: 700; color: var(--ink); padding: 2px 8px; max-width: 120px;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--panel); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lang-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.lang-btn:disabled { opacity: 0.5; cursor: default; }
.lang-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 10px; }
.lang-col { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 80px; }
.lang-col-head { font-weight: 700; font-size: 0.8571rem; color: var(--muted); margin-bottom: 6px; }
.lang-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; }
.lang-row-name small { color: var(--muted); margin-left: 6px; }
.lang-row-nodict { color: var(--danger); font-size: 0.7857rem; margin-left: 6px; }
.lang-col-empty { color: var(--muted); font-size: 0.8571rem; }

.pane-foot { flex: 0 0 auto; padding: 10px 8px; border-top: 1px solid var(--line); background: var(--panel); }

/* Variations dropdowns of the step buttons (extract versions / analysis runs).
 * Positioned under their step button by app.js (position: fixed). */
.step-dropdown {
  position: fixed; z-index: 900; width: 300px; max-width: calc(100vw - 16px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); overflow: hidden;
}
.step-dropdown[hidden] { display: none; }
.step-dropdown-head {
  display: flex; align-items: center; gap: 6px; padding: 0 12px; height: 18px;
  background: #eaecef; font-size: 0.8571rem; font-weight: 600; color: var(--ink);
}
.step-dropdown-head .count { margin-left: auto; line-height: 1.4; }
.extract-list { list-style: none; margin: 0; padding: 2px 0 8px 6px; overflow-y: auto; max-height: min(60vh, 420px); }
.extract-empty { margin: 0; padding: 8px 12px; color: var(--muted); font-size: 0.8571rem; }
.step-caret {
  display: inline-block; margin-right: 8px; font-size: 0.7143rem; color: var(--muted);
  transform: rotate(-90deg); transition: transform 0.15s ease;
}
.step-btn.dropdown-open .step-caret { transform: none; color: var(--accent); }
.run-q {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 52px; font-size: 0.7857rem; color: var(--muted);
}
.row-trail {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: auto; flex: 0 0 auto;
}
.extract-item {
  display: flex; flex-direction: row; align-items: center; gap: 8px; position: relative;
  padding: 6px 3px 6px 5px; border-radius: 0; cursor: pointer; min-height: 42px;
  border-left: 3px solid transparent; font-size: 1rem;
}
.extract-item:hover { background: var(--bg); }
.extract-item.selected { background: #e8f2fb; border-left-color: var(--accent); }
.extract-item.selected:hover { background: #e8f2fb; }
.extract-name {
  flex: 1 1 auto; min-width: 0; font-size: 1rem; font-weight: 400; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.extract-item.is-main .extract-name { font-weight: 700; }
.extract-q { position: relative; flex: 0 0 auto; height: 42px; }
.extract-main-btn {
  display: none; position: absolute; inset: 0; z-index: 1;
  align-items: center; justify-content: center;
  border: none; border-radius: 4px; background: var(--bg);
  padding: 0; cursor: pointer; font: inherit; font-size: 0.8571rem; font-weight: 700; color: var(--ink);
}
.extract-item.selected .extract-main-btn { background: #e8f2fb; }
.extract-item:hover .extract-main-btn { display: flex; }
.extract-item.is-main .extract-main-btn { display: none; }
/* Metadata variations: the row background is the completion stage. */
.md-var-item { margin: 2px 6px 2px 0; border-radius: 4px; min-height: 36px; }
.md-var-item.md-var-pending, .md-var-item.md-var-pending:hover { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.md-var-item.md-var-due, .md-var-item.md-var-due:hover { background: #f6e2a0; }
.md-var-item.md-var-complete, .md-var-item.md-var-complete:hover { background: #bfe3cb; }
.md-var-item:hover { filter: brightness(0.97); }
.md-var-item.selected { border-left-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.md-var-main-btn {
  display: none; border: none; border-radius: 4px; background: rgba(255, 255, 255, 0.75);
  padding: 2px 8px; cursor: pointer; font: inherit; font-size: 0.8571rem; font-weight: 700; color: var(--ink);
}
.md-var-item:hover .md-var-main-btn { display: inline-block; }
.md-var-item.is-main .md-var-main-btn { display: none; }
.step-dropdown.is-busy .extract-item { cursor: default; }
.step-dropdown.is-busy .extract-main-btn,
.step-dropdown.is-busy .doc-del { visibility: hidden; pointer-events: none; }
.btn-block { display: block; width: 100%; text-align: center; }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(0.96); }

/* Full-window Document Table View */
.doc-table-view {
  position: fixed; inset: 0; z-index: 1200; background: var(--bg, #fff);
  display: flex; flex-direction: column;
}
.doc-table-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.doc-table-title { font-weight: 700; }
.doc-table-info { color: var(--muted); font-size: 0.9286rem; margin-left: auto; }
.doc-table-scroll { flex: 1 1 auto; overflow: auto; padding: 0; }
.doc-table { border-collapse: collapse; width: 100%; font-size: 0.9286rem; }
.doc-table th, .doc-table td {
  border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top;
  min-width: 90px; max-width: 320px;
}
.doc-table thead th {
  position: sticky; top: 0; background: var(--panel); z-index: 1; white-space: nowrap;
}
.doc-table-fixed { color: var(--muted); background: #fafbfc; }
.doc-table-edit { background: #fff; cursor: text; }
.doc-table-edit:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: #eef4ff; }

@media (max-width: 900px) {
  #md { flex-direction: column; }
  #md-left, #md-right { flex: 1 1 auto !important; }
  .pane-splitter[data-split="md"] { display: none; }
}


/* ===== Project / user bar (server-side projects) ===== */
.project-bar {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-strong);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
}
.project-row { display: flex; align-items: center; gap: 6px; }
.project-label {
  font-size: 0.7857rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: 46px;
  flex: 0 0 auto;
}
.project-row select {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 0.8571rem;
  padding: 3px 4px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
}
.project-actions { justify-content: space-between; }
.project-actions .btn { flex: 1 1 0; padding: 2px 4px; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { border-color: var(--danger); }

/* ===== Work mode switch + working directory ===== */
.collapse-btn { margin-left: auto; flex: 0 0 auto; }
.btn-gear { display: inline-flex; align-items: center; justify-content: center; padding: 5px 8px; }
.gear-icon { width: 18px; height: 18px; fill: currentColor; display: block; }
.mode-switch { cursor: pointer; }
.mode-switch .fmt-opt { font-size: 0.8571rem; }
.mode-switch .fmt-track { background: #8e6c3a; }
.mode-switch input:checked + .fmt-track { background: var(--accent); }
body.mode-archive .mode-switch .fmt-opt[data-side="archive"],
body:not(.mode-archive) .mode-switch .fmt-opt[data-side="independent"] { color: var(--ink); }
body.mode-archive .project-bar { background: #f7f1e8; }
.mode-archive .project-label { width: auto; min-width: 46px; }
.workdir-btn {
  flex: 1 1 0; min-width: 0; text-align: left; font: inherit; font-size: 0.7857rem; font-weight: 600;
  padding: 2px 6px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--panel); color: var(--ink); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl;
}
.workdir-btn:hover { border-color: var(--accent); }

/* ===== Archive tree (modal + table view) ===== */
.arch-modal-card { height: 78vh; }
.arch-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.arch-hint { color: var(--muted); font-size: 0.8571rem; margin-left: auto; }
.arch-tree { overflow: auto; font-size: 0.9286rem; user-select: none; }
.arch-tree-modal { flex: 1 1 auto; padding: 8px 12px; min-height: 0; }
.arch-tree ul { list-style: none; margin: 0; padding-left: 16px; }
.arch-tree > ul { padding-left: 0; }
.arch-node {
  display: flex; align-items: center; gap: 5px; padding: 3px 6px; border-radius: 6px; cursor: pointer;
  white-space: nowrap;
}
.arch-node:hover { background: var(--bg); }
.arch-node.selected { background: #e8f2fb; box-shadow: inset 3px 0 0 var(--accent); }
.arch-node.drop-target { background: #dff0ff; outline: 2px dashed var(--accent); outline-offset: -2px; }
.arch-node.dragging { opacity: 0.5; }
.arch-caret { width: 14px; flex: 0 0 auto; color: var(--muted); text-align: center; font-size: 0.7143rem; }
.arch-name { overflow: hidden; text-overflow: ellipsis; }
.arch-count { color: var(--muted); font-size: 0.7857rem; }
.arch-lock { font-size: 0.7857rem; }
.arch-doc { color: var(--muted); font-weight: 400; cursor: grab; }
.arch-doc .arch-name { color: var(--ink); }
.arch-selected-path { margin-right: auto; color: var(--muted); font-size: 0.8571rem; align-self: center; }

/* ===== Import duplicate dialog ===== */
.dup-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.dup-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr); gap: 10px; align-items: center;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
}
.dup-file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.dup-file small { display: block; color: var(--muted); font-weight: 400; }
.dup-row input[type="text"] {
  font: inherit; font-size: 0.8571rem; padding: 4px 6px; border: 1px solid var(--line-strong); border-radius: 6px; width: 100%;
}
.dup-row input[type="text"]:disabled { opacity: 0.45; }

/* ===== Document Table View: archive tree + summary ===== */
.doc-table-scope { color: var(--muted); font-size: 0.9286rem; }
.doc-table-tree-wrap {
  flex: 0 0 auto; height: 220px; min-height: 34px; display: flex; flex-direction: column;
  background: var(--panel); border-bottom: 1px solid var(--line); position: relative;
}
.doc-table-tree-wrap.folded { height: 34px !important; }
.doc-table-tree-wrap.folded .doc-table-tree, .doc-table-tree-wrap.folded .wb-resizer { display: none; }
.doc-table-tree-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 14px; }
.doc-table-tree { flex: 1 1 auto; min-height: 0; padding: 0 14px 6px; }
.doc-table-summary {
  flex: 0 0 auto; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--panel);
  color: var(--muted); font-size: 0.8571rem; display: flex; flex-wrap: wrap; gap: 14px;
}
.doc-table-summary b { color: var(--ink); }
.doc-table tr.doc-table-sub td { background: #fbfcfd; }
.doc-table tr.doc-table-sep td {
  background: var(--bg); color: var(--muted); font-size: 0.7857rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.doc-table-head { flex-wrap: wrap; row-gap: 6px; }
.doc-table-seg button { padding: 4px 10px; font-size: 0.8571rem; }
.doc-table-toggle[hidden] { display: none; }
.doc-table-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.doc-table-fmt { font-size: 0.8571rem; padding: 3px 4px; }
.doc-table-tree-hint { color: var(--muted); font-size: 0.7857rem; margin-left: 10px; margin-right: auto; }
.doc-table td.rec-ind { white-space: nowrap; min-width: 70px; }
.doc-table td.rec-cell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.doc-table .rec-pct { font-size: 0.7857rem; color: var(--muted); }
.doc-table tbody tr td[data-level="ok"] { color: #1b6e3a; background: #eaf8ef; }
.doc-table tbody tr td[data-level="warn"] { color: #7a5a00; background: #fff6dc; }
.doc-table tbody tr td[data-level="bad"] { color: #a1262b; background: #fdecec; }
/* Records view (nested): grey document header, extracts, unfoldable pages */
.doc-table tr.rec-doc td {
  background: #e9ecef; color: var(--ink); font-weight: 700; max-width: none;
  border-top: 2px solid var(--line-strong);
}
/* Horizontal scroll: document header text and the Extract column stay put */
.doc-table .rec-doc-label { position: sticky; left: 8px; display: inline-block; }
.doc-table th.rec-sticky, .doc-table td.rec-sticky {
  position: sticky; left: 0; z-index: 2; box-shadow: 1px 0 0 var(--line-strong);
}
.doc-table thead th.rec-sticky { z-index: 3; }
.doc-table .rec-doc-folder { margin-left: 12px; font-weight: 400; color: var(--muted); font-size: 0.7857rem; }
.doc-table tr.rec-extract td { background: #fff; color: var(--ink); }
.doc-table tr.rec-main td { font-weight: 700; }
.doc-table tr.rec-page td, .doc-table tr.rec-page-flat td { background: #fafbfc; color: var(--muted); font-size: 0.8571rem; }
.doc-table tr.rec-page td:first-child { padding-left: 30px; }
.doc-table tr.rec-empty td { color: var(--muted); font-style: italic; }
.rec-caret {
  border: none; background: none; cursor: pointer; width: 18px; padding: 0; margin-right: 4px;
  color: var(--muted); font-size: 0.8571rem;
}
.rec-caret:disabled { cursor: default; }

/* ---- header: AI status, Load AI, API settings gear ---------------------- */
.head-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.head-right .btn { white-space: nowrap; }
.ai-pill { font-size: 0.7857rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap; }
.ai-pill.ai-warm { color: #1b6e3a; border-color: #8fd4a8; background: #eaf8ef; }
.ai-pill.ai-warming { color: #8a5a00; border-color: #f0c674; background: #fff7e0; }
.ai-pill.ai-cold { color: #35507a; border-color: #b7c8e6; background: #eef3fb; }
.ai-pill.ai-off { color: var(--muted); }
.gate-msg { white-space: pre-line; }

/* ---- AI API settings modal --------------------------------------------- */
.modal-card-wide { width: 860px; }
#apiSettingsModal .fp-group { container-type: inline-size; }
.api-hint { margin: 0; font-size: 0.8571rem; color: var(--muted); line-height: 1.45; }
.ocr-quota-field { display: flex; flex-direction: column; gap: 4px; margin: 12px 2px 6px; font-size: 0.8571rem; font-weight: 600; }
.ocr-quota-field input { font: inherit; font-weight: 400; padding: 6px 8px; border: 1px solid var(--line, #ccd); border-radius: 6px; }
.api-hint code { font-size: 0.7857rem; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.api-file { font-weight: 400; font-size: 0.7857rem; color: var(--muted); }
.api-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 14px; }
.api-grid .picker-toggle { align-self: end; }
.api-secret { display: flex; gap: 4px; }
.api-secret input { flex: 1 1 auto; min-width: 0; }
.api-fold { margin: 10px 0 2px; }
.api-fold:not([open]) > :not(summary) { display: none; }
.api-fold > summary {
  cursor: pointer; font-size: calc(0.9286rem + 2px); font-weight: 700; letter-spacing: 0.01em;
}
.api-rates-wrap {
  margin-top: 6px; max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: 8px;
  width: fit-content; min-width: 50cqw; max-width: 100%;
}
.api-rates td.num, .api-rates th.num { text-align: right; }
.api-rates input[type="number"] {
  width: auto; min-width: 0; field-sizing: content; text-align: right; font: inherit; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 7px; padding: 4px 8px;
}
.api-status { display: flex; flex-wrap: wrap; gap: 6px; }
.api-st { font-size: 0.7857rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-strong); }
.api-st.ok { color: #1b6e3a; border-color: #8fd4a8; background: #eaf8ef; }
.api-st.missing { color: #8a3b3b; border-color: #e8b4b4; background: #fdf0f0; }
.api-billing-wrap { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.api-billing { border-collapse: collapse; font-size: 0.7857rem; width: 100%; }
.api-billing.api-rates { width: 100%; max-width: 100%; }
.api-billing th, .api-billing td { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.api-billing th { position: sticky; top: 0; background: var(--panel); font-weight: 700; }
.api-st.warn { color: #7a5a00; border-color: #e6cf85; background: #fdf7e3; }

/* Preferences > Self-hosting (selfhost.js) */
.sh-local { display: flex; flex-direction: column; gap: 6px; }
.sh-ollama-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 2px 0; }
.sh-ollama-info { font-size: 0.7857rem; color: var(--muted); }
.sh-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; margin-top: 4px; }
.sh-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sh-col-head {
  font-size: calc(0.7857rem + 2px); font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.04em; padding-bottom: 3px; border-bottom: 1px solid var(--line);
}
.sh-group-head { font-size: 0.8571rem; font-weight: 700; color: var(--ink); margin: 4px 0 0; }
.sh-card {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel);
  display: flex; flex-direction: column; gap: 4px;
}
.sh-card:hover { border-color: var(--line-strong); }
.sh-card.inactive { background: var(--bg); }
.sh-card.inactive .sh-name, .sh-card.inactive .sh-strengths { opacity: 0.6; }
.sh-card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.sh-name { font-size: 0.9286rem; }
.sh-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 0.7857rem; color: var(--muted); }
.sh-meta code { font-size: 0.7143rem; background: var(--bg); padding: 0 4px; border-radius: 4px; }
.sh-strengths { font-size: 0.8214rem; line-height: 1.4; color: var(--ink); }
.sh-actions { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.sh-actions a.btn { text-decoration: none; }
.sh-actions .sh-active { margin-left: auto; cursor: pointer; }
.sh-remove:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }
.sh-job { display: flex; flex-direction: column; gap: 2px; font-size: 0.7857rem; color: var(--muted); }
.sh-job-err { color: var(--danger); }
.sh-prog { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.sh-prog-fill { height: 100%; background: var(--accent); transition: width 0.3s ease; }
.sh-prog.indet .sh-prog-fill { animation: sh-indet 1.2s ease-in-out infinite; }
@keyframes sh-indet { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
@container (max-width: 560px) { .sh-cols { grid-template-columns: 1fr; } }

/* ===================== Full-page settings views (Preferences, Help) ===================== */
/* Below regular modals (z 100) so dialogs opened from these pages stay on top. */
.modal.modal-fullpage { z-index: 90; background: var(--bg); align-items: stretch; justify-content: stretch; }
.modal-fullpage .fp-card {
  width: 100%; max-width: none; max-height: none; height: 100%; border-radius: 0; box-shadow: none;
  background: var(--bg); display: flex; flex-direction: column;
}
.fp-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.fp-title { font-weight: 700; font-size: 1.1429rem; }
.fp-head-actions { margin-left: auto; display: flex; gap: 8px; }
.fp-foot {
  flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 8px;
  padding: 10px 18px; border-top: 1px solid var(--line); background: var(--panel);
}
.fp-layout { flex: 1 1 auto; min-height: 0; display: flex; }
.fp-nav {
  flex: 0 0 240px; overflow-y: auto; padding: 16px 10px; display: flex; flex-direction: column; gap: 2px;
  border-right: 1px solid var(--line); background: var(--bg);
}
.fp-nav a {
  display: block; padding: 8px 14px; border-radius: 8px; color: var(--ink); text-decoration: none;
  font-size: 0.9286rem; font-weight: 600;
}
.fp-nav a.fp-sub { padding: 5px 14px 5px 30px; font-weight: 400; font-size: 0.8571rem; color: var(--muted); }
.fp-nav a:hover { background: var(--line); }
.fp-nav a.active { background: #e3f0fa; color: var(--accent); }
.fp-content { flex: 1 1 auto; min-width: 0; overflow-y: auto; padding: 8px 32px 48px; }
.fp-chapter { max-width: 920px; margin: 0 auto; }
.fp-chapter > h2 { font-size: 1.2857rem; margin: 22px 4px 10px; }
.fp-group {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 18px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px;
}
.fp-group > h3 { margin: 0; font-size: calc(0.9286rem + 2px); letter-spacing: 0.01em; }
.fp-group .api-fold { margin: 0; }
@media (max-width: 760px) { .fp-nav { flex-basis: 170px; } .fp-content { padding: 8px 14px 40px; } }

/* ===================== Help ===================== */
.fp-content.help-body { line-height: 1.55; font-size: 0.9286rem; }
.help-body .fp-chapter {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 2px 22px 14px; margin-top: 22px;
}
.help-body .fp-chapter > h2 { margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.help-body h3 { font-size: 1rem; margin: 16px 0 4px; }
.help-body p { margin: 6px 0; }
.help-body ul { margin: 4px 0 8px; padding-left: 20px; }
.help-body li { margin: 3px 0; }
.help-body code { font-size: 0.8571rem; background: var(--bg); padding: 0 4px; border-radius: 4px; }
.help-body kbd {
  display: inline-block; min-width: 1.2em; padding: 0 5px; font: 600 0.8571rem ui-monospace, monospace;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--panel); text-align: center;
}
/* ===================== Preferences: Display ===================== */
.pref-row { display: flex; align-items: center; gap: 8px; }
.pref-label { font-size: 0.9286rem; min-width: 70px; }
.pref-row input[type="range"] { width: 180px; }
.pref-value { min-width: 2em; text-align: center; }

/* ===================== Page Navigation tour ===================== */
.tour-overlay { position: fixed; inset: 0; z-index: 3000; cursor: pointer; }
.tour-dim { position: absolute; inset: 0; }
.tour-spot { position: absolute; border: 2px solid #2f8fd0; border-radius: 8px; pointer-events: none; }
.tour-spot-step { border-width: 3px; box-shadow: 0 0 0 3px rgba(47,143,208,0.35); }
.tour-cap {
  position: absolute; display: inline-flex; align-items: center; gap: 8px; max-width: 280px;
  background: #fff; color: #1a5f99; font-weight: 600; font-size: 0.9286rem; line-height: 1.3;
  padding: 6px 10px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.25); pointer-events: none;
}
.tour-cap-step { font-size: 1.1429rem; max-width: 320px; padding: 8px 14px; }
.tour-badge {
  flex: 0 0 auto; width: 2em; height: 2em; border-radius: 50%; background: #2f8fd0; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.4286rem; font-weight: 800;
}
.tour-title {
  position: absolute; transform: translate(-50%, -50%); color: #fff; text-align: center; white-space: nowrap;
  font-size: 1.5714rem; font-weight: 700; text-shadow: 0 2px 8px rgba(0,0,0,0.5); pointer-events: none;
}
.tour-title span { display: block; font-size: 0.8571rem; font-weight: 500; opacity: 0.85; }

.app-version { font-size: 0.7857rem; color: var(--muted); opacity: 0.8; align-self: center; user-select: text; }

/* Update WebApp Version (localhost only) */
#btnUpdate {
  background: linear-gradient(180deg, #fbe7a1, #f0c94d); color: #5c4200; border-color: #d4a82a; font-weight: 700;
}
#btnUpdate:hover:not(:disabled) { filter: brightness(1.05); }
#btnUpdate.has-update {
  background: linear-gradient(180deg, #f5cf4e, #d9a514); color: #3d2c00; border-color: #b8860b;
  box-shadow: 0 0 0 2px rgba(218, 165, 32, 0.35);
}
.update-card { width: 520px; }
.update-detail { color: var(--muted); font-size: 0.8571rem; line-height: 1.45; word-break: break-word; }

/* ===================== Section 3: paragraph categorization ===================== */
#an-tools { position: relative; }
.an-settings-pop {
  position: absolute; z-index: 850; top: calc(100% - 6px); left: 12px; width: 340px;
  max-width: calc(100% - 24px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); overflow: hidden;
}
.an-settings-pop[hidden] { display: none; }
.an-set-block { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.an-set-block:last-child { border-bottom: none; }
.an-set-title { font-size: 0.8571rem; font-weight: 700; color: var(--ink); }
.an-engine-seg button, .an-type-seg button { padding: 3px 10px; font-size: 0.8571rem; }
.an-thr-row { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8571rem; }
.an-thr-row input { width: 64px; margin-left: 4px; }
#anBtnSettings[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#anBtnSettings[aria-expanded="true"] .gear-icon { fill: #fff; }

.an-summary-type { cursor: pointer; }
.an-summary-type.type-undef { background: #f4f4f4; border-color: var(--line-strong); color: var(--muted); }
.an-summary-type.is-review {
  background: #fde8e6; border-color: #e0786c; color: #a42618;
  box-shadow: 0 0 0 2px rgba(224, 120, 108, 0.25);
}
.an-summary-type.is-manual::after { content: " \270E"; font-weight: 400; }
.an-field-wrap.an-review .wb-field { border-color: #e0786c; }
.an-bubble.is-review { background: #fde8e6; border-color: #e0786c; color: #a42618; }
.an-bubble.is-below { opacity: 0.55; border-style: dashed; }
.an-bubble.is-manual { border-style: solid; border-width: 2px; }
.an-type-info { font-size: 0.8571rem; color: var(--muted); line-height: 1.45; }
.an-type-info b { color: var(--ink); }
.an-type-info .an-review-msg { color: #a42618; font-weight: 600; }
.an-type-seg button.active { font-weight: 700; }
.an-head-btn { margin-left: auto; }
.an-class-type-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.an-class-item .an-pct { margin-left: 4px; }
.an-class-item.is-below span { color: var(--muted); }

.an-run-body { display: flex; flex-direction: column; gap: 6px; }
.an-run-opt { display: flex; align-items: baseline; gap: 6px; font-size: 0.9286rem; }
.an-run-opt .an-hint { margin: 0; }
.an-run-target { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.an-run-warn { color: #a42618; min-height: 1em; }

.an-thr-body { display: flex; flex-direction: column; gap: 18px; }
.an-thr-part { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.an-thr-part-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.an-thr-part-head .an-hint { margin: 0; }
.an-hist { width: 100%; height: 150px; display: block; }
.an-hist .bar-pre { fill: #b48ae0; }
.an-hist .bar-op { fill: #6cbf8a; }
.an-hist .bar-cat { fill: #7fb0d8; }
.an-hist .thr-line { stroke: #c0392b; stroke-width: 2; }
.an-hist .axis { fill: var(--muted); font-size: 9px; }
.an-hist-legend { display: flex; gap: 12px; font-size: 0.7857rem; color: var(--muted); }
.an-hist-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px; }
.an-thr-slider { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.an-thr-slider input[type="range"] { flex: 1 1 auto; }
.an-thr-slider .val { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.5em; }
.an-thr-preview { font-size: 0.8571rem; color: var(--muted); margin-top: 4px; }

/* ===================== Table view: actions, current document ===================== */
.doc-table-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.doc-table-actions .doc-table-info { margin-left: 0; }
.doc-table tr.doc-current td { background: #e3f1fb; }
.doc-table tr.rec-doc.doc-current td { background: #c9e4f6; }
.doc-table tr.rec-page.doc-current td, .doc-table tr.cat-para.doc-current td { background: #eef7fd; }
.doc-table tr.cat-run td { background: #fff; color: var(--ink); }
.doc-table tr.cat-run.rec-main td { font-weight: 700; }
.doc-table tr.cat-para td { background: #fafbfc; color: var(--muted); font-size: 0.8571rem; }
.doc-table tr.cat-para td:first-child { padding-left: 30px; }
.doc-table td.cat-review { color: #a42618; font-weight: 700; }
.run-parts { display: block; font-size: 0.7143rem; font-weight: 400; color: var(--muted); white-space: normal; line-height: 1.35; }
#analysisRunDropdown { width: 400px; }

/* ---- movable pane borders (layout.js) ---- */
.pane-splitter {
  flex: 0 0 7px; margin: 0 -3px; cursor: col-resize; position: relative; z-index: 20;
}
.pane-splitter::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 2px; width: 3px;
  background: transparent; transition: background 0.12s ease;
}
.pane-splitter:hover::after, .pane-splitter.dragging::after { background: var(--accent); }
#app.collapsed #sidebarSplitter { display: none; }
body.col-resizing { cursor: col-resize; user-select: none; }
body.col-resizing .wb-pages, body.col-resizing .wb-fields { pointer-events: none; }
.pane-list { min-width: 0; overflow: hidden; }
.pane-list .project-row, .pane-list .pane-head { min-width: 0; }
.pane-list .mode-switch, .pane-list .pane-head > span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
/* Frozen preview width: same zoom, grey margins or scroll bars when the pane changes. */
.wb-pages.fixed-base .wb-page { max-width: none; width: calc(var(--page-base) * var(--zoom, 1)); }

/* Tool rows and the bottom bar scroll sideways instead of wrapping or
 * overlapping. The right tab row (Layout / Post-processing / Raw + Save as /
 * quality dots) wraps onto extra lines and grows vertically instead. */
.wb-tool-row, .step-shared-bar {
  flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
}
.wb-tool-row > * { flex-shrink: 0; }
.wb-tool-row > .retrieve-progress { flex-shrink: 1; }
.wb-tool-row2 .engine-label-wrap { flex-shrink: 1; }
.wb-right-tabrow {
  flex-wrap: wrap; overflow-x: visible; overflow-y: visible; row-gap: 6px;
}
.wb-tabrow-right { flex: 1 1 auto; min-width: 0; }
.wb-tabrow-line { flex-wrap: wrap; row-gap: 4px; }
.step-shared-bar > .bar-half { flex-shrink: 0; }
.step-shared-bar > .bar-half-left { flex-shrink: 1; }

/* Help / Page Navigation / Preferences always stay visible; the section
   buttons scroll underneath them when the header is too narrow. */
.step-head { flex-wrap: nowrap; }
.step-tabs {
  flex: 1 1 auto; min-width: 0; overflow-x: auto; overflow-y: hidden;
  padding: 2px 0; scrollbar-width: none;
}
.step-tabs::-webkit-scrollbar { display: none; }
.step-tabs > .step-btn { flex-shrink: 0; }
.head-right { position: relative; z-index: 2; background: var(--bg); }

/* Section 3 tool row: Highlight filter in the middle, between equal side columns. */
.wb-tool-row.an-tool-row {
  display: grid; grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  column-gap: 8px;
}
.an-tool-left { display: flex; align-items: center; gap: 8px; }
.an-tool-row > .wb-tool-right { justify-self: end; margin-left: 0; }

/* Section 3 right pane: tags toggle in a draft, Submit applies it. */
.an-bubble-toggle { cursor: pointer; }
.an-bubble.is-removed { opacity: 0.6; text-decoration: line-through; border-style: dashed; }
.an-bubble.is-draft { box-shadow: 0 0 0 2px rgba(224, 168, 0, 0.45); }
.an-class-submit-row { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.an-class-submit-row .an-hint { margin-right: auto; color: #8a5a00; }
