<div>
    {{-- Flash Messages --}}
    @if(session('success'))
    <div class="mb-4 p-4 bg-green-50 border border-green-200 rounded-lg text-green-700 text-sm">
        {{ session('success') }}
    </div>
    @endif
    @if(session('error'))
    <div class="mb-4 p-4 bg-red-50 border border-red-200 rounded-lg text-red-700 text-sm">
        {{ session('error') }}
    </div>
    @endif

    {{-- Header Card --}}
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6 mb-4 sm:mb-6">
        <div class="flex flex-col sm:flex-row sm:items-start justify-between gap-4">
            <div class="flex items-center gap-4">
                <div class="w-14 h-14 rounded-full bg-indigo-100 flex items-center justify-center">
                    <span class="text-xl font-bold text-indigo-700">
                        {{ mb_substr($person?->name_ar ?? '', 0, 1) }}
                    </span>
                </div>
                <div>
                    <h1 class="text-xl font-bold text-gray-800">
                        {{ $person?->name_ar }}
                    </h1>
                    @if($person?->name)
                    <p class="text-sm text-gray-500" dir="ltr">
                        {{ $person->name }}
                    </p>
                    @endif
                    <div class="flex items-center gap-3 mt-1">
                        <span class="text-sm text-gray-500 font-mono" dir="ltr">{{ $employee->employee_number }}</span>
                        @php
                            $statusValue = $employee->status->value ?? $employee->status;
                            $statusColors = [
                                'active' => 'green',
                                'on_leave' => 'amber',
                                'suspended' => 'red',
                                'terminated' => 'gray',
                                'resigned' => 'orange',
                            ];
                            $color = $statusColors[$statusValue] ?? 'gray';
                        @endphp
                        <span class="px-2 py-0.5 text-xs bg-{{ $color }}-100 text-{{ $color }}-700 rounded-full font-medium">
                            {{ $employee->status->label() }}
                        </span>
                        @if($employee->position)
                        <span class="text-sm text-gray-500">{{ $employee->position }}</span>
                        @endif
                        @if($employee->department)
                        <span class="text-sm text-gray-400">|</span>
                        <span class="text-sm text-gray-500">{{ $employee->department }}</span>
                        @endif
                    </div>
                </div>
            </div>
            <div class="flex items-center gap-2 self-start sm:self-auto">
                @can('employees.delete')
                <button wire:click="delete"
                        wire:confirm="{{ __('هل أنت متأكد من حذف هذا الموظف؟ سيتم تعطيل حساب المستخدم المرتبط وتغيير حالة المدرب إلى غير نشط.') }}"
                        wire:loading.attr="disabled"
                        wire:target="delete"
                        class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 text-sm font-medium transition-colors">
                    <span wire:loading.remove wire:target="delete">{{ __('حذف الموظف') }}</span>
                    <span wire:loading wire:target="delete">{{ __('جارٍ الحذف...') }}</span>
                </button>
                @endcan
                @can('employees.update')
                <a href="{{ route('employees.edit', $employee) }}" wire:navigate
                   class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 text-sm font-medium">
                    {{ __('تعديل') }}
                </a>
                @endcan
                <a href="{{ route('employees.list') }}" wire:navigate
                   class="px-4 py-2 text-gray-600 hover:text-gray-800 text-sm">
                    {{ __('رجوع') }}
                </a>
            </div>
        </div>
    </div>

    {{-- KPI Row --}}
    <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3 sm:gap-4 mb-4 sm:mb-6">
        {{-- Tenure --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 rounded-lg bg-blue-50 flex items-center justify-center">
                    <svg class="w-5 h-5 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                    </svg>
                </div>
                <div>
                    <p class="text-xs text-gray-500">{{ __('مدة الخدمة') }}</p>
                    <p class="text-lg font-bold text-gray-800">
                        @if($tenureYears > 0)
                            {{ $tenureYears }} {{ __('سنة') }}
                            @if($tenureMonths > 0) {{ $tenureMonths }} {{ __('شهر') }} @endif
                        @elseif($tenureMonths > 0)
                            {{ $tenureMonths }} {{ __('شهر') }}
                        @else
                            {{ __('جديد') }}
                        @endif
                    </p>
                </div>
            </div>
        </div>

        {{-- Working Hours --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 rounded-lg bg-green-50 flex items-center justify-center">
                    <svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                </div>
                <div>
                    <p class="text-xs text-gray-500">{{ __('ساعات العمل/أسبوع') }}</p>
                    <p class="text-lg font-bold text-gray-800">{{ $employee->working_hours_per_week ?? '—' }}</p>
                </div>
            </div>
        </div>

        {{-- Direct Reports --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 rounded-lg bg-purple-50 flex items-center justify-center">
                    <svg class="w-5 h-5 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"/>
                    </svg>
                </div>
                <div>
                    <p class="text-xs text-gray-500">{{ __('المرؤوسين') }}</p>
                    <p class="text-lg font-bold text-gray-800">{{ $directReportsCount }}</p>
                </div>
            </div>
        </div>

        {{-- Documents --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 rounded-lg bg-amber-50 flex items-center justify-center">
                    <svg class="w-5 h-5 text-amber-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                    </svg>
                </div>
                <div>
                    <p class="text-xs text-gray-500">{{ __('المستندات') }}</p>
                    <p class="text-lg font-bold text-gray-800">{{ $documentsCount }}</p>
                </div>
            </div>
        </div>

        {{-- Monthly Salary --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 rounded-lg bg-emerald-50 flex items-center justify-center">
                    <svg class="w-5 h-5 text-emerald-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                </div>
                <div>
                    <p class="text-xs text-gray-500">{{ __('الراتب الشهري') }}</p>
                    <p class="text-lg font-bold text-gray-800" dir="ltr">
                        @if($monthlySalary > 0)
                            {{ number_format($monthlySalary / 100, 2) }} {{ __('ج.م') }}
                        @else
                            —
                        @endif
                    </p>
                </div>
            </div>
        </div>

        {{-- Trainer Status --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 rounded-lg bg-cyan-50 flex items-center justify-center">
                    <svg class="w-5 h-5 text-cyan-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                    </svg>
                </div>
                <div>
                    <p class="text-xs text-gray-500">{{ __('مدرب') }}</p>
                    @if($isTrainer)
                        <p class="text-lg font-bold text-green-600">{{ __('نعم') }}</p>
                    @else
                        <p class="text-lg font-bold text-gray-400">{{ __('لا') }}</p>
                    @endif
                </div>
            </div>
        </div>
    </div>

    {{-- Tabs --}}
    <div x-data="{ activeTab: @entangle('activeTab') }">
        <div class="border-b border-gray-200 mb-6">
            <nav class="flex gap-2 sm:gap-6 -mb-px overflow-x-auto pb-1">
                <button @click="activeTab = 'overview'"
                        :class="activeTab === 'overview' ? 'border-blue-600 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'"
                        class="pb-3 border-b-2 text-sm font-medium transition whitespace-nowrap">
                    {{ __('نظرة عامة') }}
                </button>
                <button @click="activeTab = 'team'"
                        :class="activeTab === 'team' ? 'border-blue-600 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'"
                        class="pb-3 border-b-2 text-sm font-medium transition whitespace-nowrap">
                    {{ __('الفريق') }}
                </button>
                <button @click="activeTab = 'documents'"
                        :class="activeTab === 'documents' ? 'border-blue-600 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'"
                        class="pb-3 border-b-2 text-sm font-medium transition whitespace-nowrap">
                    {{ __('المستندات') }}
                </button>
                <button @click="activeTab = 'timeline'"
                        :class="activeTab === 'timeline' ? 'border-blue-600 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'"
                        class="pb-3 border-b-2 text-sm font-medium transition whitespace-nowrap">
                    {{ __('السجل الزمني') }}
                </button>
            </nav>
        </div>

        {{-- Overview Tab --}}
        <div x-show="activeTab === 'overview'" x-cloak>
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
                {{-- Personal Info Card --}}
                <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
                    <h3 class="text-base font-semibold text-gray-800 mb-4">{{ __('البيانات الشخصية') }}</h3>
                    <dl class="space-y-3">
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('الهاتف') }}</dt>
                            <dd class="text-sm text-gray-800" dir="ltr">{{ $person?->phone ?? '—' }}</dd>
                        </div>
                        @if($person?->phone_secondary)
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('هاتف إضافي') }}</dt>
                            <dd class="text-sm text-gray-800" dir="ltr">{{ $person->phone_secondary }}</dd>
                        </div>
                        @endif
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('البريد الإلكتروني') }}</dt>
                            <dd class="text-sm text-gray-800" dir="ltr">{{ $person?->email ?? '—' }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('الرقم القومي') }}</dt>
                            <dd class="text-sm text-gray-800 font-mono" dir="ltr">{{ $person?->national_id ?? '—' }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('الجنس') }}</dt>
                            <dd class="text-sm text-gray-800">{{ $person?->gender === 'male' ? __('ذكر') : ($person?->gender === 'female' ? __('أنثى') : '—') }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('تاريخ الميلاد') }}</dt>
                            <dd class="text-sm text-gray-800" dir="ltr">{{ $person?->date_of_birth?->format('Y-m-d') ?? '—' }}</dd>
                        </div>
                        @if($person?->address)
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('العنوان') }}</dt>
                            <dd class="text-sm text-gray-800">{{ $person->address }}</dd>
                        </div>
                        @endif
                    </dl>
                </div>

                {{-- Employment Info Card --}}
                <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
                    <h3 class="text-base font-semibold text-gray-800 mb-4">{{ __('بيانات التوظيف') }}</h3>
                    <dl class="space-y-3">
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('المسمى الوظيفي') }}</dt>
                            <dd class="text-sm text-gray-800">{{ $employee->position ?? '—' }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('القسم') }}</dt>
                            <dd class="text-sm text-gray-800">{{ $employee->department ?? '—' }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('الفرع') }}</dt>
                            <dd class="text-sm text-gray-800">{{ $employee->branch?->name_ar ?? $employee->branch?->name ?? '—' }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('نوع التوظيف') }}</dt>
                            <dd class="text-sm text-gray-800">{{ $employee->employment_type?->label() ?? '—' }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('تاريخ البدء') }}</dt>
                            <dd class="text-sm text-gray-800" dir="ltr">{{ $employee->start_date?->format('Y-m-d') ?? '—' }}</dd>
                        </div>
                        @if($employee->end_date)
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('تاريخ الانتهاء') }}</dt>
                            <dd class="text-sm text-gray-800" dir="ltr">{{ $employee->end_date->format('Y-m-d') }}</dd>
                        </div>
                        @endif
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('المدير المباشر') }}</dt>
                            <dd class="text-sm text-gray-800">
                                @if($employee->manager)
                                    {{ $employee->manager->person?->name_ar ?? '—' }}
                                @else
                                    —
                                @endif
                            </dd>
                        </div>
                    </dl>
                </div>

                {{-- Compensation Card --}}
                <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
                    <h3 class="text-base font-semibold text-gray-800 mb-4">{{ __('بيانات التعويضات') }}</h3>
                    <dl class="space-y-3">
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('الراتب') }}</dt>
                            <dd class="text-sm text-gray-800" dir="ltr">
                                @if($employee->salary_amount)
                                    {{ number_format($employee->salary_amount / 100, 2) }} {{ __('ج.م') }}
                                @else
                                    —
                                @endif
                            </dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('دورة الصرف') }}</dt>
                            <dd class="text-sm text-gray-800">{{ $employee->salary_frequency?->label() ?? '—' }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('ساعات العمل الأسبوعية') }}</dt>
                            <dd class="text-sm text-gray-800">{{ $employee->working_hours_per_week ?? '—' }}</dd>
                        </div>
                        <div class="flex justify-between">
                            <dt class="text-sm text-gray-500">{{ __('المعادل الشهري') }}</dt>
                            <dd class="text-sm font-medium text-gray-800" dir="ltr">
                                @if($monthlySalary > 0)
                                    {{ number_format($monthlySalary / 100, 2) }} {{ __('ج.م') }}
                                @else
                                    —
                                @endif
                            </dd>
                        </div>
                    </dl>
                </div>

                {{-- Notes Card --}}
                @if($employee->notes)
                <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
                    <h3 class="text-base font-semibold text-gray-800 mb-4">{{ __('ملاحظات') }}</h3>
                    <p class="text-sm text-gray-600 whitespace-pre-line">{{ $employee->notes }}</p>
                </div>
                @endif
            </div>
        </div>

        {{-- Team Tab --}}
        <div x-show="activeTab === 'team'" x-cloak>
            <div class="space-y-6">
                {{-- Manager Card --}}
                <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
                    <h3 class="text-base font-semibold text-gray-800 mb-4">{{ __('المدير المباشر') }}</h3>
                    @if($employee->manager)
                    <div class="flex items-center gap-4">
                        <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center">
                            <span class="text-lg font-bold text-blue-700">
                                {{ mb_substr($employee->manager->person?->name_ar ?? '', 0, 1) }}
                            </span>
                        </div>
                        <div>
                            @can('employees.list')
                            <a href="{{ route('employees.show', $employee->manager) }}" wire:navigate
                               class="text-sm font-semibold text-blue-600 hover:text-blue-800 hover:underline">
                                {{ $employee->manager->person?->name_ar ?? '—' }}
                            </a>
                            @else
                            <p class="text-sm font-semibold text-gray-800">{{ $employee->manager->person?->name_ar ?? '—' }}</p>
                            @endcan
                            <p class="text-xs text-gray-500">{{ $employee->manager->position ?? '' }}</p>
                            <p class="text-xs text-gray-400">{{ $employee->manager->department ?? '' }}</p>
                        </div>
                    </div>
                    @else
                    <div class="text-center py-6">
                        <svg class="w-10 h-10 text-gray-300 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                        </svg>
                        <p class="text-gray-500 text-sm">{{ __('لا يوجد مدير مباشر') }}</p>
                    </div>
                    @endif
                </div>

                {{-- Direct Reports Table --}}
                <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
                    <div class="p-4 border-b border-gray-100">
                        <h3 class="text-base font-semibold text-gray-800">{{ __('المرؤوسين المباشرين') }} ({{ $directReportsCount }})</h3>
                    </div>

                    @if($employee->directReports->isNotEmpty())
                    <div class="overflow-x-auto">
                        <table class="w-full text-sm">
                            <thead class="bg-gray-50 border-b border-gray-200">
                                <tr>
                                    <th class="px-4 py-3 text-start font-medium text-gray-600">{{ __('الاسم') }}</th>
                                    <th class="px-4 py-3 text-start font-medium text-gray-600">{{ __('المسمى الوظيفي') }}</th>
                                    <th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('الحالة') }}</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-gray-100">
                                @foreach($employee->directReports as $report)
                                <tr class="hover:bg-gray-50">
                                    <td class="px-4 py-3">
                                        @can('employees.list')
                                        <a href="{{ route('employees.show', $report) }}" wire:navigate
                                           class="font-medium text-blue-600 hover:text-blue-800 hover:underline">
                                            {{ $report->person?->name_ar ?? '—' }}
                                        </a>
                                        @else
                                        <span class="font-medium text-gray-800">{{ $report->person?->name_ar ?? '—' }}</span>
                                        @endcan
                                    </td>
                                    <td class="px-4 py-3 text-gray-600">{{ $report->position ?? '—' }}</td>
                                    <td class="px-4 py-3 text-center">
                                        @php
                                            $rStatusValue = $report->status->value ?? $report->status;
                                            $rColor = $statusColors[$rStatusValue] ?? 'gray';
                                        @endphp
                                        <span class="px-2 py-0.5 text-xs bg-{{ $rColor }}-100 text-{{ $rColor }}-700 rounded-full font-medium">
                                            {{ $report->status->label() }}
                                        </span>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    @else
                    <div class="px-4 py-12 text-center">
                        <svg class="w-10 h-10 text-gray-300 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/>
                        </svg>
                        <p class="text-gray-500 text-sm">{{ __('لا يوجد مرؤوسين') }}</p>
                    </div>
                    @endif
                </div>
            </div>
        </div>

        {{-- Documents Tab --}}
        <div x-show="activeTab === 'documents'" x-cloak>
            <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
                <div class="p-4 border-b border-gray-100">
                    <h3 class="text-base font-semibold text-gray-800">{{ __('المستندات') }} ({{ $documentsCount }})</h3>
                </div>

                @if($employee->documents->isNotEmpty())
                <div class="overflow-x-auto">
                    <table class="w-full text-sm">
                        <thead class="bg-gray-50 border-b border-gray-200">
                            <tr>
                                <th class="px-4 py-3 text-start font-medium text-gray-600">{{ __('نوع المستند') }}</th>
                                <th class="px-4 py-3 text-start font-medium text-gray-600">{{ __('اسم الملف') }}</th>
                                <th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('الحالة') }}</th>
                                <th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('تاريخ الرفع') }}</th>
                                <th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('تاريخ الانتهاء') }}</th>
                                <th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('إجراء') }}</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-100">
                            @foreach($employee->documents as $document)
                            <tr class="hover:bg-gray-50">
                                <td class="px-4 py-3">
                                    <span class="font-medium text-gray-800">{{ $document->document_type?->label() ?? '—' }}</span>
                                </td>
                                <td class="px-4 py-3 text-gray-600">
                                    {{ $document->original_filename ?? '—' }}
                                </td>
                                <td class="px-4 py-3 text-center">
                                    @php
                                        $docStatusValue = $document->status->value ?? $document->status ?? 'pending';
                                        $docStatusColors = [
                                            'pending' => 'amber',
                                            'approved' => 'green',
                                            'rejected' => 'red',
                                            'expired' => 'gray',
                                        ];
                                        $docStatusLabels = [
                                            'pending' => 'قيد المراجعة',
                                            'approved' => 'معتمد',
                                            'rejected' => 'مرفوض',
                                            'expired' => 'منتهي',
                                        ];
                                        $dColor = $docStatusColors[$docStatusValue] ?? 'gray';
                                    @endphp
                                    <span class="px-2 py-0.5 text-xs bg-{{ $dColor }}-100 text-{{ $dColor }}-700 rounded-full">
                                        {{ __($docStatusLabels[$docStatusValue] ?? $docStatusValue) }}
                                    </span>
                                </td>
                                <td class="px-4 py-3 text-center text-gray-600" dir="ltr">
                                    {{ $document->created_at?->format('Y-m-d') ?? '—' }}
                                </td>
                                <td class="px-4 py-3 text-center" dir="ltr">
                                    @if($document->expires_at)
                                        <span class="{{ $document->isExpired() ? 'text-red-600 font-medium' : 'text-gray-600' }}">
                                            {{ $document->expires_at->format('Y-m-d') }}
                                        </span>
                                    @else
                                        <span class="text-gray-400">—</span>
                                    @endif
                                </td>
                                <td class="px-4 py-3 text-center">
                                    @if($document->file_path)
                                    <a href="{{ Storage::url($document->file_path) }}" target="_blank"
                                       class="inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-blue-600 hover:text-blue-800 bg-blue-50 rounded hover:bg-blue-100 transition">
                                        <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                                        </svg>
                                        {{ __('تحميل') }}
                                    </a>
                                    @else
                                    <span class="text-gray-400 text-xs">—</span>
                                    @endif
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
                @else
                <div class="px-4 py-12 text-center">
                    <svg class="w-10 h-10 text-gray-300 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                    </svg>
                    <p class="text-gray-500 text-sm">{{ __('لا توجد مستندات مرفوعة') }}</p>
                </div>
                @endif
            </div>
        </div>

        {{-- Timeline Tab --}}
        <div x-show="activeTab === 'timeline'" x-cloak>
            <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
                <h3 class="text-base font-semibold text-gray-800 mb-6">{{ __('السجل الزمني') }}</h3>

                <div class="relative">
                    {{-- Timeline line --}}
                    <div class="absolute top-0 bottom-0 start-4 w-0.5 bg-gray-200"></div>

                    <div class="space-y-6">
                        {{-- Start Date --}}
                        @if($employee->start_date)
                        <div class="relative flex items-start gap-4 ps-10">
                            <div class="absolute start-2 w-4 h-4 rounded-full bg-green-500 border-2 border-white shadow"></div>
                            <div>
                                <p class="text-sm font-medium text-gray-800">{{ __('تاريخ بدء العمل') }}</p>
                                <p class="text-sm text-gray-600" dir="ltr">{{ $employee->start_date->format('Y-m-d') }}</p>
                                @if($employee->employment_type)
                                <p class="text-xs text-gray-500 mt-1">{{ __('نوع التوظيف') }}: {{ $employee->employment_type->label() }}</p>
                                @endif
                            </div>
                        </div>
                        @endif

                        {{-- Trainer linked --}}
                        @if($isTrainer)
                        <div class="relative flex items-start gap-4 ps-10">
                            <div class="absolute start-2 w-4 h-4 rounded-full bg-cyan-500 border-2 border-white shadow"></div>
                            <div>
                                <p class="text-sm font-medium text-gray-800">{{ __('تعيين كمدرب') }}</p>
                                <p class="text-xs text-gray-500">{{ __('الموظف مسجل كمدرب في النظام') }}</p>
                            </div>
                        </div>
                        @endif

                        {{-- End Date (if terminated/resigned) --}}
                        @if($employee->end_date)
                        <div class="relative flex items-start gap-4 ps-10">
                            <div class="absolute start-2 w-4 h-4 rounded-full bg-red-500 border-2 border-white shadow"></div>
                            <div>
                                <p class="text-sm font-medium text-gray-800">{{ __('تاريخ انتهاء الخدمة') }}</p>
                                <p class="text-sm text-gray-600" dir="ltr">{{ $employee->end_date->format('Y-m-d') }}</p>
                                @if($employee->termination_reason)
                                <div class="mt-2 p-3 bg-red-50 rounded-lg border border-red-100">
                                    <p class="text-xs text-red-600 font-medium mb-1">{{ __('سبب إنهاء الخدمة') }}:</p>
                                    <p class="text-sm text-red-700">{{ $employee->termination_reason }}</p>
                                </div>
                                @endif
                            </div>
                        </div>
                        @endif

                        {{-- Notes --}}
                        @if($employee->notes)
                        <div class="relative flex items-start gap-4 ps-10">
                            <div class="absolute start-2 w-4 h-4 rounded-full bg-gray-400 border-2 border-white shadow"></div>
                            <div>
                                <p class="text-sm font-medium text-gray-800">{{ __('ملاحظات') }}</p>
                                <p class="text-sm text-gray-600 whitespace-pre-line mt-1">{{ $employee->notes }}</p>
                            </div>
                        </div>
                        @endif

                        {{-- Current status --}}
                        @if(!$employee->end_date)
                        <div class="relative flex items-start gap-4 ps-10">
                            <div class="absolute start-2 w-4 h-4 rounded-full bg-blue-500 border-2 border-white shadow animate-pulse"></div>
                            <div>
                                <p class="text-sm font-medium text-gray-800">{{ __('الحالة الحالية') }}</p>
                                <span class="px-2 py-0.5 text-xs bg-{{ $color }}-100 text-{{ $color }}-700 rounded-full font-medium">
                                    {{ $employee->status->label() }}
                                </span>
                            </div>
                        </div>
                        @endif
                    </div>
                </div>

                {{-- Empty state if no start date --}}
                @if(!$employee->start_date && !$employee->end_date && !$employee->notes)
                <div class="text-center py-8">
                    <svg class="w-10 h-10 text-gray-300 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                    <p class="text-gray-500 text-sm">{{ __('لا توجد بيانات زمنية متاحة') }}</p>
                </div>
                @endif
            </div>
        </div>
    </div>
</div>
