/* ===================================================
   ENHANCED MODAL SCROLL LOCK CSS
   =================================================== */

/* Body with modal open - additional safety measures */
body.modal-open {
    /* Ensure no scrolling even if JavaScript fails */
    overflow: hidden !important;

    /* Prevent iOS Safari rubber band scrolling */
    position: fixed !important;
    width: 100% !important;

    /* Prevent any touch scrolling behavior */
    touch-action: none;
    -webkit-overflow-scrolling: touch;

    /* Ensure content doesn't shift */
    margin: 0 !important;
}

/* Additional mobile-specific fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific fixes */
    body.modal-open {
        /* Prevent iOS Safari from bouncing */
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height */
        -webkit-overflow-scrolling: touch;
    }
}

/* Prevent scrolling on the root element as well */
html.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* Modal containers should allow internal scrolling */
.modal-open .modal,
.modal-open .modal-content,
.modal-open .issue-detail-modal,
.modal-open .duplicate-modal,
.modal-open [role="dialog"],
.modal-open [aria-modal="true"] {
    /* Allow touch actions within modals */
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
}

/* Scrollable areas within modals */
.modal-open .modal-body,
.modal-open .issue-detail-content-area,
.modal-open .issue-detail-sidebar,
.modal-open .modal-scrollable {
    /* Enable smooth scrolling within modal areas */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* Prevent text selection during touch events when modal is open */
.modal-open * {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow text selection within modal content */
.modal-open .modal,
.modal-open .modal-content,
.modal-open .issue-detail-modal,
.modal-open .duplicate-modal,
.modal-open [role="dialog"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

.modal-open .modal input,
.modal-open .modal textarea,
.modal-open .modal-content input,
.modal-open .modal-content textarea,
.modal-open .issue-detail-modal input,
.modal-open .issue-detail-modal textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    body.modal-open {
        border: 2px solid transparent;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    body.modal-open {
        transition: none !important;
    }
}

/* Landscape orientation fixes for mobile */
@media (orientation: landscape) and (max-height: 600px) {
    body.modal-open {
        height: 100vh !important;
        height: 100svh !important; /* Small viewport height */
    }
}

/* Additional security - prevent any potential scroll restoration */
body.modal-open {
    scroll-behavior: auto !important;
}

/* Ensure backdrop elements don't interfere with scroll lock */
.modal-open .modal-backdrop,
.modal-open .issue-detail-backdrop,
.modal-open .duplicate-modal-backdrop {
    touch-action: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Support for nested modals (just in case) */
.modal-open .modal .modal {
    touch-action: auto;
}

/* Debug mode styles (optional - only include if you want visual debugging) */
.modal-scroll-lock-debug body.modal-open {
    outline: 3px solid red !important;
    outline-offset: -3px;
}

.modal-scroll-lock-debug body.modal-open::before {
    content: "SCROLL LOCKED";
    position: fixed;
    top: 10px;
    right: 10px;
    background: red;
    color: white;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: bold;
    z-index: 999999;
    border-radius: 3px;
}

/* ===================================================
   LEGACY SUPPORT
   These ensure compatibility with existing modals
   =================================================== */

/* Support for any existing modal implementations */
.modal-open .modal-dialog {
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
}

/* Bootstrap modal compatibility (if used) */
.modal-open .modal-content {
    touch-action: auto;
}

/* Custom modal compatibility */
.modal-open .custom-modal,
.modal-open .popup-modal,
.modal-open .overlay-modal {
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===================================================
   PRINT SUPPORT
   =================================================== */

@media print {
    body.modal-open {
        position: static !important;
        overflow: visible !important;
        height: auto !important;
        width: auto !important;
    }

    html.modal-open {
        position: static !important;
        overflow: visible !important;
        height: auto !important;
        width: auto !important;
    }
}