<x-filament-panels::page>
    @php($scope = $this->appliedScope())
    @php($summary = $this->summaryCounts())
    @php($availableFilters = $this->availableFilters())

    <div class="space-y-6">
        <x-filament::section>
            <div class="flex flex-col gap-4">
                <div class="space-y-2">
                    <div class="inline-flex w-fit items-center gap-2 rounded-full border border-primary-200 bg-primary-50 px-3 py-1 text-xs font-medium text-primary-700 dark:border-primary-700/60 dark:bg-primary-950/40 dark:text-primary-300">
                        <x-filament::icon icon="heroicon-o-clipboard-document-check" class="h-3.5 w-3.5" />
                        Assigned to me
                    </div>

                    <div class="space-y-1">
                        <h1 class="text-2xl font-semibold tracking-tight text-gray-950 dark:text-white">
                            My Findings
                        </h1>

                        <p class="max-w-3xl text-sm leading-6 text-gray-600 dark:text-gray-300">
                            Review open assigned findings across visible tenants in one queue. ManagedEnvironment context can narrow the view, but the personal assignment scope stays fixed.
                        </p>
                    </div>
                </div>

                <div class="grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-4">
                    <div class="rounded-2xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
                        <div class="text-xs font-medium uppercase tracking-[0.14em] text-gray-500 dark:text-gray-400">
                            Open assigned
                        </div>
                        <div class="mt-2 text-3xl font-semibold text-gray-950 dark:text-white">
                            {{ $summary['open_assigned'] }}
                        </div>
                        <div class="mt-1 text-sm text-gray-600 dark:text-gray-300">
                            Visible rows after the current filters.
                        </div>
                    </div>

                    <div class="rounded-2xl border border-danger-200 bg-danger-50/70 p-4 shadow-sm dark:border-danger-700/50 dark:bg-danger-950/30">
                        <div class="text-xs font-medium uppercase tracking-[0.14em] text-danger-700 dark:text-danger-200">
                            Overdue
                        </div>
                        <div class="mt-2 text-3xl font-semibold text-danger-950 dark:text-danger-100">
                            {{ $summary['overdue_assigned'] }}
                        </div>
                        <div class="mt-1 text-sm text-danger-800 dark:text-danger-200">
                            Assigned findings that are already past due.
                        </div>
                    </div>

                    <div class="rounded-2xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
                        <div class="text-xs font-medium uppercase tracking-[0.14em] text-gray-500 dark:text-gray-400">
                            Applied scope
                        </div>
                        <div class="mt-2 text-sm font-semibold text-gray-950 dark:text-white">
                            Assigned to me only
                        </div>
                        <div class="mt-1 text-sm text-gray-600 dark:text-gray-300">
                            @if (($scope['tenant_prefilter_source'] ?? 'none') === 'active_tenant_context')
                                ManagedEnvironment prefilter from active context:
                                <span class="font-medium text-gray-950 dark:text-white">{{ $scope['tenant_label'] }}</span>
                            @elseif (($scope['tenant_prefilter_source'] ?? 'none') === 'explicit_filter')
                                ManagedEnvironment filter applied:
                                <span class="font-medium text-gray-950 dark:text-white">{{ $scope['tenant_label'] }}</span>
                            @else
                                All visible tenants are currently included.
                            @endif
                        </div>
                    </div>

                    <div class="rounded-2xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
                        <div class="text-xs font-medium uppercase tracking-[0.14em] text-gray-500 dark:text-gray-400">
                            Available filters
                        </div>
                        <div class="mt-2 flex flex-wrap gap-2">
                            @foreach ($availableFilters as $filter)
                                <span class="inline-flex items-center rounded-full border px-3 py-1 text-xs font-medium {{ ($filter['fixed'] ?? false) ? 'border-primary-200 bg-primary-50 text-primary-700 dark:border-primary-700/60 dark:bg-primary-950/40 dark:text-primary-300' : 'border-gray-200 bg-gray-50 text-gray-700 dark:border-white/10 dark:bg-white/5 dark:text-gray-300' }}">
                                    {{ $filter['label'] }}
                                    @if (($filter['fixed'] ?? false) === true)
                                        <span class="ml-2 text-[11px] uppercase tracking-[0.12em] opacity-70">Fixed</span>
                                    @endif
                                </span>
                            @endforeach
                        </div>
                    </div>
                </div>
            </div>
        </x-filament::section>

        {{ $this->table }}
    </div>
</x-filament-panels::page>
