<?php
session_start();
include '../koneksi.php';

if(!isset($_SESSION['admin'])){
    header("Location: login.php");
    exit();
}

// Proses upload video
if(isset($_POST['submit'])){
    $judul = mysqli_real_escape_string($koneksi, $_POST['judul']);
    $deskripsi = mysqli_real_escape_string($koneksi, $_POST['deskripsi']);
    $tanggal = mysqli_real_escape_string($koneksi, $_POST['tanggal']); // Ganti tahun jadi tanggal
    $durasi = mysqli_real_escape_string($koneksi, $_POST['durasi']);
    $kualitas = mysqli_real_escape_string($koneksi, $_POST['kualitas']);
    $tahun = date('Y', strtotime($tanggal)); // Ambil tahun dari tanggal
    
    // Upload video
    $video = $_FILES['video']['name'];
    $tmp_video = $_FILES['video']['tmp_name'];
    $ukuran = $_FILES['video']['size'];
    $error = $_FILES['video']['error'];
    
    // Validasi file video
    $ekstensi_video = array('mp4', 'webm', 'ogg', 'avi', 'mov');
    $ekstensi = strtolower(pathinfo($video, PATHINFO_EXTENSION));
    
    if(in_array($ekstensi, $ekstensi_video)){
        if($ukuran <= 100000000){ // Max 100MB
            // Buat nama file unik
            $nama_baru = time() . '_' . $video;
            $folder_tujuan = "../img/video/";
            
            // Buat folder jika belum ada
            if(!file_exists($folder_tujuan)){
                mkdir($folder_tujuan, 0777, true);
            }
            
            if(move_uploaded_file($tmp_video, $folder_tujuan . $nama_baru)){
                $query = mysqli_query($koneksi, "
                    INSERT INTO arsip_video (judul, deskripsi, tanggal, video, durasi, tahun, kualitas) 
                    VALUES ('$judul', '$deskripsi', '$tanggal', '$nama_baru', '$durasi', '$tahun', '$kualitas')
                ");
                
                if($query){
                    echo "<script>
                        alert('✅ Video berhasil diupload!');
                        window.location='tambah_video.php';
                    </script>";
                } else {
                    echo "<script>
                        alert('❌ Gagal menyimpan data!');
                        window.location='tambah_video.php';
                    </script>";
                }
            } else {
                echo "<script>
                    alert('❌ Gagal upload video!');
                    window.location='tambah_video.php';
                </script>";
            }
        } else {
            echo "<script>
                alert('⚠️ Ukuran video terlalu besar (Max 100MB)!');
                window.location='tambah_video.php';
            </script>";
        }
    } else {
        echo "<script>
            alert('⚠️ Format video tidak didukung! Gunakan: mp4, webm, ogg');
            window.location='tambah_video.php';
        </script>";
    }
}

// Ambil data video untuk ditampilkan
$query_video = mysqli_query($koneksi, "SELECT * FROM arsip_video ORDER BY id DESC");
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kelola Video - Admin DPAD</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400;14..32,500;14..32,600;14..32,700;14..32,800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            background: #f0f2f5;
            min-height: 100vh;
            color: #1e293b;
            overflow-x: hidden;
        }

        /* ========== SIDEBAR MODERN PREMIUM ========== */
        .sidebar {
            width: 280px;
            height: 100vh;
            background: linear-gradient(135deg, #0a3d32 0%, #1a2e24 50%, #0a2d24 100%);
            backdrop-filter: blur(10px);
            position: fixed;
            left: 0;
            top: 0;
            display: flex;
            flex-direction: column;
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            z-index: 999;
            box-shadow: 8px 0 30px rgba(0, 0, 0, 0.3), inset -1px 0 0 rgba(255,255,255,0.05);
            overflow-y: auto;
            overflow-x: hidden;
            border-right: 1px solid rgba(255,255,255,0.08);
        }

        .sidebar::-webkit-scrollbar {
            width: 4px;
        }
        .sidebar::-webkit-scrollbar-track {
            background: rgba(255,255,255,0.05);
            border-radius: 10px;
        }
        .sidebar::-webkit-scrollbar-thumb {
            background: linear-gradient(180deg, #f5c542, #eab308);
            border-radius: 10px;
        }

        /* ========== LOGO AREA ========== */
        .logo {
            text-align: center;
            padding: 35px 20px 30px;
            border-bottom: 1px solid rgba(255,255,255,0.08);
            margin-bottom: 25px;
            position: relative;
        }

        .logo::before {
            content: '✦';
            position: absolute;
            bottom: -12px;
            left: 50%;
            transform: translateX(-50%);
            color: #f5c542;
            font-size: 14px;
            background: #0a3d32;
            padding: 0 10px;
        }

        .logo-img {
            width: 85px;
            height: 85px;
            margin: 0 auto 15px;
            background: linear-gradient(135deg, rgba(255,255,255,0.15), rgba(255,255,255,0.05));
            border-radius: 25px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
            overflow: hidden;
            cursor: pointer;
            box-shadow: 0 10px 20px rgba(0,0,0,0.2);
            border: 1px solid rgba(255,255,255,0.1);
        }

        .logo-img:hover {
            transform: scale(1.05) rotate(5deg);
            background: linear-gradient(135deg, rgba(245,197,66,0.2), rgba(245,197,66,0.05));
            box-shadow: 0 15px 30px rgba(0,0,0,0.3);
            border-color: rgba(245,197,66,0.3);
        }

        .logo-img img {
            width: 60px;
            height: 60px;
            object-fit: contain;
            transition: all 0.3s ease;
        }

        .logo-img:hover img {
            transform: scale(1.1);
        }

        .logo-text h2 {
            color: white;
            font-size: 1.4rem;
            font-weight: 800;
            letter-spacing: -0.5px;
            margin-bottom: 8px;
            background: linear-gradient(135deg, #fff, #f5c542);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            text-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }

        .logo-text p {
            color: rgba(255,255,255,0.6);
            font-size: 0.7rem;
            margin-bottom: 4px;
            letter-spacing: 0.5px;
        }

        .logo-text .subtitle {
            color: #f5c542;
            font-size: 0.68rem;
            margin-top: 5px;
            font-weight: 700;
            letter-spacing: 1px;
            text-transform: uppercase;
            background: rgba(245,197,66,0.15);
            display: inline-block;
            padding: 3px 12px;
            border-radius: 20px;
        }

        /* ========== NAVIGATION MENU ========== */
        .nav-menu {
            flex: 1;
            padding: 0 15px;
        }

        .nav-footer {
            padding: 20px 15px;
            border-top: 1px solid rgba(255,255,255,0.08);
            margin-top: auto;
            position: relative;
        }

        .nav-footer::before {
            content: '';
            position: absolute;
            top: -2px;
            left: 20px;
            right: 20px;
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(245,197,66,0.3), transparent);
        }

        .nav-item {
            display: flex;
            align-items: center;
            gap: 15px;
            padding: 12px 16px;
            margin-bottom: 10px;
            border-radius: 16px;
            text-decoration: none;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            overflow: hidden;
        }

        .nav-item::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 0;
            background: linear-gradient(90deg, rgba(245,197,66,0.15), rgba(245,197,66,0.05));
            transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            border-radius: 16px;
        }

        .nav-item:hover::before {
            width: 100%;
        }

        .nav-item:hover {
            transform: translateX(8px);
        }

        .nav-item::after {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 3px;
            background: linear-gradient(180deg, #f5c542, #eab308);
            border-radius: 3px;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .nav-item:hover::after {
            opacity: 1;
        }

        .nav-item .nav-icon {
            width: 44px;
            height: 44px;
            background: rgba(255,255,255,0.06);
            border-radius: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
            position: relative;
            z-index: 1;
            border: 1px solid rgba(255,255,255,0.05);
        }

        .nav-item .nav-icon i {
            font-size: 1.25rem;
            color: rgba(255,255,255,0.7);
            transition: all 0.3s ease;
        }

        .nav-item .nav-text {
            position: relative;
            z-index: 1;
        }

        .nav-item .nav-text span {
            display: block;
            color: rgba(255,255,255,0.85);
            font-weight: 600;
            font-size: 0.9rem;
            transition: all 0.3s ease;
            letter-spacing: -0.2px;
        }

        .nav-item .nav-text small {
            display: block;
            color: rgba(255,255,255,0.4);
            font-size: 0.65rem;
            margin-top: 3px;
            transition: all 0.3s ease;
            letter-spacing: 0.3px;
        }

        .nav-item:not(.logout):hover .nav-icon {
            background: linear-gradient(135deg, rgba(245,197,66,0.2), rgba(245,197,66,0.05));
            transform: scale(1.05) translateY(-2px);
            border-color: rgba(245,197,66,0.3);
        }

        .nav-item:not(.logout):hover .nav-icon i {
            color: #f5c542;
            text-shadow: 0 0 5px rgba(245,197,66,0.5);
            transform: scale(1.05);
        }

        .nav-item:not(.logout):hover .nav-text span {
            color: white;
            letter-spacing: -0.1px;
        }

        .nav-item:not(.logout):hover .nav-text small {
            color: rgba(245,197,66,0.7);
        }

        .nav-item.active {
            background: linear-gradient(135deg, #f5c542, #eab308);
            box-shadow: 0 6px 20px rgba(245,197,66,0.35), inset 0 1px 0 rgba(255,255,255,0.2);
        }

        .nav-item.active .nav-icon {
            background: rgba(0,0,0,0.12);
            transform: scale(1.02);
            border-color: rgba(0,0,0,0.1);
        }

        .nav-item.active .nav-icon i {
            color: #0f3b2c;
            text-shadow: none;
        }

        .nav-item.active .nav-text span {
            color: #0f3b2c;
            font-weight: 800;
        }

        .nav-item.active .nav-text small {
            color: rgba(15,59,44,0.75);
            font-weight: 500;
        }

        .nav-item.active:hover {
            transform: translateX(5px);
        }

        .nav-item.logout {
            margin-top: 8px;
            position: relative;
        }

        .nav-item.logout .nav-icon {
            background: rgba(239,68,68,0.12);
            border-color: rgba(239,68,68,0.15);
        }

        .nav-item.logout .nav-icon i {
            color: #ef4444;
        }

        .nav-item.logout:hover .nav-icon {
            background: rgba(239,68,68,0.25);
            transform: scale(1.05);
            border-color: rgba(239,68,68,0.3);
        }

        .nav-item.logout:hover .nav-icon i {
            color: #f87171;
            text-shadow: 0 0 8px rgba(239,68,68,0.5);
        }

        .nav-item.logout:hover .nav-text span {
            color: #f87171;
        }

        /* ========== MAIN CONTENT ========== */
        .main-content {
            margin-left: 280px;
            padding: 25px 35px;
            min-height: 100vh;
            background: linear-gradient(135deg, #f0f4f8 0%, #e8edf2 100%);
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
        }

        .main-content::before {
            content: '';
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background-image: radial-gradient(circle at 10% 20%, rgba(245,197,66,0.02) 0%, transparent 50%);
            pointer-events: none;
            z-index: -1;
        }

        /* ========== TOP HEADER ========== */
        .top-header {
            background: #fff;
            padding: 16px 28px;
            border-radius: 20px;
            border: 1px solid #e9edf2;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.04);
        }

        .top-header .page-title {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .top-header .page-title h1 {
            font-size: 1.3rem;
            font-weight: 700;
            color: #0a3d32;
        }

        .top-header .page-title h1 i {
            color: #1a5f4b;
            margin-right: 8px;
        }

        .top-header .page-title .badge {
            background: #f1f5f9;
            padding: 2px 12px;
            border-radius: 20px;
            font-size: 0.65rem;
            color: #64748b;
            font-weight: 600;
        }

        .top-header .header-actions {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .top-header .header-actions .user-info {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 6px 14px 6px 10px;
            border-radius: 30px;
            font-size: 0.8rem;
            color: #1e293b;
            background: #f8fafc;
            border: 1px solid #e9edf2;
        }

        .top-header .header-actions .user-info i {
            color: #1a5f4b;
            font-size: 1.1rem;
        }

        /* ========== FORM CARD ========== */
        .form-card {
            background: #fff;
            border-radius: 20px;
            box-shadow: 0 8px 30px rgba(0,0,0,0.06);
            overflow: hidden;
            border: 1px solid #e9edf2;
            margin-bottom: 30px;
        }

        .card-header-form {
            padding: 20px 28px;
            border-bottom: 1px solid #e9edf2;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .card-header-form .title-section {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .card-header-form .title-section i {
            color: #1a5f4b;
            font-size: 1.2rem;
        }

        .card-header-form .title-section h3 {
            font-size: 1rem;
            font-weight: 700;
            color: #0a3d32;
        }

        .card-header-form .status-badge {
            font-size: 0.65rem;
            background: #f0fdf4;
            color: #1a5f4b;
            padding: 4px 14px;
            border-radius: 20px;
            font-weight: 600;
        }

        .card-body {
            padding: 28px;
        }

        /* ========== FORM ========== */
        .form-group {
            margin-bottom: 22px;
        }

        .form-group label {
            display: flex;
            align-items: center;
            gap: 8px;
            font-weight: 600;
            color: #1e293b;
            margin-bottom: 6px;
            font-size: 0.85rem;
        }

        .form-group label i {
            color: #1a5f4b;
            width: 18px;
            font-size: 0.9rem;
        }

        .form-group label .required {
            color: #ef4444;
            margin-left: 2px;
        }

        .form-group .hint {
            font-size: 0.7rem;
            color: #94a3b8;
            margin-top: 4px;
        }

        .form-control {
            width: 100%;
            padding: 12px 14px;
            border: 2px solid #e5e9f0;
            border-radius: 10px;
            font-family: 'Inter', sans-serif;
            font-size: 0.9rem;
            transition: 0.3s;
            background: #fafbfc;
            color: #1e293b;
        }

        .form-control:focus {
            outline: none;
            border-color: #1a5f4b;
            background: #fff;
            box-shadow: 0 0 0 4px rgba(26,95,75,0.07);
        }

        .form-control::placeholder {
            color: #b0b8c5;
        }

        textarea.form-control {
            resize: vertical;
            min-height: 100px;
        }

        /* ========== ALERT ========== */
        .alert-custom {
            background: #f0fdf4;
            border: 1px solid #bbf7d0;
            padding: 12px 16px;
            border-radius: 10px;
            margin-bottom: 22px;
            font-size: 0.82rem;
            color: #065f46;
            display: flex;
            align-items: flex-start;
            gap: 10px;
        }

        .alert-custom i {
            font-size: 1.1rem;
            color: #1a5f4b;
            margin-top: 1px;
        }

        .alert-custom strong {
            font-weight: 700;
        }

        /* ========== FILE UPLOAD ========== */
        .file-upload-area {
            border: 2px dashed #d9dfe8;
            border-radius: 12px;
            padding: 32px 20px;
            text-align: center;
            cursor: pointer;
            transition: 0.3s;
            background: #fafbfc;
        }

        .file-upload-area:hover {
            border-color: #1a5f4b;
            background: #f0fdf6;
        }

        .file-upload-area.dragover {
            border-color: #1a5f4b;
            background: #e6f7f0;
        }

        .file-upload-area .upload-icon {
            font-size: 3.5rem;
            color: #1a5f4b;
            display: block;
            margin-bottom: 8px;
        }

        .file-upload-area .upload-title {
            font-weight: 600;
            color: #1e293b;
            font-size: 0.95rem;
        }

        .file-upload-area .upload-sub {
            color: #94a3b8;
            font-size: 0.82rem;
        }

        .file-upload-area .upload-formats {
            color: #94a3b8;
            font-size: 0.7rem;
            margin-top: 6px;
        }

        .file-upload-area .file-name-display {
            margin-top: 12px;
            display: none;
            padding: 8px 16px;
            background: #dcfce7;
            border-radius: 30px;
            font-size: 0.8rem;
            font-weight: 500;
            color: #1a5f4b;
        }

        .file-upload-area .file-name-display.active {
            display: inline-block;
        }

        input[type="file"] {
            display: none;
        }

        .row-2 {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
        }

        /* ========== FORM ACTIONS ========== */
        .form-actions {
            margin-top: 8px;
            display: flex;
            gap: 12px;
        }

        .btn-submit {
            flex: 1;
            background: linear-gradient(135deg, #0a3d32, #1a5f4b);
            color: #fff;
            border: none;
            padding: 14px 24px;
            border-radius: 12px;
            font-size: 0.95rem;
            font-weight: 700;
            cursor: pointer;
            transition: 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        .btn-submit:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 28px rgba(10,61,50,0.30);
        }

        .btn-reset {
            padding: 14px 24px;
            border-radius: 12px;
            font-size: 0.95rem;
            font-weight: 600;
            cursor: pointer;
            transition: 0.3s;
            border: 2px solid #e5e9f0;
            background: #fff;
            color: #64748b;
        }

        .btn-reset:hover {
            background: #f8fafc;
            border-color: #cbd5e1;
        }

        /* ========== TABEL VIDEO ========== */
        .table-container {
            background: #fff;
            border-radius: 20px;
            box-shadow: 0 8px 30px rgba(0,0,0,0.06);
            overflow: hidden;
            border: 1px solid #e9edf2;
        }

        .table-header {
            padding: 16px 24px;
            border-bottom: 1px solid #e9edf2;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .table-header h3 {
            font-size: 1rem;
            font-weight: 700;
            color: #0a3d32;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .table-header span {
            font-size: 0.8rem;
            color: #64748b;
        }

        .table-wrapper {
            overflow-x: auto;
            padding: 0 4px 4px 4px;
        }

        .video-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 0.85rem;
        }

        .video-table th {
            background: #f8fafc;
            padding: 12px 16px;
            text-align: left;
            font-weight: 600;
            color: #0a3d32;
            border-bottom: 2px solid #e9edf2;
        }

        .video-table td {
            padding: 12px 16px;
            border-bottom: 1px solid #e9edf2;
            color: #475569;
        }

        .video-table tr:hover {
            background: #f8fafc;
        }

        .status-badge {
            display: inline-block;
            padding: 3px 12px;
            border-radius: 20px;
            font-size: 0.7rem;
            font-weight: 600;
            background: #dcfce7;
            color: #1a5f4b;
        }

        .btn-delete {
            background: #fee2e2;
            color: #dc2626;
            border: none;
            padding: 5px 12px;
            border-radius: 30px;
            cursor: pointer;
            font-size: 0.7rem;
            transition: 0.3s;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 4px;
        }

        .btn-delete:hover {
            background: #dc2626;
            color: white;
        }

        .empty-table {
            text-align: center;
            padding: 40px;
            color: #94a3b8;
        }

        .empty-table i {
            font-size: 40px;
            display: block;
            margin-bottom: 10px;
            color: #cbd5e1;
        }

        /* ========== RESPONSIVE ========== */
        @media (max-width: 768px) {
            .sidebar {
                width: 72px;
            }
            
            .sidebar:hover {
                width: 260px;
            }
            
            .sidebar:hover .logo-text h2,
            .sidebar:hover .logo-text p,
            .sidebar:hover .logo-text .subtitle,
            .sidebar:hover .nav-text {
                display: block;
            }
            
            .logo {
                padding: 20px 0;
            }
            
            .logo-img {
                width: 48px;
                height: 48px;
            }
            
            .logo-img img {
                width: 34px;
                height: 34px;
            }
            
            .logo-text h2,
            .logo-text p,
            .logo-text .subtitle,
            .nav-text {
                display: none;
            }
            
            .sidebar:hover .logo {
                padding: 30px 15px;
            }
            
            .sidebar:hover .logo-img {
                width: 75px;
                height: 75px;
                margin: 0 auto 15px;
            }
            
            .sidebar:hover .logo-img img {
                width: 52px;
                height: 52px;
            }
            
            .nav-item {
                justify-content: center;
                padding: 12px;
                margin-bottom: 8px;
            }
            
            .sidebar:hover .nav-item {
                justify-content: flex-start;
                padding: 12px 16px;
            }
            
            .nav-item .nav-icon {
                margin: 0;
            }
            
            .nav-footer {
                padding: 15px 0;
            }
            
            .sidebar:hover .nav-footer {
                padding: 20px 15px;
            }
            
            .main-content {
                margin-left: 72px;
                padding: 15px;
            }
            
            .top-header {
                flex-direction: column;
                text-align: center;
                gap: 10px;
                padding: 15px 20px;
            }
            
            .card-body {
                padding: 20px;
            }
            
            .card-header-form {
                padding: 16px 20px;
                flex-wrap: wrap;
                gap: 8px;
            }
            
            .row-2 {
                grid-template-columns: 1fr;
                gap: 15px;
            }
            
            .file-upload-area {
                padding: 24px 12px;
            }
            
            .form-actions {
                flex-direction: column;
            }
            
            .btn-reset {
                padding: 12px 20px;
            }
            
            .table-header {
                flex-direction: column;
                gap: 8px;
                align-items: flex-start;
                padding: 12px 16px;
            }
            
            .video-table th,
            .video-table td {
                padding: 8px 10px;
                font-size: 0.75rem;
            }
        }

        @media (max-width: 480px) {
            .card-body {
                padding: 16px;
            }
            .form-control {
                padding: 10px 12px;
                font-size: 0.85rem;
            }
            .btn-submit {
                padding: 12px 18px;
                font-size: 0.85rem;
            }
        }
    </style>
</head>
<body>

<!-- ========== SIDEBAR MODERN PREMIUM ========== -->
<div class="sidebar">
    <div class="logo">
        <div class="logo-img">
            <img src="../img/logo.png" alt="Logo DPAD" onerror="this.src='https://placehold.co/60x60/1a5f4b/white?text=DPAD'">
        </div>
        <div class="logo-text">
            <h2>ADMIN</h2>
            <p>Dinas Perpustakaan </p>
            <p class="subtitle">Kab. Solok Selatan</p>
        </div>
    </div>

    <div class="nav-menu">
        <!-- DASHBOARD -->
        <a href="index.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-tachometer-alt"></i></div>
            <div class="nav-text"><span>Dashboard</span><small>Halaman Utama</small></div>
        </a>

        <!-- TAMBAH BERITA -->
        <a href="tambah_berita.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-plus-circle"></i></div>
            <div class="nav-text"><span>Tambah Berita</span><small>Publikasi berita baru</small></div>
        </a>
        <!-- ARSIP FOTO -->
        <a href="arsip_poto.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-history"></i></div>
            <div class="nav-text"><span>Arsip Foto</span><small>Kelola arsip Poto</small></div>
        </a>
        <!-- EDIT VISI MISI -->
        <a href="edit_visi_misi.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-edit"></i></div>
            <div class="nav-text"><span>Edit Visi & Misi</span><small>Kelola Visi & Misi</small></div>
        </a>
        <!-- PENGADUAN -->
        <a href="pengaduan_admin.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-comments"></i></div>
            <div class="nav-text"><span>Pengaduan</span><small>Kelola pengaduan</small></div>
        </a>
         <!-- TAMBAH VIDEO (ACTIVE) -->
        <a href="tambah_video.php" class="nav-item active">
            <div class="nav-icon"><i class="fas fa-video"></i></div>
            <div class="nav-text"><span>Tambah Video</span><small>Upload video baru</small></div>
        </a>

    </div>

    <div class="nav-footer">
        <!-- LOGOUT -->
        <a href="logout.php" class="nav-item logout">
            <div class="nav-icon"><i class="fas fa-sign-out-alt"></i></div>
            <div class="nav-text"><span>Logout</span><small>Keluar dari dashboard</small></div>
        </a>
    </div>
</div>

<!-- ========== MAIN CONTENT ========== -->
<div class="main-content">

    <!-- ========== TOP HEADER ========== -->
    <header class="top-header">
        <div class="page-title">
            <h1><i class="fas fa-video"></i> Kelola Video</h1>
            <span class="badge"><i class="far fa-clock"></i> Upload</span>
        </div>
        <div class="header-actions">
            <div class="user-info">
                <i class="fas fa-user-circle"></i>
                <span>Admin</span>
            </div>
        </div>
    </header>

    <!-- ========== FORM CARD ========== -->
    <div class="form-card">
        <div class="card-header-form">
            <div class="title-section">
                <i class="fas fa-upload"></i>
                <h3>Upload Video Baru</h3>
            </div>
            <span class="status-badge"><i class="fas fa-check-circle"></i> Form Wajib Diisi</span>
        </div>

        <div class="card-body">

            <!-- Alert -->
            <div class="alert-custom">
                <i class="fas fa-info-circle"></i>
                <div>
                    <strong>Perhatian!</strong> Field dengan tanda <span style="color: #ef4444;">*</span> wajib diisi. 
                    Pastikan data yang dimasukkan sudah benar sebelum menyimpan.
                </div>
            </div>

            <form action="" method="POST" enctype="multipart/form-data">
                
                <!-- Judul -->
                <div class="form-group">
                    <label>
                        <i class="fas fa-heading"></i> 
                        Judul Video <span class="required">*</span>
                    </label>
                    <input type="text" name="judul" class="form-control" placeholder="Masukkan judul video..." required>
                </div>

                <!-- Deskripsi -->
                <div class="form-group">
                    <label>
                        <i class="fas fa-align-left"></i> 
                        Deskripsi
                    </label>
                    <textarea name="deskripsi" class="form-control" rows="3" placeholder="Deskripsi singkat tentang video..."></textarea>
                </div>

                <!-- Row 2 kolom - TANGGAL -->
                <div class="row-2">
                    <div class="form-group">
                        <label>
                            <i class="fas fa-calendar-alt"></i> 
                            Tanggal Upload <span class="required">*</span>
                        </label>
                        <input type="date" name="tanggal" id="tanggal" class="form-control" value="<?php echo date('Y-m-d'); ?>" required>
                        <div class="hint">Tanggal otomatis diisi dengan tanggal hari ini</div>
                    </div>
                    <div class="form-group">
                        <label>
                            <i class="fas fa-clock"></i> 
                            Durasi
                        </label>
                        <input type="text" name="durasi" class="form-control" placeholder="2:35">
                        <div class="hint">Format: MM:SS (contoh: 2:35)</div>
                    </div>
                </div>

                <!-- Kualitas -->
                <div class="form-group">
                    <label>
                        <i class="fas fa-tag"></i> 
                        Kualitas
                    </label>
                    <select name="kualitas" class="form-control">
                        <option value="HD">HD</option>
                        <option value="FHD">FHD</option>
                        <option value="4K">4K</option>
                        <option value="SD">SD</option>
                    </select>
                </div>

                <!-- Upload File -->
                <div class="form-group">
                    <label>
                        <i class="fas fa-file-video"></i> 
                        File Video <span class="required">*</span>
                    </label>
                    
                    <div class="file-upload-area" id="fileUploadArea" onclick="document.getElementById('videoFile').click()">
                        <span class="upload-icon"><i class="fas fa-cloud-upload-alt"></i></span>
                        <div class="upload-title">Klik atau seret video ke sini</div>
                        <div class="upload-sub">Pilih file video untuk diupload</div>
                        <div class="upload-formats">Format: MP4, WebM, OGG, AVI (Max 100MB)</div>
                        <div class="file-name-display" id="fileNameDisplay">
                            <i class="fas fa-check-circle"></i> <span id="fileNameText"></span>
                        </div>
                    </div>
                    <input type="file" name="video" id="videoFile" accept=".mp4,.webm,.ogg,.avi,.mov" required>
                </div>

                <!-- Actions -->
                <div class="form-actions">
                    <button type="submit" name="submit" class="btn-submit">
                        <i class="fas fa-upload"></i>
                        <span>Upload Video</span>
                    </button>
                    <button type="reset" class="btn-reset" onclick="return confirm('Yakin ingin mereset form?')">
                        <i class="fas fa-undo"></i> Reset
                    </button>
                </div>

            </form>
        </div>
    </div>

    <!-- ========== TABEL DAFTAR VIDEO ========== -->
    <div class="table-container">
        <div class="table-header">
            <h3><i class="fas fa-list" style="color: #1a5f4b;"></i> Daftar Video</h3>
            <span>Total: <?php echo mysqli_num_rows($query_video); ?> video</span>
        </div>
        <div class="table-wrapper">
            <table class="video-table">
                <thead>
                    <tr>
                        <th>No</th>
                        <th>Judul</th>
                        <th>Tanggal</th>
                        <th>Durasi</th>
                        <th>Kualitas</th>
                        <th>Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(mysqli_num_rows($query_video) > 0): ?>
                        <?php $no = 1; while($video = mysqli_fetch_array($query_video)): ?>
                        <tr>
                            <td><?php echo $no++; ?></td>
                            <td><strong><?php echo htmlspecialchars($video['judul']); ?></strong></td>
                            <td><?php echo date('d/m/Y', strtotime($video['tanggal'])); ?></td>
                            <td><?php echo $video['durasi'] ?: '-'; ?></td>
                            <td><span class="status-badge"><?php echo $video['kualitas']; ?></span></td>
                            <td>
                                <a href="hapus_video.php?id=<?php echo $video['id']; ?>" onclick="return confirm('Yakin ingin menghapus video ini?')" class="btn-delete">
                                    <i class="fas fa-trash"></i> Hapus
                                </a>
                            </td>
                        </tr>
                        <?php endwhile; ?>
                    <?php else: ?>
                        <tr>
                            <td colspan="6" class="empty-table">
                                <i class="fas fa-video"></i>
                                Belum ada video yang diupload
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

</div>

<script>
    // Tampilkan nama file yang dipilih
    document.getElementById('videoFile').addEventListener('change', function(e) {
        const fileName = this.files[0]?.name || '';
        const display = document.getElementById('fileNameDisplay');
        const text = document.getElementById('fileNameText');
        
        if(fileName){
            text.textContent = fileName;
            display.classList.add('active');
        } else {
            display.classList.remove('active');
        }
    });

    // Drag & Drop
    const dropArea = document.getElementById('fileUploadArea');
    const fileInput = document.getElementById('videoFile');
    
    dropArea.addEventListener('dragover', e => {
        e.preventDefault();
        dropArea.classList.add('dragover');
    });
    
    dropArea.addEventListener('dragleave', e => {
        e.preventDefault();
        dropArea.classList.remove('dragover');
    });
    
    dropArea.addEventListener('drop', e => {
        e.preventDefault();
        dropArea.classList.remove('dragover');
        if (e.dataTransfer.files.length) {
            fileInput.files = e.dataTransfer.files;
            const event = new Event('change');
            fileInput.dispatchEvent(event);
        }
    });
</script>

</body>
</html>