<div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="fw-bold mb-0"><i class="fas fa-map-marker-alt me-2 text-primary"></i>Sites</h5>
    <a class="btn btn-sm btn-primary" href="<?= url('/Sites/create') ?>"><i class="fas fa-plus me-1"></i>New Site</a>
</div>

<?php if (!empty($flash)): ?>
    <div class="alert alert-info py-2 small"><?= e($flash) ?></div>
<?php endif; ?>

<div class="rs-card p-3">
<?php if (empty($sites)): ?>
    <p class="text-muted small mb-0">No sites yet — create your first one.</p>
<?php else: ?>
    <table class="table table-sm table-hover mb-0">
        <thead>
            <tr>
                <th>Name</th><th>Code</th><th>Parent</th><th>City / Region</th>
                <th class="text-end">Assets</th><th>Status</th><th></th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($sites as $s): ?>
                <tr>
                    <td><a href="<?= url('/Sites/show/' . (int) $s['site_id']) ?>" class="fw-semibold text-decoration-none"><?= e($s['name']) ?></a></td>
                    <td class="small text-muted"><?= e($s['code'] ?? '—') ?></td>
                    <td class="small text-muted"><?= e($s['parent_name'] ?? '—') ?></td>
                    <td class="small text-muted"><?= e(trim(($s['city'] ?? '') . ' · ' . ($s['region'] ?? ''), ' ·') ?: '—') ?></td>
                    <td class="text-end"><?= (int) $s['asset_count'] ?></td>
                    <td><span class="badge bg-secondary text-uppercase"><?= e($s['status']) ?></span></td>
                    <td class="text-end"><a href="<?= url('/Sites/edit/' . (int) $s['site_id']) ?>" class="btn btn-sm btn-outline-primary"><i class="fas fa-pen"></i></a></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php endif; ?>
</div>
