<?php
// File: staff/staff/scholarreport.php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include "../include/config.php";

// Check if user is logged in as staff/admin
if (!isset($_SESSION['email']) && !isset($_SESSION['admin_id'])) {
    header("location:../index.php");
    exit();
}

// Safe rounding function to handle null values
function safeRound($value, $precision = 1) {
    if ($value === null || $value === '' || !is_numeric($value)) {
        return 0;
    }
    return round(floatval($value), $precision);
}

// Safe percentage calculation
function safePercentage($part, $total) {
    if ($total == 0) {
        return 0;
    }
    return safeRound(($part / $total) * 100);
}

// Get filter parameters
$filter_program = $_GET['program'] ?? 'All Programs';
$filter_intake = $_GET['intake'] ?? 'All Intakes';
$filter_year = $_GET['year'] ?? 'All Years';
$filter_gender = $_GET['gender'] ?? 'All Genders';

// Build WHERE clause for filters
$whereConditions = [];
$params = [];
$types = '';

if ($filter_program !== 'All Programs' && !empty($filter_program)) {
    $whereConditions[] = "s.program = ?";
    $params[] = $filter_program;
    $types .= 's';
}

if ($filter_intake !== 'All Intakes' && !empty($filter_intake)) {
    $whereConditions[] = "s.intake = ?";
    $params[] = $filter_intake;
    $types .= 's';
}

if ($filter_year !== 'All Years' && !empty($filter_year)) {
    $whereConditions[] = "sch.year = ?";
    $params[] = $filter_year;
    $types .= 's';
}

if ($filter_gender !== 'All Genders' && !empty($filter_gender)) {
    $whereConditions[] = "s.gender = ?";
    $params[] = $filter_gender;
    $types .= 's';
}

$whereClause = !empty($whereConditions) ? "WHERE " . implode(' AND ', $whereConditions) : '';

// Prepare and execute main query
$overviewQuery = "
    SELECT 
        COUNT(DISTINCT s.studentid) as total_students,
        COUNT(DISTINCT sch.studentid) as students_with_scholarship,
        COUNT(DISTINCT s.program) as total_programs,
        COUNT(DISTINCT s.intake) as active_intakes,
        COUNT(DISTINCT sch.year) as scholarship_years,
        AVG(sch.percentage) as avg_scholarship_percentage
    FROM students s
    LEFT JOIN scholarship sch ON s.studentid = sch.studentid
    $whereClause
";

// Using prepared statement
$stmt = mysqli_prepare($conn, $overviewQuery);
if ($stmt) {
    if (!empty($params)) {
        mysqli_stmt_bind_param($stmt, $types, ...$params);
    }
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    $overview = mysqli_fetch_assoc($result);
    mysqli_stmt_close($stmt);
} else {
    $result = mysqli_query($conn, $overviewQuery);
    $overview = mysqli_fetch_assoc($result);
}

// Apply safe functions to prevent null warnings
$total_students = $overview['total_students'] ?? 0;
$students_with_scholarship = $overview['students_with_scholarship'] ?? 0;
$total_programs = $overview['total_programs'] ?? 0;
$active_intakes = $overview['active_intakes'] ?? 0;
$scholarship_years = $overview['scholarship_years'] ?? 0;
$avg_scholarship_percentage = safeRound($overview['avg_scholarship_percentage'] ?? 0);
$coverage_rate = safePercentage($students_with_scholarship, $total_students);

// Get gender distribution
$genderQuery = "
    SELECT 
        s.gender,
        COUNT(DISTINCT s.studentid) as total,
        COUNT(DISTINCT sch.studentid) as with_scholarship,
        AVG(sch.percentage) as avg_percentage
    FROM students s
    LEFT JOIN scholarship sch ON s.studentid = sch.studentid
    $whereClause
    GROUP BY s.gender
    ORDER BY total DESC
";

$genderResult = mysqli_query($conn, $genderQuery);

