{{-- 
========================================
SIDEBAR MENU MODULARE NETGESCON
========================================
Sidebar completamente modulare con gestione permessi,
componenti separati e stili/JS esterni.

Struttura:
- Header (logo, data, news ticker)
- Notifiche e quick actions
- Menu navigation con permessi
- Footer con info utente

Autore: NetGesCon Development Team
Data: 2024
========================================
--}}

{{-- Include helpers per gestione permessi --}}
@include('components.menu.sections.menu-helpers')

{{-- Sidebar container principale --}}
<div class="netgescon-sidebar d-flex flex-column h-100" id="netgesconSidebar">
    
    {{-- Header con Logo, Data e News --}}
    @include('components.menu.sections.header')

    {{-- Notifiche e Quick Actions --}}
    @include('components.menu.sections.notifications')

    {{-- Menu Navigation principale --}}
    <nav class="sidebar-nav flex-fill overflow-auto" role="navigation" aria-label="Menu principale NetGesCon">
        <ul class="nav nav-pills flex-column p-2">
            
            {{-- Dashboard - Sempre visibile --}}
            @if(canUserAccessMenu('dashboard'))
                @include('components.menu.sections.dashboard')
            @endif
            
            {{-- Stabili - Solo amministratori e superiori --}}
            @if(canUserAccessMenu('stabili'))
                @include('components.menu.sections.stabili')
            @endif
            
            {{-- Condomini - Solo amministratori e superiori --}}
            @if(canUserAccessMenu('condomini'))
                @include('components.menu.sections.condomini')
            @endif
            
            {{-- Contabilità - Solo ruoli economici --}}
            @if(canUserAccessMenu('contabilita'))
                @include('components.menu.sections.contabilita')
            @endif
            
            {{-- Fiscale - Solo ruoli economici --}}
            @if(canUserAccessMenu('fiscale'))
                @include('components.menu.sections.fiscale')
            @endif
            
            {{-- Menu Semplici - Comunicazioni, tickets, etc --}}
            @if(canUserAccessAnyMenu(['comunicazioni', 'tickets', 'assemblee']))
                @include('components.menu.sections.menu-semplici')
            @endif
            
        </ul>
    </nav>

    {{-- Footer con info utente e versione --}}
    @include('components.menu.sections.footer')
    
</div>

{{-- Include CSS e JS esterni per la sidebar --}}
@push('styles')
    <link rel="stylesheet" href="{{ asset('css/sidebar.css') }}">
@endpush

@push('scripts')
    <script src="{{ asset('js/sidebar.js') }}"></script>
@endpush


.dark .sidebar .collapse .nav-link:hover {
    background-color: rgba(55, 65, 81, 0.3);
    color: #d1d5db;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        z-index: 1050;
        transition: left 0.3s ease;
    }
    
    .sidebar.show {
        left: 0;
    }
}
</style>

