/* ============================================================
   Express Care — Global UX layer
   Preloader, scroll progress, reveal-on-scroll, drag-to-scroll,
   back-to-top. Loaded on every page via expresscare-ux.js.
   ============================================================ */

/* ---------- Global responsive foundation ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Media can never break the layout */
img, video, svg, canvas {
  display: block;
  max-width: 100%;
}
img, video { height: auto; }

/* Form controls inherit typography — consistent sizing everywhere */
button, input, textarea, select {
  font: inherit;
  max-width: 100%;
}

/* Long text wraps instead of forcing the layout wider */
h1, h2, h3, h4, h5, h6, p {
  overflow-wrap: break-word;
}

/* ---------- Responsive design tokens & container system ----------
   DEVICE VIEWPORT → SAFE VIEWPORT → MAX CONTENT WIDTH → FLUID
   COMPONENTS. Use these tokens instead of fixed px/breakpoints. */
:root {
  --content-max: 1440px;
  --page-padding: clamp(16px, 4vw, 64px);
  --section-padding: clamp(40px, 7vw, 100px);
  --element-gap: clamp(12px, 2vw, 32px);
  --radius: clamp(10px, 1vw, 20px);
}

/* Page shell — never narrower than 320px, never overflows sideways */
.page {
  width: 100%;
  min-width: 320px;
  overflow-x: clip;
}

/* Content container — fluid margins, capped on wide/ultra-wide */
.container,
.page-container,
.section-container {
  width: min(calc(100% - (var(--page-padding) * 2)), var(--content-max));
  margin-inline: auto;
}

.section {
  width: 100%;
  padding-block: var(--section-padding);
}

/* Short landscape screens (phones rotated, etc.) — relax tall
   sections and overlays so content isn't clipped */
@media (max-height: 500px) and (orientation: landscape) {
  [class*="hero"], [class*="banner"] {
    min-height: auto !important;
    padding-block: 32px;
  }
  .bottom-sheet,
  .filters-panel,
  .search-modal,
  .mobile-menu,
  .auth-dropdown {
    max-height: 100dvh;
  }
}

/* ---------- Global scroll behaviour & jank fixes ---------- */
/* No animations/transitions anywhere — instant, stable UI with
   no visual dragging or jank on any page */
*, *::before, *::after {
  animation: none !important;
  transition: none !important;
}
html {
  scroll-behavior: auto !important;
}

/* Anchor targets clear the sticky headers (~70-90px) */
[id] {
  scroll-margin-top: 96px;
}

/* Kill horizontal page drag / rubber-banding without breaking
   position:sticky (overflow-x:clip does not create a scroll box) */
html, body {
  overflow-x: clip;
}
@supports not (overflow: clip) {
  html { overflow-x: hidden; }
}

/* ---------- Responsive safety baseline ---------- */
img, video {
  max-width: 100%;
  height: auto;
}

/* iOS Safari zooms the page when a focused input is under ~16px.
   Enforce 16px on touch devices and narrow viewports only —
   desktop styling is untouched. */
@media (pointer: coarse), (max-width: 768px) {
  input, textarea, select {
    font-size: 16px !important;
  }
}

/* ---------- Modern viewport & safe-area handling ---------- */
/* dvh tracks the real visible viewport (mobile URL-bar aware);
   unsupported browsers keep each page's 100vh fallback */
body {
  min-height: 100dvh;
}

/* iPhone notch / rounded-corner insets — 0 on devices without them */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Prevent intrinsic-width blowout: let grid/flex children shrink
   below their content size instead of forcing the layout wider */
[class*="grid"] > *,
[class~="flex"] > *,
.header-container > *,
.site-header-container > * {
  min-width: 0;
}

/* Product/nav elements keep their existing design but must never
   force the layout wider than the viewport */
.product-card,
.category-card,
.search-wrapper,
.search-form,
.auth-wrap {
  min-width: 0;
  max-width: 100%;
}

/* Footer — same shrink safety; long links/emails wrap cleanly */
.footer > *,
.site-footer > *,
.footer-container > *,
.footer-bottom > *,
.footer-column {
  min-width: 0;
}
.footer a,
.site-footer a,
.footer-column a {
  overflow-wrap: break-word;
}

