<!-- Navbar -->
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <!-- Left navbar links -->
    <ul class="navbar-nav justify-content-around align-items-center topFixed ">
        <li class="nav-items toggler-button">
            <a class="nav-link" data-widget="pushmenu" href="#" role="button">
                <i class="fas fa-bars" style="font-size: 18px; color: #475569;"></i>
            </a>
        </li>
        <li class=" ml-lg-3 ">
            <div class="form-row">
                <div class="col-md-12">
                    <div class="input-group rounded mt-1 userSearchWrapper" style="text-align: left">
                        <i class="fas fa-search" style="color: #9ca3af; font-size: 14px;"></i>
                        <input type="text" id="userSearch" name="id" class="form-control rounded border-none"
                            placeholder="Search user..." style="width: 160px; max-width: 200px; font-size: 12px;" />


                    </div>
                </div>
                <div class="col-md-12" id="list">

                </div>
            </div>
        </li>

        <li class="nav-tiem dropdown d-block  d-xl-none" id="toggleDropDown">

            <a class="nav-link btn m-1 " data-toggle="dropdown" href="#">
                <i class="fas fa-user-circle" style="font-size:26px; color:#475569;"></i>

            </a>

            <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right " id="toggler">


                <div class="d-flex flex-column justify-content-between align-items-start py-3 ">

                    <div class="dropdown-item drop-border">
                        <div class="d-flex justify-content-start align-items-center" style="column-gap: 15px;">

                            @if (!empty(siteinfo()))

                                @if (siteinfo()->img_url)
                                    <div class="profile-image-container">
                                        <img src="{{ asset('storage/company/' . siteinfo()->img_url) }}" alt=""
                                            class="profile-image">
                                    </div>
                                @else
                                    <div class="profile-image d-flex justify-content-center align-items-center"
                                        style="background: linear-gradient(135deg, #475569, #64748b); color: white; font-weight: 600;">
                                        {{ Str::substr(siteinfo()->name, 0, 2) }}
                                    </div>
                                @endif
                            @endif

                            <div>
                                <p
                                    style="text-transform: capitalize; font-size:16px; letter-spacing:0.02em; font-weight: 600; color: #374151;">
                                    {{ Str::limit(auth()->user()->name, '15') }}</p>
                                <small style="color: #6b7280;">{{ Auth::user()->getRoleNames()->first() }}</small>
                            </div>
                        </div>
                    </div>

                    <a href="{{ route('user.edit', Auth::user()->id) }}" class="nav-link  dropdown-item"
                        role="menuitem">
                        <i class="fas fa-user" style="color: #475569;"></i>
                        <span style="text-transform: capitalize;">My Profile</span>
                    </a>

                    @can('password-change')
                        <a href="{{ route('passwordReset', Auth::user()->email) }}" class="nav-link  dropdown-item"
                            role="menuitem">
                            <i class="fas fa-key" style="color: #f59e0b;"></i>
                            <span>Password Change</span>
                        </a>
                    @endcan
                    <a href="{{ route('settings.create') }}" class="nav-link  dropdown-item" role="menuitem">
                        <i class="fas fa-cog" style="color: #6b7280;"></i>
                        <span>Settings</span>
                    </a>

                    <form method="POST" action="{{ route('logout') }}" class="nav-link dropdown-item text-start"
                        style="cursor: pointer;">
                        @csrf
                        <i class="fas fa-sign-out-alt" style="color: #ef4444;"></i>
                        <button type="submit" class="d-inline-block" id="logout-btn"
                            style="color: #ef4444; font-weight: 500;">Logout</button>
                    </form>
                </div>

            </div>
        </li>


    </ul>

    <!-- Right navbar links -->
    <ul class="navbar-nav ml-auto flex-wrap align-items-center" style="gap: 2px;">


        <!-- Messages Dropdown Menu -->
        <li class="nav-item d-flex flex-wrap align-items-center" style="gap: 3px;">

            @can('mac-customer_create')
                <span class="nav-link border noted topbar-item">
                    <a class="noted" href="{{ route('clients.create') }}">
                        <i class="fas fa-user-plus" style="margin-right: 3px;"></i>Add Customer
                    </a>
                </span>
            @endcan

            @can('manager-balance-on-topbar')
                <span class="nav-link border noted topbar-item">
                    <a class="noted" href="{{ route('resellers.index') }}">
                        <i class="fas fa-wallet" style="margin-right: 3px;"></i>Balance: {{ managerBalance() }}
                    </a>
                    <span id="" class="text-success font-weight-bold"></span>
                </span>
            @endcan

            @can('sub-manager-balance-on-topbar')
                <span class="nav-link border noted topbar-item">
                    <a class="noted" href="{{ route('pop.index') }}">
                        <i class="fas fa-wallet" style="margin-right: 3px;"></i>Balance: {{ subManagerBalance() }}
                    </a>
                    <span id="" class="text-success font-weight-bold"></span>
                </span>
            @endcan

            @can('manager_commission_top_ber')
                @if (auth()->user()->hasRole(['Reseller Admin', 'Reseller', 'Reseller Technician']))
                    <span class="nav-link border noted topbar-item">
                        <a class="noted" href="{{ route('resellers.index') }}">
                            <i class="fas fa-coins" style="margin-right: 3px;"></i>Commission: {{ managerCommission() }}
                        </a>
                        <span id="" class="text-success font-weight-bold"></span>
                    </span>
                @endif
            @endcan

            @if (siteinfo()->online_offline_topbar == 'Yes')
                @cannot('specific_management_services')
                    <a class="noted" href="{{ route('onlineCustomer') }}">
                        <span class="nav-link border noted topbar-item">
                            <i class="fas fa-circle"
                                style="font-size: 7px; color: #22c55e; margin-right: 3px;"></i>Online:
                            <span id="topbar_online_user" class="text-success font-weight-bold"></span>
                        </span>
                    </a>
                    <a class="noted" href="{{ route('oflineCustomer') }}">
                        <span class="nav-link border noted topbar-item">
                            <i class="fas fa-circle"
                                style="font-size: 7px; color: #ef4444; margin-right: 3px;"></i>Offline:
                            <span id="topbar_offline_user" class="text-danger font-weight-bold"></span>
                        </span>
                    </a>
                @endcannot
            @endif
            @can('radius_online_customer_reset')
                @if (!checkAPI())
                    <a href="{{ route('delete-radius-online-customer') }}" class="nav-link border noted topbar-item topbar-btn-colored"
                        style="background: linear-gradient(135deg, #ef4444, #dc2626) !important; color:#FFFFFF; border-color: rgba(239, 68, 68, 0.3) !important;">
                        <i class="fas fa-trash-alt" style="margin-right: 2px;"></i>Delete Online Customer
                    </a>
                @endif
            @endcan
            @if (checkAPI() == false)
                @can('refresh')
                    <a class="nav-link border noted topbar-item topbar-btn-colored" href="{{ route('refresh_session') }}"
                        style="background: linear-gradient(135deg, #14b8a6, #0d9488) !important; color:#FFFFFF; border-color: rgba(20, 184, 166, 0.3) !important;">
                        <i class="fas fa-sync-alt" style="margin-right: 2px;"></i>Refresh
                    </a>
                @endcan
            @endif

            @if (checkSettings('store') == 'enable')
                @hasanyrole('Reseller Admin|Reseller|Sub Reseller')
                @else
                    <a class="nav-link border noted topbar-item topbar-btn-colored" href="{{ route('requisition.create') }}"
                        style="background: linear-gradient(135deg, #f97316, #ea580c) !important; color:#FFFFFF; border-color: rgba(249, 115, 22, 0.3) !important;">
                        <i class="fas fa-clipboard-list" style="margin-right: 2px;"></i>Requisition
                    </a>
                @endhasanyrole
            @endif
            @if (checksettings('new-line-request') == 'enable')
                <span class="nav-link border d-flex align-items-center noted">
                    <a class="nav-link" href="{{ route('new-line-request.index') }}"style="padding: 8px;">
                        <i class="fas fa-plus-circle" aria-hidden="true"
                            style="font-size: 22px; color: #475569;"></i>
                        <span class="badge badge-danger navbar-badge text-light">
                            {{ newClientRequestCount() }}
                        </span>
                    </a>
                </span>

                <span class="nav-link border d-flex align-items-center noted">
                    <a class="nav-link" href="{{ route('newline.newIndex', ['multi_router' => 'Yes', 'done_status' => 'No', 'support_done' => 1]) }}" style="padding: 8px;" title="Multi Router Yes Support Pending">
                        <span style="font-size: 22px;">🔗</span>
                        <span class="badge badge-danger navbar-badge text-light">
                            {{ newLineRequestMultiRouterYesSupportDoneYesPendingCount() }}
                        </span>
                    </a>
                </span>
            @endif


            <!-- Notifications Dropdown Menu -->
            @if (checkSettings('store') == 'enable')
                @hasrole('Admin|Store Manager')
                    <span class="nav-link border d-flex align-items-center noted">
                        <a class="nav-link" data-toggle="dropdown" href="#" data-toggle="tooltip"
                            data-placement="bottom" title="Stock Reminder ">

                            <i class="fas fa-clock" style="font-size: 20px; color: #f59e0b;"></i>
                            <span class="badge badge-warning navbar-badge text-light">
                                {{ \App\Classes\AvailableStockCalculation::stock_alert() }}
                            </span>
                        </a>
                    </span>
                @endhasrole
            @endif

            <span class="nav-link border d-flex align-items-center noted">
                <a class="nav-link  m-1" data-toggle="dropdown" href="#">
                    <i class="fas fa-bell" style="font-size: 20px; color: #475569;"></i>
                    @if (checkSettings('local-user-first-approve') == 'enable')
                        <span class="badge badge-warning navbar-badge text-light">
                            {{ \App\Services\ClientServices::customerList('pendingCustomer')->count() }}
                            @can('local-user-first-approve')
                                /{{ \App\Services\ClientServices::customerList('finalPendingCustomer')->count() }}
                            </span>
                        @endcan
                    @else
                        <span class="badge  navbar-badge "
                            style="background: linear-gradient(135deg, #f43f5e, #e11d48) !important; color:white; font-size:12px !important;">
                            {{ \App\Services\ClientServices::customerList('pendingCustomer')->count() }}
                        </span>
                    @endif
                </a>

                <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">

                    <a href="{{ route('pendingCustomer') }}" class="nav-link d-block dropdown-item" role="menuitem">
                        <i class="fas fa-user-clock" style="color: #475569;"></i> Pending Customer
                        <span class="badge text-light"
                            style="background: linear-gradient(135deg, #f43f5e, #e11d48); margin-left: 8px;">
                            {{ \App\Services\ClientServices::customerList('pendingCustomer')->count() }}
                        </span>
                    </a>
                    @if (checkSettings('local-user-first-approve') == 'enable')
                        @can('local-user-first-approve')
                            <a href="{{ route('pendingCustomer') }}" class="nav-link d-block dropdown-item"
                                role="menuitem">
                                <i class="fas fa-user-check" style="color: #f59e0b;"></i>Final Pending Customer
                                <span class="badge badge-warning text-light" style="margin-left: 8px;">
                                    {{ \App\Services\ClientServices::customerList('finalPendingCustomer')->count() }}
                                </span>
                            </a>
                        @endcan
                    @endif
                </div>
            </span>
        </li>



        <li class="nav-item px-2 d-flex align-items-center">
            <button class="theme-toggle" id="themeToggle" title="Toggle dark mode">
                <i class="fas fa-sun theme-icon sun-icon"></i>
                <i class="fas fa-moon theme-icon moon-icon"></i>
            </button>
        </li>




        <li class="nav-tiem dropdown d-none d-xl-block " id="togglerIcon-desktop">

            <a class="nav-link  m-1 border " data-toggle="dropdown" href="#" id="toggleDropDown">
                <i class="fas fa-user-circle" style="font-size:20px; color: #475569;"></i>
                <span style="text-transform: capitalize;"
                    class="admin-name">{{ Str::limit(auth()->user()->name, '10') }}</span>
                <i class="fas fa-chevron-down" style="font-size: 10px; color: #9ca3af;"></i>
            </a>

            <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right " id="toggler">


                <div class="d-flex flex-column justify-content-between align-items-start py-3 "
                    style="row-gap: 2.5px;">

                    <div class="dropdown-item drop-border">
                        <div class="d-flex justify-content-start align-items-center" style="column-gap: 15px;">

                            @if (!empty(siteinfo()))

                                @if (siteinfo()->img_url)
                                    <div class="profile-image-container">
                                        <img src="{{ asset('storage/company/' . siteinfo()->img_url) }}"
                                            alt="" class="profile-image">
                                    </div>
                                @else
                                    <div class="profile-image d-flex justify-content-center align-items-center"
                                        style="background: linear-gradient(135deg, #475569, #64748b); color: white; font-weight: 600;">
                                        {{ Str::substr(siteinfo()->name, 0, 2) }}
                                    </div>
                                @endif
                            @endif

                            <div>
                                <p
                                    style="text-transform: capitalize; font-size:16px; letter-spacing:0.02em; font-weight: 600; color: #374151;">
                                    {{ Str::limit(auth()->user()->name, '15') }}</p>
                                <small style="color: #6b7280;">{{ Auth::user()->getRoleNames()->first() }}</small>
                            </div>
                        </div>
                    </div>

                    <a href="{{ route('user.edit', Auth::user()->id) }}" class="nav-link  dropdown-item"
                        role="menuitem">
                        <i class="fas fa-user" style="color: #475569;"></i>
                        <span style="text-transform: capitalize;">My Profile</span>
                    </a>

                    @can('password-change')
                        <a href="{{ route('passwordReset', Auth::user()->email) }}" class="nav-link  dropdown-item"
                            role="menuitem">
                            <i class="fas fa-key" style="color: #f59e0b;"></i>
                            <span>Password Change</span>
                        </a>
                    @endcan

                    <form method="POST" action="{{ route('logout') }}" class="nav-link dropdown-item text-start"
                        style="cursor: pointer;">
                        @csrf
                        <i class="fas fa-sign-out-alt" style="color: #ef4444;"></i>
                        <button type="submit" class="d-inline-block" id="logout-btn"
                            style="color: #ef4444; font-weight: 500;">Logout</button>
                    </form>
                </div>

            </div>
        </li>


    </ul>
