<div>
    <!-- Top Header -->
    <div class="mb-6 flex items-center justify-between">
        <div>
            <div class="flex items-center gap-2 mb-1">
                <a href="<?php echo e(route('pages')); ?>" class="text-indigo-600 hover:text-indigo-800 text-sm font-bold flex items-center gap-1 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 5l7 7-7 7"></path></svg>
                    العودة للصفحات
                </a>
            </div>
            <h1 class="text-2xl font-black text-slate-800 flex items-center gap-2">
                سجل العمليات: <?php echo e($page->name); ?>

            </h1>
            <p class="text-sm text-slate-500 mt-1 font-medium">الدفتر: <?php echo e($page->ledger->name ?? '-'); ?> | الرمز: <span dir="ltr"><?php echo e($page->code); ?></span></p>
        </div>
        
        <!-- Balance Summary -->
        <div class="flex gap-2">
            <div class="bg-white border rounded-lg px-3 py-1.5 shadow-sm min-w-[100px] text-center flex flex-col justify-center" style="background-color: <?php echo e($settings['color_debit_bg'] ?? '#f0fdf4'); ?>; color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>; border-color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>33">
                <div class="text-[10px] font-bold opacity-80 mb-0.5">إجمالي المدين</div>
                <div class="text-sm font-black" dir="ltr"><?php echo e(number_format($totalDebit, 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?></div>
            </div>
            <div class="bg-white border rounded-lg px-3 py-1.5 shadow-sm min-w-[100px] text-center flex flex-col justify-center" style="background-color: <?php echo e($settings['color_credit_bg'] ?? '#fef2f2'); ?>; color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>; border-color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>33">
                <div class="text-[10px] font-bold opacity-80 mb-0.5">إجمالي الدائن</div>
                <div class="text-sm font-black" dir="ltr"><?php echo e(number_format($totalCredit, 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?></div>
            </div>
            <div class="bg-white border rounded-lg px-3 py-1.5 shadow-sm min-w-[120px] max-w-[150px] text-center flex flex-col justify-center" style="background-color: <?php echo e($settings['color_balance_bg'] ?? '#f8fafc'); ?>; color: <?php echo e($settings['color_balance_text'] ?? '#1e293b'); ?>; border-color: <?php echo e($settings['color_balance_text'] ?? '#1e293b'); ?>33">
                <div class="text-[10px] font-bold opacity-80 mb-0.5">الرصيد الصافي</div>
                <div class="text-sm font-black" dir="ltr"><?php echo e(number_format(abs($netBalance), 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?></div>
                <div class="text-[9px] font-bold mt-0.5 truncate" title="<?php if($netBalance == 0): ?> مطابق <?php elseif($netBalance > 0): ?> لصالح (<?php echo e($page->creditAccount->party->name ?? 'الدائن'); ?>) <?php else: ?> لصالح (<?php echo e($page->debitAccount->party->name ?? 'المدين'); ?>) <?php endif; ?>">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($netBalance == 0): ?>
                        مطابق
                    <?php elseif($netBalance > 0): ?>
                        لصالح (<?php echo e(mb_substr($page->creditAccount->party->name ?? 'الدائن', 0, 15)); ?>..)
                    <?php else: ?>
                        لصالح (<?php echo e(mb_substr($page->debitAccount->party->name ?? 'المدين', 0, 15)); ?>..)
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session()->has('message')): ?>
        <div class="p-4 mb-6 text-sm text-emerald-800 rounded-lg bg-emerald-50 border border-emerald-200" role="alert">
            <span class="font-bold">نجاح!</span> <?php echo e(session('message')); ?>

        </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <!-- Page Accounts Info (Compact) -->
    <div class="bg-white rounded-2xl shadow-sm border border-slate-200 p-5 mb-6 flex items-center justify-between gap-6">
        <div class="flex-1 flex flex-col gap-2">
            <h3 class="text-xs font-bold text-slate-500 uppercase tracking-wider">الطرف المدين (+)</h3>
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 rounded-full flex items-center justify-center font-black text-lg" style="background-color: <?php echo e($settings['color_debit_bg'] ?? '#f0fdf4'); ?>; color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>">
                    <?php echo e(mb_substr($page->debitAccount->party->name ?? 'M', 0, 1)); ?>

                </div>
                <div>
                    <div class="text-sm font-bold text-slate-800"><?php echo e($page->debitAccount->party->name ?? 'مفقود'); ?></div>
                    <div class="text-xs text-slate-500 mt-0.5">الحساب: <span class="font-bold"><?php echo e($page->debitAccount->name ?? '-'); ?></span> <span dir="ltr">(<?php echo e($page->debitAccount->account_number ?? ''); ?>)</span></div>
                </div>
            </div>
        </div>
        
        <div class="w-px h-12 bg-slate-200"></div>
        
        <div class="flex-1 flex flex-col gap-2">
            <h3 class="text-xs font-bold text-slate-500 uppercase tracking-wider">الطرف الدائن (-)</h3>
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 rounded-full flex items-center justify-center font-black text-lg" style="background-color: <?php echo e($settings['color_credit_bg'] ?? '#fef2f2'); ?>; color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>">
                    <?php echo e(mb_substr($page->creditAccount->party->name ?? 'M', 0, 1)); ?>

                </div>
                <div>
                    <div class="text-sm font-bold text-slate-800"><?php echo e($page->creditAccount->party->name ?? 'مفقود'); ?></div>
                    <div class="text-xs text-slate-500 mt-0.5">الحساب: <span class="font-bold"><?php echo e($page->creditAccount->name ?? '-'); ?></span> <span dir="ltr">(<?php echo e($page->creditAccount->account_number ?? ''); ?>)</span></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Print Reports Card -->
    <div x-data="{ showPrint: false }" class="bg-white rounded-xl shadow-sm border border-slate-200 mb-6 overflow-hidden">
        <button @click="showPrint = !showPrint" type="button" class="w-full bg-slate-50 hover:bg-slate-100 border-b border-slate-200 px-6 py-3 flex items-center justify-between transition-colors">
            <h2 class="text-sm font-bold text-slate-800 flex items-center gap-2">
                <span>🖨️</span> طباعة واستخراج التقارير
            </h2>
            <svg class="w-4 h-4 text-slate-500 transform transition-transform" :class="{'rotate-180': showPrint}" 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"></path></svg>
        </button>
        
        <div x-show="showPrint" x-collapse class="p-6 bg-white">
            <form action="<?php echo e(route('pages.report', $page->id)); ?>" method="GET" target="_blank" class="grid grid-cols-1 md:grid-cols-12 gap-6 items-end">
                <input type="hidden" name="filter" value="1">
                
                <div class="col-span-12 md:col-span-2">
                    <label class="block text-[11px] font-bold text-slate-600 mb-1">من تاريخ</label>
                    <input type="date" name="date_from" class="w-full bg-slate-50 border border-slate-300 text-slate-800 rounded-lg shadow-inner text-sm h-10 focus:ring-indigo-500 focus:border-indigo-500 transition-colors">
                </div>
                
                <div class="col-span-12 md:col-span-2">
                    <label class="block text-[11px] font-bold text-slate-600 mb-1">إلى تاريخ</label>
                    <input type="date" name="date_to" class="w-full bg-slate-50 border border-slate-300 text-slate-800 rounded-lg shadow-inner text-sm h-10 focus:ring-indigo-500 focus:border-indigo-500 transition-colors">
                </div>

                <div class="col-span-12 md:col-span-6 flex flex-wrap gap-x-6 gap-y-3 items-center mb-2">
                    <div class="space-y-3">
                        <label class="flex items-center gap-2 text-xs font-bold text-slate-700 cursor-pointer">
                            <input type="checkbox" name="with_opening_balance" value="1" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-600" checked>
                            تضمين الرصيد الافتتاحي
                        </label>
                        <label class="flex items-center gap-2 text-xs font-bold text-slate-700 cursor-pointer">
                            <input type="checkbox" name="with_notes" value="1" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-600">
                            عرض الملاحظات
                        </label>
                        <label class="flex items-center gap-2 text-xs font-bold text-slate-700 cursor-pointer">
                            <input type="checkbox" name="hide_credit_party" value="1" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-600">
                            إخفاء الطرف الدائن
                        </label>
                    </div>
                    
                    <div class="space-y-3">
                        <label class="flex items-center gap-2 text-xs font-bold text-slate-700 cursor-pointer">
                            <input type="checkbox" name="hide_transaction_number" value="1" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-600" checked>
                            إخفاء رقم الحركة
                        </label>
                        <label class="flex items-center gap-2 text-xs font-bold text-slate-700 cursor-pointer">
                            <input type="checkbox" name="hide_reference" value="1" class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-600" checked>
                            إخفاء المرجع
                        </label>
                    </div>
                </div>

                <div class="col-span-12 md:col-span-2 text-left">
                    <button type="submit" class="w-full bg-slate-800 hover:bg-slate-900 text-white font-bold text-sm py-2 px-4 rounded-lg shadow-md transition-colors h-10 flex items-center justify-center gap-2">
                        <span>إنشاء التقرير</span>
                        <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="M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2zm8-12V5a2 2 0 00-2-2H9a2 2 0 00-2 2v4h10z"></path></svg>
                    </button>
                </div>
            </form>
        </div>
    </div>

    <!-- Quick Entry Form -->
    <div class="bg-white rounded-2xl shadow-sm border border-slate-200 mb-6 overflow-hidden">
        <div class="px-6 py-4 border-b border-slate-100 bg-slate-50 flex items-center gap-2">
            <svg class="w-5 h-5 text-indigo-500" 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"></path></svg>
            <h2 class="text-sm font-bold text-slate-800">تسجيل حركة جديدة</h2>
        </div>
        <form wire:submit.prevent="save" class="p-6">
            <div class="grid grid-cols-1 md:grid-cols-12 gap-4 items-start">
                
                <div class="col-span-12 md:col-span-2">
                    <label class="block text-[11px] font-bold text-slate-600 mb-1">نوع الإدخال</label>
                    <select wire:model.live="transaction_type" class="w-full bg-slate-50 border border-slate-300 text-slate-800 rounded-lg shadow-inner text-sm h-10 focus:ring-indigo-500 focus:border-indigo-500 transition-colors">
                        <option value="transaction">قيد مالي</option>
                        <option value="note">ملاحظة</option>
                    </select>
                </div>
                
                <div class="col-span-12 md:col-span-2">
                    <label class="block text-[11px] font-bold text-slate-600 mb-1">التاريخ</label>
                    <input type="date" wire:model="transaction_date" class="w-full bg-slate-50 border border-slate-300 text-slate-800 rounded-lg shadow-inner text-sm h-10 focus:ring-indigo-500 focus:border-indigo-500 transition-colors" required>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['transaction_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <span class="text-[10px] text-red-500 mt-1 block"><?php echo e($message); ?></span> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
                
                <div class="col-span-12 <?php echo e($transaction_type === 'note' ? 'md:col-span-6' : 'md:col-span-2'); ?>">
                    <label class="block text-[11px] font-bold text-slate-600 mb-1">البيان / الشرح</label>
                    <input type="text" wire:model="description" placeholder="وصف الحركة المالية..." class="w-full bg-slate-50 border border-slate-300 text-slate-800 rounded-lg shadow-inner text-sm h-10 focus:ring-indigo-500 focus:border-indigo-500 transition-colors" required autofocus>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['description'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <span class="text-[10px] text-red-500 mt-1 block"><?php echo e($message); ?></span> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
                
                <div class="col-span-12 md:col-span-2">
                    <label class="block text-[11px] font-bold text-slate-600 mb-1">المرجع (اختياري)</label>
                    <input type="text" wire:model="reference_number" placeholder="رقم المستند" class="w-full bg-slate-50 border border-slate-300 text-slate-800 rounded-lg shadow-inner text-sm h-10 focus:ring-indigo-500 focus:border-indigo-500 transition-colors" dir="ltr">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['reference_number'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <span class="text-[10px] text-red-500 mt-1 block"><?php echo e($message); ?></span> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
                
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($transaction_type === 'transaction'): ?>
                <div class="col-span-12 md:col-span-2">
                    <label class="block text-[11px] font-bold text-slate-600 mb-1">توجيه الحركة</label>
                    <div class="flex rounded-lg shadow-inner border border-slate-300 bg-slate-50 overflow-hidden h-10 p-1 gap-1">
                        <label class="flex-1 text-center cursor-pointer relative rounded-md transition-all" style="background-color: <?php echo e($direction === 'debit' ? ($settings['color_debit_bg'] ?? '#f0fdf4') : 'transparent'); ?>; border: 1px solid <?php echo e($direction === 'debit' ? ($settings['color_debit_text'] ?? '#166534').'40' : 'transparent'); ?>">
                            <input type="radio" wire:model.live="direction" value="debit" class="sr-only">
                            <span class="flex items-center justify-center h-full text-xs font-bold transition-colors" style="color: <?php echo e($direction === 'debit' ? ($settings['color_debit_text'] ?? '#166534') : '#64748b'); ?>">مدين (+)</span>
                        </label>
                        <label class="flex-1 text-center cursor-pointer relative rounded-md transition-all" style="background-color: <?php echo e($direction === 'credit' ? ($settings['color_credit_bg'] ?? '#fef2f2') : 'transparent'); ?>; border: 1px solid <?php echo e($direction === 'credit' ? ($settings['color_credit_text'] ?? '#991b1b').'40' : 'transparent'); ?>">
                            <input type="radio" wire:model.live="direction" value="credit" class="sr-only">
                            <span class="flex items-center justify-center h-full text-xs font-bold transition-colors" style="color: <?php echo e($direction === 'credit' ? ($settings['color_credit_text'] ?? '#991b1b') : '#64748b'); ?>">دائن (-)</span>
                        </label>
                    </div>
                </div>

                <div class="col-span-12 md:col-span-2">
                    <label class="block text-[11px] font-bold text-slate-600 mb-1">المبلغ (<?php echo e($settings['base_currency'] ?? 'SAR'); ?>)</label>
                    <input type="number" wire:model.live.debounce.300ms="amount" step="0.01" min="0.01" placeholder="0.00" class="w-full bg-indigo-50/50 border border-indigo-200 text-indigo-900 rounded-lg shadow-inner text-sm h-10 font-black focus:ring-indigo-600 focus:border-indigo-600 text-left transition-colors" dir="ltr" required>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <span class="text-[10px] text-red-500 mt-1 block"><?php echo e($message); ?></span> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
            
            <div class="flex items-center justify-between mt-4">
                <div class="text-xs font-bold text-indigo-700 min-h-[20px]">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($amount && is_numeric($amount)): ?>
                        <span>تفقيط المبلغ:</span>
                        <?php echo e($this->getTafqeet($amount)); ?>

                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
                <div class="flex items-center gap-2">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($editing_id): ?>
                        <button type="button" wire:click="cancelEdit" class="px-6 py-2 bg-white border border-slate-300 hover:bg-slate-50 text-slate-700 text-sm font-bold rounded-lg shadow-sm transition-all">
                            إلغاء التعديل
                        </button>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    <button type="submit" class="px-6 py-2 bg-indigo-600 hover:bg-indigo-700 text-white text-sm font-bold rounded-lg shadow-sm transition-all flex items-center gap-2">
                        <span wire:loading.remove wire:target="save">
                            <?php echo e($editing_id ? 'حفظ التعديلات' : 'تسجيل الحركة (Enter)'); ?>

                        </span>
                        <span wire:loading wire:target="save">جاري التسجيل...</span>
                    </button>
                </div>
            </div>
        </form>
    </div>

    <!-- Transactions Grid -->
    <div class="bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden">
        <div class="p-4 border-b border-slate-100 flex items-center justify-between bg-slate-50">
            <h2 class="text-sm font-bold text-slate-800 flex items-center gap-2">
                <svg class="w-4 h-4 text-slate-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16"></path></svg>
                العمليات المسجلة
            </h2>
            <div class="relative w-64">
                <div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
                    <svg class="w-4 h-4 text-slate-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"></path></svg>
                </div>
                <input wire:model.live.debounce.300ms="search" type="text" placeholder="بحث في العمليات..." class="block w-full border-slate-200 rounded-lg pr-9 pl-3 py-1.5 text-xs focus:ring-indigo-500 focus:border-indigo-500">
            </div>
        </div>
        
        <div class="overflow-x-auto">
            <table class="w-full text-right text-sm">
                <thead class="bg-slate-50/50 text-slate-500 text-xs">
                    <tr>
                        <th class="px-4 py-3 font-bold border-b border-slate-100 text-center w-12">#</th>
                        <th class="px-4 py-3 font-bold border-b border-slate-100">رقم الحركة</th>
                        <th class="px-4 py-3 font-bold border-b border-slate-100">التاريخ</th>
                        <th class="px-4 py-3 font-bold border-b border-slate-100">البيان</th>
                        <th class="px-4 py-3 font-bold border-b border-slate-100">المرجع</th>
                        <th class="px-4 py-3 font-bold border-b border-slate-100 text-left">مدين (+)</th>
                        <th class="px-4 py-3 font-bold border-b border-slate-100 text-left">دائن (-)</th>
                        <th class="px-4 py-3 font-bold border-b border-slate-100 text-left">الرصيد التراكمي</th>
                        <th class="px-4 py-3 font-bold border-b border-slate-100">بواسطة</th>
                        <th class="px-4 py-3 border-b border-slate-100"></th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                        <tr class="hover:bg-slate-50 transition-colors group">
                            <td class="px-4 py-3 text-center text-xs font-bold text-slate-400">
                                <?php echo e($transactions->total() - ($transactions->firstItem() + $loop->index) + 1); ?>

                            </td>
                            <td class="px-4 py-3">
                                <span class="text-xs font-bold <?php echo e($trx->type === 'note' ? 'text-amber-600 bg-amber-50 border border-amber-200' : 'text-slate-600 bg-slate-100 border border-transparent'); ?> px-2 py-1 rounded" dir="ltr">
                                    <?php echo e($trx->transaction_number); ?>

                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx->type === 'note'): ?> <span class="mr-1">📝</span> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                </span>
                            </td>
                            <td class="px-4 py-3">
                                <div class="text-xs font-bold text-slate-800" dir="ltr"><?php echo e($trx->transaction_date->format($settings['date_format'] ?? 'Y-m-d')); ?></div>
                            </td>
                            <td class="px-4 py-3">
                                <div class="text-sm font-bold text-slate-800"><?php echo e($trx->description); ?></div>
                            </td>
                            <td class="px-4 py-3">
                                <span class="text-xs text-slate-500"><?php echo e($trx->reference_number ?? '-'); ?></span>
                            </td>
                            <td class="px-4 py-3 text-left">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx->type === 'note'): ?>
                                    <span class="text-xs text-slate-300">-</span>
                                <?php elseif($trx->debit_amount > 0): ?>
                                    <span class="text-sm font-black px-2 py-1 rounded" dir="ltr" style="color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>; background-color: <?php echo e($settings['color_debit_bg'] ?? '#f0fdf4'); ?>">
                                        <?php echo e(number_format($trx->debit_amount, 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?>

                                    </span>
                                <?php else: ?>
                                    <span class="text-slate-300">-</span>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="px-4 py-3 text-left">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx->type === 'note'): ?>
                                    <span class="text-xs text-slate-300">-</span>
                                <?php elseif($trx->credit_amount > 0): ?>
                                    <span class="text-sm font-black px-2 py-1 rounded" dir="ltr" style="color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>; background-color: <?php echo e($settings['color_credit_bg'] ?? '#fef2f2'); ?>">
                                        <?php echo e(number_format($trx->credit_amount, 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?>

                                    </span>
                                <?php else: ?>
                                    <span class="text-slate-300">-</span>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="px-4 py-3 text-left">
                                <?php
                                    $bal = $this->getRunningBalance($trx);
                                ?>
                                <span class="text-sm font-black" dir="ltr" style="color: <?php echo e($bal > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($bal < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#64748b')); ?>">
                                    <?php echo e(number_format(abs($bal), 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?>

                                </span>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($bal != 0): ?>
                                    <span class="text-[9px] font-bold opacity-75 mr-1"><?php echo e($bal > 0 ? 'مدين' : 'دائن'); ?></span>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="px-4 py-3 text-xs text-slate-500">
                                <?php echo e($trx->creator->name ?? 'النظام'); ?>

                            </td>
                            <td class="px-4 py-3 text-left opacity-0 group-hover:opacity-100 transition-opacity flex justify-end gap-1">
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update records')): ?>
                                <button wire:click="edit(<?php echo e($trx->id); ?>)" class="p-1.5 text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 rounded transition" 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="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>
                                </button>
                                <?php endif; ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete records')): ?>
                                <button wire:click="delete(<?php echo e($trx->id); ?>)" wire:confirm="هل أنت متأكد من حذف هذه الحركة نهائياً؟ سيؤثر هذا على الرصيد." class="p-1.5 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded transition" 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="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
                                </button>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                        <tr>
                            <td colspan="8" class="px-6 py-12 text-center text-slate-500">
                                <div class="flex flex-col items-center justify-center">
                                    <svg class="w-12 h-12 text-slate-300 mb-3" 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"></path></svg>
                                    <span class="text-sm font-medium">لا توجد حركات مسجلة في هذه الصفحة حتى الآن.</span>
                                </div>
                            </td>
                        </tr>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </tbody>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($transactions->total() > 0): ?>
                <tfoot class="bg-slate-50 font-black border-t-2 border-slate-200">
                    <tr>
                        <td colspan="5" class="px-4 py-4 text-left text-sm text-slate-600">
                            الإجماليات الكلية: 
                            <span class="text-xs font-bold text-slate-400 mr-2">(عدد العمليات: <?php echo e($transactions->total()); ?>)</span>
                        </td>
                        <td class="px-4 py-4 text-left" dir="ltr" style="color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>">
                            <?php echo e(number_format($totalDebit, 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?>

                        </td>
                        <td class="px-4 py-4 text-left" dir="ltr" style="color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>">
                            <?php echo e(number_format($totalCredit, 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?>

                        </td>
                        <td class="px-4 py-4 text-left" dir="ltr">
                            <span style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($netBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#64748b')); ?>">
                                <?php echo e(number_format(abs($netBalance), 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?>

                            </span>
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($netBalance != 0): ?>
                                <span class="px-2 py-0.5 text-[10px] rounded ml-1" style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($settings['color_credit_text'] ?? '#991b1b')); ?>; background-color: <?php echo e($netBalance > 0 ? ($settings['color_debit_bg'] ?? '#f0fdf4') : ($settings['color_credit_bg'] ?? '#fef2f2')); ?>">
                                    <?php echo e($netBalance > 0 ? 'مدين' : 'دائن'); ?>

                                </span>
                            <?php else: ?>
                                <span class="px-2 py-0.5 text-[10px] rounded ml-1 text-slate-500 bg-slate-100">مطابق</span>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </td>
                        <td colspan="2"></td>
                    </tr>
                </tfoot>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </table>
        </div>
        
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($transactions->hasPages()): ?>
        <div class="p-4 border-t border-slate-100 bg-slate-50/50">
            <?php echo e($transactions->links()); ?>

        </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>

    <!-- Final Account Status Card -->
    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($transactions->total() > 0): ?>
    <div class="mt-6 bg-white rounded-2xl shadow-sm border border-slate-200 p-6 flex flex-col md:flex-row items-center justify-between gap-6" style="background-color: <?php echo e($netBalance > 0 ? ($settings['color_debit_bg'] ?? '#f0fdf4') : ($netBalance < 0 ? ($settings['color_credit_bg'] ?? '#fef2f2') : '#f8fafc')); ?>">
        <div class="flex items-center gap-4">
            <div class="w-16 h-16 rounded-full flex items-center justify-center font-black text-2xl shadow-sm" style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($netBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#64748b')); ?>; background: white">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($netBalance == 0): ?>
                    =
                <?php elseif($netBalance > 0): ?>
                    +
                <?php else: ?>
                    -
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
            <div>
                <h3 class="text-sm font-bold opacity-75" style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($netBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#64748b')); ?>">الحالة النهائية للحساب</h3>
                <div class="text-2xl font-black mt-1" style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($netBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#64748b')); ?>">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($netBalance == 0): ?>
                        الرصيد مصفر ومطابق
                    <?php elseif($netBalance > 0): ?>
                        <div>المتبقي على (<?php echo e($page->debitAccount->party->name ?? 'المدين'); ?>)</div>
                        <div class="text-lg opacity-90 mt-0.5">لصالح (<?php echo e($page->creditAccount->party->name ?? 'الدائن'); ?>)</div>
                    <?php else: ?>
                        <div>المتبقي على (<?php echo e($page->creditAccount->party->name ?? 'الدائن'); ?>)</div>
                        <div class="text-lg opacity-90 mt-0.5">لصالح (<?php echo e($page->debitAccount->party->name ?? 'المدين'); ?>)</div>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
            </div>
        </div>
        
        <div class="text-center md:text-left">
            <div class="text-3xl font-black mb-2" dir="ltr" style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($netBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#64748b')); ?>">
                <?php echo e(number_format(abs($netBalance), 2, $settings['decimal_separator'] ?? '.', $settings['thousand_separator'] ?? ',')); ?> <?php echo e($settings['base_currency'] ?? 'SAR'); ?>

            </div>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($netBalance != 0): ?>
                <div class="text-sm font-bold bg-white/60 px-4 py-2 rounded-lg inline-block" style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($netBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#64748b')); ?>">
                    <?php echo e($this->getTafqeet(abs($netBalance))); ?>

                </div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>
    </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
</div>
<?php /**PATH D:\laragon\www\Ledger\resources\views/livewire/page-transactions.blade.php ENDPATH**/ ?>