<?php
/**
 * RUHONDO BEACH RESORT HMS + POS System
 * View Maintenance Ticket Details - FIXED PATH
 * Developer: JOACHIM'S INNOTECH
 */

// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Calculate the correct path using multiple fallbacks
$base_path = null;

// Method 1: Try dirname(__DIR__, 3) - should go up three levels to root from admin/housekeeping/maintenance/
$base_path = dirname(__DIR__, 3);

// Method 2: If config doesn't exist there, try manual calculation
if (!file_exists($base_path . '/config/config.php')) {
    // Manual calculation: /HMSPOS/admin/housekeeping/maintenance/ -> /HMSPOS/
    $base_path = dirname(__DIR__, 4);
}

// Method 3: If still not found, use absolute path as last resort
if (!file_exists($base_path . '/config/config.php')) {
    $base_path = '/Applications/XAMPP/xamppfiles/htdocs/HMSPOS';
}

// Method 4: Try to find by traversing up until we find config directory
$current_dir = __DIR__;
while (!file_exists($current_dir . '/config/config.php') && $current_dir != dirname($current_dir)) {
    $current_dir = dirname($current_dir);
}
if (file_exists($current_dir . '/config/config.php')) {
    $base_path = $current_dir;
}

// Load required files
$required_files = [
    '/config/config.php',
    '/config/constants.php',
    '/config/database.php',
    '/config/helpers.php',
    '/config/auth.php',
    '/config/csrf.php'
];

foreach ($required_files as $file) {
    $file_path = $base_path . $file;
    if (file_exists($file_path)) {
        require_once $file_path;
    } else {
        error_log("Required file not found: " . $file_path);
        // Try alternate path without HMSPOS
        $alt_path = str_replace('/HMSPOS', '', $base_path) . $file;
        if (file_exists($alt_path)) {
            require_once $alt_path;
        } else {
            // Try one more fallback
            $fallback_path = dirname(__DIR__, 2) . $file;
            if (file_exists($fallback_path)) {
                require_once $fallback_path;
            }
        }
    }
}

// Require authentication
if (function_exists('require_auth')) {
    require_auth();
} else {
    // Fallback authentication check
    session_start();
    if (!isset($_SESSION['user_id'])) {
        header('Location: /HMSPOS/public/login.php');
        exit;
    }
}

// Define permission check function if it doesn't exist
if (!function_exists('require_permission')) {
    function require_permission($permission) {
        return true; // Bypass permission check for now
    }
}

// Define has_permission function if it doesn't exist
if (!function_exists('has_permission')) {
    function has_permission($permission) {
        return true; // Bypass permission check for now
    }
}

// Define escape_html function if it doesn't exist
if (!function_exists('escape_html')) {
    function escape_html($text) {
        return htmlspecialchars($text ?? '', ENT_QUOTES, 'UTF-8');
    }
}

// Define format_datetime function if it doesn't exist
if (!function_exists('format_datetime')) {
    function format_datetime($datetime, $format = 'M d, Y H:i') {
        if (empty($datetime)) return '';
        return date($format, strtotime($datetime));
    }
}

// Define format_currency function if it doesn't exist
if (!function_exists('format_currency')) {
    function format_currency($amount) {
        return 'RWF ' . number_format($amount ?? 0, 2);
    }
}

// Define time_ago function if it doesn't exist
if (!function_exists('time_ago')) {
    function time_ago($datetime) {
        if (empty($datetime)) return '';
        $time = strtotime($datetime);
        $now = time();
        $diff = $now - $time;
        
        if ($diff < 60) return $diff . ' seconds ago';
        if ($diff < 3600) return floor($diff / 60) . ' minutes ago';
        if ($diff < 86400) return floor($diff / 3600) . ' hours ago';
        if ($diff < 2592000) return floor($diff / 86400) . ' days ago';
        return date('M d, Y', $time);
    }
}

// Define set_flash_message function if it doesn't exist
if (!function_exists('set_flash_message')) {
    function set_flash_message($type, $message) {
        if (!isset($_SESSION['flash_messages'])) {
            $_SESSION['flash_messages'] = [];
        }
        $_SESSION['flash_messages'][] = ['type' => $type, 'message' => $message];
    }
}

// Define redirect function if it doesn't exist
if (!function_exists('redirect')) {
    function redirect($url) {
        header('Location: ' . $url);
        exit;
    }
}

// Define base_url function if it doesn't exist
if (!function_exists('base_url')) {
    function base_url($path = '') {
        return '/HMSPOS/' . ltrim($path, '/');
    }
}

