/**
 * Sparkles Modal Components
 * Modals, dialogs, and overlay patterns
 * Extends: sparkles-utilities.css, sparkles-animations.css, sparkles-tokens.css
 * All 3 optimization layers applied: keyframes consolidated, patterns extracted, component organization
 */

/* ========== MODAL BACKDROP ========== */
.sparkles-modal-backdrop {
    --tw-bg-opacity: 0.5;
}

/* Container query anchors for modal modules */
:where(.sparkles-modal-backdrop,
    .sparkles-quickview-modal,
    .sparkles-drawer) {
    container-type: inline-size;
}

.sparkles-modal-backdrop-active {
    opacity: 1;
    visibility: visible;
}

/* ========== BASE MODAL ========== */
.sparkles-modal {
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    border-radius: .5rem;
    --tw-shadow: 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a;
    --tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);
    max-width: 28rem;
    isolation: isolate;
    width: 100%;
    max-height: 100%;
    overflow: hidden;
}

.sparkles-modal-active {
    transform: scale(1);
    opacity: 1;
    visibility: visible;
}

/* Modal Sizes */
/* .sparkles-modal-sm {
    width: 400px;
} */

.sparkles-modal-md {
    width: 37.5rem;
}

.sparkles-modal-lg {
    width: 50rem;
}

/* .sparkles-modal-xl {
    width: 1200px;
} */

.sparkles-modal-full {
    width: calc(100vw - 2rem);
    /* stylelint-disable-next-line declaration-block-no-duplicate-properties -- dvh fallback for older browsers */
    height: calc(100vh - 2rem);
    height: calc(100dvh - 2rem);
}

/* Modal Header */
.sparkles-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom-width: 1px;
    border-color: var(--gray-200);
}

.sparkles-modal-title {
    font-family: var(--font-display);
    padding-right: 2.5rem;
}

.sparkles-modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    color: var(--gray-400);
    z-index: var(--z-low);
    flex-shrink: 0;
}

/* Modal Body */
.sparkles-modal-body,
.sparkles-cart-items {
    padding: 1.5rem;
    overflow-y: auto;
}

.sparkles-modal-body {
    /* stylelint-disable-next-line declaration-block-no-duplicate-properties -- dvh fallback for older browsers */
    max-height: calc(90vh - 140px);
    max-height: calc(90dvh - 140px);
}

/* Modal Footer */
.sparkles-modal-footer {
    padding: 1.5rem;
    border-top-width: 1px;
    border-color: var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .75rem;
}

/* ========== QUICK VIEW MODAL ========== */
/* .sparkles-quickview-modal {
    width: 900px;
} */

.sparkles-quickview-content {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2rem;
}

.sparkles-quickview-gallery {
    position: relative;
}

.sparkles-quickview-image {
    width: 100%;
    object-fit: cover;
    border-radius: .5rem;
}

.sparkles-quickview-thumbnails {
    display: flex;
    gap: .5rem;
    margin-top: 1rem;
    overflow-x: auto;
}

.sparkles-quickview-thumb {
    width: 5rem;
    height: 5rem;
    object-fit: cover;
    border-radius: .25rem;
    cursor: pointer;
    opacity: .6;
    transition-property: opacity;
    transition-timing-function: cubic-bezier(.4, 0, .2, 1);
    transition-duration: .2s;
    border-width: 2px;
    border-color: #0000;
}

.sparkles-quickview-thumb:hover,
.sparkles-quickview-thumb-active {
    border-color: var(--color-primary);
    opacity: 1;
}

.sparkles-quickview-info {
    display: flex;
    flex-direction: column;
}

/* ========== DRAWER/SLIDE-OUT ========== */
.sparkles-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 20rem;
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    --tw-shadow: 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a;
    --tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);
    transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
    --tw-translate-x: 100%;
    transition-property: transform;
    transition-duration: .3s;
    transition-timing-function: cubic-bezier(0, 0, .2, 1);
    z-index: var(--z-fixed);
    isolation: isolate;
}

