/*
 * LastMily add-on services panel under the selected LastMily rate
 * (cart and classic checkout, rendered by WC_LastMily_Checkout::add_delivery_options).
 *
 * Layout rules:
 * - The panel sits directly under its own rate label and spans to the right
 *   edge of the method list; the following methods stay in the same column.
 * - No separator line at the top of the panel; a divider is only drawn
 *   between the pickup-point block and the add-ons when both are shown.
 * - When another method is chosen WooCommerce re-renders the list without
 *   the panel, so nothing is left behind.
 */

/* Plain list (setting «Εμφάνιση αποστολής σε κάρτες» off): radio | label, panel under the label. */
body:not(.obs-ship-cards) ul#shipping_method:has(input[value^="lastmily"]) > li,
body:not(.obs-ship-cards) ul.woocommerce-shipping-methods:has(input[value^="lastmily"]) > li {
    display: grid !important;
    grid-template-columns: auto 1fr;
    column-gap: 0.5em;
    align-items: center;
    width: 100% !important;
    margin: 0 0 0.5em !important;
    padding: 0 !important;
    text-indent: 0 !important;
    text-align: left;
    box-sizing: border-box;
}
body:not(.obs-ship-cards) ul#shipping_method:has(input[value^="lastmily"]) > li:last-child,
body:not(.obs-ship-cards) ul.woocommerce-shipping-methods:has(input[value^="lastmily"]) > li:last-child {
    margin-bottom: 0 !important;
}
body:not(.obs-ship-cards) ul#shipping_method:has(input[value^="lastmily"]) > li > input.shipping_method,
body:not(.obs-ship-cards) ul.woocommerce-shipping-methods:has(input[value^="lastmily"]) > li > input.shipping_method {
    grid-column: 1;
    margin: 0 !important;
}
body:not(.obs-ship-cards) ul#shipping_method:has(input[value^="lastmily"]) > li > label,
body:not(.obs-ship-cards) ul.woocommerce-shipping-methods:has(input[value^="lastmily"]) > li > label {
    grid-column: 2;
    margin: 0 !important;
    text-indent: 0 !important;
}
body:not(.obs-ship-cards) ul#shipping_method:has(input[value^="lastmily"]) > li > input[type="hidden"],
body:not(.obs-ship-cards) ul.woocommerce-shipping-methods:has(input[value^="lastmily"]) > li > input[type="hidden"] {
    display: none;
}
/* Single available method: no radio, the label and the panel use the full width. */
body:not(.obs-ship-cards) ul#shipping_method:has(input[value^="lastmily"]) > li > input[type="hidden"] ~ *,
body:not(.obs-ship-cards) ul.woocommerce-shipping-methods:has(input[value^="lastmily"]) > li > input[type="hidden"] ~ * {
    grid-column: 1 / -1;
}
/* Anything else a rate prints after its label (our panel, other plugins' notes) goes under the label. */
body:not(.obs-ship-cards) ul#shipping_method:has(input[value^="lastmily"]) > li > :not(input):not(label),
body:not(.obs-ship-cards) ul.woocommerce-shipping-methods:has(input[value^="lastmily"]) > li > :not(input):not(label) {
    grid-column: 2;
}

/* Narrow shipping cell, plain list: row stacked by lastmily-shipping-extras.js,
   heading above and the methods across the full table width. */
tr.woocommerce-shipping-totals.lastmily-ship-stacked > th { display: none !important; }
tr.woocommerce-shipping-totals.lastmily-ship-stacked > td { width: 100% !important; text-align: left !important; }
tr.woocommerce-shipping-totals.lastmily-ship-stacked > td::before {
    content: attr(data-title);
    display: block;
    margin: 0 0 0.6em;
    font-weight: 600;
}

/* The panel itself. It takes the width of the column it sits in and never
   widens the order-review table (inline-size containment); its content
   adapts to narrow columns through the container queries below. */
.lastmily-delivery-options {
    container-type: inline-size;
    container-name: lastmily-extras;
    display: block;
    clear: both;
    box-sizing: border-box;
    margin: 8px 0 4px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    text-align: left;
    text-indent: 0;
    overflow-wrap: normal;
}
@media (max-width: 480px) {
    .lastmily-delivery-options { padding: 10px; }
}
/* Some themes (XStore) lay rates out inline-flex; keep the panel on its own row. */
#shipping_method li .lastmily-delivery-options,
.woocommerce-shipping-methods li .lastmily-delivery-options {
    flex: none !important;
    width: auto !important;
    max-width: 100%;
}

.lastmily-delivery-options h4 {
    margin: 0 0 8px;
    padding: 0;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
    color: #0f172a;
    text-transform: none;
    letter-spacing: 0;
}
.lastmily-delivery-options .obs-extras-opt {
    font-weight: 400;
    color: #64748b;
}

