/**
 * Frontend CSS for Weight-Based Pricing
 */

/* Weight Selector Container */
.wccwp-weight-selector {
    margin-bottom: 20px;
    padding: 15px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.wccwp-weight-selector label {
    display: block;
    font-weight: bold;
    margin-bottom: 10px;
}

/* Weight Presets */
.wccwp-weight-presets {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.wccwp-preset-btn {
    padding: 8px 16px;
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    color: #333 !important; /* Ensure text is always visible */
}

.wccwp-preset-btn:hover {
    background: #f0f0f0;
    border-color: #999;
    color: #333 !important;
}

.wccwp-preset-btn.active {
    background: #333;
    color: #fff !important;
    border-color: #333;
}

/* Custom Weight Input - Hidden for preset-only mode */
.wccwp-custom-weight {
    display: none;
}

/* Price Display */
.wccwp-price-display {
    background: #fff;
    padding: 10px 15px;
    border: 2px solid #27ae60;
    border-radius: 4px;
    text-align: center;
}

.wccwp-calculated-price {
    font-size: 1.4em;
    font-weight: bold;
    color: #27ae60;
}

/* Price per gram display */
.wccwp-price-per-gram {
    margin: 10px 0;
    padding: 8px;
    background: #f9f9f9;
    border-left: 3px solid #27ae60;
}

.wccwp-price-per-gram .price {
    font-size: 1.1em;
    color: #666;
}

/* Cart Weight Display */
.wccwp-cart-weight {
    font-weight: bold;
    color: #27ae60;
}

/* Order Weight Display */
.wccwp-order-weight {
    color: #666;
    font-weight: normal;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .wccwp-weight-presets {
        justify-content: space-between;
    }
    
    .wccwp-preset-btn {
        flex: 1 1 45%;
        text-align: center;
    }
    
}

/* Hide default price displays for weight-based products */
.woocommerce-product-details__short-description + .price,
.summary > .price:first-of-type {
    /* Will be hidden by inline styles for weight-based products */
}

/* Integration with common themes */
.woocommerce div.product form.cart .wccwp-weight-selector {
    clear: both;
}

/* Storefront theme compatibility */
.storefront-full-width-content .wccwp-weight-selector {
    max-width: 100%;
}

/* Flatsome theme compatibility */
.product-info .wccwp-weight-selector {
    margin-top: 15px;
}

/* Disable quantity buttons for weight-based products */
.product-type-simple.wccwp-weight-based .quantity {
    display: none !important;
}

/* Variation Form Adjustments */
.variations_form .wccwp-weight-selector {
    display: none;
}

.variations_form.variation-selected .wccwp-weight-selector {
    display: block;
}

/* Loading State */
.wccwp-weight-selector.loading {
    opacity: 0.5;
    pointer-events: none;
}

.wccwp-weight-selector.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 #333;
    border-radius: 50%;
    animation: wccwp-spin 1s linear infinite;
}

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

/* Savings Message */
.wccwp-savings-message {
    margin-top: 10px;
    padding: 8px 12px;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    color: #856404;
    font-size: 0.9em;
    font-weight: 500;
    display: none;
}

.wccwp-savings-message:not(:empty) {
    display: block;
}

/* Loading state for price */
.wccwp-loading {
    color: #999;
    font-style: italic;
}

/* Shop/Archive Page Styles */
.wccwp-price-range {
    display: block;
    margin-bottom: 8px;
}

.wccwp-price-range .separator {
    margin: 0 5px;
    color: #666;
    font-weight: normal;
}

/* Ensure both price amounts have identical styling */
.wccwp-price-range .woocommerce-Price-amount {
    font-size: inherit !important;
    font-weight: inherit !important;
    color: inherit !important;
    text-decoration: none !important;
}

.wccwp-price-range .woocommerce-Price-amount.amount {
    font-size: inherit !important;
    font-weight: inherit !important;
    color: inherit !important;
}

.wccwp-price-range .woocommerce-Price-amount bdi {
    font-size: inherit !important;
    font-weight: inherit !important;
    color: inherit !important;
}

.wccwp-price-range .woocommerce-Price-currencySymbol {
    font-size: inherit !important;
    font-weight: inherit !important;
    color: inherit !important;
}


/* Select Options Button Styling */
.wccwp-select-options {
    background: #27ae60 !important;
    color: #fff !important;
    border-color: #27ae60 !important;
}

.wccwp-select-options:hover {
    background: #229954 !important;
    border-color: #229954 !important;
}

/* Make the button stand out for weight-based products */
.product.wccwp-weight-based .add_to_cart_button,
.product .wccwp-select-options {
    font-weight: 600;
}


/* Theme-specific adjustments */
/* Storefront theme */
.storefront .wccwp-price-range {
    font-size: 1.1em;
}

/* GeneratePress theme */
.generatepress .wccwp-select-options {
    width: 100%;
    text-align: center;
}

/* Tier Consolidation Display */
.wccwp-tier-consolidation-info {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 20px;
    font-family: inherit;
}

.wccwp-tier-consolidation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.wccwp-tier-consolidation-title {
    color: #155724;
    font-weight: 600;
    display: flex;
    align-items: center;
    font-size: 1em;
}

.wccwp-tier-consolidation-icon {
    font-size: 1.2em;
    margin-right: 8px;
    display: inline-block;
}

.wccwp-tier-consolidation-savings {
    color: #155724;
    font-weight: bold;
    font-size: 1.1em;
}

.wccwp-tier-consolidation-details {
    font-size: 0.9em;
}

.wccwp-tier-consolidation-tier {
    margin-bottom: 8px;
}

.wccwp-tier-consolidation-tier-line {
    display: flex;
    justify-content: space-between;
    color: #495057;
}

.wccwp-tier-consolidation-tier-info {
    font-weight: 500;
}

.wccwp-tier-consolidation-tier-savings {
    color: #155724;
}

.wccwp-tier-consolidation-note {
    font-size: 0.8em;
    color: #6c757d;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #c3e6cb;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .wccwp-tier-consolidation-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .wccwp-tier-consolidation-tier-line {
        flex-direction: column;
        gap: 4px;
    }
    
    .wccwp-tier-consolidation-tier-savings {
        text-align: left;
    }
}

