/**
 * Cargus Checkout Enhancer - Modern shipping methods UI
 * Compatibil cu Astra theme + WooCommerce checkout clasic
 */

/* ==========================================================================
   Container - Shipping methods
   Label "Livrare" sus, cardurile dedesubt (full-width)
   ========================================================================== */

/* Convertim TOT tabelul de review la layout block/flex uniform.
   Motiv: hibrid (thead în table-layout + tbody/tfoot block) fragmenta lățimile coloanelor.
   Acum table = block container la 100%, fiecare rând e flex sau block. */

body .woocommerce-checkout-review-order-table,
.woocommerce-checkout .woocommerce-checkout-review-order-table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    border-collapse: separate !important;
}

body .woocommerce-checkout-review-order-table > thead,
body .woocommerce-checkout-review-order-table > tbody,
body .woocommerce-checkout-review-order-table > tfoot,
.woocommerce-checkout .woocommerce-checkout-review-order-table > thead,
.woocommerce-checkout .woocommerce-checkout-review-order-table > tbody,
.woocommerce-checkout .woocommerce-checkout-review-order-table > tfoot {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* Rânduri standard (header produs, cart item, sub-total, total) → flex 2 coloane */
body .woocommerce-checkout-review-order-table > thead > tr,
body .woocommerce-checkout-review-order-table tr.cart_item,
body .woocommerce-checkout-review-order-table tr.cart-subtotal,
body .woocommerce-checkout-review-order-table tr.order-total {
    display: flex !important;
    justify-content: space-between !important;
    align-items: baseline !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 10px 0 !important;
    border: none !important;
    border-bottom: 1px solid #f1f1f1 !important;
}

body .woocommerce-checkout-review-order-table > thead > tr {
    font-weight: 600;
    border-bottom: 1px solid #e5e7eb !important;
}

body .woocommerce-checkout-review-order-table tr.order-total {
    font-weight: 700;
    border-bottom: none !important;
    padding-top: 14px !important;
}

body .woocommerce-checkout-review-order-table > thead > tr > th,
body .woocommerce-checkout-review-order-table > thead > tr > td,
body .woocommerce-checkout-review-order-table tr.cart_item > th,
body .woocommerce-checkout-review-order-table tr.cart_item > td,
body .woocommerce-checkout-review-order-table tr.cart-subtotal > th,
body .woocommerce-checkout-review-order-table tr.cart-subtotal > td,
body .woocommerce-checkout-review-order-table tr.order-total > th,
body .woocommerce-checkout-review-order-table tr.order-total > td {
    display: block !important;
    width: auto !important;
    padding: 0 !important;
    border: none !important;
    text-align: left !important;
}

body .woocommerce-checkout-review-order-table tr.cart_item > .product-total,
body .woocommerce-checkout-review-order-table tr.cart-subtotal > td,
body .woocommerce-checkout-review-order-table tr.order-total > td,
body .woocommerce-checkout-review-order-table > thead > tr > .product-total {
    text-align: right !important;
    flex-shrink: 0;
    margin-left: 12px;
}

/* Rândurile shipping & notice — block full-width, label "Livrare" deasupra */
body .woocommerce-checkout-review-order-table tr.shipping,
body .woocommerce-checkout-review-order-table tr.cce-address-needed {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 14px 0 !important;
    border: none !important;
    border-bottom: 1px solid #f1f1f1 !important;
}

body .woocommerce-checkout-review-order-table tr.cce-address-needed {
    border-bottom: none !important;
    padding-bottom: 4px !important;
}

body .woocommerce-checkout-review-order-table tr.shipping > th,
body .woocommerce-checkout-review-order-table tr.shipping > td,
body .woocommerce-checkout-review-order-table tr.cce-address-needed > td {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 0 !important;
    border: none !important;
    text-align: left !important;
}

/* Ascundem rândurile Cargus Ship&Go când nu sunt necesare (clase d-none de la pluginul lor) */
body .woocommerce-checkout-review-order-table tr.cargus-ship-and-go-select.d-none,
body .woocommerce-checkout-review-order-table tr.cargus-ship-and-go-selected-point.d-none {
    display: none !important;
}

.woocommerce-checkout-review-order-table tr.shipping > th {
    font-weight: 600 !important;
    font-size: 14px !important;
    color: #111827 !important;
    margin-bottom: 10px !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
}

.woocommerce-checkout-review-order-table tr.cce-address-needed {
    padding-bottom: 4px !important;
}

.woocommerce-checkout #shipping_method,
.woocommerce-cart #shipping_method {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

#shipping_method li {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    display: block;
    width: 100%;
}

/* Spațiu vertical între carduri (fallback dacă tema dezactivează gap pe flex) */
#shipping_method li + li {
    margin-top: 10px !important;
}

/* Ascundem bullet-urile și styling-ul default */
#shipping_method li::before,
#shipping_method li::marker {
    display: none !important;
    content: '' !important;
}

/* ==========================================================================
   Radio button (ascuns vizual, dar funcțional)
   ========================================================================== */

/* "Visually hidden but focusable" — radio rămâne accesibil/focusabil
   ca WC checkout.js să-l poată referi după AJAX update. */
#shipping_method li input[type="radio"] {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ==========================================================================
   Label = card-ul efectiv
   ========================================================================== */

