<?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),
        last_visit TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )
");

$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, user_agent) 
        VALUES ('$ip', '$tanggal', '{$_SERVER['HTTP_USER_AGENT']}')
    ");
} else {
    mysqli_query($koneksi, "
        UPDATE visitor_counter 
        SET last_visit = NOW() 
        WHERE ip_address = '$ip' AND tanggal = '$tanggal'
    ");
}

$totalVisitor = 0;
$query_total = mysqli_query($koneksi, "SELECT COUNT(DISTINCT ip_address) as total FROM visitor_counter");
if($query_total && mysqli_num_rows($query_total) > 0){
    $row = mysqli_fetch_assoc($query_total);
    $totalVisitor = $row['total'];
}

// Ambil data berita terbaru untuk ditampilkan
$berita_terbaru = mysqli_query($koneksi, "SELECT * FROM berita ORDER BY id DESC LIMIT 3");

// Ambil data galeri (arsip foto)
$galeri = mysqli_query($koneksi, "SELECT * FROM arsip_foto ORDER BY id DESC LIMIT 4");

// Hitung statistik
$total_pegawai = 87;
$total_arsip = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT COUNT(*) as total FROM arsip_foto"))['total'];
$total_berita_count = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT COUNT(*) as total FROM berita"))['total'];
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
    <title>Struktur Organisasi | DPAD Solok Selatan</title>

    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&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', 'Plus Jakarta Sans', sans-serif;
            background: #f0f7f2;
            color: #1e293b;
            overflow-x: hidden;
            padding-top: 80px;
        }

        /* ========== HEADER PREMIUM ========== */
        .header {
            background: linear-gradient(135deg, #0a3d32, #1a5f4b);
            padding: 12px 40px;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
            overflow: hidden;
        }

        .header::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(245,197,66,0.08), transparent);
            animation: rotateBg 20s linear infinite;
        }

        @keyframes rotateBg {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .header::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: linear-gradient(90deg, transparent, #f5c542, #f5c542, transparent);
        }

        .header-content {
            max-width: 1280px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 15px;
            position: relative;
            z-index: 2;
        }

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

        .logo-icon {
            width: 45px;
            height: 45px;
            background: rgba(255,255,255,0.15);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

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

        .logo-text h2 {
            color: white;
            font-size: 1rem;
            font-weight: 700;
        }

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

        .back-btn {
            background: rgba(255,255,255,0.12);
            backdrop-filter: blur(10px);
            color: white;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            text-decoration: none;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 1px solid rgba(255,255,255,0.2);
        }

        .back-btn:hover {
            background: white;
            color: #1a5f4b;
            transform: translateX(-3px) rotate(360deg);
        }

        /* ========== HERO ========== */
        .hero {
            background: linear-gradient(135deg, #1a5f4b, #0f3b2c);
            padding: 60px 20px 50px;
            text-align: center;
            color: white;
            position: relative;
            overflow: hidden;
            min-height: 280px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            margin-top: 70px;
        }

        .hero::before {
            content: '';
            position: absolute;
            inset: 0;
            background: url('img/kantor.jpg') center/cover;
            opacity: .12;
        }

        .hero::after {
            content: "🏛️";
            position: absolute;
            right: -30px;
            top: -30px;
            font-size: 180px;
            opacity: 0.06;
        }

        .hero h1 {
            font-size: 2.2rem;
            font-weight: 800;
            margin-bottom: 10px;
            position: relative;
            z-index: 2;
        }

        .hero p {
            max-width: 600px;
            margin: 0 auto;
            font-size: 0.95rem;
            opacity: 0.85;
            position: relative;
            z-index: 2;
        }

        .hero .badge-hero {
            display: inline-block;
            background: rgba(245,197,66,0.2);
            padding: 5px 20px;
            border-radius: 50px;
            font-size: 0.75rem;
            color: #f5c542;
            margin-bottom: 15px;
            position: relative;
            z-index: 2;
            border: 1px solid rgba(245,197,66,0.15);
        }

        /* ========== BREADCRUMB ========== */
        .breadcrumb {
            max-width: 1280px;
            margin: 15px auto 0;
            padding: 0 20px;
            font-size: 0.8rem;
            color: #94a3b8;
        }

        .breadcrumb a {
            color: #1a5f4b;
            text-decoration: none;
        }

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

        /* ========== STATISTIK BAR ========== */
        .stats-bar {
            max-width: 1280px;
            margin: -25px auto 0;
            padding: 0 20px;
            position: relative;
            z-index: 20;
        }

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

        .stat-card {
            background: white;
            border-radius: 18px;
            padding: 22px 18px;
            text-align: center;
            box-shadow: 0 8px 25px rgba(0,0,0,0.06);
            transition: 0.3s;
            border: 1px solid #eef2f5;
        }

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

        .stat-card i {
            font-size: 32px;
            color: #1a5f4b;
            margin-bottom: 8px;
        }

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

        .stat-card p {
            font-size: 0.75rem;
            color: #64748b;
        }

        /* ========== STRUKTUR ORGANISASI ========== */
        .struktur-utama {
            max-width: 1280px;
            margin: 45px auto 60px;
            padding: 0 20px;
        }

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

        .section-title h2 {
            font-size: 1.8rem;
            font-weight: 800;
            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.9rem;
            margin-top: 8px;
        }

        /* ===== BAGAN ORGANISASI ===== */
        .org-chart {
            background: white;
            border-radius: 28px;
            padding: 35px 30px;
            box-shadow: 0 10px 35px rgba(0,0,0,0.06);
            border: 1px solid #eef2f5;
        }

        .org-row {
            display: flex;
            justify-content: center;
            flex-wrap: wrap;
            gap: 25px;
        }

        .org-item {
            background: white;
            border-radius: 16px;
            padding: 20px 28px;
            text-align: center;
            box-shadow: 0 4px 15px rgba(0,0,0,0.06);
            transition: 0.3s;
            min-width: 200px;
            border: 1px solid #eef2f5;
            position: relative;
        }

        .org-item:hover {
            transform: translateY(-4px);
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            border-color: #1a5f4b;
        }

        .org-item .avatar {
            width: 70px;
            height: 70px;
            margin: 0 auto 12px;
            background: linear-gradient(135deg, #dcfce7, #e8f5e9);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
            border: 3px solid #f5c542;
        }

        .org-item .avatar i {
            font-size: 32px;
            color: #1a5f4b;
        }

        .org-item .avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .org-item h4 {
            font-size: 0.95rem;
            font-weight: 700;
            color: #0f3b2c;
            margin-bottom: 3px;
        }

        .org-item .jabatan {
            font-size: 0.7rem;
            font-weight: 600;
            color: #1a5f4b;
            margin-bottom: 3px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .org-item .nip {
            font-size: 0.6rem;
            color: #94a3b8;
        }

        /* Level 1 - Kepala Dinas */
        .org-item.level-1 {
            background: linear-gradient(135deg, #1a5f4b, #0f3b2c);
            color: white;
            border-color: #1a5f4b;
            min-width: 280px;
        }

        .org-item.level-1 h4 {
            color: white;
        }

        .org-item.level-1 .jabatan {
            color: #f5c542;
        }

        .org-item.level-1 .nip {
            color: rgba(255,255,255,0.6);
        }

        .org-item.level-1 .avatar {
            border-color: #f5c542;
            background: rgba(255,255,255,0.15);
        }

        .org-item.level-1 .avatar i {
            color: white;
        }

        /* Level 2 - Sekretaris */
        .org-item.level-2 {
            background: linear-gradient(135deg, #2563eb, #1d4ed8);
            color: white;
            border-color: #2563eb;
            min-width: 250px;
        }

        .org-item.level-2 h4 {
            color: white;
        }

        .org-item.level-2 .jabatan {
            color: #93c5fd;
        }

        .org-item.level-2 .nip {
            color: rgba(255,255,255,0.6);
        }

        .org-item.level-2 .avatar {
            border-color: #93c5fd;
            background: rgba(255,255,255,0.15);
        }

        .org-item.level-2 .avatar i {
            color: white;
        }

        /* Level 3 - Kabid */
        .org-item.level-3 {
            background: linear-gradient(135deg, #f59e0b, #d97706);
            color: white;
            border-color: #f59e0b;
            min-width: 220px;
        }

        .org-item.level-3 h4 {
            color: white;
        }

        .org-item.level-3 .jabatan {
            color: #fde68a;
        }

        .org-item.level-3 .nip {
            color: rgba(255,255,255,0.6);
        }

        .org-item.level-3 .avatar {
            border-color: #fde68a;
            background: rgba(255,255,255,0.15);
        }

        .org-item.level-3 .avatar i {
            color: white;
        }

        /* Level 4 - Subbagian */
        .org-item.level-4 {
            background: linear-gradient(135deg, #8b5cf6, #7c3aed);
            color: white;
            border-color: #8b5cf6;
            min-width: 220px;
        }

        .org-item.level-4 h4 {
            color: white;
        }

        .org-item.level-4 .jabatan {
            color: #c4b5fd;
        }

        .org-item.level-4 .nip {
            color: rgba(255,255,255,0.6);
        }

        .org-item.level-4 .avatar {
            border-color: #c4b5fd;
            background: rgba(255,255,255,0.15);
        }

        .org-item.level-4 .avatar i {
            color: white;
        }

        .connector-line {
            display: flex;
            justify-content: center;
            padding: 5px 0;
        }

        .connector-line .line-v {
            width: 2px;
            height: 30px;
            background: linear-gradient(to bottom, #1a5f4b, #cbd5e1);
        }

        .connector-line .line-h {
            width: 60%;
            height: 2px;
            background: linear-gradient(to right, transparent, #1a5f4b, #1a5f4b, transparent);
        }

        /* ===== STAF GRID ===== */
        .staf-section {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 2px dashed #eef2f5;
        }

        .staf-section .staf-title {
            font-size: 1rem;
            font-weight: 700;
            color: #0f3b2c;
            margin-bottom: 15px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .staf-section .staf-title i {
            color: #f5c542;
        }

        .staf-section .staf-title .total {
            font-size: 0.7rem;
            font-weight: 500;
            color: #94a3b8;
            background: #f1f5f9;
            padding: 2px 12px;
            border-radius: 30px;
        }

        .staf-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 15px;
        }

        .staf-item {
            background: #f8fafc;
            border-radius: 14px;
            padding: 16px 14px;
            text-align: center;
            border: 1px solid #eef2f5;
            transition: 0.3s;
        }

        .staf-item:hover {
            transform: translateY(-3px);
            border-color: #1a5f4b;
            box-shadow: 0 8px 20px rgba(0,0,0,0.06);
        }

        .staf-item .avatar {
            width: 50px;
            height: 50px;
            margin: 0 auto 10px;
            background: #dcfce7;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .staf-item .avatar i {
            font-size: 22px;
            color: #1a5f4b;
        }

        .staf-item h5 {
            font-size: 0.85rem;
            font-weight: 600;
            color: #0f3b2c;
            margin-bottom: 2px;
        }

        .staf-item .nip {
            font-size: 0.6rem;
            color: #94a3b8;
        }

        /* ========== GALERI & BERITA ========== */
        .info-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
            margin-top: 30px;
        }

        .info-card {
            background: white;
            border-radius: 24px;
            padding: 25px;
            box-shadow: 0 10px 35px rgba(0,0,0,0.06);
            border: 1px solid #eef2f5;
        }

        .info-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 18px;
            padding-bottom: 12px;
            border-bottom: 2px solid #f5c542;
        }

        .info-header h3 {
            font-size: 1.1rem;
            font-weight: 700;
            color: #0f3b2c;
        }

        .info-header a {
            color: #1a5f4b;
            text-decoration: none;
            font-weight: 500;
            font-size: 0.85rem;
            transition: 0.3s;
        }

        .info-header a:hover {
            color: #f5c542;
        }

        .galeri-list {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }

        .galeri-item {
            display: flex;
            gap: 15px;
            background: #f8fafc;
            border-radius: 14px;
            overflow: hidden;
            transition: 0.3s;
            border: 1px solid #eef2f5;
            padding: 8px;
        }

        .galeri-item:hover {
            transform: translateX(5px);
            border-color: #1a5f4b;
        }

        .galeri-item img {
            width: 70px;
            height: 70px;
            object-fit: cover;
            border-radius: 10px;
        }

        .galeri-item .info {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .galeri-item .info h4 {
            font-size: 0.85rem;
            font-weight: 600;
            margin-bottom: 3px;
        }

        .galeri-item .info p {
            font-size: 0.7rem;
            color: #94a3b8;
        }

        .berita-list {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .berita-item {
            display: flex;
            gap: 12px;
            padding: 10px 0;
            border-bottom: 1px solid #eef2f5;
        }

        .berita-item:last-child {
            border-bottom: none;
        }

        .berita-item img {
            width: 55px;
            height: 55px;
            object-fit: cover;
            border-radius: 10px;
        }

        .berita-item .info {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .berita-item .info h5 {
            font-size: 0.85rem;
            font-weight: 600;
            color: #0f3b2c;
            margin-bottom: 3px;
        }

        .berita-item .date {
            font-size: 0.65rem;
            color: #94a3b8;
        }

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

        .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;
            position: relative;
            display: inline-block;
            padding-bottom: 10px;
            color: #f5c542;
        }

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

        .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.1);
            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 {
            width: 20px;
            font-size: 0.8rem;
            color: #f5c542;
        }

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

        .social-links {
            display: flex;
            gap: 12px;
            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;
            font-size: 1rem;
            text-decoration: none;
        }

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

        .social-icon:hover {
            transform: translateY(-3px);
            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.12);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #f5c542;
            font-size: 0.9rem;
            flex-shrink: 0;
        }

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

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

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

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

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

        /* ========== RESPONSIVE ========== */
        @media (max-width: 992px) {
            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: 15px;
            }
            .footer-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: 30px;
            }
            .info-grid {
                grid-template-columns: 1fr;
                gap: 20px;
            }
            .org-item {
                min-width: 180px;
                padding: 16px 20px;
            }
            .org-item.level-1 {
                min-width: 220px;
            }
            .org-item.level-2 {
                min-width: 200px;
            }
            .org-item.level-3 {
                min-width: 200px;
            }
            .org-item.level-4 {
                min-width: 200px;
            }
            .staf-grid {
                grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
            }
        }

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

            .header {
                padding: 10px 20px;
            }
            .logo-text h2 {
                font-size: 0.85rem;
            }
            .logo-text p {
                font-size: 0.55rem;
            }
            .back-btn {
                width: 35px;
                height: 35px;
                font-size: 14px;
            }

            .hero {
                padding: 50px 15px 40px;
                min-height: 220px;
                margin-top: 60px;
            }
            .hero h1 {
                font-size: 1.6rem;
            }
            .hero p {
                font-size: 0.85rem;
            }

            .stats-grid {
                grid-template-columns: 1fr 1fr;
                gap: 12px;
            }
            .stat-card {
                padding: 16px 12px;
            }
            .stat-card .number {
                font-size: 1.3rem;
            }
            .stat-card i {
                font-size: 26px;
            }

            .section-title h2 {
                font-size: 1.4rem;
            }

            .org-chart {
                padding: 20px 15px;
            }
            .org-item {
                min-width: 100%;
                padding: 14px 16px;
            }
            .org-item.level-1 {
                min-width: 100%;
            }
            .org-item.level-2 {
                min-width: 100%;
            }
            .org-item.level-3 {
                min-width: 100%;
            }
            .org-item.level-4 {
                min-width: 100%;
            }
            .org-item .avatar {
                width: 55px;
                height: 55px;
            }
            .org-item .avatar i {
                font-size: 24px;
            }
            .org-item h4 {
                font-size: 0.85rem;
            }
            .org-item .jabatan {
                font-size: 0.6rem;
            }

            .staf-grid {
                grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
                gap: 12px;
            }
            .staf-item {
                padding: 12px 10px;
            }
            .staf-item .avatar {
                width: 40px;
                height: 40px;
            }
            .staf-item .avatar i {
                font-size: 18px;
            }
            .staf-item h5 {
                font-size: 0.75rem;
            }

            .staf-section .staf-title {
                font-size: 0.9rem;
            }

            .footer-grid {
                grid-template-columns: 1fr;
                gap: 25px;
                text-align: center;
            }
            .footer-logo {
                justify-content: center;
            }
            .footer-col h3::after {
                left: 50%;
                transform: translateX(-50%);
            }
            .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) {
            .header {
                padding: 8px 15px;
            }
            .logo-text h2 {
                font-size: 0.75rem;
            }
            .logo-text p {
                font-size: 0.5rem;
            }
            .logo-icon {
                width: 35px;
                height: 35px;
            }

            .hero h1 {
                font-size: 1.3rem;
            }
            .hero p {
                font-size: 0.75rem;
            }

            .stats-grid {
                grid-template-columns: 1fr;
                gap: 10px;
            }
            .stat-card {
                padding: 14px 10px;
            }

            .org-item .avatar {
                width: 50px;
                height: 50px;
            }

            .staf-grid {
                grid-template-columns: 1fr 1fr;
                gap: 10px;
            }
            .staf-item {
                padding: 10px 8px;
            }
            .staf-item h5 {
                font-size: 0.7rem;
            }
            .staf-item .nip {
                font-size: 0.5rem;
            }

            .info-card {
                padding: 18px 15px;
            }
            .info-header h3 {
                font-size: 1rem;
            }
            .galeri-item img {
                width: 55px;
                height: 55px;
            }
            .berita-item img {
                width: 45px;
                height: 45px;
            }
        }
    </style>
</head>
<body>

<!-- HEADER -->
<div class="header">
    <div class="header-content">
        <div class="logo-area">
            <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">
                <h2>Solok Selatan</h2>
                <p>Dinas Perpustakaan dan Arsip Daerah</p>
            </div>
        </div>
        <a href="dashboard.php" class="back-btn">
            <i class="fas fa-home"></i>
        </a>
    </div>
</div>

<!-- HERO -->
<section class="hero">
    <span class="badge-hero"><i class="fas fa-sitemap"></i> Struktur Organisasi</span>
    <h1 data-aos="fade-down">Struktur Organisasi</h1>
    <p data-aos="fade-up">Bagan organisasi Dinas Perpustakaan dan Arsip Daerah Kabupaten Solok Selatan</p>
</section>

<!-- BREADCRUMB -->
<div class="breadcrumb">
    <a href="dashboard.php"><i class="fas fa-home"></i> Beranda</a> / 
    <span>Struktur Organisasi</span>
</div>

<!-- STATISTIK -->
<div class="stats-bar">
    <div class="stats-grid">
        <div class="stat-card" data-aos="fade-up" data-aos-delay="0">
            <i class="fas fa-newspaper"></i>
            <div class="number"><?php echo $total_berita_count; ?></div>
            <p>Total Berita</p>
        </div>
        <div class="stat-card" data-aos="fade-up" data-aos-delay="100">
            <i class="fas fa-archive"></i>
            <div class="number"><?php echo $total_arsip; ?></div>
            <p>Arsip Foto</p>
        </div>
        <div class="stat-card" data-aos="fade-up" data-aos-delay="200">
            <i class="fas fa-users"></i>
            <div class="number"><?php echo $total_pegawai; ?></div>
            <p>Total Pegawai</p>
        </div>
        <div class="stat-card" data-aos="fade-up" data-aos-delay="300">
            <i class="fas fa-calendar"></i>
            <div class="number">2009</div>
            <p>Tahun Berdiri</p>
        </div>
    </div>
</div>

<!-- STRUKTUR ORGANISASI -->
<div class="struktur-utama">
    <div class="section-title" data-aos="fade-up">
        <h2>STRUKTUR ORGANISASI</h2>
        <p>Dinas Perpustakaan dan Arsip Daerah Kabupaten Solok Selatan</p>
    </div>

    <div class="org-chart" data-aos="fade-up">
        <!-- TAMPILKAN SATU FOTO BAGAN STRUKTUR -->
        <div style="text-align: center; padding: 20px;">
            <?php 
            $foto_struktur = "img/struktur.jpg"; // Ganti dengan nama file foto kamu
            if(file_exists($foto_struktur)): 
            ?>
                <img src="<?php echo $foto_struktur; ?>" alt="Struktur Organisasi" style="width: 100%; max-width: 900px; border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,0.1);">
            <?php else: ?>
                <div style="background: #f8fafc; border-radius: 16px; padding: 60px 20px; border: 2px dashed #cbd5e1;">
                    <i class="fas fa-image" style="font-size: 50px; color: #94a3b8; margin-bottom: 15px;"></i>
                    <p style="color: #64748b;">Foto struktur organisasi belum diupload</p>
                    <p style="color: #94a3b8; font-size: 0.8rem;">Upload file: img/struktur/struktur_organisasi.jpg</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<!-- GALERI & BERITA -->
<div class="struktur-utama">
    <div class="info-grid">
        <!-- Galeri -->
        <div class="info-card" data-aos="fade-right">
            <div class="info-header">
                <h3><i class="fas fa-images"></i> Arsip Galeri</h3>
                <a href="sejarah_poto.php">Lihat Semua →</a>
            </div>
            <div class="galeri-list">
                <?php if(mysqli_num_rows($galeri) > 0): ?>
                    <?php while($row = mysqli_fetch_array($galeri)):
                        $fotoArray = explode(',', $row['foto']);
                        $fotoPertama = trim($fotoArray[0]);
                    ?>
                    <div class="galeri-item">
                        <?php if($fotoPertama && file_exists("img/arsip/".$fotoPertama)): ?>
                            <img src="img/arsip/<?php echo $fotoPertama; ?>" alt="<?php echo $row['judul']; ?>">
                        <?php else: ?>
                            <img src="https://placehold.co/70x70/1a5f4b/white?text=DPAD" alt="Default">
                        <?php endif; ?>
                        <div class="info">
                            <h4><?php echo htmlspecialchars(substr($row['judul'], 0, 35)); ?>...</h4>
                            <p><i class="fas fa-calendar-alt"></i> <?php echo date('d M Y', strtotime($row['created_at'])); ?></p>
                        </div>
                    </div>
                    <?php endwhile; ?>
                <?php else: ?>
                    <div style="text-align:center; padding:30px; color:#94a3b8; font-size:0.9rem;">Belum ada galeri</div>
                <?php endif; ?>
            </div>
        </div>

        <!-- Berita Terbaru -->
        <div class="info-card" data-aos="fade-left">
            <div class="info-header">
                <h3><i class="fas fa-newspaper"></i> Berita Terbaru</h3>
                <a href="berita.php">Lihat Semua →</a>
            </div>
            <div class="berita-list">
                <?php if(mysqli_num_rows($berita_terbaru) > 0): ?>
                    <?php while($row = mysqli_fetch_array($berita_terbaru)):
                        $gambarArray = explode(',', $row['gambar']);
                        $gambarPertama = trim($gambarArray[0]);
                    ?>
                    <div class="berita-item">
                        <?php if(!empty($gambarPertama) && file_exists("img/".$gambarPertama)): ?>
                            <img src="img/<?php echo $gambarPertama; ?>" alt="<?php echo $row['judul']; ?>">
                        <?php else: ?>
                            <img src="https://placehold.co/55x55/1a5f4b/white?text=News" alt="News">
                        <?php endif; ?>
                        <div class="info">
                            <h5><?php echo htmlspecialchars(substr($row['judul'], 0, 35)); ?></h5>
                            <div class="date"><i class="far fa-calendar-alt"></i> <?php echo date('d M Y', strtotime($row['tanggal'])); ?></div>
                        </div>
                    </div>
                    <?php endwhile; ?>
                <?php else: ?>
                    <div style="text-align:center; padding:30px; color:#94a3b8; font-size:0.9rem;">Belum ada berita</div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<!-- FOOTER PREMIUM -->
<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>DPAD 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 Instansi</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>

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

</body>
</html>