<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>@yield('title', 'Admin CRM') – MotoSolution Bangladesh</title>
    
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    
    @vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body class="bg-[#0B0F19] text-slate-100 font-sans antialiased selection:bg-red-600 selection:text-white min-h-screen flex flex-col lg:flex-row">

    <!-- Admin CRM Left Sidebar -->
    <aside class="w-full lg:w-64 bg-[#111827] border-r border-white/10 shrink-0 flex flex-col justify-between" x-data="{ open: false }">
        <div>
            <!-- Header Brand -->
            <div class="h-16 px-5 flex items-center justify-between border-b border-white/10">
                <a href="{{ route('admin.dashboard') }}" class="flex items-center gap-2.5">
                    <div class="w-8 h-8 rounded-lg bg-gradient-to-br from-red-600 to-red-800 flex items-center justify-center text-white font-extrabold text-sm shadow-md">
                        M
                    </div>
                    <div>
                        <span class="font-extrabold text-white tracking-tight font-heading text-base">MOTO<span class="text-red-500">CRM</span></span>
                        <span class="block text-[9px] text-red-400 font-bold uppercase tracking-wider">Management Console</span>
                    </div>
                </a>
                <button @click="open = !open" class="lg:hidden p-2 text-slate-400 hover:text-white">
                    <i class="fa-solid fa-bars"></i>
                </button>
            </div>

            <!-- Admin Staff Card -->
            <div class="px-4 py-3 border-b border-white/10 flex items-center gap-2.5 bg-white/5">
                <div class="w-8 h-8 rounded-lg bg-red-600 text-white flex items-center justify-center font-bold text-xs">
                    {{ strtoupper(substr(Auth::user()->name, 0, 1)) }}
                </div>
                <div class="min-w-0 flex-1">
                    <p class="font-bold text-white text-xs truncate">{{ Auth::user()->name }}</p>
                    <p class="text-[10px] text-red-400 font-semibold uppercase tracking-wider truncate">{{ str_replace('_', ' ', Auth::user()->role) }}</p>
                </div>
            </div>

            <!-- Navigation Links -->
            <nav class="p-3 space-y-1 text-xs font-medium max-h-[calc(100vh-180px)] overflow-y-auto" :class="{'block': open, 'hidden': !open}" class="lg:block">
                
                <p class="px-3 pt-2 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500">Core Operations</p>
                
                <a href="{{ route('admin.dashboard') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.dashboard') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-gauge-high w-4 text-center"></i>
                    <span>Dashboard</span>
                </a>

                <a href="{{ route('admin.bids.index') }}" class="flex items-center justify-between px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.bids.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <div class="flex items-center gap-2.5">
                        <i class="fa-solid fa-gavel w-4 text-center"></i>
                        <span>Customer Bids</span>
                    </div>
                    @php $pendingBids = \App\Models\Bid::where('status', 'pending')->count(); @endphp
                    @if($pendingBids > 0)
                        <span class="text-[10px] bg-amber-500 text-slate-950 font-black px-1.5 py-0.5 rounded-full animate-pulse">{{ $pendingBids }}</span>
                    @endif
                </a>

                <a href="{{ route('admin.customers.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.customers.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-users w-4 text-center"></i>
                    <span>Customer 360 CRM</span>
                </a>

                <a href="{{ route('admin.leads.index') }}" class="flex items-center justify-between px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.leads.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <div class="flex items-center gap-2.5">
                        <i class="fa-solid fa-funnel-dollar w-4 text-center"></i>
                        <span>Leads & Inquiries</span>
                    </div>
                    @php $newLeads = \App\Models\Lead::where('status', 'new')->count(); @endphp
                    @if($newLeads > 0)
                        <span class="text-[10px] bg-blue-500 text-white font-bold px-1.5 py-0.5 rounded-full">{{ $newLeads }}</span>
                    @endif
                </a>

                <p class="px-3 pt-3 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500">Automotive Inventory</p>

                <a href="{{ route('admin.inventory.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.inventory.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-car w-4 text-center"></i>
                    <span>Ready Stock Vehicles</span>
                </a>

                <a href="{{ route('admin.auctions.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.auctions.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-satellite-dish w-4 text-center"></i>
                    <span>Japan Live Auctions</span>
                </a>

                <p class="px-3 pt-3 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500">Logistics & Revenue</p>

                <a href="{{ route('admin.orders.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.orders.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-ship w-4 text-center"></i>
                    <span>Import Tracking Orders</span>
                </a>

                <a href="{{ route('admin.payments.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.payments.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-receipt w-4 text-center"></i>
                    <span>Invoices & Payments</span>
                </a>

                <a href="{{ route('admin.calculator.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.calculator.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-calculator w-4 text-center"></i>
                    <span>Tax Rules & Landed Cost</span>
                </a>

                <p class="px-3 pt-3 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500">CMS & Growth</p>

                <a href="{{ route('admin.cms.blog') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.cms.blog*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-newspaper w-4 text-center"></i>
                    <span>Blog & Guides</span>
                </a>

                <a href="{{ route('admin.cms.faqs') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.cms.faqs*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-circle-question w-4 text-center"></i>
                    <span>FAQ Management</span>
                </a>

                <a href="{{ route('admin.seo.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.seo.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-chart-line w-4 text-center"></i>
                    <span>SEO & Metadata</span>
                </a>

                <p class="px-3 pt-3 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500">System Administration</p>

                <a href="{{ route('admin.users.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.users.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-user-shield w-4 text-center"></i>
                    <span>Staff & Roles (RBAC)</span>
                </a>

                <a href="{{ route('admin.settings.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.settings.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-sliders w-4 text-center"></i>
                    <span>System Settings</span>
                </a>

                <a href="{{ route('admin.audit-logs.index') }}" class="flex items-center gap-2.5 px-3 py-2 rounded-lg transition {{ request()->routeIs('admin.audit-logs.*') ? 'bg-red-600 text-white font-bold shadow' : 'text-slate-300 hover:bg-white/5 hover:text-white' }}">
                    <i class="fa-solid fa-clock-rotate-left w-4 text-center"></i>
                    <span>Audit Logs</span>
                </a>
            </nav>
        </div>

        <!-- Footer Bottom Action -->
        <div class="p-3 border-t border-white/10 flex items-center justify-between">
            <a href="{{ route('home') }}" target="_blank" class="text-xs text-slate-400 hover:text-white flex items-center gap-1.5 font-medium">
                <i class="fa-solid fa-arrow-up-right-from-square text-[10px]"></i> Live Website
            </a>
            <form method="POST" action="{{ route('logout') }}">
                @csrf
                <button type="submit" class="text-xs text-rose-400 hover:text-rose-300 font-semibold">
                    Logout
                </button>
            </form>
        </div>
    </aside>

    <!-- Main CRM Content Area -->
    <div class="flex-1 flex flex-col min-w-0 bg-[#0B0F19]">
        <!-- Topbar -->
        <header class="h-16 bg-[#111827] border-b border-white/10 px-6 flex items-center justify-between">
            <div class="flex items-center gap-3">
                <h2 class="text-base font-bold text-white font-heading">@yield('page_title', 'Admin Dashboard')</h2>
            </div>
            <div class="flex items-center space-x-3">
                <!-- Sync Auction Now Button -->
                <form method="POST" action="{{ route('admin.auctions.sync') }}">
                    @csrf
                    <button type="submit" class="inline-flex items-center gap-1.5 bg-white/10 hover:bg-white/15 text-slate-200 text-xs font-semibold px-3 py-1.5 rounded-lg border border-white/10 transition">
                        <i class="fa-solid fa-arrows-rotate text-emerald-400"></i>
                        <span>Sync Japan Auction Feed</span>
                    </button>
                </form>

                <a href="{{ route('admin.inventory.create') }}" class="inline-flex items-center gap-1.5 bg-red-600 hover:bg-red-700 text-white text-xs font-bold px-3 py-1.5 rounded-lg shadow transition">
                    <i class="fa-solid fa-plus"></i>
                    <span>Add Vehicle</span>
                </a>
            </div>
        </header>

        <!-- Flash alerts -->
        @if(session('success'))
            <div class="bg-emerald-600 text-white text-xs font-medium py-2.5 px-6 flex items-center gap-2">
                <i class="fa-solid fa-circle-check"></i>
                <span>{{ session('success') }}</span>
            </div>
        @endif
        @if(session('error'))
            <div class="bg-rose-600 text-white text-xs font-medium py-2.5 px-6 flex items-center gap-2">
                <i class="fa-solid fa-triangle-exclamation"></i>
                <span>{{ session('error') }}</span>
            </div>
        @endif

        <div class="p-6 lg:p-8 flex-1 overflow-y-auto">
            @yield('content')
        </div>
    </div>

    @yield('scripts')
</body>
</html>
