<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($title ?? 'Emergency Response Coordination System', ENT_QUOTES, 'UTF-8') ?></title>
    <meta name="description" content="<?= htmlspecialchars($meta_description ?? 'Rapid emergency reporting and dispatch system.', ENT_QUOTES, 'UTF-8') ?>">
    
    <!-- Google Fonts: Inter for clean, highly legible UI -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/4.0.0/jquery.min.js"></script>

    <!-- FontAwesome for standard icons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    <!-- Tailwind CSS CDN -->
    <script src="https://cdn.tailwindcss.com"></script>
    <script>

        tailwind.config = {
            theme: {
                extend: {
                    fontFamily: {
                        sans: ['Inter', 'sans-serif'],
                    },
                    colors: {
                        navy: {
                            800: '#1e3a8a',
                            900: '#1e3a8a', // Deep professional navy
                            950: '#172554',
                        },
                        brandBlue: {
                            500: '#3b82f6', // Bright, actionable blue
                            600: '#2563eb',
                        },
                        alert: '#ef4444', // Red for emergencies
                    }
                }
            }
        }
    </script>

    <!-- SweetAlert2 CSS & JS for elegant notifications -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    <!-- Coreflux Head Injection -->
    <?= htmlspecialchars(Core\View::renderHead(), ENT_QUOTES, 'UTF-8') ?>

    <style>
        
        body {
            font-family: 'Inter', sans-serif;
            background-color: #f8fafc; 
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }
        main {
            flex: 1;
        }
        
        ::-webkit-scrollbar {
            width: 8px;
        }
        ::-webkit-scrollbar-track {
            background: #f1f1f1; 
        }
        ::-webkit-scrollbar-thumb {
            background: #cbd5e1; 
            border-radius: 4px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: #94a3b8; 
        }
    </style>
</head>
<body class="text-slate-800 antialiased">

    <!-- Navbar -->
    <nav class="bg-navy-950 text-white shadow-lg sticky top-0 z-50">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16">
                <!-- Logo & Brand -->
                <div class="flex items-center">
                    <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/" class="flex-shrink-0 flex items-center gap-2 group">
                        <div class="w-10 h-10 bg-alert text-white rounded-lg flex items-center justify-center font-bold text-xl shadow-md group-hover:scale-105 transition-transform">
                            <i class="fas fa-shield-alt"></i>
                        </div>
                        <span class="font-bold text-xl tracking-tight hidden sm:block">ERCS</span>
                    </a>
                </div>

                <!-- Desktop Menu -->
                <div class="hidden md:flex items-center space-x-4">
                    <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/" class="px-3 py-2 rounded-md text-sm font-medium hover:bg-navy-800 transition-colors">Home</a>
                    <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/about" class="px-3 py-2 rounded-md text-sm font-medium hover:bg-navy-800 transition-colors">About</a>
                    <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/contact" class="px-3 py-2 rounded-md text-sm font-medium hover:bg-navy-800 transition-colors">Contact</a>
                    
                    <!-- Primary Call to Action -->
                    <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/emergency/report" class="ml-4 px-4 py-2 bg-alert hover:bg-red-600 text-white font-semibold rounded-md shadow-md transition-colors flex items-center gap-2 pulse-animation">
                        <i class="fas fa-exclamation-triangle"></i> Report Emergency
                    </a>

                    <!-- Auth Links / Dynamic State -->
                    <?php if (Core\Auth::check()): ?>
                        <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/dashboard" class="ml-2 px-3 py-2 text-sm font-medium text-brandBlue-500 hover:text-white transition-colors">
                            <i class="fas fa-user-circle mr-1"></i> Dashboard
                        </a>
                    <?php else: ?>
                        <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/login" class="ml-2 px-3 py-2 text-sm font-medium text-slate-300 hover:text-white transition-colors">
                            Login
                        </a>
                    <?php endif; ?>
                </div>

                <!-- Mobile menu button -->
                <div class="md:hidden flex items-center">
                    <button id="mobile-menu-btn" class="text-slate-300 hover:text-white focus:outline-none">
                        <i class="fas fa-bars text-2xl"></i>
                    </button>
                </div>
            </div>
        </div>

        <!-- Mobile Menu (Hidden by default) -->
        <div id="mobile-menu" class="hidden md:hidden bg-navy-900 border-t border-navy-800 pb-4 shadow-inner">
            <div class="px-2 pt-2 space-y-1">
                <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/" class="block px-3 py-2 rounded-md text-base font-medium hover:bg-navy-800">Home</a>
                <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/about" class="block px-3 py-2 rounded-md text-base font-medium hover:bg-navy-800">About</a>
                <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/contact" class="block px-3 py-2 rounded-md text-base font-medium hover:bg-navy-800">Contact</a>
                
                <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/emergency/report" class="block mt-2 px-3 py-3 bg-alert text-white rounded-md text-base font-bold text-center shadow">
                    <i class="fas fa-exclamation-triangle mr-2"></i> Report Emergency
                </a>
                
                <div class="border-t border-navy-800 mt-2 pt-2">
                    <?php if (Core\Auth::check()): ?>
                        <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/dashboard" class="block px-3 py-2 rounded-md text-base font-medium text-brandBlue-500 hover:bg-navy-800">Dashboard</a>
                        <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/logout" class="block px-3 py-2 rounded-md text-base font-medium text-slate-300 hover:bg-navy-800">Logout</a>
                    <?php else: ?>
                        <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/login" class="block px-3 py-2 rounded-md text-base font-medium text-slate-300 hover:bg-navy-800">Login</a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </nav>

    <!-- Main Content Area where individual views are injected -->
    <main>
        <!-- Path: app/Views/responder/incident_detail.view.php -->
