/**
 * Frontend styles for Tiered Unit Pricing Module - Radio Interface
 * 
 * @package UWE
 * @since 1.0.0
 */

/* Radio-based Pricing Interface */
.uwe-tiered-pricing-radio-interface {
    margin: 20px 0;
    padding: 0;
    background: transparent;
}

.uwe-tiered-pricing-radio-interface h4 {
    margin: 0 0 20px 0;
    font-size: 20px;
    font-weight: 600;
    color: #333;
    text-align: center;
}

.uwe-pricing-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.uwe-pricing-option {
    position: relative;
    border: 2px solid #e5e5e5;
    border-radius: 8px;
    background: #fff;
    transition: all 0.2s ease;
    overflow: hidden;
}

.uwe-pricing-option:hover {
    border-color: #ccc;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.uwe-pricing-option.has-label {
    border-color: #ff4444;
    position: relative;
}

.uwe-pricing-option.has-label::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #ff4444;
    z-index: 1;
}

.tier-badge {
    position: absolute;
    top: -1px;
    right: 15px;
    background: #ff4444;
    color: white;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    z-index: 2;
    max-width: 120px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.option-header {
    padding: 0;
}

.uwe-pricing-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.tier-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    cursor: pointer;
    margin: 0;
    position: relative;
}

.tier-label::before {
    content: '';
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 50%;
    background: #fff;
    transition: all 0.2s ease;
}

.uwe-pricing-option input[type="radio"]:checked + .tier-label::before {
    border-color: #007cba;
    background: #007cba;
    box-shadow: inset 0 0 0 3px #fff;
}

.tier-info {
    margin-left: 40px;
    flex: 1;
}

.tier-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.tier-subtitle {
    font-size: 14px;
    color: #666;
}

