/* ============================================
   PRODUCTION-READY MODAL SYSTEM
   Professional E-commerce Modal Implementation
   ============================================ */

/* ============================================
   Z-INDEX HIERARCHY SYSTEM
   ============================================ */
:root {
    --z-base: 1;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-overlay: 1000;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-modal-close: 1055;
    --z-tooltip: 1060;
}

/* ============================================
   HEADER & NAVIGATION Z-INDEX
   ============================================ */
.header-wrap,
.header-bottom,
.main-menu,
.search-form {
    position: relative;
    z-index: var(--z-fixed);
}

.header-wrap.is-fixed,
.header-bottom.is-fixed {
    z-index: var(--z-fixed);
}

/* ============================================
   MODAL BACKDROP & OVERLAY
   ============================================ */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-backdrop.show {
    opacity: 1;
}

.modal-backdrop.fade {
    transition: opacity 0.15s linear;
}

/* ============================================
   MODAL CONTAINER
   ============================================ */
.custom-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-modal);
    display: none;
    overflow-x: hidden;
    overflow-y: auto;
    outline: 0;
}

.custom-modal.show {
    display: block;
}

.custom-modal.fade {
    opacity: 0;
    transition: opacity 0.15s linear;
}

.custom-modal.show.fade {
    opacity: 1;
}

/* ============================================
   MODAL DIALOG - PERFECT CENTERING
   ============================================ */
.custom-modal .modal-dialog {
    position: relative;
    width: auto;
    margin: 1.75rem auto;
    max-width: 888px;
    pointer-events: none;
    display: flex;
    align-items: center;
    min-height: calc(100% - 3.5rem);
    padding: 1rem;
}

@media (max-width: 576px) {
    .custom-modal .modal-dialog {
        margin: 0.5rem;
        min-height: calc(100% - 1rem);
        max-width: calc(100% - 1rem);
    }
}

/* Perfect vertical and horizontal centering */
.custom-modal.show .modal-dialog {
    transform: none;
}

.custom-modal.fade .modal-dialog {
    transform: translate(0, -50px);
    transition: transform 0.3s ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .custom-modal.fade .modal-dialog {
        transition: none;
    }
}

/* ============================================
   MODAL CONTENT
   ============================================ */
.custom-modal .modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: auto;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #BCE3C9;
    border-radius: 25px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    outline: 0;
    padding: 0;
    overflow: hidden;
}

/* ============================================
   MODAL BODY
   ============================================ */
.custom-modal .modal-body {
    position: relative;
    flex: 1 1 auto;
    padding: 2rem;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}

@media (max-width: 768px) {
    .custom-modal .modal-body {
        padding: 1.5rem;
        max-height: calc(100vh - 150px);
    }
}

@media (max-width: 576px) {
    .custom-modal .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 100px);
    }
}

/* ============================================
   CLOSE BUTTON - PRODUCTION READY
   ============================================ */
.custom-modal .btn-close {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: var(--z-modal-close);
    width: 40px;
    height: 40px;
    padding: 0;
    margin: 0;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    opacity: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
    color: #333;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.custom-modal .btn-close:hover,
.custom-modal .btn-close:focus {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.2);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    color: #000;
    outline: none;
}

.custom-modal .btn-close:active {
    transform: scale(0.95);
}

/* Close button icon */
.custom-modal .btn-close::before {
    content: '×';
    display: block;
    line-height: 1;
    font-size: 28px;
    font-weight: 300;
}

/* ============================================
   MODAL IMAGES
   ============================================ */
.custom-modal .modal-body img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 10px;
}

/* ============================================
   BODY SCROLL LOCK
   ============================================ */
body.modal-open {
    overflow: hidden;
    padding-right: 0 !important;
}

/* Prevent layout shift from scrollbar */
html.modal-open {
    overflow: hidden;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 992px) {
    .custom-modal .modal-dialog {
        max-width: 90%;
    }
}

@media (max-width: 768px) {
    .custom-modal .modal-dialog {
        max-width: 95%;
        margin: 0.5rem;
    }
    
    .custom-modal .modal-content {
        border-radius: 15px;
    }
    
    .custom-modal .btn-close {
        width: 35px;
        height: 35px;
        top: 10px;
        right: 10px;
        font-size: 20px;
    }
}

@media (max-width: 576px) {
    .custom-modal .modal-dialog {
        max-width: 100%;
        margin: 0;
        padding: 0.5rem;
    }
    
    .custom-modal .modal-content {
        border-radius: 10px;
    }
    
    .custom-modal .modal-body {
        padding: 1rem;
    }
    
    .custom-modal .btn-close {
        width: 32px;
        height: 32px;
        top: 8px;
        right: 8px;
        font-size: 18px;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.custom-modal .btn-close:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.custom-modal[aria-hidden="true"] {
    display: none;
}

/* ============================================
   ANIMATIONS & TRANSITIONS
   ============================================ */
@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.custom-modal.show .modal-dialog {
    animation: modalSlideIn 0.3s ease-out;
}

/* ============================================
   PREVENT OVERLAP WITH HEADER/SEARCH
   ============================================ */
.custom-modal .modal-dialog {
    margin-top: 2rem;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .custom-modal .modal-dialog {
        margin-top: 1rem;
        margin-bottom: 1rem;
    }
}

/* ============================================
   CLEANUP - REMOVE CONFLICTS
   ============================================ */
.custom-modal .modal-dialog {
    /* Remove conflicting transforms */
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
}


