/* v523 iOS/Safari + cross-device item modal compatibility.
   Loaded after the existing customer responsive layers and v522 quantity repair.
   Scope is intentionally limited to the shared item customization modal. */

:root {
  --item-modal-v523-visual-height: 100vh;
  --item-modal-v523-visual-top: 0px;
  --item-modal-v523-visual-bottom: 0px;
  --item-modal-v523-safe-top: env(safe-area-inset-top, 0px);
  --item-modal-v523-safe-right: env(safe-area-inset-right, 0px);
  --item-modal-v523-safe-bottom: env(safe-area-inset-bottom, 0px);
  --item-modal-v523-safe-left: env(safe-area-inset-left, 0px);
}

html,
body {
  -webkit-text-size-adjust: 100%;
}

.shop-page #item-modal.premium-modal {
  box-sizing: border-box;
  top: var(--item-modal-v523-visual-top, 0px) !important;
  right: 0 !important;
  bottom: auto !important;
  left: 0 !important;
  width: 100% !important;
  height: var(--item-modal-v523-visual-height, 100vh) !important;
  min-height: 0 !important;
  padding-top: calc(12px + var(--item-modal-v523-safe-top)) !important;
  padding-right: calc(12px + var(--item-modal-v523-safe-right)) !important;
  padding-bottom: calc(12px + var(--item-modal-v523-safe-bottom) + var(--item-modal-v523-visual-bottom, 0px)) !important;
  padding-left: calc(12px + var(--item-modal-v523-safe-left)) !important;
  overflow: hidden !important;
  touch-action: none;
}

.shop-page #item-modal .premium-modal-card {
  box-sizing: border-box;
  width: min(760px, 100%) !important;
  max-width: 100% !important;
  max-height: calc(var(--item-modal-v523-visual-height, 100vh) - 24px - var(--item-modal-v523-safe-top) - var(--item-modal-v523-safe-bottom)) !important;
  min-height: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-gutter: stable;
}

.shop-page #item-modal .modal-scrim {
  touch-action: none;
}

.shop-page #item-modal .modal-x,
.shop-page #item-modal .qty-stepper button,
.shop-page #item-modal .modal-add-button-v33 {
  -webkit-tap-highlight-color: transparent;
}

.shop-page #item-modal .modal-x,
.shop-page #item-modal .qty-stepper button {
  touch-action: manipulation;
}

.shop-page #item-modal .modal-bottom,
.shop-page #item-modal .modal-bottom > * {
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box;
}

.shop-page #item-modal .qty-stepper {
  grid-template-columns: 40px minmax(0, 1fr) 40px !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  overflow: hidden !important;
  contain: layout paint;
}

.shop-page #item-modal .qty-stepper input[type="number"] {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  font-size: 16px !important;
  line-height: 1.2;
  appearance: textfield;
  -webkit-appearance: none;
  -moz-appearance: textfield;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

.shop-page #item-modal .item-note {
  min-width: 0 !important;
  max-width: 100% !important;
  font-size: 16px !important;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

.shop-page #item-modal .qty-stepper input[type="number"]::-webkit-inner-spin-button,
.shop-page #item-modal .qty-stepper input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
}

@media (max-width: 720px), (pointer: coarse) and (max-width: 920px) {
  .shop-page #item-modal.premium-modal {
    place-items: end center !important;
    padding-top: calc(8px + var(--item-modal-v523-safe-top)) !important;
    padding-right: var(--item-modal-v523-safe-right) !important;
    padding-bottom: var(--item-modal-v523-visual-bottom, 0px) !important;
    padding-left: var(--item-modal-v523-safe-left) !important;
  }

  .shop-page #item-modal .premium-modal-card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(var(--item-modal-v523-visual-height, 100vh) - 8px - var(--item-modal-v523-safe-top)) !important;
    border-radius: 28px 28px 0 0 !important;
    padding-right: max(16px, var(--item-modal-v523-safe-right)) !important;
    padding-bottom: calc(18px + var(--item-modal-v523-safe-bottom)) !important;
    padding-left: max(16px, var(--item-modal-v523-safe-left)) !important;
  }

  .shop-page #item-modal .modal-bottom {
    bottom: calc(-18px - var(--item-modal-v523-safe-bottom)) !important;
    padding-bottom: calc(12px + var(--item-modal-v523-safe-bottom)) !important;
  }

  .shop-page #item-modal .qty-stepper {
    grid-template-columns: 52px minmax(0, 1fr) 52px !important;
    min-height: 54px !important;
  }

  .shop-page #item-modal .qty-stepper button {
    min-width: 52px !important;
    min-height: 54px !important;
    font-size: 24px !important;
  }

  .shop-page #item-modal .qty-stepper input[type="number"] {
    min-height: 54px !important;
    font-size: 18px !important;
    font-weight: 900;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .shop-page #item-modal.premium-modal {
    place-items: center !important;
    padding-top: calc(6px + var(--item-modal-v523-safe-top)) !important;
    padding-bottom: calc(6px + var(--item-modal-v523-safe-bottom) + var(--item-modal-v523-visual-bottom, 0px)) !important;
  }

  .shop-page #item-modal .premium-modal-card {
    width: min(760px, 100%) !important;
    max-height: calc(var(--item-modal-v523-visual-height, 100vh) - 12px - var(--item-modal-v523-safe-top) - var(--item-modal-v523-safe-bottom)) !important;
    border-radius: 24px !important;
    padding-top: 14px !important;
    padding-bottom: calc(14px + var(--item-modal-v523-safe-bottom)) !important;
  }

  .shop-page #item-modal .modal-hero {
    grid-template-columns: 82px minmax(0, 1fr) !important;
    gap: 12px !important;
  }

  .shop-page #item-modal .modal-image {
    height: 82px !important;
  }

  .shop-page #item-modal .modal-hero h2 {
    font-size: 24px !important;
  }
}

@supports (-webkit-touch-callout: none) {
  .shop-page #item-modal .premium-modal-card {
    transform: translateZ(0);
  }

  .shop-page #item-modal .modal-bottom {
    transform: translateZ(0);
  }
}