.discount-badge {
    background: #ff4444;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}

.tier-pricing {
    text-align: right;
    margin-right: 10px;
}

.total-price {
    font-size: 24px;
    font-weight: 700;
    color: #333;
    margin-bottom: 4px;
}

.unit-price {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.original-price {
    text-decoration: line-through;
    color: #999;
    font-size: 14px;
}

.price-per-unit {
    font-size: 14px;
    color: #666;
}

.quantity-selector {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    background: #f9f9f9;
}

.quantity-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.qty-btn {
    width: 40px;
    height: 40px;
    border: 2px solid var(--wc-primary-color, #007cba);
    background: transparent;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--wc-primary-color, #007cba);
}

.qty-btn:hover {
    background: var(--wc-primary-color, #007cba);
    color: white;
    transform: translateY(-1px);
}

.qty-btn:active {
    transform: scale(0.95);
}

.qty-btn:focus {
    outline: 2px solid var(--wc-primary-color, #007cba);
    outline-offset: 2px;
}

.qty-input {
    width: 80px;
    height: 40px;
    text-align: center;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    background: #fff;
}

.qty-input:focus {
    outline: none;
    border-color: #007cba;
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.1);
}

/* Selected state styling */
.uwe-pricing-option input[type="radio"]:checked + .tier-label {
    background: rgba(0, 124, 186, 0.05);
}

.uwe-pricing-option input[type="radio"]:checked {
    + .tier-label {
        background: rgba(0, 124, 186, 0.05);
    }
}

.uwe-pricing-option:has(input[type="radio"]:checked) {
    border-color: #007cba;
    box-shadow: 0 0 0 1px rgba(0, 124, 186, 0.2);
}

/* Price Update Indicator */
.uwe-price-update {
    display: inline-block;
    margin-left: 10px;
    padding: 4px 8px;
    background: #28a745;
    color: white;
    font-size: 12px;
    border-radius: 12px;
    animation: uwe-pulse 0.5s ease-in-out;
}

@keyframes uwe-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .uwe-tiered-pricing-radio-interface {
        margin: 15px 0;
    }
    
    .uwe-tiered-pricing-radio-interface h4 {
        font-size: 18px;
        margin-bottom: 15px;
        padding: 0 10px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .uwe-pricing-options {
        gap: 8px;
    }
    
    .tier-label {
        padding: 15px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        min-height: auto;
    }
    
    .tier-label::before {
        left: 15px;
        top: 18px;
        transform: none;
        width: 18px;
        height: 18px;
    }
    
    .tier-info {
        margin-left: 40px;
        margin-right: 0;
        width: calc(100% - 40px);
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .tier-title {
        font-size: 15px;
        line-height: 1.3;
        margin-bottom: 6px;
        word-wrap: break-word;
    }
    
    .tier-subtitle {
        font-size: 13px;
        line-height: 1.2;
        word-wrap: break-word;
    }
    
    .discount-badge {
        font-size: 11px;
        padding: 3px 8px;
        white-space: nowrap;
    }
    
    .tier-pricing {
        text-align: left;
        margin-right: 0;
        margin-left: 40px;
        width: calc(100% - 40px);
    }
    
    .total-price {
        font-size: 20px;
        line-height: 1.2;
        margin-bottom: 6px;
        word-wrap: break-word;
    }
    
    .price-per-unit {
        font-size: 13px;
        line-height: 1.3;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .original-price {
        font-size: 13px;
    }
    
    .quantity-selector {
        padding: 12px 15px;
        margin-top: 8px;
    }
    
    .qty-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
        min-width: 36px;
        flex-shrink: 0;
    }
    
    .qty-input {
        width: 70px;
        height: 36px;
        font-size: 14px;
        min-width: 70px;
    }
    
    .quantity-controls {
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .uwe-tiered-pricing-radio-interface {
        margin: 10px 0;
        padding: 0 5px;
    }
    
    .uwe-pricing-option {
        border-radius: 6px;
        margin-bottom: 8px;
    }
    
    .uwe-tiered-pricing-radio-interface h4 {
        font-size: 16px;
        margin: 0 0 12px 0;
        padding: 0 10px;
        text-align: center;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
    
    .tier-label {
        padding: 12px;
        gap: 10px;
    }
    
    .tier-label::before {
        left: 12px;
        top: 15px;
        width: 16px;
        height: 16px;
    }
    
    .tier-info {
        margin-left: 35px;
        width: calc(100% - 35px);
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
    
    .tier-pricing {
        margin-left: 35px;
        width: calc(100% - 35px);
    }
    
    .tier-title {
        font-size: 14px;
        line-height: 1.3;
        margin-bottom: 4px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .tier-subtitle {
        font-size: 12px;
        line-height: 1.2;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .total-price {
        font-size: 18px;
        line-height: 1.2;
        margin-bottom: 4px;
        word-wrap: break-word;
    }
    
    .price-per-unit {
        font-size: 11px;
        line-height: 1.3;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
    
    .original-price {
        font-size: 12px;
    }
    
    .tier-badge {
        right: 8px;
        padding: 2px 6px;
        font-size: 9px;
        max-width: 100px;
        word-wrap: break-word;
        overflow-wrap: break-word;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .discount-badge {
        font-size: 9px;
        padding: 2px 6px;
        white-space: nowrap;
    }
    
    .quantity-selector {
        padding: 10px 12px;
    }
    
    .qty-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
        min-width: 32px;
    }
    
    .qty-input {
        width: 60px;
        height: 32px;
        font-size: 13px;
        min-width: 60px;
    }
    
    .quantity-controls {
        gap: 6px;
    }
}

/* Animation for smooth transitions */
.uwe-pricing-option {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Additional mobile improvements */
@media (max-width: 360px) {
    .uwe-tiered-pricing-radio-interface h4 {
        font-size: 15px;
        line-height: 1.3;
    }
    
    .tier-title {
        font-size: 13px;
    }
    
    .tier-subtitle {
        font-size: 11px;
    }
    
    .total-price {
        font-size: 16px;
    }
    
    .price-per-unit {
        font-size: 10px;
    }
    
    .tier-label {
        padding: 10px;
    }
    
    .tier-info, .tier-pricing {
        margin-left: 32px;
        width: calc(100% - 32px);
    }
}

/* Focus states for accessibility */
.uwe-pricing-option input[type="radio"]:focus + .tier-label::before {
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.3);
}

.tier-label:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.uwe-pricing-tiers tbody td {
    color: #495057;
}

.uwe-pricing-tiers tbody td:first-child {
    color: #212529;
    font-weight: 600;
    }
}

/* Animation for table appearance */
.uwe-tiered-pricing-table {
    animation: uwe-fadeInUp 0.5s ease-out;
}

@keyframes uwe-fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tier highlight on quantity change */
.uwe-pricing-tiers tbody tr.uwe-active-tier {
    background-color: #e3f2fd;
    border-left: 4px solid #2196f3;
}

.uwe-pricing-tiers tbody tr.uwe-active-tier td {
    color: #1976d2;
    font-weight: 600;
}

/* Loading state for price updates */
.uwe-price-loading {
    position: relative;
    opacity: 0.7;
}

.uwe-price-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -25px;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: uwe-spin 1s linear infinite;
}

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

/* Accessibility improvements */
.uwe-pricing-tiers:focus-within {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.uwe-pricing-tiers tbody tr:focus {
    background-color: #e3f2fd;
    outline: none;
}

/* Theme compatibility improvements */
.uwe-tiered-pricing-radio-interface {
    /* Ensure compatibility with various themes */
    box-sizing: border-box;
    font-family: inherit;
}

.uwe-tiered-pricing-radio-interface * {
    box-sizing: border-box;
}

/* Better button integration with site colors */
.qty-btn {
    /* Try to inherit theme button colors */
    border-color: var(--wp--preset--color--primary, var(--wc-primary-color, #007cba));
    color: var(--wp--preset--color--primary, var(--wc-primary-color, #007cba));
}

.qty-btn:hover {
    background: var(--wp--preset--color--primary, var(--wc-primary-color, #007cba));
    color: var(--wp--preset--color--contrast, white);
}

/* Ensure proper spacing in different themes */
.uwe-pricing-option {
    margin-bottom: 12px;
    clear: both;
    overflow: hidden;
}

/* Better text contrast for accessibility */
.tier-title {
    color: var(--wp--preset--color--foreground, #333);
}

.tier-subtitle {
    color: var(--wp--preset--color--foreground, #666);
}

.total-price {
    color: var(--wp--preset--color--foreground, #333);
}

.price-per-unit {
    color: var(--wp--preset--color--foreground, #666);
}

/* Print styles */
@media print {
    .uwe-tiered-pricing-table {
        background: white;
        border: 1px solid #000;
        box-shadow: none;
    }
    
    .uwe-pricing-tiers thead {
        background: #f0f0f0;
        color: #000;
    }
    
    .uwe-pricing-tiers tbody tr:hover {
        background: transparent;
    }
    
    .uwe-tiered-pricing-radio-interface {
        background: white;
        color: black;
    }
    
    .qty-btn {
        border-color: #000;
        color: #000;
    }
}

/* Hide default WooCommerce quantity input when tiered pricing is enabled */
.single-product .uwe-tiered-pricing-radio-interface ~ .cart .quantity,
.single-product .cart .quantity:has(~ .uwe-tiered-pricing-radio-interface),
.single-product .product .cart .quantity {
    display: none !important;
}

/* Show quantity input only when tiered pricing is not present */
body:not(.single-product) .cart .quantity,
.single-product:not(:has(.uwe-tiered-pricing-radio-interface)) .cart .quantity {
    display: block !important;
}

/* Alternative approach using JavaScript class */
.uwe-tiered-pricing-active .cart .quantity {
    display: none !important;
}

/* Ensure add to cart button remains visible */
.single-product .cart .single_add_to_cart_button {
    display: inline-block !important;
}