/*
 * KARTA METODY WYSYŁKI — koszyk i kasa
 *
 * Jedna anatomia dla obu stron: radio, nazwa (z logo przewoźnika), cena po
 * prawej, pod nazwą opis metody, a przy ORLEN Paczce wybór punktu w tej samej
 * karcie. Etykietę `.evenus-wysylka__nazwa` + `.evenus-wysylka__cena` buduje
 * `inc/woocommerce.php`.
 *
 * Plik ładuje się jako ostatni na stronach koszyka i kasy. Listę wysyłki
 * układa pięć wcześniejszych arkuszy (style.css, cart-page-modern,
 * checkout-page-modern, checkout-critical-fixes, inline/checkout-style), każdy
 * na `!important`, stąd selektor z identyfikatorem i klasą tabeli.
 */

html body .shop_table #shipping_method.woocommerce-shipping-methods {
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
    width: 100% !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods > li {
    display: grid !important;
    grid-template-columns: 20px minmax(0, 1fr) !important;
    column-gap: 14px !important;
    row-gap: 2px !important;
    align-items: center !important;
    width: 100% !important;
    margin: 0 0 8px !important;
    padding: 14px 18px !important;
    background: var(--c-bg-muted) !important;
    border: 1px solid #e0e5eb !important;
    border-radius: var(--radius-lg) !important;
    text-align: left !important;
    cursor: pointer !important;
    transition: background-color 0.15s ease, border-color 0.15s ease !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods > li:last-child {
    margin-bottom: 0 !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods > li:hover {
    border-color: var(--c-primary) !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods > li:has(input:checked) {
    background: #e8f1fb !important;
    border-color: var(--c-primary) !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods > li > input[type="radio"] {
    grid-column: 1 !important;
    grid-row: 1 !important;
    position: static !important;
    display: block !important;
    width: 20px !important;
    height: 20px !important;
    margin: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
    appearance: auto !important;
    accent-color: var(--c-primary) !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods > li > label {
    grid-column: 2 !important;
    grid-row: 1 !important;
    display: flex !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4px 12px !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 1rem !important;
    line-height: 1.4 !important;
    color: var(--c-text) !important;
    text-align: left !important;
    cursor: pointer !important;
}

/* Starsze arkusze dorysowują własne kółko przed etykietą kasy. */
html body .shop_table #shipping_method.woocommerce-shipping-methods > li > label::before,
html body .shop_table #shipping_method.woocommerce-shipping-methods > li > label::after {
    content: none !important;
    display: none !important;
}

/* Cena nie spada pod nazwę: przy braku miejsca łamie się nazwa. W kasie przy 390 px
   „Paczkomat InPost” + cena brakowało 1 px i karta rosła z 70 do 97 px. */
html body .shop_table #shipping_method.woocommerce-shipping-methods .evenus-wysylka__nazwa {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 10px !important;
    margin: 0 !important;
    font-size: inherit !important;
    font-weight: 500 !important;
    color: inherit !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods .evenus-wysylka__logo {
    display: block !important;
    width: 28px !important;
    height: 28px !important;
    max-width: none !important;
    margin: -4px 0 !important;
    flex-shrink: 0 !important;
    border-radius: var(--radius-sm) !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods .evenus-wysylka__cena,
html body .shop_table #shipping_method.woocommerce-shipping-methods .evenus-wysylka__cena .woocommerce-Price-amount {
    display: inline !important;
    margin: 0 0 0 auto !important;
    font-size: inherit !important;
    font-weight: 600 !important;
    color: var(--c-primary-darker) !important;
    white-space: nowrap !important;
    font-variant-numeric: tabular-nums !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods .evenus-wysylka__cena .woocommerce-Price-amount {
    margin: 0 !important;
}

/*
 * Karta bez opisu (Kurier) miała 49 px przy 71 px pozostałych. Etykieta
 * dostaje wysokość linii nazwy, odstępu i linii opisu, a flex wyśrodkowuje
 * w niej nazwę i cenę — wysokość nie zależy od paddingu karty.
 */
html body .shop_table #shipping_method.woocommerce-shipping-methods > li:not(:has(> .shipping-method-description)) > label {
    min-height: calc(1.4rem + 2px + 1.4 * 0.875rem) !important;
}

html body .shop_table #shipping_method.woocommerce-shipping-methods > li > .shipping-method-description {
    grid-column: 2 !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 0.875rem !important;
    line-height: 1.4 !important;
    color: var(--c-text-muted) !important;
    text-align: left !important;
}

/*
 * PODSUMOWANIE ZAMÓWIENIA W KASIE: WIERSZE ZAMIAST KOLUMN TABELI
 *
 * Wiersz wysyłki ma nagłówek nad kartami, nie obok, więc jego komórki są
 * blokami. W tabeli trafiały przez to do jednej anonimowej komórki pierwszej
 * kolumny: karty zajmowały 685 z 978 px na desktopie i 216 z 309 px na
 * telefonie, a druga kolumna stała pusta. Tabela staje się stosem wierszy:
 * nazwa po lewej, kwota po prawej, wysyłka na całą szerokość. Wiersz pola
 * punktu wtyczka chowa stylem inline, więc nie dostaje tu `display`.
 */
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table,
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table > thead,
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table > tbody,
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table > tfoot {
    display: block !important;
    width: 100% !important;
}

html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table tr:not(.woocommerce-shipping-totals):not(.orlen-paczka-pickup-point-row):not(.easypack-parcel-machine) {
    display: flex !important;
    align-items: baseline !important;
    justify-content: space-between !important;
    gap: 0 !important;
    width: 100% !important;
}

/* Bez gap: komórki mają własne dolne linie, odstęp przerwałby je w połowie. */
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table tr:not(.woocommerce-shipping-totals):not(.easypack-parcel-machine) > :first-child {
    flex: 1 1 auto !important;
    min-width: 0 !important;
}

html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table tr:not(.woocommerce-shipping-totals):not(.easypack-parcel-machine) > :last-child:not(:first-child) {
    flex: 0 0 auto !important;
    padding-left: 16px !important;
    text-align: right !important;
}

html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table tr.woocommerce-shipping-totals {
    display: block !important;
    width: 100% !important;
}

html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table tr.woocommerce-shipping-totals > th,
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table tr.woocommerce-shipping-totals > td {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/*
 * WYBÓR PUNKTU ORLEN PACZKI W KARCIE METODY (kasa)
 *
 * Wtyczka trzyma pole wyboru punktu jako rodzeństwo listy metod i pilnuje
 * tego miejsca skryptem: przeniesione do karty wraca pod listę. Dlatego lista
 * znika z układu (`display: contents`), karty i pole stają się elementami
 * jednej kolumny, a `order` stawia pole tuż pod kartą ORLEN Paczki.
 */
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table tr.woocommerce-shipping-totals > td:has(> #shipping_method) {
    display: flex !important;
    flex-direction: column !important;
    padding: 0 20px 16px !important;
}

html body .woocommerce-checkout-review-order-table td:has(> #orlen_paczka_pickup_point_field) > #shipping_method.woocommerce-shipping-methods {
    display: contents !important;
}

html body .woocommerce-checkout-review-order-table #shipping_method > li { order: 1 !important; }
html body .woocommerce-checkout-review-order-table #shipping_method > li:has(input[value^="orlen_paczka"]) { order: 2 !important; }
html body .woocommerce-checkout-review-order-table #shipping_method > li:has(input[value^="orlen_paczka"]) ~ li { order: 4 !important; }
html body .woocommerce-checkout-review-order-table td:has(> #shipping_method) > #orlen_paczka_pickup_point_field { order: 3 !important; }
html body .woocommerce-checkout-review-order-table td:has(> #shipping_method) > :not(#shipping_method):not(#orlen_paczka_pickup_point_field) { order: 5 !important; }

/* Przy `display: contents` znika `li:last-child` listy — odstęp trzyma gap kolumny. */
html body .woocommerce-checkout-review-order-table td:has(> #orlen_paczka_pickup_point_field) {
    gap: 8px !important;
}

html body .woocommerce-checkout-review-order-table td:has(> #orlen_paczka_pickup_point_field) > #shipping_method > li {
    margin: 0 !important;
}

html body .woocommerce-checkout-review-order-table td:has(> #orlen_paczka_pickup_point_field:not([style*="none"])) > #shipping_method > li:has(input[value^="orlen_paczka"]:checked) {
    border-bottom-color: transparent !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    padding-bottom: 6px !important;
}

html body .woocommerce-checkout-review-order-table td:has(> #orlen_paczka_pickup_point_field:not([style*="none"])):has(input[value^="orlen_paczka"]:checked) {
    row-gap: 0 !important;
}

html body .woocommerce-checkout-review-order-table td:has(input[value^="orlen_paczka"]:checked) > #orlen_paczka_pickup_point_field,
html body.woocommerce-checkout #order_review tfoot > tr.easypack-parcel-machine {
    margin: 0 !important;
    padding: 0 18px 16px 52px !important;
    background: #e8f1fb !important;
    border: 1px solid var(--c-primary) !important;
    border-top: 0 !important;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg) !important;
}

/* Bez `:checked` pole i tak jest ukryte przez wtyczkę; tu tylko na czas przełączania. */
html body .woocommerce-checkout-review-order-table td:has(> #shipping_method) > #orlen_paczka_pickup_point_field {
    margin: 0 !important;
    text-align: left !important;
}

#orlen_paczka_pickup_point_field > h3,
#orlen_paczka_pickup_point_field.evenus-orlen-pole > #orlen_paczka_pickup_point_label {
    display: none !important;
}

#orlen_paczka_pickup_point_field .evenus-orlen-punkt,
tr.easypack-parcel-machine #selected-parcel-machine {
    display: flex !important;
    flex-direction: column !important;
    margin: 0 0 12px !important;
    padding: 12px 14px !important;
    background: var(--c-bg) !important;
    border-radius: var(--radius-md) !important;
    font-size: 0.9375rem !important;
    line-height: 1.45 !important;
    color: var(--c-text) !important;
    border: 0 !important;
    min-width: 0 !important;
}

#orlen_paczka_pickup_point_field .evenus-orlen-punkt strong {
    font-weight: 600 !important;
    color: var(--c-primary-darker) !important;
}

#orlen_paczka_pickup_point_field .evenus-orlen-punkt span {
    font-weight: 400 !important;
}

