/**
 * BuyTogether Frontend Styles
 */

/* Main container */
.buytogether-suggestions {
    margin: 20px 0;
    padding: 20px;
    background: linear-gradient(-45deg, #f9f9f9, #e8f4f8, #f9f9f9, #e8f4f8);
    background-size: 400% 400%;
    animation: gradientMove 8s ease infinite;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
}

/* Close button */
.buytogether-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 20;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    color: #666;
    transition: all 0.3s ease;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.buytogether-close:hover {
    background: #fff;
    color: #e74c3c;
    border-color: #e74c3c;
    transform: scale(1.1);
}

/* Dynamic patterns will be injected here */

.buytogether-suggestions > * {
    z-index: 10;
}

/* Animations */
@keyframes twinkle {
    0%, 100% { opacity: 0.15; }
    50% { opacity: 0.3; }
}

@keyframes slidePattern {
    0% { transform: translateX(0); }
    100% { transform: translateX(60px); }
}

@keyframes floatCircles {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes confettiFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    33% { transform: translateY(-5px) rotate(1deg); }
    66% { transform: translateY(5px) rotate(-1deg); }
}

@keyframes gradientMove {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes scrollLeft {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

@keyframes scrollRight {
    0% { transform: translateX(-50%); }
    100% { transform: translateX(0); }
}

/* Main title container */
.buytogether-main-title {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.buytogether-title {
    margin: 0;
    font-size: 32px;
    color: #333;
    font-weight: 700;
    line-height: 1.2;
}

/* Header */
.buytogether-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
}

/* Countdown timer */
.buytogether-countdown {
    display: flex;
    align-items: center;
    gap: 10px;
}

.countdown-message {
    font-size: 16px;
    color: #666;
    font-weight: 500;
}

.countdown-timer {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 18px;
    font-weight: bold;
    color: #e74c3c;
    background: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.countdown-timer .minutes,
.countdown-timer .seconds {
    min-width: 20px;
    text-align: center;
}

/* Free shipping bar */
.buytogether-free-shipping-bar {
    margin-bottom: 20px;
    padding: 15px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.buytogether-free-shipping-bar .shipping-message span[style*=\"color: white\"] {
    color: white !important;
    background: none !important;
}

.buytogether-free-shipping-bar .woocommerce-Price-amount {
    color: white !important;
    background: none !important;
}

.shipping-message {
    font-size: 16px;
    color: #333;
    margin-bottom: 10px;
    font-weight: 500;
}

.shipping-progress {
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #45a049);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Products grid */
.buytogether-products {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
    position: relative;
    flex-wrap: wrap;
}

/* Force single row for 6 products or less */
.buytogether-products[data-product-count="1"],
.buytogether-products[data-product-count="2"],
.buytogether-products[data-product-count="3"],
.buytogether-products[data-product-count="4"],
.buytogether-products[data-product-count="5"] {
    flex-wrap: nowrap;
    overflow-x: visible;
    justify-content: center;
    padding-bottom: 5px;
}

.buytogether-products[data-product-count="6"] {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 5px;
}

/* Adjust product card width for single row display */
.buytogether-products[data-product-count="5"] .buytogether-product-card {
    min-width: 180px;
    max-width: 180px;
    flex-shrink: 0;
}

.buytogether-products[data-product-count="6"] .buytogether-product-card {
    min-width: 180px;
    max-width: 180px;
    flex-shrink: 0;
}

/* Auto scroll container */
.buytogether-products.auto-scroll {
    overflow: hidden;
    justify-content: flex-start;
    flex-wrap: nowrap;
    width: 100%;
    position: relative;
    height: auto;
    display: flex;
}

.buytogether-products.auto-scroll .products-slider {
    display: flex;
    flex-direction: row;
    gap: 10px;
    flex-wrap: nowrap;
    width: max-content;
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Auto scroll animations */
.buytogether-products.auto-scroll.scroll-left .products-slider {
    animation: scrollLeft linear infinite;
    animation-duration: 30s; /* Default duration, will be overridden by JavaScript */
    animation-play-state: running;
    animation-fill-mode: both;
}

.buytogether-products.auto-scroll.scroll-right .products-slider {
    animation: scrollRight linear infinite;
    animation-duration: 30s; /* Default duration, will be overridden by JavaScript */
    animation-play-state: running;
    animation-fill-mode: both;
}

/* Ensure animation works on all browsers */
@-webkit-keyframes scrollLeft {
    0% { -webkit-transform: translateX(0); transform: translateX(0); }
    100% { -webkit-transform: translateX(-50%); transform: translateX(-50%); }
}

@-webkit-keyframes scrollRight {
    0% { -webkit-transform: translateX(-50%); transform: translateX(-50%); }
    100% { -webkit-transform: translateX(0); transform: translateX(0); }
}

@-moz-keyframes scrollLeft {
    0% { -moz-transform: translateX(0); transform: translateX(0); }
    100% { -moz-transform: translateX(-50%); transform: translateX(-50%); }
}

@-moz-keyframes scrollRight {
    0% { -moz-transform: translateX(-50%); transform: translateX(-50%); }
    100% { -moz-transform: translateX(0); transform: translateX(0); }
}

/* Popup products grid - horizontal layout */
.buytogether-popup .buytogether-products {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
    position: relative;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 10px;
}

/* Hide horizontal scrollbar but keep functionality */
.buytogether-popup .buytogether-products::-webkit-scrollbar,
.buytogether-products::-webkit-scrollbar {
    height: 6px;
}

.buytogether-popup .buytogether-products::-webkit-scrollbar-track,
.buytogether-products::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.buytogether-popup .buytogether-products::-webkit-scrollbar-thumb,
.buytogether-products::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.buytogether-popup .buytogether-products::-webkit-scrollbar-thumb:hover,
.buytogether-products::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Product card */
.buytogether-product-card {
    background: #fff;
    border-radius: 8px;
    padding: 0;
    color: #333;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    text-align: center;
    display: flex;
    flex-direction: column;
    width: 200px;
    height: 350px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid #ddd;
    flex-shrink: 1;
}

/* Popup product card - fixed width for horizontal layout */
.buytogether-popup .buytogether-product-card {
    min-width: 200px;
    flex-shrink: 0;
}

.buytogether-product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.buytogether-product-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.buytogether-product-card:hover::before {
    opacity: 1;
}

/* Product image */
.product-image {
    text-align: center;
    padding: 20px;
    flex-shrink: 0;
    background: #f8f9fa;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-image img {
    max-width: 160px;
    max-height: 160px;
    object-fit: contain;
    border-radius: 4px;
}

/* Product details */
.product-details {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    padding: 15px;
    background: #fff;
    height: 150px;
    justify-content: space-between;
}

.product-name {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    color: #333;
    height: 32px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    flex-shrink: 0;
}

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

.product-name a:hover {
    color: #0073aa;
    text-decoration: none;
}

.product-meta {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
}

.product-price {
    font-size: 16px;
    font-weight: bold;
    margin: 0;
    text-align: center;
    color: #333;
}

.product-price .woocommerce-Price-amount {
    font-size: 16px;
}

.product-price del {
    opacity: 0.7;
    font-size: 14px;
}

/* Product rating */
.product-rating {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin: 0;
}

.product-rating .star-rating {
    color: #ffc107;
    font-size: 12px;
}

.rating-count {
    font-size: 10px;
    opacity: 0.7;
    color: #666;
}

/* Add to cart button */
.buytogether-add-to-cart {
    background: #0073aa;
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    margin-top: 8px;
    flex-shrink: 0;
}

.buytogether-add-to-cart:hover {
    background: #005a87;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.buytogether-add-to-cart:hover {
    background: #005a87;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.buytogether-add-to-cart:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

/* Popup styles */
.buytogether-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.buytogether-popup.show {
    visibility: visible;
    opacity: 1;
}

.popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    cursor: pointer;
}

.popup-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 15px;
    padding: 30px;
    width: auto;
    height: auto;
    min-width: 600px;
    max-width: 95vw;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

/* Popup content auto-sizing */
.buytogether-popup .popup-body {
    width: fit-content;
    max-width: 100%;
}

/* Popup suggestions container */
.buytogether-popup .buytogether-suggestions {
    margin: 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    width: fit-content;
    max-width: 100%;
}


/* Variation Modal */
.buytogether-variation-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
}

.variation-attributes {
    margin-bottom: 20px;
}

.attribute-group {
    margin-bottom: 15px;
}

.attribute-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #333;
}

.attribute-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: #fff;
}

.attribute-group select:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.selected-variation-info {
    text-align: center;
    padding: 20px;
    margin-bottom: 20px;
    background: #f8f9fa;
    border-radius: 4px;
}

.selected-variation-info .variation-price {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 15px;
}

.selected-variation-info .button-add-to-cart {
    background: #0073aa;
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.3s ease;
}

.selected-variation-info .button-add-to-cart:hover {
    background: #005a87;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.button-cancel,
.button-add-to-cart {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.button-cancel {
    background: #f1f1f1;
    color: #666;
}

.button-cancel:hover {
    background: #e1e1e1;
}

.button-add-to-cart {
    background: #0073aa;
    color: #fff;
}

.button-add-to-cart:hover:not(:disabled) {
    background: #005a87;
}

.button-add-to-cart:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Message styles */
.buytogether-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 8px;
    font-weight: 500;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.buytogether-message-success {
    background: #4caf50;
    color: #fff;
}

.buytogether-message-error {
    background: #f44336;
    color: #fff;
}

/* Responsive design */
@media (max-width: 768px) {
    .buytogether-suggestions {
        margin: 15px 0;
        padding: 15px;
    }
    
    .buytogether-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .buytogether-title {
        font-size: 26px;
    }
    
    .buytogether-products {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .buytogether-product-card {
        padding: 15px;
    }
    
    .popup-content {
        padding: 20px;
        max-width: 95%;
        min-width: 300px;
    }
    
    /* Mobile popup products - stack vertically */
    .buytogether-popup .buytogether-products {
        flex-direction: column;
        flex-wrap: wrap;
        overflow-x: visible;
    }
    
    .countdown-timer {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .buytogether-suggestions {
        margin: 10px 0;
        padding: 10px;
    }
    
    .buytogether-title {
        font-size: 22px;
    }
    
    .buytogether-product-card {
        padding: 12px;
    }
    
    .product-name {
        font-size: 16px;
    }
    
    .product-price {
        font-size: 18px;
    }
    
    .buytogether-add-to-cart {
        padding: 10px 20px;
        font-size: 14px;
    }
}

/* Animation for card entrance */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.buytogether-product-card {
    animation: slideInUp 0.6s ease-out;
}

.buytogether-product-card:nth-child(1) {
    animation-delay: 0.1s;
}

.buytogether-product-card:nth-child(2) {
    animation-delay: 0.2s;
}

.buytogether-product-card:nth-child(3) {
    animation-delay: 0.3s;
}

/* Loading state */
.buytogether-loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.buytogether-loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

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

/* Empty state */
.buytogether-empty {
    text-align: center;
    padding: 40px;
    color: #666;
    font-style: italic;
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .buytogether-suggestions {
        background: #2c2c2c;
        color: #fff;
    }
    
    .buytogether-title {
        color: #fff;
    }
    
    .buytogether-free-shipping-bar {
        background: #3c3c3c;
    }
    
    .popup-content {
        background: #2c2c2c;
        color: #fff;
    }
    
    .popup-close {
        color: #ccc;
    }
    
    .popup-close:hover {
        background: #3c3c3c;
        color: #fff;
    }
}