/*
 * ============================================================
 *  header.css - Header & Navigation
 * ============================================================
 *
 *  Load order:  bootstrap.min.css -> theme-{name}.css -> main.css -> THIS FILE
 *
 *  Contains no raw brand values. Nav tokens below are derived from
 *  tokens main.css and the theme file supply.
 *
 *  Covers:
 *    Nav tokens
 *    Desktop navigation & submenus
 *    App Nav & Rail for CRM-style needs
 *    Mega-menu
 *    Mobile offcanvas menu
 *    Mobile submenu toggles
 * ============================================================
 */


/* ============================================================
   NAV TOKENS
   ============================================================ */

/*
 * Declared under :root, [data-bs-theme] for the same reason as the
 * main.css derivation block: a token declared only on :root resolves
 * once against html and inherits as a fixed value, so nav accents
 * inside a nested [data-bs-theme] scope would keep the outer mode's
 * brand colour. Do not collapse this back to a bare :root.
 *
 * --sub-nav-bg is the one token that genuinely differs by mode
 * (body-bg on light, tertiary-bg on dark), so it keeps an override.
 */
:root,
[data-bs-theme] {
    --menu-link-color:          var(--bs-body-color);
    --menu-link-color-hover:    var(--theme);
    --collapse-link-color:      var(--theme);
    --sub-nav-border-radius:    var(--bs-border-radius-lg);
    --sub-nav-bg:               var(--bs-body-bg);
    --sub-nav-border:           var(--bs-border-color);
    --sub-nav-shadow:           var(--bs-box-shadow-lg);

    --menu-toggle-size:         40px;
    --menu-size-desktop:        0.9rem;
    --menu-size-mobile:         1.0rem;
}

[data-bs-theme="dark"] {
    --sub-nav-bg:               var(--bs-tertiary-bg);
}

/* ============================================================
   LOGO THEME SWAP
   ============================================================ */

/*
 * Two <img> tags, one shown per mode. Correct on first paint because
 * data-bs-theme is set by the head script before body renders, so there
 * is no flash of the wrong logo the way a JS src swap produces.
 * Mark the hidden one aria-hidden="true" in markup.
 */
[data-bs-theme="light"] .site-logo-dark  { display: none; }
[data-bs-theme="dark"]  .site-logo-light { display: none; }


/* ============================================================
   DESKTOP NAVIGATION
   ============================================================ */

.navbar { transition: all .3s ease; }

.navbar .nav-item    { height: 100%; }
.navbar .has-subnav  { position: relative; }
.navbar .nav-item .nav-link { font-size: var(--menu-size-desktop); }
.navbar .nav-item .nav-link:hover { color: var(--menu-link-color-hover); }
.navbar .nav-item .nav-link.active { color: var(--theme); }

/*
 * Dropdown submenu — hidden by default, revealed on parent hover.
 * Uses visibility + opacity for smooth CSS transition
 * (display:none can't transition).
 */
.navbar .sub-menu {
    position: absolute;
    z-index: 1000;
    padding: 0;
    margin-top: 10px;
    list-style: none;
    text-align: left;
    background: var(--sub-nav-bg);
    border-radius: var(--sub-nav-border-radius);
    box-shadow: var(--sub-nav-shadow);
    border: 1px solid var(--sub-nav-border);
    box-sizing: border-box;
    visibility: hidden;
    opacity: 0;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-in, margin 0.3s ease-out;
}

/* Align submenu to right edge of parent */
.navbar .sub-menu.sub-menu-right { right: 0; }
.navbar .sub-menu li { display: block; padding: 0 0.25rem; }
.navbar .sub-menu a { white-space: nowrap; }

.navbar .sub-menu.sub-menu-center {
    left: 50%;
    transform: translateX(-50%);
    right: auto;
}

/* Consistent menu links with optional icons */
.navbar .menu-link {
    display: flex;
    align-items: center;
    padding-left: 0 !important;
}

.navbar .menu-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 1.35rem;
    width: 1.35rem;
    margin-right: 0.55rem;
}

/* Slide in on parent hover */
.navbar li:hover > .sub-menu {
    margin-top: 0;
    visibility: visible;
    opacity: 1;
}

/* Nested submenu — offset to the right */
.navbar .sub-menu .sub-menu {
    top: 0;
    left: 100%;
    margin-top: 0;
    margin-left: 0.25rem;
    transition-property: none;
}

