<?php
// Simple access check for cabang_lomba_kab/index.php
session_start();

// Check if access is allowed (set by the redirect-kabupaten.php script)
if (!isset($_SESSION['allow_kabupaten_access']) || $_SESSION['allow_kabupaten_access'] !== true) {
    // Not authorized - redirect to main dashboard
    header("Location: ../dashboard_awal/index.php?error=unauthorized");
    exit;
}

// If we want to enforce a session timeout, we could add:
if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > 1)) {
    // Session expired
    session_unset();     // unset $_SESSION variables
    header("Location: ../dashboard_awal/index.php?error=session_expired");
    exit;
}
$_SESSION['last_activity'] = time(); // update last activity timestamp
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="..\assets\logoFLS3N.png" type="image/x-icon">
    <title>FLS3N 2026</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-color: #9d174d;
            --secondary-color: #f43f5e;
            --accent-color: #fbcfe8;
            --dark-color: #4b5563;
            --light-color: #f9fafb;
            --blue-color: #3b82f6;
            --green-color: #10b981;
        }
        
        body {
            font-family: 'Poppins', sans-serif;
            background-color: #f5f5f7;
            color: var(--dark-color);
            line-height: 1.6;
        }
        
        .page-container {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }
        
        .main-header {
            position: fixed;
            width: 100%;
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            background: rgba(157, 23, 77, 0.95);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: space-between;
            z-index: 10;
            top: 0;
            height: 80px;
            padding: 0 2rem;
            box-shadow: 0 4px 20px rgba(157, 23, 77, 0.3);
            transition: all 0.3s ease;
        }

        .main-header:hover {
            background: rgba(157, 23, 77, 1);
        }

        /* Logo styling */
        .logo-container {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .main-header .logo-container img {
            height: 65px;
            transition: transform 0.3s ease;
        }

        .main-header .logo-container img:hover {
            transform: scale(1.05);
        }

        .main-header .logo img {
            height: 65px;
            transition: transform 0.3s ease;
        }

        .main-header .logo img:hover {
            transform: scale(1.05);
        }

        /* Nama instansi */
        .main-header .instansi-name {
            font-size: 26px;
            font-weight: 700;
            letter-spacing: 1px;
            background: linear-gradient(90deg, #fff, #f0abfc);
            background-clip: text;
            -webkit-text-fill-color: transparent;
            text-shadow: 0 2px 10px rgba(255, 255, 255, 0.2);
        }
        /* Content Styling */
        .content-wrapper {
            flex: 1;
            margin-top: 120px;
            padding-bottom: 60px;
        }
        
        .page-title {
            font-size: 2rem;
            font-weight: 800;
            color: var(--primary-color);
            text-align: center;
            margin-bottom: 2rem;
            position: relative;
            padding-bottom: 1rem;
        }
        
        .page-title::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 100px;
            height: 4px;
            background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
            border-radius: 2px;
        }
        
        /* Category Title Styling */
        .category-container {
            margin-top: 3rem;
            position: relative;
            padding: 2rem;
            background-color: white;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
            overflow: hidden;
            transition: transform 0.3s ease;
        }
        
        .category-container:hover {
            transform: translateY(-5px);
        }
        
        .category-container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 8px;
        }
        
        .seni-pertunjukan::before {
            background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
        }
        
        .seni-penciptaan::before {
            background: linear-gradient(90deg, var(--blue-color), var(--green-color));
        }
        
        .category-title {
            display: inline-flex;
            align-items: center;
            padding: 12px 30px;
            border-radius: 50px;
            font-size: 1.25rem;
            font-weight: 700;
            margin-bottom: 1.5rem;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .category-title:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
        }
        
        .category-title i {
            margin-right: 10px;
        }
        
        .category-title.seni-pertunjukan {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            color: white;
        }
        
        .category-title.seni-penciptaan {
            background: linear-gradient(135deg, var(--blue-color) 0%, var(--green-color) 100%);
            color: white;
        }
        
        /* Card Styling */
        .competition-card {
            background: white;
            border-radius: 12px;
            padding: 20px;
            text-align: center;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
            height: 100%;
            border: 1px solid #e5e7eb;
            position: relative;
            overflow: hidden;
        }
        
        .competition-card::before {
            content: '';
            position: absolute;
            top: -2px;
            left: -2px;
            right: -2px;
            height: 6px;
            background: linear-gradient(90deg, #f9a8d4, #c084fc);
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        
        .competition-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
            border-color: #d1d5db;
        }
        
        .competition-card:hover::before {
            opacity: 1;
        }
        
        .competition-card img {
            max-width: 80px;
            height: 80px;
            margin: 0 auto 15px;
            transition: transform 0.3s ease;
            object-fit: contain;
        }
        
        .competition-card:hover img {
            transform: scale(1.1);
        }
        
        .competition-card p {
            margin-top: 15px;
            font-weight: 600;
            font-size: 0.90rem;
            color: var(--dark-color);
        }
        
        .card-btn {
            background: none;
            border: none;
            width: 100%;
            cursor: pointer;
            padding: 10px;
            transition: all 0.3s;
        }
        
        /* Footer Styling */
        footer {
            background: linear-gradient(90deg, #9d174d, #be185d);
            color: white;
            text-align: center;
            padding: 1.5rem 0;
            width: 100%;
            margin-top: auto;
            position: relative;
            box-shadow: 0 -5px 20px rgba(157, 23, 77, 0.2);
        }

        footer p {
            margin: 0;
            font-size: 0.9rem;
            letter-spacing: 0.5px;
        }
        
        /* Animation effects */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .animate-fade-in {
            animation: fadeIn 0.6s ease forwards;
        }
        
        .stagger-item {
            opacity: 0;
        }
        
        /* Responsive Adjustments */
        @media (max-width: 768px) {
            .main-header {
                padding: 0 1rem;
                height: 70px;
            }
            
            .main-header .logo-container img {
                height: 45px;
            }
            
            .main-header .instansi-name {
                font-size: 20px;
            }
            
            
            .page-title {
                font-size: 1.5rem;
            }
            
            .category-title {
                font-size: 1rem;
                padding: 10px 20px;
            }
            
            .category-container {
                padding: 1.5rem 1rem;
            }
        }
    </style>
</head>
<body>
    <div class="page-container">
        <header class="main-header">
        <div class="logo-container"> 
            <img src="../assets/tutwurii.png" alt="Logo TI Unisbank">
            <img src="../assets/unisbank.png" alt="Logo Unisbank">
            <img src="../assets/logoFLS3N.png" alt="Logo FLS3N">    
            </div>
            <div class="instansi-name">FLS3N 2026</div>
        </header>

        <div class="content-wrapper">
            <div class="container">
                <h1 class="page-title animate-fade-in">PILIH CABANG LOMBA FLS3N SMA/SMK/PKBM TAHUN 2026</h1>
                
                <div class="category-container seni-pertunjukan animate-fade-in">
                    <h2 class="category-title seni-pertunjukan"><i class="fas fa-theater-masks"></i> SENI PERTUNJUKAN</h2>
                    <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4 g-4">
                        <?php
                        require_once "../admin/config.php";
                        $conn = connectDB();
                        $result = $conn->query("SELECT * FROM cabang_lomba WHERE ID BETWEEN 1 AND 8");
                        $delay = 0;
                        while($row = $result->fetch_assoc()) {
                            echo "
                            <div class='col stagger-item' style='animation-delay: {$delay}s'>
                                <form action='proses-pilih-cabang.php' method='POST'>
                                    <input type='hidden' name='cabang_lomba' value='{$row['ID']}'>
                                    <input type='hidden' name='domisili' value='kabupaten demak'>
                                    <button type='submit' class='card-btn'>
                                        <div class='competition-card'>
                                            <img src='../assets/{$row['Bidang_Lomba']}.png' alt='{$row['Bidang_Lomba']}'>
                                            <p>{$row['Bidang_Lomba']}</p>
                                        </div>
                                    </button>
                                </form>
                            </div>";
                            $delay += 0.1;
                        }
                        ?>
                    </div>
                </div>

                <div class="category-container seni-penciptaan animate-fade-in" style="animation-delay: 0.2s">
                    <h2 class="category-title seni-penciptaan"><i class="fas fa-paint-brush"></i> SENI PENCIPTAAN</h2>
                    <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4 g-4">
                        <?php
                        $result = $conn->query("SELECT * FROM cabang_lomba WHERE ID BETWEEN 9 AND 16");
                        $delay = 0;
                        while($row = $result->fetch_assoc()) {
                            echo "
                            <div class='col stagger-item' style='animation-delay: {$delay}s'>
                                <form action='proses-pilih-cabang.php' method='POST'>
                                    <input type='hidden' name='cabang_lomba' value='{$row['ID']}'>
                                    <input type='hidden' name='domisili' value='kabupaten demak'>
                                    <button type='submit' class='card-btn'>
                                        <div class='competition-card'>
                                            <img src='../assets/{$row['Bidang_Lomba']}.png' alt='{$row['Bidang_Lomba']}'>
                                            <p>{$row['Bidang_Lomba']}</p>
                                        </div>
                                    </button>
                                </form>
                            </div>";
                            $delay += 0.1;
                        }
                        $conn->close();
                        ?>
                    </div>
                </div>
            </div>
        </div>
        
        <footer>
            <div class="container mx-auto">
                <p>&copy;<?php echo date("Y"); ?> FTII Unisbank. All rights reserved.</p>
            </div>
        </footer>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Animation for staggered item loading
        document.addEventListener('DOMContentLoaded', function() {
            const staggerItems = document.querySelectorAll('.stagger-item');
            
            staggerItems.forEach((item, index) => {
                setTimeout(() => {
                    item.style.animation = 'fadeIn 0.6s ease forwards';
                }, 100 + (index * 100));
            });
        });
    </script>
</body>
</html>