<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@yield('title', 'Admin') — Panel Admin Desa Suka Baru</title>
    <!-- Favicon -->
    @if(file_exists(public_path('images/logo_cropped.png')))
        <link rel="icon" type="image/png" href="{{ asset('images/logo_cropped.png') }}">
    @elseif(file_exists(public_path('images/logo.png')))
        <link rel="icon" type="image/png" href="{{ asset('images/logo.png') }}">
    @elseif(file_exists(public_path('images/logo.jpg')))
        <link rel="icon" type="image/jpeg" href="{{ asset('images/logo.jpg') }}">
    @elseif(file_exists(public_path('images/logo.jpeg')))
        <link rel="icon" type="image/jpeg" href="{{ asset('images/logo.jpeg') }}">
    @elseif(file_exists(public_path('images/logo.svg')))
        <link rel="icon" type="image/svg+xml" href="{{ asset('images/logo.svg') }}">
    @else
        <link rel="icon" href="{{ asset('favicon.ico') }}">
    @endif

    <!-- Leaflet CSS (untuk form peta) -->
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" crossorigin="">

    @vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body class="font-sans bg-gray-50 text-text-main">

<!-- Backdrop Overlay for Mobile/Tablet Sidebar -->
<div id="admin-sidebar-backdrop" class="fixed inset-0 bg-black/60 z-40 hidden transition-opacity lg:hidden"></div>

<div class="flex h-screen overflow-hidden relative">

    <!-- Sidebar -->
    @include('partials.admin-sidebar')

    <!-- Main Content Area -->
    <div class="flex-1 flex flex-col min-w-0 overflow-hidden">
        <!-- Top Bar -->
        <header class="bg-white border-b border-gray-200 px-4 sm:px-6 py-3.5 flex items-center justify-between z-10">
            <div class="flex items-center gap-3">
                <!-- Hamburger Button (Mobile & Tablet) -->
                <button id="admin-sidebar-toggle" class="lg:hidden p-2 rounded-lg text-gray-600 hover:bg-gray-100 focus:outline-none transition-colors" aria-label="Toggle Sidebar">
                    <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/>
                    </svg>
                </button>

                <div>
                    <h1 class="text-base sm:text-lg font-semibold text-text-main leading-tight truncate">@yield('page-title', 'Dashboard')</h1>
                    <p class="text-[11px] sm:text-xs text-gray-400">Panel Admin Desa Suka Baru</p>
                </div>
            </div>

            <div class="flex items-center gap-2 sm:gap-4">
                <a href="{{ route('home') }}" target="_blank" class="text-xs sm:text-sm text-secondary hover:underline flex items-center gap-1 bg-blue-50 sm:bg-transparent px-2.5 py-1.5 sm:p-0 rounded-lg">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/></svg>
                    <span class="hidden sm:inline">Lihat Website</span>
                    <span class="sm:hidden">Web</span>
                </a>
                <div class="h-4 w-px bg-gray-200 hidden sm:block"></div>
                <span class="text-xs sm:text-sm font-medium text-gray-700 hidden sm:inline-block truncate max-w-32">{{ auth()->user()->name }}</span>
                <form method="POST" action="{{ route('logout') }}">
                    @csrf
                    <button type="submit" class="text-xs sm:text-sm text-red-500 hover:text-red-700 font-medium px-2 py-1 rounded hover:bg-red-50 transition-colors">Keluar</button>
                </form>
            </div>
        </header>

        <!-- Alert Messages -->
        <div class="px-4 sm:px-6 pt-4">
            @if(session('success'))
                <div class="flex items-center gap-2 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-lg text-sm mb-4">
                    <svg class="w-4 h-4 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/></svg>
                    <span>{{ session('success') }}</span>
                </div>
            @endif
            @if(session('error'))
                <div class="flex items-center gap-2 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg text-sm mb-4">
                    <svg class="w-4 h-4 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/></svg>
                    <span>{{ session('error') }}</span>
                </div>
            @endif
        </div>

        <!-- Page Content -->
        <main class="flex-1 overflow-y-auto p-4 sm:p-6">
            @yield('content')
        </main>
    </div>
</div>

<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" crossorigin=""></script>
@stack('scripts')
</body>
</html>