/* Pluginul Cargus forțează `display: inline !important; white-space: nowrap !important`
   pe `#shipping_method li label` (specificitate 1 ID + 2 type-uri).
   Adăugăm prefix `.woocommerce-checkout`/`.woocommerce-cart`/`body` pentru a câștiga la specificitate. */
body #shipping_method li label,
.woocommerce-checkout #shipping_method li label,
.woocommerce-cart #shipping_method li label {
    display: block !important;
    vertical-align: baseline !important;
    white-space: normal !important;
    width: 100%;
    box-sizing: border-box;
    margin: 0 !important;
    padding: 14px 16px !important;
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    font-weight: 400 !important;
    color: #111827 !important;
    text-indent: 0 !important;
    line-height: 1.4 !important;
}

body ul#shipping_method li,
.woocommerce-checkout ul#shipping_method li,
.woocommerce-cart ul#shipping_method li {
    text-indent: 0 !important;
}

#shipping_method li label:hover {
    border-color: #d1d5db;
    background: #fafafa;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

/* Card selectat - când radio-ul ascuns e checked */
#shipping_method li input[type="radio"]:checked + label,
#shipping_method li input[type="radio"]:checked ~ label {
    border-color: #f97316; /* portocaliu Astra-friendly, schimbabil */
    background: #fff7ed;
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

/* Bulina de selectare în dreapta-sus */
#shipping_method li label::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid #d1d5db;
    border-radius: 50%;
    background: #fff;
    transition: all 0.2s ease;
}

#shipping_method li input[type="radio"]:checked + label::after,
#shipping_method li input[type="radio"]:checked ~ label::after {
    border-color: #f97316;
    background: radial-gradient(circle, #f97316 0%, #f97316 45%, #fff 50%, #fff 100%);
}

/* ==========================================================================
   Conținutul card-ului (icon + titlu + preț)
   ========================================================================== */

#shipping_method li label .cce-rate-wrap {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    gap: 14px !important;
    padding-right: 36px !important; /* spațiu pentru bulina din dreapta */
    width: 100% !important;
}

#shipping_method li label .cce-rate-icon {
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    width: 42px !important;
    height: 42px !important;
    background: #f3f4f6;
    border-radius: 8px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: all 0.2s ease;
}

#shipping_method li label .cce-rate-icon svg {
    width: 22px;
    height: 22px;
}

#shipping_method li input[type="radio"]:checked + label .cce-rate-icon,
#shipping_method li input[type="radio"]:checked ~ label .cce-rate-icon {
    background: #f97316;
    color: #fff;
}

#shipping_method li label .cce-rate-body {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    display: block !important;
    align-self: center;
}

#shipping_method li label .cce-rate-title {
    display: block !important;
    width: 100% !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    color: #111827 !important;
    line-height: 1.3 !important;
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
    clear: both !important;
}

#shipping_method li label .cce-rate-desc {
    display: block !important;
    width: 100% !important;
    font-size: 13px !important;
    font-weight: 400 !important;
    color: #6b7280 !important;
    line-height: 1.4 !important;
    margin: 4px 0 0 0 !important;
    padding: 0 !important;
    float: none !important;
    clear: both !important;
}

#shipping_method li label .cce-rate-cost {
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    font-weight: 700;
    font-size: 15px;
    color: #111827;
    margin-left: auto !important;
    padding-left: 12px;
    text-align: right;
    white-space: nowrap;
}

.cce-rate-cost .cce-free {
    display: inline-block;
    color: #047857;
    background: #d1fae5;
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 3px 8px;
    border-radius: 999px;
    line-height: 1.2;
}

.cce-rate-cost .woocommerce-Price-amount {
    font-weight: 700;
}

/* Pentru ridicare din depozit nu mai afișăm badge-ul "Gratuit" — e implicit gratuit */
.cce-rate-wrap[data-method-type="pickup"] .cce-rate-cost {
    display: none;
}

/* ==========================================================================
   Notice când lipsește adresa
   ========================================================================== */

tr.cce-address-needed td {
    padding: 0 !important;
}

.cce-notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    color: #78350f;
    font-size: 13px;
    line-height: 1.4;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: break-word;
    word-break: break-word;
}

.cce-notice > span:not(.cce-notice-icon) {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.cce-notice-icon {
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1.4;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 600px) {
    #shipping_method li label {
        padding: 12px !important;
    }

    .cce-rate-wrap {
        gap: 10px;
        padding-right: 28px;
    }

    .cce-rate-icon {
        width: 36px;
        height: 36px;
    }

    .cce-rate-icon svg {
        width: 18px;
        height: 18px;
    }

    .cce-rate-title {
        font-size: 14px;
    }

    .cce-rate-desc {
        font-size: 12px;
    }

    .cce-rate-cost {
        font-size: 14px;
    }
}

/* ==========================================================================
   Compatibilitate cu Astra theme - reset bullet & spacing
   ========================================================================== */

.ast-theme-transparent-header #shipping_method li,
body[class*="astra"] #shipping_method li {
    background-image: none !important;
}

/* Loading state când recalculează shipping */
.woocommerce-checkout .blockUI.blockOverlay {
    border-radius: 10px;
}