</nav>
<!-- /.navbar -->


<style>
    .dropdown-menu-right {
        right: -30px;
    }

    .dropdown-menu-lg {
        max-width: 260px;
        min-width: 240px;
    }

    #logout-btn {
        border: none;
        background: inherit;
        cursor: pointer;
    }

    nav {
        font-family: "Montserrat", sans-serif !important;
        font-weight: 500;
    }

    .navbar-expand .navbar-nav .dropdown-menu {
        top: 54px;
    }

    .icon-color {
        color: #475569;
    }

    .dropdown-menu>a {
        font-size: 14px;
    }

    .drop-border {
        border-bottom: 1px solid rgba(99, 102, 241, 0.15) !important;
        background: linear-gradient(135deg, rgba(249, 250, 251, 0.8), rgba(243, 244, 246, 0.6)) !important;
    }

    .profile-image {
        width: 38px;
        height: 38px;
        border-radius: 100%;
        border: 2px solid rgba(99, 102, 241, 0.3);
        object-fit: cover;
    }

    .profile-image-container {
        width: 42px;
        height: 42px;
        display: flex;
        justify-content: center;
        align-items: center;
        background: linear-gradient(135deg, #475569, #64748b);
        border-radius: 50%;
        padding: 2px;
    }

    .toggler-button {
        margin-left: 10px !important;
    }

    @media(max-width:1400px) {
        .admin-name {
            display: none !important;
        }
    }

    .noted {
        padding-right: 2.5px !important;
        padding-left: 2.5px !important;
    }

    .noted a {
        color: inherit;
        text-decoration: none;
    }

    #darkmode-toggle {
        background: transparent;
        color: #666;
        transition: all 0.3s ease;
        margin: 0 10px;
    }

    #darkmode-toggle:hover {
        background: rgba(0, 0, 0, 0.1);
    }

    #darkmode-toggle.active {
        color: #ffdd57;
    }

    .dark-icon,
    .light-icon {
        font-size: 18px;
    }

    .dark-mode-text {
        font-size: 14px;
        font-weight: 500;
    }

    #darkmode-toggle.active .dark-icon {
        display: none;
    }

    #darkmode-toggle.active .light-icon {
        display: inline-block !important;
    }

    /* Modern Dark Mode Toggle Styles */
    .dark-mode-toggle-wrapper {
        display: flex;
        align-items: center;
    }

    .dark-mode-toggle {
        background: transparent;
        border: none;
        padding: 0;
        cursor: pointer;
        position: relative;
        outline: none;
    }

    .toggle-track {
        width: 50px;
        height: 24px;
        background-color: #f3f4f6;
        /* Light gray background */
        border-radius: 12px;
        position: relative;
        transition: background-color 0.3s ease;
        display: flex;
        align-items: center;
        padding: 0 4px;
    }

    .toggle-icons {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        z-index: 1;
    }

    .toggle-icons i {
        font-size: 12px;
        color: #64748b;
        transition: color 0.3s ease;
    }

    .toggle-thumb {
        width: 20px;
        height: 20px;
        background-color: white;
        border-radius: 50%;
        position: absolute;
        left: 2px;
        transition: transform 0.3s ease;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    }

    /* Active State */
    #darkmode-toggle.active .toggle-track {
        background-color: #4f46e5;
        /* Modern indigo color */
    }

    #darkmode-toggle.active .toggle-thumb {
        transform: translateX(26px);
    }

    #darkmode-toggle.active .toggle-icons .light-icon {
        color: #fef08a;
        /* Soft yellow/amber */
    }

    #darkmode-toggle.active .toggle-icons .dark-icon {
        color: #94a3b8;
        /* Slate gray */
    }

    #darkmode-toggle:not(.active) .toggle-icons .light-icon {
        color: #94a3b8;
        /* Slate gray */
    }

    #darkmode-toggle:not(.active) .toggle-icons .dark-icon {
        color: #334155;
        /* Darker slate */
    }

    /* Hover Effects */
    .toggle-track:hover {
        opacity: 0.9;
    }

    /* Focus State */
    #darkmode-toggle:focus .toggle-track {
        box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.4);
        /* Matching indigo with opacity */
    }

    /* Animation */
    @keyframes toggleMove {
        0% {
            transform: scale(1);
        }

        50% {
            transform: scale(0.9);
        }

        100% {
            transform: scale(1);
        }
    }

    #darkmode-toggle:active .toggle-thumb {
        animation: toggleMove 0.2s ease;
    }

    /* Responsive */
    @media (max-width: 768px) {
        .toggle-track {
            width: 44px;
            height: 22px;
        }

        .toggle-thumb {
            width: 18px;
            height: 18px;
        }

        #darkmode-toggle.active .toggle-thumb {
            transform: translateX(22px);
        }
    }

    /* Updated dark mode toggle styles */
    .theme-toggle {
        padding: 8px;
        border-radius: 8px;
        background: transparent;
        border: none;
        cursor: pointer;
        transition: all 0.2s;
        position: relative;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .theme-toggle:hover {
        background: rgba(67, 97, 238, 0.05);
    }

    .theme-icon {
        font-size: 1.25rem;
        position: absolute;
        transition: opacity 0.2s ease, transform 0.2s ease;
    }

    .sun-icon {
        color: #fbbf24;
        opacity: 0;
        transform: scale(0.5);
    }

    .moon-icon {
        color: #64748b;
        opacity: 1;
        transform: scale(1);
    }

    /* Dark mode states */
    .theme-toggle.dark-mode .sun-icon {
        opacity: 1;
        transform: scale(1);
    }

    .theme-toggle.dark-mode .moon-icon {
        opacity: 0;
        transform: scale(0.5);
    }

    /* Hover states */
    .theme-toggle:hover .moon-icon {
        color: #4338ca;
    }

    .theme-toggle.dark-mode:hover .sun-icon {
        color: #f59e0b;
    }

    /* ── Topbar responsive fixes ── */
    .main-header.navbar {
        flex-wrap: wrap !important;
        padding: 4px 8px !important;
        height: auto !important;
    }

    .main-header .navbar-nav.topFixed {
        flex-shrink: 1;
        min-width: 0;
    }

    .main-header .navbar-nav.topFixed > li {
        flex-shrink: 0;
    }

    .main-header .nav-link {
        padding: 2px 5px !important;
        font-size: 12px;
    }

    .main-header .nav-link.border {
        border-radius: 6px;
    }

    .topbar-item {
        font-size: 12px !important;
        padding: 1px 4px !important;
        line-height: 1.4;
    }

    .topbar-btn-colored {
        font-size: 11px !important;
        padding: 1px 5px !important;
        border-radius: 4px;
    }

    .topbar-btn-colored i {
        font-size: 10px !important;
    }

    @media (max-width: 1600px) {
        .main-header .nav-link {
            font-size: 11px;
            padding: 2px 4px !important;
        }

        .main-header .toggler-button {
            margin-left: 4px !important;
        }

        #userSearch {
            width: 150px !important;
            max-width: 170px !important;
            font-size: 12px;
        }
    }

    @media (max-width: 1200px) {
        .main-header .nav-link {
            font-size: 10px;
            padding: 2px 3px !important;
        }

        #userSearch {
            width: 120px !important;
            max-width: 140px !important;
        }

        .main-header .ml-lg-5 {
            margin-left: 0.5rem !important;
        }
    }

    @media (max-width: 992px) {
        #userSearch {
            width: 100px !important;
            max-width: 120px !important;
        }

        .main-header .nav-link {
            font-size: 10px;
            padding: 1px 3px !important;
        }
    }

    @media (max-width: 768px) {
        .main-header .navbar-nav.topFixed {
            flex: 0 0 auto;
        }

        #userSearch {
            width: 80px !important;
            max-width: 100px !important;
            font-size: 10px;
        }

        .main-header .nav-link {
            font-size: 9px;
            padding: 1px 2px !important;
        }

        .main-header .theme-toggle {
            width: 32px;
            height: 32px;
        }
    }
</style>
