/* 064 — Pull to Refresh
   Liste scrollable avec tirage élastique. La liste est translatée par anim.js
   (transition coupée pendant le drag, spring de la classe au relâcher) ; le
   gap révélé en haut découvre l'indicateur, dont l'opacité/échelle sont
   pilotées par --pr-progress (custom property posée par le JS) et dont l'arc
   SVG se remplit via stroke-dashoffset. Seuil atteint : la flèche pivote et
   l'arc passe en accent-2 (.is-armed) ; pendant le refresh, l'anneau tourne
   (.is-loading) ; le nouvel item entre avec le keyframe pull-refresh-in. */

.pull-refresh {
  width: 300px;
  max-width: 100%;
  font-size: 12px;
}

.pull-refresh__bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 2px 6px;
}

.pull-refresh__title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ml-fg, #e8eaf2);
}

.pull-refresh__count {
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--ml-muted, #8b91a3);
}

/* — Zone : cadre qui contient l'indicateur + le viewport scrollable — */
.pull-refresh__zone {
  position: relative;
  height: 152px;
  border: 1px solid rgba(139, 145, 163, 0.16);
  border-radius: 14px;
  background: var(--ml-bg, #0d1017);
  overflow: hidden;
}

/* — Indicateur : révélé par le gap, piloté par --pr-progress (0→1) — */
.pull-refresh__indicator {
  --pr-progress: 0;
  position: absolute;
  top: 9px;
  left: calc(50% - 15px);
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  color: var(--ml-muted, #8b91a3);
  opacity: var(--pr-progress);
  transform: scale(calc(0.65 + 0.35 * var(--pr-progress)));
  transition:
    opacity 0.25s ease,
    transform 0.3s cubic-bezier(0.3, 1.3, 0.4, 1),
    color 0.2s ease;
}

/* pendant le drag, les valeurs inline arrivent à chaque frame : pas de lag */
.pull-refresh.is-pulling .pull-refresh__indicator {
  transition: color 0.2s ease;
}

.pull-refresh__ring {
  grid-area: 1 / 1;
  width: 30px;
  height: 30px;
}

.pull-refresh__track {
  fill: none;
  stroke: rgba(139, 145, 163, 0.22);
  stroke-width: 2.5;
}

/* Arc de progression : dasharray = circonférence (r=12 → 75.4),
   dashoffset posé en inline par anim.js */
.pull-refresh__arc {
  fill: none;
  stroke: var(--ml-accent, #7c8cff);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 75.4;
  stroke-dashoffset: 75.4;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 0.25s ease, stroke 0.2s ease, opacity 0.15s ease;
}

.pull-refresh.is-pulling .pull-refresh__arc {
  transition: stroke 0.2s ease;
}

.pull-refresh__indicator.is-armed .pull-refresh__arc {
  stroke: var(--ml-accent-2, #2dd4bf);
}

/* Flèche centrale : pivote à 180° quand le seuil est armé */
.pull-refresh__arrow {
  grid-area: 1 / 1;
  width: 11px;
  height: 11px;
  justify-self: center;
  align-self: center;
  transition: transform 0.3s cubic-bezier(0.3, 1.4, 0.4, 1), opacity 0.15s ease;
}

.pull-refresh__indicator.is-armed {
  color: var(--ml-accent-2, #2dd4bf);
}

.pull-refresh__indicator.is-armed .pull-refresh__arrow {
  transform: rotate(180deg);
}

/* Refresh en cours : flèche et arc laissent place à l'anneau qui tourne */
.pull-refresh__spin {
  fill: none;
  stroke: var(--ml-accent, #7c8cff);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 26 49.4;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.pull-refresh__indicator.is-loading {
  opacity: 1;
  transform: scale(1);
}

.pull-refresh__indicator.is-loading .pull-refresh__arrow,
.pull-refresh__indicator.is-loading .pull-refresh__arc {
  opacity: 0;
}

.pull-refresh__indicator.is-loading .pull-refresh__spin {
  opacity: 1;
}

.pull-refresh__indicator.is-loading .pull-refresh__ring {
  animation: pull-refresh-spin 0.8s linear infinite;
}

@keyframes pull-refresh-spin {
  to { transform: rotate(360deg); }
}

/* — Viewport scrollable : le pull ne s'arme que si scrollTop = 0 — */
.pull-refresh__viewport {
  position: relative; /* peint au-dessus de l'indicateur (ordre DOM) */
  height: 100%;
  overflow-y: auto;
  touch-action: pan-y;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.pull-refresh__viewport::-webkit-scrollbar {
  display: none;
}

/* La liste porte le spring de retour ; transition coupée en inline
   pendant le drag */
.pull-refresh__list {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  will-change: transform;
  transition: transform 0.5s cubic-bezier(0.24, 1.3, 0.4, 1);
}

.pull-refresh__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--ml-surface, #151a24);
  border: 1px solid rgba(139, 145, 163, 0.14);
  border-radius: 10px;
  user-select: none;
  -webkit-user-select: none;
}

/* Entrée eep-style du nouvel item (fondu + montée + léger scale) */
.pull-refresh__item--new {
  animation: pull-refresh-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) 0.05s both;
}

@keyframes pull-refresh-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.96);
  }
}

.pull-refresh__chip {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #8a92a6, #565d6e);
}

.pull-refresh__chip--oak { background: linear-gradient(135deg, #a06a3c, #5b3a20); }
.pull-refresh__chip--steel { background: linear-gradient(135deg, #9aa4b5, #5c6675); }
.pull-refresh__chip--terra { background: linear-gradient(135deg, #c9825e, #8c4b34); }
.pull-refresh__chip--leather { background: linear-gradient(135deg, #a4633c, #6e3d22); }
.pull-refresh__chip--felt { background: linear-gradient(135deg, #78808f, #464c58); }
.pull-refresh__chip--ceramic { background: linear-gradient(135deg, #d9d5cd, #a09c94); }
.pull-refresh__chip--walnut { background: linear-gradient(135deg, #6e4a30, #3a2417); }
.pull-refresh__chip--brass { background: linear-gradient(135deg, #c9a24a, #8a6a26); }
.pull-refresh__chip--linen { background: linear-gradient(135deg, #cfc7b4, #a29a86); }
.pull-refresh__chip--concrete { background: linear-gradient(135deg, #9599a2, #63666e); }

.pull-refresh__txt {
  flex: 1;
  min-width: 0;
}

.pull-refresh__name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ml-fg, #e8eaf2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pull-refresh__meta {
  display: block;
  font-size: 10px;
  color: var(--ml-muted, #8b91a3);
}

.pull-refresh__hint {
  margin-top: 8px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ml-muted, #8b91a3);
  opacity: 0.75;
  text-align: center;
}

/* — Région live pour lecteurs d'écran — */
.pull-refresh__live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* — Reduced motion : retour court sans spring, pas de spin ni d'entrée
   animée — le pull et le refresh restent fonctionnels — */
@media (prefers-reduced-motion: reduce) {
  .pull-refresh__list {
    transition: transform 0.15s ease;
  }

  .pull-refresh__indicator,
  .pull-refresh__arc,
  .pull-refresh__arrow {
    transition: none;
  }

  .pull-refresh__indicator.is-loading .pull-refresh__ring {
    animation: none;
  }

  /* arc complet statique pendant le chargement, à la place du spinner */
  .pull-refresh__indicator.is-loading .pull-refresh__arc {
    opacity: 1;
    stroke-dashoffset: 0;
  }

  .pull-refresh__indicator.is-loading .pull-refresh__spin {
    opacity: 0;
  }

  .pull-refresh__item--new {
    animation: none;
  }
}
