/* ─────────────────────────────────────────────────────────────
 * Axis Puls — shared language switcher (13 languages, /<lang>/ URLs)
 * Glass pill button + animated dropdown panel with live search.
 * Self-contained: works on ANY page (public, dashboard, chat, shifts).
 * Mount: explicit <div data-lang-switcher></div> slot, else auto-mount
 * into .topbar / header / nav, else floating top-start.
 * ───────────────────────────────────────────────────────────── */
.ap-lang-switch {
    position: relative;
    z-index: 1200;
    flex: 0 0 auto;
    font-family: inherit;
}

/* ── Icon-only button (globe symbol; names live in the dropdown) ── */
.ap-lang-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    background: var(--glass-md, rgba(255, 255, 255, 0.06));
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    backdrop-filter: blur(12px) saturate(150%);
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.16));
    border-radius: 12px;
    color: var(--text, #e8eef4);
    font-family: inherit;
    cursor: pointer;
    line-height: 1;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    transition: border-color 0.22s ease, background 0.22s ease,
        transform 0.22s ease, box-shadow 0.22s ease;
}

.ap-lang-btn:hover {
    border-color: var(--primary, #a56eff);
    background: var(--glass-hover, rgba(255, 255, 255, 0.1));
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
}

.ap-lang-btn:active {
    transform: translateY(0) scale(0.97);
}

.ap-lang-btn:focus-visible {
    outline: 2px solid var(--primary, #a56eff);
    outline-offset: 2px;
}

.ap-lang-flag {
    font-size: 19px;
    line-height: 1;
    text-align: center;
    flex-shrink: 0;
}

/* header code badge (IR / EN / …) */
.ap-lang-code {
    font-size: 12.5px;
    font-weight: 800;
    letter-spacing: 1.2px;
    line-height: 1;
    flex-shrink: 0;
}

.ap-lang-name {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 110px;
}

.ap-lang-caret {
    font-size: 10px;
    opacity: 0.7;
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.ap-lang-btn[aria-expanded="true"] .ap-lang-caret {
    transform: rotate(180deg);
}

/* ── Dropdown panel ──────────────────────────────────────── */
.ap-lang-drop {
    position: absolute;
    top: calc(100% + 10px);
    inset-inline-end: 0;
    width: 232px;
    max-width: min(78vw, 300px);
    max-height: 340px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-2, rgba(13, 34, 51, 0.92));
    -webkit-backdrop-filter: blur(22px) saturate(160%);
    backdrop-filter: blur(22px) saturate(160%);
    border: 1.5px solid var(--glass-border, rgba(255, 255, 255, 0.16));
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    padding: 8px;
    transform-origin: top center;
}

.ap-lang-drop[hidden] {
    display: none;
}

.ap-lang-drop:not([hidden]) {
    animation: ap-lang-in 0.22s ease both;
}

@keyframes ap-lang-in {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ── Search row ──────────────────────────────────────────── */
.ap-lang-search {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 4px 8px;
    position: sticky;
    top: 0;
}

.ap-lang-search-icon {
    font-size: 14px;
    opacity: 0.6;
    flex-shrink: 0;
}

.ap-lang-search-input {
    flex: 1;
    min-width: 0;
    background: var(--glass, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.14));
    border-radius: 10px;
    color: var(--text, #e8eef4);
    font-family: inherit;
    font-size: 12.5px;
    padding: 7px 10px;
    outline: none;
    transition: border-color 0.2s ease;
}

.ap-lang-search-input::placeholder {
    color: var(--text-muted, #8b98a8);
}

.ap-lang-search-input:focus {
    border-color: var(--primary, #a56eff);
}

/* ── Language list ───────────────────────────────────────── */
.ap-lang-list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 2px 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary, #a56eff) transparent;
}

.ap-lang-list::-webkit-scrollbar {
    width: 6px;
}

.ap-lang-list::-webkit-scrollbar-track {
    background: transparent;
}

.ap-lang-list::-webkit-scrollbar-thumb {
    background: var(--primary, #a56eff);
    border-radius: 6px;
    opacity: 0.5;
}

.ap-lang-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: none;
    border-radius: 10px;
    background: none;
    color: var(--text, #e8eef4);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    text-align: start;
    transition: background 0.16s ease, transform 0.16s ease;
}

.ap-lang-item:hover {
    background: var(--primary-glass, rgba(165, 110, 255, 0.14));
    transform: translateX(-2px);
}

[dir="ltr"] .ap-lang-item:hover {
    transform: translateX(2px);
}

.ap-lang-item.active {
    background: var(--primary-glass, rgba(165, 110, 255, 0.16));
    font-weight: 800;
}

.ap-lang-item:focus-visible {
    outline: 2px solid var(--primary, #a56eff);
    outline-offset: -2px;
}

.ap-lang-item-flag {
    font-size: 20px;
    line-height: 1;
    width: 30px;
    text-align: center;
    flex-shrink: 0;
}

.ap-lang-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ap-lang-item-check {
    font-size: 13px;
    font-weight: 800;
    color: var(--ok, #06d6a0);
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0;
}

.ap-lang-item.active .ap-lang-item-check {
    opacity: 1;
}

.ap-lang-empty {
    padding: 14px 10px;
    text-align: center;
    font-size: 12.5px;
    color: var(--text-muted, #8b98a8);
}

/* ── Fallback floating position (no layout slot found) ───── */
.ap-lang-switch.ap-lang-floating {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    inset-inline-start: 10px;
}

.ap-lang-switch.ap-lang-floating .ap-lang-drop {
    inset-inline-start: 0;
    inset-inline-end: auto;
}

/* ── Light theme ─────────────────────────────────────────── */
[data-theme="light"] .ap-lang-btn {
    background: rgba(255, 255, 255, 0.75);
    border-color: rgba(15, 25, 40, 0.12);
    color: #16202e;
    box-shadow: 0 4px 14px rgba(15, 25, 40, 0.1);
}

[data-theme="light"] .ap-lang-btn:hover {
    border-color: var(--primary, #7a3cff);
    background: #ffffff;
}

[data-theme="light"] .ap-lang-drop {
    background: rgba(255, 255, 255, 0.96);
    border-color: rgba(15, 25, 40, 0.1);
    box-shadow: 0 24px 55px rgba(15, 25, 40, 0.18);
}

[data-theme="light"] .ap-lang-item {
    color: #16202e;
}

[data-theme="light"] .ap-lang-search-input {
    background: rgba(15, 25, 40, 0.045);
    border-color: rgba(15, 25, 40, 0.12);
    color: #16202e;
}

[data-theme="light"] .ap-lang-empty {
    color: #5b6b7d;
}

/* ── Small screens ───────────────────────────────────────── */
@media (max-width: 480px) {
    .ap-lang-name {
        max-width: 74px;
    }

    .ap-lang-drop {
        width: 216px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ap-lang-drop:not([hidden]) {
        animation: none;
    }

    .ap-lang-btn,
    .ap-lang-item {
        transition: none;
    }
}
