<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>{{ title|default('Sprint Planner') }}</title>
    <link rel="icon" type="image/svg+xml" href="/favicon.svg">
    {# Disable htmx's built-in indicator <style> injection. With strict CSP
       (style-src 'self', no inline) the browser blocks it on every page
       load and floods the audit log with `csp_violation` rows. The
       equivalent rules ship from app.css instead. #}
    <meta name="htmx-config" content='{"includeIndicatorStyles": false}'>
    <script src="/assets/js/theme-init.js"></script>
    <link rel="stylesheet" href="/assets/css/app.css">
    <script src="/assets/js/vendor/htmx.min.js" defer></script>
    <script src="/assets/js/vendor/sortable.min.js" defer></script>
    <script src="/assets/js/app.js" defer></script>
    <script src="/assets/js/vendor/alpine-csp.min.js" defer></script>
    {% block head_extra %}{% endblock %}
</head>
<body class="bg-slate-100 text-slate-900 antialiased dark:bg-slate-900 dark:text-slate-100">
    <header class="border-b bg-white dark:bg-slate-800 dark:border-slate-700">
        <div class="max-w-7xl mx-auto px-4 py-3 flex items-center gap-4">
            <a href="/" class="flex items-center gap-2 font-semibold tracking-tight">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="24" height="24" aria-hidden="true" class="block" fill="none">
                    <defs>
                        <radialGradient id="brand-cycle-glow" cx="32" cy="32" r="20" gradientUnits="userSpaceOnUse">
                            <stop offset="0"   stop-color="#6366f1" stop-opacity="0.55"/>
                            <stop offset="0.6" stop-color="#6366f1" stop-opacity="0.12"/>
                            <stop offset="1"   stop-color="#6366f1" stop-opacity="0"/>
                        </radialGradient>
                    </defs>
                    <circle cx="32" cy="32" r="20" fill="url(#brand-cycle-glow)"/>
                    <path d="M52 32 A20 20 0 1 1 32 12" stroke="currentColor" stroke-width="3.5" stroke-linecap="round"/>
                    <path d="M44 8 L52 12 L48 20" stroke="currentColor" stroke-width="3.5" stroke-linecap="round" stroke-linejoin="round"/>
                    <circle cx="32" cy="32" r="5"  fill="#6366f1"/>
                    <circle cx="48" cy="20" r="2.5" fill="currentColor" opacity="0.55"/>
                    <circle cx="52" cy="40" r="2.5" fill="currentColor" opacity="0.55"/>
                    <circle cx="40" cy="50" r="2.5" fill="currentColor" opacity="0.55"/>
                    <circle cx="20" cy="48" r="2.5" fill="currentColor" opacity="0.55"/>
                    <circle cx="14" cy="32" r="2.5" fill="#10b981"/>
                </svg>
                <span>Sprint Planner</span>
            </a>

            <nav class="ml-auto flex items-center gap-4 text-sm">
                {% if currentUser is not null %}
                    <a href="/" class="text-slate-600 hover:text-slate-900 hover:underline dark:text-slate-300 dark:hover:text-slate-100">Sprints</a>
                    {% if currentUser.isAdmin %}
                        <a href="/sprints/new" class="text-slate-600 hover:text-slate-900 hover:underline dark:text-slate-300 dark:hover:text-slate-100">New sprint</a>
                    {% endif %}
                    <span class="text-slate-400 dark:text-slate-600">·</span>
                    <span class="text-slate-600 dark:text-slate-300">
                        {{ currentUser.displayName }}
                        {% if currentUser.isAdmin %}
                            <span class="ml-1 inline-block px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider bg-amber-100 text-amber-800 rounded dark:bg-amber-900 dark:text-amber-200">admin</span>
                        {% endif %}
                    </span>
                    <div class="relative" x-data="appMenu">
                        <button type="button"
                                x-ref="trigger"
                                x-on:click="toggle()"
                                x-bind:aria-expanded="open"
                                aria-haspopup="true"
                                aria-controls="app-menu"
                                aria-label="Open menu"
                                class="p-2 rounded-md hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:text-slate-200 dark:hover:bg-slate-700">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="20" height="20" aria-hidden="true" class="block stroke-current" fill="none" stroke-width="2" stroke-linecap="round">
                                <line x1="3" y1="5"  x2="17" y2="5"></line>
                                <line x1="3" y1="10" x2="17" y2="10"></line>
                                <line x1="3" y1="15" x2="17" y2="15"></line>
                            </svg>
                        </button>
                        <div id="app-menu"
                             role="menu"
                             x-show="open"
                             x-on:click.outside="close()"
                             x-on:keydown.escape.window="closeAndFocus()"
                             x-on:click="closeOnItem($event)"
                             x-cloak
                             class="absolute right-0 mt-2 min-w-[12rem] rounded-md border border-slate-200 bg-white shadow-lg py-1 z-10 dark:bg-slate-800 dark:border-slate-700">
                            {% if currentUser.isAdmin %}
                                <a href="/sprints/import" role="menuitem"
                                   class="block px-3 py-2 text-sm text-slate-700 hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:text-slate-200 dark:hover:bg-slate-700">Import</a>
                                <a href="/workers" role="menuitem"
                                   class="block px-3 py-2 text-sm text-slate-700 hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:text-slate-200 dark:hover:bg-slate-700">Workers</a>
                                <a href="/users" role="menuitem"
                                   class="block px-3 py-2 text-sm text-slate-700 hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:text-slate-200 dark:hover:bg-slate-700">Users</a>
                                <a href="/audit" role="menuitem"
                                   class="block px-3 py-2 text-sm text-slate-700 hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:text-slate-200 dark:hover:bg-slate-700">Audit log</a>
                                <a href="/settings" role="menuitem"
                                   class="block px-3 py-2 text-sm text-slate-700 hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-slate-400 dark:text-slate-200 dark:hover:bg-slate-700">Settings</a>
                            {% endif %}
                            <button type="button" role="menuitem" x-data="themeToggle" x-on:click="flip()"
                                    class="w-full text-left px-3 py-2 text-sm text-slate-700 hover:bg-slate-50 flex items-center justify-between focus:outline-none focus:ring-2 focus:ring-slate-400 dark:text-slate-200 dark:hover:bg-slate-700">
                                <span>Theme</span>
                                <span x-text="label" class="text-slate-500 dark:text-slate-400">Light</span>
                            </button>
                            <hr class="my-1 border-slate-200 dark:border-slate-700">
                            <form method="post" action="/auth/logout">
                                <input type="hidden" name="_csrf" value="{{ csrfToken }}">
                                <button type="submit" role="menuitem"
                                        class="block w-full text-left px-3 py-2 text-sm text-slate-700 hover:bg-slate-50 font-[inherit] focus:outline-none focus:ring-2 focus:ring-slate-400 dark:text-slate-200 dark:hover:bg-slate-700">
                                    Sign out
                                </button>
                            </form>
                        </div>
                    </div>
                {% else %}
                    <a href="/auth/login"
                       class="text-blue-700 hover:underline dark:text-blue-400 dark:hover:text-blue-300">Sign in</a>
                {% endif %}
            </nav>
        </div>
    </header>

    <main class="max-w-7xl mx-auto px-4 py-6">
        {% block content %}{% endblock %}
    </main>
</body>
</html>
