<!doctype html>
<html lang="fr" class="h-full">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %}Kodi - Films{% endblock %}</title>
    <script>
      (function() {
        const stored = localStorage.getItem('theme');
        const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
        if (stored === 'dark' || (!stored && prefersDark)) {
          document.documentElement.classList.add('dark');
        } else {
          document.documentElement.classList.remove('dark');
        }
      })();
    </script>
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
      tailwind.config = { darkMode: 'class' };
    </script>
  </head>
  <body class="h-full bg-gray-50 text-gray-900 dark:bg-gray-900 dark:text-gray-100">
    <div class="max-w-7xl mx-auto p-4 md:p-6">
      <header class="flex items-center gap-3 mb-4">
        <h1 class="text-xl md:text-2xl font-semibold">Kodi - Films</h1>
        <div class="ml-auto flex items-center gap-2">
          <button id="themeToggle" class="px-3 py-1 rounded-lg border dark:border-gray-700 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700">
            <span class="inline dark:hidden">🌙 Mode sombre</span>
            <span class="hidden dark:inline">☀️ Mode clair</span>
          </button>
        </div>
      </header>
      {% block content %}{% endblock %}
    </div>
    <script>
      document.getElementById('themeToggle')?.addEventListener('click', () => {
        const el = document.documentElement;
        const newTheme = el.classList.contains('dark') ? 'light' : 'dark';
        el.classList.toggle('dark');
        localStorage.setItem('theme', newTheme);
      });
    </script>
  </body>
</html>
