<div class="d-flex justify-content-between align-items-center mb-3">
    <h4 class="mb-0"><i class="fas fa-futbol me-2"></i>Match <?=e($match['match_number'])?></h4>
    <a href="/sports/matches" class="btn btn-secondary btn-sm">Back</a>
</div>
<div class="row g-3">
<div class="col-md-8">
    <div class="card"><div class="card-body text-center">
        <div class="row align-items-center">
            <div class="col-md-4"><h5><?=e($match['home_name']??'TBD')?></h5><span class="text-muted">Home</span></div>
            <div class="col-md-4">
                <?php if($match['status']==='completed'):?><h2 class="display-6"><?=$match['home_score']?> - <?=$match['away_score']?></h2>
                <?php else:?><h4 class="text-muted">vs</h4><?php endif;?>
                <div><?=status_badge($match['status'])?></div>
                <small class="text-muted"><?=format_date($match['match_date'])?> <?=$match['start_time']?substr($match['start_time'],0,5):''?></small>
            </div>
            <div class="col-md-4"><h5><?=e($match['away_name']??'TBD')?></h5><span class="text-muted">Away</span></div>
        </div>
    </div></div>
    <?php if($match['status']!=='completed' && auth_can('sports.manage')):?>
    <div class="card mt-3"><div class="card-header">Record Result</div><div class="card-body">
        <form method="POST" action="/sports/matches/<?=$match['id']?>/result" data-ajax="true"><?=csrf_field()?>
        <div class="row g-2 align-items-end">
            <div class="col-md-4"><label class="form-label">Home Score</label><input type="number" name="home_score" class="form-control" min="0" value="0"></div>
            <div class="col-md-4"><label class="form-label">Away Score</label><input type="number" name="away_score" class="form-control" min="0" value="0"></div>
            <div class="col-md-4"><button type="submit" class="btn btn-success w-100"><i class="fas fa-check me-1"></i>Save Result</button></div>
        </div></form>
    </div></div>
    <?php endif;?>
    <?php if(!empty($events)):?>
    <div class="card mt-3"><div class="card-header">Match Events</div><div class="card-body p-0">
        <table class="table table-sm mb-0"><thead><tr><th>Min</th><th>Event</th><th>Team</th><th>Player</th></tr></thead><tbody>
        <?php foreach($events as $ev):?>
        <tr><td><?=$ev['event_minute']?>'</td><td><?=ucfirst(str_replace('_',' ',$ev['event_type']))?></td><td><?=e($ev['team_name']??'')?></td><td><?=e($ev['member_name']??'')?></td></tr>
        <?php endforeach;?>
        </tbody></table>
    </div></div>
    <?php endif;?>
</div>
<div class="col-md-4"><div class="card"><div class="card-body">
    <table class="table table-sm mb-0">
        <tr><th>Sport</th><td><?=e($match['sport_name']??'')?></td></tr>
        <tr><th>Type</th><td><?=ucfirst($match['match_type'])?></td></tr>
        <tr><th>Venue</th><td><?=e($match['facility_name']??'TBD')?></td></tr>
        <?php if($match['league_name']):?><tr><th>League</th><td><?=e($match['league_name'])?></td></tr><?php endif;?>
        <?php if($match['round_number']):?><tr><th>Round</th><td><?=$match['round_number']?></td></tr><?php endif;?>
        <?php if($match['referee_name']):?><tr><th>Referee</th><td><?=e($match['referee_name'])?></td></tr><?php endif;?>
    </table>
</div></div></div>
</div>