/**
 * Mauritius Guide — global stacking order (single source of truth).
 *
 * Layer stack (low → high):
 *   base / raised → sticky → map → floating widgets → toasts → overlays → modals → top modal
 */

:root {
  --mg-z-base: 1;
  --mg-z-raised: 2;
  --mg-z-sticky: 100;
  --mg-z-header: 200;
  --mg-z-map: 500;
  --mg-z-map-popup: 1000;
  --mg-z-float: 8000;
  --mg-z-gtranslate: 8200;
  --mg-z-app-search: 230;
  --mg-z-spotlight: 8800;
  --mg-z-voice: 9000;
  --mg-z-toast: 9600;
  --mg-z-overlay: 100000;
  --mg-z-modal: 100010;
  --mg-z-modal-top: 100020;
}

/* Full-screen modals — shared sizing + safe areas */
.mg-booking-modal,
.mg-offers-modal,
.mg-tool-modal {
  z-index: var(--mg-z-base);
  padding:
    max(0.75rem, env(safe-area-inset-top, 0px))
    max(0.75rem, env(safe-area-inset-right, 0px))
    max(0.75rem, env(safe-area-inset-bottom, 0px))
    max(0.75rem, env(safe-area-inset-left, 0px));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.mg-booking-modal.is-open,
.mg-offers-modal.is-open,
.mg-tool-modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.mg-booking-modal.is-open {
  z-index: var(--mg-z-modal-top);
}

.mg-offers-modal.is-open,
.mg-tool-modal.is-open {
  z-index: var(--mg-z-modal);
}

/* Atlas offers modal uses mg-atlas-sheet slide-up (see mg-atlas.css) */
#mgOffersModal.mg-atlas-sheet.is-open {
  z-index: 260;
}

.mg-booking-modal__panel,
.mg-offers-modal__panel,
.mg-tool-modal__panel {
  position: relative;
  z-index: calc(var(--mg-z-modal) + 1);
  width: min(480px, 100%);
  max-height: min(90vh, calc(100dvh - 2rem));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.mg-booking-modal__backdrop,
.mg-offers-modal__backdrop,
.mg-tool-modal__backdrop {
  z-index: var(--mg-z-overlay);
}

/* When any booking/offers/tool modal is open, tuck floating widgets underneath */
body.mg-modal-open .mg-voice-widget,
body.mg-modal-open .mg-local-services-widget,
body.mg-modal-open .mg-quick-tools-widget,
body.mg-modal-open #gt_float_wrapper,
body.mg-modal-open #gt_float_wrapper.mg-gt-ocean,
body.mg-modal-open .mg-region-spotlight,
body.mg-modal-open .mg-region-spotlight__pill,
#gt_float_wrapper.mg-gt-hidden-overlay {
  z-index: var(--mg-z-base) !important;
  pointer-events: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  transform: none !important;
}

body.mg-modal-open .mg-voice-widget *,
body.mg-modal-open #gt_float_wrapper * {
  pointer-events: none !important;
}

@media (max-width: 640px) {
  .mg-booking-modal,
  .mg-offers-modal,
  .mg-tool-modal {
    align-items: center;
    justify-content: center;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  }

  .mg-guide--atlas .mg-booking-modal,
  .mg-guide--atlas .mg-offers-modal,
  .mg-guide--atlas .mg-tool-modal,
  .mg-guide--atlas .mg-atlas-sheet,
  .mg-guide--atlas #mgOffersModal {
    align-items: center;
    justify-content: center;
    padding:
      max(0.5rem, env(safe-area-inset-top, 0px))
      max(0.5rem, env(safe-area-inset-right, 0px))
      max(0.5rem, env(safe-area-inset-bottom, 0px))
      max(0.5rem, env(safe-area-inset-left, 0px));
  }

  .mg-booking-modal__panel,
  .mg-offers-modal__panel,
  .mg-tool-modal__panel {
    width: 100%;
    max-height: min(92vh, calc(100dvh - 1rem));
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .mg-guide--atlas .mg-booking-modal__panel,
  .mg-guide--atlas .mg-tool-modal__panel,
  .mg-guide--atlas .mg-atlas-sheet__panel,
  .mg-guide--atlas #mgOffersModal .mg-atlas-sheet__panel {
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;
  }

  .mg-offers-modal__panel {
    max-height: min(88vh, calc(100dvh - 1rem));
  }
}