#orlen_paczka_pickup_point_field .evenus-orlen-punkt__brak {
    color: var(--c-text-muted) !important;
}

html body #orlen_paczka_pickup_point_field .orlen-modal-button.button,
html body tr.easypack-parcel-machine #easypack_show_geowidget {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: auto !important;
    min-height: 44px !important;
    margin: 0 !important;
    max-width: none !important;
    padding: 10px 18px !important;
    background: var(--c-primary) !important;
    border: 0 !important;
    border-radius: var(--radius-btn) !important;
    box-shadow: none !important;
    font-size: 0.9375rem !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    text-align: center !important;
    cursor: pointer !important;
    letter-spacing: 0 !important;
    text-transform: none !important;
    color: #fff !important;
    transition: background-color 0.15s ease !important;
}

html body #orlen_paczka_pickup_point_field .orlen-modal-button.button:hover,
html body #orlen_paczka_pickup_point_field .orlen-modal-button.button:focus-visible,
html body tr.easypack-parcel-machine #easypack_show_geowidget:hover,
html body tr.easypack-parcel-machine #easypack_show_geowidget:focus-visible {
    background: var(--c-primary-darker) !important;
    transform: none !important;
}

html body #orlen_paczka_pickup_point_field .orlen-modal-button.button:focus-visible,
html body tr.easypack-parcel-machine #easypack_show_geowidget:focus-visible {
    outline: 2px solid var(--c-primary) !important;
    outline-offset: 2px !important;
}

