<?php
require_once __DIR__ . '/config/db.php';
startSession();

// Delete remember-me token from DB
if (!empty($_SESSION['user_id'])) {
    try {
        db()->prepare("DELETE FROM remember_tokens WHERE user_id=?")
           ->execute([$_SESSION['user_id']]);
    } catch(PDOException $e) {}
}

// Clear remember-me cookie
if (isset($_COOKIE['remember_token'])) {
    setcookie('remember_token', '', time() - 3600, '/', '', false, true);
    unset($_COOKIE['remember_token']);
}

// Destroy session completely
$_SESSION = [];
session_destroy();

// Always redirect to reviewer login with absolute path
header('Location: /reviewer/login.php?msg=logout');
exit;