/* ==========================================================================
   Dialog shell (modal.js), JetBrains form controls, and the Settings dialog.
   Every colour, border and radius comes from tokens.css.
   ========================================================================== */

/* ------------------------------------------------------------ modal shell */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay);
  opacity: 0;
  transition: opacity 120ms var(--ease);
}
.modal-overlay.in { opacity: 1; }

.dialog {
  display: flex;
  flex-direction: column;
  min-width: 260px;
  max-width: calc(100vw - 20px);
  max-height: calc(100vh - 20px);
  background: var(--bg-dialog);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--fs-ui);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  transform: translateY(-4px);
  transition: transform 120ms var(--ease);
}
.modal-overlay.in .dialog { transform: none; }

.dlg-title {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  flex: none;
  padding: 0 8px 0 14px;
  cursor: default;
  user-select: none;
}
.dlg-title-text { font-weight: 600; }
.dlg-title .spacer, .dlg-footer .spacer { flex: 1; min-width: 8px; }
.dlg-close, .dlg-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: var(--radius-s);
  color: var(--fg-dim);
}
.dlg-close:hover, .dlg-help:hover { background: var(--bg-hover); color: var(--fg); }
.dlg-close svg, .dlg-help svg { width: 14px; height: 14px; }
.dlg-help { margin-right: auto; }

.dlg-body { flex: 1; min-height: 0; overflow: auto; padding: 2px 14px 10px; }

.dlg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 50px;
  flex: none;
  padding: 0 14px;
  border-top: 1px solid var(--bd-soft);
}

.dlg-btn {
  height: 26px;
  min-width: 76px;
  padding: 0 14px;
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--fg);
  font-size: var(--fs-ui);
  cursor: default;
  transition: background 90ms var(--ease), border-color 90ms var(--ease);
}
.dlg-btn:hover:not(:disabled) { background: var(--bg-hover); }
.dlg-btn:active:not(:disabled) { background: var(--bg-pressed); }
.dlg-btn:focus-visible { box-shadow: 0 0 0 2px var(--accent-soft); border-color: var(--accent); }
.dlg-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.dlg-btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.dlg-btn.danger { border-color: var(--stop-red); color: var(--stop-red); }
.dlg-btn:disabled { opacity: 0.55; color: var(--fg-disabled); border-color: var(--bd-soft); }
.dlg-btn.primary:disabled { background: var(--bd-soft); border-color: var(--bd-soft); color: var(--fg-disabled); opacity: 1; }

.dialog.shake { animation: dlgShake 240ms var(--ease); }
@keyframes dlgShake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

/* --------------------------------------------------------- form controls */
.input, .select {
  height: 24px;
  min-width: 0;
  padding: 0 7px;
  border: 1px solid var(--bd);
  border-radius: var(--radius-s);
  background-color: var(--bg-input);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--fs-ui);
  outline: none;
}
.input::placeholder { color: var(--fg-muted); }
.input:hover:not(:disabled), .select:hover:not(:disabled) { border-color: var(--bd-strong); }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.input:disabled, .select:disabled { color: var(--fg-disabled); border-color: var(--bd-soft); }
.input.num { width: 72px; text-align: left; font-variant-numeric: tabular-nums; }
.input[type='search']::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 26px;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) calc(50% - 1px), calc(100% - 9px) calc(50% - 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.select option { background: var(--bg-popup); color: var(--fg); }

.checkbox, .radio {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: default;
  line-height: 16px;
}
.checkbox input, .radio input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 14px;
  height: 14px;
  flex: none;
  margin: 0;
  border: 1px solid var(--bd-strong);
  background: var(--bg-input);
  outline: none;
}
.checkbox input { border-radius: var(--radius-s); }
.radio input { border-radius: 50%; }
.checkbox input:hover, .radio input:hover { border-color: var(--accent); }
.checkbox input:focus-visible, .radio input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.checkbox input:checked, .radio input:checked { background: var(--accent); border-color: var(--accent); }
.checkbox input:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 3px;
  height: 7px;
  border: solid var(--accent-fg);
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(42deg);
}
.radio input:checked::after {
  content: '';
  position: absolute;
  inset: 3.5px;
  border-radius: 50%;
  background: var(--accent-fg);
}
.radio-group { display: flex; flex-direction: column; gap: 5px; }

