/* Pull-to-refresh indicator (touch devices only).
   Driven by controllers/pull_to_refresh_controller.js — it sets --ptr-distance
   and toggles the is-visible / is-ready / is-spinning classes. */

.pull-to-refresh {
  --ptr-distance: 0px;

  position: fixed;
  top: 0;
  left: 50%;
  z-index: 2000;

  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;

  /* Ride the pull down from just above the viewport. */
  transform: translate(-50%, calc(var(--ptr-distance) - 44px));

  color: var(--bs-body-color);
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.2);

  opacity: 0;
  pointer-events: none;
}

.pull-to-refresh.is-visible {
  opacity: 1;
}

/* Snap back / ease into the spin position only when not actively dragging. */
.pull-to-refresh:not(.is-visible),
.pull-to-refresh.is-spinning {
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.pull-to-refresh__spinner {
  display: flex;
  font-size: 1.25rem;
  line-height: 1;

  /* Rotate the arrow proportionally to how far it's been pulled. */
  transform: rotate(calc(var(--ptr-distance) * 3deg));
  transition: color 0.15s ease;
}

/* Passed the threshold — signal that releasing will refresh. */
.pull-to-refresh.is-ready {
  color: var(--bs-primary, var(--bs-body-color));
  border-color: var(--bs-primary, var(--bs-border-color));
}

/* Refreshing — spin continuously until the page navigates. */
.pull-to-refresh.is-spinning .pull-to-refresh__spinner {
  animation: pull-to-refresh-spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .pull-to-refresh.is-spinning .pull-to-refresh__spinner {
    animation-duration: 1.4s;
  }
}
