/* ==========================================================================
   Floating surfaces: menus, completion, tooltips, intentions, chooser, dialogs.
   ========================================================================== */

.popup {
  position: fixed;
  z-index: var(--z-popup);
  background: var(--bg-popup);
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-popup);
  outline: none;
  overflow: hidden;
}

/* ------------------------------------------------------------------ menus */
.menu {
  position: fixed;
  z-index: var(--z-popup);
  min-width: 190px;
  max-width: 420px;
  max-height: 78vh;
  overflow-y: auto;
  padding: 4px 0;
  background: var(--bg-popup);
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-popup);
  outline: none;
}
.menu-item-row {
  display: flex; align-items: center; gap: 7px;
  padding: 3px 10px 3px 6px; min-height: 22px;
  white-space: nowrap;
}
.menu-item-row:hover:not(.disabled), .menu-item-row.active:not(.disabled) { background: var(--bg-sel); }
.menu-item-row.disabled { color: var(--fg-disabled); }
.menu-item-row.danger .mi-label { color: var(--sq-error); }
.menu-item-row.danger:hover .mi-label { color: #fff; }
.mi-check { width: 14px; flex: none; display: grid; place-items: center; color: var(--fg); }
.mi-check svg { width: 12px; height: 12px; }
.mi-icon { width: 16px; height: 16px; flex: none; opacity: var(--icon-op); }
.mi-icon svg { width: 16px; height: 16px; display: block; }
.mi-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.mi-label u { text-decoration: underline; text-underline-offset: 2px; }
.mi-key { color: var(--fg-muted); font-size: 10.5px; margin-left: 20px; }
.menu-item-row:hover .mi-key, .menu-item-row.active .mi-key { color: #b8c7e0; }
.mi-arrow { color: var(--fg-muted); display: flex; }
.mi-arrow svg { width: 11px; height: 11px; }
.menu-sep { height: 1px; background: var(--bd-soft); margin: 4px 0; }
.menu-header {
  padding: 4px 10px 3px; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--fg-muted); font-weight: 600;
}

/* ------------------------------------------------------------- completion */
.popup.cmp { min-width: 280px; max-width: 620px; padding: 0; }
.cmp-list { max-height: 320px; overflow-y: auto; padding: 2px 0; }
.cmp-row {
  display: flex; align-items: center; gap: 6px;
  height: 21px; padding: 0 8px 0 5px; white-space: nowrap;
  font-family: var(--font-mono); font-size: 12.5px;
}
.cmp-row.selected { background: var(--bg-sel); }
.cmp-icon { width: 16px; height: 16px; flex: none; }
.cmp-icon svg { width: 16px; height: 16px; display: block; }
.cmp-label { flex: none; color: var(--fg); }
.cmp-label b { color: var(--accent); font-weight: 700; }
.cmp-row.selected .cmp-label b { color: #9dc0ff; }
.cmp-tail { color: var(--fg-muted); }
.cmp-detail {
  margin-left: auto; padding-left: 24px; color: var(--fg-muted);
  font-size: 11.5px; overflow: hidden; text-overflow: ellipsis;
}
.cmp-hint {
  border-top: 1px solid var(--bd-soft); padding: 3px 8px;
  color: var(--fg-muted); font-size: 10.5px; font-family: var(--font-ui);
  display: flex; gap: 5px; align-items: center;
}
.popup.cmp-doc {
  max-width: 380px; min-width: 240px; overflow-y: auto;
  padding: 8px 11px; font-family: var(--font-ui); line-height: 1.6;
}
.qd-sig {
  font-family: var(--font-mono); font-size: 12px; color: var(--fg);
  padding-bottom: 7px; margin-bottom: 7px; border-bottom: 1px solid var(--bd-soft);
  white-space: pre-wrap; word-break: break-word;
}
.qd-body { color: var(--fg-dim); font-size: 11.5px; }
.qd-body code { font-family: var(--font-mono); background: var(--bg-hover); padding: 0 3px; border-radius: 2px; }
.qd-tag { color: var(--sy-doctag); font-weight: 600; }
.qd-foot { margin-top: 8px; color: var(--fg-muted); font-size: 10.5px; }

/* --------------------------------------------------------------- tooltips */
.popup.tooltip {
  max-width: 480px; padding: 0; font-family: var(--font-ui);
  box-shadow: var(--shadow-tooltip);
}
.tt-body { padding: 7px 10px; }
.tt-head { display: flex; gap: 7px; align-items: flex-start; }
.tt-sev { flex: none; margin-top: 1px; }
.tt-sev svg { width: 14px; height: 14px; display: block; }
.tt-sev.error { color: var(--sq-error); }
.tt-sev.warning { color: var(--sq-warning); }
.tt-sev.weak, .tt-sev.unused { color: var(--sq-weak); }
.tt-msg { line-height: 1.55; word-break: break-word; }
.tt-foot {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin-top: 7px; padding-top: 6px; border-top: 1px solid var(--bd-soft);
  font-size: 10.5px; color: var(--fg-muted);
}
.tt-code { color: var(--fg-muted); }
.tt-link { color: var(--accent); text-decoration: none; cursor: default; }
.tt-link:hover { text-decoration: underline; }
.tt-sep { height: 1px; background: var(--bd-soft); margin: 7px -10px; }
.popup.tooltip.sticky { border-color: var(--bd-strong); }

/* --------------------------------------------------------- parameter info */
.popup.param-info {
  padding: 4px 9px; font-family: var(--font-mono); font-size: 12px;
  max-width: 620px; background: var(--bg-popup);
}
.pi-row { white-space: pre-wrap; color: var(--fg-muted); }
.pi-active { color: var(--fg); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.pi-param { color: var(--fg-muted); }
.pi-doc { font-family: var(--font-ui); color: var(--fg-muted); font-size: 11px; margin-top: 3px; }

/* -------------------------------------------------------------- intentions */
.popup.intentions { min-width: 300px; max-width: 520px; padding: 0; }
.int-list { max-height: 340px; overflow-y: auto; padding: 3px 0; }
.int-row { display: flex; align-items: center; gap: 8px; height: 23px; padding: 0 10px 0 6px; white-space: nowrap; }
.int-row.selected { background: var(--bg-sel); }
.int-icon { width: 16px; height: 16px; flex: none; }
.int-icon svg { width: 15px; height: 15px; display: block; }
.int-icon.fix { color: var(--sq-error); }
.int-icon.intention { color: var(--sq-warning); }
.int-icon.suppress, .int-icon.ide { color: var(--fg-muted); }
.int-label { overflow: hidden; text-overflow: ellipsis; }
.int-sep { height: 1px; background: var(--bd-soft); margin: 4px 0; }

/* ----------------------------------------------------------------- chooser */
.chooser-overlay { position: fixed; inset: 0; z-index: calc(var(--z-popup) - 1); background: transparent; }
.popup.chooser {
  left: 50%; top: 14vh; transform: translateX(-50%) translateY(-6px);
  width: min(720px, 92vw); max-height: 70vh;
  display: flex; flex-direction: column; padding: 0;
  opacity: 0; transition: opacity 110ms var(--ease), transform 110ms var(--ease);
  box-shadow: var(--shadow-modal);
}
.popup.chooser.in { opacity: 1; transform: translateX(-50%) translateY(0); }
.popup.chooser.with-preview { width: min(980px, 96vw); }
.ch-head { display: flex; align-items: center; gap: 9px; padding: 9px 13px; border-bottom: 1px solid var(--bd-soft); }
.ch-icon { color: var(--fg-muted); display: flex; }
.ch-icon svg { width: 17px; height: 17px; }
.ch-input {
  flex: 1; background: transparent; border: none; outline: none;
  font-size: 15px; color: var(--fg); font-family: var(--font-ui);
}
.ch-input::placeholder { color: var(--fg-muted); }
.ch-tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--bd-soft); }
.ch-tab {
  padding: 5px 10px; color: var(--fg-dim); border-bottom: 2px solid transparent;
  display: flex; align-items: center; gap: 5px; white-space: nowrap;
}
.ch-tab:hover { color: var(--fg); }
.ch-tab.active { color: var(--fg); border-bottom-color: var(--accent); }
.ch-body { flex: 1; display: flex; min-height: 0; }
.ch-list { flex: 1; overflow-y: auto; padding: 4px 0; min-width: 0; }
.popup.chooser.with-preview .ch-list { flex: 0 0 46%; border-right: 1px solid var(--bd-soft); }
.ch-preview { flex: 1; overflow: auto; background: var(--bg-editor); min-width: 0; }
.ch-preview.hidden { display: none; }
.ch-row { display: flex; align-items: center; gap: 8px; height: 24px; padding: 0 12px; white-space: nowrap; }
.ch-row.selected { background: var(--bg-sel); }
.ch-ricon { width: 16px; height: 16px; flex: none; }
.ch-ricon svg { width: 16px; height: 16px; display: block; }
.ch-name { overflow: hidden; text-overflow: ellipsis; flex: none; max-width: 62%; }
.ch-name.mono { font-family: var(--font-mono); font-size: 11.5px; }
.ch-name b { color: var(--accent); font-weight: 700; }
.ch-row.selected .ch-name b { color: #9dc0ff; }
.ch-name.disabled { color: var(--fg-disabled); }
.ch-name.is-open { font-weight: 500; }
.ch-loc { margin-left: auto; color: var(--fg-muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; padding-left: 14px; }
.ch-key { margin-left: 12px; }
.ch-check { color: var(--run-green); }
.ch-group {
  padding: 7px 12px 3px; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--fg-muted); font-weight: 600;
}
.ch-more { padding: 3px 12px; color: var(--fg-muted); font-size: 11px; }
.ch-empty { padding: 26px; text-align: center; color: var(--fg-muted); }
.ch-footer {
  border-top: 1px solid var(--bd-soft); padding: 5px 12px;
  color: var(--fg-muted); font-size: 10.5px; display: flex; gap: 6px; flex-wrap: wrap;
}

/* ----------------------------------------------------------------- dialogs */
.modal-overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: var(--bg-overlay);
  display: grid; place-items: center;
  opacity: 0; transition: opacity 120ms var(--ease);
  padding: 16px;
}
.modal-overlay.in { opacity: 1; }
.dialog {
  background: var(--bg-dialog);
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-modal);
  display: flex; flex-direction: column;
  max-width: calc(100vw - 32px); max-height: calc(100vh - 32px);
  transform: translateY(-8px); transition: transform 120ms var(--ease);
  outline: none;
}
.modal-overlay.in .dialog { transform: none; }
.dialog.shake { animation: dlgShake 220ms var(--ease); }
@keyframes dlgShake { 0%,100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.dlg-title {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 12px 11px 16px; font-weight: 600; font-size: 13px;
  cursor: default; user-select: none;
}
.dlg-title .spacer { flex: 1; }
.dlg-close { width: 22px; height: 22px; display: grid; place-items: center; border-radius: var(--radius-s); color: var(--fg-muted); }
.dlg-close:hover { background: var(--bg-hover); color: var(--fg); }
.dlg-close svg { width: 14px; height: 14px; }
.dlg-body { flex: 1; overflow: auto; padding: 4px 16px 12px; min-height: 0; }
.dlg-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--bd-soft);
}
.dlg-footer .spacer { flex: 1; }
.dlg-help { width: 22px; height: 22px; display: grid; place-items: center; color: var(--fg-muted); border-radius: var(--radius-s); }
.dlg-help:hover { background: var(--bg-hover); }
.dlg-btn {
  min-width: 76px; height: 26px; padding: 0 14px;
  border: 1px solid var(--bd-strong); background: transparent;
  color: var(--fg); border-radius: var(--radius-m); cursor: default;
  transition: background 90ms var(--ease), border-color 90ms var(--ease);
}
.dlg-btn:hover:not(:disabled) { background: var(--bg-hover); }
.dlg-btn:disabled { opacity: 0.45; }
.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(--sq-error); color: var(--sq-error); }
.dlg-btn.danger:hover:not(:disabled) { background: var(--sq-error); color: #fff; }
.dlg-btn:focus-visible { box-shadow: 0 0 0 2px var(--accent-soft); }

.dlg-message { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0 6px; line-height: 1.6; }
.dlg-mi { flex: none; color: var(--accent); }
.dlg-mi svg { width: 22px; height: 22px; }
.dlg-sub { color: var(--fg-muted); margin-top: 5px; font-size: 11.5px; }
.dlg-error { color: var(--sq-error); font-size: 11px; min-height: 15px; margin-top: 4px; }
.form-note { color: var(--fg-muted); font-size: 11px; margin: 8px 0 4px; }

/* form controls (shared with the settings dialog) */
.form-row { display: flex; align-items: flex-start; gap: 12px; margin: 12px 0; }
.form-label { flex: none; width: 130px; padding-top: 4px; color: var(--fg-dim); text-align: right; }
.form-control { flex: 1; min-width: 0; }
.form-hint { color: var(--fg-muted); font-size: 10.5px; margin-top: 4px; line-height: 1.5; }
.input, .select {
  width: 100%; height: 26px; padding: 0 8px;
  background: var(--bg-input); color: var(--fg);
  border: 1px solid var(--bd-strong); border-radius: var(--radius-s);
  outline: none; font-family: var(--font-ui);
}
.input.num { width: 90px; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.select { appearance: none; padding-right: 22px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 12px) 11px, calc(100% - 8px) 11px;
  background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; }
.checkbox, .radio { display: flex; align-items: center; gap: 7px; margin: 7px 0; }
.checkbox input, .radio input { appearance: none; width: 14px; height: 14px; flex: none;
  border: 1px solid var(--bd-strong); background: var(--bg-input); border-radius: 2px; position: relative; }
.radio input { border-radius: 50%; }
.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: 4px; height: 8px;
  border: solid #fff; border-width: 0 1.6px 1.6px 0; transform: rotate(42deg);
}
.radio input:checked::after { content: ''; position: absolute; inset: 3px; background: #fff; border-radius: 50%; }
.checkbox input:focus-visible, .radio input:focus-visible { box-shadow: 0 0 0 2px var(--accent-soft); }
.fieldset { margin: 14px 0; }
.fieldset-caption { font-weight: 600; color: var(--fg-dim); margin-bottom: 6px; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.4px; }
.radio-group { display: flex; flex-direction: column; }

/* narrow viewports */
@media (max-width: 700px) {
  .popup.chooser.with-preview .ch-list { flex: 1; border-right: none; }
  .popup.chooser .ch-preview { display: none; }
  .form-row { flex-direction: column; gap: 4px; }
  .form-label { width: auto; text-align: left; padding-top: 0; }
}
