<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" class="h-full">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ $title ?? 'ThrillWiki' }}</title>

    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">

    <!-- Prevent flash of wrong theme -->
    <script>
        let theme = localStorage.getItem("theme");
        if (!theme) {
            theme = window.matchMedia("(prefers-color-scheme: dark)").matches
                ? "dark"
                : "light";
            localStorage.setItem("theme", theme);
        }
        if (theme === "dark") {
            document.documentElement.classList.add("dark");
        }
    </script>

    <!-- HTMX -->
    <script src="https://unpkg.com/htmx.org@1.9.6"></script>

    <!-- Scripts and Styles (loaded via Vite) -->
    @vite(['resources/js/app.js', 'resources/css/app.css'])

    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">

    <style>
        .dropdown-menu {
            position: absolute;
            right: 0;
            margin-top: 0.5rem;
            width: 12rem;
            border-radius: 0.375rem;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
                0 4px 6px -2px rgba(0, 0, 0, 0.05);
            z-index: 50;
            overflow: hidden;
        }
        .htmx-indicator {
            display: none;
        }
        .htmx-request .htmx-indicator {
            display: block;
        }
        .htmx-request.htmx-indicator {
            display: block;
        }
    </style>

    @stack('styles')
</head>
<body class="flex flex-col min-h-screen text-gray-900 bg-gradient-to-br from-white via-blue-50 to-indigo-50">
    <!-- Header -->
    <header class="sticky top-0 z-40 border-b shadow-lg bg-white/90 backdrop-blur-lg border-gray-200/50">
        <nav class="container mx-auto nav-container">
            <div class="flex items-center justify-between">
                <!-- Logo -->
                <div class="flex items-center">
                    <a href="{{ route('home') }}" class="font-bold text-transparent transition-transform site-logo bg-gradient-to-r from-primary to-secondary bg-clip-text hover:scale-105">
                        ThrillWiki
                    </a>
                </div>

                <!-- Navigation Links (Always Visible) -->
                <div class="flex items-center space-x-2 sm:space-x-4">
                    <a href="{{ route('parks.index') }}" class="nav-link">
                        <i class="fas fa-map-marker-alt"></i>
                        <span>Parks</span>
                    </a>
                    <a href="{{ route('rides.index') }}" class="nav-link">
                        <i class="fas fa-rocket"></i>
                        <span>Rides</span>
                    </a>
                </div>

                <!-- Search Bar -->
                <div class="flex-1 hidden max-w-md mx-8 lg:flex">
                    <form action="{{ route('search') }}" method="get" class="w-full">
                        <div class="relative">
                            <input type="text" name="q" placeholder="Search parks and rides..." class="form-input">
                        </div>
                    </form>
                </div>

                <!-- Right Side Menu -->
                <div class="flex items-center space-x-2 sm:space-x-6">
                    <!-- Theme Toggle -->
                    <livewire:theme-toggle-component />

                    <!-- User Menu -->
                    @auth
                        @if(auth()->user()->can('access-moderation'))
                        <a href="{{ route('moderation.dashboard') }}" class="nav-link">
                            <i class="fas fa-shield-alt"></i>
                            <span>Moderation</span>
                        </a>
                        @endif
                        <livewire:user-menu-component />
                    @else
                        <!-- Generic Profile Icon for Unauthenticated Users -->
                        <livewire:auth-menu-component />
                    @endauth

                    <!-- Mobile Menu -->
                    <livewire:mobile-menu-component />
                </div>
            </div>
        </nav>
    </header>

    <!-- Flash Messages -->
    @if (session('status'))
        <div class="fixed top-0 right-0 z-50 p-4 space-y-4">
            <div class="alert alert-success">
                {{ session('status') }}
            </div>
        </div>
    @endif

    <!-- Main Content -->
    <main class="container flex-grow px-6 py-8 mx-auto">
        {{ $slot }}
    </main>

    <!-- Footer -->
    <footer class="mt-auto border-t bg-white/90 backdrop-blur-lg border-gray-200/50">
        <div class="container px-6 py-6 mx-auto">
            <div class="flex items-center justify-between">
                <div class="text-gray-600">
                    <p>&copy; {{ date('Y') }} ThrillWiki. All rights reserved.</p>
                </div>
                <div class="space-x-4">
                    <a href="{{ route('terms') }}" class="text-gray-600 transition-colors hover:text-primary">Terms</a>
                    <a href="{{ route('privacy') }}" class="text-gray-600 transition-colors hover:text-primary">Privacy</a>
                </div>
            </div>
        </div>
    </footer>

    @stack('scripts')
</body>
</html>