<?php
ob_start();
header('Content-Type: application/json');
require_once '../config.php';

$user_id = $_SESSION['user_id'] ?? 0;
$unread = 0;

if ($user_id) {
    $unread = $db->fetchOne("SELECT COUNT(*) as cnt FROM notifications WHERE user_id IN (0, $user_id) AND is_read = 0 AND status = 1")['cnt'] ?? 0;
}

echo json_encode(['unread' => $unread]);
exit;