<!DOCTYPE html>
<html lang="tr" class="light">
<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', 'Admin Panel') - Askeri Platform</title>
    
    {{-- Global Theme CSS Variables --}}
    @include('components.theme-styles')
    
    <style>
        :root {
            --tblr-font-sans-serif: 'Inter', -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
            --tblr-primary: var(--primary-color, #1e40af);
            --tblr-primary-fg: #ffffff;
            --tblr-secondary: #8b5cf6;
            --tblr-success: #10b981;
            --tblr-warning: #f59e0b;
            --tblr-danger: #ef4444;
            --tblr-body-bg: var(--background-color, #f1f5f9);
            --tblr-bg-surface: #ffffff;
            --tblr-border-color: var(--border-color, #e2e8f0);
        }
        * { box-sizing: border-box; }
        body {
            font-family: var(--font-family, var(--tblr-font-sans-serif));
            background: var(--tblr-body-bg);
            margin: 0;
            padding: 0;
            font-size: 0.9375rem;
            line-height: 1.5;
        }
        .navbar {
            background: var(--tblr-bg-surface);
            border-bottom: 1px solid var(--tblr-border-color);
            padding: 0.75rem 1.5rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
            position: sticky;
            top: 0;
            z-index: 1000;
        }
        .navbar-brand {
            font-weight: 700;
            font-size: 1.25rem;
            color: var(--primary-color, var(--tblr-primary));
            text-decoration: none;
        }
        .navbar-nav {
            display: flex;
            gap: 1rem;
            align-items: center;
        }
        .nav-link {
            color: #64748b;
            text-decoration: none;
            padding: 0.5rem 0.75rem;
            border-radius: 0.375rem;
            transition: all 0.2s;
            font-size: 0.875rem;
        }
        .nav-link:hover, .nav-link.active {
            background: #f1f5f9;
            color: var(--primary-color, var(--tblr-primary));
        }
        .sidebar {
            width: 260px;
            background: var(--tblr-bg-surface);
            border-right: 1px solid var(--tblr-border-color);
            position: fixed;
            top: 60px;
            left: 0;
            bottom: 0;
            overflow-y: auto;
            padding: 0.75rem 0 2rem;
        }
        .sidebar-nav {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .nav-item {
            margin: 0.125rem 0.75rem;
        }
        .nav-section-title {
            font-size: 0.7rem;
            font-weight: 700;
            color: #94a3b8;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            padding: 0.75rem 0.75rem 0.25rem;
            margin-top: 0.5rem;
        }

        /* Main nav links */
        .nav-item > .nav-link {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.45rem 0.75rem;
            border-radius: 0.4rem;
            font-size: 0.8438rem;
            font-weight: 500;
            color: #374151;
            width: 100%;
        }
        .nav-item > .nav-link:hover { background: #f1f5f9; color: var(--primary-color, var(--tblr-primary)); }
        .nav-item > .nav-link.active { background: #eff6ff; color: var(--primary-color, var(--tblr-primary)); font-weight: 600; }

        /* Collapsible groups */
        .nav-group { margin: 0.125rem 0.75rem; }
        .nav-group-toggle {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.45rem 0.75rem;
            border-radius: 0.4rem;
            font-size: 0.8438rem;
            font-weight: 500;
            color: #374151;
            cursor: pointer;
            width: 100%;
            background: none;
            border: none;
            text-align: left;
            transition: all 0.2s;
            justify-content: space-between;
        }
        .nav-group-toggle:hover { background: #f1f5f9; color: var(--primary-color, var(--tblr-primary)); }
        .nav-group-toggle.open { color: var(--primary-color, var(--tblr-primary)); background: #eff6ff; }
        .nav-group-toggle .toggle-icon { transition: transform 0.2s; font-size: 10px; color: #94a3b8; }
        .nav-group-toggle.open .toggle-icon { transform: rotate(90deg); }
        .nav-group-label { display: flex; align-items: center; gap: 0.5rem; }

        .nav-sub {
            list-style: none;
            padding: 0.25rem 0 0.25rem 1.75rem;
            margin: 0;
            display: none;
        }
        .nav-sub.open { display: block; }
        .nav-sub .nav-item { margin: 0.1rem 0; }
        .nav-sub .nav-item .nav-link {
            font-size: 0.8rem;
            color: #64748b;
            padding: 0.35rem 0.6rem;
            border-radius: 0.35rem;
        }
        .nav-sub .nav-item .nav-link:hover { color: var(--primary-color, var(--tblr-primary)); background: #f8fafc; }
        .nav-sub .nav-item .nav-link.active { color: var(--primary-color, var(--tblr-primary)); background: #eff6ff; font-weight: 600; }

        /* Active indicator for group when child is active */
        .nav-group.has-active .nav-group-toggle { color: var(--primary-color, var(--tblr-primary)); }

        .main-content {
            margin-left: 260px;
            margin-top: 60px;
            padding: 1.5rem;
            min-height: calc(100vh - 60px);
        }
        .card {
            background: var(--tblr-bg-surface);
            border: 1px solid var(--tblr-border-color);
            border-radius: 0.5rem;
            box-shadow: 0 1px 3px rgba(0,0,0,0.05);
            margin-bottom: 1.5rem;
        }
        .card-header {
            padding: 1rem 1.5rem;
            border-bottom: 1px solid var(--tblr-border-color);
            font-weight: 600;
        }
        .card-body { padding: 1.5rem; }
        .card-title { margin: 0; font-size: 1.125rem; font-weight: 600; }
        .row { display: flex; flex-wrap: wrap; margin: -0.75rem; }
        .col { flex: 1; padding: 0.75rem; min-width: 250px; }
        .col-12 { flex: 0 0 100%; }
        .col-6 { flex: 0 0 50%; }
        .col-4 { flex: 0 0 33.333%; }
        .col-3 { flex: 0 0 25%; }
        .stat-card { text-align: center; padding: 1.5rem; }
        .stat-value { font-size: 2rem; font-weight: 700; color: var(--tblr-primary); }
        .stat-label { color: #64748b; font-size: 0.875rem; margin-top: 0.5rem; }
        .table { width: 100%; border-collapse: collapse; }
        .table th, .table td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--tblr-border-color); }
        .table th { font-weight: 600; color: #475569; background: #f8fafc; }
        .badge { display: inline-block; padding: 0.25rem 0.5rem; font-size: 0.75rem; font-weight: 600; border-radius: 9999px; }
        .badge-success { background: #dcfce7; color: #166534; }
        .badge-warning { background: #fef3c7; color: #92400e; }
        .badge-danger { background: #fee2e2; color: #991b1b; }
        .badge-info { background: #dbeafe; color: #1e40af; }
        .btn {
            display: inline-block; padding: 0.5rem 1rem; font-size: 0.875rem;
            font-weight: 500; text-align: center; text-decoration: none;
            border-radius: 0.375rem; border: none; cursor: pointer; transition: all 0.2s;
        }
        .btn-primary { background: var(--primary-color, var(--tblr-primary)); color: white; }
        .btn-primary:hover { background: #1e3a8a; color: white; text-decoration: none; }
        .btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
        .alert { padding: 1rem 1.5rem; border-radius: 0.5rem; margin-bottom: 1rem; }
        .alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
        .alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
        .form-control { width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--tblr-border-color); border-radius: 0.375rem; font-size: 0.875rem; }
        .form-control:focus { outline: none; border-color: var(--primary-color, var(--tblr-primary)); box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1); }
        .form-label { display: block; margin-bottom: 0.5rem; font-weight: 500; color: #334155; }
        .mb-3 { margin-bottom: 1rem; }
        .mt-3 { margin-top: 1rem; }
        .text-muted { color: #64748b; }
        .text-center { text-align: center; }

        /* Management Grid */
        .management-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
            gap: 1.5rem;
            margin-bottom: 2rem;
        }
        .management-section {
            background: var(--tblr-bg-surface);
            border: 1px solid var(--tblr-border-color);
            border-radius: 0.5rem;
            overflow: hidden;
        }
        .section-header {
            background: linear-gradient(135deg, #f0f4f8 0%, #f8fafc 100%);
            padding: 1rem 1.5rem;
            border-bottom: 1px solid var(--tblr-border-color);
        }
        .section-header h2 {
            margin: 0;
            font-size: 1rem;
            font-weight: 600;
            color: #1e293b;
        }
        .section-links {
            display: flex;
            flex-direction: column;
            padding: 0.75rem;
            gap: 0.5rem;
        }
        .mg-link {
            display: flex;
            align-items: flex-start;
            gap: 0.75rem;
            padding: 0.75rem 1rem;
            text-decoration: none;
            border-radius: 0.375rem;
            transition: all 0.2s;
            cursor: pointer;
        }
        .mg-link:hover {
            background: #f0f4f8;
            transform: translateX(2px);
        }
        .mg-icon {
            font-size: 1.5rem;
            line-height: 1;
            flex-shrink: 0;
            margin-top: 2px;
        }
        .mg-content {
            flex: 1;
            min-width: 0;
        }
        .mg-title {
            font-size: 0.875rem;
            font-weight: 500;
            color: #1e293b;
            margin-bottom: 2px;
        }
        .mg-desc {
            font-size: 0.75rem;
            color: #64748b;
        }

        /* Quick Actions Grid */
        .quick-actions-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
            gap: 1rem;
        }
        .quick-action-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 1.5rem 1rem;
            background: linear-gradient(135deg, #f0f4f8 0%, #f8fafc 100%);
            border: 1px solid var(--tblr-border-color);
            border-radius: 0.75rem;
            text-decoration: none;
            transition: all 0.3s;
            text-align: center;
            gap: 0.5rem;
        }
        .quick-action-item:hover {
            background: linear-gradient(135deg, #e0e9f8 0%, #f0f6fc 100%);
            border-color: var(--primary-color, var(--tblr-primary));
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(30, 64, 175, 0.15);
        }
        .quick-action-icon {
            font-size: 2rem;
            line-height: 1;
        }
        .quick-action-label {
            font-size: 0.813rem;
            font-weight: 500;
            color: #374151;
        }
        .quick-action-item:hover .quick-action-label {
            color: var(--primary-color, var(--tblr-primary));
        }

        /* Info Grid */
        .info-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1.5rem;
        }
        .info-item {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }
        .info-item span:first-child {
            font-size: 0.75rem;
            font-weight: 600;
            text-transform: uppercase;
            color: #94a3b8;
            letter-spacing: 0.05em;
        }
        .info-item span:last-child {
            font-size: 1rem;
            font-weight: 500;
            color: #1e293b;
        }

        /* Stats Grid */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1rem;
            margin-bottom: 1.5rem;
        }
        .stat-card {
            background: var(--tblr-bg-surface);
            border: 1px solid var(--tblr-border-color);
            border-radius: 0.5rem;
            padding: 1.5rem;
            transition: all 0.3s;
        }
        .stat-card:hover {
            border-color: var(--primary-color, var(--tblr-primary));
            box-shadow: 0 4px 12px rgba(30, 64, 175, 0.1);
        }
        .stat-card-content {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            gap: 1rem;
        }
        .stat-card-text h3 {
            margin: 0;
            font-size: 0.875rem;
            font-weight: 500;
            color: #64748b;
            text-transform: capitalize;
        }
        .stat-card-icon {
            width: 48px;
            height: 48px;
            border-radius: 0.5rem;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }
        .stat-card-icon svg {
            width: 24px;
            height: 24px;
            color: white;
        }
        .stat-card-icon.blue { background: #3b82f6; }
        .stat-card-icon.green { background: #10b981; }
        .stat-card-icon.purple { background: #8b5cf6; }
        .stat-card-icon.yellow { background: #f59e0b; }

        /* Page Title */
        .page-title {
            margin-bottom: 2rem;
        }
        .page-title h1 {
            margin: 0 0 0.5rem 0;
            font-size: 1.875rem;
            font-weight: 700;
            color: #1e293b;
        }
        .page-title p {
            margin: 0;
            color: #64748b;
            font-size: 0.938rem;
        }

        /* Sidebar scrollbar */
        .sidebar::-webkit-scrollbar { width: 4px; }
        .sidebar::-webkit-scrollbar-track { background: transparent; }
        .sidebar::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 4px; }
    </style>
</head>
<body>
    <!-- Navbar -->
    <nav class="navbar">
        <a href="{{ url('/admin') }}" class="navbar-brand">
            🎖️ Askeri Platform Admin
        </a>
        <div class="navbar-nav">
            <a href="{{ url('/') }}" target="_blank" class="nav-link">🌐 Siteyi Görüntüle</a>
            <span class="nav-link" style="color:#374151;font-weight:500;">{{ auth()->user()->name }}</span>
            <form method="POST" action="{{ route('logout') }}" class="d-inline">
                @csrf
                <button type="submit" class="btn btn-sm" style="background: #ef4444; color: white;">Çıkış</button>
            </form>
        </div>
    </nav>

    <!-- Sidebar -->
    <aside class="sidebar">
        <ul class="sidebar-nav">

            {{-- Ana Menü --}}
            <li class="nav-section-title">Ana Menü</li>
            <li class="nav-item">
                <a href="{{ url('/admin') }}" class="nav-link {{ request()->is('admin') ? 'active' : '' }}">
                    📊 Dashboard
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ url('/admin/istatistikler') }}" class="nav-link {{ request()->is('admin/istatistikler') ? 'active' : '' }}">
                    📈 İstatistikler
                </a>
            </li>

            {{-- Ana Sayfa --}}
            <li class="nav-section-title">Görünüm</li>
            <li class="nav-item">
                <a href="{{ route('admin.homepage.index') }}" class="nav-link {{ request()->is('admin/homepage*') ? 'active' : '' }}">
                    🏠 Ana Sayfa Widgetları
                </a>
            </li>

            {{-- Blog --}}
            <li class="nav-section-title">İçerik Yönetimi</li>

            @php
                $blogActive = request()->is('admin/blog*') || request()->is('admin/blog-categories*') || request()->is('admin/blog-comments*');
                $forumActive = request()->is('admin/forum*');
                $libraryActive = request()->is('admin/library*');
                $interviewActive = request()->is('admin/interview*');
                $chatActive = request()->is('admin/chat*');
            @endphp

            <li class="nav-group {{ $blogActive ? 'has-active' : '' }}">
                <button class="nav-group-toggle {{ $blogActive ? 'open' : '' }}" onclick="toggleGroup(this)">
                    <span class="nav-group-label">📝 Blog</span>
                    <span class="toggle-icon">▶</span>
                </button>
                <ul class="nav-sub {{ $blogActive ? 'open' : '' }}">
                    <li class="nav-item">
                        <a href="{{ url('/admin/blog') }}" class="nav-link {{ request()->is('admin/blog') || request()->is('admin/blog/create') ? 'active' : '' }}">
                            📄 Yazılar
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/blog-categories') }}" class="nav-link {{ request()->is('admin/blog-categories*') ? 'active' : '' }}">
                            📁 Kategoriler
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/blog-comments') }}" class="nav-link {{ request()->is('admin/blog-comments*') ? 'active' : '' }}">
                            💬 Yorumlar
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/seo') }}" class="nav-link {{ request()->is('admin/seo*') ? 'active' : '' }}">
                            🔍 SEO Ayarları
                        </a>
                    </li>
                </ul>
            </li>

            <li class="nav-group {{ $forumActive ? 'has-active' : '' }}">
                <button class="nav-group-toggle {{ $forumActive ? 'open' : '' }}" onclick="toggleGroup(this)">
                    <span class="nav-group-label">💬 Forum</span>
                    <span class="toggle-icon">▶</span>
                </button>
                <ul class="nav-sub {{ $forumActive ? 'open' : '' }}">
                    <li class="nav-item">
                        <a href="{{ url('/admin/forum-categories') }}" class="nav-link {{ request()->is('admin/forum-categories*') ? 'active' : '' }}">
                            📂 Kategoriler
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/forum-topics') }}" class="nav-link {{ request()->is('admin/forum-topics*') ? 'active' : '' }}">
                            📋 Konular
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/forum-posts') }}" class="nav-link {{ request()->is('admin/forum-posts*') ? 'active' : '' }}">
                            📨 Gönderiler
                        </a>
                    </li>
                </ul>
            </li>

            <li class="nav-group {{ $libraryActive ? 'has-active' : '' }}">
                <button class="nav-group-toggle {{ $libraryActive ? 'open' : '' }}" onclick="toggleGroup(this)">
                    <span class="nav-group-label">📚 Kütüphane</span>
                    <span class="toggle-icon">▶</span>
                </button>
                <ul class="nav-sub {{ $libraryActive ? 'open' : '' }}">
                    <li class="nav-item">
                        <a href="{{ url('/admin/library') }}" class="nav-link {{ request()->is('admin/library') ? 'active' : '' }}">
                            📊 Genel Bakış
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/library-contents') }}" class="nav-link {{ request()->is('admin/library-contents*') ? 'active' : '' }}">
                            📄 İçerikler
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/library-categories') }}" class="nav-link {{ request()->is('admin/library-categories*') ? 'active' : '' }}">
                            📁 Kategoriler
                        </a>
                    </li>
                </ul>
            </li>

            <li class="nav-group {{ $interviewActive ? 'has-active' : '' }}">
                <button class="nav-group-toggle {{ $interviewActive ? 'open' : '' }}" onclick="toggleGroup(this)">
                    <span class="nav-group-label">🎯 Mülakat</span>
                    <span class="toggle-icon">▶</span>
                </button>
                <ul class="nav-sub {{ $interviewActive ? 'open' : '' }}">
                    <li class="nav-item">
                        <a href="{{ url('/admin/interview') }}" class="nav-link {{ request()->is('admin/interview') ? 'active' : '' }}">
                            📊 Genel Bakış
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/interview-questions') }}" class="nav-link {{ request()->is('admin/interview-questions*') ? 'active' : '' }}">
                            ❓ Sorular
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/interview-categories') }}" class="nav-link {{ request()->is('admin/interview-categories*') ? 'active' : '' }}">
                            📁 Kategoriler
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/interview-flashcards') }}" class="nav-link {{ request()->is('admin/interview-flashcards*') ? 'active' : '' }}">
                            🃏 Flashcard'lar
                        </a>
                    </li>
                </ul>
            </li>

            <li class="nav-group {{ $chatActive ? 'has-active' : '' }}">
                <button class="nav-group-toggle {{ $chatActive ? 'open' : '' }}" onclick="toggleGroup(this)">
                    <span class="nav-group-label">🗨️ Sohbet</span>
                    <span class="toggle-icon">▶</span>
                </button>
                <ul class="nav-sub {{ $chatActive ? 'open' : '' }}">
                    <li class="nav-item">
                        <a href="{{ url('/admin/chat-rooms') }}" class="nav-link {{ request()->is('admin/chat-rooms*') ? 'active' : '' }}">
                            🏠 Odalar
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('/admin/chat-categories') }}" class="nav-link {{ request()->is('admin/chat-categories*') ? 'active' : '' }}">
                            📁 Kategoriler
                        </a>
                    </li>
                </ul>
            </li>

            {{-- Sistem Yönetimi --}}
            <li class="nav-section-title">Sistem Yönetimi</li>
            <li class="nav-item">
                <a href="{{ url('/admin/users') }}" class="nav-link {{ request()->is('admin/users*') ? 'active' : '' }}">
                    👥 Kullanıcılar
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ url('/admin/menus') }}" class="nav-link {{ request()->is('admin/menus*') ? 'active' : '' }}">
                    🗂️ Menü Yönetimi
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ url('/admin/modules') }}" class="nav-link {{ request()->is('admin/modules*') ? 'active' : '' }}">
                    📦 Modüller
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ url('/admin/adsense') }}" class="nav-link {{ request()->is('admin/adsense*') ? 'active' : '' }}">
                    💰 AdSense
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ url('/admin/pages') }}" class="nav-link {{ request()->is('admin/pages*') ? 'active' : '' }}">
                    📄 Statik Sayfalar
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ url('/admin/settings') }}" class="nav-link {{ request()->is('admin/settings*') ? 'active' : '' }}">
                    ⚙️ Site Ayarları
                </a>
            </li>

        </ul>
    </aside>

    <!-- Main Content -->
    <main class="main-content">
        @if(session('success'))
            <div class="alert alert-success">
                ✅ {{ session('success') }}
            </div>
        @endif
        
        @if(session('error'))
            <div class="alert alert-danger">
                ❌ {{ session('error') }}
            </div>
        @endif

        @yield('content')
    </main>

    <script>
        function toggleGroup(btn) {
            btn.classList.toggle('open');
            const sub = btn.nextElementSibling;
            sub.classList.toggle('open');
        }
    </script>
</body>
</html>
