/**
 * Frequently Bought Together - Frontend Styles
 * RESPONSIVE DESIGN: Optimized for all screen sizes - desktop, tablet, mobile
 * DYNAMIC SIZING: Adapts product sizes based on quantity for optimal space usage
 * Updated: Smart sizing that adjusts to product count + better mobile centering
 */

/* Use theme colors automatically - minimal approach */
.fbt-container {
    margin: 30px auto;
    padding: 0;
    background: transparent;
    font-family: inherit;
    color: inherit;
    max-width: 1200px; /* Constraint for large screens */
    overflow: hidden;
    border: none;
    box-shadow: none;
    width: 100%;
    box-sizing: border-box;
}

/* Inherit border color from WooCommerce elements */
.woocommerce .fbt-container {
    background: transparent;
}

/* Title - clean and simple */
.fbt-title {
    margin: 0 0 25px 0;
    padding: 0;
    font-size: 1.3em;
    font-weight: 600;
    color: inherit;
    text-align: left;
    border: none;
    font-family: inherit;
}

/* Use theme's primary color for title if available */
.woocommerce .fbt-title {
    color: inherit;
}

.fbt-products-wrapper {
    display: flex;
    gap: 25px;
    align-items: flex-start;
    max-width: 100%;
    overflow: hidden;
}

.fbt-products {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 5px;
    scrollbar-width: thin;
    scrollbar-color: #e0e0e0 transparent;
}

.fbt-products::-webkit-scrollbar {
    height: 6px;
}

.fbt-products::-webkit-scrollbar-track {
    background: transparent;
}

.fbt-products::-webkit-scrollbar-thumb {
    background: #e0e0e0;
    border-radius: 3px;
}

.fbt-products::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* 
 * DYNAMIC PRODUCT SIZING - Adapts based on product count
 * 2 products = larger, 3+ products = smaller for optimal space usage
 */

/* Default product styling - base case */
.fbt-product {
    background: #fff;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    flex: 0 0 auto;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    color: inherit;
    min-height: 280px;
    
    /* Default sizing for 3+ products */
    min-width: 180px;
    max-width: 220px;
    width: 200px;
}

/* 2 products - make them bigger to fill space better */
.fbt-products:has(.fbt-product:nth-child(3):not(.fbt-product)) .fbt-product,
.fbt-products .fbt-product:first-child:nth-last-child(2),
.fbt-products .fbt-product:first-child:nth-last-child(2) ~ .fbt-product {
    min-width: 280px;
    max-width: 320px;
    width: 300px;
}

/* 4+ products - make them smaller */
.fbt-products .fbt-product:first-child:nth-last-child(n+4),
.fbt-products .fbt-product:first-child:nth-last-child(n+4) ~ .fbt-product {
    min-width: 160px;
    max-width: 180px;
    width: 170px;
}

/* 5+ products - even smaller */
.fbt-products .fbt-product:first-child:nth-last-child(n+5),
.fbt-products .fbt-product:first-child:nth-last-child(n+5) ~ .fbt-product {
    min-width: 140px;
    max-width: 160px;
    width: 150px;
}

/* Theme-aware product styling */
.woocommerce .fbt-product {
    background: #fff;
    border-color: #f0f0f0;
}

.fbt-product:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    border-color: #e0e0e0;
}

/* Main product - subtle highlight */
.fbt-main-product {
    border-color: #e0e0e0;
    background: #fafafa;
}

.woocommerce .fbt-main-product {
    border-color: #e0e0e0;
    background: #fafafa;
}

.fbt-product-image {
    margin-bottom: 12px;
}

.fbt-product-image img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    aspect-ratio: 1/1;
    object-fit: cover;
}

.fbt-product-image a {
    display: block;
    text-decoration: none;
}

