/* JustB2B Quantity Buttons - Professional Styling */

/* ==========================================================================
   CSS Variables for Consistent Theming
   ========================================================================== */

:root {
    --j2b-primary-color: #000000;
    --j2b-primary-hover: #333333;
    --j2b-primary-active: #000000;
    --j2b-text-light: #ffffff;
    --j2b-text-dark: #374151;
    --j2b-border-color: #d1d5db;
    --j2b-border-hover: #9ca3af;
    --j2b-background-default: #f9fafb;
    --j2b-background-hover: #f3f4f6;
    --j2b-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --j2b-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --j2b-transition: none;
    --j2b-border-radius: 4px;
    --j2b-border-radius-lg: 4px;
    --j2b-spacing-xs: 4px;
    --j2b-spacing-sm: 6px;
    --j2b-spacing-md: 8px;
    --j2b-spacing-xl: 12px;
    --j2b-spacing-2xl: 16px;
}

/* ==========================================================================
   Quantity Buttons
   ========================================================================== */

.quantity-buttons {
    margin-top: var(--j2b-spacing-xl);
    display: flex;
    flex-wrap: wrap;
    gap: var(--j2b-spacing-sm);
    align-items: center;
}

/* ==========================================================================
   Quantity Button Base Styles
   ========================================================================== */

.qty-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--j2b-spacing-sm) var(--j2b-spacing-xl);
    min-width: 36px;
    min-height: 28px;
    border: 1px solid var(--j2b-border-color);
    border-radius: var(--j2b-border-radius);
    background-color: var(--j2b-background-default);
    color: var(--j2b-text-dark);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    cursor: pointer;
    transition: var(--j2b-transition);
    box-shadow: var(--j2b-shadow-sm);
    user-select: none;
    -webkit-appearance: none;
    appearance: none;
    outline: none;

    /* State variations */
    &:hover {
        background-color: var(--j2b-background-hover);
        border-color: var(--j2b-border-hover);
        box-shadow: var(--j2b-shadow-md);
        transform: translateY(-1px);
    }

    &:focus {
        outline: 2px solid var(--j2b-primary-color);
        outline-offset: 2px;
        box-shadow: var(--j2b-shadow-md), 0 0 0 2px rgba(0, 0, 0, 0.2);
    }

    &:active {
        transform: translateY(0);
        box-shadow: var(--j2b-shadow-sm);
    }

    &.active {
        background-color: var(--j2b-primary-color);
        border-color: var(--j2b-primary-active);
        color: var(--j2b-text-light);
        box-shadow: var(--j2b-shadow-md);
        font-weight: 600;

        &:hover {
            background-color: var(--j2b-primary-hover);
            border-color: var(--j2b-primary-active);
        }

        &:focus {
            outline-color: var(--j2b-primary-color);
            box-shadow: var(--j2b-shadow-md), 0 0 0 2px rgba(0, 0, 0, 0.3);
        }
    }

    &.loading {
        opacity: 0.7;
        pointer-events: none;

        &::after {
            content: '';
            position: absolute;
            width: var(--j2b-spacing-xl);
            height: var(--j2b-spacing-xl);
            margin: auto;
            border: 2px solid transparent;
            border-top-color: currentColor;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
    }
}

/* ==========================================================================
   Related Products Options Styling
   ========================================================================== */

#justb2b_related_products_list {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--j2b-spacing-sm);
    border: none;
    padding: 0;
    margin-top: var(--j2b-spacing-2xl);
}

/* ==========================================================================
   Product Option Labels
   ========================================================================== */

#justb2b_related_products_list label {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 2px;
    border: 1px solid var(--j2b-border-color);
    padding: var(--j2b-spacing-sm);
    cursor: pointer;
    border-radius: var(--j2b-border-radius-lg);
    background-color: var(--j2b-background-default);
    transition: var(--j2b-transition);
    box-shadow: var(--j2b-shadow-sm);
    position: relative;

    &:hover {
        border-color: var(--j2b-border-hover);
        background-color: var(--j2b-background-hover);
        box-shadow: var(--j2b-shadow-md);
        transform: translateY(-2px);
    }

    /* Hidden radio input */
    input[type="radio"] {
        position: absolute;
        opacity: 0;
        pointer-events: none;
    }

    /* Product image */
    img {
        width: 60px;
        height: 60px;
        object-fit: cover;
        border-radius: var(--j2b-border-radius);
        border: 1px solid var(--j2b-border-color);
        flex-shrink: 0;
        padding: 0;
        margin: 0;
        align-self: center;
    }

    /* Product info */
    span {
        flex: 1;
        font-size: 11px;
        font-weight: 500;
        color: var(--j2b-text-dark);
        line-height: 1.3;
        word-wrap: break-word;
        text-align: center;
        width: 100%;
    }

    /* Price styling */
    strong {
        font-size: 10px;
        font-weight: 600;
        color: var(--j2b-primary-color);
        text-align: center;

        .woocommerce-Price-amount {
            font-size: 10px;
            font-weight: 600;
        }
    }

    /* Selected state styling */
    &:has(input[type="radio"]:checked) {
        border-color: var(--j2b-primary-color);
        background-color: rgba(0, 0, 0, 0.05);
        box-shadow: var(--j2b-shadow-md), 0 0 0 2px rgba(0, 0, 0, 0.1);

        &::before {
            content: '';
            position: absolute;
            top: var(--j2b-spacing-sm);
            left: var(--j2b-spacing-sm);
            width: 20px;
            height: 20px;
            background-color: var(--j2b-primary-color);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 12px;
            font-weight: bold;
            z-index: 1;
        }

        &::after {
            content: '✓';
            position: absolute;
            top: var(--j2b-spacing-sm);
            left: var(--j2b-spacing-sm);
            width: 20px;
            height: 20px;
            color: white;
            font-size: 12px;
            font-weight: bold;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 2;
        }
    }
}

/* ==========================================================================
   Animations
   ========================================================================== */

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

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

@media (max-width: 768px) {
    .quantity-buttons {
        gap: var(--j2b-spacing-xs);
    }

    .qty-button {
        padding: var(--j2b-spacing-xs) var(--j2b-spacing-md);
        min-width: 32px;
        min-height: 24px;
        font-size: 11px;
    }

    #justb2b_related_products_list {
        gap: var(--j2b-spacing-xs);
        grid-template-columns: repeat(7, 1fr);
    }

    #justb2b_related_products_list label img {
        width: 50px;
        height: 50px;
    }

    #justb2b_related_products_list label span {
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    #justb2b_related_products_list {
        grid-template-columns: repeat(3, 1fr);
    }

    #justb2b_related_products_list label img {
        width: 45px;
        height: 45px;
        padding: 0;
        margin: 0;
    }

    #justb2b_related_products_list label span {
        font-size: 9px;
    }
}
