/* ==========================================================================
   006 — Hold to Confirm · boutons
   Action destructive à maintenir : l'anneau SVG se remplit pendant le press
   (stroke-dashoffset piloté par anim.js) avec un micro-tremblement qui
   s'intensifie à l'approche du seuil. Relâcher trop tôt → l'anneau se
   rembobine vite et le bouton se rétablit d'un petit snap élastique.
   Maintien complet → état confirmé (fond danger, check dessiné, onde).
   Préfixe de classes : .hold-confirm (abréviation du slug hold-to-confirm).
   ========================================================================== */

.hold-confirm {
  --hold-confirm-danger: #f87171;
  --hold-confirm-ring: var(--ml-muted, #8b91a3);
  --hc-shake: 0; /* amplitude du tremblement, pilotée par anim.js (0 → ~1) */

  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1.5rem 0.85rem 1.05rem;
  border: 1px solid color-mix(in srgb, var(--hold-confirm-danger) 32%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--hold-confirm-danger) 9%, var(--ml-surface, #151a24));
  color: var(--ml-fg, #e8eaf2);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.015em;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none; /* évite le scroll qui casserait le hold au tactile */
  transition:
    background-color 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.hold-confirm:focus-visible {
  outline: 2px solid var(--ml-accent-2, #2dd4bf);
  outline-offset: 3px;
}

/* Tremblement : amplitude via --hc-shake (0 au repos → anim.js la fait
   grimper avec le progrès). L'animation tourne pendant tout le hold mais
   reste invisible tant que l'amplitude est nulle. */
.hold-confirm--holding {
  animation: hold-confirm-tremble 0.09s linear infinite;
}

@keyframes hold-confirm-tremble {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(calc(var(--hc-shake) * 1.1px), calc(var(--hc-shake) * -0.7px)); }
  50% { transform: translate(calc(var(--hc-shake) * -1px), calc(var(--hc-shake) * 0.5px)); }
  75% { transform: translate(calc(var(--hc-shake) * 0.6px), calc(var(--hc-shake) * 0.9px)); }
}

/* Snap élastique quand on relâche trop tôt (classe posée puis retirée par JS). */
.hold-confirm--snap {
  animation: hold-confirm-snap 0.5s cubic-bezier(0.34, 1.86, 0.44, 1);
}

@keyframes hold-confirm-snap {
  0% { transform: scale(0.965); }
  100% { transform: scale(1); }
}

/* --- Anneau + check (SVG inline, pathLength="1" côté markup) --------------- */

.hold-confirm__dial {
  display: block;
  width: 24px;
  height: 24px;
  flex: none;
}

.hold-confirm__track {
  fill: none;
  stroke: color-mix(in srgb, var(--hold-confirm-ring) 35%, transparent);
  stroke-width: 2;
}

.hold-confirm__ring {
  fill: none;
  stroke: var(--hold-confirm-danger);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  /* Rembobinage à l'abandon : rapide, avec une pointe élastique.
     Pendant le hold, anim.js coupe cette transition (--holding). */
  transition: stroke-dashoffset 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.hold-confirm--holding .hold-confirm__ring {
  transition: none;
}

.hold-confirm__check {
  fill: none;
  stroke: var(--ml-bg, #0d1017);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
}

/* --- Labels superposés ------------------------------------------------------ */

.hold-confirm__labels {
  position: relative;
  display: grid;
}

.hold-confirm__label,
.hold-confirm__label-done {
  grid-area: 1 / 1;
  white-space: nowrap;
  transition:
    opacity 0.28s ease,
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.hold-confirm__label-done {
  opacity: 0;
  transform: translateY(6px);
}

/* --- État confirmé ------------------------------------------------------------ */

.hold-confirm--confirmed {
  background: var(--hold-confirm-danger);
  border-color: var(--hold-confirm-danger);
  color: var(--ml-bg, #0d1017);
  box-shadow: 0 10px 30px -10px color-mix(in srgb, var(--hold-confirm-danger) 65%, transparent);
}

.hold-confirm--confirmed .hold-confirm__track,
.hold-confirm--confirmed .hold-confirm__ring {
  stroke: color-mix(in srgb, var(--ml-bg, #0d1017) 55%, transparent);
}

.hold-confirm--confirmed .hold-confirm__check {
  opacity: 1;
  animation: hold-confirm-check 0.4s cubic-bezier(0.3, 1.2, 0.5, 1) 0.08s both;
}

@keyframes hold-confirm-check {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}

.hold-confirm--confirmed .hold-confirm__label {
  opacity: 0;
  transform: translateY(-6px);
}

.hold-confirm--confirmed .hold-confirm__label-done {
  opacity: 1;
  transform: translateY(0);
}

/* Onde de confirmation : anneau fantôme qui s'échappe du bouton. */
.hold-confirm::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 1.5px solid var(--hold-confirm-danger);
  opacity: 0;
  pointer-events: none;
}

.hold-confirm--confirmed::after {
  animation: hold-confirm-wave 0.7s cubic-bezier(0.16, 0.84, 0.44, 1) 0.05s;
}

@keyframes hold-confirm-wave {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.28, 1.75); opacity: 0; }
}

/* --- Wrapper de démo (galerie) ----------------------------------------------- */

.hold-confirm-demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}

.hold-confirm-hint {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  color: var(--ml-muted, #8b91a3);
}

/* --- Accessibilité ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .hold-confirm--holding {
    animation: none; /* pas de tremblement */
  }

  .hold-confirm--snap {
    animation: none;
  }

  .hold-confirm__ring {
    transition: stroke-dashoffset 0.2s ease-out;
  }

  .hold-confirm--confirmed::after {
    animation: none;
  }

  .hold-confirm--confirmed .hold-confirm__check {
    animation: none;
    stroke-dashoffset: 0;
  }
}
