/*
 * Desktop navbar: centered category menu with hover dropdowns.
 *
 * Layout: a three-column grid with two symmetric side columns, so the
 * menu in the middle column is always exactly centered in the header
 * regardless of the logo width, the user menu width or the (translated)
 * label widths. The row is fixed to the navbar height so oversized
 * children (the logo) never push content below the bar.
 *
 * Categories: Home · Vulnerabilities ▾ · Monitoring ▾ · Resources ▾ · Pricing
 * Below 968px the menu becomes the slide-out drawer (style.css) and the
 * dropdown groups are rendered inline as indented lists.
 */
:root {
    --nav-side-width: 260px;
    --nav-dropdown-bg: rgba(16, 16, 22, 0.94);
    --nav-dropdown-border: rgba(255, 255, 255, 0.09);

    /* Shared menu-item states for the navbar dropdowns (nav, language,
       profile). Light values live in theme-light.css. */
    --menu-item-text: var(--text-secondary);
    --menu-item-hover-bg: rgba(255, 255, 255, 0.07);
    --menu-item-hover-text: var(--text-primary);
    --menu-item-active-bg: rgba(99, 102, 241, 0.12);
    --menu-item-danger: var(--severity-critical, #ef4444);
    --menu-item-disabled-opacity: 0.45;
    --menu-focus-ring: var(--primary-500);
}

/* Logo: a fixed box instead of the raw image size. */
.logo a {
    display: flex;
    align-items: center;
    height: 100%;
}

.logo-image {
    display: block;
    height: 46px;
    width: auto;
    max-width: 180px;
    object-fit: contain;
}

.logo-light { display: none; }
[data-theme="light"] .logo-dark { display: none; }
[data-theme="light"] .logo-light { display: block; }

@media (min-width: 969px) {
    .navbar {
        display: grid;
        grid-template-columns:
            minmax(var(--nav-side-width), 1fr)
            minmax(0, max-content)
            minmax(var(--nav-side-width), 1fr);
        grid-template-rows: minmax(0, 1fr);
        align-items: center;
        column-gap: var(--spacing-md);
        height: 64px;
        padding: 0;
    }

    .navbar .logo {
        grid-column: 1;
        justify-self: start;
        height: 100%;
    }

    .navbar .mobile-menu-toggle {
        display: none !important;
    }

    .navbar .nav-menu {
        grid-column: 2;
        justify-self: center;
        display: flex;
        align-items: center;
        gap: 0.25rem;
        min-width: 0;
        flex-wrap: nowrap;
        height: 100%;
    }

    .navbar .nav-actions {
        grid-column: 3;
        justify-self: end;
        width: auto;
    }

    .nav-item {
        position: relative;
        display: flex;
        align-items: center;
        height: 100%;
    }

    .nav-menu .nav-link {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        padding: 0.5rem 0.85rem;
        font-size: 0.9375rem;
        font-weight: var(--fw-medium);
        white-space: nowrap;
        border-radius: var(--radius-md);
        overflow: visible;
    }

    .nav-chevron {
        flex: 0 0 auto;
        opacity: 0.6;
        transition: transform var(--transition-base), opacity var(--transition-base);
    }

    .nav-item-has-menu:hover > .nav-link .nav-chevron,
    .nav-item-has-menu:focus-within > .nav-link .nav-chevron {
        transform: rotate(180deg);
        opacity: 1;
    }

    /* Dropdown panel ------------------------------------------------- */
    .nav-dropdown {
        position: absolute;
        /* Overlaps the bottom of the full-height list item, so the pointer can
           move from the link straight into the panel without a gap. */
        top: calc(100% - 4px);
        left: 50%;
        min-width: 300px;
        padding: 0.5rem;
        display: flex;
        flex-direction: column;
        gap: 2px;
        background: var(--nav-dropdown-bg);
        -webkit-backdrop-filter: blur(24px) saturate(160%);
        backdrop-filter: blur(24px) saturate(160%);
        border: 1px solid var(--nav-dropdown-border);
        border-radius: var(--radius-lg);
        box-shadow:
            0 24px 60px rgba(0, 0, 0, 0.55),
            0 0 0 1px rgba(99, 102, 241, 0.08),
            inset 0 1px 0 rgba(255, 255, 255, 0.05);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translate(-50%, 10px) scale(0.98);
        transform-origin: top center;
        transition:
            opacity 180ms ease,
            transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
            visibility 0s linear 180ms;
        z-index: var(--z-dropdown, 1000);
    }

    /* Small caret pointing at the parent item. */
    .nav-dropdown::after {
        content: "";
        position: absolute;
        top: -6px;
        left: 50%;
        width: 10px;
        height: 10px;
        margin-left: -5px;
        background: var(--nav-dropdown-bg);
        border-left: 1px solid var(--nav-dropdown-border);
        border-top: 1px solid var(--nav-dropdown-border);
        transform: rotate(45deg);
    }

    .nav-item-has-menu:hover > .nav-dropdown,
    .nav-item-has-menu:focus-within > .nav-dropdown {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transform: translate(-50%, 0) scale(1);
        transition-delay: 0s;
    }

    .nav-dropdown-link {
        display: flex;
        align-items: center;
        gap: 0.8rem;
        padding: 0.6rem 0.7rem;
        border-radius: calc(var(--radius-lg) - 0.4rem);
        color: var(--menu-item-text);
        text-decoration: none;
        transition: background var(--transition-base), color var(--transition-base);
    }

    .nav-dropdown-link:hover,
    .nav-dropdown-link:focus-visible {
        background: var(--menu-item-hover-bg);
        color: var(--menu-item-hover-text);
        outline: none;
    }

    .nav-dropdown-link:focus-visible {
        outline: 2px solid var(--menu-focus-ring);
        outline-offset: -2px;
    }

    .nav-dropdown-link.active {
        background: var(--menu-item-active-bg);
        color: var(--menu-item-hover-text);
    }

    .nav-dropdown-link[aria-disabled="true"] {
        opacity: var(--menu-item-disabled-opacity);
        cursor: not-allowed;
        pointer-events: none;
    }

    .nav-dropdown-icon {
        flex: 0 0 38px;
        width: 38px;
        height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.06);
        color: var(--primary-400);
        transition: background var(--transition-base), color var(--transition-base), transform var(--transition-base);
    }

    .nav-dropdown-icon svg {
        width: 19px;
        height: 19px;
    }

    .nav-dropdown-link:hover .nav-dropdown-icon,
    .nav-dropdown-link.active .nav-dropdown-icon {
        background: linear-gradient(135deg, var(--primary-500), var(--accent-purple));
        border-color: transparent;
        color: #fff;
        transform: translateY(-1px);
    }

    .nav-dropdown-text {
        display: flex;
        flex-direction: column;
        gap: 2px;
        min-width: 0;
    }

    .nav-dropdown-title {
        font-size: 0.9rem;
        font-weight: var(--fw-semibold);
        color: inherit;
        line-height: 1.2;
    }

    .nav-dropdown-desc {
        font-size: 0.76rem;
        color: var(--text-muted);
        line-height: 1.35;
        white-space: nowrap;
    }

    .nav-dropdown-link:hover .nav-dropdown-desc,
    .nav-dropdown-link.active .nav-dropdown-desc {
        color: var(--text-secondary);
    }

    @media (prefers-reduced-motion: reduce) {
        .nav-dropdown,
        .nav-chevron,
        .nav-dropdown-icon {
            transition: none;
        }
    }
}

