/* ============================================================
   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: 1500px;
  --page-padding: clamp(16px, 2.5vw, 40px);
  --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;
  }
}

/* ---------- Mobile: full-width, edge-to-edge content ----------
   On phones the pages read cramped because section/container wrappers
   add side padding on top of every component's own padding. On small
   screens the layout shell goes edge-to-edge; components (cards,
   forms, text blocks) keep their own internal padding. */
@media (max-width: 768px) {
  :root {
    --page-padding: 0px;
    --section-padding: clamp(24px, 6vw, 40px);
  }

  /* Layout shells reach the screen corners — !needed to beat
     Tailwind px-* utilities on the same elements */
  .page,
  .container,
  .page-container,
  .section-container,
  [class*="-inner"],
  [class*="Inner"],
  [class*="wrapper"],
  [class*="Wrapper"] {
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0;
    margin-right: 0;
    max-width: none;
    width: 100%;
  }

  /* One consistent 1rem gutter comes from <main>; nested shells add none */
  main {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    margin-left: 0;
    margin-right: 0;
    max-width: none;
    width: 100%;
  }

  /* Generic page sections: flush horizontally, keep vertical rhythm */
  section:not([class*="hero"]):not([class*="nav"]) {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  /* Forms and form rows inside sections span full width */
  form,
  [class*="form"],
  [class*="Form"] {
    max-width: 100%;
  }
}

/* ---------- Global scroll behaviour ---------- */
/* Consistent, restrained motion — the professional standard.
   Components animate smoothly; no abrupt pops or jank. */
html {
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !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, links and buttons can never be ghost-dragged or
   accidentally text-selected during touch scroll */
img, a, button, [class*="btn"], svg {
  -webkit-user-drag: none;
  user-select: none;
}
img {
  -webkit-touch-callout: none; /* no long-press callout over imagery */
  pointer-events: auto;
}
/* Form fields keep full selection/drag for usability */
input, textarea, [contenteditable="true"] {
  user-select: auto;
  -webkit-user-drag: auto;
}

/* 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: 'Inter', 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;
  }
}

/* ═══ Standard centered content container ═══
   Content never touches the viewport edges on desktop: a 1280px
   column with fluid side padding. Section backgrounds stay full-width;
   only the inner shells are capped and centred. ═══ */
:root {
  --site-max: 1600px;
  --site-pad: clamp(1.25rem, 3vw, 3.5rem);
}
@media (min-width: 769px) {
  /* Structural shells (home/shop headers, sections, footers) run
     full width with fluid gutters — wide, not a centred strip */
  .site-header-container,
  .header-container,
  .footer-container,
  .footer-bottom,
  .branches-inner,
  .featured-head,
  main.max-w-\[1440px\] {
    max-width: none !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  /* Text/app pages stay capped for readability, just wider */
  .max-w-7xl,
  .pf-shell {
    max-width: var(--site-max) !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  .site-header-container,
  .header-container,
  .footer-container,
  .footer-bottom,
  .hero-inner,
  .branches-inner,
  .featured-head {
    padding-left: var(--site-pad) !important;
    padding-right: var(--site-pad) !important;
  }
  .category-section {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
  /* Category strip + hero sit centred on wide screens — content stays
     in a standard column instead of running to the corners */
  .category-header,
  .category-scroll,
  .hero-inner {
    max-width: min(1400px, 92vw);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--site-pad) !important;
    padding-right: var(--site-pad) !important;
  }
  .category-scroll { scroll-padding-inline: var(--site-pad); }
}

/* ═══ One-row header on desktop & tablet ═══
   Logo left, search flexes to fill, actions right — items never
   wrap to a second line at any width. Medium, standard sizing. */
@media (min-width: 741px) {
  .site-header-container {
    flex-wrap: nowrap !important;
    /* nav group sits centred in the bar — not packed to the left */
    justify-content: center !important;
    gap: 1.25rem !important;
    padding-left: clamp(1.5rem, 4vw, 5rem) !important;
    padding-right: clamp(1.5rem, 4vw, 5rem) !important;
  }
  .site-header .logo { margin-left: 0 !important; margin-right: 0 !important; }
  .site-header .logo-img { height: 44px; }
  .site-header .search-wrapper {
    flex: 0 1 680px !important;
    min-width: 140px !important;
    max-width: 680px;
    margin: 0 !important;
  }
  .site-header .back-btn { margin-right: 0 !important; }
  .site-header .search-form input.search-input {
    font-size: 0.95rem !important;
  }
  .site-header .signin-btn { font-size: 0.88rem; }
  .site-header .cart-btn { font-size: 1.55rem; }
  .site-header .auth-wrap { margin-right: 0 !important; }
}
/* Tablet / narrow laptop: icon-only sign-in so the row always fits */
@media (min-width: 741px) and (max-width: 1080px) {
  .site-header .signin-btn { padding: 0.3rem; }
  .site-header .signin-btn #authBtnText,
  .site-header .signin-btn .signin-arrow { display: none; }
}

/* Fixed top bars (about, cart, prescription…) — centred bar so the
   back button/logo and page title sit toward the middle, not the edges */
@media (min-width: 769px) {
  div.fixed.top-0.z-\[100\] > .justify-between {
    max-width: 1100px !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding-left: 1.5rem !important;
    padding-right: 1.5rem !important;
  }
}

/* ═══ Navigation visibility — bolder, higher-contrast controls ═══ */
.site-header .menu-btn,
.site-header .cart-btn,
.site-header .mobile-search-btn,
.site-header .signin-btn,
.site-header .header-nav a,
.site-header .nav-link,
.auth-dropdown .auth-dd-item,
.mobile-menu-links a,
.mobile-menu-links button,
.footer a,
.footer .footer-column h4 {
  font-weight: 700;
}

/* Solid-icon nav glyphs read stronger at a slightly deeper shade */
.site-header .menu-btn i,
.site-header .cart-btn i,
.site-header .mobile-search-btn i {
  color: #2b2b32;
}

/* ═══ Compact medium footer — smaller footprint, tighter text,
   applies to every page sharing .footer / .site-footer markup ═══ */
.footer,
.site-footer {
  padding: 1.6rem 1.25rem 1rem !important;
  font-size: 0.82rem !important;
}
.footer-container {
  gap: 1rem 0.9rem !important;
  justify-content: space-between !important;
}
.footer-column {
  flex: 0 0 140px !important;
  min-width: 130px !important;
}
.footer-column h4 {
  font-size: 0.72rem !important;
  margin-bottom: 0.55rem !important;
}
.footer-column li { margin-bottom: 0.38rem !important; }
.footer-column a { font-size: 0.8rem !important; }
.footer-bottom {
  margin-top: 1.2rem !important;
  padding-top: 0.85rem !important;
  font-size: 0.7rem !important;
  gap: 0.7rem !important;
}
.footer-bottom-links { gap: 1rem !important; }
.footer-bottom-links a { font-size: 0.7rem !important; }

@media (max-width: 740px) {
  .footer,
  .site-footer { padding: 1.25rem 1rem 0.85rem !important; }
  .footer-column {
    flex: 0 0 46% !important;
    min-width: 115px !important;
  }
  .footer-column h4 { font-size: 0.7rem !important; }
  .footer-column a { font-size: 0.76rem !important; }
}

/* Rotating footer category links fade in on each cycle */
ul[data-footer-categories] li.fc-rot {
  animation: fcRotIn 0.45s ease both;
}
@keyframes fcRotIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: none; }
}

/* ═══ Scroll & interaction polish — smooth, professional, no jank ═══ */

/* Page never rubber-bands sideways; inner strips never chain to the page */
html, body { overscroll-behavior-x: none; }

/* Every horizontal strip gets momentum + edge containment.
   IMPORTANT: only X is contained — a Y-contain on a strip that can't
   scroll vertically blocks page scroll when swiping starts on it. */
.category-scroll,
.branches-grid,
#mobileCategoryPills,
#categoryPills,
.fp-rail {
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  /* NOTE: no scroll-behavior:smooth — it makes native touch scroll laggy */
  /* vertical swipes scroll the page, horizontal swipes scroll the strip */
  touch-action: pan-x pan-y;
}

/* Inner vertical panels/dropdowns don't steal page scroll at their edges */
#sidebarCategories,
#sidebarFilters .filters-panel,
.auth-dropdown,
.mobile-menu,
.search-dropdown,
.search-modal-list,
.user-dropdown-menu {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Controls shouldn't flash-select text when a swipe starts on them */
button,
a.category-card,
.fp-card,
.product-card,
.category-chip,
.category-nav button,
.hero-btn {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ═══ Drag/swipe support for horizontal sections ═══ */
.ec-dragscroll {
  overflow-x: auto !important;
  scrollbar-width: none;
  -ms-overflow-style: none;
  cursor: grab;
}
.ec-dragscroll::-webkit-scrollbar { display: none; }
.ec-dragscroll.dragging {
  cursor: grabbing;
  scroll-snap-type: none; /* snap would fight mid-drag positions */
}
.hero-image-card {
  touch-action: pan-y;   /* vertical page scroll still works over the card */
  cursor: grab;
}

/* ═══ Final smoothness polish ═══ */

/* Anchor jumps land below the sticky header, not under it */
html { scroll-padding-top: 96px; }

/* Hero slideshow card — swiping must never select or ghost-drag */
.hero-image-card {
  -webkit-user-select: none;
  user-select: none;
}
.hero-image-card img { pointer-events: none; }

/* Scrollbars on interactive strips stay invisible + smooth on all browsers */
.ec-dragscroll { scrollbar-width: none; -ms-overflow-style: none; }
