/*
 * Public storefront horizontal rhythm.
 * One physical left/right gutter for homepage content on all viewports.
 * Keep the four-benefit trust strip full-bleed by design.
 * Loaded AFTER older homepage, mobile and daylight overrides.
 */
body:not(.admin-page) {
  --ts-layout-gutter: clamp(16px, 2vw, 24px);
  --page-gutter: var(--ts-layout-gutter);
  --ts-home-content-max: 1500px;
  --ts-inner-content-max: 1220px;
}

/* All homepage section content shares the same two edges. */
body[data-bsg-page="home"]:not(.admin-page) .home-page-shell
  > section:not(.pc-trust-section):not(.pc-hero-image-only) > .container {
  box-sizing: border-box !important;
  width: min(var(--ts-home-content-max), calc(100% - var(--ts-layout-gutter) - var(--ts-layout-gutter))) !important;
  max-width: var(--ts-home-content-max) !important;
  min-width: 0 !important;
  margin-inline: auto !important;
  padding-inline: 0 !important;
}

/* Hero artwork, main navigation and footer line up with the section cards. */
body[data-bsg-page="home"]:not(.admin-page) .pc-hero-image-only,
body[data-bsg-page="home"]:not(.admin-page) .header,
body[data-bsg-page="home"]:not(.admin-page) .footer > .container {
  box-sizing: border-box !important;
  width: min(var(--ts-home-content-max), calc(100% - var(--ts-layout-gutter) - var(--ts-layout-gutter))) !important;
  max-width: var(--ts-home-content-max) !important;
  min-width: 0 !important;
  margin-inline: auto !important;
}

/* The image itself still fills its card; don't double-apply the outer gutter. */
body[data-bsg-page="home"]:not(.admin-page)
  .pc-hero-image-only > .pc-home-hero__grid {
  width: 100% !important;
  max-width: none !important;
  margin-inline: 0 !important;
  padding-inline: 0 !important;
}

/* A horizontally scrollable mobile category row is full width, but its first
 * and last items align with the same inset as all other homepage sections. */
@media (max-width: 760px) {
  body[data-bsg-page="home"]:not(.admin-page) .ts-mobile-category-stories {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-inline: 0 !important;
  }
  body[data-bsg-page="home"]:not(.admin-page) .ts-mobile-category-stories__track {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    padding-inline: var(--ts-layout-gutter) !important;
    scroll-padding-inline: var(--ts-layout-gutter);
  }
  /* The hero formerly sat flush to the viewport edges on phones. */
  body[data-bsg-page="home"]:not(.admin-page) .pc-hero-image-only {
    left: auto !important;
    right: auto !important;
    transform: none !important;
    border-radius: 20px !important;
  }
  body[data-bsg-page="home"]:not(.admin-page) .pc-hero-image-only
    .pc-home-hero__slider {
    border-radius: inherit !important;
  }
}

/* Fix the mobile "دسته‌بندی‌های برتر" heading/action overshoot, without
 * hiding cards or horizontally scrolling rails behind a clipped wrapper. */
body[data-bsg-page="home"]:not(.admin-page)
  .pc-home-categories .section-head-row,
body[data-bsg-page="home"]:not(.admin-page)
  .pc-home-categories .section-head-copy,
body[data-bsg-page="home"]:not(.admin-page)
  .pc-home-categories .home-category-grid {
  box-sizing: border-box !important;
  min-width: 0 !important;
  max-width: 100% !important;
}
body[data-bsg-page="home"]:not(.admin-page) .pc-home-categories
  .home-category-grid {
  width: 100% !important;
}
body[data-bsg-page="home"]:not(.admin-page) .pc-home-categories
  .home-category-grid > * {
  box-sizing: border-box !important;
  min-width: 0 !important;
  max-width: 100% !important;
}
@media (max-width: 760px) {
  body[data-bsg-page="home"]:not(.admin-page) .pc-home-categories
    .section-head-row {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: flex-start !important;
    justify-content: space-between !important;
    column-gap: 12px !important;
    row-gap: 10px !important;
    width: 100% !important;
    margin-inline: 0 !important;
    padding-inline: 0 !important;
  }
  body[data-bsg-page="home"]:not(.admin-page) .pc-home-categories
    .section-head-copy {
    flex: 1 1 170px !important;
    width: auto !important;
  }
  body[data-bsg-page="home"]:not(.admin-page) .pc-home-categories
    .section-head-row h2 {
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
  }
  body[data-bsg-page="home"]:not(.admin-page) .pc-home-categories
    .section-link {
    flex: 0 1 auto !important;
    max-width: 100% !important;
    white-space: normal !important;
  }
  body[data-bsg-page="home"]:not(.admin-page) .pc-home-categories
    .home-category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
    margin-inline: 0 !important;
    padding-inline: 0 !important;
  }
}

/* Exception: the benefits rail runs edge-to-edge. Its own card spacing
 * stays intact and does not inherit the common content gutter. */
body[data-bsg-page="home"]:not(.admin-page) .home-page-shell > .pc-trust-section {
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: none !important;
  margin-inline: 0 !important;
  border-inline: 0 !important;
  border-radius: 0 !important;
}

/* Inner pages: normalize the external margins only, not internal card layouts. */
body:not(.admin-page):not([data-bsg-page="home"]) .page-body >
  :is(.container, .products-page, .profile-page, .product-detail,
      .product-detail-breadcrumb, .product-description-section, .product-reviews,
      .similar-products-section, .cart-checkout-page, .error-page-wrap,
      .blog-shell) {
  box-sizing: border-box !important;
  width: min(var(--ts-inner-content-max), calc(100% - var(--ts-layout-gutter) - var(--ts-layout-gutter))) !important;
  max-width: var(--ts-inner-content-max) !important;
  min-width: 0 !important;
  margin-inline: auto !important;
}
/* Prevent long blog article media and the about/contact cards from widening
 * the parent; long tabular content remains scrollable inside its own box. */
body:not(.admin-page) .page-body
  :is(.blog-shell, .blog-grid, .blog-article, .products-page .contact-grid,
      .products-page .stats) {
  box-sizing: border-box !important;
  min-width: 0 !important;
  max-width: 100% !important;
}
