<?php
$title = 'Weapons Reports';
$active = 'reports';
$init_charts = true;
require_once __DIR__ . '/../layouts/header.php';
require_once __DIR__ . '/../layouts/sidebar.php';

$type = $_GET['type'] ?? 'inventory';

// Ensure $data is always defined and is an array
$data = $data ?? [];

// Check if data is empty and show appropriate message
$hasData = !empty($data);

// Calculate summary data for chart
$serviceable = 0;
$unserviceable = 0;
$underRepair = 0;

if ($hasData && $type == 'inventory') {
    $serviceable = count(array_filter($data, function($w) { return ($w['condition'] ?? '') == 'Serviceable'; }));
    $unserviceable = count(array_filter($data, function($w) { return ($w['condition'] ?? '') == 'Unserviceable'; }));
    $underRepair = count(array_filter($data, function($w) { return ($w['condition'] ?? '') == 'Under Repair'; }));
}
?>

<div class="container-fluid">
    <!-- Page Header -->
    <div class="page-header">
        <div class="header-content">
            <h1>
                <i class="fas fa-gun"></i>
                Weapons Reports
            </h1>
            <p>Weapons inventory and status reports</p>
        </div>
        <div class="header-actions">
            <button class="btn btn-success" onclick="saveReport()">
                <i class="fas fa-bookmark"></i> Save Report
            </button>
            <div class="btn-group">
                <button class="btn btn-outline" onclick="exportReport('pdf')">
                    <i class="fas fa-file-pdf"></i> PDF
                </button>
                <button class="btn btn-outline" onclick="exportReport('csv')">
                    <i class="fas fa-file-csv"></i> CSV
                </button>
                <button class="btn btn-outline" onclick="exportReport('excel')">
                    <i class="fas fa-file-excel"></i> Excel
                </button>
            </div>
            <a href="<?php echo BASE_URL; ?>/reports" class="btn btn-secondary">
                <i class="fas fa-arrow-left"></i> Back
            </a>
        </div>
    </div>

    <!-- Report Controls -->
    <div class="report-controls">
        <form method="GET" action="<?php echo BASE_URL; ?>/reports/weapons" id="reportForm">
            <div class="controls-grid">
                <div class="control-group">
                    <label>Report Type</label>
                    <select name="type" id="reportType" onchange="this.form.submit()">
                        <option value="inventory" <?php echo $type == 'inventory' ? 'selected' : ''; ?>>Full Inventory</option>
                        <option value="issued" <?php echo $type == 'issued' ? 'selected' : ''; ?>>Issued Weapons</option>
                        <option value="unserviceable" <?php echo $type == 'unserviceable' ? 'selected' : ''; ?>>Unserviceable Weapons</option>
                        <option value="by_type" <?php echo $type == 'by_type' ? 'selected' : ''; ?>>Weapons by Type</option>
                    </select>
                </div>
            </div>
        </form>
    </div>

    <!-- Report Content -->
    <div class="report-content" id="reportContent">
        <?php if (!$hasData): ?>
            <div class="empty-state">
                <i class="fas fa-gun"></i>
                <p>No weapons data found for the selected report type.</p>
            </div>
        <?php elseif ($type == 'inventory'): ?>
            <div class="report-section">
                <h2>Weapons Inventory Report</h2>
                <p class="report-date">Generated: <?php echo date('d/m/Y H:i'); ?></p>
                
                <!-- Summary Cards with Professional Colors -->
                <div class="summary-section">
                    <div class="summary-cards">
                        <div class="summary-card" style="background: linear-gradient(135deg, #2E7D32 0%, #4CAF50 100%);">
                            <div class="card-icon"><i class="fas fa-check-circle"></i></div>
                            <div class="card-content">
                                <div class="card-value"><?php echo $serviceable; ?></div>
                                <div class="card-label">Serviceable</div>
                            </div>
                        </div>
                        <div class="summary-card" style="background: linear-gradient(135deg, #B71C1C 0%, #D32F2F 100%);">
                            <div class="card-icon"><i class="fas fa-times-circle"></i></div>
                            <div class="card-content">
                                <div class="card-value"><?php echo $unserviceable; ?></div>
                                <div class="card-label">Unserviceable</div>
                            </div>
                        </div>
                        <div class="summary-card" style="background: linear-gradient(135deg, #B26A00 0%, #FF8F00 100%);">
                            <div class="card-icon"><i class="fas fa-tools"></i></div>
                            <div class="card-content">
                                <div class="card-value"><?php echo $underRepair; ?></div>
                                <div class="card-label">Under Repair</div>
                            </div>
                        </div>
                        <div class="summary-card" style="background: linear-gradient(135deg, #0D47A1 0%, #1976D2 100%);">
                            <div class="card-icon"><i class="fas fa-gun"></i></div>
                            <div class="card-content">
                                <div class="card-value"><?php echo count($data); ?></div>
                                <div class="card-label">Total Weapons</div>
                            </div>
                        </div>
                    </div>

                    <!-- Chart Section -->
                    <div class="chart-container">
                        <canvas id="weaponsChart" style="width:100%; height:300px;"></canvas>
                    </div>
                </div>
                
                <div class="table-responsive">
                    <table class="report-table">
                        <thead>
                            <tr>
                                <th>Weapon ID</th>
                                <th>Type</th>
                                <th>Make/Model</th>
                                <th>Serial Number</th>
                                <th>Calibre</th>
                                <th>Source</th>
                                <th>Location</th>
                                <th>Custodian</th>
                                <th>Condition</th>
                                <th>Date Acquired</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($data as $weapon): ?>
                            <tr>
                                <td><span class="asset-code"><?php echo isset($weapon['weapon_id']) ? htmlspecialchars($weapon['weapon_id']) : '-'; ?></span></td>
                                <td><?php echo isset($weapon['type_name']) ? htmlspecialchars($weapon['type_name']) : 'Other'; ?></td>
                                <td><?php echo isset($weapon['make_model']) ? htmlspecialchars($weapon['make_model']) : '-'; ?></td>
                                <td><code><?php echo isset($weapon['serial_no']) ? htmlspecialchars($weapon['serial_no']) : '-'; ?></code></td>
                                <td><?php echo isset($weapon['calibre_name']) ? htmlspecialchars($weapon['calibre_name']) : 'N/A'; ?></td>
                                <td><?php echo $weapon['source'] ?? '-'; ?></td>
                                <td><?php echo $weapon['current_location'] ?? '-'; ?></td>
                                <td><?php echo $weapon['custodian'] ?? '-'; ?></td>
                                <td>
                                    <?php 
                                    $condition = $weapon['condition'] ?? 'Unknown';
                                    $conditionClass = '';
                                    if ($condition == 'Serviceable') $conditionClass = 'badge-success';
                                    elseif ($condition == 'Unserviceable') $conditionClass = 'badge-danger';
                                    elseif ($condition == 'Under Repair') $conditionClass = 'badge-warning';
                                    ?>
                                    <span class="badge <?php echo $conditionClass; ?>">
                                        <?php echo $condition; ?>
                                    </span>
                                </td>
                                <td><?php echo isset($weapon['date_acquired']) ? date('d/m/Y', strtotime($weapon['date_acquired'])) : '-'; ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>

        <?php elseif ($type == 'issued'): ?>
            <div class="report-section">
                <h2>Issued Weapons Report</h2>
                <p class="report-date">Generated: <?php echo date('d/m/Y H:i'); ?></p>
                
                <div class="table-responsive">
                    <table class="report-table">
                        <thead>
                            <tr>
                                <th>Weapon ID</th>
                                <th>Type</th>
                                <th>Serial Number</th>
                                <th>Issue Date</th>
                                <th>Officer</th>
                                <th>Rank</th>
                                <th>Unit</th>
                                <th>Purpose</th>
                                <th>Expected Return</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($data as $issue): ?>
                            <tr>
                                <td><span class="asset-code"><?php echo isset($issue['weapon_id']) ? htmlspecialchars($issue['weapon_id']) : '-'; ?></span></td>
                                <td><?php echo isset($issue['type_name']) ? htmlspecialchars($issue['type_name']) : '-'; ?></td>
                                <td><code><?php echo isset($issue['serial_no']) ? htmlspecialchars($issue['serial_no']) : '-'; ?></code></td>
                                <td><?php echo isset($issue['issue_date']) ? date('d/m/Y', strtotime($issue['issue_date'])) : '-'; ?></td>
                                <td><?php echo isset($issue['officer_name']) ? htmlspecialchars($issue['officer_name']) : '-'; ?></td>
                                <td><?php echo isset($issue['officer_rank']) ? htmlspecialchars($issue['officer_rank']) : '-'; ?></td>
                                <td><?php echo isset($issue['unit']) ? htmlspecialchars($issue['unit']) : '-'; ?></td>
                                <td><?php echo $issue['purpose'] ?? '-'; ?></td>
                                <td><?php echo isset($issue['expected_return_date']) ? date('d/m/Y', strtotime($issue['expected_return_date'])) : '-'; ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>

        <?php elseif ($type == 'unserviceable'): ?>
            <div class="report-section">
                <h2>Unserviceable Weapons Report</h2>
                <p class="report-date">Generated: <?php echo date('d/m/Y H:i'); ?></p>
                
                <div class="table-responsive">
                    <table class="report-table">
                        <thead>
                            <tr>
                                <th>Weapon ID</th>
                                <th>Type</th>
                                <th>Make/Model</th>
                                <th>Serial Number</th>
                                <th>Location</th>
                                <th>Remarks</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($data as $weapon): ?>
                            <tr>
                                <td><span class="asset-code"><?php echo isset($weapon['weapon_id']) ? htmlspecialchars($weapon['weapon_id']) : '-'; ?></span></td>
                                <td><?php echo isset($weapon['type_name']) ? htmlspecialchars($weapon['type_name']) : '-'; ?></td>
                                <td><?php echo isset($weapon['make_model']) ? htmlspecialchars($weapon['make_model']) : '-'; ?></td>
                                <td><code><?php echo isset($weapon['serial_no']) ? htmlspecialchars($weapon['serial_no']) : '-'; ?></code></td>
                                <td><?php echo $weapon['current_location'] ?? '-'; ?></td>
                                <td><?php echo $weapon['remarks'] ?? '-'; ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>

        <?php elseif ($type == 'by_type'): ?>
            <div class="report-section">
                <h2>Weapons by Type</h2>
                <p class="report-date">Generated: <?php echo date('d/m/Y H:i'); ?></p>
                
                <!-- Chart for weapons by type with professional color palette -->
                <div class="chart-container" style="margin-bottom: 30px;">
                    <canvas id="typeChart" style="width:100%; height:300px;"></canvas>
                </div>
                
                <div class="table-responsive">
                    <table class="report-table">
                        <thead>
                            <tr>
                                <th>Weapon Type</th>
                                <th>Count</th>
                                <th>Percentage</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                            $total = array_sum(array_column($data, 'count'));
                            foreach ($data as $item): 
                                $count = $item['count'] ?? 0;
                                $percentage = $total > 0 ? round(($count / $total) * 100, 1) : 0;
                            ?>
                            <tr>
                                <td><?php echo isset($item['type']) ? htmlspecialchars($item['type']) : '-'; ?></td>
                                <td class="text-center"><strong><?php echo $count; ?></strong></td>
                                <td>
                                    <div class="progress-bar-container">
                                        <div class="progress-bar" style="width: <?php echo $percentage; ?>%; background: #27ae60;"></div>
                                        <span class="progress-text"><?php echo $percentage; ?>%</span>
                                    </div>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        <?php endif; ?>
    </div>
