<div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
    <div class="overflow-x-auto">
        <table class="w-full">
            <thead>
                <tr class="bg-gray-50 border-b border-gray-200">
                    <th class="px-4 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Organisation</th>
                    <th class="px-4 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Type</th>
                    <th class="px-4 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Status</th>
                    <th class="px-4 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Level</th>
                    <th class="px-4 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Directory</th>
                    <th class="px-4 py-3 text-center text-xs font-semibold text-gray-600 uppercase tracking-wider">Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($partners as $partner)
                    <tr class="odd:bg-white even:bg-gray-50 hover:bg-blue-50/60 transition border-b border-gray-100 last:border-0">
                        <td class="px-4 py-3">
                            <div class="flex items-center gap-3">
                                @if($partner->logo)
                                    <img src="{{ asset('storage/' . $partner->logo) }}"
                                         alt="{{ $partner->organization_name }}"
                                         class="w-9 h-9 rounded-lg object-contain border border-gray-200 flex-shrink-0">
                                @else
                                    <div class="w-9 h-9 bg-blue-100 rounded-lg flex items-center justify-center flex-shrink-0">
                                        <i class="fas fa-building text-blue-600 text-sm"></i>
                                    </div>
                                @endif
                                <div>
                                    <div class="text-sm font-medium text-gray-900 flex items-center gap-1.5">
                                        {{ $partner->organization_name }}
                                        @if($partner->is_featured)
                                            <i class="fas fa-star text-yellow-500 text-xs" title="Featured"></i>
                                        @endif
                                        @if($partner->is_verified)
                                            <i class="fas fa-check-circle text-green-500 text-xs" title="Verified"></i>
                                        @endif
                                    </div>
                                    <div class="text-xs text-gray-500">{{ $partner->email }}</div>
                                </div>
                            </div>
                        </td>
                        <td class="px-4 py-3 text-sm text-gray-700 whitespace-nowrap">{{ $partner->type_label }}</td>
                        <td class="px-4 py-3 whitespace-nowrap">
                            @php
                                $sc = [
                                    'active'    => 'bg-green-100 text-green-800',
                                    'pending'   => 'bg-yellow-100 text-yellow-800',
                                    'inactive'  => 'bg-gray-100 text-gray-800',
                                    'suspended' => 'bg-red-100 text-red-800',
                                ][$partner->partnership_status] ?? 'bg-gray-100 text-gray-800';
                            @endphp
                            <span class="px-2 py-0.5 text-xs font-semibold rounded-full {{ $sc }}">
                                {{ ucfirst($partner->partnership_status) }}
                            </span>
                        </td>
                        <td class="px-4 py-3 whitespace-nowrap">
                            <span class="px-2 py-0.5 text-xs font-semibold rounded-full
                                @if($partner->partnership_level === 'platinum') bg-purple-100 text-purple-800
                                @elseif($partner->partnership_level === 'gold') bg-yellow-100 text-yellow-800
                                @elseif($partner->partnership_level === 'silver') bg-gray-200 text-gray-800
                                @else bg-orange-100 text-orange-800
                                @endif">
                                {{ ucfirst($partner->partnership_level ?? 'bronze') }}
                            </span>
                        </td>
                        <td class="px-4 py-3 text-sm whitespace-nowrap">
                            @if($partner->show_in_directory)
                                <span class="text-green-600 flex items-center gap-1">
                                    <i class="fas fa-eye text-xs"></i> Visible
                                </span>
                            @else
                                <span class="text-gray-400 flex items-center gap-1">
                                    <i class="fas fa-eye-slash text-xs"></i> Hidden
                                </span>
                            @endif
                        </td>
                        <td class="px-4 py-3 text-center">
                            <div class="flex items-center justify-center gap-1 flex-wrap">
                                @can('view partners')
                                    <a href="{{ route('partners.show', $partner) }}"
                                       class="inline-flex items-center gap-1 px-2.5 py-1 bg-blue-50 text-blue-700 hover:bg-blue-100 rounded-lg text-xs font-medium transition">
                                        <i class="fas fa-eye"></i> View
                                    </a>
                                @endcan
                                @can('edit partners')
                                    <a href="{{ route('partners.edit', $partner) }}"
                                       class="inline-flex items-center gap-1 px-2.5 py-1 bg-indigo-50 text-indigo-700 hover:bg-indigo-100 rounded-lg text-xs font-medium transition">
                                        <i class="fas fa-edit"></i> Edit
                                    </a>
                                @endcan
                                @can('edit own partners')
                                    @if(!auth()->user()->can('edit partners') && auth()->user()->partner?->id === $partner->id)
                                        <a href="{{ route('partners.edit', $partner) }}"
                                           class="inline-flex items-center gap-1 px-2.5 py-1 bg-indigo-50 text-indigo-700 hover:bg-indigo-100 rounded-lg text-xs font-medium transition">
                                            <i class="fas fa-edit"></i> Edit
                                        </a>
                                    @endif
                                @endcan
                                @can('verify partners')
                                    @if(!$partner->is_verified && $partner->partnership_status === 'pending')
                                        <button onclick="verifyPartner({{ $partner->id }})"
                                                class="inline-flex items-center gap-1 px-2.5 py-1 bg-green-50 text-green-700 hover:bg-green-100 rounded-lg text-xs font-medium transition">
                                            <i class="fas fa-check-circle"></i> Verify
                                        </button>
                                    @endif
                                @endcan
                                @can('delete partners')
                                    <form action="{{ route('partners.destroy', $partner) }}" method="POST" class="inline"
                                          onsubmit="return confirm('Delete this partner? This cannot be undone.')">
                                        @csrf @method('DELETE')
                                        <button type="submit"
                                                class="inline-flex items-center gap-1 px-2.5 py-1 bg-red-50 text-red-700 hover:bg-red-100 rounded-lg text-xs font-medium transition">
                                            <i class="fas fa-trash"></i> Delete
                                        </button>
                                    </form>
                                @endcan
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="6" class="px-4 py-14 text-center text-gray-500">
                            <i class="fas fa-building text-5xl text-gray-300 mb-3 block"></i>
                            <p class="font-medium text-gray-600">No partners found.</p>
                            <p class="text-sm text-gray-400 mt-1">Try adjusting your search or filter criteria.</p>
                        </td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    @if(method_exists($partners, 'hasPages') && $partners->hasPages())
        <div class="px-4 py-3 border-t border-gray-200 bg-gray-50">
            {{ $partners->withQueryString()->links() }}
        </div>
    @endif
</div>
