<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>@yield('title', 'Yönetim Paneli') — Markamama Kariyer</title>
    @vite(['resources/css/app.css', 'resources/js/app.js'])
    @stack('head')
    <style>
        .bg-primary { background-color: #ff7b00; }
        .text-primary { color: #ff7b00; }
        .border-primary { border-color: #ff7b00; }
        .hover\:bg-primary-dark:hover { background-color: #e06a00; }
        .sidebar-link.active { background-color: #ff7b00; color: white; }
        .sidebar-link:not(.active):hover { background-color: #fff3e8; color: #ff7b00; }

        /* Global cursor & user-select düzeltmesi */
        * { cursor: default !important; user-select: none; }
        a, button, [role="button"], select,
        input[type="submit"], input[type="button"],
        input[type="checkbox"], input[type="radio"],
        label, .cursor-pointer, [onclick],
        summary { cursor: pointer !important; }
        input[type="text"], input[type="email"],
        input[type="password"], input[type="number"],
        input[type="search"], input[type="tel"],
        input[type="url"], input[type="date"],
        input[type="time"], input[type="datetime-local"],
        textarea { cursor: text !important; }
        input[type="text"], input[type="email"],
        input[type="password"], input[type="number"],
        input[type="search"], input[type="tel"],
        input[type="url"], input[type="date"],
        input[type="time"], input[type="datetime-local"],
        textarea, [contenteditable] { user-select: text; }
        input[type="color"], input[type="file"],
        input[type="range"] { cursor: pointer !important; }
    </style>
</head>
<body class="bg-gray-100 font-sans antialiased">

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

    {{-- SIDEBAR --}}
    <aside class="w-64 bg-white shadow-md flex flex-col flex-shrink-0">
        {{-- Logo --}}
        <div class="px-6 py-5 border-b border-gray-100">
            @php $adminLogoPath = \App\Models\SiteSetting::get('site_logo_path'); @endphp
            <a href="{{ route('admin.dashboard') }}" class="flex items-center gap-2">
                @if($adminLogoPath)
                <img src="{{ Storage::url($adminLogoPath) }}" alt="Markamama" class="h-8 w-auto object-contain">
                @else
                <img src="{{ asset('images/markamama-M-kucuk.jpg') }}" alt="Markamama" class="h-8 w-auto object-contain">
                @endif
            </a>
            <p class="text-xs text-gray-400 mt-0.5">Kariyer Yönetim Paneli</p>
        </div>

        {{-- Nav --}}
        <nav class="flex-1 px-3 py-4 space-y-1 overflow-y-auto">
            {{-- Dashboard --}}
            <a href="{{ route('admin.dashboard') }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium text-gray-700 transition-colors {{ request()->routeIs('admin.dashboard') ? 'active' : '' }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/></svg>
                Dashboard
            </a>

            {{-- İş İlanları --}}
            @php $canIlanlar = auth()->user()->can('view job postings'); @endphp
            <a href="{{ $canIlanlar ? route('admin.ilanlar.index') : route('admin.erisim-yok', ['from' => 'ilanlar']) }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors {{ request()->routeIs('admin.ilanlar.*') ? 'active' : ($canIlanlar ? 'text-gray-700' : 'text-gray-400') }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 13.255A23.931 23.931 0 0112 15c-3.183 0-6.22-.62-9-1.745M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2 2v2m4 6h.01M5 20h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
                İş İlanları
                @if(!$canIlanlar)<svg class="w-3.5 h-3.5 ml-auto opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>@endif
            </a>

            {{-- Başvurular --}}
            @php $canBasvurular = auth()->user()->can('view applications'); @endphp
            <a href="{{ $canBasvurular ? route('admin.basvurular.index') : route('admin.erisim-yok', ['from' => 'basvurular']) }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors {{ request()->routeIs('admin.basvurular.*') ? 'active' : ($canBasvurular ? 'text-gray-700' : 'text-gray-400') }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
                Başvurular
                @if(!$canBasvurular)<svg class="w-3.5 h-3.5 ml-auto opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>@endif
            </a>

            {{-- Görüşmeler --}}
            @php $canGorusmeler = auth()->user()->can('view interviews'); @endphp
            <a href="{{ $canGorusmeler ? route('admin.gorusmeler.index') : route('admin.erisim-yok', ['from' => 'gorusmeler']) }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors {{ request()->routeIs('admin.gorusmeler.*') ? 'active' : ($canGorusmeler ? 'text-gray-700' : 'text-gray-400') }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                Görüşmeler
                @if(!$canGorusmeler)<svg class="w-3.5 h-3.5 ml-auto opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>@endif
            </a>

            {{-- Departmanlar --}}
            @php $canDepartmanlar = auth()->user()->can('view departments'); @endphp
            <a href="{{ $canDepartmanlar ? route('admin.departmanlar.index') : route('admin.erisim-yok', ['from' => 'departmanlar']) }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors {{ request()->routeIs('admin.departmanlar.*') ? 'active' : ($canDepartmanlar ? 'text-gray-700' : 'text-gray-400') }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
                Departmanlar
                @if(!$canDepartmanlar)<svg class="w-3.5 h-3.5 ml-auto opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>@endif
            </a>

            {{-- Site Ayarları --}}
            @php $canAyarlar = auth()->user()->can('view site settings') || auth()->user()->can('manage site settings'); @endphp
            <a href="{{ $canAyarlar ? route('admin.ayarlar.index') : route('admin.erisim-yok', ['from' => 'ayarlar']) }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors {{ request()->routeIs('admin.ayarlar.*') ? 'active' : ($canAyarlar ? 'text-gray-700' : 'text-gray-400') }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
                Site Ayarları
                @if(!$canAyarlar)<svg class="w-3.5 h-3.5 ml-auto opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>@endif
            </a>

            {{-- Kullanıcılar --}}
            @php $canKullanicilar = auth()->user()->can('view users'); @endphp
            <a href="{{ $canKullanicilar ? route('admin.kullanicilar.index') : route('admin.erisim-yok', ['from' => 'kullanicilar']) }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors {{ request()->routeIs('admin.kullanicilar.*') ? 'active' : ($canKullanicilar ? 'text-gray-700' : 'text-gray-400') }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"/></svg>
                Kullanıcılar
                @if(!$canKullanicilar)<svg class="w-3.5 h-3.5 ml-auto opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>@endif
            </a>

            {{-- Rol Yönetimi (sadece super-admin) --}}
            @if(auth()->user()->hasRole('super-admin'))
            <a href="{{ route('admin.roller.index') }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium text-gray-700 transition-colors {{ request()->routeIs('admin.roller.*') ? 'active' : '' }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/></svg>
                Rol Yönetimi
            </a>
            @endif

            {{-- Aktivite Logları --}}
            @php $canLoglar = auth()->user()->can('view logs'); @endphp
            <a href="{{ $canLoglar ? route('admin.loglar.index') : route('admin.erisim-yok', ['from' => 'loglar']) }}"
               class="sidebar-link flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors {{ request()->routeIs('admin.loglar.*') ? 'active' : ($canLoglar ? 'text-gray-700' : 'text-gray-400') }}">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/></svg>
                Aktivite Logları
                @if(!$canLoglar)<svg class="w-3.5 h-3.5 ml-auto opacity-40" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>@endif
            </a>
        </nav>

        {{-- User --}}
        <div class="px-4 py-4 border-t border-gray-100">
            <a href="{{ route('admin.profil.show') }}"
               class="flex items-center gap-3 mb-3 hover:bg-gray-50 rounded-lg p-1.5 -mx-1.5 transition-colors group">
                @if(auth()->user()->avatar)
                    <img src="{{ \Illuminate\Support\Facades\Storage::url(auth()->user()->avatar) }}"
                         alt="{{ auth()->user()->name }}"
                         class="w-8 h-8 rounded-full object-cover border-2 border-orange-200 flex-shrink-0">
                @else
                    <div class="w-8 h-8 bg-primary rounded-full flex items-center justify-center text-white text-sm font-bold flex-shrink-0">
                        {{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
                    </div>
                @endif
                <div class="flex-1 min-w-0">
                    <p class="text-sm font-medium text-gray-800 truncate group-hover:text-primary transition-colors">{{ auth()->user()->name }}</p>
                    <p class="text-xs text-gray-400 truncate">{{ auth()->user()->getRoleNames()->first() }}</p>
                </div>
                <svg class="w-3.5 h-3.5 text-gray-300 group-hover:text-primary transition-colors flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/></svg>
            </a>
            <form method="POST" action="{{ route('logout') }}">
                @csrf
                <button type="submit" class="w-full text-left text-xs text-gray-500 hover:text-red-500 transition-colors flex items-center gap-1.5">
                    <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="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/></svg>
                    Çıkış Yap
                </button>
            </form>
        </div>
    </aside>

    {{-- MAIN CONTENT --}}
    <div class="flex-1 flex flex-col overflow-hidden">
        {{-- Top Bar --}}
        <header class="bg-white shadow-sm px-6 py-4 flex items-center justify-between flex-shrink-0">
            <div>
                <h1 class="text-lg font-bold text-gray-800">@yield('page-title', 'Dashboard')</h1>
                @hasSection('page-subtitle')
                <p class="text-sm text-gray-500">@yield('page-subtitle')</p>
                @endif
            </div>
            <div class="flex items-center gap-3">
                <a href="{{ route('home') }}" target="_blank"
                   class="text-sm text-gray-500 hover:text-primary flex items-center gap-1 transition-colors">
                    <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>
                    Siteyi Gör
                </a>
            </div>
        </header>

        {{-- Flash Messages --}}
        <div class="px-6 pt-4">
            @if(session('success'))
            <div id="flash-success" class="bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-lg text-sm mb-4 flex items-center gap-2 transition-opacity duration-500">
                <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>
                {{ session('success') }}
                <button onclick="this.parentElement.remove()" class="ml-auto text-green-500 hover:text-green-700">
                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                </button>
            </div>
            <script nonce="{{ app('csp-nonce') }}">
                setTimeout(function() {
                    var el = document.getElementById('flash-success');
                    if (el) { el.style.opacity = '0'; setTimeout(function(){ el.remove(); }, 500); }
                }, 3500);
            </script>
            @endif
            @if(session('error'))
            <div id="flash-error" class="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg text-sm mb-4 flex items-center gap-2 transition-opacity duration-500">
                <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 16zm-1-9v4a1 1 0 102 0V9a1 1 0 10-2 0zm1-4a1 1 0 100 2 1 1 0 000-2z" clip-rule="evenodd"/></svg>
                {{ session('error') }}
                <button onclick="this.parentElement.remove()" class="ml-auto text-red-500 hover:text-red-700">
                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                </button>
            </div>
            <script nonce="{{ app('csp-nonce') }}">
                setTimeout(function() {
                    var el = document.getElementById('flash-error');
                    if (el) { el.style.opacity = '0'; setTimeout(function(){ el.remove(); }, 500); }
                }, 3500);
            </script>
            @endif
        </div>

        {{-- Page Content --}}
        <main class="flex-1 overflow-y-auto px-6 pb-6">
            @yield('content')
        </main>
    </div>
</div>

@stack('modals')
@stack('scripts')

<script nonce="{{ app('csp-nonce') }}">
function previewImage(input, previewId) {
    var preview = document.getElementById(previewId);
    var img = preview.querySelector('img');
    var label = document.getElementById(previewId + '_label');
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function(e) {
            img.src = e.target.result;
            preview.classList.remove('hidden');
            if (label) label.textContent = 'Seçilen görsel önizlemesi';
        };
        reader.readAsDataURL(input.files[0]);
    }
}

function checkFileSize(input, maxMB) {
    var errorEl = document.getElementById(input.name + '_size_error');
    if (!errorEl) return true;
    if (input.files && input.files[0]) {
        var sizeMB = input.files[0].size / 1024 / 1024;
        if (sizeMB > maxMB) {
            errorEl.classList.remove('hidden');
            input.value = '';
            var previewId = input.getAttribute('onchange');
            return false;
        } else {
            errorEl.classList.add('hidden');
        }
    }
    return true;
}
</script>
</body>
</html>
