/**
 * WooCommerce Tiered Pricing Styles
 * 
 * @package WC_Tiered_Pricing
 * @subpackage Tiered_Pricing
 */

/* ============================================
   Variation Swatches (Shopee Style)
   ============================================ */
.wc-variation-swatches {
    margin: 20px 0;
    padding: 0;
}

.wc-variation-attribute {
    margin-bottom: 20px;
}

.wc-variation-label {
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

.wc-variation-label strong {
    margin-right: 8px;
}

.wc-selected-value {
    color: #e74c3c;
    font-weight: 600;
    margin-left: 5px;
}

.wc-variation-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.wc-variation-option {
    padding: 8px 16px;
    border: 2px solid #ddd;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    color: #333;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.wc-variation-option:hover {
    border-color: #e74c3c;
    color: #e74c3c;
}

.wc-variation-option.active {
    border-color: #e74c3c;
    background: #e74c3c;
    color: #fff;
    font-weight: 600;
}

.wc-variation-option.active::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    background: #27ae60;
    color: #fff;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid #fff;
}

/* Color swatches */
.wc-variation-color .wc-variation-option {
    width: 50px;
    height: 50px;
    padding: 0;
    border-radius: 50%;
    border: 3px solid #ddd;
    position: relative;
    overflow: visible;
}

.wc-variation-color .wc-variation-option:hover {
    border-color: #e74c3c;
    transform: scale(1.1);
}

.wc-variation-color .wc-variation-option.active {
    border-color: #e74c3c;
    border-width: 3px;
    transform: scale(1.15);
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #e74c3c;
}

.wc-color-swatch {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: block;
}

/* Size swatches */
.wc-variation-size .wc-variation-option {
    min-width: 50px;
    padding: 10px 15px;
    font-weight: 700;
}

/* Text swatches */
.wc-variation-text .wc-variation-option {
    padding: 2px;
    font-size: 8pt;
}

/* Hide default variation dropdown */
.wc-variation-dropdown-hidden {
    display: none !important;
}

/* Hide default WooCommerce variation dropdowns when swatches are present */
body.single-product.has-wc-swatches .variations select,
body.single-product.has-wc-swatches .variations tr,
body.single-product.has-wc-swatches .variations .form-row,
body.single-product.has-wc-swatches .variations table {
    display: none !important;
}

/* Alternative: Hide when swatches container exists */
body.single-product .wc-variation-swatches ~ .variations,
body.single-product .variations:has(+ .wc-variation-swatches) {
    display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
    .wc-variation-options {
        gap: 8px;
    }
    
    .wc-variation-option {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .wc-variation-color .wc-variation-option {
        width: 45px;
        height: 45px;
    }
}

/* ============================================
   Tier Table Container
   ============================================ */
.wc-tier-table-container {
    margin: 20px 0;
    padding: 20px;
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.wc-tier-table-title {
    margin: 0 0 20px 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
    text-align: center;
}

/* ============================================
   Tier Table
   ============================================ */
.wc-tier-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.wc-tier-header {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    font-weight: 600;
    color: #495057;
    text-align: center;
}

.wc-tier-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 15px;
    padding: 15px;
    border-bottom: 1px solid #e9ecef;
    text-align: center;
    transition: background-color 0.2s ease;
}

.wc-tier-row:hover {
    background-color: #f8f9fa;
}

.wc-tier-row.wc-tier-over-quantity {
    background-color: #fff3cd;
    border-color: #ffeaa7;
    font-style: italic;
    color: #856404;
}

.wc-tier-col-qty {
    font-weight: 500;
}

.wc-tier-col-discount {
    color: #28a745;
    font-weight: 500;
}

.wc-tier-col-price {
    color: #007cba;
    font-weight: 600;
}

.wc-tier-col-save {
    color: #dc3545;
    font-weight: 500;
}

/* ============================================
   Quantity Input
   ============================================ */
.wc-tier-quantity-input {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
}

.wc-tier-quantity-input label {
    font-weight: 500;
    color: #495057;
}

.wc-qty-controls,
.b2b-qty-controls {
    display: flex;
    align-items: center;
    border: 1px solid #ced4da;
    border-radius: 4px;
    overflow: hidden;
    gap: 5px;
    margin: 10px 0;
}

.wc-qty-minus,
.wc-qty-plus,
.b2b-qty-minus,
.b2b-qty-plus {
    width: 40px;
    height: 40px;
    border: none;
    background: #007cba;
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wc-qty-minus:hover,
.wc-qty-plus:hover,
.b2b-qty-minus:hover,
.b2b-qty-plus:hover {
    background: #005a87;
}

.wc-qty-input,
.b2b-qty-input {
    width: auto;
    height: 40px;
    border: none;
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    background: white;
    padding: 5px;
}

.wc-qty-input:focus,
.b2b-qty-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.25);
}

