<?php
if (session_status() === PHP_SESSION_NONE) session_start();
require_once __DIR__ . '/../config/database.php'; // Définit BASE_URL
?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CIBER - Auto-contrôle Qualité BTP</title>
    <!-- Bootstrap 5 + FontAwesome + DataTables -->
    <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">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css">
    <!-- CSS personnalisé -->
    <link rel="stylesheet" href="<?= BASE_URL ?>assets/css/style.css">
    <!-- Fabric.js pour l'annotation des images -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.0/fabric.min.js"></script>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom">
        <div class="container-fluid">
            <a class="navbar-brand" href="<?= BASE_URL ?>index.php">
                <img src="<?= BASE_URL ?>assets/images/logo-ciber.png" alt="CIBER" height="60">
            </a>
            <div class="d-flex align-items-center">
                <div class="text-danger fw-bold me-4 d-flex align-items-center">
                    <i class="fas fa-hard-hat fa-2x me-2"></i>
                    <span class="fs-5">LA SÉCURITÉ D'ABORD !</span>
                </div>
                <?php if (isset($_SESSION['user_id'])): ?>
                <div class="dropdown">
                    <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="userMenu" data-bs-toggle="dropdown">
                        <i class="fas fa-user-circle"></i> <?= htmlspecialchars($_SESSION['user_nom']) ?> (<?= $_SESSION['user_role'] ?>)
                    </button>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <?php if ($_SESSION['user_role'] === 'personnel'): ?>
                            <li><a class="dropdown-item" href="<?= BASE_URL ?>user/profile.php"><i class="fas fa-id-card"></i> Mon profil</a></li>
                            <li><a class="dropdown-item" href="<?= BASE_URL ?>user/logout.php"><i class="fas fa-sign-out-alt"></i> Déconnexion</a></li>
                        <?php else: ?>
                            <li><a class="dropdown-item" href="<?= BASE_URL ?>profile.php"><i class="fas fa-id-card"></i> Mon profil</a></li>
                            <li><a class="dropdown-item" href="<?= BASE_URL ?>logout.php"><i class="fas fa-sign-out-alt"></i> Déconnexion</a></li>
                        <?php endif; ?>
                    </ul>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </nav>
    <main class="container my-4">