<?php
require_once '../config.php';

// Ensure session is started
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Check if user is logged in
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header('Location: ' . BASE_URL . '/admin/login');
    exit;
}

$admin_name = $_SESSION['admin_name'] ?? $_SESSION['admin_username'] ?? 'Admin';

// Handle form submission
$message = '';
$message_type = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $conn = get_db_connection();

    // Define all color settings with defaults
    $color_settings = [
        'site_color' => '#F49321',
        'primary_color' => '#1C418C',
        'secondary_color' => '#68BA62',
        'text_color' => '#333333',
        'text_light_color' => '#707070',
        'background_color' => '#FFFFFF',
        'background_light_color' => '#F4F4F4',
        'border_color' => '#D1D1D1',
        'accent_color' => '#BD921E',
        'link_color' => '#18BCA9',
        'link_hover_color' => '#008A81',
        'button_bg_color' => '#F49321',
        'button_text_color' => '#FFFFFF',
        'button_hover_color' => '#d67d1a',
        'header_bg_color' => '#FFFFFF',
        'header_text_color' => '#333333',
        'footer_bg_color' => '#3A3A37',
        'footer_text_color' => '#FFFFFF',
    ];

    $success = true;
    foreach ($color_settings as $key => $default) {
        $value = trim($_POST[$key] ?? $default);
        if (!empty($value)) {
            $stmt = $conn->prepare("INSERT INTO website_settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
            $stmt->bind_param("sss", $key, $value, $value);
            if (!$stmt->execute()) {
                $success = false;
                break;
            }
            $stmt->close();
        }
    }

    if ($success) {
        $message = 'Color settings saved successfully!';
        $message_type = 'success';
        header('Location: ' . BASE_URL . '/admin/colors?success=1');
        exit;
    } else {
        $message = 'Error saving color settings. Please try again.';
        $message_type = 'error';
    }
}

// Check for success message
if (isset($_GET['success']) && $_GET['success'] == '1') {
    $message = 'Color settings saved successfully!';
    $message_type = 'success';
}

// Get current color settings from database
$conn = get_db_connection();
$settings_result = $conn->query("SELECT setting_key, setting_value FROM website_settings WHERE setting_key LIKE '%_color'");
$db_colors = [];
if ($settings_result) {
    while ($row = $settings_result->fetch_assoc()) {
        $db_colors[$row['setting_key']] = $row['setting_value'];
    }
}