/* Pickup point block */
.lastmily-pickup-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.lastmily-pickup-row .lastmily-pickup-label {
    font-weight: 600;
    font-size: 13px;
    color: #0f172a;
}
.lastmily-pickup-selection #lastmily-select-pickup-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 0 !important;
    padding: 7px 14px !important;
    line-height: 1.2 !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    white-space: nowrap !important;
    flex-shrink: 0;
    border: 1.5px solid #01aeba !important;
    background: #01aeba !important;
    color: #fff !important;
    border-radius: 8px !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    box-shadow: none !important;
}
.lastmily-pickup-selection #lastmily-select-pickup-btn:hover,
.lastmily-pickup-selection #lastmily-select-pickup-btn:focus {
    background: #018a93 !important;
    border-color: #018a93 !important;
}
.lastmily-delivery-options .lastmily-selected-point-info {
    margin-top: 10px;
    padding: 10px 12px;
    background: #e6f8f9;
    border: 1px solid #a5e6ea;
    border-left-width: 1px;
    border-radius: 8px;
    font-size: 12.5px;
    line-height: 1.45;
    color: #0f4a52;
    word-wrap: break-word;
}
.lastmily-selected-point-info .lspi-label {
    display: block;
    font-weight: 600;
    color: #01717b;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}
.lastmily-selected-point-info .lspi-name { font-weight: 600; color: #0f172a; }
.lastmily-selected-point-info .lspi-address { display: block; color: #64748b; font-size: 12px; margin-top: 2px; }
.lastmily-selected-point-info .lastmily-clear-point { display: inline-block; margin-top: 6px; font-size: 12px; }
.lastmily-delivery-options .lastmily-no-point-selected { margin-top: 6px; padding: 0; color: #94a3b8; font-size: 12px; font-style: italic; }

/* Add-on services: no top separator unless the pickup block precedes it */
.lastmily-delivery-options .lastmily-additional-services {
    margin: 0;
    padding: 0;
    border: 0;
}
.lastmily-delivery-options .lastmily-pickup-selection + .lastmily-additional-services {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}
.lastmily-delivery-options .lastmily-extras-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.lastmily-delivery-options .lastmily-extras-options label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    margin: 0 !important;
    padding: 7px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.3;
    text-indent: 0;
}
.lastmily-delivery-options .lastmily-extras-options label:hover { border-color: #a5e6ea; }
.lastmily-delivery-options .lastmily-extras-options label input[type="checkbox"] { flex: none; margin: 0; }
.lastmily-delivery-options .obs-extra-fee { margin-left: auto; white-space: nowrap; color: #475569; }
.lastmily-delivery-options select.obs-extra-slot {
    width: 100%;
    max-width: 100%;
    /* themes (e.g. XStore) give every select a fixed height: let the text decide */
    height: auto;
    min-height: 38px;
    line-height: 1.4;
    margin: 0;
    padding: 6px 8px;
    box-sizing: border-box;
}
.lastmily-delivery-options .obs-extras-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
    color: #475569;
}
.lastmily-delivery-options .obs-extras-total .obs-extras-total-value { white-space: nowrap; color: #0f172a; }

/* Fixed label/value split in the order review totals, so a long add-ons fee
   label does not widen the label column and squeeze the shipping options. */
body.woocommerce-checkout .woocommerce-checkout-review-order-table tfoot th { width: 30%; }
body.woocommerce-checkout .woocommerce-checkout-review-order-table tfoot td { width: 70%; }

/* Narrow columns (theme sidebars such as Storefront's order review): lighter
   rows without boxes, fee under the service name, no broken words. */
@container lastmily-extras (max-width: 200px) {
    .lastmily-delivery-options .lastmily-extras-options { gap: 2px; }
    .lastmily-delivery-options .lastmily-extras-options label {
        flex-wrap: wrap;
        align-items: flex-start;
        column-gap: 8px;
        row-gap: 0;
        padding: 4px 0;
        border: 0;
        background: none;
    }
    .lastmily-delivery-options .lastmily-extras-options label input[type="checkbox"] { margin-top: 3px; }
    .lastmily-delivery-options .obs-extra-name {
        flex: 1 1 auto;
        overflow-wrap: normal;
        word-break: normal;
        hyphens: manual;
    }
    .lastmily-delivery-options .obs-extra-fee {
        flex-basis: 100%;
        margin-left: 21px;
    }
    .lastmily-delivery-options .obs-extras-total { flex-wrap: wrap; }
}
@container lastmily-extras (max-width: 160px) {
    .lastmily-delivery-options h4,
    .lastmily-delivery-options .obs-extras-total { overflow-wrap: normal; word-break: normal; }
}
