<?php
require_once __DIR__ . '/../config.php';
requireLogin();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $pageTitle ?? 'InvAnalytics Admin'; ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <link href="../assets/css/style.css" rel="stylesheet">
</head>
<body>
    <div class="app-layout">
        <aside class="sidebar">
            <div class="sidebar-header">
                <div class="sidebar-brand">
                    <i class="bi bi-shield-check brand-icon"></i>
                    <span>InvAnalytics</span>
                </div>
            </div>
            <nav class="sidebar-menu">
                <div class="menu-section">
                    <div class="menu-section-title">Main Menu</div>
                </div>
                <div class="menu-section">
                    <a href="dashboard.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'dashboard.php' ? 'active' : ''; ?>">
                        <i class="bi bi-speedometer2 menu-icon"></i>
                        <span>Dashboard</span>
                    </a>
                    <a href="orders.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'orders.php' ? 'active' : ''; ?>">
                        <i class="bi bi-cart menu-icon"></i>
                        <span>Orders</span>
                    </a>
                    <a href="grv.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'grv.php' ? 'active' : ''; ?>">
                        <i class="bi bi-box-seam menu-icon"></i>
                        <span>GRV</span>
                    </a>
                    <a href="transactions.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'transactions.php' ? 'active' : ''; ?>">
                        <i class="bi bi-arrow-left-right menu-icon"></i>
                        <span>Inventory Transactions</span>
                    </a>
                </div>
                <div class="menu-section">
                    <div class="menu-section-title">Management</div>
                </div>
                <div class="menu-section">
                    <a href="suppliers.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'suppliers.php' ? 'active' : ''; ?>">
                        <i class="bi bi-truck menu-icon"></i>
                        <span>Suppliers</span>
                    </a>
                    <a href="inventory.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'inventory.php' ? 'active' : ''; ?>">
                        <i class="bi bi-boxes menu-icon"></i>
                        <span>Inventory</span>
                    </a>
                    <a href="reports.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'reports.php' ? 'active' : ''; ?>">
                        <i class="bi bi-file-earmark-bar-graph menu-icon"></i>
                        <span>Reports</span>
                    </a>
                </div>
                <div class="menu-section">
                    <div class="menu-section-title">System</div>
                </div>
                <div class="menu-section">
                    <a href="users.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'users.php' ? 'active' : ''; ?>">
                        <i class="bi bi-people menu-icon"></i>
                        <span>User Management</span>
                    </a>
                    <a href="../index.php" class="menu-item">
                        <i class="bi bi-arrow-left-circle menu-icon"></i>
                        <span>Main System</span>
                    </a>
                </div>
            </nav>
            <div class="sidebar-footer">
                &copy; <?php echo date('Y'); ?> InvAnalytics
            </div>
        </aside>
        <div class="main-wrapper">
            <header class="topbar">
                <button class="sidebar-toggle" onclick="toggleSidebar()">
                    <i class="bi bi-list"></i>
                </button>
                <h1 class="topbar-title"><?php echo $pageTitle ?? 'Admin Dashboard'; ?></h1>
                <div class="topbar-actions">
                    <div class="user-menu">
                        <div class="user-avatar">
                            <?php echo strtoupper(substr($_SESSION['full_name'] ?? $_SESSION['username'] ?? 'A', 0, 1)); ?>
                        </div>
                        <div class="user-info">
                            <span class="user-name"><?php echo $_SESSION['full_name'] ?? $_SESSION['username']; ?></span>
                            <span class="user-role"><?php echo ucfirst($_SESSION['role'] ?? 'Admin'); ?></span>
                        </div>
                    </div>
                    <a href="../logout.php" class="btn-logout" title="Logout">
                        <i class="bi bi-box-arrow-right"></i>
                    </a>
                </div>
            </header>
            <main class="main-content">
