<?php
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;
        }

        /* ✅ Zone cliquable agrandie et fluide */
        .profile-menu {
            position: relative;
            display: inline-block;
            cursor: pointer;
            padding: 5px 10px;
            border-radius: 25px;
            transition: background 0.3s;
        }
        .profile-menu:hover {
            background: rgba(255, 255, 255, 0.2);
        }

        .profile-pic {
            width: 42px;
            height: 42px;
            border-radius: 50%;
            object-fit: cover;
            border: 2px solid white;
            vertical-align: middle;
        }

        .dropdown {
            display: none;
            position: absolute;
            right: 0;
            top: 55px;
            background: white;
            border-radius: 10px;
            box-shadow: 0 3px 12px rgba(0,0,0,0.15);
            min-width: 180px;
            overflow: hidden;
            z-index: 1000;
        }

        .dropdown a {
            color: #ff91a4;
            padding: 12px 16px;
            text-decoration: none;
            display: block;
            transition: 0.2s;
        }

        .dropdown a:hover {
            background: #ffe5ec;
        }

        /* ✅ Ouverture plus fluide (hover ou clic sur toute la zone) */
        .profile-menu:hover .dropdown,
        .profile-menu:focus-within .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" tabindex="0">
                <?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: ?>
            <a href="login.php">Connexion</a>
            <a href="register.php">Inscription</a>
        <?php endif; ?>
    </nav>
</header>
