<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" data-bs-theme="light">
<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', 'Dashboard') &middot; {{ config('app.name') }}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css" rel="stylesheet">
    <style>
        :root { --sidebar: 270px; --brand: #6658f6; --surface: #f5f7fb; }
        body { background: var(--surface); color: #172033; }
        .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 1040; background: #11182b; color: #aeb8cd; overflow-y: auto; transition: transform .25s ease; }
        .brand { height: 76px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
        .brand-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: linear-gradient(135deg,#6658f6,#9b6dff); }
        .sidebar .nav-link { color: #aeb8cd; border-radius: 10px; margin: 2px 12px; padding: .7rem .9rem; }
        .sidebar .nav-link:hover,.sidebar .nav-link.active { color: #fff; background: rgba(102,88,246,.22); }
        .sidebar .nav-link i { width: 25px; }
        .sidebar-label { padding: 1.1rem 1.35rem .35rem; font-size: .7rem; letter-spacing: .12em; color: #6f7a91; }
        .main { margin-left: var(--sidebar); min-height: 100vh; }
        .topbar { height: 76px; background: rgba(255,255,255,.92); backdrop-filter: blur(12px); border-bottom: 1px solid #e7eaf1; position: sticky; top: 0; z-index: 1030; }
        .content { padding: 1.75rem; }
        .metric-card,.panel { border: 0; border-radius: 16px; box-shadow: 0 5px 24px rgba(24,35,70,.06); }
        .metric-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.25rem; }
        .metric-value { font-size: 1.65rem; font-weight: 750; }
        .avatar { width: 38px; height: 38px; border-radius: 12px; display:grid; place-items:center; color:#fff; background:linear-gradient(135deg,#6658f6,#9b6dff); }
        .status-dot { width: 8px; height: 8px; display:inline-block; border-radius:50%; background:#20c997; }
        [data-bs-theme="dark"] body { --surface:#0c1220; color:#e6e9f2; }
        [data-bs-theme="dark"] .topbar,[data-bs-theme="dark"] .card { background:#151d2f!important; color:#e6e9f2; border-color:#283249; }
        @media(max-width:991.98px){ .sidebar{transform:translateX(-100%)} .sidebar.show{transform:none} .main{margin-left:0}.content{padding:1rem} }
    </style>
    @stack('styles')
</head>
<body>
<aside class="sidebar" id="sidebar">
    <div class="brand d-flex align-items-center gap-3 px-4"><span class="brand-icon"><i class="bi bi-shield-lock-fill"></i></span><div><strong>{{ config('app.name') }}</strong><div class="small text-secondary">Security Console</div></div></div>
    <div class="sidebar-label">COMMAND CENTER</div>
    <nav class="nav flex-column">
        <a class="nav-link {{ request()->routeIs('admin.dashboard') ? 'active' : '' }}" href="{{ route('admin.dashboard') }}"><i class="bi bi-grid-1x2-fill"></i> Dashboard</a>
        <a class="nav-link {{ request()->route('module') === 'users' ? 'active' : '' }}" href="{{ route('admin.modules.index','users') }}"><i class="bi bi-people"></i> User Management</a>
        <a class="nav-link {{ request()->route('module') === 'devices' ? 'active' : '' }}" href="{{ route('admin.modules.index','devices') }}"><i class="bi bi-phone"></i> Device Management</a>
        <a class="nav-link {{ request()->route('module') === 'tracking' ? 'active' : '' }}" href="{{ route('admin.modules.index','tracking') }}"><i class="bi bi-geo-alt"></i> Live Tracking</a>
        <a class="nav-link {{ request()->route('module') === 'alerts' ? 'active' : '' }}" href="{{ route('admin.modules.index','alerts') }}"><i class="bi bi-shield-exclamation"></i> Theft Alerts</a>
        <a class="nav-link {{ request()->route('module') === 'subscriptions' ? 'active' : '' }}" href="{{ route('admin.modules.index','subscriptions') }}"><i class="bi bi-gem"></i> Subscriptions</a>
        <a class="nav-link {{ request()->route('module') === 'payments' ? 'active' : '' }}" href="{{ route('admin.modules.index','payments') }}"><i class="bi bi-credit-card"></i> Wallet & Payments</a>
        <a class="nav-link {{ request()->route('module') === 'notifications' ? 'active' : '' }}" href="{{ route('admin.modules.index','notifications') }}"><i class="bi bi-bell"></i> Notifications</a>
        <a class="nav-link {{ request()->route('module') === 'reports' ? 'active' : '' }}" href="{{ route('admin.modules.index','reports') }}"><i class="bi bi-bar-chart"></i> Reports & Analytics</a>
    </nav>
    <div class="sidebar-label">ADMINISTRATION</div>
    <nav class="nav flex-column pb-4">
        <a class="nav-link {{ request()->route('module') === 'settings' ? 'active' : '' }}" href="{{ route('admin.modules.index','settings') }}"><i class="bi bi-gear"></i> Settings</a>
        <a class="nav-link {{ request()->route('module') === 'roles' ? 'active' : '' }}" href="{{ route('admin.modules.index','roles') }}"><i class="bi bi-person-lock"></i> Roles & Permissions</a>
        <a class="nav-link {{ request()->routeIs('admin.security') ? 'active' : '' }}" href="{{ route('admin.security') }}"><i class="bi bi-key"></i> Security & 2FA</a>
    </nav>
</aside>
<div class="main">
    <header class="topbar d-flex align-items-center px-3 px-lg-4 gap-3">
        <button class="btn btn-light d-lg-none" id="sidebarToggle"><i class="bi bi-list fs-5"></i></button>
        <div class="input-group d-none d-md-flex" style="max-width:420px"><span class="input-group-text bg-transparent border-end-0"><i class="bi bi-search"></i></span><input class="form-control border-start-0" placeholder="Search users, devices, IMEI..."></div>
        <div class="ms-auto d-flex align-items-center gap-2">
            <button class="btn btn-light" id="themeToggle" aria-label="Toggle dark mode"><i class="bi bi-moon-stars"></i></button>
            <button class="btn btn-light position-relative"><i class="bi bi-bell"></i><span class="position-absolute top-0 start-100 translate-middle p-1 bg-danger border border-light rounded-circle"></span></button>
            <div class="dropdown"><button class="btn d-flex align-items-center gap-2 border-0" data-bs-toggle="dropdown"><span class="avatar">{{ strtoupper(substr(auth('admin')->user()->name, 0, 1)) }}</span><span class="d-none d-md-block text-start"><strong class="small d-block">{{ auth('admin')->user()->name }}</strong><span class="text-secondary" style="font-size:.72rem">Super Administrator</span></span></button><ul class="dropdown-menu dropdown-menu-end"><li><a class="dropdown-item" href="{{ route('admin.security') }}"><i class="bi bi-shield-check me-2"></i>Security</a></li><li><hr class="dropdown-divider"></li><li><form method="POST" action="{{ route('admin.logout') }}">@csrf<button class="dropdown-item text-danger"><i class="bi bi-box-arrow-right me-2"></i>Logout</button></form></li></ul></div>
        </div>
    </header>
    <main class="content">@yield('content')</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
<script>
    document.getElementById('sidebarToggle')?.addEventListener('click',()=>document.getElementById('sidebar').classList.toggle('show'));
    const root=document.documentElement; const savedTheme=localStorage.getItem('admin-theme'); if(savedTheme) root.dataset.bsTheme=savedTheme;
    document.getElementById('themeToggle')?.addEventListener('click',()=>{root.dataset.bsTheme=root.dataset.bsTheme==='dark'?'light':'dark';localStorage.setItem('admin-theme',root.dataset.bsTheme)});
</script>
@stack('scripts')
</body>
</html>
