/* ==============================================
   COMPLETE MOBILE PRODUCT PAGE CSS
   Final version - includes all fixes + image cropping fix
   ============================================== */

/* ==============================================
   FLOATING HEADER WITH DESIGN BUTTON
   ============================================== */

.floating-product-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #e5e7eb;
    padding: 0.75rem 1rem;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.floating-product-header.visible {
    transform: translateY(0);
}

.floating-product-header {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    /* Smoother easing curve */
}

.floating-product-header.visible {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Slightly faster appear than disappear */
}

/* Always show floating header on mobile screens */
@media (max-width: 768px) {
    .floating-product-header {
        transform: translateY(0) !important;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(15px);
        box-shadow: 0 2px 15px rgba(0, 0, 0, 0.15);
    }
    
    /* Always apply body offset on mobile */
    body {
        padding-top: 70px !important;
    }
}

.floating-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1280px;
    margin: 0 auto;
    gap: 1rem;
}

.floating-product-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.floating-editor-button {
    background-color: var(--btn-bck);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    transition: background-color 0.2s ease;
}

.floating-editor-button:hover {
    background-color: var(--btn-hover);
    color: white;
    text-decoration: none;
}

.floating-editor-button.disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
    pointer-events: none;
}

/* Offset body content when floating header is visible */
body.floating-header-active {
    padding-top: 70px;
}

/* Mobile floating button adjustments */
@media (max-width: 768px) {
    .floating-editor-button {
        padding: 0.625rem 1rem;
        font-size: 0.8rem;
        border-radius: 8px;
        font-weight: 700;
        box-shadow: 0 2px 8px rgba(29, 181, 190, 0.25);
    }
    
    .floating-product-title {
        font-size: 0.875rem;
    }
}

/* ==============================================
   CSS VARIABLES FOR MOBILE
   ============================================== */

:root {
    --mobile-padding: 1rem;
    --mobile-gallery-height: 60vh;
    --mobile-button-height: 3rem;
    --floating-header-height: 70px;
}

@media (max-width: 480px) {
    :root {
        --mobile-padding: 0.75rem;
        --mobile-gallery-height: 50vh;
        --mobile-button-height: 2.75rem;
        --floating-header-height: 65px;
    }
}

/* ==============================================
   CRITICAL MOBILE LAYOUT FIXES
   ============================================== */

/* Mobile: Stack gallery and summary vertically */
@media (max-width: 1024px) {
    /* Reset gallery and summary to full width on mobile */
    .woocommerce-product-gallery {
        width: 100% !important;
        float: none !important;
        margin-bottom: 2rem;
    }
    
    .woocommerce div.product div.summary {
        width: 100% !important;
        float: none !important;
        clear: both;
    }
    
    /* Force proper mobile layout structure */
    .woocommerce div.product {
        display: block !important;
    }
    
    .woocommerce div.product .summary {
        clear: both !important;
        float: none !important;
        width: 100% !important;
        margin-top: 2rem;
    }
    
    .woocommerce div.product .images {
        float: none !important;
        width: 100% !important;
        margin-bottom: 2rem;
    }
    
    /* Make the main editor button more prominent on mobile */
    .editor-button {
        padding: 1rem 2rem;
        font-size: 1.125rem;
        font-weight: 700;
        margin: 1.5rem 0;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(29, 181, 190, 0.3);
    }
    
    /* Adjust floating button size for mobile */
    .floating-editor-button {
        padding: 0.625rem 1.25rem;
        font-size: 0.8rem;
    }
    
    .floating-product-title {
        font-size: 0.875rem;
    }
}

/* ==============================================
   MOBILE GALLERY COMPLETE OVERHAUL - FIXED
   ============================================== */

