/* ==========================================================================
   114 — Search Expand
   Loupe seule (cercle) qui se déplie en champ de recherche complet au
   clic/focus : largeur animée, le contour se morphe de cercle en pill, le
   placeholder apparaît en fondu décalé. Reste ouvert tant qu'il y a du
   texte (:has + :not(:placeholder-shown)), se replie sinon à la perte de
   focus. 100 % CSS — Escape vide le champ nativement (type="search").
   ========================================================================== */

.search-expand {
  --se-accent: var(--ml-accent, #7c8cff);
  --se-size: 48px;                                /* diamètre replié = hauteur */
  --se-width: min(260px, 76vw);                   /* largeur dépliée */
  --se-ease: cubic-bezier(0.22, 1, 0.36, 1);

  position: relative;
  width: var(--se-size);
  height: var(--se-size);
  border-radius: 999px;                           /* cercle → pill, morph naturel */
  background-color: var(--ml-surface, #151a24);
  border: 1px solid color-mix(in srgb, var(--ml-muted, #8b91a3) 28%, transparent);
  transition:
    width 0.45s var(--se-ease),
    border-color 0.3s var(--se-ease),
    box-shadow 0.3s var(--se-ease);
}

/* déplié : focus n'importe où dedans, OU champ non vide */
.search-expand:focus-within,
.search-expand:has(.search-expand__input:not(:placeholder-shown)) {
  width: var(--se-width);
  border-color: color-mix(in srgb, var(--se-accent) 60%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--se-accent) 14%, transparent);
}

/* anneau net réservé à la navigation clavier */
.search-expand:has(.search-expand__input:focus-visible) {
  outline: 2px solid var(--se-accent);
  outline-offset: 3px;
}

/* --- Loupe ------------------------------------------------------------------ */

/* le label focus l'input au clic : c'est lui, la « poignée » du composant */
.search-expand__icon {
  position: absolute;
  inset: 0 auto 0 0;
  display: grid;
  place-items: center;
  width: var(--se-size);
  color: var(--ml-muted, #8b91a3);
  cursor: pointer;
  transition:
    color 0.3s var(--se-ease),
    transform 0.45s var(--se-ease);
}

.search-expand:focus-within .search-expand__icon,
.search-expand:has(.search-expand__input:not(:placeholder-shown)) .search-expand__icon {
  color: var(--se-accent);
  transform: scale(0.86);                          /* la loupe cède la vedette au champ */
}

.search-expand:hover .search-expand__icon {
  color: var(--ml-fg, #e8eaf2);
}

.search-expand__svg {
  display: block;
  width: 20px;
  height: 20px;
}

/* --- Champ ------------------------------------------------------------------- */

.search-expand__input {
  width: 100%;
  height: 100%;
  padding: 0 14px 0 var(--se-size);
  border: 0;
  border-radius: inherit;
  background: none;
  color: var(--ml-fg, #e8eaf2);
  font: inherit;
  font-size: 0.92rem;
  outline: none;                                   /* focus porté par la bordure + :focus-visible */
  caret-color: var(--se-accent);
  opacity: 0;
  transition: opacity 0.25s var(--se-ease);
}

.search-expand:focus-within .search-expand__input,
.search-expand:has(.search-expand__input:not(:placeholder-shown)) .search-expand__input {
  opacity: 1;
  transition-delay: 0.08s;
}

/* placeholder en fondu décalé, une fois le champ déplié */
.search-expand__input::placeholder {
  color: color-mix(in srgb, var(--ml-muted, #8b91a3) 70%, transparent);
  opacity: 0;
  transition: opacity 0.3s var(--se-ease);
}

.search-expand:focus-within .search-expand__input::placeholder {
  opacity: 1;
  transition-delay: 0.22s;
}

/* --- Bouton × natif (type="search", WebKit/Blink) ------------------------------ */

.search-expand__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  margin-right: 2px;
  background-color: var(--ml-muted, #8b91a3);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6l12 12M18 6L6 18' stroke='%23000' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6l12 12M18 6L6 18' stroke='%23000' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  cursor: pointer;
  transition: background-color 0.2s var(--se-ease), transform 0.2s var(--se-ease);
}

.search-expand__input::-webkit-search-cancel-button:hover {
  background-color: var(--ml-fg, #e8eaf2);
  transform: scale(1.15);
}

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

@media (prefers-reduced-motion: reduce) {
  .search-expand,
  .search-expand__icon,
  .search-expand__input,
  .search-expand__input::placeholder,
  .search-expand:focus-within .search-expand__input,
  .search-expand:focus-within .search-expand__input::placeholder {
    transition-duration: 0.01s;
    transition-delay: 0s;
  }
}
