/* MENU PRINCIPALE */
#mainPagesMenu {
    margin: 0;
    padding: 0;
}

    #mainPagesMenu li {
        list-style: none;
        position: relative;
    }

    /* LINK NORMALI: allineati a destra */
    #mainPagesMenu a {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        width: 100%;
        box-sizing: border-box;
        padding: 10px 12px;
        gap: 8px;
        text-decoration: none;
        color: #212529;
        white-space: normal;
        overflow-wrap: anywhere;
        border-radius: 8px;
    }

        #mainPagesMenu a:hover {
            background: #eef3ff;
        }

/* VOCI CON SOTTOMENŲ */
.submenu-parent {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    gap: 8px;
    background: none;
    border: none;
    border-radius: 8px;
    text-align: right;
    color: #212529;
    cursor: pointer;
    white-space: normal;
    overflow-wrap: anywhere;
}

    .submenu-parent:hover {
        background: #eef3ff;
    }

    .submenu-parent:focus {
        outline: none;
    }

    .submenu-parent .label {
        flex: 0 1 auto;
        text-align: right;
    }

    /* FRECCIA ALL'INIZIO, PUNTA A SINISTRA */
    .submenu-parent .arrow {
        order: -1;
        margin-right: 8px;
        width: 0;
        height: 0;
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        border-right: 7px solid #495057;
        transition: transform .2s ease;
    }

    /* APERTO: FRECCIA VERSO IL BASSO */
    .submenu-parent[aria-expanded="true"] .arrow {
        transform: rotate(-90deg);
    }

/* SOTTOMENŲ */
.submenu {
    position: static;
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
    margin: 4px 0 6px 0;
    padding: 0 14px 0 0;
    border-right: 2px solid #eef3ff;
    border-left: none;
    text-align: right;
    display: none;
}

    .submenu a {
        justify-content: flex-end;
        padding: 9px 12px;
        white-space: normal;
        overflow-wrap: anywhere;
    }

/* OVERLAY BURGER */
#userNavbar.burger-overlay {
    display: none;
}

    #userNavbar.burger-overlay.show {
        display: block;
    }

/* IMPORTANTE: ancoraggio relativo al pulsante */
#userNavbar {
    position: relative;
}

    /* QUI č la parte che fa "espandere verso sinistra":
   l'overlay č un contenitore flex che allinea il pannello a destra */
    #userNavbar.burger-overlay {
        display: none;
        justify-content: flex-end; /* pannello sempre attaccato a destra */
        width: auto;
    }

        #userNavbar.burger-overlay.show {
            display: flex;
        }

/* PANNELLO: larghezza dinamica, non fissa */
.burger-panel {
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 10px 30px rgba(0,0,0,.15);
    width: fit-content; /* dinamico */
    max-width: calc(100vw - 24px); /* non esce dallo schermo */
    overflow: visible;
}

/* Fallback se un browser non supporta fit-content */
@supports not (width: fit-content) {
    .burger-panel {
        width: max-content;
    }
}

/* Desktop: overlay ancorato a destra del pulsante */
@media (min-width: 992px) {
    #userNavbar.burger-overlay {
        position: absolute;
        top: calc(100% + 6px);
        right: 0;
        left: auto;
        transform: none;
        z-index: 3000;
    }
}

/* Mobile: stesso comportamento, quindi resta vicino e cresce verso sinistra */
@media (max-width: 991.98px) {
    #userNavbar.burger-overlay {
        position: absolute;
        top: calc(100% + 6px);
        right: 0;
        left: auto;
        transform: none;
        z-index: 4000;
    }

    .burger-panel {
        max-height: calc(100vh - (env(safe-area-inset-top) + 96px));
        overflow: auto;
    }
}