/* Narrow desktops (969-1199px): avatar only, so the side columns can
   shrink while the menu stays centered. The dropdown still opens on hover
   of the avatar. */
@media (min-width: 969px) and (max-width: 1199px) {
    :root {
        --nav-side-width: 190px;
    }

    .user-menu .user-name,
    .user-menu .user-tier {
        display: none;
    }
}

/* Drawer (<= 968px): dropdown groups become indented inline lists. */
@media (max-width: 968px) {
    /* A closed off-canvas drawer must not enlarge the page or remain focusable. */
    .navbar .nav-menu:not(.active) {
        display: none;
    }

    /* The drawer is a fixed-height flex column; without this the list items
       shrink and clip their (now taller) grouped content. */
    .nav-menu > li {
        flex: 0 0 auto;
    }

    .nav-menu .nav-link .nav-chevron {
        display: none;
    }

    .nav-dropdown {
        display: flex;
        flex-direction: column;
        padding: 0 0 0.5rem;
        background: rgba(255, 255, 255, 0.02);
    }

    .nav-dropdown-link {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.7rem 1.75rem 0.7rem 2.25rem;
        color: var(--text-secondary);
        font-size: 0.9rem;
        text-decoration: none;
    }

    .nav-dropdown-link:hover,
    .nav-dropdown-link.active {
        color: var(--menu-item-hover-text);
        background: var(--menu-item-active-bg);
    }

    .nav-dropdown-icon {
        flex: 0 0 auto;
        display: inline-flex;
        width: 20px;
        height: 20px;
        color: var(--primary-400);
    }

    .nav-dropdown-icon svg {
        width: 18px;
        height: 18px;
    }

    .nav-dropdown-desc {
        display: none;
    }

    .nav-dropdown-title {
        font-weight: var(--fw-medium);
    }

    /* Keep the three navbar controls visible on mobile. */
    .navbar .nav-actions {
        display: flex !important;
        align-items: center;
        gap: 6px;
    }

    .navbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* While the drawer is open, the close button moves into the space its
       header reserves on the right; in the navbar it covered the drawer logo. */
    .navbar .mobile-menu-toggle.active {
        position: fixed;
        top: 10px;
        right: 12px;
    }

    /* 100vh includes the area behind Safari's toolbar on iOS, which hid
       the last drawer items; dvh is the visible height. */
    @supports (height: 100dvh) {
        .navbar .nav-menu {
            height: 100dvh;
        }
    }
}