@media (max-width: 768px) {
    /* Reset all gallery positioning */
    .woocommerce-product-gallery {
        position: relative !important;
        display: block !important;
        flex-direction: column !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 1rem !important;
    }
    
    /* Main image viewport - FIXED: Auto height to prevent cropping */
    .woocommerce-product-gallery .flex-viewport {
        width: 100% !important;
        height: auto !important; /* Changed from fixed height to auto */
        min-height: 50vh !important; /* Minimum height to prevent too small images */
        max-height: 70vh !important; /* Maximum height to prevent too large images */
        margin: 0 !important;
        order: 0 !important;
        position: relative;
        overflow: hidden;
        border-radius: 8px;
        background: #f9fafb;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Gallery wrapper - FIXED: Auto height */
    .woocommerce-product-gallery__wrapper {
        height: auto !important; /* Changed from 100% to auto */
        display: flex !important;
        transition: transform 0.3s ease !important;
        min-height: inherit !important;
    }
    
    /* Individual gallery images - FIXED: Reduced padding and proper sizing */
    .woocommerce-product-gallery__image {
        width: 100% !important;
        height: auto !important; /* Changed from 100% to auto */
        min-height: 50vh !important; /* Ensure minimum height */
        flex-shrink: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0.5rem !important; /* Reduced from 1rem to 0.5rem */
    }
    
    .woocommerce-product-gallery__image img {
        max-width: calc(100% - 1rem) !important; /* Account for padding */
        max-height: 100% !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain !important; /* Ensure full image is visible */
        object-position: center !important; /* Center the image */
        display: block !important;
        border-radius: 4px !important;
        margin: 0 auto !important; /* Center horizontally */
    }
    
    /* Thumbnail navigation - move below main image */
    .woocommerce div.product div.images .flex-control-thumbs {
        width: 100% !important;
        order: 1 !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        gap: 0.5rem !important;
        margin: 1rem 0 0 0 !important;
        padding: 0.5rem !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        scroll-snap-type: x mandatory;
    }
    
    .woocommerce div.product div.images .flex-control-thumbs::-webkit-scrollbar {
        display: none;
    }
    
    /* Thumbnail items */
    .woocommerce div.product div.images .flex-control-thumbs li {
        width: 60px !important;
        height: 60px !important;
        margin: 0 !important;
        flex-shrink: 0 !important;
        border: 2px solid transparent !important;
        border-radius: 6px !important;
        overflow: hidden !important;
        background: #f9fafb !important;
        scroll-snap-align: center;
    }
    
    .woocommerce div.product div.images .flex-control-thumbs li img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        opacity: 0.6 !important;
        transition: opacity 0.2s ease !important;
        border-radius: 4px !important;
    }
    
    /* Active/hover thumbnail states */
    .woocommerce div.product div.images .flex-control-thumbs li img.flex-active {
        opacity: 1 !important;
        border: 2px solid var(--btn-bck) !important;
    }
    
    .woocommerce div.product div.images .flex-control-thumbs li:hover img {
        opacity: 0.8 !important;
    }
    
    /* Gallery navigation buttons */
    .gallery-nav-button {
        position: absolute !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        background: rgba(255, 255, 255, 0.9) !important;
        border: none !important;
        border-radius: 50% !important;
        width: 40px !important;
        height: 40px !important;
        font-size: 20px !important;
        line-height: 1 !important;
        cursor: pointer !important;
        z-index: 10 !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
        backdrop-filter: blur(4px) !important;
        transition: all 0.2s ease !important;
    }
    
    .gallery-nav-button:hover {
        background: rgba(255, 255, 255, 1) !important;
        transform: translateY(-50%) scale(1.05) !important;
    }
    
    .gallery-prev {
        left: 10px !important;
    }
    
    .gallery-next {
        right: 10px !important;
    }
    
    /* Hide navigation buttons if only one image */
    .woocommerce-product-gallery:has(.flex-control-thumbs li:only-child) .gallery-nav-button {
        display: none !important;
    }
}

/* ==============================================
   MOBILE PRODUCT SUMMARY IMPROVEMENTS
   ============================================== */

@media (max-width: 768px) {
    /* Product title */
    h1.product_title {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
        margin-bottom: 1rem !important;
        padding: 0 1rem !important;
    }
    
    /* Product rating */
    .custom-product-rating {
        padding: 0 1rem !important;
        margin: 1rem 0 !important;
    }
    
    /* Product excerpt */
    .woocommerce-product-details__short-description {
        padding: 0 1rem !important;
        margin-bottom: 1.5rem !important;
    }
    
    /* Variation selectors container */
    .custom-variations-container {
        padding: 0 1rem !important;
        margin-bottom: 2rem !important;
    }
    
    /* Individual variation selectors */
    .color-selector,
    .stitch-color-selector,
    .size-selector {
        margin-bottom: 1.5rem !important;
    }
    
    /* Selector headers */
    .selector-header {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        margin-bottom: 1rem !important;
    }
    
    .selector-header h5 {
        margin: 0 !important;
        font-size: 1rem !important;
    }
    
    .size-guide-link {
        font-size: 0.875rem !important;
        color: var(--btn-bck) !important;
        text-decoration: underline !important;
    }
}

