<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}{{ app_name }}{% endblock %}</title>

    <!-- Bootstrap 5 CSS with Dark Theme -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Bootstrap Icons -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">

    <!-- Custom Dark Theme CSS -->
    <link rel="stylesheet" href="/static/css/dark-theme.css">

    <!-- Highlight.js for code syntax highlighting (GitHub Dark theme) -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/styles/github-dark.min.css">
    <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/highlight.min.js"></script>

    <!-- Marked.js for Markdown rendering -->
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>

    <!-- Mermaid.js for diagram rendering -->
    <script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>

    {% block extra_head %}{% endblock %}
</head>
<body>
    <!-- Navigation Bar -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark border-bottom border-secondary">
        <div class="container-fluid">
            <a class="navbar-brand" href="/menu">
                <i class="bi bi-chat-dots-fill"></i> {{ app_name }}
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/menu">
                            <i class="bi bi-house-fill"></i> Home
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/conversations">
                            <i class="bi bi-list-ul"></i> Conversations
                        </a>
                    </li>
                    {% if new_conversations_allowed %}
                    <li class="nav-item">
                        <a class="nav-link" href="/conversations/new">
                            <i class="bi bi-plus-circle"></i> New
                        </a>
                    </li>
                    {% endif %}
                    {% if actions_enabled %}
                    <li class="nav-item">
                        <a class="nav-link" href="/actions">
                            <i class="bi bi-robot"></i> Actions
                        </a>
                    </li>
                    {% endif %}
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <span class="nav-link text-muted">
                            <small>v{{ app_version }}</small>
                        </span>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="container-fluid py-4">
        {% block content %}{% endblock %}
    </main>

    <!-- Footer -->
    <footer class="footer mt-auto py-3 bg-dark">
        <div class="container text-center">
            <span class="text-muted">{{ app_name }} v{{ app_version }} - {{ app_description }}</span>
        </div>
    </footer>

    <!-- Bootstrap 5 JS Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>

    <!-- Custom JS -->
    <script src="/static/js/main.js"></script>

    {% block extra_scripts %}{% endblock %}

    {% if heartbeat_enabled %}
    <!-- Browser heartbeat - auto-shutdown when browser closes -->
    <script>
    setInterval(() => {
        fetch('/api/heartbeat', { method: 'POST' }).catch(() => {});
    }, {{ heartbeat_interval_ms }});
    // Send initial heartbeat immediately
    fetch('/api/heartbeat', { method: 'POST' }).catch(() => {});
    </script>
    {% endif %}
</body>
</html>