// Get program distribution
$programQuery = "
    SELECT 
        s.program,
        COUNT(DISTINCT s.studentid) as total,
        COUNT(DISTINCT sch.studentid) as with_scholarship,
        AVG(sch.percentage) as avg_percentage
    FROM students s
    LEFT JOIN scholarship sch ON s.studentid = sch.studentid
    $whereClause
    GROUP BY s.program
    ORDER BY total DESC
    LIMIT 10
";

$programResult = mysqli_query($conn, $programQuery);

// Get intake distribution
$intakeQuery = "
    SELECT 
        s.intake,
        COUNT(DISTINCT s.studentid) as total_students,
        COUNT(DISTINCT sch.studentid) as with_scholarship,
        AVG(sch.percentage) as avg_percentage
    FROM students s
    LEFT JOIN scholarship sch ON s.studentid = sch.studentid
    $whereClause
    GROUP BY s.intake
    ORDER BY s.intake DESC
    LIMIT 10
";

$intakeResult = mysqli_query($conn, $intakeQuery);

// Fetch all lists for filter dropdowns
$programsResult = mysqli_query($conn, "SELECT DISTINCT program FROM students WHERE program != '' ORDER BY program");
$intakesResult = mysqli_query($conn, "SELECT DISTINCT intake FROM students WHERE intake != '' ORDER BY intake DESC");
$yearsResult = mysqli_query($conn, "SELECT DISTINCT year FROM scholarship WHERE year IS NOT NULL AND year != '' ORDER BY year DESC");
$gendersResult = mysqli_query($conn, "SELECT DISTINCT gender FROM students WHERE gender IS NOT NULL AND gender != '' ORDER BY gender");
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Scholarship Analysis Dashboard - Staff Portal</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        :root {
            --primary: #4361ee;
            --secondary: #6c757d;
            --success: #28a745;
            --warning: #ffc107;
            --danger: #dc3545;
            --info: #17a2b8;
            --light: #f8f9fa;
            --dark: #343a40;
            --primary-light: #e3f2fd;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f5f5;
            color: var(--dark);
        }

        .content {
            padding: 20px;
        }

        .page-header {
            background: white;
            padding: 30px;
            margin-bottom: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            border-left: 5px solid var(--primary);
        }

        .page-title {
            color: var(--primary);
            font-weight: 700;
            margin-bottom: 10px;
        }

        .page-subtitle {
            color: var(--secondary);
            font-size: 16px;
        }

        .stat-card {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            border-top: 4px solid var(--primary);
            transition: transform 0.3s ease;
        }

        .stat-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }

        .stat-card.success { border-top-color: var(--success); }
        .stat-card.warning { border-top-color: var(--warning); }
        .stat-card.info { border-top-color: var(--info); }
        .stat-card.danger { border-top-color: var(--danger); }

        .stat-icon {
            width: 50px;
            height: 50px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            margin-bottom: 15px;
            background: var(--primary-light);
            color: var(--primary);
        }

        .stat-card.success .stat-icon { background: #d4edda; color: var(--success); }
        .stat-card.warning .stat-icon { background: #fff3cd; color: var(--warning); }
        .stat-card.info .stat-icon { background: #d1ecf1; color: var(--info); }
        .stat-card.danger .stat-icon { background: #f8d7da; color: var(--danger); }

        .stat-number {
            font-size: 32px;
            font-weight: 800;
            color: var(--dark);
            line-height: 1;
            margin-bottom: 5px;
        }

        .stat-label {
            color: var(--secondary);
            font-size: 14px;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .filter-card {
            background: white;
            border-radius: 10px;
            padding: 25px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 30px;
        }

        .filter-title {
            color: var(--primary);
            font-weight: 600;
            margin-bottom: 20px;
            font-size: 18px;
        }

        .data-card {
            background: white;
            border-radius: 10px;
            padding: 0;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 30px;
            overflow: hidden;
        }

        .card-header {
            background: var(--primary);
            color: white;
            padding: 15px 20px;
            margin: 0;
            font-weight: 600;
            font-size: 16px;
        }

        .table-responsive {
            padding: 20px;
        }

        .table th {
            background-color: #f8f9fa;
            border-bottom: 2px solid var(--primary);
            font-weight: 600;
            color: var(--dark);
        }

        .progress-container {
            margin: 10px 0;
        }

        .progress {
            height: 8px;
            border-radius: 4px;
            background-color: #e9ecef;
        }

        .progress-bar {
            border-radius: 4px;
        }

        .badge-custom {
            padding: 5px 10px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
        }

        .badge-high { background: #d4edda; color: #155724; }
        .badge-medium { background: #fff3cd; color: #856404; }
        .badge-low { background: #f8d7da; color: #721c24; }

        .insight-box {
            background: var(--primary-light);
            border-radius: 10px;
            padding: 20px;
            border-left: 4px solid var(--primary);
        }

        .summary-card {
            background: white;
            border-radius: 10px;
            padding: 25px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 30px;
        }

        .summary-title {
            color: var(--primary);
            font-weight: 600;
            margin-bottom: 20px;
            font-size: 18px;
            border-bottom: 2px solid var(--primary-light);
            padding-bottom: 10px;
        }

        .form-control, .form-select {
            border: 2px solid #e9ecef;
            border-radius: 6px;
            padding: 10px 15px;
            font-size: 14px;
        }

        .form-control:focus, .form-select:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
        }

        .btn-primary {
            background: var(--primary);
            border: none;
            padding: 10px 20px;
            font-weight: 600;
        }

        .btn-primary:hover {
            background: #3a56d4;
            transform: translateY(-1px);
        }

        @media (max-width: 768px) {
            .content {
                padding: 15px;
            }
            
            .page-header {
                padding: 20px;
            }
            
            .stat-number {
                font-size: 24px;
            }
            
            .stat-icon {
                width: 40px;
                height: 40px;
                font-size: 20px;
            }
        }
    </style>
</head>
<body>
    <?php include "../include/nav.php"; ?>
    
    <div class="content">
        <!-- Page Header -->
        <div class="page-header">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <h1 class="page-title">
                        <i class="fas fa-chart-bar me-2"></i>Scholarship Analysis Dashboard
                    </h1>
                    <p class="page-subtitle">
                        Comprehensive report analyzing scholarship distribution by gender, program, intake, and year
                    </p>
                </div>
                <div class="col-md-4 text-md-end">
                    <div class="badge bg-primary fs-6 px-3 py-2">
                        <i class="fas fa-calendar me-1"></i> <?php echo date('M j, Y'); ?>
                    </div>
                </div>
            </div>
        </div>

        <!-- Filter Section -->
        <div class="filter-card">
            <h5 class="filter-title"><i class="fas fa-filter me-2"></i>Filter Report Data</h5>
            <form method="GET" action="">
                <div class="row g-3">
                    <div class="col-md-3">
                        <label class="form-label">Program</label>
                        <select name="program" class="form-select">
                            <option value="All Programs">All Programs</option>
                            <?php
                            if ($programsResult) {
                                while ($row = mysqli_fetch_assoc($programsResult)) {
                                    $selected = $filter_program == $row['program'] ? 'selected' : '';
                                    echo "<option value='{$row['program']}' $selected>{$row['program']}</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">Intake</label>
                        <select name="intake" class="form-select">
                            <option value="All Intakes">All Intakes</option>
                            <?php
                            if ($intakesResult) {
                                mysqli_data_seek($intakesResult, 0);
                                while ($row = mysqli_fetch_assoc($intakesResult)) {
                                    $selected = $filter_intake == $row['intake'] ? 'selected' : '';
                                    echo "<option value='{$row['intake']}' $selected>{$row['intake']}</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">Year</label>
                        <select name="year" class="form-select">
                            <option value="All Years">All Years</option>
                            <?php
                            if ($yearsResult) {
                                while ($row = mysqli_fetch_assoc($yearsResult)) {
                                    $selected = $filter_year == $row['year'] ? 'selected' : '';
                                    echo "<option value='{$row['year']}' $selected>{$row['year']}</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">Gender</label>
                        <select name="gender" class="form-select">
                            <option value="All Genders">All Genders</option>
                            <?php
                            if ($gendersResult) {
                                mysqli_data_seek($gendersResult, 0);
                                while ($row = mysqli_fetch_assoc($gendersResult)) {
                                    $selected = $filter_gender == $row['gender'] ? 'selected' : '';
                                    echo "<option value='{$row['gender']}' $selected>{$row['gender']}</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="col-md-2 d-flex align-items-end">
                        <button type="submit" class="btn btn-primary w-100">
                            <i class="fas fa-search me-2"></i>Filter
                        </button>
                    </div>
                </div>
            </form>
        </div>

        <!-- Quick Stats Row -->
        <div class="row">
            <div class="col-md-3">
                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="fas fa-users"></i>
                    </div>
                    <div class="stat-number"><?php echo $total_students; ?></div>
                    <div class="stat-label">Total Students</div>
                    <small class="text-muted">
                        <i class="fas fa-graduation-cap me-1"></i>
                        <?php echo $total_programs; ?> Programs
                    </small>
                </div>
            </div>
            <div class="col-md-3">
                <div class="stat-card success">
                    <div class="stat-icon">
                        <i class="fas fa-award"></i>
                    </div>
                    <div class="stat-number"><?php echo $students_with_scholarship; ?></div>
                    <div class="stat-label">With Scholarship</div>
                    <div class="progress-container">
                        <div class="progress">
                            <div class="progress-bar bg-success" style="width: <?php echo min($coverage_rate, 100); ?>%">
                                <?php echo $coverage_rate; ?>%
                            </div>
                        </div>
                    </div>
                    <small class="text-muted">Coverage Rate</small>
                </div>
            </div>
            <div class="col-md-3">
                <div class="stat-card info">
                    <div class="stat-icon">
                        <i class="fas fa-percentage"></i>
                    </div>
                    <div class="stat-number"><?php echo $avg_scholarship_percentage; ?>%</div>
                    <div class="stat-label">Average Scholarship</div>
                    <small class="text-muted">
                        <i class="fas fa-info-circle me-1"></i>
                        Across all students
                    </small>
                </div>
            </div>
            <div class="col-md-3">
                <div class="stat-card warning">
                    <div class="stat-icon">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <div class="stat-number"><?php echo $active_intakes; ?></div>
                    <div class="stat-label">Active Intakes</div>
                    <small class="text-muted">
                        <i class="fas fa-calendar-alt me-1"></i>
                        <?php echo $scholarship_years; ?> Scholarship Years
                    </small>
                </div>
            </div>
        </div>

        <!-- Data Tables -->
        <div class="row">
            <!-- Gender Distribution -->
            <div class="col-lg-6">
                <div class="data-card">
                    <h5 class="card-header">
                        <i class="fas fa-venus-mars me-2"></i>Gender Distribution
                    </h5>
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>Gender</th>
                                    <th>Total</th>
                                    <th>With Scholarship</th>
                                    <th>Coverage</th>
                                    <th>Average %</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($genderResult && mysqli_num_rows($genderResult) > 0) {
                                    while ($row = mysqli_fetch_assoc($genderResult)) {
                                        $gender = $row['gender'] ?: 'Not Specified';
                                        $total = $row['total'] ?? 0;
                                        $with_scholarship = $row['with_scholarship'] ?? 0;
                                        $avg_percentage = safeRound($row['avg_percentage'] ?? 0);
                                        $coverage = safePercentage($with_scholarship, $total);
                                        ?>
                                        <tr>
                                            <td><strong><?php echo htmlspecialchars($gender); ?></strong></td>
                                            <td><?php echo $total; ?></td>
                                            <td><?php echo $with_scholarship; ?></td>
                                            <td>
                                                <div class="progress-container">
                                                    <div class="progress">
                                                        <div class="progress-bar bg-primary" style="width: <?php echo min($coverage, 100); ?>%">
                                                            <?php echo $coverage; ?>%
                                                        </div>
                                                    </div>
                                                </div>
                                            </td>
                                            <td><strong><?php echo $avg_percentage; ?>%</strong></td>
                                        </tr>
                                        <?php
                                    }
                                } else {
                                    echo '<tr><td colspan="5" class="text-center py-4 text-muted">No gender data available</td></tr>';
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <!-- Program Distribution -->
            <div class="col-lg-6">
                <div class="data-card">
                    <h5 class="card-header">
                        <i class="fas fa-graduation-cap me-2"></i>Top Programs by Scholarship
                    </h5>
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>Program</th>
                                    <th>Total</th>
                                    <th>With Scholarship</th>
                                    <th>Coverage</th>
                                    <th>Average %</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($programResult && mysqli_num_rows($programResult) > 0) {
                                    while ($row = mysqli_fetch_assoc($programResult)) {
                                        $program = $row['program'] ?: 'Unknown';
                                        $total = $row['total'] ?? 0;
                                        $with_scholarship = $row['with_scholarship'] ?? 0;
                                        $avg_percentage = safeRound($row['avg_percentage'] ?? 0);
                                        $coverage = safePercentage($with_scholarship, $total);
                                        ?>
                                        <tr>
                                            <td><strong><?php echo htmlspecialchars($program); ?></strong></td>
                                            <td><?php echo $total; ?></td>
                                            <td><?php echo $with_scholarship; ?></td>
                                            <td>
                                                <div class="progress-container">
                                                    <div class="progress">
                                                        <div class="progress-bar bg-success" style="width: <?php echo min($coverage, 100); ?>%">
                                                            <?php echo $coverage; ?>%
                                                        </div>
                                                    </div>
                                                </div>
                                            </td>
                                            <td><strong><?php echo $avg_percentage; ?>%</strong></td>
                                        </tr>
                                        <?php
                                    }
                                } else {
                                    echo '<tr><td colspan="5" class="text-center py-4 text-muted">No program data available</td></tr>';
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Intake Distribution -->
        <div class="row">
            <div class="col-lg">
                <div class="data-card">
                    <h5 class="card-header">
                        <i class="fas fa-calendar-alt me-2"></i>Intake Distribution
                    </h5>
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>Intake</th>
                                    <th>Total Students</th>
                                    <th>With Scholarship</th>
                                    <th>Coverage Rate</th>
                                    <th>Average Scholarship %</th>
                                    <th>Performance</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($intakeResult && mysqli_num_rows($intakeResult) > 0) {
                                    while ($row = mysqli_fetch_assoc($intakeResult)) {
                                        $intake = $row['intake'] ?: 'Unknown';
                                        $total_students = $row['total_students'] ?? 0;
                                        $with_scholarship = $row['with_scholarship'] ?? 0;
                                        $avg_percentage = safeRound($row['avg_percentage'] ?? 0);
                                        $coverage = safePercentage($with_scholarship, $total_students);
                                        
                                        // Determine performance
                                        if ($coverage >= 75) {
                                            $performance = 'Excellent';
                                            $badge_class = 'badge-high';
                                        } elseif ($coverage >= 50) {
                                            $performance = 'Good';
                                            $badge_class = 'badge-medium';
                                        } elseif ($coverage >= 25) {
                                            $performance = 'Average';
                                            $badge_class = 'badge-medium';
                                        } else {
                                            $performance = 'Needs Attention';
                                            $badge_class = 'badge-low';
                                        }
                                        ?>
                                        <tr>
                                            <td><strong><?php echo htmlspecialchars($intake); ?></strong></td>
                                            <td><?php echo $total_students; ?></td>
                                            <td><?php echo $with_scholarship; ?></td>
                                            <td><?php echo $coverage; ?>%</td>
                                            <td><strong><?php echo $avg_percentage; ?>%</strong></td>
                                            <td>
                                                <span class="badge-custom <?php echo $badge_class; ?>">
                                                    <?php echo $performance; ?>
                                                </span>
                                            </td>
                                        </tr>
                                        <?php
                                    }
                                } else {
                                    echo '<tr><td colspan="6" class="text-center py-4 text-muted">No intake data available</td></tr>';
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            

        <!-- Report Summary -->
        <div class="summary-card">
            <h5 class="summary-title">
                <i class="fas fa-file-alt me-2"></i>Report Summary
            </h5>
            <div class="row">
                <div class="col-md-8">
                    <div class="mb-4">
                        <h6>Overall Scholarship Coverage</h6>
                        <div class="progress-container">
                            <div class="progress" style="height: 20px;">
                                <div class="progress-bar bg-success" style="width: <?php echo min($coverage_rate, 100); ?>%">
                                    <span class="fw-bold"><?php echo $coverage_rate; ?>% Coverage</span>
                                </div>
                            </div>
                        </div>
                        <p class="text-muted mt-2">
                            <?php echo $students_with_scholarship; ?> out of <?php echo $total_students; ?> students have scholarships
                        </p>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-4">
                            <div class="text-center p-3 border rounded bg-light">
                                <div class="h4 text-primary mb-2"><?php echo $total_programs; ?></div>
                                <div class="text-muted small">Programs</div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="text-center p-3 border rounded bg-light">
                                <div class="h4 text-success mb-2"><?php echo $active_intakes; ?></div>
                                <div class="text-muted small">Active Intakes</div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="text-center p-3 border rounded bg-light">
                                <div class="h4 text-info mb-2"><?php echo $scholarship_years; ?></div>
                                <div class="text-muted small">Scholarship Years</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="p-3 border rounded bg-light h-100">
                        <h6 class="mb-3">
                            <i class="fas fa-chart-pie me-2"></i>Quick Stats
                        </h6>
                        <div class="mb-3">
                            <div class="d-flex justify-content-between mb-2">
                                <span>With Scholarship:</span>
                                <span class="fw-bold text-success"><?php echo $students_with_scholarship; ?></span>
                            </div>
                            <div class="d-flex justify-content-between mb-2">
                                <span>Without Scholarship:</span>
                                <span class="fw-bold text-danger"><?php echo $total_students - $students_with_scholarship; ?></span>
                            </div>
                        </div>
                        <hr>
                        <div class="mb-2">
                            <div class="d-flex justify-content-between">
                                <span>Average Scholarship:</span>
                                <span class="fw-bold text-primary"><?php echo $avg_scholarship_percentage; ?>%</span>
                            </div>
                        </div>
                        <div class="mb-2">
                            <div class="d-flex justify-content-between">
                                <span>Coverage Rate:</span>
                                <span class="fw-bold text-success"><?php echo $coverage_rate; ?>%</span>
                            </div>
                        </div>
                        <div class="mb-2">
                            <div class="d-flex justify-content-between">
                                <span>Programs Covered:</span>
                                <span class="fw-bold">All <?php echo $total_programs; ?> programs</span>
                            </div>
                        </div>
                        <div class="mb-2">
                            <div class="d-flex justify-content-between">
                                <span>Report Generated:</span>
                                <span class="fw-bold"><?php echo date('M j, Y'); ?></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Add click effect to stat cards
            const statCards = document.querySelectorAll('.stat-card');
            statCards.forEach(card => {
                card.addEventListener('click', function() {
                    this.style.transform = 'translateY(-5px)';
                    setTimeout(() => {
                        this.style.transform = '';
                    }, 150);
                });
            });
        });
    </script>
</body>
</html>