<?php require_once 'layouts/header.php'; ?>
<?php require_once 'layouts/sidebar.php'; ?>

<div class="flex-1 flex flex-col min-w-0 h-full overflow-hidden" x-data="{ 
 showModal: false, 
 viewModalOpen: false,
 deleteModalOpen: false, 
 deleteId: null, 
 previewUrl: null,
 previewType: null,
 expense: {id: '', title: '', expense_category_id: '', amount: '', date: '<?php echo date('Y-m-d'); ?>', description: '', payment_method: 'Cash', old_attachment: ''},
 handleFileChange(event) {
 const file = event.target.files[0];
 if (file) {
 this.previewUrl = URL.createObjectURL(file);
 this.previewType = file.type;
 }
 },
 resetForm() {
 this.expense = {id: '', title: '', expense_category_id: '', amount: '', date: '<?php echo date('Y-m-d'); ?>', description: '', payment_method: 'Cash', old_attachment: ''};
 this.previewUrl = null;
 this.previewType = null;
 if(document.getElementById('attachment-input')) document.getElementById('attachment-input').value = '';
 }
}">
 <?php require_once 'layouts/topbar.php'; ?>

 <main class="flex-1 relative overflow-y-auto py-4 sm:py-6 px-3 sm:px-6 lg:px-8 bg-gray-50 custom-scrollbar">
 <div class="max-w-6xl mx-auto space-y-6 pb-6">
 <!-- Header -->
 <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-1 py-2">
 <div>
 <h1 class="text-xl sm:text-2xl font-bold text-gray-900">Expenses</h1>
 <p class="text-[10px] sm:text-xs font-medium text-gray-400 mt-0.5">Record and monitor institute overheads</p>
 </div>
 <div class="flex flex-col sm:flex-row items-center gap-3">
 <a href="<?php echo url('admin/expense-categories'); ?>" class="w-full sm:w-auto px-5 py-3 bg-white border border-gray-200 text-gray-600 text-xs font-semibold rounded-xl hover:bg-gray-50 transition-all flex items-center justify-center gap-2">
 <i class="fa-solid fa-tags text-sm"></i>
 <span>Categories</span>
 </a>
 <button @click="resetForm(); showModal = true" class="w-full sm:w-auto px-5 py-3 bg-blue-600 text-white text-xs font-semibold rounded-xl hover:bg-blue-700 transition-all flex items-center justify-center gap-2 -600/20">
 <i class="fa-solid fa-receipt text-sm"></i>
 <span>Add Expense</span>
 </button>
 </div>
 </div>

 <!-- Filters & Search -->
 <form action="<?php echo url('admin/expenses'); ?>" method="GET" class="bg-white border border-gray-200 rounded-2xl p-4 space-y-4">
 <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
 <div class="relative group">
 <div class="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-gray-400 group-focus-within:text-blue-600 transition-colors">
 <i class="fa-solid fa-magnifying-glass text-xs"></i>
 </div>
 <input name="search" type="text" value="<?php echo htmlspecialchars($params['search']); ?>" class="w-full pl-10 pr-4 py-3 bg-white border border-gray-200 rounded-xl text-xs font-medium text-gray-900 focus:ring-4 focus:ring-blue-600/5 focus:border-blue-600 transition-all outline-none" placeholder="Search by title...">
 </div>

 <div class="relative">
 <select name="category_id" onchange="this.form.submit()" class="w-full px-4 py-3 bg-white border border-gray-200 rounded-xl text-xs font-medium text-gray-900 focus:ring-4 focus:ring-blue-600/5 focus:border-blue-600 transition-all outline-none appearance-none cursor-pointer">
 <option value="">All Categories</option>
 <?php foreach($categories as $cat): ?>
 <option value="<?php echo $cat['id']; ?>"<?php echo $params['category_id'] == $cat['id'] ? 'selected' : ''; ?>><?php echo $cat['name']; ?></option>
 <?php endforeach; ?>
 </select>
 <div class="absolute inset-y-0 right-0 pr-3.5 flex items-center pointer-events-none text-gray-400 border-l border-gray-100 ml-2 pl-3">
 <i class="fa-solid fa-chevron-down text-[10px]"></i>
 </div>
 </div>

 <div class="flex items-center justify-between bg-blue-50/50 rounded-xl border border-blue-100 px-4 py-2 sm:col-span-2 lg:col-span-1">
 <span class="text-[10px] font-bold text-blue-600 uppercase tracking-widest">Total Expenses</span>
 <span class="text-sm font-black text-gray-900">₹<?php 
 $total = array_sum(array_column($expenses, 'amount'));
 echo number_format($total, 2); 
 ?></span>
 </div>
 </div>
 </form>

 <!-- Desktop View (Table) -->
 <div class="hidden md:block bg-white border border-gray-200 rounded-2xl overflow-hidden">
 <div class="overflow-x-auto">
 <table class="w-full text-left border-collapse">
 <thead>
 <tr class="bg-gray-50/80 border-b border-gray-200">
 <th class="px-6 py-4 text-[10px] font-bold text-gray-500 uppercase tracking-widest w-16 text-center">SL</th>
 <th class="px-6 py-4 text-[10px] font-bold text-gray-500 uppercase tracking-widest min-w-[200px] border-l border-gray-100/50">Expense Info</th>
 <th class="px-6 py-4 text-[10px] font-bold text-gray-500 uppercase tracking-widest border-l border-gray-100/50">Details</th>
 <th class="px-6 py-4 text-[10px] font-bold text-gray-500 uppercase tracking-widest border-l border-gray-100/50 text-center">Amount</th>
 <th class="px-6 py-4 text-[10px] font-bold text-gray-500 uppercase tracking-widest text-right w-24 border-l border-gray-100/50">Actions</th>
 </tr>
 </thead>
 <tbody class="divide-y divide-gray-100">
 <?php if(empty($expenses)): ?>
 <tr><td colspan="5" class="px-5 py-12 text-center text-xs font-bold text-gray-400">No expenses found</td></tr>
 <?php else: ?>
 <?php foreach($expenses as $index => $exp): ?>
 <tr class="group hover:bg-gray-50 transition-colors">
 <td class="px-6 py-4 text-center">
 <span class="text-[10px] font-bold text-gray-400"><?php echo str_pad($index + 1, 2, '0', STR_PAD_LEFT); ?></span>
 </td>
 <td class="px-6 py-5 border-l border-gray-100/50">
 <div>
 <h3 class="text-xs font-bold text-gray-900 mb-0.5 group-hover:text-blue-600 transition-colors"><?php echo $exp['title']; ?></h3>
 <p class="text-[9px] font-bold text-blue-600 uppercase tracking-tight"><?php echo $exp['category_name']; ?></p>
 <div class="flex items-center gap-1.5 text-[10px] font-medium text-gray-400 mt-1">
 <i class="fa-solid fa-calendar-day text-[9px]"></i>
 <span><?php echo date('d M, Y', strtotime($exp['date'])); ?></span>
 </div>
 </div>
 </td>
 <td class="px-6 py-5 border-l border-gray-100/50">
 <div class="space-y-1">
 <div class="flex items-center gap-2 text-[10px] font-bold text-gray-700">
 <i class="fa-solid fa-wallet text-blue-600/40"></i>
 <span><?php echo $exp['payment_method']; ?></span>
 </div>
 <?php if($exp['description']): ?>
 <div class="flex items-center gap-2 text-[10px] font-medium text-gray-400">
 <i class="fa-solid fa-align-left text-gray-300"></i>
 <span class="truncate max-w-[150px]"><?php echo $exp['description']; ?></span>
 </div>
 <?php endif; ?>
 </div>
 </td>
 <td class="px-6 py-5 text-center border-l border-gray-100/50">
 <span class="text-xs font-black text-red-600">₹<?php echo number_format($exp['amount'], 2); ?></span>
 </td>
 <td class="px-6 py-5 border-l border-gray-100/50 text-right">
 <div class="flex items-center justify-end gap-2">
 <button @click="expense = <?php echo htmlspecialchars(json_encode($exp)); ?>; viewModalOpen = true" class="h-8 w-8 flex items-center justify-center rounded-lg bg-gray-100 text-gray-600 hover:bg-gray-200 transition-all border border-gray-200">
 <i class="fa-solid fa-eye text-xs"></i>
 </button>
 <button @click="resetForm(); expense = <?php echo htmlspecialchars(json_encode($exp)); ?>; expense.old_attachment = expense.attachment; showModal = true" class="h-8 w-8 flex items-center justify-center rounded-lg bg-blue-600/10 text-blue-600 hover:bg-blue-600 hover:text-white transition-all border border-blue-600/20">
 <i class="fa-solid fa-pen-to-square text-xs"></i>
 </button>
 <button @click="deleteId = <?php echo $exp['id']; ?>; deleteModalOpen = true" class="h-8 w-8 flex items-center justify-center rounded-lg bg-red-50 text-red-600 border border-red-100 hover:bg-red-600 hover:text-white transition-all active:scale-95">
 <i class="fa-solid fa-trash-can text-xs"></i>
 </button>
 </div>
 </td>
 </tr>
 <?php endforeach; ?>
 <?php endif; ?>
 </tbody>
 </table>
 </div>
 </div>

 <!-- Mobile View (Cards) -->
 <div class="md:hidden space-y-4">
 <?php foreach($expenses as $index => $exp): ?>
 <div class="bg-white border border-gray-200 rounded-2xl p-5 space-y-4 relative overflow-hidden">
 <div class="absolute top-0 right-0 px-3 py-1 bg-gray-50 border-b border-l border-gray-100 rounded-bl-xl">
 <span class="text-[9px] font-bold text-gray-400">#<?php echo str_pad($index + 1, 2, '0', STR_PAD_LEFT); ?></span>
 </div>

 <div class="flex items-start gap-4">
 <div class="h-12 w-12 bg-blue-600/10 rounded-2xl flex items-center justify-center text-blue-600 flex-none">
 <i class="fa-solid fa-receipt text-xl"></i>
 </div>
 <div class="min-w-0 pr-8">
 <h3 class="text-sm font-bold text-gray-900 truncate"><?php echo $exp['title']; ?></h3>
 <p class="text-[10px] font-bold text-blue-600 uppercase tracking-tight"><?php echo $exp['category_name']; ?></p>
 <span class="inline-flex items-center mt-2 px-2 py-0.5 rounded-lg text-[9px] font-black bg-red-50 text-red-600 border border-red-100">
 ₹<?php echo number_format($exp['amount'], 2); ?>
 </span>
 </div>
 </div>

 <div class="grid grid-cols-2 gap-4 py-4 border-y border-gray-50">
 <div class="space-y-1">
 <p class="text-[8px] font-bold text-gray-400 uppercase tracking-widest">Payment</p>
 <div class="flex items-center gap-1.5 text-[10px] font-bold text-gray-700">
 <i class="fa-solid fa-wallet text-blue-600/40 text-[9px]"></i>
 <span><?php echo $exp['payment_method']; ?></span>
 </div>
 </div>
 <div class="space-y-1">
 <p class="text-[8px] font-bold text-gray-400 uppercase tracking-widest">Date</p>
 <div class="flex items-center gap-1.5 text-[10px] font-bold text-gray-700">
 <i class="fa-solid fa-calendar-day text-blue-600/40 text-[9px]"></i>
 <span><?php echo date('d M, Y', strtotime($exp['date'])); ?></span>
 </div>
 </div>
 </div>

 <div class="flex items-center justify-end gap-2 pt-1">
 <button @click="expense = <?php echo htmlspecialchars(json_encode($exp)); ?>; viewModalOpen = true" class="h-9 w-9 flex items-center justify-center rounded-xl bg-gray-100 text-gray-600 border border-gray-200">
 <i class="fa-solid fa-eye text-xs"></i>
 </button>
 <button @click="resetForm(); expense = <?php echo htmlspecialchars(json_encode($exp)); ?>; expense.old_attachment = expense.attachment; showModal = true" class="h-9 w-9 flex items-center justify-center rounded-xl bg-blue-600/10 text-blue-600 border border-blue-600/20">
 <i class="fa-solid fa-pen-to-square text-xs"></i>
 </button>
 <button @click="deleteId = <?php echo $exp['id']; ?>; deleteModalOpen = true" class="h-9 w-9 flex items-center justify-center rounded-xl bg-red-50 text-red-600 border border-red-100 hover:bg-red-600 hover:text-white transition-all active:scale-95">
 <i class="fa-solid fa-trash-can text-xs"></i>
 </button>
 </div>
 </div>
 <?php endforeach; ?>
 </div>
 </div>
 </main>

 <!-- Create/Edit Modal -->
 <div x-show="showModal" class="fixed inset-0 z-50 overflow-y-auto" x-cloak>
 <div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
 <div class="fixed inset-0 bg-gray-900/40 backdrop-blur-sm transition-opacity" @click="showModal = false"></div>
 <span class="hidden sm:inline-block sm:align-middle sm:h-screen">&#8203;</span>
 
 <div class="inline-block align-bottom bg-white rounded-3xl text-left overflow-hidden transform transition-all sm:my-8 sm:align-middle lg:max-w-4xl sm:w-full border-none">
 <div class="bg-white px-6 py-6 sm:p-10">
 <div class="flex items-center justify-between mb-10 border-b border-gray-50 pb-6">
 <div>
 <h3 class="text-xl font-bold text-gray-900 leading-tight" x-text="expense.id ? 'Update Expense' : 'Record Expense'"></h3>
 <p class="text-[11px] font-medium text-gray-400 mt-1 tracking-wide uppercase">Provide detailed information about the overhead</p>
 </div>
 <button @click="showModal = false" class="h-12 w-12 flex items-center justify-center rounded-2xl bg-gray-50 text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-all border border-gray-200">
 <i class="fa-solid fa-xmark text-xl"></i>
 </button>
 </div>

 <form action="<?php echo url('admin/expenses/save'); ?>" method="POST" enctype="multipart/form-data" class="space-y-8">
 <input type="hidden" name="id" x-model="expense.id">
 <input type="hidden" name="old_attachment" x-model="expense.old_attachment">
 
 <div class="grid grid-cols-1 lg:grid-cols-2 gap-x-12 gap-y-8">
 
 <!-- Left Column -->
 <div class="space-y-6">
 <div class="space-y-2">
 <label class="text-[10px] font-bold text-gray-400 ml-0.5 uppercase tracking-widest">Title / Payee</label>
 <input name="title" x-model="expense.title" type="text" required class="w-full px-4 py-3.5 bg-white border border-gray-200 rounded-xl text-xs font-semibold text-gray-900 focus:ring-4 focus:ring-blue-600/5 focus:border-blue-600 transition-all outline-none" placeholder="e.g. Office Rent">
 </div>

 <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-1 gap-6">
 <div class="space-y-2">
 <label class="text-[10px] font-bold text-gray-400 ml-0.5 uppercase tracking-widest text-blue-600">Category</label>
 <div class="relative">
 <select name="expense_category_id" x-model="expense.expense_category_id" required class="w-full px-4 py-3.5 bg-white border border-gray-200 rounded-xl text-xs font-semibold text-gray-900 focus:ring-4 focus:ring-blue-600/5 focus:border-blue-600 transition-all outline-none appearance-none cursor-pointer">
 <option value="">Choose a category...</option>
 <?php foreach($categories as $cat): ?>
 <option value="<?php echo $cat['id']; ?>"><?php echo $cat['name']; ?></option>
 <?php endforeach; ?>
 </select>
 <div class="absolute inset-y-0 right-0 pr-4 flex items-center pointer-events-none text-gray-400 border-l border-gray-100 ml-2 pl-4">
 <i class="fa-solid fa-chevron-down text-[10px]"></i>
 </div>
 </div>
 </div>

 <div class="space-y-2">
 <label class="text-[10px] font-bold text-gray-400 ml-0.5 uppercase tracking-widest">Amount (₹)</label>
 <input name="amount" x-model="expense.amount" type="number" step="0.01" required class="w-full px-4 py-3.5 bg-white border border-gray-200 rounded-xl text-xs font-semibold text-gray-900 focus:ring-4 focus:ring-blue-600/5 focus:border-blue-600 transition-all outline-none" placeholder="0.00">
 </div>
 </div>
 </div>

 <!-- Right Column -->
 <div class="space-y-6">
 <div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
 <div class="space-y-2">
 <label class="text-[10px] font-bold text-gray-400 ml-0.5 uppercase tracking-widest">Date</label>
 <input name="date" x-model="expense.date" type="date" required class="w-full px-4 py-3.5 bg-white border border-gray-200 rounded-xl text-xs font-semibold text-gray-900 focus:ring-4 focus:ring-blue-600/5 focus:border-blue-600 transition-all outline-none">
 </div>
 <div class="space-y-2">
 <label class="text-[10px] font-bold text-gray-400 ml-0.5 uppercase tracking-widest">Payment Mode</label>
 <div class="relative">
 <select name="payment_method" x-model="expense.payment_method" class="w-full px-4 py-3.5 bg-white border border-gray-200 rounded-xl text-xs font-semibold text-gray-900 focus:ring-4 focus:ring-blue-600/5 focus:border-blue-600 transition-all outline-none appearance-none cursor-pointer">
 <option value="Cash">Cash</option>
 <option value="UPI">UPI</option>
 <option value="Bank Transfer">Bank Transfer</option>
 </select>
 <div class="absolute inset-y-0 right-0 pr-4 flex items-center pointer-events-none text-gray-400 border-l border-gray-100 ml-2 pl-4">
 <i class="fa-solid fa-chevron-down text-[10px]"></i>
 </div>
 </div>
 </div>
 </div>

 <div class="space-y-2">
 <label class="text-[10px] font-bold text-gray-400 ml-0.5 uppercase tracking-widest">Description</label>
 <textarea name="description" x-model="expense.description" rows="1" class="w-full px-4 py-3.5 bg-white border border-gray-200 rounded-xl text-xs font-semibold text-gray-900 focus:ring-4 focus:ring-blue-600/5 focus:border-blue-600 transition-all outline-none" placeholder="Optional details..."></textarea>
 </div>

 <div class="space-y-4">
 <div class="space-y-2">
 <label class="text-[10px] font-bold text-gray-400 ml-0.5 uppercase tracking-widest">Bill / Receipt</label>
 <div class="relative group">
 <input type="file" name="attachment" id="attachment-input" @change="handleFileChange" class="hidden">
 <label for="attachment-input" class="flex flex-col items-center justify-center w-full px-4 py-6 bg-gray-50 border-2 border-dashed border-gray-200 rounded-2xl cursor-pointer hover:bg-blue-50/30 hover:border-blue-400 transition-all text-center">
 <i class="fa-solid fa-cloud-arrow-up text-xl text-gray-300 group-hover:text-blue-500 mb-2"></i>
 <span class="text-[10px] font-bold text-gray-500 group-hover:text-blue-600">Click to upload bill</span>
 <span class="text-[8px] text-gray-400 mt-1 uppercase">PDF or Image (Max 5MB)</span>
 </label>
 </div>
 <template x-if="expense.old_attachment && !previewUrl">
 <p class="text-[9px] font-bold text-emerald-600 flex items-center gap-1.5 mt-2">
 <i class="fa-solid fa-file-circle-check"></i> 
 <span>Existing bill attached</span>
 </p>
 </template>
 </div>

 <!-- Live Preview -->
 <div x-show="previewUrl" class="space-y-2 animate-in fade-in slide-in-from-top-2 duration-300">
 <div class="flex items-center justify-between">
 <label class="text-[10px] font-bold text-blue-600 ml-0.5 uppercase tracking-widest">Live Preview</label>
 <button type="button" @click="previewUrl = null; document.getElementById('attachment-input').value = ''" class="text-[9px] font-bold text-red-500 hover:underline uppercase">Clear</button>
 </div>
 <div class="border border-gray-100 rounded-2xl overflow-hidden bg-white flex items-center justify-center">
 <template x-if="previewType === 'application/pdf'">
 <iframe :src="previewUrl" class="w-full h-[250px] border-none"></iframe>
 </template>
 <template x-if="previewType && previewType.startsWith('image/')">
 <img :src="previewUrl" class="max-w-full h-auto max-h-[250px] object-contain p-2">
 </template>
 </div>
 </div>
 </div>
 </div>
 </div>

 <div class="pt-8 flex flex-col sm:flex-row items-center justify-end gap-3 border-t border-gray-50">
 <button type="button" @click="showModal = false" class="w-full sm:w-auto px-8 py-3.5 bg-white border border-gray-200 text-gray-600 text-[11px] font-bold rounded-xl hover:bg-gray-50 transition-all">Discard</button>
 <button type="submit" class="w-full sm:w-auto px-8 py-3.5 bg-blue-600 text-white text-[11px] font-bold rounded-xl hover:bg-blue-700 transition-all flex items-center justify-center gap-2 active:scale-95 -600/20">
 <i class="fa-solid fa-check-double text-[10px]"></i>
 <span x-text="expense.id ? 'Confirm Changes' : 'Save Record'"></span>
 </button>
 </div>
 </form>
 </div>
 </div>
 </div>
 </div>

 <!-- View Modal -->
 <div x-show="viewModalOpen" class="fixed inset-0 z-50 overflow-y-auto" x-cloak>
 <div class="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
 <div class="fixed inset-0 bg-gray-900/40 backdrop-blur-sm transition-opacity" @click="viewModalOpen = false"></div>
 <span class="hidden sm:inline-block sm:align-middle sm:h-screen">&#8203;</span>
 
 <div class="inline-block align-middle bg-white rounded-3xl text-left overflow-hidden transform transition-all sm:my-8 sm:align-middle sm:max-w-2xl sm:w-full border-none">
 <div class="bg-white p-6 sm:p-8">
 <div class="flex items-start justify-between mb-8">
 <div class="flex items-center gap-4">
 <div class="h-12 w-12 rounded-2xl bg-blue-600/10 text-blue-600 flex items-center justify-center">
 <i class="fa-solid fa-receipt text-xl"></i>
 </div>
 <div>
 <h3 class="text-xl font-bold text-gray-900 leading-tight" x-text="expense.title"></h3>
 <p class="text-[10px] font-bold text-gray-400 uppercase tracking-widest mt-0.5" x-text="expense.category_name"></p>
 </div>
 </div>
 <button @click="viewModalOpen = false" class="h-10 w-10 flex items-center justify-center rounded-xl bg-gray-50 text-gray-400 hover:text-gray-600 transition-all"><i class="fa-solid fa-xmark text-lg"></i></button>
 </div>

 <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
 <!-- Left Info -->
 <div class="space-y-6">
 <div class="grid grid-cols-2 gap-4">
 <div class="p-4 bg-gray-50 rounded-2xl border border-gray-100">
 <p class="text-[8px] font-bold text-gray-400 uppercase tracking-widest mb-1.5">Amount</p>
 <p class="text-lg font-black text-red-600">₹<span x-text="Number(expense.amount).toLocaleString('en-IN', {minimumFractionDigits: 2})"></span></p>
 </div>
 <div class="p-4 bg-gray-50 rounded-2xl border border-gray-100">
 <p class="text-[8px] font-bold text-gray-400 uppercase tracking-widest mb-1.5">Date</p>
 <p class="text-xs font-bold text-gray-700" x-text="expense.date"></p>
 </div>
 </div>

 <div class="p-4 bg-gray-50 rounded-2xl border border-gray-100">
 <p class="text-[8px] font-bold text-gray-400 uppercase tracking-widest mb-1.5">Payment Mode</p>
 <p class="text-xs font-bold text-gray-700" x-text="expense.payment_method"></p>
 </div>

 <div class="p-4 bg-gray-50 rounded-2xl border border-gray-100">
 <p class="text-[8px] font-bold text-gray-400 uppercase tracking-widest mb-1.5">Description</p>
 <p class="text-xs font-medium text-gray-600 leading-relaxed" x-text="expense.description || 'No description provided'"></p>
 </div>
 </div>

 <!-- Right Preview -->
 <div class="space-y-4">
 <p class="text-[9px] font-bold text-gray-400 uppercase tracking-widest ml-1">Bill Attachment</p>
 <template x-if="expense.attachment">
 <div class="space-y-3">
 <div class="border border-gray-100 rounded-2xl overflow-hidden bg-white min-h-[300px] flex items-center justify-center">
 <template x-if="expense.attachment.toLowerCase().endsWith('.pdf')">
 <iframe :src="'<?php echo url(''); ?>' + expense.attachment" class="w-full h-[350px] border-none"></iframe>
 </template>
 <template x-if="!expense.attachment.toLowerCase().endsWith('.pdf')">
 <img :src="'<?php echo url(''); ?>' + expense.attachment" class="max-w-full h-auto max-h-[350px] object-contain p-2">
 </template>
 </div>
 <a :href="'<?php echo url(''); ?>' + expense.attachment" target="_blank" class="w-full py-3 bg-blue-600 text-white text-[10px] font-bold rounded-xl hover:bg-blue-700 transition-all flex items-center justify-center gap-2 -600/20">
 <i class="fa-solid fa-download"></i>
 Download Bill
 </a>
 </div>
 </template>
 <template x-if="!expense.attachment">
 <div class="h-[300px] rounded-2xl border-2 border-dashed border-gray-100 flex flex-col items-center justify-center text-gray-300 gap-2">
 <i class="fa-solid fa-file-circle-xmark text-4xl"></i>
 <p class="text-[10px] font-bold uppercase">No bill attached</p>
 </div>
 </template>
 </div>
 </div>
 </div>
 </div>
 </div>
 </div>

 <!-- Delete Modal Overlay -->
 <div x-show="deleteModalOpen" class="fixed inset-0 z-[110] overflow-y-auto" x-cloak>
 <div class="flex items-center justify-center min-h-screen px-4">
 <div class="fixed inset-0 bg-gray-900/40 backdrop-blur-sm" @click="deleteModalOpen = false"></div>
 <div class="bg-white rounded-3xl p-6 max-w-[440px] w-full relative z-[120] border border-gray-100">
 <div class="flex items-start gap-5">
 <div class="w-12 h-12 bg-red-50 text-red-500 rounded-2xl flex items-center justify-center flex-none text-lg">
 <i class="fa-solid fa-trash-can"></i>
 </div>
 <div class="flex-1">
 <h3 class="text-lg font-black text-gray-900">Remove Expense Record?</h3>
 <p class="text-[11px] font-medium text-gray-400 leading-relaxed mt-1">Are you sure you want to delete this expense record? This action cannot be undone.</p>
 <div class="flex justify-end gap-2 mt-6">
 <button @click="deleteModalOpen = false" class="px-5 py-2.5 bg-white border border-gray-200 text-gray-500 text-[10px] font-bold rounded-xl hover:bg-gray-50 transition-all">Cancel</button>
 <a :href="'<?php echo url('admin/expenses/delete'); ?>?id=' + deleteId" class="px-5 py-2.5 bg-red-500 text-white text-[10px] font-bold rounded-xl hover:bg-red-600 transition-all active:scale-95 flex items-center justify-center">Yes, Delete</a>
 </div>
 </div>
 </div>
 </div>
 </div>
 </div>
</div>

<?php require_once 'layouts/footer.php'; ?>
