<style>
    .top-navbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: #f8fafc;
        border-bottom: 1px solid #e2e8f0;
        z-index: 1000;
        height: 60px;
    }
    
    .navbar-container {
        max-width: 100%;
        margin: 0;
        padding: 0 24px;
        height: 100%;
        display: flex;
        align-items: stretch;
        justify-content: space-between;
    }
    
    .navbar-brand {
        display: flex;
        align-items: center;
        text-decoration: none;
        padding: 12px 0;
        margin-right: 7%;
    }
    
    .navbar-brand img {
        height: 36px;
        width: auto;
    }
    
    .navbar-menu {
        display: flex;
        align-items: stretch;
        gap: 0;
        list-style: none;
        margin: 0;
        padding: 0;
        height: 100%;
        flex: 1;
    }
    
    .navbar-menu li {
        margin: 0;
        height: 100%;
        display: flex;
        align-items: stretch;
    }
    
    .nav-link {
        display: flex;
        align-items: center;
        padding: 0 24px;
        color: #64748b;
        text-decoration: none;
        font-weight: 500;
        font-size: 14px;
        transition: all 0.2s ease;
        white-space: nowrap;
        background: transparent;
        border: none;
        border-bottom: 3px solid transparent;
        position: relative;
        height: 100%;
        min-width: 140px;
        justify-content: center;
    }
    
    .nav-link:hover {
        background: rgba(59, 130, 246, 0.05);
        color: #3b82f6;
        border-bottom-color: rgba(59, 130, 246, 0.3);
    }
    
    .nav-link.active {
        background: white;
        color: #1e293b;
        border-bottom-color: #3b82f6;
        font-weight: 600;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    .nav-link i {
        margin-right: 8px;
        font-size: 14px;
        opacity: 0.8;
    }
    
    .nav-link.active i {
        opacity: 1;
        color: #3b82f6;
    }
    
    /* Remove the old styles that are no longer needed */
    /* Add subtle animation for tab switching */
    .nav-link {
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* Tab content area styling */
    .tab-content-area {
        margin-top: 60px;
        background: white;
        min-height: calc(100vh - 60px);
    }
    
    .navbar-right {
        display: flex;
        align-items: center;
        gap: 16px;
        padding: 12px 0;
    }
    
    .user-info {
        display: flex;
        align-items: center;
        gap: 14px;
        padding:8px 18px;
        background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
        border-radius: 12px;
       /* border: 1px solid #e2e8f0; */
        transition: all 0.3s ease;
    }
    
    .user-info:hover {
        background: linear-gradient(135deg, #edf2f7 0%, #e2e8f0 100%);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }
    
    .user-avatar {
        width: 36px;
        height: 36px;
        border-radius: 11px;
        background: linear-gradient(135deg, #1a70b8 0%, #60e438 100%);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 16px;
        box-shadow: 0 3px 10px rgba(26, 112, 184, 0.3);
    }
    
    .user-details {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }
    
    .user-name {
        font-weight: 700;
        color: #1a202c;
        font-size: 15px;
        line-height: 1.2;
    }
    
    .user-role {
        font-size: 12px;
        color: #1a70b8;
        font-weight: 500;
        display: flex;
        align-items: center;
        gap: 4px;
    }
    
    .user-role i {
        font-size: 10px;
    }
    
    .btn-logout {
        background: linear-gradient(135deg, #1a70b8 0%, #60e438 100%);
        color: white;
        padding: 10px 24px;
        border-radius: 8px;
        text-decoration: none;
        font-weight: 600;
        font-size: 14px;
        transition: all 0.3s ease;
        display: inline-flex;
        align-items: center;
        border: none;
        cursor: pointer;
    }
    
    .btn-logout:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(26, 112, 184, 0.4);
        color: white;
    }
    
    .btn-logout i {
        margin-right: 8px;
    }
    
    .mobile-menu-toggle {
        display: none;
        background: none;
        border: none;
        font-size: 24px;
        color: #4a5568;
        cursor: pointer;
    }
    
    @media (max-width: 968px) {
        .navbar-menu {
            position: fixed;
            top: 60px;
            left: 0;
            right: 0;
            background: white;
            flex-direction: column;
            padding: 20px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            display: none;
            gap: 4px;
            height: auto;
        }
        
        .navbar-menu.active {
            display: flex;
        }
        
        .navbar-menu li {
            width: 100%;
            height: auto;
        }
        
        .nav-link {
            width: 100%;
            justify-content: flex-start;
            border-radius: 8px;
            border: 1px solid #e2e8f0;
            border-bottom: 1px solid #e2e8f0;
            margin-bottom: 4px;
            height: 48px;
            min-width: auto;
            background: #f8fafc;
        }
        
        .nav-link.active {
            border-bottom: 1px solid #3b82f6;
            background: white;
        }
        
        .mobile-menu-toggle {
            display: block;
        }
        
        .user-details {
            display: none;
        }
        
        .navbar-right {
            gap: 12px;
        }
        
        .navbar-container {
            align-items: center;
        }
    }
</style>

<nav class="top-navbar">
    <div class="navbar-container">
        <?php
        $currentDir = basename(dirname($_SERVER['PHP_SELF']));
        $assetPath = ($currentDir !== 'client') ? '../../' : '../';
        $dashboardPath = ($currentDir !== 'client') ? '../dashboard.php' : 'dashboard.php';
        
       $activePage = basename($_SERVER['PHP_SELF'], ".php");
        
        // Get user permissions
        try {
            $stmt = $pdo->prepare("SELECT userRole, permissions FROM tblclient WHERE clientId = ?");
            $stmt->execute([$_SESSION['clientId']]);
            $currentUser = $stmt->fetch();
            
            // If columns don't exist yet, grant all permissions for backward compatibility
            if(!isset($currentUser['userRole']) || $currentUser['userRole'] === null) {
                $isAdmin = true;
                $permissions = [
                    'enrollment' => true,
                    'calls' => true,
                    'reimbursement' => true,
                    'tasks' => true,
                    'documents' => true,
                    'reports' => true
                ];
            } else {
                $isAdmin = ($currentUser['userRole'] === 'admin');
                $permissions = json_decode($currentUser['permissions'] ?? '{}', true);
                
                // Admin has access to everything
                if($isAdmin) {
                    $permissions = [
                        'enrollment' => true,
                        'calls' => true,
                        'reimbursement' => true,
                        'tasks' => true,
                        'documents' => true,
                        'reports' => true
                    ];
                }
            }
        } catch(PDOException $e) {
            // If columns don't exist, grant all permissions for backward compatibility
            $isAdmin = true;
            $permissions = [
                'enrollment' => true,
                'calls' => true,
                'reimbursement' => true,
                'tasks' => true,
                'documents' => true,
                'reports' => true
            ];
        }
        ?>
        <a href="<?= $dashboardPath; ?>" class="navbar-brand">
            <img src="<?= $assetPath; ?>images/logo.png" alt="My Care">
        </a>
        
        <button class="mobile-menu-toggle" onclick="toggleMobileMenu()">
            <i class="fas fa-bars"></i>
        </button>
        
        <ul class="navbar-menu" id="navbarMenu">
            <li>
                <a href="dashboard.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'dashboard.php' ? 'active' : ''; ?>">
                    <i class="fas fa-home"></i>
                    <span>Overview</span>
                </a>
            </li>
            <?php if(!empty($permissions['enrollment'])): ?>
            <li>
                <a href="de/index.php" class="nav-link <?php echo strpos($_SERVER['PHP_SELF'], '/de/') !== false ? 'active' : ''; ?>">
                    <i class="fas fa-user-edit"></i>
                    <span>Enrollment</span>
                </a>
            </li>
            <?php endif; ?>
            <?php if(!empty($permissions['calls'])): ?>
            <li>
                <a href="pharmacy/index.php" class="nav-link <?php echo strpos($_SERVER['PHP_SELF'], '/pharmacy/') !== false ? 'active' : ''; ?>">
                    <i class="fas fa-headset"></i>
                    <span>Patient Calls</span>
                </a>
            </li>
            <?php endif; ?>
            <?php if(!empty($permissions['reimbursement'])): ?>
            <li>
                <a href="reimbursement/index.php" class="nav-link <?php echo strpos($_SERVER['PHP_SELF'], '/reimbursement/') !== false ? 'active' : ''; ?>">
                    <i class="fas fa-file-invoice-dollar"></i>
                    <span>Reimbursement</span>
                </a>
            </li>
            <?php endif; ?>
            <?php if(!empty($permissions['tasks'])): ?>
            <li>
                <a href="tasks.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'tasks.php' ? 'active' : ''; ?>">
                    <i class="fas fa-tasks"></i>
                    <span>Tasks</span>
                </a>
            </li>
            <?php endif; ?>
            <?php if(!empty($permissions['documents'])): ?>
            <li>
                <a href="files.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'files.php' ? 'active' : ''; ?>">
                    <i class="fas fa-folder-open"></i>
                    <span>Documents</span>
                </a>
            </li>
            <?php endif; ?>
           
            <?php if(!empty($permissions['insights']) || $isAdmin): ?>
            <li>
                <a href="patientInsights.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'patientInsights.php' ? 'active' : ''; ?>">
                    <i class="fas fa-chart-pie"></i>
                    <span>Patient Insights</span>
                </a>
            </li>
            <?php endif; ?>
               <?php if(!empty($permissions['insights']) || $isAdmin): ?>
            <li>
                <a href="physicianInsights.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'physicianInsights.php' ? 'active' : ''; ?>">
                    <i class="fas fa-chart-pie"></i>
                    <span>Physician Insights</span>
                </a>
            </li>
            <?php endif; ?>
            <?php if(!empty($permissions['reports'])): ?>
            <li>
                <a href="reports.php" class="nav-link <?php  if($activePage == 'reports' || $activePage == 'kabi-patient-detailed-report' || $activePage == 'kabi-skpi-report') { echo 'active'; } ?>">
                    <i class="fas fa-chart-line"></i>
                    <span>Reports</span>
                </a>
            </li>
            <?php endif; ?>
            <?php if($isAdmin): ?>
            <li>
                <a href="settings.php" class="nav-link <?php echo basename($_SERVER['PHP_SELF']) == 'settings.php' ? 'active' : ''; ?>">
                    <i class="fas fa-cog"></i>
                    <span>Settings</span>
                </a>
            </li>
            <?php endif; ?>
        </ul>
        
        <div class="navbar-right">
            <div class="user-info">
                <div class="user-avatar">
                    <?php echo getUserInititals($pdo, $_SESSION['clientId']); ?>
                </div>
                <div class="user-details">
                    <span class="user-name"><?php echo $_SESSION['clientName']; ?></span>
                    <span class="user-role">
                        <i class="fas fa-circle" style="color: #60e438;"></i>
                        Client Access
                    </span>
                </div>
            </div>
            <a href="logout.php" class="btn-logout">
                <i class="fas fa-sign-out-alt"></i>
                <span>Logout</span>
            </a>
        </div>
    </div>
</nav>

<script>
function toggleMobileMenu() {
    const menu = document.getElementById('navbarMenu');
    menu.classList.toggle('active');
}

// Close mobile menu when clicking outside
document.addEventListener('click', function(event) {
    const menu = document.getElementById('navbarMenu');
    const toggle = document.querySelector('.mobile-menu-toggle');
    
    if (!menu.contains(event.target) && !toggle.contains(event.target)) {
        menu.classList.remove('active');
    }
});
</script>
