/* ═══════════════════════════════════════════════════════════════
   RAVEN AI FUSION — Command Palette
   frontend/css/command_palette.css  ?v=20260610p4

   FE-4: Combined global search + command palette (Ctrl+K / ⌘K).
   Single surface — fuzzy command registry + live backend search.

   Design decisions (documented per CLAUDE.md policy):
   - z-index at --rv-z-dialog (1010): sits above sheets/floats, below
     tooltips. Matches spec "dialog tier" requirement.
   - Overlay uses --rv-color-bg-overlay backdrop; the input/results
     card is centred at 640px wide — wide enough for sublabels.
   - transform+opacity animations only (GPU-accelerated per CLAUDE.md).
   - ARIA: combobox/listbox pattern wired in JS.

   Spec: dev-dev-docs/ux/2026-06-10-ux-overhaul-implementation-spec.md §FE-4
   ═══════════════════════════════════════════════════════════════ */

/* ── Palette backdrop ─────────────────────────────────────────── */

#rv-palette-backdrop {
  position: fixed;
  inset: 0;
  background: var(--rv-color-bg-overlay);
  z-index: var(--rv-z-dialog);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: clamp(80px, 12vh, 140px);
  /* Entry animation. UI-1 (audit): when closed, the backdrop must not
     intercept clicks — visibility+pointer-events gate the invisible overlay. */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--rv-dur-fast) var(--rv-ease-out),
              visibility 0s linear var(--rv-dur-fast);
}

#rv-palette-backdrop.rv-palette--open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity var(--rv-dur-fast) var(--rv-ease-out);
}

/* ── Palette card ─────────────────────────────────────────────── */

#rv-palette-card {
  width: min(640px, 96vw);
  max-height: min(520px, 80vh);
  background: var(--rv-color-bg-panel);
  border: 1px solid var(--rv-color-border-accent);
  border-radius: var(--rv-r-xl);
  box-shadow: var(--rv-shadow-xl), var(--rv-shadow-accent);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Entry animation — slide down from above */
  transform: translateY(-16px) scale(0.98);
  opacity: 0;
  transition:
    transform var(--rv-dur-normal) var(--rv-ease-spring),
    opacity   var(--rv-dur-fast)   var(--rv-ease-out);
}

#rv-palette-backdrop.rv-palette--open #rv-palette-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ── Search row ───────────────────────────────────────────────── */

.rv-palette-search-row {
  display: flex;
  align-items: center;
  gap: var(--rv-space-2);
  padding: var(--rv-space-3) var(--rv-space-4);
  border-bottom: 1px solid var(--rv-color-border);
  flex-shrink: 0;
}

.rv-palette-search-icon {
  color: var(--rv-color-text-muted);
  font-size: var(--rv-fs-lg);
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
}

#rv-palette-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--rv-color-text-primary);
  font-family: var(--rv-font-ui);
  font-size: var(--rv-fs-md);
  font-weight: var(--rv-fw-normal);
  caret-color: var(--rv-color-accent);
}

#rv-palette-input::placeholder {
  color: var(--rv-color-text-muted);
  font-size: var(--rv-fs-base);
}

.rv-palette-kbd-hint {
  font-family: var(--rv-font-mono);
  font-size: var(--rv-fs-xs);
  color: var(--rv-color-text-muted);
  background: var(--rv-color-bg-card);
  border: 1px solid var(--rv-color-border-bright);
  border-radius: var(--rv-r-sm);
  padding: 2px 6px;
  flex-shrink: 0;
  letter-spacing: var(--rv-ls-wide);
  white-space: nowrap;
}

/* ── Results list ─────────────────────────────────────────────── */

#rv-palette-results {
  overflow-y: auto;
  flex: 1;
  padding: var(--rv-space-2) 0;
  /* Thin scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--rv-color-border-bright) transparent;
}

#rv-palette-results::-webkit-scrollbar {
  width: 4px;
}
#rv-palette-results::-webkit-scrollbar-track {
  background: transparent;
}
#rv-palette-results::-webkit-scrollbar-thumb {
  background: var(--rv-color-border-bright);
  border-radius: var(--rv-r-full);
}

/* ── Group section header ─────────────────────────────────────── */

.rv-palette-group-header {
  padding: var(--rv-space-1) var(--rv-space-4);
  font-family: var(--rv-font-mono);
  font-size: var(--rv-fs-xs);
  font-weight: var(--rv-fw-semibold);
  color: var(--rv-color-text-muted);
  letter-spacing: var(--rv-ls-wider);
  text-transform: uppercase;
  margin-top: var(--rv-space-2);
  /* First group: no top margin */
  &:first-child { margin-top: 0; }
}

.rv-palette-group-header:first-child {
  margin-top: 0;
}

/* ── Individual result item ───────────────────────────────────── */

.rv-palette-item {
  display: flex;
  align-items: center;
  gap: var(--rv-space-3);
  padding: var(--rv-space-2) var(--rv-space-4);
  cursor: pointer;
  border-radius: 0;
  transition:
    background var(--rv-dur-instant) var(--rv-ease-out),
    opacity    var(--rv-dur-instant) var(--rv-ease-out);
  user-select: none;
  /* Arrow-key focus ring is via .rv-palette-item--active */
}

.rv-palette-item:hover,
.rv-palette-item--active {
  background: var(--rv-color-bg-card-hover);
}

.rv-palette-item--active {
  /* Accent left border for keyboard-navigation clarity */
  box-shadow: inset 2px 0 0 var(--rv-color-accent);
}