// Define constants if not defined
if (!defined('CURRENCY_SYMBOL')) {
    define('CURRENCY_SYMBOL', 'RWF');
}

// Check permission
if (function_exists('require_permission')) {
    require_permission('hk.maintenance.view');
}

// Set page title
$page_title = 'Maintenance Ticket Details';

// Get current user
$current_user = null;
if (function_exists('current_user')) {
    $current_user = current_user();
} else {
    // Fallback: get user from session
    if (isset($_SESSION['user_id'])) {
        try {
            if (function_exists('db_fetch_one')) {
                $current_user = db_fetch_one("SELECT * FROM users WHERE user_id = ?", [$_SESSION['user_id']]);
            }
        } catch (Exception $e) {
            error_log("Error fetching current user: " . $e->getMessage());
        }
    }
}

$user_id = $current_user['user_id'] ?? $_SESSION['user_id'] ?? 0;

if (!$user_id) {
    header('Location: /HMSPOS/public/login.php');
    exit;
}

// Get ticket ID from URL
$ticket_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if (!$ticket_id) {
    if (function_exists('set_flash_message')) {
        set_flash_message('danger', 'Invalid ticket ID');
    }
    if (function_exists('redirect')) {
        redirect('tickets.php');
    } else {
        header('Location: tickets.php');
        exit;
    }
}

