@use '../_sass_variables' as *;

/**
 * Maestro menu mode: drawer + vertical submenu.
 * Sidebar is icon-only when a nested submenu is active (layout-sidebar-expanded false);
 * full width with labels when no submenu (layout-sidebar-expanded true).
 */
@media screen and (min-width: $breakpoint) {
    .layout-maestro {
        .layout-topbar {
            .topbar-left {
                .horizontal-logo {
                    display: none;
                }

                .menu-button {
                    display: none;
                }

                .topbar-separator {
                    display: none;
                }
            }
        }

        .layout-maestro-with-submenu .layout-content.with-submenu {
            padding-left: 1rem;
        }

        .layout-sidebar {
            height: 100%;
            top: 0;
            transition: width 0.3s cubic-bezier(0, 0, 0.2, 1);
            width: 4.5rem; /* small width, same as original collapsed */
            z-index: 999;
            overflow-x: hidden;
            display: flex;
            flex-direction: column;

            .sidebar-header {
                width: 100%;
                min-height: 4rem;
                height: 4rem;
                display: flex;
                justify-content: flex-start;
                align-items: center;
                gap: 0.5rem;
                padding: 0.5rem $maestro-left-padding;
                box-sizing: border-box;
                overflow: hidden;
                transition: all 0.15s;

                .logo {
                    display: flex;
                    align-items: center;
                    border: none;
                    padding: 0;
                    margin: 0;
                    flex-shrink: 0;
                    transition: all 0.15s;
                    .logo-image {
                        height: 2.25rem;
                        width: auto;
                        max-width: 2.25rem;
                        object-fit: contain;
                        display: block;
                        transition: all 0.15s;
                    }
                    .app-name {
                        opacity: 0;
                        width: 0;
                        overflow: hidden;
                        transition: all 0.15s;
                    }
                }

                .layout-sidebar-pin {
                    display: none;
                }
            }

            /* Expanded-style: scrollable vertically only, no horizontal scrollbar */
            .layout-menu-container {
                flex: 1;
                min-height: 0;
                overflow-x: hidden;
                overflow-y: auto;
                display: flex;
                flex-direction: column;
            }

            .layout-menu {
                flex: 1;
                min-height: 0;
                transition: all 0.4s;
                min-width: 0;
                display: flex;
                flex-direction: column;
                gap: 0.5rem;

                /* Push separator and items after it (e.g. Start/Documentation) to bottom */
                .menu-separator {
                    margin-top: auto;
                }

                /* Root: same structure as expanded, but icons only (labels hidden) */
                .layout-root-menuitem {
                    > .layout-menuitem-root-text {
                        display: none; /* do not show root section label */
                        opacity: 0;
                        white-space: nowrap;
                        min-height: 2.2rem;
                    }

                    /* Root link: icon visible, label hidden when sidebar collapsed / subsidebar visible */
                    > a {
                        span {
                            opacity: 0;
                        }
                        .layout-menuitem-icon {
                            font-size: 1.25rem;
                            width: auto;
                        }
                    }
                }

                /* Nested: same padding hierarchy as expanded, labels hidden */
                ul {
                    margin: 0;
                    padding: 0;
                    list-style-type: none;
                    display: flex;
                    flex-direction: column;
                    gap: 0.5rem;

                    a {
                        padding: 0.45rem 0.75rem;

                        .layout-submenu-toggler {
                            display: block;
                        }

                        span {
                            opacity: 0; /* icons only */
                            white-space: nowrap;
                            transition: all 0.1s;
                        }

                        .layout-menuitem-icon {
                            font-size: 1.25rem;
                            width: auto;
                        }
                    }

                    ul {
                        overflow: hidden;
                        border-radius: var(--border-radius);

                        li {
                            a {
                                padding-left: 2.5rem;
                            }

                            li {
                                a {
                                    padding-left: 3rem;
                                }

                                li {
                                    a {
                                        padding-left: 3.5rem;
                                    }

                                    li {
                                        a {
                                            padding-left: 4rem;
                                        }

                                        li {
                                            a {
                                                padding-left: 5.5rem;
                                            }

                                            li {
                                                a {
                                                    padding-left: 5rem;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        /* Wide menu with item labels when no subitems in first-level children (sidebarExpanded) */
        &.layout-sidebar-expanded {
            .layout-sidebar {
                width: 14rem;
                display: flex;
                flex-direction: column;

                .layout-menu-container {
                    flex: 1;
                    min-height: 0;
                    overflow: auto;
                    display: flex;
                    flex-direction: column;
                }

                .sidebar-header {
                    justify-content: space-between;
                    min-height: 4rem;
                    height: 4rem;
                    padding: 0.5rem 0.5rem 0.5rem 1.75rem; /* left = menu alignment */
                    box-sizing: border-box;
                    overflow: hidden;
                    .logo {
                        display: flex;
                        align-items: center;
                        justify-content: flex-start;
                        width: auto;
                        flex-shrink: 0;

                        .logo-image {
                            height: 2.25rem;
                            width: auto;
                            max-width: 2.25rem;
                            object-fit: contain;
                            display: block;
                        }

                        .app-name {
                            display: inline-block;
                            opacity: 1;
                            width: auto;
                        }
                    }
                    .layout-sidebar-pin {
                        display: flex;
                        flex-shrink: 0;
                        margin-inline-end: 0.5rem;
                        align-items: center;
                        justify-content: center;
                    }
                }

                .layout-menu {
                    flex: 1;
                    min-height: 0;
                    display: flex;
                    flex-direction: column;

                    .menu-separator {
                        margin-top: auto;
                    }

                    .layout-root-menuitem > .layout-menuitem-root-text {
                        display: none;
                    }

                    /* Show root-link labels (Dashboard, Bedrijven, Settings) when sidebar is expanded */
                    .layout-root-menuitem.layout-menuitem-root-link > a span {
                        opacity: 1;
                    }

                    /* Show item labels in wide mode */
                    ul {
                        display: flex;
                        flex-direction: column;
                        gap: 0.5rem;
                    }
                    ul a {
                        padding: 0.45rem 0.75rem;
                        span {
                            opacity: 1;
                        }
                        .layout-menuitem-icon {
                            margin-right: 0.5rem; // restore icon–label gap in full-size sidebar
                        }
                    }
                    ul ul {
                        overflow: hidden;
                        border-radius: var(--border-radius);
                        li a {
                            padding-left: 2.5rem;
                        }
                        li li a {
                            padding-left: 3rem;
                        }
                        li li li a {
                            padding-left: 3.5rem;
                        }
                        li li li li a {
                            padding-left: 4rem;
                        }
                        li li li li li a {
                            padding-left: 5.5rem;
                        }
                        li li li li li li a {
                            padding-left: 5rem;
                        }
                    }
                }
            }
        }

        &.layout-sidebar-anchored {
            .sidebar-header {
                .layout-sidebar-pin {
                    color: var(--primary-color);
                }
            }
        }
        &.layout-sidebar-dark {
            &.layout-sidebar-anchored {
                .sidebar-header {
                    .layout-sidebar-pin {
                        color: var(--text-color);
                    }
                }
            }
        }

        /* When using drawer + vertical submenu, arrange content and submenu side by side */
        .layout-content.with-submenu {
            display: flex;
            flex-direction: row;
            padding-left: 0;
            padding-right: 0;
            padding-bottom: 0;
            padding-top: 2rem;
            min-height: 0;

            .layout-content-main {
                flex: 1;
                min-width: 0;
                padding-left: 2rem;
                padding-right: 2rem;
                padding-top: 0;
                padding-bottom: 0;
                overflow-y: auto;
                will-change: contents;
            }
        }

        @media screen and (max-width: ($breakpoint - 1)) {
            .layout-content.with-submenu {
                padding-top: 1rem;

                .layout-content-main {
                    padding-left: 1rem;
                    padding-right: 1rem;
                }
            }
        }

        @media screen and (min-width: $breakpoint) and (max-width: 1200px) {
            .layout-content.with-submenu {
                padding-top: 1.5rem;

                .layout-content-main {
                    padding-left: 1rem;
                    padding-right: 1rem;
                }
            }
        }
    }
}

/* Mobile: same narrow icon-only when sidebar is open */
@media screen and (max-width: ($breakpoint - 1)) {
    .layout-maestro.layout-mobile-active .layout-sidebar {
        width: 4.5rem;
        max-width: 4.5rem;
        overflow-x: hidden;

        .sidebar-header {
            min-height: 4rem;
            height: 4rem;
            justify-content: flex-start;
            padding: 0.5rem 0.5rem;
            box-sizing: border-box;
            overflow: hidden;
            .logo .app-name {
                opacity: 0;
                width: 0;
            }
            .logo .logo-image {
                height: 2.25rem;
                width: auto;
                max-width: 2.25rem;
                object-fit: contain;
                display: block;
            }
        }
        .layout-menu-container {
            overflow-x: hidden;
            overflow-y: auto;
        }
        .layout-menu {
            min-width: 0;
            .layout-root-menuitem {
                > .layout-menuitem-root-text {
                    display: none;
                    opacity: 0;
                    white-space: nowrap;
                    min-height: 2.2rem;
                }
                > a {
                    span {
                        opacity: 0;
                    }
                    .layout-menuitem-icon {
                        font-size: 1.25rem;
                        width: auto;
                    }
                }
            }
            ul {
                display: flex;
                flex-direction: column;
                gap: 0.5rem;
            }
            ul a {
                span {
                    opacity: 0;
                    white-space: nowrap;
                }
                .layout-menuitem-icon {
                    font-size: 1.25rem;
                    width: auto;
                }
            }
        }
    }
}
