<?php
// Admin layout with sidebar
$current_page = basename($_SERVER['PHP_SELF']);
$page_title = $page_title ?? 'AstroSidhi Admin';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $page_title; ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="assets/admin.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #1e293b;
            --secondary-color: #334155;
            --accent-color: #3b82f6;
            --success-color: #10b981;
            --danger-color: #ef4444;
            --info-color: #06b6d4;
            --warning-color: #f59e0b;
            --light-color: #f8fafc;
            --dark-color: #0f172a;
            --sidebar-width: 280px;
            --header-height: 70px;
        }

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

        body {
            font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 50%, #cbd5e1 100%);
            min-height: 100vh;
            overflow-x: hidden;
        }

        /* Sidebar */
        .sidebar {
            position: fixed;
            top: 0;
            left: 0;
            width: var(--sidebar-width);
            height: 100vh;
            background: linear-gradient(180deg, var(--primary-color) 0%, var(--dark-color) 100%);
            color: white;
            z-index: 1000;
            transition: all 0.3s ease;
            overflow-y: auto;
            box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
            border-right: 1px solid rgba(255, 255, 255, 0.1);
        }

        .sidebar.collapsed {
            width: 80px;
        }

        .sidebar-header {
            padding: 25px 20px;
            text-align: center;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            background: rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(10px);
        }

        .sidebar-header h3 {
            margin: 0;
            font-size: 1.6rem;
            font-weight: 700;
            color: var(--accent-color);
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        }

        .sidebar-header .logo {
            width: 50px;
            height: 50px;
            background: linear-gradient(135deg, var(--accent-color) 0%, #1d4ed8 100%);
            border-radius: 15px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 12px;
            box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
        }

        .sidebar-header .logo i {
            font-size: 24px;
            color: white;
        }

        .sidebar-menu {
            padding: 25px 0;
        }

        .menu-section {
            margin-bottom: 30px;
        }

        .menu-section-title {
            padding: 0 20px 10px;
            font-size: 0.75rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: rgba(255, 255, 255, 0.5);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 15px;
        }

        .menu-item {
            display: flex;
            align-items: center;
            padding: 16px 20px;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: all 0.3s ease;
            border-left: 4px solid transparent;
            position: relative;
            margin: 2px 10px;
            border-radius: 12px;
        }

        .menu-item:hover {
            background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(29, 78, 216, 0.1) 100%);
            color: white;
            text-decoration: none;
            border-left-color: var(--accent-color);
            transform: translateX(8px);
            box-shadow: 0 4px 15px rgba(59, 130, 246, 0.2);
        }

        .menu-item.active {
            background: linear-gradient(135deg, var(--accent-color) 0%, #1d4ed8 100%);
            color: white;
            border-left-color: #1d4ed8;
            font-weight: 600;
            box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
        }

        .menu-item i {
            width: 24px;
            margin-right: 15px;
            text-align: center;
            font-size: 18px;
            opacity: 0.9;
        }

        .menu-item.active i {
            opacity: 1;
        }

        .menu-text {
            transition: opacity 0.3s ease;
            font-size: 15px;
            font-weight: 500;
            flex: 1;
        }

        .sidebar.collapsed .menu-text {
            opacity: 0;
            width: 0;
            overflow: hidden;
        }

        .menu-badge {
            background: var(--danger-color);
            color: white;
            border-radius: 10px;
            padding: 2px 8px;
            font-size: 0.8rem;
            margin-left: auto;
        }

        /* Main Content */
        .main-content {
            margin-left: var(--sidebar-width);
            min-height: 100vh;
            transition: all 0.3s ease;
            background: transparent;
        }

        .main-content.expanded {
            margin-left: 70px;
        }

        /* Header */
        .header {
            background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 250, 252, 0.9) 100%);
            backdrop-filter: blur(20px);
            padding: 20px 35px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: sticky;
            top: 0;
            z-index: 999;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        }

        .header-left {
            display: flex;
            align-items: center;
        }

        .sidebar-toggle {
            background: linear-gradient(135deg, var(--accent-color) 0%, #1d4ed8 100%);
            border: none;
            font-size: 18px;
            color: white;
            cursor: pointer;
            margin-right: 25px;
            padding: 12px;
            border-radius: 12px;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
        }

        .sidebar-toggle:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
        }

        .page-title {
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--primary-color);
            margin: 0;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
            padding: 10px 20px;
            background: rgba(255, 255, 255, 0.8);
            border-radius: 15px;
            border: 1px solid rgba(0, 0, 0, 0.05);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        }

        .user-avatar {
            width: 45px;
            height: 45px;
            background: linear-gradient(135deg, var(--accent-color) 0%, #1d4ed8 100%);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 18px;
            box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
        }

        .user-details {
            display: flex;
            flex-direction: column;
        }

        .user-name {
            font-weight: 600;
            color: var(--primary-color);
            font-size: 15px;
            margin: 0;
        }

        .user-role {
            font-size: 13px;
            color: var(--secondary-color);
            opacity: 0.8;
            margin: 0;
        }

        /* Content Area */
        .content {
            padding: 35px;
            background: transparent;
        }

        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            border-radius: 20px;
            padding: 30px;
            margin-bottom: 25px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            padding: 30px;
            margin-bottom: 30px;
        }

        /* Responsive */
        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
                width: var(--sidebar-width);
            }

            .sidebar.show {
                transform: translateX(0);
            }

            .main-content {
                margin-left: 0;
            }

            .main-content.expanded {
                margin-left: 0;
            }

            .content {
                padding: 15px;
            }

            .content-card {
                padding: 20px;
                margin-bottom: 20px;
            }

            .header {
                padding: 15px 20px;
            }

            .page-title {
                font-size: 1.5rem;
            }
        }

        @media (max-width: 576px) {
            .header-right {
                gap: 10px;
            }

            .user-info {
                flex-direction: column;
                gap: 5px;
            }

            .user-avatar {
                width: 35px;
                height: 35px;
                font-size: 0.9rem;
            }
        }

        /* Custom Scrollbar */
        .sidebar::-webkit-scrollbar {
            width: 6px;
        }

        .sidebar::-webkit-scrollbar-track {
            background: rgba(255, 255, 255, 0.1);
        }

        .sidebar::-webkit-scrollbar-thumb {
            background: var(--accent-color);
            border-radius: 3px;
        }

        .sidebar::-webkit-scrollbar-thumb:hover {
            background: #e0a800;
        }

        /* Animation */
        .fade-in {
            animation: fadeIn 0.5s ease-in;
        }

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

        /* Mobile Overlay */
        .mobile-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 999;
            display: none;
        }

        .mobile-overlay.show {
            display: block;
        }
    </style>
