<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0"><?= e(current_lang() === 'ar' ? ($term['term_name_ar'] ?: $term['term_name_en']) : $term['term_name_en']) ?></h4>
    <div class="d-flex gap-2">
        <?php if (auth_can('board.manage')): ?>
        <a href="/board/terms/<?= $term['id'] ?>/edit" class="btn btn-warning"><i class="fas fa-edit me-1"></i><?= lang('common.edit') ?></a>
        <?php endif; ?>
        <a href="/board/terms" class="btn btn-secondary"><i class="fas fa-arrow-left me-1"></i><?= lang('common.back') ?></a>
    </div>
</div>

<div class="row g-3">
    <div class="col-md-4">
        <div class="card h-100">
            <div class="card-header"><h6 class="mb-0"><?= lang('common.details') ?></h6></div>
            <div class="card-body">
                <table class="table table-sm table-borderless">
                    <tr><td class="text-muted"><?= lang('common.status') ?></td><td><?= status_badge($term['status']) ?></td></tr>
                    <tr><td class="text-muted"><?= lang('board.start_date') ?></td><td><?= format_date($term['start_date']) ?></td></tr>
                    <tr><td class="text-muted"><?= lang('board.end_date') ?></td><td><?= format_date($term['end_date']) ?></td></tr>
                    <tr><td class="text-muted"><?= lang('board.election_date') ?></td><td><?= format_date($term['election_date']) ?: '-' ?></td></tr>
                </table>
                <?php if ($term['notes']): ?>
                <p class="text-muted small"><?= nl2br(e($term['notes'])) ?></p>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <div class="col-md-8">
        <div class="card">
            <div class="card-header"><h6 class="mb-0"><?= lang('board.board_members') ?> (<?= count($members) ?>)</h6></div>
            <div class="card-body p-0">
                <table class="table table-sm mb-0">
                    <thead><tr><th><?= lang('board.name') ?></th><th><?= lang('board.position') ?></th><th><?= lang('common.status') ?></th></tr></thead>
                    <tbody>
                    <?php foreach ($members as $m): ?>
                    <tr>
                        <td><?= e($m['full_name_en']) ?></td>
                        <td><?= e($m['position_title'] ?? '-') ?></td>
                        <td><?= status_badge($m['status']) ?></td>
                    </tr>
                    <?php endforeach; ?>
                    <?php if (empty($members)): ?>
                    <tr><td colspan="3" class="text-center text-muted py-3">No board members assigned</td></tr>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="card mt-3">
            <div class="card-header"><h6 class="mb-0"><?= lang('board.recent_meetings') ?></h6></div>
            <div class="card-body p-0">
                <table class="table table-sm mb-0">
                    <thead><tr><th>#</th><th><?= lang('board.title') ?></th><th><?= lang('board.date') ?></th><th><?= lang('common.status') ?></th></tr></thead>
                    <tbody>
                    <?php foreach ($meetings as $mt): ?>
                    <tr>
                        <td><a href="/board/meetings/<?= $mt['id'] ?>"><?= e($mt['meeting_number']) ?></a></td>
                        <td><?= e($mt['title_en']) ?></td>
                        <td><?= format_date($mt['meeting_date']) ?></td>
                        <td><?= status_badge($mt['status']) ?></td>
                    </tr>
                    <?php endforeach; ?>
                    <?php if (empty($meetings)): ?>
                    <tr><td colspan="4" class="text-center text-muted py-3">No meetings yet</td></tr>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>