/* ============================================================
 * KernelHost i18n styles — language dropdown + RTL helpers.
 * Loaded by every page served via the /v2 router. The dropdown
 * is intentionally self-contained: no Bootstrap classes, no
 * jQuery, just CSS + a tiny init script in /js/i18n.js.
 * ============================================================ */

/* Trigger button (glass pill) ------------------------------- */
.kh-lang-dropdown {
    position: relative;
    display: inline-block;
}
.kh-lang-current {
    appearance: none;
    background: rgba(255, 255, 255, 0.06);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.14);
    padding: 6px 10px 6px 8px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.3px;
    border-radius: 6px;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.kh-lang-current:hover,
.kh-lang-current:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.28);
    outline: none;
}
.kh-lang-current:active {
    transform: scale(0.97);
}
.kh-lang-current .kh-flag {
    width: 18px;
    height: 12px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.kh-lang-caret {
    font-size: 9px;
    line-height: 1;
    margin-left: 1px;
    opacity: 0.85;
    transition: transform 0.2s ease;
}
.kh-lang-dropdown.kh-lang-open .kh-lang-caret {
    transform: rotate(180deg);
}

/* Menu panel (glass card) ----------------------------------- */
.kh-lang-menu {
    /* Animation defaults: hidden, ready to fade in. */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;

    position: absolute;
    top: calc(100% + 10px);
    right: 0;

    /* Glass surface. */
    background: rgba(15, 23, 42, 0.94);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    backdrop-filter: blur(20px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 8px !important;
    box-shadow:
        0 24px 60px -12px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(255, 255, 255, 0.03) inset;

    /* 2-column compact grid for desktop. */
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2px;
    width: 360px;
    max-height: min(80vh, 540px);
    overflow-y: auto;

    list-style: none !important;
    margin: 0 !important;
    z-index: 99999;
}
.kh-lang-dropdown.kh-lang-open .kh-lang-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Reset stale list/bullet styling that bleeds in from the
   site's existing global rules. */
.kh-lang-menu li {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
}
.kh-lang-menu li::before,
.kh-lang-menu li::marker {
    content: none !important;
    display: none !important;
}

/* Language item ---------------------------------------------- */
.kh-lang-menu a {
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    color: #e2e8f0 !important;
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.2;
    border-radius: 8px;
    transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
    white-space: nowrap;
}
.kh-lang-menu a:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff !important;
}
.kh-lang-menu a:active {
    transform: scale(0.98);
}
.kh-lang-menu a.kh-lang-active {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff !important;
    box-shadow: 0 4px 14px -2px rgba(59, 130, 246, 0.45);
}
.kh-lang-menu a.kh-lang-active:hover {
    background: linear-gradient(135deg, #4f8ff7 0%, #3b72ed 100%);
}
.kh-lang-menu a .kh-flag {
    width: 20px;
    height: 14px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}
.kh-lang-menu .kh-lang-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Custom scrollbar inside the dropdown ---------------------- */
.kh-lang-menu::-webkit-scrollbar {
    width: 6px;
}
.kh-lang-menu::-webkit-scrollbar-track {
    background: transparent;
}
.kh-lang-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
}
.kh-lang-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* RTL adjustments ------------------------------------------- */
html[dir="rtl"] .kh-lang-menu {
    right: auto;
    left: 0;
}
html[dir="rtl"] .kh-lang-current {
    flex-direction: row-reverse;
}
html[dir="rtl"] .kh-lang-menu a {
    flex-direction: row-reverse;
    text-align: right;
}

/* Mobile: single column, narrower ---------------------------- */
@media (max-width: 575px) {
    .kh-lang-menu {
        width: 240px;
        grid-template-columns: 1fr;
        right: -10px;
    }
    html[dir="rtl"] .kh-lang-menu {
        right: auto;
        left: -10px;
    }
}

/* Light-theme fallback for the dropdown ---------------------- */
@media (prefers-color-scheme: light) {
    /* Site defaults already use a dark topbar, so the dropdown
       intentionally stays dark for contrast against the topbar. */
}
