<?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'; ?></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-box-seam brand-icon"></i>
                    <span>InvAnalytics</span>
                </div>
            </div>
            <nav class="sidebar-menu">
                <div class="menu-section">
                    <div class="menu-section-title">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="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="procurement.php" class="menu-item <?php echo basename($_SERVER['PHP_SELF']) === 'procurement.php' ? 'active' : ''; ?>">
                        <i class="bi bi-cart menu-icon"></i>
                        <span>Procurement</span>
                    </a>
                    <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>
                    <?php if (hasRole(['admin', 'manager'])): ?>
                    <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>
                    <?php endif; ?>
                    <?php if (hasRole(['admin'])): ?>
                    <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>Users</span>
                    </a>
                    <?php endif; ?>
                </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 ?? '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'] ?? 'User'); ?></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">
