.header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(186, 230, 253, 0.6);
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.06);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: box-shadow 0.3s ease;
}

.header.scrolled {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

.header-container {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 40px;
    height: 64px;
    gap: 1rem;
}

.nav {
    display: flex;
    justify-content: center;
    align-items: center;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.025em;
    flex-shrink: 0;
    transition: filter 0.3s ease;
}

.logo:hover {
    filter: drop-shadow(0 0 8px rgba(14, 165, 233, 0.4));
}

.logo-accent {
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    font-weight: 800;
    font-size: 36px;
    letter-spacing: 1px;
}

.logo img {
    height: 40px;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 4px;
    margin: 0;
    padding: 0;
    align-items: center;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--primary-color);
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.nav-link {
    position: relative;
    color: #475569;
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.3px;
    padding: 7px 16px;
    border-radius: 999px;
    transition: color 0.2s ease, background 0.2s ease;
}

.nav-link::after {
    display: none;
}

.nav-link:hover {
    color: #0284c7;
    background: #f0f9ff;
}

.nav-link.active {
    color: #0284c7;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.12), rgba(99, 102, 241, 0.12));
}

.nav-link-admin {
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    color: #fff !important;
    border-radius: 999px;
    padding: 6px 16px !important;
    font-size: 13px !important;
    font-weight: 600;
    letter-spacing: 0.3px;
    transition: filter 0.2s ease;
    padding-bottom: 6px;
}

.nav-link-admin:hover {
    filter: brightness(1.1);
    color: #fff !important;
}

.nav-link-admin::after {
    display: none;
}

.nav-link-admin.active::after {
    display: none;
}

.lang-switcher {
    position: relative;
}

.lang-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lang-toggle {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 999px;
    padding: 4px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 13px;
    font-weight: 500;
    color: #0284c7;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.lang-toggle:hover {
    background: #e0f2fe;
    border-color: #7dd3fc;
    color: #0284c7;
}

.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: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    list-style: none;
    margin: 0;
    padding: 0.3rem 0;
    min-width: 130px;
    z-index: 1000;
}

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

.lang-dropdown li a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

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

/* On mobile, drop the 12px backdrop blur on the sticky header. A live Gaussian
   blur of the content behind a sticky/fixed element runs on the GPU every
   single frame during scroll — on low/mid-range phones this is the single
   biggest source of scroll jank on the page. Swapping to an opaque background
   removes the per-frame blur cost entirely, and on a phone-sized screen the
   visual difference is imperceptible. Dark-mode override below matches. */
@media (max-width: 768px) {
    .header {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: #ffffff;
    }
    [data-theme="dark"] .header {
        background: #0f172a;
    }
}

/* ── Mobile / tablet hamburger menu (≤ 1024 px) ──────────────────────────── */
@media (max-width: 1024px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
    }

    .header-container {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        padding: 0 1rem;
        min-height: 64px;
        height: auto;
        position: relative;
        gap: 0;
    }

    /* Logo left, controls + hamburger right */
    .logo {
        flex: 0 0 auto;
        font-size: 1.5rem;
    }

    .logo-accent {
        font-size: 28px;
    }

    .nav {
        order: 10;
        flex: 0 0 100%;
        justify-content: flex-start;
    }

    .nav-controls {
        margin-left: auto;
        margin-right: 0.5rem;
        flex: 0 0 auto;
    }

    .mobile-menu-btn {
        flex: 0 0 auto;
    }

    /* Nav links dropdown */
    .nav-links {
        display: none;
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        width: 100%;
        background: rgba(255, 255, 255, 0.97);
        border-top: 1px solid rgba(186, 230, 253, 0.6);
        padding: 0.5rem 0;
        margin-top: 0.25rem;
    }

    .nav-links.open {
        display: flex;
    }

    .nav-links li {
        width: 100%;
    }

    .nav-links li a {
        display: block;
        padding: 0.75rem 1.25rem;
        min-height: 44px;
        box-sizing: border-box;
        color: #475569;
        font-size: 15px;
        border-radius: 0;
        background: transparent;
        border-left: 3px solid transparent;
    }

    .nav-links li a:hover {
        background: #f0f9ff;
        color: #0284c7;
        border-left-color: rgba(6, 182, 212, 0.4);
    }

    .nav-links li a.active {
        background: #f0f9ff;
        color: #0284c7;
        border-left-color: #06b6d4;
    }

    .nav-link-admin {
        background: none;
        color: #0284c7 !important;
        border-radius: 0;
        padding: 0.75rem 1.25rem !important;
        min-height: 44px !important;
        box-sizing: border-box !important;
        font-size: 15px !important;
        filter: none;
        border-left: 3px solid transparent;
    }

    .nav-link-admin:hover {
        filter: none;
        background: #f0f9ff !important;
    }

    .nav-link::after,
    .nav-link.active::after {
        display: none;
    }

    /* Lang dropdown — opens below the controls bar */
    .lang-dropdown {
        position: absolute !important;
        right: 0 !important;
        left: auto !important;
        top: calc(100% + 6px) !important;
        width: auto !important;
        min-width: 160px !important;
        max-width: 200px !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
        border: 1px solid #e2e8f0;
        border-radius: 8px !important;
        padding: 4px !important;
        background: #fff;
        z-index: 200;
    }

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

    .lang-dropdown li {
        width: auto !important;
    }

    .lang-dropdown li a {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        padding: 10px 16px !important;
        border-radius: 6px !important;
        font-size: 14px;
        white-space: nowrap;
        min-width: 150px !important;
        min-height: 44px !important;
        box-sizing: border-box !important;
    }

    .lang-dropdown li a:hover {
        background: #e0f2fe;
        color: #0284c7;
    }

    /* RTL: mirror border side for mobile menu items */
    [dir="rtl"] .nav-links li a {
        border-left: none;
        border-right: 3px solid transparent;
    }

    [dir="rtl"] .nav-links li a:hover {
        border-right-color: rgba(6, 182, 212, 0.4);
    }

    [dir="rtl"] .nav-links li a.active {
        border-right-color: #06b6d4;
    }

    [dir="rtl"] .nav-link-admin {
        border-left: none;
        border-right: 3px solid transparent;
    }

    [dir="rtl"] .lang-dropdown {
        right: auto !important;
        left: 0 !important;
    }
}

