/* ============================================================
   KBH navigation — custom responsive nav.
   Desktop: horizontal bar with animated underline + hover dropdowns.
   Mobile (<900px): off-canvas drawer with backdrop + accordion submenus.
   Icons come from the inline SVG sprite (assets/icons/icons.svg).
   ============================================================ */

.kbh-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 1rem;
    min-width: 0;
}
.kbh-brand {
    flex-shrink: 0;
}
.kbh-brand a {
    text-decoration: none;
}

/* Header logo (core/site-logo). Sized in CSS so the SVG matches the wordmark
   height exactly and stays pixel-identical regardless of the block's width. */
.kbh-brand .kbh-logo {
    margin: 0;
    line-height: 0;
}
.kbh-brand .kbh-logo img {
    height: 60px;
    width: auto;
    display: block;
}

.kbh-icon {
    width: 24px;
    height: 24px;
    display: block;
}

/* Reset for the icon buttons */
.kbh-burger,
.kbh-drawer-close,
.kbh-sub-toggle {
    appearance: none;
    background: none;
    border: 0;
    margin: 0;
    cursor: pointer;
    color: var(--wp--preset--color--koningsblauw);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.kbh-burger:focus-visible,
.kbh-drawer-close:focus-visible,
.kbh-sub-toggle:focus-visible,
.kbh-menu a:focus-visible {
    outline: 2px solid var(--wp--preset--color--koningsblauw);
    outline-offset: 3px;
}

/* The menu list */
.kbh-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}
.kbh-menu a {
    text-decoration: none;
    color: var(--wp--preset--color--koningsblauw);
}

/* Sticky-header drop shadow — nav.js adds .is-stuck once the page is scrolled. */
@media (min-width: 900px) {
    .kbh-header-wrap.is-stuck {
        box-shadow: 0 6px 18px rgba(15, 20, 45, 0.1);
    }
}
@media (min-width: 900px) and (prefers-reduced-motion: no-preference) {
    .kbh-header-wrap {
        transition: box-shadow 0.25s ease;
    }
}

/* ---------- DESKTOP (>= 900px) ---------- */
@media (min-width: 900px) {
    .kbh-burger,
    .kbh-drawer-head,
    .kbh-drawer-backdrop {
        display: none !important;
    }

    .kbh-nav {
        display: block;
    }

    /* two-row header: brand on top, menu centered below */
    .kbh-header-inner {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
    }

    /* keep the wordmark on one line next to the logo */
    .kbh-brand .wp-block-site-title,
    .kbh-brand .wp-block-site-title a {
        white-space: nowrap;
    }

    .kbh-menu {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-wrap: wrap;
        gap: 1.75rem;
    }
    .kbh-menu > li {
        position: relative;
        display: flex;
        align-items: center;
    }

    .kbh-menu > li > a {
        position: relative;
        font-weight: 700;
        padding: 0.35rem 0;
        line-height: 1.2;
        white-space: nowrap;
    }
    /* animated underline sweep */
    .kbh-menu > li > a::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: -4px;
        height: 2px;
        background: var(--wp--preset--color--venetiaans-rood);
        transform: scaleX(0);
        transform-origin: left;
        transition: transform 0.25s ease;
    }
    .kbh-menu > li > a:hover::after,
    .kbh-menu > li > a:focus-visible::after {
        transform: scaleX(1);
    }
    .kbh-menu > li > a[aria-current="page"]::after {
        transform: scaleX(1);
        background: var(--wp--preset--color--koningsblauw);
    }

    /* submenu parent chevron (decorative on desktop) */
    .kbh-sub-toggle {
        padding: 0 0 0 0.15rem;
        pointer-events: none;
    }
    .kbh-sub-toggle .kbh-icon {
        width: 18px;
        height: 18px;
        transition: transform 0.25s ease;
    }
    .has-sub:hover .kbh-sub-toggle .kbh-icon,
    .has-sub:focus-within .kbh-sub-toggle .kbh-icon {
        transform: rotate(180deg);
    }

    /* dropdown */
    .kbh-submenu {
        position: absolute;
        top: 100%;
        left: -0.5rem;
        min-width: 230px;
        margin: 0;
        padding: 0.3rem 0;
        list-style: none;
        background: var(--wp--preset--color--wit);
        border: 1px solid var(--wp--preset--color--zilvergrijs);
        box-shadow: 0 12px 28px rgba(35, 56, 142, 0.14);
        opacity: 0;
        visibility: hidden;
        transform: translateY(8px);
        transition:
            opacity 0.2s ease,
            transform 0.2s ease,
            visibility 0.2s;
        z-index: 200;
    }
    .has-sub:hover > .kbh-submenu,
    .has-sub:focus-within > .kbh-submenu {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
    .kbh-submenu a {
        display: block;
        padding: 0.6rem 1.1rem;
        font-weight: 400;
        white-space: nowrap;
        transition:
            background-color 0.15s ease,
            color 0.15s ease;
    }
    .kbh-submenu a:hover,
    .kbh-submenu a:focus-visible {
        background: rgba(35, 56, 142, 0.06);
        color: var(--wp--preset--color--venetiaans-rood);
    }
}

