/* ─── SITREP: Daily AI Briefing Frontend ─────────── */ (function() { 'use strict'; const API_BASE = '/api/sitrep'; let archiveDates = []; let currentDate = null; // ─── DOM Elements ──────────────────────────────── const els = { dateTitle: document.getElementById('sitrepDateTitle'), notice: document.getElementById('sitrepNotice'), noticeText: document.getElementById('sitrepNoticeText'), cryptoBar: document.getElementById('sitrepCryptoBar'), briefing: document.getElementById('sitrepBriefing'), content: document.getElementById('sitrepContent'), metaSources: document.getElementById('metaSources'), metaModel: document.getElementById('metaModel'), metaGenerated: document.getElementById('metaGenerated'), archiveList: document.getElementById('sitrepArchiveList'), btnPrev: document.getElementById('sitrepPrev'), btnNext: document.getElementById('sitrepNext'), btnGenerate: document.getElementById('sitrepGenerate') }; // ─── Markdown to HTML ──────────────────────────── function mdToHtml(md) { if (!md) return '

No content available.

'; let html = md; // Escape HTML entities (but preserve markdown) html = html.replace(/&/g, '&').replace(//g, '>'); // Restore markdown-safe chars html = html.replace(/> /gm, '> '); // blockquotes // Horizontal rules html = html.replace(/^---+$/gm, '
'); html = html.replace(/^\*\*\*+$/gm, '
'); // Headers (must be before bold processing) html = html.replace(/^### (.+)$/gm, '

$1

'); html = html.replace(/^## (.+)$/gm, '

$1

'); html = html.replace(/^# (.+)$/gm, '

$1

'); // Bold + Italic html = html.replace(/\*\*\*(.+?)\*\*\*/g, '$1'); html = html.replace(/\*\*(.+?)\*\*/g, '$1'); html = html.replace(/(?$1'); // Inline code html = html.replace(/`([^`]+)`/g, '$1'); // Links [text](url) html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); // Blockquotes (multi-line support) html = html.replace(/^> (.+)$/gm, '
$1
'); // Merge consecutive blockquotes html = html.replace(/<\/blockquote>\n
/g, '
'); // Unordered lists html = html.replace(/^[\-\*] (.+)$/gm, '
  • $1
  • '); // Wrap consecutive
  • in