/* Raptool Import Wizard — styles for shared/import-wizard.js. Every class is prefixed riw-.
   Colours come from the host's CSS variables (with fallbacks) so any theme, light or dark, is adopted:
   --surface --surface-2 --border --text --text-2 --text-3 --accent --accent-ink --bad --ok --radius --font */

.riw-overlay {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(2, 6, 16, .6);
  font-family: var(--font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  font-size: 14px; line-height: 1.4; color: var(--text, #1b2430);
}
.riw-overlay *, .riw-overlay *::before, .riw-overlay *::after { box-sizing: border-box; }

.riw-dialog {
  display: flex; flex-direction: column; min-width: 0;
  width: min(860px, 100%); max-height: 92vh; max-height: 92dvh;
  background: var(--surface, #fff); color: var(--text, #1b2430);
  border: 1px solid var(--border, #dde2e8); border-radius: calc(var(--radius, 10px) + 6px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .35); outline: none;
}

/* head */
.riw-head { padding: 14px 20px 12px; border-bottom: 1px solid var(--border, #dde2e8); }
.riw-head-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.riw-title { margin: 0; font-size: 16px; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.riw-fmt {
  margin-left: auto; flex: none; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ok, #1e8e3e); border: 1px solid color-mix(in srgb, var(--ok, #1e8e3e) 50%, transparent);
  background: color-mix(in srgb, var(--ok, #1e8e3e) 10%, transparent); border-radius: 999px; padding: 1px 9px;
}
.riw-steps { display: flex; gap: 6px; flex-wrap: wrap; list-style: none; margin: 10px 0 0; padding: 0; }
.riw-step { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-3, #7a8594); }
.riw-step + .riw-step::before { content: ""; width: 18px; height: 1px; background: var(--border, #dde2e8); margin-right: 3px; }
.riw-step b {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  font-size: 11px; font-weight: 700; background: var(--surface-2, #f4f6f9); border: 1px solid var(--border, #dde2e8);
}
.riw-step.riw-on { color: var(--text, #1b2430); font-weight: 600; }
.riw-step.riw-on b { background: var(--accent, #0b6bcb); border-color: var(--accent, #0b6bcb); color: var(--accent-ink, #fff); }
.riw-step.riw-done b { background: color-mix(in srgb, var(--ok, #1e8e3e) 14%, transparent); border-color: var(--ok, #1e8e3e); color: var(--ok, #1e8e3e); }

/* body / foot */
.riw-body { flex: 1 1 auto; min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden; padding: 6px 20px 18px; }
.riw-foot {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 20px;
  border-top: 1px solid var(--border, #dde2e8); background: var(--surface-2, #f4f6f9);
  border-radius: 0 0 calc(var(--radius, 10px) + 5px) calc(var(--radius, 10px) + 5px);
}
.riw-foot .riw-back { margin-right: auto; }

/* buttons */
.riw-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 7px 14px;
  font: inherit; font-weight: 600; cursor: pointer; color: var(--text, #1b2430);
  background: var(--surface, #fff); border: 1px solid var(--border, #dde2e8); border-radius: var(--radius, 10px);
}
.riw-btn:hover:not(:disabled) { border-color: var(--accent, #0b6bcb); }
.riw-btn:disabled { opacity: .5; cursor: default; }
.riw-btn.riw-primary { background: var(--accent, #0b6bcb); border-color: var(--accent, #0b6bcb); color: var(--accent-ink, #fff); }
.riw-btn.riw-primary:hover:not(:disabled) { filter: brightness(1.08); }
.riw-btn.riw-ghost { background: transparent; }
.riw-btn-ic { display: inline-flex; }
.riw-btn:focus-visible, .riw-link:focus-visible, .riw-dd-btn:focus-visible, .riw-input:focus-visible, .riw-textarea:focus-visible,
.riw-choice input:focus-visible { outline: 2px solid var(--accent, #0b6bcb); outline-offset: 2px; }
.riw-link {
  padding: 0; border: 0; background: none; font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline;
  color: var(--accent, #0b6bcb);
}

/* drop zone */
.riw-drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 12px; padding: 20px 16px;
  text-align: center; cursor: pointer; color: var(--text-2, #4a5563);
  border: 1.5px dashed color-mix(in srgb, var(--text-3, #7a8594) 70%, transparent); border-radius: calc(var(--radius, 10px) + 2px);
  transition: border-color .12s, background .12s;
}
.riw-drop:hover, .riw-drop.riw-over { border-color: var(--accent, #0b6bcb); background: color-mix(in srgb, var(--accent, #0b6bcb) 8%, transparent); }
.riw-drop.riw-has { border-style: solid; border-color: var(--ok, #1e8e3e); }
.riw-drop b { color: var(--text, #1b2430); font-weight: 600; overflow-wrap: anywhere; }
.riw-drop small { font-size: 12px; color: var(--text-3, #7a8594); }
.riw-drop .riw-choose { margin-top: 6px; }
.riw-drop-ic {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; margin-bottom: 2px;
  color: var(--accent, #0b6bcb); background: color-mix(in srgb, var(--accent, #0b6bcb) 12%, transparent);
}

/* fieldsets, fields, inputs */
.riw-fieldset { margin-top: 16px; }
.riw-fieldset h3 {
  display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font-size: 11.5px; font-weight: 650;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-3, #7a8594);
}
.riw-count { margin-left: auto; font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--text-2, #4a5563); }
.riw-grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; }
.riw-opts, .riw-toolbar { margin-top: 12px; }
.riw-toolbar { margin-top: 10px; align-items: end; }
.riw-field { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.riw-label { font-size: 12.5px; font-weight: 600; color: var(--text-2, #4a5563); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.riw-star { color: var(--bad, #d93025); font-weight: 700; }
/* v1.3.0: optional fields — a small × on an added field, "+ Add column" under the grid */
.riw-label-rm { display: flex; align-items: center; gap: 4px; }
.riw-label-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.riw-rmcol {
  display: inline-flex; align-items: center; justify-content: center; flex: none; margin-left: auto;
  width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: transparent; color: var(--text-3, #7a8594);
}
.riw-rmcol:hover { background: color-mix(in srgb, var(--bad, #d93025) 12%, transparent); color: var(--bad, #d93025); }
.riw-rmcol:focus-visible { outline: 2px solid var(--accent, #0b6bcb); outline-offset: 1px; }
.riw-addcol { margin-top: 10px; }
.riw-addcol:empty { display: none; }
.riw-dd-btn.riw-add {
  width: auto; min-width: 180px; max-width: 100%; border-style: dashed; color: var(--accent, #0b6bcb); font-weight: 650;
}
.riw-dd-btn.riw-add .riw-dd-caret { color: var(--accent, #0b6bcb); }
.riw-input, .riw-textarea {
  width: 100%; min-height: 36px; padding: 7px 10px; font: inherit; color: var(--text, #1b2430);
  background: var(--surface, #fff); border: 1px solid var(--border, #dde2e8); border-radius: var(--radius, 10px);
}
.riw-textarea { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; resize: vertical; }
.riw-note { margin: 10px 0 0; font-size: 12.5px; color: var(--text-3, #7a8594); }
.riw-err { margin-top: 10px; color: var(--bad, #d93025); font-weight: 600; overflow-wrap: anywhere; }
.riw-err:empty { display: none; }
.riw-warn { color: var(--bad, #d93025); }

/* custom dropdown (button + listbox) */
.riw-dd-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 36px; padding: 7px 10px;
  font: inherit; text-align: left; cursor: pointer; color: var(--text, #1b2430);
  background: var(--surface, #fff); border: 1px solid var(--border, #dde2e8); border-radius: var(--radius, 10px);
}
.riw-dd-btn:hover { border-color: var(--text-3, #7a8594); }
.riw-dd-btn[aria-expanded="true"] { border-color: var(--accent, #0b6bcb); }
.riw-dd-btn.riw-ok { border-color: color-mix(in srgb, var(--ok, #1e8e3e) 65%, transparent); }
.riw-input.riw-fixedin { border-color: color-mix(in srgb, var(--ok, #1e8e3e) 65%, transparent); }
.riw-dd-btn.riw-miss { border-color: color-mix(in srgb, var(--bad, #d93025) 75%, transparent); }
.riw-dd-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.riw-dd-skip { color: var(--text-3, #7a8594); }
.riw-dd-caret { display: inline-flex; flex: none; color: var(--text-3, #7a8594); }
.riw-dd-list {
  position: fixed; z-index: 9100; margin: 0; padding: 4px; list-style: none; overflow-y: auto; outline: none;
  background: var(--surface, #fff); color: var(--text, #1b2430);
  border: 1px solid var(--border, #dde2e8); border-radius: var(--radius, 10px); box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
}
.riw-dd-opt {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 7px 10px;
  border-radius: calc(var(--radius, 10px) - 3px); cursor: pointer;
}
.riw-dd-opt.riw-active { background: color-mix(in srgb, var(--accent, #0b6bcb) 12%, transparent); }
.riw-dd-opt.riw-sel .riw-dd-olabel { font-weight: 650; color: var(--accent, #0b6bcb); }
.riw-dd-olabel { min-width: 0; overflow-wrap: anywhere; }
.riw-dd-hint { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text-3, #7a8594); }

/* preview table */
.riw-table-wrap {
  max-width: 100%; max-height: 240px; overflow: auto;
  border: 1px solid var(--border, #dde2e8); border-radius: var(--radius, 10px);
}
.riw-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.riw-table th, .riw-table td { padding: 6px 10px; text-align: left; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--border, #dde2e8); }
.riw-table th { position: sticky; top: 0; font-weight: 650; background: var(--surface-2, #f4f6f9); color: var(--text-2, #4a5563); }
.riw-table td { color: var(--text-2, #4a5563); }
.riw-table tbody tr:last-child td { border-bottom: 0; }
.riw-table .riw-num { width: 1%; color: var(--text-3, #7a8594); text-align: right; }
.riw-table tr.riw-bad td { background: color-mix(in srgb, var(--bad, #d93025) 9%, transparent); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--bad, #d93025) 50%, transparent); }
.riw-table tr.riw-bad td.riw-issue, .riw-table tr.riw-bad td.riw-num { text-decoration: none; }
.riw-table td.riw-issue { color: var(--bad, #d93025); font-weight: 600; white-space: normal; min-width: 180px; }
.riw-table td.riw-issue svg { vertical-align: -2px; margin-right: 5px; }

/* confirm step */
.riw-choice { display: flex; align-items: flex-start; gap: 9px; padding: 5px 0; cursor: pointer; }
.riw-choice input { flex: none; width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent, #0b6bcb); }
.riw-sum { margin-top: 14px; padding: 10px 12px; border-radius: var(--radius, 10px); background: var(--surface-2, #f4f6f9); font-weight: 600; }
.riw-problems h3 { margin: 14px 0 6px; font-size: 11.5px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3, #7a8594); }
.riw-problems ul { margin: 0; padding-left: 18px; color: var(--text-2, #4a5563); font-size: 12.5px; }
.riw-problems li { margin: 2px 0; overflow-wrap: anywhere; }
.riw-problems .riw-more { list-style: none; margin-left: -18px; color: var(--text-3, #7a8594); }

/* progress + result */
.riw-bar { height: 8px; overflow: hidden; border-radius: 999px; background: var(--surface-2, #f4f6f9); border: 1px solid var(--border, #dde2e8); }
.riw-bar i { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--accent, #0b6bcb); transition: width .15s linear; }
.riw-result p { margin: 6px 0; }
.riw-kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 6px 0; }
.riw-kv dt { color: var(--text-3, #7a8594); text-transform: capitalize; }
.riw-kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* narrow screens (the wizard must work at 600px wide and below) */
@media (max-width: 640px) {
  .riw-overlay { padding: 10px; }
  .riw-dialog { max-height: 96vh; max-height: 96dvh; }
  .riw-head, .riw-foot { padding-left: 14px; padding-right: 14px; }
  .riw-body { padding-left: 14px; padding-right: 14px; }
  .riw-grid3 { grid-template-columns: 1fr 1fr; }
  .riw-step span { display: none; }
  .riw-step.riw-on span { display: inline; }
}
@media (max-width: 420px) {
  .riw-grid3 { grid-template-columns: 1fr; }
  .riw-foot .riw-btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) { .riw-bar i, .riw-drop { transition: none; } }
