/* ── Navbar ── */
.site-navbar {
    position: sticky; top: 0; z-index: 100;
    height: var(--navbar-height);
    background: var(--navbar-bg);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--color-border);
    transition: background var(--transition-base);
}
.site-navbar .container {
    display: flex; align-items: center; height: 100%; gap: var(--space-md);
}

/* ── Brand ── */
.navbar-brand {
    display: flex; align-items: center; gap: var(--space-sm);
    color: var(--color-text); flex-shrink: 0; font-size: 0.82rem;
    font-weight: var(--font-weight-bold); letter-spacing: 0.02em;
}
.navbar-logo {
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    object-fit: contain; flex-shrink: 0; display: block;
}
.navbar-brand-text {
    display: flex; flex-direction: column; line-height: 1.2; min-height: 28px; justify-content: center;
}
.navbar-brand-name { font-size: 0.82rem; font-weight: var(--font-weight-bold); }
.navbar-brand-abbr { font-size: 0.6rem; color: var(--color-text-muted); letter-spacing: 0.06em; }

/* ── Links ── */
.navbar-links {
    display: flex; align-items: center; gap: 2px; list-style: none;
    flex: 1; justify-content: center;
}
.navbar-links > li { position: relative; }
.navbar-links a {
    display: flex; align-items: center; gap: 5px;
    padding: 6px 12px; border-radius: var(--radius-md);
    font-size: 0.8rem; font-weight: var(--font-weight-medium);
    color: var(--color-text-muted); transition: color var(--transition-fast);
    white-space: nowrap;
}
.navbar-links a svg { width: 14px; height: 14px; flex-shrink: 0; }
.navbar-links a:hover { color: var(--color-text); }
.navbar-links a.active { color: var(--color-accent); }

/* ── Dropdown ── */
.dropdown-arrow {
    width: 10px; height: 10px; margin-left: 1px;
    transition: transform var(--transition-fast);
}
.nav-dropdown {
    position: absolute; top: calc(100% + 4px); left: 50%;
    min-width: 200px; background: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border); border-radius: var(--radius-lg);
    padding: var(--space-xs); box-shadow: var(--shadow-lg);
    opacity: 0; visibility: hidden;
    transform: translateX(-50%) translateY(-4px);
    transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
    pointer-events: none;
}
.nav-dropdown::before {
    content: ''; position: absolute; top: -8px; left: 0; right: 0; height: 8px;
}
.navbar-links > li:hover > .nav-dropdown,
.navbar-links > li:focus-within > .nav-dropdown {
    opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); pointer-events: auto;
}
.navbar-links > li:hover .dropdown-arrow { transform: rotate(180deg); }
.nav-dropdown a {
    display: flex; align-items: center; gap: var(--space-sm);
    padding: 8px 12px; border-radius: var(--radius-md);
    font-size: 0.78rem; color: var(--color-text-secondary);
}
.nav-dropdown a:hover { color: var(--color-text); background: var(--color-surface-elevated); }
.nav-dropdown a svg { width: 14px; height: 14px; opacity: 0.5; }

/* ── Right side ── */
.navbar-right {
    display: flex; align-items: center; gap: var(--space-sm); flex-shrink: 0;
}
.navbar-controls { display: flex; align-items: center; gap: 2px; }
.navbar-ctrl-btn {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: var(--radius-sm);
    border: 1px solid transparent; color: var(--color-text-muted);
    transition: all var(--transition-fast); padding: 0;
}
.navbar-ctrl-btn:hover { color: var(--color-text); background: var(--color-surface-elevated); }
.navbar-ctrl-btn svg { width: 15px; height: 15px; }
.search-toggle-btn svg { width: 16px; height: 16px; }
.lang-toggle-btn {
    font-size: 0.68rem; font-weight: var(--font-weight-semibold);
    letter-spacing: 0.04em; font-family: var(--font-primary); width: 32px;
}

