/* ==========================================================================
   102 — Command Palette
   Palette ⌘K : backdrop blur, panneau qui tombe avec un spring depuis
   -12 px, résultats en stagger, filtrage live (réordonnancement FLIP géré
   par anim.js), surbrillance qui glisse aux flèches, flash accent à
   l'exécution (Enter/clic).
   Racine : .command-palette — états .is-open / .is-closing pilotés par
   anim.js. Démo CONTENUE : overlay absolute dans la racine (relative).
   Voir README pour le passage en fixed plein écran.
   ========================================================================== */

.command-palette {
  --cp-accent: var(--ml-accent, #7c8cff);

  position: relative;
  width: min(320px, 100%);
  height: 248px;
  border-radius: 16px;
  overflow: hidden;
  background: var(--ml-surface, #151a24);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--ml-fg, #e8eaf2);
}

/* --- Décor : fausse interface derrière la palette --------------------------- */

.command-palette__scene {
  position: absolute;
  inset: 0;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.command-palette__ghost {
  height: 9px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--ml-muted, #8b91a3) 15%, transparent);
}

.command-palette__ghost--title {
  width: 42%;
  height: 13px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--ml-muted, #8b91a3) 25%, transparent);
}

.command-palette__ghost--short { width: 58%; }

/* --- Déclencheur « ⌘K Rechercher » ------------------------------------------ */

.command-palette__trigger {
  position: absolute;
  left: 50%;
  bottom: 24px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: color-mix(in srgb, var(--ml-surface, #151a24) 86%, white);
  color: var(--ml-muted, #8b91a3);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transform: translateX(-50%);
  transition:
    color 0.25s ease,
    border-color 0.25s ease,
    transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.3s ease;
}

.command-palette__trigger:hover {
  color: var(--ml-fg, #e8eaf2);
  border-color: color-mix(in srgb, var(--cp-accent) 45%, transparent);
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 10px 22px -12px color-mix(in srgb, var(--cp-accent) 60%, transparent);
}

.command-palette__trigger:active {
  transform: translateX(-50%) translateY(0) scale(0.97);
}

.command-palette__trigger:focus-visible {
  outline: 2px solid var(--cp-accent);
  outline-offset: 3px;
}

.command-palette__trigger svg {
  display: block;
  width: 13px;
  height: 13px;
}

.command-palette__kbd {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--ml-muted, #8b91a3);
  font-family: inherit;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

/* --- Overlay + backdrop blur -------------------------------------------------- */

.command-palette__overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px;
}

.command-palette__overlay[hidden] { display: none; }

.command-palette__backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--ml-bg, #0d1017) 55%, transparent);
  opacity: 0;
  -webkit-backdrop-filter: blur(0px);
  backdrop-filter: blur(0px);
  cursor: pointer;
  transition:
    opacity 0.28s ease,
    -webkit-backdrop-filter 0.4s ease,
    backdrop-filter 0.4s ease;
}

.command-palette.is-open .command-palette__backdrop {
  opacity: 1;
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.command-palette.is-closing .command-palette__backdrop {
  transition-duration: 0.16s;
}

/* --- Panneau : chute spring depuis -12 px -------------------------------------- */

.command-palette__panel {
  position: relative;
  width: min(280px, 100%);
  border-radius: 13px;
  background: color-mix(in srgb, var(--ml-surface, #151a24) 88%, white);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 22px 44px -16px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transform: translateY(-12px) scale(0.97);
  overflow: hidden;
}

.command-palette.is-open .command-palette__panel {
  animation: command-palette-panel-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes command-palette-panel-in {
  0%   { opacity: 0; transform: translateY(-12px) scale(0.97); }
  60%  { opacity: 1; transform: translateY(3px) scale(1.005); }
  82%  { transform: translateY(-1px) scale(1); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.command-palette.is-closing .command-palette__panel {
  animation: command-palette-panel-out 0.18s cubic-bezier(0.55, 0, 0.55, 0.2) forwards;
}

@keyframes command-palette-panel-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-8px) scale(0.97); }
}

/* --- Champ de recherche --------------------------------------------------------- */

.command-palette__field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px 9px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  color: var(--ml-muted, #8b91a3);
}

.command-palette__field svg {
  display: block;
  width: 13px;
  height: 13px;
  flex: none;
}

.command-palette__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ml-fg, #e8eaf2);
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1.3;
  outline: none;
  caret-color: var(--cp-accent);
}

.command-palette__input::placeholder {
  color: var(--ml-muted, #8b91a3);
  opacity: 0.75;
}

/* --- Liste de résultats + surbrillance qui glisse -------------------------------- */

.command-palette__list {
  position: relative;
  padding: 5px;
  max-height: 188px; /* 6 items visibles sans scroll dans la démo */
  overflow-y: auto;
}

.command-palette__cursor {
  position: absolute;
  left: 5px;
  right: 5px;
  top: 0;
  height: 28px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--cp-accent) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--cp-accent) 24%, transparent);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.2s cubic-bezier(0.3, 1.3, 0.45, 1),
    height 0.2s cubic-bezier(0.3, 1.3, 0.45, 1),
    opacity 0.15s ease;
}

.command-palette__list.has-selection .command-palette__cursor {
  opacity: 1;
}

.command-palette__item {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ml-muted, #8b91a3);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 500;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  transition: color 0.15s ease;
}

.command-palette__item.is-hidden { display: none; }

.command-palette__item.is-selected {
  color: var(--ml-fg, #e8eaf2);
}

.command-palette__item.is-selected .command-palette__item-icon {
  color: var(--cp-accent);
}

.command-palette__item:focus-visible {
  outline: 2px solid var(--cp-accent);
  outline-offset: -2px;
}

.command-palette__item-icon {
  display: block;
  width: 14px;
  height: 14px;
  flex: none;
  transition: color 0.15s ease;
}

.command-palette__label { flex: 1; }

/* Entrée en stagger — animation (pas transition) : fill backwards uniquement,
   pour laisser le FLIP inline reprendre la main une fois l'entrée jouée */
.command-palette.is-open .command-palette__item {
  animation: command-palette-item-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.command-palette.is-open .command-palette__item:nth-child(2) { animation-delay: 0.05s; }
.command-palette.is-open .command-palette__item:nth-child(3) { animation-delay: 0.08s; }
.command-palette.is-open .command-palette__item:nth-child(4) { animation-delay: 0.11s; }
.command-palette.is-open .command-palette__item:nth-child(5) { animation-delay: 0.14s; }
.command-palette.is-open .command-palette__item:nth-child(6) { animation-delay: 0.17s; }
.command-palette.is-open .command-palette__item:nth-child(7) { animation-delay: 0.2s; }

@keyframes command-palette-item-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Exécution : flash accent avant fermeture */
.command-palette__item.is-exec {
  animation: command-palette-exec 0.3s ease;
  color: var(--ml-fg, #e8eaf2);
}

@keyframes command-palette-exec {
  0%   { background: color-mix(in srgb, var(--cp-accent) 55%, transparent); transform: scale(1); }
  35%  { background: color-mix(in srgb, var(--cp-accent) 40%, transparent); transform: scale(0.985); }
  100% { background: transparent; transform: scale(1); }
}

/* --- État vide -------------------------------------------------------------------- */

.command-palette__empty {
  margin: 0;
  padding: 14px 12px 16px;
  font-size: 0.74rem;
  text-align: center;
  color: var(--ml-muted, #8b91a3);
}

.command-palette__empty[hidden] { display: none; }

/* --- Reduced motion ----------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .command-palette__trigger {
    transition: none;
  }

  .command-palette__trigger:hover,
  .command-palette__trigger:active {
    transform: translateX(-50%);
  }

  .command-palette__backdrop,
  .command-palette.is-closing .command-palette__backdrop {
    transition-duration: 0.01s;
  }

  .command-palette.is-open .command-palette__panel,
  .command-palette.is-closing .command-palette__panel {
    animation-duration: 0.01s;
  }

  .command-palette.is-open .command-palette__item,
  .command-palette__item.is-exec {
    animation-duration: 0.01s;
    animation-delay: 0s;
  }

  .command-palette__cursor {
    transition-duration: 0.01s;
  }
}