/* Item icon chip */
.rv-palette-item-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--rv-r-md);
  background: var(--rv-color-bg-card);
  border: 1px solid var(--rv-color-border);
  font-size: var(--rv-fs-base);
  flex-shrink: 0;
  color: var(--rv-color-text-secondary);
  line-height: 1;
}

/* Data-result items get a type-coloured icon */
.rv-palette-item[data-result-type="entity"]   .rv-palette-item-icon { border-color: var(--rv-color-accent-border); color: var(--rv-color-accent); }
.rv-palette-item[data-result-type="threat"]   .rv-palette-item-icon { border-color: var(--rv-color-sev-high);       color: var(--rv-color-sev-high); }
.rv-palette-item[data-result-type="asset"]    .rv-palette-item-icon { border-color: var(--rv-color-sev-low);        color: var(--rv-color-sev-low); }
.rv-palette-item[data-result-type="ops_room"] .rv-palette-item-icon { border-color: var(--rv-color-sev-medium);     color: var(--rv-color-sev-medium); }

/* Item text content */
.rv-palette-item-text {
  flex: 1;
  min-width: 0;
}

.rv-palette-item-label {
  display: block;
  font-size: var(--rv-fs-base);
  font-weight: var(--rv-fw-medium);
  color: var(--rv-color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rv-palette-item-sublabel {
  display: block;
  font-size: var(--rv-fs-xs);
  color: var(--rv-color-text-muted);
  font-family: var(--rv-font-mono);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: var(--rv-ls-wide);
}

/* Item right-side key badge (for commands) */
.rv-palette-item-kbd {
  font-family: var(--rv-font-mono);
  font-size: var(--rv-fs-xs);
  color: var(--rv-color-text-muted);
  background: var(--rv-color-bg-card);
  border: 1px solid var(--rv-color-border-bright);
  border-radius: var(--rv-r-sm);
  padding: 1px 5px;
  flex-shrink: 0;
  display: none; /* shown only when item is .rv-palette-item--active */
}

.rv-palette-item--active .rv-palette-item-kbd {
  display: block;
}

/* ── Empty / loading / error states ──────────────────────────── */

.rv-palette-empty,
.rv-palette-loading,
.rv-palette-error {
  padding: var(--rv-space-6) var(--rv-space-4);
  text-align: center;
  color: var(--rv-color-text-muted);
  font-size: var(--rv-fs-sm);
  font-family: var(--rv-font-mono);
  letter-spacing: var(--rv-ls-wide);
}

.rv-palette-error {
  color: var(--rv-color-sev-critical);
}

.rv-palette-loading::before {
  content: '⟳ ';
  animation: rv-palette-spin 1s linear infinite;
  display: inline-block;
}

@keyframes rv-palette-spin {
  to { transform: rotate(360deg); }
}

/* ── Footer ───────────────────────────────────────────────────── */

.rv-palette-footer {
  display: flex;
  align-items: center;
  gap: var(--rv-space-4);
  padding: var(--rv-space-2) var(--rv-space-4);
  border-top: 1px solid var(--rv-color-border);
  flex-shrink: 0;
  font-family: var(--rv-font-mono);
  font-size: var(--rv-fs-xs);
  color: var(--rv-color-text-muted);
  letter-spacing: var(--rv-ls-wide);
}

.rv-palette-footer-key {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.rv-palette-footer-key kbd {
  background: var(--rv-color-bg-card);
  border: 1px solid var(--rv-color-border-bright);
  border-radius: var(--rv-r-sm);
  padding: 1px 5px;
  font-family: var(--rv-font-mono);
  font-size: var(--rv-fs-xs);
  color: var(--rv-color-text-secondary);
}

/* ── Topbar search trigger box ────────────────────────────────── */

#rv-topbar-search {
  display: flex;
  align-items: center;
  gap: var(--rv-space-2);
  height: 28px;
  padding: 0 var(--rv-space-3);
  background: var(--rv-color-bg-card);
  border: 1px solid var(--rv-color-border-bright);
  border-radius: var(--rv-r-lg);
  cursor: pointer;
  font-family: var(--rv-font-mono);
  font-size: var(--rv-fs-xs);
  color: var(--rv-color-text-muted);
  letter-spacing: var(--rv-ls-wide);
  transition:
    border-color var(--rv-dur-fast) var(--rv-ease-out),
    background   var(--rv-dur-fast) var(--rv-ease-out);
  white-space: nowrap;
  flex-shrink: 0;
}

#rv-topbar-search:hover,
#rv-topbar-search:focus-visible {
  border-color: var(--rv-color-accent-border);
  background: var(--rv-color-bg-card-hover);
  color: var(--rv-color-text-secondary);
  outline: none;
}

.rv-topbar-search-icon {
  font-size: var(--rv-fs-base);
  color: var(--rv-color-text-muted);
  line-height: 1;
}

.rv-topbar-search-label {
  /* label text is hidden on very small viewports */
}

#rv-topbar-search .rv-palette-kbd-hint {
  /* override sizing for the topbar mini version */
  font-size: var(--rv-fs-xs); /* 0.78rem — floor per F-19 */
  padding: 1px 4px;
}

/* Responsive: hide label text below 900px to keep topbar compact */
@media (max-width: 900px) {
  .rv-topbar-search-label {
    display: none;
  }
  #rv-topbar-search {
    width: 28px;
    padding: 0;
    justify-content: center;
  }
  #rv-topbar-search .rv-palette-kbd-hint {
    display: none;
  }
}
