/* DESKTOP MODAL - PREMIUM APPLE-INSPIRED DESIGN */

@media (min-width: 768px) {
    /* Modal Backdrop - Frosted Glass Effect */
    .modal-backdrop {
        --modal-width: 1000px;
        --modal-height: 650px;
        --poster-gap: 56px;
        --poster-width: 280px;
        position: fixed !important;
        inset: 0 !important;
        background: rgba(0, 0, 0, 0.25) !important;
        backdrop-filter: blur(40px) saturate(1.8) !important;
        -webkit-backdrop-filter: blur(40px) saturate(1.8) !important;
        z-index: 9999 !important;
        display: none !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
        opacity: 0 !important;
        transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
    }

    .modal-backdrop.modal-show {
        opacity: 1 !important;
        display: flex !important;
    }

    /* Close Button - Simple positioning inside modal container */
    .modal-close-btn {
        position: absolute;
        top: -20px; /* Outside modal top edge */
        right: -20px; /* Outside modal right edge */
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(128, 128, 128, 0.8);
        color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 10002; /* Higher than modal content */
        border: 2px solid rgba(255, 255, 255, 0.2);
        transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); /* Add shadow for visibility */
    }

    /* Close button positioning is now automatic - no manual positioning needed! */
    
    .modal-close-btn svg {
        width: 22px;
        height: 22px;
        stroke: #ffffff;
        stroke-width: 3.5;
    }
    
    /* Inline Star Icon */
    .inline-star {
        display: inline-block;
        vertical-align: middle;
        margin: 0 2px;
    }

    .modal-close-btn:hover {
        background: rgba(96, 96, 96, 0.9);
        border-color: rgba(255, 255, 255, 0.4);
        transform: scale(1.05);
    }

    .modal-close-btn:active {
        transform: scale(0.95);
        background: rgba(64, 64, 64, 0.9);
    }

    /* Modal Flex Wrapper - Owns layout for modal + poster */
    .modal-flex-wrapper {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--poster-gap);
        width: 100%;
        height: 100%;
        padding: 0 48px;
        box-sizing: border-box;
    }

    /* Floating Poster Preview - Layout-driven, no absolute positioning */
    .floating-poster-container {
        width: var(--poster-width);
        height: calc(var(--poster-width) * 1.5);
        display: none;
        flex: 0 0 auto;
        align-items: center;
        justify-content: center;
        position: relative;
        pointer-events: none;
        perspective: 1200px;
        transition: opacity 0.4s ease;
        opacity: 0;
        z-index: 10001;
    }

    .floating-poster-container.is-visible {
        display: flex;
        opacity: 1;
    }

    .poster-wrapper {
        width: 100%;
        height: 100%;
        position: relative;
        transform-style: preserve-3d;
        animation: posterRotate 20s linear infinite;
    }

    .poster {
        width: 100%;
        height: 100%;
        position: absolute;
        transform-style: preserve-3d;
        animation: posterFlutter 3s ease-in-out infinite;
    }

    .poster-face {
        position: absolute;
        width: 100%;
        height: 100%;
        backface-visibility: hidden;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    }

    .poster-front {
        background: transparent;
        transform: translateZ(3px);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0;
    }

    .poster-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .poster-back {
        background: #ffffff;
        transform: rotateY(180deg) translateZ(3px);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #333;
        font-size: 24px;
        font-weight: bold;
        text-align: center;
        padding: 20px;
        border: 1px solid #e0e0e0;
    }

    .poster-back-content {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 16px;
    }

    .poster-back-logo {
        width: 80px;
        height: 80px;
        object-fit: contain;
    }

    .poster-edge {
        position: absolute;
        background: #333;
        backface-visibility: hidden;
    }

    .poster-edge-top {
        width: 100%;
        height: 6px;
        top: -3px;
        left: 0;
        transform: rotateX(90deg) translateZ(3px);
        background: linear-gradient(to bottom, #555, #333);
    }

    .poster-edge-bottom {
        width: 100%;
        height: 6px;
        bottom: -3px;
        left: 0;
        transform: rotateX(-90deg) translateZ(3px);
        background: linear-gradient(to top, #555, #333);
    }

    .poster-edge-left {
        width: 6px;
        height: 100%;
        top: 0;
        left: -3px;
        transform: rotateY(-90deg) translateZ(3px);
        background: linear-gradient(to right, #555, #333);
    }

    .poster-edge-right {
        width: 6px;
        height: 100%;
        top: 0;
        right: -3px;
        transform: rotateY(90deg) translateZ(3px);
        background: linear-gradient(to left, #555, #333);
    }

    @keyframes posterRotate {
        0% {
            transform: rotateY(0deg) rotateX(6deg) rotateZ(-2deg);
        }
        100% {
            transform: rotateY(360deg) rotateX(6deg) rotateZ(-2deg);
        }
    }

    @keyframes posterFlutter {
        0%,
        100% {
            transform: rotateX(0deg) translateY(0px);
        }
        25% {
            transform: rotateX(2deg) translateY(-5px);
        }
        50% {
            transform: rotateX(-1deg) translateY(0px);
        }
        75% {
            transform: rotateX(1deg) translateY(-3px);
        }
    }

    @media (max-width: 1400px) {
        .floating-poster-container {
            display: none !important;
        }
    }

    /* Modal Container - Centered by backdrop's flex properties */
    .modal-container {
        position: relative;
        width: var(--modal-width) !important;
        height: var(--modal-height) !important;
        background: white;
        border-radius: 20px;
        box-shadow: 0 32px 64px -12px rgba(0, 0, 0, 0.15);
        display: flex;
        overflow: visible; /* Allow close button to show outside modal bounds */
        flex-shrink: 0;
        z-index: 10000;
    }

    .modal-backdrop.modal-show .modal-container {
        transform: scale(1) translateY(0) !important;
        opacity: 1 !important;
    }

    /* Image Section - Left Side - Exact 2:3 aspect ratio */
    .modal-image-section {
        flex: 0 0 433px !important; /* Exact width for 2:3 ratio (650px height ÷ 3 × 2) */
        height: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: #f8fafc !important;
        position: relative !important;
        overflow: hidden !important;
        padding: 0 !important; /* No padding - edge to edge */
    }

    /* Hide Mobile-Specific Elements on Desktop */
    .modal-pull-indicator {
        display: none !important;
    }

    .modal-image-container {
        display: contents !important;
    }

    .modal-content-padding {
        display: contents !important;
    }

    /* Make scrollable wrapper transparent on desktop - should not affect layout */
    .modal-scrollable-wrapper {
        display: contents !important; /* This makes the wrapper transparent to layout */
    }

    /* Product Image - Perfect 2:3 aspect ratio, edge to edge */
    .modal-product-image {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important; /* Cover maintains aspect ratio and fills space */
        object-position: center !important;
        border-radius: 0 !important; /* No border radius for edge to edge */
    }

    /* Content Section - Right Side */
    .modal-content {
        flex: 1 !important; /* Takes remaining space after image section */
        height: 100% !important;
        padding: 40px 36px 20px 36px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
        background: rgba(255, 255, 255, 0.95) !important;
        justify-content: flex-start !important;
        overflow-y: auto !important;
        border-radius: 0 20px 20px 0 !important; /* Match modal border radius on right side */
    }

    /* Top Section - Title & Rating */
    .modal-top-section {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    /* Product Title - Dynamic */
    .modal-product-title {
        font-size: 24px;
        font-weight: 700;
        color: #1d1d1f;
        margin: 0;
        line-height: 1.2;
        letter-spacing: -0.015em;
        text-align: center;
    }

    /* Product Subtitle - Small grey text */
    .modal-product-subtitle {
        font-size: 14px;
        font-weight: 700;
        color: #8e8e93;
        margin: 2px 0 0 0;
        text-align: center;
        line-height: 1.2;
    }

    /* Star Rating - Live Display */
    .modal-product-rating {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 10px 14px;
        background: rgba(242, 242, 247, 0.6);
        backdrop-filter: blur(10px);
        border-radius: 4px;
    }

    .modal-stars {
        display: flex;
        gap: 2px;
    }

    .modal-stars .star {
        width: 14px;
        height: 14px;
        fill: #ff9500;
        color: #ff9500;
    }

    .modal-rating-text {
        font-size: 13px;
        color: #8e8e93;
        font-weight: 500;
    }

    /* Middle Section - Sizes & Price */
    .modal-middle-section {
        display: flex;
        flex-direction: column;
        gap: 20px;
        flex: 1;
    }

    /* Size Selection - Premium Buttons */
    .modal-size-section {
        margin: 0;
    }

    .modal-section-title {
        font-size: 18px;
        font-weight: 600;
        color: #1d1d1f;
        margin: 0 0 12px 0;
        text-align: center;
        letter-spacing: -0.01em;
    }

    .modal-size-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .modal-size-btn {
        padding: 14px 10px;
        border: none;
        background: rgba(255, 255, 255, 0.9);
        color: #1d1d1f;
        cursor: pointer;
        text-align: center;
        transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        border-radius: 14px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        backdrop-filter: blur(10px);
        position: relative;
    }

    .modal-size-name {
        font-size: 15px;
        font-weight: 600;
        color: #1d1d1f;
    }

    .modal-size-dimensions {
        font-size: 11px;
        color: #8e8e93;
        font-weight: 400;
    }

    .modal-size-btn:hover {
        background: rgba(255, 255, 255, 1);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    .modal-size-btn.selected {
        background: #007aff;
        color: white;
        transform: translateY(-1px);
        box-shadow: 0 6px 16px rgba(0, 122, 255, 0.25);
    }

    .modal-size-btn.selected .modal-size-name {
        color: white;
    }

    .modal-size-btn.selected .modal-size-dimensions {
        color: rgba(255, 255, 255, 0.8);
    }

    /* Price Display */
    .modal-price-section {
        background: rgba(248, 248, 248, 0.8);
        backdrop-filter: blur(20px);
        padding: 18px;
        border-radius: 18px;
        text-align: center;
    }

    .modal-price-display {
        display: flex;
        align-items: baseline;
        justify-content: center;
        gap: 8px;
        margin-bottom: 10px;
        min-height: 32px; /* Ensure consistent height whether note is shown or not */
    }

    .modal-current-price {
        font-size: 28px;
        font-weight: 700;
        color: #1d1d1f;
        letter-spacing: -0.02em;
    }

    .modal-price-note {
        font-size: 10px;
        color: #30d158;
        background: rgba(48, 209, 88, 0.1);
        padding: 3px 6px;
        border-radius: 6px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        display: none; /* Hidden by default, shown only for A3 */
    }

    .modal-shipping-info {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        font-size: 12px;
        color: #8e8e93;
        font-weight: 500;
    }

    .modal-shipping-icon {
        color: #30d158;
        width: 14px;
        height: 14px;
    }

    /* Premium Features */
    .modal-features {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        background: rgba(242, 242, 247, 0.5);
        backdrop-filter: blur(10px);
        padding: 16px;
        border-radius: 16px;
    }

    .modal-feature-item {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 12px;
        color: #1d1d1f;
        font-weight: 500;
        padding: 0;
    }

    .modal-feature-icon {
        color: #007aff;
        width: 14px;
        height: 14px;
        flex-shrink: 0;
    }

    /* Bottom Section - Add to Cart - Fixed Position */
    .modal-cart-section {
        position: sticky;
        bottom: 0;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        padding: 16px 0 0 0;
        margin-top: auto;
    }

    /* Button Container */
    .modal-button-container {
        display: flex;
        gap: 12px;
        align-items: center;
    }

    /* Back Button - Complementary Orange */
    .modal-back-btn {
        width: 20%;
        padding: 16px 12px;
        background: #000000;
        color: white;
        border: none;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        border-radius: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
        flex-shrink: 0;
    }

    .modal-back-btn:hover {
        background: #111111;
        transform: translateY(-1px);
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    }

    .modal-back-btn:active {
        transform: scale(0.98);
        background: #222222;
    }

    .modal-back-icon {
        width: 16px;
        height: 16px;
    }

    .modal-add-to-cart-btn {
        flex: 1;
        padding: 16px 20px;
        background: #007aff;
        color: white;
        border: none;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        border-radius: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        box-shadow: 0 4px 16px rgba(0, 122, 255, 0.25);
    }

    .modal-add-to-cart-btn:hover {
        background: #0051d5;
        transform: translateY(-1px);
        box-shadow: 0 6px 24px rgba(0, 122, 255, 0.35);
    }

    .modal-add-to-cart-btn:active {
        transform: scale(0.98);
        background: #004bb5;
    }

    .modal-cart-icon {
        width: 18px;
        height: 18px;
    }

    /* Reviews Section */
    .modal-reviews-section {
        margin-top: 20px;
        padding: 20px;
        background: #f8f9fa;
        border-radius: 12px;
        margin-bottom: 20px;
    }

    .modal-reviews-section .modal-section-title {
        color: #1d1d1f;
        font-size: 18px;
        font-weight: 600;
        margin: 0 0 16px 0;
        text-align: center;
    }

    .modal-reviews-container {
        display: flex;
        flex-direction: column;
        gap: 16px;
        max-height: none;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
    }

    .modal-review-item {
        background: #ffffff;
        padding: 16px;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .modal-review-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 8px;
    }

    .modal-review-author {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .modal-review-name {
        font-size: 14px;
        font-weight: 600;
        color: #1d1d1f;
    }

    .modal-review-date {
        font-size: 12px;
        color: #8e8e93;
    }

    .modal-review-stars {
        display: flex;
        gap: 2px;
    }

    .modal-review-star.filled {
        color: #ff9500;
        fill: #ff9500;
    }

    .modal-review-star.empty {
        color: #d1d5db;
        stroke: #d1d5db;
    }

    .modal-review-comment {
        font-size: 13px;
        color: #374151;
        line-height: 1.4;
        margin: 0;
    }

    /* Large Desktop */
    @media (min-width: 1200px) {
        .modal-container {
            width: var(--modal-width) !important; /* Fixed size - never changes */
            height: var(--modal-height) !important; /* Fixed size - never changes */
        }

        .modal-content {
            padding: 44px 40px;
        }

        .modal-product-title {
            font-size: 28px;
        }

        .modal-current-price {
            font-size: 32px;
        }
        
        /* Close button positioning is automatic now - no complex calculations needed! */
    }
    
    /* Ultra-wide screens */
    @media (min-width: 1600px) {
        /* Ultra-wide screen adjustments - modal stays same size */
        .modal-container {
            width: var(--modal-width) !important; /* Fixed size - never changes */
            height: var(--modal-height) !important; /* Fixed size - never changes */
        }

        /* Close button positioning is automatic now - works on all screen sizes! */
    }
}

/* Prevent background scrolling */
body.modal-open {
    overflow: hidden;
}

@media (min-width: 768px) {
    body.modal-open {
        transform: none !important;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .modal-backdrop,
    .modal-container,
    .modal-close-btn,
    .modal-size-btn,
    .modal-add-to-cart-btn {
        transition: none !important;
    }
}
