<?php
// Démarre la session et le tampon proprement (évite les erreurs de headers)
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
if (!ob_get_level()) ob_start();
?>

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <title>Mon Mini CMS 🌸</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body { margin:0; padding:0; font-family: 'Poppins', sans-serif; }
        header {
            background: linear-gradient(90deg, #ff91a4, #ffcba4);
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 40px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }
        header h1 {
            color: white;
            font-size: 1.6em;
            margin: 0;
        }
        header h1 a {
            text-decoration: none;
            color: white;
        }
        nav a {
            color: white;
            margin-left: 20px;
            text-decoration: none;
            font-weight: 500;
            transition: 0.3s;
        }
        nav a:hover {
            color: #fff8f9;
            text-shadow: 0 0 5px white;
        }
        .profile-menu {
            position: relative;
            display: inline-block;
        }
        .profile-pic {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            object-fit: cover;
            border: 2px solid white;
            cursor: pointer;
        }
        .dropdown {
            display: none;
            position: absolute;
            right: 0;
            background: white;
            border-radius: 10px;
            box-shadow: 0 3px 10px rgba(0,0,0,0.15);
            margin-top: 8px;
            min-width: 160px;
        }
        .dropdown a {
            color: #ff91a4;
            padding: 10px 15px;
            text-decoration: none;
            display: block;
        }
        .dropdown a:hover {
            background: #ffe5ec;
        }
        .profile-menu:hover .dropdown {
            display: block;
        }
        .logo {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .logo img {
            width: 45px;
            height: 45px;
            border-radius: 50%;
            object-fit: cover;
        }
    </style>
</head>
<body>
    <header>
        <div class="logo">
            <?php if (file_exists('logo_aya.png')): ?>
                <img src="logo_aya.png" alt="Logo Aya">
            <?php endif; ?>
            <h1><a href="index.php">📰 Mon Mini CMS</a></h1>
        </div>

        <nav>
            <a href="index.php">Accueil</a>
            <?php if (isset($_SESSION['user'])): ?>
                <?php if ($_SESSION['user']['role'] === 'admin'): ?>
                    <a href="dashboard.php">Gestion</a>
                <?php endif; ?>
                <a href="add_article.php">Publier un article</a>
                <div class="profile-menu">
                    <?php if (!empty($_SESSION['user']['profile_picture'])): ?>
                        <img src="<?= htmlspecialchars($_SESSION['user']['profile_picture']) ?>" alt="Profil" class="profile-pic">
                    <?php else: ?>
                        <div class="profile-pic" style="background:#fff;display:flex;justify-content:center;align-items:center;font-size:20px;">👤</div>
                    <?php endif; ?>
                    <div class="dropdown">
                        <a href="profile.php">Mon profil</a>
                        <a href="logout.php">Déconnexion</a>
                    </div>
                </div>
            <?php else: ?>
                <!-- Boutons connexion / inscription -->
                <a href="login.php">Connexion</a>
                <a href="register.php">Inscription</a>
            <?php endif; ?>
        </nav>
    </header>
