<div>
    {{-- Header --}}
    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4 sm:mb-6">
        <div>
            <h1 class="text-xl sm:text-2xl font-bold text-gray-800">{{ __('تسجيل في مجموعة') }}</h1>
            <p class="text-sm text-gray-500 mt-1">{{ __('اختر المشترك والمجموعة لإتمام التسجيل') }}</p>
        </div>
        <a href="{{ route('enrollments.list') }}" wire:navigate
           class="text-sm text-gray-600 hover:text-gray-800 flex items-center gap-1">
            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 17l-5-5m0 0l5-5m-5 5h12"/>
            </svg>
            {{ __('العودة للقائمة') }}
        </a>
    </div>

    {{-- Flash Messages --}}
    @if(session('error'))
    <div class="mb-4 p-4 bg-red-50 border border-red-200 rounded-lg text-red-700 text-sm flex items-start gap-2">
        <svg class="w-5 h-5 shrink-0 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
        </svg>
        <span>{{ session('error') }}</span>
    </div>
    @endif

    @if(session('success'))
    <div class="mb-4 p-4 bg-green-50 border border-green-200 rounded-lg text-green-700 text-sm flex items-start gap-2">
        <svg class="w-5 h-5 shrink-0 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
        </svg>
        <span>{{ session('success') }}</span>
    </div>
    @endif

    {{-- Progress Steps Indicator --}}
    <div class="mb-6">
        <div class="flex items-center justify-center gap-2 sm:gap-4">
            {{-- Step 1 --}}
            <div class="flex items-center gap-2">
                <div class="w-8 h-8 rounded-full flex items-center justify-center text-sm font-bold
                    {{ $participantId ? 'bg-green-500 text-white' : 'bg-blue-600 text-white' }}">
                    @if($participantId)
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/>
                        </svg>
                    @else
                        1
                    @endif
                </div>
                <span class="text-xs sm:text-sm font-medium text-gray-700 hidden sm:inline">{{ __('المشترك') }}</span>
            </div>

            <div class="flex-1 h-0.5 max-w-12 {{ $participantId ? 'bg-green-300' : 'bg-gray-200' }}"></div>

            {{-- Step 2 --}}
            <div class="flex items-center gap-2">
                <div class="w-8 h-8 rounded-full flex items-center justify-center text-sm font-bold
                    {{ $trainingGroupId ? 'bg-green-500 text-white' : ($participantId ? 'bg-blue-600 text-white' : 'bg-gray-200 text-gray-500') }}">
                    @if($trainingGroupId)
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/>
                        </svg>
                    @else
                        2
                    @endif
                </div>
                <span class="text-xs sm:text-sm font-medium text-gray-700 hidden sm:inline">{{ __('المجموعة') }}</span>
            </div>

            <div class="flex-1 h-0.5 max-w-12 {{ $trainingGroupId ? 'bg-green-300' : 'bg-gray-200' }}"></div>

            {{-- Step 3 --}}
            <div class="flex items-center gap-2">
                <div class="w-8 h-8 rounded-full flex items-center justify-center text-sm font-bold
                    {{ $trainingGroupId ? 'bg-blue-600 text-white' : 'bg-gray-200 text-gray-500' }}">
                    3
                </div>
                <span class="text-xs sm:text-sm font-medium text-gray-700 hidden sm:inline">{{ __('التأكيد') }}</span>
            </div>
        </div>
    </div>

    <div class="space-y-6">
        {{-- ═══════════════════════════════════════════════════════════════
             PANEL 1: Select Participant
        ═══════════════════════════════════════════════════════════════ --}}
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
            <div class="px-4 sm:px-6 py-4 border-b border-gray-100 bg-gray-50/50">
                <h2 class="text-base font-semibold text-gray-800 flex items-center gap-2">
                    <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="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                    </svg>
                    {{ __('اختيار المشترك') }}
                </h2>
            </div>

            <div class="p-4 sm:p-6">
                {{-- Search Input --}}
                <div class="relative">
                    <label for="participantSearch" class="block text-sm font-medium text-gray-700 mb-2">
                        {{ __('ابحث عن المشترك') }} <span class="text-red-500">*</span>
                    </label>
                    <div class="relative">
                        <input type="text"
                               id="participantSearch"
                               wire:model.live.debounce.300ms="participantSearch"
                               placeholder="{{ __('اكتب اسم المشترك أو رقم العضوية أو رقم الهاتف...') }}"
                               class="w-full ps-10 pe-4 py-2.5 text-sm border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
                               autocomplete="off">
                        <div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
                            <svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                            </svg>
                        </div>
                        <div wire:loading wire:target="participantSearch" class="absolute inset-y-0 end-0 flex items-center pe-3">
                            <svg class="animate-spin w-4 h-4 text-blue-500" fill="none" viewBox="0 0 24 24">
                                <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
                                <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/>
                            </svg>
                        </div>
                    </div>

                    {{-- Search Results Dropdown --}}
                    @if(strlen($participantSearch) >= 2 && !$participantId)
                    <div class="absolute z-20 w-full mt-1 bg-white border border-gray-200 rounded-lg shadow-lg max-h-60 overflow-y-auto">
                        @forelse($this->searchResults as $result)
                        <button type="button"
                                wire:click="$set('participantId', {{ $result->id }})"
                                class="w-full text-start px-4 py-3 hover:bg-blue-50 border-b border-gray-100 last:border-0 transition-colors">
                            <div class="flex items-center justify-between">
                                <div>
                                    <span class="text-sm font-medium text-gray-800">{{ $result->person?->name_ar ?? $result->person?->name }}</span>
                                    @if($result->participant_number)
                                    <span class="text-xs text-gray-500 ms-2">#{{ $result->participant_number }}</span>
                                    @endif
                                </div>
                                <span class="text-xs px-2 py-0.5 rounded-full {{ $this->getStatusBadgeClass($result->status->value) }}">
                                    {{ $this->getStatusLabel($result->status->value) }}
                                </span>
                            </div>
                            @if($result->person?->phone)
                            <p class="text-xs text-gray-500 mt-0.5" dir="ltr">{{ $result->person->phone }}</p>
                            @endif
                        </button>
                        @empty
                        <div class="px-4 py-3 text-sm text-gray-500 text-center">
                            {{ __('لا توجد نتائج') }}
                        </div>
                        @endforelse
                    </div>
                    @endif
                </div>

                @error('participantId')
                <p class="mt-2 text-xs text-red-600">{{ $message }}</p>
                @enderror

                {{-- Selected Participant Card --}}
                @if($participantData)
                <div class="mt-4 p-4 rounded-lg border {{ $participantData['is_blocked'] ? 'border-red-200 bg-red-50' : 'border-green-200 bg-green-50' }}">
                    <div class="flex items-start justify-between">
                        <div class="flex items-center gap-3">
                            <div class="w-10 h-10 rounded-full bg-gray-200 flex items-center justify-center">
                                <svg class="w-5 h-5 text-gray-500" 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>
                                <h3 class="text-sm font-semibold text-gray-800">{{ $participantData['name'] }}</h3>
                                <div class="flex items-center gap-3 mt-1 text-xs text-gray-600">
                                    <span class="px-2 py-0.5 rounded-full {{ $this->getStatusBadgeClass($participantData['status']) }}">
                                        {{ $this->getStatusLabel($participantData['status']) }}
                                    </span>
                                    @if($participantData['age'])
                                    <span>{{ $participantData['age'] }} {{ __('سنة') }}</span>
                                    @endif
                                    <span>{{ $participantData['enrollments_count'] }} {{ __('تسجيل نشط') }}</span>
                                </div>
                            </div>
                        </div>
                        <div class="flex items-center gap-2">
                            <div class="text-end">
                                <p class="text-xs text-gray-500">{{ __('رصيد المحفظة') }}</p>
                                <p class="text-sm font-semibold text-gray-800" dir="ltr">{{ $this->formatMoney($participantData['wallet_balance']) }}</p>
                            </div>
                            <button type="button"
                                    wire:click="$set('participantId', null)"
                                    class="ms-2 p-1 text-gray-400 hover:text-red-500 transition-colors"
                                    title="{{ __('تغيير المشترك') }}">
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                                </svg>
                            </button>
                        </div>
                    </div>

                    {{-- Blocked Status Warning --}}
                    @if($participantData['is_blocked'])
                    <div class="mt-3 p-3 bg-red-100 border border-red-300 rounded-lg flex items-center gap-2">
                        <svg class="w-5 h-5 text-red-600 shrink-0" fill="currentColor" viewBox="0 0 20 20">
                            <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
                        </svg>
                        <p class="text-sm font-medium text-red-800">
                            {{ __('لا يمكن تسجيل هذا المشترك — الحالة:') }} {{ $this->getStatusLabel($participantData['status']) }}
                        </p>
                    </div>
                    @endif
                </div>
                @endif
            </div>
        </div>

        {{-- ═══════════════════════════════════════════════════════════════
             PANEL 2: Select Group (only visible after participant selected)
        ═══════════════════════════════════════════════════════════════ --}}
        @if($participantId && $participantData && !$participantData['is_blocked'])
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden" wire:transition>
            <div class="px-4 sm:px-6 py-4 border-b border-gray-100 bg-gray-50/50">
                <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
                    <h2 class="text-base font-semibold text-gray-800 flex items-center gap-2">
                        <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="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>
                        {{ __('اختيار المجموعة') }}
                    </h2>

                    {{-- Program Filter --}}
                    <div class="flex items-center gap-2">
                        <label for="programFilter" class="text-xs text-gray-600 whitespace-nowrap">{{ __('فلترة بالبرنامج:') }}</label>
                        <select wire:model.live="programFilter" id="programFilter"
                                class="text-sm border border-gray-300 rounded-lg px-3 py-1.5 focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                            <option value="">{{ __('الكل') }}</option>
                            @foreach($this->availablePrograms as $program)
                            <option value="{{ $program->id }}">{{ $program->name_ar }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>

            <div class="p-4 sm:p-6">
                {{-- Loading state --}}
                <div wire:loading wire:target="programFilter" class="flex justify-center py-8">
                    <svg class="animate-spin w-6 h-6 text-blue-500" fill="none" viewBox="0 0 24 24">
                        <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
                        <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/>
                    </svg>
                </div>

                {{-- Groups Grid --}}
                <div wire:loading.remove wire:target="programFilter" class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
                    @forelse($this->availableGroups as $group)
                    @php
                        $isSelected = $trainingGroupId === $group->id;
                        $isFull = $group->isFull();
                        $capacityPct = $this->getCapacityPercentage($group->current_count, $group->max_capacity);
                    @endphp
                    <button type="button"
                            wire:click="selectGroup({{ $group->id }})"
                            class="text-start p-4 rounded-xl border-2 transition-all duration-200 hover:shadow-md
                                {{ $isSelected ? 'border-blue-500 bg-blue-50 ring-2 ring-blue-200' : 'border-gray-200 hover:border-blue-300 bg-white' }}">

                        {{-- Group Header --}}
                        <div class="flex items-start justify-between mb-3">
                            <div>
                                <h3 class="text-sm font-bold text-gray-800">{{ $group->name_ar }}</h3>
                                @if($group->code)
                                <p class="text-xs text-gray-500 mt-0.5">{{ $group->code }}</p>
                                @endif
                            </div>
                            <span class="text-xs px-2 py-0.5 rounded-full {{ $this->getStatusBadgeClass($group->status->value) }}">
                                @if($isFull)
                                    {{ __('ممتلئة') }}
                                @else
                                    {{ $this->getStatusLabel($group->status->value) }}
                                @endif
                            </span>
                        </div>

                        {{-- Program Name --}}
                        @if($group->program)
                        <p class="text-xs text-blue-600 font-medium mb-2">{{ $group->program->name_ar }}</p>
                        @endif

                        {{-- Trainer --}}
                        @if($group->headTrainer)
                        <div class="flex items-center gap-1.5 text-xs text-gray-600 mb-2">
                            <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="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                            </svg>
                            <span>{{ $group->headTrainer->name }}</span>
                        </div>
                        @endif

                        {{-- Schedule --}}
                        @if($group->schedules->where('is_active', true)->isNotEmpty())
                        <div class="flex flex-wrap gap-1 mb-3">
                            @foreach($group->schedules->where('is_active', true) as $schedule)
                            <span class="inline-flex items-center gap-1 text-xs bg-gray-100 text-gray-700 px-2 py-1 rounded">
                                <svg class="w-3 h-3" 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>
                                {{ $schedule->day_name }} {{ substr($schedule->start_time, 0, 5) }}-{{ substr($schedule->end_time, 0, 5) }}
                            </span>
                            @endforeach
                        </div>
                        @endif

                        {{-- Capacity Bar --}}
                        <div class="mt-auto">
                            <div class="flex items-center justify-between text-xs text-gray-600 mb-1">
                                <span>{{ __('السعة') }}</span>
                                <span class="font-medium" dir="ltr">{{ $group->current_count }}/{{ $group->max_capacity }}</span>
                            </div>
                            <div class="w-full h-2 bg-gray-200 rounded-full overflow-hidden">
                                <div class="h-full rounded-full transition-all duration-300 {{ $this->getCapacityColor($group->current_count, $group->max_capacity) }}"
                                     style="width: {{ min($capacityPct, 100) }}%"></div>
                            </div>
                            @if($isFull && $group->program?->allow_waitlist)
                            <p class="text-xs text-amber-600 font-medium mt-1">{{ __('ممتلئة - قائمة انتظار') }}</p>
                            @elseif($isFull)
                            <p class="text-xs text-red-600 font-medium mt-1">{{ __('ممتلئة - لا تقبل تسجيلات') }}</p>
                            @endif
                        </div>

                        {{-- Selected Indicator --}}
                        @if($isSelected)
                        <div class="mt-3 flex items-center justify-center gap-1 text-xs text-blue-700 font-medium">
                            <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
                                <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
                            </svg>
                            {{ __('تم الاختيار') }}
                        </div>
                        @endif
                    </button>
                    @empty
                    <div class="col-span-full flex flex-col items-center justify-center py-12 text-gray-400">
                        <svg class="w-12 h-12 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 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"/>
                        </svg>
                        <p class="text-sm font-medium">{{ __('لا توجد مجموعات متاحة') }}</p>
                        <p class="text-xs mt-1">{{ __('جرب تغيير فلتر البرنامج') }}</p>
                    </div>
                    @endforelse
                </div>

                @error('trainingGroupId')
                <p class="mt-3 text-xs text-red-600">{{ $message }}</p>
                @enderror

                {{-- Schedule Conflict Warning --}}
                @if(!empty($scheduleConflicts))
                <div class="mt-4 p-4 bg-amber-50 border border-amber-200 rounded-lg">
                    <div class="flex items-start gap-2">
                        <svg class="w-5 h-5 text-amber-600 shrink-0 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
                            <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
                        </svg>
                        <div>
                            <h4 class="text-sm font-semibold text-amber-800">{{ __('تعارض في الجدول') }}</h4>
                            <ul class="mt-1 space-y-1">
                                @foreach($scheduleConflicts as $conflict)
                                <li class="text-xs text-amber-700">
                                    {{ $conflict['day'] }} {{ $conflict['time'] }} {{ __('مع') }} "{{ $conflict['conflicting_group'] }}"
                                </li>
                                @endforeach
                            </ul>
                            <p class="text-xs text-amber-600 mt-2">{{ __('يمكنك المتابعة لكن قد يحدث تداخل في المواعيد') }}</p>
                        </div>
                    </div>
                </div>
                @endif

                {{-- Waitlist Notice --}}
                @if($isGroupFull && $selectedGroupData)
                <div class="mt-4 p-4 bg-blue-50 border border-blue-200 rounded-lg flex items-start gap-2">
                    <svg class="w-5 h-5 text-blue-600 shrink-0 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
                        <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/>
                    </svg>
                    <p class="text-sm text-blue-800">
                        {{ __('هذه المجموعة ممتلئة. سيتم إضافة المشترك إلى قائمة الانتظار عند التأكيد.') }}
                    </p>
                </div>
                @endif
            </div>
        </div>
        @endif

        {{-- ═══════════════════════════════════════════════════════════════
             PANEL 3: Price & Confirmation (only visible after group selected)
        ═══════════════════════════════════════════════════════════════ --}}
        @if($trainingGroupId && $selectedGroupData)
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden" wire:transition>
            <div class="px-4 sm:px-6 py-4 border-b border-gray-100 bg-gray-50/50">
                <h2 class="text-base font-semibold text-gray-800 flex items-center gap-2">
                    <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="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                    {{ __('معاينة السعر والتأكيد') }}
                </h2>
            </div>

            <div class="p-4 sm:p-6">
                <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
                    {{-- Price Preview Card --}}
                    <div>
                        <h3 class="text-sm font-semibold text-gray-700 mb-3">{{ __('تفاصيل السعر') }}</h3>

                        @if($pricePreview)
                        <div class="border border-gray-200 rounded-lg overflow-hidden">
                            {{-- Base Price --}}
                            <div class="flex items-center justify-between px-4 py-3 border-b border-gray-100">
                                <span class="text-sm text-gray-600">{{ __('السعر الأساسي') }}</span>
                                <span class="text-sm font-medium text-gray-800" dir="ltr">{{ $this->formatMoney($pricePreview['base_amount']) }}</span>
                            </div>

                            {{-- Applied Discounts --}}
                            @if(!empty($pricePreview['applied_rules']))
                            @foreach($pricePreview['applied_rules'] as $rule)
                            <div class="flex items-center justify-between px-4 py-2 border-b border-gray-100 bg-green-50/50">
                                <span class="text-xs text-green-700 flex items-center gap-1">
                                    <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"/>
                                    </svg>
                                    {{ $rule['rule_name'] }}
                                </span>
                                <span class="text-xs font-medium text-green-700" dir="ltr">-{{ $this->formatMoney($rule['discount']) }}</span>
                            </div>
                            @endforeach
                            @endif

                            {{-- Total Discount Summary --}}
                            @if($pricePreview['has_discount'])
                            <div class="flex items-center justify-between px-4 py-2 border-b border-gray-100 bg-green-50">
                                <span class="text-xs font-medium text-green-800">{{ __('إجمالي الخصم') }} ({{ $pricePreview['discount_percentage'] }}%)</span>
                                <span class="text-xs font-bold text-green-800" dir="ltr">-{{ $this->formatMoney($pricePreview['total_discount']) }}</span>
                            </div>
                            @endif

                            {{-- Final Amount --}}
                            <div class="flex items-center justify-between px-4 py-3 bg-blue-50">
                                <span class="text-sm font-bold text-blue-900">{{ __('المبلغ المطلوب') }}</span>
                                <span class="text-lg font-bold text-blue-900" dir="ltr">{{ $this->formatMoney($pricePreview['final_amount']) }}</span>
                            </div>
                        </div>
                        @elseif($priceError)
                        <div class="p-4 bg-amber-50 border border-amber-200 rounded-lg">
                            <div class="flex items-center gap-2">
                                <svg class="w-5 h-5 text-amber-600" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/>
                                </svg>
                                <p class="text-sm text-amber-800">{{ $priceError }}</p>
                            </div>
                            <p class="text-xs text-amber-600 mt-1">{{ __('سيتم التسجيل بدون فاتورة تلقائية') }}</p>
                        </div>
                        @else
                        <div class="p-4 bg-gray-50 border border-gray-200 rounded-lg text-center">
                            <svg class="w-8 h-8 text-gray-300 mx-auto mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" 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>
                            <p class="text-xs text-gray-500">{{ __('جارٍ حساب السعر...') }}</p>
                        </div>
                        @endif
                    </div>

                    {{-- Enrollment Options --}}
                    <div class="space-y-4">
                        <h3 class="text-sm font-semibold text-gray-700 mb-3">{{ __('خيارات التسجيل') }}</h3>

                        {{-- Start Date --}}
                        <div>
                            <label for="startDate" class="block text-sm font-medium text-gray-700 mb-1">
                                {{ __('تاريخ البدء') }}
                            </label>
                            <input type="date" wire:model="startDate" id="startDate" dir="ltr"
                                   class="w-full px-4 py-2.5 text-sm border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 @error('startDate') border-red-500 @enderror">
                            @error('startDate')
                            <p class="mt-1 text-xs text-red-600">{{ $message }}</p>
                            @enderror
                        </div>

                        {{-- Auto Invoice Toggle --}}
                        <div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg border border-gray-200">
                            <div>
                                <label for="autoInvoice" class="text-sm font-medium text-gray-700 cursor-pointer">
                                    {{ __('إنشاء فاتورة تلقائياً') }}
                                </label>
                                <p class="text-xs text-gray-500 mt-0.5">{{ __('سيتم إنشاء فاتورة بالمبلغ المحسوب') }}</p>
                            </div>
                            <label class="relative inline-flex items-center cursor-pointer">
                                <input type="checkbox" wire:model="autoInvoice" id="autoInvoice" class="sr-only peer">
                                <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-blue-600"></div>
                            </label>
                        </div>

                        {{-- Notes --}}
                        <div>
                            <label for="notes" class="block text-sm font-medium text-gray-700 mb-1">
                                {{ __('ملاحظات') }}
                            </label>
                            <textarea wire:model="notes" id="notes" rows="3"
                                      class="w-full px-4 py-2.5 text-sm border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 @error('notes') border-red-500 @enderror"
                                      placeholder="{{ __('ملاحظات إضافية (اختياري)...') }}"></textarea>
                            @error('notes')
                            <p class="mt-1 text-xs text-red-600">{{ $message }}</p>
                            @enderror
                        </div>
                    </div>
                </div>

                {{-- Enrollment Summary --}}
                <div class="mt-6 p-4 bg-gray-50 rounded-lg border border-gray-200">
                    <h4 class="text-xs font-semibold text-gray-500 uppercase mb-2">{{ __('ملخص التسجيل') }}</h4>
                    <div class="grid grid-cols-1 sm:grid-cols-3 gap-3 text-sm">
                        <div>
                            <span class="text-gray-500">{{ __('المشترك:') }}</span>
                            <span class="font-medium text-gray-800 ms-1">{{ $participantData['name'] ?? '' }}</span>
                        </div>
                        <div>
                            <span class="text-gray-500">{{ __('المجموعة:') }}</span>
                            <span class="font-medium text-gray-800 ms-1">{{ $selectedGroupData['name'] ?? '' }}</span>
                        </div>
                        <div>
                            <span class="text-gray-500">{{ __('البرنامج:') }}</span>
                            <span class="font-medium text-gray-800 ms-1">{{ $selectedGroupData['program_name'] ?? '' }}</span>
                        </div>
                    </div>
                </div>

                {{-- Submit Actions --}}
                <div class="mt-6 flex flex-col-reverse sm:flex-row items-stretch sm:items-center justify-end gap-3 pt-4 border-t border-gray-200">
                    <a href="{{ route('enrollments.list') }}" wire:navigate
                       class="text-center px-6 py-2.5 text-sm text-gray-700 hover:bg-gray-100 rounded-lg border border-gray-300 font-medium transition-colors">
                        {{ __('إلغاء') }}
                    </a>
                    <button type="button"
                            wire:click="save"
                            wire:loading.attr="disabled"
                            wire:target="save"
                            @if(!empty($scheduleConflicts))
                            wire:confirm="{{ __('يوجد تعارض في الجدول. هل تريد المتابعة؟') }}"
                            @endif
                            @if($participantData && $participantData['is_blocked'])
                            disabled
                            @endif
                            class="text-center px-6 py-2.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2">
                        <span wire:loading.remove wire:target="save">
                            <svg class="w-4 h-4 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
                            </svg>
                            {{ __('تسجيل في المجموعة') }}
                        </span>
                        <span wire:loading wire:target="save" class="flex items-center gap-2">
                            <svg class="animate-spin w-4 h-4" fill="none" viewBox="0 0 24 24">
                                <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
                                <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/>
                            </svg>
                            {{ __('جارٍ التسجيل...') }}
                        </span>
                    </button>
                </div>
            </div>
        </div>
        @endif
    </div>
</div>