/*
 * WYBÓR PACZKOMATU INPOST W KARCIE METODY (kasa)
 *
 * Wtyczka InPost wypisuje przycisk mapy i wybrany punkt w osobnym wierszu
 * stopki tabeli (`tr.easypack-parcel-machine`), tylko przy zaznaczonym
 * paczkomacie i zawsze za całym wierszem wysyłki. Żeby stanął pod kartą,
 * a nie pod listą, wiersz wysyłki, jego komórka i lista znikają z układu
 * (`display: contents`), stopka staje się kolumną, a `order` wstawia wiersz
 * InPost tuż za zaznaczoną kartą. Karty zostają w kolejności z panelu.
 * Wygląd karty, punktu i przycisku dzieli z ORLEN Paczką (reguły wyżej).
 */
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table > tfoot:has(> tr.easypack-parcel-machine) {
    display: flex !important;
    flex-direction: column !important;
}

html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) > tr.woocommerce-shipping-totals,
html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) > tr.woocommerce-shipping-totals > td:has(> #shipping_method),
html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) #shipping_method.woocommerce-shipping-methods {
    display: contents !important;
}

/* Komórka znika z układu razem ze swoim paddingiem, margines kart go odtwarza. */
html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) #shipping_method > li { order: 10 !important; width: auto !important; margin: 0 20px 8px !important; }
html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) #shipping_method > li:last-child { margin-bottom: 16px !important; }
html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) #shipping_method > li:has(input[value^="easypack_parcel_machines"]:checked) {
    order: 20 !important;
    margin-bottom: 0 !important;
    padding-bottom: 6px !important;
    border-bottom-color: transparent !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}
