/* ==============================
    BASE NAVIGATION (UNCHANGED)
============================== */
.main-nav {    
    font-size: 1.4rem;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.main-nav a {
    text-decoration: none;
    color: #333;
    font-weight: 500;
    margin: 0 2px 0 10px; /* top right bottom left  */
    padding: 0 0 6px 0;  /* top right bottom left  */
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.main-nav a:hover { 
	color: #0078e7; 
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 2.0rem;
    cursor: pointer;
    margin-left: 2px;
}

.submenu-toggle {
    background: none;
    border: none;
    padding: 0;
    margin-left: 0px;
    cursor: pointer;
    color: inherit;
    display: inline-flex;
    align-items: center;
}

/* ==============================
    L1 (TOP LEVEL)
============================== */
.menu-item-l1 { 
	position: relative; 
}

/* LEVEL 2 (submenu) */
.menu-items-l2 {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    border: 1px solid #ccc;
    min-width: 180px;
    flex-direction: column;
    z-index: 9998;
}

/* ==============================
   LEVEL 2 ITEMS 
============================== */
.menu-item-l2 {
    position: relative;
    display: block;
}

/* LEVEL 3 (flyout submenu) */
.menu-items-l3 {
    display: none;
    position: fixed;  /* CHANGE 1: Set to fixed so JS can move it outside the L2 scroll box */
    background: #fff;
    border: 1px solid #ccc;
    min-width: 180px;
    flex-direction: column;
    z-index: 9999;
}

/* DESKTOP */ 
@media (min-width: 769px) {
    .main-nav i { display: flex; }

    .menu-item-l2 > .submenu-toggle i {
      transform: rotate(270deg);
      transition: transform 0.3s;
    }

   
    .menu-item-l1:hover > .menu-items-l2 {
        display: block; /* Changed from flex to block */
    }
    
    /*
    .menu-item-l2:hover > .menu-items-l3 { 
      	display: flex; 
    }
    */
    
    
	/* CHANGE 2: Added the scroll to L2 */
    .menu-items-l2 {
        max-height: calc(100vh - 200px);
        overflow-y: auto;   /* This creates the scrollbar */
        overflow-x: hidden; /* Prevents horizontal shifting */
        
        /* Force block behavior for scrolling */
        display: none; 
        flex-direction: unset; 
    }
    
}

/* TABLET (UNCHANGED EXCEPT position:static !important) */ 
@media (max-width: 768px) {

    .main-nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
    }
    
    .main-nav a { 
		padding: 6px 0;  /* top/bottom and left/right padding */
	}

    #navMenu { 
		display: none; 
	}  

    #navMenu.open {
        display: block;    
        border: 1px solid #ccc;
        max-height: calc(100vh - 120px); /* adjust header height */
        overflow-y: auto; 
        -webkit-overflow-scrolling: touch;
    }

    .menu-item-l1 { 
		width: 100%; 
	}
    
    .main-nav i { 
		display: inline-flex; 
	}

    .menu-items-l2,
    .menu-items-l3 { 
        position: static !important;  /* Added !important to override the fixed positioning used for desktop JS */
        border: none;
        background: none;
        padding-left: 20px;
        display: none;
    }

    .menu-item-l2 > a,
    .menu-items-l3 a { 
		padding: 8px 0; /* top/bottom and left/right padding */
	}

    .menu-item-l1.open > .menu-items-l2,  
    .menu-item-l2.open > .menu-items-l3 {
        display: flex;
    }

    .menu-item-l1.open > .submenu-toggle i,
    .menu-item-l2.open > .submenu-toggle i {
        transform: rotate(180deg);
        transition: transform 0.3s;
    }

	/* show hamburger */
    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* PHONE (UNCHANGED) */
@media (max-width: 480px) {

    .menu-toggle { 
		font-size: 1.4rem; 
	}
    
}
