<?php
ob_start();
$user_id = $_SESSION['user_id'];
$id = intval($_GET['id'] ?? 0);

$msg = $db->fetchOne("SELECT * FROM notifications WHERE id = $id AND user_id IN (0, $user_id) AND status = 1");

if (!$msg) {
    header('Location: ?page=notifications');
    exit;
}

// 标记已读
$db->query("UPDATE notifications SET is_read = 1 WHERE id = $id");
?>

<style>
.detail-container {
    max-width: 700px;
    margin: 0 auto;
    padding: 20px;
}

.detail-card {
    background: white;
    border-radius: 16px;
    padding: 28px;
    border: 1px solid #f0f0f0;
}

.detail-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #f0f0f0;
}

.detail-title {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 8px;
}

.detail-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    color: #94a3b8;
    font-size: 13px;
}

.detail-content {
    color: #64748b;
    line-height: 1.8;
    font-size: 15px;
}

.btn-back {
    display: inline-block;
    margin-top: 20px;
    color: #667eea;
    text-decoration: none;
}
</style>

<div class="detail-container">
    <div class="detail-card">
        <div class="detail-header">
            <div class="detail-title"><?php echo htmlspecialchars($msg['title']); ?></div>
            <div class="detail-meta">
                <span><?php echo date('Y-m-d H:i', strtotime($msg['created_at'])); ?></span>
            </div>
        </div>
        <div class="detail-content">
            <?php echo nl2br(htmlspecialchars($msg['content'])); ?>
        </div>
    </div>
    <a href="?page=notifications" class="btn-back">← 返回消息列表</a>
</div>