<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] != 'admin') {
    header("Location: ../login.php");
    exit();
}
?>

<!DOCTYPE html>
<html lang="th">
<head>
    <meta charset="UTF-8">
    <title>Admin Dashboard</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(to right, #6a11cb, #2575fc);
            margin: 0;
            padding: 0;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .dashboard-container {
            background: #fff;
            padding: 40px;
            width: 90%;
            max-width: 800px;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0,0,0,0.3);
            text-align: center;
        }
        h1 {
            color: #333;
            margin-bottom: 40px;
        }
        .btn-group {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 20px;
        }
        .btn {
            flex: 1 1 200px;
            padding: 15px 25px;
            font-size: 18px;
            font-weight: bold;
            text-decoration: none;
            color: #fff;
            border-radius: 8px;
            transition: transform 0.2s, box-shadow 0.2s;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        .btn-add { background: #28a745; }
        .btn-add:hover { background: #218838; transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.3); }

        .btn-manage { background: #007bff; }
        .btn-manage:hover { background: #0056b3; transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.3); }

        .btn-comments { background: #17a2b8; }
        .btn-comments:hover { background: #117a8b; transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.3); }

        .btn-logout { background: #dc3545; }
        .btn-logout:hover { background: #c82333; transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.3); }

        @media(max-width:600px){
            .btn-group { flex-direction: column; }
        }
    </style>
</head>
<body>
<div class="dashboard-container">
    <h1>ยินดีต้อนรับ <?php echo htmlspecialchars($_SESSION['username']); ?> สู่ระบบ Admin</h1>
    <div class="btn-group">
        <a class="btn btn-add" href="add_article.php">เพิ่มข่าวใหม่</a>
        <a class="btn btn-manage" href="manage_articles.php">จัดการข่าว</a>
        <a class="btn btn-comments" href="manage_comments.php">จัดการความคิดเห็น</a>
        <a class="btn btn-logout" href="../admin/logout.php">ออกจากระบบ</a>
    </div>
</div>
</body>
</html>
