/* Custom Cart Table Widget Styles */

.custom-cart-table {
    width: 100%;
}

.custom-cart-table__wrapper {
    display: flex;
    flex-direction: column;
}

/* Table Body */
.custom-cart-table__body {
    display: flex;
    flex-direction: column;
    gap: 30px;
    padding: 20px 0;
}

/* New Flexbox Layout for Cart Items */
.custom-cart-table__body-item {
    display: flex;
    align-items: stretch; /* Changed from flex-start - allows content to match image height */
    gap: 50px;
    width: 100%;
}

/* Product Content Wrapper (Right side of image) */
.custom-cart-table .product-content-wrapper {
    display: flex;
    flex: 1;
    justify-content: space-between;
    align-items: stretch; /* Changed from flex-start - allows left and right content to match image height */
    min-width: 0; /* Allow flex shrinking */
}

/* Left Content (Title, Variations, Price, Quantity) */
.custom-cart-table .product-left-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

/* Right Content (Subtotal top, Remove bottom) */
.custom-cart-table .product-right-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
    align-self: stretch; /* Stretch to match left content height */
    min-width: 0;
}

/* Product Title - Default styles (Elementor controls can override) */
.custom-cart-table .product-title {
    margin: 0;
    margin-bottom: 4px;
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 700; /* Standardized to 700 per design guidelines */
    line-height: 1.5; /* Standardized to 1.5 per design guidelines */
    color: #000000; /* Black */
}

/* Product Title Link - Override theme/WooCommerce link colors */
.custom-cart-table .product-title a,
.woocommerce .custom-cart-table .product-title a {
    color: #000000 !important; /* Black - override theme link colors */
}

.custom-cart-table .product-variations {
    margin: 0;
    margin-bottom: 4px;
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5; /* Standardized to 1.5 per design guidelines */
    color: #7a7a7a;
}

/* Product Price - Default styles */
.custom-cart-table .product-price {
    margin: 0;
    margin-bottom: auto; /* Push quantity to bottom */
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5; /* Standardized to 1.5 per design guidelines */
    color: #7a7a7a;
}

/* Original Price (on sale) - matches order details style */
.custom-cart-table .product-price del,
.custom-cart-table .product-price .woocommerce-Price-amount.amount del {
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 400;
    color: #7a7a7a; /* Gray - matches variations & price */
    text-decoration: line-through;
    margin-right: 8px;
}

/* Sale Price - matches order details style */
.custom-cart-table .product-price ins,
.custom-cart-table .product-price .woocommerce-Price-amount.amount ins {
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 400;
    color: #7a7a7a; /* Gray - matches regular price color */
    text-decoration: none; /* Remove underline from ins tag */
    display: inline; /* Ensure inline display */
}

/* Product Quantity - Bottom aligned */
.custom-cart-table .product-quantity {
    margin-top: auto; /* Push to bottom, align with image bottom */
}

/* Product Subtotal - Top right, same height as title, bold, right-aligned */
.custom-cart-table .product-subtotal {
    margin: 0;
    margin-bottom: auto; /* Push remove button to bottom */
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 700; /* Standardized to 700 per design guidelines */
    line-height: 1.5; /* Standardized to 1.5 per design guidelines */
    color: inherit;
    text-align: right;
}

.custom-cart-table .product-subtotal .cart-item-subtotal {
    display: inline-block;
    text-align: right;
}

/* Product Thumbnail - Left side, 150px width, maintains natural aspect ratio */
.custom-cart-table .product-thumbnail {
    position: relative;
    display: block;
    flex-shrink: 0;
    width: 150px;
    min-width: 150px;
    /* No fixed height - let image maintain natural aspect ratio */
}

.custom-cart-table .product-thumbnail img {
    object-fit: cover;
    width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid #f2f2f2;
    display: block;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.custom-cart-table .product-thumbnail a {
    display: block;
    width: 100%;
}

/* Remove Button - Bottom right, hover-reveal, text link */
.custom-cart-table .product-remove {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    margin-top: auto; /* Push to bottom, align with quantity control */
}

.custom-cart-table__body-item:hover .product-remove {
    opacity: 1;
    visibility: visible;
}

.custom-cart-table .product-remove a.remove_from_cart_button {
    display: inline-block;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: 400;
    color: #7a7a7a;
    background-color: transparent;
    padding: 0;
    border: none;
}

/* Override WooCommerce default red color */
.woocommerce .custom-cart-table .product-remove a.remove_from_cart_button {
    color: #7a7a7a !important;
    text-decoration: underline !important;
}

.custom-cart-table .product-remove a.remove_from_cart_button:hover {
    color: #5a5a5a;
    text-decoration: underline;
}

/* Quantity Controls - No border, menu cart style */
.custom-cart-quantity {
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 0;
    overflow: visible;
    margin: 0;
    padding: 0;
}

.custom-cart-quantity .minus-button {
    display: inline-block;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700; /* Standardized to 700 per design guidelines */
    line-height: 1;
    transition: all 0.3s ease;
    user-select: none;
    padding: 2px 2px;
    margin: 0;
    color: #101010; /* Standardized to #101010 per design guidelines */
    flex-shrink: 0;
}

.custom-cart-quantity .minus-button.disabled,
.custom-cart-quantity .plus-button.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    background: none;
}

