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

// ========== HIT COUNTER PENGUNJUNG ==========
$ip = $_SERVER['REMOTE_ADDR'];
$tanggal = date('Y-m-d');

mysqli_query($koneksi, "
    CREATE TABLE IF NOT EXISTS visitor_counter (
        id INT AUTO_INCREMENT PRIMARY KEY,
        ip_address VARCHAR(100),
        tanggal DATE,
        user_agent VARCHAR(255)
    )
");

$cek = mysqli_query($koneksi, "
    SELECT * FROM visitor_counter 
    WHERE ip_address = '$ip' AND tanggal = '$tanggal'
");

if(mysqli_num_rows($cek) == 0){
    mysqli_query($koneksi, "
        INSERT INTO visitor_counter (ip_address, tanggal) 
        VALUES ('$ip', '$tanggal')
    ");
}

$totalVisitor = mysqli_fetch_assoc(mysqli_query($koneksi, "
    SELECT COUNT(DISTINCT ip_address) as total FROM visitor_counter
"))['total'];

$query = mysqli_query($koneksi, "SELECT * FROM arsip_foto 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>Arsip Foto Sejarah | DPAD Solok Selatan</title>
    
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            background: #f0f7f2;
            color: #1e293b;
            padding-top: 80px;
        }

        /* ========== HEADER ========== */
        .header {
            background: linear-gradient(135deg, #0a3d32 0%, #1a5f4b 50%, #0f3b2c 100%);
            padding: 0;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 9999;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
        }

        .header.scrolled {
            padding: 5px 0;
            box-shadow: 0 4px 25px rgba(0,0,0,0.15);
        }

        .header-content {
            max-width: 1400px;
            margin: 0 auto;
            padding: 12px 40px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 15px;
        }

        .logo-area {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .logo-img {
            width: 60px;
            height: 60px;
            border-radius: 14px;
            background: rgba(255,255,255,0.12);
            padding: 8px;
            border: 2px solid rgba(255,255,255,0.12);
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .logo-img:hover {
            border-color: #f5c542;
            transform: scale(1.05);
        }

        .logo-img img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }

        .logo-img i {
            font-size: 28px;
            color: #f5c542;
        }

        .logo-text h1 {
            font-size: 1.3rem;
            font-weight: 800;
            color: white;
            font-family: 'Playfair Display', serif;
            line-height: 1.2;
        }

        .logo-text p {
            color: rgba(255,255,255,0.7);
            font-size: 0.7rem;
        }

        .header-menu {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-wrap: wrap;
        }

        .menu-item {
            position: relative;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

        .menu-icon {
            width: 44px;
            height: 44px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(255,255,255,0.08);
            color: white;
            font-size: 16px;
            border: 1px solid rgba(255,255,255,0.06);
            transition: all 0.3s ease;
            text-decoration: none;
            cursor: pointer;
        }

        .menu-icon:hover {
            background: white;
            color: #1a5f4b;
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(0,0,0,0.15);
        }

        .menu-item .tooltip {
            position: absolute;
            bottom: -38px;
            left: 50%;
            transform: translateX(-50%) scale(0.9);
            background: rgba(0,0,0,0.85);
            backdrop-filter: blur(10px);
            color: white;
            padding: 4px 14px;
            border-radius: 20px;
            font-size: 0.6rem;
            font-weight: 600;
            white-space: nowrap;
            opacity: 0;
            visibility: hidden;
            transition: all 0.25s ease;
            pointer-events: none;
            border: 1px solid rgba(255,255,255,0.05);
        }

        .menu-item:hover .tooltip {
            opacity: 1;
            visibility: visible;
            transform: translateX(-50%) scale(1);
            bottom: -42px;
        }

        /* ========== HERO ========== */
        .hero-page {
            background: linear-gradient(135deg, #0f3b2c, #1a5f4b);
            margin: 20px 40px 30px;
            border-radius: 30px;
            padding: 55px 50px;
            color: white;
            position: relative;
            overflow: hidden;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }

        .hero-page::before {
            content: "📸";
            position: absolute;
            right: -20px;
            top: -20px;
            font-size: 200px;
            opacity: 0.06;
        }

        .hero-page::after {
            content: "🏛️";
            position: absolute;
            left: -20px;
            bottom: -20px;
            font-size: 200px;
            opacity: 0.06;
        }

        .hero-page .hero-badge {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            background: rgba(245,197,66,0.2);
            padding: 6px 18px;
            border-radius: 50px;
            font-size: 0.75rem;
            font-weight: 600;
            color: #f5c542;
            margin-bottom: 15px;
        }

        .hero-page h1 {
            font-size: 2.5rem;
            font-weight: 800;
            font-family: 'Playfair Display', serif;
            position: relative;
            z-index: 2;
            margin-bottom: 8px;
        }

        .hero-page h1 span {
            color: #f5c542;
        }

        .hero-page p {
            font-size: 1.05rem;
            opacity: 0.9;
            max-width: 600px;
            position: relative;
            z-index: 2;
            line-height: 1.7;
        }

        /* ========== BREADCRUMB ========== */
        .breadcrumb-wrap {
            max-width: 1400px;
            margin: -8px auto 0;
            padding: 0 40px 25px;
        }

        .breadcrumb {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 0.8rem;
            color: #94a3b8;
            flex-wrap: wrap;
        }

        .breadcrumb a {
            color: #1a5f4b;
            text-decoration: none;
            font-weight: 500;
            transition: 0.3s;
        }

        .breadcrumb a:hover {
            color: #f5c542;
        }

        .breadcrumb .sep {
            color: #cbd5e1;
        }

        .breadcrumb .active {
            color: #1a5f4b;
            font-weight: 600;
        }

        /* ========== STATISTIK ========== */
        .stats-wrap {
            max-width: 1400px;
            margin: -15px auto 0;
            padding: 0 40px 30px;
            position: relative;
            z-index: 10;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 20px;
        }

        .stat-card {
            background: white;
            border-radius: 20px;
            padding: 25px 20px;
            text-align: center;
            border: 1px solid #e8edf2;
            box-shadow: 0 4px 15px rgba(0,0,0,0.04);
            transition: all 0.3s ease;
        }

        .stat-card:hover {
            transform: translateY(-5px);
            border-color: #1a5f4b;
            box-shadow: 0 12px 30px rgba(0,0,0,0.08);
        }

        .stat-card .stat-icon {
            width: 55px;
            height: 55px;
            background: linear-gradient(135deg, #eaf5ed, #d4e8db);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 10px;
            transition: all 0.3s ease;
        }

        .stat-card:hover .stat-icon {
            background: linear-gradient(135deg, #1a5f4b, #0f3b2c);
            transform: scale(1.05);
        }

        .stat-card:hover .stat-icon i {
            color: white;
        }

        .stat-card .stat-icon i {
            font-size: 24px;
            color: #1a5f4b;
            transition: all 0.3s ease;
        }

        .stat-card .stat-number {
            font-size: 1.8rem;
            font-weight: 800;
            color: #0f3b2c;
        }

        .stat-card .stat-label {
            font-size: 0.85rem;
            color: #64748b;
            margin-top: 2px;
        }

        /* ========== GALLERY ========== */
        .gallery-section {
            max-width: 1400px;
            margin: 0 auto;
            padding: 0 40px 50px;
        }

        .section-title {
            text-align: center;
            margin-bottom: 40px;
        }

        .section-title h2 {
            font-size: 1.8rem;
            font-weight: 700;
            color: #0f3b2c;
            position: relative;
            display: inline-block;
            padding-bottom: 12px;
        }

        .section-title h2::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 60px;
            height: 3px;
            background: #f5c542;
            border-radius: 3px;
        }

        .section-title p {
            color: #64748b;
            font-size: 0.95rem;
            margin-top: 10px;
        }

        /* Gallery Grid */
        .gallery-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 25px;
        }

        .gallery-card {
            background: white;
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 4px 15px rgba(0,0,0,0.06);
            border: 1px solid #e8edf2;
            transition: all 0.4s ease;
            cursor: pointer;
        }

        .gallery-card:hover {
            transform: translateY(-10px);
            border-color: #1a5f4b;
            box-shadow: 0 20px 40px rgba(0,0,0,0.12);
        }

        .card-image {
            position: relative;
            height: 250px;
            overflow: hidden;
            background: #f1f5f9;
        }

        .card-image img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.5s ease;
        }

        .gallery-card:hover .card-image img {
            transform: scale(1.08);
        }

        .card-image .image-overlay {
            position: absolute;
            inset: 0;
            background: rgba(26, 95, 75, 0.8);
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .gallery-card:hover .image-overlay {
            opacity: 1;
        }

        .card-image .image-overlay i {
            font-size: 40px;
            color: #f5c542;
        }

        .card-image .badge-photo {
            position: absolute;
            top: 15px;
            right: 15px;
            background: rgba(0,0,0,0.7);
            backdrop-filter: blur(5px);
            padding: 5px 14px;
            border-radius: 30px;
            font-size: 0.7rem;
            color: white;
            display: flex;
            align-items: center;
            gap: 6px;
            z-index: 5;
        }

        .card-image .badge-photo i {
            color: #f5c542;
        }

        .card-content {
            padding: 22px;
        }

        .card-content h3 {
            font-size: 1.1rem;
            font-weight: 700;
            color: #0f3b2c;
            margin-bottom: 8px;
            line-height: 1.3;
        }

        .card-content .card-year {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: #eaf5ed;
            padding: 4px 14px;
            border-radius: 30px;
            font-size: 0.7rem;
            font-weight: 600;
            color: #1a5f4b;
            margin-bottom: 10px;
        }

        .card-content p {
            color: #64748b;
            font-size: 0.85rem;
            line-height: 1.6;
        }

        /* ========== EMPTY STATE ========== */
        .empty-state {
            text-align: center;
            padding: 80px 40px;
            background: white;
            border-radius: 24px;
            grid-column: 1/-1;
            border: 1px solid #e8edf2;
        }

        .empty-state i {
            font-size: 70px;
            color: #cbd5e1;
            margin-bottom: 20px;
        }

        .empty-state h3 {
            color: #1e293b;
            margin-bottom: 10px;
            font-size: 1.2rem;
        }

        .empty-state p {
            color: #64748b;
        }

        /* ========== MODAL ========== */
        .modal-gallery {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.95);
            z-index: 99999;
            justify-content: center;
            align-items: center;
            backdrop-filter: blur(10px);
        }

        .modal-gallery.active {
            display: flex;
            animation: fadeInModal 0.3s ease;
        }

        @keyframes fadeInModal {
            from { opacity: 0; transform: scale(0.95); }
            to { opacity: 1; transform: scale(1); }
        }

        .modal-content {
            max-width: 90%;
            max-height: 90%;
            position: relative;
        }

        .modal-content img {
            max-width: 100%;
            max-height: 80vh;
            object-fit: contain;
            border-radius: 12px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.5);
        }

        .modal-close {
            position: absolute;
            top: -50px;
            right: -10px;
            color: white;
            font-size: 35px;
            cursor: pointer;
            background: none;
            border: none;
            width: 45px;
            height: 45px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
            border-radius: 50%;
        }

        .modal-close:hover {
            color: #f5c542;
            transform: rotate(90deg);
            background: rgba(255,255,255,0.05);
        }

        .modal-nav {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 100%;
            display: flex;
            justify-content: space-between;
            padding: 0 20px;
            pointer-events: none;
        }

        .modal-nav button {
            width: 50px;
            height: 50px;
            background: rgba(26,95,75,0.8);
            border: none;
            color: white;
            font-size: 1.2rem;
            border-radius: 50%;
            cursor: pointer;
            pointer-events: auto;
            transition: all 0.3s ease;
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255,255,255,0.05);
        }

        .modal-nav button:hover {
            background: #f5c542;
            color: #0f3b2c;
            transform: scale(1.1);
        }

        .modal-indicator {
            position: absolute;
            top: -45px;
            left: 0;
            background: rgba(26,95,75,0.8);
            padding: 6px 18px;
            border-radius: 30px;
            font-size: 0.75rem;
            color: white;
            backdrop-filter: blur(5px);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .modal-indicator i {
            color: #f5c542;
        }

        .modal-caption {
            position: absolute;
            bottom: -60px;
            left: 0;
            right: 0;
            text-align: center;
            color: white;
            font-size: 0.85rem;
            background: rgba(0,0,0,0.7);
            padding: 14px 24px;
            border-radius: 40px;
            backdrop-filter: blur(8px);
            border: 1px solid rgba(255,255,255,0.05);
        }

        .modal-caption strong {
            color: #f5c542;
        }

        /* ========== FOOTER ========== */
        .footer-premium {
            background: linear-gradient(135deg, #0a3d32, #0f3b2c);
            color: white;
            padding-top: 50px;
            margin-top: 30px;
            position: relative;
            overflow: hidden;
        }

        .footer-premium::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: linear-gradient(90deg, #f5c542, #eab308, #f5c542);
        }

        .footer-container {
            max-width: 1280px;
            margin: 0 auto;
            padding: 0 20px;
        }

        .footer-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 35px;
            margin-bottom: 40px;
        }

        .footer-col h3 {
            font-size: 1.1rem;
            font-weight: 700;
            margin-bottom: 20px;
            padding-bottom: 10px;
            position: relative;
            color: #f5c542;
        }

        .footer-col h3::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 40px;
            height: 2px;
            background: #f5c542;
        }

        .footer-logo {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 15px;
        }

        .footer-logo .logo-icon {
            width: 50px;
            height: 50px;
            background: rgba(255,255,255,0.08);
            border-radius: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .footer-logo .logo-icon i {
            font-size: 28px;
            color: #f5c542;
        }

        .footer-logo .logo-text h3 {
            font-size: 1.1rem;
            font-weight: 700;
            color: white;
            margin-bottom: 2px;
        }

        .footer-logo .logo-text p {
            font-size: 0.7rem;
            opacity: 0.7;
        }

        .footer-description {
            color: #cbd5e1;
            line-height: 1.6;
            font-size: 0.85rem;
            margin-bottom: 15px;
        }

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

        .footer-menu li {
            margin-bottom: 10px;
        }

        .footer-menu li a {
            color: #cbd5e1;
            text-decoration: none;
            transition: all 0.3s;
            display: inline-flex;
            align-items: center;
            gap: 10px;
            font-size: 0.85rem;
        }

        .footer-menu li a i {
            color: #f5c542;
            width: 20px;
        }

        .footer-menu li a:hover {
            color: #f5c542;
            transform: translateX(8px);
        }

        .social-links {
            display: flex;
            gap: 10px;
            margin-top: 15px;
        }

        .social-icon {
            width: 38px;
            height: 38px;
            border-radius: 50%;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: white;
            transition: all 0.3s;
            text-decoration: none;
            font-size: 0.9rem;
        }

        .social-fb { background: #1877f2; }
        .social-ig { background: #e4405f; }
        .social-yt { background: #ff0000; }
        .social-tt { background: #010101; }

        .social-icon:hover {
            transform: translateY(-4px);
            filter: brightness(1.1);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        .footer-contact-item {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 12px;
            color: #cbd5e1;
            font-size: 0.85rem;
        }

        .footer-contact-item i {
            width: 35px;
            height: 35px;
            background: rgba(245,197,66,0.1);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #f5c542;
        }

        .footer-bottom {
            border-top: 1px solid rgba(255,255,255,0.06);
            padding-top: 25px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 15px;
        }

        .footer-bottom p {
            color: rgba(255,255,255,0.5);
            font-size: 0.75rem;
        }

        .footer-bottom a {
            color: #f5c542;
            text-decoration: none;
        }

        .visitor-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: rgba(255,255,255,0.06);
            padding: 5px 14px;
            border-radius: 30px;
            font-size: 0.7rem;
            color: #f5c542;
        }

        .dev-credit {
            text-align: center;
            padding-top: 20px;
            margin-top: 20px;
            border-top: 1px solid rgba(255,255,255,0.04);
            color: #94a3b8;
            font-size: 0.75rem;
        }

        .dev-credit a {
            color: #f5c542;
            text-decoration: none;
            font-weight: 500;
        }

        /* ========== RESPONSIVE ========== */
        @media (max-width: 1024px) {
            .gallery-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 992px) {
            .footer-grid {
                grid-template-columns: repeat(2, 1fr);
            }
            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 768px) {
            body {
                padding-top: 70px;
            }

            .header-content {
                padding: 8px 15px;
            }
            .logo-img {
                width: 40px;
                height: 40px;
                padding: 6px;
            }
            .logo-text h1 {
                font-size: 0.85rem;
            }
            .logo-text p {
                font-size: 0.6rem;
            }
            .menu-icon {
                width: 36px;
                height: 36px;
                font-size: 13px;
            }
            .header-menu {
                gap: 4px;
            }
            .menu-item .tooltip {
                display: none;
            }

            .hero-page {
                margin: 15px;
                padding: 30px 20px;
                border-radius: 20px;
            }
            .hero-page h1 {
                font-size: 1.8rem;
            }
            .hero-page p {
                font-size: 0.95rem;
            }
            .hero-page .hero-badge {
                font-size: 0.65rem;
                padding: 4px 14px;
            }

            .breadcrumb-wrap {
                padding: 0 15px 18px;
            }
            .breadcrumb {
                font-size: 0.7rem;
            }

            .stats-wrap {
                padding: 0 15px 20px;
            }
            .stats-grid {
                grid-template-columns: 1fr 1fr;
                gap: 12px;
            }
            .stat-card {
                padding: 18px 15px;
            }
            .stat-card .stat-number {
                font-size: 1.4rem;
            }

            .gallery-section {
                padding: 0 15px 30px;
            }
            .gallery-grid {
                grid-template-columns: 1fr;
                gap: 18px;
            }
            .card-image {
                height: 220px;
            }
            .section-title h2 {
                font-size: 1.5rem;
            }

            .modal-nav button {
                width: 40px;
                height: 40px;
                font-size: 1rem;
            }
            .modal-caption {
                font-size: 0.7rem;
                bottom: -50px;
                padding: 10px 16px;
            }
            .modal-indicator {
                font-size: 0.65rem;
                top: -40px;
                padding: 4px 14px;
            }
            .modal-close {
                top: -45px;
                font-size: 28px;
            }

            .footer-grid {
                grid-template-columns: 1fr;
                gap: 25px;
                text-align: center;
            }
            .footer-col h3::after {
                left: 50%;
                transform: translateX(-50%);
            }
            .footer-logo {
                justify-content: center;
            }
            .footer-menu li a {
                justify-content: center;
            }
            .social-links {
                justify-content: center;
            }
            .footer-contact-item {
                justify-content: center;
            }
            .footer-bottom {
                flex-direction: column;
                text-align: center;
            }
        }

        @media (max-width: 480px) {
            .hero-page h1 {
                font-size: 1.4rem;
            }
            .hero-page p {
                font-size: 0.85rem;
            }
            .stats-grid {
                grid-template-columns: 1fr 1fr;
                gap: 8px;
            }
            .stat-card {
                padding: 14px 10px;
                border-radius: 14px;
            }
            .stat-card .stat-number {
                font-size: 1.2rem;
            }
            .stat-card .stat-label {
                font-size: 0.7rem;
            }
            .stat-card .stat-icon {
                width: 45px;
                height: 45px;
            }
            .stat-card .stat-icon i {
                font-size: 18px;
            }
            .card-image {
                height: 180px;
            }
            .card-content {
                padding: 16px;
            }
            .card-content h3 {
                font-size: 1rem;
            }
        }
    </style>
</head>
<body>

<!-- ========== HEADER ========== -->
<div class="header" id="mainHeader">
    <div class="header-content">
        <div class="logo-area">
            <div class="logo-img">
                <?php if(file_exists("img/logo.png")): ?>
                    <img src="img/logo.png" alt="Logo DPAD">
                <?php else: ?>
                    <i class="fas fa-archive"></i>
                <?php endif; ?>
            </div>
            <div class="logo-text">
                <h1>Dinas Arsip Solok Selatan</h1>
                <p>Dinas Arsip Daerah</p>
            </div>
        </div>

        <div class="header-menu">
            <div class="menu-item">
                <a href="dashboard.php" class="menu-icon">
                    <i class="fas fa-home"></i>
                </a>
                <span class="tooltip">Dashboard</span>
            </div>
            <div class="menu-item">
                <a href="layanan_arsip.php" class="menu-icon">
                    <i class="fas fa-concierge-bell"></i>
                </a>
                <span class="tooltip">Layanan</span>
            </div>
            <div class="menu-item">
                <a href="berita.php" class="menu-icon">
                    <i class="fas fa-newspaper"></i>
                </a>
                <span class="tooltip">Berita</span>
            </div>
            <div class="menu-item">
                <a href="sejarah_video.php" class="menu-icon">
                    <i class="fas fa-video"></i>
                </a>
                <span class="tooltip">Video</span>
            </div>
        </div>
    </div>
</div>

<!-- ========== HERO ========== -->
<div class="hero-page" data-aos="fade-up">
    <div class="hero-badge">
        <i class="fas fa-star"></i> Galeri Arsip Solok Selatan
    </div>
    <h1>Arsip Foto <span>Sejarah</span></h1>
    <p>Dokumentasi perjalanan dan kegiatan Dinas Perpustakaan dan Arsip Daerah Kabupaten Solok Selatan</p>
</div>

<!-- ========== BREADCRUMB ========== -->
<div class="breadcrumb-wrap">
    <div class="breadcrumb">
        <a href="index.php"><i class="fas fa-home"></i></a>
        <span class="sep">/</span>
        <a href="layanan.php">Layanan</a>
        <span class="sep">/</span>
        <span class="active">Arsip Foto</span>
    </div>
</div>

<!-- ========== STATISTIK ========== -->
<div class="stats-wrap" data-aos="fade-up" data-aos-delay="100">
    <div class="stats-grid">
        <div class="stat-card">
            <div class="stat-icon"><i class="fas fa-folder-open"></i></div>
            <div class="stat-number"><?php echo mysqli_num_rows($query); ?></div>
            <div class="stat-label">Album Arsip</div>
        </div>
        <div class="stat-card">
            <div class="stat-icon"><i class="fas fa-camera"></i></div>
            <div class="stat-number"><?php 
                $totalFoto = 0;
                $tempQuery = mysqli_query($koneksi, "SELECT foto FROM arsip_foto");
                while($row = mysqli_fetch_array($tempQuery)){
                    $fotoArray = explode(',', $row['foto']);
                    $totalFoto += count($fotoArray);
                }
                echo number_format($totalFoto);
            ?></div>
            <div class="stat-label">Total Foto</div>
        </div>
        <div class="stat-card">
            <div class="stat-icon"><i class="fas fa-calendar-alt"></i></div>
            <div class="stat-number">1950-2026</div>
            <div class="stat-label">Rentang Waktu</div>
        </div>
    </div>
</div>

<!-- ========== GALLERY ========== -->
<section class="gallery-section">
    <div class="section-title" data-aos="fade-up">
        <h2>Galeri Arsip Foto</h2>
        <p>Menelusuri jejak sejarah dan perjalanan DPAD Solok Selatan</p>
    </div>

    <div class="gallery-grid">
        <?php if(mysqli_num_rows($query) > 0): ?>
            <?php while($row = mysqli_fetch_array($query)):
                $fotoArray = explode(',', $row['foto']);
                $fotoArray = array_map('trim', $fotoArray);
                $fotoArray = array_filter($fotoArray);
                $fotoPertama = reset($fotoArray);
                $jumlahFoto = count($fotoArray);
                $jsonFoto = json_encode(array_values($fotoArray));
            ?>
            <div class="gallery-card" data-aos="fade-up" data-aos-delay="50"
                 data-foto='<?php echo $jsonFoto; ?>'
                 data-judul="<?php echo htmlspecialchars($row['judul']); ?>"
                 data-deskripsi="<?php echo htmlspecialchars($row['deskripsi']); ?>"
                 data-tahun="<?php echo $row['tahun'] ?: 'Tidak diketahui'; ?>"
                 onclick="openGallery(this)">
                <div class="card-image">
                    <?php if($fotoPertama && file_exists("img/arsip/".$fotoPertama)): ?>
                        <img src="img/arsip/<?php echo $fotoPertama; ?>" alt="<?php echo htmlspecialchars($row['judul']); ?>" loading="lazy">
                    <?php else: ?>
                        <img src="https://placehold.co/600x400/1a5f4b/white?text=DPAD" alt="Placeholder">
                    <?php endif; ?>
                    <div class="image-overlay">
                        <i class="fas fa-search-plus"></i>
                    </div>
                    <?php if($jumlahFoto > 1): ?>
                        <div class="badge-photo">
                            <i class="fas fa-images"></i> <?php echo $jumlahFoto; ?>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="card-content">
                    <h3><?php echo htmlspecialchars($row['judul']); ?></h3>
                    <div class="card-year">
                        <i class="fas fa-calendar-alt"></i> <?php echo $row['tahun'] ?: 'Tidak diketahui'; ?>
                    </div>
                    <p><?php echo htmlspecialchars(substr($row['deskripsi'], 0, 100)); ?>...</p>
                </div>
            </div>
            <?php endwhile; ?>
        <?php else: ?>
            <div class="empty-state" data-aos="fade-up">
                <i class="fas fa-images"></i>
                <h3>Belum Ada Arsip Foto</h3>
                <p>Belum ada arsip foto sejarah yang diunggah.</p>
                <?php if(isset($_SESSION['admin'])): ?>
                    <a href="admin/arsip_foto.php" style="display:inline-block; margin-top:20px; background:#1a5f4b; color:white; padding:10px 28px; border-radius:40px; text-decoration:none; transition:0.3s;">
                        <i class="fas fa-plus"></i> Tambah Arsip
                    </a>
                <?php endif; ?>
            </div>
        <?php endif; ?>
    </div>
</section>

<!-- ========== MODAL ========== -->
<div id="modalGallery" class="modal-gallery">
    <button class="modal-close" onclick="closeGallery()"><i class="fas fa-times"></i></button>
    <div class="modal-content">
        <img id="modalImage" src="" alt="Gallery Image">
        <div class="modal-nav">
            <button onclick="changeImage(-1)"><i class="fas fa-chevron-left"></i></button>
            <button onclick="changeImage(1)"><i class="fas fa-chevron-right"></i></button>
        </div>
        <div class="modal-indicator" id="modalIndicator"></div>
        <div class="modal-caption" id="modalCaption"></div>
    </div>
</div>

<!-- ========== FOOTER ========== -->
<footer class="footer-premium">
    <div class="footer-container">
        <div class="footer-grid">
            <div class="footer-col" data-aos="fade-up">
                <div class="footer-logo">
                    <div class="logo-icon">
                        <?php if(file_exists("img/logo.png")): ?>
                            <img src="img/logo.png" style="width:35px; height:35px; object-fit:contain;">
                        <?php else: ?>
                            <i class="fas fa-archive"></i>
                        <?php endif; ?>
                    </div>
                    <div class="logo-text">
                        <h3>Dinas Arsip Solok Selatan</h3>
                        <p>Dinas Perpustakaan & Arsip Daerah</p>
                    </div>
                </div>
                <p class="footer-description">
                    Melestarikan sejarah, menjaga arsip, dan membangun peradaban literasi untuk masyarakat Solok Selatan yang cerdas dan berbudaya.
                </p>
                <div class="social-links">
                    <a href="https://www.facebook.com/profile.php?id=61573699960407" class="social-icon social-fb" target="_blank"><i class="fab fa-facebook-f"></i></a>
                    <a href="https://www.instagram.com/arsip_solsel/" class="social-icon social-ig" target="_blank"><i class="fab fa-instagram"></i></a>
                    <a href="https://www.youtube.com/@pustakadpksolsel" class="social-icon social-yt" target="_blank"><i class="fab fa-youtube"></i></a>
                    <a href="https://www.tiktok.com/@solselnews" class="social-icon social-tt" target="_blank"><i class="fab fa-tiktok"></i></a>
                </div>
            </div>

            <div class="footer-col" data-aos="fade-up" data-aos-delay="100">
                <h3><i class="fas fa-link"></i> Menu Cepat</h3>
                <ul class="footer-menu">
                    <li><a href="dashboard.php"><i class="fas fa-home"></i> Beranda</a></li>
                    <li><a href="profil_istansi.php"><i class="fas fa-building"></i> Profil</a></li>
                    <li><a href="visi.php"><i class="fas fa-eye"></i> Visi & Misi</a></li>
                    <li><a href="struktur.php"><i class="fas fa-diagram-project"></i> Struktur Organisasi</a></li>
                    <li><a href="berita.php"><i class="fas fa-newspaper"></i> Berita</a></li>
                </ul>
            </div>

            <div class="footer-col" data-aos="fade-up" data-aos-delay="200">
                <h3><i class="fas fa-star"></i> Layanan</h3>
                <ul class="footer-menu">
                    <li><a href="https://perpustakaan.solselkab.go.id/read/166/bidang-kearsipan"><i class="fas fa-book"></i> Perpustakaan</a></li>
                    <li><a href="layanan_arsip.php"><i class="fas fa-archive"></i> Kearsipan</a></li>
                    <li><a href="layanan_kunjungan.php"><i class="fas fa-users"></i> Kunjungan Edukasi</a></li>
                    <li><a href="layanan_konsultasi.php"><i class="fas fa-comments"></i> Konsultasi Arsip</a></li>
                    <li><a href="pengaduan.php"><i class="fas fa-headset"></i> Pengaduan Masyarakat</a></li>
                </ul>
            </div>

            <div class="footer-col" data-aos="fade-up" data-aos-delay="300">
                <h3><i class="fas fa-map-marker-alt"></i> Lokasi & Kontak</h3>
                <div class="footer-contact-item">
                    <i class="fas fa-map-marker-alt"></i>
                    <span>Jl. Lubuk Gadang - Simpang Tigo Rimbo Tangah, Sangir</span>
                </div>
                <div class="footer-contact-item">
                    <i class="fas fa-envelope"></i>
                    <span>pustaka.arsipsolsel@gmail.com</span>
                </div>
                <div class="footer-contact-item">
                    <i class="fas fa-clock"></i>
                    <span>Senin - Jumat, 08.00 - 16.00 WIB</span>
                </div>
            </div>
        </div>

        <div class="footer-bottom">
            <div>
                <p>&copy; <?php echo date('Y'); ?> Dinas Perpustakaan dan Arsip Daerah Kabupaten Solok Selatan</p>
                <p style="margin-top:4px; font-size:0.65rem; opacity:0.5;">All Rights Reserved</p>
            </div>
            <div>
                <p style="font-size:0.7rem; color:#94a3b8;">Sistem Informasi Perpustakaan dan Arsip Daerah</p>
                <div class="visitor-badge">
                    <i class="fas fa-eye"></i> <?php echo number_format($totalVisitor); ?> Pengunjung
                </div>
                <div class="dev-credit" style="margin-top:8px;">
                    Developed by <a href="https://www.pnp.ac.id/download/psdku-solok-selatan/" target="_blank">PSDKU Solok Selatan</a>
                </div>
            </div>
        </div>
    </div>
</footer>

<!-- ========== SCRIPTS ========== -->
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script>
    AOS.init({
        duration: 600,
        once: true,
        offset: 30,
        easing: 'ease-in-out'
    });

    // Header Sticky
    const header = document.getElementById('mainHeader');
    window.addEventListener('scroll', function() {
        if (window.scrollY > 50) {
            header.classList.add('scrolled');
        } else {
            header.classList.remove('scrolled');
        }
    });

    // ========== GALLERY MODAL ==========
    let currentGallery = {
        images: [],
        currentIndex: 0,
        title: '',
        year: '',
        deskripsi: ''
    };

    function openGallery(element) {
        currentGallery.images = JSON.parse(element.getAttribute('data-foto'));
        currentGallery.currentIndex = 0;
        currentGallery.title = element.getAttribute('data-judul');
        currentGallery.deskripsi = element.getAttribute('data-deskripsi');
        currentGallery.year = element.getAttribute('data-tahun');
        
        const modal = document.getElementById('modalGallery');
        modal.classList.add('active');
        document.body.style.overflow = 'hidden';
        updateModalImage();
    }

    function updateModalImage() {
        const img = document.getElementById('modalImage');
        const indicator = document.getElementById('modalIndicator');
        const caption = document.getElementById('modalCaption');
        
        const imagePath = 'img/arsip/' + currentGallery.images[currentGallery.currentIndex];
        img.src = imagePath;
        img.alt = currentGallery.title;
        
        indicator.innerHTML = `<i class="fas fa-image"></i> ${currentGallery.currentIndex + 1} / ${currentGallery.images.length}`;
        caption.innerHTML = `<strong>${currentGallery.title}</strong> • ${currentGallery.year}<br>${currentGallery.deskripsi}`;
        
        img.onerror = function() {
            img.src = 'https://placehold.co/800x600/1a5f4b/white?text=Gambar+Tidak+Ditemukan';
        };
    }

    function changeImage(direction) {
        let newIndex = currentGallery.currentIndex + direction;
        if (newIndex < 0) newIndex = currentGallery.images.length - 1;
        if (newIndex >= currentGallery.images.length) newIndex = 0;
        currentGallery.currentIndex = newIndex;
        updateModalImage();
    }

    function closeGallery() {
        const modal = document.getElementById('modalGallery');
        modal.classList.remove('active');
        document.body.style.overflow = '';
    }

    // Keyboard Navigation
    document.addEventListener('keydown', function(e) {
        const modal = document.getElementById('modalGallery');
        if (!modal.classList.contains('active')) return;
        if (e.key === 'Escape') closeGallery();
        if (e.key === 'ArrowLeft') changeImage(-1);
        if (e.key === 'ArrowRight') changeImage(1);
    });

    // Close on click outside
    document.getElementById('modalGallery').addEventListener('click', function(e) {
        if (e.target === this) closeGallery();
    });

    // Touch Swipe Support
    let touchStartX = 0;
    let touchEndX = 0;

    document.getElementById('modalGallery').addEventListener('touchstart', function(e) {
        touchStartX = e.changedTouches[0].screenX;
    });

    document.getElementById('modalGallery').addEventListener('touchend', function(e) {
        touchEndX = e.changedTouches[0].screenX;
        handleSwipe();
    });

    function handleSwipe() {
        const swipeThreshold = 50;
        const diff = touchStartX - touchEndX;
        if (Math.abs(diff) > swipeThreshold) {
            if (diff > 0) {
                changeImage(1); // swipe left -> next
            } else {
                changeImage(-1); // swipe right -> previous
            }
        }
    }
</script>
</body>
</html>