.fieldset { margin: 0 0 14px; }
.fieldset-caption {
  color: var(--fg-dim);
  font-weight: 600;
  margin-bottom: 7px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--bd-soft);
}
.form-row { display: flex; align-items: center; gap: 10px; padding: 3px 4px; border-radius: var(--radius-s); }
.form-label { flex: none; width: 200px; color: var(--fg); }
.form-control { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.form-hint { color: var(--fg-muted); font-size: var(--fs-ui-s); max-width: 380px; line-height: 1.45; }

/* ==================================================== the Settings dialog */
.dlg-settings .dlg-body { padding: 0; }
.dlg-settings .dlg-title { border-bottom: 1px solid var(--bd-soft); }

.st-wrap { --st-left-w: 230px; display: flex; height: 100%; min-height: 0; }
.st-left {
  width: var(--st-left-w);
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-panel);
}
.st-tree { flex: 1; overflow: auto; padding: 2px 4px 8px; outline: none; }
.st-tree-empty { padding: 16px 10px; }

.st-splitter { width: 1px; flex: none; position: relative; background: var(--bd); cursor: col-resize; }
.st-splitter::after { content: ''; position: absolute; top: 0; bottom: 0; left: -3px; right: -3px; }
.st-splitter:hover, .st-splitter.active, .st-splitter:focus-visible { background: var(--accent); }

.st-right { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-dialog); }
.st-crumbs {
  height: 32px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 12px;
  border-bottom: 1px solid var(--bd-soft);
  color: var(--fg-dim);
}
.st-crumbs .spacer { flex: 1; min-width: 8px; }
.st-crumb.last { color: var(--fg); font-weight: 600; }
.st-crumb-sep { display: inline-flex; opacity: 0.5; }
.st-crumb-sep svg { width: 11px; height: 11px; }
.st-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  margin-right: 4px;
  padding: 0;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--fg-dim);
}
.st-back:hover { background: var(--bg-hover); color: var(--fg); }
.st-back svg { width: 14px; height: 14px; }
.st-reset {
  border: none;
  background: transparent;
  padding: 2px 4px;
  border-radius: var(--radius-s);
  color: var(--accent);
  font-size: var(--fs-ui);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.st-reset:hover { background: var(--bg-hover); }
.st-reset:focus-visible { box-shadow: 0 0 0 2px var(--accent-soft); }

.st-content { flex: 1; min-height: 0; overflow: auto; padding: 14px 16px; }
.st-content.wide { display: flex; overflow: hidden; padding: 10px 12px; }
.st-form { max-width: 660px; }

/* ------------------------------------------------------------ search box */
.st-search { position: relative; flex: none; margin: 8px 8px 6px; display: flex; }
.st-search-input { flex: 1; padding-left: 24px; }
.st-search-icon {
  position: absolute;
  left: 6px; top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  color: var(--fg-muted);
  pointer-events: none;
}
.st-search-icon svg { width: 13px; height: 13px; }

mark.st-match {
  background: color-mix(in srgb, var(--sq-warning) 45%, transparent);
  color: inherit;
  border-radius: 2px;
}
.form-row.st-hit { background: color-mix(in srgb, var(--sq-warning) 12%, transparent); }
.st-nothing { padding: 10px 4px; color: var(--fg-muted); }
.st-nothing-title { color: var(--fg-dim); font-weight: 600; margin-bottom: 4px; }
.st-nothing-hint { font-size: var(--fs-ui-s); line-height: 1.5; }

/* ------------------------------------------------- trees inside the dialog */
.dlg-settings .tree { outline: none; }
.dlg-settings .tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding-right: 8px;
  border-radius: var(--radius-s);
  white-space: nowrap;
  color: var(--fg);
}
.dlg-settings .tree-row:hover { background: var(--bg-hover); }
.dlg-settings .tree-row.selected { background: var(--bg-sel-inactive); }
.dlg-settings .tree:focus .tree-row.selected { background: var(--bg-sel); }
.dlg-settings .tree-arrow {
  width: 13px; height: 13px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
}
.dlg-settings .tree-arrow svg { width: 11px; height: 11px; }
.dlg-settings .tree-icon {
  width: 16px; height: 16px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: var(--icon-op);
}
.dlg-settings .tree-icon svg { width: 14px; height: 14px; }
.dlg-settings .tree-label { overflow: hidden; text-overflow: ellipsis; }
.dlg-settings .tree-suffix {
  margin-left: auto;
  padding-left: 14px;
  color: var(--fg-muted);
  font-size: var(--fs-ui-s);
  font-variant-numeric: tabular-nums;
}
.dlg-settings .tree-row.st-dirty .tree-label { font-weight: 600; }
.dlg-settings .tree-row.st-dirty::after {
  content: '';
  width: 6px; height: 6px;
  margin-left: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
}

