.header {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    align-self: stretch;
    box-sizing: border-box;
    background: var(--page);
    padding-top: 0.7rem;
    padding-bottom: 0.5rem;
    overflow-x: clip;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.header.scrolled {
    background: var(--paper);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}

.header-container {
    width: var(--wrap);
    margin: 0 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: 1rem;
    direction: ltr;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    color: var(--navy);
    font-weight: 700;
    font-size: 1.7rem;
    letter-spacing: -0.03em;
    overflow: visible;
    /* Brand lockup is Latin + a left-side chip. Keep it LTR in Arabic so it
       is not mirrored or re-anchored by the page dir. */
    direction: ltr;
    unicode-bidi: isolate;
    justify-self: start;
}

.logo:hover { color: var(--blue); }

.logo-lockup {
    display: block;
    direction: ltr;
    unicode-bidi: isolate;
    height: 3.15rem;
    line-height: 0;
}

.logo-art {
    display: block;
    height: 100%;
    width: auto;
    overflow: visible;
    direction: ltr;
    unicode-bidi: isolate;
    writing-mode: horizontal-tb;
    transform: none;
}

.logo-traces { opacity: 0.72; }

.logo-word {
    font-family: Inter, Arial, sans-serif;
    letter-spacing: 0;
}

.logo img { height: 44px; width: auto; }

.header .logo-lockup {
    height: 4.75rem;
}

.header .logo img { height: 76px; }

.nav {
    display: contents;
}

.nav-links {
    list-style: none;
    display: flex;
    align-items: center;
    justify-self: center;
    gap: 1.4rem;
    margin: 0;
    padding: 0;
}

@media (min-width: 1281px) {
    .nav-links {
        transform: translateY(-0.45rem);
    }
}

.nav-link {
    color: var(--ink);
    font-size: 1.02rem;
    font-weight: 500;
    padding: 0.7em 0;
    border-bottom: 4px solid transparent;
}

.nav-link:hover,
.nav-link.active {
    color: var(--navy-deep);
    border-bottom-color: var(--navy-deep);
}

.nav-link-admin {
    color: var(--blue);
    font-weight: 600;
}

.nav-controls {
    display: flex;
    align-items: center;
    justify-self: end;
    gap: 0.5rem;
    position: relative;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.35rem;
    cursor: pointer;
    color: var(--navy);
    min-width: 44px;
    min-height: 44px;
}

.lang-switcher { position: relative; }

.lang-toggle {
    background: var(--paper);
    border: 1px solid var(--border-color);
    border-radius: 25px;
    padding: 5px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 13px;
    font-weight: 600;
    color: var(--navy);
}

.lang-toggle:hover { border-color: var(--blue); }

.lang-chevron { font-size: 0.65rem; transition: transform 0.2s; }
.lang-switcher.open .lang-chevron { transform: rotate(180deg); }

.lang-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 0 0 8px 8px;
    list-style: none;
    margin: 0;
    padding: 0.3rem 0;
    min-width: 140px;
    z-index: 1000;
}

.lang-switcher.open .lang-dropdown { display: block; }

.lang-dropdown li a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--ink);
    font-size: 0.9rem;
}

.lang-dropdown li a:hover {
    background: var(--blue);
    color: #fff;
}

.theme-toggle-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.theme-toggle-track {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 54px;
    height: 28px;
    background: #dce8f5;
    border: 1px solid #b7c9de;
    border-radius: 999px;
    padding: 0 7px;
    box-sizing: border-box;
}

.theme-icon-sun { color: #f59e0b; font-size: 0.7rem; z-index: 1; }
.theme-icon-moon { color: #94a3b8; font-size: 0.7rem; z-index: 1; opacity: 0.5; }

.theme-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

[data-theme="dark"] .theme-toggle-track {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .theme-icon-sun { color: #94a3b8; opacity: 0.5; }
[data-theme="dark"] .theme-icon-moon { color: #fbbf24; opacity: 1; }
[data-theme="dark"] .theme-toggle-thumb {
    transform: translateX(26px);
    background: #334155;
}

[dir="rtl"] .logo,
[dir="rtl"] .logo-lockup,
[dir="rtl"] .logo-art,
[dir="rtl"] .logo img {
    direction: ltr;
    unicode-bidi: isolate;
    transform: none;
}

[dir="rtl"] .nav-links {
    direction: rtl;
}

@media (max-width: 1440px) and (min-width: 1281px) {
    .nav-links { gap: 0.85rem; }
    .nav-link { font-size: 0.92rem; }
}

@media (max-width: 1280px) {
    .header {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding-inline: 0;
    }
    .header-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding-inline: max(0.5rem, env(safe-area-inset-left, 0px)) max(0.5rem, env(safe-area-inset-right, 0px));
        box-sizing: border-box;
        min-width: 0;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 0.5rem;
        row-gap: 0;
    }
    .logo {
        min-width: 0;
        max-width: 100%;
    }
    .header .logo-lockup {
        height: 3.4rem;
        max-width: 100%;
    }
    .header .logo img {
        height: 54px;
        max-width: 100%;
    }
    .logo-art {
        max-width: 100%;
    }
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        justify-self: end;
    }
    .nav {
        display: none;
        grid-column: 1 / -1;
        margin-inline-start: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        background: var(--paper);
        border-top: 1px solid var(--line);
        padding: 0.35rem 0 0.85rem;
    }
    .nav.open { display: flex; }
    .nav-links {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        width: 100%;
        padding: 0;
        transform: none;
    }
    .nav-links li a {
        display: block;
        padding: 0.65rem 0.25rem;
        min-height: 44px;
        border-bottom: 0;
        box-sizing: border-box;
    }
    .nav-link:hover,
    .nav-link.active {
        border-bottom: 0;
        color: var(--blue);
    }
    .nav-controls {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.75rem;
        margin-top: 0.35rem;
        padding: 0.75rem 0.25rem 0.15rem;
        border-top: 1px solid var(--line);
    }
    .nav.open .lang-dropdown {
        position: static;
        flex: 1 0 100%;
        right: auto;
        left: auto;
        min-width: 0;
        width: 100%;
        margin-top: 0.15rem;
        border-radius: 8px;
        box-shadow: none;
    }
    [dir="rtl"] .nav-links,
    [dir="rtl"] .nav-controls {
        direction: rtl;
    }
}