/* ---------- No dragging — design stays put ---------- */
/* Images and links can never be ghost-dragged */
img, a {
  -webkit-user-drag: none;
  user-select: none;
}
img {
  -webkit-touch-callout: none; /* no long-press callout over imagery */
}

/* No rubber-band bounce past the page edges */
html {
  overscroll-behavior: none;
}

/* Snappier taps — kills the 300ms double-tap delay and the gray flash */
body {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Branded page preloader ---------- */
#ecPreloader {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background:
    radial-gradient(900px 600px at 110% -10%, rgba(31, 111, 174, 0.10), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, rgba(47, 164, 200, 0.08), transparent 55%),
    rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

#ecPreloader.ec-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#ecPreloader .ec-pl-logo {
  height: 72px;
  width: auto;
  object-fit: contain;
  animation: ecPlFloat 2.2s ease-in-out infinite;
}

#ecPreloader .ec-pl-name {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #1e3a5f;
}

#ecPreloader .ec-pl-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid rgba(31, 111, 174, 0.15);
  border-top-color: #1f6fae;
  animation: ecPlSpin 0.9s linear infinite;
}

#ecPreloader .ec-pl-bar {
  width: 160px;
  height: 3px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(31, 111, 174, 0.12);
  position: relative;
}

#ecPreloader .ec-pl-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: 3px;
  background: linear-gradient(90deg, #1f6fae, #2fa4c8);
  animation: ecPlSlide 1.1s ease-in-out infinite;
}

@keyframes ecPlSpin {
  to { transform: rotate(360deg); }
}

@keyframes ecPlSlide {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(420%); }
}

@keyframes ecPlFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

/* ---------- Top scroll / navigation progress bar ---------- */
#ecProgress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99998;
  width: 100%;
  height: 3px;
  pointer-events: none;
  transform-origin: 0 50%;
  transform: scaleX(0);
  background: linear-gradient(90deg, #1f6fae, #2fa4c8);
  box-shadow: 0 0 8px rgba(47, 164, 200, 0.55);
  opacity: 0;
  transition: opacity 0.25s ease;
}

#ecProgress.ec-active {
  opacity: 1;
}

/* Indeterminate state while navigating to another page */
#ecProgress.ec-nav {
  transform: none;
  animation: ecNavBar 1s ease-in-out infinite;
}

@keyframes ecNavBar {
  0%   { transform: translateX(-100%) scaleX(0.4); }
  50%  { transform: translateX(30%)  scaleX(0.4); }
  100% { transform: translateX(100%) scaleX(0.4); }
}

/* ---------- Reveal on scroll ---------- */
[data-ec-reveal] {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 0.65s cubic-bezier(0.22, 0.61, 0.36, 1),
              transform 0.65s cubic-bezier(0.22, 0.61, 0.36, 1);
}

[data-ec-reveal].ec-in {
  opacity: 1;
  transform: none;
}

/* ---------- Back to top ---------- */
#ecTop {
  position: fixed;
  right: max(22px, env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 9990;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #1f6fae, #2fa4c8);
  box-shadow: 0 6px 18px rgba(31, 111, 174, 0.35);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.3s ease, transform 0.3s ease,
              visibility 0.3s ease, box-shadow 0.2s ease;
}

#ecTop.ec-show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

#ecTop:hover {
  box-shadow: 0 8px 24px rgba(31, 111, 174, 0.5);
  transform: translateY(-2px);
}

#ecTop svg {
  width: 20px;
  height: 20px;
}



/* ---------- Lazy image fade-in ---------- */
img.ec-fade {
  opacity: 0;
  transition: opacity 0.5s ease;
}

img.ec-fade.ec-loaded {
  opacity: 1;
}

/* ---------- Header elevation once scrolled ---------- */
.header.ec-scrolled,
.site-header.ec-scrolled,
header.ec-scrolled {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  #ecPreloader .ec-pl-logo,
  #ecPreloader .ec-pl-ring,
  #ecPreloader .ec-pl-bar::after,
  #ecProgress.ec-nav {
    animation: none !important;
  }

  [data-ec-reveal] {
    opacity: 1;
    transform: none;
    transition: none;
  }

  #ecTop, img.ec-fade {
    transition: none;
  }
}
