/* Main tabs share the document scroller. The companion controller marks only
   primary app pages and suspends these rules while a task owns the viewport.
   Keep the legacy DOM intact: renderers still address #app and .shell directly. */
html[data-bb-tab-viewport="document"] {
  --bb-tab-bottom-gap: calc(110px + env(safe-area-inset-bottom, 0px));
  --bb-tab-action-clearance: 0px;
  --bb-tab-storefront-clearance: 0px;
}

html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) {
  height: auto !important;
  max-height: none !important;
  min-height: 100%;
  /* hidden + visible computes to a second auto scroller; clip does not. */
  overflow-x: clip !important;
  overflow-y: visible !important;
  scroll-padding-bottom: calc(var(--bb-tab-bottom-gap) + var(--bb-tab-action-clearance));
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) body {
  position: static !important;
  inset: auto !important;
  height: auto !important;
  max-height: none !important;
  min-height: 100dvh;
  padding-bottom: 0 !important;
  overflow-x: clip !important;
  overflow-y: visible !important;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* Clear height/overflow constraints only on the actual primary-page wrappers.
   Cards, horizontal recipe swipes, dialogs and the guided Cook panel keep their
   own presentation and interaction rules. */
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) body > .shell,
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) body > .shell > #app,
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) #bbReleaseShopOverview,
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) #app > #bbMobileShopPreview {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
}

/* One end-of-page gap, including the page footer. Applying the same padding to
   #app and its .shell would double it and leave excessive empty scroll space.
   JS adds measured clearance for any extra fixed/sticky primary action bar. */
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) body > .shell,
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) body > .shell:has(> nav#bbPrimaryNavigation[data-bb-navigation="polished"]) {
  padding-bottom: calc(var(--bb-tab-bottom-gap) + var(--bb-tab-action-clearance)) !important;
}

/* These two measured lists were the remaining in-page vertical scroll boxes.
   Their contents now grow the document, including the Cook page's fallback
   stock list; no fullscreen recipe or receipt-review surface is targeted. */
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) #app aside.bb321-need-box,
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) body.bb-r6-cook-page > .shell .stock-table,
html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) body.bb-photo-meal-page > .shell .stock-table {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

html[data-bb-tab-viewport="document"]:not([data-bb-tab-scroll-lock]):not(.bb-account-open):not(.bb-onboarding-open):not(.bb172-welcome-open) #app aside.bb321-need-box > h3 {
  position: static !important;
  top: auto !important;
}

/* In-store mode deliberately owns one fullscreen scroller and hides the dock.
   Lock the background document, while preserving its scroll position. This is
   separate from account/onboarding locks, which own their existing body styles. */
html[data-bb-tab-viewport="document"][data-bb-tab-scroll-lock]:has(body.bb172-storefront-visible),
html[data-bb-tab-viewport="document"][data-bb-tab-scroll-lock] body.bb172-storefront-visible {
  overflow: hidden !important;
}

html[data-bb-tab-viewport="document"] #bb172Storefront.bb172-storefront {
  padding-bottom: max(var(--bb-tab-bottom-gap), var(--bb-tab-storefront-clearance)) !important;
  scroll-padding-bottom: max(var(--bb-tab-bottom-gap), var(--bb-tab-storefront-clearance));
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* The old Cook food chooser capped its tile list inside the page. Keep its
   horizontal category strip, but let the food tiles use the document scroll. */
html[data-bb-tab-viewport="document"] body.bb-photo-meal-page > .shell .bb-inline-section .tile-grid,
html[data-bb-tab-viewport="document"] body.bb-r6-cook-page > .shell .bb-inline-section .tile-grid {
  max-height: none !important;
  overflow: visible !important;
}

/* Horizontal category strips must not become a competing vertical scroller
   when mobile text wraps. They retain native sideways swiping. */
html[data-bb-tab-viewport="document"] body #app .bbpg-tabs {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Remove double-tap zoom delays without cancelling native scrolling, pinch
   zoom, keyboard selection or the deliberate Plan drag handle's own rules. */
html body :is(button, a[href], summary, label, [role="button"], [role="tab"], [role="switch"], input[type="checkbox"], input[type="radio"]) {
  touch-action: manipulation;
}

@media (max-width: 700px) {
  /* Keep existing colours, fonts and component arrangements. Compact controls
     get real, non-overlapping hit boxes rather than invisible overlapping
     extensions; normal full-width actions are already at least this size. */
  html body :is(button, [role="button"], [role="tab"], [role="switch"]),
  html body #app :is(.btn, .small-btn) {
    min-height: 44px;
    min-width: 44px;
  }
  html body #app.bbnext-plan .bbfeed-meta .bbfeed-meal button,
  html body #app.bbnext-plan .bbfeed-control button {
    min-height: 44px !important;
    min-width: 44px !important;
  }
  html body #app :is(.bb174-day-ideas, .bb16-toggle-filters, #bbFeaturedBatch),
  html body[data-bbnext-view="discover"] #app .bb-featured-card #bbFeaturedBatch,
  html body #bbRealTourCookLaunch {
    min-height: 44px !important;
  }
  html body #app summary {
    min-height: 44px;
  }
  html body #app :is(.bb172-inline-all-days, .bb172-day-toggle) {
    display: flex;
    align-items: center;
    min-height: 44px;
  }
  html body #app.bbnext-plan[data-bb-compact-plan="true"] #bb1759MealsSummary .bb1759-summary-heading .bb77-clear-week {
    min-height: 44px !important;
  }
  /* The reserved action gutter already has enough room for the info target. */
  html body #app.bbnext-plan[data-bb-compact-plan="true"] #bbpolAutofillCard > #bbnextPlanAutofill > summary {
    width: 44px;
    right: 0;
  }
  html body #app #bb173ShopFridge #bb76StorageSections .bbpi-ui .bbpi-step,
  html body #app #bb173ShopFridge #bb76StorageSections .bbpi-summary-actions .bbpi-step,
  html body #app #bb173ShopFridge #bb76StorageSections .bbpi-ui .bbpi-edit {
    width: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }
  html body #app #bb173ShopFridge .bbpi-stepper {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }
  html body #app #bb173ShopFridge .bbpi-reduced-row .bbpi-summary-actions {
    grid-template-columns: 44px 44px 44px;
  }
  html body .shell > .foot a,
  html body .shell > footer a,
  html body .shell .topbar a.back.bb17513-meal-premium {
    display: inline-flex;
    align-items: center;
    min-height: 44px !important;
    min-width: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html[data-bb-tab-viewport="document"] {
    scroll-behavior: auto !important;
  }
}
