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

        <title>{{ config('app.name', 'Avante') }} - Portal Cliente</title>

        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />

        <!-- Scripts -->
        @vite(['resources/css/app.css', 'resources/js/app.js'])
        @livewireStyles

        <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
            integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
            crossorigin=""/>
        <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
            integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
            crossorigin=""></script>

        <!-- PWA -->
        <link rel="manifest" href="{{ mix('manifest.json') }}">

        <style>
            .client-portal {
                max-width: 1200px;
                margin: 0 auto;
                padding: 1rem;
            }
            .project-card {
                border: 1px solid #e2e8f0;
                border-radius: 0.5rem;
                overflow: hidden;
                transition: transform 0.2s, box-shadow 0.2s;
            }
            .project-card:hover {
                transform: translateY(-2px);
                box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            }
            .gallery-grid {
                display: grid;
                grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
                gap: 1rem;
                margin-top: 1.5rem;
            }
            .gallery-item {
                border-radius: 0.5rem;
                overflow: hidden;
                box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
            }
            .change-order-card {
                border-left: 4px solid;
                padding: 1rem;
                margin-bottom: 1rem;
                border-radius: 0 0.5rem 0.5rem 0;
            }
            .change-order-pending { border-left-color: #f59e0b; background-color: #fffbeb; }
            .change-order-approved { border-left-color: #10b981; background-color: #ecfdf5; }
            .change-order-rejected { border-left-color: #ef4444; background-color: #fef2f2; }
        </style>
    </head>
    <body class="font-sans antialiased bg-gray-50">
        <div class="min-h-screen">
            <!-- Header -->
            <header class="bg-white shadow-sm">
                <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
                    <div class="flex justify-between h-16">
                        <div class="flex items-center">
                            <div class="flex-shrink-0">
                                <img src="{{ asset('logo.png') }}" alt="Avante" class="h-8 w-auto" onerror="this.onerror=null;this.src='https://via.placeholder.com/150x40?text=Avante'; this.alt='Avante Logo'">
                            </div>
                            <div class="hidden md:ml-6 md:flex md:space-x-4">
                                <a href="{{ url('/client/projects') }}" class="px-3 py-2 rounded-md text-sm font-medium text-gray-600 hover:bg-gray-50">{{ __('My Projects') }}</a>
                                <a href="{{ url('/client/profile') }}" class="px-3 py-2 rounded-md text-sm font-medium text-gray-600 hover:bg-gray-50">{{ __('Profile') }}</a>
                            </div>
                        </div>
                        <div class="hidden md:block">
                            <div class="ml-4 flex items-center md:ml-6">
                                <livewire:user-nav />
                            </div>
                        </div>
                        <div class="hidden md:block">
                            @livewire('common.language-switcher')
                        </div>
                    </div>
                </div>
            </header>

            <!-- Mobile menu -->
            <nav class="md:hidden" id="mobile-menu">
                <div class="px-2 pt-2 pb-3 space-y-1">
                    <a href="{{ url('/client/projects') }}" class="block px-3 py-2 rounded-md text-base font-medium text-gray-700 hover:bg-gray-50">{{ __('My Projects') }}</a>
                    <a href="{{ url('/client/profile') }}" class="block px-3 py-2 rounded-md text-base font-medium text-gray-700 hover:bg-gray-50">{{ __('Profile') }}</a>
                </div>
            </nav>

            <!-- Main Content -->
            <main class="mt-16">
                <div class="client-portal">
                    {{ $slot }}
                </div>
            </main>
        </div>

        @stack('scripts')
        @livewireScripts
        <script>
            {{-- PWA retirada: sw.js ahora es de auto-limpieza (borra caches y se desregistra) --}}
            if ('serviceWorker' in navigator) {
                navigator.serviceWorker.register('/sw.js');
            }

            // Mobile menu toggle
            document.addEventListener('DOMContentLoaded', function() {
                const menuBtn = document.querySelector('[data-dropdown-toggle]');
                const mobileMenu = document.getElementById('mobile-menu');
                if (menuBtn && mobileMenu) {
                    menuBtn.addEventListener('click', function() {
                        mobileMenu.classList.toggle('hidden');
                    });
                }
            });
        </script>
    </body>
</html>
