<?php
session_start();
require_once '../includes/config.php';
require_once '../includes/functions.php';

// Cek apakah user sudah login dan memiliki akses admin
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] != 'admin_soal') {
    header('Location: ../login.php');
    exit;
}

// Ambil jumlah soal teori S1 dari database
$total_soal_teori_s1 = 0;
try {
    $stmt = $pdo->query("SELECT COUNT(*) as total FROM bank_soal_teori_s1");
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    $total_soal_teori_s1 = $result['total'];
} catch (PDOException $e) {
    $error_teori = 'Gagal mengambil data soal teori S1';
}

// Ambil jumlah soal teori dari database
$total_soal_teori = 0;
try {
    $stmt = $pdo->query("SELECT COUNT(*) as total FROM bank_soal_teori");
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    $total_soal_teori = $result['total'];
} catch (PDOException $e) {
    $error_teori = 'Gagal mengambil data soal teori';
}

// Ambil jumlah soal praktik dari database
$total_soal_praktik = 0;
try {
    $stmt = $pdo->query("SELECT COUNT(*) as total FROM bank_soal_praktik");
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    $total_soal_praktik = $result['total'];
} catch (PDOException $e) {
    $error_praktik = 'Gagal mengambil data soal praktik';
}

// Ambil data soal terbaru untuk ditampilkan
$soal_teori_s1_terbaru = [];
$soal_teori_terbaru = [];
$soal_praktik_terbaru = [];
try {
    // Ambil 5 soal teori S1 terbaru
    $stmt = $pdo->query("SELECT * FROM bank_soal_teori_s1 ORDER BY created_at DESC LIMIT 5");
    $soal_teori_s1_terbaru = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    // Ambil 5 soal teori terbaru
    $stmt = $pdo->query("SELECT * FROM bank_soal_teori ORDER BY created_at DESC LIMIT 5");
    $soal_teori_terbaru = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    // Ambil 5 soal praktik terbaru
    $stmt = $pdo->query("SELECT * FROM bank_soal_praktik ORDER BY created_at DESC LIMIT 5");
    $soal_praktik_terbaru = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $error_recent = 'Gagal mengambil data soal terbaru';
}

