/**
 * WC Bundles - Frontend Styles
 *
 * Minimal, flat design with internal scrolling for large product lists.
 * @package PlugnLoad_WC_Bundles
 * @since 1.0.0
 */

/* ============================================
   CSS Custom Properties
   ============================================ */
:root {
    /* Colors - Clean & Flat */
    --wcb-primary: #2271b1; /* WordPress Blue */
    --wcb-primary-hover: #135e96;
    --wcb-text: #2c3338;
    --wcb-text-muted: #646970;
    --wcb-border: #dcdcde;
    --wcb-bg: #ffffff;
    --wcb-bg-alt: #f6f7f7;
    --wcb-bg-selected: #f0f6fc;
    
    /* Spacing */
    --wcb-spacing-xs: 4px;
    --wcb-spacing-sm: 8px;
    --wcb-spacing-md: 15px;
    
    /* Flat Design */
    --wcb-radius: 3px;
    --wcb-transition: 0.15s ease-out;
}

/* ============================================
   Main Container
   ============================================ */
.plugnload-wc-bundles-selector {
    margin: 20px 0;
    font-family: inherit;
    max-width: 100%;
}

/* Loading */
.plugnload-wc-bundles-loading {
    padding: 20px;
    text-align: center;
    color: var(--wcb-text-muted);
    font-size: 14px;
    border: 1px solid var(--wcb-border);
    background: var(--wcb-bg-alt);
}

.plugnload-wc-bundles-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    border: 2px solid rgba(0,0,0,0.1);
    border-top-color: var(--wcb-text-muted);
    border-radius: 50%;
    animation: wcb-spin 0.6s linear infinite;
    vertical-align: middle;
}

@keyframes wcb-spin { to { transform: rotate(360deg); } }

/* ============================================
   Tier Accordion (Minimal)
   ============================================ */
.wcb-tier {
    border: 1px solid var(--wcb-border);
    margin-bottom: 12px;
    background: var(--wcb-bg);
    border-radius: 14px;
    overflow: hidden;
}

.wcb-tier:first-child {
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
}

.wcb-tier:last-child {
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 14px;
    margin-bottom: 20px;
}

.wcb-tier.wcb-has-selection {
    border-color: var(--wcb-border);
}

.wcb-tier.wcb-tier-open {
    border-color: #c3c4c7;
}

.wcb-tier.wcb-tier-locked .wcb-tier-header {
    background: #fcfcfd;
    cursor: default;
}

.wcb-tier.wcb-tier-locked .wcb-tier-title,
.wcb-tier.wcb-tier-locked .wcb-tier-meta {
    color: var(--wcb-text-muted);
}

/* Tier Header */
.wcb-tier-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 18px;
    background: #fff;
    cursor: pointer;
    user-select: none;
    font-size: 14px;
}

.wcb-tier-header:hover {
    background: #f6f7f7;
}

.wcb-tier-header-left {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.wcb-tier-heading {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.wcb-tier-toggle svg {
    color: var(--wcb-text-muted);
    transition: transform var(--wcb-transition);
    margin-top: 1px;
}

.wcb-tier-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: #f0f0f1;
    flex-shrink: 0;
}

.wcb-tier-open .wcb-tier-toggle svg {
    transform: rotate(180deg);
}

.wcb-tier-title {
    font-weight: 700;
    color: var(--wcb-text);
    line-height: 1.25;
    font-size: 16px;
}

.wcb-tier-meta {
    display: block;
    color: var(--wcb-text-muted);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wcb-tier-meta:empty {
    display: none;
}

.wcb-tier-header-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.wcb-tier-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}

.wcb-tier-status-ready {
    background: #f6f7f7;
    color: #3c434a;
}

.wcb-tier-status-pending {
    background: #fef3c7;
    color: #92400e;
}

.wcb-tier-status-complete {
    background: #dcfce7;
    color: #166534;
}

.wcb-tier-status-locked {
    background: #f3f4f6;
    color: #6b7280;
}

/* Tier Body */
.wcb-tier-body {
    border-top: 1px solid #eef2f7;
    padding: 0; /* Removing padding to let grid control it */
    display: none;
}

/* ============================================
   Products List & Scrollbar
   ============================================ */
.wcb-product-search {
    padding: 10px 10px 0;
}

.wcb-product-search-input {
    width: 100%;
    min-height: 34px;
    border: 1px solid var(--wcb-border);
    border-radius: var(--wcb-radius);
    padding: 6px 8px;
    color: var(--wcb-text);
    background: #fff;
    font-size: 13px;
}

.wcb-product-search-input:focus {
    border-color: var(--wcb-primary);
    outline: 1px solid var(--wcb-primary);
    outline-offset: 0;
}

.wcb-products-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 8px 10px 10px;
    
    /* Scrollbar Logic */
    max-height: 430px;
    overflow-y: auto;
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: #c0c0c0 transparent;
}