.navbar .sub-menu li:hover > .sub-menu { visibility: visible; opacity: 1; }

/* ============================================================
   APP NAV & RAIL 
   ============================================================ */
/* Vertical nav list */
.app-nav {
    display: flex;
    flex-direction: column;
}
.app-nav .nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--bs-secondary-color);
    font-family: var(--bs-body-font-family);
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.app-nav .nav-link:before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 100%;
    background: var(--theme);
    transition: width 0.2s ease;
}
.app-nav .nav-link:hover {
    color: var(--theme);
    background-color: var(--bs-secondary-bg);
}
.app-nav .nav-link.active {
    color: var(--bs-body-color);
    background-color: var(--bs-secondary-bg);
}
.app-nav .nav-link:hover:before,
.app-nav .nav-link.active:before {
    width: 3px;
}   
.app-rail-link {
    display: flex;
    align-items: center;
    flex-direction: row;
    justify-content: flex-start;
    text-align: left;
    padding: 0.5rem 0.75rem !important;
}
@media (min-width: 992px) {
    .app-rail-wrap { flex: 0 0; }
    .app-rail-link {
        flex-direction: column;
        justify-content: center;
        text-align: center;
        font-size: 0.67rem;
        font-weight: 600;
        padding: 0.75rem !important;
    }
    .app-rail-link span {font-size: 1.25rem;}
}

/* ============================================================
   MEGA MENU
   ============================================================ */

/*
 * Mega-menu uses the normal submenu contract:
 * - top-level list has .sub-menu.mega-menu
 * - each category is li.has-subnav
 * - each category child list is still .sub-menu
 * - assumes 3 column mega menu
 */
.navbar .sub-menu.mega-menu {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto auto;
    gap: 0.5rem 1.5rem;
    min-width: 720px;
    padding: 0.75rem;
    list-style: none;
}

/* Mega category columns */
.navbar .sub-menu.mega-menu > li { padding: 0; }
.navbar .sub-menu.mega-menu > li > a {
    display: block;
    white-space: nowrap;
}

/*
 * PER-PROJECT GRID PLACEMENT
 * ---------------------------------------------------------------
 * The only project-specific rules in this file. They assume a
 * 4-item mega menu where items 1 and 2 stack in column 1 and
 * items 3 and 4 each span both rows.
 *
 * If a project's mega menu has a different shape, override these
 * in that project's own stylesheet (renderSection('css')) rather
 * than editing this shared file. Reset with:
 *     .navbar .sub-menu.mega-menu > li { grid-column: auto; grid-row: auto; }
 * then re-place as needed.
 */
.navbar .sub-menu.mega-menu > li:nth-child(1) { grid-column: 1; grid-row: 1; }
.navbar .sub-menu.mega-menu > li:nth-child(2) { grid-column: 1; grid-row: 2; }
.navbar .sub-menu.mega-menu > li:nth-child(3) { grid-column: 2; grid-row: 1 / span 2; }
.navbar .sub-menu.mega-menu > li:nth-child(4) { grid-column: 3; grid-row: 1 / span 2; }

/*
 * Prevent mega child lists from behaving like desktop flyout menus.
 * They remain .sub-menu for JS/mobile compatibility,
 * but desktop mega layout treats them as visible column lists.
 */
.navbar li:hover > .sub-menu.mega-menu > li > .sub-menu {
    position: static;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    opacity: 1;
    visibility: visible;
    background: transparent;
    list-style: none;
    transform: none;
}


/* ============================================================
   MOBILE OFFCANVAS MENU
   ============================================================
   Breakpoint matches navbar-expand-lg (991px).
   Update if you change the navbar breakpoint:
     sm: 575px | md: 767px | lg: 991px | xl: 1199px | xxl: 1399px
   ============================================================ */