[dir="rtl"] .nav-link::after {
    left: auto;
    right: 0;
    background: linear-gradient(to left, #06b6d4, #3b82f6);
}

[dir="rtl"] .lang-dropdown {
    right: auto;
    left: 0;
}

@media (min-width: 1440px) {
    .header-container {
        max-width: 1380px;
    }
}

@media (min-width: 1920px) {
    .header-container {
        max-width: 1700px;
    }
}

@media (min-width: 2560px) {
    .header-container {
        max-width: 2200px;
    }
}

/* ── Dark mode toggle button ─────────────────────────────────────────────── */
.theme-toggle-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.theme-toggle-track {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 54px;
    height: 28px;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    border-radius: 999px;
    padding: 0 7px;
    box-sizing: border-box;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.theme-icon-sun,
.theme-icon-moon {
    font-size: 0.7rem;
    z-index: 1;
    transition: color 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}

.theme-icon-sun {
    color: #f59e0b;
}

.theme-icon-moon {
    color: #94a3b8;
    opacity: 0.5;
}

.theme-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease;
    pointer-events: none;
}

/* ── Dark mode overrides ─────────────────────────────────────────────────── */
/* CSS-only fallback: system dark preference before JS sets data-theme */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .header {
        background: rgba(15, 23, 42, 0.97);
        border-bottom-color: #1e293b;
    }

    :root:not([data-theme="light"]) .nav-link {
        color: #94a3b8;
    }

    :root:not([data-theme="light"]) .nav-link:hover {
        color: #60a5fa;
        background: rgba(255, 255, 255, 0.05);
    }

    :root:not([data-theme="light"]) .nav-link.active {
        color: #60a5fa;
        background: linear-gradient(135deg, rgba(6, 182, 212, 0.12), rgba(99, 102, 241, 0.12));
    }

    :root:not([data-theme="light"]) .lang-toggle {
        background: #1e293b;
        border-color: #334155;
        color: #60a5fa;
    }

    :root:not([data-theme="light"]) .lang-dropdown {
        background: #1e293b;
        border-color: #334155;
    }

    :root:not([data-theme="light"]) .lang-dropdown li a {
        color: #e2e8f0;
    }

    :root:not([data-theme="light"]) .theme-toggle-track {
        background: #1e293b;
        border-color: #334155;
    }

    :root:not([data-theme="light"]) .theme-icon-sun {
        color: #94a3b8;
        opacity: 0.5;
    }

    :root:not([data-theme="light"]) .theme-icon-moon {
        color: #fbbf24;
        opacity: 1;
    }

    :root:not([data-theme="light"]) .theme-toggle-thumb {
        transform: translateX(26px);
        background: #334155;
    }

    @media (max-width: 1024px) {
        :root:not([data-theme="light"]) .nav-links {
            background: rgba(15, 23, 42, 0.97);
            border-top-color: #334155;
        }

        :root:not([data-theme="light"]) .nav-links li a {
            color: #94a3b8;
        }

        :root:not([data-theme="light"]) .lang-dropdown {
            background: #1e293b;
            border-color: #334155;
        }
    }
}

[data-theme="dark"] .header {
    background: rgba(15, 23, 42, 0.97);
    border-bottom-color: #1e293b;
}

[data-theme="dark"] .nav-link {
    color: #94a3b8;
}

[data-theme="dark"] .nav-link:hover {
    color: #60a5fa;
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .nav-link.active {
    color: #60a5fa;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.12), rgba(99, 102, 241, 0.12));
}

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

[data-theme="dark"] .lang-toggle:hover {
    background: #334155;
    border-color: #475569;
    color: #60a5fa;
}

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

[data-theme="dark"] .lang-dropdown li a {
    color: #e2e8f0;
}

[data-theme="dark"] .lang-dropdown li a:hover {
    background: #334155;
    color: #60a5fa;
}

[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;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

@media (max-width: 1024px) {
    [data-theme="dark"] .nav-links {
        background: rgba(15, 23, 42, 0.97);
        border-top-color: #334155;
    }

    [data-theme="dark"] .nav-links li a {
        color: #94a3b8;
    }

    [data-theme="dark"] .nav-links li a:hover {
        background: #1e293b;
        color: #60a5fa;
    }

    [data-theme="dark"] .nav-link-admin:hover {
        background: #1e293b !important;
    }

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

    [data-theme="dark"] .lang-dropdown li a:hover {
        background: #334155;
        color: #60a5fa;
    }
}