<?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">
 <?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">
 
 <!-- Welcome Header -->
 <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-1">
 <div>
 <h1 class="text-xl sm:text-3xl font-black text-gray-900 tracking-tight">
 How's it going, <span class="text-blue-600"><?php echo explode(' ', $_SESSION['user_name'] ?? 'Admin')[0]; ?>?</span>
 </h1>
 <p class="text-[10px] sm:text-xs font-bold text-gray-400 uppercase tracking-widest mt-1.5 flex items-center gap-2">
 <span class="h-2 w-2 rounded-full bg-emerald-500 animate-pulse"></span>
 Institute Overview • <?php echo date('l, d/m/Y'); ?>
 </p>
 </div>
 <div class="flex items-center gap-3">
 <a href="<?php echo url('/admin/admissions'); ?>" class="px-5 py-3 bg-blue-600 text-white text-[10px] font-black uppercase tracking-widest rounded-xl hover:bg-blue-700 transition-all -600/20 active:scale-95 flex items-center gap-2">
 <i class="fa-solid fa-plus text-xs"></i>
 <span>New Admission</span>
 </a>
 </div>
 </div>

 <!-- Modern Stats Grid -->
 <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
 <!-- Students Card -->
 <?php if(isset($stats['total_students'])): ?>
 <div class="bg-white p-6 rounded-3xl border border-gray-100 group hover:border-blue-600/20 transition-all">
 <div class="flex items-center justify-between mb-4">
 <div class="h-12 w-12 bg-blue-50 text-blue-600 rounded-2xl flex items-center justify-center text-xl group-hover:scale-110 transition-transform">
 <i class="fa-solid fa-user-graduate"></i>
 </div>
 <div class="text-right">
 <p class="text-[8px] font-black text-emerald-500 uppercase tracking-widest bg-emerald-50 px-2 py-0.5 rounded-lg inline-block">Active: <?php echo $stats['active_students']; ?></p>
 </div>
 </div>
 <h3 class="text-[10px] font-black text-gray-400 uppercase tracking-widest mb-1">Total Students</h3>
 <p class="text-2xl font-black text-gray-900"><?php echo number_format($stats['total_students']); ?></p>
 </div>
 <?php endif; ?>

 <!-- Revenue Card -->
 <?php if(isset($stats['total_revenue'])): ?>
 <div class="bg-white p-6 rounded-3xl border border-gray-100 group hover:border-emerald-600/20 transition-all">
 <div class="flex items-center justify-between mb-4">
 <div class="h-12 w-12 bg-emerald-50 text-emerald-600 rounded-2xl flex items-center justify-center text-xl group-hover:scale-110 transition-transform">
 <i class="fa-solid fa-hand-holding-dollar"></i>
 </div>
 <div class="text-right">
 <p class="text-[8px] font-black text-emerald-500 uppercase tracking-widest">Total Income</p>
 </div>
 </div>
 <h3 class="text-[10px] font-black text-gray-400 uppercase tracking-widest mb-1">Revenue</h3>
 <p class="text-2xl font-black text-gray-900">₹<?php echo number_format($stats['total_revenue'], 0); ?></p>
 </div>

 <!-- Dues Card -->
 <div class="bg-white p-6 rounded-3xl border border-gray-100 group hover:border-red-600/20 transition-all">
 <div class="flex items-center justify-between mb-4">
 <div class="h-12 w-12 bg-red-50 text-red-600 rounded-2xl flex items-center justify-center text-xl group-hover:scale-110 transition-transform">
 <i class="fa-solid fa-file-invoice-dollar"></i>
 </div>
 <div class="text-right">
 <p class="text-[8px] font-black text-red-500 uppercase tracking-widest">Outstanding</p>
 </div>
 </div>
 <h3 class="text-[10px] font-black text-gray-400 uppercase tracking-widest mb-1">Total Dues</h3>
 <p class="text-2xl font-black text-gray-900">₹<?php echo number_format($stats['total_dues'], 0); ?></p>
 </div>
 <?php endif; ?>

 <!-- Expenses Card -->
 <?php if(isset($stats['total_expenses'])): ?>
 <div class="bg-white p-6 rounded-3xl border border-gray-100 group hover:border-amber-600/20 transition-all">
 <div class="flex items-center justify-between mb-4">
 <div class="h-12 w-12 bg-amber-50 text-amber-600 rounded-2xl flex items-center justify-center text-xl group-hover:scale-110 transition-transform">
 <i class="fa-solid fa-receipt"></i>
 </div>
 <div class="text-right">
 <p class="text-[8px] font-black text-amber-500 uppercase tracking-widest">Institute Cost</p>
 </div>
 </div>
 <h3 class="text-[10px] font-black text-gray-400 uppercase tracking-widest mb-1">Expenses</h3>
 <p class="text-2xl font-black text-gray-900">₹<?php echo number_format($stats['total_expenses'], 0); ?></p>
 </div>
 <?php endif; ?>
 </div>

 <!-- Activity & Schedule Section -->
 <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
 
 <!-- Recent Activity Feed -->
 <div class="lg:col-span-2 space-y-4">
 <div class="flex items-center justify-between px-1">
 <h3 class="text-xs font-black text-gray-400 uppercase tracking-widest flex items-center gap-2">
 <i class="fa-solid fa-bolt-lightning text-blue-600"></i>
 Recent Activity
 </h3>
 </div>
 
 <div class="bg-white rounded-[32px] border border-gray-100 overflow-hidden">
 <?php if(empty($activities)): ?>
 <div class="py-16 text-center">
 <div class="h-16 w-16 bg-gray-50 rounded-3xl flex items-center justify-center mx-auto mb-4 text-gray-200">
 <i class="fa-solid fa-ghost text-2xl"></i>
 </div>
 <p class="text-[11px] font-bold text-gray-400 uppercase tracking-widest">No recent activity found</p>
 </div>
 <?php else: ?>
 <div class="divide-y divide-gray-50">
 <?php foreach($activities as $act): ?>
 <div class="px-6 py-5 flex items-center justify-between hover:bg-gray-50/50 transition-colors group">
 <div class="flex items-center gap-4">
 <div class="h-11 w-11 rounded-2xl flex items-center justify-center text-sm <?php echo $act['type'] === 'Admission' ? 'bg-blue-50 text-blue-600' : 'bg-emerald-50 text-emerald-600'; ?>">
 <i class="fa-solid <?php echo $act['type'] === 'Admission' ? 'fa-user-plus' : 'fa-indian-rupee-sign'; ?>"></i>
 </div>
 <div>
 <h4 class="text-xs font-black text-gray-900 group-hover:text-blue-600 transition-colors"><?php echo $act['student_name']; ?></h4>
 <p class="text-[10px] font-bold text-gray-400 uppercase tracking-tight mt-0.5">
 <?php echo $act['type']; ?> • <?php echo $act['detail']; ?>
 </p>
 </div>
 </div>
 <div class="text-right">
 <?php if($act['type'] === 'Payment'): ?>
 <p class="text-xs font-black text-emerald-600">+₹<?php echo number_format($act['amount'], 2); ?></p>
 <?php endif; ?>
 <p class="text-[9px] font-bold text-gray-400 mt-1 uppercase"><?php echo date('d M, h:i A', strtotime($act['date'])); ?></p>
 </div>
 </div>
 <?php endforeach; ?>
 </div>
 <?php if(\App\Core\Auth::hasPermission('fees_management')): ?>
 <div class="p-4 bg-gray-50/50 text-center border-t border-gray-50">
 <a href="<?php echo url('/admin/fees'); ?>" class="text-[10px] font-black text-blue-600 hover:text-blue-700 uppercase tracking-widest">View Financial Ledger</a>
 </div>
 <?php endif; ?>
 <?php endif; ?>
 </div>
 </div>

 <!-- Schedule & Quick Info -->
 <div class="space-y-6">
 <!-- Today's Schedule -->
 <div class="space-y-4">
 <h3 class="text-xs font-black text-gray-400 uppercase tracking-widest px-1 flex items-center gap-2">
 <i class="fa-solid fa-calendar-day text-blue-500"></i>
 Live Schedule
 </h3>
 <div class="bg-white rounded-[32px] border border-gray-100 p-6">
 <?php if(empty($activeBatchesToday)): ?>
 <div class="py-8 text-center">
 <p class="text-[10px] font-black text-gray-300 uppercase tracking-widest">No classes scheduled</p>
 <p class="text-[9px] font-medium text-gray-400 mt-1">Enjoy your free day!</p>
 </div>
 <?php else: ?>
 <div class="space-y-4">
 <?php foreach($activeBatchesToday as $batch): ?>
 <div class="relative pl-4 border-l-2 border-blue-600">
 <div class="flex items-center justify-between mb-1">
 <h4 class="text-xs font-black text-gray-900"><?php echo $batch['name']; ?></h4>
 <span class="text-[9px] font-bold text-blue-600 bg-blue-50 px-2 py-0.5 rounded-lg uppercase"><?php echo date('h:i A', strtotime($batch['start_time'])); ?></span>
 </div>
 <p class="text-[10px] font-bold text-gray-400 uppercase truncate"><?php echo $batch['course_name']; ?></p>
 <p class="text-[9px] font-medium text-gray-500 mt-1 flex items-center gap-1">
 <i class="fa-solid fa-user-tie text-[8px]"></i>
 <?php echo $batch['teacher_name']; ?>
 </p>
 </div>
 <?php endforeach; ?>
 </div>
 <?php endif; ?>
 </div>
 </div>

 <!-- Quick Actions -->
 <?php if(\App\Core\Auth::user()['role'] === 'admin'): ?>
 <div class="bg-blue-600 rounded-[32px] p-6 -600/20 overflow-hidden relative group">
 <div class="absolute top-0 right-0 p-8 -mr-8 -mt-8 bg-white/10 rounded-full blur-2xl group-hover:bg-white/20 transition-all"></div>
 <h3 class="text-white text-sm font-black mb-4 relative z-10">Quick Tools</h3>
 <div class="grid grid-cols-2 gap-3 relative z-10">
 <a href="<?php echo url('/admin/fees/generate'); ?>" class="bg-white/10 hover:bg-white/20 text-white rounded-2xl p-4 transition-all text-center">
 <i class="fa-solid fa-magic-sparkles mb-2"></i>
 <p class="text-[9px] font-black uppercase tracking-tighter">Auto Fees</p>
 </a>
 <a href="<?php echo url('/admin/settings'); ?>" class="bg-white/10 hover:bg-white/20 text-white rounded-2xl p-4 transition-all text-center">
 <i class="fa-solid fa-cog mb-2"></i>
 <p class="text-[9px] font-black uppercase tracking-tighter">Settings</p>
 </a>
 </div>
 </div>
 <?php endif; ?>
 </div>

 </div>

 </div>
 </main>
</div>

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

