/* =========================================================================
   COMMAND PALETTE (⌘K) — the global search overlay, shared by the admin app
   and the client portal (src/shared/lib/commandPalette.js).

   Desktop: a floating panel anchored near the top of the viewport. Mobile: a
   full-height sheet, so the on-screen keyboard doesn't squash the results.
   All colour comes from tokens, so it themes light/dark with everything else.
   ========================================================================= */

.cmdk-root {
  position: fixed;
  inset: 0;
  z-index: 1200;                       /* above drawers + sheets */
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh var(--space-4) var(--space-4);
  animation: cmdkIn var(--motion-overlay) var(--ease-enter);
}
.cmdk-root.is-closing { animation: cmdkOut 150ms var(--ease-exit) forwards; }
@keyframes cmdkIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes cmdkOut { to { opacity: 0; } }

.cmdk-scrim {
  position: absolute;
  inset: 0;
  background: var(--sheet-scrim);
  backdrop-filter: blur(2px);
}

.cmdk-panel {
  position: relative;
  width: min(640px, 100%);
  max-height: min(70vh, 640px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: cmdkRise 200ms var(--ease-enter);
}
@keyframes cmdkRise { from { opacity: 0; transform: translateY(-8px) scale(0.985); } to { opacity: 1; transform: none; } }
.cmdk-root.is-closing .cmdk-panel { animation: none; }

/* ---- input row ---- */
.cmdk-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-faint);
}
/* accent, matching the topbar box this overlay opens from (.search svg) */
.cmdk-head-ico { display: inline-flex; color: var(--primary-500); }
.cmdk-head-ico svg { width: 18px; height: 18px; }
.cmdk-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  font-family: var(--font-sans);
  font-size: var(--text-lg, 16px);
  color: var(--text-strong);
  padding: 4px 0;
  box-shadow: none;
  border-radius: 0;
}
.cmdk-input:focus, .cmdk-input:focus-visible { outline: 0; box-shadow: none; border: 0; }
.cmdk-input::placeholder { color: var(--text-soft); }
.cmdk-esc {
  border: 1px solid var(--border);
  background: var(--surface-field);
  color: var(--text-soft);
  border-radius: var(--radius-xs);
  font: 600 var(--text-2xs) / 1 var(--font-sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 5px 8px;
  cursor: pointer;
}
.cmdk-esc:hover { color: var(--text); border-color: var(--border-strong); }

/* the in-flight indicator: only visible while a request is out */
.cmdk-spinner {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary-600);
  opacity: 0;
  transition: opacity 120ms linear;
}
.cmdk-root.is-loading .cmdk-spinner { opacity: 1; animation: cmdkSpin 0.7s linear infinite; }
@keyframes cmdkSpin { to { transform: rotate(360deg); } }

/* ---- results ---- */
.cmdk-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.cmdk-group + .cmdk-group { margin-top: var(--space-2); }
.cmdk-group-label {
  padding: var(--space-2) var(--space-3) 6px;
  font-size: var(--text-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.cmdk-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  scroll-margin: var(--space-2);
}
.cmdk-row[aria-selected="true"] { background: var(--surface-hover-strong); }
.cmdk-row-ico {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--text-soft);
}
.cmdk-row-ico svg { width: 17px; height: 17px; }
/* rows that carry a real identity mark (client logo / lead avatar) instead of
   a glyph — sized to the row, and never tinted by the selection state */
.cmdk-row-ico--face { width: 24px; height: 24px; }
.cmdk-row-ico--face .proj-logo { width: 24px; height: 24px; font-size: 11px; border-radius: var(--radius-sm); }
.cmdk-row-ico--face .avatar { width: 24px; height: 24px; font-size: 10px; }
.cmdk-row[aria-selected="true"] .cmdk-row-ico { color: var(--primary-600); }
.cmdk-row-text { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.cmdk-row-title {
  font-size: var(--text-md);
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmdk-row-sub {
  font-size: var(--text-xs);
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmdk-row-title mark, .cmdk-row-sub mark {
  background: color-mix(in srgb, var(--primary-600) 22%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}
.cmdk-row-meta {
  flex: 0 0 auto;
  font-size: var(--text-2xs);
  color: var(--text-soft);
  white-space: nowrap;
}

/* an inline note under the list (e.g. search unreachable) */
.cmdk-note {
  padding: var(--space-3);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-soft);
}

.cmdk-empty {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-soft);
}

/* ---- footer hints ---- */
.cmdk-foot {
  display: flex;
  gap: var(--space-4);
  padding: 8px var(--space-4);
  border-top: 1px solid var(--border-faint);
  background: var(--surface-sunk);
  font-size: var(--text-2xs);
  color: var(--text-soft);
}
.cmdk-foot kbd {
  display: inline-block;
  min-width: 16px;
  text-align: center;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  padding: 1px 4px;
  margin-right: 3px;
  font: 500 10px/1.4 var(--font-sans);
  color: var(--text-muted);
}

/* the ⌘K badge inside the topbar search box (the palette's trigger) */
.search .search-kbd {
  margin-left: auto;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  padding: 2px 6px;
  font: 600 10px/1.5 var(--font-sans);
  color: var(--text-soft);
  pointer-events: none;
}

/* ---- mobile: full-height sheet ---- */
@media (max-width: 640px) {
  .cmdk-root { padding: 0; align-items: stretch; }
  .cmdk-panel {
    width: 100%;
    max-height: none;
    height: 100%;
    border: 0;
    border-radius: 0;
    padding-top: env(safe-area-inset-top);
    animation: none;
  }
  .cmdk-foot { display: none; }          /* no physical keyboard to hint at */
  .cmdk-body { padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .cmdk-root, .cmdk-panel { animation: none; }
  .cmdk-root.is-loading .cmdk-spinner { animation: none; }
}
