<!-- Google Fonts -->
<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=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">

<?php
    $user = auth()->user();
    $lowStockRequestItemCount = $user && $user->role === 'sekretariat'
        ? \App\Models\RequestItem::query()
            ->whereColumn('stock', '<=', 'min_stock')
            ->count()
        : 0;
    $verificationCount = 0;

    if ($user) {
        $borrowStatus = match ($user->role) {
            'staff_bidang' => 'pending',
            'sekretariat' => 'pending',
            default => null,
        };

        if ($borrowStatus) {
            $verificationCount += \App\Models\BorrowRequest::where('status', $borrowStatus)->count();
        } elseif ($user->role === 'kepala_bidang') {
            $verificationCount += \App\Models\BorrowRequest::whereIn('status', ['staff_approved', 'sekretariat_approved'])->count();
        }

        if (in_array($user->role, ['staff_bidang', 'sekretariat'], true)) {
            $verificationCount += \App\Models\RoomBooking::where('status', 'pending')->count();
            $verificationCount += \App\Models\VehicleBooking::where('status', 'pending')->count();
        } elseif ($user->role === 'kepala_bidang') {
            $verificationCount += \App\Models\RoomBooking::whereIn('status', ['staff_approved', 'sekretariat_approved'])->count();
            $verificationCount += \App\Models\VehicleBooking::whereIn('status', ['staff_approved', 'sekretariat_approved'])->count();
        }

        if ($user->role === 'sekretariat') {
            $verificationCount += \App\Models\BorrowRequest::where('status', 'return_pending')->count();
        }

        if ($user->role === 'staff_bidang') {
            $verificationCount += \App\Models\ItemRequest::where('status', 'pending')->count();
        } elseif ($user->role === 'kepala_bidang') {
            $verificationCount += \App\Models\ItemRequest::where('status', 'staff_approved')->count();
        }
    }
?>

