<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{% block title %}ECDA LLM{% endblock %}</title>

    <link rel="stylesheet" href="/static/css/styles.css?v=22803718_1">
    <link rel="icon" href="/static/images/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">

    <!-- SweetAlert2 -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/dompurify@3.0.6/dist/purify.min.js"></script>

</head>

<body class="{% block body_class %}{% endblock %}">

    <nav class="top-nav">
        <div class="nav-inner">
            <button id="themeToggle" class="btn btn-base theme-toggle" type="button">
                🌓 Theme
            </button>
            <a href="/setting" class="btn btn-base theme-toggle">
                ⚙️ Settings
            </a>
        </div>
    </nav>

    <div class="wrap">
        {% block content %}{% endblock %}
    </div>

    <script>
        (function initTheme() {
            const saved = localStorage.getItem("theme");
            const prefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
            const theme = saved || (prefersDark ? "dark" : "light");
            document.documentElement.dataset.theme = theme;
        })();

        document.addEventListener("click", (e) => {
            const btn = e.target.closest("#themeToggle");
            if (!btn) return;

            const current = document.documentElement.dataset.theme || "light";
            const next = current === "dark" ? "light" : "dark";
            document.documentElement.dataset.theme = next;
            localStorage.setItem("theme", next);
        });

    </script>

</body>

</html>