/* Custom Scrollbar for Webkit */
.wcb-products-grid::-webkit-scrollbar {
    width: 6px;
}

.wcb-products-grid::-webkit-scrollbar-track {
    background: transparent;
}

.wcb-products-grid::-webkit-scrollbar-thumb {
    background-color: #c0c0c0;
    border-radius: 3px;
}

/* ============================================
   Product Rows (Compact)
   ============================================ */
.wcb-product-card {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
    border-bottom-color: #f0f0f1;
    border-radius: 0;
    background: #fff;
    padding: 8px;
    transition: background-color 0.1s, border-color 0.1s;
}

.wcb-product-card:first-child {
    border-top-left-radius: var(--wcb-radius);
    border-top-right-radius: var(--wcb-radius);
}

.wcb-product-card:last-child {
    border-bottom-color: transparent;
    border-bottom-left-radius: var(--wcb-radius);
    border-bottom-right-radius: var(--wcb-radius);
}

.wcb-product-card:hover {
    background: #f8f8f8;
    border-color: #d0d2d4;
}

.wcb-product-card.wcb-selected {
    border-color: var(--wcb-primary);
    background: var(--wcb-bg-selected);
}

/* Disabled/OOS */
.wcb-product-card.wcb-out-of-stock {
    opacity: 0.5;
    background: #f8f8f8;
    pointer-events: none;
    filter: grayscale(60%);
}

.wcb-product-card.wcb-out-of-stock .wcb-product-label {
    cursor: not-allowed;
}

.wcb-product-card.wcb-out-of-stock .wcb-item-qty-btn,
.wcb-product-card.wcb-out-of-stock .wcb-product-checkbox {
    pointer-events: none;
    opacity: 0.3;
}

/* Stock Badge */
.wcb-stock-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    border-radius: 999px;
    white-space: nowrap;
}

.wcb-stock-badge.wcb-oos {
    background: #ef4444;
    color: white;
}

.wcb-stock-badge.wcb-low-stock {
    background: #f59e0b;
    color: white;
}

.wcb-stock-badge.wcb-in-stock {
    background: #22c55e;
    color: white;
}

.wcb-product-label {
    flex: 1;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    cursor: default;
    padding: 0;
    min-width: 0;
}

/* Image */
.wcb-product-image {
    position: relative;
    width: 48px;
    height: 48px;
    background: #f0f0f1;
    overflow: hidden;
    border-radius: 2px;
    flex-shrink: 0;
}

.wcb-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Minimal Checkbox Top-Right */
.wcb-product-checkbox-wrapper {
    position: static;
    z-index: 1;
}

