@forelse($results as $i => $result)
<tr class="odd:bg-white even:bg-gray-50 hover:bg-indigo-50/60 transition-colors border-b border-gray-100 last:border-0">

    {{-- # --}}
    <td class="px-4 py-3 text-gray-400 text-xs font-medium">
        {{ $results->firstItem() + $i }}
    </td>

    {{-- Trainee --}}
    <td class="px-4 py-3">
        <div class="flex items-center gap-2">
            <span class="w-7 h-7 bg-purple-100 rounded-full flex items-center justify-center text-xs font-bold text-purple-600 flex-shrink-0">
                {{ strtoupper(substr($result->user->name ?? 'U', 0, 1)) }}
            </span>
            <div>
                <p class="font-semibold text-gray-800 text-sm leading-tight">{{ $result->user->name ?? '—' }}</p>
                <p class="text-gray-400 text-xs mt-0.5">{{ $result->user->email ?? '—' }}</p>
            </div>
        </div>
    </td>

    {{-- Course --}}
    <td class="px-4 py-3">
        <p class="text-sm font-medium text-gray-700 line-clamp-1">{{ $result->course->title ?? '—' }}</p>
    </td>

    {{-- Score --}}
    <td class="px-4 py-3">
        <span class="text-sm font-semibold text-gray-800">
            {{ $result->correct_answers }}/{{ $result->total_questions }}
        </span>
        <span class="text-xs text-gray-400 ml-1">({{ number_format((float) $result->score_percentage, 1) }}%)</span>
    </td>

    {{-- Passed badge --}}
    <td class="px-4 py-3">
        @if($result->passed)
            <span class="inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-green-100 text-green-700">
                <i class="fas fa-check text-xs"></i> PASS
            </span>
        @else
            <span class="inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-red-100 text-red-700">
                <i class="fas fa-times text-xs"></i> FAIL
            </span>
        @endif
    </td>

    {{-- Threshold --}}
    <td class="px-4 py-3">
        <span class="text-sm text-gray-600">{{ $result->passing_threshold }}%</span>
    </td>

    {{-- Date --}}
    <td class="px-4 py-3">
        <span class="text-xs text-gray-500">{{ $result->created_at->format('d M Y') }}</span>
        <span class="text-xs text-gray-400 block">{{ $result->created_at->format('H:i') }}</span>
    </td>

    {{-- Actions --}}
    <td class="px-4 py-3">
        <div class="flex items-center gap-1">
            @can('view self-paced results')
            <a href="{{ route('self-paced.dashboard.results.show', $result) }}"
               title="View Details"
               class="w-7 h-7 flex items-center justify-center rounded-lg bg-indigo-50 hover:bg-indigo-100 text-indigo-600 transition">
                <i class="fas fa-eye text-xs"></i>
            </a>
            @endcan
            <a href="{{ route('self-paced.dashboard.results.result-slip', $result) }}"
               title="Download Result Slip"
               class="w-7 h-7 flex items-center justify-center rounded-lg bg-teal-50 hover:bg-teal-100 text-teal-600 transition">
                <i class="fas fa-download text-xs"></i>
            </a>
        </div>
    </td>
</tr>
@empty
<tr>
    <td colspan="8" class="px-6 py-16 text-center">
        <i class="fas fa-clipboard-list text-5xl text-gray-200 mb-4 block"></i>
        <p class="text-gray-400 font-medium">No results found</p>
        <p class="text-gray-300 text-sm mt-1">Try adjusting your search or filters.</p>
    </td>
</tr>
@endforelse
