/*
 * Global "Back to Top" button — shared by the legacy admin and every storefront theme.
 *
 * Themes/pages must NOT copy this file. Customise only through CSS variables:
 *   --back-to-top-background, --back-to-top-color, --back-to-top-right,
 *   --back-to-top-bottom, --back-to-top-z-index, --back-to-top-focus-ring
 *
 * --back-to-top-lift is written by back-to-top.js at runtime to keep the button
 * above floating elements (chat, LINE/WhatsApp bar, sticky pagination ...).
 */
.global-back-to-top {
  --back-to-top-size: 48px;

  position: fixed;
  right: var(--back-to-top-right, 24px);
  bottom: calc(
    var(--back-to-top-bottom, 24px) +
    env(safe-area-inset-bottom, 0px) +
    var(--back-to-top-lift, 0px)
  );
  z-index: var(--back-to-top-z-index, 1040);

  box-sizing: border-box;
  width: var(--back-to-top-size);
  height: var(--back-to-top-size);
  min-width: var(--back-to-top-size);
  min-height: var(--back-to-top-size);
  max-width: var(--back-to-top-size);
  max-height: var(--back-to-top-size);
  margin: 0;
  padding: 0;
  aspect-ratio: 1 / 1;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  border: 0;
  border-radius: 50%;
  background: var(--back-to-top-background, #007bff);
  color: var(--back-to-top-color, #fff);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  font-size: 0;
  line-height: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    filter 0.2s ease;
}

.global-back-to-top[hidden] {
  display: none !important;
}

.global-back-to-top svg {
  display: block;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  pointer-events: none;
}

.global-back-to-top:hover {
  filter: brightness(0.9);
  transform: translateY(-2px);
}

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

.global-back-to-top:focus-visible {
  outline: 3px solid var(--back-to-top-focus-ring, rgba(0, 123, 255, 0.35));
  outline-offset: 3px;
}

/* Never float above an open Bootstrap modal / SweetAlert dialog. */
body.modal-open .global-back-to-top,
body.swal2-shown .global-back-to-top {
  visibility: hidden;
}

/*
 * Mobile uses its own variables so a theme's :root overrides still win
 * (declaring --back-to-top-right on the element itself would shadow :root).
 */
@media (max-width: 767px) {
  .global-back-to-top {
    --back-to-top-size: 44px;
    right: var(--back-to-top-right-mobile, 16px);
    bottom: calc(
      var(--back-to-top-bottom-mobile, 16px) +
      env(safe-area-inset-bottom, 0px) +
      var(--back-to-top-lift, 0px)
    );
  }
}

@media print {
  .global-back-to-top {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .global-back-to-top {
    transition: none;
  }

  .global-back-to-top:hover {
    transform: none;
  }
}
