/* Screen changes and tap feedback on phones (the Android and iPhone apps, and the web app at
   phone width), with js/vo-motion.js. Short (about 200 ms), and nothing moves when the system
   asks for reduced motion. Desktop widths only get the delayed loaders at the end. */

/* ---------- Screen to screen (View Transitions, set up by vo-motion.js) ---------- */

@keyframes vo-vt-fade-out { to { opacity: 0; } }
@keyframes vo-vt-fade-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes vo-vt-out-left { to { opacity: 0; transform: translateX(-18%); } }
@keyframes vo-vt-in-right { from { opacity: 0; transform: translateX(28%); } }
@keyframes vo-vt-out-right { to { opacity: 0; transform: translateX(28%); } }
@keyframes vo-vt-in-left { from { opacity: 0; transform: translateX(-18%); } }

@media (prefers-reduced-motion: no-preference) {
  html.vo-vt::view-transition-old(root),
  html.vo-vt::view-transition-new(root) {
    animation-duration: 210ms;
    animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
    animation-fill-mode: both;
  }
  /* Between tabs: the new screen replaces the old one in a single frame, like a native tab bar.
     (A crossfade made both screens half see-through for a moment, which read as a blink now that
     screens open with their saved data already in place.) The transition still holds the old
     screen until the new one has rendered, so nothing half-built shows. */
  html.vo-vt-fade::view-transition-old(root),
  html.vo-vt-fade::view-transition-new(root) { animation: none; }
  /* Into a screen: it slides in from the right over the one it came from. */
  html.vo-vt-fwd::view-transition-old(root) { animation-name: vo-vt-out-left; }
  html.vo-vt-fwd::view-transition-new(root) { animation-name: vo-vt-in-right; }
  /* Back: the reverse. */
  html.vo-vt-back::view-transition-old(root) { animation-name: vo-vt-out-right; }
  html.vo-vt-back::view-transition-new(root) { animation-name: vo-vt-in-left; }

  /* The bottom tab bar stays put while the screen above it changes. */
  html.vo-vt::view-transition-group(vo-tabs) { animation: none; z-index: 2; }
  html.vo-vt::view-transition-old(vo-tabs) { animation: none; opacity: 0; }
  html.vo-vt::view-transition-new(vo-tabs) { animation: none; }
}

@media (prefers-reduced-motion: reduce) {
  html.vo-vt::view-transition-group(*),
  html.vo-vt::view-transition-old(*),
  html.vo-vt::view-transition-new(*) { animation: none !important; }
}

/* ---------- Without View Transitions ---------- */
/* The new screen just replaces the old one: no fade, which flashed a screen that was already
   drawn from its saved copy. */

/* ---------- Panes that switch inside a screen ---------- */
/* Animated by vo-motion.js, only at the moment a pane actually switches (Office/Chat tabs, an
   Inbox conversation and its list, the office Chat tab's list and conversation). CSS animations
   here used to play whenever a screen appeared, and again when the screen change ended: the
   office flashed blank for a frame right after it had loaded. */

/* ---------- Tap feedback ---------- */

html { -webkit-tap-highlight-color: transparent; }
/* No double-tap-to-zoom wait on taps. */
:is(a, button, [role="button"], [role="menuitem"], [role="tab"], label, summary, input, select, textarea) {
  touch-action: manipulation;
}

@media (hover: none) and (pointer: coarse) {
  /* Pressed buttons shrink a little the moment a finger lands, and spring back on release.
     scale (not transform) so buttons that are already moved or rotated stay where they are. */
  :is(button, [role="button"], .btn):not(:disabled):not(.vo-ain-row, .vo-ain-mrow, [role="menuitem"], .vo-mobile-more > *, .vo-mobile-nav > *) {
    transition: scale 140ms ease-out, background-color 120ms, color 120ms;
  }
  :is(button, [role="button"], .btn):not(:disabled):not(.vo-ain-row, .vo-ain-mrow, [role="menuitem"], .vo-mobile-more > *, .vo-mobile-nav > *):active {
    scale: 0.95;
    transition-duration: 0s;
  }
  /* Tab bar: the icon and label dip; the tab itself lights up on the tap (vo-motion.js). */
  .vo-mobile-nav > :is(a, button) > :is(svg, span) { transition: scale 140ms ease-out; }
  .vo-mobile-nav > :is(a, button):active > :is(svg, span) { scale: 0.9; transition-duration: 0s; }
  /* Rows and menu items: a highlight like a native list. */
  :is(.vo-ain-row, .vo-ain-mrow, .vo-mobile-more > *, [role="menuitem"], .vo-search-row, .vo-act-row):active {
    background-color: var(--vo-accent-soft, rgba(0, 85, 251, 0.1));
    transition-duration: 0s;
  }
  a:not(.btn):not([role]):active { opacity: 0.7; transition: opacity 0s; }
  .vo-mobile-nav > a:active { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  :is(button, [role="button"], .btn):active,
  .vo-mobile-nav > :is(a, button):active > :is(svg, span) { scale: 1 !important; }
}

/* ---------- Loaders ---------- */
/* A screen whose data arrives quickly no longer flashes "Loading…" for a split second: the
   loader only shows when loading takes longer than a quarter of a second. */

@keyframes vo-loader-late { from { opacity: 0; } to { opacity: 1; } }

.vo-loader.vo-loader--page,
.vo-loader.vo-ain-loading {
  animation: vo-loader-late 160ms ease-out 250ms both;
}

/* ---------- Pull to refresh (PullToRefresh.razor, phone apps only) ---------- */

.vo-ptr { display: none; }
html.vo-app .vo-ptr {
  display: grid;
  place-items: center;
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) - 44px);
  z-index: 60;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  border-radius: 50%;
  background: var(--vo-bg-elev, #1e293b);
  color: var(--vo-muted, #94a3b8);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(var(--vo-ptr-y, 0px));
}
html.vo-app .vo-ptr.is-on { opacity: 1; }
html.vo-app .vo-ptr.is-settling { transition: transform 200ms ease-out, opacity 200ms ease-out; }
html.vo-app .vo-ptr.is-ready,
html.vo-app .vo-ptr.is-spinning { color: var(--vo-accent, #6366f1); }
html.vo-app .vo-ptr__icon { width: 20px; height: 20px; transform: rotate(var(--vo-ptr-turn, 0deg)); }
html.vo-app .vo-ptr.is-spinning .vo-ptr__icon { animation: vo-ptr-spin 700ms linear infinite; }
@keyframes vo-ptr-spin { to { transform: rotate(360deg); } }
