<?php
session_start();

if (!isset($_SESSION['admin_id'])) {
    header("Location: login.php");
    exit();
}

if (isset($_GET['logout']) && $_GET['logout'] == '1') {
    session_unset();
    session_destroy();
    header("Location: login.php");
    exit();
}

$adminName = $_SESSION['admin_name'] ?? 'Admin';
?>
<!DOCTYPE html>
<html lang="en" id="htmlTag">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard - SMB Tech Solutions</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">

    <style>
        * {
            font-family: 'Poppins', sans-serif;
            box-sizing: border-box;
            transition: all 0.3s ease;
        }

        :root {
            --primary-red: #8b0000;
            --secondary-red: #c1121f;
            --dark-bg: #111111;
            --light-bg: #f8f9fc;
            --sidebar-dark: #161616;
            --card-shadow: 0 10px 25px rgba(0,0,0,0.10);
            --hover-shadow: 0 14px 28px rgba(0,0,0,0.16);
            --text-dark: #2c2c2c;
            --text-muted: #777;
            --white-soft: rgba(255,255,255,0.08);
            --white-border: rgba(255,255,255,0.12);
        }

        body {
            margin: 0;
            background: #f3f4f8;
            color: var(--text-dark);
            overflow-x: hidden;
        }

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

        .sidebar {
            width: 280px;
            background: linear-gradient(180deg, #4e0000, #7a0000, #aa0f1d);
            color: #fff;
            padding: 22px 16px;
            position: sticky;
            top: 0;
            height: 100vh;
            box-shadow: 8px 0 24px rgba(0,0,0,0.10);
        }

        .brand-area {
            text-align: center;
            margin-bottom: 28px;
            padding-bottom: 18px;
            border-bottom: 1px solid rgba(255,255,255,0.14);
        }

        .brand-logo {
            width: 68px;
            height: 68px;
            margin: 0 auto 12px;
            border-radius: 18px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(255,255,255,0.12);
            font-size: 28px;
            box-shadow: 0 10px 20px rgba(0,0,0,0.18);
        }

        .brand-title {
            font-size: 20px;
            font-weight: 700;
            margin-bottom: 4px;
        }

        .brand-subtitle {
            font-size: 12px;
            color: #ffdede;
            margin: 0;
        }

        .menu-title {
            font-size: 12px;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: #ffd4d4;
            margin: 18px 10px 10px;
        }

        .sidebar .nav-link {
            color: #fff;
            border-radius: 14px;
            padding: 12px 14px;
            margin-bottom: 8px;
            display: flex;
            align-items: center;
            gap: 12px;
            font-size: 14px;
            font-weight: 500;
            text-decoration: none;
            background: rgba(255,255,255,0.05);
            border: 1px solid rgba(255,255,255,0.06);
        }

        .sidebar .nav-link:hover,
        .sidebar .nav-link.active {
            background: rgba(255,255,255,0.16);
            transform: translateX(4px);
            box-shadow: 0 10px 18px rgba(0,0,0,0.16);
        }

        .sidebar .nav-link i {
            font-size: 18px;
            min-width: 22px;
        }

        .main-content {
            flex: 1;
            padding: 22px;
        }

        .topbar {
            background: #fff;
            border-radius: 20px;
            padding: 16px 20px;
            box-shadow: var(--card-shadow);
            margin-bottom: 22px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 15px;
            flex-wrap: wrap;
        }

        .topbar-left h1 {
            font-size: 24px;
            font-weight: 700;
            margin: 0 0 4px 0;
            color: var(--primary-red);
        }

        .topbar-left p {
            margin: 0;
            color: var(--text-muted);
            font-size: 14px;
        }

        .topbar-right {
            display: flex;
            align-items: center;
            gap: 12px;
            flex-wrap: wrap;
        }

        .welcome-badge {
            background: linear-gradient(135deg, #8b0000, #c1121f);
            color: #fff;
            padding: 10px 16px;
            border-radius: 14px;
            font-size: 14px;
            font-weight: 600;
            box-shadow: 0 10px 20px rgba(139, 0, 0, 0.15);
        }

        .logout-btn {
            background: #fff0f1;
            color: #b00020;
            border: 1px solid #ffd0d4;
            padding: 10px 16px;
            border-radius: 14px;
            text-decoration: none;
            font-size: 14px;
            font-weight: 600;
        }

        .logout-btn:hover {
            background: #b00020;
            color: #fff;
            border-color: #b00020;
        }

        .hero-card {
            background: linear-gradient(135deg, #660000, #8b0000, #c1121f);
            color: #fff;
            border-radius: 22px;
            padding: 28px 24px;
            box-shadow: 0 18px 35px rgba(139, 0, 0, 0.20);
            margin-bottom: 22px;
            position: relative;
            overflow: hidden;
        }

        .hero-card::before {
            content: "";
            position: absolute;
            right: -40px;
            top: -40px;
            width: 180px;
            height: 180px;
            background: rgba(255,255,255,0.07);
            border-radius: 50%;
        }

        .hero-card::after {
            content: "";
            position: absolute;
            bottom: -60px;
            right: 80px;
            width: 150px;
            height: 150px;
            background: rgba(255,255,255,0.06);
            border-radius: 50%;
        }

        .hero-card h2 {
            font-size: 28px;
            font-weight: 700;
            margin-bottom: 10px;
            position: relative;
            z-index: 1;
        }

        .hero-card p {
            margin: 0;
            max-width: 700px;
            color: #ffeaea;
            line-height: 1.7;
            font-size: 14px;
            position: relative;
            z-index: 1;
        }

        .stats-row {
            margin-bottom: 22px;
        }

        .stat-card {
            background: #fff;
            border-radius: 20px;
            padding: 20px;
            box-shadow: var(--card-shadow);
            height: 100%;
            position: relative;
            overflow: hidden;
        }

        .stat-card:hover {
            transform: translateY(-4px);
            box-shadow: var(--hover-shadow);
        }

        .stat-icon {
            width: 54px;
            height: 54px;
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 22px;
            color: #fff;
            margin-bottom: 14px;
            background: linear-gradient(135deg, #8b0000, #c1121f);
            box-shadow: 0 10px 20px rgba(139, 0, 0, 0.18);
        }

        .stat-title {
            font-size: 14px;
            color: var(--text-muted);
            margin-bottom: 8px;
        }

        .stat-value {
            font-size: 28px;
            font-weight: 700;
            color: var(--primary-red);
            line-height: 1;
        }

        .stat-note {
            margin-top: 10px;
            font-size: 13px;
            color: #666;
        }

        .section-card {
            background: #fff;
            border-radius: 20px;
            padding: 22px;
            box-shadow: var(--card-shadow);
            height: 100%;
        }

        .section-title {
            font-size: 18px;
            font-weight: 700;
            color: var(--primary-red);
            margin-bottom: 16px;
        }

        .quick-action-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 14px;
        }

        .quick-action-btn {
            background: linear-gradient(135deg, #fff5f5, #fff);
            border: 1px solid #f2d6d8;
            border-radius: 16px;
            padding: 16px;
            text-decoration: none;
            color: #333;
            display: block;
            box-shadow: 0 8px 18px rgba(0,0,0,0.05);
        }

        .quick-action-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 12px 22px rgba(0,0,0,0.10);
            border-color: #d19aa1;
        }

        .quick-action-btn i {
            font-size: 22px;
            color: var(--secondary-red);
            display: block;
            margin-bottom: 10px;
        }

        .quick-action-btn span {
            font-weight: 600;
            font-size: 14px;
            display: block;
            margin-bottom: 4px;
        }

        .quick-action-btn small {
            color: #777;
            font-size: 12px;
        }

        .activity-list {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .activity-item {
            display: flex;
            gap: 14px;
            padding: 14px 0;
            border-bottom: 1px solid #f0f0f0;
        }

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

        .activity-icon {
            width: 42px;
            height: 42px;
            border-radius: 12px;
            background: linear-gradient(135deg, #8b0000, #c1121f);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 17px;
            flex-shrink: 0;
        }

        .activity-content h6 {
            margin: 0 0 4px;
            font-size: 14px;
            font-weight: 600;
        }

        .activity-content p {
            margin: 0;
            color: #777;
            font-size: 13px;
            line-height: 1.6;
        }

        .activity-time {
            display: inline-block;
            margin-top: 6px;
            font-size: 12px;
            color: #999;
        }

        .footer-note {
            text-align: center;
            margin-top: 20px;
            color: #888;
            font-size: 13px;
        }

        .mobile-toggle {
            display: none;
        }

        @media (max-width: 991px) {
            .sidebar {
                position: fixed;
                left: -100%;
                top: 0;
                z-index: 999;
                width: 270px;
                transition: 0.35s ease;
            }

            .sidebar.show {
                left: 0;
            }

            .main-content {
                width: 100%;
                padding: 16px;
            }

            .mobile-toggle {
                display: inline-flex;
                align-items: center;
                justify-content: center;
                width: 44px;
                height: 44px;
                border: none;
                border-radius: 12px;
                background: linear-gradient(135deg, #8b0000, #c1121f);
                color: #fff;
                font-size: 20px;
                box-shadow: 0 10px 18px rgba(139, 0, 0, 0.18);
            }

            .topbar {
                padding: 14px 16px;
            }

            .topbar-left h1 {
                font-size: 21px;
            }

            .hero-card h2 {
                font-size: 24px;
            }
        }

        @media (max-width: 767px) {
            .quick-action-grid {
                grid-template-columns: 1fr;
            }

            .hero-card {
                padding: 22px 18px;
            }

            .hero-card h2 {
                font-size: 22px;
            }

            .stat-value {
                font-size: 24px;
            }

            .section-card {
                padding: 18px;
            }
        }

        .sidebar-backdrop {
            display: none;
        }

        @media (max-width: 991px) {
            .sidebar-backdrop.show {
                display: block;
                position: fixed;
                inset: 0;
                background: rgba(0,0,0,0.35);
                z-index: 998;
            }
        }
    </style>
</head>
<body>

<div class="sidebar-backdrop" id="sidebarBackdrop"></div>

<div class="dashboard-wrapper">

    <aside class="sidebar" id="sidebarMenu">
        <div class="brand-area">
            <div class="brand-logo">
                <i class="bi bi-grid-1x2-fill"></i>
            </div>
            <div class="brand-title">SMBTech Solutions</div>
            <p class="brand-subtitle">POS Management System</p>
        </div>

        <div class="menu-title">Main Menu</div>

        <a href="dashboard.php" class="nav-link active">
            <i class="bi bi-house-door-fill"></i>
            <span>Dashboard</span>
        </a>

        <a href="#" class="nav-link">
            <i class="bi bi-person-plus-fill"></i>
            <span>User Registration</span>
        </a>

        <a href="#" class="nav-link">
            <i class="bi bi-bank2"></i>
            <span>Bank Account</span>
        </a>

        <a href="#" class="nav-link">
            <i class="bi bi-truck"></i>
            <span>Supplier</span>
        </a>

        <a href="#" class="nav-link">
            <i class="bi bi-box-seam-fill"></i>
            <span>Products</span>
        </a>

        <a href="#" class="nav-link">
            <i class="bi bi-people-fill"></i>
            <span>Customer</span>
        </a>

        <a href="#" class="nav-link">
            <i class="bi bi-cash-coin"></i>
            <span>Expenses</span>
        </a>

        <a href="dashboard.php?logout=1" class="nav-link">
            <i class="bi bi-box-arrow-right"></i>
            <span>Logout</span>
        </a>
    </aside>

    <main class="main-content">
        <div class="topbar">
            <div class="topbar-left d-flex align-items-start gap-3">
                <button class="mobile-toggle" id="menuToggle">
                    <i class="bi bi-list"></i>
                </button>
                <div>
                    <h1>Dashboard</h1>
                    <p>Welcome to your POS management Super Dashboard.</p>
                </div>
            </div>

            <div class="topbar-right">
                <div class="welcome-badge">
                    <i class="bi bi-person-circle me-2"></i>
                    <?php echo htmlspecialchars($adminName); ?>
                </div>
                <a href="dashboard.php?logout=1" class="logout-btn">
                    <i class="bi bi-box-arrow-right me-1"></i> Logout
                </a>
            </div>
        </div>

        <div class="hero-card">
            <h2>Welcome Back, <?php echo htmlspecialchars($adminName); ?>!</h2>
            <p>
                Your system is ready. From here you can manage users, products, suppliers, customers,
                expenses, and other core business operations in one place with a clean and powerful interface.
            </p>
        </div>

        <div class="row stats-row g-4">
            <div class="col-xl-3 col-md-6">
                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="bi bi-people-fill"></i>
                    </div>
                    <div class="stat-title">Total Users</div>
                    <div class="stat-value">01</div>
                    <div class="stat-note">Currently active system users</div>
                </div>
            </div>

            <div class="col-xl-3 col-md-6">
                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="bi bi-box-seam-fill"></i>
                    </div>
                    <div class="stat-title">Products</div>
                    <div class="stat-value">00</div>
                    <div class="stat-note">Total registered products</div>
                </div>
            </div>

            <div class="col-xl-3 col-md-6">
                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="bi bi-people"></i>
                    </div>
                    <div class="stat-title">Customers</div>
                    <div class="stat-value">00</div>
                    <div class="stat-note">Registered customer records</div>
                </div>
            </div>

            <div class="col-xl-3 col-md-6">
                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="bi bi-cash-stack"></i>
                    </div>
                    <div class="stat-title">Today Sale</div>
                    <div class="stat-value">0</div>
                    <div class="stat-note">Today sales summary placeholder</div>
                </div>
            </div>
        </div>

        <div class="row g-4">
            <div class="col-lg-7">
                <div class="section-card">
                    <div class="section-title">Recent Activity</div>

                    <ul class="activity-list">
                        <li class="activity-item">
                            <div class="activity-icon">
                                <i class="bi bi-person-check-fill"></i>
                            </div>
                            <div class="activity-content">
                                <h6>Admin Login Successful</h6>
                                <p>You have successfully logged into the POS system dashboard.</p>
                                <span class="activity-time">Just now</span>
                            </div>
                        </li>

                        <li class="activity-item">
                            <div class="activity-icon">
                                <i class="bi bi-shield-lock-fill"></i>
                            </div>
                            <div class="activity-content">
                                <h6>System Security Active</h6>
                                <p>Session protection is enabled and unauthorized access is restricted.</p>
                                <span class="activity-time">Live</span>
                            </div>
                        </li>

                        <li class="activity-item">
                            <div class="activity-icon">
                                <i class="bi bi-graph-up-arrow"></i>
                            </div>
                            <div class="activity-content">
                                <h6>Dashboard Ready</h6>
                                <p>Your analytics and modules area are ready for the next development steps.</p>
                                <span class="activity-time">Today</span>
                            </div>
                        </li>

                        <li class="activity-item">
                            <div class="activity-icon">
                                <i class="bi bi-database-check"></i>
                            </div>
                            <div class="activity-content">
                                <h6>Database Connected</h6>
                                <p>The system can now be expanded with live totals and dynamic reporting.</p>
                                <span class="activity-time">Today</span>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>

            <div class="col-lg-5">
                <div class="section-card">
                    <div class="section-title">Quick Actions</div>

                    <div class="quick-action-grid">
                        <a href="#" class="quick-action-btn">
                            <i class="bi bi-person-plus-fill"></i>
                            <span>Add User</span>
                            <small>Create a new system user</small>
                        </a>

                        <a href="#" class="quick-action-btn">
                            <i class="bi bi-box2-fill"></i>
                            <span>Add Product</span>
                            <small>Insert new product record</small>
                        </a>

                        <a href="#" class="quick-action-btn">
                            <i class="bi bi-people-fill"></i>
                            <span>Add Customer</span>
                            <small>Create customer profile</small>
                        </a>

                        <a href="#" class="quick-action-btn">
                            <i class="bi bi-wallet2"></i>
                            <span>Add Expense</span>
                            <small>Record new expense entry</small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="footer-note">
            Web Application Development by <strong>SMB Tech Solutions</strong>
        </div>
    </main>
</div>

<script>
    const menuToggle = document.getElementById('menuToggle');
    const sidebarMenu = document.getElementById('sidebarMenu');
    const sidebarBackdrop = document.getElementById('sidebarBackdrop');

    menuToggle.addEventListener('click', function () {
        sidebarMenu.classList.toggle('show');
        sidebarBackdrop.classList.toggle('show');
    });

    sidebarBackdrop.addEventListener('click', function () {
        sidebarMenu.classList.remove('show');
        sidebarBackdrop.classList.remove('show');
    });
</script>

</body>
</html>