/* Custom language switcher with flags */

/* Kill legacy select styles that still target #J_lang_switch (black #444 block) */
#app-header #J_lang_switch.lang-switch,
#app-header .lang-switch {
    background: transparent !important;
    background-color: transparent !important;
    color: inherit !important;
    height: auto !important;
    line-height: normal !important;
    margin-left: 10px !important;
    padding: 0 !important;
    text-align: left !important;
    border: 0 !important;
    box-shadow: none !important;
}

.lang-switch {
    --ls-border: #d8e0ec;
    --ls-bg: #fff;
    --ls-text: #243047;
    --ls-muted: #6b7280;
    --ls-hover: #f3f6fb;
    --ls-primary: var(--primary-color, #4066b8);
    position: relative;
    z-index: 40;
    margin-left: 10px;
    user-select: none;
}

#app-header .lang-switch__btn {
    background: var(--ls-bg) !important;
    color: var(--ls-text) !important;
    height: auto !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 10px 0 8px !important;
    text-align: left !important;
}

.lang-switch__btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 10px 0 8px;
    border: 1px solid var(--ls-border);
    border-radius: 999px;
    background: var(--ls-bg);
    color: var(--ls-text);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}

.lang-switch__btn:hover,
.lang-switch.is-open .lang-switch__btn,
.lang-switch:hover .lang-switch__btn {
    border-color: rgba(64, 102, 184, 0.45);
    box-shadow: 0 4px 14px rgba(32, 54, 110, 0.08);
    background: #fff;
}

.lang-switch__flag {
    width: 20px;
    height: 14px;
    border-radius: 2px;
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
    flex: 0 0 auto;
    display: block;
}

.lang-switch__flag svg {
    display: block;
    width: 100%;
    height: 100%;
}

.lang-switch__label {
    letter-spacing: 0.02em;
    text-transform: none;
}

.lang-switch__caret {
    width: 10px;
    height: 10px;
    color: var(--ls-muted);
    transition: transform .2s ease;
}

.lang-switch:hover .lang-switch__caret,
.lang-switch.is-open .lang-switch__caret {
    transform: rotate(180deg);
    color: var(--ls-primary);
}

.lang-switch__menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 148px;
    padding: 6px;
    margin: 0;
    list-style: none;
    background: #fff;
    border: 1px solid var(--ls-border);
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(32, 54, 110, 0.14);
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity .18s ease, transform .18s ease, visibility .18s ease;
    pointer-events: none;
}

.lang-switch__menu::before {
    content: "";
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
}

.lang-switch:hover .lang-switch__menu,
.lang-switch.is-open .lang-switch__menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.lang-switch__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ls-text);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
    text-transform: none;
}

.lang-switch__item:hover {
    background: var(--ls-hover);
    color: var(--ls-primary);
}

.lang-switch__item.is-active {
    background: rgba(64, 102, 184, 0.1);
    color: var(--ls-primary);
}

.lang-switch__item-check {
    margin-left: auto;
    width: 14px;
    height: 14px;
    color: var(--ls-primary);
    opacity: 0;
}

.lang-switch__item.is-active .lang-switch__item-check {
    opacity: 1;
}

/* Hide legacy select if still present */
select.J_lang_switch {
    display: none !important;
}

@media (max-width: 991.98px) {
    .lang-switch {
        margin: 10px 0 0;
        width: 100%;
    }

    .lang-switch__btn {
        width: 100%;
        justify-content: flex-start;
        border-radius: 10px;
        min-height: 40px;
    }

    .lang-switch__caret {
        margin-left: auto;
    }

    /* Mobile: tap to open (hover unreliable on touch) */
    .lang-switch__menu,
    .lang-switch:hover .lang-switch__menu {
        position: static;
        margin-top: 8px;
        box-shadow: none;
        transform: none;
        display: none;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .lang-switch.is-open .lang-switch__menu,
    .lang-switch.is-open:hover .lang-switch__menu {
        display: block;
    }
}
