/**
 * FreeCreditHub — global Back to Top floating button
 * Loaded site-wide via mu-plugin. Does not alter layout of other components.
 */

.fch-back-to-top {
  --fch-btt-size: 44px;
  --fch-btt-right: 20px;
  /* Sit above fixed .bottom-app-nav (54 + 18) with ~24px clearance on desktop */
  --fch-btt-bottom: calc(54px + 18px + 24px + env(safe-area-inset-bottom, 0px));

  position: fixed;
  right: calc(var(--fch-btt-right) + env(safe-area-inset-right, 0px));
  bottom: var(--fch-btt-bottom);
  z-index: 65;
  box-sizing: border-box;
  display: inline-grid;
  place-items: center;
  width: var(--fch-btt-size);
  height: var(--fch-btt-size);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #ffffff;
  background: linear-gradient(145deg, #4f7cf5 0%, #2852cc 100%);
  box-shadow:
    0 10px 22px rgba(40, 82, 204, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(10px) scale(0.96);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    visibility 0.22s ease,
    box-shadow 0.18s ease,
    filter 0.18s ease;
}

.fch-back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.fch-back-to-top:hover {
  filter: brightness(1.05);
  box-shadow:
    0 14px 28px rgba(40, 82, 204, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
  transform: translateY(-2px) scale(1);
}

.fch-back-to-top:active {
  filter: brightness(0.98);
  transform: translateY(0) scale(0.98);
}

.fch-back-to-top:focus {
  outline: none;
}

.fch-back-to-top:focus-visible {
  outline: 2px solid #2852cc;
  outline-offset: 3px;
}

.fch-back-to-top__icon {
  display: block;
  width: 20px;
  height: 20px;
  pointer-events: none;
}

/* Fallback when a page has no bottom app nav */
body:not(:has(.bottom-app-nav)) .fch-back-to-top {
  --fch-btt-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 900px) {
  .fch-back-to-top {
    --fch-btt-size: 40px;
    --fch-btt-right: 12px;
    /* ~14px clearance above bottom nav on mobile */
    --fch-btt-bottom: calc(54px + 18px + 14px + env(safe-area-inset-bottom, 0px));
  }

  .fch-back-to-top__icon {
    width: 18px;
    height: 18px;
  }

  body:not(:has(.bottom-app-nav)) .fch-back-to-top {
    --fch-btt-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .fch-back-to-top {
    transition: opacity 0.01ms linear, visibility 0.01ms linear;
    transform: none;
  }

  .fch-back-to-top.is-visible,
  .fch-back-to-top:hover,
  .fch-back-to-top:active {
    transform: none;
  }
}
