/* workspace/io/io.css: export/import card dialogs (native modal, the valet's look) and the
   search/replace panel. Uses var(--token) from tokens.css only. At <=640px the dialogs are
   full-width bottom sheets, like the side pane (core section 16). */

/* ---- card dialog ---- */
.ws-sheet {
  display: flex; flex-direction: column; width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  margin: auto; padding: 0; overflow: hidden; font: 15px/1.45 var(--font-ui); color: var(--ink); background: var(--paper);
  border: 1px solid var(--hairline-2); border-radius: 10px; box-shadow: var(--shadow);
}
.ws-sheet:not([open]) { display: none; }
#ws-export-dialog { width: min(520px, calc(100vw - 32px)); }
.ws-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 10px 10px 20px; border-bottom: 1px solid var(--hairline); }
.ws-sheet-head h2, .ws-search-head h2 { margin: 0; font: 600 20px/1.25 var(--font-serif); color: var(--ink); }
.ws-sheet-body { display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto; min-height: 0; padding: 16px 20px 18px; overflow-y: auto; }
.ws-sheet-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--hairline); }
#ws-btn-import-valet { margin-right: auto; }

/* ---- fields ---- */
.ws-sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.ws-sheet input[type="text"], .ws-sheet select, #ws-search-input, #ws-replace-input, #ws-search-scope {
  min-height: 44px; padding: 8px 10px; font: 15px var(--font-ui); color: var(--ink); background: var(--card-bg);
  border: 1px solid var(--hairline-2); border-radius: 6px;
}
#ws-import-file {
  width: 100%; padding: 10px; font-size: 16px; color: var(--ink); background: var(--card-bg);
  border: 1px dashed var(--hairline-2); border-radius: 8px; overflow-wrap: anywhere;
}
#ws-import-file::file-selector-button {
  min-height: 44px; margin-right: 12px; padding: 8px 14px; font: 14px var(--font-ui); color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--hairline-2); border-radius: 8px; cursor: pointer;
}
.ws-io-note { margin: 0; font-size: 13px; color: var(--ink-faint); }
.ws-io-note[hidden], .ws-io-options[hidden] { display: none; }
.ws-io-options { display: flex; flex-direction: column; gap: 12px; }
.ws-io-filename { padding: 8px 10px; font: 13px var(--font-mono); color: var(--ink-soft); background: var(--paper-2); border: 1px solid var(--hairline); border-radius: 6px; word-break: break-all; }
.ws-sheet .ws-io-check, .ws-search-panel .ws-io-check { display: flex; flex-direction: row; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; color: var(--ink); cursor: pointer; }
.ws-io-check input[type="checkbox"] { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* ---- buttons: one primary per surface ---- */
.ws-sheet button, .ws-search-panel button {
  min-height: 44px; padding: 8px 14px; font: 14px/1.3 var(--font-ui); color: var(--ink-soft); background: var(--paper-2);
  border: 1px solid var(--hairline-2); border-radius: 6px; cursor: pointer;
}
.ws-sheet button:hover:not(:disabled), .ws-search-panel button:hover:not(:disabled) { background: var(--paper-3); color: var(--ink); }
.ws-sheet button:disabled, .ws-search-panel button:disabled { opacity: .5; cursor: default; }
#ws-btn-export-confirm, #ws-btn-import-confirm, #ws-btn-replace-apply { color: var(--on-accent, var(--paper)); background: var(--accent); border-color: var(--accent); font-weight: 600; }
#ws-btn-export-confirm:hover:not(:disabled), #ws-btn-import-confirm:hover:not(:disabled), #ws-btn-replace-apply:hover:not(:disabled) { color: var(--on-accent, var(--paper)); background: var(--accent); filter: brightness(.92); }
.ws-sheet .ws-sheet-x, .ws-search-panel .ws-sheet-x { display: inline-grid; place-items: center; flex: none; width: 44px; padding: 0; background: transparent; border-color: transparent; }
.ws-sheet-x::before {
  content: ""; width: 16px; height: 16px; background: currentColor;
  -webkit-mask: var(--ws-x) center / 16px no-repeat; mask: var(--ws-x) center / 16px no-repeat;
  --ws-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='m4.25 4.25 7.5 7.5m0-7.5-7.5 7.5'/%3E%3C/svg%3E");
}

/* ---- import preview ---- */
.ws-io-coverage { padding: 8px 10px; font-size: 13px; color: var(--ink-soft); background: var(--paper-2); border: 1px solid var(--hairline); border-radius: 6px; }
.ws-io-coverage:empty { display: none; }
.ws-io-coverage-unassigned { margin-bottom: 4px; padding: 6px 10px; color: var(--caution-fg); background: var(--caution-bg); border-radius: 6px; }
.ws-io-suggestions { display: flex; flex-direction: column; gap: 4px; }
.ws-io-suggestions:empty { display: none; }
.ws-io-suggestions-head { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.ws-sheet .ws-io-suggestion { padding: 6px 10px; font-size: 13px; background: var(--card-bg); border: 1px solid var(--hairline); border-radius: 6px; }
.ws-io-preview { display: flex; flex-direction: column; }
.ws-io-empty { font-size: 13px; color: var(--ink-faint); }
.ws-io-chapter { padding: 8px 2px; border-bottom: 1px solid var(--hairline); }
.ws-io-chapter:first-child { border-top: 1px solid var(--hairline); }
.ws-io-chapter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.ws-io-chapter-title { font: 600 15px/1.35 var(--font-serif); color: var(--ink); overflow-wrap: anywhere; }
.ws-io-chapter-meta { flex: none; font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.ws-io-part-start, .ws-io-flag { display: inline-block; margin: 4px 4px 0 0; padding: 1px 8px; font-size: 12px; border-radius: 999px; }
.ws-io-part-start { color: var(--chip-med-fg); background: var(--chip-med-bg); }
.ws-io-flags { display: inline; }
.ws-io-flag { color: var(--chip-low-fg); background: var(--chip-low-bg); }
.ws-io-warnings { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.ws-io-warnings div { padding: 6px 10px; font-size: 12px; color: var(--caution-fg); background: var(--caution-bg); border-radius: 6px; }

/* ---- inline error ---- */
.ws-io-error { padding: 6px 10px; font-size: 13px; color: var(--caution-fg); background: var(--caution-bg); border-radius: 6px; }
.ws-io-error[hidden] { display: none; }

/* ---- search panel: header, query, replace right below, results by chapter ---- */
.ws-search-panel { display: flex; flex-direction: column; gap: 8px; font: 14px/1.45 var(--font-ui); color: var(--ink); }
.ws-search-panel[hidden] { display: none; }
.ws-search-head {
  position: sticky; top: -12px; z-index: 2; display: flex; align-items: center; gap: 10px;
  margin-top: -12px; padding-top: 12px; background: var(--paper-2); /* stays in view as results scroll */
}
.ws-search-head h2 { font-size: 19px; }
.ws-search-count { flex: 1; font-size: 12px; color: var(--ink-faint); }
.ws-search-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#ws-search-scope { flex: 1 1 140px; font-size: 14px; }
#ws-replace-input { margin-top: 4px; }
.ws-search-results { display: flex; flex-direction: column; gap: 4px; }
.ws-search-group { margin: 8px 0 0; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.ws-search-panel .ws-search-result {
  display: block; width: 100%; padding: 8px 10px; text-align: left; font: 14px/1.5 var(--font-serif); color: var(--ink);
  background: var(--card-bg); border-color: var(--hairline); white-space: pre-wrap; word-break: break-word;
}
.ws-search-hit { padding: 0 1px; color: var(--chip-high-fg); background: var(--chip-high-bg); border-radius: 2px; }
#ws-search-more { align-self: flex-start; }
#ws-search-more[hidden] { display: none; }
.ws-replace-preview { display: flex; flex-direction: column; gap: 6px; }
.ws-replace-total { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.ws-replace-chapter { padding: 8px 10px; background: var(--card-bg); border: 1px solid var(--hairline); border-radius: 6px; }
.ws-replace-chapter-head { margin-bottom: 4px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
/* before and after of each sample, only the changed words marked */
.ws-replace-sample { font: 14px/1.5 var(--font-serif); color: var(--ink-soft); white-space: pre-wrap; overflow-wrap: anywhere; }
.ws-replace-before { margin-top: 8px; }
.ws-replace-sample del, .ws-replace-sample ins { padding: 0 1px; border-radius: 2px; }
.ws-replace-sample del { color: var(--caution-fg); background: var(--caution-bg); }
.ws-replace-sample ins { color: var(--chip-high-fg); background: var(--chip-high-bg); text-underline-offset: 3px; }
/* a context cut mid-word hides the cut part (still in the text) behind an ellipsis */
.ws-cut { display: none; }
.ws-cut-start::before, .ws-cut-end::after { content: "\2026"; }

/* ---- focus rings ---- */
.ws-sheet :focus-visible, .ws-search-panel :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- small screens: a bottom sheet as tall as its content (the valet's too), comfortable inputs ---- */
@media (max-width: 640px) {
  .ws-sheet, #ws-export-dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: auto 0 0; border-radius: 12px 12px 0 0; border-width: 1px 0 0; }
  .ws-sheet-head { padding-left: 14px; }
  .ws-sheet-body { padding: 14px; }
  .ws-sheet-actions { padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .ws-sheet-actions button { flex: 1 1 auto; }
}
@media (max-width: 760px) {
  .ws-sheet input[type="text"], .ws-sheet select, #ws-search-input, #ws-replace-input, #ws-search-scope { font-size: 16px; }
}
