<?php $__env->startSection('title', 'Typist Command Center'); ?>

<?php $__env->startSection('content'); ?>
<div class="mx-auto max-w-[1800px] space-y-5" x-data="{ filtersOpen: <?php echo e(collect($filters)->filter()->isNotEmpty() ? 'true' : 'false'); ?>, focusMode: false }">
    <?php
        $viewLinks = [
            ['mine', 'My queue', $metrics['active']],
            ['returned', 'Returned', $metrics['returned']],
            ['documents', 'Document holds', $metrics['documents_pending']],
            ['payment', 'Payment holds', $metrics['payment_holds']],
            ['sla', 'SLA risk', $metrics['sla_warnings']],
            ['paused', 'Paused', $metrics['paused']],
        ];
        if (auth()->user()->hasPermission('applications.assign')) {
            $viewLinks[] = ['unassigned', 'Unassigned', $metrics['unassigned']];
        }
    ?>

    <?php echo $__env->make('tenant.partials.typist-page-nav', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <section class="relative overflow-hidden rounded-[28px] border border-sky-100 bg-gradient-to-br from-white via-sky-50 to-orange-50 px-5 py-6 text-slate-950 shadow-sm sm:px-7 lg:px-8">
        <div class="absolute -right-16 -top-24 h-72 w-72 rounded-full bg-orange-200/40 blur-3xl"></div>
        <div class="absolute bottom-0 right-[28%] h-36 w-36 rounded-full bg-sky-200/40 blur-2xl"></div>
        <div class="relative flex flex-col gap-6 xl:flex-row xl:items-center xl:justify-between">
            <div class="max-w-2xl">
                <div class="flex flex-wrap items-center gap-2 text-[10px] font-bold uppercase tracking-[.18em] text-orange-600">
                    <span>Typist operations</span>
                    <span class="h-1 w-1 rounded-full bg-orange-400"></span>
                    <span><?php echo e(auth()->user()->defaultBranch?->name ?? 'Active branch'); ?></span>
                    <span class="rounded-full border border-emerald-200 bg-emerald-100 px-2 py-1 text-[9px] tracking-wider text-emerald-700">Live queue</span>
                </div>
                <h1 class="mt-3 text-2xl font-bold tracking-tight sm:text-3xl">Typing Command Center</h1>
                <p class="mt-2 max-w-xl text-xs leading-5 text-slate-600">Welcome, <?php echo e(auth()->user()->name); ?>. Process verified applications, resolve government returns, monitor SLA commitments and hand work to supervisors from one focused workspace.</p>
            </div>
            <div class="grid grid-cols-2 gap-2 sm:grid-cols-4 xl:min-w-[560px]">
                <div class="rounded-2xl border border-slate-200 bg-white/90 p-3.5 shadow-sm backdrop-blur-sm">
                    <p class="text-[9px] font-bold uppercase tracking-wider text-slate-400">Active work</p>
                    <strong class="mt-1.5 block text-2xl"><?php echo e(number_format($metrics['active'])); ?></strong>
                    <span class="text-[9px] text-slate-400">Assigned to me</span>
                </div>
                <div class="rounded-2xl border border-orange-200 bg-orange-100/70 p-3.5 backdrop-blur-sm">
                    <p class="text-[9px] font-bold uppercase tracking-wider text-orange-700">Due attention</p>
                    <strong class="mt-1.5 block text-2xl text-orange-700"><?php echo e(number_format($metrics['sla_warnings'])); ?></strong>
                    <span class="text-[9px] text-orange-600">SLA risk or overdue</span>
                </div>
                <div class="rounded-2xl border border-slate-200 bg-white/90 p-3.5 shadow-sm backdrop-blur-sm">
                    <p class="text-[9px] font-bold uppercase tracking-wider text-slate-400">Completed today</p>
                    <strong class="mt-1.5 block text-2xl text-emerald-600"><?php echo e(number_format($metrics['completed_today'])); ?></strong>
                    <span class="text-[9px] text-slate-400"><?php echo e(number_format($metrics['completed_week'])); ?> this week</span>
                </div>
                <div class="rounded-2xl border border-slate-200 bg-white/90 p-3.5 shadow-sm backdrop-blur-sm">
                    <p class="text-[9px] font-bold uppercase tracking-wider text-slate-400">On-time rate</p>
                    <strong class="mt-1.5 block text-2xl"><?php echo e($metrics['on_time_rate'] === null ? '—' : $metrics['on_time_rate'].'%'); ?></strong>
                    <span class="text-[9px] text-slate-400">Last 30 days</span>
                </div>
            </div>
        </div>
    </section>

    <section class="grid grid-cols-2 gap-3 sm:grid-cols-3 xl:grid-cols-6" x-show="!focusMode" x-transition>
        <?php $__currentLoopData = [
            ['Assigned today', $metrics['assigned_today'], 'AS', 'bg-blue-50 text-blue-600', 'New handoffs'],
            ['Typing now', $metrics['typing'], 'TY', 'bg-orange-50 text-orange-600', 'Ready and in progress'],
            ['Returned cases', $metrics['returned'], 'RT', 'bg-amber-50 text-amber-700', 'Correction required'],
            ['Document holds', $metrics['documents_pending'], 'DC', 'bg-violet-50 text-violet-600', 'Missing or unverified'],
            ['Payment holds', $metrics['payment_holds'], 'PY', 'bg-rose-50 text-rose-600', 'Awaiting clearance'],
            ['Overdue', $metrics['overdue'], 'SL', 'bg-red-50 text-red-600', 'Immediate action'],
        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $value, $icon, $iconClass, $note]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <article class="group rounded-2xl border border-slate-200/80 bg-white p-4 shadow-sm transition hover:-translate-y-0.5 hover:border-orange-200 hover:shadow-lg">
                <div class="flex items-start justify-between gap-3">
                    <span class="grid h-9 w-9 place-items-center rounded-xl text-[10px] font-black <?php echo e($iconClass); ?>"><?php echo e($icon); ?></span>
                    <span class="text-[9px] font-bold uppercase tracking-wider text-slate-300">Today</span>
                </div>
                <strong class="mt-4 block text-2xl text-[#0b1f38]"><?php echo e(number_format($value)); ?></strong>
                <p class="mt-0.5 text-[11px] font-bold text-slate-700"><?php echo e($label); ?></p>
                <p class="mt-1 text-[9px] text-slate-400"><?php echo e($note); ?></p>
            </article>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </section>

    <div class="grid gap-5 2xl:grid-cols-[minmax(0,1fr)_340px]">
        <section class="min-w-0 rounded-[24px] border border-slate-200 bg-white shadow-sm">
            <div class="border-b border-slate-100 px-4 py-4 sm:px-5">
                <div class="flex flex-col gap-4 xl:flex-row xl:items-center xl:justify-between">
                    <div>
                        <div class="flex items-center gap-2">
                            <span class="grid h-8 w-8 place-items-center rounded-xl bg-orange-50 text-[10px] font-black text-orange-600">SQ</span>
                            <div><h2 class="text-sm font-bold text-[#0b1f38]">Smart Queue</h2><p class="text-[10px] text-slate-400">Priority, government returns and SLA risk are ranked automatically.</p></div>
                        </div>
                    </div>
                    <div class="flex flex-wrap items-center gap-2">
                        <button type="button" @click="focusMode = !focusMode" class="rounded-xl border border-slate-200 px-3 py-2 text-[10px] font-bold text-slate-600 transition hover:border-orange-200 hover:text-orange-600"><span x-text="focusMode ? 'Exit focus mode' : 'Focus mode'"></span></button>
                        <button type="button" @click="filtersOpen = !filtersOpen" class="rounded-xl border border-slate-200 px-3 py-2 text-[10px] font-bold text-slate-600 transition hover:border-orange-200 hover:text-orange-600">Advanced filters</button>
                        <a href="<?php echo e(route('app.applications.kanban')); ?>" class="rounded-xl bg-[#0b1f38] px-3.5 py-2 text-[10px] font-bold text-white shadow-sm transition hover:bg-orange-600">Workflow board</a>
                    </div>
                </div>

                <nav class="mt-4 flex gap-2 overflow-x-auto pb-1" aria-label="Queue views">
                    <?php $__currentLoopData = $viewLinks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$key, $label, $count]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <a href="<?php echo e(request()->fullUrlWithQuery(['view' => $key, 'page' => null])); ?>" class="inline-flex shrink-0 items-center gap-2 rounded-xl border px-3 py-2 text-[10px] font-bold transition <?php echo e($view === $key ? 'border-orange-200 bg-orange-50 text-orange-700 shadow-sm' : 'border-slate-200 text-slate-500 hover:border-slate-300 hover:text-slate-800'); ?>">
                            <?php echo e($label); ?> <span class="rounded-md <?php echo e($view === $key ? 'bg-orange-600 text-white' : 'bg-slate-100 text-slate-500'); ?> px-1.5 py-0.5 text-[8px]"><?php echo e(number_format($count)); ?></span>
                        </a>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </nav>

                <form method="GET" action="<?php echo e(route('app.work_queue')); ?>" x-show="filtersOpen" x-transition class="mt-4 rounded-2xl border border-slate-200 bg-slate-50/80 p-3">
                    <input type="hidden" name="view" value="<?php echo e($view); ?>">
                    <div class="grid gap-2 md:grid-cols-2 xl:grid-cols-[minmax(220px,1.5fr)_repeat(5,minmax(120px,1fr))_auto]">
                        <label class="relative block">
                            <span class="sr-only">Search queue</span>
                            <input name="q" value="<?php echo e($filters['q'] ?? ''); ?>" placeholder="Application, customer, mobile or service" class="erp-input h-10 bg-white pl-3 text-[10px]">
                        </label>
                        <select name="priority" class="erp-input h-10 bg-white text-[10px]"><option value="">All priorities</option><?php $__currentLoopData = ['urgent' => 'Urgent', 'vip' => 'VIP', 'high' => 'High', 'normal' => 'Normal']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($key); ?>" <?php if(($filters['priority'] ?? '') === $key): echo 'selected'; endif; ?>><?php echo e($label); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
                        <select name="stage_id" class="erp-input h-10 bg-white text-[10px]"><option value="">All stages</option><?php $__currentLoopData = $stageOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stage): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($stage->id); ?>" <?php if((string) ($filters['stage_id'] ?? '') === (string) $stage->id): echo 'selected'; endif; ?>><?php echo e($stage->stage_name_en); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
                        <select name="service_id" class="erp-input h-10 bg-white text-[10px]"><option value="">All services</option><?php $__currentLoopData = $serviceOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $service): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($service->id); ?>" <?php if((string) ($filters['service_id'] ?? '') === (string) $service->id): echo 'selected'; endif; ?>><?php echo e($service->name_en); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
                        <select name="branch_id" class="erp-input h-10 bg-white text-[10px]"><option value="">All branches</option><?php $__currentLoopData = $branchOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($branch->id); ?>" <?php if((string) ($filters['branch_id'] ?? '') === (string) $branch->id): echo 'selected'; endif; ?>><?php echo e($branch->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
                        <select name="sort" class="erp-input h-10 bg-white text-[10px]"><option value="smart" <?php if(($filters['sort'] ?? 'smart') === 'smart'): echo 'selected'; endif; ?>>Smart ranking</option><option value="sla" <?php if(($filters['sort'] ?? '') === 'sla'): echo 'selected'; endif; ?>>Nearest SLA</option><option value="priority" <?php if(($filters['sort'] ?? '') === 'priority'): echo 'selected'; endif; ?>>Priority first</option><option value="oldest" <?php if(($filters['sort'] ?? '') === 'oldest'): echo 'selected'; endif; ?>>Oldest first</option><option value="newest" <?php if(($filters['sort'] ?? '') === 'newest'): echo 'selected'; endif; ?>>Newest first</option></select>
                        <div class="flex gap-2"><button class="h-10 rounded-xl bg-orange-600 px-4 text-[10px] font-bold text-white">Apply</button><a href="<?php echo e(route('app.work_queue')); ?>" class="grid h-10 place-items-center rounded-xl border border-slate-200 bg-white px-3 text-[10px] font-bold text-slate-500">Reset</a></div>
                    </div>
                </form>
            </div>

            <div class="space-y-3 p-3 sm:p-4">
                <?php $__empty_1 = true; $__currentLoopData = $applications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $application): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <?php
                        $isPaused = $application->sla_paused_at !== null;
                        $isOverdue = !$isPaused && $application->due_at?->isPast();
                        $isRisk = !$isPaused && ($isOverdue || in_array($application->sla_status, ['at_risk', 'warning', 'overdue'], true) || $application->due_at?->lessThanOrEqualTo(now()->addHours(4)));
                        $transitions = collect($application->queue_transitions ?? []);
                        $readyTransition = $transitions->firstWhere('ready', true);
                        $blockedTransition = $transitions->first(fn ($transition) => !($transition['ready'] ?? false));
                        $latestSubmission = $application->latest_submission;
                        $paymentReady = (float) $application->total_price <= 0 || in_array($application->payment_status, ['paid', 'credit_account', 'corporate_credit'], true);
                        $documentsReady = (int) $application->pending_documents_count === 0 && !in_array($application->document_status, ['missing_documents', 'exception'], true);
                    ?>
                    <article class="group relative overflow-hidden rounded-2xl border <?php echo e($isOverdue ? 'border-rose-200 bg-rose-50/20' : ($application->status === 'returned' || $application->currentStage?->stage_code === 'GOVERNMENT_RETURNED' ? 'border-amber-200 bg-amber-50/20' : 'border-slate-200 bg-white')); ?> p-4 transition hover:border-orange-200 hover:shadow-[0_14px_40px_rgba(15,23,42,.08)] sm:p-5">
                        <span class="absolute inset-y-0 left-0 w-1 <?php echo e($application->priority === 'urgent' ? 'bg-rose-500' : ($application->priority === 'vip' ? 'bg-violet-500' : ($application->priority === 'high' ? 'bg-orange-500' : 'bg-sky-500'))); ?>"></span>
                        <div class="grid gap-4 xl:grid-cols-[minmax(0,1.5fr)_minmax(230px,.75fr)_190px] xl:items-center">
                            <div class="min-w-0 pl-1">
                                <div class="flex flex-wrap items-center gap-2">
                                    <a href="<?php echo e(route('app.applications.show', $application->id)); ?>" class="text-sm font-black tracking-tight text-orange-600 hover:text-orange-700"><?php echo e($application->application_number); ?></a>
                                    <span class="erp-status" data-status="<?php echo e($application->priority); ?>"><?php echo e(ucfirst($application->priority)); ?></span>
                                    <?php if($application->status === 'returned' || $application->currentStage?->stage_code === 'GOVERNMENT_RETURNED'): ?><span class="rounded-full bg-amber-100 px-2 py-1 text-[8px] font-black uppercase tracking-wider text-amber-700">Government return</span><?php endif; ?>
                                    <?php if($isPaused): ?><span class="erp-status" data-status="paused">SLA paused</span><?php elseif($isOverdue): ?><span class="erp-status" data-status="overdue">Overdue</span><?php elseif($isRisk): ?><span class="erp-status" data-status="warning">SLA risk</span><?php endif; ?>
                                </div>
                                <div class="mt-2 flex min-w-0 flex-col gap-1 sm:flex-row sm:items-center sm:gap-3">
                                    <h3 class="truncate text-sm font-bold text-[#0b1f38]"><?php echo e($application->customer?->full_name_en ?? 'Customer unavailable'); ?></h3>
                                    <span class="hidden h-1 w-1 rounded-full bg-slate-300 sm:block"></span>
                                    <p class="truncate text-[11px] font-semibold text-slate-500"><?php echo e($application->service?->name_en ?? 'Service unavailable'); ?></p>
                                </div>
                                <div class="mt-3 flex flex-wrap items-center gap-x-4 gap-y-2 text-[9px] text-slate-500">
                                    <span><strong class="text-slate-700">Mobile:</strong> <?php echo e($application->customer?->contact?->primary_mobile ?? 'Not recorded'); ?></span>
                                    <span><strong class="text-slate-700">Authority:</strong> <?php echo e($application->service?->authority?->name_en ?? $latestSubmission?->authority_code ?? 'Not assigned'); ?></span>
                                    <span><strong class="text-slate-700">Branch:</strong> <?php echo e($application->branch?->name ?? 'Main branch'); ?></span>
                                    <span><strong class="text-slate-700">Waiting:</strong> <?php echo e(($application->stage_entered_at ?? $application->updated_at)->diffForHumans(null, true)); ?></span>
                                </div>
                                <?php if($application->currentStage?->instructions): ?>
                                    <p class="mt-3 line-clamp-2 rounded-xl bg-slate-50 px-3 py-2 text-[9px] leading-4 text-slate-500"><strong class="text-slate-700">Stage instruction:</strong> <?php echo e($application->currentStage->instructions); ?></p>
                                <?php endif; ?>
                            </div>

                            <div class="rounded-2xl border border-slate-100 bg-slate-50/80 p-3">
                                <div class="flex items-center justify-between gap-3">
                                    <div class="min-w-0"><p class="text-[8px] font-bold uppercase tracking-wider text-slate-400">Current stage</p><p class="mt-1 truncate text-[11px] font-bold text-[#0b1f38]"><?php echo e($application->currentStage?->stage_name_en ?? 'Start stage'); ?></p></div>
                                    <span class="shrink-0 rounded-lg bg-white px-2 py-1 text-[8px] font-black text-slate-500 shadow-sm"><?php echo e($application->currentStage?->stage_code ?? 'START'); ?></span>
                                </div>
                                <div class="mt-3 grid grid-cols-3 gap-1.5">
                                    <div class="rounded-lg <?php echo e($documentsReady ? 'bg-emerald-50 text-emerald-700' : 'bg-amber-50 text-amber-700'); ?> px-2 py-2 text-center"><strong class="block text-[9px]"><?php echo e($documentsReady ? 'Ready' : $application->pending_documents_count.' pending'); ?></strong><span class="text-[7px] uppercase tracking-wider">Documents</span></div>
                                    <div class="rounded-lg <?php echo e($paymentReady ? 'bg-emerald-50 text-emerald-700' : 'bg-rose-50 text-rose-700'); ?> px-2 py-2 text-center"><strong class="block text-[9px]"><?php echo e($paymentReady ? 'Cleared' : 'On hold'); ?></strong><span class="text-[7px] uppercase tracking-wider">Payment</span></div>
                                    <div class="rounded-lg <?php echo e($application->open_tasks_count ? 'bg-blue-50 text-blue-700' : 'bg-slate-100 text-slate-500'); ?> px-2 py-2 text-center"><strong class="block text-[9px]"><?php echo e($application->open_tasks_count); ?></strong><span class="text-[7px] uppercase tracking-wider">Open tasks</span></div>
                                </div>
                                <?php if($latestSubmission): ?>
                                    <div class="mt-2 flex items-center justify-between border-t border-slate-200 pt-2 text-[8px]"><span class="text-slate-400">Gov. attempt <?php echo e($latestSubmission->attempt_number); ?></span><span class="erp-status" data-status="<?php echo e($latestSubmission->status); ?>"><?php echo e(str($latestSubmission->status)->replace('_', ' ')->title()); ?></span></div>
                                <?php endif; ?>
                            </div>

                            <div class="flex flex-col gap-2 xl:items-stretch">
                                <div class="rounded-xl border <?php echo e($isOverdue ? 'border-rose-200 bg-rose-50' : ($isRisk ? 'border-amber-200 bg-amber-50' : 'border-slate-200 bg-white')); ?> px-3 py-2.5">
                                    <p class="text-[8px] font-bold uppercase tracking-wider <?php echo e($isOverdue ? 'text-rose-500' : ($isRisk ? 'text-amber-600' : 'text-slate-400')); ?>"><?php echo e($isPaused ? 'SLA paused' : ($isOverdue ? 'SLA overdue' : 'Stage deadline')); ?></p>
                                    <strong class="mt-1 block text-[11px] <?php echo e($isOverdue ? 'text-rose-700' : 'text-slate-700'); ?>"><?php echo e($isPaused ? str($application->sla_pause_reason)->replace('_', ' ')->title() : ($application->due_at?->diffForHumans() ?? 'Not configured')); ?></strong>
                                    <?php if($application->due_at && !$isPaused): ?><span class="mt-0.5 block text-[8px] text-slate-400"><?php echo e($application->due_at->format('d M Y, h:i A')); ?></span><?php endif; ?>
                                </div>
                                <a href="<?php echo e(route('app.applications.show', $application->id)); ?>" class="grid h-10 place-items-center rounded-xl bg-[#0b1f38] px-3 text-[10px] font-bold text-white transition hover:bg-orange-600">Open Application 360</a>
                                <?php if(!$application->assigned_user_id && auth()->user()->hasPermission('applications.assign')): ?>
                                    <form method="POST" action="<?php echo e(route('app.applications.claim', $application->id)); ?>"><?php echo csrf_field(); ?><button class="h-10 w-full rounded-xl border border-orange-200 bg-orange-50 text-[10px] font-bold text-orange-700">Claim application</button></form>
                                <?php elseif($readyTransition): ?>
                                    <form method="POST" action="<?php echo e(route('app.applications.transition', $application->id)); ?>"><?php echo csrf_field(); ?><input type="hidden" name="target_stage_id" value="<?php echo e($readyTransition['to_stage_id']); ?>"><button class="h-10 w-full rounded-xl border border-emerald-200 bg-emerald-50 px-2 text-[9px] font-bold text-emerald-700"><?php echo e($readyTransition['action_name_en']); ?></button></form>
                                <?php elseif($blockedTransition && !empty($blockedTransition['blockers'])): ?>
                                    <p class="rounded-lg bg-amber-50 px-2.5 py-2 text-[8px] leading-3 text-amber-700">Blocked: <?php echo e($blockedTransition['blockers'][0]); ?></p>
                                <?php endif; ?>
                            </div>
                        </div>
                    </article>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <div class="py-16 text-center">
                        <span class="mx-auto grid h-16 w-16 place-items-center rounded-2xl bg-emerald-50 text-lg font-black text-emerald-600">OK</span>
                        <h3 class="mt-4 text-base font-bold text-[#0b1f38]">Your work queue is clear</h3>
                        <p class="mx-auto mt-2 max-w-md text-xs leading-5 text-slate-400">There are no applications matching this view. Assigned typing work and government corrections will appear here automatically.</p>
                        <?php if(collect($filters)->filter()->isNotEmpty()): ?><a href="<?php echo e(route('app.work_queue')); ?>" class="mt-4 inline-flex rounded-xl bg-[#0b1f38] px-4 py-2.5 text-[10px] font-bold text-white">Clear queue filters</a><?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>

            <?php if($applications->hasPages()): ?>
                <div class="border-t border-slate-100 px-4 py-4"><?php echo e($applications->links()); ?></div>
            <?php endif; ?>
        </section>

        <aside class="space-y-5" x-show="!focusMode" x-transition>
            <section class="rounded-[24px] border border-slate-200 bg-white p-5 shadow-sm">
                <div class="flex items-start justify-between"><div><h2 class="text-sm font-bold text-[#0b1f38]">Daily Output</h2><p class="mt-1 text-[9px] text-slate-400">Applications completed over 7 days.</p></div><span class="rounded-lg bg-emerald-50 px-2 py-1 text-[9px] font-bold text-emerald-600"><?php echo e($metrics['completed_week']); ?> this week</span></div>
                <div class="mt-5 flex h-36 items-end justify-between gap-2 rounded-2xl bg-slate-50 p-3">
                    <?php $__currentLoopData = $dailyOutput; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $day): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php ($height = max(8, (int) round(($day['count'] / $dailyOutputMax) * 100))); ?>
                        <div class="flex h-full flex-1 flex-col items-center justify-end gap-1.5">
                            <span class="text-[8px] font-bold text-slate-500"><?php echo e($day['count']); ?></span>
                            <div class="w-full max-w-6 rounded-t-md <?php echo e($day['date'] === today()->format('Y-m-d') ? 'bg-gradient-to-t from-orange-600 to-orange-400' : 'bg-gradient-to-t from-sky-700 to-sky-400'); ?>" style="height: <?php echo e($height); ?>%"></div>
                            <span class="text-[7px] font-bold uppercase text-slate-400"><?php echo e($day['label']); ?></span>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
                <div class="mt-4 grid grid-cols-2 gap-2">
                    <div class="rounded-xl border border-slate-100 p-3"><span class="text-[8px] font-bold uppercase text-slate-400">Avg. turnaround</span><strong class="mt-1 block text-sm text-[#0b1f38]"><?php echo e($metrics['average_minutes'] === null ? 'No data' : ($metrics['average_minutes'] >= 1440 ? number_format($metrics['average_minutes'] / 1440, 1).' days' : ($metrics['average_minutes'] >= 60 ? number_format($metrics['average_minutes'] / 60, 1).' hrs' : $metrics['average_minutes'].' min'))); ?></strong></div>
                    <div class="rounded-xl border border-slate-100 p-3"><span class="text-[8px] font-bold uppercase text-slate-400">On-time rate</span><strong class="mt-1 block text-sm text-[#0b1f38]"><?php echo e($metrics['on_time_rate'] === null ? 'No data' : $metrics['on_time_rate'].'%'); ?></strong></div>
                </div>
            </section>

            <section class="rounded-[24px] border border-slate-200 bg-white p-5 shadow-sm">
                <div class="flex items-center justify-between"><div><h2 class="text-sm font-bold text-[#0b1f38]">Workload by Stage</h2><p class="mt-1 text-[9px] text-slate-400">Your live workflow distribution.</p></div><span class="text-lg font-black text-orange-600"><?php echo e($metrics['active']); ?></span></div>
                <div class="mt-4 space-y-3">
                    <?php $__empty_1 = true; $__currentLoopData = $stageBreakdown->take(6); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stage): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div>
                            <div class="flex items-center justify-between gap-3 text-[9px]"><span class="truncate font-bold text-slate-600"><?php echo e($stage['name']); ?></span><strong class="text-[#0b1f38]"><?php echo e($stage['total']); ?></strong></div>
                            <div class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-slate-100"><div class="h-full rounded-full bg-gradient-to-r from-sky-600 to-orange-500" style="width: <?php echo e($stage['percent']); ?>%"></div></div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <p class="rounded-xl bg-slate-50 px-3 py-4 text-center text-[9px] text-slate-400">No active stage workload.</p>
                    <?php endif; ?>
                </div>
            </section>

            <section class="rounded-[24px] border border-slate-200 bg-white p-5 shadow-sm">
                <div class="flex items-center justify-between"><div><h2 class="text-sm font-bold text-[#0b1f38]">My Workflow Tasks</h2><p class="mt-1 text-[9px] text-slate-400">Stage handoffs and follow-ups.</p></div><a href="<?php echo e(route('app.tasks.index')); ?>" class="text-[9px] font-bold text-orange-600">View all</a></div>
                <div class="mt-4 space-y-2.5">
                    <?php $__empty_1 = true; $__currentLoopData = $myTasks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $task): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="rounded-xl border <?php echo e($task->due_at?->isPast() ? 'border-rose-200 bg-rose-50/30' : 'border-slate-100 bg-slate-50/60'); ?> p-3">
                            <div class="flex items-start justify-between gap-2"><div class="min-w-0"><p class="truncate text-[10px] font-bold text-slate-700"><?php echo e($task->title); ?></p><p class="mt-1 text-[8px] text-slate-400"><?php echo e($task->task_number); ?> · <?php echo e($task->due_at?->diffForHumans() ?? 'No deadline'); ?></p></div><span class="erp-status" data-status="<?php echo e($task->priority); ?>"><?php echo e(ucfirst($task->priority)); ?></span></div>
                            <?php if(auth()->user()->hasPermission('tasks.manage')): ?>
                                <form method="POST" action="<?php echo e(route('app.tasks.status', $task->id)); ?>" class="mt-2 flex gap-1.5"><?php echo csrf_field(); ?><select name="status" class="erp-select-compact flex-1"><option value="in_progress">Start</option><option value="waiting">Waiting</option><option value="completed">Complete</option></select><button class="rounded-lg bg-[#0b1f38] px-2.5 text-[8px] font-bold text-white">Update</button></form>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <p class="rounded-xl bg-slate-50 px-3 py-5 text-center text-[9px] text-slate-400">No open workflow tasks.</p>
                    <?php endif; ?>
                </div>
            </section>

            <section class="rounded-[24px] border border-slate-200 bg-white p-5 shadow-sm">
                <div class="flex items-center justify-between"><div><h2 class="text-sm font-bold text-[#0b1f38]">Recent Completions</h2><p class="mt-1 text-[9px] text-slate-400">Your latest finished work.</p></div><span class="grid h-8 w-8 place-items-center rounded-xl bg-emerald-50 text-[9px] font-black text-emerald-600">DONE</span></div>
                <div class="mt-4 divide-y divide-slate-100">
                    <?php $__empty_1 = true; $__currentLoopData = $recentCompleted; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $completed): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <a href="<?php echo e(route('app.applications.show', $completed->id)); ?>" class="flex items-center gap-3 py-2.5 first:pt-0 last:pb-0"><span class="grid h-8 w-8 shrink-0 place-items-center rounded-lg bg-slate-50 text-[8px] font-black text-slate-500"><?php echo e(str($completed->customer?->full_name_en ?? 'NA')->substr(0, 2)->upper()); ?></span><span class="min-w-0 flex-1"><strong class="block truncate text-[9px] text-slate-700"><?php echo e($completed->application_number); ?></strong><small class="block truncate text-[8px] text-slate-400"><?php echo e($completed->service?->name_en); ?></small></span><time class="text-[8px] text-slate-400"><?php echo e($completed->completed_at?->format('d M')); ?></time></a>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <p class="rounded-xl bg-slate-50 px-3 py-5 text-center text-[9px] text-slate-400">Completed applications will appear here.</p>
                    <?php endif; ?>
                </div>
            </section>
        </aside>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\typingcenter\resources\views/tenant/panels/work_queue.blade.php ENDPATH**/ ?>