@forelse($questions as $i => $question)
<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">
        {{ $questions->firstItem() + $i }}
    </td>

    {{-- Question --}}
    <td class="px-4 py-3">
        <p class="text-sm text-gray-800 leading-snug">{{ Str::limit($question->question_text, 80) }}</p>
    </td>

    {{-- Course --}}
    <td class="px-4 py-3">
        @if($question->course)
            <span class="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-700">
                <i class="fas fa-book text-xs"></i>
                {{ Str::limit($question->course->title, 35) }}
            </span>
        @else
            <span class="text-gray-300 text-xs">—</span>
        @endif
    </td>

    {{-- Correct Answer --}}
    <td class="px-4 py-3">
        @php
            $answerColors = ['A' => 'bg-green-100 text-green-700', 'B' => 'bg-blue-100 text-blue-700', 'C' => 'bg-purple-100 text-purple-700', 'D' => 'bg-amber-100 text-amber-700'];
            $colorClass = $answerColors[$question->correct_answer] ?? 'bg-gray-100 text-gray-600';
        @endphp
        <span class="inline-flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold {{ $colorClass }}">
            {{ $question->correct_answer }}
        </span>
    </td>

    {{-- Active --}}
    <td class="px-4 py-3">
        @if($question->is_active)
            <span class="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-700">
                <i class="fas fa-check text-xs"></i> Yes
            </span>
        @else
            <span class="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-500">
                <i class="fas fa-times text-xs"></i> No
            </span>
        @endif
    </td>

    {{-- Actions --}}
    <td class="px-4 py-3">
        <div class="flex items-center gap-1">
            @can('manage self-paced exams')
            <a href="{{ route('self-paced.dashboard.exams.edit', [$question->course, $question]) }}"
               title="Edit"
               class="w-7 h-7 flex items-center justify-center rounded-lg bg-amber-50 hover:bg-amber-100 text-amber-600 transition">
                <i class="fas fa-pencil text-xs"></i>
            </a>
            <button type="button"
                    title="Delete"
                    onclick="confirmExamDelete({{ $question->id }}, '{{ addslashes(Str::limit($question->question_text, 50)) }}')"
                    class="w-7 h-7 flex items-center justify-center rounded-lg bg-red-50 hover:bg-red-100 text-red-600 transition">
                <i class="fas fa-trash text-xs"></i>
            </button>
            <form id="delete-exam-form-{{ $question->id }}"
                  action="{{ route('self-paced.dashboard.exams.destroy', [$question->course, $question]) }}"
                  method="POST" class="hidden">
                @csrf @method('DELETE')
            </form>
            @endcan
        </div>
    </td>
</tr>
@empty
<tr>
    <td colspan="6" class="px-6 py-16 text-center">
        <i class="fas fa-clipboard-question text-5xl text-gray-200 mb-4 block"></i>
        <p class="text-gray-400 font-medium">No questions found</p>
        <p class="text-gray-300 text-sm mt-1">Try adjusting your search or filters.</p>
    </td>
</tr>
@endforelse