/* checkbox rows (inspection tree) */
.dlg-settings .st-cbrow .tree-icon {
  width: 13px; height: 13px;
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius-s);
  background: var(--bg-input);
  opacity: 1;
  color: var(--accent-fg);
}
.dlg-settings .st-cbrow.st-on .tree-icon,
.dlg-settings .st-cbrow.st-mixed .tree-icon { background: var(--accent); border-color: var(--accent); }
.dlg-settings .st-cbrow .tree-icon svg { width: 11px; height: 11px; }
.dlg-settings .st-cbrow.st-off .tree-label { color: var(--fg-muted); }
.dlg-settings .st-cbgroup .tree-label { font-weight: 600; }

/* ---------------------------------------------------------------- previews */
.st-section { margin-top: 6px; }
.st-section-caption {
  color: var(--fg-dim);
  font-weight: 600;
  margin-bottom: 7px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--bd-soft);
}
.st-theme-preview {
  border: 1px solid var(--bd);
  border-radius: var(--radius-m);
  background: var(--bg-editor);
  overflow: hidden;
}
.st-theme-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--bd);
  color: var(--fg-dim);
}
.st-theme-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.st-theme-code {
  margin: 0;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--sy-text);
  white-space: pre-wrap;
}
.st-swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 10px; border-top: 1px solid var(--bd-soft); background: var(--bg-panel); }
.st-swatch { display: inline-flex; align-items: center; gap: 5px; color: var(--fg-dim); font-size: var(--fs-ui-s); }
.st-swatch i { width: 13px; height: 13px; border-radius: var(--radius-s); border: 1px solid var(--bd); display: inline-block; }
.st-font-preview {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--bd);
  border-radius: var(--radius-m);
  background: var(--bg-editor);
  color: var(--sy-text);
  white-space: pre;
  overflow: auto;
}

.st-index { display: flex; flex-direction: column; gap: 2px; }
.st-index-row { padding: 4px 8px; border-radius: var(--radius-s); color: var(--accent); }
.st-index-row:hover { background: var(--bg-hover); }
.st-index-row:focus-visible { box-shadow: 0 0 0 2px var(--accent-soft); }

.st-hint { color: var(--fg-muted); font-size: var(--fs-ui-s); padding: 6px 2px 0; line-height: 1.5; }
.st-btn {
  height: 22px;
  padding: 0 10px;
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--fg);
  font-size: var(--fs-ui-s);
}
.st-btn:hover { background: var(--bg-hover); }
.st-btn:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* ------------------------------------------------------------- keymap page */
.st-keymap { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.st-km-tools { display: flex; align-items: center; gap: 6px; flex: none; }
.st-km-tools .st-search { margin: 0; flex: 1; }
.st-km-capture {
  flex: 1;
  height: 24px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-s);
  background: var(--bg-input);
  color: var(--fg-dim);
  outline: none;
}
.st-km-capture:empty::before { content: 'Press a shortcut to find its actions…'; }
.st-km-capture:not(:empty) { color: var(--fg); font-family: var(--font-mono); }
.st-km-capture:focus { box-shadow: 0 0 0 2px var(--accent-soft); }
.st-km-mode {
  width: 26px; height: 24px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--fg-dim);
}
.st-km-mode:hover { background: var(--bg-hover); color: var(--fg); }
.st-km-mode.on { background: var(--bg-pressed); color: var(--accent); border-color: var(--accent); }
.st-km-mode svg { width: 15px; height: 15px; }
.st-km-tree { flex: 1; min-height: 0; overflow: auto; margin-top: 8px; border: 1px solid var(--bd); border-radius: var(--radius-s); padding: 4px; background: var(--bg-input); }
.st-km-empty { flex: 1; min-height: 0; overflow: auto; margin-top: 8px; }
.dlg-settings .st-km-group .tree-label { font-weight: 600; color: var(--fg-dim); }
.dlg-settings .st-km-action.st-unbound .tree-label { color: var(--fg-dim); }
.dlg-settings .st-reserved .tree-suffix::after { content: '⚠'; margin-left: 6px; color: var(--sq-warning); }

