  

    * {
        box-sizing: border-box;
    }

    body {
        margin: 0;
        overflow-x: hidden;

    }

    .header {
        position: relative;
        z-index: 100;
        border-bottom: 1px solid rgb(238, 233, 233);
    }

    .menu {
        display: flex;
        justify-content: flex-start;
        padding: 0px;
        margin-right :20px;
    }
    

   .menu-item , .menu-item-has {
        position: relative;
    }

 .menu-item a, .menu-item-has a {
    text-decoration: none;
    color: #212121;
    margin-left: 30px;
}

    .menu-item a {
        margin-left: 30px;
    }

 .mega-menu{
    position: fixed;
    direction: rtl;
    top: 200px;
    left: 50%;
    transform: translateX(-50%);
     z-index: 10000;
    width: 99%;
    height: calc(100vh - 150px);

    background: #FFF3F3;
    border-radius: 25px;

    padding: 10px;

    display: flex;
    gap: 5px;
    flex-direction: row;

    opacity: 0;
    visibility: hidden;

    transition: opacity .2s ease, visibility .2s ease;
}

.mega-menu.active{
    opacity: 1;
    visibility: visible;
}

/* SIDEBAR */
.mega-sidebar{
    width: 17%;
    height: 100%;

    background: #fff;
    border-radius: 25px;

    padding: 20px;

    flex-shrink: 0;
}

/* =========================
   LEVEL 2 (SIDEBAR PANEL)
========================= */



/* =========================
   LEVEL 2 LIST
========================= */

.mega-menu-list{
    list-style: none;
    margin: 0;
    padding: 0;

    display: flex;
    flex-direction: column;
    gap: 15px;

    text-align: right;
}

.mega-menu-list li a{
    display: block;
    position: relative;

    text-decoration: none;
    color: #333;

    font-size: 15px;
    font-weight: 500;

    padding: 10px 15px;
    border-radius: 12px;

    transition: color .2s ease;
}

/* خط قرمز */
.mega-menu-list li a::after{
    content: "";
    position: absolute;

    right: -18px;
    top: 25%;

    width: 2px;
    height: 50%;

    background: #F12E31;
    border-radius: 10px;

    opacity: 0;
    transition: opacity .2s ease;
}

/* ACTIVE LEVEL 2 */
.mega-menu-list li a.active{
    color: #F12E31;
}

.mega-menu-list li a.active::after{
    opacity: 1;
}

/* hover fallback */
.mega-menu-list li a:hover{
    color: #F12E31;
}

.mega-menu-list li a:hover::after{
    opacity: 1;
}

/* =========================
   LEVEL 3 WRAPPER (FIX مهم)
========================= */





/* =========================
   LEVEL 3 LIST (FIXED BUG HERE)
========================= */

.content-list{
    list-style: none;
    margin: 0;
    padding: 0;

    display: none;              /* 🔥 مهم: کل لیست پیش‌فرض مخفی */
    flex-direction: column;
    gap: 15px;

    text-align: right;
}

/* فقط لیست فعال نمایش داده شود */
.content-box.active .content-list{
    display: flex;
}

/* آیتم‌های لول 3 */
.content-list li a{
    display: block;
    position: relative;

    text-decoration: none;
    color: #333;

    font-size: 15px;
    font-weight: 500;

    padding: 10px 15px;
    border-radius: 12px;

    transition: color .2s ease;
}

/* خط قرمز لول 3 */
.content-list li a::after{
    content: "";
    position: absolute;

    right: -18px;
    top: 25%;

    width: 2px;
    height: 50%;

    background: #F12E31;
    border-radius: 10px;

    opacity: 0;
    transition: opacity .2s ease;
}

/* ACTIVE LEVEL 3 */
.content-list li a.active{
    color: #F12E31;
}

.content-list li a.active::after{
    opacity: 1;
}

/* hover fallback */
.content-list li a:hover{
    color: #F12E31;
}

.content-list li a:hover::after{
    opacity: 1;
}


/* وقتی آیتم فعال شد */




/* LEVEL 2 */
.mega-sidebar{ width:14%; }

/* LEVEL 3 */
.mega-submenu{
    width:13%;
    background:#fff;
    border-radius:25px;
    padding:20px;

    opacity:0;
    visibility:hidden;
}

.mega-submenu.active{
    opacity:1;
    visibility:visible;
}

/* LEVEL 4 */
.mega-subsubmenu{
    width:17%;
    background:#fff;
    border-radius:25px;
    padding:20px;

    opacity:0;
    visibility:hidden;
}

.mega-subsubmenu.active{
    opacity:1;
    visibility:visible;
}

    /* lists */
    .content-list,
    .content-list-4{
        display:none;
        flex-direction:column;
        gap:12px;
    }

    .content-list.active,
    .content-list-4.active{
        display:flex;
    }


    .content-list-4{
        list-style: none;
        margin: 0;
        padding: 0;

        
        flex-direction: column;
        gap: 15px;

        text-align: right;
    }




.content-list-4 li a{
    display: block;
    position: relative;

    text-decoration: none;
    color: #333;

    font-size: 15px;
    font-weight: 500;

    padding: 10px 12px;
    border-radius: 12px;

    transition: color .2s ease;
}

/* خط قرمز لول 4 */
.content-list-4 li a::after{
    content: "";
    position: absolute;

    right: -18px;
    top: 25%;

    width: 2px;
    height: 50%;

    background: #F12E31;
    border-radius: 10px;

    opacity: 0;
    transition: opacity .2s ease;
}

