/* ---------------------------------------------------------
   Language switcher (template-parts/header/language-switcher.php)

   Header: a dropdown next to the cart showing the current language
   (flag + name, as the translation plugin outputs it). Below 576px the
   toggle is a globe icon, like the other icon-only header actions.
   Mobile menu: a row of language links.
--------------------------------------------------------- */

.p2p-language-switcher {
    position: relative;

    /* Plugin flag images (TranslatePress, Polylang, WPML). */
    img {
        display: inline-block;
        width: 1.25em;
        height: auto;
        margin-right: 0.45em;
        vertical-align: -0.1em;
    }
}


/* Toggle ------------------------------------------------- */

.p2p-language-switcher__toggle {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

/* The globe only stands in when there is no current language to show. */
.p2p-language-switcher__globe:not(.is-fallback) {
    display: none;
}

.p2p-language-switcher__globe .p2p-icon {
    width: 20px;
    height: 20px;
}

.p2p-language-switcher__chevron {
    font-size: 0.7em;
    transition: transform 0.2s ease;
}

.p2p-language-switcher.is-open .p2p-language-switcher__chevron {
    transform: rotate(180deg);
}


/* Dropdown ----------------------------------------------- */

.p2p-language-switcher__list {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    z-index: 20;

    /*
     * Sized to the longest language name. Without this the list is sized
     * against the (narrow) toggle and long names run into the edge.
     */
    width: max-content;
    min-width: max(100%, 10rem);
    margin: 0;
    padding: 0.5rem;
    list-style: none;

    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);

    visibility: hidden;
    opacity: 0;
    transform: translateY(-4px);
    transition:
        opacity 0.15s ease,
        transform 0.15s ease,
        visibility 0s linear 0.15s;

    /* Bridges the gap above the list, so hover isn't lost on the way. */
    &::before {
        content: "";
        position: absolute;
        right: 0;
        bottom: 100%;
        left: 0;
        height: 0.6rem;
    }
}

.p2p-language-switcher.is-open .p2p-language-switcher__list {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition:
        opacity 0.15s ease,
        transform 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
    .p2p-language-switcher--header:hover .p2p-language-switcher__list {
        visibility: visible;
        opacity: 1;
        transform: none;
        transition:
            opacity 0.15s ease,
            transform 0.15s ease;
    }

    .p2p-language-switcher--header:hover .p2p-language-switcher__chevron {
        transform: rotate(180deg);
    }
}

.p2p-language-switcher__list .p2p-language-switcher__link {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem 0.5rem 0.75rem;
    border-radius: 5px;
    color: inherit;
    text-decoration: none;
    white-space: nowrap;

    &:hover,
    &:focus-visible {
        background: #f0f0f0;
    }

    &.is-current {
        font-weight: 600;
    }
}


/* Mobile menu row ---------------------------------------- */

.p2p-language-switcher__inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;

    img {
        display: inline-block;
        width: 1.25em;
        height: auto;
        margin-right: 0.45em;
        vertical-align: -0.1em;
    }

    .is-current {
        font-weight: 600;
    }
}


/* Shortcode output: the plugin styles it, the theme only places it. */
.p2p-language-switcher--shortcode {
    display: inline-flex;
    align-items: center;
}


/* xs: globe icon only, like the other header actions. */
@media (max-width: 575.98px) {
    .p2p-language-switcher__globe:not(.is-fallback) {
        display: inline-flex;
    }

    .p2p-language-switcher__chevron {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .p2p-language-switcher__chevron,
    .p2p-language-switcher__list {
        transition: none !important;
    }
}
