/* ==========================================================================
   Pull to refresh — pull down at the top of a list to load what's new.

   <main data-moey-refresh>…the list…</main>                (the page scrolls)
   <div class="overflow-y-auto h-96" data-moey-refresh>…</div> (a panel that scrolls itself)

   list.addEventListener('moey:refresh', (e) => e.detail.waitUntil(loadNewItems()));

   Touch screens only (the mouse has nothing to pull — give desktops a refresh button that calls
   Moey.refresh(el)). The phone's own pull-to-reload is switched off where this is used.
   ========================================================================== */

[data-moey-refresh] {
  --mo-refresh-pull: 0px;
  position: relative;
  overscroll-behavior-y: contain;            /* no browser reload / bounce fighting the pull */
}
html:has(body[data-moey-refresh], body > [data-moey-refresh], body > .app [data-moey-refresh]) { overscroll-behavior-y: contain; }
[data-moey-refresh] > :not(.refresh-indicator) { translate: 0 var(--mo-refresh-pull); }
[data-moey-refresh]:not(.is-pulling) > :not(.refresh-indicator) { transition: translate .3s cubic-bezier(.2, 0, 0, 1); }

.refresh-indicator {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  margin-left: -1.25rem;
  color: var(--mo-fg-2);
  pointer-events: none;
  background: var(--mo-bg-raised);
  border-radius: 999px;
  box-shadow: var(--mo-shadow-overlay);
  opacity: 0;
  translate: 0 calc(var(--mo-refresh-pull) - 3rem);
}
[data-moey-refresh]:not(.is-pulling) > .refresh-indicator { transition: translate .3s cubic-bezier(.2, 0, 0, 1), opacity .2s; }
[data-moey-refresh]:is(.is-pulling, .is-refreshing) > .refresh-indicator { opacity: 1; }
.refresh-indicator > .refresh-arrow {
  width: 1.125rem;
  height: 1.125rem;
  background: currentcolor;
  mask: var(--mo-icon-chevron) center / contain no-repeat;
  rotate: calc(var(--mo-refresh-turn, 0) * 180deg);
}
[data-moey-refresh].is-ready > .refresh-indicator { color: var(--mo-default-base); }
.refresh-indicator > .spinner { display: none; width: 1.25rem; height: 1.25rem; }
[data-moey-refresh].is-refreshing > .refresh-indicator > .spinner { display: inline-block; }
[data-moey-refresh].is-refreshing > .refresh-indicator > .refresh-arrow { display: none; }
@media (prefers-reduced-motion: reduce) {
  [data-moey-refresh] > *, [data-moey-refresh] > .refresh-indicator { transition: none !important; }
}