.content-list-4 li a.active{
    color: #F12E31;
}

.content-list-4 li a.active::after{
    opacity: 1;
}

.content-list-4 li a:hover{
    color: #F12E31;
}

.content-list-4 li a:hover::after{
    opacity: 1;
}


.mega-gallery {
    width: 100%;
    height: 100%;
    background: #fff;
    border-radius: 25px;
    padding: 20px;
    margin: 0;
    box-sizing: border-box;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition: opacity .2s ease;

    position: absolute;   /* 🔥 مهم */
    top: 0;
    left: 0;
}



.mega-gallery.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;

  
    flex-direction: column;
}

.gallery-inner {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 15px;

    overflow-y: auto;
    overflow-x: hidden;

    min-height: 0;

    /* مهم برای جلوگیری از overflow در mega menu */
    max-height: 100%;
}

.gallery-item {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    background: #f5f5f5;

   
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* پیشنهاد بهتر از contain */
    display: block;
}

/* hide scrollbar (optional) */
.gallery-inner::-webkit-scrollbar{
    width: 6px;
}

.gallery-inner::-webkit-scrollbar-thumb{
    background: #ddd;
    border-radius: 10px;
}


/* =========================
   BASE FLEX LAYOUT (FIXED LOGIC)
========================= */





/* Level2 */
.mega-sidebar{
    flex:0 0 15%;
    height:100%;
}

/* Level3 */
.mega-submenu{

    opacity:0;
    visibility:hidden;
 
    overflow:hidden;
    transition:flex .25s ease, opacity .2s ease;
    height:100%;
}

/* Level4 */
.mega-subsubmenu{
    opacity:0;
    visibility:hidden;
    pointer-events:none;
    overflow:hidden;
    transition:flex .25s ease, opacity .2s ease;
    height:100%;
}

/* Level5 (Gallery) */

.mega-submenu,
.mega-subsubmenu{
    width: 15%;
    background:#fff;
    border-radius:25px;
    padding:20px;

    opacity:0;
    visibility:hidden;
    pointer-events:none;

    transition: opacity .2s ease;
}

.mega-submenu.active,
.mega-subsubmenu.active{
    opacity:1;
    visibility:visible;
    pointer-events:auto;
}

.mega-menu.stage-1 .mega-sidebar{
    flex: 0 0 100%;
}

.mega-menu.stage-1 .mega-submenu,
.mega-menu.stage-1 .mega-subsubmenu,
.mega-menu.stage-1 .mega-gallery-container{
    flex: 0 0 0%;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* =========================
   STAGE 2 (Level3 full remaining)
========================= */



.mega-menu.stage-2 .mega-submenu{
    flex:1;
    opacity:1;
    visibility:visible;
    pointer-events:auto;
}

.mega-menu.stage-2 .mega-subsubmenu{
    flex:0 0 0%;
    opacity:0;
    visibility:hidden;
    pointer-events:none;
       display: none;
}

.mega-menu.stage-2 .mega-gallery-container{
    flex:0 0 0%;
    opacity:0;
    visibility:hidden;
}

/* =========================
   STAGE 3 (Level4 appears)
========================= */


.mega-menu.stage-3 .mega-submenu{
    flex:0 0 15%;
    opacity:1;
    visibility:visible;
     transition: 0.5s ease;
}


.mega-menu.stage-3 .mega-subsubmenu{
    flex:1;
    opacity:1;
    visibility:visible;
    pointer-events:auto;
    display: block;
     transition: 0.5s ease;
}

.mega-menu.stage-4:not(.stage-4-gallery) .mega-submenu{
    flex: 0 0 15%;
}

.mega-menu.stage-4.stage-4-gallery .mega-submenu{
    flex: 0 0 20%;
    transition: 0.4s ease;
}

.mega-menu.stage-3 .mega-gallery-container{
    flex:0 0 0%;
    opacity:0;
    visibility:hidden;
}

/* =========================
   STAGE 4 (Gallery appears)
========================= */

.mega-menu.stage-4 .mega-submenu{
    flex: 0 0 15%;
    transition: 0.5s ease;
}



.mega-menu.stage-4 .mega-subsubmenu{
    flex:0 0 15%;
     transition: 0.5s ease;
}

.mega-menu.stage-4 .mega-gallery-container{
    flex:1;
    opacity:1;
    visibility:visible;
    display: flex;
     transition: 0.5s ease;
}

.mega-menu.stage-4 .mega-gallery {
    visibility:visible;
    opacity: 1;
    display: block;
     transition: 0.5s ease;
}





.mega-gallery.active{
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    background-color: #fff;
    
}

.mega-gallery{
    position: absolute;
    inset: 0;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition: opacity .2s ease;
}



.mega-menu.stage-4 .mega-gallery,
.mega-menu.stage-5 .mega-gallery{
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    display: block;
    transition: 0.5s ease;
}



/* default */
.mega-menu .mega-gallery{
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    position: absolute;
    inset: 0;
    transition: opacity .2s ease;
}


.mega-gallery-container{
    flex: 0 0 auto;
    flex: 1;
    position: relative;
    height: 100%;
}

.content-list-4.no-level4 {
    display: none !important;
}

.mega-menu.stage-4.gallery-mode .mega-submenu{
    flex: 0 0 30%;
    transition: 0.5s ease;
}