/* Drawer Positions */
.sparkles-drawer-left {
    left: 0;
    --tw-translate-x: -100%;
}

.sparkles-drawer-right {
    right: 0;
    --tw-translate-x: 100%;
}

.sparkles-drawer-active.sparkles-drawer-left,
.sparkles-drawer-active.sparkles-drawer-right {
    --tw-translate-x: 0px;
}

/* Drawer Sizes */
/* .sparkles-drawer-sm {
    width: 300px;
} */

/* .sparkles-drawer-md {
    width: 400px;
} */

/* .sparkles-drawer-lg {
    width: 600px;
} */

/* Drawer Header */
.sparkles-drawer-header {
    z-index: var(--z-dropdown);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom-width: 1px;
    border-color: var(--gray-200);
    position: sticky;
    top: 0;
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
}

.sparkles-drawer-body {
    padding: 1.5rem;
}

/* ========== CART DRAWER ========== */
/* .sparkles-cart-drawer {
    width: 400px;
} */

.sparkles-cart-items {
    /* stylelint-disable-next-line declaration-block-no-duplicate-properties -- dvh fallback for older browsers */
    max-height: calc(100vh - 280px);
    max-height: calc(100dvh - 280px);
}

.sparkles-cart-item {
    display: flex;
    gap: 1rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
    border-bottom-width: 1px;
    border-color: var(--gray-200);
}

.sparkles-cart-item-image {
    width: 5rem;
    height: 5rem;
    object-fit: cover;
    border-radius: .5rem;
}

.sparkles-cart-item-info {
    flex: 1 1 0%;
}

.sparkles-cart-item-title,
.sparkles-product-card-minimal .sparkles-product-title {
    color: var(--color-secondary);
    font-weight: 500;
    margin-bottom: .5rem;
}

.sparkles-cart-item-meta {
    margin-bottom: .5rem;
}

.sparkles-cart-footer {
    position: sticky;
    bottom: 0;
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    border-top-width: 1px;
    border-color: var(--gray-200);
    padding: 1.5rem;
}

.sparkles-cart-summary {
    margin-bottom: 1rem;
}

.sparkles-cart-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

/* ========== NOTIFICATION MODAL ========== */
.sparkles-notification {
    position: fixed;
    top: 1rem;
    right: 1rem;
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    border-radius: .5rem;
    --tw-shadow: 0 10px 15px -3px #0000001a, 0 4px 6px -4px #0000001a;
    --tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
    border-width: 1px;
    border-color: var(--gray-200);
    padding: 1rem;
    max-width: 24rem;
    z-index: var(--z-notification);
    transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
    --tw-translate-x: 100%;
    transition-property: transform;
    transition-duration: .3s;
    transition-timing-function: cubic-bezier(0, 0, .2, 1);
}

.sparkles-notification-active {
    --tw-translate-x: 0px;
}

.sparkles-notification-content,
.sparkles-faq-question {
    display: flex;
    gap: .75rem;
    align-items: flex-start;
}

.sparkles-notification-icon {
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
}

.sparkles-notification-success .sparkles-notification-icon {
    --tw-text-opacity: 1;
    color: rgba(16, 185, 129, var(--tw-text-opacity, 1));
}

.sparkles-notification-error .sparkles-notification-icon {
    --tw-text-opacity: 1;
    color: rgba(239, 68, 68, var(--tw-text-opacity, 1));
}

.sparkles-notification-warning .sparkles-notification-icon {
    --tw-text-opacity: 1;
    color: rgba(245, 158, 11, var(--tw-text-opacity, 1));
}

.sparkles-notification-body {
    flex: 1 1 0%;
}

.sparkles-notification-title {
    font-weight: 600;
    margin-bottom: .25rem;
}

