<?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'];
}

// ========== PENCARIAN BERITA ==========
$keyword = isset($_GET['keyword']) ? mysqli_real_escape_string($koneksi, $_GET['keyword']) : '';
$where = "1=1";

if($keyword != '') {
    $where .= " AND (judul LIKE '%$keyword%' OR isi LIKE '%$keyword%')";
}

$query = mysqli_query($koneksi, "SELECT * FROM berita WHERE $where ORDER BY id DESC");
$total_berita = mysqli_num_rows($query);
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Berita | 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=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 PREMIUM ========== */
        .header {
            background: linear-gradient(135deg, #0a3d32, #1a5f4b);
            padding: 12px 40px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 100;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
        }

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

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

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

        .logo-icon:hover {
            transform: scale(1.05);
            background: rgba(255,255,255,0.25);
        }

        .logo-icon img {
            width: 32px;
            height: 32px;
            object-fit: contain;
        }

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

        .logo-text h2 {
            color: white;
            font-size: 0.95rem;
            font-weight: 700;
            line-height: 1.2;
        }

        .logo-text p {
            color: rgba(255,255,255,0.7);
            font-size: 0.6rem;
            margin-top: 2px;
        }

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

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

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

        .icon-btn .tooltip {
            position: absolute;
            bottom: -38px;
            left: 50%;
            transform: translateX(-50%);
            background: #1e293b;
            color: white;
            padding: 5px 12px;
            border-radius: 8px;
            font-size: 0.65rem;
            font-weight: 500;
            white-space: nowrap;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s;
            z-index: 100;
            pointer-events: none;
            box-shadow: 0 4px 10px rgba(0,0,0,0.2);
        }

        .icon-btn .tooltip::before {
            content: '';
            position: absolute;
            top: -5px;
            left: 50%;
            transform: translateX(-50%);
            border-left: 5px solid transparent;
            border-right: 5px solid transparent;
            border-bottom: 5px solid #1e293b;
        }

        .icon-btn:hover .tooltip {
            opacity: 1;
            visibility: visible;
            bottom: -33px;
        }

        /* ===== SEARCH FORM ===== */
        .search-form {
            display: flex;
            background: rgba(255,255,255,0.12);
            border-radius: 30px;
            overflow: hidden;
            border: 1px solid rgba(255,255,255,0.1);
            align-items: center;
        }

        .search-form input {
            border: none;
            padding: 7px 14px;
            background: transparent;
            color: white;
            outline: none;
            font-size: 13px;
            min-width: 140px;
        }

        .search-form input::placeholder {
            color: rgba(255,255,255,0.6);
        }

        .search-form .btn-search {
            background: rgba(255,255,255,0.12);
            border: none;
            padding: 7px 12px;
            color: white;
            cursor: pointer;
            transition: 0.3s;
            display: flex;
            align-items: center;
            gap: 4px;
            font-size: 12px;
        }

        .search-form .btn-search:hover {
            background: #f5c542;
            color: #0a3d32;
        }

        .search-form .btn-reset {
            background: rgba(239, 68, 68, 0.2);
            border: none;
            padding: 7px 12px;
            color: rgba(255,255,255,0.8);
            cursor: pointer;
            transition: 0.3s;
            display: flex;
            align-items: center;
            gap: 4px;
            font-size: 12px;
            border-left: 1px solid rgba(255,255,255,0.1);
        }

        .search-form .btn-reset:hover {
            background: #ef4444;
            color: white;
        }

        .search-form .btn-reset.hidden {
            display: none;
        }

        /* ========== PAGE HEADER ========== */
        .page-header {
            background: linear-gradient(135deg, #1a5f4b, #0f3b2c);
            margin: 20px 40px 30px;
            border-radius: 30px;
            padding: 50px 40px;
            color: white;
            text-align: center;
            position: relative;
            overflow: hidden;
            box-shadow: 0 15px 35px rgba(0,0,0,0.1);
        }

        .page-header::before {
            content: "📰";
            position: absolute;
            right: -30px;
            top: -30px;
            font-size: 180px;
            opacity: 0.08;
            transform: rotate(15deg);
        }

        .page-header::after {
            content: "📚";
            position: absolute;
            left: -30px;
            bottom: -30px;
            font-size: 180px;
            opacity: 0.08;
            transform: rotate(-15deg);
        }

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

        .page-header h1 i {
            color: #f5c542;
        }

        .page-header p {
            font-size: 1rem;
            opacity: 0.9;
            max-width: 600px;
            margin: 0 auto;
            position: relative;
            z-index: 2;
        }

        .page-header .result-info {
            margin-top: 20px;
            background: rgba(255,255,255,0.15);
            backdrop-filter: blur(10px);
            padding: 8px 25px;
            border-radius: 50px;
            display: inline-block;
            font-size: 0.85rem;
            position: relative;
            z-index: 2;
            border: 1px solid rgba(255,255,255,0.08);
        }

        .page-header .result-info i {
            color: #f5c542;
        }

        /* ========== CONTAINER ========== */
        .container {
            max-width: 1280px;
            margin: 0 auto;
            padding: 40px 20px;
        }

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

        /* ========== CARD ========== */
        .card {
            background: white;
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 4px 15px rgba(0,0,0,0.06);
            transition: all 0.3s ease;
            border: 1px solid #e8edf2;
        }

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

        .news-image {
            height: 200px;
            overflow: hidden;
            background: #f1f5f9;
        }

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

        .card:hover .news-image img {
            transform: scale(1.05);
        }

        .news-content {
            padding: 20px;
        }

        .news-content .badge {
            display: inline-block;
            background: #dcfce7;
            color: #1a5f4b;
            padding: 3px 12px;
            border-radius: 20px;
            font-size: 0.6rem;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .news-date {
            font-size: 0.75rem;
            color: #94a3b8;
            margin-bottom: 8px;
        }

        .news-date i {
            margin-right: 4px;
        }

        .news-content h3 {
            font-size: 1.1rem;
            font-weight: 700;
            color: #0f3b2c;
            margin-bottom: 10px;
            line-height: 1.4;
        }

        .news-content p {
            color: #64748b;
            font-size: 0.9rem;
            line-height: 1.6;
            margin-bottom: 15px;
        }

        .read-more {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            color: #1a5f4b;
            text-decoration: none;
            font-weight: 600;
            font-size: 0.85rem;
            transition: all 0.3s ease;
        }

        .read-more:hover {
            gap: 12px;
            color: #0f3b2c;
        }

        /* ========== 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;
            font-size: 0.95rem;
        }

        .empty-state .back-btn {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            margin-top: 20px;
            padding: 12px 28px;
            background: #1a5f4b;
            color: white;
            border-radius: 40px;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .empty-state .back-btn:hover {
            background: #0f3b2c;
            gap: 14px;
            transform: translateY(-3px);
        }

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

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

        .footer-premium::after {
            content: '📚';
            position: absolute;
            bottom: 20px;
            right: 20px;
            font-size: 120px;
            opacity: 0.03;
            pointer-events: none;
        }

        .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: 50px;
        }

        .footer-col h3 {
            font-size: 1.1rem;
            font-weight: 700;
            margin-bottom: 25px;
            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: 20px;
        }

        .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;
            overflow: hidden;
        }

        .footer-logo .logo-icon img {
            width: 35px;
            height: 35px;
            object-fit: contain;
        }

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

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

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

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

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

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

        .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: 20px;
        }

        .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: 15px;
            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: 25px;
            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: 20px;
            margin-top: 20px;
            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) {
            .grid-3 {
                grid-template-columns: repeat(2, 1fr);
                gap: 20px;
            }
            .page-header {
                margin: 15px 20px 25px;
                padding: 35px 25px;
            }
            .page-header h1 {
                font-size: 2rem;
            }
            .footer-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: 30px;
            }
        }

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

            .header {
                padding: 10px 15px;
                flex-wrap: wrap;
                gap: 8px;
            }
            .header.scrolled {
                padding: 6px 15px;
            }

            .logo-text h2 {
                font-size: 0.75rem;
            }
            .logo-text p {
                font-size: 0.5rem;
            }
            .logo-icon {
                width: 36px;
                height: 36px;
            }
            .logo-icon i {
                font-size: 18px;
            }
            .icon-btn {
                width: 34px;
                height: 34px;
                font-size: 0.9rem;
            }
            .icon-btn .tooltip {
                display: none;
            }
            .search-form input {
                min-width: 80px;
                font-size: 11px;
                padding: 5px 10px;
            }
            .search-form .btn-search,
            .search-form .btn-reset {
                padding: 5px 10px;
                font-size: 11px;
            }
            .search-form .btn-reset span {
                display: none;
            }

            .page-header {
                margin: 15px;
                padding: 30px 20px;
                border-radius: 20px;
            }
            .page-header h1 {
                font-size: 1.6rem;
            }
            .page-header p {
                font-size: 0.9rem;
            }
            .page-header .result-info {
                font-size: 0.75rem;
                padding: 6px 18px;
            }

            .container {
                padding: 20px 15px;
            }

            .grid-3 {
                grid-template-columns: 1fr;
                gap: 18px;
            }

            .news-image {
                height: 180px;
            }
            .news-content {
                padding: 16px;
            }
            .news-content h3 {
                font-size: 1rem;
            }
            .news-content p {
                font-size: 0.85rem;
            }

            .empty-state {
                padding: 50px 20px;
            }
            .empty-state i {
                font-size: 50px;
            }
            .empty-state h3 {
                font-size: 1.1rem;
            }

            .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: 6px 10px;
            }
            .header.scrolled {
                padding: 4px 10px;
            }

            .logo-text h2 {
                font-size: 0.65rem;
            }
            .logo-text p {
                font-size: 0.45rem;
            }
            .logo-icon {
                width: 30px;
                height: 30px;
            }
            .logo-icon i {
                font-size: 16px;
            }
            .icon-btn {
                width: 30px;
                height: 30px;
                font-size: 0.8rem;
            }
            .search-form input {
                min-width: 60px;
                font-size: 10px;
                padding: 4px 8px;
            }
            .search-form .btn-search {
                padding: 4px 8px;
                font-size: 10px;
            }
            .search-form .btn-reset {
                padding: 4px 8px;
                font-size: 10px;
            }
            .search-form .btn-search span {
                display: none;
            }

            .page-header h1 {
                font-size: 1.3rem;
            }
            .page-header p {
                font-size: 0.8rem;
            }
            .page-header .result-info {
                font-size: 0.65rem;
                padding: 4px 14px;
            }

            .news-image {
                height: 160px;
            }
            .news-content {
                padding: 14px;
            }
            .news-content h3 {
                font-size: 0.95rem;
            }
            .news-content p {
                font-size: 0.8rem;
            }
            .read-more {
                font-size: 0.8rem;
            }
            .footer-premium {
                padding-top: 40px;
                margin-top: 40px;
            }
            .footer-grid {
                gap: 20px;
            }
            .visitor-badge {
                font-size: 0.6rem;
            }
        }
    </style>
</head>
<body>

<!-- ========== HEADER ========== -->
<div class="header" id="mainHeader">
    <div class="logo-area">
        <div class="logo-icon">
            <?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">
            <h2>DINAS KEARSIPAN<br>KABUPATEN SOLOK SELATAN</h2>
            <p>Dinas Perpustakaan dan Arsip Daerah</p>
        </div>
    </div>
    
    <div class="header-actions">
         <!-- Form Pencarian -->
        <form class="search-form" action="berita.php" method="GET" id="searchForm">
            <input type="text" name="keyword" placeholder="Cari berita..." value="<?php echo htmlspecialchars($keyword); ?>" id="searchInput">
            <button type="submit" class="btn-search">
                <i class="fas fa-search"></i>
                <span>Cari</span>
            </button>
            <?php if($keyword != ''): ?>
            <button type="button" class="btn-reset" onclick="resetSearch()">
                <i class="fas fa-times"></i>
                <span>Reset</span>
            </button>
            <?php endif; ?>
        </form>
        <a href="dashboard.php" class="icon-btn">
            <i class="fas fa-home"></i>
            <span class="tooltip">Dashboard</span>
        </a>
        
       
        
        <a href="layanan_arsip.php" class="icon-btn">
            <i class="fas fa-concierge-bell"></i>
            <span class="tooltip">Layanan</span>
        </a>
        
        <a href="javascript:history.back()" class="icon-btn">
            <i class="fas fa-arrow-left"></i>
            <span class="tooltip">Kembali</span>
        </a>
    </div>
</div>

<!-- ========== PAGE HEADER ========== -->
<div class="page-header" data-aos="fade-up">
    <h1>Berita & Informasi</h1>
    <p>Dapatkan informasi terbaru seputar kegiatan dan layanan Dinas Arsip Solok Selatan</p>
    <div class="result-info">
        <i class="fas fa-newspaper"></i> 
        <?php if($keyword != ''): ?>
            Hasil pencarian untuk "<strong><?php echo htmlspecialchars($keyword); ?></strong>" - 
        <?php endif; ?>
        <strong><?php echo $total_berita; ?></strong> berita ditemukan
    </div>
</div>

<!-- ========== CONTENT ========== -->
<div class="container">
    <?php if(mysqli_num_rows($query) > 0): ?>
        <div class="grid-3">
            <?php while($data = mysqli_fetch_array($query)):
                $gambarArray = explode(',', $data['gambar']);
                $gambarPertama = trim($gambarArray[0]);
            ?>
            <div class="card" data-aos="fade-up" data-aos-delay="50">
                <div class="news-image">
                    <?php if(!empty($gambarPertama) && file_exists("img/".$gambarPertama)): ?>
                        <img src="img/<?php echo $gambarPertama; ?>" alt="<?php echo htmlspecialchars($data['judul']); ?>" loading="lazy">
                    <?php else: ?>
                        <img src="https://placehold.co/600x400/1a5f4b/white?text=DPAD+News" alt="Default Image">
                    <?php endif; ?>
                </div>
                <div class="news-content">
                    <span class="badge"><i class="fas fa-tag"></i> Berita</span>
                    <div class="news-date">
                        <i class="far fa-calendar-alt"></i> <?php echo date('d F Y', strtotime($data['tanggal'])); ?>
                    </div>
                    <h3><?php echo htmlspecialchars($data['judul']); ?></h3>
                    <p><?php echo substr(strip_tags($data['isi']), 0, 120); ?>...</p>
                    <a href="detail_berita.php?id=<?php echo $data['id']; ?>" class="read-more">
                        Baca Selengkapnya <i class="fas fa-arrow-right"></i>
                    </a>
                </div>
            </div>
            <?php endwhile; ?>
        </div>
    <?php else: ?>
        <div class="empty-state" data-aos="fade-up">
            <i class="fas fa-search"></i>
            <h3>Berita Tidak Ditemukan</h3>
            <p>Maaf, tidak ada berita yang sesuai dengan kata kunci "<strong><?php echo htmlspecialchars($keyword); ?></strong>"</p>
            <a href="berita.php" class="back-btn">
                <i class="fas fa-arrow-left"></i> Lihat Semua Berita
            </a>
        </div>
    <?php endif; ?>
</div>

<!-- ========== FOOTER PREMIUM ========== -->
<footer class="footer-premium">
    <div class="footer-container">
        <div class="footer-grid">
            <!-- TENTANG KAMI -->
            <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 Kearsipan 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>

            <!-- MENU CEPAT -->
            <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>

            <!-- LAYANAN -->
            <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>

            <!-- LOKASI & KONTAK -->
            <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, Solok Selatan</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>

        <!-- BOTTOM FOOTER -->
        <div class="footer-bottom">
            <div>
                <p>&copy; <?php echo date('Y'); ?> Dinas Perpustakaan dan Arsip Daerah Kabupaten Solok Selatan</p>
                <p style="margin-top: 5px;">All Rights Reserved | <a>Kebijakan Privasi</a> | <a>Sitemap</a></p>
            </div>
            <div>
                <p>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>
        </div>
        
        <!-- DEVELOPER CREDIT -->
        <div class="dev-credit">
            Developed by <a href="https://www.pnp.ac.id/download/psdku-solok-selatan/" target="_blank">PSDKU Solok Selatan</a>
            <span style="margin: 0 8px; opacity: 0.3;">|</span>
            <span style="opacity: 0.7;">Version 1.0</span>
        </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');
        }
    });

    // ========== RESET SEARCH ==========
    function resetSearch() {
        window.location.href = 'berita.php';
    }

    // ========== SEARCH ON ENTER ==========
    document.getElementById('searchInput').addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
            document.getElementById('searchForm').submit();
        }
    });
</script>
</body>
</html>