/*
 * CountryPicker — reusable public country picker primitive (UIUX-008R).
 * Markup: template-parts/components/country-picker.php
 * Behaviour: assets/js/country-picker.js
 *
 * Visual vocabulary follows the header Market selector (24x18 flag with a
 * hairline, 44px rows, rounded popover, search field, bottom sheet on small
 * screens) but the selected state is the approved neutral/charcoal language,
 * never a green fill. Consumes canonical tokens only; declares none.
 */

.country-picker {
    /* The site-wide focus utility forces outline-color: var(--color-focus);
       re-point that canonical token so focus rings here are charcoal, not green. */
    --color-focus: #1f2328;
    position: relative;
    display: grid;
    gap: 0.4rem;
    width: min(100%, 22.5rem);
    min-width: 0;
}

.country-picker__label {
    color: var(--u8r-ink, #181a19);
    font-size: 0.9375rem;
    font-weight: 700;
    line-height: 1.3;
    cursor: pointer;
}

.country-picker__trigger {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    min-height: var(--touch-target-preferred, 44px);
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--u8r-rule-strong, #b7bfb9);
    border-radius: 10px;
    background: var(--neutral-0, #fff);
    color: var(--u8r-ink, #181a19);
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 650;
    line-height: 1.2;
    text-align: left;
    cursor: pointer;
    transition: border-color 150ms ease, background-color 150ms ease;
}

.country-picker__trigger:hover {
    border-color: var(--u8r-charcoal, #202321);
    background: var(--u8r-control-hover, #efefef);
}

.country-picker__trigger:focus-visible {
    outline: 3px solid var(--u8r-focus, #356c80);
    outline-offset: 3px;
}

.country-picker__trigger[aria-expanded="true"] {
    border-color: var(--u8r-charcoal, #202321);
}

.country-picker__flag,
.country-picker__option-flag {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 18px;
    line-height: 1;
}

.country-picker__flag-img {
    display: block;
    width: 24px;
    height: 18px;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--u8r-ink, #181a19) 12%, transparent);
}

.country-picker__flag-emoji {
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    font-size: 1.05rem;
}

.country-picker__globe,
.country-picker__chevron,
.country-picker__check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--u8r-muted, #59615c);
}

.country-picker .aanya-icon,
.country-picker .aanya-icon svg {
    display: block;
    width: 1.05rem;
    height: 1.05rem;
}

.country-picker__value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.country-picker__chevron {
    flex: 0 0 auto;
    margin-left: auto;
    color: var(--u8r-charcoal, #202321);
    transition: transform 150ms ease;
}

.country-picker__trigger[aria-expanded="true"] .country-picker__chevron {
    transform: rotate(180deg);
}

/* Anchored popover (desktop / tablet) */
.country-picker__popover {
    position: absolute;
    top: calc(100% + 0.4rem);
    left: 0;
    z-index: var(--z-dropdown, 500);
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 17.5rem;
    max-height: min(24rem, 70vh);
    border: 1px solid var(--u8r-rule, #d9deda);
    border-radius: 14px;
    background: var(--neutral-0, #fff);
    box-shadow: var(--elevation-3, 0 18px 44px rgba(24, 26, 25, 0.11));
    overflow: hidden;
}

.country-picker__popover[hidden],
.country-picker__backdrop[hidden],
.country-picker__search-wrap[hidden],
.country-picker__no-match[hidden],
.country-picker__list [hidden] {
    display: none;
}

.country-picker__head {
    display: none;
}

.country-picker__search-wrap {
    flex: 0 0 auto;
    padding: 0.6rem 0.6rem 0.35rem;
}

.country-picker__search {
    width: 100%;
    min-height: var(--touch-target-compact, 40px);
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--u8r-rule-strong, #b7bfb9);
    border-radius: 10px;
    background: var(--neutral-0, #fff);
    color: var(--u8r-ink, #181a19);
    font: inherit;
    font-size: 0.9375rem;
}

.country-picker__search:focus-visible {
    outline: 3px solid var(--u8r-focus, #356c80);
    outline-offset: 1px;
}

.country-picker__list {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    align-content: start;
    gap: 0.15rem;
    margin: 0;
    padding: 0.4rem;
    list-style: none;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.country-picker__option {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) 1.05rem;
    align-items: center;
    gap: 0.7rem;
    min-height: var(--touch-target-preferred, 44px);
    padding: 0.45rem 0.65rem;
    border-radius: 10px;
    color: var(--u8r-ink, #181a19);
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.3;
    text-decoration: none;
    cursor: pointer;
}

.country-picker__option:hover {
    background: var(--u8r-control-hover, #efefef);
    color: var(--u8r-ink, #181a19);
}

.country-picker__option:focus-visible {
    outline: 2px solid var(--u8r-focus, #356c80);
    outline-offset: -2px;
}

.country-picker__option-name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.country-picker__check {
    visibility: hidden;
    color: var(--u8r-charcoal, #202321);
}

/* Selected: neutral/charcoal — surface tint + charcoal rule + check, never green. */
.country-picker__option[aria-selected="true"] {
    background: var(--u8r-surface-muted, #f2f2f2);
    box-shadow: inset 3px 0 0 var(--u8r-charcoal, #202321);
    font-weight: 700;
}

.country-picker__option[aria-selected="true"] .country-picker__check {
    visibility: visible;
}

.country-picker__no-match,
.country-picker__note {
    margin: 0;
    padding: 0.35rem 1rem 0.85rem;
    color: var(--u8r-muted, #59615c);
    font-size: 0.875rem;
    line-height: 1.45;
}

.country-picker__noscript {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1rem;
    margin: 0.35rem 0 0;
    padding: 0;
    list-style: none;
}

.country-picker__backdrop {
    display: none;
}

body.country-picker-open {
    overflow: hidden;
}

/* Small screens: the Market selector's bottom-sheet pattern. */
@media (max-width: 767px) {
    .country-picker {
        width: 100%;
    }

    .country-picker__backdrop:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: var(--z-chrome-modal-backdrop, 10080);
        display: block;
        background: color-mix(in srgb, var(--u8r-ink, #181a19) 40%, transparent);
    }

    .country-picker__popover.is-sheet {
        position: fixed;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: var(--z-chrome-modal, 10082);
        width: 100%;
        min-width: 0;
        max-height: min(85vh, 36rem);
        border-radius: 16px 16px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .country-picker__popover.is-sheet .country-picker__head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.85rem 0.6rem 0.25rem 1rem;
    }

    .country-picker__title {
        margin: 0;
        color: var(--u8r-ink, #181a19);
        font-size: 1rem;
        font-weight: 700;
    }

    .country-picker__close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: var(--touch-target-preferred, 44px);
        height: var(--touch-target-preferred, 44px);
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: var(--u8r-charcoal, #202321);
        cursor: pointer;
    }

    .country-picker__close:focus-visible {
        outline: 3px solid var(--u8r-focus, #356c80);
        outline-offset: -3px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .country-picker__trigger,
    .country-picker__chevron {
        transition: none;
    }
}