.sparkles-notification-progress {
    height: 3px;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--gray-200);
    border-bottom-right-radius: .5rem;
    border-bottom-left-radius: .5rem;
    overflow: hidden;
}

.sparkles-notification-progress-bar {
    background-color: var(--color-primary);
    animation: notification-progress 5s linear;
    /* Keep raw for animation */
    height: 100%;
}

/* notification-progress keyframe moved to sparkles-animations.css */

/* ========== LIGHTBOX ========== */
.sparkles-lightbox {
    --tw-bg-opacity: 0.9;
}

.sparkles-lightbox-active {
    opacity: 1;
    visibility: visible;
}

.sparkles-lightbox-image {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
}

.sparkles-lightbox-controls {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    gap: .75rem;
    z-index: var(--z-low);
}

.sparkles-lightbox-btn {
    position: absolute;
    transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
    width: 3rem;
    height: 3rem;
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    --tw-bg-opacity: 0.2;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    --tw-text-opacity: 1;
    color: rgba(255, 255, 255, var(--tw-text-opacity, 1));
    transition-property: all;
    transition-timing-function: cubic-bezier(.4, 0, .2, 1);
    transition-duration: .2s;
}

.sparkles-lightbox-btn:hover {
    --tw-bg-opacity: 0.4;
    --tw-scale-x: 1.1;
    --tw-scale-y: 1.1;
}

/* ========== CONFIRM DIALOG ========== */
.sparkles-confirm {
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    border-radius: .5rem;
    --tw-shadow: 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a;
    --tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);
    padding: 1.5rem;
    max-width: 24rem;
    width: 100%;
    text-align: center;
}

.sparkles-confirm-icon {
    --sparkles-icon-color: rgba(245, 158, 11, var(--tw-text-opacity, 1));
}

.sparkles-confirm-title,
.sparkles-blog-card .sparkles-post-title {
    color: var(--color-secondary);
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: .75rem;
}

.sparkles-confirm-title {
    line-height: 1.75rem;
}

.sparkles-confirm-message {
    color: var(--gray-600);
    margin-bottom: 1.5rem;
}

.sparkles-confirm-actions {
    gap: .75rem;
    justify-content: center;
}

/* ========== ANIMATIONS - MOVED TO CENTRAL LOCATION ========== */
/* modal-fade-in keyframe moved to sparkles-animations.css */
/* drawer-slide-in keyframe moved to sparkles-animations.css */
/* modal-bounce-in keyframe moved to sparkles-animations.css */

/* ========== RESPONSIVE DESIGN ========== */
@container (max-width: 768px) {
    .sparkles-modal-backdrop {
        padding: 0.5rem;
    }

    .sparkles-modal {
        width: calc(100vw - 1rem);
        /* stylelint-disable-next-line declaration-block-no-duplicate-properties -- dvh fallback for older browsers */
        max-height: calc(100vh - 1rem);
        max-height: calc(100dvh - 1rem);
        margin: 0 auto;
    }

    .sparkles-modal-sm,
    .sparkles-modal-md,
    .sparkles-modal-lg,
    .sparkles-modal-xl {
        width: calc(100vw - 1rem);
    }

    .sparkles-quickview-content {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }

    .sparkles-quickview-image {
        height: 300px;
    }

    .sparkles-drawer-sm,
    .sparkles-drawer-md,
    .sparkles-drawer-lg,
    .sparkles-cart-drawer {
        width: 100vw;
    }

}

/* ========== ACCESSIBILITY ========== */
/* Focus trap */
.sparkles-modal:focus,
.sparkles-drawer:focus {
    outline: 2px solid #0000;
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

    .sparkles-modal,
    .sparkles-modal-backdrop,
    .sparkles-drawer,
    .sparkles-notification,
    .sparkles-lightbox {
        animation: none;
    }
}

/* High contrast */
@media (prefers-contrast: high) {

    .sparkles-modal,
    .sparkles-drawer {
        border-width: 2px;
        border-style: solid;
    }
}
