/* Shared Chinese / English segmented control. */
:is(
    .ui-language-switch,
    .creation-language,
    .portal-language,
    .auth-language-switch,
    .kc-language,
    .topbar-actions > .language,
    .top-actions > .language
) {
    display: inline-flex !important;
    align-items: center !important;
    gap: 3px !important;
    padding: 3px !important;
    border: 1px solid #d8e1ee !important;
    border-radius: 10px !important;
    background: #f8fafc !important;
    box-shadow: none !important;
}

/* Compact mobile language switch used by every shared application topbar. */
@media (max-width: 920px) {
    html body :is(
        header[data-fuuvo-shared-topbar="1"] .ui-language-switch,
        header[data-fuuvo-shared-topbar="1"] .creation-language,
        header[data-fuuvo-shared-topbar="1"] .portal-language,
        .auth-language-switch,
        .kc-language,
        .topbar-actions > .language,
        .top-actions > .language,
        .mobile-chat-actions .ui-language-switch
    ) {
        width: auto !important;
        min-width: 0 !important;
        height: 42px !important;
        min-height: 42px !important;
        padding: 2px !important;
        gap: 2px !important;
        border-radius: 9px !important;
        box-sizing: border-box !important;
    }

    html body :is(
        header[data-fuuvo-shared-topbar="1"] .ui-language-switch-btn,
        header[data-fuuvo-shared-topbar="1"] .creation-language a,
        header[data-fuuvo-shared-topbar="1"] .portal-language a,
        .auth-language-switch > a,
        .auth-language-switch > button,
        .kc-language > a,
        .kc-language > button,
        .topbar-actions > .language > a,
        .topbar-actions > .language > button,
        .top-actions > .language > a,
        .top-actions > .language > button,
        .mobile-chat-actions .ui-language-switch .ui-language-switch-btn
    ) {
        width: 38px !important;
        min-width: 38px !important;
        height: 36px !important;
        min-height: 36px !important;
        padding: 0 6px !important;
        border-radius: 7px !important;
        font-size: 14px !important;
        line-height: 36px !important;
        box-sizing: border-box !important;
    }
}

/* Highest-priority compact size for the shared chat header. */
@media (max-width: 920px) {
    html body[data-mode="chat"] header[data-fuuvo-shared-topbar="1"] .ui-language-switch {
        height: 40px !important;
        min-height: 40px !important;
        padding: 2px !important;
        gap: 2px !important;
    }

    html body[data-mode="chat"] header[data-fuuvo-shared-topbar="1"] .ui-language-switch .ui-language-switch-btn,
    html body[data-mode="chat"] header[data-fuuvo-shared-topbar="1"] .ui-language-switch .ui-language-switch-btn.active {
        width: 36px !important;
        min-width: 36px !important;
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 5px !important;
        font-size: 14px !important;
        line-height: 34px !important;
    }
}

@media (max-width: 920px) {
    html body[data-mode="chat"] header[data-fuuvo-shared-topbar="1"] .ui-language-switch {
        height: 40px !important;
        min-height: 40px !important;
        padding: 2px !important;
        gap: 2px !important;
    }

    html body[data-mode="chat"] header[data-fuuvo-shared-topbar="1"] .ui-language-switch .ui-language-switch-btn,
    html body[data-mode="chat"] header[data-fuuvo-shared-topbar="1"] .ui-language-switch .ui-language-switch-btn.active {
        width: 36px !important;
        min-width: 36px !important;
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 5px !important;
        font-size: 14px !important;
        line-height: 34px !important;
    }
}

:is(
    .ui-language-switch,
    .creation-language,
    .portal-language,
    .auth-language-switch,
    .kc-language,
    .topbar-actions > .language,
    .top-actions > .language
) > :is(a, button) {
    width: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
    min-height: 32px !important;
    padding: 0 9px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 1px solid transparent !important;
    border-radius: 7px !important;
    background: transparent !important;
    color: #7b8ca3 !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
    writing-mode: horizontal-tb !important;
    flex: 0 0 38px !important;
    text-decoration: none !important;
    box-shadow: none !important;
}

:is(
    .ui-language-switch,
    .creation-language,
    .portal-language,
    .auth-language-switch,
    .kc-language,
    .topbar-actions > .language,
    .top-actions > .language
) > :is(a, button).active {
    border-color: #b8d3fa !important;
    background: #eaf3ff !important;
    color: #176dcc !important;
    font-weight: 700 !important;
    box-shadow: inset 0 0 0 1px rgba(23, 109, 204, .08) !important;
}

