/* palette.css — ⌘K command palette with Genie-bar morph animation */

/* ── Backdrop ─────────────────────────────────────────────────── */
.palette-backdrop {
  position: fixed; inset: 0;
  z-index: 90;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 11vh;
  background: rgba(15, 20, 35, 0);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  transition: background 220ms ease, backdrop-filter 220ms ease, -webkit-backdrop-filter 220ms ease;
  /* Allow the genie pill to overflow during the morph */
  overflow: hidden;
}
.palette-backdrop.is-open {
  background: rgba(15, 20, 35, 0.42);
  backdrop-filter: blur(8px) saturate(1.05);
  -webkit-backdrop-filter: blur(8px) saturate(1.05);
}

/* ── The palette card (Genie morph target) ────────────────────── */
.palette {
  width: min(680px, 92vw);
  max-height: 72vh;
  background: var(--surface, #fff);
  border-radius: 12px;
  box-shadow:
    0 24px 64px rgba(15, 20, 35, 0.28),
    0 2px 8px rgba(15, 20, 35, 0.08);
  border: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;

  /* Genie morph: starts at the search-bar's pose (vars set via JS),
     ends at identity. Transitioning the class flip plays it both ways. */
  transform-origin: 50% 0;
  transform:
    translate(var(--genie-tx, 0px), var(--genie-ty, -10px))
    scale(var(--genie-sx, .96), var(--genie-sy, .96));
  opacity: 0;
  filter: blur(var(--genie-blur, 4px));
  border-radius: var(--genie-radius, 18px);
  will-change: transform, opacity, filter, border-radius;
  transition:
    transform 320ms cubic-bezier(.2,.85,.25,1.02),
    opacity 220ms ease,
    filter 240ms ease,
    border-radius 280ms ease;
}
.palette.is-open {
  transform: none;
  opacity: 1;
  filter: blur(0);
  border-radius: 12px;
}

/* While the genie is folded down (entering or exiting), let inner
   children fade with the card to avoid visible "snap" of text/list. */
.palette:not(.is-open) .palette-results,
.palette:not(.is-open) .palette-scope,
.palette:not(.is-open) .palette-footer { opacity: 0; transition: opacity 160ms ease; }
.palette.is-open .palette-results,
.palette.is-open .palette-scope,
.palette.is-open .palette-footer { opacity: 1; transition: opacity 220ms ease 80ms; }

/* ── Search bar (top of card) ─────────────────────────────────── */
.palette-searchbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  min-height: 52px;
}
.palette-searchbar > svg { color: var(--ink-muted); flex-shrink: 0; }

