<div>
    {{-- Header --}}
    <div class="flex items-center justify-between 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('receptionist.dashboard') }}" wire:navigate
           class="inline-flex items-center gap-2 px-4 py-2 text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200 text-sm font-medium transition-colors">
            <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>
            {{ __('العودة للاستقبال') }}
        </a>
    </div>

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

    {{-- Step Indicator --}}
    @if($currentStep < 5)
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 mb-6">
        <div class="flex items-center justify-between">
            @php
                $steps = [
                    1 => 'بحث عن المشترك',
                    2 => 'الفواتير المستحقة',
                    3 => 'تحديد المبلغ',
                    4 => 'تأكيد',
                ];
            @endphp
            @foreach($steps as $num => $label)
            <div class="flex items-center {{ !$loop->last ? 'flex-1' : '' }}">
                <button wire:click="goToStep({{ $num }})"
                        @if($num >= $currentStep) disabled @endif
                        class="flex items-center gap-2 {{ $num < $currentStep ? 'cursor-pointer' : 'cursor-default' }}">
                    <div class="w-8 h-8 rounded-full flex items-center justify-center text-sm font-bold transition-colors
                        {{ $num === $currentStep ? 'bg-amber-600 text-white' : '' }}
                        {{ $num < $currentStep ? 'bg-green-500 text-white' : '' }}
                        {{ $num > $currentStep ? 'bg-gray-200 text-gray-500' : '' }}">
                        @if($num < $currentStep)
                            <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="M5 13l4 4L19 7"/>
                            </svg>
                        @else
                            {{ $num }}
                        @endif
                    </div>
                    <span class="text-xs font-medium hidden sm:inline
                        {{ $num === $currentStep ? 'text-amber-600' : '' }}
                        {{ $num < $currentStep ? 'text-green-600' : '' }}
                        {{ $num > $currentStep ? 'text-gray-400' : '' }}">
                        {{ __($label) }}
                    </span>
                </button>
                @if(!$loop->last)
                <div class="flex-1 h-0.5 mx-3 {{ $num < $currentStep ? 'bg-green-500' : 'bg-gray-200' }}"></div>
                @endif
            </div>
            @endforeach
        </div>
    </div>
    @endif

    {{-- Step Content --}}
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
        {{-- Step 1: Search Participant or Invoice --}}
        @if($currentStep === 1)
        <div>
            <h2 class="text-lg font-semibold text-gray-800 mb-4">{{ __('بحث عن المشترك أو الفاتورة') }}</h2>

            {{-- Search Mode Tabs --}}
            <div class="flex gap-2 mb-4">
                <button wire:click="switchSearchMode('participant')"
                        class="px-4 py-2 rounded-lg text-sm font-medium transition-colors
                            {{ $searchMode === 'participant' ? 'bg-amber-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200' }}">
                    {{ __('بحث بالمشترك') }}
                </button>
                <button wire:click="switchSearchMode('invoice')"
                        class="px-4 py-2 rounded-lg text-sm font-medium transition-colors
                            {{ $searchMode === 'invoice' ? 'bg-amber-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200' }}">
                    {{ __('بحث برقم الفاتورة') }}
                </button>
            </div>

            {{-- Search Input --}}
            <div class="mb-6">
                <input type="text" wire:model.live.debounce.300ms="search"
                       class="w-full px-4 py-3 min-h-16 border border-gray-300 rounded-lg focus:ring-2 focus:ring-amber-500 focus:border-amber-500 text-lg"
                       placeholder="{{ $searchMode === 'participant' ? __('بحث بالاسم، الهاتف، الرقم القومي، أو رقم المشترك...') : __('بحث برقم الفاتورة أو اسم العميل...') }}">
            </div>

            @if($searchMode === 'participant')
                {{-- Selected Participant Indicator --}}
                @if($selected_participant_id)
                <div class="mb-4 p-4 bg-amber-50 border border-amber-200 rounded-xl flex items-center justify-between">
                    <div class="flex items-center gap-3">
                        <div class="w-10 h-10 rounded-full bg-amber-200 flex items-center justify-center">
                            <svg class="w-5 h-5 text-amber-700" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                            </svg>
                        </div>
                        <span class="font-medium text-amber-800">{{ $selected_participant_name }}</span>
                        @if($selected_participant_is_free) <x-ui.free-player-badge :small="true" /> @endif
                    </div>
                    <button wire:click="$set('selected_participant_id', null)" class="text-amber-600 hover:text-amber-800 text-sm">
                        {{ __('تغيير') }}
                    </button>
                </div>
                @endif

                {{-- Participant Search Results --}}
                @if(strlen($search) >= 2 && !$selected_participant_id)
                <div class="space-y-2" wire:loading.class="opacity-50">
                    @forelse($searchResults as $result)
                    <button wire:click="selectParticipant({{ $result->id }}, '{{ addslashes($result->person?->name_ar) }}')"
                            class="w-full p-4 min-h-16 border border-gray-200 rounded-xl text-start hover:border-amber-300 hover:bg-amber-50 transition-all flex items-center justify-between">
                        <div>
                            <p class="font-medium text-gray-800">{{ $result->person?->name_ar }}</p>
                            <div class="flex items-center gap-3 mt-1 text-xs text-gray-500">
                                @if($result->participant_number)
                                <span dir="ltr">{{ $result->participant_number }}</span>
                                @endif
                                @if($result->person?->phone)
                                <span dir="ltr">{{ $result->person->phone }}</span>
                                @endif
                            </div>
                        </div>
                        <span class="px-2 py-0.5 text-xs rounded-full
                            {{ $result->status->value === 'active' ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600' }}">
                            {{ $result->status->value === 'active' ? __('نشط') : __($result->status->value) }}
                        </span>
                    </button>
                    @empty
                    <div class="text-center py-8 text-gray-500">
                        <svg class="w-12 h-12 mx-auto text-gray-300 mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                        </svg>
                        <p>{{ __('لا توجد نتائج') }}</p>
                    </div>
                    @endforelse
                </div>
                @elseif(strlen($search) < 2 && !$selected_participant_id)
                <div class="text-center py-8 text-gray-400">
                    <svg class="w-16 h-16 mx-auto text-gray-200 mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                    </svg>
                    <p class="text-sm">{{ __('اكتب حرفين على الأقل للبحث') }}</p>
                </div>
                @endif

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

                <div class="flex justify-end mt-8">
                    <button wire:click="nextStep" wire:loading.attr="disabled"
                            @if(!$selected_participant_id) disabled @endif
                            class="inline-flex items-center gap-2 px-6 py-3 min-h-16 bg-amber-600 text-white rounded-lg hover:bg-amber-700 text-base font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed">
                        <span wire:loading.remove wire:target="nextStep">{{ __('التالي') }}</span>
                        <span wire:loading wire:target="nextStep">{{ __('جارٍ...') }}</span>
                        <svg class="w-5 h-5 rotate-180" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                        </svg>
                    </button>
                </div>
            @else
                {{-- Invoice Search Results --}}
                @if(strlen($search) >= 2)
                <div class="space-y-2" wire:loading.class="opacity-50">
                    @forelse($invoiceSearchResults as $inv)
                    <button wire:click="selectInvoiceDirectly({{ $inv->id }})"
                            class="w-full p-4 border border-gray-200 rounded-xl text-start hover:border-amber-300 hover:bg-amber-50 transition-all">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="font-medium text-gray-800" dir="ltr">{{ $inv->number }}</p>
                                <p class="text-sm text-gray-500 mt-1">{{ $inv->contact_name ?? __('عميل عابر') }}</p>
                            </div>
                            <div class="text-end">
                                <p class="font-bold text-red-600">{{ number_format($inv->due_amount / 100, 2) }} {{ __('ج.م') }}</p>
                                <p class="text-xs text-gray-400 mt-0.5">{{ __('من أصل') }} {{ number_format($inv->total_amount / 100, 2) }}</p>
                            </div>
                        </div>
                    </button>
                    @empty
                    <div class="text-center py-8 text-gray-500">
                        <svg class="w-12 h-12 mx-auto text-gray-300 mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
                        </svg>
                        <p>{{ __('لا توجد فواتير مستحقة بهذا الرقم') }}</p>
                    </div>
                    @endforelse
                </div>
                @else
                <div class="text-center py-8 text-gray-400">
                    <svg class="w-16 h-16 mx-auto text-gray-200 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-sm">{{ __('اكتب رقم الفاتورة أو اسم العميل للبحث') }}</p>
                </div>
                @endif

                @error('selected_invoice_id') <p class="mt-2 text-sm text-red-600">{{ $message }}</p> @enderror
            @endif
        </div>
        @endif

        {{-- Step 2: Outstanding Invoices --}}
        @if($currentStep === 2)
        <div>
            <h2 class="text-lg font-semibold text-gray-800 mb-6">{{ __('الفواتير المستحقة') }}</h2>

            @if($invoices->isEmpty())
            <div class="text-center py-12 text-gray-500">
                <svg class="w-16 h-16 mx-auto text-gray-300 mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                </svg>
                <p class="text-lg font-medium">{{ __('لا يوجد فواتير مستحقة') }}</p>
                <p class="text-sm mt-1">{{ __('هذا المشترك ليس عليه أي مستحقات') }}</p>
            </div>
            @else
            <div class="space-y-3">
                @foreach($invoices as $invoice)
                <label class="relative cursor-pointer block">
                    <input type="radio" wire:model.live="selected_invoice_id" value="{{ $invoice->id }}" class="peer sr-only">
                    <div class="p-5 min-h-16 border border-gray-200 rounded-xl transition-all
                                peer-checked:border-amber-500 peer-checked:bg-amber-50 peer-checked:shadow-sm
                                hover:border-gray-300">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="font-bold text-gray-800">{{ $invoice->number }}</p>
                                <p class="text-sm text-gray-500 mt-1">{{ $invoice->notes ?? __('فاتورة اشتراك') }}</p>
                                @if($invoice->due_date)
                                <p class="text-xs mt-1 {{ $invoice->due_date->isPast() ? 'text-red-600 font-medium' : 'text-gray-400' }}">
                                    {{ __('تاريخ الاستحقاق') }}: <span dir="ltr">{{ $invoice->due_date->format('Y-m-d') }}</span>
                                </p>
                                @endif
                            </div>
                            <div class="text-end">
                                <p class="text-lg font-bold text-gray-800" dir="ltr">
                                    {{ number_format($invoice->due_amount / 100, 2) }} {{ __('ج.م') }}
                                </p>
                                @if($invoice->paid_amount > 0)
                                <p class="text-xs text-green-600">
                                    {{ __('مدفوع') }}: <span dir="ltr">{{ number_format($invoice->paid_amount / 100, 2) }}</span>
                                </p>
                                @endif
                                @php
                                    $statusColors = [
                                        'sent' => 'blue',
                                        'partially_paid' => 'amber',
                                        'overdue' => 'red',
                                    ];
                                    $statusLabels = [
                                        'sent' => 'مرسلة',
                                        'partially_paid' => 'مدفوعة جزئيًا',
                                        'overdue' => 'متأخرة',
                                    ];
                                    $statusValue = $invoice->status->value ?? $invoice->status;
                                    $color = $statusColors[$statusValue] ?? 'gray';
                                @endphp
                                <span class="inline-block mt-1 px-2 py-0.5 text-xs rounded-full bg-{{ $color }}-100 text-{{ $color }}-700">
                                    {{ __($statusLabels[$statusValue] ?? $statusValue) }}
                                </span>
                            </div>
                        </div>
                    </div>
                </label>
                @endforeach
            </div>
            @endif

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

            {{-- Admin Price Override --}}
            @if($isSuperAdmin && $selected_invoice_id)
            <div class="mt-4 border border-dashed border-red-300 rounded-xl overflow-hidden" x-data="{ open: @entangle('priceOverrideEnabled') }">
                <button type="button" @click="open = !open; $wire.set('priceOverrideEnabled', open)"
                        class="w-full flex items-center justify-between p-4 text-start hover:bg-red-50 transition-colors">
                    <div class="flex items-center gap-2">
                        <svg class="w-5 h-5 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
                        </svg>
                        <span class="text-sm font-semibold text-red-700">{{ __('تعديل مبلغ الفاتورة (أدمن)') }}</span>
                    </div>
                    <svg class="w-4 h-4 text-red-400 transition-transform" :class="open ? 'rotate-180' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
                    </svg>
                </button>
                <div x-show="open" x-cloak x-transition class="p-4 pt-0 space-y-4">
                    <p class="text-xs text-red-600">{{ __('تحذير: هذا التعديل سيغير مبلغ الفاتورة بشكل نهائي ويتم تسجيل من قام به') }}</p>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">{{ __('المبلغ الجديد (ج.م)') }}</label>
                        <input type="number" wire:model="priceOverrideInput" dir="ltr" step="0.01" min="0"
                               class="w-full max-w-xs px-4 py-3 border border-red-300 rounded-lg focus:ring-2 focus:ring-red-400 focus:border-red-400 text-lg font-mono"
                               placeholder="0.00">
                        @error('priceOverrideInput') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
                        @if($selectedInvoice)
                        <p class="mt-1 text-xs text-gray-500">{{ __('المبلغ الأصلي') }}: <span dir="ltr">{{ number_format($selectedInvoice->total_amount / 100, 2) }}</span> {{ __('ج.م') }}</p>
                        @endif
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">{{ __('سبب التعديل') }}</label>
                        <input type="text" wire:model="priceOverrideReason"
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-400 text-sm"
                               placeholder="{{ __('مثال: خصم خاص، اتفاقية، تخفيض إداري') }}">
                    </div>
                    <button wire:click="applyAdminOverride" wire:loading.attr="disabled"
                            class="inline-flex items-center gap-2 px-5 py-2.5 bg-red-600 text-white rounded-lg hover:bg-red-700 text-sm font-medium transition-colors disabled:opacity-50">
                        <span wire:loading.remove wire:target="applyAdminOverride">{{ __('تطبيق التعديل') }}</span>
                        <span wire:loading wire:target="applyAdminOverride">{{ __('جارٍ...') }}</span>
                    </button>
                </div>
            </div>
            @endif

            {{-- Override Applied Badge --}}
            @if($selectedInvoice && ($selectedInvoice->metadata['admin_override'] ?? false))
            <div class="mt-3 p-3 bg-red-50 border border-red-200 rounded-lg flex items-center gap-3">
                <svg class="w-5 h-5 text-red-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                </svg>
                <div class="text-xs text-red-700">
                    <span class="font-bold">{{ __('تم تعديل المبلغ') }}</span>
                    {{ __('بواسطة') }} {{ $selectedInvoice->metadata['admin_override']['applied_by_name'] }}
                    — {{ __('من') }} <span dir="ltr">{{ number_format($selectedInvoice->metadata['admin_override']['original_total_piasters'] / 100, 2) }}</span>
                    {{ __('إلى') }} <span dir="ltr">{{ number_format($selectedInvoice->metadata['admin_override']['new_total_piasters'] / 100, 2) }}</span> {{ __('ج.م') }}
                    @if($selectedInvoice->metadata['admin_override']['reason'])
                    — {{ $selectedInvoice->metadata['admin_override']['reason'] }}
                    @endif
                </div>
            </div>
            @endif

            {{-- Upcoming Installments & Renewals --}}
            @if($upcomingPayments->isNotEmpty())
            <div class="mt-6 p-4 bg-indigo-50 border border-indigo-200 rounded-xl">
                <h3 class="text-sm font-semibold text-indigo-800 mb-3 flex items-center gap-2">
                    <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="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>
                    {{ __('مواعيد قادمة') }}
                </h3>
                <div class="space-y-2">
                    @foreach($upcomingPayments->take(5) as $upcoming)
                    <div class="flex items-center justify-between py-2 px-3 bg-white rounded-lg border border-indigo-100">
                        <div class="flex items-center gap-2">
                            @if($upcoming['type'] === 'installment')
                            <span class="w-2 h-2 rounded-full bg-amber-500"></span>
                            @else
                            <span class="w-2 h-2 rounded-full bg-green-500"></span>
                            @endif
                            <span class="text-sm text-gray-800">{{ $upcoming['label'] }}</span>
                        </div>
                        <div class="flex items-center gap-3">
                            @if($upcoming['amount'])
                            <span class="text-sm font-medium text-gray-700" dir="ltr">{{ number_format($upcoming['amount'] / 100, 2) }} {{ __('ج.م') }}</span>
                            @endif
                            @if($upcoming['type'] === 'renewal' && $upcoming['due_date']->isPast())
                            <button wire:click="generateRenewalForEnrollment({{ $upcoming['enrollment_id'] }})"
                                    wire:loading.attr="disabled"
                                    class="text-xs px-3 py-1 rounded-lg bg-green-600 text-white hover:bg-green-700 font-medium transition-colors">
                                <span wire:loading.remove wire:target="generateRenewalForEnrollment({{ $upcoming['enrollment_id'] }})">{{ __('إنشاء فاتورة') }}</span>
                                <span wire:loading wire:target="generateRenewalForEnrollment({{ $upcoming['enrollment_id'] }})">{{ __('جارٍ...') }}</span>
                            </button>
                            @else
                            <span class="text-xs px-2 py-0.5 rounded-full {{ $upcoming['due_date']->isPast() ? 'bg-red-100 text-red-700' : ($upcoming['due_date']->isToday() ? 'bg-amber-100 text-amber-700' : 'bg-gray-100 text-gray-600') }}" dir="ltr">
                                {{ $upcoming['due_date']->format('Y-m-d') }}
                            </span>
                            @endif
                        </div>
                    </div>
                    @endforeach
                </div>
            </div>
            @endif

            <div class="flex justify-between mt-8">
                <button wire:click="previousStep"
                        class="inline-flex items-center gap-2 px-6 py-3 min-h-16 text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200 text-base font-medium transition-colors">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                    </svg>
                    {{ __('السابق') }}
                </button>
                <button wire:click="nextStep" wire:loading.attr="disabled"
                        @if(!$selected_invoice_id) disabled @endif
                        class="inline-flex items-center gap-2 px-6 py-3 min-h-16 bg-amber-600 text-white rounded-lg hover:bg-amber-700 text-base font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed">
                    <span wire:loading.remove wire:target="nextStep">{{ __('التالي') }}</span>
                    <span wire:loading wire:target="nextStep">{{ __('جارٍ...') }}</span>
                    <svg class="w-5 h-5 rotate-180" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                    </svg>
                </button>
            </div>
        </div>
        @endif

        {{-- Step 3: Amount & Method --}}
        @if($currentStep === 3)
        <div>
            <h2 class="text-lg font-semibold text-gray-800 mb-6">{{ __('تحديد المبلغ وطريقة الدفع') }}</h2>

            {{-- Invoice Summary --}}
            @if($selectedInvoice)
            <div class="p-4 bg-gray-50 rounded-xl border border-gray-200 mb-6">
                <div class="flex items-center justify-between">
                    <span class="text-gray-600">{{ __('الرصيد المستحق') }}</span>
                    <span class="text-xl font-bold text-gray-800" dir="ltr">
                        {{ number_format($selectedInvoice->due_amount / 100, 2) }} {{ __('ج.م') }}
                    </span>
                </div>
                @if($selectedInvoice->metadata['admin_override'] ?? false)
                <div class="mt-2 pt-2 border-t border-gray-200 flex items-center gap-2 text-xs text-red-600">
                    <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="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                    <span>{{ __('تم تعديل المبلغ بواسطة') }} {{ $selectedInvoice->metadata['admin_override']['applied_by_name'] }}
                    ({{ __('الأصلي') }}: <span dir="ltr">{{ number_format($selectedInvoice->metadata['admin_override']['original_total_piasters'] / 100, 2) }}</span> {{ __('ج.م') }})</span>
                </div>
                @endif
            </div>
            @endif

            <div class="space-y-6">
                {{-- Amount Input --}}
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">{{ __('المبلغ المراد تحصيله') }}</label>
                    <div class="relative">
                        <input type="number" wire:model="payment_amount_display" dir="ltr" step="0.01" min="0.01"
                               class="w-full px-4 py-4 min-h-16 border border-gray-300 rounded-lg focus:ring-2 focus:ring-amber-500 focus:border-amber-500 text-2xl font-bold text-center"
                               placeholder="0.00">
                        <span class="absolute top-1/2 -translate-y-1/2 end-4 text-gray-400 text-sm">{{ __('ج.م') }}</span>
                    </div>
                    @error('payment_amount_display') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror

                    @if($selectedInvoice)
                    <button wire:click="payFullAmount" class="mt-2 text-sm text-amber-600 hover:text-amber-800 font-medium">
                        {{ __('دفع كامل المبلغ المستحق') }}
                    </button>
                    @endif
                </div>

                {{-- Payment Method --}}
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-3">{{ __('طريقة الدفع') }}</label>
                    <div class="grid grid-cols-3 sm:grid-cols-4 gap-3">
                        {{-- Cash --}}
                        <label class="relative cursor-pointer">
                            <input type="radio" wire:model="payment_method" value="cash" class="peer sr-only">
                            <div class="p-3 min-h-16 flex flex-col items-center justify-center gap-1.5 border border-gray-300 rounded-xl transition-all peer-checked:border-green-500 peer-checked:bg-green-50 peer-checked:text-green-700 hover:border-gray-400">
                                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 9V7a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2m2 4h10a2 2 0 002-2v-6a2 2 0 00-2-2H9a2 2 0 00-2 2v6a2 2 0 002 2zm7-5a2 2 0 11-4 0 2 2 0 014 0z"/>
                                </svg>
                                <span class="text-xs font-medium">{{ __('نقدي') }}</span>
                            </div>
                        </label>
                        {{-- Card --}}
                        <label class="relative cursor-pointer">
                            <input type="radio" wire:model="payment_method" value="card" class="peer sr-only">
                            <div class="p-3 min-h-16 flex flex-col items-center justify-center gap-1.5 border border-gray-300 rounded-xl transition-all peer-checked:border-blue-500 peer-checked:bg-blue-50 peer-checked:text-blue-700 hover:border-gray-400">
                                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"/>
                                </svg>
                                <span class="text-xs font-medium">{{ __('بطاقة') }}</span>
                            </div>
                        </label>
                        {{-- Bank Transfer --}}
                        <label class="relative cursor-pointer">
                            <input type="radio" wire:model="payment_method" value="bank_transfer" class="peer sr-only">
                            <div class="p-3 min-h-16 flex flex-col items-center justify-center gap-1.5 border border-gray-300 rounded-xl transition-all peer-checked:border-indigo-500 peer-checked:bg-indigo-50 peer-checked:text-indigo-700 hover:border-gray-400">
                                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/>
                                </svg>
                                <span class="text-xs font-medium">{{ __('تحويل بنكي') }}</span>
                            </div>
                        </label>
                        {{-- Wallet --}}
                        <label class="relative cursor-pointer">
                            <input type="radio" wire:model="payment_method" value="wallet" class="peer sr-only">
                            <div class="p-3 min-h-16 flex flex-col items-center justify-center gap-1.5 border border-gray-300 rounded-xl transition-all peer-checked:border-purple-500 peer-checked:bg-purple-50 peer-checked:text-purple-700 hover:border-gray-400">
                                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a2.25 2.25 0 01-2.25 2.25H15a2.25 2.25 0 01-2.25-2.25 2.25 2.25 0 012.25-2.25h3.75A2.25 2.25 0 0121 12zM3 6.75A2.25 2.25 0 015.25 4.5h13.5A2.25 2.25 0 0121 6.75v10.5a2.25 2.25 0 01-2.25 2.25H5.25A2.25 2.25 0 013 17.25V6.75z"/>
                                </svg>
                                <span class="text-xs font-medium">{{ __('محفظة') }}</span>
                            </div>
                        </label>
                        {{-- Online --}}
                        <label class="relative cursor-pointer">
                            <input type="radio" wire:model="payment_method" value="online" class="peer sr-only">
                            <div class="p-3 min-h-16 flex flex-col items-center justify-center gap-1.5 border border-gray-300 rounded-xl transition-all peer-checked:border-cyan-500 peer-checked:bg-cyan-50 peer-checked:text-cyan-700 hover:border-gray-400">
                                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z"/>
                                </svg>
                                <span class="text-xs font-medium">{{ __('إلكتروني') }}</span>
                            </div>
                        </label>
                        {{-- Cheque --}}
                        <label class="relative cursor-pointer">
                            <input type="radio" wire:model="payment_method" value="cheque" class="peer sr-only">
                            <div class="p-3 min-h-16 flex flex-col items-center justify-center gap-1.5 border border-gray-300 rounded-xl transition-all peer-checked:border-amber-500 peer-checked:bg-amber-50 peer-checked:text-amber-700 hover:border-gray-400">
                                <svg class="w-6 h-6" 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>
                                <span class="text-xs font-medium">{{ __('شيك') }}</span>
                            </div>
                        </label>
                        {{-- Other --}}
                        <label class="relative cursor-pointer">
                            <input type="radio" wire:model="payment_method" value="other" class="peer sr-only">
                            <div class="p-3 min-h-16 flex flex-col items-center justify-center gap-1.5 border border-gray-300 rounded-xl transition-all peer-checked:border-gray-500 peer-checked:bg-gray-50 peer-checked:text-gray-700 hover:border-gray-400">
                                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                </svg>
                                <span class="text-xs font-medium">{{ __('أخرى') }}</span>
                            </div>
                        </label>
                    </div>
                    @error('payment_method') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
                </div>

                {{-- Notes --}}
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">{{ __('ملاحظات') }} <span class="text-gray-400 text-xs">({{ __('اختياري') }})</span></label>
                    <textarea wire:model="payment_notes" rows="2"
                              class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-amber-500 focus:border-amber-500"
                              placeholder="{{ __('أي ملاحظات على هذا الدفع...') }}"></textarea>
                </div>
            </div>

            <div class="flex justify-between mt-8">
                <button wire:click="previousStep"
                        class="inline-flex items-center gap-2 px-6 py-3 min-h-16 text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200 text-base font-medium transition-colors">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                    </svg>
                    {{ __('السابق') }}
                </button>
                <button wire:click="nextStep" wire:loading.attr="disabled"
                        class="inline-flex items-center gap-2 px-6 py-3 min-h-16 bg-amber-600 text-white rounded-lg hover:bg-amber-700 text-base font-medium transition-colors disabled:opacity-50">
                    <span wire:loading.remove wire:target="nextStep">{{ __('التالي') }}</span>
                    <span wire:loading wire:target="nextStep">{{ __('جارٍ...') }}</span>
                    <svg class="w-5 h-5 rotate-180" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                    </svg>
                </button>
            </div>
        </div>
        @endif

        {{-- Step 4: Confirm --}}
        @if($currentStep === 4)
        <div>
            <h2 class="text-lg font-semibold text-gray-800 mb-6">{{ __('تأكيد الدفع') }}</h2>

            <div class="p-6 bg-gray-50 rounded-xl border border-gray-200 mb-6">
                <div class="space-y-4">
                    <div class="flex items-center justify-between">
                        <span class="text-gray-600">{{ __('المشترك') }}</span>
                        <span class="font-medium text-gray-800">{{ $selected_participant_name }}</span>
                    </div>
                    @if($selectedInvoice)
                    <div class="flex items-center justify-between">
                        <span class="text-gray-600">{{ __('رقم الفاتورة') }}</span>
                        <span class="font-medium text-gray-800" dir="ltr">{{ $selectedInvoice->number }}</span>
                    </div>
                    @endif
                    <div class="flex items-center justify-between">
                        <span class="text-gray-600">{{ __('طريقة الدفع') }}</span>
                        <span class="font-medium text-gray-800">
                            {{ \App\Domain\Financial\Enums\PaymentMethod::tryFrom($payment_method)?->label() ?? $payment_method }}
                        </span>
                    </div>
                    @if($selectedInvoice && ($selectedInvoice->metadata['admin_override'] ?? false))
                    <div class="flex items-center justify-between text-red-700">
                        <span class="text-gray-600">{{ __('خصم إداري') }}</span>
                        <div class="text-end">
                            <span class="font-medium text-sm" dir="ltr">
                                -{{ number_format(($selectedInvoice->metadata['admin_override']['original_total_piasters'] - $selectedInvoice->metadata['admin_override']['new_total_piasters']) / 100, 2) }} {{ __('ج.م') }}
                            </span>
                            <p class="text-xs text-red-500">{{ __('بواسطة') }} {{ $selectedInvoice->metadata['admin_override']['applied_by_name'] }}</p>
                        </div>
                    </div>
                    @endif
                    <div class="border-t border-gray-300 pt-4 flex items-center justify-between">
                        <span class="text-lg font-bold text-gray-800">{{ __('المبلغ') }}</span>
                        <span class="text-2xl font-bold text-green-700" dir="ltr">
                            {{ number_format((float)$payment_amount_display, 2) }} {{ __('ج.م') }}
                        </span>
                    </div>
                </div>
            </div>

            <div class="flex justify-between mt-8">
                <button wire:click="previousStep"
                        class="inline-flex items-center gap-2 px-6 py-3 min-h-16 text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200 text-base font-medium transition-colors">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                    </svg>
                    {{ __('السابق') }}
                </button>
                <button wire:click="confirm" wire:loading.attr="disabled"
                        class="inline-flex items-center gap-2 px-8 py-3 min-h-16 bg-green-600 text-white rounded-lg hover:bg-green-700 text-base font-bold transition-colors disabled:opacity-50">
                    <span wire:loading.remove wire:target="confirm">{{ __('تأكيد الدفع') }}</span>
                    <span wire:loading wire:target="confirm">
                        <svg class="animate-spin w-5 h-5" 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>
                    <span wire:loading wire:target="confirm">{{ __('جارٍ تسجيل الدفع...') }}</span>
                </button>
            </div>
        </div>
        @endif

        {{-- Step 5: Receipt / Success --}}
        @if($currentStep === 5)
        <div class="text-center py-8">
            <div class="w-20 h-20 mx-auto bg-green-100 rounded-full flex items-center justify-center mb-6 animate-bounce">
                <svg class="w-10 h-10 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                </svg>
            </div>

            <h2 class="text-2xl font-bold text-green-700 mb-2">{{ __('تم تسجيل الدفع بنجاح!') }}</h2>
            <p class="text-gray-600 mb-6">{{ __('تم تحصيل المبلغ وتحديث الفاتورة') }}</p>

            {{-- Receipt Summary --}}
            <div class="inline-block bg-gray-50 border border-gray-200 rounded-xl p-6 mb-6 text-start">
                @if($receipt_number)
                <div class="mb-3">
                    <p class="text-xs text-gray-500">{{ __('رقم الإيصال') }}</p>
                    <p class="text-lg font-bold text-gray-800" dir="ltr">{{ $receipt_number }}</p>
                </div>
                @endif
                <div class="mb-3">
                    <p class="text-xs text-gray-500">{{ __('المبلغ المحصل') }}</p>
                    <p class="text-xl font-bold text-green-700" dir="ltr">{{ number_format($paid_amount / 100, 2) }} {{ __('ج.م') }}</p>
                </div>
                <div>
                    <p class="text-xs text-gray-500">{{ __('المشترك') }}</p>
                    <p class="font-medium text-gray-800">{{ $selected_participant_name }}</p>
                </div>
            </div>

            @if($last_payment_uuid)
            <div class="flex justify-center mt-4">
                <x-ui.print-receipt-button :route="route('receipts.payment.print', $last_payment_uuid)" size="lg" />
            </div>
            @endif

            <div class="flex items-center justify-center gap-4 mt-6">
                <a href="{{ route('receptionist.dashboard') }}" wire:navigate
                   class="inline-flex items-center gap-2 px-6 py-3 min-h-16 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 text-base font-medium transition-colors">
                    {{ __('العودة للاستقبال') }}
                </a>
                <a href="{{ route('receptionist.collect-payment') }}" wire:navigate
                   class="inline-flex items-center gap-2 px-6 py-3 min-h-16 bg-amber-600 text-white rounded-lg hover:bg-amber-700 text-base font-medium transition-colors">
                    {{ __('تحصيل آخر') }}
                </a>
            </div>

            {{-- Navigation Links --}}
            <div class="flex items-center justify-center gap-3 mt-4">
                @if($participant_uuid)
                <a href="{{ route('participants.show', $participant_uuid) }}" wire:navigate
                   class="inline-flex items-center gap-2 px-4 py-2.5 min-h-[44px] border border-blue-300 rounded-lg text-sm font-medium text-blue-700 hover:bg-blue-50 active:bg-blue-100 transition-colors">
                    <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="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                    </svg>
                    {{ __('عرض المشترك') }}
                </a>
                @endif
                @if($invoice_uuid)
                <a href="{{ route('invoices.show', $invoice_uuid) }}" wire:navigate
                   class="inline-flex items-center gap-2 px-4 py-2.5 min-h-[44px] border border-gray-300 rounded-lg text-sm font-medium text-gray-700 hover:bg-gray-50 active:bg-gray-100 transition-colors">
                    <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="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>
                    {{ __('عرض الفاتورة') }}
                </a>
                @endif
            </div>
        </div>
        @endif
    </div>
</div>