</div>

<style>
:root {
    --primary-dark: #2E7D32;
    --primary: #4CAF50;
    --danger-dark: #B71C1C;
    --danger: #D32F2F;
    --warning-dark: #B26A00;
    --warning: #FF8F00;
    --info-dark: #0D47A1;
    --info: #1976D2;
    --text-dark: #2c3e50;
    --text-light: #7f8c8d;
    --border: #e2e8f0;
    --bg-light: #f8f9fa;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.02);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.05);
}

.report-controls {
    background: white;
    border-radius: 8px;
    padding: 20px 25px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-group label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    margin-bottom: 6px;
    font-weight: 600;
}

.control-group select,
.control-group input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.2s;
    background: white;
}

.control-group select:focus,
.control-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.report-content {
    background: white;
    border-radius: 8px;
    padding: 30px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.report-section h2 {
    margin: 0 0 8px 0;
    color: var(--text-dark);
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.5px;
}

.report-date {
    color: var(--text-light);
    margin-bottom: 25px;
    font-size: 0.85rem;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border);
}

/* Professional Summary Cards */
.summary-section {
    margin-bottom: 35px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.summary-card {
    color: white;
    padding: 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
    pointer-events: none;
}

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

.summary-card .card-icon {
    font-size: 2.2rem;
    opacity: 0.9;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.summary-card .card-content {
    flex: 1;
}

.summary-card .card-value {
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -1px;
}

.summary-card .card-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

/* Chart Container */
.chart-container {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 30px;
}

/* Table Styles */
.table-responsive {
    overflow-x: auto;
    margin-top: 20px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.report-table th {
    background: var(--bg-light);
    padding: 14px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-dark);
    border-bottom: 2px solid var(--border);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

.report-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.report-table tbody tr:hover {
    background: var(--bg-light);
}

.report-table tbody tr:last-child td {
    border-bottom: none;
}

.asset-code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    background: var(--bg-light);
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--primary-dark);
}

code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    background: var(--bg-light);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.8rem;
}

