/**
 * Product Bundles Frontend Styles
 *
 * Uses the Swift Commerce Design System (Swift Commerce-frontend.css)
 * All components reference shared design tokens for consistency.
 *
 * @package Swift Commerce
 */

/* ==========================================================================
   CSS Reset - Theme Isolation
   ========================================================================== */

.swift-commerce-bundle,
.swift-commerce-bundle *,
.swift-commerce-bundle *::before,
.swift-commerce-bundle *::after {
    box-sizing: border-box !important;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* ==========================================================================
   Base Container
   ========================================================================== */

.swift-commerce-bundle {
    /* Map bundle-specific variables to global design tokens */
    --Swift Commerce-bundle-primary: var(--sc-primary, #7c3aed);
    --Swift Commerce-bundle-success: var(--sc-success, #16a34a);
    --Swift Commerce-bundle-danger: var(--sc-danger, #ef4444);
    --Swift Commerce-bundle-border: var(--sc-border, #e5e7eb);
    --Swift Commerce-bundle-text: var(--sc-foreground, #1f2937);
    --Swift Commerce-bundle-text-muted: var(--sc-gray-500, #6b7280);
    --Swift Commerce-bundle-bg: var(--sc-background, #ffffff);
    --Swift Commerce-bundle-bg-muted: var(--sc-muted, #f9fafb);
    --Swift Commerce-bundle-radius: var(--sc-radius-lg, 8px);
    
    font-size: 14px !important;
    line-height: 1.5 !important;
}

/* ==========================================================================
   Bundle Items Container
   ========================================================================== */

.swift-commerce-bundle-items {
    margin-bottom: 24px;
}

/* Grid Layout */
.swift-commerce-bundle-items--grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

/* List Layout */
.swift-commerce-bundle-items--list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.swift-commerce-bundle-items--list .swift-commerce-bundle-item {
    flex-direction: row;
    align-items: center;
}

.swift-commerce-bundle-items--list .swift-commerce-bundle-item-image {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
}

.swift-commerce-bundle-items--list .swift-commerce-bundle-item-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

/* Compact Layout */
.swift-commerce-bundle-items--compact {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.swift-commerce-bundle-items--compact .swift-commerce-bundle-item {
    flex-direction: row;
    align-items: center;
    padding: 8px 12px;
    gap: 8px;
}

.swift-commerce-bundle-items--compact .swift-commerce-bundle-item-image {
    width: 40px;
    height: 40px;
}

.swift-commerce-bundle-items--compact .swift-commerce-bundle-item-title {
    font-size: 13px;
}

.swift-commerce-bundle-items--compact .swift-commerce-bundle-item-price,
.swift-commerce-bundle-items--compact .swift-commerce-bundle-item-quantity {
    display: none;
}

/* ==========================================================================
   Bundle Item Card
   ========================================================================== */

.swift-commerce-bundle-item {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--Swift Commerce-bundle-bg);
    border: 1px solid var(--Swift Commerce-bundle-border);
    border-radius: var(--Swift Commerce-bundle-radius);
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.swift-commerce-bundle-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* Item Image */
.swift-commerce-bundle-item-image {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--Swift Commerce-bundle-bg-muted);
}

.swift-commerce-bundle-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.swift-commerce-bundle-item:hover .swift-commerce-bundle-item-image img {
    transform: scale(1.05);
}

/* Item Content */
.swift-commerce-bundle-item-content {
    padding: 12px;
}

/* Item Title */
.swift-commerce-bundle-item-title {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--Swift Commerce-bundle-text);
    line-height: 1.4;
}

.swift-commerce-bundle-item-title a {
    color: inherit;
    text-decoration: none;
}

.swift-commerce-bundle-item-title a:hover {
    color: var(--Swift Commerce-bundle-primary);
}

/* Item Price */
.swift-commerce-bundle-item-price {
    margin-bottom: 8px;
    font-size: 14px;
}

.swift-commerce-bundle-item-price del {
    color: var(--Swift Commerce-bundle-text-muted);
    margin-right: 8px;
}

.swift-commerce-bundle-item-price ins {
    color: var(--Swift Commerce-bundle-success);
    text-decoration: none;
    font-weight: 600;
}

/* Item Rating */
.swift-commerce-bundle-item-rating {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
}

.swift-commerce-bundle-item-rating .star-rating {
    font-size: 12px;
}

/* Item Stock */
.swift-commerce-bundle-item-stock {
    font-size: 12px;
    margin-bottom: 8px;
}

.swift-commerce-bundle-item-stock.in-stock {
    color: var(--Swift Commerce-bundle-success);
}

.swift-commerce-bundle-item-stock.out-of-stock {
    color: var(--Swift Commerce-bundle-danger);
}

/* ==========================================================================
   Discount Badge
   ========================================================================== */

.swift-commerce-bundle-discount-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    background: var(--Swift Commerce-bundle-danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 4px;
    z-index: 1;
}

.swift-commerce-bundle-discount-badge--top-left {
    top: 8px;
    left: 8px;
    right: auto;
}

.swift-commerce-bundle-discount-badge--bottom-left {
    top: auto;
    bottom: 8px;
    left: 8px;
    right: auto;
}

.swift-commerce-bundle-discount-badge--bottom-right {
    top: auto;
    bottom: 8px;
}

/* ==========================================================================
   Quantity Controls
   ========================================================================== */

.swift-commerce-bundle-item-quantity {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.swift-commerce-bundle-item-quantity label {
    font-size: 12px;
    color: var(--Swift Commerce-bundle-text-muted);
}

/* Stepper Style */
.swift-commerce-bundle-qty-stepper {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--Swift Commerce-bundle-border);
    border-radius: 4px;
    overflow: hidden;
}

.swift-commerce-bundle-qty-stepper button {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--Swift Commerce-bundle-bg-muted);
    cursor: pointer;
    font-size: 16px;
    color: var(--Swift Commerce-bundle-text);
    transition: background 0.2s ease;
}

.swift-commerce-bundle-qty-stepper button:hover {
    background: var(--Swift Commerce-bundle-border);
}

.swift-commerce-bundle-qty-stepper input {
    width: 40px;
    height: 28px;
    border: none;
    text-align: center;
    font-size: 13px;
    -moz-appearance: textfield;
}

.swift-commerce-bundle-qty-stepper input::-webkit-outer-spin-button,
.swift-commerce-bundle-qty-stepper input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Input Style */
.swift-commerce-bundle-qty {
    width: 60px;
    padding: 6px 8px;
    border: 1px solid var(--Swift Commerce-bundle-border);
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
}

.swift-commerce-bundle-qty:focus {
    border-color: var(--Swift Commerce-bundle-primary);
    outline: none;
}

/* Fixed Quantity */
.swift-commerce-bundle-qty-fixed {
    font-size: 13px;
    color: var(--Swift Commerce-bundle-text-muted);
}

/* ==========================================================================
   Bundle Summary
   ========================================================================== */

.swift-commerce-bundle-summary {
    padding: 16px;
    background: var(--Swift Commerce-bundle-bg-muted);
    border-radius: var(--Swift Commerce-bundle-radius);
    margin-bottom: 16px;
}

/* Savings Display */
.swift-commerce-bundle-savings {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: var(--Swift Commerce-bundle-radius);
    margin-bottom: 16px;
    color: var(--Swift Commerce-bundle-success);
    font-weight: 600;
    font-size: 14px;
}

.swift-commerce-bundle-savings::before {
    content: '✓';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: var(--Swift Commerce-bundle-success);
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
}

/* Total Price */
.swift-commerce-bundle-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--Swift Commerce-bundle-bg-muted);
    border-radius: var(--Swift Commerce-bundle-radius);
    margin-bottom: 16px;
}

.swift-commerce-bundle-total-label {
    font-size: 16px;
    font-weight: 600;
    color: var(--Swift Commerce-bundle-text);
}

.swift-commerce-bundle-total-price {
    font-size: 24px;
    font-weight: 700;
    color: var(--Swift Commerce-bundle-primary);
}

.swift-commerce-bundle-total-price del {
    font-size: 16px;
    color: var(--Swift Commerce-bundle-text-muted);
    margin-right: 8px;
}

/* ==========================================================================
   Add to Cart Button
   ========================================================================== */

.swift-commerce-bundle-add-to-cart {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px 24px;
    background: var(--Swift Commerce-bundle-primary);
    color: #fff;
    border: none;
    border-radius: var(--Swift Commerce-bundle-radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.swift-commerce-bundle-add-to-cart:hover {
    background: #6d28d9;
    transform: translateY(-1px);
}

.swift-commerce-bundle-add-to-cart:active {
    transform: translateY(0);
}

.swift-commerce-bundle-add-to-cart:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.swift-commerce-bundle-add-to-cart .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: Swift Commerce-spin 0.8s linear infinite;
}

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

/* Button Styles */
.swift-commerce-bundle-add-to-cart--centered {
    width: auto;
    margin: 0 auto;
    display: flex;
}

.swift-commerce-bundle-add-to-cart--default {
    width: auto;
}

/* ==========================================================================
   Cart Badge
   ========================================================================== */

.swift-commerce-bundle-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--Swift Commerce-bundle-primary);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 10px;
    text-transform: uppercase;
    margin-left: 8px;
    vertical-align: middle;
}

/* ==========================================================================
   Cart Bundle Items
   ========================================================================== */

.swift-commerce-bundle-cart-items {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--Swift Commerce-bundle-bg-muted);
    border-radius: 4px;
    font-size: 12px;
}

.swift-commerce-bundle-cart-items small {
    display: block;
    color: var(--Swift Commerce-bundle-text-muted);
    margin-bottom: 4px;
}

.swift-commerce-bundle-cart-items ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.swift-commerce-bundle-cart-items li {
    padding: 2px 0;
    color: var(--Swift Commerce-bundle-text);
}

.swift-commerce-bundle-cart-items li .discount {
    color: var(--Swift Commerce-bundle-success);
    font-weight: 500;
}

/* ==========================================================================
   Product Page Price
   ========================================================================== */

.swift-commerce-bundle-price-savings {
    display: block;
    margin-top: 8px;
    font-size: 14px;
    color: var(--Swift Commerce-bundle-success);
    font-weight: 500;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 991px) {
    .swift-commerce-bundle-items--grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 575px) {
    .swift-commerce-bundle-items--grid {
        grid-template-columns: 1fr;
    }
    
    .swift-commerce-bundle-items--list .swift-commerce-bundle-item-content {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .swift-commerce-bundle-total {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
}

/* ==========================================================================
   Theme Compatibility
   ========================================================================== */

/* Ensure styles work with common WooCommerce themes */
.woocommerce .swift-commerce-bundle .button {
    margin-top: 0;
}

.woocommerce div.product .swift-commerce-bundle {
    margin-top: 20px;
}

/* Elementor Compatibility */
.swift-commerce-bundle-elementor {
    width: 100%;
}

.elementor-widget-Swift Commerce_product_bundle .swift-commerce-bundle-items--grid {
    grid-template-columns: repeat(var(--Swift Commerce-columns, 3), 1fr);
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .swift-commerce-bundle-add-to-cart,
    .swift-commerce-bundle-item-quantity {
        display: none !important;
    }
}