.wc-tier-selected-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 10px;
}

.wc-tier-selected-price {
    font-size: 18px;
    font-weight: 600;
    color: #007cba;
}

.wc-tier-selected-tier {
    font-size: 14px;
    color: #6c757d;
    font-style: italic;
}

/* ============================================
   Actions & Buttons
   ============================================ */
.wc-tier-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 15px;
    text-align: center;
}

.wc-tier-actions .button {
    display: inline-block !important;
    margin: 5px;
    min-width: 120px;
}

/* Button visibility logic */
.b2b-order-tiered,
.wc-order-tiered {
    display: none;
}

.wc-tier-table-container.b2b-over-qty .b2b-add-to-cart-tiered,
.wc-tier-table-container.b2b-over-qty .wc-add-to-cart-tiered,
.wc-tier-table-container.b2b-over-qty .wc-buy-now-tiered {
    display: none !important;
}

.wc-tier-table-container.b2b-over-qty .b2b-order-tiered,
.wc-tier-table-container.b2b-over-qty .wc-order-tiered {
    display: inline-block !important;
}

.b2b-add-to-cart-tiered,
.wc-add-to-cart-tiered,
.wc-buy-now-tiered,
.b2b-order-tiered,
.wc-order-tiered {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
}

.b2b-add-to-cart-tiered,
.wc-add-to-cart-tiered,
.wc-buy-now-tiered {
    background: #28a745;
    color: white;
}

.b2b-add-to-cart-tiered:hover,
.wc-add-to-cart-tiered:hover,
.wc-buy-now-tiered:hover {
    background: #218838;
    color: white;
    text-decoration: none;
}

.wc-buy-now-tiered {
    background: #ff9800;
}

.wc-buy-now-tiered:hover {
    background: #fb8c00;
}

.b2b-order-tiered,
.wc-order-tiered {
    background: #dc3545;
    color: white;
}

.b2b-order-tiered:hover,
.wc-order-tiered:hover {
    background: #c82333;
    color: white;
    text-decoration: none;
}

/* Button visibility classes */
.b2b-hide-add-to-cart {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
}

.b2b-hide-order-button {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
    position: absolute !important;
    left: -9999px !important;
}

.b2b-show-add-to-cart {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    width: auto !important;
    overflow: visible !important;
    position: static !important;
    left: auto !important;
}

.b2b-show-order-button {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    width: auto !important;
    overflow: visible !important;
    position: static !important;
    left: auto !important;
}

/* ============================================
   Checkout Button Modifications
   ============================================ */
.woocommerce-checkout .checkout-button {
    background: #007cba !important;
    color: white !important;
    border: none !important;
    padding: 12px 24px !important;
    border-radius: 6px !important;
    font-size: 16px !important;
    font-weight: 500 !important;
    text-decoration: none !important;
    display: inline-block !important;
    transition: background-color 0.2s ease !important;
}

.woocommerce-checkout .checkout-button:hover {
    background: #005a87 !important;
    color: white !important;
}

/* Nút "Đặt hàng" - Màu đỏ */
.b2b-restricted-checkout,
.b2b-order-button.b2b-restricted-checkout {
    background-color: #e74c3c !important;
    border-color: #e74c3c !important;
    color: white !important;
}

.b2b-restricted-checkout:hover,
.b2b-order-button.b2b-restricted-checkout:hover {
    background-color: #c0392b !important;
    border-color: #c0392b !important;
    color: white !important;
}

/* Nút "Thanh toán" - Màu xanh */
.checkout-button:not(.b2b-restricted-checkout),
#check-out:not(.b2b-restricted-checkout) {
    background-color: #0073aa !important;
    border-color: #0073aa !important;
    color: white !important;
}

.checkout-button:not(.b2b-restricted-checkout):hover,
#check-out:not(.b2b-restricted-checkout):hover {
    background-color: #005a87 !important;
    border-color: #005a87 !important;
    color: white !important;
}

.b2b-order-button {
    background-color: #007cba;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    position: relative;
}

.b2b-order-button:hover {
    background-color: #005a87;
    color: white;
    text-decoration: none;
}

