/* Substituir texto em PDF — página dedicada */
.replace-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-top: 8px;
}
.replace-bar .text-input { width: 100%; }
.replace-bar .btn { min-height: 42px; }

.replace-scope {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.replace-scope .opt-group { flex-wrap: nowrap; }
.replace-scope .opt-label { margin: 0; font-size: 12.5px; }
.replace-scope .text-input {
  width: auto;
  min-width: 112px;
  padding: 7px 9px;
  font-size: 12.5px;
}
.replace-scope #searchRange { width: 104px; min-width: 104px; }
.replace-scope .chk { margin: 0; font-size: 12.5px; }
.replace-scope .hint { flex-basis: 100%; margin: 0; font-size: 12px; }
.replace-scope #searchRangeWrap[hidden] { display: none !important; }

.replace-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.replace-options .chk { margin: 0; font-size: 13.5px; }
.replace-options .hint { flex-basis: 100%; }
.opt-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}
.opt-group .opt-label { margin: 0; }
.chk-compact {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.chk-compact input { width: 15px; height: 15px; accent-color: #2563eb; }
#textColor {
  width: 44px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
#textColor::-webkit-color-swatch-wrapper { padding: 2px; }
#textColor::-webkit-color-swatch { border: 0; border-radius: 5px; }

.replace-warnings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 0;
}
.replace-warning {
  margin: 0;
  padding: 9px 13px;
  border: 1px solid #fcd34d;
  border-radius: 11px;
  background: #fffbeb;
  color: #92400e;
  font-size: 12.5px;
  line-height: 1.5;
}
.replace-warning a { color: #b45309; font-weight: 700; }
[data-theme="dark"] .replace-warning {
  border-color: #a16207;
  background: rgba(161, 98, 7, .16);
  color: #fde68a;
}
.replace-privacy {
  margin: 12px 0 0;
  padding: 9px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 11px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}
.replace-privacy.is-visual {
  border-color: #fcd34d;
  background: #fffbeb;
  color: #92400e;
}
.replace-privacy.is-real {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
}
[data-theme="dark"] .replace-privacy.is-visual {
  border-color: #a16207;
  background: rgba(161, 98, 7, .16);
  color: #fde68a;
}
[data-theme="dark"] .replace-privacy.is-real {
  border-color: #047857;
  background: rgba(4, 120, 87, .18);
  color: #a7f3d0;
}

.replace-batch {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}
.replace-batch summary {
  cursor: pointer;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  list-style: none;
}
.replace-batch summary::-webkit-details-marker { display: none; }
.replace-batch summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 7px;
  color: var(--muted);
  transition: transform .15s ease;
}
.replace-batch[open] summary::before { transform: rotate(90deg); }
.replace-batch-body { padding: 12px 14px 14px; }
.replace-batch-rows { display: flex; flex-direction: column; gap: 8px; }
.replace-batch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.replace-batch-row .text-input { width: 100%; }
.replace-batch-remove {
  padding: 7px 9px;
  line-height: 1;
}
.replace-batch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.replace-batch-actions .btn { padding: 7px 11px; font-size: 12.5px; }
.replace-batch-body .hint { margin-top: 10px; }

.replace-dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  max-width: 420px;
  width: calc(100% - 32px);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .35);
}
.replace-dialog::backdrop { background: rgba(15, 23, 42, .55); }
.replace-dialog form { padding: 20px; }
.replace-dialog h2 { margin: 0 0 8px; font-size: 18px; }
.replace-dialog .text-input { width: 100%; }
.replace-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.replace-howto ol { margin: 8px 0 0; padding-left: 22px; color: var(--muted); line-height: 1.7; }
.replace-howto li { margin: 6px 0; }
.replace-howto strong { color: var(--text); }