/* ==============================================
   MOBILE VARIATION SELECTORS
   ============================================== */

@media (max-width: 768px) {
    .custom-variations-container {
        margin-bottom: 1.5rem;
    }
    
    /* Improve color selector layout on mobile */
    .color-selector-wrapper,
    .stitch-color-selector-wrapper {
        gap: 0.75rem;
        justify-content: center;
    }
    
    .color-box,
    .stitch-color-box {
        width: 2.25rem;
        height: 2.25rem;
        min-width: 44px;
        min-height: 44px;
        margin: 0.25rem;
    }
    
    /* Size selector improvements */
    .size-selector-wrapper {
        gap: 0.5rem;
        justify-content: center;
    }
    
    .size-box {
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    
    /* Size dropdown adjustments */
    .size-selector select {
        padding: 0.75rem;
        font-size: 1rem;
        border-radius: 6px;
    }
}

/* ==============================================
   MOBILE PRICE AND BUTTON SECTION
   ============================================== */

@media (max-width: 768px) {
    /* Variant container */
    .variant-container {
        padding: 1rem !important;
        margin: 0 !important;
        background: #f9fafb !important;
        border-radius: 8px !important;
        margin: 0 1rem 2rem 1rem !important;
        gap: 1rem;
        padding-top: 1rem;
    }
    
    .variant-info-boxes {
        flex-direction: column;
        gap: 1rem;
    }
    
    .variant-box {
        padding: 1rem;
        border-radius: 6px;
    }
    
    /* Price display */
    .variation-price {
        font-size: 1.5rem !important;
        font-weight: 700 !important;
        color: #1f2937 !important;
        margin-bottom: 1rem !important;
    }
    
    .variant-days {
        font-size: 1rem;
    }
    
    /* Main editor button */
    .editor-button {
        width: 100% !important;
        padding: 1rem 2rem !important;
        font-size: 1.125rem !important;
        font-weight: 700 !important;
        border-radius: 8px !important;
        margin: 1rem 0 !important;
        min-height: var(--mobile-button-height) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        box-shadow: 0 4px 12px rgba(29, 181, 190, 0.25) !important;
        transition: all 0.2s ease !important;
    }
    
    .editor-button:hover:not(.editor-button__disabled) {
        transform: translateY(-1px) !important;
        box-shadow: 0 6px 16px rgba(29, 181, 190, 0.35) !important;
    }
    
    .editor-button__disabled {
        background-color: #9ca3af !important;
        box-shadow: none !important;
        transform: none !important;
    }
}

/* ==============================================
   MOBILE PRODUCT TABS
   ============================================== */

@media (max-width: 768px) {
    /* Tab navigation wrapper */
    .woocommerce-tabs {
        margin-top: 2rem !important;
        padding: 0 1rem !important;
    }
    
    /* Tab list */
    .woocommerce-tabs ul.tabs {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        gap: 0 !important;
        padding: 0 !important;
        margin: 0 0 1rem 0 !important;
        border-bottom: 1px solid #e5e7eb !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }
    
    .woocommerce-tabs ul.tabs::-webkit-scrollbar {
        display: none !important;
    }
    
    /* Individual tabs */
    .woocommerce-tabs ul.tabs li {
        flex-shrink: 0 !important;
        padding: 0 1rem !important;
        margin: 0 !important;
        white-space: nowrap !important;
        min-width: 120px !important;
    }
    
    .woocommerce-tabs ul.tabs li a {
        font-size: 0.9rem !important;
        padding: 0.75rem 0 !important;
        display: block !important;
    }
    
    /* Tab content */
    .woocommerce-Tabs-panel {
        padding: 1rem 0 !important;
    }
}

/* ==============================================
   MOBILE PRODUCT SPECS GRID
   ============================================== */

@media (max-width: 768px) {
    .product-specs-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem;
        padding: 0 1rem;
    }
    
    .product-spec-item {
        padding: 1rem;
        background: #f9fafb;
        border-radius: 8px;
    }
    
    .product-spec-header {
        margin-bottom: 1rem;
        padding-bottom: 1rem;
    }
    
    .product-icon {
        width: 40px;
        height: 40px;
    }
}

/* ==============================================
   VERY SMALL SCREENS (< 480px)
   ============================================== */

@media (max-width: 480px) {
    .floating-header-content {
        padding: 0 0.5rem;
    }
    
    .floating-product-title {
        font-size: 0.8rem;
    }
    
    .floating-editor-button {
        padding: 0.5rem 1rem;
        font-size: 0.75rem;
    }
    
    /* Reduce padding for very small screens */
    .woocommerce-product-gallery {
        padding: 0 0.75rem !important;
    }
    
    /* FIXED: Better gallery sizing for small screens */
    .woocommerce-product-gallery .flex-viewport {
        min-height: 40vh !important;
        max-height: 60vh !important;
    }
    
    .woocommerce-product-gallery__image {
        min-height: 40vh !important;
        padding: 0.25rem !important; /* Even less padding on small screens */
    }
    
    .woocommerce-product-gallery__image img {
        max-width: calc(100% - 0.5rem) !important;
    }
    
    h1.product_title,
    .custom-product-rating,
    .woocommerce-product-details__short-description,
    .custom-variations-container {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    
    .variant-container {
        margin-left: 0.75rem !important;
        margin-right: 0.75rem !important;
        padding: 0.75rem !important;
    }
    
    .woocommerce-tabs {
        padding: 0 0.75rem !important;
    }
    
    /* Even smaller color swatches for very small screens */
    .color-box,
    .stitch-color-box {
        width: 2rem;
        height: 2rem;
    }
    
    /* Smaller thumbnails */
    .woocommerce div.product div.images .flex-control-thumbs li {
        width: 50px !important;
        height: 50px !important;
    }
    
    /* Smaller navigation buttons */
    .gallery-nav-button {
        width: 36px !important;
        height: 36px !important;
        font-size: 18px !important;
    }
    
    .gallery-prev {
        left: 5px !important;
    }
    
    .gallery-next {
        right: 5px !important;
    }
}

/* ==============================================
   REVIEWS SECTION IMPROVEMENTS
   ============================================== */

/* Move reviews summary above the reviews */
#reviews .woocommerce-Reviews {
    display: flex;
    flex-direction: column;
}

/* Target the reviews summary (usually has class .reviews-summary or similar) */
#reviews .reviews-summary,
#reviews .comment-form-rating,
#reviews .woocommerce-Reviews-title + div,
#reviews .woocommerce-Reviews .woocommerce-review-display-meta {
    order: -1; /* Move to top */
    margin-bottom: 2rem;
}