.custom-cart-quantity .quantity {
    display: inline-block;
    border: none;
    margin: 0;
    padding: 0;
}

.custom-cart-quantity .quantity .quantity-text {
    display: inline-block;
    text-align: center;
    font-size: 14px;
    font-weight: normal;
    min-width: 20px;
    padding: 2px 4px;
    color: inherit;
}

.custom-cart-quantity .quantity input[type="hidden"] {
    display: none;
}

.custom-cart-quantity .plus-button {
    display: inline-block;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700; /* Standardized to 700 per design guidelines */
    line-height: 1;
    transition: all 0.3s ease;
    user-select: none;
    padding: 2px 2px;
    margin: 0;
    color: #101010; /* Standardized to #101010 per design guidelines */
    flex-shrink: 0;
}

.custom-cart-quantity .minus-button:hover,
.custom-cart-quantity .plus-button:hover {
    background: none;
    border: none;
}

.custom-cart-quantity .quantity input[type="number"]::-webkit-outer-spin-button,
.custom-cart-quantity .quantity input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Empty cart message */
.custom-cart-table__empty {
    text-align: center;
    padding: 40px 20px;
}

.custom-cart-table__empty p {
    font-family: Arial, sans-serif !important;
    font-size: 14px !important;
    font-weight: 400 !important;
    line-height: 1.5 !important; /* Match design guidelines */
    color: #101010 !important; /* Standard text color */
    margin: 0 0 10px 0 !important;
}

/* Editor hint message (for Elementor editor preview) */
.custom-cart-table__editor-hint {
    font-family: Arial, sans-serif !important;
    font-size: 14px !important; /* Standard size, not 12px */
    font-weight: 400 !important;
    line-height: 1.5 !important; /* Match design guidelines */
    color: #999999 !important; /* Full hex, match design guidelines */
    margin-top: 10px !important;
    margin-bottom: 0 !important;
}

