@use 'variables' as *;

.navbar {
    background-color: $red-primary;
    box-shadow: 0 2px 8px rgb(from var(--red-primary) r g b / 0.1);
    // White rule so the navbar and the pinned table header (also red) read
    // as two separate bands when the page is scrolled and they touch.
    border-bottom: 3px solid $white;
    position: sticky;
    top: 0;
    z-index: $z-navbar;
    margin: 0 -16px 24px;
}

.navbar-inner {
    max-width: $max-width;
    margin: 0 auto;
    padding: 0 16px;
}

.navbar-top {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 8px 0;
}

.navbar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    justify-self: start;
}

.navbar-brand-stacked {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.navbar-logo {
    height: 68px;
    width: 68px;
    object-fit: contain;
    border-radius: 50%;
    background: $white;
    padding: 6px;
}

.navbar-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: $white;
    letter-spacing: 0.02em;
    text-decoration: none;
    white-space: nowrap;
    padding-bottom: 6px;

    &:hover {
        color: rgb(from var(--white) r g b / 0.85);
    }
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-self: end;
}

.navbar-logo-right {
    height: 60px;
    width: auto;
    object-fit: contain;
    border-radius: 8px;
    background: $white;
    padding: 4px;
}

// ─── Hamburger toggle (hidden on desktop) ─────────────────────────────────────
.navbar-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;

    &__bar {
        display: block;
        width: 26px;
        height: 2px;
        background: $white;
        border-radius: 2px;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    &[aria-expanded="true"] {
        .navbar-toggle__bar:nth-child(1) {
            transform: translateY(7px) rotate(45deg);
        }

        .navbar-toggle__bar:nth-child(2) {
            opacity: 0;
        }

        .navbar-toggle__bar:nth-child(3) {
            transform: translateY(-7px) rotate(-45deg);
        }
    }
}

// ─── Site nav ─────────────────────────────────────────────────────────────────
.site-nav {
    display: flex;
    align-items: stretch;

    &__list {
        display: flex;
        align-items: stretch;
        list-style: none;
        gap: 0;
    }

    &__item {
        position: relative;
        display: flex;
        align-items: stretch;
    }

    &__link {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 0 18px;
        color: rgb(from var(--white) r g b / 0.92);
        font-size: 0.95rem;
        font-weight: 600;
        letter-spacing: 0.01em;
        text-decoration: none;
        background: transparent;
        border: none;
        cursor: pointer;
        white-space: nowrap;
        transition: background 0.15s, color 0.15s;

        &:hover,
        &--parent:hover {
            background: rgba(0, 0, 0, 0.18);
            color: $white;
        }
    }

    &__item--has-dropdown:hover>.site-nav__link--parent {
        background: rgba(0, 0, 0, 0.18);
        color: $white;
    }

    // Chevron icon
    &__chevron {
        width: 14px;
        height: 14px;
        transition: transform 0.2s ease;
        flex-shrink: 0;
    }

    &__item--has-dropdown {

        &:hover .site-nav__chevron,
        &:focus-within .site-nav__chevron {
            transform: rotate(180deg);
        }

        &:hover .site-nav__dropdown,
        &:focus-within .site-nav__dropdown {
            display: block;
        }
    }

    // Dropdown panel
    &__dropdown {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        min-width: 220px;
        list-style: none;
        background: $navy;
        border-top: 3px solid $red-primary;
        border-radius: 0 0 8px 8px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
        z-index: $z-dropdown;
        padding: 6px 0;
    }

    &__dropdown-item {
        border-bottom: 1px solid rgb(from var(--white) r g b / 0.06);

        &:last-child {
            border-bottom: none;
        }
    }

    &__dropdown-link {
        display: block;
        padding: 10px 20px;
        color: rgb(from var(--white) r g b / 0.85);
        font-size: 0.9rem;
        font-weight: 500;
        text-decoration: none;
        transition: background 0.15s, color 0.15s;

        &:hover {
            background: rgb(from var(--red-primary) r g b / 0.25);
            color: $white;
        }
    }
}

// ─── Responsive ───────────────────────────────────────────────────────────────
@media (max-width: $bp-tablet) {
    .navbar-toggle {
        display: flex;
        align-self: center;
    }

    .navbar-logo {
        height: 56px;
        width: 56px;
    }

    .navbar-logo-right {
        height: 44px;
    }

    .navbar-title {
        font-size: 1.1rem;
        white-space: normal;
        padding-bottom: 4px;
    }

    .site-nav {
        display: none;
        border-top: 1px solid rgb(from var(--white) r g b / 0.15);
        margin-top: 4px;

        &.is-open {
            display: flex;
        }

        &__list {
            flex-direction: column;
            align-items: stretch;
            padding-bottom: 8px;
        }

        &__item {
            align-items: stretch;
            flex-direction: column;
        }

        &__link {
            padding: 13px 16px;
            justify-content: space-between;
        }

        &__dropdown {
            position: static;
            box-shadow: none;
            border-radius: 0;
            border-top: none;
            border-left: 3px solid rgb(from var(--white) r g b / 0.4);
            margin-left: 16px;
            padding: 4px 0;
            background: transparent;
        }

        &__item--has-dropdown {

            &:hover .site-nav__dropdown,
            &:focus-within .site-nav__dropdown {
                display: none;
            }
        }
    }
}