<style>
    :root {
        --font-family: 'Inter', sans-serif;
        --sidebar-bg: #eaf2ff;
        --sidebar-panel: rgba(255, 255, 255, 0.9);
        --rail-bg:
            radial-gradient(circle at 50% 0%, rgba(79, 70, 229, 0.16), transparent 28%),
            radial-gradient(circle at 50% 100%, rgba(56, 189, 248, 0.18), transparent 30%),
            linear-gradient(180deg, #f7faff 0%, #edf5ff 46%, #e9f0ff 100%);
        --panel-bg:
            radial-gradient(circle at 12% 8%, rgba(79, 70, 229, 0.14), transparent 24%),
            radial-gradient(circle at 94% 4%, rgba(56, 189, 248, 0.16), transparent 26%),
            radial-gradient(circle at 18% 92%, rgba(37, 99, 235, 0.10), transparent 24%),
            linear-gradient(180deg, #fbfdff 0%, #f0f6ff 48%, #eaf2ff 100%);
        --text-primary: #18233f;
        --text-secondary: #70819f;
        --border-color: rgba(216, 226, 243, 0.95);
        --hover-bg: rgba(232, 240, 255, 0.86);
        --active-bg: linear-gradient(135deg, #4f46e5 0%, #2563eb 100%);
        --active-text: #ffffff;
        --shadow-soft: 0 24px 45px rgba(148, 163, 184, 0.18);
        --shadow-card: 0 14px 28px rgba(148, 163, 184, 0.12);
        --shadow-active: 0 16px 24px rgba(79, 70, 229, 0.20);
    }

    .sidebar-shell {
        font-family: var(--font-family);
        flex: 0 0 294px;
        width: 294px;
        height: 100vh;
        position: sticky;
        top: 0;
        align-self: flex-start;
        padding: 0;
        background: var(--sidebar-bg);
        box-sizing: border-box;
        z-index: 50;
        overflow: hidden;
        transition: width 0.28s ease, flex-basis 0.28s ease;
    }

    .sidebar-shell.ready {
        visibility: visible;
    }

    .sidebar {
        display: block;
        height: 100%;
        padding: 14px 12px;
    }

    .sidebar-rail,
    .sidebar-panel {
        border: 1px solid rgba(255, 255, 255, 0.78);
        box-shadow: var(--shadow-soft);
        backdrop-filter: blur(10px);
    }

    .sidebar-rail {
        background: var(--rail-bg);
        border-radius: 28px;
        padding: 18px 10px;
        display: none;
        flex-direction: column;
        align-items: center;
        gap: 10px;
        height: 100%;
        position: relative;
        overflow: hidden;
    }

    .sidebar-panel {
        background: var(--panel-bg);
        border-radius: 30px;
        padding: 18px;
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
        position: relative;
    }

    .sidebar-rail::before,
    .sidebar-panel::before {
        content: "";
        position: absolute;
        inset: 0;
        pointer-events: none;
        background:
            linear-gradient(135deg, rgba(255, 255, 255, 0.74), transparent 34%),
            linear-gradient(315deg, rgba(79, 70, 229, 0.08), transparent 42%);
    }

    .sidebar-rail > *,
    .sidebar-panel > * {
        position: relative;
        z-index: 1;
    }

    .sidebar-star {
        width: 36px;
        height: 36px;
        border-radius: 14px;
        display: grid;
        place-items: center;
        color: #4338ca;
        background: linear-gradient(135deg, #ffffff, #edf4ff);
        box-shadow: var(--shadow-card);
        border: 1px solid var(--border-color);
        flex-shrink: 0;
    }

    .sidebar-rail-nav {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        width: 100%;
    }

    .sidebar-rail-link {
        position: relative;
        width: 36px;
        height: 36px;
        display: grid;
        place-items: center;
        border-radius: 14px;
        color: var(--text-secondary);
        border: 1px solid transparent;
        text-decoration: none;
        transition: all 0.2s ease;
    }

    .sidebar-rail-link:hover {
        background: var(--hover-bg);
        color: var(--text-primary);
        border-color: var(--border-color);
        transform: translateY(-1px);
    }

    .sidebar-rail-link.active {
        color: var(--active-text);
        background: var(--active-bg);
        box-shadow: var(--shadow-active);
    }

    .sidebar-rail-divider {
        width: 18px;
        height: 1px;
        margin: 4px 0;
        background: #d8e2f3;
    }

    .sidebar-rail-bottom {
        margin-top: auto;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .sidebar-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 14px;
    }

    .sidebar-title-label {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        color: var(--text-primary);
        font-size: 12px;
        font-weight: 800;
        letter-spacing: 0.04em;
    }

    .sidebar-title-label::before {
        content: "✦";
        font-size: 10px;
    }

    .brand {
        margin-top: 10px;
        font-size: 28px;
        font-weight: 800;
        line-height: 1;
        letter-spacing: -0.04em;
        color: var(--text-primary);
    }

    .brand-sub {
        margin-top: 6px;
        font-size: 12px;
        color: var(--text-secondary);
        letter-spacing: 0.04em;
    }

    .close-btn {
        display: none;
        width: 34px;
        height: 34px;
        border-radius: 12px;
        border: 1px solid var(--border-color);
        background: #ffffff;
        color: var(--text-secondary);
        cursor: pointer;
    }

    .desktop-toggle-btn {
        width: 34px;
        height: 34px;
        border-radius: 12px;
        border: 1px solid var(--border-color);
        background: #ffffff;
        color: var(--text-secondary);
        display: grid;
        place-items: center;
        cursor: pointer;
        box-shadow: var(--shadow-card);
        transition: all 0.2s ease;
    }

    .desktop-toggle-btn:hover {
        color: var(--text-primary);
        background: var(--hover-bg);
    }

    .profile-card {
        margin-bottom: 16px;
        padding: 14px 14px 12px;
        border-radius: 18px;
        border: 1px solid var(--border-color);
        background:
            radial-gradient(circle at top right, rgba(79, 70, 229, 0.10), transparent 34%),
            linear-gradient(135deg, rgba(255, 255, 255, 0.88), rgba(239, 246, 255, 0.82));
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88);
    }

    .profile-card h4 {
        margin: 0;
        font-size: 15px;
        font-weight: 700;
        color: var(--text-primary);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .profile-card p {
        margin: 4px 0 0;
        font-size: 12px;
        color: var(--text-secondary);
    }

    .role-pill {
        display: inline-flex;
        margin-top: 10px;
        padding: 6px 11px;
        border-radius: 999px;
        background: #ffffff;
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        font-size: 10px;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .nav {
        display: flex;
        flex-direction: column;
        gap: 6px;
        overflow-y: auto;
        padding-right: 4px;
        min-height: 0;
    }

    .nav::-webkit-scrollbar {
        width: 4px;
    }

    .nav::-webkit-scrollbar-thumb {
        background: #dbe4f4;
        border-radius: 999px;
    }

    .nav-group-label {
        margin: 10px 8px 4px;
        color: #97a6bf;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .nav a {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        border-radius: 14px;
        color: var(--text-secondary);
        text-decoration: none;
        border: 1px solid transparent;
        transition: all 0.2s ease;
    }

    .nav a:hover {
        background: var(--hover-bg);
        color: var(--text-primary);
        border-color: #e3eaf7;
    }

    .nav a.active {
        background: var(--active-bg);
        color: var(--active-text);
        box-shadow: var(--shadow-active);
    }

    .nav a.active .nav-icon {
        stroke: #ffffff;
    }

    .nav-copy {
        display: flex;
        flex-direction: column;
        gap: 2px;
        min-width: 0;
        flex: 1;
    }

    .nav-title {
        font-size: 13px;
        font-weight: 700;
        line-height: 1.2;
    }

    .nav-meta {
        font-size: 11px;
        color: currentColor;
        opacity: 0.62;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-icon {
        width: 18px;
        height: 18px;
        stroke-width: 1.9;
        flex-shrink: 0;
    }

    .nav-trailing {
        margin-left: auto;
        font-size: 11px;
        font-weight: 700;
        opacity: 0.62;
    }

    .nav-badge {
        margin-left: auto;
        min-width: 22px;
        height: 22px;
        padding: 0 7px;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: #ffffff;
        color: #dc2626;
        border: 1px solid #fecaca;
        font-size: 11px;
        font-weight: 800;
        box-shadow: 0 8px 16px rgba(248, 113, 113, 0.12);
    }

    .nav-badge.danger,
    .rail-badge {
        background: #dc2626;
        color: #ffffff;
        border-color: #ef4444;
        box-shadow: 0 10px 18px rgba(220, 38, 38, 0.22);
    }

    .rail-badge {
        position: absolute;
        top: -6px;
        right: -6px;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid #ffffff;
        font-size: 10px;
        font-weight: 900;
        line-height: 1;
    }

    .sidebar-rail-link.alert,
    .nav a.alert {
        color: #dc2626;
        background: #fef2f2;
        border-color: #fecaca;
    }

    .sidebar-rail-link.alert:hover,
    .nav a.alert:hover {
        color: #b91c1c;
        background: #fee2e2;
        border-color: #fca5a5;
    }

    .nav a.alert .nav-meta {
        opacity: 0.78;
    }

    .sidebar-rail-link.alert.active,
    .nav a.alert.active {
        color: #ffffff;
        background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
        border-color: #ef4444;
        box-shadow: 0 16px 24px rgba(220, 38, 38, 0.22);
    }

    .sidebar-footer {
        margin-top: 14px;
        padding-top: 14px;
        border-top: 1px solid var(--border-color);
    }

    .logout-btn {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        border-radius: 14px;
        border: 1px solid var(--border-color);
        background: #ffffff;
        color: var(--text-secondary);
        font-family: inherit;
        font-size: 13px;
        font-weight: 700;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .logout-btn:hover {
        color: #dc2626;
        border-color: #fecaca;
        background: #fff5f5;
    }

    .mobile-toggle {
        display: none;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 40;
        width: 42px;
        height: 42px;
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid var(--border-color);
        box-shadow: 0 16px 24px rgba(148, 163, 184, 0.16);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.4);
        z-index: 45;
        backdrop-filter: blur(4px);
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
    }

    .sidebar-shell.collapsed {
        flex-basis: 92px;
        width: 92px;
    }

    .sidebar-shell.collapsed .sidebar-rail {
        display: flex;
    }

    .sidebar-shell.collapsed .sidebar-panel {
        display: none;
    }

    @media (max-width: 1180px) {
        .sidebar-shell {
            flex-basis: 280px;
            width: 280px;
        }

        .sidebar-panel {
            padding: 16px;
        }
    }

    @media (max-width: 1024px) {
        .mobile-toggle {
            display: grid;
            place-items: center;
        }

        .sidebar-shell {
            position: fixed;
            left: 0;
            top: 0;
            transform: translateX(-100%);
            transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            width: 294px;
            flex-basis: 294px;
            height: 100vh;
        }

        .sidebar-shell.active {
            transform: translateX(0);
        }

        .sidebar-shell.collapsed {
            width: 294px;
            flex-basis: 294px;
        }

        .sidebar-shell.collapsed .sidebar-rail {
            display: none;
        }

        .sidebar-shell.collapsed .sidebar-panel {
            display: flex;
        }

        .close-btn {
            display: grid;
            place-items: center;
        }

        .desktop-toggle-btn {
            display: none;
        }

        .sidebar-overlay {
            display: block;
            pointer-events: none;
        }

        .sidebar-overlay.active {
            pointer-events: auto;
        }
    }
</style>

<button class="mobile-toggle" onclick="toggleSidebar()">
    <svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M4 6h12M4 10h12M4 14h12" stroke-linecap="round" />
    </svg>
</button>

<div class="sidebar-overlay" onclick="toggleSidebar()"></div>

<aside class="sidebar-shell" id="appSidebar">
    <div class="sidebar">
        <div class="sidebar-rail">
            <button type="button" class="sidebar-star" onclick="toggleSidebarCollapse()" aria-label="Buka sidebar">
                <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.8" viewBox="0 0 24 24">
                    <path d="M9 6l6 6-6 6" stroke-linecap="round" stroke-linejoin="round" />
                </svg>
            </button>

            <nav class="sidebar-rail-nav">
                <a href="<?php echo e(route('dashboard')); ?>" class="sidebar-rail-link <?php echo e(request()->routeIs('dashboard') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                </a>
                <a href="<?php echo e(route('items.index')); ?>" class="sidebar-rail-link <?php echo e(request()->is('items*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                </a>
                <a href="<?php echo e(route('borrow.index')); ?>" class="sidebar-rail-link <?php echo e(request()->is('borrow*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                </a>
                <a href="<?php echo e(route('item-requests.index')); ?>" class="sidebar-rail-link <?php echo e(request()->is('item-requests*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M9 12h6m-6 4h6M7 4h10a2 2 0 012 2v12a2 2 0 01-2 2H7a2 2 0 01-2-2V6a2 2 0 012-2z" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                </a>
                <a href="<?php echo e(route('returns.index')); ?>" class="sidebar-rail-link <?php echo e(request()->is('returns*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                </a>
                <a href="<?php echo e(route('history.index')); ?>" class="sidebar-rail-link <?php echo e(request()->is('history*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                </a>
                <a href="<?php echo e(route('rooms.index')); ?>" class="sidebar-rail-link <?php echo e(request()->routeIs('rooms.*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke="currentColor" fill="none">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
                    </svg>
                </a>
                <a href="<?php echo e(route('vehicles.index')); ?>" class="sidebar-rail-link <?php echo e(request()->routeIs('vehicles.*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke="currentColor" fill="none">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M8.25 18.75a1.5 1.5 0 0 1-3 0m13.5 0a1.5 1.5 0 0 1-3 0m-13.5 0H5.25A2.25 2.25 0 0 1 3 16.5V15.75m14.25 3h.75A2.25 2.25 0 0 0 21 16.5v-7.5a2.25 2.25 0 0 0-2.25-2.25h-3a1.125 1.125 0 0 1-1.125-1.125V4.5a2.25 2.25 0 0 0-2.25-2.25h-3a2.25 2.25 0 0 0-2.25 2.25v.75m10.5 3.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM3.75 13.5h16.5a1.5 1.5 0 0 1 1.5 1.5v2.25a1.5 1.5 0 0 1-1.5 1.5H3.75a1.5 1.5 0 0 1-1.5-1.5V15a1.5 1.5 0 0 1 1.5-1.5Z" />
                    </svg>
                </a>
                <?php if(in_array($user->role, ['staff_bidang', 'kepala_bidang', 'sekretariat'])): ?>
                    <?php if(in_array($user->role, ['staff_bidang', 'kepala_bidang'])): ?>
                        <a href="<?php echo e(route('admin.request-items.index')); ?>" class="sidebar-rail-link <?php echo e(request()->is('admin/request-items*') ? 'active' : ''); ?>">
                            <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" stroke-linecap="round" stroke-linejoin="round" />
                            </svg>
                        </a>
                    <?php endif; ?>
                    <a href="<?php echo e(route('verification.index')); ?>" class="sidebar-rail-link <?php echo e(request()->is('verification*') ? 'active' : ''); ?> <?php echo e($verificationCount > 0 ? 'alert' : ''); ?>">
                        <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" stroke-linecap="round" stroke-linejoin="round" />
                        </svg>
                        <?php if($verificationCount > 0): ?>
                            <span class="rail-badge"><?php echo e($verificationCount > 99 ? '99+' : $verificationCount); ?></span>
                        <?php endif; ?>
                    </a>
                    <?php if(in_array($user->role, ['kepala_bidang', 'sekretariat'])): ?>
                        <a href="<?php echo e(Route::has('reports.index') ? route('reports.index') : '#'); ?>" class="sidebar-rail-link <?php echo e(request()->is('reports*') ? 'active' : ''); ?>">
                            <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M9 17v-2m3 2v-4m3 2v-6m2 9H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
                            </svg>
                        </a>
                    <?php endif; ?>
                <?php endif; ?>
            </nav>

            <div class="sidebar-rail-divider"></div>

            <div class="sidebar-rail-bottom">
                <a href="<?php echo e(Route::has('profile.index') ? route('profile.index') : '#'); ?>" class="sidebar-rail-link <?php echo e(request()->is('profile*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
                    </svg>
                </a>
                <button type="button" class="sidebar-rail-link" onclick="document.getElementById('sidebarLogoutForm').requestSubmit()">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                </button>
            </div>
        </div>

        <div class="sidebar-panel">
            <div class="sidebar-header">
                <div>
                    <div class="sidebar-title-label">Menu</div>
                    <div class="brand">Sipian</div>
                    <div class="brand-sub">Management Portal</div>
                </div>
                <button type="button" class="desktop-toggle-btn" onclick="toggleSidebarCollapse()" aria-label="Tutup sidebar">
                    <svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2">
                        <path d="M11 5L5 9l6 4M5 9h8" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                </button>
                <button class="close-btn" onclick="toggleSidebar()">
                    <svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2">
                        <path d="M13 5L5 13M5 5l8 8" stroke-linecap="round" />
                    </svg>
                </button>
            </div>

            <div class="profile-card">
                <h4><?php echo e($user->name ?? 'Guest'); ?></h4>
                <p><?php echo e(data_get($user, 'divisi.nama', $user->divisi ?? 'General')); ?></p>
                <div class="role-pill"><?php echo e(ucfirst(str_replace('_', ' ', $user->role ?? 'user'))); ?></div>
            </div>

            <nav class="nav">
                <div class="nav-group-label">Utama</div>

                <a href="<?php echo e(route('dashboard')); ?>" class="<?php echo e(request()->routeIs('dashboard') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Dashboard</span>
                        <span class="nav-meta">Ringkasan sistem</span>
                    </span>
                </a>

                <a href="<?php echo e(route('items.index')); ?>" class="<?php echo e(request()->is('items*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Stok Barang</span>
                        <span class="nav-meta">Inventaris aktif</span>
                    </span>
                </a>

                <a href="<?php echo e(route('borrow.index')); ?>" class="<?php echo e(request()->is('borrow*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Peminjaman Barang</span>
                        <span class="nav-meta">Buat peminjaman</span>
                    </span>
                </a>

                <a href="<?php echo e(route('item-requests.index')); ?>" class="<?php echo e(request()->is('item-requests*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M9 12h6m-6 4h6M7 4h10a2 2 0 012 2v12a2 2 0 01-2 2H7a2 2 0 01-2-2V6a2 2 0 012-2z" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Permintaan Barang</span>
                        <span class="nav-meta">Pengajuan kebutuhan</span>
                    </span>
                </a>

                <a href="<?php echo e(route('returns.index')); ?>" class="<?php echo e(request()->is('returns*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Peminjaman Aktif</span>
                        <span class="nav-meta">Sedang berjalan</span>
                    </span>
                </a>

                <a href="<?php echo e(route('history.index')); ?>" class="<?php echo e(request()->is('history*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" stroke-linecap="round" stroke-linejoin="round" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Riwayat Selesai</span>
                        <span class="nav-meta">Arsip transaksi</span>
                    </span>
                </a>

                <div class="nav-group-label">Fasilitas</div>

                <a href="<?php echo e(route('rooms.index')); ?>" class="<?php echo e(request()->routeIs('rooms.*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke="currentColor" fill="none">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Manajemen Ruangan</span>
                        <span class="nav-meta">Ruang operasional</span>
                    </span>
                </a>

                <a href="<?php echo e(route('vehicles.index')); ?>" class="<?php echo e(request()->routeIs('vehicles.*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke="currentColor" fill="none">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M8.25 18.75a1.5 1.5 0 0 1-3 0m13.5 0a1.5 1.5 0 0 1-3 0m-13.5 0H5.25A2.25 2.25 0 0 1 3 16.5V15.75m14.25 3h.75A2.25 2.25 0 0 0 21 16.5v-7.5a2.25 2.25 0 0 0-2.25-2.25h-3a1.125 1.125 0 0 1-1.125-1.125V4.5a2.25 2.25 0 0 0-2.25-2.25h-3a2.25 2.25 0 0 0-2.25 2.25v.75m10.5 3.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM3.75 13.5h16.5a1.5 1.5 0 0 1 1.5 1.5v2.25a1.5 1.5 0 0 1-1.5 1.5H3.75a1.5 1.5 0 0 1-1.5-1.5V15a1.5 1.5 0 0 1 1.5-1.5Z" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Manajemen Kendaraan</span>
                        <span class="nav-meta">Armada dinas</span>
                    </span>
                </a>

                <?php if(in_array($user->role, ['staff_bidang', 'kepala_bidang', 'sekretariat'])): ?>
                    <div class="nav-group-label">Admin Menu</div>

                    <?php if(in_array($user->role, ['staff_bidang', 'kepala_bidang'])): ?>
                        <a href="<?php echo e(route('admin.request-items.index')); ?>" class="<?php echo e(request()->is('admin/request-items*') ? 'active' : ''); ?>">
                            <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" stroke-linecap="round" stroke-linejoin="round" />
                            </svg>
                            <span class="nav-copy">
                                <span class="nav-title">Barang</span>
                                <span class="nav-meta">Kelola stok & batas minimum</span>
                            </span>
                            <?php if($lowStockRequestItemCount > 0): ?>
                                <span class="nav-badge"><?php echo e($lowStockRequestItemCount); ?></span>
                            <?php else: ?>
                                <span class="nav-trailing">Kelola</span>
                            <?php endif; ?>
                        </a>
                    <?php endif; ?>

                    <a href="<?php echo e(route('verification.index')); ?>" class="<?php echo e(request()->is('verification*') ? 'active' : ''); ?> <?php echo e($verificationCount > 0 ? 'alert' : ''); ?>">
                        <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" stroke-linecap="round" stroke-linejoin="round" />
                        </svg>
                        <span class="nav-copy">
                            <span class="nav-title">Verifikasi</span>
                            <span class="nav-meta">Persetujuan & tindak lanjut</span>
                        </span>
                        <?php if($verificationCount > 0): ?>
                            <span class="nav-badge danger"><?php echo e($verificationCount > 99 ? '99+' : $verificationCount); ?></span>
                        <?php endif; ?>
                    </a>

                    <?php if(in_array($user->role, ['kepala_bidang', 'sekretariat'])): ?>
                        <a href="<?php echo e(Route::has('reports.index') ? route('reports.index') : '#'); ?>" class="<?php echo e(request()->is('reports*') ? 'active' : ''); ?>">
                            <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M9 17v-2m3 2v-4m3 2v-6m2 9H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
                            </svg>
                            <span class="nav-copy">
                                <span class="nav-title">Laporan</span>
                                <span class="nav-meta">Rekap & analitik</span>
                            </span>
                        </a>
                    <?php endif; ?>
                <?php endif; ?>

                <div class="nav-group-label">Akun</div>

                <a href="<?php echo e(Route::has('profile.index') ? route('profile.index') : '#'); ?>" class="<?php echo e(request()->is('profile*') ? 'active' : ''); ?>">
                    <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
                    </svg>
                    <span class="nav-copy">
                        <span class="nav-title">Profil</span>
                        <span class="nav-meta">Pengaturan akun</span>
                    </span>
                </a>
            </nav>

            <div class="sidebar-footer">
                <form method="POST" action="<?php echo e(route('logout')); ?>" id="sidebarLogoutForm">
                    <?php echo csrf_field(); ?>
                    <button class="logout-btn" type="submit">
                        <svg class="nav-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" stroke-linecap="round" stroke-linejoin="round" />
                        </svg>
                        <span>Logout</span>
                    </button>
                </form>
            </div>
        </div>
    </div>
</aside>

<script>
    (function() {
        const savedState = localStorage.getItem('sipian-sidebar-collapsed');

        if (savedState === '1') {
            document.documentElement.classList.add('sipian-sidebar-collapsed');
        }
    })();

    function toggleSidebar() {
        const sidebar = document.getElementById('appSidebar');
        const overlay = document.querySelector('.sidebar-overlay');
        sidebar.classList.toggle('active');
        overlay.classList.toggle('active');
    }

    function toggleSidebarCollapse() {
        const sidebar = document.getElementById('appSidebar');

        if (window.innerWidth <= 1024) {
            toggleSidebar();
            return;
        }

        sidebar.classList.toggle('collapsed');
        const isCollapsed = sidebar.classList.contains('collapsed');
        document.documentElement.classList.toggle('sipian-sidebar-collapsed', isCollapsed);
        localStorage.setItem('sipian-sidebar-collapsed', isCollapsed ? '1' : '0');
    }

    document.addEventListener('DOMContentLoaded', () => {
        const sidebar = document.getElementById('appSidebar');

        if (window.innerWidth > 1024 && document.documentElement.classList.contains('sipian-sidebar-collapsed')) {
            sidebar.classList.add('collapsed');
        }

        sidebar.classList.add('ready');
    });
</script>
<?php /**PATH /Users/Afifudin/Downloads/Magang/SIpian_2026-05-06/resources/views/partials/sidebar.blade.php ENDPATH**/ ?>