// Hitung total semua soal
$total_semua_soal = $total_soal_teori_s1 + $total_soal_teori + $total_soal_praktik;
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard - SOCA OSCE System</title>
    <link rel="stylesheet" href="../assets/css/style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        /* ===== RESET & BASE ===== */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: #d4d8dc;
            display: flex;
            min-height: 100vh;
        }

        /* ===== SIDEBAR ===== */
        .sidebar {
            width: 260px;
            background: linear-gradient(180deg, #1a2332 0%, #0f1724 100%);
            color: #fff;
            padding: 0;
            position: fixed;
            height: 100vh;
            overflow-y: auto;
            z-index: 100;
            transition: all 0.3s ease;
            box-shadow: 4px 0 20px rgba(0,0,0,0.1);
        }

        .sidebar::-webkit-scrollbar {
            width: 4px;
        }

        .sidebar::-webkit-scrollbar-track {
            background: transparent;
        }

        .sidebar::-webkit-scrollbar-thumb {
            background: rgba(255,255,255,0.2);
            border-radius: 10px;
        }

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

        .sidebar-header h2 {
            font-size: 20px;
            font-weight: 700;
            letter-spacing: 1px;
            background: linear-gradient(135deg, #60a5fa, #a78bfa);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .sidebar-header p {
            font-size: 12px;
            color: rgba(255,255,255,0.5);
            margin-top: 4px;
            letter-spacing: 2px;
            text-transform: uppercase;
        }

        .sidebar-menu {
            list-style: none;
            padding: 15px 0;
        }

        .sidebar-menu li {
            margin: 2px 12px;
        }

        .sidebar-menu li a {
            display: flex;
            align-items: center;
            gap: 14px;
            padding: 12px 16px;
            color: rgba(255,255,255,0.6);
            text-decoration: none;
            border-radius: 12px;
            transition: all 0.3s ease;
            font-size: 14px;
            font-weight: 500;
            position: relative;
        }

        .sidebar-menu li a i {
            width: 20px;
            font-size: 16px;
            text-align: center;
            transition: all 0.3s ease;
        }

        .sidebar-menu li a:hover {
            background: rgba(255,255,255,0.08);
            color: #fff;
            transform: translateX(4px);
        }

        .sidebar-menu li a.active {
            background: linear-gradient(135deg, rgba(96,165,250,0.2), rgba(167,139,250,0.2));
            color: #60a5fa;
            box-shadow: inset 3px 0 0 #60a5fa;
        }

        .sidebar-menu li a.active i {
            color: #60a5fa;
        }

        .sidebar-menu .menu-divider {
            height: 1px;
            background: rgba(255,255,255,0.06);
            margin: 12px 20px;
        }

        .sidebar-menu .menu-label {
            padding: 10px 20px 6px;
            font-size: 10px;
            text-transform: uppercase;
            letter-spacing: 1.5px;
            color: rgba(255,255,255,0.25);
            font-weight: 600;
        }

        /* ===== MAIN CONTENT ===== */
        .main-content {
            margin-left: 260px;
            flex: 1;
            padding: 30px 35px 40px;
            min-height: 100vh;
        }

        /* ===== HEADER ===== */
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            flex-wrap: wrap;
            gap: 15px;
        }

        .header-left h1 {
            font-size: 28px;
            font-weight: 700;
            color: #1a2332;
            letter-spacing: -0.5px;
        }

        .header-left .greeting {
            font-size: 14px;
            color: #6b7a8f;
            margin-top: 4px;
        }

        .header-left .greeting span {
            font-weight: 600;
            color: #1a2332;
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .header-right .user-badge {
            display: flex;
            align-items: center;
            gap: 10px;
            background: #fff;
            padding: 8px 16px 8px 12px;
            border-radius: 50px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.06);
        }

        .header-right .user-badge .avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: linear-gradient(135deg, #60a5fa, #a78bfa);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-weight: 600;
            font-size: 16px;
        }

        .header-right .user-badge .user-name {
            font-weight: 600;
            font-size: 14px;
            color: #1a2332;
        }

        .header-right .user-badge .user-role {
            font-size: 12px;
            color: #6b7a8f;
        }

        .btn-logout {
            background: #fee2e2;
            color: #dc2626;
            border: none;
            padding: 8px 16px;
            border-radius: 50px;
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-logout:hover {
            background: #fecaca;
            transform: scale(1.02);
        }

        /* ===== STATS CARDS ===== */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background: #fff;
            border-radius: 16px;
            padding: 24px 22px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.05);
            transition: all 0.3s ease;
            border: 1px solid rgba(0,0,0,0.04);
            position: relative;
            overflow: hidden;
        }

        .stat-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 8px 30px rgba(0,0,0,0.08);
        }

        .stat-card .stat-icon {
            width: 48px;
            height: 48px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            margin-bottom: 14px;
        }

        .stat-card .stat-icon.blue {
            background: #dbeafe;
            color: #2563eb;
        }

        .stat-card .stat-icon.green {
            background: #d1fae5;
            color: #059669;
        }

        .stat-card .stat-icon.purple {
            background: #ede9fe;
            color: #7c3aed;
        }

        .stat-card .stat-icon.orange {
            background: #fef3c7;
            color: #d97706;
        }

        .stat-card .stat-number {
            font-size: 32px;
            font-weight: 700;
            color: #1a2332;
            line-height: 1.2;
        }

        .stat-card .stat-label {
            font-size: 14px;
            color: #6b7a8f;
            margin-top: 4px;
            font-weight: 500;
        }

        .stat-card .stat-trend {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            font-size: 12px;
            font-weight: 600;
            margin-top: 10px;
            padding: 3px 10px;
            border-radius: 50px;
        }

        .stat-card .stat-trend.up {
            background: #d1fae5;
            color: #059669;
        }

        .stat-card .stat-trend.down {
            background: #fee2e2;
            color: #dc2626;
        }

        /* ===== QUICK ACTIONS ===== */
        .quick-actions {
            background: #fff;
            border-radius: 16px;
            padding: 24px 28px;
            margin-bottom: 30px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.05);
            border: 1px solid rgba(0,0,0,0.04);
        }

        .quick-actions .section-title {
            font-size: 16px;
            font-weight: 600;
            color: #1a2332;
            margin-bottom: 16px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .quick-actions .section-title i {
            color: #60a5fa;
        }

        .quick-actions-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 12px;
        }

        .quick-action-btn {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 12px 18px;
            background: #f8fafc;
            border-radius: 10px;
            text-decoration: none;
            color: #1a2332;
            font-weight: 500;
            font-size: 13px;
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }

        .quick-action-btn:hover {
            background: #eff6ff;
            border-color: #60a5fa;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(96,165,250,0.15);
        }

        .quick-action-btn i {
            font-size: 18px;
            color: #60a5fa;
        }

        /* ===== RECENT SECTION ===== */
        .recent-section {
            background: #fff;
            border-radius: 16px;
            padding: 24px 28px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.05);
            border: 1px solid rgba(0,0,0,0.04);
        }

        .recent-section .section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 18px;
            flex-wrap: wrap;
            gap: 10px;
        }

        .recent-section .section-title {
            font-size: 16px;
            font-weight: 600;
            color: #1a2332;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .recent-section .section-title i {
            color: #60a5fa;
        }

        .recent-section .view-all {
            font-size: 13px;
            color: #60a5fa;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .recent-section .view-all:hover {
            color: #2563eb;
            text-decoration: underline;
        }

        /* ===== TABS ===== */
        .tabs {
            display: flex;
            gap: 4px;
            background: #f1f5f9;
            padding: 4px;
            border-radius: 10px;
            margin-bottom: 18px;
        }

        .tab-btn {
            padding: 8px 18px;
            border: none;
            background: transparent;
            border-radius: 8px;
            font-size: 13px;
            font-weight: 500;
            color: #6b7a8f;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .tab-btn:hover {
            color: #1a2332;
        }

        .tab-btn.active {
            background: #fff;
            color: #1a2332;
            box-shadow: 0 2px 8px rgba(0,0,0,0.06);
        }

        .tab-content {
            display: none;
        }

        .tab-content.active {
            display: block;
        }

        /* ===== RECENT ITEMS ===== */
        .recent-items {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .recent-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 14px 18px;
            background: #f8fafc;
            border-radius: 10px;
            transition: all 0.3s ease;
            border-left: 3px solid transparent;
            flex-wrap: wrap;
            gap: 10px;
        }

        .recent-item:hover {
            background: #f1f5f9;
            border-left-color: #60a5fa;
        }

        .recent-item .item-info {
            flex: 1;
            min-width: 150px;
        }

        .recent-item .item-title {
            font-weight: 600;
            font-size: 14px;
            color: #1a2332;
        }

        .recent-item .item-meta {
            font-size: 12px;
            color: #6b7a8f;
            display: flex;
            align-items: center;
            gap: 16px;
            margin-top: 2px;
            flex-wrap: wrap;
        }

        .recent-item .item-meta span {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .recent-item .item-badge {
            font-size: 11px;
            font-weight: 600;
            padding: 4px 12px;
            border-radius: 50px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .recent-item .item-badge.teori-s1 {
            background: #dbeafe;
            color: #2563eb;
        }

        .recent-item .item-badge.teori {
            background: #ede9fe;
            color: #7c3aed;
        }

        .recent-item .item-badge.praktik {
            background: #d1fae5;
            color: #059669;
        }

        .recent-item .item-actions {
            display: flex;
            gap: 8px;
        }

        .recent-item .item-actions a {
            padding: 4px 12px;
            border-radius: 6px;
            font-size: 12px;
            text-decoration: none;
            transition: all 0.3s ease;
        }

        .recent-item .item-actions .btn-edit {
            background: #eff6ff;
            color: #2563eb;
        }

        .recent-item .item-actions .btn-edit:hover {
            background: #dbeafe;
        }

        .recent-item .item-actions .btn-delete {
            background: #fee2e2;
            color: #dc2626;
        }

        .recent-item .item-actions .btn-delete:hover {
            background: #fecaca;
        }

        .empty-state {
            text-align: center;
            padding: 40px 20px;
            color: #6b7a8f;
        }

        .empty-state i {
            font-size: 40px;
            color: #d1d5db;
            margin-bottom: 12px;
            display: block;
        }

        .empty-state p {
            font-size: 14px;
        }

        /* ===== RESPONSIVE ===== */
        @media (max-width: 992px) {
            .sidebar {
                width: 220px;
            }
            .main-content {
                margin-left: 220px;
                padding: 20px;
            }
        }

        @media (max-width: 768px) {
            .sidebar {
                width: 0;
                transform: translateX(-100%);
            }
            .sidebar.open {
                width: 280px;
                transform: translateX(0);
            }
            .main-content {
                margin-left: 0;
                padding: 15px;
            }
            .header {
                flex-direction: column;
                align-items: flex-start;
            }
            .stats-grid {
                grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
            }
            .quick-actions-grid {
                grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
            }
            .recent-item {
                flex-direction: column;
                align-items: flex-start;
            }
            .recent-item .item-actions {
                width: 100%;
                justify-content: flex-start;
            }
        }

        @media (max-width: 480px) {
            .stats-grid {
                grid-template-columns: 1fr 1fr;
            }
            .stat-card {
                padding: 16px;
            }
            .stat-card .stat-number {
                font-size: 24px;
            }
        }

        /* ===== HAMBURGER ===== */
        .hamburger {
            display: none;
            background: none;
            border: none;
            font-size: 24px;
            color: #1a2332;
            cursor: pointer;
            padding: 8px;
        }

        @media (max-width: 768px) {
            .hamburger {
                display: block;
            }
        }

        /* ===== OVERLAY ===== */
        .sidebar-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.4);
            z-index: 99;
        }

        .sidebar-overlay.active {
            display: block;
        }
    </style>
