/**
 * Estilos frontend para Rafas Custom Shipping
 */

.rafas-custom-shipping-options {
    background: #f8f9fa;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    padding: 20px;
    margin: 20px 0;
    clear: both;
}

/* Estilos específicos para el carrito */
.woocommerce-cart .rafas-custom-shipping-options {
    margin-top: 0;
}

.woocommerce-cart-form + .rafas-custom-shipping-options {
    margin-top: 20px;
}

/* Ocultar sección de shipping si está vacía */
.woocommerce-shipping-totals:empty {
    display: none !important;
}

tr.woocommerce-shipping-totals.shipping:has(#shipping_method:empty) {
    display: none !important;
}

/* Ocultar fila de shipping si el contenedor de métodos está vacío */
.woocommerce-shipping-totals .woocommerce-shipping-methods:empty {
    display: none;
}

.woocommerce-shipping-totals:has(.woocommerce-shipping-methods:empty) {
    display: none !important;
}

/* Ocultar mensaje de no shipping disponible cuando hay métodos personalizados */
.woocommerce-shipping-totals:has(+ .rafas-custom-shipping-options) {
    display: none !important;
}

/* Compatibilidad adicional para ocultar shipping de WooCommerce */
.woocommerce-cart table.shop_table tr.woocommerce-shipping-totals:has(#shipping_method input[type="hidden"]:only-child) {
    display: none !important;
}

/* Ocultar el método de envío dummy de Rafas Custom Shipping */
#shipping_method li:has(input[value="rafas_custom_shipping_dummy"]),
.woocommerce-shipping-totals:has(input[value="rafas_custom_shipping_dummy"]) {
    display: none !important;
}

/* Ocultar completamente la sección de shipping cuando solo hay el método dummy */
.woocommerce-shipping-totals.shipping {
    display: none !important;
}


/* Alinear valores de fees (costos de envío) a la derecha */
.woocommerce table.shop_table tr.fee td,
.woocommerce-page table.shop_table tr.fee td,
.woocommerce table.woocommerce-checkout-review-order-table tr.fee td,
.woocommerce-page table.woocommerce-checkout-review-order-table tr.fee td {
    text-align: right;
}

/* Asegurar que el precio esté alineado a la derecha */
.woocommerce table.shop_table tr.fee td .woocommerce-Price-amount,
.woocommerce-page table.shop_table tr.fee td .woocommerce-Price-amount {
    display: inline-block;
    text-align: right;
}

.rafas-custom-shipping-options h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

/* Opciones de envío */
.shipping-methods-list {
    margin-bottom: 20px;
}

.shipping-method-option {
    background: #fff;
    border: 2px solid #e1e1e1;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.shipping-method-option:hover {
    border-color: #2271b1;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.shipping-method-option label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    margin: 0;
    width: 100%;
}

.shipping-method-option input[type="radio"] {
    margin-top: 3px;
    margin-right: 12px;
    flex-shrink: 0;
}

.shipping-method-option input[type="radio"]:checked + .shipping-method-info {
    color: #2271b1;
}

.shipping-method-option:has(input[type="radio"]:checked) {
    border-color: #2271b1;
    background: #f0f6fc;
}

.shipping-method-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-grow: 1;
}

.shipping-method-name {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.shipping-method-description {
    font-size: 14px;
    color: #666;
    line-height: 1.4;
}

.shipping-method-cost {
    font-size: 15px;
    font-weight: 600;
    color: #2271b1;
    margin-top: 5px;
}

/* Costos de envío por producto */
.product-shipping-costs {
    background: #fff;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    padding: 15px;
    margin-top: 15px;
}

.product-shipping-costs h4 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

.product-shipping-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.product-shipping-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.product-shipping-item:last-child {
    border-bottom: none;
}

.product-name {
    font-size: 14px;
    color: #333;
    flex-grow: 1;
}

.product-shipping-details {
    font-size: 14px;
    color: #666;
    text-align: right;
    white-space: nowrap;
    margin-left: 15px;
}

.product-shipping-details strong {
    color: #333;
    margin-left: 10px;
}

.product-shipping-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    margin-top: 12px;
    border-top: 2px solid #e1e1e1;
    font-size: 16px;
}

