<!-- Restaurants Content for Super Admin Layout -->
<div class="space-y-6">
    <div class="flex justify-between items-center">
        <div>
            <h2 class="text-xl font-bold text-white">Manage Restaurants</h2>
            <p class="text-slate-400 text-sm mt-1">All registered restaurants on the platform</p>
        </div>
        <a href="/restpo/superadmin/restaurants/create" class="flex items-center gap-2 px-5 py-2.5 rounded-xl font-semibold text-white transition shadow-lg" style="background:linear-gradient(135deg,#8b5cf6,#3b82f6)">
            <i class="fas fa-plus"></i> Add Restaurant
        </a>
    </div>

    <?php if(isset($_GET['success'])): ?>
    <div class="rounded-xl p-4 text-sm font-medium mb-4" style="background:rgba(16,185,129,0.15); border:1px solid rgba(16,185,129,0.3); color:#6ee7b7">
        <i class="fas fa-check-circle mr-2"></i>
        <?php 
        if ($_GET['success'] === 'edit') {
            echo 'Restaurant updated successfully!';
        } elseif ($_GET['success'] === 'delete') {
            echo 'Restaurant deleted successfully!';
        } else {
            echo 'Restaurant created successfully!';
        }
        ?>
    </div>
    <?php endif; ?>

    <?php if(isset($_GET['error'])): ?>
    <div class="rounded-xl p-4 text-sm font-medium mb-4" style="background:rgba(239,68,68,0.15); border:1px solid rgba(239,68,68,0.3); color:#fca5a5">
        <i class="fas fa-exclamation-circle mr-2"></i>
        <?php echo htmlspecialchars($_GET['error']); ?>
    </div>
    <?php endif; ?>

    <div class="rounded-2xl overflow-hidden" style="background:rgba(255,255,255,0.04); border:1px solid rgba(255,255,255,0.08)">
        <table class="w-full text-sm">
            <thead><tr class="border-b border-white/5">
                <th class="text-left px-6 py-4 text-slate-500 font-medium">Restaurant</th>
                <th class="text-left px-6 py-4 text-slate-500 font-medium">Contact</th>
                <th class="text-left px-6 py-4 text-slate-500 font-medium">Package</th>
                <th class="text-left px-6 py-4 text-slate-500 font-medium">Status</th>
                <th class="text-left px-6 py-4 text-slate-500 font-medium">Expires</th>
                <th class="px-6 py-4 text-slate-500 font-medium text-right">Actions</th>
            </tr></thead>
            <tbody>
                <?php if(empty($restaurants)): ?>
                <tr><td colspan="6" class="px-6 py-12 text-center text-slate-500">No restaurants yet. <a href="/restpo/superadmin/restaurants/create" class="text-purple-400 hover:underline">Add your first one →</a></td></tr>
                <?php endif; ?>
                <?php foreach($restaurants as $r): ?>
                <tr class="border-b border-white/5 hover:bg-white/5 transition">
                    <td class="px-6 py-4">
                        <div class="flex items-center gap-3">
                            <div class="w-10 h-10 rounded-xl flex items-center justify-center font-bold" style="background:rgba(139,92,246,0.2); color:#a78bfa"><?php echo strtoupper(substr($r['name'],0,2)); ?></div>
                            <div class="font-medium text-white"><?php echo htmlspecialchars($r['name']); ?></div>
                        </div>
                    </td>
                    <td class="px-6 py-4 text-slate-400"><?php echo htmlspecialchars($r['email']); ?><br><span class="text-xs"><?php echo htmlspecialchars($r['phone']); ?></span></td>
                    <td class="px-6 py-4 text-slate-300"><?php echo htmlspecialchars($r['package_name'] ?? '—'); ?></td>
                    <td class="px-6 py-4">
                        <span class="px-2.5 py-1 rounded-full text-xs font-semibold" style="background:<?php echo $r['status']==='active'?'rgba(16,185,129,0.15)':'rgba(239,68,68,0.15)'; ?>; color:<?php echo $r['status']==='active'?'#6ee7b7':'#fca5a5'; ?>"><?php echo ucfirst($r['status']); ?></span>
                    </td>
                    <td class="px-6 py-4 text-slate-400"><?php echo $r['subscription_ends_at'] ? date('M d, Y', strtotime($r['subscription_ends_at'])) : '—'; ?></td>
                    <td class="px-6 py-4 text-right">
                        <a href="/restpo/superadmin/restaurants/billing?id=<?php echo $r['id']; ?>" class="text-emerald-400 hover:text-emerald-300 mr-3 text-xs inline-block"><i class="fas fa-credit-card"></i> Billing</a>
                        <a href="/restpo/superadmin/restaurants/edit?id=<?php echo $r['id']; ?>" class="text-purple-400 hover:text-purple-300 mr-3 text-xs inline-block"><i class="fas fa-edit"></i> Edit</a>
                        <form action="/restpo/superadmin/restaurants/delete" method="POST" class="inline" onsubmit="return confirm('Are you sure you want to delete this restaurant? This will permanently delete all its data, including users, floors, tables, menus, orders, inventory, shift schedules, and payroll records.');">
                            <input type="hidden" name="id" value="<?php echo $r['id']; ?>">
                            <button type="submit" class="text-red-400 hover:text-red-300 text-xs cursor-pointer bg-transparent border-0 p-0"><i class="fas fa-trash-alt"></i> Delete</button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