/* ---------- MOBILE (< 900px) ---------- */
@media (max-width: 480px) {
    /* mobile: show a compact "KBH" wordmark instead of the full name */
    .kbh-brand .wp-block-site-title a {
        font-size: 0;
        line-height: 0;
    }
    .kbh-brand .wp-block-site-title a::after {
        content: "KBH";
        font-size: 1.4rem;
        line-height: 1.1;
        letter-spacing: 0.02em;
    }
}
@media (max-width: 899.98px) {
    .kbh-burger {
        padding: 0.35rem;
    }
    .kbh-burger .kbh-icon {
        width: 30px;
        height: 30px;
    }

    /* off-canvas drawer */
    .kbh-nav {
        position: fixed;
        top: 0;
        right: 0;
        height: 100dvh;
        width: min(87vw, 360px);
        background: var(--wp--preset--color--wit);
        box-shadow: -10px 0 40px rgba(15, 20, 45, 0.22);
        transform: translateX(100%);
        transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        overscroll-behavior: contain;
        z-index: 1000;
    }
    .kbh-nav.is-open {
        transform: translateX(0);
    }

    .kbh-drawer-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 20, 45, 0.5);
        opacity: 0;
        transition: opacity 0.32s ease;
        z-index: 999;
    }
    .kbh-drawer-backdrop.is-visible {
        opacity: 1;
    }

    .kbh-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1.1rem 1.25rem;
        border-bottom: 1px solid var(--wp--preset--color--zilvergrijs);
        position: sticky;
        top: 0;
        background: var(--wp--preset--color--wit);
    }
    .kbh-drawer-title {
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.14em;
        font-size: 0.8rem;
        color: var(--wp--preset--color--koningsblauw);
    }
    .kbh-drawer-close {
        padding: 0.25rem;
    }
    .kbh-drawer-close .kbh-icon {
        width: 28px;
        height: 28px;
    }

    .kbh-menu {
        display: flex;
        flex-direction: column;
        padding: 0.25rem 0 1.5rem;
    }
    .kbh-menu > li {
        border-bottom: 1px solid #eef0f5;
    }

    .kbh-menu > li > a {
        display: block;
        padding: 1rem 1.4rem;
        font-size: 1.12rem;
        font-weight: 700;
    }
    .kbh-menu a[aria-current="page"] {
        box-shadow: inset 4px 0 0 var(--wp--preset--color--venetiaans-rood);
    }

    /* rows with a submenu: link + chevron toggle on one line */
    .has-sub {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
    }
    .has-sub > a {
        grid-column: 1;
    }
    .kbh-sub-toggle {
        grid-column: 2;
        padding: 1rem 1.25rem;
        align-self: stretch;
    }
    .kbh-sub-toggle .kbh-icon {
        transition: transform 0.25s ease;
    }
    .has-sub.is-open .kbh-sub-toggle .kbh-icon {
        transform: rotate(180deg);
    }

    /* accordion submenu */
    .kbh-submenu {
        grid-column: 1 / -1;
        list-style: none;
        margin: 0;
        padding: 0;
        background: #f5f6fa;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.32s ease;
    }
    .has-sub.is-open .kbh-submenu {
        max-height: 60vh;
    }
    .kbh-submenu a {
        display: block;
        padding: 0.85rem 1.4rem 0.85rem 2.2rem;
        font-size: 1.02rem;
        font-weight: 400;
    }
    .kbh-submenu li + li a {
        border-top: 1px solid #e6e9f2;
    }
}

/* tighten the bar on the tablet band so 6 items never overflow */
@media (min-width: 900px) and (max-width: 1120px) {
    .kbh-menu {
        gap: 1.1rem;
    }
    .kbh-menu > li > a {
        font-size: 0.94rem;
    }
}

/* lock page scroll while the drawer is open */
html.kbh-menu-open {
    overflow: hidden;
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .kbh-nav,
    .kbh-drawer-backdrop,
    .kbh-submenu,
    .kbh-menu > li > a::after,
    .kbh-sub-toggle .kbh-icon {
        transition: none !important;
    }
}