/* Ensure reviews list comes after summary */
#reviews .commentlist,
#reviews ol.commentlist,
#reviews .woocommerce-Reviews .commentlist {
    order: 1;
}

/* Style improvements for reviews summary on mobile */
@media (max-width: 768px) {
    #reviews .reviews-summary {
        padding: 1rem;
        background: #f9fafb;
        border-radius: 8px;
        margin: 0 1rem 2rem 1rem;
    }
    
    #reviews {
        padding: 0 !important;
    }
    
    #reviews .woocommerce-Reviews-title {
        padding: 0 1rem;
        margin-bottom: 1rem;
    }
    
    #reviews .commentlist {
        padding: 0 1rem;
    }
    
    #reviews .comment {
        margin-bottom: 1.5rem;
        padding-bottom: 1.5rem;
        border-bottom: 1px solid #e5e7eb;
    }
}

/* ==============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================== */

@media (max-width: 768px) {
    /* Focus states for touch devices */
    .color-box:focus,
    .stitch-color-box:focus,
    .size-box:focus {
        outline: 3px solid var(--btn-bck) !important;
        outline-offset: 2px !important;
    }
    
    .gallery-nav-button:focus {
        outline: 3px solid var(--btn-bck) !important;
        outline-offset: 2px !important;
    }
    
    /* High contrast support */
    @media (prefers-contrast: high) {
        .gallery-nav-button {
            background: #ffffff !important;
            border: 2px solid #000000 !important;
            color: #000000 !important;
        }
        
        .floating-product-header {
            background: rgba(255, 255, 255, 1) !important;
            border-bottom: 2px solid #000000 !important;
        }
    }
    
    /* Reduced motion support */
    @media (prefers-reduced-motion: reduce) {
        .woocommerce-product-gallery__wrapper {
            transition: none !important;
        }
        
        .gallery-nav-button {
            transition: none !important;
        }
        
        .editor-button {
            transition: none !important;
        }
        
        .editor-button:hover {
            transform: none !important;
        }
        
        .floating-product-header {
            transition: none !important;
        }
    }
}