/* =============================================================================
 * SHIPPING REGION CARDS
 * =============================================================================
 * Component: the delivery-region chooser. One card per region, with the shipping
 *            cost on the card.
 * Owner:     Child theme (markup: inc/shipping-regions.php, behaviour:
 *            assets/js/shipping-regions.js).
 * Scope:     Cart page (inside the shipping collapse), cart drawer popup, and the
 *            checkout region field. Every page, either direction.
 *
 * Layout:    Each card is a full-width row: a radio mark at the start edge, the
 *            region name, the cost at the end edge. In right-to-left pages the
 *            start edge is the right, so the mark is on the right and the cost on
 *            the left, with no direction-specific rules: only logical properties
 *            (inline-start / inline-end, padding-inline, text-align: start/end).
 * Sizing:    One column at every width. A card is at least 52px tall (comfortable
 *            tap target); long names wrap, the cost never wraps.
 * Colors:    The theme's tokens (--color-primary and the gray scale), so the
 *            component follows the colors saved in the theme options.
 * States:    default, hover, keyboard focus, selected, unavailable, loading, error.
 * Specificity: Every rule is scoped under .unimart-region-picker (the card rules under
 *            .unimart-region-picker .unimart-region-list). On checkout the cards sit
 *            inside a .form-row, and WooCommerce's ".woocommerce form .form-row label
 *            { display: block; line-height: 2 }" and the theme's radio-input rules would
 *            otherwise win over a bare class selector and collapse the layout.
 * ============================================================================= */

.unimart-region-picker {
    margin: 0;
}

.unimart-region-picker .unimart-region-hint {
    margin: 0 0 12px;
    font-size: var(--font-size-b3, 14px);
    line-height: 1.6;
    color: var(--color-body, #737373);
    text-align: start;
}

.unimart-region-picker .unimart-region-list {
    display: grid;
    gap: 8px;
}

/* -----------------------------------------------------------------------------
 * Card
 * --------------------------------------------------------------------------- */
.unimart-region-picker .unimart-region-list .unimart-region-option {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    margin: 0;
    padding-block: 10px;
    padding-inline: 14px;
    background-color: #fff;
    border: 1.5px solid var(--color-gray-200, #e6e6e6);
    border-radius: 10px;
    cursor: pointer;
    text-align: start;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

/* The radio mark. The real input is visually hidden but stays focusable and
   keyboard operable (arrow keys move between cards). */
.unimart-region-picker .unimart-region-list .unimart-region-option::before {
    content: "";
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    box-sizing: border-box;
    border: 2px solid var(--color-gray-300, #cfcfcf);
    border-radius: 50%;
    background-color: #fff;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.unimart-region-picker .unimart-region-input {
    position: absolute;
    inset-inline-start: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.unimart-region-picker .unimart-region-name {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 500;
    line-height: 1.5;
    color: var(--color-heading, #000);
    overflow-wrap: anywhere;
}

.unimart-region-picker .unimart-region-price {
    flex: 0 0 auto;
    font-weight: 700;
    white-space: nowrap;
    color: var(--color-heading, #000);
    text-align: end;
    unicode-bidi: isolate;
}

/* -----------------------------------------------------------------------------
 * States
 * --------------------------------------------------------------------------- */
@media (hover: hover) {
    .unimart-region-picker .unimart-region-list .unimart-region-option:not(.is-unavailable):not(.is-selected):hover {
        border-color: var(--color-primary);
    }
}

.unimart-region-picker .unimart-region-list .unimart-region-option.is-selected {
    border-color: var(--color-primary);
    background-color: var(--color-gray-100, #f3f3f3);
}

@supports (background-color: color-mix(in srgb, red 10%, white)) {
    .unimart-region-picker .unimart-region-list .unimart-region-option.is-selected {
        background-color: color-mix(in srgb, var(--color-primary) 8%, #fff);
    }
}

.unimart-region-picker .unimart-region-list .unimart-region-option.is-selected::before {
    border-color: var(--color-primary);
    background-color: var(--color-primary);
    box-shadow: inset 0 0 0 3px #fff;
}

.unimart-region-picker .unimart-region-list .unimart-region-option.is-selected .unimart-region-price {
    color: var(--color-primary);
}

/* Keyboard focus only (a mouse or touch choice does not draw the ring). */
.unimart-region-picker .unimart-region-list .unimart-region-option:has(.unimart-region-input:focus-visible) {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.unimart-region-picker .unimart-region-list .unimart-region-option.is-unavailable {
    background-color: var(--color-gray-100, #f3f3f3);
    cursor: not-allowed;
    opacity: 0.6;
}

.unimart-region-picker .unimart-region-list .unimart-region-option.is-unavailable .unimart-region-price {
    font-weight: 500;
}

/* Saving a choice: the list stays visible but cannot be changed until the answer arrives. */
.unimart-region-picker.is-busy .unimart-region-list {
    opacity: 0.65;
    pointer-events: none;
}

.unimart-region-picker .unimart-region-status {
    min-height: 1.4em;
    margin: 8px 0 0;
    font-size: 13px;
    line-height: 1.4;
    color: var(--color-body, #737373);
    text-align: start;
}

/* On checkout nothing ever writes in the status line, and an empty line still reserved about
   30px (its minimum height and top margin), which showed as a blank gap between the cards and
   the next field. Empty, it takes no space; the element stays in the page, so when the cart
   page or drawer writes "جارٍ تحديث تكلفة الشحن…" into it screen readers still announce it. */
.unimart-region-picker .unimart-region-status:empty {
    min-height: 0;
    margin: 0;
}

.unimart-region-picker .unimart-region-status.is-error {
    color: var(--color-danger, #e53e3e);
}

/* -----------------------------------------------------------------------------
 * Checkout field
 * --------------------------------------------------------------------------- */
.unimart-region-legend {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--color-heading, #000);
    text-align: start;
}

.unimart-region-legend .required {
    color: var(--color-danger, #e53e3e);
    text-decoration: none;
}

/* -----------------------------------------------------------------------------
 * Shipping row in the totals (cart page, drawer, checkout summary)
 * --------------------------------------------------------------------------- */
.unimart-shipping-pending {
    font-size: 0.92em;
    font-weight: 500;
    color: var(--color-body, #737373);
}

.unimart-shipping-free {
    color: var(--color-success, #198754);
    font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
    .unimart-region-picker .unimart-region-list .unimart-region-option,
    .unimart-region-picker .unimart-region-list .unimart-region-option::before {
        transition: none;
    }
}