/* Badge System */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success {
    background: #E8F5E9;
    color: #2E7D32;
}

.badge-danger {
    background: #FFEBEE;
    color: #B71C1C;
}

.badge-warning {
    background: #FFF3E0;
    color: #B26A00;
}

/* Progress Bar for Percentage */
.progress-bar-container {
    width: 120px;
    height: 6px;
    background: var(--bg-light);
    border-radius: 3px;
    position: relative;
    display: inline-block;
    vertical-align: middle;
}

.progress-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-text {
    margin-left: 8px;
    font-size: 0.75rem;
    color: var(--text-light);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 15px;
    color: #ccc;
}

.empty-state p {
    font-size: 1rem;
}

/* Buttons */
.btn-group {
    display: flex;
    gap: 5px;
}

.btn {
    transition: all 0.2s;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

/* Responsive */
@media (max-width: 768px) {
    .report-content {
        padding: 20px;
    }
    
    .summary-cards {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    
    .summary-card {
        padding: 15px;
    }
    
    .summary-card .card-icon {
        font-size: 1.8rem;
    }
    
    .summary-card .card-value {
        font-size: 1.5rem;
    }
    
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .summary-cards {
        grid-template-columns: 1fr;
    }
}

/* Print Styles */
@media print {
    .header-actions,
    .sidebar,
    footer,
    .report-controls,
    .chart-container {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 20px !important;
    }
    
    .report-content {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
    }
    
    .report-table th {
        background: var(--bg-light) !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

.summary-card .card-value,
.summary-card .card-label {
    color: white !important;
}

.summary-card .card-icon i {
    color: white;
}
</style>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
function exportReport(format) {
    const type = document.getElementById('reportType').value;
    window.location.href = '<?php echo BASE_URL; ?>/reports/weapons?type=' + type + '&format=' + format;
}

function saveReport() {
    const reportName = prompt('Enter a name for this report:');
    if (reportName) {
        const type = document.getElementById('reportType').value;
        
        const form = document.createElement('form');
        form.method = 'POST';
        form.action = '<?php echo BASE_URL; ?>/reports/save';
        
        const csrf = document.createElement('input');
        csrf.type = 'hidden';
        csrf.name = 'csrf_token';
        
        <?php if (class_exists('Security') && method_exists('Security', 'csrfToken')): ?>
        csrf.value = '<?php echo Security::csrfToken(); ?>';
        <?php else: ?>
        csrf.value = '<?php echo $_SESSION['csrf_token'] ?? ''; ?>';
        <?php endif; ?>
        
        form.appendChild(csrf);
        
        const nameInput = document.createElement('input');
        nameInput.type = 'hidden';
        nameInput.name = 'report_name';
        nameInput.value = reportName;
        form.appendChild(nameInput);
        
        const typeInput = document.createElement('input');
        typeInput.type = 'hidden';
        typeInput.name = 'report_type';
        typeInput.value = 'weapons';
        form.appendChild(typeInput);
        
        const paramsInput = document.createElement('input');
        paramsInput.type = 'hidden';
        paramsInput.name = 'parameters';
        paramsInput.value = JSON.stringify({type});
        form.appendChild(paramsInput);
        
        document.body.appendChild(form);
        form.submit();
    }
}

// Initialize charts with professional color palette
document.addEventListener('DOMContentLoaded', function() {
    <?php if ($hasData && $type == 'inventory'): ?>
    // Weapons Status Chart - Professional color palette
    const ctx1 = document.getElementById('weaponsChart').getContext('2d');
    new Chart(ctx1, {
        type: 'doughnut',
        data: {
            labels: ['Serviceable', 'Unserviceable', 'Under Repair'],
            datasets: [{
                data: [<?php echo $serviceable; ?>, <?php echo $unserviceable; ?>, <?php echo $underRepair; ?>],
                backgroundColor: [
                    '#4CAF50',
                    '#D32F2F',
                    '#FF8F00'
                ],
                borderWidth: 0,
                hoverOffset: 5
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            cutout: '65%',
            plugins: {
                legend: {
                    position: 'bottom',
                    labels: {
                        padding: 20,
                        usePointStyle: true,
                        pointStyle: 'circle',
                        font: {
                            size: 12,
                            family: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
                        }
                    }
                },
                title: {
                    display: true,
                    text: 'Weapons by Condition',
                    font: {
                        size: 16,
                        weight: '500',
                        family: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
                    },
                    padding: {
                        bottom: 20
                    }
                },
                tooltip: {
                    backgroundColor: 'rgba(44, 62, 80, 0.9)',
                    titleFont: { size: 13, weight: '500' },
                    bodyFont: { size: 12 },
                    padding: 12,
                    cornerRadius: 6
                }
            }
        }
    });
    <?php endif; ?>

    <?php if ($hasData && $type == 'by_type'): ?>
    // Weapons by Type Chart - Professional color palette
    const ctx2 = document.getElementById('typeChart').getContext('2d');
    
    // Professional color palette for bars
    const professionalColors = [
        '#4CAF50', '#2196F3', '#FF9800', '#9C27B0', '#F44336',
        '#009688', '#673AB7', '#FFC107', '#E91E63', '#3F51B5',
        '#8BC34A', '#00BCD4', '#FF5722', '#795548', '#607D8B'
    ];
    
    const labels = [];
    const counts = [];
    const colors = [];
    
    <?php 
    $index = 0;
    foreach ($data as $item): 
    ?>
    labels.push('<?php echo isset($item['type']) ? addslashes($item['type']) : 'Other'; ?>');
    counts.push(<?php echo $item['count'] ?? 0; ?>);
    colors.push(professionalColors[<?php echo $index % 15; ?>]);
    <?php 
    $index++;
    endforeach; 
    ?>
    
    new Chart(ctx2, {
        type: 'bar',
        data: {
            labels: labels,
            datasets: [{
                label: 'Number of Weapons',
                data: counts,
                backgroundColor: colors,
                borderRadius: 4,
                barPercentage: 0.7,
                categoryPercentage: 0.8
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: false
                },
                title: {
                    display: true,
                    text: 'Weapons Distribution by Type',
                    font: {
                        size: 16,
                        weight: '500',
                        family: "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
                    },
                    padding: {
                        bottom: 20
                    }
                },
                tooltip: {
                    backgroundColor: 'rgba(44, 62, 80, 0.9)',
                    titleFont: { size: 13, weight: '500' },
                    bodyFont: { size: 12 },
                    padding: 12,
                    cornerRadius: 6,
                    callbacks: {
                        label: function(context) {
                            return `Count: ${context.raw}`;
                        }
                    }
                }
            },
            scales: {
                y: {
                    beginAtZero: true,
                    grid: {
                        color: 'rgba(0,0,0,0.05)',
                        drawBorder: false
                    },
                    ticks: {
                        stepSize: 1,
                        font: { size: 11 }
                    }
                },
                x: {
                    grid: {
                        display: false
                    },
                    ticks: {
                        font: { size: 11 }
                    }
                }
            }
        }
    });
    <?php endif; ?>
});
</script>

<?php require_once __DIR__ . '/../layouts/footer.php'; ?>