/* AI Translate Language Switcher Shortcode Styles */

/* Menu integration - ensure proper positioning in nav menus */
.menu-item-language-switcher {
    position: relative;
}

/* Desktop: keep switcher inline with siblings, no layout override */
.menu-item-language-switcher > .ai-menu-language-current {
    white-space: nowrap;
}

/* Force black text only on submenu elements for contrast */
.menu-item-language-switcher .sub-menu .ai-menu-language-item a,
.menu-item-language-switcher .sub-menu .ai-menu-language-item a *,
.menu-item-language-switcher .sub-menu .ai-menu-language-item .ai-menu-language-code {
    color: #000 !important;
}

/* Main menu inherits parent color */
.menu-item-language-switcher .ai-menu-language-current {
    color: inherit !important;
}

.menu-item-language-switcher > .ai-language-switcher-dropdown,
.menu-item-language-switcher > .ai-language-switcher-inline {
    margin: 0;
    padding: 0;
}

/* Menu-specific language switcher styling */
.ai-menu-language-current {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    text-decoration: none !important;
    background: none !important;
    border: none !important;
    cursor: pointer;
    font-size: inherit;
    color: inherit;
    line-height: inherit;
}

.ai-menu-language-current:hover,
.ai-menu-language-current:focus {
    text-decoration: none !important;
}


/* Inline language switcher in menu */
.menu-item-language-switcher .ai-language-switcher-inline {
    display: flex !important;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    margin: 0;
    padding: 0;
}

.menu-item-language-switcher .ai-language-switcher-inline .ai-language-item {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    text-decoration: none;
    color: #495057;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    margin: 0;
}

