/* =========================================================================
   Public catalog popups (product details + enquiry): final layout layer.
   Loaded after every theme. Uses #id selectors so it wins over the theme's
   class-level !important rules without adding more of them than needed.

   Goals
   - The popup always fits the *visible* screen on phones, whether the
     browser address bar is shown or hidden (no 100vh, which is taller than
     the visible area on mobile browsers).
   - The close button never scrolls away: the popup frame stays still and
     only the text area inside it scrolls.
   - Safe areas (notch / home bar) are respected.
   ========================================================================= */

/* ---- Backdrop: fills the visible screen and centres the popup ---- */
#productModal,
#enquiryModal {
  align-items: center;
  justify-content: center;
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgba(6, 24, 18, .58);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: cmFade .18s ease-out;
}

/* ---- Product popup frame: fixed header (photo), scrolling body ---- */
#productModal .product-modal {
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  max-width: 100% !important;
  /* 100% of the backdrop's content box = visible screen minus the padding above */
  max-height: 100% !important;
  margin: 0;
  border-radius: 22px !important;
  box-shadow: 0 30px 80px -24px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .06) !important;
  animation: cmPop .22s cubic-bezier(.2, .8, .3, 1) !important;
}
@media (min-width: 601px) {
  #productModal .product-modal { max-height: min(100%, 820px) !important; }
}
#productModal .modal-gallery,
#productModal .modal-thumbs { flex: 0 0 auto; }
#productModal .modal-product-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* Long names never run under the close button */
#productModal #modalProductName { padding-right: 4px; overflow-wrap: anywhere; }

/* ---- Close button: always on top, always reachable, 44px touch target ---- */
#productModal .modal-close,
#enquiryModal .modal-close {
  width: 44px;
  height: 44px;
  border: 0 !important;
  border-radius: 50%;
  background: rgba(255, 255, 255, .96) !important;
  color: #13241d !important;
  box-shadow: 0 4px 14px -2px rgba(0, 0, 0, .35) !important;
  cursor: pointer;
  transition: transform .15s ease, background-color .15s ease;
}
#productModal .modal-close {
  position: absolute !important;
  top: 10px !important;
  right: 10px !important;
  z-index: 6 !important;
}
#productModal .modal-close:hover,
#enquiryModal .modal-close:hover { background: #fff !important; transform: scale(1.06); }
#productModal .modal-close:focus-visible,
#enquiryModal .modal-close:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--sf-brand, #0f7a5a) 55%, #fff);
  outline-offset: 2px;
}

/* ---- Enquiry popup: it scrolls itself (keyboard open), so the close button sticks to its top ---- */
#enquiryModal .enquiry-modal {
  max-width: 100% !important;
  max-height: 100% !important;
  margin: 0;
  border-radius: 22px !important;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: cmPop .22s cubic-bezier(.2, .8, .3, 1) !important;
}
#enquiryModal .modal-close {
  position: sticky !important;
  top: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  margin: -8px -8px -36px auto; /* takes no vertical space: overlays the heading's right padding */
}

/* ---- Short screens (phones in landscape): smaller photo so the text keeps room ---- */
@media (max-height: 560px) {
  #productModal .modal-gallery .modal-product-image { max-height: 42vh !important; }
  #productModal .modal-thumbs { display: none !important; }
}

/* ---- Exact visible-screen sizing (set by the page script while a popup is open) ----
   Works the same on Android Chrome, Samsung Internet, iPhone Safari and older browsers
   without dvh support: the backdrop is exactly the visible area, above the keyboard too. */
html.cm-fit .modal-backdrop {
  top: var(--cm-top) !important;
  bottom: auto !important;
  height: var(--cm-vh) !important;
}

@keyframes cmFade { from { opacity: 0; } }
@keyframes cmPop { from { opacity: 0; transform: translateY(12px) scale(.98); } }

@media (prefers-reduced-motion: reduce) {
  #productModal, #enquiryModal,
  #productModal .product-modal, #enquiryModal .enquiry-modal { animation: none !important; }
  #productModal .modal-close, #enquiryModal .modal-close { transition: none; }
}