.palette-chips {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.palette-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 6px 3px 8px;
  background: var(--surface-2, #f1f4f9);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px; font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}
.palette-chip-key {
  font-size: 10px; color: var(--ink-muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}
.palette-chip-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}
.palette-chip-x {
  border: none; background: transparent; color: var(--ink-muted);
  cursor: pointer; padding: 0; display: inline-flex;
  border-radius: 3px;
}
.palette-chip-x:hover { color: var(--ink); background: rgba(0,0,0,.06); }

.palette-input {
  flex: 1; min-width: 120px;
  border: none; outline: none; background: transparent;
  font: inherit; font-size: 15px; color: var(--ink);
  padding: 2px 0;
}
.palette-input::placeholder { color: var(--ink-muted); }

.palette-kbd {
  font-size: 10px; font-weight: 700;
  color: var(--ink-muted);
  background: var(--surface-2, #f1f4f9);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: inherit;
  letter-spacing: .02em;
}
.palette-esc { margin-left: auto; }

/* ── Scope strip ──────────────────────────────────────────────── */
.palette-scope {
  display: flex; gap: 2px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2, #fafbfd);
  font-size: 12px;
  overflow-x: auto;
}
.palette-scope button {
  border: none; background: transparent;
  padding: 5px 10px;
  border-radius: 6px;
  font: inherit; font-size: 12px; font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap;
}
.palette-scope button:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.palette-scope button.is-active {
  background: var(--brand-faint, #e1eeff);
  color: var(--brand, #0073ea);
}
.palette-scope-count {
  font-size: 10px;
  background: rgba(0,0,0,.08);
  color: inherit;
  padding: 0 5px;
  border-radius: 8px;
  min-width: 16px; text-align: center;
}
.palette-scope button.is-active .palette-scope-count {
  background: rgba(0, 115, 234, .18);
}

/* ── Results ──────────────────────────────────────────────────── */
.palette-results {
  overflow-y: auto; flex: 1;
  padding: 4px 0 8px;
}
.palette-group-label {
  font-size: 10px; font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 10px 16px 4px;
  display: flex; align-items: center; gap: 8px;
}
.palette-group-label::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.palette-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  border-left: 2px solid transparent;
  min-height: 36px;
}
.palette-row:hover { background: var(--surface-2, #f5f7fb); }
.palette-row.is-active {
  background: var(--brand-faint, #e1eeff);
  border-left-color: var(--brand, #0073ea);
}
.palette-row-icon {
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px;
  background: var(--surface-2, #f1f4f9);
  color: var(--ink-muted);
  flex-shrink: 0;
  font-size: 11px; font-weight: 700;
}
.palette-row-icon--epic {
  width: 4px; height: 24px; border-radius: 2px; background: var(--ink-muted);
}
.palette-row-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.palette-row-title {
  font-size: 13px; font-weight: 500; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.palette-row-title mark {
  background: rgba(255, 203, 0, .4);
  color: inherit; padding: 0 1px; border-radius: 2px;
  font-weight: 700;
}
.palette-row-meta {
  font-size: 11px; color: var(--ink-muted);
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.palette-row-meta-sep { opacity: .4; }
.palette-row-right {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0; color: var(--ink-muted); font-size: 11px;
}
.palette-row.is-active .palette-row-right .palette-enter { display: inline-flex; }
.palette-enter { display: none; align-items: center; gap: 4px; font-weight: 600; color: var(--brand); }

.palette-empty {
  padding: 48px 16px; text-align: center;
  color: var(--ink-muted); font-size: 13px;
}
.palette-empty-title { font-weight: 600; color: var(--ink); margin-bottom: 4px; font-size: 14px; }
.palette-empty-hint { font-size: 12px; margin-top: 10px; }
.palette-empty-hint code {
  background: var(--surface-2, #f1f4f9);
  border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px;
  font-size: 11px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink);
}

.palette-footer {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--ink-muted);
  background: var(--surface-2, #fafbfd);
  flex-wrap: wrap;
}
.palette-footer-item { display: inline-flex; align-items: center; gap: 5px; }
.palette-footer-spacer { flex: 1; }
.palette-footer-brand { font-weight: 600; color: var(--ink-muted); }

/* ── Topbar trigger styling — hint that it's the genie origin ── */
.topbar-search {
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 220ms cubic-bezier(.2,.85,.3,1), opacity 220ms ease;
}
.topbar-search.is-palette-trigger:hover {
  border-color: var(--brand, #0073ea);
  background: var(--surface);
}
.topbar-search-kbd {
  margin-left: auto;
  font-size: 10px; font-weight: 700;
  color: var(--ink-muted);
  background: var(--surface-2, #f1f4f9);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
}

/* While the genie is open, fade the trigger so it feels like the
   bar lifted off into the palette. The card is always visible. */
.topbar-search.is-genie-launching {
  opacity: 0;
  transform: scale(.96);
  pointer-events: none;
}

/* Reduced motion — respect user preference */
@media (prefers-reduced-motion: reduce) {
  .palette,
  .palette-backdrop,
  .topbar-search { transition-duration: 0.01ms !important; }
  .palette { transform: none !important; filter: none !important; }
}

/* ─────────────────────────────────────────────────────────────────
   AI search bar — animated gradient border, pulsing sparkle, drift
   ───────────────────────────────────────────────────────────────── */

/* Register the rotating angle so it can be animated. Without @property
   support the gradient renders statically (graceful fallback). */
@property --ai-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

.topbar-search.ai-bar {
  position: relative;
  width: 320px;
  height: 36px;
  padding: 0 8px 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background:
    linear-gradient(var(--surface, #fff), var(--surface, #fff)) padding-box,
    conic-gradient(
      from var(--ai-angle, 0deg),
      #a25ddc 0%,
      #6c2bd9 18%,
      #4c8bf5 36%,
      #38d6c4 52%,
      #f59e0b 68%,
      #f06ea2 84%,
      #a25ddc 100%
    ) border-box;
  box-shadow:
    0 0 0 1px rgba(162, 93, 220, 0.06),
    0 6px 18px -8px rgba(108, 43, 217, 0.28),
    0 1px 2px rgba(15, 20, 35, 0.05);
  overflow: hidden;
  animation: ai-rotate 7s linear infinite;
  display: flex; align-items: center; gap: 8px;
}
@keyframes ai-rotate {
  to { --ai-angle: 360deg; }
}

/* Subtle internal sheen that drifts left→right */
.topbar-search.ai-bar::before {
  content: "";
  position: absolute; inset: 1px;
  border-radius: 999px;
  background:
    radial-gradient(120% 200% at 0% 50%, rgba(162, 93, 220, .10), transparent 55%),
    radial-gradient(120% 200% at 100% 50%, rgba(76, 139, 245, .08), transparent 55%);
  pointer-events: none;
  z-index: 0;
}

/* Animated shimmer streak across the bar — fires every 5s */
.topbar-search.ai-bar::after {
  content: "";
  position: absolute; top: 0; bottom: 0; left: -40%;
  width: 40%;
  background: linear-gradient(105deg,
    transparent 0%,
    rgba(255, 255, 255, .55) 50%,
    transparent 100%);
  filter: blur(2px);
  pointer-events: none;
  animation: ai-shimmer 5.5s ease-in-out infinite;
  z-index: 1;
}
@keyframes ai-shimmer {
  0%, 80%, 100% { transform: translateX(0); opacity: 0; }
  85% { opacity: 1; }
  98% { transform: translateX(360%); opacity: 0; }
}

.topbar-search.ai-bar:hover {
  box-shadow:
    0 0 0 1px rgba(162, 93, 220, 0.10),
    0 10px 22px -8px rgba(108, 43, 217, 0.42),
    0 2px 4px rgba(15, 20, 35, 0.06);
  transform: translateY(-1px);
}

.topbar-search.ai-bar:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(162, 93, 220, 0.25),
    0 10px 22px -8px rgba(108, 43, 217, 0.42);
}

/* ── The sparkle icon + floating sparks ── */
.ai-bar-icon {
  position: relative;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  z-index: 2;
}
.ai-bar-icon svg {
  width: 16px; height: 16px;
  fill: #a25ddc;
  stroke: #a25ddc;
  stroke-width: 1;
  color: #a25ddc;
  filter: drop-shadow(0 0 6px rgba(162, 93, 220, 0.45));
  animation: ai-pulse 2.4s ease-in-out infinite;
}
@keyframes ai-pulse {
  0%, 100% { transform: scale(1) rotate(0deg); filter: drop-shadow(0 0 4px rgba(162, 93, 220, 0.35)); }
  50%      { transform: scale(1.08) rotate(8deg); filter: drop-shadow(0 0 10px rgba(162, 93, 220, 0.65)); }
}

/* Three tiny floating sparks around the sparkle */
.ai-bar-spark {
  position: absolute;
  width: 3px; height: 3px;
  background: #a25ddc;
  border-radius: 50%;
  opacity: 0;
  filter: drop-shadow(0 0 3px currentColor);
}
.ai-bar-spark--a {
  top: 1px; left: 16px;
  background: #f59e0b;
  animation: ai-spark 3.2s ease-in-out infinite;
}
.ai-bar-spark--b {
  bottom: 2px; left: 0px;
  background: #38d6c4;
  animation: ai-spark 3.2s ease-in-out 1.1s infinite;
}
.ai-bar-spark--c {
  top: 4px; left: -2px;
  background: #f06ea2;
  animation: ai-spark 3.2s ease-in-out 2.1s infinite;
}
@keyframes ai-spark {
  0%, 100% { opacity: 0; transform: translate(0, 0) scale(.6); }
  20%      { opacity: 1; transform: translate(2px, -3px) scale(1); }
  60%      { opacity: 0; transform: translate(4px, -6px) scale(.4); }
}

/* ── Text: gradient prompt + caret + dim hint ── */
.ai-bar-text {
  flex: 1; min-width: 0;
  display: flex; align-items: baseline; gap: 6px;
  font-size: 13px;
  white-space: nowrap; overflow: hidden;
  z-index: 2;
}
.ai-bar-prompt {
  font-weight: 600;
  background: linear-gradient(95deg, #a25ddc, #6c2bd9 35%, #4c8bf5 70%, #38d6c4);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: ai-text-shift 4.5s ease-in-out infinite;
}
@keyframes ai-text-shift {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}
.ai-bar-caret {
  display: inline-block;
  width: 1.5px; height: 13px;
  background: #a25ddc;
  border-radius: 1px;
  transform: translateY(2px);
  animation: ai-caret 1s ease-in-out infinite;
}
@keyframes ai-caret {
  0%, 50%  { opacity: 1; }
  51%, 100% { opacity: 0; }
}
.ai-bar-hint {
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.ai-bar-hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: rgba(162, 93, 220, 0.08);
  border: 1px solid rgba(162, 93, 220, 0.18);
  border-radius: 4px;
  padding: 1px 4px;
  color: #6c2bd9;
}

/* Compact when there's no room for the hint */
@media (max-width: 1100px) {
  .topbar-search.ai-bar { width: 240px; }
  .ai-bar-hint { display: none; }
}

/* Keyboard hint chip — slightly recolored for the AI bar */
.ai-bar-kbd {
  background: rgba(162, 93, 220, 0.10);
  border-color: rgba(162, 93, 220, 0.25);
  color: #6c2bd9;
  z-index: 2;
}

/* When the genie is launching, the bar fades out — but keep its glow
   alive for an extra beat so the morph feels continuous. */
.topbar-search.ai-bar.is-genie-launching::after,
.topbar-search.ai-bar.is-genie-launching::before { opacity: 0; }

/* Reduced motion — disable the spinning/shimmer/pulse */
@media (prefers-reduced-motion: reduce) {
  .topbar-search.ai-bar,
  .topbar-search.ai-bar::after,
  .ai-bar-icon svg,
  .ai-bar-spark,
  .ai-bar-prompt,
  .ai-bar-caret { animation: none !important; }
}

/* Inline SVG gradient definition — referenced by the sparkle icon's
   fill="url(#fb-ai-grad)". Defined globally so we paint with brand hues. */
.ai-bar-svg-defs { position: absolute; width: 0; height: 0; pointer-events: none; }

