<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><%= title || 'QA Dashboard' %> — AI QA Pipeline</title>
  <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="/css/style.css">
  <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</head>
<body>
  <nav class="navbar">
    <div class="nav-inner">
      <a href="/" class="nav-brand">AI QA Pipeline</a>
      <div class="nav-links">
        <a href="/projects">Projects</a>
        <a href="/stories">Stories</a>
        <a href="/runs">Runs</a>
        <a href="/review">Review</a>
        <a href="/analytics">Analytics</a>
        <a href="/data">Test Data</a>
        <button onclick="location.reload()" class="btn-refresh" title="Refresh">↻</button>
      </div>
    </div>
  </nav>
  <main class="container">
    <%- body %>
  </main>
  <script src="/js/main.js"></script>
  <script>
  // Signal the server when the tab is closed
  window.addEventListener('beforeunload', () => {
    navigator.sendBeacon('/shutdown', '{}');
  });

  // React-like live reload connection
  const reloadSource = new EventSource('/live-reload');
  reloadSource.onerror = () => {
    // If connection is lost (server restarted), wait 1s and reload browser
    setTimeout(() => {
      location.reload();
    }, 1000);
  };
  </script>
</body>
</html>
