/* ================================================================
   Resayil — Lenis portal smooth scroll integration (Phase 24.12-10)
   ----------------------------------------------------------------
   Assumes rs-motion.js has already started a Lenis instance on
   portal pages (Phase 24.11 Plan 01). CSS here disables conflicting
   native smooth-scroll + provides an escape hatch for nested
   scroll containers (modals, popovers, dropdowns, autocompletes).

   Desk (body.desk, body[data-route], /app/*) is intentionally
   unaffected — those :not() selectors keep Frappe's native scroll
   behaviour intact.
   ================================================================ */

/* ----- Kill native smooth-scroll on portal --------------------- */
/* Lenis owns vertical scrolling on the portal. The CSS-level
   `scroll-behavior: smooth` that some themes inject would cause
   visible double-easing / stutter when combined with Lenis. Force
   `auto` here (Lenis does the actual smoothing via RAF). */
html:not(.desk),
body:not(.desk):not([data-route]) {
  scroll-behavior: auto;
}

/* ----- Escape hatches for nested scroll containers ------------- */
/* Any element tagged with `data-lenis-prevent` is a scroll region
   Lenis should not own — modals, drawers, long dropdowns, code
   editors, etc. We leave native scroll intact and just clamp the
   overscroll chain so the parent Lenis surface does not also react
   to wheel events that bubble out of the container. */
[data-lenis-prevent] {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* A softer variant — only prevents wheel events from reaching
   Lenis (popover menus, autocompletes). Touch scroll is still
   inherited from the parent. */
[data-lenis-prevent-wheel] {
  overscroll-behavior-y: contain;
}

/* ----- iOS Safari / touch devices ------------------------------ */
/* Lenis feels good on desktop but on touch devices native momentum
   scroll is smoother and better-integrated with the OS (rubber-band,
   address-bar hide, etc.). rs-motion.js already detects reduced
   motion and skips Lenis at OS level; this is belt-and-braces at
   the CSS layer so even if Lenis did start, iOS keeps momentum. */
@media (pointer: coarse) {
  html {
    -webkit-overflow-scrolling: auto;
  }
}

/* ----- Reduced motion safety net ------------------------------- */
/* rs-motion.js already refuses to instantiate Lenis when
   prefers-reduced-motion is set. This block is redundant but cheap:
   it guarantees native scroll behaviour even if someone flips the
   accessibility setting mid-session and Lenis is torn down. */
@media (prefers-reduced-motion: reduce) {
  html,
  html:not(.desk),
  body:not(.desk):not([data-route]) {
    scroll-behavior: auto !important;
  }
}