// Default colors
$colors = [
    'site_color' => $db_colors['site_color'] ?? '#F49321',
    'primary_color' => $db_colors['primary_color'] ?? '#1C418C',
    'secondary_color' => $db_colors['secondary_color'] ?? '#68BA62',
    'text_color' => $db_colors['text_color'] ?? '#333333',
    'text_light_color' => $db_colors['text_light_color'] ?? '#707070',
    'background_color' => $db_colors['background_color'] ?? '#FFFFFF',
    'background_light_color' => $db_colors['background_light_color'] ?? '#F4F4F4',
    'border_color' => $db_colors['border_color'] ?? '#D1D1D1',
    'accent_color' => $db_colors['accent_color'] ?? '#BD921E',
    'link_color' => $db_colors['link_color'] ?? '#18BCA9',
    'link_hover_color' => $db_colors['link_hover_color'] ?? '#008A81',
    'button_bg_color' => $db_colors['button_bg_color'] ?? '#F49321',
    'button_text_color' => $db_colors['button_text_color'] ?? '#FFFFFF',
    'button_hover_color' => $db_colors['button_hover_color'] ?? '#d67d1a',
    'header_bg_color' => $db_colors['header_bg_color'] ?? '#FFFFFF',
    'header_text_color' => $db_colors['header_text_color'] ?? '#333333',
    'footer_bg_color' => $db_colors['footer_bg_color'] ?? '#3A3A37',
    'footer_text_color' => $db_colors['footer_text_color'] ?? '#FFFFFF',
];
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Color Settings - Crest Chimney</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-color: #2563eb;
            --primary-hover: #1d4ed8;
            --secondary-color: #64748b;
            --success-color: #10b981;
            --danger-color: #ef4444;
            --bg-primary: #0f172a;
            --bg-card: #ffffff;
            --bg-light: #f8fafc;
            --text-primary: #1e293b;
            --text-secondary: #64748b;
            --text-light: #94a3b8;
            --border-color: #e2e8f0;
            --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
            --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: var(--bg-light);
            color: var(--text-primary);
            line-height: 1.6;
            font-size: 14px;
        }

        .admin-wrapper {
            display: flex;
            min-height: 100vh;
        }

        .admin-sidebar {
            width: 260px;
            background: var(--bg-primary);
            color: white;
            position: fixed;
            height: 100vh;
            overflow-y: auto;
            box-shadow: var(--shadow-lg);
            z-index: 1000;
        }

        .sidebar-header {
            padding: 24px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .sidebar-header h1 {
            font-size: 20px;
            font-weight: 700;
            color: white;
            margin-bottom: 4px;
        }

        .sidebar-header p {
            font-size: 12px;
            color: var(--text-light);
        }

        .sidebar-nav {
            padding: 16px 0;
        }

        .nav-item {
            display: block;
            padding: 12px 20px;
            color: rgba(255, 255, 255, 0.7);
            text-decoration: none;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.2s;
            border-left: 3px solid transparent;
        }

        .nav-item:hover {
            background: rgba(255, 255, 255, 0.05);
            color: white;
        }

        .nav-item.active {
            background: rgba(37, 99, 235, 0.2);
            color: white;
            border-left-color: var(--primary-color);
        }

        .nav-item i {
            width: 20px;
            margin-right: 12px;
            text-align: center;
        }

        .admin-main {
            flex: 1;
            margin-left: 260px;
        }

        .admin-topbar {
            background: var(--bg-card);
            padding: 16px 32px;
            box-shadow: var(--shadow-sm);
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .topbar-title {
            font-size: 20px;
            font-weight: 600;
            color: var(--text-primary);
        }

        .topbar-user {
            display: flex;
            align-items: center;
            gap: 16px;
        }

        .user-info {
            text-align: right;
        }

        .user-name {
            font-size: 14px;
            font-weight: 600;
            color: var(--text-primary);
        }

        .user-role {
            font-size: 12px;
            color: var(--text-secondary);
        }

        .btn-logout {
            background: var(--danger-color);
            color: white;
            padding: 8px 16px;
            border-radius: 6px;
            text-decoration: none;
            font-size: 13px;
            font-weight: 500;
            transition: all 0.2s;
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }

        .btn-logout:hover {
            background: #dc2626;
            transform: translateY(-1px);
            box-shadow: var(--shadow-md);
        }

        .admin-content {
            padding: 32px;
        }

        .page-section {
            background: var(--bg-card);
            border-radius: 12px;
            padding: 32px;
            box-shadow: var(--shadow-sm);
            border: 1px solid var(--border-color);
        }

        .page-section h2 {
            font-size: 24px;
            font-weight: 700;
            color: var(--text-primary);
            margin-bottom: 32px;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .page-section h2 i {
            color: var(--primary-color);
        }

        .message {
            padding: 16px 20px;
            border-radius: 8px;
            margin-bottom: 24px;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .message.success {
            background: #d1fae5;
            color: #065f46;
            border: 1px solid #a7f3d0;
        }

        .message.error {
            background: #fee2e2;
            color: #991b1b;
            border: 1px solid #fecaca;
        }

        .message i {
            font-size: 18px;
        }

        .colors-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 24px;
            margin-top: 24px;
        }

        .color-group {
            background: var(--bg-light);
            padding: 20px;
            border-radius: 8px;
            border: 1px solid var(--border-color);
        }

        .color-group h3 {
            font-size: 14px;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 16px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .color-item {
            margin-bottom: 16px;
        }

        .color-item:last-child {
            margin-bottom: 0;
        }

        .color-item label {
            display: block;
            font-size: 13px;
            font-weight: 500;
            color: var(--text-secondary);
            margin-bottom: 8px;
        }

        .color-input-wrapper {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .color-input-wrapper input[type="color"] {
            width: 60px;
            height: 40px;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            cursor: pointer;
        }

        .color-input-wrapper input[type="text"] {
            flex: 1;
            padding: 8px 12px;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            font-size: 13px;
            font-family: 'Courier New', monospace;
        }

        .color-preview {
            width: 40px;
            height: 40px;
            border-radius: 6px;
            border: 1px solid var(--border-color);
            background: var(--preview-color);
        }

        .btn-save {
            background: var(--primary-color);
            color: white;
            padding: 12px 32px;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            margin-top: 24px;
        }

        .btn-save:hover {
            background: var(--primary-hover);
            transform: translateY(-1px);
            box-shadow: var(--shadow-md);
        }

        /* Mobile Responsive */
        @media (max-width: 768px) {
            .admin-sidebar {
                transform: translateX(-100%);
                transition: transform 0.3s;
            }

            .admin-sidebar.active {
                transform: translateX(0);
            }

            .admin-main {
                margin-left: 0;
                width: 100%;
            }

            .admin-topbar {
                padding: 16px;
            }

            .menu-toggle {
                display: block !important;
                background: none;
                border: none;
                font-size: 24px;
                cursor: pointer;
                color: var(--text-primary);
                margin-right: 12px;
            }

            .colors-grid {
                grid-template-columns: 1fr;
            }
        }

        .menu-toggle {
            display: none;
        }
    </style>
</head>

<body>
    <div class="admin-wrapper">
        <aside class="admin-sidebar">
            <div class="sidebar-header">
                <div style="display: flex; justify-content: space-between; align-items: center;">
                    <h1>Crest Chimney</h1>
                    <button id="closeSidebar"
                        style="background:none; border:none; color:white; font-size:20px; display:none;"
                        class="mobile-only"><i class="fas fa-times"></i></button>
                </div>
                <p>Admin Panel</p>
            </div>
            <nav class="sidebar-nav">
                <a href="dashboard" class="nav-item">
                    <i class="fas fa-home"></i>
                    Dashboard
                </a>
                <a href="services" class="nav-item">
                    <i class="fas fa-briefcase"></i>
                    Services
                </a>
                <a href="page-titles" class="nav-item">
                    <i class="fas fa-heading"></i>
                    Page Titles
                </a>
                <a href="settings" class="nav-item">
                    <i class="fas fa-cog"></i>
                    Settings
                </a>
                <a href="colors" class="nav-item active">
                    <i class="fas fa-palette"></i>
                    Colors
                </a>
            </nav>
        </aside>

        <main class="admin-main">
            <div class="admin-topbar">
                <div style="display: flex; align-items: center;">
                    <button class="menu-toggle" id="menuToggle">
                        <i class="fas fa-bars"></i>
                    </button>
                    <h2 class="topbar-title">Website Color Settings</h2>
                </div>
                <div class="topbar-user">
                    <div class="user-info">
                        <div class="user-name"><?php echo htmlspecialchars($admin_name); ?></div>
                        <div class="user-role">Administrator</div>
                    </div>
                    <a href="logout" class="btn-logout">
                        <i class="fas fa-sign-out-alt"></i>
                        Logout
                    </a>
                </div>
            </div>

            <div class="admin-content">
                <div class="page-section">
                    <h2><i class="fas fa-palette"></i> Website Color Customization</h2>

                    <?php if ($message): ?>
                        <div class="message <?php echo $message_type; ?>">
                            <i
                                class="fas fa-<?php echo $message_type === 'success' ? 'check-circle' : 'exclamation-circle'; ?>"></i>
                            <?php echo htmlspecialchars($message); ?>
                        </div>
                    <?php endif; ?>

                    <form method="POST" action="">
                        <div class="colors-grid">
                            <div class="color-group">
                                <h3>Primary Colors</h3>
                                <div class="color-item">
                                    <label>Site Color (Main Brand)</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="site_color"
                                            value="<?php echo htmlspecialchars($colors['site_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['site_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Primary Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="primary_color"
                                            value="<?php echo htmlspecialchars($colors['primary_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['primary_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Secondary Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="secondary_color"
                                            value="<?php echo htmlspecialchars($colors['secondary_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['secondary_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Accent Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="accent_color"
                                            value="<?php echo htmlspecialchars($colors['accent_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['accent_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                            </div>

                            <div class="color-group">
                                <h3>Text Colors</h3>
                                <div class="color-item">
                                    <label>Text Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="text_color"
                                            value="<?php echo htmlspecialchars($colors['text_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['text_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Text Light Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="text_light_color"
                                            value="<?php echo htmlspecialchars($colors['text_light_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['text_light_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Link Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="link_color"
                                            value="<?php echo htmlspecialchars($colors['link_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['link_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Link Hover Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="link_hover_color"
                                            value="<?php echo htmlspecialchars($colors['link_hover_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['link_hover_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                            </div>

                            <div class="color-group">
                                <h3>Background Colors</h3>
                                <div class="color-item">
                                    <label>Background Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="background_color"
                                            value="<?php echo htmlspecialchars($colors['background_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['background_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Background Light Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="background_light_color"
                                            value="<?php echo htmlspecialchars($colors['background_light_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['background_light_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Border Color</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="border_color"
                                            value="<?php echo htmlspecialchars($colors['border_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['border_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                            </div>

                            <div class="color-group">
                                <h3>Button Colors</h3>
                                <div class="color-item">
                                    <label>Button Background</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="button_bg_color"
                                            value="<?php echo htmlspecialchars($colors['button_bg_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['button_bg_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Button Text</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="button_text_color"
                                            value="<?php echo htmlspecialchars($colors['button_text_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['button_text_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Button Hover</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="button_hover_color"
                                            value="<?php echo htmlspecialchars($colors['button_hover_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['button_hover_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                            </div>

                            <div class="color-group">
                                <h3>Header & Footer</h3>
                                <div class="color-item">
                                    <label>Header Background</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="header_bg_color"
                                            value="<?php echo htmlspecialchars($colors['header_bg_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['header_bg_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Header Text</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="header_text_color"
                                            value="<?php echo htmlspecialchars($colors['header_text_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['header_text_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Footer Background</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="footer_bg_color"
                                            value="<?php echo htmlspecialchars($colors['footer_bg_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['footer_bg_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                                <div class="color-item">
                                    <label>Footer Text</label>
                                    <div class="color-input-wrapper">
                                        <input type="color" name="footer_text_color"
                                            value="<?php echo htmlspecialchars($colors['footer_text_color']); ?>"
                                            onchange="this.nextElementSibling.value=this.value">
                                        <input type="text"
                                            value="<?php echo htmlspecialchars($colors['footer_text_color']); ?>"
                                            onchange="this.previousElementSibling.value=this.value"
                                            pattern="^#[0-9A-Fa-f]{6}$">
                                    </div>
                                </div>
                            </div>
                        </div>

                        <button type="submit" class="btn-save">
                            <i class="fas fa-save"></i>
                            Save All Colors
                        </button>
                    </form>
                </div>
            </div>
        </main>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const menuToggle = document.getElementById('menuToggle');
            const sidebar = document.querySelector('.admin-sidebar');
            const closeSidebar = document.getElementById('closeSidebar');

            if (menuToggle) {
                menuToggle.addEventListener('click', function () {
                    sidebar.classList.toggle('active');
                    if (window.innerWidth <= 768) {
                        closeSidebar.style.display = 'block';
                    }
                });
            }

            if (closeSidebar) {
                closeSidebar.addEventListener('click', function () {
                    sidebar.classList.remove('active');
                });
            }
        });
    </script>
</body>

</html>