/* The measured keyboard height already includes its bottom safe area. */
html:has(> body.bbc-keyboard-open) {
  scroll-behavior: auto;
}

body.bbc-keyboard-open .bbc-book-dock,
body.bbc-keyboard-open[data-public-page="home"][data-step="0"] .bbc-book-dock[data-active] {
  display: none;
}

html:has(> body.bbc-keyboard-open[data-public-page="home"]),
body.bbc-keyboard-open[data-public-page="home"] {
  overflow: hidden;
  overscroll-behavior: none;
}

/* Keep the landing page's place in the document when its booking panel is
   pinned for typing. Closing the keyboard restores the same document layout. */
html.home-landing body.bbc-keyboard-open[data-step="0"]::before {
  content: "";
  display: block;
  height: max(35rem, 100svh);
}

body.bbc-keyboard-open[data-public-page="home"] #booking-top {
  position: fixed;
  z-index: 50;
  inset: 0 0 auto;
  margin: 0 auto;
  min-width: 0;
  min-height: 0;
  height: calc(100dvh - var(--bbc-keyboard-height, 0px));
  max-height: calc(100dvh - var(--bbc-keyboard-height, 0px));
  overflow: hidden;
}

body.bbc-keyboard-open #booking-top .booking-header {
  flex: none;
  height: 2.75rem;
  min-height: 2.75rem;
}

body.bbc-keyboard-open #booking-top #main {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-padding-block: .5rem;
  scroll-behavior: auto;
  overflow-anchor: none;
}

body.bbc-keyboard-open #booking-top #footer {
  position: static;
  flex: none;
  min-width: 0;
  padding-block: .3rem;
  transform: none;
}

body.bbc-keyboard-open #booking-top #footer .primary {
  min-height: 44px;
}

body.bbc-keyboard-open #booking-top :is(.explore-service, .footerinner) {
  display: none;
}

body.bbc-keyboard-open[data-step="4"] #booking-top #main {
  display: block;
}

body.bbc-keyboard-open[data-step="4"] #booking-top #main .content {
  display: block;
  min-width: 0;
  overflow: visible;
  padding-bottom: .4rem;
}

body.bbc-keyboard-open #details :is(input, textarea) {
  scroll-margin-block: .4rem;
}

/* On the ZIP screen the middle row can give up the couch image or secondary
   copy before an input or the submit button needs to move off-screen. */
html.home-landing body.bbc-keyboard-open #booking-top #main {
  container: bbc-zip-entry / size;
}

html.home-landing body.bbc-keyboard-open #booking-top #main .content {
  flex: none;
  min-height: 100%;
  overflow: visible;
}

@container bbc-zip-entry (max-height: 20rem) {
  .home-landing .hero img.sliding-couch { display: none; }
  .home-landing .hero { justify-content: center; padding-block: .3rem; }
  .home-landing .hero h1 { font-size: 2rem; }
  .home-landing .home-intake { margin-bottom: .25rem; }
}

@container bbc-zip-entry (max-height: 13rem) {
  .home-landing .hero, .home-landing .trust { display: none; }
  .home-landing .home-intake { margin: auto auto 0; }
}

/* The partner application is a normal page with document scrolling. Keep the
   current form action above the keyboard and leave room to reach its last field. */
body.bbc-keyboard-open[data-public-page="haulers"] {
  --hauler-keyboard-actions: 3.75rem;
  padding-bottom: 0;
}

body.bbc-keyboard-open[data-public-page="haulers"] .hauler-layout {
  padding-bottom: calc(var(--bbc-keyboard-height, 0px) + var(--hauler-keyboard-actions) + 1rem);
}

body.bbc-keyboard-open[data-public-page="haulers"] .hauler-actions {
  position: fixed;
  z-index: 46;
  inset: auto 0 var(--bbc-keyboard-height, 0px);
  width: 100%;
  max-width: 34rem;
  min-height: var(--hauler-keyboard-actions);
  margin: 0 auto;
  padding: .35rem max(.65rem, env(safe-area-inset-right, 0px)) .35rem max(.65rem, env(safe-area-inset-left, 0px));
  background: #fff;
  box-shadow: 0 -1px 0 #17342512;
}

body.bbc-keyboard-open .hauler-step :is(input, textarea) {
  scroll-margin-top: calc(4.25rem + env(safe-area-inset-top, 0px));
  scroll-margin-bottom: calc(var(--bbc-keyboard-height, 0px) + var(--hauler-keyboard-actions) + .5rem);
}

@media (max-height: 32rem) {
  body.bbc-keyboard-open #booking-top .booking-header,
  body.bbc-keyboard-open[data-step="4"] #booking-top .nav { display: none; }

  body.bbc-keyboard-open[data-public-page="haulers"] .bbc-top { position: static; }
  body.bbc-keyboard-open .hauler-step :is(input, textarea) { scroll-margin-top: .5rem; }
}

@media (min-width: 800px) and (min-height: 500px) {
  html.home-landing body.bbc-keyboard-open[data-step="0"]::before { height: max(38rem, 100svh); }
}