.menu-item-language-switcher .ai-language-switcher-inline .ai-language-item:hover,
.menu-item-language-switcher .ai-language-switcher-inline .ai-language-item:focus {
    background: #e9ecef;
    border-color: #dee2e6;
    color: #212529;
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.ai-menu-language-flag {
    width: 16px;
    height: 12px;
    border-radius: 2px;
    vertical-align: middle;
    flex-shrink: 0;
}

.ai-menu-language-code {
    font-weight: 600;
    font-size: 0.9em;
    text-transform: uppercase;
}

/* Submenu styling for language switcher */
.menu-item-language-switcher .sub-menu {
    min-width: 55px !important;
    background: #fff !important;
    border: 2px solid #ddd !important;
    border-radius: 0 0 4px 4px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    z-index: 999999 !important; /* Very high z-index to go over topbar overlay */
    margin-top: 0 !important;
    display: none !important; /* Hidden by default */
    opacity: 1 !important;
    visibility: visible !important;
}

/* Desktop hover/focus behavior */
@media (min-width: 769px) {
    .menu-item-language-switcher:hover .sub-menu,
    .menu-item-language-switcher:focus-within .sub-menu,
    .menu-item-language-switcher .sub-menu:hover,
    .menu-item-language-switcher .sub-menu:focus-within {
        display: block !important; /* Show on hover/focus */
    }
}

/* Force show submenu when JavaScript sets ai-force-show class */
.menu-item-language-switcher .sub-menu.ai-force-show {
    display: block !important;
    max-height: 500px !important;
    opacity: 1 !important;
    visibility: visible !important;
    z-index: 999999 !important;
}

.menu-item-language-switcher .sub-menu .ai-menu-language-item {
    list-style: none !important;
    margin: 0 !important;
}

.menu-item-language-switcher .sub-menu .ai-menu-language-item a {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 8px 12px !important;
    text-decoration: none !important;
    color: #333 !important;
    white-space: nowrap !important;
    border-bottom: 1px solid #f0f0f0 !important;
}

.menu-item-language-switcher .sub-menu .ai-menu-language-item:last-child a {
    border-bottom: none !important;
}

.menu-item-language-switcher .sub-menu .ai-menu-language-item:hover a,
.menu-item-language-switcher .sub-menu .ai-menu-language-item:focus a {
    background-color: #f8f9fa !important;
}

.menu-item-language-switcher .sub-menu .ai-menu-language-item.current-menu-item a {
    font-weight: 600 !important;
    background-color: #e3f2fd !important;
    color: #000 !important;
}

/* Admin menu interface styling */
.ai-language-switcher-tab-link .nav-tab-link {
    border-color: #007cba;
    background: #fff;
    color: #007cba;
}

.ai-language-switcher-tab-link .nav-tab-link.nav-tab-active,
.ai-language-switcher-tab-link .nav-tab-link:hover {
    background: #007cba;
    color: #fff;
}

.ai-language-switcher-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.ai-language-switcher-inline .ai-language-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    text-decoration: none;
    color: #495057;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.ai-language-switcher-inline .ai-language-item:hover,
.ai-language-switcher-inline .ai-language-item:focus {
    background: #e9ecef;
    border-color: #dee2e6;
    color: #212529;
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.ai-language-switcher-inline .ai-language-item.current {
    background: #007cba;
    border-color: #007cba;
    color: #fff;
}

/* Compact flag orb. The legacy `gallery` shortcode now renders this minimal
 * trigger so it remains a useful language selector in headers and corners. */
.ai-language-switcher-orb {
    position: relative;
    display: inline-block;
    --ai-language-orb-size: 52px;
}

.ai-language-orb-trigger {
    position: relative;
    display: grid;
    width: var(--ai-language-orb-size);
    height: var(--ai-language-orb-size);
    place-items: center;
    padding: 4px;
    overflow: visible;
    border: 0;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.ai-language-orb-trigger:hover,
.ai-language-orb-trigger:focus-visible,
.ai-language-switcher-orb.is-open .ai-language-orb-trigger {
    outline: none;
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.25);
}

.ai-language-orb-flag {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.ai-language-orb-menu {
    position: absolute;
    z-index: 2147483001;
    top: calc(100% + 14px);
    left: 0;
    display: grid;
    width: max-content;
    max-width: calc(100vw - 40px);
    gap: 4px;
    min-width: 0;
    padding: 7px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.2);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px) scale(0.96);
    transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
    visibility: hidden;
}

.ai-language-orb-menu[hidden] {
    display: grid;
}

.ai-language-switcher-orb.is-open .ai-language-orb-menu {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    visibility: visible;
}

.ai-language-orb-item {
    display: flex;
    width: auto;
    height: 42px;
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    padding: 5px 10px 5px 5px;
    border-radius: 12px;
    background: transparent;
    color: #182230;
    text-decoration: none;
    transition: background-color 160ms ease, color 160ms ease;
}

.ai-language-orb-item:hover,
.ai-language-orb-item:focus-visible {
    outline: none;
    background: #edf8ff;
}

.ai-language-orb-item.is-current {
    background: #f2f4f7;
    cursor: default;
}

.ai-language-orb-item-flag {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border-radius: 50%;
    object-fit: cover;
}

.ai-language-orb-item-name {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

/* Header-friendly row: all languages are visible, current language has a ring. */
.ai-language-switcher-bar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    --ai-language-bar-size: 32px;
}

.ai-language-bar-item,
.ai-language-bar-link,
.ai-language-bar-current {
    display: inline-flex;
}

.ai-language-bar-link,
.ai-language-bar-current {
    position: relative;
    width: var(--ai-language-bar-size);
    height: var(--ai-language-bar-size);
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 50%;
    color: inherit;
    text-decoration: none;
}

.ai-language-bar-link:hover,
.ai-language-bar-link:focus-visible {
    outline: 2px solid #007cba;
    outline-offset: 3px;
    transform: translateY(-1px);
}

.ai-language-bar-item.is-current .ai-language-bar-current {
    box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #007cba;
}

.ai-language-bar-flag {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
}

.ai-language-bar-code {
    position: absolute;
    right: -2px;
    bottom: -2px;
    padding: 2px 3px;
    border-radius: 4px;
    background: #182230;
    color: #ffffff;
    font-size: 8px;
    line-height: 1;
}

.ai-language-bar-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.ai-language-switcher-dropdown {
    position: relative;
    display: inline-block;
}

/* Floating switcher positions — match classic compact pill + calm grey hover */
.ai-language-switcher-floating {
    position: fixed;
    z-index: 2147483000;
}

/* Immediate navigation feedback stays inside the existing flag orb: the flag
 * fades and the same circle becomes a spinner until the next page is ready. */
.ai-language-switching .ai-language-switcher-orb .ai-language-orb-trigger {
    pointer-events: none;
}

.ai-language-switching .ai-language-switcher-orb .ai-language-orb-trigger > :not(.ai-language-orb-flag) {
    opacity: 0;
}

.ai-language-switching .ai-language-switcher-orb .ai-language-orb-flag {
    opacity: 0;
}

.ai-language-switching .ai-language-switcher-orb .ai-language-orb-trigger::after {
    position: absolute;
    width: 42%;
    height: 42%;
    box-sizing: border-box;
    border: 2px solid rgba(24, 34, 48, 0.22);
    border-top-color: #182230;
    border-radius: 50%;
    content: "";
    animation: ai-language-switch-spin 750ms linear infinite;
}

@keyframes ai-language-switch-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .ai-language-switcher-floating {
        transition: none;
    }

    .ai-language-switching .ai-language-orb-trigger::after {
        animation: none;
    }
}