</head>
<body>
    <!-- Mobile Overlay -->
    <div class="mobile-overlay" id="mobileOverlay"></div>

    <!-- Sidebar -->
    <div class="sidebar" id="sidebar">
        <div class="sidebar-header">
            <div class="logo">
                <i class="fas fa-star"></i>
            </div>
            <h3 class="sidebar-title">AstroSidhi</h3>
        </div>
        
        <nav class="sidebar-menu">
            <!-- Main Section -->
            <div class="menu-section">
                <div class="menu-section-title">Main</div>
            <a href="index.php" class="menu-item <?php echo $current_page == 'index.php' ? 'active' : ''; ?>">
                    <i class="fas fa-chart-line"></i>
                <span class="menu-text">Dashboard</span>
            </a>
            </div>
            
            <!-- Bookings Section -->
            <div class="menu-section">
                <div class="menu-section-title">Bookings</div>
            <a href="appointments.php" class="menu-item <?php echo $current_page == 'appointments.php' ? 'active' : ''; ?>">
                <i class="fas fa-calendar-check"></i>
                <span class="menu-text">Appointments</span>
            </a>
            
                <a href="slot_management.php" class="menu-item <?php echo $current_page == 'slot_management.php' ? 'active' : ''; ?>">
                    <i class="fas fa-calendar-alt"></i>
                    <span class="menu-text">Slot Management</span>
                </a>
            
                <a href="tatkal_management_panel.php" class="menu-item <?php echo $current_page == 'tatkal_management_panel.php' ? 'active' : ''; ?>">
                    <i class="fas fa-bolt"></i>
                    <span class="menu-text">Tatkal Management</span>
                </a>
                
                <a href="manage_booking_settings.php" class="menu-item <?php echo $current_page == 'manage_booking_settings.php' ? 'active' : ''; ?>">
                    <i class="fas fa-cogs"></i>
                    <span class="menu-text">Booking Settings</span>
                </a>
                
                <a href="consultation_types_management.php" class="menu-item <?php echo $current_page == 'consultation_types_management.php' ? 'active' : ''; ?>">
                    <i class="fas fa-phone"></i>
                    <span class="menu-text">Consultation Types</span>
                </a>
                
                <a href="setup_cron_job.php" class="menu-item <?php echo $current_page == 'setup_cron_job.php' ? 'active' : ''; ?>">
                    <i class="fas fa-clock"></i>
                    <span class="menu-text">Cron Job Setup</span>
                </a>
            </div>

            <!-- Payments Section -->
            <div class="menu-section">
                <div class="menu-section-title">Payments</div>
                <a href="payments.php" class="menu-item <?php echo $current_page == 'payments.php' ? 'active' : ''; ?>">
                    <i class="fas fa-credit-card"></i>
                    <span class="menu-text">Payment Records</span>
                </a>
            </div>

            <!-- Users & Content Section -->
            <div class="menu-section">
                <div class="menu-section-title">Users & Content</div>
            <a href="users.php" class="menu-item <?php echo $current_page == 'users.php' ? 'active' : ''; ?>">
                <i class="fas fa-users"></i>
                <span class="menu-text">Users</span>
            </a>
            
            <a href="notifications.php" class="menu-item <?php echo $current_page == 'notifications.php' ? 'active' : ''; ?>">
                <i class="fas fa-bell"></i>
                <span class="menu-text">Notifications</span>
            </a>
            
            <a href="blog_management.php" class="menu-item <?php echo $current_page == 'blog_management.php' ? 'active' : ''; ?>">
                <i class="fas fa-blog"></i>
                <span class="menu-text">Blog</span>
            </a>
            
            <a href="quotes_management.php" class="menu-item <?php echo $current_page == 'quotes_management.php' ? 'active' : ''; ?>">
                <i class="fas fa-quote-left"></i>
                <span class="menu-text">Quotes</span>
            </a>
            </div>

            <!-- Astrology Section -->
            <div class="menu-section">
                <div class="menu-section-title">Astrology</div>
                <a href="panchang_management.php" class="menu-item <?php echo $current_page == 'panchang_management.php' ? 'active' : ''; ?>">
                    <i class="fas fa-calendar-alt"></i>
                    <span class="menu-text">Panchang</span>
                </a>
            </div>

            <!-- System Section -->
            <div class="menu-section">
                <div class="menu-section-title">System</div>
                <a href="settings.php" class="menu-item <?php echo $current_page == 'settings.php' ? 'active' : ''; ?>">
                    <i class="fas fa-cog"></i>
                    <span class="menu-text">Settings</span>
            </a>
            
            <a href="help_settings_management.php" class="menu-item <?php echo $current_page == 'help_settings_management.php' ? 'active' : ''; ?>">
                <i class="fas fa-headset"></i>
                <span class="menu-text">Help Settings</span>
            </a>
            
            <a href="cron.php" class="menu-item <?php echo $current_page == 'cron.php' ? 'active' : ''; ?>">
                <i class="fas fa-tasks"></i>
                <span class="menu-text">Cron Jobs</span>
            </a>
            
                <a href="logout.php" class="menu-item" style="margin-top: 20px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 20px;">
                <i class="fas fa-sign-out-alt"></i>
                <span class="menu-text">Logout</span>
            </a>
            </div>
        </nav>
    </div>

    <!-- Main Content -->
    <div class="main-content" id="mainContent">
        <!-- Header -->
        <div class="header">
            <div class="header-left">
                <button class="sidebar-toggle" id="sidebarToggle">
                    <i class="fas fa-bars"></i>
                </button>
                <h1 class="page-title"><?php echo $page_title; ?></h1>
            </div>
            
            <div class="header-right">
                <div class="user-info">
                    <div class="user-avatar">
                        <i class="fas fa-user-shield"></i>
                    </div>
                    <div class="user-details">
                        <div class="user-name">Admin User</div>
                        <small class="user-role">Administrator</small>
                    </div>
                </div>
            </div>
        </div>

        <!-- Content -->
        <div class="content fade-in">
            <?php if (isset($content)): ?>
                <?php echo $content; ?>
            <?php endif; ?>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Sidebar toggle functionality
        const sidebar = document.getElementById('sidebar');
        const mainContent = document.getElementById('mainContent');
        const sidebarToggle = document.getElementById('sidebarToggle');
        const mobileOverlay = document.getElementById('mobileOverlay');

        if (sidebarToggle) {
            sidebarToggle.addEventListener('click', function() {
                sidebar.classList.toggle('collapsed');
                mainContent.classList.toggle('expanded');
            });
        }

        // Mobile overlay functionality
        if (mobileOverlay) {
            mobileOverlay.addEventListener('click', function() {
                sidebar.classList.remove('show');
                mobileOverlay.classList.remove('show');
            });
        }

        // Mobile sidebar toggle
        if (window.innerWidth <= 768 && sidebarToggle) {
            sidebarToggle.addEventListener('click', function() {
                sidebar.classList.toggle('show');
                mobileOverlay.classList.toggle('show');
            });
        }

        // Handle window resize
        window.addEventListener('resize', function() {
            if (window.innerWidth > 768) {
                sidebar.classList.remove('show');
                if (mobileOverlay) {
                    mobileOverlay.classList.remove('show');
                }
            }
        });

        // Auto-hide alerts after 5 seconds
        setTimeout(function() {
            const alerts = document.querySelectorAll('.alert');
            alerts.forEach(function(alert) {
                const bsAlert = new bootstrap.Alert(alert);
                bsAlert.close();
            });
        }, 5000);
    </script>
</body>
</html>
