/* ============================================================
   Language Switcher — Kipchumba Foundation
   Responsive, accessible, RTL-aware.
   Loaded by includes/header.php after the site stylesheet so it
   can override layout direction with [dir="rtl"].
   ============================================================ */

.kf-lang {
    position: relative;
    display: inline-block;
    font-family: inherit;
    --kf-accent: #b8860b;        /* brand gold */
    --kf-bg:     #ffffff;
    --kf-fg:     #1a1a1a;
    --kf-muted:  #6b7280;
    --kf-border: #e5e7eb;
    --kf-hover:  #f9fafb;
}

/* ---- Trigger button ----------------------------------------- */
.kf-lang__trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.7rem;
    background: var(--kf-bg);
    color: var(--kf-fg);
    border: 1px solid var(--kf-border);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.kf-lang__trigger:hover { border-color: var(--kf-accent); }
.kf-lang__trigger:focus-visible {
    outline: 2px solid var(--kf-accent);
    outline-offset: 2px;
}
.kf-lang__trigger[aria-expanded="true"] {
    border-color: var(--kf-accent);
    box-shadow: 0 0 0 3px rgba(184,134,11,.12);
}
.kf-lang__globe  { font-size: 1rem; line-height: 1; }
.kf-lang__current {
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
.kf-lang__caret {
    font-size: 0.7rem;
    color: var(--kf-muted);
    transition: transform .15s ease;
}
.kf-lang__trigger[aria-expanded="true"] .kf-lang__caret {
    transform: rotate(180deg);
}

/* ---- Dropdown panel ----------------------------------------- */
.kf-lang__panel {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;            /* LTR: anchor right; RTL flips via [dir=rtl] */
    z-index: 1000;
    width: min(22rem, 92vw);
    max-height: min(28rem, 70vh);
    display: flex;
    flex-direction: column;
    background: var(--kf-bg);
    color: var(--kf-fg);
    border: 1px solid var(--kf-border);
    border-radius: 0.75rem;
    box-shadow: 0 12px 32px rgba(0,0,0,.14);
    overflow: hidden;
}
[dir="rtl"] .kf-lang__panel { right: auto; left: 0; }
.kf-lang__panel[hidden] { display: none; }

/* ---- Search ------------------------------------------------- */
.kf-lang__search {
    padding: 0.6rem 0.7rem;
    border-bottom: 1px solid var(--kf-border);
    background: #fafafa;
    flex-shrink: 0;
}
.kf-lang__search-input {
    width: 100%;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--kf-border);
    border-radius: 0.5rem;
    font-size: 0.85rem;
    background: #fff;
}
.kf-lang__search-input:focus-visible {
    outline: 2px solid var(--kf-accent);
    outline-offset: 1px;
}

/* ---- Scrollable list ---------------------------------------- */
.kf-lang__group { padding: 0.4rem 0; }
.kf-lang__group + .kf-lang__group { border-top: 1px solid var(--kf-border); }

.kf-lang__group-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.3rem 0.85rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--kf-muted);
}
.kf-lang__count {
    font-size: 0.65rem;
    background: var(--kf-border);
    color: var(--kf-fg);
    border-radius: 999px;
    padding: 0 0.4rem;
}

.kf-lang__opts {
    max-height: 14rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.kf-lang__opts:focus-within { outline: none; }

/* ---- Each option -------------------------------------------- */
.kf-lang__opt {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.85rem;
    text-decoration: none;
    color: var(--kf-fg);
    font-size: 0.875rem;
    line-height: 1.3;
    cursor: pointer;
    transition: background .1s ease;
}
.kf-lang__opt:hover,
.kf-lang__opt:focus-visible { background: var(--kf-hover); }
.kf-lang__opt:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--kf-accent); }

.kf-lang__opt.is-current {
    background: rgba(184,134,11,.08);
    color: var(--kf-accent);
    font-weight: 600;
}

/* pending (non-clickable) */
.kf-lang__opt.is-pending {
    cursor: not-allowed;
    color: var(--kf-muted);
    opacity: 0.65;
}
.kf-lang__opt.is-pending:hover { background: transparent; }