.replace-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.replace-results {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
  align-self: stretch;
}
.replace-results-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-wrap: wrap;
}
.replace-results-count {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.replace-results-head strong { font-size: 13px; }
.replace-results-head > .btn { padding: 6px 10px; font-size: 12.5px; white-space: nowrap; margin-left: auto; }
.replace-results-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.replace-results-tools .chk { margin: 0; }
.result-search {
  width: 168px;
  min-width: 130px;
  padding: 5px 8px;
  font-size: 12px;
}
.replace-results-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}
.replace-results-nav .btn {
  padding: 4px 8px;
  font-size: 11.5px;
  margin: 0;
}
.replace-position {
  min-width: 78px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.replace-list {
  max-height: 560px;
  overflow: auto;
  padding: 6px;
}
.replace-list-more {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.replace-list-more[hidden] { display: none !important; }
.replace-list-more .btn { padding: 5px 10px; font-size: 12px; }
.replace-list-more .hint { margin: 0; }
.replace-empty {
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
}
.replace-empty a { color: #2563eb; font-weight: 600; }

.replace-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.replace-group-title span { font-weight: 500; letter-spacing: 0; text-transform: none; }

.replace-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}
.replace-item:hover { background: var(--bg); }
.replace-item.selected { border-color: #2563eb; background: rgba(37, 99, 235, .07); }
.replace-item.done .replace-item-text,
.replace-item.done .replace-check { opacity: .62; }
.replace-item.done .replace-item-text { text-decoration: line-through; text-decoration-thickness: 1px; }
.replace-check {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 3px 0 0;
  accent-color: #2563eb;
  cursor: pointer;
}
.replace-item-main {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}
.replace-item-text { display: block; overflow-wrap: anywhere; }
.replace-item-text mark { background: #fde68a; color: #111; border-radius: 3px; padding: 0 1px; }
.replace-item.done .replace-item-text mark { background: #bbf7d0; }
.replace-linebreak {
  display: inline-block;
  margin: 0 3px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(37, 99, 235, .1);
  color: #1d4ed8;
  font-size: 10px;
  font-weight: 700;
  vertical-align: 1px;
}
.replace-item-badge {
  display: inline-block;
  margin-top: 4px;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 20px;
  background: rgba(37, 99, 235, .1);
  color: #1d4ed8;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .02em;
}
[data-theme="dark"] .replace-linebreak,
[data-theme="dark"] .replace-item-badge {
  background: rgba(96, 165, 250, .18);
  color: #bfdbfe;
}
.replace-item-status {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 7px;
  border-radius: 20px;
  background: rgba(22, 163, 74, .12);
  color: #166534;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .02em;
}
[data-theme="dark"] .replace-item-status { background: rgba(34, 197, 94, .2); color: #86efac; }
.replace-item-preview {
  display: block;
  margin-top: 5px;
  color: #047857;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.replace-item-preview .new { font-weight: 600; }
.replace-item-preview .meta {
  margin-left: 5px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
}
.replace-item-preview .empty { color: #92400e; font-style: italic; }
.replace-item-reason {
  display: block;
  margin-top: 3px;
  color: #92400e;
  font-size: 10.5px;
  line-height: 1.4;
}
.replace-item-undo {
  flex: 0 0 auto;
  align-self: flex-start;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font: 600 10.5px 'Inter', sans-serif;
  cursor: pointer;
}
.replace-item-undo:hover { border-color: #fca5a5; color: #b91c1c; }
[data-theme="dark"] .replace-item-preview { color: #6ee7b7; }
[data-theme="dark"] .replace-item-reason { color: #fde68a; }
[data-theme="dark"] .replace-item-undo { color: #cbd5e1; }

.replace-preview { min-width: 0; }
.replace-pager {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.replace-pager .btn { padding: 6px 12px; }
.page-select { width: 74px; padding: 6px 8px; }
.page-total { font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.zoom-group { display: inline-flex; align-items: center; gap: 4px; }
.zoom-group .btn { padding: 6px 9px; }
.result-filter { font-size: 12px; padding: 5px 8px; width: 100%; max-width: 190px; }
#pageStatus { min-height: 18px; }
#pageStatus.is-warn { color: #b45309; font-weight: 600; }

.replace-canvas-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 280px;
  max-height: min(760px, calc(100vh - 150px));
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background:
    linear-gradient(45deg, rgba(15, 23, 42, .035) 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(-45deg, rgba(15, 23, 42, .035) 25%, transparent 25%) 0 0 / 18px 18px,
    var(--surface);
  overflow: auto;
}
[data-theme="dark"] .replace-canvas-wrap {
  background:
    linear-gradient(45deg, rgba(255, 255, 255, .04) 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(-45deg, rgba(255, 255, 255, .04) 25%, transparent 25%) 0 0 / 18px 18px,
    #0b1220;
}
#previewCanvas {
  display: block;
  max-width: 100%;
  height: auto !important;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, .14);
  cursor: text;
}
.replace-overlay {
  position: absolute;
  top: 10px;
  left: 50%;
  pointer-events: none;
  z-index: 2;
}

.replace-hit {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 1px solid #eab308;
  border-radius: 3px;
  background: rgba(250, 204, 21, .32);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
  cursor: pointer;
  pointer-events: auto;
  transition: background .12s ease, border-color .12s ease;
}
.replace-hit:hover { background: rgba(250, 204, 21, .55); }
.replace-hit:focus-visible,
.replace-applied:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
.replace-hit.done {
  border-color: #16a34a;
  background: rgba(34, 197, 94, .18);
}
.replace-hit.selected {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
  z-index: 3;
}
.replace-applied {
  position: absolute;
  margin: 0;
  padding: 0 1px;
  border: 1px solid rgba(22, 163, 74, .55);
  border-radius: 3px;
  overflow: visible;
  white-space: pre;
  line-height: 1;
  font-family: "DejaVu Sans", Inter, Arial, sans-serif;
  text-align: left;
  appearance: none;
  cursor: pointer;
  pointer-events: auto;
  z-index: 4;
}
.replace-applied.empty { color: transparent; }
.replace-applied.selected {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
  z-index: 5;
}

.replace-export-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.replace-export-row .text-input { flex: 1 1 260px; min-width: 0; }
.replace-export-row .opt-label { margin: 0; }
.replace-export-row .hint { margin: 0; white-space: nowrap; }

.replace-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.replace-actions .btn { padding: 9px 14px; }
.replace-actions-spacer { flex: 1 1 auto; }
#replaceCount { min-height: 20px; }

#resultText { color: #047857; }
[data-theme="dark"] #resultText { color: #6ee7b7; }
#verifyReport p { color: inherit; }
.toast-success { background: #047857; }
#btnExport { background: #047857; border-color: #047857; }
#btnExport:hover:not(:disabled) { background: #065f46; border-color: #065f46; }
.replace-verify {
  margin-top: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  font-size: 13px;
  line-height: 1.55;
}
.replace-verify ul { margin: 6px 0 0; padding-left: 20px; }
.replace-verify li { margin: 2px 0; }
.replace-verify.is-ok { border-color: #a7f3d0; background: #ecfdf5; color: #065f46; }
.replace-verify.is-warn { border-color: #fcd34d; background: #fffbeb; color: #92400e; }
.replace-verify.is-info { border-color: #bfdbfe; background: #eff6ff; color: #1e3a8a; }
[data-theme="dark"] .replace-verify.is-ok { border-color: #047857; background: rgba(4, 120, 87, .18); color: #a7f3d0; }
[data-theme="dark"] .replace-verify.is-warn { border-color: #a16207; background: rgba(161, 98, 7, .16); color: #fde68a; }
[data-theme="dark"] .replace-verify.is-info { border-color: #1d4ed8; background: rgba(30, 64, 175, .2); color: #bfdbfe; }

.replace-warn {
  margin: 14px 0 0;
  padding: 10px 14px;
  border: 1px solid #fcd34d;
  border-radius: 12px;
  background: #fffbeb;
  color: #92400e;
  font-size: 13px;
  line-height: 1.55;
}
.replace-warn a { color: #b45309; font-weight: 700; }
[data-theme="dark"] .replace-warn {
  border-color: #a16207;
  background: rgba(161, 98, 7, .16);
  color: #fde68a;
}

#fileInfo { min-height: 20px; }
.replace-actions .btn-success { background: #16a34a; border-color: #16a34a; }
.replace-actions .btn-success:hover:not(:disabled) { background: #15803d; border-color: #15803d; }

@media (max-width: 980px) {
  .replace-layout { grid-template-columns: 1fr; }
  .replace-results { order: 2; }
  .replace-preview { order: 1; }
  .replace-list { max-height: 330px; }
}

@media (max-width: 640px) {
  .replace-bar { grid-template-columns: 1fr; gap: 10px; }
  .replace-bar .btn { width: 100%; }
  .replace-scope { align-items: stretch; }
  .replace-scope .opt-group { flex: 1 1 100%; }
  .replace-scope .text-input { width: 100%; }
  .replace-results-tools { width: 100%; }
  .result-filter, .result-search { max-width: none; width: 100%; }
  .replace-results-nav { width: 100%; }
  .replace-position { flex: 1 1 auto; }
  .replace-options { padding: 11px 12px; gap: 10px 14px; }
  #replaceMode { min-width: 0 !important; width: 100%; }
  .replace-options .opt-label { margin-left: 0 !important; }
  .opt-group { flex: 1 1 100%; }
  #fontSize { width: 100%; }
  #fontFamily { width: 100% !important; }
  .replace-export-row { align-items: stretch; }
  .replace-export-row .text-input { flex-basis: 100%; }
  .replace-actions { gap: 8px; }
  .replace-actions .btn { flex: 1 1 calc(50% - 8px); }
  .replace-actions #btnReplaceChecked { flex-basis: 100%; }
  .replace-actions-spacer { display: none; }
  .replace-actions #replaceCount { flex-basis: 100%; }
  .replace-warning, .replace-privacy { font-size: 12px; }
  .replace-batch-row { grid-template-columns: 1fr auto; }
  .replace-batch-row input[data-batch="replace"] { grid-column: 1 / 2; }
  .replace-batch-row .replace-batch-remove { grid-column: 2 / 3; grid-row: 1 / 3; align-self: stretch; }
  .replace-batch-actions .btn { flex: 1 1 100%; }
  .replace-pager { justify-content: center; }
  #pageStatus { flex-basis: 100%; text-align: center; }
  .replace-canvas-wrap { min-height: 200px; padding: 6px; }
  .replace-overlay { top: 6px; }
  .replace-canvas-wrap { max-height: 64vh; }
}