/* Responsive - Mobile Card Layout (matching order details pattern) */
@media (max-width: 768px) {
    /* Ensure full width on mobile */
    .custom-cart-table {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .custom-cart-table__wrapper {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .custom-cart-table__body {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* Card Layout - Row (image left, content right) */
    .custom-cart-table__body-item {
        flex-direction: row !important;
        align-items: flex-start !important;
        gap: 15px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Product Image - 80px width, 3:4 aspect ratio */
    .custom-cart-table .product-thumbnail {
        flex-shrink: 0 !important;
        width: 80px !important;
        min-width: 80px !important;
        max-width: 80px !important;
        display: flex !important;
        align-items: flex-start !important;
        justify-content: flex-start !important;
        margin: 0 !important;
    }
    
    .custom-cart-table .product-thumbnail img {
        width: 80px !important;
        height: auto !important;
        max-width: 80px !important;
        min-width: 80px !important;
        object-fit: cover !important;
        -webkit-aspect-ratio: 3 / 4 !important; /* Safari prefix */
        aspect-ratio: 3 / 4 !important;
        border-radius: 4px !important;
        display: block !important;
    }
    
    /* ============================================
       SINGLE-COLUMN GRID LAYOUT
       Title/Remove and Quantity/Subtotal in same rows
       ============================================ */
    
    /* Content Wrapper - Single column grid with explicit rows */
    .custom-cart-table .product-content-wrapper {
        flex: 1 1 auto !important;
        display: grid !important;
        grid-template-columns: 1fr !important; /* Single column, full width */
        grid-template-rows: auto auto auto 1fr auto !important; /* Row 1: Title+Remove, Row 2: Variations, Row 3: Price, Row 4: Space, Row 5: Quantity+Subtotal */
        gap: 4px !important; /* Gap between rows */
        min-width: 0 !important;
        height: calc(80px * 4 / 3) !important;
        min-height: calc(80px * 4 / 3) !important;
        margin: 0 !important;
        padding: 0 !important;
        position: relative !important; /* For absolute positioning of remove and subtotal */
    }
    
    /* Flatten structure - children become direct grid items */
    .custom-cart-table .product-left-content,
    .custom-cart-table .product-right-content {
        display: contents !important; /* Makes children act as direct grid children */
    }
    
    /* Row 1: Product Title (left side, with padding for remove button) */
    .custom-cart-table .product-title {
        grid-row: 1 !important;
        margin: 0 !important;
        padding: 0 !important;
        padding-right: 80px !important; /* Space for remove button on the right */
        line-height: 1.25 !important;
    }
    
    /* Row 1: Product Remove (right side, absolute positioned) */
    .custom-cart-table .product-remove {
        grid-row: 1 !important;
        position: absolute !important;
        right: 0 !important;
        top: 0 !important;
        opacity: 1 !important;
        visibility: visible !important;
        margin: 0 !important;
        padding: 0 !important;
        line-height: 12px !important;
    }
    
    /* Product Remove Link */
    .custom-cart-table .product-remove a.remove_from_cart_button {
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Row 2: Product Variations */
    .custom-cart-table .product-variations {
        grid-row: 2 !important;
        margin: 0 !important;
        line-height: 1.25 !important;
    }
    
    /* Row 3: Product Price */
    .custom-cart-table .product-price {
        grid-row: 3 !important;
        margin: 0 !important;
        margin-bottom: 0 !important; /* Override desktop margin-bottom: auto */
        line-height: 1.25 !important;
    }
    
    /* Row 5: Product Quantity (left side, with padding for subtotal) */
    .custom-cart-table .product-quantity {
        grid-row: 5 !important;
        margin: 0 !important;
        padding-right: 100px !important; /* Space for subtotal on the right */
        line-height: 17px !important;
    }
    
    /* Row 5: Product Subtotal (right side, absolute positioned) */
    .custom-cart-table .product-subtotal {
        grid-row: 5 !important;
        position: absolute !important;
        right: 0 !important;
        bottom: 0 !important;
        text-align: right !important;
        margin: 0 !important;
        line-height: 21px !important;
    }
}

/* Loading states removed - UI updates instantly without visual delays */
/* Ensure no opacity changes or gray-out effects during updates */
.custom-cart-table__body-item,
.custom-cart-table__body-item.updating-cart,
.custom-cart-table__body-item .cart-item-subtotal,
.custom-cart-table__body-item .cart-item-subtotal.loading {
    opacity: 1 !important;
    transition: none !important;
}

#custom-cart-totals-widget,
#custom-cart-totals-widget.loading,
#custom-cart-totals-widget.updating-cart {
    opacity: 1 !important;
    transition: none !important;
}

/* Prevent WooCommerce from adding loading states to our custom cart table */
.woocommerce .custom-cart-table__body-item.updating-cart,
.woocommerce .custom-cart-table__body-item.loading,
.woocommerce .custom-cart-table__body-item .cart-item-subtotal.loading,
.woocommerce .custom-cart-table__body-item .cart-item-subtotal.updating {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Prevent WooCommerce loading spinner - hide ALL loading spinners */
.custom-cart-table__body-item .cart-item-subtotal.loading::after,
.custom-cart-table__body-item .cart-item-subtotal.loading::before,
.custom-cart-table__body-item .cart-item-subtotal.updating::after,
.custom-cart-table__body-item .cart-item-subtotal.updating::before,
.woocommerce .custom-cart-table__body-item .cart-item-subtotal.loading::after,
.woocommerce .custom-cart-table__body-item .cart-item-subtotal.loading::before,
.woocommerce .custom-cart-table__body-item .cart-item-subtotal.updating::after,
.woocommerce .custom-cart-table__body-item .cart-item-subtotal.updating::before,
.custom-cart-table__body-item.loading::after,
.custom-cart-table__body-item.loading::before,
.custom-cart-table__body-item.updating-cart::after,
.custom-cart-table__body-item.updating-cart::before,
.woocommerce .custom-cart-table__body-item.loading::after,
.woocommerce .custom-cart-table__body-item.loading::before,
.woocommerce .custom-cart-table__body-item.updating-cart::after,
.woocommerce .custom-cart-table__body-item.updating-cart::before {
    display: none !important;
    content: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Prevent font changes during update (FOUC fix) - but allow Elementor controls to work */
/* Only apply to elements that don't have Elementor typography controls */
.custom-cart-table__body-item.updating-cart:not([class*="elementor"]),
.custom-cart-table__body-item.loading:not([class*="elementor"]) {
    /* Only prevent transitions, not font properties */
    transition: none !important;
}

/* Allow Elementor typography controls to work - don't override them */
/* Elementor's generated CSS will handle typography, we just prevent FOUC transitions */

/* RTL Support */
.rtl .custom-cart-table__head,
.rtl .custom-cart-table__body-item {
    direction: rtl;
}

.rtl .custom-cart-table .product-content-wrapper {
    flex-direction: row-reverse;
}

.rtl .custom-cart-table .product-left-content {
    align-items: flex-end;
}

.rtl .custom-cart-table .product-right-content {
    align-items: flex-start;
}

.rtl .custom-cart-table .product-subtotal {
    text-align: left;
}

/* ============================================================================
 * Empty Cart Page Section Visibility Control
 * ============================================================================
 * Controls visibility of sections based on cart empty state
 * Uses body class 'cart-is-empty' added by PHP filter
 * Editor mode protection: Uses body:not(.elementor-editor-active) pattern
 * 
 * NOTE: Simple display control - JavaScript handles timing for smooth UX
 */

/* Hide empty cart message section when cart has items */
body:not(.elementor-editor-active) .empty-cart-page-msg {
    display: none;
}

/* Show empty cart message section when cart is empty */
body:not(.elementor-editor-active).cart-is-empty .empty-cart-page-msg {
    display: block;
}

/* Hide sections with 'hide-when-cart-empty' class when cart is empty */
body:not(.elementor-editor-active).cart-is-empty .hide-when-cart-empty {
    display: none !important;
}