{{-- JavaScript per funzionalità sidebar --}}
<script>
document.addEventListener('DOMContentLoaded', function() {
    // Gestione toggle menu collassabili
    const collapseElements = document.querySelectorAll('[data-bs-toggle="collapse"]');
    collapseElements.forEach(element => {
        element.addEventListener('click', function() {
            const icon = this.querySelector('.fa-chevron-down, .fa-chevron-up');
            if (icon) {
                icon.classList.toggle('fa-chevron-down');
                icon.classList.toggle('fa-chevron-up');
            }
        });
    });

    // Gestione menu attivo
    const navLinks = document.querySelectorAll('.sidebar .nav-link[href]');
    const currentPath = window.location.pathname;
    
    navLinks.forEach(link => {
        if (link.getAttribute('href') === currentPath) {
            link.classList.add('active');
            // Espandi il menu parent se è collassato
            const parentCollapse = link.closest('.collapse');
            if (parentCollapse) {
                parentCollapse.classList.add('show');
                const toggleButton = document.querySelector(`[href="#${parentCollapse.id}"]`);
                if (toggleButton) {
                    toggleButton.setAttribute('aria-expanded', 'true');
                }
            }
        }
    });

    // Aggiorna data e ora ogni minuto
    function updateDateTime() {
        const now = new Date();
        const dateElement = document.getElementById('current-date');
        const timeElement = document.getElementById('current-time');
        
        if (dateElement) {
            dateElement.textContent = now.toLocaleDateString('it-IT');
        }
        if (timeElement) {
            timeElement.textContent = now.toLocaleTimeString('it-IT', { hour: '2-digit', minute: '2-digit' });
        }
    }
    
    updateDateTime();
    setInterval(updateDateTime, 60000);

    // News ticker animation
    const newsTicker = document.querySelector('.news-ticker');
    if (newsTicker) {
        newsTicker.addEventListener('animationend', function() {
            this.style.animation = 'none';
            setTimeout(() => {
                this.style.animation = 'scroll-left 30s linear infinite';
            }, 50);
        });
    }
});
</script>
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#condominiMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-users me-2"></i>
                        <span>Condomini</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="condominiMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Elenco Condomini</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-user-plus me-2"></i>Nuovo Condomino</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-home me-2"></i>Abbinamento Unità</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-percentage me-2"></i>Tabelle Millesimi</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Fornitori --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#fornitoriMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-truck me-2"></i>
                        <span>Fornitori</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="fornitoriMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Elenco Fornitori</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-invoice me-2"></i>Fatture Elettroniche</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tools me-2"></i>Manutentori</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tags me-2"></i>Tag e Categorie</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Contabilità --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#contabilitaMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-calculator me-2"></i>
                        <span>Contabilità</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="contabilitaMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-receipt me-2"></i>Rate</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-line me-2"></i>Bilanci</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-exchange-alt me-2"></i>Movimenti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-search me-2"></i>Revisioni</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Altri menu principali --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-users-cog me-2"></i>
                    <span>Assemblee</span>
                </a>
            </li>

            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-university me-2"></i>
                    <span>Risorse Economiche</span>
                </a>
            </li>

            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-envelope me-2"></i>
                    <span>Comunicazioni</span>
                </a>
            </li>

            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-key me-2"></i>
                    <span>Affitti</span>
                </a>
            </li>

            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-folder-open me-2"></i>
                    <span>Pratiche</span>
                </a>
            </li>

            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-file-invoice-dollar me-2"></i>
                    <span>Fiscale</span>
                </a>
            </li>

            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-tint me-2"></i>
                    <span>Consumi</span>
                </a>
            </li>

            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-ticket-simple me-2"></i>
                    <span>Tickets</span>
                </a>
            </li>

            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-cog me-2"></i>
                    <span>Impostazioni</span>
                </a>
            </li>
        </ul>
    </nav>

    {{-- Footer --}}
    <div class="p-2 border-top border-primary text-center">
        <small class="text-muted">
            © 2025 NetGesCon - v2.1.0<br>
            <a href="#" class="text-decoration-none">Supporto</a> • 
            <a href="#" class="text-decoration-none">Contatti</a> • 
            <a href="#" class="text-decoration-none">www.netgescon.it</a>
        </small>
    </div>
</div>

<script>
    // Aggiorna data e ora
    function updateDateTime() {
        const now = new Date();
        const options = {
            weekday: 'short',
            year: 'numeric',
            month: 'short',
            day: 'numeric',
            hour: '2-digit',
            minute: '2-digit'
        };
        document.getElementById('datetime-display').textContent = now.toLocaleDateString('it-IT', options);
    }

    // Aggiorna ogni minuto
    updateDateTime();
    setInterval(updateDateTime, 60000);

    // News ticker animation
    function animateNews() {
        const newsText = document.getElementById('news-text');
        if (newsText) {
            const news = [
                '🌤️ Meteo: Sereno 18°C • 📈 FTSE MIB +0.5% • 🏛️ Nuove agevolazioni fiscali 2025',
                '⚡ BREAKING: Nuovo decreto condomini • 💰 EURO/USD 1.095 • 🏠 Mercato immobiliare +2.3%',
                '🎯 Scadenza F24: 16/01 • 📊 Inflazione 0.8% • 🔧 Bonus ristrutturazioni prorogato'
            ];
            
            let index = 0;
            setInterval(() => {
                index = (index + 1) % news.length;
                newsText.textContent = news[index];
            }, 10000);
        }
    }

    // Avvia animazione news
    animateNews();

    // Funzione per aprire pagina news
    function openNewsPage() {
        window.open('https://www.ansa.it/sito/notizie/economia/economia.html', '_blank');
    }
