<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<x-source-comment />
@inject('deployment', 'App\Services\DeploymentService')
@php
    // Reverb (Echo) endpoint derived at RUNTIME from the effective domain, so changing
    // the panel domain from the dashboard needs no JS rebuild. Read by resources/js/app.js.
    $reverb = $deployment->reverbClient();
@endphp
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ $title ?? 'Clusev' }}</title>
    @include('partials.head-icons')
    <script>
        window.__clusev = { reverb: {
            key: @js($reverb['key']),
            host: @js($reverb['host']),
            port: {{ (int) $reverb['port'] }},
            scheme: @js($reverb['scheme']),
        } };
    </script>
    @vite(['resources/css/app.css', 'resources/js/app.js'])
    @livewireStyles
</head>
<body class="min-h-screen overflow-x-clip bg-void font-sans text-ink antialiased selection:bg-accent/25">
    <div x-data="{ nav: false, desktop: window.matchMedia('(min-width: 1024px)').matches }"
         @resize.window.debounce.200ms="desktop = window.matchMedia('(min-width: 1024px)').matches">
        {{-- mobile/tablet backdrop --}}
        <div x-show="nav" x-cloak x-transition.opacity @click="nav = false"
             class="fixed inset-0 z-30 bg-void/70 lg:hidden"
             aria-hidden="true"></div>

        <x-sidebar />

        <div class="relative z-10 lg:pl-[272px]">
            <x-topbar />
            <main class="mx-auto w-full max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
                {{-- Default-password warning: shown while the seeded password is still in use (rotation
                     is recommended but not forced). Disappears once the password is actually changed. --}}
                @if (auth()->user()?->must_change_password)
                    <div class="mb-5 flex items-center gap-3 rounded-lg border border-warning/30 bg-warning/10 px-4 py-3">
                        <x-icon name="alert" class="h-4 w-4 shrink-0 text-warning" />
                        <p class="min-w-0 flex-1 font-mono text-[12px] leading-relaxed text-ink-2">{{ __('auth.default_pw_warning') }}</p>
                        <a href="{{ route('password.change') }}" wire:navigate
                           class="shrink-0 rounded-md border border-warning/40 px-2.5 py-1 font-mono text-[11px] text-warning transition-colors hover:bg-warning/10">{{ __('auth.default_pw_change') }}</a>
                    </div>
                @endif
                {{ $slot }}
            </main>
        </div>
    </div>
    @include('partials.toaster')

    {{-- First-run onboarding tour (dimmed spotlight overlay; auto-opens once, relaunchable from Settings).
         @persist so it does NOT re-mount on wire:navigate — otherwise mount() would re-read the flag and
         could re-open the tour in the window before markSeen() persists. --}}
    @persist('onboarding-tour')
        <livewire:onboarding.tour />
    @endpersist

    {{-- Command palette + keyboard shortcuts (persistent; one global keydown listener) --}}
    <x-command-palette />

    {{-- Persist the modal manager across wire:navigate: otherwise body.replaceWith +
         Alpine.destroyTree tear down its window-level `openModal` listener on every SPA
         navigation, leaving a post-landing window where a click finds no live component
         (dead trigger / "Could not find Livewire component in DOM tree"). @persist keeps
         ONE stable manager + listener for the whole session. --}}
    @persist('modal')
        <livewire:wire-elements-modal />
    @endpersist
    @livewireScripts
</body>
</html>