/* ── Theme menu ── */
.navbar-theme { position: relative; }
.navbar-theme-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0;
    min-width: 172px; background: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border); border-radius: var(--radius-lg);
    padding: var(--space-xs); box-shadow: var(--shadow-lg);
    opacity: 0; visibility: hidden; transform: translateY(-4px);
    transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
    pointer-events: none; z-index: 110;
}
.navbar-theme-dropdown.open {
    opacity: 1; visibility: visible; transform: translateY(0); pointer-events: auto;
}
.navbar-theme-dropdown button {
    display: flex; align-items: center; gap: var(--space-sm); width: 100%;
    padding: 8px 12px; border-radius: var(--radius-md);
    font-size: 0.78rem; color: var(--color-text-secondary); text-align: left;
}
.navbar-theme-dropdown button:hover {
    color: var(--color-text); background: var(--color-surface-elevated);
}
.navbar-theme-dropdown .theme-opt-icon {
    width: 15px; height: 15px; flex-shrink: 0; opacity: 0.7;
}
.navbar-theme-dropdown button span { flex: 1; }
.navbar-theme-dropdown .theme-check {
    width: 14px; height: 14px; flex-shrink: 0;
    color: var(--color-accent); opacity: 0;
}
.navbar-theme-dropdown button.active { color: var(--color-text); }
.navbar-theme-dropdown button.active .theme-opt-icon { opacity: 1; color: var(--color-accent); }
.navbar-theme-dropdown button.active .theme-check { opacity: 1; }

/* ── User menu ── */
.navbar-user { position: relative; }
.navbar-user-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 3px; border-radius: var(--radius-full);
    border: 1px solid transparent; cursor: pointer;
    transition: border-color var(--transition-fast);
}
.navbar-user-btn:hover { border-color: var(--color-border); }
.navbar-user-btn .avatar { width: 28px; height: 28px; }
.navbar-user-btn .avatar svg { width: 14px; height: 14px; }
.navbar-user-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0;
    min-width: 180px; background: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border); border-radius: var(--radius-lg);
    padding: var(--space-xs); box-shadow: var(--shadow-lg);
    opacity: 0; visibility: hidden; transform: translateY(-4px);
    transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
    pointer-events: none;
}
.navbar-user-dropdown::before {
    content: ''; position: absolute; top: -8px; left: 0; right: 0; height: 8px;
}
.navbar-user:hover .navbar-user-dropdown {
    opacity: 1; visibility: visible; transform: translateY(0); pointer-events: auto;
}
.navbar-user-dropdown a, .navbar-user-dropdown button {
    display: flex; align-items: center; gap: var(--space-sm); width: 100%;
    padding: 8px 12px; border-radius: var(--radius-md);
    font-size: 0.78rem; color: var(--color-text-secondary); text-align: left;
}
.navbar-user-dropdown a:hover, .navbar-user-dropdown button:hover {
    color: var(--color-text); background: var(--color-surface-elevated);
}
.navbar-user-dropdown svg { width: 14px; height: 14px; opacity: 0.5; flex-shrink: 0; }
.navbar-user-divider {
    height: 1px; background: var(--color-border); margin: var(--space-xs) 0;
}
.navbar-user-info {
    padding: 8px 12px; font-size: 0.72rem; color: var(--color-text-muted);
}
.navbar-user-info strong {
    display: block; color: var(--color-text); font-size: 0.78rem; margin-bottom: 1px;
}
.navbar-login-btn {
    display: flex; align-items: center; gap: 5px;
    padding: 5px 14px; border-radius: var(--radius-full);
    font-size: 0.78rem; font-weight: var(--font-weight-medium);
    color: var(--color-accent-text); background: var(--color-accent);
    transition: background var(--transition-fast);
}
.navbar-login-btn:hover { background: var(--color-accent-hover); }
.navbar-login-btn svg { width: 14px; height: 14px; }

/* ── Hamburger ── */
.navbar-hamburger {
    display: none; padding: 6px; color: var(--color-text);
}
.navbar-hamburger svg { width: 20px; height: 20px; }

