/**
 * Modal base styles
 * Shared by every modal built on the native <dialog> element and driven by
 * assets/js/sq-modal.js (SqModal). Used by: Login Modal, Artisan Modal,
 * Request List Modal, Stock Availability Modal. The Product drawer has its own
 * <dialog> styles in unified-product-block/assets/product-modal.css.
 *
 * Markup:
 *   <dialog id="x" class="sq-modal">
 *     <div class="modal__overlay" data-modal-overlay>
 *       <div class="modal__container"> ... </div>
 *     </div>
 *   </dialog>
 */

/* ============================================
   Dialog shell: a transparent, full viewport box.
   The visible dimmed background is the overlay inside it.
   ============================================ */

dialog.sq-modal {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    overflow: visible;
}

dialog.sq-modal::backdrop {
    background: transparent;
}

/* ============================================
   Modal Overlay - Full Viewport Coverage
   ============================================ */

.modal__overlay,
.login-modal__overlay,
.artisan-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}

/* Pseudo-element to make overlay background clickable for closing */
.modal__overlay::before,
.login-modal__overlay::before,
.artisan-modal-overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: auto;
    z-index: -1;
}

/* Artisan modal uses slightly darker overlay with blur */
.artisan-modal-overlay {
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
}

/* ============================================
   Modal Container Base
   ============================================ */
.modal__container,
.login-modal__container,
.artisan-modal-container {
    position: relative;
    background-color: #ffffff;
    border-radius: 8px;
    /* max-width: 90%; */
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    pointer-events: auto;
    z-index: 1;
}

/* Enhanced shadow for artisan modal */
.artisan-modal-container {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

/* ============================================
   Animations
   ============================================ */

@keyframes sq-modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes sq-modal-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes sq-modal-slide-in {
    from {
        opacity: 0;
        transform: translateY(-15%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes sq-modal-slide-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10%);
    }
}

/* Opening */
dialog.sq-modal[open] [data-modal-overlay] {
    animation: sq-modal-fade-in 0.3s cubic-bezier(0, 0, 0.2, 1);
}

dialog.sq-modal[open] :is(.modal__container, .login-modal__container, .artisan-modal-container) {
    animation: sq-modal-slide-in 0.3s cubic-bezier(0, 0, 0.2, 1);
}

/* Closing (SqModal adds .is-closing, then closes the dialog when these end) */
dialog.sq-modal.is-closing [data-modal-overlay] {
    animation: sq-modal-fade-out 0.3s cubic-bezier(0, 0, 0.2, 1) forwards;
}

dialog.sq-modal.is-closing :is(.modal__container, .login-modal__container, .artisan-modal-container) {
    animation: sq-modal-slide-out 0.3s cubic-bezier(0, 0, 0.2, 1) forwards;
}

@media (prefers-reduced-motion: reduce) {
    dialog.sq-modal [data-modal-overlay],
    dialog.sq-modal :is(.modal__container, .login-modal__container, .artisan-modal-container) {
        animation: none !important;
    }
}

/* ============================================
   Body Scroll Prevention
   (the sq-modal-open class is toggled by SqModal)
   ============================================ */

/* Base: All devices prevent overflow scrolling */
body.sq-modal-open {
    overflow: hidden !important;
}

/* Mobile-specific scroll lock (< 768px)

   Why different from desktop?
   - CANNOT use position: fixed on mobile browsers
   - Causes page to "jump" to scroll position 0 when modal opens
   - Creates jarring visual "jump" when closing and reopening
   - Mobile browsers handle position: fixed differently than desktop

   Solution:
   - Use position: relative + overflow: hidden instead
*/
@media (max-width: 767px) {
    body.sq-modal-open {
        position: relative;
        overflow: hidden;
    }
}

/* Desktop scroll lock (≥ 768px)

   - position: fixed completely prevents background scrolling (mouse wheel, keyboard)
   - SqModal sets body.style.top to the negative scroll offset and restores it on close
   - width and height ensure no content reflow when fixed
*/
@media (min-width: 768px) {
    body.sq-modal-open {
        position: fixed;
        width: 100%;
        height: 100%;
    }
}