.wcb-product-checkbox {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.wcb-checkbox-custom {
    display: block;
    width: 18px;
    height: 18px;
    border: 1px solid #8c8f94;
    background: #fff;
    border-radius: 2px;
}

.wcb-product-checkbox:checked + .wcb-checkbox-custom {
    background: var(--wcb-primary);
    border-color: var(--wcb-primary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
    background-size: 12px;
    background-position: center;
    background-repeat: no-repeat;
}

/* Info */
.wcb-product-info {
    text-align: left;
    font-size: 13px;
    min-width: 0;
}

.wcb-product-name {
    display: block;
    color: var(--wcb-text);
    line-height: 1.3;
    font-weight: 500;
    display: -webkit-box;
    line-clamp: 1;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.wcb-product-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.wcb-product-price {
    font-size: 13px;
    color: var(--wcb-text-muted);
}

.wcb-price-free { color: var(--wcb-text); font-weight: bold; }
.wcb-price-discounted { color: #d63638; font-weight: 600; margin-left: 5px; }
.wcb-price-original { text-decoration: line-through; opacity: 0.7; }

/* Variation Selector */
.wcb-product-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 132px;
}

.wcb-variation-selector {
    padding: 0;
    background: transparent;
    border-top: 0;
}

.wcb-variation-select {
    width: 130px;
    max-width: 100%;
    font-size: 12px;
    padding: 4px;
    border: 1px solid var(--wcb-border);
    border-radius: 2px;
    background: #fff;
    color: var(--wcb-text);
}

/* ============================================
   Summary Section
   ============================================ */
.plugnload-wc-bundles-summary {
    margin-top: 20px;
    background: #fff;
    border: 1px solid var(--wcb-border);
    border-radius: 14px;
    overflow: hidden;
}

.plugnload-wc-bundles-summary h4 {
    margin: 0;
    padding: 16px 18px 12px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    color: #3c434a;
    border-bottom: 1px solid #eef2f7;
}

.plugnload-wc-bundles-summary-items {
    padding: 6px 18px 0;
}

.wcb-summary-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    font-size: 14px;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f1;
}

.wcb-summary-item-name {
    min-width: 0;
    flex: 1;
    color: var(--wcb-text);
}

.wcb-summary-item-price {
    white-space: nowrap;
    color: var(--wcb-text);
    font-weight: 600;
}

.wcb-summary-item-price-free {
    color: #166534;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.wcb-summary-item:last-child {
    border-bottom: none;
}

.plugnload-wc-bundles-summary-total,
.wcb-summary-total {
    margin-top: 0;
    padding: 18px 0 20px;
    border-top: 1px solid #eef2f7;
    background: #fcfcfd;
}

.wcb-savings {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    width: 100%;
    padding: 0 22px;
    box-sizing: border-box;
}

.wcb-savings-label {
    color: #3c434a;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
}

.wcb-savings-amount {
    color: var(--wcb-text);
    font-size: 18px;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
}

/* ============================================
   Cart Bundle Display
   ============================================ */
.wcb-cart-bundle-items {
    display: block;
    flex-direction: column;
    width: 100%;
    max-width: none;
    max-height: none;
    margin: 6px 0 0 0;
    padding: 0;
    font-size: 12px;
    color: var(--wcb-text-muted, #646970);
    white-space: normal;
    overflow: visible;
}

.wcb-cart-bundle-items li,
.wcb-cart-bundle-item-row {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    max-width: none;
    padding: 0;
    margin: 0 0 4px;
    white-space: normal;
    overflow: visible;
}

.wcb-cart-bundle-items li {
    border-bottom: 1px dashed #eee;
    padding-bottom: 4px;
}

.wcb-cart-bundle-items li:last-child {
    border-bottom: none;
}

.wcb-cart-bundle-item-row:last-child {
    margin-bottom: 0;
}

.wcb-cart-bundle-items .wcb-item-name,
.wcb-cart-bundle-item-row .wcb-item-name {
    min-width: 0;
    flex: 0 1 auto;
    white-space: normal;
    overflow-wrap: anywhere;
    overflow: visible;
    text-overflow: clip;
}

.wcb-cart-bundle-items .wcb-item-price,
.wcb-cart-bundle-item-row .wcb-item-price {
    color: var(--wcb-text, #2c3338);
    font-weight: 500;
    white-space: nowrap;
}

.wcb-cart-bundle-items .wcb-item-price-free,
.wcb-cart-bundle-item-row .wcb-item-price-free {
    color: #46b450;
    font-weight: 600;
    white-space: nowrap;
}

.woocommerce-cart-form .wcb-bundle-item {
    background-color: #fafafa;
}

/* Cart item data display for bundles */
.woocommerce-cart-form__cart-item dl.variation {
    margin-bottom: 0;
}

.woocommerce-cart-form__cart-item .wcb-cart-bundle-items {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
}

.woocommerce-cart-form__cart-item .wcb-cart-bundle-item-row {
    max-width: 100%;
}

.woocommerce-mini-cart .wcb-cart-bundle-items,
.widget_shopping_cart .wcb-cart-bundle-items,
.widget_shopping_cart_content .wcb-cart-bundle-items,
.mini_cart_item .wcb-cart-bundle-items {
    max-height: none;
    overflow: visible;
}

.woocommerce-mini-cart .wcb-cart-bundle-item-row,
.widget_shopping_cart .wcb-cart-bundle-item-row,
.widget_shopping_cart_content .wcb-cart-bundle-item-row,
.mini_cart_item .wcb-cart-bundle-item-row {
    width: 100%;
}

.woocommerce-mini-cart .wcb-cart-bundle-items .wcb-item-name,
.widget_shopping_cart .wcb-cart-bundle-items .wcb-item-name,
.widget_shopping_cart_content .wcb-cart-bundle-items .wcb-item-name,
.mini_cart_item .wcb-cart-bundle-items .wcb-item-name {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
}

.wc-block-components-product-details__bundle-includes {
    display: block !important;
    max-height: none !important;
    overflow: visible !important;
    white-space: normal !important;
}

.wc-block-components-product-details__bundle-includes .wc-block-components-product-details__name,
.wc-block-components-product-details__bundle-includes .wc-block-components-product-details__value {
    display: block !important;
    max-width: none !important;
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
}

.wc-block-components-product-details__bundle-includes .wcb-cart-bundle-items {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    white-space: normal !important;
}

.wc-block-components-product-details__bundle-includes .wcb-cart-bundle-item-row {
    display: flex !important;
    width: 100% !important;
    max-width: none !important;
    max-height: none !important;
    height: auto !important;
    margin: 0 0 4px !important;
    overflow: visible !important;
    white-space: normal !important;
}

.wc-block-components-product-details__bundle-includes .wcb-cart-bundle-item-row:last-child {
    margin-bottom: 0 !important;
}

.wc-block-components-product-details__bundle-includes .wcb-item-name {
    display: inline !important;
    min-width: 0 !important;
    max-width: none !important;
    overflow: visible !important;
    overflow-wrap: anywhere !important;
    text-overflow: clip !important;
    white-space: normal !important;
}

/* ============================================
   Dropdown Highlight Animation
   ============================================ */
.wcb-variation-select.wcb-highlight {
    animation: wcb-flash 0.3s ease-in-out 3;
    border-color: var(--wcb-primary) !important;
    outline: 2px solid var(--wcb-primary);
    outline-offset: 1px;
}

@keyframes wcb-flash {
    0%, 100% {
        background-color: #fff;
    }
    50% {
        background-color: #fff3cd;
    }
}

/* Hide bundle selector when not activated */
.plugnload-wc-bundles-selector.wcb-bundle-inactive .wcb-tiers-container {
    opacity: 0.4;
    pointer-events: none;
    filter: grayscale(50%);
}

/* ============================================
   Item Quantity Selector (Scaled Bundles)
   ============================================ */
.wcb-item-qty-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.wcb-item-qty-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--wcb-border);
    background: var(--wcb-bg-alt);
    color: var(--wcb-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--wcb-transition);
    user-select: none;
}

.wcb-item-qty-btn:hover {
    background: var(--wcb-primary);
    border-color: var(--wcb-primary);
    color: white;
}

.wcb-item-qty-minus {
    border-radius: var(--wcb-radius) 0 0 var(--wcb-radius);
}

.wcb-item-qty-plus {
    border-radius: 0 var(--wcb-radius) var(--wcb-radius) 0;
}

.wcb-item-qty-input {
    width: 40px;
    height: 28px;
    border: 1px solid var(--wcb-border);
    border-left: none;
    border-right: none;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--wcb-text);
    background: white;
    appearance: textfield;
    -moz-appearance: textfield;
}

.wcb-item-qty-input::-webkit-outer-spin-button,
.wcb-item-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
    display: none;
}