/* ── Mobile ── */
@media (max-width: 768px) {
    .navbar-hamburger { display: flex; flex-shrink: 0; }
    /* The centered links are hidden on mobile; push the controls to the right
       so the hamburger never gets crowded off the edge. */
    .navbar-right { margin-left: auto; }
    .navbar-brand { min-width: 0; overflow: hidden; }
    .navbar-brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* Icon-only login on mobile to save room for the hamburger. */
    .navbar-login-btn { padding: 6px; }
    .navbar-login-btn span { display: none; }
    .navbar-login-btn svg { width: 16px; height: 16px; }
    /* ── Mobile menu: slide-in drawer with accordion categories ──
       Rebuilt independently of the desktop hover dropdown. Shown via a
       transform/opacity slide (not display:none) and expanded categories use a
       max-height accordion, so nothing depends on fragile display toggling.
       Item text uses the high-contrast --color-text so it is always legible. */
    .navbar-links {
        /* The navbar's backdrop-filter is the containing block for this fixed
           child, so height is pinned explicitly rather than via bottom:0. */
        position: fixed; top: var(--navbar-height); left: 0; right: 0; bottom: auto;
        height: calc(100vh - var(--navbar-height));
        height: calc(100dvh - var(--navbar-height));
        display: flex; flex-direction: column; align-items: stretch;
        justify-content: flex-start; gap: 4px;
        padding: var(--space-md) var(--space-lg) var(--space-2xl);
        background: var(--color-bg); border-top: 1px solid var(--color-border);
        overflow-y: auto; z-index: 90;
        transform: translateX(-100%); opacity: 0; visibility: hidden;
        transition: transform 0.26s ease, opacity 0.26s ease, visibility 0.26s ease;
    }
    .navbar-links.open { transform: none; opacity: 1; visibility: visible; }
    .navbar-links > li { width: 100%; }

    /* Level 1 — top-level rows, flush left, high contrast */
    .navbar-links > li > a {
        display: flex; align-items: center; gap: 8px; width: 100%;
        padding: 14px 12px; font-size: 1rem; justify-content: flex-start;
        color: var(--color-text); font-weight: var(--font-weight-medium);
        border-radius: var(--radius-md);
    }
    .navbar-links > li > a:hover,
    .navbar-links > li > a:active { background: var(--color-surface-elevated); }
    .navbar-links > li > a.active { color: var(--color-accent); }

    /* Category trigger — chevron pushed right, rotates when open */
    .nav-dropdown-trigger { cursor: pointer; }
    .nav-dropdown-trigger .dropdown-arrow {
        width: 16px; height: 16px; margin-left: auto;
        transition: none;   /* instant, so it always matches the .open state */
    }
    /* On touch, hover "sticks" after a tap; the desktop rule rotates the arrow
       on hover, so it stayed up after collapsing. Let ONLY .open drive it. */
    .navbar-links > li:hover .dropdown-arrow { transform: none; }
    .navbar-links > li.open > .nav-dropdown-trigger { color: var(--color-accent); }
    .navbar-links > li.open > .nav-dropdown-trigger .dropdown-arrow { transform: rotate(180deg); }

    /* Accordion submenu — max-height reveal, deeper indent (Level 2) */
    /* Collapsed with display:none, expanded with display:flex — a reliable
       toggle (an animated max-height transition gets stuck at 0 in this
       flex + overflow:hidden layout on Chromium, hiding the items). */
    .nav-dropdown {
        position: static; transform: none; box-shadow: none; border: none;
        background: transparent; min-width: 0; pointer-events: auto;
        opacity: 1; visibility: visible; padding: 0;
        display: none; flex-direction: column; overflow: visible;
    }
    .nav-dropdown::before { display: none; }
    .navbar-links > li.open > .nav-dropdown { display: flex; }
    /* Neutralise the desktop hover/focus-within dropdown positioning, which
       otherwise shifts the submenu off-screen (translateX(-50%)) once the
       category trigger gains focus. */
    .navbar-links > li:hover > .nav-dropdown,
    .navbar-links > li:focus-within > .nav-dropdown {
        transform: none; opacity: 1; visibility: visible;
    }
    .nav-dropdown a {
        display: flex; align-items: center; gap: 10px;
        padding: 12px 12px 12px 34px; font-size: 0.92rem;
        color: var(--color-text); border-radius: var(--radius-md);
    }
    .nav-dropdown a:hover, .nav-dropdown a:active { background: var(--color-surface-elevated); }
    .nav-dropdown a svg { width: 15px; height: 15px; opacity: 0.6; }
}
