<div>
    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4 sm:mb-6">
        <h1 class="text-xl sm:text-2xl font-bold text-gray-800">{{ __('تسجيل مصروف') }}</h1>
        <a href="{{ route('expenses.list') }}" wire:navigate
           class="inline-flex items-center gap-1 text-sm text-gray-600 hover:text-gray-800">
            <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>

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

    <form wire:submit="save" class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 sm:gap-6">
            {{-- Category --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('فئة المصروف') }} <span class="text-red-500">*</span></label>
                <select wire:model="category" class="w-full rounded-lg border-gray-300 text-sm py-2.5">
                    <option value="">{{ __('اختر الفئة') }}</option>
                    @foreach($categories as $cat)
                    <option value="{{ $cat->value }}">{{ $cat->label() }}</option>
                    @endforeach
                </select>
                @error('category') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Amount --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('المبلغ (ج.م)') }} <span class="text-red-500">*</span></label>
                <input type="number" wire:model="amount_display" dir="ltr" step="0.01" min="0"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5" placeholder="0.00">
                @error('amount_display') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Description --}}
            <div class="md:col-span-2">
                <label class="block text-sm text-gray-600 mb-1">{{ __('الوصف') }} <span class="text-red-500">*</span></label>
                <input type="text" wire:model="description"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5"
                       placeholder="{{ __('مثال: شراء أدوات تدريب للفريق الأول') }}">
                @error('description') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Recipient --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('المستلم / راحت لمين') }}</label>
                <input type="text" wire:model="recipient_name"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5"
                       placeholder="{{ __('اسم الشخص أو المحل') }}">
                @error('recipient_name') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Payment Method --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('طريقة الدفع') }} <span class="text-red-500">*</span></label>
                <select wire:model="payment_method" class="w-full rounded-lg border-gray-300 text-sm py-2.5">
                    <option value="cash">{{ __('نقدي') }}</option>
                    <option value="card">{{ __('بطاقة') }}</option>
                    <option value="bank_transfer">{{ __('تحويل بنكي') }}</option>
                    <option value="cheque">{{ __('شيك') }}</option>
                    <option value="other">{{ __('أخرى') }}</option>
                </select>
                @error('payment_method') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Receipt Reference --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('رقم الإيصال') }}</label>
                <input type="text" wire:model="receipt_reference" dir="ltr"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5">
                @error('receipt_reference') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Date --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('تاريخ المصروف') }} <span class="text-red-500">*</span></label>
                <input type="date" wire:model="expense_date" dir="ltr"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5">
                @error('expense_date') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Notes --}}
            <div class="md:col-span-2">
                <label class="block text-sm text-gray-600 mb-1">{{ __('ملاحظات') }}</label>
                <textarea wire:model="notes" rows="2"
                          class="w-full rounded-lg border-gray-300 text-sm py-2.5"></textarea>
            </div>
        </div>

        {{-- Submit --}}
        <div class="mt-6 flex justify-end">
            <button type="submit" wire:loading.attr="disabled" wire:target="save"
                    class="inline-flex items-center gap-2 px-6 py-2.5 bg-emerald-600 text-white rounded-lg hover:bg-emerald-700 transition text-sm font-medium disabled:opacity-50">
                <span wire:loading.remove wire:target="save">{{ __('تسجيل المصروف') }}</span>
                <span wire:loading wire:target="save">{{ __('جارٍ الحفظ...') }}</span>
            </button>
        </div>
    </form>
</div>
