<nav class="navbar navbar-expand-lg navbar-light bg-white border-bottom">
    <div class="container">
        <a class="navbar-brand" href="{{ url('/') }}">
            <img src="{{ asset('assets/images/logo.png') }}" alt="Logo" height="40">
        </a>
        
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarMain">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarMain">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" href="{{ url('/') }}">Home</a>
                </li>
                
                @foreach($categories as $category)
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="{{ route('category.show', $category->slug) }}" 
                           data-bs-toggle="dropdown">
                            {{ $category->name }}
                        </a>
                        @if($category->subcategories->count() > 0)
                            <div class="dropdown-menu">
                                @foreach($category->subcategories as $subcategory)
                                    <a class="dropdown-item" href="{{ route('subcategory.show', [$category->slug, $subcategory->slug]) }}">
                                        {{ $subcategory->name }}
                                    </a>
                                @endforeach
                            </div>
                        @endif
                    </li>
                @endforeach
            </ul>

            <div class="d-flex align-items-center">
                <form class="d-flex me-3" action="{{ route('search') }}" method="GET">
                    <input class="form-control me-2" type="search" name="q" placeholder="Search products...">
                    <button class="btn btn-outline-primary" type="submit">Search</button>
                </form>

                <div class="d-flex">
                    <a href="{{ route('cart') }}" class="btn btn-link position-relative me-2">
                        <i class="bi bi-cart3 fs-5"></i>
                        <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                            {{ Cart::count() }}
                        </span>
                    </a>
                    
                    @auth
                        <div class="dropdown">
                            <button class="btn btn-link dropdown-toggle" type="button" data-bs-toggle="dropdown">
                                <i class="bi bi-person-circle fs-5"></i>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li><a class="dropdown-item" href="{{ route('profile') }}">My Profile</a></li>
                                <li><a class="dropdown-item" href="{{ route('orders') }}">My Orders</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li>
                                    <form action="{{ route('logout') }}" method="POST">
                                        @csrf
                                        <button class="dropdown-item" type="submit">Logout</button>
                                    </form>
                                </li>
                            </ul>
                        </div>
                    @else
                        <a href="{{ route('login') }}" class="btn btn-outline-primary me-2">Login</a>
                        <a href="{{ route('register') }}" class="btn btn-primary">Register</a>
                    @endauth
                </div>
            </div>
        </div>
    </div>
</nav>

@push('styles')
<style>
    /* Custom styles for mega menu on larger screens */
    @media (min-width: 992px) {
        .navbar .dropdown:hover > .dropdown-menu {
            display: block;
        }
        
        .navbar .dropdown-menu {
            margin-top: 0;
            border-radius: 0;
            border-top: 3px solid #0d6efd;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        
        .navbar .dropdown-item:hover {
            background-color: #f8f9fa;
        }
    }

    /* Mobile menu adjustments */
    @media (max-width: 991.98px) {
        .navbar-collapse {
            max-height: 80vh;
            overflow-y: auto;
        }
        
        .dropdown-menu {
            border: none;
            padding-left: 1.5rem;
        }
        
        .navbar .dropdown-item {
            padding: 0.5rem 0;
        }
    }
</style>
@endpush