@media (max-width: 991px) {

    /*
     * Offcanvas panel — slides in from the right.
     * Uses transform rather than left/right for GPU compositing.
     */
    .offcanvas-collapse {
        position: fixed;
        z-index: 1001;
        top: 0;
        bottom: 0;
        left: 100%;
        width: 400px;
        max-width: 100%;
        padding: 0.5rem 1rem;
        overflow-y: auto;
        visibility: hidden;
        background-color: var(--sub-nav-bg);
        transition: transform .3s ease-in-out, visibility .3s ease-in-out;
    }

    .offcanvas-collapse.open {
        visibility: visible;
        transform: translateX(-100%);
    }

    /* ── Nav links ── */
    .navbar .dropdown-toggle:after { display: none; }
    .app-toggler,
    .navbar .navbar-toggler:focus { box-shadow: none; }

    .navbar .navbar-collapse a { margin: 0 !important; }

    /* ── Hamburger toggler ── */
    .app-toggler,
    .navbar .navbar-toggler {
        line-height: 1;
        color: var(--bs-navbar-color);
        background-color: transparent;        
        padding: 0;
        border: 0;
        font-size: 1.5rem;
        outline: 0;
    }

    /* Scrim overlay behind open menu */
    .navbar .navbar-toggler.open:before {
        content: "";
        position: fixed;
        z-index: -1;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 1;
        transition: opacity .2s ease-in-out;
    }

    .navbar .navbar-toggler:before { width: 0; opacity: 0; }


/* ============================================================
   MOBILE SUBMENU TOGGLES
   ============================================================ */

    /*
     * Submenus collapse to max-height: 0 by default.
     * JS adds .active to expand — max-height transition
     * creates the accordion effect.
     */
    .navbar li .sub-menu {
        overflow: hidden;
        margin-top: 0 !important;
        opacity: 1;
        display: block;
        visibility: visible;
        max-height: 0;
        width: 100%;
        padding-left: 0;
    }

    .navbar .sub-menu li { padding-left: 0; padding-right: 0; }
    .navbar .sub-menu li .sub-menu { left: 0 !important; margin-left: 0; }

    .navbar .nav-item .nav-link { font-size: var(--menu-size-mobile); }

    .navbar li .sub-menu.active {
        max-height: 120rem;
        position: relative;
        box-shadow: none;
        transition: max-height 1s ease-in-out;
    }

    .navbar li .sub-menu:not(.active) {
        position: relative;
        box-shadow: none;
        max-height: 0;
        transition: max-height 0.5s ease-out;
    }

    .navbar .sub-menu { border: none; }

    .navbar .sub-menu a {
        padding-left: 0.8em !important;
        padding-right: 2.25rem !important;
    }

    .navbar .sub-menu .sub-menu a {
        padding-left: 1.6em !important;
    }

    /*
     * Toggle icon — plus/minus indicator on right edge of nav item.
     */
    .navbar .has-subnav .toggle-link {
        display: flex;
        justify-content: center;
        align-items: center;
        position: absolute;
        top: 0;
        right: 0;
        width: var(--menu-toggle-size);
        height: var(--menu-toggle-size);
        cursor: pointer;
        z-index: 1001;
    }

    .navbar .has-subnav .toggle-link:before,
    .navbar .has-subnav .toggle-link:after {
        content: "";
        position: absolute;
        width: 18px;
        height: 2px;
        top: 50%;
        background: var(--collapse-link-color);
        transform: translateY(-50%) rotate(0);
        transition: transform 0.5s ease;
    }

    /* Vertical bar hidden when submenu is open (.active added by JS) */
    .navbar .has-subnav .toggle-link:not(.active):after {
        transform: translateY(-50%) rotate(270deg);
    }

    /* ── Mobile mega menu ── */
    .navbar .sub-menu.mega-menu {
        display: block;
        min-width: unset;
        padding: 0;
    }

    /*
     * Re-enable normal mobile accordion behavior for mega child lists.
     * This overrides the desktop mega rule that makes child lists visible.
     */
    .navbar .sub-menu.mega-menu > li > .sub-menu {
        position: relative;
        overflow: hidden;
        margin-top: 0 !important;
        opacity: 1;
        display: block;
        visibility: visible;
        max-height: 0;
        width: 100%;
        padding-left: 0;
        background: transparent;
    }

    .navbar .sub-menu.mega-menu > li > .sub-menu.active {
        max-height: 120rem;
        box-shadow: none;
        transition: max-height 1s ease-in-out;
    }

    .navbar .sub-menu.mega-menu > li > .sub-menu:not(.active) {
        max-height: 0;
        box-shadow: none;
        transition: max-height 0.5s ease-out;
    }

} /* end @media (max-width: 991px) */