<?php $bp = defined('BASE_PATH') ? BASE_PATH : '/gmind'; $results = $results ?? []; $statusColors = ['draft'=>'#999','pending_approval'=>'#f39c12','approved'=>'#3498db','published'=>'#27ae60','rejected'=>'#e84118']; ?>
<div class="admin-section">
    <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px;">
        <h2 style="margin:0;font-size:1.1rem;color:#0d3b3b;">Results</h2>
        <a href="<?= $bp ?>/branch/results/create" style="background:#16a085;color:#fff;text-decoration:none;padding:10px 20px;border-radius:8px;font-size:0.86rem;font-weight:600;">+ Create Result</a>
    </div>
    <div style="background:#fff;border-radius:10px;overflow:hidden;box-shadow:0 2px 8px rgba(0,0,0,0.06);">
        <?php if (empty($results)): ?><div style="text-align:center;padding:50px 20px;color:#999;"><p style="margin:0;">No results yet.</p></div><?php else: ?>
        <table style="width:100%;border-collapse:collapse;font-size:0.84rem;"><thead><tr style="background:#f8f9fa;border-bottom:2px solid #dee2e6;">
            <th style="padding:10px;text-align:left;">Student</th><th style="padding:10px;text-align:left;">Enrollment</th>
            <th style="padding:10px;text-align:left;">Course</th><th style="padding:10px;text-align:right;">%</th>
            <th style="padding:10px;text-align:center;">Grade</th><th style="padding:10px;text-align:center;">Status</th>
            <th style="padding:10px;text-align:right;">Actions</th>
        </tr></thead><tbody>
        <?php foreach ($results as $r): ?>
            <tr style="border-bottom:1px solid #f0f0f0;">
                <td style="padding:10px;font-weight:600;color:#0d3b3b;"><?= htmlspecialchars($r['student_name'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td>
                <td style="padding:10px;font-family:monospace;font-size:0.78rem;color:#16a085;"><?= htmlspecialchars($r['enrollment_no'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td>
                <td style="padding:10px;color:#666;font-size:0.8rem;"><?= htmlspecialchars($r['course_name'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td>
                <td style="padding:10px;text-align:right;font-weight:600;"><?= (float)($r['percentage'] ?? 0) ?>%</td>
                <td style="padding:10px;text-align:center;font-weight:600;color:#1a4fa0;"><?= htmlspecialchars($r['grade'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td>
                <td style="padding:10px;text-align:center;"><span style="padding:2px 8px;border-radius:10px;font-size:0.7rem;font-weight:600;color:#fff;background:<?= $statusColors[$r['status']] ?? '#999' ?>;"><?= htmlspecialchars(str_replace('_',' ',ucfirst($r['status'] ?? '')), ENT_QUOTES, 'UTF-8') ?></span></td>
                <td style="padding:10px;text-align:right;"><a href="<?= $bp ?>/branch/results/<?= (int)$r['id'] ?>" style="background:#3498db;color:#fff;text-decoration:none;padding:4px 10px;border-radius:4px;font-size:0.72rem;">View</a></td>
            </tr>
        <?php endforeach; ?>
        </tbody></table>
        <?php endif; ?>
    </div>
</div>
