<?php
// Prevent direct access if session isn't started in the parent file
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
if (!isset($_SESSION['admin_id'])) {
    header("Location: login.php");
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Dashboard - MK Construction</title>
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="css/admin-style.css?v=<?= time() ?>">
</head>
<body>

<div class="admin-layout">
    <div id="sidebar-overlay"></div>
    
    <!-- Sidebar -->
    <aside class="sidebar">
        <div class="sidebar-header">
            <img src="../assets/img/mklogo.png" alt="MK Logo" class="sidebar-logo">
        </div>
        <ul class="sidebar-nav">
            <li><a href="index.php"><i class="fa-solid fa-gauge"></i> Dashboard</a></li>
            <li><a href="enquiries.php"><i class="fa-solid fa-envelope-open-text"></i> Enquiries</a></li>
            <li class="has-submenu">
                <a href="#" class="submenu-toggle"><i class="fa-solid fa-users-viewfinder"></i> Leads <i class="fa-solid fa-chevron-down ms-auto chevron"></i></a>
                <ul class="submenu">
                    <li><a href="leads.php"><i class="fa-solid fa-list" style="width:14px;"></i> All Leads</a></li>
                    <li><a href="lead_followups.php"><i class="fa-regular fa-calendar-check" style="width:14px;"></i> Follow-ups</a></li>
                    <li><a href="lead_pipeline.php"><i class="fa-solid fa-diagram-project" style="width:14px;"></i> Pipeline View</a></li>
                    <li><a href="lead_reports.php"><i class="fa-solid fa-chart-bar" style="width:14px;"></i> Reports</a></li>
                    <li><a href="lead_duplicates.php"><i class="fa-solid fa-copy" style="width:14px;"></i> Duplicate Finder</a></li>
                    <li><a href="lead_statuses.php"><i class="fa-solid fa-tags" style="width:14px;"></i> Pipeline Stages</a></li>
                    <li><a href="lead_sources.php"><i class="fa-solid fa-share-nodes" style="width:14px;"></i> Lead Sources</a></li>
                    <li><a href="lead_services.php"><i class="fa-solid fa-briefcase" style="width:14px;"></i> Manage Services</a></li>
                    <li><a href="lead_service_add_edit.php"><i class="fa-solid fa-plus-circle" style="width:14px;"></i> Add Service</a></li>
                    <li><a href="leads_junk.php"><i class="fa-solid fa-ban" style="width:14px;"></i> Junk Leads</a></li>
                </ul>
            </li>
            <li class="has-submenu">
                <a href="#" class="submenu-toggle"><i class="fa-solid fa-user-check"></i> Customers <i class="fa-solid fa-chevron-down ms-auto chevron"></i></a>
                <ul class="submenu">
                    <li><a href="customers.php">All Customers</a></li>
                </ul>
            </li>
            <li class="has-submenu">
                <a href="#" class="submenu-toggle"><i class="fa-solid fa-images"></i> Portfolio <i class="fa-solid fa-chevron-down ms-auto chevron"></i></a>
                <ul class="submenu">
                    <li><a href="portfolio_items.php">All Items</a></li>
                    <li><a href="portfolio_categories.php">Categories</a></li>
                    <li><a href="portfolio_subcategories.php">Subcategories</a></li>
                </ul>
            </li>
            <li class="has-submenu">
                <a href="#" class="submenu-toggle"><i class="fa-solid fa-newspaper"></i> Blogs <i class="fa-solid fa-chevron-down ms-auto chevron"></i></a>
                <ul class="submenu">
                    <li><a href="blog_posts.php">All Blogs</a></li>
                    <li><a href="blog_categories.php">Categories</a></li>
                    <li><a href="blog_subcategories.php">Subcategories</a></li>
                    <li><a href="blog_tags.php">Tags</a></li>
                </ul>
            </li>
            <li class="has-submenu">
                <a href="#" class="submenu-toggle"><i class="fa-solid fa-users-rectangle"></i> Meetings <i class="fa-solid fa-chevron-down ms-auto chevron"></i></a>
                <ul class="submenu">
                    <li><a href="meetings.php">All Meetings</a></li>
                    <li><a href="meeting_add_edit.php">Schedule Meeting</a></li>
                </ul>
            </li>
            <li class="has-submenu">
                <a href="#" class="submenu-toggle"><i class="fa-solid fa-user-tie"></i> Sales Agents <i class="fa-solid fa-chevron-down ms-auto chevron"></i></a>
                <ul class="submenu">
                    <li><a href="agent_dashboard.php"><i class="fa-solid fa-gauge" style="width:14px;"></i> Agent Dashboard</a></li>
                    <li><a href="sales_agents.php"><i class="fa-solid fa-users" style="width:14px;"></i> All Agents</a></li>
                    <li><a href="leads.php?unassigned=1"><i class="fa-solid fa-user-plus" style="width:14px;"></i> Assign Leads</a></li>
                    <li><a href="agent/login.php" target="_blank"><i class="fa-solid fa-arrow-up-right-from-square" style="width:14px;"></i> Agent Portal</a></li>
                </ul>
            </li>
            <li class="has-submenu">
                <a href="#" class="submenu-toggle"><i class="fa-regular fa-calendar-days"></i> Calendar <i class="fa-solid fa-chevron-down ms-auto chevron"></i></a>
                <ul class="submenu">
                    <li><a href="calendar.php">View Calendar</a></li>
                </ul>
            </li>
            <li><a href="#"><i class="fa-solid fa-file-lines"></i> Pages</a></li>
        </ul>
        <div class="sidebar-footer">
            <a href="logout.php" class="logout-btn"><i class="fa-solid fa-right-from-bracket"></i> Logout</a>
        </div>
    </aside>

    <!-- Main Content -->
    <main class="main-content">
        <header class="topbar">
            <div class="topbar-left">
                <button id="mobile-menu-btn" class="mobile-menu-btn">
                    <i class="fa-solid fa-bars"></i>
                </button>
                <h1>Dashboard</h1>
            </div>
            <div class="topbar-right">
                <div class="admin-profile">
                    <div class="avatar"><i class="fa-solid fa-user"></i></div>
                    <span>Welcome, <?= htmlspecialchars($_SESSION['admin_username'] ?? 'Admin') ?></span>
                </div>
            </div>
        </header>

        <!-- Mobile Bottom Nav (App Style) -->
        <nav class="mobile-bottom-nav">
            <a href="index.php" class="<?= basename($_SERVER['PHP_SELF']) == 'index.php' ? 'active' : '' ?>">
                <i class="fa-solid fa-gauge"></i>
                <span>Home</span>
            </a>
            <a href="leads.php" class="<?= basename($_SERVER['PHP_SELF']) == 'leads.php' ? 'active' : '' ?>">
                <i class="fa-solid fa-users-viewfinder"></i>
                <span>Leads</span>
            </a>
            <a href="lead_followups.php" class="<?= basename($_SERVER['PHP_SELF']) == 'lead_followups.php' ? 'active' : '' ?>">
                <i class="fa-regular fa-calendar-check"></i>
                <span>Tasks</span>
            </a>
            <a href="enquiries.php" class="<?= basename($_SERVER['PHP_SELF']) == 'enquiries.php' ? 'active' : '' ?>">
                <i class="fa-solid fa-envelope"></i>
                <span>Inbox</span>
            </a>
            <button onclick="document.getElementById('mobile-menu-btn').click()">
                <i class="fa-solid fa-bars"></i>
                <span>Menu</span>
            </button>
        </nav>