/* The selected inline/gallery presentation still needs the same corner anchoring
 * as the default dropdown when it is rendered by the site-wide switcher. */
.ai-language-switcher-floating.ai-language-switcher-inline,
.ai-language-switcher-floating.ai-language-switcher-bar {
    max-width: min(640px, calc(100vw - 40px));
}

.ai-language-switcher-floating.ai-language-switcher-inline {
    padding: 8px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.ai-language-switcher-floating .ai-language-switcher-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: 24px;
    border: none;
    background: #1e3a8a;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: none;
}

.ai-language-switcher-floating .ai-language-switcher-btn:hover,
.ai-language-switcher-floating .ai-language-switcher-btn:focus {
    background: #1e3a8a;
    border: none;
    outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.ai-language-switcher-floating .ai-language-flag {
    width: 20px;
    height: 14px;
    border-radius: 2px;
}

.ai-language-switcher-floating .ai-language-switcher-menu {
    right: auto;
    left: 0;
    min-width: 140px;
    width: max-content;
    max-height: none;
    margin-top: 0;
    padding: 8px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    overflow: visible;
}

.ai-language-switcher-floating .ai-language-item {
    gap: 8px;
    padding: 8px 10px;
    border-bottom: none;
    border-radius: 6px;
    color: #222;
    font-size: 13px;
    transition: none;
}

.ai-language-switcher-floating .ai-language-item:hover,
.ai-language-switcher-floating .ai-language-item:focus {
    background: #f3f4f6;
    outline: none;
    color: #222 !important;
}

.ai-language-switcher-floating .ai-language-item.current {
    background: transparent;
    font-weight: 600;
}

.ai-language-switcher-pos-bottom-left {
    bottom: 20px;
    left: 20px;
}

.ai-language-switcher-pos-bottom-right {
    right: 20px;
    bottom: 20px;
}

.ai-language-switcher-pos-top-left {
    top: 20px;
    left: 20px;
}

.ai-language-switcher-pos-top-right {
    top: 20px;
    right: 20px;
}

.ai-language-switcher-pos-bottom-left .ai-language-switcher-menu,
.ai-language-switcher-pos-bottom-right .ai-language-switcher-menu {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 8px;
}

.ai-language-switcher-pos-bottom-right .ai-language-switcher-menu,
.ai-language-switcher-pos-top-right .ai-language-switcher-menu {
    right: 0;
    left: auto;
}

.ai-language-switcher-pos-top-left .ai-language-switcher-menu,
.ai-language-switcher-pos-top-right .ai-language-switcher-menu {
    top: 100%;
    bottom: auto;
    margin-top: 8px;
    margin-bottom: 0;
}

/* Override the classic floating-dropdown treatment for the intentionally
 * circular orb and compact bar. These selectors are placed after the legacy
 * floating rules so theme-independent orb sizing remains intact. */
.ai-language-switcher-floating.ai-language-switcher-orb .ai-language-orb-trigger {
    display: grid;
    width: var(--ai-language-orb-size);
    height: var(--ai-language-orb-size);
    padding: 4px;
    border: 0;
    border-radius: 50%;
    background: #ffffff;
    color: #182230;
}

.ai-language-switcher-floating.ai-language-switcher-orb .ai-language-orb-trigger:hover,
.ai-language-switcher-floating.ai-language-switcher-orb .ai-language-orb-trigger:focus-visible {
    background: #ffffff;
}

.ai-language-switcher-floating.ai-language-switcher-orb .ai-language-orb-menu {
    display: grid;
    width: max-content;
    max-width: calc(100vw - 40px);
    min-width: 0;
    padding: 7px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    overflow: visible;
}

.ai-language-switcher-floating.ai-language-switcher-orb .ai-language-orb-item {
    width: auto;
    height: 42px;
    padding: 5px 10px 5px 5px;
    color: #182230;
}

.ai-language-switcher-floating.ai-language-switcher-orb .ai-language-orb-item:hover,
.ai-language-switcher-floating.ai-language-switcher-orb .ai-language-orb-item:focus-visible {
    background: #edf8ff;
    color: #182230 !important;
}

.ai-language-switcher-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #007cba;
    border: 2px solid #007cba;
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.ai-language-switcher-btn:hover,
.ai-language-switcher-btn:focus {
    background: #005a87;
    border-color: #005a87;
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.ai-language-switcher-btn[aria-expanded="true"] .ai-language-arrow {
    transform: rotate(180deg);
}

.ai-language-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.ai-language-switcher-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    margin-top: 15px;
    max-height: 300px;
    overflow-y: auto;
}

.ai-language-switcher-menu[hidden] {
    display: none;
}

.ai-language-switcher-menu:not([hidden]) {
    display: block;
}

.ai-language-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    text-decoration: none;
    color: inherit;
    font-size: 14px;
    transition: background-color 0.2s ease;
    border-bottom: 1px solid #f8f9fa;
}

