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

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

// Ambil data visi misi
$query = mysqli_query($koneksi, "SELECT * FROM visi_misi WHERE id='1'");
$data = mysqli_fetch_assoc($query);

// Default jika database kosong
$visi = $data['visi'] ?? "Terwujudnya masyarakat Solok Selatan yang cerdas, literat, dan berbudaya melalui pelayanan perpustakaan dan kearsipan modern.";

$misi = $data['misi'] ?? "Meningkatkan budaya gemar membaca masyarakat|Mengembangkan layanan perpustakaan berbasis digital|Meningkatkan pengelolaan arsip daerah yang tertib dan modern|Meningkatkan kualitas pelayanan publik di bidang perpustakaan dan kearsipan";

// Ubah format misi dari pipe (|) menjadi baris baru untuk textarea
$misi_textarea = str_replace("|", "\n", $misi);

// Proses update data
if(isset($_POST['submit'])){
    $visi = mysqli_real_escape_string($koneksi, $_POST['visi']);
    
    // Ambil misi dari form (per baris) lalu gabung dengan pipe (|)
    $misi_raw = $_POST['misi'];
    // Pisahkan per baris
    $misi_lines = explode("\n", $misi_raw);
    // Hapus spasi kosong di awal/akhir tiap baris
    $misi_lines = array_map('trim', $misi_lines);
    // Filter baris yang kosong
    $misi_lines = array_filter($misi_lines);
    // Gabungkan kembali dengan pipe (|) untuk disimpan ke database
    $misi_simpan = implode("|", $misi_lines);
    
    // Cek apakah data sudah ada
    $check = mysqli_query($koneksi, "SELECT * FROM visi_misi WHERE id='1'");
    
    if(mysqli_num_rows($check) > 0){
        // Update data yang sudah ada
        $query = "UPDATE visi_misi SET visi='$visi', misi='$misi_simpan' WHERE id='1'";
    } else {
        // Insert data baru
        $query = "INSERT INTO visi_misi (id, visi, misi) VALUES ('1', '$visi', '$misi_simpan')";
    }
    
    if(mysqli_query($koneksi, $query)){
        echo "<script>
            alert('✅ Visi & Misi berhasil diperbarui!');
            window.location='edit_visi_misi.php';
        </script>";
    } else {
        echo "<script>
            alert('❌ Gagal memperbarui data! Error: " . mysqli_error($koneksi) . "');
        </script>";
    }
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Edit Visi & Misi | Admin DPAD</title>
    
    <!-- Google Fonts -->
    <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">
    
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        .card-header {
            background: linear-gradient(135deg, #0a3d32, #1a5f4b);
            padding: 25px 30px;
            color: white;
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: relative;
        }

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

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

        .card-header .title-section i {
            font-size: 2rem;
            color: #f5c542;
        }

        .card-header .title-section h3 {
            font-size: 1.5rem;
            font-weight: 700;
            font-family: 'Playfair Display', serif;
        }

        .card-header .title-section p {
            opacity: 0.85;
            font-size: 0.85rem;
            margin-top: 4px;
        }

        .card-header .status-badge {
            font-size: 0.65rem;
            background: rgba(255,255,255,0.15);
            color: white;
            padding: 4px 14px;
            border-radius: 20px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 6px;
            backdrop-filter: blur(10px);
        }

        .card-body {
            padding: 30px;
        }

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

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

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

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

        .form-group .hint {
            font-size: 0.75rem;
            color: #94a3b8;
            margin-top: 6px;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .form-group .hint i {
            color: #94a3b8;
        }

        .form-control {
            width: 100%;
            padding: 14px 18px;
            border: 2px solid #e5e9f0;
            border-radius: 12px;
            font-family: 'Inter', sans-serif;
            font-size: 0.95rem;
            transition: all 0.3s ease;
            background: #fafbfc;
            color: #1e293b;
            resize: vertical;
            min-height: 120px;
            line-height: 1.6;
        }

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

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

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

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

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

        /* ========== PREVIEW BOX ========== */
        .preview-box {
            background: #f8fafc;
            border-radius: 12px;
            padding: 20px;
            margin-top: 15px;
            border: 1px solid #e2e8f0;
            display: none;
        }

        .preview-box.active {
            display: block;
            animation: fadeUp 0.4s ease;
        }

        @keyframes fadeUp {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .preview-box h4 {
            font-size: 0.9rem;
            color: #1a5f4b;
            margin-bottom: 15px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .preview-misi {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .preview-item {
            display: flex;
            align-items: flex-start;
            gap: 12px;
            padding: 8px 0;
            border-bottom: 1px dashed #e2e8f0;
        }

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

        .preview-number {
            width: 28px;
            height: 28px;
            background: #1a5f4b;
            color: white;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.75rem;
            font-weight: 700;
            flex-shrink: 0;
        }

        .preview-text {
            color: #334155;
            font-size: 0.85rem;
            line-height: 1.5;
        }

        /* ========== BUTTONS ========== */
        .btn-preview {
            background: #f1f5f9;
            color: #1a5f4b;
            border: 1px solid #e2e8f0;
            padding: 8px 18px;
            border-radius: 10px;
            cursor: pointer;
            font-size: 0.8rem;
            transition: all 0.3s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }

        .btn-preview:hover {
            background: #e2e8f0;
            transform: translateY(-2px);
        }

        .btn-group {
            display: flex;
            gap: 15px;
            margin-top: 25px;
        }

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

        .btn-submit:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 30px rgba(10,61,50,0.3);
        }

        .btn-submit i {
            font-size: 1.1rem;
        }

        .btn-cancel {
            flex: 1;
            padding: 14px 24px;
            border-radius: 12px;
            font-size: 0.95rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            border: 2px solid #e5e9f0;
            background: #fff;
            color: #64748b;
            text-decoration: none;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        .btn-cancel:hover {
            background: #f8fafc;
            border-color: #cbd5e1;
            color: #1e293b;
        }

        /* ========== RESPONSIVE SIDEBAR ========== */
        @media (max-width: 768px) {
            .sidebar {
                width: 72px;
            }
            
            .sidebar:hover {
                width: 260px;
            }
            
            .sidebar:hover .logo-text h2,
            .sidebar:hover .logo-text p,
            .sidebar:hover .logo-text .subtitle,
            .sidebar:hover .nav-text {
                display: block;
            }
            
            .logo {
                padding: 20px 0;
            }
            
            .logo-img {
                width: 48px;
                height: 48px;
            }
            
            .logo-img img {
                width: 34px;
                height: 34px;
            }
            
            .logo-text h2,
            .logo-text p,
            .logo-text .subtitle,
            .nav-text {
                display: none;
            }
            
            .sidebar:hover .logo {
                padding: 30px 15px;
            }
            
            .sidebar:hover .logo-img {
                width: 75px;
                height: 75px;
                margin: 0 auto 15px;
            }
            
            .sidebar:hover .logo-img img {
                width: 52px;
                height: 52px;
            }
            
            .nav-item {
                justify-content: center;
                padding: 12px;
                margin-bottom: 8px;
            }
            
            .sidebar:hover .nav-item {
                justify-content: flex-start;
                padding: 12px 16px;
            }
            
            .nav-item .nav-icon {
                margin: 0;
            }
            
            .nav-footer {
                padding: 15px 0;
            }
            
            .sidebar:hover .nav-footer {
                padding: 20px 15px;
            }
            
            .main-content {
                margin-left: 72px;
                padding: 15px;
            }
            
            .top-header {
                flex-direction: column;
                text-align: center;
                gap: 10px;
                padding: 15px 20px;
            }
            
            .card-body {
                padding: 20px;
            }
            
            .card-header {
                padding: 20px 24px;
                flex-wrap: wrap;
                gap: 8px;
                flex-direction: column;
                text-align: center;
            }
            
            .card-header .title-section {
                flex-direction: column;
                text-align: center;
            }
            
            .card-header .title-section h3 {
                font-size: 1.2rem;
            }
            
            .card-header .status-badge {
                display: none;
            }
            
            .btn-group {
                flex-direction: column;
            }
            
            .btn-submit {
                width: 100%;
            }
            
            .btn-cancel {
                width: 100%;
            }
            
            .top-header .page-title .badge {
                display: none;
            }
        }

        @media (max-width: 480px) {
            .main-content {
                margin-left: 72px;
                padding: 10px;
            }
            
            .card-body {
                padding: 16px;
            }
            
            .form-control {
                padding: 10px 14px;
                font-size: 0.85rem;
            }
            
            .preview-box {
                padding: 15px;
            }
            
            .preview-item {
                padding: 6px 0;
            }
            
            .preview-text {
                font-size: 0.8rem;
            }
            
            .btn-submit {
                padding: 12px 18px;
                font-size: 0.85rem;
            }
            
            .btn-cancel {
                padding: 12px 18px;
                font-size: 0.85rem;
            }
        }
    </style>
</head>
<body>

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

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

        <a href="tambah_berita.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-plus-circle"></i></div>
            <div class="nav-text"><span>Tambah Berita</span><small>Publikasi berita baru</small></div>
        </a>

        <a href="../edit_berita.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-edit"></i></div>
            <div class="nav-text"><span>Edit Berita</span><small>Edit atau update berita</small></div>
        </a>

        <a href="arsip_poto.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-history"></i></div>
            <div class="nav-text"><span>Arsip Foto</span><small>Kelola arsip Poto</small></div>
        </a>

        <a href="edit_visi_misi.php" class="nav-item active">
            <div class="nav-icon"><i class="fas fa-edit"></i></div>
            <div class="nav-text"><span>Edit Visi & Misi</span><small>Kelolah Visi & Misi</small></div>
        </a>

        <a href="pengaduan_admin.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-comments"></i></div>
            <div class="nav-text"><span>Pengaduan</span><small>Kelola pengaduan</small></div>
        </a>

        <a href="tambah_video.php" class="nav-item">
            <div class="nav-icon"><i class="fas fa-video"></i></div>
            <div class="nav-text"><span>Video</span><small>Upload video baru</small></div>
        </a>
    </div>

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

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

    <!-- ========== TOP HEADER ========== -->
    <header class="top-header">
        <div class="page-title">
            <h1><i class="fas fa-edit"></i> Edit Visi & Misi</h1>
            <span class="badge"><i class="far fa-clock"></i> Perbarui</span>
        </div>
        <div class="header-actions">
            <div class="user-info">
                <i class="fas fa-user-circle"></i>
                <span>Admin</span>
            </div>
        </div>
    </header>

    <!-- ========== FORM CARD ========== -->
    <div class="form-card">
        <div class="card-header">
            <div class="title-section">
                <i class="fas fa-edit"></i>
                <div>
                    <h3>Edit Visi & Misi</h3>
                    <p>Perbarui visi dan misi Dinas Kearsipan Solok Selatan</p>
                </div>
            </div>
            <span class="status-badge"><i class="fas fa-check-circle"></i> Form Wajib Diisi</span>
        </div>

        <div class="card-body">

            <!-- Alert -->
            <div class="alert-custom">
                <i class="fas fa-info-circle"></i>
                <div>
                    <strong>Perhatian!</strong> Pastikan data yang dimasukkan sudah benar sebelum menyimpan. 
                    Visi dan misi akan ditampilkan di halaman depan website.
                </div>
            </div>

            <form method="POST" action="">
                <!-- Form Visi -->
                <div class="form-group">
                    <label>
                        <i class="fas fa-eye"></i> Visi <span class="required">*</span>
                    </label>
                    <textarea name="visi" class="form-control" rows="4" placeholder="Masukkan visi instansi..." required><?php echo htmlspecialchars($visi); ?></textarea>
                    <div class="hint">
                        <i class="fas fa-lightbulb"></i> Tuliskan visi instansi dengan jelas dan inspiratif
                    </div>
                </div>
                
                <!-- Form Misi -->
                <div class="form-group">
                    <label>
                        <i class="fas fa-list-check"></i> Misi <span class="required">*</span>
                    </label>
                    <textarea name="misi" id="misiText" class="form-control" rows="8" placeholder="Tulis setiap misi pada baris baru&#10;Contoh:&#10;Meningkatkan budaya gemar membaca&#10;Mengembangkan layanan digital&#10;Meningkatkan kualitas pelayanan" required><?php echo htmlspecialchars($misi_textarea); ?></textarea>
                    <div class="hint">
                        <i class="fas fa-lightbulb"></i> Tulis setiap misi pada baris baru (Enter). Setiap baris akan menjadi satu misi.
                    </div>
                </div>
                
                <!-- Tombol Preview -->
                <div style="text-align: right; margin-bottom: 15px;">
                    <button type="button" class="btn-preview" onclick="previewMisi()">
                        <i class="fas fa-eye"></i> Preview Misi
                    </button>
                </div>
                
                <!-- Preview Misi -->
                <div class="preview-box" id="previewBox">
                    <h4><i class="fas fa-eye"></i> Preview Misi</h4>
                    <div class="preview-misi" id="previewList"></div>
                </div>
                
                <!-- Tombol Aksi -->
                <div class="btn-group">
                    <button type="submit" name="submit" class="btn-submit">
                        <i class="fas fa-save"></i> Simpan Perubahan
                    </button>
                    <a href="edit_visi_misi.php" class="btn-cancel">
                        <i class="fas fa-times"></i> Batal
                    </a>
                </div>
            </form>

        </div>
    </div>

</div>

<script>
    // Auto preview saat halaman dimuat
    document.addEventListener('DOMContentLoaded', function() {
        previewMisi();
    });

    function previewMisi() {
        const misiText = document.getElementById('misiText').value;
        const lines = misiText.split('\n');
        const previewBox = document.getElementById('previewBox');
        const previewList = document.getElementById('previewList');
        
        // Filter garis kosong
        const validLines = lines.filter(line => line.trim() !== '');
        
        if(validLines.length === 0) {
            previewBox.classList.add('active');
            previewList.innerHTML = '<p style="color:#ef4444; font-size:0.85rem;"><i class="fas fa-exclamation-circle"></i> Tidak ada misi yang ditulis</p>';
        } else {
            let html = '';
            validLines.forEach((line, index) => {
                html += `
                    <div class="preview-item">
                        <div class="preview-number">${index + 1}</div>
                        <div class="preview-text">${escapeHtml(line.trim())}</div>
                    </div>
                `;
            });
            previewList.innerHTML = html;
            previewBox.classList.add('active');
        }
        
        previewBox.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
    }
    
    function escapeHtml(text) {
        const div = document.createElement('div');
        div.textContent = text;
        return div.innerHTML;
    }
</script>

</body>
</html>