/* Dark theme compatibility */
.dark .wccwp-tier-consolidation-info,
body.dark .wccwp-tier-consolidation-info {
    background: #2d3748;
    border-color: #4a5568;
    color: #e2e8f0;
}

.dark .wccwp-tier-consolidation-title,
body.dark .wccwp-tier-consolidation-title,
.dark .wccwp-tier-consolidation-savings,
body.dark .wccwp-tier-consolidation-savings {
    color: #68d391;
}


.dark .wccwp-tier-consolidation-tier-line,
body.dark .wccwp-tier-consolidation-tier-line {
    color: #cbd5e0;
}

.dark .wccwp-tier-consolidation-tier-savings,
body.dark .wccwp-tier-consolidation-tier-savings {
    color: #68d391;
}

.dark .wccwp-tier-consolidation-note,
body.dark .wccwp-tier-consolidation-note {
    color: #a0aec0;
    border-color: #4a5568;
}

/* Quantity Pricing Display */
.wccwp-quantity-pricing-header {
    margin-top: 15px;
    border-top: 1px solid #c3e6cb;
    padding-top: 15px;
}

.wccwp-quantity-pricing-title {
    color: #155724;
    font-weight: 600;
    display: flex;
    align-items: center;
    font-size: 1em;
    margin-bottom: 10px;
}

.wccwp-quantity-pricing-icon {
    font-size: 1.2em;
    margin-right: 8px;
    display: inline-block;
}

.wccwp-quantity-pricing-details {
    font-size: 0.9em;
}

.wccwp-quantity-pricing-item {
    margin-bottom: 8px;
}

.wccwp-quantity-pricing-item-line {
    color: #495057;
}

.wccwp-quantity-pricing-item-info {
    font-weight: 500;
}

.wccwp-quantity-pricing-note {
    font-size: 0.8em;
    color: #6c757d;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #c3e6cb;
}

/* Dark theme compatibility for quantity pricing */
.dark .wccwp-quantity-pricing-title,
body.dark .wccwp-quantity-pricing-title {
    color: #68d391;
}