/* ------------------------------------------------------- inspections page */
.st-insp { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; gap: 8px; }
.st-insp-general { flex: none; max-width: none; }
.st-insp-general .fieldset { margin-bottom: 6px; }
.st-insp-tools { display: flex; align-items: center; gap: 6px; flex: none; }
.st-insp-tools .st-search { margin: 0; flex: 1; max-width: 320px; }
.st-insp-tools .spacer { flex: 1; }
.st-insp-split { flex: 1; min-height: 0; display: flex; gap: 10px; }
.st-insp-left { flex: 1 1 58%; min-width: 0; display: flex; min-height: 0; }
.st-insp-tree { flex: 1; overflow: auto; border: 1px solid var(--bd); border-radius: var(--radius-s); padding: 4px; background: var(--bg-input); }
.st-insp-empty { flex: 1; overflow: auto; }
.st-insp-detail {
  flex: 1 1 42%;
  min-width: 0;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--bd);
  border-radius: var(--radius-s);
  background: var(--bg-panel);
}
.st-insp-name { font-weight: 600; margin-bottom: 3px; }
.st-insp-code { color: var(--fg-muted); font-size: var(--fs-ui-s); margin-bottom: 10px; word-break: break-word; }
.st-insp-sev { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.st-insp-sev .form-label { width: auto; }
.st-insp-note { color: var(--fg-dim); line-height: 1.55; }
.st-insp-hint { color: var(--fg-muted); }

/* -------------------------------------------------------- code style page */
.st-cs { display: flex; flex: 1; min-width: 0; min-height: 0; gap: 12px; }
.st-cs-left { flex: 0 1 46%; min-width: 0; overflow: auto; padding-right: 6px; }
.st-cs-options { max-width: none; }
.st-cs-options .form-label { width: 175px; }
.st-cs-right { flex: 1 1 54%; min-width: 0; display: flex; flex-direction: column; }
.st-cs-tabs { display: flex; gap: 2px; flex: none; margin-bottom: 6px; }
.st-cs-tab { padding: 3px 10px; border-radius: var(--radius-s); color: var(--fg-dim); }
.st-cs-tab:hover { background: var(--bg-hover); }
.st-cs-tab.active { background: var(--bg-pressed); color: var(--fg); }
.st-cs-tab:focus-visible { box-shadow: 0 0 0 2px var(--accent-soft); }
.st-cs-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--bd);
  border-radius: var(--radius-s);
  background: var(--bg-editor);
}
.st-cs-preview {
  margin: 0;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--sy-text);
  white-space: pre;
  outline: none;
}
.st-cs-note { flex: none; padding: 5px 2px 0; color: var(--sq-warning); font-size: var(--fs-ui-s); }

/* ------------------------------------------------------------ tiny popups */
.st-menu {
  position: fixed;
  z-index: var(--z-popup);
  min-width: 190px;
  padding: 4px;
  border-radius: var(--radius-m);
  background: var(--bg-popup);
  box-shadow: var(--shadow-popup);
}
.st-menu-item { padding: 4px 10px; border-radius: var(--radius-s); color: var(--fg); outline: none; }
.st-menu-item:hover, .st-menu-item:focus { background: var(--bg-sel); }

.st-capture-body { display: flex; flex-direction: column; gap: 10px; padding: 6px 0 2px; }
.st-capture-label { color: var(--fg-dim); }
.st-capture {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--bd-strong);
  border-radius: var(--radius-m);
  background: var(--bg-input);
  color: var(--fg-muted);
  outline: none;
}
.st-capture:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.st-capture.st-has { color: var(--fg); font-family: var(--font-mono); font-size: 14px; border-style: solid; }
.st-conflicts { display: flex; flex-direction: column; gap: 6px; }
.st-conflict { color: var(--fg-dim); line-height: 1.5; }
.st-conflict ul { margin: 4px 0 0; padding-left: 18px; }
.st-conflict.st-warn { display: flex; align-items: flex-start; gap: 6px; color: var(--sq-warning); }
.st-warn-icon svg { width: 14px; height: 14px; }

/* -------------------------------------------------------------- responsive */
.st-wrap.narrow { --st-left-w: 100%; }
.st-wrap.narrow .st-splitter { display: none; }
.st-wrap.narrow .st-left { display: none; width: 100%; }
.st-wrap.narrow.show-tree .st-left { display: flex; }
.st-wrap.narrow.show-tree .st-right { display: none; }
.st-wrap.narrow .st-back { display: inline-flex; }
.st-wrap.narrow .form-label, .st-wrap.narrow .st-cs-options .form-label { width: 132px; }

/* single column: the whole page scrolls, scrollable panels get a fixed height */
.st-wrap.narrow .st-content.wide { display: block; overflow: auto; padding: 12px; }
.st-wrap.narrow .st-cs, .st-wrap.narrow .st-keymap,
.st-wrap.narrow .st-insp, .st-wrap.narrow .st-insp-split, .st-wrap.narrow .st-insp-left { display: block; }
.st-wrap.narrow .st-cs-left { overflow: visible; padding-right: 0; }
.st-wrap.narrow .st-cs-right, .st-wrap.narrow .st-insp-detail { margin-top: 10px; }
.st-wrap.narrow .st-insp-tools { margin: 8px 0; }
.st-wrap.narrow .st-insp-tools .st-search { max-width: none; }
.st-wrap.narrow .st-cs-scroll, .st-wrap.narrow .st-insp-tree, .st-wrap.narrow .st-km-tree { height: 260px; }
