<?php
// Get the current script name to set the active link
$current_page = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Panel</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700&display=swap');
        /* Internal CSS for Premium Dashboard */
        :root {
            /* Houseboat Theme Colors */
            --sidebar-bg: #0a2d4d; /* Deep navy blue */
            --sidebar-link: #c5dceb; /* Light, muted blue */
            --sidebar-hover-bg: #1a4a73; /* Brighter blue for hover */
            --sidebar-hover-text: #ffffff;
            --sidebar-active-bg: #2780f0; /* A vibrant blue for active */
            --sidebar-active-text: #ffffff;
            --sidebar-active-border: #f0c419; /* Gold accent for active border */

            --page-bg: #f4f7f6;
            --text-primary: #ffffff;
            --text-secondary: #e2e8f0;
            --border-color: #dddfe2;
            --white: #fff;
            --danger: #c0392b; /* A deep red for actions like logout */

            /* Premium Dark Theme Additions */
            --content-card-bg: rgba(16, 42, 67, 0.85);
            --content-card-bg-hover: rgba(26, 60, 95, 0.9);
            --content-card-border: rgba(197, 220, 235, 0.2);
            --content-text-primary: #ffffff;
            --content-text-secondary: #e2e8f0;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            background-color: var(--page-bg);
            margin: 0;
            padding: 0;
            color: var(--text-primary);
        }
        
        .dashboard-layout {
            display: flex;
            min-height: 100vh;
        }
        .sidebar {
            width: 260px;
            background: linear-gradient(180deg, var(--sidebar-bg), #061a2e);
            color: var(--sidebar-link);
            padding: 1.5em;
            box-sizing: border-box;
            display: flex;
            flex-direction: column;
            flex-shrink: 0;
            position: fixed;
            top: 0;
            left: 0;
            height: 100vh;
            overflow-y: auto;
            z-index: 1000;
            box-shadow: 4px 0 15px rgba(0,0,0,0.1);
        }
        .sidebar-header {
            padding: 1em 0;
            margin-bottom: 1.5em;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            text-align: center;
        }
        .sidebar-header h2 {
            font-family: 'Playfair Display', serif;
            color: var(--white);
            margin: 0;
            font-size: 1.8em;
            letter-spacing: 1px;
            font-weight: 700;
        }
        .main-content {
            flex-grow: 1;
            padding: 2em 3em;
            /* Premium Houseboat Theme Background */
            background: linear-gradient(rgba(15, 23, 42, 0.5), rgba(15, 23, 42, 0.5)), url('https://images.unsplash.com/photo-1544551763-46a8723ba3f9?auto=format&fit=crop&q=80&w=2070') no-repeat center center fixed !important;
            background-size: cover !important;
            margin-left: 260px;
            min-height: 100vh;
        }

        /* Dashboard Specific Styles (now global) */
        .dashboard-hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 40px;
            border-radius: 15px;
            margin-bottom: 40px;
            box-shadow: 0 10px 20px rgba(118, 75, 162, 0.2);
            position: relative;
            overflow: hidden;
        }
        .dashboard-hero h1 {
            margin: 0;
            font-size: 2.2rem;
            font-weight: 700;
        }
        .dashboard-hero p {
            margin: 10px 0 0;
            font-size: 1.1rem;
            opacity: 0.9;
        }
        .dashboard-hero::after {
            content: '';
            position: absolute;
            top: -50px;
            right: -50px;
            width: 200px;
            height: 200px;
            background: rgba(255,255,255,0.1);
            border-radius: 50%;
        }
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 30px;
        }
        .stat-card {
            background: var(--content-card-bg);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            border: 1px solid var(--content-card-border);
        }
        .stat-card:hover {
            background: var(--content-card-bg-hover);
            transform: translateY(-10px);
            box-shadow: 0 15px 30px rgba(0,0,0,0.1);
        }
        .stat-content { position: relative; z-index: 2; }
        .stat-number {
            font-size: 3rem;
            font-weight: 800;
            color: var(--content-text-primary);
            line-height: 1;
            margin-bottom: 5px;
        }
        .stat-label {
            color: var(--content-text-secondary);
            font-size: 0.95rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
        .stat-icon-bg {
            position: absolute;
            right: -20px;
            bottom: -20px;
            font-size: 8rem;
            opacity: 0.1;
            transform: rotate(-15deg);
            transition: transform 0.3s ease;
            z-index: 1;
        }
        .stat-card:hover .stat-icon-bg {
            transform: rotate(0deg) scale(1.1);
        }
        .card-messages .stat-number, .card-messages .stat-icon-bg { color: #4299e1; }
        .card-gallery .stat-number, .card-gallery .stat-icon-bg { color: #ed8936; }
        .card-services .stat-number, .card-services .stat-icon-bg { color: #48bb78; }
        .card-blog .stat-number, .card-blog .stat-icon-bg { color: #9f7aea; }

        h1, h2 {
            color: var(--content-text-primary);
            margin-bottom: 1em;
        }
        a {
            color: #1877f2;
            text-decoration: none;
        }
        a:hover { text-decoration: none; }

        /* Sidebar Navigation */
        .dashboard-nav { flex-grow: 1; }
        .dashboard-nav ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .dashboard-nav li {
            margin-bottom: 5px;
        }
        .dashboard-nav a {
            display: flex;
            align-items: center;
            padding: 14px 20px;
            color: var(--sidebar-link);
            border-radius: 8px;
            font-weight: 500;
            transition: all 0.2s ease;
            text-align: left;
            border-left: 4px solid transparent;
        }
        .dashboard-nav a i {
            width: 20px;
            margin-right: 15px;
            font-size: 1.1em;
            text-align: center;
        }
        .dashboard-nav a:hover {
            background-color: var(--sidebar-hover-bg);
            color: var(--sidebar-hover-text);
        }
        .dashboard-nav a.active {
            background-color: var(--sidebar-active-bg);
            color: var(--sidebar-active-text);
            border-left-color: var(--sidebar-active-border);
            font-weight: 600;
            box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
        }
        .dashboard-nav a small { font-size: 0.8em; opacity: 0.7; }

        .sidebar-footer {
            margin-top: auto;
            padding-top: 1em;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }
        .sidebar-footer .logout-button {
            display: flex;
            align-items: center;
            width: 100%;
            padding: 14px 20px;
            color: var(--sidebar-link);
            border-radius: 8px;
            font-weight: 500;
            transition: all 0.2s ease;
            text-align: left;
            border: none;
            background: transparent;
            cursor: pointer;
        }
        .sidebar-footer .logout-button i {
            width: 20px;
            margin-right: 15px;
            font-size: 1.1em;
            text-align: center;
        }
        .sidebar-footer .logout-button:hover {
            background-color: var(--danger);
            color: var(--white);
        }

        /* General Content Styles */
        .content-wrapper {
            background: transparent;
            border: none;
            box-shadow: none;
            padding: 2em 3em;
        }
        .page-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5em;
            padding-bottom: 2rem;
            border-bottom: none;
        }
        .page-header h1 {
            margin: 0;
            color: #fff;
            text-shadow: 0 2px 4px rgba(0,0,0,0.3);
            font-family: 'Playfair Display', serif;
            font-size: 2.5rem;
        }
        .btn {
            background: #fff;
            color: #2563eb;
            font-weight: 600;
            padding: 12px 25px;
            border-radius: 50px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            transition: 0.3s;
            border: none;
            cursor: pointer;
            font-size: 14px;
        }
        .btn:hover {
            background: #2563eb;
            color: #fff;
            transform: translateY(-2px);
        }
        table {
            border-collapse: separate;
            border-spacing: 0 12px;
            width: 100%;
            margin: 0;
        }
        table thead th {
            background: transparent;
            color: var(--content-text-secondary);
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            font-size: 0.8rem;
            border: none;
            padding: 0 20px 10px;
            text-align: left;
        }
        table tbody tr {
            background: var(--content-card-bg);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
            transition: transform 0.2s, box-shadow 0.2s;
            color: var(--content-text-primary);
        }
        table tbody tr:hover {
            background: var(--content-card-bg-hover);
            transform: translateY(-3px);
            box-shadow: 0 10px 25px rgba(0,0,0,0.08);
        }
        table td {
            border: none;
            padding: 20px;
            vertical-align: middle;
        }
        table td:first-child { border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
        table td:last-child { border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
        table tr:nth-child(even) { background-color: var(--content-card-bg); }

        table img {
            width: 80px;
            height: 60px;
            object-fit: cover;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }

        /* Button Actions */
        .edit, .delete { padding: 8px 16px !important; border-radius: 20px !important; font-size: 0.85rem !important; transition: 0.2s; box-shadow: none !important; display: inline-block; text-decoration: none; }
        .edit { background: #eff6ff; color: #2563eb !important; }
        .edit:hover { background: #2563eb; color: white !important; }
        .delete { background: #fef2f2; color: #dc2626 !important; }
        .delete:hover { background: #dc2626; color: white !important; }

        form label { display: block; margin-bottom: 5px; font-weight: bold; }
        .form-group {
            margin-bottom: 1.25rem;
        }
        form input[type="text"], form input[type="password"], form textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid var(--content-card-border);
            border-radius: 6px;
            box-sizing: border-box;
            font-size: 16px;
            background-color: var(--sidebar-bg);
            color: var(--content-text-primary);
        }
        form input[type="file"] {
            width: 100%;
            padding: 12px;
            border: 1px dashed var(--content-card-border);
            border-radius: 6px;
            box-sizing: border-box;
            font-size: 16px;
            color: var(--content-text-secondary);
        }
        form textarea { min-height: 120px; resize: vertical; }
        form input[type="text"]:focus, form input[type="password"]:focus, form textarea:focus { outline: none; border-color: var(--sidebar-active-bg); box-shadow: 0 0 0 2px rgba(39, 128, 240, 0.3); }
        form button { width: 100%; padding: 12px; background-color: #1877f2; border: none; color: white; border-radius: 6px; cursor: pointer; font-size: 18px; font-weight: bold; margin-top: 10px; }
        form button:hover { background-color: #166fe5; }
        .error { color: #f8b4b4; background-color: rgba(220, 38, 38, 0.2); border: 1px solid rgba(220, 38, 38, 0.4); padding: 10px; border-radius: 4px; margin-bottom: 15px; text-align: left; }
        .success { color: #a7f3d0; background-color: rgba(16, 185, 129, 0.2); border: 1px solid rgba(16, 185, 129, 0.4); padding: 10px; border-radius: 4px; margin-bottom: 15px; text-align: left; }

        /* Contact Messages Page - Inbox Style */
        .message-list {
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }
        .message-card {
            background: var(--content-card-bg);
            backdrop-filter: blur(10px);
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
            border: 1px solid var(--content-card-border);
            transition: all 0.3s ease;
        }
        .message-card:hover {
            background: var(--content-card-bg-hover);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
            transform: translateY(-5px);
        }
        .message-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            padding: 1rem 1.5rem;
            border-bottom: 1px solid var(--content-card-border);
        }
        .message-sender {
            font-weight: 700;
            font-size: 1.1rem;
            color: var(--content-text-primary);
        }
        .message-subject {
            font-size: 0.9rem;
            color: var(--content-text-secondary);
            margin-top: 4px;
        }
        .message-date {
            font-size: 0.85rem;
            color: var(--content-text-secondary);
            flex-shrink: 0;
            margin-left: 1rem;
        }
        .message-body {
            padding: 1.5rem;
            line-height: 1.6;
            color: var(--content-text-secondary);
        }
        .message-body p {
            margin: 0;
        }
        .message-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem 1.5rem;
            background-color: rgba(0,0,0,0.2);
            border-top: 1px solid var(--content-card-border);
            border-bottom-left-radius: 10px;
            border-bottom-right-radius: 10px;
        }
        .message-contact {
            display: flex;
            align-items: center;
            gap: 1.5rem;
            font-size: 0.9rem;
        }
        .message-contact a, .message-contact span {
            color: var(--content-text-secondary);
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
        }
        .message-contact a:hover {
            color: var(--bs-primary);
            text-decoration: none;
        }
        .message-actions a.delete {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            padding: 8px 12px;
            border-radius: 6px;
            font-size: 0.9rem;
            font-weight: 500;
            transition: all 0.2s ease;
        }
        .message-actions a.delete:hover {
            background-color: var(--danger);
            color: var(--white);
            text-decoration: none;
        }

        /* Item Grid for Manage Pages (Services, Gallery, Blog) */
        .item-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 1.5rem;
        }

        .item-card {
            background: var(--content-card-bg);
            backdrop-filter: blur(10px);
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
            border: 1px solid var(--content-card-border);
            transition: all 0.3s ease;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .item-card:hover {
            background: var(--content-card-bg-hover);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
            transform: translateY(-5px);
        }

        .item-card-image {
            width: 100%;
            height: 200px;
            object-fit: cover;
            border-bottom: 1px solid var(--content-card-border);
        }

        .item-card-content {
            padding: 1rem 1.25rem;
            flex-grow: 1;
        }

        .item-card-title {
            font-weight: 600;
            font-size: 1.1rem;
            color: var(--content-text-primary);
            margin-bottom: 0;
        }

        .item-card-category {
            font-size: 0.85rem;
            color: var(--content-text-secondary);
            margin-top: 4px;
            display: block;
        }

        .item-card-actions {
            padding: 0.75rem 1.25rem;
            background-color: rgba(0,0,0,0.2);
            border-top: 1px solid var(--content-card-border);
            display: flex;
            gap: 0.5rem;
            justify-content: flex-end;
        }

        .item-card-actions a {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            padding: 6px 10px;
            border-radius: 6px;
            font-size: 0.85rem;
            font-weight: 500;
            transition: all 0.2s ease;
            text-decoration: none;
        }
        .item-card-actions a.edit { color: #3b82f6; }
        .item-card-actions a.edit:hover { background-color: #3b82f6; color: var(--white); text-decoration: none; }
        .item-card-actions a.delete { color: #ef4444; }
        .item-card-actions a.delete:hover { background-color: #ef4444; color: var(--white); text-decoration: none; }
    </style>
</head>
<body>
    <div class="dashboard-layout">
        <aside class="sidebar">
            <div class="sidebar-header">
                <a href="dashboard.php">
                    <img src="../img/oglogo2.png" alt="Cruise Kerala Logo" style="max-height: 60px; width:170px; background: #fff; padding: 5px; border-radius: 8px;">
                </a>
                <h2>Admin Panel</h2>
            </div>
            <nav class="dashboard-nav">
                <ul>
                        
                    <li><a href="dashboard.php" class="<?= ($current_page == 'dashboard.php') ? 'active' : '' ?>"><i class="fas fa-tachometer-alt"></i> <span>Dashboard</span></a></li>
                    <li><a href="contact_messages.php" class="<?= ($current_page == 'contact_messages.php') ? 'active' : '' ?>"><i class="fas fa-calendar-check"></i> <span>Bookings</span></a></li>
                    <li><a href="booking.php" class="<?= ($current_page == 'booking.php') ? 'active' : '' ?>"><i class="fas fa-envelope-open-text"></i> <span>Contact Messages</span></a></li>
                    <li><a href="manage_gallery.php" class="<?= ($current_page == 'manage_gallery.php' || $current_page == 'add_gallery.php') ? 'active' : '' ?>"><i class="fas fa-images"></i> <span>Gallery</span></a></li>
                    <li><a href="manage_service.php" class="<?= ($current_page == 'manage_service.php' || $current_page == 'add_service.php') ? 'active' : '' ?>"><i class="fas fa-concierge-bell"></i> <span>Services</span></a></li>
                    <li><a href="manage_blog.php" class="<?= ($current_page == 'manage_blog.php' || $current_page == 'add_blog.php' || $current_page == 'edit_blog.php') ? 'active' : '' ?>"><i class="fas fa-blog"></i> <span>Blog</span></a></li>
                    <li><a href="view_review.php" class="<?= ($current_page == 'view_review.php' || $current_page == 'add_review.php') ? 'active' : '' ?>"><i class="fas fa-star"></i> <span>Reviews</span></a></li>
                </ul>
            </nav>
            <div class="sidebar-footer">
                <a href="logout.php" class="logout-button"><i class="fas fa-sign-out-alt"></i> <span>Logout</span></a>
            </div>
        </aside>
        <main class="main-content">