.dark .wccwp-quantity-pricing-item-line,
body.dark .wccwp-quantity-pricing-item-line {
    color: #cbd5e0;
}

.dark .wccwp-quantity-pricing-note,
body.dark .wccwp-quantity-pricing-note {
    color: #a0aec0;
    border-color: #4a5568;
}

/* Bulk Pricing Motivation Display */
.wccwp-bulk-pricing-motivation {
    margin: 20px 0;
    padding: 20px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
}

.wccwp-tiers-title {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 700;
    color: #2c3e50;
    display: flex;
    align-items: center;
}

.wccwp-tiers-subtitle {
    margin: 0 0 15px 0;
    font-size: 14px;
    color: #6c757d;
    font-style: italic;
}

/* Pricing table styles (both weight and quantity) */
.wccwp-weight-pricing-tiers,
.wccwp-quantity-pricing-tiers {
    margin-bottom: 20px;
}

.wccwp-pricing-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.wccwp-pricing-table thead th {
    background: #f8f9fa;
    font-weight: 700;
    color: #495057;
    font-size: 14px;
    padding: 12px 16px;
    border-bottom: 2px solid #e9ecef;
    text-align: left;
}

.wccwp-pricing-table tbody tr {
    transition: all 0.3s ease;
    position: relative;
}

.wccwp-pricing-table tbody tr:hover {
    background: #f8f9fa;
}

.wccwp-pricing-table tbody tr:nth-child(even) {
    background: #fafafa;
}

.wccwp-pricing-table tbody tr:nth-child(even):hover {
    background: #f0f0f0;
}

.wccwp-pricing-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

.wccwp-pricing-table tbody tr:last-child td {
    border-bottom: none;
}

/* Quantity table columns */
.wccwp-table-qty {
    width: 30%;
    font-weight: 600;
    color: #2c3e50;
}

.wccwp-table-price {
    width: 70%;
    font-weight: 600;
    color: #27ae60;
    text-align: center;
}

/* Weight table columns */
.wccwp-table-weight {
    width: 25%;
    font-weight: 600;
    color: #2c3e50;
}

.wccwp-table-total {
    width: 50%;
    font-weight: 600;
    color: #27ae60;
    text-align: center;
}

.wccwp-table-per-gram {
    width: 25%;
    text-align: right;
    color: #6c757d;
    font-size: 14px;
}

