/* VaultX Find & Replace dialog, highlight overlay and extract results (owned by the find/replace workstream).
   Colors come only from the shared design tokens in app.css (with dark fallbacks). */

.vf-dialog,
.vf-results,
.vf-overlay {
  --vf-bg: var(--surface2, #1e2229);
  --vf-raised: var(--surface3, #252a32);
  --vf-field: var(--surface, #181b20);
  --vf-line: var(--line, #2b3039);
  --vf-line-soft: var(--line-soft, #242932);
  --vf-text: var(--text, #f0f2f6);
  --vf-muted: var(--muted, #949eae);
  --vf-soft: var(--text-soft, #6f7a8b);
  --vf-accent: var(--accent, #5d96ff);
  --vf-accent-strong: var(--accent-strong, #397cf6);
  --vf-accent-soft: var(--accent-soft, #1c2d4c);
  --vf-accent-text: var(--accent-text, #ffffff);
  --vf-hover: var(--hover, #ffffff0f);
  --vf-active: var(--active, #ffffff1a);
  --vf-selected: var(--selected, #1c2d4c);
  --vf-focus: var(--focus-ring, #5d96ff);
  --vf-red: var(--red, #f18e94);
  --vf-amber: var(--amber, #e5b567);
  --vf-green: var(--green, #79c5a6);
  --vf-danger-soft: var(--danger-soft, #3a2328);
  --vf-match: var(--find-match, #f2c94c47);
  --vf-current: var(--find-current, #ff9f43b3);
  --vf-scope: var(--find-scope, #5d96ff1f);
  --vf-radius: var(--radius, 12px);
  --vf-radius-sm: var(--radius-sm, 8px);
  --vf-radius-xs: var(--radius-xs, 6px);
  --vf-ui: var(--font-ui, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
  --vf-mono: var(--font-mono, ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace);
}

/* ---------- Dialog shell ---------- */
.vf-dialog {
  position: absolute;
  z-index: 40;
  top: 12px;
  left: 12px;
  width: 470px;
  max-width: calc(100% - 8px);
  max-height: calc(100% - 8px);
  display: flex;
  flex-direction: column;
  color: var(--vf-text);
  background: var(--vf-bg);
  border: 1px solid var(--vf-line);
  border-radius: var(--vf-radius);
  box-shadow: var(--shadow-lg, 0 18px 50px #00000080);
  font: 12.5px/1.35 var(--vf-ui);
  text-align: left;
}
.vf-dialog[data-mode="find"] { width: 440px; }
.vf-dialog[data-mode="find"] .vf-replace-only { display: none !important; }
.vf-dialog.vf-enter { animation: vf-pop .14s ease-out; }
.vf-dialog.is-dragging { user-select: none; box-shadow: var(--shadow-lg, 0 18px 50px #00000080), 0 0 0 1px var(--vf-accent-soft); }
@keyframes vf-pop { from { opacity: 0; transform: translateY(-4px) scale(.985); } to { opacity: 1; transform: none; } }

.vf-dialog svg,
.vf-results svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
  flex-shrink: 0;
}
.vf-dialog :focus-visible,
.vf-results :focus-visible {
  outline: 2px solid var(--vf-focus);
  outline-offset: 1px;
}
.vf-dialog button,
.vf-results button {
  font: inherit;
  color: inherit;
  margin: 0;
}
.vf-dialog button:disabled,
.vf-results button:disabled {
  cursor: not-allowed;
  opacity: .45;
}
.vf-dialog code,
.vf-dialog kbd {
  font-family: var(--vf-mono);
  font-size: 11.5px;
}
.vf-dialog kbd {
  padding: 0 4px;
  border: 1px solid var(--vf-line);
  border-radius: 4px;
  background: var(--vf-bg);
  color: var(--vf-text);
  white-space: nowrap;
}

/* Title bar (drag handle) */
.vf-titlebar {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 32px;
  flex-shrink: 0;
  padding: 0 4px 0 12px;
  border-bottom: 1px solid var(--vf-line-soft);
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.vf-dialog.is-dragging .vf-titlebar { cursor: grabbing; }
.vf-title {
  flex: 1;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .1px;
}
.vf-tbtn,
.vf-ibtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--vf-radius-xs);
  background: transparent;
  color: var(--vf-muted);
  font-weight: 600;
  cursor: pointer;
}
.vf-tbtn:hover,
.vf-ibtn:hover:not(:disabled) { background: var(--vf-hover); color: var(--vf-text); }
.vf-tbtn:active,
.vf-ibtn:active:not(:disabled) { background: var(--vf-active); }
.vf-tbtn[aria-expanded="true"] { background: var(--vf-accent-soft); color: var(--vf-accent); }

.vf-help {
  padding: 8px 12px;
  border-bottom: 1px solid var(--vf-line-soft);
  background: var(--vf-field);
  color: var(--vf-muted);
  font-size: 12px;
  line-height: 1.6;
}
.vf-help p { margin: 0 0 6px; }
.vf-help p:last-child { margin-bottom: 0; }
.vf-help strong { color: var(--vf-text); font-weight: 600; margin-right: 4px; }
.vf-help code { color: var(--vf-text); }

.vf-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  /* Scroll shadows: a soft edge appears at the top / bottom only while there is more to scroll to
     (the dialog shrinks to stay above the extract results panel or a short window). */
  background:
    linear-gradient(var(--vf-bg) 40%, transparent) center top / 100% 18px no-repeat local,
    linear-gradient(transparent, var(--vf-bg) 60%) center bottom / 100% 18px no-repeat local,
    linear-gradient(var(--vf-line), transparent) center top / 100% 7px no-repeat scroll,
    linear-gradient(transparent, var(--vf-line)) center bottom / 100% 7px no-repeat scroll;
}

/* ---------- Two-column body ---------- */
.vf-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 12px;
  padding: 10px 12px 10px;
}
.vf-left { min-width: 0; display: flex; flex-direction: column; gap: 8px; }

.vf-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 4px;
}
.vf-label {
  grid-column: 1 / -1;
  margin: 0 0 3px;
  font-size: 12px;
  color: var(--vf-muted);
}
.vf-combo {
  position: relative;
  display: flex;
  align-items: stretch;
  min-width: 0;
  height: 30px;
  background: var(--vf-field);
  border: 1px solid var(--vf-line);
  border-radius: var(--vf-radius-xs);
  transition: border-color .12s, box-shadow .12s;
}
.vf-combo:focus-within {
  border-color: var(--vf-accent);
  box-shadow: 0 0 0 2px var(--vf-accent-soft);
}
.vf-combo.is-invalid { border-color: var(--vf-red); }
.vf-combo.is-invalid:focus-within { box-shadow: 0 0 0 2px var(--vf-danger-soft); }
.vf-dialog .vf-input,
.vf-results .vf-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0 8px;
  border: 0;
  border-radius: var(--vf-radius-xs);
  background: transparent;
  color: var(--vf-text);
  font: 13px/1.2 var(--vf-mono);
  box-shadow: none;
  outline: 0;
}
.vf-dialog .vf-input::placeholder,
.vf-results .vf-input::placeholder { color: var(--vf-soft); font-family: var(--vf-ui); font-size: 12px; }
.vf-drop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--vf-line-soft);
  border-radius: 0 var(--vf-radius-xs) var(--vf-radius-xs) 0;
  background: transparent;
  color: var(--vf-muted);
  cursor: pointer;
}
.vf-drop:hover { background: var(--vf-hover); color: var(--vf-text); }
.vf-token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--vf-line);
  border-radius: var(--vf-radius-xs);
  background: var(--vf-raised);
  color: var(--vf-muted);
  cursor: pointer;
}
.vf-token:hover { color: var(--vf-text); background: var(--vf-hover); }
/* Keep the slot so both fields stay aligned when the token menu does not apply. */
.vf-dialog .vf-token.is-unavailable { visibility: hidden; }
.vf-dialog[data-mode="find"] .vf-token.is-unavailable { display: none; }

/* Options */
.vf-options,
.vf-modes,
.vf-advanced {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px 10px;
}
.vf-options { margin-top: 2px; }
.vf-modes,
.vf-advanced {
  padding-top: 7px;
  border-top: 1px solid var(--vf-line-soft);
}
.vf-check {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 23px;
  min-width: 0;
  color: var(--vf-text);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}
.vf-check > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vf-check u { text-decoration-color: var(--vf-muted); text-underline-offset: 2px; }
.vf-check.is-disabled { color: var(--vf-soft); cursor: default; }
.vf-dialog .vf-check input {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  margin: 0;
  padding: 0;
  accent-color: var(--vf-accent-strong);
  cursor: inherit;
}
.vf-dialog .vf-advanced { grid-template-columns: minmax(0, 1fr); }
.vf-check code {
  padding: 0 5px;
  border-radius: 4px;
  background: var(--vf-raised);
  color: var(--vf-accent);
  font-weight: 700;
}
.vf-check.is-disabled code { color: var(--vf-soft); }

/* Right column buttons */
.vf-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
/* Replace mode has the longest button column (ten buttons): keep it compact so the dialog fits
   above the extract results panel without cutting its last button. Desktop only (phones: below). */
@media (min-width: 801px) {
  .vf-dialog[data-mode="replace"] .vf-actions { gap: 4px; }
  .vf-dialog[data-mode="replace"] .vf-actions .vf-btn { min-height: 26px; padding-top: 2px; padding-bottom: 2px; }
}
.vf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 28px;
  padding: 3px 10px;
  border: 1px solid var(--vf-line);
  border-radius: var(--vf-radius-xs);
  background: var(--vf-raised);
  color: var(--vf-text);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.vf-btn:hover:not(:disabled) { background: var(--vf-hover); border-color: var(--vf-muted); }
.vf-btn:active:not(:disabled) { background: var(--vf-active); }
.vf-btn.is-on { border-color: var(--vf-accent); color: var(--vf-accent); }
.vf-btn.vf-primary {
  background: var(--vf-accent-strong);
  border-color: var(--vf-accent-strong);
  color: var(--vf-accent-text);
  font-weight: 600;
}
.vf-btn.vf-primary:hover:not(:disabled) { background: var(--vf-accent); border-color: var(--vf-accent); }
.vf-btn.vf-strong { border-color: var(--vf-accent); color: var(--vf-accent); font-weight: 600; }
.vf-btn.vf-small { min-height: 26px; padding: 2px 9px; font-size: 12px; }
.vf-split { display: flex; min-width: 0; }
.vf-split .vf-btn:first-child { flex: 1; min-width: 0; border-radius: var(--vf-radius-xs) 0 0 var(--vf-radius-xs); }
.vf-split .vf-split-arrow { width: 24px; padding: 0; border-left: 0; border-radius: 0 var(--vf-radius-xs) var(--vf-radius-xs) 0; }

/* Batch: the bar is pinned under the scrolling body (above the status line), so it is never cut in
   half when the dialog has to shrink; the batch list opens above it, at the end of the body. */
.vf-batchbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-top: 1px solid var(--vf-line-soft);
}
.vf-batch-summary { flex: 1; color: var(--vf-muted); font-size: 12px; text-align: right; }
.vf-batch { padding: 8px 12px 10px; border-top: 1px solid var(--vf-line-soft); }
.vf-batch-list {
  list-style: none;
  margin: 0;
  padding: 3px;
  max-height: 152px;
  overflow: auto;
  border: 1px solid var(--vf-line);
  border-radius: var(--vf-radius-xs);
  background: var(--vf-field);
}
.vf-batch-list:empty { display: none; }
.vf-batch-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 0 0 6px;
  border-radius: 5px;
}
.vf-batch-row:hover { background: var(--vf-hover); }
.vf-batch-row.is-selected { background: var(--vf-selected); }
.vf-batch-row.is-off .vf-batch-item { opacity: .5; }
.vf-dialog .vf-batch-row input { margin: 0; padding: 0; width: 14px; height: 14px; accent-color: var(--vf-accent-strong); flex-shrink: 0; }
.vf-batch-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 6px 2px 2px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.vf-batch-find,
.vf-batch-replace {
  min-width: 0;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: pre;
  font: 12px/1.3 var(--vf-mono);
}
.vf-batch-replace.is-empty { font-family: var(--vf-ui); font-style: italic; color: var(--vf-soft); }
.vf-batch-arrow { color: var(--vf-soft); flex-shrink: 0; }
.vf-badges { margin-left: auto; display: flex; gap: 3px; flex-shrink: 0; }
.vf-badge {
  padding: 0 4px;
  border-radius: 4px;
  background: var(--vf-accent-soft);
  color: var(--vf-accent);
  font: 600 10.5px/16px var(--vf-mono);
}
.vf-batch-empty { margin: 0; padding: 10px; border: 1px dashed var(--vf-line); border-radius: var(--vf-radius-xs); color: var(--vf-muted); font-size: 12px; text-align: center; }
.vf-batch-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}
.vf-batch-tools .vf-strong { margin-left: auto; }

/* Status line */
.vf-status {
  flex-shrink: 0;
  min-height: 28px;
  padding: 6px 12px;
  border-top: 1px solid var(--vf-line-soft);
  border-radius: 0 0 var(--vf-radius) var(--vf-radius);
  background: var(--vf-field);
  color: var(--vf-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.vf-status:empty::before { content: "\00a0"; }
.vf-status[data-tone="error"] { color: var(--vf-red); }
.vf-status[data-tone="warn"] { color: var(--vf-amber); }
.vf-status[data-tone="ok"] { color: var(--vf-green); }
.vf-status[data-tone="info"] { color: var(--vf-accent); }

/* Popups: history list and token / extract menus. Same look as the app's other menus
   (app.css .menu / .file-context-menu and the editor menus): popover surface, 10px radius,
   large shadow, 13px rows with --hover / --active backgrounds and --line separators. */
.vf-popup {
  position: absolute;
  z-index: 5;
  min-width: 180px;
  max-width: 340px;
  max-height: 260px;
  overflow: auto;
  padding: 4px;
  color: var(--vf-text);
  font-size: 13px; /* menu buttons inherit their font (".vf-dialog button { font: inherit }") */
  font-weight: 450;
  background: var(--popover, var(--surface3, #23262e));
  border: 1px solid var(--vf-line);
  border-radius: 10px;
  box-shadow: var(--shadow-lg, 0 4px 12px #0000004d, 0 24px 64px #00000080);
  scrollbar-width: thin;
}
.vf-popup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 28px;
  padding: 4px 10px;
  border: 0;
  border-radius: var(--vf-radius-xs);
  background: transparent;
  color: var(--vf-text);
  font-size: 13px;
  font-weight: 450;
  text-align: left;
  cursor: pointer;
}
.vf-popup-item:hover { background: var(--vf-hover); }
.vf-popup-item:focus,
.vf-popup-item[aria-selected="true"] { background: var(--vf-active); outline: 0; }
/* Keyboard focus stays visible on top of the --active background. */
.vf-dialog .vf-popup-item:focus-visible { outline: 0; box-shadow: inset 0 0 0 1px var(--vf-focus); }
.vf-popup-item code { color: var(--vf-accent); font: 12.5px var(--vf-mono); white-space: pre; }
.vf-popup-list .vf-popup-label { font-family: var(--vf-mono); font-size: 12.5px; white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.vf-popup-sep { height: 1px; margin: 4px -4px; background: var(--vf-line); }

/* ---------- Highlight overlay (inside .editor-layers, behind the transparent textarea text) ---------- */
.vf-overlay {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  color: transparent;
  will-change: transform;
}
.vf-line {
  position: absolute;
  left: 0;
  margin: 0;
  padding: 0;
  color: transparent;
}
.vf-overlay mark {
  color: transparent;
  background: var(--vf-match);
  border-radius: 2px;
  margin: 0;
  padding: 0;
}
.vf-overlay mark.vf-current {
  background: var(--vf-current);
  box-shadow: 0 0 0 1px var(--vf-amber);
}
.vf-overlay mark.vf-empty {
  background: transparent;
  border-left: 2px solid var(--vf-amber);
  margin: 0 -1px;
}
.vf-overlay .vf-scope,
.vf-line.vf-scope-line { background: var(--vf-scope); }

/* ---------- Extract results panel (docked at the bottom of the editor) ---------- */
.vf-results {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 90px;
  color: var(--vf-text);
  background: var(--vf-bg);
  border-top: 1px solid var(--vf-line);
  font: 12.5px/1.35 var(--vf-ui);
}
.vf-results.is-resizing { user-select: none; }
.vf-results-grip {
  position: absolute;
  z-index: 2;
  top: -4px;
  left: 0;
  right: 0;
  height: 8px;
  cursor: ns-resize;
  touch-action: none;
}
.vf-results-grip:hover,
.vf-results.is-resizing .vf-results-grip { background: var(--vf-accent-soft); }
.vf-results-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 4px 6px 4px 12px;
  border-bottom: 1px solid var(--vf-line-soft);
  flex-wrap: wrap;
}
.vf-results-title { font-size: 13px; font-weight: 600; }
.vf-results-count { color: var(--vf-muted); font-size: 12px; }
.vf-results-msg { flex: 1; min-width: 0; color: var(--vf-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vf-results-msg[data-tone="ok"] { color: var(--vf-green); }
.vf-results-msg[data-tone="warn"] { color: var(--vf-amber); }
.vf-results-msg[data-tone="error"] { color: var(--vf-red); white-space: normal; }
.vf-results-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.vf-results-save {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--vf-line-soft);
  background: var(--vf-field);
}
.vf-results-save[hidden] { display: none !important; }
.vf-results-save label { color: var(--vf-muted); font-size: 12px; }
.vf-results .vf-results-save .vf-input {
  flex: 1;
  max-width: 340px;
  height: 28px;
  border: 1px solid var(--vf-line);
  background: var(--vf-bg);
}
.vf-results .vf-results-save .vf-input:focus { border-color: var(--vf-accent); }
.vf-results-list {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  font: 13px/22px var(--vf-mono);
  outline-offset: -2px;
}
.vf-results-sizer { position: relative; min-height: 100%; }
.vf-row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  height: 22px;
  cursor: pointer;
  white-space: pre;
  tab-size: 4;
}
.vf-row:hover { background: var(--vf-hover); }
.vf-row.is-active { background: var(--vf-selected); }
.vf-row-ln {
  flex-shrink: 0;
  width: 60px;
  padding-right: 12px;
  text-align: right;
  color: var(--vf-soft);
  user-select: none;
}
.vf-row-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; padding-right: 12px; }
.vf-row mark { color: inherit; background: var(--vf-match); border-radius: 2px; }
/* The document changed at this result after the extract ran. */
.vf-row.is-stale .vf-row-text { opacity: .55; }
.vf-row.is-stale .vf-row-ln { color: var(--vf-amber); }

/* ---------- Phones: dock as a full-width bottom sheet ---------- */
@media (max-width: 800px) {
  .vf-dialog,
  .vf-dialog[data-mode="find"] {
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: var(--vf-sheet-bottom, 0px);
    width: auto;
    max-width: none;
    /* --vf-sheet-max (set from JS) keeps the title bar inside the editor above the results panel. */
    max-height: min(72%, 560px, var(--vf-sheet-max, 100%));
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    border-radius: var(--vf-radius) var(--vf-radius) 0 0;
  }
  .vf-status { border-radius: 0; }
  .vf-titlebar { cursor: default; }
  .vf-body { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .vf-options,
  .vf-modes,
  .vf-advanced { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); }
  .vf-actions { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .vf-actions > .vf-btn,
  .vf-actions > .vf-split { flex: 1 1 auto; }
  .vf-actions > .vf-btn[data-vf="close"] { display: none; }
  .vf-btn { min-height: 34px; }
  .vf-combo { height: 36px; }
  .vf-token { height: 36px; width: 32px; }
  .vf-dialog .vf-input,
  .vf-results .vf-input { font-size: 16px; }
  .vf-check { min-height: 30px; }
  .vf-results-head { padding-left: 10px; }
  .vf-results-msg { flex-basis: 100%; order: 3; }
  .vf-row-ln { width: 44px; padding-right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .vf-dialog.vf-enter { animation: none; }
  .vf-combo,
  .vf-btn { transition: none; }
}
