<?php require_once __DIR__ . '/auth.php'; requireLogin(); $currentUser = getCurrentUser(); $unreadCount = getUnreadMessagesCount(); $currentPage = basename($_SERVER['PHP_SELF'], '.php'); ?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= isset($pageTitle) ? escape($pageTitle) . ' — ' : '' ?>Dashboard — Maître Bouchareb</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;500;600&family=Inter:wght@300;400;500;600;700&family=Italiana&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <!-- SIDEBAR -->
    <aside class="sidebar">
        <div class="sidebar-header">
            <div class="sidebar-logo">
                <i class="fas fa-balance-scale"></i>
            </div>
            <div class="sidebar-brand">
                <div class="sidebar-brand-sub">Espace Avocat</div>
            </div>
        </div>

        <nav class="sidebar-nav">
            <div class="nav-section">
                <div class="nav-section-title">Tableau de bord</div>
                <a href="dashboard.php" class="nav-item <?= $currentPage === 'dashboard' ? 'active' : '' ?>">
                    <i class="fas fa-th-large"></i>
                    <span>Vue d'ensemble</span>
                </a>
                <a href="messages.php" class="nav-item <?= $currentPage === 'messages' || $currentPage === 'message-view' ? 'active' : '' ?>">
                    <i class="fas fa-inbox"></i>
                    <span>Messages du site</span>
                    <?php if ($unreadCount > 0): ?>
                        <span class="badge"><?= $unreadCount ?></span>
                    <?php endif; ?>
                </a>
            </div>

            <div class="nav-section">
                <div class="nav-section-title">Boîte mail</div>
                <a href="inbox.php" class="nav-item <?= $currentPage === 'inbox' || $currentPage === 'view' ? 'active' : '' ?>">
                    <i class="fas fa-envelope"></i>
                    <span>Boîte de réception</span>
                </a>
                <a href="sent.php" class="nav-item <?= $currentPage === 'sent' ? 'active' : '' ?>">
                    <i class="fas fa-paper-plane"></i>
                    <span>Envoyés</span>
                </a>
                <a href="compose.php" class="nav-item <?= $currentPage === 'compose' ? 'active' : '' ?>">
                    <i class="fas fa-pen"></i>
                    <span>Nouveau message</span>
                </a>
            </div>
        </nav>

        <div class="sidebar-footer">
            <div class="user-info">
                <div class="user-avatar">
                    <?= strtoupper(substr($currentUser['full_name'], 0, 1)) ?>
                </div>
                <div class="user-details">
                    <div class="user-name"><?= escape($currentUser['full_name']) ?></div>
                    <div class="user-role">Administrateur</div>
                </div>
            </div>
            <a href="logout.php" class="logout-btn" title="Se déconnecter">
                <i class="fas fa-sign-out-alt"></i>
            </a>
        </div>
    </aside>

    <!-- MOBILE TOGGLE -->
    <button class="mobile-toggle" id="mobileToggle">
        <i class="fas fa-bars"></i>
    </button>

    <!-- MAIN CONTENT -->
    <main class="main-content">