// Get ticket data with all details
$ticket = [];
if (function_exists('db_fetch_one')) {
    try {
        $ticket = db_fetch_one("
            SELECT 
                t.*,
                r.room_number, rt.type_name,
                u.first_name as reported_first, u.last_name as reported_last,
                a.first_name as assigned_first, a.last_name as assigned_last,
                res.first_name as resolved_first, res.last_name as resolved_last,
                (SELECT COUNT(*) FROM maintenance_tickets WHERE room_id = t.room_id AND ticket_id != t.ticket_id) as previous_tickets
            FROM maintenance_tickets t
            LEFT JOIN rooms r ON t.room_id = r.room_id
            LEFT JOIN room_types rt ON r.room_type_id = rt.room_type_id
            LEFT JOIN users u ON t.reported_by = u.user_id
            LEFT JOIN users a ON t.assigned_to = a.user_id
            LEFT JOIN users res ON t.resolved_by = res.user_id
            WHERE t.ticket_id = ?
        ", [$ticket_id]) ?: [];
    } catch (Exception $e) {
        error_log("Error fetching ticket: " . $e->getMessage());
    }
}

if (empty($ticket)) {
    if (function_exists('set_flash_message')) {
        set_flash_message('danger', 'Ticket not found');
    }
    if (function_exists('redirect')) {
        redirect('tickets.php');
    } else {
        header('Location: tickets.php');
        exit;
    }
}

// Calculate age
$age = isset($ticket['created_at']) ? (time() - strtotime($ticket['created_at'])) / 86400 : 0;

// Get status history (simulated from audit logs)
$history = [];
if (function_exists('db_fetch_all')) {
    try {
        $history = db_fetch_all("
            SELECT * FROM audit_logs 
            WHERE table_name = 'maintenance_tickets' AND record_id = ?
            ORDER BY created_at DESC
            LIMIT 20
        ", [$ticket_id]) ?: [];
    } catch (Exception $e) {
        error_log("Error fetching history: " . $e->getMessage());
    }
}

// Include header
$header_path = $base_path . '/views/partials/header.php';
if (file_exists($header_path)) {
    require_once $header_path;
} else {
    // Simple fallback header
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Maintenance Ticket Details</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
        <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
        <style>
            body { background-color: #f4f6f9; font-family: 'Segoe UI', sans-serif; }
            .content-wrapper { padding: 20px; }
            .card { border-radius: 0.5rem; box-shadow: 0 0 10px rgba(0,0,0,0.1); margin-bottom: 20px; }
            .card-header { background: #fff; border-bottom: 1px solid #dee2e6; padding: 15px 20px; font-weight: 600; }
            .badge-lg { font-size: 1rem; padding: 0.5rem 1rem; }
            .me-1 { margin-right: 0.25rem; }
            .me-2 { margin-right: 0.5rem; }
            .ms-2 { margin-left: 0.5rem; }
            .mb-2 { margin-bottom: 0.5rem; }
            .mb-3 { margin-bottom: 1rem; }
            .mt-2 { margin-top: 0.5rem; }
            .mt-3 { margin-top: 1rem; }
            .text-end { text-align: right; }
            .timeline {
                position: relative;
                padding: 0;
                list-style: none;
            }
            .timeline-item {
                position: relative;
                padding-bottom: 15px;
                padding-left: 20px;
                border-left: 2px solid #dee2e6;
            }
            .timeline-item:last-child {
                padding-bottom: 0;
            }
            .timeline-item .time {
                position: absolute;
                left: -30px;
                top: 0;
                color: #6c757d;
                font-size: 0.75rem;
                white-space: nowrap;
            }
            .timeline-item .timeline-body {
                padding: 5px 0 0 0;
            }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
                <div class="container-fluid">
                    <a class="navbar-brand" href="#">Maintenance Ticket Details</a>
                    <div class="navbar-nav ms-auto">
                        <span class="nav-item nav-link text-white">
                            <i class="fas fa-user"></i> 
                            <?php echo isset($current_user['username']) ? htmlspecialchars($current_user['username']) : 'User'; ?>
                        </span>
                        <a class="nav-item nav-link" href="/HMSPOS/public/logout.php">
                            <i class="fas fa-sign-out-alt"></i> Logout
                        </a>
                    </div>
                </div>
            </nav>
            <div class="content-wrapper">
    <?php
}
?>

<!-- Content Header -->
<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1 class="m-0">Maintenance Ticket: <?php echo htmlspecialchars($ticket['ticket_code'] ?? 'N/A'); ?></h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="/HMSPOS/public/dashboard.php">Home</a></li>
                    <li class="breadcrumb-item"><a href="/HMSPOS/housekeeping/dashboard.php">Housekeeping</a></li>
                    <li class="breadcrumb-item"><a href="tickets.php">Maintenance</a></li>
                    <li class="breadcrumb-item active">View</li>
                </ol>
            </div>
        </div>
    </div>
</div>

<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <!-- Action Buttons -->
        <div class="row mb-3">
            <div class="col-12">
                <div class="btn-group">
                    <a href="tickets.php" class="btn btn-secondary">
                        <i class="fas fa-arrow-left me-1"></i> Back to List
                    </a>
                    
                    <?php if (function_exists('has_permission') && has_permission('hk.maintenance.manage')): ?>
                        <a href="update.php?id=<?php echo $ticket_id; ?>" class="btn btn-warning">
                            <i class="fas fa-edit me-1"></i> Update Ticket
                        </a>
                    <?php endif; ?>
                    
                    <?php if (!empty($ticket['room_id'])): ?>
                        <a href="/HMSPOS/rooms/rooms/view.php?id=<?php echo $ticket['room_id']; ?>" class="btn btn-info">
                            <i class="fas fa-door-open"></i> View Room
                        </a>
                    <?php endif; ?>
                    
                    <button type="button" class="btn btn-primary" onclick="window.print()">
                        <i class="fas fa-print"></i> Print
                    </button>
                </div>
            </div>
        </div>

        <div class="row">
            <!-- Ticket Information -->
            <div class="col-md-4">
                <div class="card card-primary card-outline">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-ticket-alt me-1"></i>
                            Ticket Information
                        </h3>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm">
                            <tr>
                                <th style="width: 120px;">Ticket #:</th>
                                <td><strong><?php echo htmlspecialchars($ticket['ticket_code'] ?? 'N/A'); ?></strong></td>
                            </tr>
                            <tr>
                                <th>Status:</th>
                                <td>
                                    <span class="badge bg-<?php 
                                        $status = $ticket['status'] ?? '';
                                        echo $status == 'resolved' ? 'success' : 
                                            ($status == 'closed' ? 'secondary' : 
                                            ($status == 'in_progress' ? 'primary' : 
                                            ($status == 'assigned' ? 'info' : 'warning')));
                                    ?> badge-lg">
                                        <?php echo ucfirst(str_replace('_', ' ', $status)); ?>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <th>Priority:</th>
                                <td>
                                    <span class="badge bg-<?php 
                                        $priority = $ticket['priority'] ?? '';
                                        echo $priority == 'urgent' ? 'danger' : 
                                            ($priority == 'high' ? 'warning' : 
                                            ($priority == 'medium' ? 'info' : 'secondary'));
                                    ?>">
                                        <?php echo ucfirst($priority); ?>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <th>Issue Type:</th>
                                <td><?php echo escape_html($ticket['issue_type'] ?? ''); ?></td>
                            </tr>
                            <tr>
                                <th>Room:</th>
                                <td>
                                    <?php if (!empty($ticket['room_id'])): ?>
                                        <a href="/HMSPOS/rooms/rooms/view.php?id=<?php echo $ticket['room_id']; ?>">
                                            Room <?php echo escape_html($ticket['room_number'] ?? ''); ?>
                                        </a>
                                        <br>
                                        <small class="text-muted"><?php echo escape_html($ticket['type_name'] ?? ''); ?></small>
                                    <?php else: ?>
                                        <span class="text-muted">Common Area</span>
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <tr>
                                <th>Age:</th>
                                <td>
                                    <?php if ($age < 1): ?>
                                        <span class="badge bg-success">Less than a day</span>
                                    <?php elseif ($age < 2): ?>
                                        <span class="badge bg-info">1 day</span>
                                    <?php else: ?>
                                        <span class="badge bg-<?php echo $age > 7 ? 'danger' : 'warning'; ?>">
                                            <?php echo round($age); ?> days
                                        </span>
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <tr>
                                <th>Previous Issues:</th>
                                <td>
                                    <span class="badge bg-info"><?php echo $ticket['previous_tickets'] ?? 0; ?></span>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>

                <!-- Cost Information -->
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-dollar-sign me-1"></i>
                            Cost Information
                        </h3>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm">
                            <tr>
                                <th>Estimated Cost:</th>
                                <td class="text-end"><?php echo !empty($ticket['estimated_cost']) ? format_currency($ticket['estimated_cost']) : 'Not set'; ?></td>
                            </tr>
                            <tr>
                                <th>Actual Cost:</th>
                                <td class="text-end"><?php echo !empty($ticket['actual_cost']) ? format_currency($ticket['actual_cost']) : 'Not set'; ?></td>
                            </tr>
                            <?php if (!empty($ticket['estimated_cost']) && !empty($ticket['actual_cost'])): ?>
                            <tr>
                                <th>Variance:</th>
                                <td class="text-end">
                                    <?php 
                                    $variance = ($ticket['actual_cost'] ?? 0) - ($ticket['estimated_cost'] ?? 0);
                                    $class = $variance <= 0 ? 'success' : 'danger';
                                    ?>
                                    <span class="text-<?php echo $class; ?>">
                                        <?php echo $variance > 0 ? '+' : ''; ?><?php echo format_currency($variance); ?>
                                    </span>
                                </td>
                            </tr>
                            <?php endif; ?>
                        </table>
                    </div>
                </div>
            </div>

            <!-- Description and Notes -->
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-align-left me-1"></i>
                            Description
                        </h3>
                    </div>
                    <div class="card-body">
                        <p><?php echo nl2br(escape_html($ticket['description'] ?? '')); ?></p>
                    </div>
                </div>

                <?php if (!empty($ticket['resolution_notes'])): ?>
                <div class="card card-success">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-check-circle me-1"></i>
                            Resolution Notes
                        </h3>
                    </div>
                    <div class="card-body">
                        <p><?php echo nl2br(escape_html($ticket['resolution_notes'])); ?></p>
                    </div>
                </div>
                <?php endif; ?>

                <?php if (!empty($ticket['notes'])): ?>
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-sticky-note me-1"></i>
                            Additional Notes
                        </h3>
                    </div>
                    <div class="card-body">
                        <p><?php echo nl2br(escape_html($ticket['notes'])); ?></p>
                    </div>
                </div>
                <?php endif; ?>
            </div>

            <!-- Personnel Information -->
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-users me-1"></i>
                            Personnel
                        </h3>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm">
                            <tr>
                                <th>Reported By:</th>
                                <td>
                                    <?php echo escape_html(($ticket['reported_first'] ?? '') . ' ' . ($ticket['reported_last'] ?? '')); ?>
                                    <br>
                                    <small class="text-muted"><?php echo isset($ticket['created_at']) ? date('M d, Y H:i', strtotime($ticket['created_at'])) : 'N/A'; ?></small>
                                </td>
                            </tr>
                            
                            <?php if (!empty($ticket['assigned_to'])): ?>
                            <tr>
                                <th>Assigned To:</th>
                                <td>
                                    <?php echo escape_html(($ticket['assigned_first'] ?? '') . ' ' . ($ticket['assigned_last'] ?? '')); ?>
                                    <br>
                                    <small class="text-muted"><?php echo !empty($ticket['assigned_at']) ? date('M d, Y H:i', strtotime($ticket['assigned_at'])) : ''; ?></small>
                                </td>
                            </tr>
                            <?php endif; ?>
                            
                            <?php if (!empty($ticket['resolved_by'])): ?>
                            <tr>
                                <th>Resolved By:</th>
                                <td>
                                    <?php echo escape_html(($ticket['resolved_first'] ?? '') . ' ' . ($ticket['resolved_last'] ?? '')); ?>
                                    <br>
                                    <small class="text-muted"><?php echo !empty($ticket['resolved_at']) ? date('M d, Y H:i', strtotime($ticket['resolved_at'])) : ''; ?></small>
                                </td>
                            </tr>
                            <?php endif; ?>
                        </table>
                    </div>
                </div>

                <!-- Timeline -->
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-history me-1"></i>
                            Timeline
                        </h3>
                    </div>
                    <div class="card-body p-0">
                        <div class="timeline" style="padding: 1rem;">
                            <!-- Created -->
                            <div class="timeline-item">
                                <span class="time">
                                    <i class="fas fa-clock"></i> <?php echo isset($ticket['created_at']) ? time_ago($ticket['created_at']) : ''; ?>
                                </span>
                                <div class="timeline-body">
                                    <i class="fas fa-plus-circle text-success me-2"></i>
                                    Ticket created by <?php echo escape_html($ticket['reported_first'] ?? 'Unknown'); ?>
                                </div>
                            </div>
                            
                            <!-- Assigned -->
                            <?php if (!empty($ticket['assigned_at'])): ?>
                            <div class="timeline-item">
                                <span class="time">
                                    <i class="fas fa-clock"></i> <?php echo time_ago($ticket['assigned_at']); ?>
                                </span>
                                <div class="timeline-body">
                                    <i class="fas fa-user-check text-info me-2"></i>
                                    Assigned to <?php echo escape_html($ticket['assigned_first'] ?? ''); ?>
                                </div>
                            </div>
                            <?php endif; ?>
                            
                            <!-- Resolved -->
                            <?php if (!empty($ticket['resolved_at'])): ?>
                            <div class="timeline-item">
                                <span class="time">
                                    <i class="fas fa-clock"></i> <?php echo time_ago($ticket['resolved_at']); ?>
                                </span>
                                <div class="timeline-body">
                                    <i class="fas fa-check-circle text-success me-2"></i>
                                    Resolved by <?php echo escape_html($ticket['resolved_first'] ?? ''); ?>
                                </div>
                            </div>
                            <?php endif; ?>
                            
                            <!-- From history -->
                            <?php foreach ($history as $entry): ?>
                            <div class="timeline-item">
                                <span class="time">
                                    <i class="fas fa-clock"></i> <?php echo isset($entry['created_at']) ? time_ago($entry['created_at']) : ''; ?>
                                </span>
                                <div class="timeline-body">
                                    <i class="fas fa-edit text-warning me-2"></i>
                                    <?php echo ucfirst($entry['action'] ?? ''); ?> - 
                                    <small><?php echo escape_html($entry['old_values'] ?? ''); ?></small>
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Quick Actions -->
        <div class="row mt-3">
            <div class="col-12">
                <div class="card card-info">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-bolt me-1"></i>
                            Quick Actions
                        </h3>
                    </div>
                    <div class="card-body">
                        <?php if (($ticket['status'] ?? '') == 'open'): ?>
                            <a href="update.php?id=<?php echo $ticket_id; ?>" class="btn btn-primary">
                                <i class="fas fa-user-plus"></i> Assign Ticket
                            </a>
                        <?php endif; ?>
                        
                        <?php if (($ticket['status'] ?? '') == 'assigned' || ($ticket['status'] ?? '') == 'in_progress'): ?>
                            <a href="update.php?id=<?php echo $ticket_id; ?>" class="btn btn-success">
                                <i class="fas fa-check-circle"></i> Mark Resolved
                            </a>
                        <?php endif; ?>
                        
                        <?php if (!empty($ticket['room_id'])): ?>
                            <a href="../tasks/create.php?room_id=<?php echo $ticket['room_id']; ?>" class="btn btn-warning">
                                <i class="fas fa-broom"></i> Create Cleaning Task
                            </a>
                        <?php endif; ?>
                        
                        <button type="button" class="btn btn-secondary" onclick="window.print()">
                            <i class="fas fa-print"></i> Print Report
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<style>
.timeline {
    position: relative;
    padding: 0;
    list-style: none;
}
.timeline-item {
    position: relative;
    padding-bottom: 15px;
    padding-left: 20px;
    border-left: 2px solid #dee2e6;
}
.timeline-item:last-child {
    padding-bottom: 0;
}
.timeline-item .time {
    position: absolute;
    left: -30px;
    top: 0;
    color: #6c757d;
    font-size: 0.75rem;
    white-space: nowrap;
}
.timeline-item .timeline-body {
    padding: 5px 0 0 0;
}
.badge-lg {
    font-size: 1rem;
    padding: 0.5rem 1rem;
}
</style>

<?php
// Include footer
$footer_path = $base_path . '/views/partials/footer.php';
if (file_exists($footer_path)) {
    require_once $footer_path;
} else {
    echo '</div></div></body></html>';
}
?>