/* InfinityDS bilingual UI layer: Persian (RTL) + English (LTR). */

html[dir="rtl"] body {
    font-family: Vazirmatn, Tahoma, "Segoe UI", Arial, sans-serif;
}

html[dir="ltr"] body {
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
}

html[dir="rtl"] body,
html[dir="rtl"] input,
html[dir="rtl"] textarea,
html[dir="rtl"] select,
html[dir="rtl"] button {
    text-align: start;
}

html[dir="ltr"] body,
html[dir="ltr"] input,
html[dir="ltr"] textarea,
html[dir="ltr"] select,
html[dir="ltr"] button {
    text-align: start;
}

/* Keep technical identifiers and numeric tokens predictable in both locales. */
[dir="ltr"],
.i18n-switcher__code,
.mono,
code,
pre,
kbd,
samp {
    unicode-bidi: isolate;
}

.i18n-switcher {
    position: fixed;
    top: 1rem;
    inset-inline-end: 1rem;
    z-index: 10000;
    direction: inherit;
    font-family: inherit;
}

.i18n-switcher__trigger {
    width: 136px;
    min-height: 42px;
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr) 16px;
    align-items: center;
    gap: .5rem;
    padding: .55rem .7rem;
    border-radius: 12px;
    border: 1px solid var(--border, rgba(148, 163, 184, .35));
    background: var(--sidebar-bg, rgba(15, 23, 42, .94));
    color: var(--text-main, #f8fafc);
    box-shadow: var(--shadow-sm, 0 10px 28px rgba(0, 0, 0, .18));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    cursor: pointer;
    font: inherit;
    text-align: start;
}

.i18n-switcher__globe {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    flex: none;
}

.i18n-switcher__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .82rem;
    font-weight: 700;
}

.i18n-switcher__chevron {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    transition: transform .2s ease;
}

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

.i18n-switcher__menu {
    position: absolute;
    top: calc(100% + .45rem);
    inset-inline-end: 0;
    width: 180px;
    padding: .4rem;
    border-radius: 14px;
    border: 1px solid var(--border, rgba(148, 163, 184, .35));
    background: var(--sidebar-bg, rgba(15, 23, 42, .98));
    color: var(--text-main, #f8fafc);
    box-shadow: var(--shadow, 0 22px 50px rgba(0, 0, 0, .28));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.i18n-switcher__option {
    width: 100%;
    min-height: 42px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: .65rem;
    padding: .5rem .65rem;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
    text-align: start;
}

.i18n-switcher__option:hover,
.i18n-switcher__option.is-active {
    background: var(--accent-soft, rgba(14, 165, 233, .12));
    color: var(--accent, #38bdf8);
}

.i18n-switcher__code {
    width: 34px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .7rem;
    opacity: .72;
    direction: ltr;
    text-align: center;
}

.i18n-switcher__native {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Standalone auth/developer pages keep language and theme controls separated. */
body.auth-page .i18n-switcher {
    inset-inline-start: max(18px, env(safe-area-inset-left), env(safe-area-inset-right));
    inset-inline-end: auto;
}

/* Shared LTR alignment helpers for tables/forms that inherit the document direction. */
html[dir="ltr"] th:not(.mono),
html[dir="ltr"] td:not(.mono),
html[dir="ltr"] .ui-input,
html[dir="ltr"] input:not([type="number"]),
html[dir="ltr"] textarea,
html[dir="ltr"] select {
    text-align: start;
}

@media (max-width: 900px) {
    .i18n-switcher {
        top: 1rem;
    }
}

@media (max-width: 560px) {
    .i18n-switcher {
        top: max(.65rem, env(safe-area-inset-top));
        inset-inline-end: max(.65rem, env(safe-area-inset-right), env(safe-area-inset-left));
    }

    body.auth-page .i18n-switcher {
        inset-inline-start: max(12px, env(safe-area-inset-left), env(safe-area-inset-right));
        inset-inline-end: auto;
    }

    .i18n-switcher__trigger {
        width: 124px;
        min-height: 40px;
        padding: .5rem .6rem;
    }

    .i18n-switcher__menu {
        width: 168px;
    }
}