<!-- Include Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />

<div class="bg-slate-100 min-h-[calc(100vh-64px)] py-6">
    <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
        
        <!-- Action Top Bar -->
        <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-4 mb-6 flex flex-col sm:flex-row justify-between items-center gap-4">
            <div>
                <a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/responder/dashboard" class="text-slate-500 hover:text-navy-900 mr-3">
                    <i class="fas fa-arrow-left"></i> Back
                </a>
                <h1 class="text-xl font-bold text-navy-900 inline-block">Incident #<?= htmlspecialchars(str_pad($incident['id'], 5, '0', STR_PAD_LEFT), ENT_QUOTES, 'UTF-8') ?></h1>
            </div>
            
            <div id="status-controls" class="flex gap-2">
                <?php if ($incident['status'] == 'dispatched'): ?>
                    <button id="btn-accept" class="bg-alert hover:bg-red-600 text-white px-6 py-2 rounded-lg font-bold shadow-md transition-colors pulse-animation">
                        <i class="fas fa-check-circle"></i> ACCEPT DISPATCH
                    </button>
                <?php elseif ($incident['status'] == 'accepted'): ?>
                    <button id="btn-enroute" data-status="en_route" class="status-btn bg-brandBlue-600 hover:bg-brandBlue-700 text-white px-6 py-2 rounded-lg font-bold shadow-md transition-colors">
                        <i class="fas fa-ambulance"></i> MARK EN ROUTE
                    </button>
                <?php elseif ($incident['status'] == 'en_route'): ?>
                    <button id="btn-resolved" data-status="resolved" class="status-btn bg-green-600 hover:bg-green-700 text-white px-6 py-2 rounded-lg font-bold shadow-md transition-colors">
                        <i class="fas fa-flag-checkered"></i> MARK RESOLVED
                    </button>
                <?php elseif ($incident['status'] == 'resolved'): ?>
                    <span class="bg-green-100 text-green-800 px-4 py-2 rounded-lg font-bold border border-green-200">
                        <i class="fas fa-check-double"></i> INCIDENT CLOSED
                    </span>
                <?php endif; ?>
            </div>
        </div>

        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
            
            <!-- Left Column: Details & Map -->
            <div class="lg:col-span-2 space-y-6">
                <!-- Victim Details -->
                <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
                    <h3 class="text-lg font-bold text-navy-900 mb-4 border-b pb-2"><i class="fas fa-user-injured text-alert mr-2"></i> Victim Information</h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
                        <div>
                            <strong class="block text-slate-500">Name</strong>
                            <span class="text-lg font-semibold text-slate-900"><?= htmlspecialchars($incident['victim_name'], ENT_QUOTES, 'UTF-8') ?></span>
                        </div>
                        <div>
                            <strong class="block text-slate-500">Contact Number</strong>
                            <a href="tel:<?= htmlspecialchars($incident['victim_phone'], ENT_QUOTES, 'UTF-8') ?>" class="text-lg font-bold text-brandBlue-600 hover:underline">
                                <i class="fas fa-phone-alt"></i> <?= htmlspecialchars($incident['victim_phone'], ENT_QUOTES, 'UTF-8') ?>
                            </a>
                        </div>
                        <div class="md:col-span-2 mt-2">
                            <strong class="block text-slate-500">Emergency Description</strong>
                            <p class="text-slate-800 bg-slate-50 p-3 rounded border border-slate-100 mt-1"><?= htmlspecialchars($incident['description'], ENT_QUOTES, 'UTF-8') ?></p>
                        </div>
                        <?php if ($incident['image_url']): ?>
                            <div class="md:col-span-2 mt-2">
                                <strong class="block text-slate-500 mb-2">Attached Evidence</strong>
                                <a href="<?= htmlspecialchars(MEDIA_URL, ENT_QUOTES, 'UTF-8') ?>/<?= htmlspecialchars($incident['image_url'], ENT_QUOTES, 'UTF-8') ?>" target="_blank">
                                    <img src="<?= htmlspecialchars(MEDIA_URL, ENT_QUOTES, 'UTF-8') ?>/<?= htmlspecialchars($incident['image_url'], ENT_QUOTES, 'UTF-8') ?>" class="max-w-full h-auto rounded-lg border shadow-sm max-h-64 object-cover" alt="Emergency Photo">
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- GPS Map Info -->
                <div class="bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
                    <div class="p-4 bg-navy-900 text-white font-semibold flex justify-between items-center">
                        <span><i class="fas fa-map-marked-alt text-brandBlue-400"></i> Target Location</span>
                        <a href="https://www.google.com/maps/dir/?api=1&destination=<?= htmlspecialchars($incident['latitude'], ENT_QUOTES, 'UTF-8') ?>,<?= htmlspecialchars($incident['longitude'], ENT_QUOTES, 'UTF-8') ?>" target="_blank" class="bg-brandBlue-600 hover:bg-brandBlue-700 px-3 py-1 rounded text-sm transition-colors flex items-center gap-1 shadow-sm">
                            <i class="fas fa-directions"></i> Nav via Google Maps
                        </a>
                    </div>
                    <div class="p-4 bg-slate-50">
                        <div class="flex justify-between items-center mb-3">
                            <div class="text-xs text-slate-500"><i class="fas fa-info-circle"></i> Incident pinned on the map below.</div>
                            <div class="font-mono text-xs font-bold text-slate-700 bg-slate-200 px-2 py-1 rounded">
                                Lat: <?= htmlspecialchars($incident['latitude'], ENT_QUOTES, 'UTF-8') ?> | Lng: <?= htmlspecialchars($incident['longitude'], ENT_QUOTES, 'UTF-8') ?>
                            </div>
                        </div>
                        <!-- Embedded Map Container -->
                        <div id="incident-map" class="w-full rounded-md border border-slate-300 shadow-inner" style="height: 350px; z-index: 1;"></div>
                    </div>
                </div>
            </div>

            <!-- Right Column: Live Chat -->
            <div class="lg:col-span-1">
                <div id="chat-card" class="bg-white rounded-xl shadow-sm border border-slate-200 h-[600px] flex flex-col transition-all duration-200">
                    <div class="p-4 bg-slate-100 border-b border-slate-200 font-semibold text-navy-900 flex justify-between items-center">
                        <span><i class="fas fa-comments text-brandBlue-500 mr-2"></i> Live Comms (Victim)</span>
                        
                        <!-- Mobile Expand/Collapse Button -->
                        <button type="button" id="btn-toggle-chat" class="lg:hidden text-xs font-semibold px-2.5 py-1 rounded bg-white text-navy-900 border border-slate-300 hover:bg-slate-50 transition-colors flex items-center gap-1.5 shadow-sm">
                            <i class="fas fa-expand-alt" id="chat-expand-icon"></i>
                            <span id="chat-expand-text">Expand</span>
                        </button>
                    </div>
                    
                    <div id="chat-messages" class="flex-1 p-4 overflow-y-auto bg-slate-50 space-y-4">
                        <!-- Messages dynamically load here -->
                    </div>
                    
                    <div class="p-3 border-t border-slate-200 bg-white rounded-b-xl">
                        <form id="chatForm" class="flex gap-2">
                            <input type="text" id="chatInput" placeholder="Message victim..." class="flex-1 px-3 py-2 border border-slate-300 rounded-md focus:outline-none focus:border-brandBlue-500 text-sm" autocomplete="off" required>
                            <button type="submit" class="bg-navy-900 hover:bg-navy-800 text-white px-4 py-2 rounded-md transition-colors">
                                Send
                            </button>
                        </form>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

