<?php $user=Auth::user();$notificationCount=unread_notification_count();$pendingAI=ai_pending_action_count();$aiReady=ai_automation_is_ready(); ?>
<header class="topbar topbar-v3 topbar-v4">
    <div class="topbar-leading">
        <button class="icon-button mobile-menu" type="button" data-mobile-menu aria-label="Open navigation"><span></span><span></span><span></span></button>
        <div class="topbar-title"><p class="eyebrow">FleetLume / <?= e(readable_status(current_role())) ?></p><h1><?= e($pageTitle??'Dashboard') ?></h1></div>
    </div>
    <button class="command-trigger" type="button" data-command-open><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg><span>Search loads, carriers, drivers, documents...</span><kbd>⌘ K</kbd></button>
    <div class="topbar-actions">
        <?php if(can('ai.use')): ?><a class="autopilot-pill <?= $aiReady?'is-active':'' ?>" href="<?= url('/ai/automation') ?>"><span class="autopilot-spark">✦</span><span><strong>Autopilot</strong><small><?= $pendingAI?$pendingAI.' waiting':'Monitoring' ?></small></span><?php if($pendingAI): ?><b><?= $pendingAI>99?'99+':$pendingAI ?></b><?php endif; ?></a><?php endif; ?>
        <a class="icon-button notification-button" href="<?= url('/notifications') ?>" aria-label="Notifications"><?= nav_icon('bell') ?><?php if($notificationCount): ?><span><?= $notificationCount>99?'99+':$notificationCount ?></span><?php endif; ?></a>
        <details class="profile-menu"><summary><span class="avatar"><?= e(user_initials($user['name']??'User')) ?></span><span class="profile-copy"><strong><?= e($user['name']??'User') ?></strong><small><?= e(readable_status($user['role']??'')) ?></small></span><i></i></summary><div class="profile-popover"><div><strong><?= e($user['name']??'User') ?></strong><span><?= e($user['email']??'') ?></span></div><?php if($user['role']!=='driver'&&$user['role']!=='carrier'): ?><a href="<?= url('/settings') ?>">Settings</a><?php endif; ?><a href="<?= url('/notifications') ?>">Notifications</a><form method="post" action="<?= url('/logout') ?>"><?= csrf_field() ?><button type="submit">Sign out</button></form></div></details>
    </div>
</header>
