/* Modal Behavior Fixes
   =====================
   Fixes for modal opening issues:
   - Prevent content jumping
   - Stop scroll to bottom
   - Keep backdrop stable
*/

/* Prevent body scroll jump when modal opens */
body.modal-open {
    overflow: hidden !important;
    padding-right: 0 !important; /* Override Bootstrap's scrollbar compensation */
}

/* Special class to preserve scroll but prevent jumping */
body.modal-open-scroll-preserve {
    position: fixed !important;
    width: 100% !important;
    overflow-y: hidden !important;
}

/* Preserve scroll position */
.modal-open-scroll-preserve {
    position: fixed !important;
    width: 100% !important;
    overflow-y: scroll !important;
}

/* Fix modal backdrop behavior */
.modal-backdrop {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
}

/* Ensure modal stays centered */
.modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    outline: 0 !important;
}

.modal-dialog {
    position: relative !important;
    margin: auto !important;
    pointer-events: none !important;
}

.modal.show .modal-dialog {
    transform: translate(0, 0) !important;
}

.modal-dialog-centered {
    display: flex !important;
    align-items: center !important;
    min-height: calc(100% - 1rem) !important;
}

.modal-content {
    position: relative !important;
    pointer-events: auto !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
}

/* Specific fixes for marketplace modal */
#marketplaceComingSoonModal {
    z-index: 1055 !important;
}

#marketplaceComingSoonModal .modal-dialog {
    z-index: auto !important;
}

#marketplaceComingSoonModal .modal-backdrop {
    z-index: 1050 !important;
}

/* Prevent content shift on modal open */
.modal-open .container,
.modal-open .navbar {
    padding-right: 0 !important;
}

/* Fix for mobile devices */
@media (max-width: 768px) {
    body.modal-open {
        position: fixed !important;
        overflow: hidden !important;
        -webkit-overflow-scrolling: auto !important;
    }
    
    .modal-dialog {
        margin: 0.5rem !important;
    }
    
    .modal-dialog-centered {
        min-height: calc(100% - 1rem) !important;
    }
    
    .modal-content {
        max-height: calc(100vh - 1rem) !important;
    }
}

/* Smooth transitions */
.modal.fade .modal-dialog {
    transition: transform 0.3s ease-out !important;
    transform: translate(0, -50px) !important;
}

.modal.show .modal-dialog {
    transform: none !important;
}

/* Fix for iOS rubber band scrolling */
@supports (-webkit-touch-callout: none) {
    body.modal-open {
        position: fixed !important;
        overflow: hidden !important;
        width: 100% !important;
        height: 100% !important;
    }
}

/* Ensure page content doesn't shift */
html.modal-open {
    overflow: hidden !important;
    height: 100% !important;
}

/* Keep the scroll position */
.modal-open .page-wrapper {
    position: fixed !important;
    width: 100% !important;
    overflow-y: scroll !important;
}