.kf-lang__native {
    flex: 0 0 auto;
    min-width: 4.5rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kf-lang__en {
    flex: 1 1 auto;
    color: var(--kf-muted);
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kf-lang__opt.is-current .kf-lang__en { color: var(--kf-accent); opacity: 0.85; }

.kf-lang__badge {
    flex: 0 0 auto;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #f3f4f6;
    color: var(--kf-muted);
    border-radius: 0.25rem;
    padding: 0.1rem 0.35rem;
}

/* ---- Footer ------------------------------------------------- */
.kf-lang__footer {
    padding: 0.5rem 0.85rem;
    border-top: 1px solid var(--kf-border);
    background: #fafafa;
    flex-shrink: 0;
}
.kf-lang__total {
    font-size: 0.7rem;
    color: var(--kf-muted);
    display: block;
}

/* ---- Empty state (search no match) -------------------------- */
.kf-lang__panel[data-empty="true"] .kf-lang__group { display: none; }
.kf-lang__panel[data-empty="true"] .kf-lang__footer::before {
    content: "No language matches your search.";
    display: block;
    font-size: 0.8rem;
    color: var(--kf-fg);
    margin-bottom: 0.35rem;
}

/* ---- Mobile: full-width sheet ------------------------------- */
@media (max-width: 640px) {
    .kf-lang__panel {
        right: -0.5rem;
        left: -0.5rem;
        width: auto;
        max-height: 80vh;
    }
    .kf-lang__current { max-width: 5rem; }
}

/* ---- RTL specifics (mirrors glyphs + alignment) -------------- */
[dir="rtl"] .kf-lang__trigger { flex-direction: row-reverse; }
[dir="rtl"] .kf-lang__caret   { transform: rotate(0deg); }
[dir="rtl"] .kf-lang__trigger[aria-expanded="true"] .kf-lang__caret {
    transform: rotate(180deg);
}

/* Respect reduced motion -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .kf-lang *, .kf-lang *::before, .kf-lang *::after {
        transition: none !important;
        animation: none !important;
    }
}

/* ============================================================
   Kipchumba site theme (dark) + language-bar placement
   ============================================================ */
.kf-lang {
    --kf-accent: var(--accent, #c4a24e);
    --kf-bg:     var(--bg-card, #15151c);
    --kf-fg:     var(--text-primary, #eaeaed);
    --kf-muted:  var(--text-secondary, #9898a2);
    --kf-border: var(--border-hover, rgba(255,255,255,0.14));
    --kf-hover:  var(--bg-card-hover, #1a1a23);
}
.kf-lang__trigger { background: transparent; font-size: 12px; padding: 4px 10px; }
.kf-lang__trigger[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--accent-dim, rgba(196,162,78,.12)); }
.kf-lang__panel   { box-shadow: 0 16px 40px rgba(0,0,0,.55); text-align: start; }
.kf-lang__search,
.kf-lang__footer  { background: var(--bg-raised, #0f0f14); }
.kf-lang__search-input { background: var(--bg-input, #12121a); color: var(--kf-fg); }
.kf-lang__search-input::placeholder { color: var(--text-muted, #5c5c66); }
.kf-lang__opts    { max-height: min(22rem, 55vh); }
.kf-lang__opt.is-current { background: var(--accent-dim, rgba(196,162,78,.12)); }
.kf-lang__badge   { background: var(--bg-raised, #0f0f14); }

/* The language bar now holds a single dropdown, aligned to the end edge */
.lang-bar.has-dropdown { overflow: visible; position: relative; z-index: 1100; }
.lang-bar.has-dropdown .lang-bar-inner { justify-content: flex-end; align-items: center; }

/* Phones: let the panel span the bar instead of the narrow trigger */
@media (max-width: 640px) {
    .lang-bar.has-dropdown .kf-lang { position: static; }
    .lang-bar.has-dropdown .kf-lang__panel { left: 0.5rem; right: 0.5rem; width: auto; }
    .lang-bar.has-dropdown .lang-bar-inner { justify-content: flex-end; }
}

/* Author Portal compact bar */
.ap-lang-switch .kf-lang__trigger { color: #e2e8f0; }