:is(
    .ui-language-switch,
    .creation-language,
    .portal-language,
    .auth-language-switch,
    .kc-language,
    .topbar-actions > .language,
    .top-actions > .language
) > :is(a, button) + :is(a, button) {
    border-left-color: transparent !important;
}

body[data-ui-theme="dark"] :is(
    .ui-language-switch,
    .creation-language,
    .portal-language,
    .auth-language-switch,
    .kc-language,
    .topbar-actions > .language,
    .top-actions > .language
) {
    border-color: #334155 !important;
    background: #172131 !important;
}

body[data-ui-theme="dark"] :is(
    .ui-language-switch,
    .creation-language,
    .portal-language,
    .auth-language-switch,
    .kc-language,
    .topbar-actions > .language,
    .top-actions > .language
) > :is(a, button) {
    color: #a8b7cf !important;
}

body[data-ui-theme="dark"] :is(
    .ui-language-switch,
    .creation-language,
    .portal-language,
    .auth-language-switch,
    .kc-language,
    .topbar-actions > .language,
    .top-actions > .language
) > :is(a, button).active {
    border-color: #426b9f !important;
    background: #203a5c !important;
    color: #b8d4ff !important;
}

@media (max-width: 920px) {
    :is(
        .ui-language-switch,
        .creation-language,
        .portal-language,
        .auth-language-switch,
        .kc-language,
        .topbar-actions > .language,
        .top-actions > .language
    ) > :is(a, button) {
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 0 9px !important;
        font-size: 14px !important;
    }

    /* The home page keeps a legacy mobile header outside the shared topbar.
       Its responsive rules are highly specific, so pin the same segmented
       contract here as the final authority. */
    html body.chat-landing[data-mode] .mobile-chat-actions .ui-language-switch,
    html body .mobile-chat-actions .ui-language-switch {
        width: auto !important;
        height: auto !important;
        min-height: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        gap: 3px !important;
        padding: 3px !important;
        border: 1px solid #d8e1ee !important;
        border-radius: 10px !important;
        background: #f8fafc !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    html body.chat-landing[data-mode] .mobile-chat-actions .ui-language-switch .ui-language-switch-btn,
    html body .mobile-chat-actions .ui-language-switch .ui-language-switch-btn {
        width: 44px !important;
        min-width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 9px !important;
        border: 1px solid transparent !important;
        border-radius: 7px !important;
        background: transparent !important;
        color: #7b8ca3 !important;
        box-shadow: none !important;
    }

    html body.chat-landing[data-mode] .mobile-chat-actions .ui-language-switch .ui-language-switch-btn.active,
    html body .mobile-chat-actions .ui-language-switch .ui-language-switch-btn.active {
        border-color: #b8d3fa !important;
        background: #eaf3ff !important;
        color: #176dcc !important;
        box-shadow: inset 0 0 0 1px rgba(23, 109, 204, .08) !important;
    }

    html body[data-ui-theme="dark"].chat-landing[data-mode] .mobile-chat-actions .ui-language-switch,
    html body[data-ui-theme="dark"] .mobile-chat-actions .ui-language-switch {
        border-color: #334155 !important;
        background: #172131 !important;
    }

    html body[data-ui-theme="dark"].chat-landing[data-mode] .mobile-chat-actions .ui-language-switch .ui-language-switch-btn,
    html body[data-ui-theme="dark"] .mobile-chat-actions .ui-language-switch .ui-language-switch-btn {
        color: #a8b7cf !important;
    }

    html body[data-ui-theme="dark"].chat-landing[data-mode] .mobile-chat-actions .ui-language-switch .ui-language-switch-btn.active,
    html body[data-ui-theme="dark"] .mobile-chat-actions .ui-language-switch .ui-language-switch-btn.active {
        border-color: #426b9f !important;
        background: #203a5c !important;
        color: #b8d4ff !important;
    }
}

@media (max-width: 920px) {
    html body header[data-fuuvo-shared-topbar="1"] :is(.ui-language-switch, .creation-language, .portal-language),
    html body .mobile-chat-actions .ui-language-switch {
        width: auto !important;
        min-width: 0 !important;
        height: 42px !important;
        min-height: 42px !important;
        padding: 2px !important;
        gap: 2px !important;
        border-radius: 9px !important;
    }

    html body header[data-fuuvo-shared-topbar="1"] :is(.ui-language-switch-btn, .creation-language a, .portal-language a),
    html body .mobile-chat-actions .ui-language-switch .ui-language-switch-btn {
        width: 38px !important;
        min-width: 38px !important;
        height: 36px !important;
        min-height: 36px !important;
        padding: 0 6px !important;
        border-radius: 7px !important;
        font-size: 14px !important;
        line-height: 36px !important;
        box-sizing: border-box !important;
    }
}