.b2b-order-button-container {
    display: block !important;
    text-align: center;
    margin: 20px 0;
}

.b2b-order-button-container .b2b-order-button {
    display: inline-block !important;
    padding: 15px 30px;
    font-size: 16px;
}

/* ============================================
   Loading States
   ============================================ */
.wc-tier-loading {
    position: relative;
    opacity: 0.7;
    pointer-events: none;
    cursor: not-allowed;
}

.wc-tier-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007cba;
    border-radius: 50%;
    animation: wc-tier-spin 1s linear infinite;
}

@keyframes wc-tier-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   Messages
   ============================================ */
.wc-tier-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 4px;
    z-index: 9999;
    max-width: 300px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    font-weight: 500;
}

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

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

/* ============================================
   Tier Info Badges
   ============================================ */
.wc-tier-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 8px;
}

.wc-tier-badge {
    background: #007cba;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
}

.wc-tier-price {
    color: #007cba;
    font-weight: bold;
    font-size: 14px;
}

.b2b-unit-price {
    color: #666;
    font-size: 12px;
    font-style: italic;
}

.wc-tier-discount {
    color: #28a745;
    font-size: 12px;
    font-weight: bold;
}

/* Over quantity price display */
.b2b-over-quantity-price {
    color: #dc3545;
    font-weight: bold;
    font-style: italic;
}

.b2b-over-quantity-badge {
    background: #dc3545;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
}

.b2b-over-quantity-price-display {
    color: #999 !important;
    font-style: italic !important;
    opacity: 0.6 !important;
    text-decoration: line-through !important;
}

/* ============================================
   Mini Cart & Loop
   ============================================ */
.b2b-mini-cart .quote-button,
.widget_shopping_cart .quote-button {
    display: none !important;
}

.b2b-mini-cart .wc-tier-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    font-size: 12px;
    color: #6c757d;
}

.woocommerce-loop-product__title + .b2b-loop-tier-info {
    margin-top: 5px;
    font-size: 12px;
    color: #6c757d;
}

.b2b-loop-tier-info .wc-tier-badge {
    background: #28a745;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
}

.woocommerce-cart-form .b2b-cart-tier-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    font-size: 12px;
    color: #6c757d;
}

.b2b-cart-tier-info .wc-tier-badge {
    background: #007cba;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
}

/* Hide custom quantity selector on cart page */
.woocommerce-cart .wc-tier-quantity-input {
    display: none !important;
}

/* ============================================
   Checkout Page Styles
   ============================================ */
.wc-checkout-payment-disabled {
    pointer-events: none;
    opacity: 0.5;
    position: relative;
}

.wc-checkout-payment-disabled::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
    border-radius: 4px;
}

.wc-checkout-message {
    background: #fff3cd !important;
    border: 1px solid #ffeaa7 !important;
    padding: 15px !important;
    margin: 20px 0 !important;
    border-radius: 4px !important;
    color: #856404 !important;
    text-align: center;
}

.wc-checkout-message p {
    margin: 0 !important;
    font-weight: 500;
}

.wc-checkout-message p:not(:last-child) {
    margin-bottom: 10px !important;
}

.wc-order-button-alternative {
    background: #e74c3c !important;
    color: white !important;
    border: none !important;
    padding: 12px 30px !important;
    border-radius: 4px !important;
    font-weight: bold !important;
    text-align: center;
    margin: 20px 0;
    display: block;
    width: 100%;
    cursor: pointer;
    transition: background 0.3s ease;
}

.wc-order-button-alternative:hover {
    background: #c0392b !important;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .wc-tier-table-container {
        padding: 15px;
        margin: 15px 0;
    }
    
    .wc-tier-header,
    .wc-tier-row {
        grid-template-columns: 1fr;
        gap: 10px;
        text-align: left;
    }
    
    .wc-tier-header > div,
    .wc-tier-row > div {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px solid #e9ecef;
    }
    
    .wc-tier-header > div:before,
    .wc-tier-row > div:before {
        content: attr(data-label);
        font-weight: 500;
        color: #6c757d;
    }
    
    .wc-tier-quantity-input {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .wc-tier-actions {
        flex-direction: column;
    }
    
    .b2b-add-to-cart-tiered,
    .wc-add-to-cart-tiered,
    .b2b-order-tiered,
    .wc-order-tiered {
        width: 100%;
        text-align: center;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .wc-tier-table-container {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .wc-tier-actions {
        display: none;
    }
    
    .wc-tier-quantity-input {
        display: none;
    }
}