.ai-language-item:hover,
.ai-language-item:focus {
    background: #f8f9fa;
    outline: 2px solid #007cba;
    outline-offset: -2px;
    color: #000 !important;
}

.ai-language-item.current {
    background: #e3f2fd;
    color: #000 !important;
    font-weight: 600;
}

.ai-language-item:last-child {
    border-bottom: none;
}

.ai-language-flag {
    width: 20px;
    height: 14px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* All language codes inherit by default */
.ai-language-code,
.ai-menu-language-code {
    font-weight: 600 !important;
    text-transform: uppercase !important;
    color: inherit !important;
}

/* Main menu language codes inherit parent color */
.menu-item-language-switcher .ai-menu-language-current .ai-menu-language-code {
    color: inherit !important;
}

/* Submenu language codes are black for contrast */
.menu-item-language-switcher .sub-menu .ai-menu-language-code {
    color: #868e96 !important;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .ai-language-switcher-inline {
        gap: 4px;
    }

    .ai-language-switcher-inline .ai-language-item {
        padding: 4px 8px;
        font-size: 13px;
    }

    .ai-language-switcher-btn {
        padding: 6px 10px;
        font-size: 13px;
    }

    .ai-language-item {
        padding: 12px 16px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .ai-language-flag {
        width: 24px;
        height: 16px;
    }

    /* Mobile menu language switcher adjustments */
    .menu-item-language-switcher .sub-menu {
        position: static !important;
        top: auto !important;
        left: auto !important;
        z-index: 999999 !important; /* Keep high z-index for mobile too */
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
        border: 1px solid #ddd !important;
        border-radius: 0 0 4px 4px !important;
        background: #fff !important;
        margin-left: 10px !important; /* Indent submenu */
        max-width: 55px !important; /* Limit width to match desktop */
        opacity: 1 !important;
        visibility: visible !important;
        color: #000 !important;
    }

    .menu-item-language-switcher .sub-menu .ai-language-item {
        color: #000 !important;
    }

    .menu-item-language-switcher .ai-menu-language-current {
        cursor: pointer !important;
        position: relative !important;
    }

    .menu-item-language-switcher .ai-menu-language-current::after {
        content: " ▼";
        font-size: 10px;
        margin-left: 2px;
        padding: 17px 15px !important;
    }

    .menu-item-language-switcher .ai-menu-language-current[aria-expanded="true"]::after {
        content: " ▲";
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .ai-language-switcher-inline .ai-language-item {
        border: 2px solid currentColor;
    }

    .ai-language-switcher-btn {
        border-width: 3px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .ai-language-switcher-inline .ai-language-item,
    .ai-language-switcher-btn,
    .ai-language-item,
    .ai-language-arrow {
        transition: none;
    }
}

/* RTL: mirror absolute menus and submenu indent (dir set by AI Translate for ar/he) */
[dir="rtl"] .menu-item-language-switcher .sub-menu {
    left: auto !important;
    right: 0 !important;
}

[dir="rtl"] .ai-language-switcher-menu {
    left: auto;
    right: 0;
}

@media (max-width: 768px) {
    [dir="rtl"] .menu-item-language-switcher .sub-menu {
        margin-left: 0 !important;
        margin-right: 10px !important;
    }

    [dir="rtl"] .menu-item-language-switcher .ai-menu-language-current::after {
        margin-left: 0;
        margin-right: 2px;
    }
}
