/**
 * Shopinger — mobile-first app chrome & responsive foundation
 * Loaded last. Tokens + critical phone overrides.
 */

:root {
  --sg-bp-app: 980px;
  --sg-header-h: 58px;
  --sg-header-h-mobile: 52px;
  --sg-tabbar-h: 64px;
  --sg-tabbar-inset: 0.55rem;
  --sg-tabbar-side: 0.7rem;
  --sg-touch: 44px;
  --sg-chrome-top: calc(var(--sg-header-h-mobile) + env(safe-area-inset-top, 0px));
  --sg-chrome-bottom: calc(
    var(--sg-tabbar-h) + var(--sg-tabbar-inset) + env(safe-area-inset-bottom, 0px)
  );
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: clip;
}
body.shopinger-theme {
  overflow-x: clip;
  min-width: 0;
}

/* Full-bleed without 100vw scrollbar bugs */
.sg-parallax {
  width: 100% !important;
  max-width: 100% !important;
  margin-inline: 0 !important;
}
.elementor-section:has(.sg-parallax),
.e-con:has(.sg-parallax),
.elementor-widget:has(.sg-parallax) {
  overflow: hidden;
}

/* —— App shell ≤980 —— */
@media (max-width: 980px) {
  :root {
    --sg-header-h: var(--sg-header-h-mobile);
  }

  body.shopinger-theme {
    padding-bottom: var(--sg-chrome-bottom) !important;
  }
  body.shopinger-theme:not(.home) {
    padding-top: var(--sg-chrome-top) !important;
  }

  .sg-header__shell {
    padding-top: env(safe-area-inset-top, 0px);
  }
  .sg-header__bar {
    min-height: var(--sg-header-h-mobile);
  }
  .sg-header__icon,
  .sg-header__icon[data-sg-search-open] {
    width: var(--sg-touch) !important;
    height: var(--sg-touch) !important;
    min-width: var(--sg-touch);
    min-height: var(--sg-touch);
  }

  .sg-tabbar {
    display: grid !important;
    inset-inline: var(--sg-tabbar-side);
    bottom: calc(var(--sg-tabbar-inset) + env(safe-area-inset-bottom, 0px));
    z-index: 240;
  }
  .sg-tabbar__item {
    min-height: var(--sg-touch);
  }

  /* Flow pages: sticky CTA owns bottom — hide tabbar */
  body.single-product .sg-tabbar,
  body.woocommerce-cart .sg-tabbar,
  body.woocommerce-checkout .sg-tabbar,
  body.woocommerce-order-received .sg-tabbar {
    display: none !important;
  }
  body.single-product.shopinger-theme,
  body.woocommerce-cart.shopinger-theme,
  body.woocommerce-checkout.shopinger-theme,
  body.woocommerce-order-received.shopinger-theme {
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Sticky / toast sit above chrome when tabbar visible */
  .sg-toast,
  .woocommerce-store-notice {
    bottom: calc(var(--sg-chrome-bottom) + 0.5rem) !important;
  }

  /* Shop filter — full-screen app sheet */
  .sg-shop-filter-backdrop {
    z-index: 270 !important;
  }
  .sg-shop__layout {
    grid-template-columns: 1fr !important;
  }
  .sg-shop__sidebar {
    position: fixed !important;
    inset: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: none !important;
    height: 100dvh !important;
    z-index: 280 !important;
    transform: translate3d(0, 105%, 0) !important;
    visibility: hidden !important;
    pointer-events: none !important;
    padding: 0 !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  }
  body.sg-filters-open .sg-shop__sidebar {
    transform: translate3d(0, 0, 0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }
  body.sg-filters-open .sg-tabbar {
    display: none !important;
  }

  /* Home cats: 4-col RTL grid, no overflow rail */
  .sg-cats {
    background: #fff;
    position: relative;
    z-index: 1;
  }
  .sg-cats__rail {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    direction: rtl !important;
    justify-items: center !important;
    overflow: visible !important;
    scroll-snap-type: none !important;
    margin-inline: 0 !important;
  }
  .sg-cats__rail > * {
    scroll-snap-align: unset;
    min-width: 0 !important;
    max-width: none !important;
    width: 100% !important;
  }

  /* Kill Elementor flex-shrink overflow stacking on phone */
  .e-con.e-parent {
    height: auto !important;
    overflow: visible !important;
  }
  .e-con > .elementor-widget {
    height: auto !important;
    flex: 0 0 auto !important;
    overflow: visible !important;
  }
  .e-con > .elementor-widget > .elementor-widget-container {
    height: auto !important;
    overflow: visible !important;
  }

  /* Promo / features denser phone layout */
  .sg-promos {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }
  .sg-promo {
    grid-template-columns: 1fr !important;
  }
  .sg-features {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.65rem !important;
  }

  /* Footer breathing room above tabbar */
  .sg-footer {
    padding-bottom: 0.5rem;
  }
  .sg-footer__legal {
    flex-wrap: wrap;
    gap: 0.35rem 0.85rem;
    justify-content: center;
  }
}

@media (min-width: 981px) {
  .sg-tabbar {
    display: none !important;
  }
}

/* —— Narrow phone ≤720 —— */
@media (max-width: 720px) {
  .sg-shop__cats {
    padding: 0.85rem 0 1rem;
  }
  .sg-shop__cats-row {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 0.75rem !important;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding-inline: var(--sg-space, 1rem);
    margin-inline: calc(-1 * var(--sg-space, 1rem));
    padding-bottom: 0.35rem;
    scrollbar-width: none;
  }
  .sg-shop__cats-row::-webkit-scrollbar {
    display: none;
  }
  .sg-shop-cat {
    flex: 0 0 auto;
    width: 76px;
    max-width: 76px;
    scroll-snap-align: start;
  }
  .sg-shop-cat__title {
    font-size: 0.68rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .sg-features {
    grid-template-columns: 1fr !important;
  }

  body.sg-page-checkout .sg-checkout,
  .sg-checkout {
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Info pages — body already clears header */
  .sg-info__mast {
    padding-top: 1.15rem !important;
  }
  .sg-info__wordmark {
    font-size: clamp(1.85rem, 9vw, 2.6rem);
  }
  .sg-info__shell {
    border-radius: 1.1rem;
  }
  .sg-info__shots {
    gap: 0.4rem;
  }
  .sg-info__mast-visual {
    min-height: 180px;
  }
}

/* —— Compact phone ≤560 —— */
@media (max-width: 560px) {
  body.shopinger-theme {
    font-size: 15px;
  }

  .sg-hero__cta,
  .sg-info__btn,
  .sglq__btn,
  .sglq-c__form .sglq__btn {
    width: 100%;
    min-height: var(--sg-touch);
  }

  .sg-bento {
    gap: 0.55rem !important;
  }

  .sg-products__track {
    gap: 0.65rem !important;
  }

  .sg-card__title {
    font-size: 0.82rem !important;
    line-height: 1.35 !important;
  }

  /* Quote compact — app sheet */
  .sglq--compact {
    padding: 1.15rem 0.85rem 1.5rem !important;
  }
  .sglq-c__shell {
    border-radius: 1.15rem !important;
    box-shadow: 0 12px 32px rgba(18, 58, 92, 0.08) !important;
  }
  .sglq-c__media {
    max-height: 180px !important;
  }
  .sglq-c__media img {
    min-height: 180px !important;
    max-height: 180px !important;
  }
  .sglq-c__side {
    padding: 1.15rem 1rem 1.25rem !important;
  }
  .sglq--compact .sglq__btn {
    width: 100%;
  }

  /* Cart line items */
  .sg-cart__item,
  .woocommerce-cart-form .cart_item {
    gap: 0.75rem;
  }

  .sg-info__shot {
    border-radius: 0.85rem;
  }
}

/* —— PDP sticky above safe area (tabbar hidden on PDP) —— */
@media (max-width: 900px) {
  .sg-pdp {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px)) !important;
  }
  .sg-pdp__sticky {
    z-index: 250 !important;
    bottom: 0 !important;
    padding: 0.65rem 0.85rem calc(0.65rem + env(safe-area-inset-bottom, 0px)) !important;
  }
  .sg-pdp__sticky-cta {
    min-height: var(--sg-touch);
    flex: 1 1 auto;
    min-width: 0;
  }
  .sg-pdp__sticky-inner {
    gap: 0.65rem;
  }
}

@media (max-width: 980px) {
  .sg-pdp__toast,
  .woocommerce-message,
  body.single-product .sg-toast {
    bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* Prevent iOS input zoom */
@media (max-width: 980px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  input[type="number"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* Touch: remove 300ms / highlight clutter */
@media (max-width: 980px) {
  a,
  button,
  .sg-tabbar__item,
  .sg-header__icon {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sg-shop-cat:hover .sg-shop-cat__media,
  .sg-info__shot:hover img {
    transform: none !important;
  }
}

/* —— App sheets: minicart + search on phone —— */
@media (max-width: 720px) {
  .sg-minicart__drawer {
    width: 100% !important;
    max-width: 100% !important;
    inset-inline: 0 !important;
    inset-block-end: 0 !important;
    inset-block-start: auto !important;
    height: min(88dvh, 100%) !important;
    max-height: min(88dvh, 100%) !important;
    border-radius: 1.25rem 1.25rem 0 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(105%) !important;
  }
  .sg-minicart.is-open .sg-minicart__drawer {
    transform: translateY(0) !important;
  }
  .sg-search__panel {
    width: min(100%, 100vw) !important;
    margin: 0.75rem !important;
    max-height: calc(100dvh - 1.5rem - env(safe-area-inset-bottom, 0px));
    border-radius: 1.15rem !important;
  }
}

/* Elementor / WC overflow guards */
@media (max-width: 980px) {
  .elementor-section,
  .elementor-container,
  .e-con,
  .woocommerce,
  .site-main,
  .sg-info {
    max-width: 100%;
    min-width: 0;
  }
  .woocommerce ul.products {
    margin: 0 !important;
  }
}