.product-shipping-total strong {
    font-weight: 600;
    color: #333;
}

.product-shipping-total span {
    font-weight: 600;
    color: #2271b1;
    font-size: 18px;
}

/* Responsive */
@media screen and (max-width: 768px) {
    .rafas-custom-shipping-options {
        padding: 15px;
    }
    
    .shipping-method-option {
        padding: 12px;
    }
    
    .shipping-method-name {
        font-size: 15px;
    }
    
    .shipping-method-description {
        font-size: 13px;
    }
    
    .product-shipping-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .product-shipping-details {
        margin-left: 0;
    }
}

/* Compatibilidad con temas WooCommerce */
.woocommerce .rafas-custom-shipping-options,
.woocommerce-page .rafas-custom-shipping-options {
    margin: 1.5em 0;
}

.woocommerce .shipping-method-option label,
.woocommerce-page .shipping-method-option label {
    font-weight: normal;
}

/* Loading state */
.rafas-custom-shipping-options.loading {
    opacity: 0.6;
    pointer-events: none;
}

.rafas-custom-shipping-options.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2271b1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* -------------------------------------------------------
   Estado bloqueado (free_shipping_min no alcanzado)
------------------------------------------------------- */
.shipping-method-option.shipping-method-locked {
    opacity: 0.45;
    background: #f5f5f5;
    border-color: #ddd;
    cursor: not-allowed;
}

.shipping-method-option.shipping-method-locked label {
    cursor: not-allowed;
}

.shipping-method-option.shipping-method-locked input[type="radio"] {
    cursor: not-allowed;
}

.shipping-method-lock-icon {
    font-style: normal;
    margin-left: 4px;
    font-size: 13px;
    vertical-align: middle;
}

.shipping-method-unlock-info {
    font-size: 12px;
    color: #b45309;
    margin-top: 5px;
    display: block;
}

/* Mini progress bar dentro de cada método bloqueado */
.shipping-method-mini-bar {
    background: #e5e7eb;
    border-radius: 99px;
    height: 5px;
    margin-top: 6px;
    overflow: hidden;
}

.shipping-method-mini-progress {
    background: linear-gradient(90deg, #fbbf24, #f59e0b);
    height: 100%;
    border-radius: 99px;
    transition: width 0.4s ease;
    min-width: 3px;
}

/* -------------------------------------------------------
   Aviso de envío gratis / barra de progreso
------------------------------------------------------- */
.rafas-free-shipping-notice {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-left: 4px solid #ffc107;
    border-radius: 4px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #5a4000;
}

.rafas-free-shipping-notice.rafas-free-shipping-achieved {
    background: #e8f5e9;
    border-color: #a5d6a7;
    border-left-color: #4caf50;
    color: #1b5e20;
    font-weight: 600;
}

.rafas-free-shipping-message {
    margin-bottom: 10px;
}

.rafas-free-shipping-bar {
    background: #ffe082;
    border-radius: 99px;
    height: 8px;
    overflow: hidden;
}

.rafas-free-shipping-progress {
    background: linear-gradient(90deg, #ffc107, #ff9800);
    height: 100%;
    border-radius: 99px;
    transition: width 0.4s ease;
    min-width: 4px;
}

/* Badge "¡Envío Gratis!" junto al método en checkout */
.shipping-method-free-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #2e7d32 !important;
    font-weight: 700 !important;
    font-size: 14px !important;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: 3px;
    padding: 2px 8px;
    margin-top: 4px;
    width: fit-content;
}

.shipping-free-original-cost {
    text-decoration: line-through;
    color: #999;
    font-weight: 400;
    font-size: 13px;
}

/* Etiqueta "Gratis desde $X" debajo del precio */
.shipping-free-threshold {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
    font-style: italic;
    font-weight: 400;
}

/* Responsive ajustes para los nuevos elementos */
@media screen and (max-width: 768px) {
    .rafas-free-shipping-notice {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .rafas-free-shipping-bar {
        height: 6px;
    }
}