/* Best value row styling */
.wccwp-pricing-table tbody tr.wccwp-best-value-row {
    background: linear-gradient(135deg, #fff8e1, #fffde7) !important;
    border-left: 4px solid #f39c12;
}

.wccwp-pricing-table tbody tr.wccwp-best-value-row:hover {
    background: linear-gradient(135deg, #fff3c4, #fff8e1) !important;
}

.wccwp-best-value-indicator {
    font-size: 16px;
    text-align: center;
    padding: 0 8px;
}


.wccwp-tiers-note {
    font-size: 13px;
    color: #6c757d;
    text-align: center;
    padding: 8px;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    margin-top: 12px;
}

/* Responsive design */
@media (max-width: 768px) {
    .wccwp-pricing-table th,
    .wccwp-pricing-table td {
        padding: 10px 8px;
        font-size: 14px;
    }
    
    .wccwp-tiers-title {
        font-size: 16px;
    }
    
    .wccwp-table-price,
    .wccwp-table-total {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .wccwp-bulk-pricing-motivation {
        margin: 15px 0;
        padding: 15px;
    }
    
    .wccwp-pricing-table {
        font-size: 13px;
    }
    
    .wccwp-pricing-table th,
    .wccwp-pricing-table td {
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .wccwp-pricing-table thead th {
        font-size: 13px;
        padding: 10px 6px;
    }
}

/* Dark theme compatibility */
.dark .wccwp-bulk-pricing-motivation,
body.dark .wccwp-bulk-pricing-motivation {
    background: #2d3748;
    border-color: #4a5568;
}

.dark .wccwp-tiers-title,
body.dark .wccwp-tiers-title {
    color: #e2e8f0;
}

.dark .wccwp-tiers-subtitle,
body.dark .wccwp-tiers-subtitle {
    color: #a0aec0;
}

.dark .wccwp-pricing-table,
body.dark .wccwp-pricing-table {
    background: #1a202c;
    border-color: #4a5568;
}

.dark .wccwp-table-row,
body.dark .wccwp-table-row {
    border-bottom-color: #2d3748;
}

.dark .wccwp-table-row:hover,
body.dark .wccwp-table-row:hover {
    background: #2d3748;
}

.dark .wccwp-table-header,
body.dark .wccwp-table-header {
    background: #2d3748;
    color: #a0aec0;
}

.dark .wccwp-table-header:hover,
body.dark .wccwp-table-header:hover {
    background: #2d3748;
}

.dark .wccwp-table-qty,
body.dark .wccwp-table-qty,
.dark .wccwp-table-weight,
body.dark .wccwp-table-weight {
    color: #e2e8f0;
}

.dark .wccwp-table-price,
body.dark .wccwp-table-price,
.dark .wccwp-table-total,
body.dark .wccwp-table-total {
    color: #68d391;
}

.dark .wccwp-table-savings,
body.dark .wccwp-table-savings {
    color: #f56565;
}

.dark .wccwp-table-per-gram,
body.dark .wccwp-table-per-gram {
    color: #a0aec0;
}

.dark .wccwp-best-value-row,
body.dark .wccwp-best-value-row {
    background: linear-gradient(135deg, #744210, #975a16);
    border-left-color: #ed8936;
}

.dark .wccwp-best-value-row:hover,
body.dark .wccwp-best-value-row:hover {
    background: linear-gradient(135deg, #975a16, #b7791f);
}

.dark .wccwp-tiers-note,
body.dark .wccwp-tiers-note {
    background: #744210;
    border-color: #d69e2e;
    color: #faf089;
}

.dark .wccwp-savings-badge,
body.dark .wccwp-savings-badge {
    background: #e53e3e;
    color: #fff;
}

.dark .wccwp-best-value,
body.dark .wccwp-best-value {
    border-color: #ed8936 !important;
    box-shadow: 0 4px 16px rgba(237, 137, 54, 0.3) !important;
}

.dark .wccwp-best-value-badge,
body.dark .wccwp-best-value-badge {
    background: linear-gradient(135deg, #ed8936, #dd6b20);
    color: #fff;
}

/* Disabled Weight Preset Buttons */
.wccwp-preset-btn.disabled,
.wccwp-preset-btn:disabled,
button.wccwp-preset-btn[disabled] {
    background: #f5f5f5 !important;
    color: #999 !important;
    border-color: #e0e0e0 !important;
    cursor: not-allowed !important;
    opacity: 0.5 !important;
    text-decoration: line-through !important;
    pointer-events: none !important;
}

.wccwp-preset-btn.disabled:hover,
.wccwp-preset-btn:disabled:hover,
button.wccwp-preset-btn[disabled]:hover {
    background: #f5f5f5 !important;
    border-color: #e0e0e0 !important;
    color: #999 !important;
}

/* Stock Info Display */
.wccwp-stock-info {
    margin-bottom: 10px;
    padding: 8px 12px;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    color: #856404;
    font-size: 0.9em;
}

.wccwp-stock-info small {
    font-weight: 500;
}

/* Out of Stock Message */
.wccwp-out-of-stock {
    padding: 15px;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    margin-bottom: 20px;
}

.wccwp-out-of-stock .stock.out-of-stock {
    color: #721c24;
    font-weight: 600;
    font-size: 1.1em;
    margin: 0;
}

/* Dark theme compatibility for stock info */
.dark .wccwp-stock-info,
body.dark .wccwp-stock-info {
    background: #744210;
    border-color: #d69e2e;
    color: #faf089;
}

.dark .wccwp-out-of-stock,
body.dark .wccwp-out-of-stock {
    background: #742a2a;
    border-color: #822727;
}

.dark .wccwp-out-of-stock .stock.out-of-stock,
body.dark .wccwp-out-of-stock .stock.out-of-stock {
    color: #feb2b2;
}