@addScript
<!-- Include Leaflet JS -->
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>

<script>
$(document).ready(function() {
    const incidentId = <?= htmlspecialchars($incident['id'], ENT_QUOTES, 'UTF-8') ?>;
    const incLat = <?= htmlspecialchars($incident['latitude'], ENT_QUOTES, 'UTF-8') ?>;
    const incLng = <?= htmlspecialchars($incident['longitude'], ENT_QUOTES, 'UTF-8') ?>;


    const map = L.map('incident-map').setView([incLat, incLng], 15);

    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(map);

    L.marker([incLat, incLng]).addTo(map)
        .bindPopup('<b class="text-alert">Incident Location</b><br>Victim is here.')
        .openPopup();

    setTimeout(() => {
        map.invalidateSize();
    }, 500);

    $('#btn-toggle-chat').on('click', function() {
        const $chatCard = $('#chat-card');
        const $icon = $('#chat-expand-icon');
        const $text = $('#chat-expand-text');
        const isExpanded = $chatCard.hasClass('fixed');

        if (!isExpanded) {
            $chatCard
                .removeClass('rounded-xl border shadow-sm h-[600px]')
                .addClass('fixed inset-0 z-50 h-full w-full rounded-none border-none');
            $icon.removeClass('fa-expand-alt').addClass('fa-compress-alt');
            $text.text('Close');
            $('body').addClass('overflow-hidden');
        } else {
            $chatCard
                .removeClass('fixed inset-0 z-50 h-full w-full rounded-none border-none')
                .addClass('rounded-xl border shadow-sm h-[600px]');
            $icon.removeClass('fa-compress-alt').addClass('fa-expand-alt');
            $text.text('Expand');
            $('body').removeClass('overflow-hidden');
        }
        
        const chatContainer = $('#chat-messages');
        chatContainer.scrollTop(chatContainer[0].scrollHeight);
    });

    $('#btn-accept').on('click', function() {
        let $btn = $(this);
        let origHtml = $btn.html();
        $btn.html('<i class="fas fa-spinner fa-spin"></i> ACCEPTING...').prop('disabled', true);
        
        $.ajax({
            url: `<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/responder/incident/${incidentId}/accept`,
            type: 'POST',
            success: function(response) {
                if(response.status === 'success') {
                    showNotification('success', 'Accepted', response.message);
                    setTimeout(() => window.location.reload(), 1500);
                }
            },
            error: function() {
                showNotification('error', 'Error', 'Failed to accept dispatch.');
                $btn.html(origHtml).prop('disabled', false);
            }
        });
    });

    $('.status-btn').on('click', function() {
        let status = $(this).data('status');
        let $btn = $(this);
        let origHtml = $btn.html();
        
        Swal.fire({
            title: 'Update Status?',
            text: "Are you sure you want to mark this as " + status.replace('_', ' ').toUpperCase() + "?",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#1e3a8a',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, update it!'
        }).then((result) => {
            if (result.isConfirmed) {
                $btn.html('<i class="fas fa-spinner fa-spin"></i> UPDATING...').prop('disabled', true);
                $.ajax({
                    url: `<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/responder/incident/${incidentId}/status`,
                    type: 'POST',
                    data: { status: status },
                    success: function(response) {
                        if(response.status === 'success') {
                            showNotification('success', 'Status Updated', response.message);
                            setTimeout(() => window.location.reload(), 1500);
                        }
                    },
                    error: function() {
                        showNotification('error', 'Error', 'Failed to update status.');
                        $btn.html(origHtml).prop('disabled', false);
                    }
                });
            }
        });
    });

    const chatContainer = $('#chat-messages');
    let lastMessageCount = 0;

    function fetchMessages() {
        $.ajax({
            url: `<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/api/emergency/${incidentId}/messages`,
            type: 'GET',
            global: false,
            success: function(response) {
                if(response.status === 'success' && response.data.length > lastMessageCount) {
                    renderMessages(response.data);
                    lastMessageCount = response.data.length;
                    chatContainer.scrollTop(chatContainer[0].scrollHeight);
                }
            }
        });
    }

    function renderMessages(messages) {
        let html = '';
        messages.forEach(msg => {
            let isResponder = msg.sender_role === 'responder' || msg.sender_role === 'admin';
            
            if(isResponder) {
                html += `
                    <div class="flex justify-end mb-4">
                        <div class="bg-navy-900 text-white p-3 rounded-lg rounded-tr-none text-sm max-w-[85%] shadow-sm">
                            ${escapeHtml(msg.message_text)}
                            <div class="text-[10px] text-slate-300 text-right mt-1">${formatTime(msg.created_at)}</div>
                        </div>
                    </div>
                `;
            } else {
                html += `
                    <div class="flex justify-start mb-4">
                        <div class="bg-white border border-slate-200 text-slate-800 p-3 rounded-lg rounded-tl-none text-sm max-w-[85%] shadow-sm">
                            <strong class="block text-xs text-alert mb-1">${escapeHtml(msg.sender_name)} (Victim)</strong>
                            ${escapeHtml(msg.message_text)}
                            <div class="text-[10px] text-slate-400 mt-1">${formatTime(msg.created_at)}</div>
                        </div>
                    </div>
                `;
            }
        });
        chatContainer.html(html);
    }

    function escapeHtml(unsafe) {
        if (unsafe == null) return '';
        return unsafe.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
    }
    
    function formatTime(dateString) {
        return new Date(dateString).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
    }

    $('#chatForm').on('submit', function(e) {
        e.preventDefault();
        let input = $('#chatInput');
        let text = input.val().trim();
        if(text === '') return;
        input.val('');
        
        $.ajax({
            url: `<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/api/emergency/${incidentId}/messages`,
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify({ message_text: text }),
            global: false,
            success: function(response) {
                if(response.status === 'success') fetchMessages();
            }
        });
    });

    setInterval(fetchMessages, 3000);
    fetchMessages();
});
</script>
@endAddScript
    </main>

    <!-- Footer -->
    <footer class="bg-slate-900 text-slate-300 py-10 mt-auto border-t border-slate-800">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
                <div>
                    <h3 class="text-white text-lg font-bold mb-4 flex items-center gap-2">
                        <i class="fas fa-shield-alt text-alert"></i> ERCS
                    </h3>
                    <p class="text-sm text-slate-400">
                        Rapid emergency reporting and intelligent responder coordination. Saving lives through instant communication and real-time location tracking.
                    </p>
                </div>
                <div>
                    <h3 class="text-white text-lg font-bold mb-4">Quick Links</h3>
                    <ul class="space-y-2 text-sm">
                        <li><a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/emergency/report" class="hover:text-white transition-colors text-alert font-semibold">Report Emergency</a></li>
                        <li><a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/about" class="hover:text-white transition-colors">How it Works</a></li>
                        <li><a href="<?= htmlspecialchars(APP_URL, ENT_QUOTES, 'UTF-8') ?>/login" class="hover:text-white transition-colors">Responder Login</a></li>
                    </ul>
                </div>
                <div>
                    <h3 class="text-white text-lg font-bold mb-4">Emergency Contacts</h3>
                    <ul class="space-y-2 text-sm text-slate-400">
                        <li><i class="fas fa-phone-alt mr-2 text-brandBlue-500"></i> Toll-Free: 112</li>
                        <li><i class="fas fa-ambulance mr-2 text-brandBlue-500"></i> Medical: 911</li>
                        <li><i class="fas fa-fire mr-2 text-brandBlue-500"></i> Fire Service: 101</li>
                    </ul>
                </div>
            </div>
            <div class="border-t border-slate-800 mt-8 pt-8 text-sm text-center text-slate-500">
                &copy; <?= htmlspecialchars(date('Y'), ENT_QUOTES, 'UTF-8') ?> Emergency Response Coordination System. All rights reserved.
            </div>
        </div>
    </footer>

    <!-- jQuery for seamless AJAX requests (Chat, Location updates) -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

    <!-- Global Layout Scripts -->
    <script>
        $(document).ready(function() {

            $('#mobile-menu-btn').on('click', function() {
                $('#mobile-menu').slideToggle('fast');
            });

            $.ajaxSetup({
                error: function(jqXHR, textStatus, errorThrown) {
                    let errorMessage = "An unexpected error occurred.";
                    if (jqXHR.responseJSON && jqXHR.responseJSON.message) {
                        errorMessage = jqXHR.responseJSON.message;
                    }


                    if (this.global !== false) {
                        Swal.fire({
                            icon: 'error',
                            title: 'System Error',
                            text: errorMessage,
                            confirmButtonColor: '#1e3a8a'
                        });
                    }
                }
            });
        });

        function showNotification(type, title, message) {
            Swal.fire({
                icon: type, // 'success', 'error', 'warning', 'info'
                title: title,
                text: message,
                toast: true,
                position: 'top-end',
                showConfirmButton: false,
                timer: 4000,
                timerProgressBar: true,
                didOpen: (toast) => {
                    toast.addEventListener('mouseenter', Swal.stopTimer)
                    toast.addEventListener('mouseleave', Swal.resumeTimer)
                }
            });
        }
    </script>

    <!-- Coreflux Injected View Scripts (e.g. Google Maps, Chat scripts added via @addScript) -->
    <?= htmlspecialchars(Core\View::renderScripts(), ENT_QUOTES, 'UTF-8') ?>
</body>
</html>