</script>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="stabiliMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Elenco Stabili</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-plus me-2"></i>Nuovo Stabile</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-pie me-2"></i>Piano dei Conti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-id-card me-2"></i>Anagrafiche</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-home me-2"></i>Unità Immobiliari</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-percentage me-2"></i>Tabelle Millesimi</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Condomini (ex Soggetti) --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#condominiMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-users me-2"></i>
                        <span>Condomini</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="condominiMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Elenco Condomini</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-user-plus me-2"></i>Nuovo Condomino</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-home me-2"></i>Abbinamento Unità</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-users-cog me-2"></i>Proprietari/Inquilini</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-address-book me-2"></i>Rubrica Completa</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Fornitori --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#fornitoriMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-truck me-2"></i>
                        <span>Fornitori</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="fornitoriMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Elenco Fornitori</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-plus me-2"></i>Nuovo Fornitore</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-invoice me-2"></i>Fatture Elettroniche</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tools me-2"></i>Manutentori</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tags me-2"></i>Categorie e Tag</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Contabilità --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#contabilitaMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-calculator me-2"></i>
                        <span>Contabilità</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="contabilitaMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-receipt me-2"></i>Rate Condominiali</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-invoice-dollar me-2"></i>Fatture</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-university me-2"></i>Movimenti Bancari</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-line me-2"></i>Bilanci</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-search me-2"></i>Revisioni Contabili</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Risorse Economiche --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#risorseMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-coins me-2"></i>
                        <span>Risorse Economiche</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="risorseMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-university me-2"></i>Conti Bancari</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-cash-register me-2"></i>Cassa Contanti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fab fa-paypal me-2"></i>PayPal</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-credit-card me-2"></i>Carte/PostePay</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-pie me-2"></i>Riepilogo Risorse</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Assemblee --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#assembleMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-users-cog me-2"></i>
                        <span>Assemblee</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="assembleMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-calendar me-2"></i>Programma Assemblee</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-plus me-2"></i>Nuova Assemblea</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-alt me-2"></i>Verbali</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-vote-yea me-2"></i>Delibere</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-bell me-2"></i>Convocazioni</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Affitti --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#affittiMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-key me-2"></i>
                        <span>Affitti</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="affittiMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Contratti Attivi</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-plus me-2"></i>Nuovo Contratto</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-euro-sign me-2"></i>Canoni</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-calendar-times me-2"></i>Scadenze</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-certificate me-2"></i>Certificazioni</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Pratiche --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#praticheMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-folder-open me-2"></i>
                        <span>Pratiche</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="praticheMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-balance-scale me-2"></i>Pratiche Legali</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-shield-alt me-2"></i>Pratiche Assicurative</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-contract me-2"></i>Pratiche Fiscali</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-building me-2"></i>Pratiche Edilizie</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-archive me-2"></i>Archivio Pratiche</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Fiscale --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#fiscaleMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-file-invoice me-2"></i>
                        <span>Fiscale</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="fiscaleMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-receipt me-2"></i>F24 e Versamenti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-percentage me-2"></i>Ritenute d'Acconto</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-export me-2"></i>Certificazioni</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-exclamation-triangle me-2"></i>Cartelle Esattoriali</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-book me-2"></i>Normative e Leggi</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Consumi --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#consumiMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-tint me-2"></i>
                        <span>Consumi</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="consumiMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tint me-2"></i>Acqua</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-fire me-2"></i>Riscaldamento</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-bolt me-2"></i>Energia Elettrica</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-burn me-2"></i>Gas</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-line me-2"></i>Ripartizioni</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Comunicazioni --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#comunicazioniMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-envelope me-2"></i>
                        <span>Comunicazioni</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="comunicazioniMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-users me-2"></i>Gruppi di Contatto</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-envelope me-2"></i>Email/PEC</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-mail-bulk me-2"></i>Raccomandate</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-sms me-2"></i>SMS</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-archive me-2"></i>Archivio Comunicazioni</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Documenti --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#documentiMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-folder me-2"></i>
                        <span>Gestione Documentale</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="documentiMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-upload me-2"></i>Carica Documenti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-search me-2"></i>Ricerca Documenti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tags me-2"></i>Categorie</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-share-alt me-2"></i>Condivisione</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Tickets --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-ticket-simple me-2"></i>
                    <span>Tickets</span>
                </a>
            </li>

            {{-- Impostazioni --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#impostazioniMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-cog me-2"></i>
                        <span>Impostazioni</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="impostazioniMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-user-cog me-2"></i>Profilo Utente</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-users-cog me-2"></i>Gestione Collaboratori</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-shield-alt me-2"></i>Permessi</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-database me-2"></i>Backup</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-undo me-2"></i>Ripristino</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-sync me-2"></i>Aggiornamenti</a>
                        </li>
                    </ul>
                </div>
            </li>
        </ul>
    </nav>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="stabiliMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Elenco Stabili</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-plus me-2"></i>Nuovo Stabile</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-pie me-2"></i>Piano dei Conti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-address-book me-2"></i>Anagrafiche</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Condomini (ex Soggetti) --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#condominiMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-users me-2"></i>
                        <span>Condomini</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="condominiMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Elenco Condomini</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-plus me-2"></i>Nuovo Condomino</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-home me-2"></i>Unità Immobiliari</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-table me-2"></i>Tabelle Millesimi</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Fornitori --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#fornitoriMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-truck me-2"></i>
                        <span>Fornitori</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="fornitoriMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Elenco Fornitori</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-invoice me-2"></i>Fatture Elettroniche</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tools me-2"></i>Manutentori</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tags me-2"></i>Tag e Categorie</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Contabilità --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#contabilitaMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-calculator me-2"></i>
                        <span>Contabilità</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="contabilitaMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-line me-2"></i>Bilanci</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-receipt me-2"></i>Rate Condominio</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-university me-2"></i>Estratti Conto</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-search me-2"></i>Revisioni Contabili</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Tickets --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#ticketsMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-ticket-simple me-2"></i>
                        <span>Tickets</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="ticketsMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Tutti i Tickets</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-plus me-2"></i>Nuovo Ticket</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-exclamation-triangle me-2"></i>Urgenti</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Assemblee --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#assembleMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-users-cog me-2"></i>
                        <span>Assemblee</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="assembleMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-calendar me-2"></i>Calendario Assemblee</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-alt me-2"></i>Verbali</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-gavel me-2"></i>Delibere</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Risorse Economiche --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#risorseMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-coins me-2"></i>
                        <span>Risorse Economiche</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="risorseMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-university me-2"></i>Conti Bancari</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-wallet me-2"></i>Cassa Contanti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fab fa-paypal me-2"></i>PayPal</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-bar me-2"></i>Riepilogo Liquidità</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Affitti --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#affittiMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-key me-2"></i>
                        <span>Affitti</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="affittiMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-list me-2"></i>Contratti Attivi</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-contract me-2"></i>Nuovo Contratto</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-euro-sign me-2"></i>Canoni</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-certificate me-2"></i>Cedolare Secca</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Pratiche Legali --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#legaliMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-balance-scale me-2"></i>
                        <span>Pratiche Legali</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="legaliMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-gavel me-2"></i>Contenziosi</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-handshake me-2"></i>Recupero Crediti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-user-tie me-2"></i>Avvocati</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Pratiche Assicurative --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#assicurazioniMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-shield-alt me-2"></i>
                        <span>Assicurazioni</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="assicurazioniMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-contract me-2"></i>Polizze Attive</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-exclamation-circle me-2"></i>Sinistri</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-calendar-check me-2"></i>Scadenze</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Fiscale --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#fiscaleMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-file-invoice-dollar me-2"></i>
                        <span>Fiscale</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="fiscaleMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-receipt me-2"></i>Ritenute d'Acconto</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-alt me-2"></i>Modelli F24</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-exclamation-triangle me-2"></i>Cartelle Esattoriali</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-certificate me-2"></i>Certificazioni</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Consumi --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#consumiMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-tachometer-alt me-2"></i>
                        <span>Consumi</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="consumiMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tint me-2"></i>Acqua</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-fire me-2"></i>Riscaldamento</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-bolt me-2"></i>Energia Elettrica</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-chart-line me-2"></i>Statistiche</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Documentale e Comunicazioni --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#documentaleMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-folder-open me-2"></i>
                        <span>Documentale</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="documentaleMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-file-alt me-2"></i>Archivio Documenti</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-envelope me-2"></i>Comunicazioni</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-mail-bulk me-2"></i>Raccomandate</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-users me-2"></i>Gruppi Contatti</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Impostazioni --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#impostazioniMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-cog me-2"></i>
                        <span>Impostazioni</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="impostazioniMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-user me-2"></i>Profilo Utente</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-database me-2"></i>Backup</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-upload me-2"></i>Ripristini</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-tools me-2"></i>Configurazioni</a>
                        </li>
                    </ul>
                </div>
            </li>

            {{-- Legislazione --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center text-dark" href="#">
                    <i class="fas fa-book me-2"></i>
                    <span>Legislazione</span>
                </a>
            </li>

            {{-- Help --}}
            <li class="nav-item mb-1">
                <a class="nav-link d-flex align-items-center justify-content-between text-dark" 
                   data-bs-toggle="collapse" href="#helpMenu" role="button">
                    <div class="d-flex align-items-center">
                        <i class="fas fa-question-circle me-2"></i>
                        <span>Help</span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </a>
                <div class="collapse" id="helpMenu">
                    <ul class="nav nav-pills flex-column ms-3">
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-book-open me-2"></i>Manuale Utente</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fab fa-youtube me-2"></i>Video Tutorial</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" href="#"><i class="fas fa-headset me-2"></i>Supporto</a>
                        </li>
                    </ul>
                </div>
            </li>
        </ul>
    </nav>
</div>
        [
            'icon' => 'fa-solid fa-home',
            'label' => 'Dashboard',
            'route' => $panelPrefix . 'dashboard',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore', 'condomino'],
        ],
        [
            'icon' => 'fa-solid fa-building',
            'label' => 'Stabili',
            'route' => $panelPrefix . 'stabili.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
            'expandable' => true,
            'id' => 'stabili-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-door-open', 'label' => 'Unità Immobiliari', 'route' => $panelPrefix . 'unitaImmobiliari.index'],
                ['icon' => 'fa-solid fa-address-book', 'label' => 'Anagrafica Condominiale', 'route' => $panelPrefix . 'anagrafica-condominiale.index'],
                ['icon' => 'fa-solid fa-table', 'label' => 'Tabelle Millesimali', 'route' => $panelPrefix . 'tabelle-millesimali.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-users',
            'label' => 'Soggetti',
            'route' => $panelPrefix . 'soggetti.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
        ],
        [
            'icon' => 'fa-solid fa-truck',
            'label' => 'Fornitori',
            'route' => $panelPrefix . 'fornitori.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
        ],
        [
            'icon' => 'fa-solid fa-file-invoice',
            'label' => 'Rate e Incassi',
            'route' => $panelPrefix . 'rate.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
            'expandable' => true,
            'id' => 'rate-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-file-plus', 'label' => 'Emissione Rate', 'route' => $panelPrefix . 'rate.emissione'],
                ['icon' => 'fa-solid fa-money-check', 'label' => 'Incassi e Pagamenti', 'route' => $panelPrefix . 'incassi.index'],
                ['icon' => 'fa-solid fa-chart-line', 'label' => 'Estratti Conto', 'route' => $panelPrefix . 'estratti-conto.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-file-invoice-dollar',
            'label' => 'Contabilità',
            'route' => $panelPrefix . 'contabilita.index',
            'roles' => ['admin', 'super-admin', 'amministratore'],
            'expandable' => true,
            'id' => 'contabilita-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-book', 'label' => 'Mastro Generale', 'route' => $panelPrefix . 'mastro.index'],
                ['icon' => 'fa-solid fa-balance-scale', 'label' => 'Bilanci', 'route' => $panelPrefix . 'bilanci.index'],
                ['icon' => 'fa-solid fa-calculator', 'label' => 'Ripartizioni', 'route' => $panelPrefix . 'ripartizioni.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-percent',
            'label' => 'Gestione Fiscale',
            'route' => $panelPrefix . 'fiscale.index',
            'roles' => ['admin', 'super-admin', 'amministratore'],
            'expandable' => true,
            'id' => 'fiscale-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-file-pdf', 'label' => 'Modelli F24', 'route' => $panelPrefix . 'f24.index'],
                ['icon' => 'fa-solid fa-coins', 'label' => 'Ritenute d\'Acconto', 'route' => $panelPrefix . 'ritenute.index'],
                ['icon' => 'fa-solid fa-file-alt', 'label' => 'Cartelle Esattoriali', 'route' => $panelPrefix . 'cartelle.index'],
                ['icon' => 'fa-solid fa-certificate', 'label' => 'Rendite Condominiali', 'route' => $panelPrefix . 'rendite.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-home',
            'label' => 'Gestione Affitti',
            'route' => $panelPrefix . 'affitti.index',
            'roles' => ['admin', 'super-admin', 'amministratore'],
            'expandable' => true,
            'id' => 'affitti-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-file-contract', 'label' => 'Contratti', 'route' => $panelPrefix . 'contratti.index'],
                ['icon' => 'fa-solid fa-money-bill', 'label' => 'Canoni', 'route' => $panelPrefix . 'canoni.index'],
                ['icon' => 'fa-solid fa-calendar-times', 'label' => 'Scadenze', 'route' => $panelPrefix . 'scadenze-affitti.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-gavel',
            'label' => 'Pratiche Legali',
            'route' => $panelPrefix . 'legali.index',
            'roles' => ['admin', 'super-admin', 'amministratore'],
        ],
        [
            'icon' => 'fa-solid fa-shield-alt',
            'label' => 'Pratiche Assicurative',
            'route' => $panelPrefix . 'assicurazioni.index',
            'roles' => ['admin', 'super-admin', 'amministratore'],
        ],
        [
            'icon' => 'fa-solid fa-users-cog',
            'label' => 'Assemblee',
            'route' => $panelPrefix . 'assemblee.index',
            'roles' => ['admin', 'super-admin', 'amministratore'],
            'expandable' => true,
            'id' => 'assemblee-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-calendar-plus', 'label' => 'Convocazioni', 'route' => $panelPrefix . 'convocazioni.index'],
                ['icon' => 'fa-solid fa-vote-yea', 'label' => 'Verbali', 'route' => $panelPrefix . 'verbali.index'],
                ['icon' => 'fa-solid fa-chart-pie', 'label' => 'Delibere', 'route' => $panelPrefix . 'delibere.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-university',
            'label' => 'Risorse Economiche',
            'route' => $panelPrefix . 'risorse.index',
            'roles' => ['admin', 'super-admin', 'amministratore'],
            'expandable' => true,
            'id' => 'risorse-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-credit-card', 'label' => 'Conti Bancari', 'route' => $panelPrefix . 'banche.index'],
                ['icon' => 'fa-solid fa-wallet', 'label' => 'Cassa Contanti', 'route' => $panelPrefix . 'cassa.index'],
                ['icon' => 'fab fa-paypal', 'label' => 'PayPal/Digital', 'route' => $panelPrefix . 'digital.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-folder-open',
            'label' => 'Gestione Documentale',
            'route' => $panelPrefix . 'documenti.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
            'expandable' => true,
            'id' => 'documenti-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-envelope', 'label' => 'Email/PEC', 'route' => $panelPrefix . 'comunicazioni.email'],
                ['icon' => 'fa-solid fa-mail-bulk', 'label' => 'Raccomandate', 'route' => $panelPrefix . 'comunicazioni.raccomandate'],
                ['icon' => 'fa-solid fa-archive', 'label' => 'Archivio', 'route' => $panelPrefix . 'archivio.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-tint',
            'label' => 'Gestione Consumi',
            'route' => $panelPrefix . 'consumi.index',
            'roles' => ['admin', 'super-admin', 'amministratore'],
            'expandable' => true,
            'id' => 'consumi-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-water', 'label' => 'Acqua', 'route' => $panelPrefix . 'consumi.acqua'],
                ['icon' => 'fa-solid fa-fire', 'label' => 'Riscaldamento', 'route' => $panelPrefix . 'consumi.riscaldamento'],
                ['icon' => 'fa-solid fa-lightbulb', 'label' => 'Elettricità', 'route' => $panelPrefix . 'consumi.elettricita'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-calendar-check',
            'label' => 'Calendario',
            'route' => $panelPrefix . 'calendario.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
        ],
        [
            'icon' => 'fa-solid fa-address-book',
            'label' => 'Rubrica',
            'route' => $panelPrefix . 'rubrica.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
        ],
        [
            'icon' => 'fa-solid fa-ticket-alt',
            'label' => 'Tickets',
            'route' => $panelPrefix . 'tickets.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
        ],
        [
            'icon' => 'fa-solid fa-cog',
            'label' => 'Impostazioni',
            'route' => $panelPrefix . 'impostazioni',
            'roles' => ['admin', 'super-admin', 'amministratore'],
            'expandable' => true,
            'id' => 'impostazioni-menu',
            'submenu' => [
                ['icon' => 'fa-solid fa-database', 'label' => 'Backup', 'route' => $panelPrefix . 'backup.index'],
                ['icon' => 'fa-solid fa-exchange-alt', 'label' => 'Revisioni Contabili', 'route' => $panelPrefix . 'revisioni.index'],
                ['icon' => 'fa-solid fa-users', 'label' => 'Gruppi Comunicazione', 'route' => $panelPrefix . 'gruppi.index'],
            ]
        ],
        [
            'icon' => 'fa-solid fa-balance-scale',
            'label' => 'Legislazione',
            'route' => $panelPrefix . 'legislazione.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore'],
        ],
        [
            'icon' => 'fa-solid fa-question-circle',
            'label' => 'Help',
            'route' => $panelPrefix . 'help.index',
            'roles' => ['admin', 'super-admin', 'amministratore', 'collaboratore', 'condomino'],
        ],
    ];
    @endphp
    
<nav class="h-100 d-flex flex-column bg-warning border-end border-4 border-primary py-3 px-2 shadow">
    
    <!-- Header stabile/anno -->
    <div class="px-2 pt-2 pb-3 bg-warning-subtle border-bottom border-primary position-sticky top-0" style="z-index: 20;">
        <div class="d-flex flex-column align-items-center">
            <small class="text-muted mb-1">{{ $annoAttivo }}/{{ $gestione }}</small>
            <div class="d-flex align-items-center gap-2 bg-light rounded px-2 py-1 shadow-sm" style="min-width: 160px;">
                <div class="d-flex flex-column me-1">
                    <button id="prev-stabile" class="btn btn-primary btn-sm p-1 mb-1" style="width: 24px; height: 24px;" title="Stabile precedente">
                        <i class="fas fa-chevron-up" style="font-size: 10px;"></i>
                    </button>
                    <button id="next-stabile" class="btn btn-primary btn-sm p-1" style="width: 24px; height: 24px;" title="Stabile successivo">
                        <i class="fas fa-chevron-down" style="font-size: 10px;"></i>
                    </button>
                </div>
                <button id="current-stabile" class="btn btn-outline-primary btn-sm flex-fill text-start" title="Cambia stabile">
                    {{ $stabileAttivo }}
                </button>
            </div>
            <button id="toggle-darkmode" class="btn btn-dark btn-sm mt-2" title="Attiva/disattiva modalità scura">
                <i class="fas fa-moon me-1"></i>
                <span>Dark</span>
            </button>
        </div>
    </div>
    
    <!-- Menu principale -->
    <div class="flex-fill overflow-auto">
        <div class="list-group list-group-flush">
            @foreach($mainMenu as $item)
                @if(array_intersect($item['roles'], $userRoles))
                    @if(isset($item['expandable']) && $item['expandable'])
                        <!-- Menu item with submenu -->
                        <div class="menu-item-wrapper">
                            <button class="list-group-item list-group-item-action d-flex align-items-center justify-content-between border-0 {{ Route::currentRouteName() == $item['route'] ? 'active' : '' }}" 
                                    type="button" 
                                    data-bs-toggle="collapse" 
                                    data-bs-target="#submenu-{{ $item['id'] }}" 
                                    aria-expanded="false" 
                                    aria-controls="submenu-{{ $item['id'] }}">
                                <div class="d-flex align-items-center">
                                    <i class="{{ $item['icon'] }} me-2"></i>
                                    <span>{{ $item['label'] }}</span>
                                </div>
                                <i class="fas fa-chevron-down"></i>
                            </button>
                            <!-- Submenu -->
                            <div class="collapse" id="submenu-{{ $item['id'] }}">
                                <div class="list-group list-group-flush ms-3">
                                    @foreach($item['submenu'] as $subItem)
                                        @if(array_intersect($subItem['roles'], $userRoles))
                                            @if(Route::has($subItem['route']))
                                                <a href="{{ route($subItem['route']) }}" 
                                                   class="list-group-item list-group-item-action py-2 border-0 {{ Route::currentRouteName() == $subItem['route'] ? 'active' : '' }}">
                                                    <i class="{{ $subItem['icon'] }} me-2 text-sm"></i>
                                                    <span class="small">{{ $subItem['label'] }}</span>
                                                </a>
                                            @else
                                                <div class="list-group-item py-2 text-muted border-0" title="Funzionalità in sviluppo">
                                                    <i class="{{ $subItem['icon'] }} me-2 text-sm"></i>
                                                    <span class="small">{{ $subItem['label'] }}</span>
                                                    <i class="fas fa-code ms-auto small"></i>
                                                </div>
                                            @endif
                                        @endif
                                    @endforeach
                                </div>
                            </div>
                        </div>
                    @else
                        <!-- Regular menu item -->
                        @if(Route::has($item['route']))
                            <a href="{{ route($item['route']) }}" 
                               class="list-group-item list-group-item-action d-flex align-items-center border-0 {{ Route::currentRouteName() == $item['route'] ? 'active' : '' }}">
                                <i class="{{ $item['icon'] }} me-2"></i>
                                <span>{{ $item['label'] }}</span>
                            </a>
                        @else
                            <div class="list-group-item py-2 text-muted d-flex align-items-center border-0" title="Funzionalità in sviluppo">
                                <i class="{{ $item['icon'] }} me-2"></i>
                                <span>{{ $item['label'] }}</span>
                                <i class="fas fa-code ms-auto small"></i>
                            </div>
                        @endif
                    @endif
                @endif
            @endforeach
        </div>
    </div>
    
    <!-- Footer -->
    <div class="mt-auto pt-3 border-top">
        <div class="text-center">
            <small class="text-muted">NetGesCon &copy; {{ date('Y') }}</small>
            <br>
            <small class="text-muted">v0.7.0-dev</small>
        </div>
    </div>
    
</nav>
<!-- Modale ricerca stabile -->
<div class="modal fade" id="modal-stabile" tabindex="-1" aria-labelledby="modalStabileLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="modalStabileLabel">Cerca stabile</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <input type="text" id="input-stabile" class="form-control mb-3" placeholder="Digita il nome dello stabile...">
                <div id="result-stabile" class="list-group" style="max-height: 200px; overflow-y: auto;"></div>
            </div>
        </div>
    </div>
</div>

<script>
// Dati stabili (temporanei per test)
const stabili = ["Condominio Roma Centro", "Residence Milano Nord", "Palazzina Napoli Est", "Villa Torino Ovest"];
let currentIndex = 0;

// Dark mode toggle
const darkBtn = document.getElementById('toggle-darkmode');
if (darkBtn) {
    darkBtn.addEventListener('click', function() {
        document.documentElement.classList.toggle('dark');
        const isDark = document.documentElement.classList.contains('dark');
        localStorage.setItem('darkMode', isDark ? 'enabled' : 'disabled');
    });
}

// Inizializza dark mode da localStorage
if (localStorage.getItem('darkMode') === 'enabled') {
    document.documentElement.classList.add('dark');
}

// Gestione stabile
function updateStabile() {
    const button = document.getElementById('current-stabile');
    if (button) {
        button.textContent = stabili[currentIndex] || 'Nessuno selezionato';
    }
}

// Bottoni navigazione stabile
const prevBtn = document.getElementById('prev-stabile');
const nextBtn = document.getElementById('next-stabile');
const currentBtn = document.getElementById('current-stabile');

if (prevBtn) {
    prevBtn.onclick = function() {
        currentIndex = (currentIndex - 1 + stabili.length) % stabili.length;
        updateStabile();
    };
}

if (nextBtn) {
    nextBtn.onclick = function() {
        currentIndex = (currentIndex + 1) % stabili.length;
        updateStabile();
    };
}

if (currentBtn) {
    currentBtn.onclick = function() {
        const modal = new bootstrap.Modal(document.getElementById('modal-stabile'));
        modal.show();
        document.getElementById('input-stabile').value = '';
        document.getElementById('result-stabile').innerHTML = '';
    };
}

// Ricerca stabile
const inputStabile = document.getElementById('input-stabile');
if (inputStabile) {
    inputStabile.oninput = function(e) {
        const val = e.target.value.toLowerCase();
        const results = stabili.filter(s => s.toLowerCase().includes(val));
        const resultDiv = document.getElementById('result-stabile');
        resultDiv.innerHTML = results.map(s => 
            `<button type="button" class="list-group-item list-group-item-action" onclick="selectStabile('${s}')">${s}</button>`
        ).join('');
    };
}

// Selezione stabile
window.selectStabile = function(nome) {
    document.getElementById('current-stabile').textContent = nome;
    const modal = bootstrap.Modal.getInstance(document.getElementById('modal-stabile'));
    modal.hide();
    
    // Chiamata AJAX per aggiornare la sessione stabile_corrente
    fetch('/session/stabile', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
        },
        body: JSON.stringify({ stabile: nome })
    }).then(res => {
        if(res.ok) window.location.reload();
    });
};

// Inizializza stabile
updateStabile();
</script>

<style>
/* Sidebar responsive */
.sidebar-responsive {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease;
}

/* Responsive per tablet e mobile */
@media (max-width: 768px) {
    .sidebar-responsive {
        transform: translateX(-100%);
    }
    
    .sidebar-responsive.show {
        transform: translateX(0);
    }
}

/* Spaziatura del contenuto principale */
@media (min-width: 769px) {
    .main-content {
        margin-left: 280px;
    }
}

/* Dark mode support */
.dark .sidebar-responsive {
    background-color: #1f2937 !important;
    color: #fff !important;
}

.dark .sidebar-responsive .list-group-item {
    background-color: #374151 !important;
    color: #fff !important;
    border-color: #4b5563 !important;
}

.dark .sidebar-responsive .list-group-item:hover {
    background-color: #4b5563 !important;
}

.dark .sidebar-responsive .list-group-item.active {
    background-color: #3b82f6 !important;
    border-color: #3b82f6 !important;
}
</style>