/* Clean product titles */
.fbt-product-title {
    margin: 0 0 4px 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.fbt-product-title a {
    color: inherit;
    text-decoration: none;
}

.fbt-product-title a:hover {
    color: var(--wc-primary-color, #0073aa);
}

/* Product brand styling */
.fbt-product-brand {
    margin: 0 0 6px 0;
    font-size: 12px;
    font-weight: 400;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.1;
}

/* Clean price styling */
.fbt-product-price {
    margin-bottom: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--wc-primary-color, #0073aa);
}

/* Price follows WooCommerce price color patterns */
.woocommerce .fbt-product-price {
    color: var(--wc-price-color, var(--wc-primary-color, #0073aa));
}

.fbt-product-checkbox {
    margin-top: 10px;
}

.fbt-product-checkbox input[type="checkbox"] {
    margin-right: 5px;
    transform: scale(1.1);
}

.fbt-product-checkbox label {
    font-size: 12px;
    color: #666;
    cursor: pointer;
    font-weight: 500;
}

.fbt-product-checkbox input[type="checkbox"]:disabled + label {
    color: #999;
    opacity: 0.6;
    cursor: default;
}

/* Clean plus signs */
.fbt-plus {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 300;
    color: #666;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    opacity: 0.8;
    background: #f8f9fa;
    border-radius: 50%;
    border: 1px solid #e9ecef;
}

/* Clean sidebar - matches the screenshot design */
.fbt-actions {
    background: #fff;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    padding: 25px;
    min-width: 320px;
    max-width: 360px;
    width: 340px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    align-self: flex-start;
    position: sticky;
    top: 20px;
    box-sizing: border-box;
}

.woocommerce .fbt-actions {
    background: #fff;
    border-color: #f0f0f0;
}

.fbt-selected-items {
    margin-bottom: 20px;
}

.fbt-selected-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f5f5f5;
    font-size: 14px;
}

.woocommerce .fbt-selected-item {
    border-bottom-color: #f5f5f5;
}

.fbt-selected-item:last-child {
    border-bottom: none;
}

.fbt-item-name {
    flex: 1;
    margin-right: 10px;
    font-weight: 500;
}

.fbt-item-price {
    color: var(--wc-primary-color, #0073aa);
    font-weight: 600;
}

.fbt-total-section {
    border-top: 2px solid #f0f0f0;
    padding-top: 18px;
    margin-top: 18px;
}

.woocommerce .fbt-total-section {
    border-top-color: #f0f0f0;
}

.fbt-total-price {
    text-align: left;
    margin-bottom: 15px;
}

.fbt-total-label {
    display: block;
    font-size: 22px;
    font-weight: 800;
    color: inherit;
    margin-bottom: 8px;
}

.fbt-total-amount {
    font-size: 20px;
    font-weight: 700;
    color: var(--wc-primary-color, #0073aa);
    line-height: 1;
}

.fbt-product-count {
    font-size: 14px;
    color: #666;
    margin-bottom: 18px;
    font-weight: 500;
}

.fbt-buttons {
    display: block;
}

/* 
 * CLEAN BUTTON STYLING - matches screenshot design
 * Inherits theme button styling automatically
 */
.fbt-add-selected {
    display: block;
    width: 100%;
    padding: 15px 25px;
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    line-height: 1.3;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    
    /* Clean fallback styling */
    background: #0073aa;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,115,170,0.25);
}

/* Use WooCommerce button styling when available */
.woocommerce .fbt-add-selected,
.woocommerce-page .fbt-add-selected {
    background: var(--wc-primary-color, #0073aa) !important;
    color: var(--wc-primary-text-color, #fff) !important;
    border-color: var(--wc-primary-color, #0073aa) !important;
}

/* Try to inherit from theme's add to cart button */
.woocommerce .fbt-add-selected {
    font-family: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    border-radius: inherit;
}

.fbt-add-selected:hover {
    background: #005a87;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,115,170,0.4);
}

.woocommerce .fbt-add-selected:hover {
    background: var(--wc-primary-hover-color, #005a87) !important;
}

.fbt-add-selected:disabled {
    background: #ccc !important;
    color: #999 !important;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Loading spinner */
.fbt-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: fbt-spin 1s ease-in-out infinite;
}

@keyframes fbt-spin {
    to { transform: rotate(360deg); }
}

/* =====================================================
   RESPONSIVE DESIGN - OPTIMIZED FOR ALL SCREEN SIZES
   ===================================================== */

/* Extra Large Screens (1400px+) */
@media (min-width: 1400px) {
    .fbt-container {
        max-width: 1400px;
        margin: 40px auto;
    }
    
    .fbt-products-wrapper {
        gap: 30px;
    }
    
    .fbt-products {
        gap: 25px;
    }
    
    /* Dynamic sizing for extra large screens */
    .fbt-product {
        min-width: 200px;
        max-width: 240px;
        width: 220px;
    }
    
    /* 2 products on XL screens */
    .fbt-products .fbt-product:first-child:nth-last-child(2),
    .fbt-products .fbt-product:first-child:nth-last-child(2) ~ .fbt-product {
        min-width: 340px;
        max-width: 380px;
        width: 360px;
    }
    
    /* 4+ products on XL screens */
    .fbt-products .fbt-product:first-child:nth-last-child(n+4),
    .fbt-products .fbt-product:first-child:nth-last-child(n+4) ~ .fbt-product {
        min-width: 180px;
        max-width: 200px;
        width: 190px;
    }
    
    .fbt-actions {
        min-width: 340px;
        max-width: 380px;
        width: 360px;
    }
}

/* Large Screens (1200px - 1399px) */
@media (min-width: 1200px) and (max-width: 1399px) {
    .fbt-container {
        max-width: 1200px;
        margin: 30px auto;
    }
    
    .fbt-products {
        gap: 20px;
    }
    
    .fbt-actions {
        min-width: 300px;
        max-width: 340px;
        width: 320px;
    }
}

/* Medium-Large Screens (1024px - 1199px) */
@media (min-width: 1024px) and (max-width: 1199px) {
    .fbt-container {
        max-width: 100%;
        margin: 25px auto;
        padding: 0 20px;
    }
    
    .fbt-products-wrapper {
        gap: 20px;
    }
    
    .fbt-products {
        gap: 15px;
    }
    
    .fbt-product {
        min-width: 160px;
        max-width: 180px;
        width: 170px;
    }
    
    /* 2 products on medium-large screens */
    .fbt-products .fbt-product:first-child:nth-last-child(2),
    .fbt-products .fbt-product:first-child:nth-last-child(2) ~ .fbt-product {
        min-width: 240px;
        max-width: 280px;
        width: 260px;
    }
    
    .fbt-actions {
        min-width: 280px;
        max-width: 300px;
        width: 290px;
        position: static;
    }
}

/* Tablet Landscape (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .fbt-container {
        margin: 20px auto;
        padding: 0 15px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .fbt-products-wrapper {
        flex-direction: column;
        gap: 20px;
        align-items: stretch;
        width: 100%;
    }
    
    .fbt-products {
        overflow-x: auto;
        gap: 15px;
        padding-bottom: 10px;
        justify-content: center;
        width: 100%;
    }
    
    .fbt-product {
        min-width: 150px;
        max-width: 170px;
        width: 160px;
    }
    
    /* 2 products on tablet landscape */
    .fbt-products .fbt-product:first-child:nth-last-child(2),
    .fbt-products .fbt-product:first-child:nth-last-child(2) ~ .fbt-product {
        min-width: 220px;
        max-width: 260px;
        width: 240px;
    }
    
    .fbt-actions {
        max-width: none;
        min-width: auto;
        width: 100%;
        position: static;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        margin: 0;
        box-sizing: border-box;
    }
    
    .fbt-selected-items {
        width: 100%;
        max-width: 500px;
    }
    
    .fbt-total-section {
        width: 100%;
        max-width: 500px;
    }
    
    .fbt-add-selected {
        max-width: 300px;
    }
}

/* Tablet Portrait & Mobile Landscape (600px - 767px) */
@media (min-width: 600px) and (max-width: 767px) {
    .fbt-container {
        margin: 15px auto;
        padding: 0 15px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .fbt-products-wrapper {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
        width: 100%;
    }
    
    .fbt-products {
        overflow-x: auto;
        gap: 12px;
        padding-bottom: 8px;
        justify-content: center;
        width: 100%;
    }
    
    .fbt-product {
        min-width: 140px;
        max-width: 160px;
        width: 150px;
        padding: 12px;
    }
    
    /* 2 products on tablet portrait */
    .fbt-products .fbt-product:first-child:nth-last-child(2),
    .fbt-products .fbt-product:first-child:nth-last-child(2) ~ .fbt-product {
        min-width: 200px;
        max-width: 240px;
        width: 220px;
    }
    
    .fbt-product-title {
        font-size: 13px;
        margin-bottom: 3px;
        line-height: 1.2;
    }
    
    .fbt-product-brand {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .fbt-product-price {
        font-size: 15px;
    }
    
    .fbt-actions {
        max-width: none;
        min-width: auto;
        width: 100%;
        padding: 15px;
        position: static;
        margin: 0;
        box-sizing: border-box;
    }
    
    .fbt-total-label {
        font-size: 18px;
    }
    
    .fbt-total-amount {
        font-size: 18px;
    }
}

/* Mobile Portrait (below 600px) */
@media (max-width: 599px) {
    .fbt-container {
        margin: 15px 0;
        padding: 0 10px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .fbt-title {
        font-size: 1.2em;
        margin-bottom: 20px;
        text-align: center;
    }
    
    .fbt-products-wrapper {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
        width: 100%;
    }
    
    .fbt-products {
        flex-direction: column;
        gap: 8px;
        overflow-x: visible;
        width: 100%;
        align-items: stretch;
    }
    
    .fbt-product {
        width: 100% !important;
        min-width: auto !important;
        max-width: none !important;
        min-height: auto;
        margin: 0;
        padding: 15px;
        display: flex;
        flex-direction: row;
        align-items: center;
        text-align: left;
        box-sizing: border-box;
    }
    
    .fbt-product-image {
        margin-bottom: 0;
        margin-right: 12px;
        flex-shrink: 0;
        width: 75px;
        height: 75px;
    }
    
    .fbt-product-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 6px;
    }
    
    .fbt-product-details {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .fbt-product-title {
        font-size: 15px;
        margin-bottom: 4px;
        line-height: 1.3;
        -webkit-line-clamp: 2;
        font-weight: 600;
    }
    
    .fbt-product-brand {
        font-size: 11px;
        margin-bottom: 5px;
        color: #888;
    }

    .fbt-product-price {
        font-size: 16px;
        margin-bottom: 0;
        font-weight: 700;
    }
    
    .fbt-plus {
        transform: rotate(90deg);
        margin: 5px auto;
        font-size: 18px;
        width: 30px;
        height: 30px;
    }
    
    .fbt-actions {
        padding: 15px;
        border-radius: 8px;
        width: 100%;
        margin: 0;
        box-sizing: border-box;
        position: static;
        min-width: auto;
        max-width: none;
    }
    
    .fbt-selected-items {
        margin-bottom: 15px;
    }
    
    .fbt-selected-item {
        padding: 10px 0;
        font-size: 14px;
    }
    
    .fbt-total-section {
        text-align: center;
    }
    
    .fbt-total-label {
        font-size: 18px;
        margin-bottom: 5px;
    }
    
    .fbt-product-count {
        font-size: 14px;
        margin-bottom: 15px;
    }
    
    .fbt-add-selected {
        width: 100%;
        padding: 12px 20px;
        font-size: 15px;
        font-weight: 700;
        border-radius: 8px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
}

/* Very Small Mobile (below 400px) */
@media (max-width: 399px) {
    .fbt-container {
        margin: 8px auto;
        padding: 0 5px;
    }
    
    .fbt-products {
        max-width: 100%;
    }
    
    .fbt-product {
        width: 100% !important;
        min-width: auto !important;
        max-width: none !important;
        padding: 12px;
        min-height: auto;
    }
    
    .fbt-product-image {
        width: 65px;
        height: 65px;
        margin-right: 10px;
    }
    
    .fbt-product-title {
        font-size: 13px;
        margin-bottom: 3px;
        line-height: 1.2;
    }
    
    .fbt-product-brand {
        font-size: 10px;
        margin-bottom: 4px;
    }

    .fbt-product-price {
        font-size: 14px;
        margin-bottom: 0;
    }
    
    .fbt-actions {
        padding: 12px;
        width: 100%;
        max-width: none;
        margin: 0;
        box-sizing: border-box;
        position: static;
        min-width: auto;
    }
    
    .fbt-add-selected {
        padding: 10px 15px;
        font-size: 14px;
    }
}

/* High contrast support */
@media (prefers-contrast: high) {
    .fbt-container {
        border-width: 2px;
    }
    
    .fbt-product {
        border-width: 2px;
    }
    
    .fbt-add-selected {
        border: 2px solid currentColor !important;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .fbt-product {
        transition: none;
    }
    
    .fbt-add-selected {
        transition: none;
    }
    
    .fbt-product:hover {
        transform: none;
    }
    
    .fbt-add-selected:hover {
        transform: none;
    }
    
    .fbt-loading {
        animation: none;
    }
}

/* Animation for product addition */
.fbt-product.fbt-adding {
    animation: fbt-pulse 0.6s ease-in-out;
}

@keyframes fbt-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

/* Success/Error messages - clean styling */
.fbt-message {
    padding: 10px 15px;
    margin: 10px 0;
    border-radius: 6px;
    font-size: 14px;
}

.fbt-message.fbt-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.fbt-message.fbt-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Stock Status - minimal styling */
.fbt-stock-status {
    margin: 8px 0;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
}

.fbt-stock-status .out-of-stock {
    color: #e74c3c;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(231, 76, 60, 0.1);
}

.fbt-stock-status .backorder-available {
    color: #f39c12;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(243, 156, 18, 0.1);
}

/* Out of stock styling */
.fbt-product .fbt-product-checkbox input[type="checkbox"]:disabled {
    opacity: 0.6;
}

.fbt-product .fbt-product-checkbox input[type="checkbox"]:disabled + label {
    opacity: 0.6;
    text-decoration: line-through;
}

.fbt-product.out-of-stock {
    opacity: 0.8;
    filter: grayscale(20%);
}

.fbt-product.out-of-stock .fbt-product-image {
    opacity: 0.7;
}

/* Theme Integration - Final catch-all */
.woocommerce .fbt-container {
    clear: both;
    width: 100%;
}

.woocommerce .fbt-container * {
    box-sizing: border-box;
}

/*
 * ADVANCED THEME INTEGRATION
 * Clean integration with popular WooCommerce themes
 */

/* Try to inherit button styling from theme's add to cart buttons */
.woocommerce .fbt-add-selected {
    font-family: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    border-radius: inherit;
}

/* Inherit typography from WooCommerce product elements */
.woocommerce .fbt-product-title a {
    font-family: inherit;
    font-weight: inherit;
}

.woocommerce .fbt-product-price {
    font-family: inherit;
    font-weight: inherit;
}

/* For themes that style WooCommerce sections */
.woocommerce-tabs .fbt-container,
.woocommerce-product-details .fbt-container,
.single-product .fbt-container {
    background: transparent;
    border: none;
    color: inherit;
} 