/* Firefox */
.wcb-item-qty-input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* When product has qty > 0 */
.wcb-product-card.wcb-selected .wcb-item-qty-input {
    color: var(--wcb-primary);
    font-weight: 700;
}

.wcb-no-products,
.wcb-no-matching-products {
    margin: 0;
    padding: 12px 15px;
    color: var(--wcb-text-muted);
    font-size: 13px;
}

@media (max-width: 560px) {
    .wcb-tier-header {
        flex-direction: column;
        align-items: stretch;
    }

    .wcb-tier-header-right {
        align-items: flex-start;
        justify-content: flex-start;
    }

    .wcb-tier-status {
        min-height: 28px;
    }

    .wcb-product-card {
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    .wcb-product-actions {
        justify-content: space-between;
        min-width: 0;
        padding-left: 58px;
        width: 100%;
    }

    .wcb-variation-selector {
        flex: 1;
    }

    .wcb-variation-select {
        width: 100%;
    }
}

/* ============================================
   Shop/Category Page Badge
   ============================================ */
.wcb-shop-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    max-width: 100%;
    background: #10b981;
    color: white;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    border-radius: 4px;
    cursor: help;
    margin: 0 auto 8px;
}

/* ============================================
   Cart - Bundle Quantity Disable
   ============================================ */
.wcb-cart-qty {
    font-weight: 600;
    font-size: 16px;
    margin-right: 8px;
}

.wcb-edit-bundle-link {
    font-size: 12px;
    color: var(--wcb-primary, #2271b1);
    text-decoration: none;
    display: block;
    margin-top: 4px;
}

.wcb-edit-bundle-link:hover {
    text-decoration: underline;
}

/* Hide quantity input for bundle items in cart */
.woocommerce-cart-form .wcb-bundle-item .quantity {
    display: none;
}
