/**
 * B2B Tiered Pricing Styles
 * 
 * @package B2B_Management
 * @subpackage Tiered_Pricing
 */

/* Tier Table Container */
.b2b-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);
}

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

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

.b2b-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;
}

.b2b-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;
}

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

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

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

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

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

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

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

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

.b2b-qty-controls {
    display: flex;
    align-items: center;
    border: 1px solid #ced4da;
    border-radius: 4px;
    overflow: hidden;
}

.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;
}

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

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

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

.b2b-tier-selected-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

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

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

/* Actions */
.b2b-tier-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

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

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

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

/* Hide potential external quote buttons in mini-cart */
.b2b-mini-cart .quote-button, .widget_shopping_cart .quote-button { display: none !important; }

.b2b-add-to-cart-tiered,
.b2b-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 {
    background: #28a745;
    color: white;
}

.b2b-add-to-cart-tiered:hover {
    background: #218838;
    color: white;
}

.b2b-order-tiered {
    background: #007cba;
    color: white;
}

.b2b-order-tiered:hover {
    background: #005a87;
    color: white;
}

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

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

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

.b2b-tier-price {
    font-weight: 500;
    color: #007cba;
}

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

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

/* Cart Page Tier Info */
.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 .b2b-tier-badge {
    background: #007cba;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
}

/* Checkout Button Override */
.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;
}

/* Loading States */
.b2b-tier-loading {
    position: relative;
    opacity: 0.7;
    pointer-events: none;
}

.b2b-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: b2b-spin 1s linear infinite;
}

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

/* Tier info in mini cart */
.b2b-tier-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 8px;
}

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

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

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

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

/* Checkout button modifications */
.b2b-order-button {
    background: #dc3545 !important;
    color: white !important;
    border-color: #dc3545 !important;
}

.b2b-order-button:hover {
    background: #c82333 !important;
    border-color: #bd2130 !important;
}

/* Prevent duplicate buttons */
.b2b-checkout-modified .b2b-order-button {
    display: block !important;
}

.b2b-checkout-modified .b2b-checkout-notice {
    display: block !important;
}

.b2b-checkout-notice {
    background: #fff3cd !important;
    border: 1px solid #ffeaa7 !important;
    padding: 15px !important;
    margin: 15px 0 !important;
    border-radius: 4px !important;
    color: #856404 !important;
}

.b2b-checkout-notice p {
    margin: 0 !important;
}

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

/* Tier actions styling */
.b2b-tier-actions {
    margin-top: 15px;
    text-align: center;
}

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

.b2b-add-to-cart-tiered {
    background-color: #007cba;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
}

.b2b-add-to-cart-tiered:hover {
    background-color: #005a87;
    color: white;
    text-decoration: none;
}

.b2b-order-tiered {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
}

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

/* Loading state */
.b2b-tier-loading {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Message styling */
.b2b-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);
}

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

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

.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;
}

.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;
}

/* 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;
}

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

/* Quantity controls styling */
.b2b-qty-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 10px 0;
}

.b2b-qty-controls button {
    background: #007cba;
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

.b2b-qty-controls button:hover {
    background: #005a87;
}

.b2b-qty-controls input {
    width: 60px;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
}

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

.b2b-tier-selected-price {
    font-weight: bold;
    color: #007cba;
    font-size: 16px;
}

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

/* Success/Error Messages */
.b2b-tier-message {
    padding: 12px 16px;
    border-radius: 6px;
    margin: 10px 0;
    font-weight: 500;
}

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

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

/* Tooltip */
.b2b-tier-tooltip {
    position: relative;
    cursor: help;
}

.b2b-tier-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.b2b-tier-tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

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

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

/* Enforce single visible button in product block */
.b2b-tier-table-container .b2b-order-tiered { display: none; }
.b2b-tier-table-container.b2b-over-qty .b2b-add-to-cart-tiered { display: none !important; }
.b2b-tier-table-container.b2b-over-qty .b2b-order-tiered { display: inline-block !important; }

/* Force override checkout button text for Elementor */
#check-out.b2b-order-button {
    background: #dc3545 !important;
    color: white !important;
}

#check-out.b2b-order-button .elementor-button-text {
    color: white !important;
}


/* Simple button visibility classes */
.b2b-hide-button {
    display: none !important;
}

.b2b-show-button {
    display: inline-block !important;
}

/* Specific button classes - Enhanced */
.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;
}

/* Cart page restricted checkout button styling */
.b2b-restricted-checkout {
    background-color: #e74c3c !important;
    border-color: #e74c3c !important;
    color: white !important;
}

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

/* Cart page button visibility */
.b2b-order-button {
    position: relative;
}

.b2b-order-button::after {
    content: " (B2B Order)";
    font-size: 0.8em;
    opacity: 0.7;
}
