<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo defined('PAGE_TITLE') ? PAGE_TITLE . ' - ' : ''; ?><?php echo APP_NAME; ?></title>
    
    <!-- Bootstrap 5 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 6 -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <!-- Chart.js -->
    <link href="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.min.css" rel="stylesheet">
    <!-- Google Fonts - Inter -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="<?php echo BASE_URL; ?>/assets/css/style.css" rel="stylesheet">
    <style>
        body { padding-top: 80px; }
        .container-fluid { max-width: 1200px; margin: 0 auto; }
    </style>
</head>
<body>
    <?php if (isLoggedIn()): ?>
    <!-- Authenticated Header - Matches LMS header.partial.php -->
    <header class="header">
        <div class="nav-wrapper">
            <button type="button" class="mobile-menu-toggle" onclick="toggleMobileMenu()">
                <i class="fas fa-bars"></i>
            </button>

            <div class="logo">
                <a href="<?php echo BASE_URL; ?>/index.php">
                    <img src="<?php echo BASE_URL; ?>/<?php echo SITE_LOGO; ?>" alt="<?php echo APP_NAME; ?>" class="site-logo">
                    <?php echo APP_NAME; ?>
                </a>
            </div>

            <nav class="nav">
                <a href="<?php echo BASE_URL; ?>/index.php" class="nav-link <?php echo (basename($_SERVER['SCRIPT_NAME']) === 'index.php') ? 'active' : ''; ?>">
                    <i class="fas fa-tachometer-alt me-1"></i> Dashboard
                </a>
                <a href="<?php echo BASE_URL; ?>/home.php" class="nav-link <?php echo (basename($_SERVER['SCRIPT_NAME']) === 'home.php') ? 'active' : ''; ?>">
                    <i class="fas fa-home me-1"></i> Public Home
                </a>
                <a href="<?php echo BASE_URL; ?>/pages/surveys.php" class="nav-link <?php echo (strpos($_SERVER['SCRIPT_NAME'], 'surveys.php') !== false) ? 'active' : ''; ?>">
                    <i class="fas fa-poll me-1"></i> Surveys
                </a>
                <a href="<?php echo BASE_URL; ?>/pages/projects.php" class="nav-link <?php echo (strpos($_SERVER['SCRIPT_NAME'], 'projects.php') !== false) ? 'active' : ''; ?>">
                    <i class="fas fa-folder me-1"></i> Projects
                </a>
                <?php if (hasRole(['admin', 'analyst', 'researcher'])): ?>
                <a href="<?php echo BASE_URL; ?>/pages/analytics.php" class="nav-link <?php echo (strpos($_SERVER['SCRIPT_NAME'], 'analytics.php') !== false) ? 'active' : ''; ?>">
                    <i class="fas fa-chart-bar me-1"></i> Analytics
                </a>
                <?php endif; ?>
                <?php if (hasRole(['admin'])): ?>
                <a href="<?php echo BASE_URL; ?>/pages/users.php" class="nav-link <?php echo (strpos($_SERVER['SCRIPT_NAME'], 'users.php') !== false) ? 'active' : ''; ?>">
                    <i class="fas fa-users-cog me-1"></i> Users
                </a>
                <?php endif; ?>
                <a href="<?php echo BASE_URL; ?>/pages/reports.php" class="nav-link <?php echo (strpos($_SERVER['SCRIPT_NAME'], 'reports.php') !== false) ? 'active' : ''; ?>">
                    <i class="fas fa-file-alt me-1"></i> Reports
                </a>
                <div class="dropdown" style="display:inline-block;">
                    <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                        <i class="fas fa-user-circle me-1"></i> <?php echo htmlspecialchars($_SESSION['user_name'] ?? 'User'); ?>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li><a class="dropdown-item" href="<?php echo BASE_URL; ?>/pages/profile.php"><i class="fas fa-user me-2"></i>Profile</a></li>
                        <li><a class="dropdown-item" href="<?php echo BASE_URL; ?>/pages/settings.php"><i class="fas fa-cog me-2"></i>Settings</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item text-danger" href="<?php echo BASE_URL; ?>/pages/logout.php"><i class="fas fa-sign-out-alt me-2"></i>Logout</a></li>
                    </ul>
                </div>
            </nav>
        </div>
    </header>
    <?php else: ?>
    <!-- Public Header - Matches LMS header.partial.php -->
    <header class="header">
        <div class="nav-wrapper">
            <button type="button" class="mobile-menu-toggle" onclick="toggleMobileMenu()">
                <i class="fas fa-bars"></i>
            </button>

            <div class="logo">
                <a href="<?php echo BASE_URL; ?>/home.php">
                    <img src="<?php echo BASE_URL; ?>/<?php echo SITE_LOGO; ?>" alt="<?php echo APP_NAME; ?>" class="site-logo">
                    <?php echo APP_NAME; ?>
                </a>
            </div>

            <nav class="nav">
                <a href="<?php echo BASE_URL; ?>/home.php" class="nav-link <?php echo (basename($_SERVER['SCRIPT_NAME']) === 'home.php') ? 'active' : ''; ?>">
                    <i class="fas fa-home me-1"></i> Home
                </a>
                <a href="#surveys" class="nav-link">
                    <i class="fas fa-list me-1"></i> Available Surveys
                </a>
                <a href="#transparency" class="nav-link">
                    <i class="fas fa-shield-alt me-1"></i> Transparency
                </a>
                <a href="<?php echo BASE_URL; ?>/pages/login.php" class="nav-link">
                    <i class="fas fa-sign-in-alt me-1"></i> Login
                </a>
            </nav>
        </div>
    </header>
    <?php endif; ?>
    
    <div class="container-fluid">
        <?php if (isset($_SESSION['flash_message'])): ?>
        <div class="alert alert-<?php echo $_SESSION['flash_type'] ?? 'info'; ?> alert-dismissible fade show mt-3" role="alert">
            <?php echo $_SESSION['flash_message']; ?>
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
        <?php 
            unset($_SESSION['flash_message']);
            unset($_SESSION['flash_type']);
        endif; ?>