</head>
<body>
    <!-- Overlay untuk mobile -->
    <div class="sidebar-overlay" id="sidebarOverlay"></div>

    <!-- Sidebar -->
    <div class="sidebar" id="sidebar">
        <div class="sidebar-header">
            <h2>BANK SOAL</h2>
            <p>Admin Panel</p>
        </div>
        <ul class="sidebar-menu">
            <li class="menu-label"><strong>Main Menu</li></strong>
            <li><a href="dashboard.php" class="active"><i class="fas fa-th-large"></i> Dashboard</a></li>
            
            <li class="menu-divider"></li>
            <li class="menu-label"><strong>Soal Teori PDG</li></strong>
            <li><a href="bank_soal_teori_s1.php"><i class="fas fa-plus-circle"></i> Tambah Soal</a></li>
            <li><a href="list_soal_teori_s1.php"><i class="fas fa-list"></i> Daftar Soal</a></li>
            
            <li class="menu-divider"></li>
            <li class="menu-label"><strong>Soal Teori PPDG</li></strong>
            <li><a href="bank_soal_teori.php"><i class="fas fa-plus-circle"></i> Tambah Soal</a></li>
            <li><a href="list_soal_teori.php"><i class="fas fa-list"></i> Daftar Soal</a></li>
            
            <li class="menu-divider"></li>
            <li class="menu-label"><strong>Soal Praktik</li></strong>
            <li><a href="bank_soal_praktik.php"><i class="fas fa-plus-circle"></i> Tambah Soal</a></li>
            <li><a href="list_soal_praktik.php"><i class="fas fa-list"></i> Daftar Soal</a></li>
            
            <li class="menu-divider"></li>
            <li class="menu-label"><strong>Lainnya</li></strong>
            <li><a href="aspek_penilaian.php"><i class="fas fa-clipboard-check"></i> Aspek Penilaian</a></li>
            <li><a href="users.php"><i class="fas fa-users"></i> Kelola Users</a></li>
            <li><a href="../logout.php"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
        </ul>
    </div>

    <!-- Main Content -->
    <div class="main-content">
        <!-- Header -->
        <div class="header">
            <div class="header-left">
                <button class="hamburger" id="hamburgerBtn">
                    <i class="fas fa-bars"></i>
                </button>
                <h1>Dashboard</h1>
                <div class="greeting">
                    Selamat datang kembali, <span><?php echo $_SESSION['user_name'] ?? 'Admin'; ?></span> 👋
                </div>
            </div>
            <div class="header-right">
                <div class="user-badge">
                    <div class="avatar">
                        <?php echo strtoupper(substr($_SESSION['user_name'] ?? 'A', 0, 1)); ?>
                    </div>
                    <div>
                        <div class="user-name"><?php echo $_SESSION['user_name'] ?? 'Admin'; ?></div>
                        <div class="user-role">Admin Soal</div>
                    </div>
                </div>
                <a href="../logout.php" class="btn-logout">
                    <i class="fas fa-sign-out-alt"></i> Logout
                </a>
            </div>
        </div>

        <!-- Stats Cards -->
        <div class="stats-grid">
            <div class="stat-card">
                <div class="stat-icon blue">
                    <i class="fas fa-file-alt"></i>
                </div>
                <div class="stat-number"><?php echo $total_soal_teori_s1; ?></div>
                <div class="stat-label">Soal Teori S1</div>
                <div class="stat-trend up">
                    <i class="fas fa-arrow-up"></i> Aktif
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-icon purple">
                    <i class="fas fa-book"></i>
                </div>
                <div class="stat-number"><?php echo $total_soal_teori; ?></div>
                <div class="stat-label">Soal Teori</div>
                <div class="stat-trend up">
                    <i class="fas fa-arrow-up"></i> Aktif
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-icon green">
                    <i class="fas fa-stethoscope"></i>
                </div>
                <div class="stat-number"><?php echo $total_soal_praktik; ?></div>
                <div class="stat-label">Soal Praktik</div>
                <div class="stat-trend up">
                    <i class="fas fa-arrow-up"></i> Aktif
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-icon orange">
                    <i class="fas fa-database"></i>
                </div>
                <div class="stat-number"><?php echo $total_semua_soal; ?></div>
                <div class="stat-label">Total Semua Soal</div>
                <div class="stat-trend up">
                    <i class="fas fa-check-circle"></i> Tersimpan
                </div>
            </div>
        </div>

        <!-- Quick Actions -->
        <div class="quick-actions">
            <div class="section-title">
                <i class="fas fa-bolt"></i> Quick Actions
            </div>
            <div class="quick-actions-grid">
                <a href="bank_soal_teori_s1.php" class="quick-action-btn">
                    <i class="fas fa-plus-circle"></i> Soal Teori S1
                </a>
                <a href="bank_soal_teori.php" class="quick-action-btn">
                    <i class="fas fa-plus-circle"></i> Soal Teori
                </a>
                <a href="bank_soal_praktik.php" class="quick-action-btn">
                    <i class="fas fa-plus-circle"></i> Soal Praktik
                </a>
                <a href="aspek_penilaian.php" class="quick-action-btn">
                    <i class="fas fa-clipboard-check"></i> Aspek Penilaian
                </a>
                <a href="users.php" class="quick-action-btn">
                    <i class="fas fa-users"></i> Kelola Users
                </a>
            </div>
        </div>

        <!-- Recent Section -->
        <div class="recent-section">
            <div class="section-header">
                <div class="section-title">
                    <i class="fas fa-clock"></i> Soal Terbaru
                </div>
                <a href="list_soal_teori_s1.php" class="view-all">Lihat Semua →</a>
            </div>

            <!-- Tabs -->
            <div class="tabs">
                <button class="tab-btn active" data-tab="tab-s1">Teori S1</button>
                <button class="tab-btn" data-tab="tab-teori">Teori</button>
                <button class="tab-btn" data-tab="tab-praktik">Praktik</button>
            </div>

            <!-- Tab: Teori S1 -->
            <div class="tab-content active" id="tab-s1">
                <?php if (empty($soal_teori_s1_terbaru)): ?>
                    <div class="empty-state">
                        <i class="fas fa-inbox"></i>
                        <p>Belum ada soal teori S1</p>
                    </div>
                <?php else: ?>
                    <div class="recent-items">
                        <?php foreach ($soal_teori_s1_terbaru as $soal): ?>
                            <div class="recent-item">
                                <div class="item-info">
                                    <div class="item-title"><?php echo htmlspecialchars($soal['nomor_registrasi']); ?></div>
                                    <div class="item-meta">
                                        <span><i class="fas fa-tag"></i> <?php echo htmlspecialchars($soal['blok'] ?? '-'); ?></span>
                                        <span><i class="fas fa-layer-group"></i> <?php echo htmlspecialchars($soal['cpmk'] ?? '-'); ?></span>
                                        <span><i class="far fa-calendar-alt"></i> <?php echo date('d/m/Y', strtotime($soal['created_at'])); ?></span>
                                    </div>
                                </div>
                                <span class="item-badge teori-s1">Teori S1</span>
                                <div class="item-actions">
                                    <a href="edit_soal_teori_s1.php?id=<?php echo $soal['id']; ?>" class="btn-edit">Edit</a>
                                    <a href="hapus_soal_teori_s1.php?id=<?php echo $soal['id']; ?>" class="btn-delete" onclick="return confirm('Yakin hapus soal ini?')">Hapus</a>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>
            </div>

            <!-- Tab: Teori -->
            <div class="tab-content" id="tab-teori">
                <?php if (empty($soal_teori_terbaru)): ?>
                    <div class="empty-state">
                        <i class="fas fa-inbox"></i>
                        <p>Belum ada soal teori</p>
                    </div>
                <?php else: ?>
                    <div class="recent-items">
                        <?php foreach ($soal_teori_terbaru as $soal): ?>
                            <div class="recent-item">
                                <div class="item-info">
                                    <div class="item-title"><?php echo htmlspecialchars($soal['nomor_registrasi']); ?></div>
                                    <div class="item-meta">
                                        <span><i class="fas fa-building"></i> <?php echo htmlspecialchars($soal['department'] ?? '-'); ?></span>
                                        <span><i class="far fa-calendar-alt"></i> <?php echo date('d/m/Y', strtotime($soal['created_at'])); ?></span>
                                    </div>
                                </div>
                                <span class="item-badge teori">Teori</span>
                                <div class="item-actions">
                                    <a href="edit_soal_teori.php?id=<?php echo $soal['id']; ?>" class="btn-edit">Edit</a>
                                    <a href="hapus_soal_teori.php?id=<?php echo $soal['id']; ?>" class="btn-delete" onclick="return confirm('Yakin hapus soal ini?')">Hapus</a>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>
            </div>

            <!-- Tab: Praktik -->
            <div class="tab-content" id="tab-praktik">
                <?php if (empty($soal_praktik_terbaru)): ?>
                    <div class="empty-state">
                        <i class="fas fa-inbox"></i>
                        <p>Belum ada soal praktik</p>
                    </div>
                <?php else: ?>
                    <div class="recent-items">
                        <?php foreach ($soal_praktik_terbaru as $soal): ?>
                            <div class="recent-item">
                                <div class="item-info">
                                    <div class="item-title"><?php echo htmlspecialchars($soal['nomor_registrasi']); ?></div>
                                    <div class="item-meta">
                                        <span><i class="fas fa-building"></i> <?php echo htmlspecialchars($soal['department'] ?? '-'); ?></span>
                                        <span><i class="far fa-calendar-alt"></i> <?php echo date('d/m/Y', strtotime($soal['created_at'])); ?></span>
                                    </div>
                                </div>
                                <span class="item-badge praktik">Praktik</span>
                                <div class="item-actions">
                                    <a href="edit_soal_praktik.php?id=<?php echo $soal['id']; ?>" class="btn-edit">Edit</a>
                                    <a href="hapus_soal_praktik.php?id=<?php echo $soal['id']; ?>" class="btn-delete" onclick="return confirm('Yakin hapus soal ini?')">Hapus</a>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <script>
        // ===== SIDEBAR TOGGLE =====
        const hamburger = document.getElementById('hamburgerBtn');
        const sidebar = document.getElementById('sidebar');
        const overlay = document.getElementById('sidebarOverlay');

        function toggleSidebar() {
            sidebar.classList.toggle('open');
            overlay.classList.toggle('active');
        }

        hamburger.addEventListener('click', toggleSidebar);
        overlay.addEventListener('click', toggleSidebar);

        // ===== TABS =====
        const tabBtns = document.querySelectorAll('.tab-btn');
        const tabContents = {
            'tab-s1': document.getElementById('tab-s1'),
            'tab-teori': document.getElementById('tab-teori'),
            'tab-praktik': document.getElementById('tab-praktik'),
        };

        tabBtns.forEach(btn => {
            btn.addEventListener('click', function() {
                // Remove active from all tabs
                tabBtns.forEach(b => b.classList.remove('active'));
                Object.values(tabContents).forEach(c => c.classList.remove('active'));

                // Activate current tab
                this.classList.add('active');
                const target = this.dataset.tab;
                if (tabContents[target]) {
                    tabContents[target].classList.add('active');
                }
            });
        });

        // ===== CLOSE SIDEBAR ON RESIZE =====
        window.addEventListener('resize', function() {
            if (window.innerWidth > 768) {
                sidebar.classList.remove('open');
                overlay.classList.remove('active');
            }
        });
    </script>
</body>
</html>