html.esnaf-touch-viewport {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-x pan-y;
}

html.esnaf-touch-viewport :where(
  body, dialog, [role="dialog"], input, select, textarea, a, button,
  .esnaf-panel-body, .esnaf-cart-lines, .esnaf-category-links, .esnaf-category-directory,
  .esnaf-inline-results, .esnaf-search-body, .esnaf-store-login [data-auth-view="register"],
  .esnaf-queue-dialog-body, .esnaf-ticket-order-select__list, .table-responsive
) {
  touch-action: pan-x pan-y;
}

/* WebKit zooms on focus when the computed text size of a form control is below 16px. */
html.esnaf-touch-viewport body :is(
  input:not([type="hidden"], [type="checkbox"], [type="radio"], [type="button"], [type="submit"], [type="reset"], [type="image"], [type="range"], [type="color"]),
  select, textarea, [contenteditable]:not([contenteditable="false"])
) {
  font-size: max(16px, 1em) !important;
}

html:has(> body.esnaf-store dialog:modal) {
  overflow: hidden;
  overscroll-behavior: none;
}

.esnaf-store dialog:modal {
  overscroll-behavior: contain;
}

.esnaf-viewport-probe {
  position: fixed;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
}

html.esnaf-touch-viewport .esnaf-store .esnaf-store-login:modal {
  /* The keyboard covers the card. The card uses the height from before the keyboard opened. */
  --esnaf-auth-top-gap: clamp(14px, calc(var(--esnaf-auth-viewport-height, 100dvh) * .06), 54px);
  inset-block: var(--esnaf-dialog-top, 0px) auto;
  margin-block: var(--esnaf-auth-top-gap) 0;
  height: var(--esnaf-auth-card-height, auto);
  max-height: calc(var(--esnaf-auth-viewport-height, 100dvh) - var(--esnaf-auth-top-gap) - 14px);
  box-sizing: border-box;
  scroll-padding-block: 12px;
}

html.esnaf-touch-viewport .esnaf-store .esnaf-store-login:modal > form[data-auth-view] {
  max-height: var(--esnaf-auth-form-height, none);
  margin-inline: -5px;
  padding: 5px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 4px;
}

@media (max-width: 699px) {
  html.esnaf-touch-viewport .esnaf-store .esnaf-search-sheet:modal {
    /* Keep the sheet surface behind the translucent keyboard controls. */
    --esnaf-search-underlay: max(0px, var(--esnaf-dialog-bottom, 0px), calc(100lvh - var(--esnaf-dialog-height, 100lvh)));
    bottom: calc(var(--esnaf-dialog-bottom, 0px) - var(--esnaf-search-underlay));
    box-sizing: border-box;
    height: calc(min(81dvh, 720px, var(--esnaf-dialog-height, 100dvh) - 12px) + var(--esnaf-search-underlay));
    max-height: none;
    padding-bottom: var(--esnaf-search-underlay);
  }
}

@media (min-width: 700px) {
  html.esnaf-touch-viewport .esnaf-store .esnaf-search-sheet:modal {
    inset-block: var(--esnaf-dialog-top, 0px) var(--esnaf-dialog-bottom, 0px);
    max-height: calc(var(--esnaf-dialog-height, 100dvh) - 24px);
  }
}

@media (max-width: 767px) {
  html.esnaf-touch-viewport .esnaf-store :is(#esnaf-cart, #esnaf-menu, .esnaf-product-preview):modal {
    bottom: var(--esnaf-dialog-bottom, 0px);
    max-height: calc(var(--esnaf-dialog-height, 100dvh) - 12px);
  }
}


@media (max-width: 767px) {
  html.esnaf-touch-viewport .esnaf-store .esnaf-store-login[data-auth-view="register"]:modal {
    --register-covered: max(0px, var(--esnaf-dialog-bottom, 0px));
    inset: var(--esnaf-dialog-top, 0px) 0 auto;
    margin: 0;
    width: 100%;
    height: calc(var(--esnaf-dialog-height, 100dvh) + var(--register-covered));
    max-height: none;
    border: 0;
    border-radius: 0;
    box-sizing: border-box;
    padding-bottom: calc(var(--register-covered) + max(10px, env(safe-area-inset-bottom)));
  }

  .esnaf-store-login > [data-auth-view="register"] {
    scroll-padding-block: 8px;
  }
}
