<?php
require_once '../includes/auth.php';

if (!isAdmin()) {
    redirect('../login.php');
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin - OSCE System</title>
    <link rel="stylesheet" href="../assets/css/style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<style>
    /* Layout */
.container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: linear-gradient(180deg, #1a1f2e 0%, #0f1119 100%);
    color: white;
    padding: 1rem 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 0 1rem 1rem;
    border-bottom: 1px solid #34495e;
    margin-bottom: 1rem;
}

.sidebar-menu {
    list-style: none;
}

.sidebar-menu li {
    margin-bottom: 0.5rem;
}

.sidebar-menu a {
    display: block;
    padding: 0.75rem 1rem;
    color: #bdc3c7;
    text-decoration: none;
    transition: all 0.3s;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
    background: #34495e;
    color: white;
    border-left: 4px solid #3498db;
}

.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 2rem;
}

/* Sidebar Modern */
        .sidebar {
            width: 250px;
            background: linear-gradient(180deg, #1a1f2e 0%, #0f1119 100%);
            color: white;
            position: fixed;
            height: 100vh;
            overflow-y: auto;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            z-index: 100;
            box-shadow: 4px 0 20px rgba(0, 0, 0, 0.08);
        }

        .sidebar-header {
            padding: 1.8rem 1.5rem;
            border-bottom: 1px solid rgba(255, 255, 255, 0.08);
            text-align: center;
        }

        .logo-area {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 12px;
            margin-bottom: 0.5rem;
        }

        .logo-icon {
            width: 45px;
            height: 45px;
            background: linear-gradient(135deg, #667eea, #1958e1);
            border-radius: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
        }

        .logo-text h3 {
            font-size: 1.2rem;
            font-weight: 700;
            letter-spacing: -0.3px;
            background: linear-gradient(135deg, #fff, #1958e1);
            background-clip: text;
            -webkit-background-clip: text;
            color: transparent;
        }

        .logo-text p {
            font-size: 0.7rem;
            opacity: 0.7;
            margin-top: 2px;
        }

        .user-info-sidebar {
            padding: 1.2rem;
            background: rgba(255, 255, 255, 0.05);
            margin: 1rem;
            border-radius: 16px;
            text-align: center;
        }

        .user-avatar {
            width: 55px;
            height: 55px;
            background: linear-gradient(135deg, #667eea, #1958e1);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 10px;
            font-size: 1.5rem;
        }

        .nav-menu {
            padding: 1rem 0;
        }

        .nav-item {
            padding: 0.75rem 1.5rem;
            margin: 0.25rem 0.75rem;
            border-radius: 12px;
            display: flex;
            align-items: center;
            gap: 12px;
            color: rgba(255, 255, 255, 0.7);
            transition: all 0.2s;
            cursor: pointer;
        }

        .nav-item:hover, .nav-item.active {
            background: rgba(102, 126, 234, 0.2);
            color: white;
        }

        .nav-item i {
            width: 24px;
            font-size: 1.1rem;
        }
</style>
<body>
    <div class="container">
        <div class="sidebar">
            <div class="sidebar-header">
                <div class="logo-area">
                <div class="logo-icon">
                    <i class="fas fa-tooth"></i>
                </div>
                <div class="logo-text">
                    <h3>OSCE</h3>
                    <p>Admin Center</p>
                </div>
            </div>
        </div>
        <div class="user-info-sidebar">
            <div class="user-avatar">
                <i class="fas fa-user-cog"></i>
            </div>
            <div style="font-weight: 600;"><?php echo htmlspecialchars($_SESSION['user_name'] ?? 'Administrator'); ?></div>
            <div style="font-size: 0.7rem; opacity: 0.7;">Administrator</div>
        </div>
            
            <ul class="sidebar-menu">
                <li><a href="dashboard.php" class="<?php echo basename($_SERVER['PHP_SELF']) == 'dashboard.php' ? 'active' : ''; ?>">
                    <i class="fas fa-tachometer-alt"></i> Dashboard
                </a></li>
                <li><a href="soal.php" class="<?php echo basename($_SERVER['PHP_SELF']) == 'soal.php' ? 'active' : ''; ?>">
                    <i class="fas fa-question-circle"></i> Kelola Soal
                </a></li>
                <li><a href="ujian.php" class="<?php echo basename($_SERVER['PHP_SELF']) == 'ujian.php' ? 'active' : ''; ?>">
                    <i class="fas fa-calendar-alt"></i> Kelola Ujian
                </a></li>
                <li><a href="peserta.php" class="<?php echo basename($_SERVER['PHP_SELF']) == 'peserta.php' ? 'active' : ''; ?>">
                    <i class="fas fa-users"></i> Kelola Peserta
                </a></li>
                <li><a href="penguji.php" class="<?php echo basename($_SERVER['PHP_SELF']) == 'penguji.php' ? 'active' : ''; ?>">
                    <i class="fas fa-chalkboard-user"></i> Kelola Penguji
                </a></li>
                <li><a href="nilai.php" class="<?php echo basename($_SERVER['PHP_SELF']) == 'nilai.php' ? 'active' : ''; ?>">
                    <i class="fas fa-chart-line"></i> Hasil Penilaian
                </a></li>
                <li><a href="backup_database.php" class="<?php echo basename($_SERVER['PHP_SELF']) == 'backup_database.php' ? 'active' : ''; ?>">
                    <i class="fas fa-database"></i> Backup Database
                </a></li>
                <li><a href="../logout.php">
                    <i class="fas fa-sign-out-alt"></i> Logout
                </a></li>
            </ul>
        </div>

        <div class="main-content">
            <div class="header">
                <h1>
                    <?php
                    // Dynamic page title based on current page
                    $page_titles = [
                        'dashboard.php' => 'Dashboard Admin',
                        'soal.php' => 'KELOLA SOAL',
                        'peserta.php' => 'Kelola Peserta', 
                        'ujian.php' => 'KELOLA UJIAN',
                        'nilai.php' => 'HASIL PENILAIAN',
                        'penguji.php' => 'Kelola Penguji'
                    ];
                    $current_page = basename($_SERVER['PHP_SELF']);
                    echo $page_titles[$current_page] ?? 'Admin Panel';
                    ?>
                </h1>
                <div class="user-info">
                    <span><i class="fas fa-user"></i> Halo, <?php echo $_SESSION['user_name']; ?></span>
                    <a href="../logout.php" class="btn btn-danger btn-sm">
                        <i class="fas fa-sign-out-alt"></i> Logout
                    </a>
                </div>
            </div>