html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) #shipping_method > li:has(input[value^="easypack_parcel_machines"]:checked) ~ li { order: 40 !important; }
html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) td:has(> #shipping_method) > :not(#shipping_method) { order: 40 !important; margin: 0 20px !important; }
html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) > tr.woocommerce-shipping-totals ~ tr { order: 90 !important; }

html body.woocommerce-checkout #order_review tfoot:has(> tr.easypack-parcel-machine) > tr.woocommerce-shipping-totals ~ tr.easypack-parcel-machine {
    display: block !important;
    order: 30 !important;
    width: auto !important;
    margin: 0 20px 8px !important;
}

html body.woocommerce-checkout #order_review tfoot:has(#shipping_method > li:last-child input[value^="easypack_parcel_machines"]:checked) > tr.woocommerce-shipping-totals ~ tr.easypack-parcel-machine {
    margin-bottom: 16px !important;
}

html body.woocommerce-checkout #order_review tr.easypack-parcel-machine > th {
    display: none !important;
}

/* Wtyczka stawia przycisk przed punktem; jak przy ORLEN punkt idzie pierwszy. */
html body.woocommerce-checkout #order_review table.woocommerce-checkout-review-order-table > tfoot > tr.easypack-parcel-machine > td {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    width: auto !important;
    padding: 0 !important;
    border: 0 !important;
    text-align: left !important;
}

/* Nagłówek „Wybrany punkt odbioru:” zostaje dla czytnika ekranu, oko widzi sam punkt. */
tr.easypack-parcel-machine #selected-parcel-machine > div:first-child {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
}

tr.easypack-parcel-machine #selected-parcel-machine {
    order: -1 !important;
    align-self: stretch !important;
    text-align: left !important;
}

/* Wtyczka pisze kod punktu, adres i opis miejsca, rozdzielone `<br>`. */
tr.easypack-parcel-machine #selected-parcel-machine-id {
    display: block !important;
    font-weight: 400 !important;
}

tr.easypack-parcel-machine #selected-parcel-machine-id::first-line {
    font-weight: 600;
    color: var(--c-primary-darker);
}

tr.easypack-parcel-machine #selected-parcel-machine-id:empty::before {
    content: "Nie wybrano punktu odbioru";
    font-weight: 400;
    color: var(--c-text-muted);
}

/*
 * Koszyk na telefonie: etykieta „Przesyłka” nad kartami zamiast obok. Obok
 * zabierała połowę szerokości i karty miały ok. 150 px przy 390 px ekranu.
 * Pozostałe wiersze podsumowania zostają parą nazwa / kwota.
 */
@media (max-width: 576px) {
    html body.woocommerce-cart .cart_totals table.shop_table,
    html body.woocommerce-cart .cart_totals table.shop_table > tbody {
        display: block !important;
        width: 100% !important;
    }

    html body.woocommerce-cart .cart_totals table.shop_table tr:not(.woocommerce-shipping-totals) {
        display: flex !important;
        align-items: baseline !important;
        justify-content: space-between !important;
        width: 100% !important;
    }

    html body.woocommerce-cart .cart_totals table.shop_table tr.woocommerce-shipping-totals,
    html body.woocommerce-cart .cart_totals table.shop_table tr.woocommerce-shipping-totals > th,
    html body.woocommerce-cart .cart_totals table.shop_table tr.woocommerce-shipping-totals > td {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box !important;
        text-align: left !important;
    }

    html body.woocommerce-cart .cart_totals table.shop_table tr.woocommerce-shipping-totals > th {
        padding-bottom: 8px !important;
        border: 0 !important;
    }

    html body.woocommerce-cart .cart_totals table.shop_table tr.woocommerce-shipping-totals > td::before {
        content: none !important;
        display: none !important;
    }
}

@media (max-width: 576px) {
    html body .shop_table #shipping_method.woocommerce-shipping-methods > li {
        column-gap: 12px !important;
        padding: 12px 14px !important;
    }

    html body .woocommerce-checkout-review-order-table td:has(input[value^="orlen_paczka"]:checked) > #orlen_paczka_pickup_point_field,
    html body.woocommerce-checkout #order_review tfoot > tr.easypack-parcel-machine {
        padding: 0 14px 14px 46px !important;
    }

    html body #orlen_paczka_pickup_point_field .orlen-modal-button.button,
    html body tr.easypack-parcel-machine #easypack_show_geowidget {
        width: 100% !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    html body .shop_table #shipping_method.woocommerce-shipping-methods > li,
    html body #orlen_paczka_pickup_point_field .orlen-modal-button.button,
    html body tr.easypack-parcel-machine #easypack_show_geowidget {
        transition: none !important;
    }
}
