<x-admin-layout>
    <x-slot name="header">
        <div class="flex items-center justify-between">
            <div>
                <h2 class="font-semibold text-lg text-gray-800 dark:text-gray-200 leading-tight">
                    <i class="fas fa-cog mr-2"></i>{{ __('Setari') }}
                </h2>
                <p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
                    <a href="{{ route('dashboard') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Dashboard</a>
                    <span class="mx-2">/</span>
                    <a href="{{ route('admin.dashboard') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Admin</a>
                    <span class="mx-2">/</span>
                    <span>Setari</span>
                    <span class="mx-2">/</span>
                    <span>CronJobs</span>
                </p>
            </div>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="px-6 lg:px-8">
            <div class="flex gap-6">
                <!-- Settings Sidebar Menu -->
                <x-settings-sidebar />

                <!-- Main Content Area -->
                <div class="flex-1">
<div class="container mx-auto"  style="padding: 0;">

    {{-- Mesaje de Succes/Eroare --}}
    @if(session('success'))
        <div class="bg-green-50 dark:bg-green-900/20 border-l-4 border-green-500 p-4 mb-6 rounded-lg">
            <div class="flex items-center">
                <svg class="h-6 w-6 text-green-500 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                </svg>
                <p class="text-green-700 dark:text-green-300 font-medium">{{ session('success') }}</p>
            </div>
        </div>
    @endif

    @if(session('error'))
        <div class="bg-red-50 dark:bg-red-900/20 border-l-4 border-red-500 p-4 mb-6 rounded-lg">
            <div class="flex items-center">
                <svg class="h-6 w-6 text-red-500 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                </svg>
                <p class="text-red-700 dark:text-red-300 font-medium">{{ session('error') }}</p>
            </div>
        </div>
    @endif

    @if($errors->any())
        <div class="bg-red-50 dark:bg-red-900/20 border-l-4 border-red-500 p-4 mb-6 rounded-lg">
            <div class="flex items-start">
                <svg class="h-6 w-6 text-red-500 mr-3 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                </svg>
                <div>
                    <p class="text-red-700 dark:text-red-300 font-medium mb-2">Erori de validare:</p>
                    <ul class="list-disc list-inside text-red-600 dark:text-red-400 text-sm">
                        @foreach($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            </div>
        </div>
    @endif

    {{-- Status Dashboard --}}
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
        <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">📊 Status Scheduler</h2>

        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div class="bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4">
                <div class="flex items-center">
                    <div class="flex-shrink-0">
                        <svg class="h-8 w-8 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                        </svg>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-green-900 dark:text-green-300">Status</p>
                        <p class="text-lg font-bold text-green-600 dark:text-green-400">Activ</p>
                    </div>
                </div>
            </div>

            <div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
                <div class="flex items-center">
                    <div class="flex-shrink-0">
                        <svg class="h-8 w-8 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                        </svg>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-blue-900 dark:text-blue-300">Ultima rulare</p>
                        <p class="text-lg font-bold text-blue-600 dark:text-blue-400" id="lastRun">{{ now()->format('H:i:s') }}</p>
                    </div>
                </div>
            </div>

            <div class="bg-purple-50 dark:bg-purple-900/20 border border-purple-200 dark:border-purple-800 rounded-lg p-4">
                <div class="flex items-center">
                    <div class="flex-shrink-0">
                        <svg class="h-8 w-8 text-purple-600 dark:text-purple-400" 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"></path>
                        </svg>
                    </div>
                    <div class="ml-4">
                        <p class="text-sm font-medium text-purple-900 dark:text-purple-300">Total comenzi</p>
                        <p class="text-lg font-bold text-purple-600 dark:text-purple-400">{{ collect($categorizedCommands)->sum(fn($cat) => count($cat['commands'])) }}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {{-- Acțiuni Rapide --}}
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
        <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">⚡ Acțiuni Rapide</h2>

        <div class="flex flex-wrap gap-3">
            <button onclick="runScheduler()" class="inline-flex items-center px-4 py-2 bg-green-600 hover:bg-green-700 text-white font-semibold rounded-lg transition">
                <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"></path>
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                </svg>
                Rulează Scheduler
            </button>

            <button onclick="restartQueue()" class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg transition">
                <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
                </svg>
                Restart Queue
            </button>

            <button onclick="showLogs()" class="inline-flex items-center px-4 py-2 bg-gray-600 hover:bg-gray-700 text-white font-semibold rounded-lg transition">
                <svg class="w-5 h-5 mr-2" 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"></path>
                </svg>
                Vezi Log-uri
            </button>

            <button onclick="refreshStatus()" class="inline-flex items-center px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white font-semibold rounded-lg transition">
                <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
                </svg>
                Refresh Status
            </button>

            {{-- Separator --}}
            <div class="w-px h-10 bg-gray-300 dark:bg-gray-600 mx-1"></div>

            {{-- Documentație --}}
            <button onclick="showWindowsDocs()" class="inline-flex items-center px-4 py-2 bg-cyan-600 hover:bg-cyan-700 text-white font-semibold rounded-lg transition">
                <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 24 24">
                    <path d="M0 3.449L9.75 2.1v9.451H0m10.949-9.602L24 0v11.4H10.949M0 12.6h9.75v9.451L0 20.699M10.949 12.6H24V24l-12.9-1.801"/>
                </svg>
                Docs Windows
            </button>

            <button onclick="showLinuxDocs()" class="inline-flex items-center px-4 py-2 bg-orange-600 hover:bg-orange-700 text-white font-semibold rounded-lg transition">
                <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 24 24">
                    <path d="M12.504 0c-.155 0-.315.008-.48.021-4.226.333-3.105 4.807-3.17 6.298-.076 1.092-.3 1.953-1.05 3.02-.885 1.051-2.127 2.75-2.716 4.521-.278.832-.41 1.684-.287 2.489a.424.424 0 00-.11.135c-.26.268-.45.6-.663.839-.199.199-.485.267-.797.4-.313.136-.658.269-.864.68-.09.189-.136.394-.132.602 0 .199.027.4.055.536.058.399.116.728.04.97-.249.68-.28 1.145-.106 1.484.174.334.535.47.94.601.81.2 1.91.135 2.774.6.926.466 1.866.67 2.616.47.526-.116.97-.464 1.208-.946.587-.003 1.23-.269 2.26-.334.699-.058 1.574.267 2.577.2.025.134.063.198.114.333l.003.003c.391.778 1.113 1.132 1.884 1.071.771-.06 1.592-.536 2.257-1.306.631-.765 1.683-1.084 2.378-1.503.348-.199.629-.469.649-.853.023-.4-.2-.811-.714-1.376v-.097l-.003-.003c-.17-.2-.25-.535-.338-.926-.085-.401-.182-.786-.492-1.046h-.003c-.059-.054-.123-.067-.188-.135a.357.357 0 00-.19-.064c.431-1.278.264-2.55-.173-3.694-.533-1.41-1.465-2.638-2.175-3.483-.796-1.005-1.576-1.957-1.56-3.368.026-2.152.236-6.133-3.544-6.139zm.529 3.405h.013c.213 0 .396.062.584.198.19.135.33.332.438.533.105.259.158.459.166.724 0-.02.006-.04.006-.06v.105a.086.086 0 01-.004-.021l-.004-.024a1.807 1.807 0 01-.15.706.953.953 0 01-.213.335.71.71 0 00-.088-.042c-.104-.045-.198-.064-.284-.133a1.312 1.312 0 00-.22-.066c.05-.06.146-.133.183-.198.053-.128.082-.264.088-.402v-.02a1.21 1.21 0 00-.061-.4c-.045-.134-.101-.2-.183-.333-.084-.066-.167-.132-.267-.132h-.016c-.093 0-.176.03-.262.132a.8.8 0 00-.205.334 1.18 1.18 0 00-.09.4v.019c.002.089.008.179.02.267-.193-.067-.438-.135-.607-.202a1.635 1.635 0 01-.018-.2v-.02a1.772 1.772 0 01.15-.768c.082-.22.232-.406.43-.533a.985.985 0 01.594-.2zm-2.962.059h.036c.142 0 .27.048.399.135.146.129.264.288.344.465.09.199.14.4.153.667v.004c.007.134.006.2-.002.266v.08c-.03.007-.056.018-.083.024-.152.055-.274.135-.393.2.012-.09.013-.18.003-.267v-.015c-.012-.133-.04-.2-.082-.333a.613.613 0 00-.166-.267.248.248 0 00-.183-.064h-.021c-.071.006-.13.04-.186.132a.552.552 0 00-.12.27.944.944 0 00-.023.33v.015c.012.135.037.2.08.334.046.134.098.2.166.268.01.009.02.018.034.024-.07.057-.117.07-.176.136a.304.304 0 01-.131.068 2.62 2.62 0 01-.275-.402 1.772 1.772 0 01-.155-.667 1.759 1.759 0 01.08-.668 1.43 1.43 0 01.283-.535c.128-.133.26-.2.418-.2zm1.37 1.706c.332 0 .733.065 1.216.399.293.2.523.269 1.052.468h.003c.255.136.405.266.478.399v-.131a.571.571 0 01.016.47c-.123.31-.516.643-1.063.842v.002c-.268.135-.501.333-.775.465-.276.135-.588.292-1.012.267a1.139 1.139 0 01-.448-.067 3.566 3.566 0 01-.322-.198c-.195-.135-.363-.332-.612-.465v-.005h-.005c-.4-.246-.616-.512-.686-.71-.07-.268-.005-.47.193-.6.224-.135.38-.271.483-.336.104-.074.143-.102.176-.131h.002v-.003c.169-.202.436-.47.839-.601.139-.036.294-.065.466-.065zm2.8 2.142c.358 1.417 1.196 3.475 1.735 4.473.286.534.855 1.659 1.102 3.024.156-.005.33.018.513.064.646-1.671-.546-3.467-1.089-3.966-.22-.2-.232-.335-.123-.335.59.534 1.365 1.572 1.646 2.757.13.535.16 1.104.021 1.67.067.028.135.06.205.067 1.032.534 1.413.938 1.23 1.537v-.002c-.06-.135-.12-.2-.18-.264-.126-.135-.263-.135-.34-.135-.142-.066-.28-.135-.418-.135-.128-.064-.262-.135-.382-.198h-.003c-.03-.136-.056-.2-.082-.267a1.99 1.99 0 00-.277-.4c.046-.067.068-.132.088-.2.025-.135.023-.2-.006-.4a2.04 2.04 0 00-.2-.535h-.003c-.04-.134-.093-.2-.142-.268-.052-.133-.108-.199-.168-.265l-.003-.003c-.022-.066-.04-.2-.022-.4.013-.2-.023-.465-.085-.668-.062-.135-.128-.267-.188-.333-.126-.2-.262-.535-.39-.869-.04-.2-.08-.468-.082-.668 0-.2-.028-.468-.071-.733-.066-.334-.152-.467-.225-.734-.067-.135-.133-.267-.194-.465-.065-.134-.125-.332-.185-.597a.48.48 0 00.003-.003c.562.533 1.303 1.27 1.63 2.079.023.053.042.104.058.155.033-.002.063-.006.095-.006h.003zm-7.246 1.037l.003.003c.168.168.288.467.448.73.068.135.148.2.224.268.034.066.065.132.092.198.052.135.082.2.091.333l.007-.007c-.023.2-.002.4.064.6.016.067.038.2.062.268.043.2.091.6.086.867-.013.401-.073.734-.159 1.001-.081.334-.2.6-.28.666-.082.067-.167.135-.27.135-.155.067-.317.136-.477.202-.005-.003-.007-.005-.013-.005-.192-.066-.371-.2-.555-.333-.157-.136-.289-.268-.414-.4-.146-.202-.3-.403-.427-.534-.128-.068-.262-.135-.374-.2-.103-.06-.2-.1-.268-.134-.15-.135-.266-.267-.371-.4a1.602 1.602 0 01-.09-.333c-.036-.067-.064-.133-.084-.199a2.772 2.772 0 01-.034-.534 2.8 2.8 0 01.027-.468l.008.008c-.003-.067.006-.133.011-.2.028-.133.054-.267.088-.4.025-.066.054-.132.084-.198.033-.067.067-.133.1-.198.036-.068.075-.133.11-.199.04-.067.085-.135.13-.202.04-.068.083-.202.125-.268.05-.2.102-.332.156-.467.057-.133.115-.265.178-.398.063-.133.132-.197.2-.331.066-.134.137-.268.2-.4.062-.133.126-.267.183-.334l.203-.002z"/>
                </svg>
                Docs Linux/cPanel
            </button>
        </div>
    </div>

    {{-- Configurare Intervale CronJobs --}}
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
        <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">⚙️ Configurare Intervale CronJobs</h2>

        <form action="{{ route('admin.cronjobs.save-settings') }}" method="POST" class="space-y-4">
            @csrf

            {{-- Rândul 1: Verificare Name Servers + Statistici DNS (Ieri) --}}
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
                {{-- Verificare Name Servers --}}
                <div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-5">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-lg font-semibold text-gray-900 dark:text-white flex items-center">
                            <i class="fas fa-server mr-2 text-blue-600"></i>
                            Verificare Name Servers
                        </h3>
                        <label class="relative inline-flex items-center cursor-pointer">
                            <input type="checkbox" name="cron_nameserver_check_enabled" value="1"
                                   {{ setting('cron_nameserver_check_enabled', true) ? 'checked' : '' }}
                                   class="sr-only peer">
                            <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
                            <span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Activat</span>
                        </label>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                            Interval de verificare (minute)
                        </label>
                        <input type="number" name="cron_nameserver_check_interval"
                               value="{{ setting('cron_nameserver_check_interval', 5) }}"
                               min="1" max="1440" required
                               class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white">
                        <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">Minim: 1 minut, Maxim: 1440 minute (24 ore)</p>
                    </div>
                </div>

                {{-- Statistici DNS (Ieri) --}}
                <div class="bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-5">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-lg font-semibold text-gray-900 dark:text-white flex items-center">
                            <i class="fas fa-chart-bar mr-2 text-green-600"></i>
                            Statistici DNS (Ieri)
                        </h3>
                        <label class="relative inline-flex items-center cursor-pointer">
                            <input type="checkbox" name="cron_statistics_yesterday_enabled" value="1"
                                   {{ setting('cron_statistics_yesterday_enabled', true) ? 'checked' : '' }}
                                   class="sr-only peer">
                            <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-green-300 dark:peer-focus:ring-green-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-green-600"></div>
                            <span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Activat</span>
                        </label>
                    </div>
                    <div class="grid grid-cols-2 gap-3">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Interval (minute)
                            </label>
                            <input type="number" name="cron_statistics_yesterday_interval"
                                   value="{{ setting('cron_statistics_yesterday_interval', 30) }}"
                                   min="1" max="1440" required
                                   class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-green-500 dark:bg-gray-700 dark:text-white">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Limita zone
                            </label>
                            <input type="number" name="cron_statistics_yesterday_limit"
                                   value="{{ setting('cron_statistics_yesterday_limit', 20) }}"
                                   min="1" max="1000" required
                                   class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-green-500 dark:bg-gray-700 dark:text-white">
                        </div>
                    </div>
                    <p class="mt-2 text-xs text-gray-500 dark:text-gray-400">Numărul maxim de zone procesate la fiecare rulare</p>
                </div>
            </div>

            {{-- Rândul 2: Statistici DNS (Azi) + Verificare Zone DNS & Alerte --}}
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
                {{-- Statistici DNS (Azi) --}}
                <div class="bg-purple-50 dark:bg-purple-900/20 border border-purple-200 dark:border-purple-800 rounded-lg p-5">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-lg font-semibold text-gray-900 dark:text-white flex items-center">
                            <i class="fas fa-chart-line mr-2 text-purple-600"></i>
                            Statistici DNS (Azi)
                        </h3>
                        <label class="relative inline-flex items-center cursor-pointer">
                            <input type="checkbox" name="cron_statistics_today_enabled" value="1"
                                   {{ setting('cron_statistics_today_enabled', true) ? 'checked' : '' }}
                                   class="sr-only peer">
                            <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-purple-300 dark:peer-focus:ring-purple-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-purple-600"></div>
                            <span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Activat</span>
                        </label>
                    </div>
                    <div class="grid grid-cols-2 gap-3">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Interval (minute)
                            </label>
                            <input type="number" name="cron_statistics_today_interval"
                                   value="{{ setting('cron_statistics_today_interval', 15) }}"
                                   min="1" max="1440" required
                                   class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-purple-500 dark:bg-gray-700 dark:text-white">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Limita zone
                            </label>
                            <input type="number" name="cron_statistics_today_limit"
                                   value="{{ setting('cron_statistics_today_limit', 10) }}"
                                   min="1" max="1000" required
                                   class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-purple-500 dark:bg-gray-700 dark:text-white">
                        </div>
                    </div>
                    <p class="mt-2 text-xs text-gray-500 dark:text-gray-400">Numărul maxim de zone procesate la fiecare rulare</p>
                </div>

                {{-- Verificare Zone DNS & Alerte --}}
                <div class="bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg p-5">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-lg font-semibold text-gray-900 dark:text-white flex items-center">
                            <i class="fas fa-exclamation-triangle mr-2 text-orange-600"></i>
                            Verificare Zone DNS & Alerte
                        </h3>
                        <label class="relative inline-flex items-center cursor-pointer">
                            <input type="checkbox" name="cron_dns_health_check_enabled" value="1"
                                   {{ setting('cron_dns_health_check_enabled', true) ? 'checked' : '' }}
                                   class="sr-only peer">
                            <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-orange-300 dark:peer-focus:ring-orange-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-orange-600"></div>
                            <span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Activat</span>
                        </label>
                    </div>
                    <div class="grid grid-cols-2 gap-3">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Interval (minute)
                            </label>
                            <input type="number" name="cron_dns_health_check_interval"
                                   value="{{ setting('cron_dns_health_check_interval', 30) }}"
                                   min="1" max="1440" required
                                   class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-orange-500 dark:bg-gray-700 dark:text-white">
                        </div>
                        <div class="flex items-end pb-1">
                            <label class="relative inline-flex items-center cursor-pointer">
                                <input type="checkbox" name="cron_dns_health_check_notify" value="1"
                                       {{ setting('cron_dns_health_check_notify', true) ? 'checked' : '' }}
                                       class="sr-only peer">
                                <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-orange-300 dark:peer-focus:ring-orange-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-orange-600"></div>
                                <span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">
                                    <i class="fas fa-bell mr-1"></i>
                                    Notificări email
                            </span>
                        </label>
                    </div>
                </div>
                <p class="mt-2 text-xs text-gray-500 dark:text-gray-400">Verifică zonele DNS offline și trimite alerte către administratori</p>
            </div>

            {{-- Buton Salvare --}}
            <div class="flex justify-end pt-4 border-t border-gray-200 dark:border-gray-700">
                <button type="submit" class="inline-flex items-center px-6 py-2.5 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg transition shadow-md hover:shadow-lg">
                    <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
                    </svg>
                    Salvează Configurare
                </button>
            </div>
        </form>
    </div>

    {{-- Comenzi Scheduled --}}
    @foreach($categorizedCommands as $category)
        @if(count($category['commands']) > 0)
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
            <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">{!! $category['title'] !!}</h2>

            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
                    <thead class="bg-gray-50 dark:bg-gray-700">
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Comanda</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Frecven?a</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Urmatoarea Rulare</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Status</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
                        @foreach($category['commands'] as $command)
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 dark:text-white">
                                <code class="bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded">{{ $command['command'] }}</code>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
                                {{ $command['expression'] }}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
                                {{ \Carbon\Carbon::parse($command['next_run'])->format('d.m.Y H:i:s') }}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300">
                                    ? Activ
                                </span>
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        @endif
    @endforeach

    {{-- Queue Status --}}
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
        <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">📋 Queue Status</h2>

        <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
            <div class="bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4">
                <p class="text-sm font-medium text-yellow-900 dark:text-yellow-300">Pending Jobs</p>
                <p class="text-2xl font-bold text-yellow-600 dark:text-yellow-400" id="pendingJobs">{{ $queueStatus['pending'] }}</p>
            </div>

            <div class="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4">
                <p class="text-sm font-medium text-red-900 dark:text-red-300">Failed Jobs</p>
                <p class="text-2xl font-bold text-red-600 dark:text-red-400" id="failedJobs">{{ $queueStatus['failed'] }}</p>
            </div>

            <div class="bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4">
                <p class="text-sm font-medium text-green-900 dark:text-green-300">Status</p>
                <p class="text-2xl font-bold text-green-600 dark:text-green-400" id="queueStatus">{{ ucfirst($queueStatus['status']) }}</p>
            </div>
        </div>

        <div class="flex gap-3">
            <button onclick="showFailedJobs()" class="inline-flex items-center px-4 py-2 bg-red-600 hover:bg-red-700 text-white font-semibold rounded-lg transition">
                Vezi Failed Jobs
            </button>
            <button onclick="retryAllFailed()" class="inline-flex items-center px-4 py-2 bg-orange-600 hover:bg-orange-700 text-white font-semibold rounded-lg transition">
                Retry All Failed
            </button>
        </div>
    </div>

    {{-- Ultimele Execuții --}}
    @if(count($recentExecutions) > 0)
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
        <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">📜 Ultimele Execuții</h2>

        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
                <thead class="bg-gray-50 dark:bg-gray-700">
                    <tr>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Timp</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Comanda</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Durata</th>
                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Status</th>
                    </tr>
                </thead>
                <tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
                    @foreach($recentExecutions as $execution)
                    <tr>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
                            {{ $execution['time'] }}
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 dark:text-white">
                            <code class="bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded">{{ $execution['command'] }}</code>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
                            {{ $execution['duration'] ?? '-' }} sec
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            @if($execution['status'] === 'done')
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300">
                                    ✓ Done
                                </span>
                            @elseif($execution['status'] === 'fail')
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300">
                                    ✗ Failed
                                </span>
                            @else
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300">
                                    ⟳ Running
                                </span>
                            @endif
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
    @endif

    {{-- Windows Task Scheduler Setup --}}
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
        <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">🪟 Configurare Windows Task Scheduler</h2>

        @if($taskSchedulerConfigured)
            <div class="bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4 mb-4">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <svg class="h-5 w-5 text-green-400" 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"></path>
                        </svg>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-sm font-medium text-green-800 dark:text-green-300">✓ Task Scheduler este configurat!</h3>
                        <p class="mt-2 text-sm text-green-700 dark:text-green-400">Scheduler-ul rulează automat la fiecare minut.</p>
                    </div>
                </div>
            </div>
        @else
            <div class="bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4 mb-4">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <svg class="h-5 w-5 text-yellow-400" fill="currentColor" viewBox="0 0 20 20">
                            <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"></path>
                        </svg>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-sm font-medium text-yellow-800 dark:text-yellow-300">⚠️ Task Scheduler nu este configurat</h3>
                        <p class="mt-2 text-sm text-yellow-700 dark:text-yellow-400">Pentru ca scheduler-ul să ruleze automat, trebuie să configurezi Windows Task Scheduler.</p>
                    </div>
                </div>
            </div>

            <div class="space-y-4">
                <div>
                    <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">Metoda 1: Automată (Recomandată)</h3>
                    <p class="text-sm text-gray-600 dark:text-gray-400 mb-3">Descarcă și rulează scriptul de setup ca Administrator:</p>
                    <a href="{{ route('admin.cronjobs.download-script') }}" class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg transition">
                        <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path>
                        </svg>
                        Download Setup Script
                    </a>
                </div>

                <div>
                    <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">Metoda 2: Manuală</h3>
                    <p class="text-sm text-gray-600 dark:text-gray-400 mb-3">Deschide PowerShell ca Administrator și rulează:</p>
                    <div class="bg-gray-900 rounded-lg p-4">
                        <code class="text-green-400 text-sm" id="setupCommand">schtasks /create /tn "Laravel Scheduler - PanelDNS" /tr "{{ base_path('run-scheduler.bat') }}" /sc minute /mo 1 /ru SYSTEM /f</code>
                    </div>
                    <button onclick="copyCommand()" class="mt-2 inline-flex items-center px-3 py-1 bg-gray-600 hover:bg-gray-700 text-white text-sm font-semibold rounded transition">
                        📋 Copiază Comanda
                    </button>
                </div>
            </div>
        @endif
    </div>
</div>

{{-- Modal pentru Log-uri --}}
<div id="logsModal" class="hidden fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4" onclick="if(event.target === this) closeLogs()">
    <div class="relative w-full max-w-3xl shadow-2xl rounded-2xl bg-white dark:bg-gray-800 animate-fade-in-scale overflow-hidden">
        <!-- Header cu gradient -->
        <div class="bg-gradient-to-r from-blue-600 to-indigo-600 px-5 py-3.5">
            <div class="flex justify-between items-center">
                <div class="flex items-center text-white">
                    <div class="bg-white bg-opacity-20 p-2 rounded-lg mr-2.5 backdrop-blur-sm">
                        <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"></path>
                        </svg>
                    </div>
                    <div>
                        <h3 class="text-lg font-bold">📋 Scheduler Logs</h3>
                        <p class="text-xs text-blue-100">Ultimele 50 linii</p>
                    </div>
                </div>
                <button onclick="closeLogs()" class="text-white hover:bg-white hover:bg-opacity-20 p-1.5 rounded-lg transition-all duration-200">
                    <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="M6 18L18 6M6 6l12 12"></path>
                    </svg>
                </button>
            </div>
        </div>

        <!-- Content -->
        <div class="p-5">
            <!-- Actions -->
            <div class="flex gap-2 mb-4">
                <button onclick="refreshLogs()" class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-semibold rounded-lg transition-all duration-200 shadow-md hover:shadow-lg">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
                    </svg>
                    Refresh
                </button>
                <button onclick="copyLogs()" class="inline-flex items-center px-4 py-2 bg-gray-600 hover:bg-gray-700 text-white text-sm font-semibold rounded-lg transition-all duration-200 shadow-md hover:shadow-lg">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path>
                    </svg>
                    Copiaza
                </button>
                <div class="flex-1"></div>
                <span class="inline-flex items-center px-3 py-2 bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200 text-xs font-semibold rounded-lg">
                    <span class="w-2 h-2 bg-green-500 rounded-full mr-2 animate-pulse"></span>
                    Live
                </span>
            </div>

            <!-- Log Content -->
            <div class="bg-gray-900 rounded-xl p-4 shadow-inner border border-gray-700" style="height: 400px; overflow-y: auto;">
                <pre id="logsContent" class="text-green-400 text-xs font-mono whitespace-pre-wrap leading-relaxed"></pre>
            </div>
        </div>

        <!-- Footer -->
        <div class="bg-gray-50 dark:bg-gray-900 px-5 py-3 border-t border-gray-200 dark:border-gray-700">
            <div class="flex justify-between items-center">
                <p class="text-xs text-gray-600 dark:text-gray-400 flex items-center">
                    <svg class="w-4 h-4 mr-1.5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                    </svg>
                    Auto-refresh la fiecare 30 secunde
                </p>
                <button onclick="closeLogs()" class="px-5 py-2 bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-200 font-semibold rounded-lg transition-all duration-200 shadow-sm hover:shadow-md">
                    Închide
                </button>
            </div>
        </div>
    </div>
</div>

<style>
@keyframes fade-in-scale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
.animate-fade-in-scale {
    animation: fade-in-scale 0.2s ease-out;
}

/* Custom scrollbar pentru log content */
#logsContent::-webkit-scrollbar {
    width: 8px;
}
#logsContent::-webkit-scrollbar-track {
    background: #1f2937;
    border-radius: 4px;
}
#logsContent::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 4px;
}
#logsContent::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Custom scrollbar pentru modale documentație */
.modal-scroll-content {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #4b5563 #1f2937;
}
.modal-scroll-content::-webkit-scrollbar {
    width: 10px;
}
.modal-scroll-content::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 5px;
}
.dark .modal-scroll-content::-webkit-scrollbar-track {
    background: #1f2937;
}
.modal-scroll-content::-webkit-scrollbar-thumb {
    background: #9ca3af;
    border-radius: 5px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
.modal-scroll-content::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}
.dark .modal-scroll-content::-webkit-scrollbar-thumb {
    background: #4b5563;
}
.dark .modal-scroll-content::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}
</style>

{{-- Modal Documentație Windows --}}
<div id="windowsDocsModal" class="hidden fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4" onclick="if(event.target === this) closeWindowsDocs()">
    <div class="relative w-full max-w-4xl shadow-2xl rounded-2xl bg-white dark:bg-gray-800 animate-fade-in-scale overflow-hidden max-h-[90vh] flex flex-col">
        <!-- Header -->
        <div class="bg-gradient-to-r from-cyan-600 to-blue-600 px-5 py-3.5 flex-shrink-0">
            <div class="flex justify-between items-center">
                <div class="flex items-center text-white">
                    <div class="bg-white bg-opacity-20 p-2 rounded-lg mr-2.5 backdrop-blur-sm">
                        <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
                            <path d="M0 3.449L9.75 2.1v9.451H0m10.949-9.602L24 0v11.4H10.949M0 12.6h9.75v9.451L0 20.699M10.949 12.6H24V24l-12.9-1.801"/>
                        </svg>
                    </div>
                    <div>
                        <h3 class="text-lg font-bold">📖 Documentație CronJobs - Windows</h3>
                        <p class="text-xs text-cyan-100">Task Scheduler Setup</p>
                    </div>
                </div>
                <button onclick="closeWindowsDocs()" class="text-white hover:bg-white hover:bg-opacity-20 p-1.5 rounded-lg transition-all duration-200">
                    <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="M6 18L18 6M6 6l12 12"></path>
                    </svg>
                </button>
            </div>
        </div>

        <!-- Content -->
        <div class="p-5 overflow-y-auto flex-1 modal-scroll-content" style="max-height: calc(90vh - 130px);">
            <div class="space-y-6">
                {{-- Metoda 1: Task Scheduler --}}
                <div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-blue-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">1</span>
                        Task Scheduler (Recomandat)
                    </h4>
                    <p class="text-sm text-gray-600 dark:text-gray-400 mb-3">Deschide PowerShell ca Administrator și rulează:</p>
                    <div class="bg-gray-900 rounded-lg p-3 relative group">
                        <code class="text-green-400 text-sm break-all" id="winCmd1">schtasks /create /tn "Laravel Scheduler - PanelDNS" /tr "{{ base_path('run-scheduler.bat') }}" /sc minute /mo 1 /ru SYSTEM /f</code>
                        <button onclick="copyToClipboard(document.getElementById('winCmd1').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                            <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                        </button>
                    </div>
                </div>

                {{-- Metoda 2: Fișier BAT --}}
                <div class="bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-green-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">2</span>
                        Conținut run-scheduler.bat
                    </h4>
                    <div class="bg-gray-900 rounded-lg p-3 relative group">
                        <pre class="text-green-400 text-sm" id="winCmd2">@echo off
cd /d {{ base_path() }}
{{ config('php.path', 'C:\\xampp\\php\\php.exe') }} artisan schedule:run >> storage/logs/scheduler.log 2>&1</pre>
                        <button onclick="copyToClipboard(document.getElementById('winCmd2').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                            <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                        </button>
                    </div>
                </div>

                {{-- Verificare Task --}}
                <div class="bg-purple-50 dark:bg-purple-900/20 border border-purple-200 dark:border-purple-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-purple-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">3</span>
                        Verificare & Management
                    </h4>
                    <div class="space-y-2">
                        <div class="bg-gray-900 rounded-lg p-3 relative group">
                            <p class="text-xs text-gray-400 mb-1"># Listează task-urile</p>
                            <code class="text-green-400 text-sm" id="winCmd3">schtasks /query /tn "Laravel Scheduler - PanelDNS"</code>
                            <button onclick="copyToClipboard(document.getElementById('winCmd3').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                                <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                            </button>
                        </div>
                        <div class="bg-gray-900 rounded-lg p-3 relative group">
                            <p class="text-xs text-gray-400 mb-1"># Șterge task-ul</p>
                            <code class="text-green-400 text-sm" id="winCmd4">schtasks /delete /tn "Laravel Scheduler - PanelDNS" /f</code>
                            <button onclick="copyToClipboard(document.getElementById('winCmd4').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                                <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                            </button>
                        </div>
                        <div class="bg-gray-900 rounded-lg p-3 relative group">
                            <p class="text-xs text-gray-400 mb-1"># Rulează manual</p>
                            <code class="text-green-400 text-sm" id="winCmd5">schtasks /run /tn "Laravel Scheduler - PanelDNS"</code>
                            <button onclick="copyToClipboard(document.getElementById('winCmd5').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                                <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                            </button>
                        </div>
                    </div>
                </div>

                {{-- Queue Worker --}}
                <div class="bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-orange-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">4</span>
                        Queue Worker (Opțional)
                    </h4>
                    <div class="bg-gray-900 rounded-lg p-3 relative group">
                        <code class="text-green-400 text-sm" id="winCmd6">php artisan queue:work --sleep=3 --tries=3</code>
                        <button onclick="copyToClipboard(document.getElementById('winCmd6').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                            <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                        </button>
                    </div>
                    <p class="text-xs text-gray-500 dark:text-gray-400 mt-2">Pentru producție, folosește Supervisor sau NSSM pentru a rula queue worker ca serviciu.</p>
                </div>
            </div>
        </div>

        <!-- Footer -->
        <div class="bg-gray-50 dark:bg-gray-900 px-5 py-3 border-t border-gray-200 dark:border-gray-700 flex-shrink-0">
            <div class="flex justify-end">
                <button onclick="closeWindowsDocs()" class="px-5 py-2 bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-200 font-semibold rounded-lg transition">
                    Închide
                </button>
            </div>
        </div>
    </div>
</div>

{{-- Modal Documentație Linux/cPanel --}}
<div id="linuxDocsModal" class="hidden fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4" onclick="if(event.target === this) closeLinuxDocs()">
    <div class="relative w-full max-w-4xl shadow-2xl rounded-2xl bg-white dark:bg-gray-800 animate-fade-in-scale overflow-hidden max-h-[90vh] flex flex-col">
        <!-- Header -->
        <div class="bg-gradient-to-r from-orange-600 to-red-600 px-5 py-3.5 flex-shrink-0">
            <div class="flex justify-between items-center">
                <div class="flex items-center text-white">
                    <div class="bg-white bg-opacity-20 p-2 rounded-lg mr-2.5 backdrop-blur-sm">
                        <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
                            <path d="M12.504 0c-.155 0-.315.008-.48.021-4.226.333-3.105 4.807-3.17 6.298-.076 1.092-.3 1.953-1.05 3.02-.885 1.051-2.127 2.75-2.716 4.521-.278.832-.41 1.684-.287 2.489a.424.424 0 00-.11.135c-.26.268-.45.6-.663.839-.199.199-.485.267-.797.4-.313.136-.658.269-.864.68-.09.189-.136.394-.132.602 0 .199.027.4.055.536.058.399.116.728.04.97-.249.68-.28 1.145-.106 1.484.174.334.535.47.94.601.81.2 1.91.135 2.774.6.926.466 1.866.67 2.616.47.526-.116.97-.464 1.208-.946.587-.003 1.23-.269 2.26-.334.699-.058 1.574.267 2.577.2.025.134.063.198.114.333l.003.003c.391.778 1.113 1.132 1.884 1.071.771-.06 1.592-.536 2.257-1.306.631-.765 1.683-1.084 2.378-1.503.348-.199.629-.469.649-.853.023-.4-.2-.811-.714-1.376v-.097l-.003-.003c-.17-.2-.25-.535-.338-.926-.085-.401-.182-.786-.492-1.046h-.003c-.059-.054-.123-.067-.188-.135a.357.357 0 00-.19-.064c.431-1.278.264-2.55-.173-3.694-.533-1.41-1.465-2.638-2.175-3.483-.796-1.005-1.576-1.957-1.56-3.368.026-2.152.236-6.133-3.544-6.139z"/>
                        </svg>
                    </div>
                    <div>
                        <h3 class="text-lg font-bold">📖 Documentație CronJobs - Linux/cPanel</h3>
                        <p class="text-xs text-orange-100">Crontab & cPanel Setup</p>
                    </div>
                </div>
                <button onclick="closeLinuxDocs()" class="text-white hover:bg-white hover:bg-opacity-20 p-1.5 rounded-lg transition-all duration-200">
                    <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="M6 18L18 6M6 6l12 12"></path>
                    </svg>
                </button>
            </div>
        </div>

        <!-- Content -->
        <div class="p-5 overflow-y-auto flex-1 modal-scroll-content" style="max-height: calc(90vh - 130px);">
            <div class="space-y-6">
                {{-- Metoda 1: Crontab Direct --}}
                <div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-blue-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">1</span>
                        Crontab Direct (SSH)
                    </h4>
                    <p class="text-sm text-gray-600 dark:text-gray-400 mb-3">Conectează-te prin SSH și rulează <code class="bg-gray-200 dark:bg-gray-700 px-1 rounded">crontab -e</code>, apoi adaugă:</p>
                    <div class="bg-gray-900 rounded-lg p-3 relative group">
                        <code class="text-green-400 text-sm" id="linuxCmd1">* * * * * cd /home/user/public_html/paneldns && php artisan schedule:run >> /dev/null 2>&1</code>
                        <button onclick="copyToClipboard(document.getElementById('linuxCmd1').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                            <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                        </button>
                    </div>
                    <p class="text-xs text-gray-500 dark:text-gray-400 mt-2">⚠️ Înlocuiește <code>/home/user/public_html/paneldns</code> cu calea reală a aplicației.</p>
                </div>

                {{-- Metoda 2: cPanel Cron Jobs --}}
                <div class="bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-green-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">2</span>
                        cPanel Cron Jobs
                    </h4>
                    <ol class="text-sm text-gray-600 dark:text-gray-400 space-y-2 mb-3">
                        <li class="flex items-start"><span class="bg-green-600 text-white text-xs w-5 h-5 rounded-full flex items-center justify-center mr-2 mt-0.5">1</span> Accesează cPanel → Cron Jobs</li>
                        <li class="flex items-start"><span class="bg-green-600 text-white text-xs w-5 h-5 rounded-full flex items-center justify-center mr-2 mt-0.5">2</span> Setează "Common Settings" la "Once Per Minute (* * * * *)"</li>
                        <li class="flex items-start"><span class="bg-green-600 text-white text-xs w-5 h-5 rounded-full flex items-center justify-center mr-2 mt-0.5">3</span> În câmpul "Command", adaugă:</li>
                    </ol>
                    <div class="bg-gray-900 rounded-lg p-3 relative group">
                        <code class="text-green-400 text-sm" id="linuxCmd2">/usr/local/bin/php /home/user/public_html/paneldns/artisan schedule:run >> /dev/null 2>&1</code>
                        <button onclick="copyToClipboard(document.getElementById('linuxCmd2').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                            <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                        </button>
                    </div>
                </div>

                {{-- Găsire cale PHP --}}
                <div class="bg-purple-50 dark:bg-purple-900/20 border border-purple-200 dark:border-purple-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-purple-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">3</span>
                        Găsire Cale PHP
                    </h4>
                    <div class="space-y-2">
                        <div class="bg-gray-900 rounded-lg p-3 relative group">
                            <p class="text-xs text-gray-400 mb-1"># Verifică versiunea PHP disponibilă</p>
                            <code class="text-green-400 text-sm" id="linuxCmd3">which php</code>
                            <button onclick="copyToClipboard(document.getElementById('linuxCmd3').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                                <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                            </button>
                        </div>
                        <div class="bg-gray-900 rounded-lg p-3 relative group">
                            <p class="text-xs text-gray-400 mb-1"># Sau pentru PHP 8.1+</p>
                            <code class="text-green-400 text-sm" id="linuxCmd4">/usr/local/bin/ea-php81</code>
                            <button onclick="copyToClipboard(document.getElementById('linuxCmd4').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                                <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                            </button>
                        </div>
                    </div>
                </div>

                {{-- Queue Worker cu Supervisor --}}
                <div class="bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-orange-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">4</span>
                        Queue Worker cu Supervisor
                    </h4>
                    <p class="text-sm text-gray-600 dark:text-gray-400 mb-3">Creează fișierul <code class="bg-gray-200 dark:bg-gray-700 px-1 rounded">/etc/supervisor/conf.d/paneldns-worker.conf</code>:</p>
                    <div class="bg-gray-900 rounded-lg p-3 relative group">
                        <pre class="text-green-400 text-sm" id="linuxCmd5">[program:paneldns-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/user/public_html/paneldns/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/home/user/public_html/paneldns/storage/logs/worker.log</pre>
                        <button onclick="copyToClipboard(document.getElementById('linuxCmd5').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                            <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                        </button>
                    </div>
                    <div class="bg-gray-900 rounded-lg p-3 mt-2 relative group">
                        <p class="text-xs text-gray-400 mb-1"># Restart Supervisor</p>
                        <code class="text-green-400 text-sm" id="linuxCmd6">sudo supervisorctl reread && sudo supervisorctl update && sudo supervisorctl start paneldns-worker:*</code>
                        <button onclick="copyToClipboard(document.getElementById('linuxCmd6').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                            <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                        </button>
                    </div>
                </div>

                {{-- Verificare Logs --}}
                <div class="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-900 dark:text-white mb-3 flex items-center">
                        <span class="bg-red-600 text-white text-xs font-bold px-2 py-1 rounded mr-2">5</span>
                        Verificare & Debugging
                    </h4>
                    <div class="space-y-2">
                        <div class="bg-gray-900 rounded-lg p-3 relative group">
                            <p class="text-xs text-gray-400 mb-1"># Vezi log-urile cron</p>
                            <code class="text-green-400 text-sm" id="linuxCmd7">tail -f /var/log/syslog | grep CRON</code>
                            <button onclick="copyToClipboard(document.getElementById('linuxCmd7').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                                <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                            </button>
                        </div>
                        <div class="bg-gray-900 rounded-lg p-3 relative group">
                            <p class="text-xs text-gray-400 mb-1"># Test manual scheduler</p>
                            <code class="text-green-400 text-sm" id="linuxCmd8">cd /home/user/public_html/paneldns && php artisan schedule:run</code>
                            <button onclick="copyToClipboard(document.getElementById('linuxCmd8').textContent, this)" class="absolute top-2 right-2 p-1.5 bg-gray-600 hover:bg-gray-500 text-white rounded opacity-0 group-hover:opacity-100 transition">
                                <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="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Footer -->
        <div class="bg-gray-50 dark:bg-gray-900 px-5 py-3 border-t border-gray-200 dark:border-gray-700 flex-shrink-0">
            <div class="flex justify-end">
                <button onclick="closeLinuxDocs()" class="px-5 py-2 bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-800 dark:text-gray-200 font-semibold rounded-lg transition">
                    Închide
                </button>
            </div>
        </div>
    </div>
</div>

</div>

@push('scripts')
<script>
function runScheduler() {
    if (!confirm('Sigur vrei să rulezi scheduler-ul manual?')) return;

    fetch('{{ route('admin.cronjobs.run') }}', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
        }
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            alert('? ' + data.message);
            location.reload();
        } else {
            alert('? ' + data.message);
        }
    })
    .catch(error => {
        alert('? Eroare: ' + error.message);
    });
}

function restartQueue() {
    if (!confirm('Sigur vrei să restartezi queue workers?')) return;

    fetch('{{ route('admin.cronjobs.restart-queue') }}', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
        }
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            alert('? ' + data.message);
        } else {
            alert('? ' + data.message);
        }
    })
    .catch(error => {
        alert('? Eroare: ' + error.message);
    });
}

function showLogs() {
    fetch('{{ route('admin.cronjobs.logs') }}')
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                document.getElementById('logsContent').textContent = data.data;
                document.getElementById('logsModal').classList.remove('hidden');
            } else {
                alert('? ' + data.message);
            }
        })
        .catch(error => {
            alert('? Eroare: ' + error.message);
        });
}

function closeLogs() {
    document.getElementById('logsModal').classList.add('hidden');
}

function refreshLogs() {
    showLogs(); // Re�ncarca log-urile
}

function copyLogs() {
    const logsContent = document.getElementById('logsContent').textContent;
    navigator.clipboard.writeText(logsContent).then(() => {
        alert('? Log-uri copiate �n clipboard!');
    }).catch(err => {
        alert('? Eroare la copiere: ' + err);
    });
}

function refreshStatus() {
    fetch('{{ route('admin.cronjobs.queue-status') }}')
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                document.getElementById('pendingJobs').textContent = data.data.pending;
                document.getElementById('failedJobs').textContent = data.data.failed;
                document.getElementById('queueStatus').textContent = data.data.status.charAt(0).toUpperCase() + data.data.status.slice(1);
                document.getElementById('lastRun').textContent = new Date().toLocaleTimeString('ro-RO');
            }
        })
        .catch(error => {
            console.error('Error refreshing status:', error);
        });
}

function showFailedJobs() {
    fetch('{{ route('admin.cronjobs.failed-jobs') }}')
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                if (data.data.length === 0) {
                    alert('? Nu exista joburi e?uate!');
                } else {
                    let message = 'Failed Jobs:\n\n';
                    data.data.forEach(job => {
                        message += `ID: ${job.id}\nQueue: ${job.queue}\nFailed at: ${job.failed_at}\n\n`;
                    });
                    alert(message);
                }
            } else {
                alert('? ' + data.message);
            }
        })
        .catch(error => {
            alert('? Eroare: ' + error.message);
        });
}

function retryAllFailed() {
    if (!confirm('Sigur vrei să reîncerci toate joburile eșuate?')) return;

    fetch('{{ route('admin.cronjobs.retry-failed') }}', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
        }
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            alert('? ' + data.message);
            refreshStatus();
        } else {
            alert('? ' + data.message);
        }
    })
    .catch(error => {
        alert('? Eroare: ' + error.message);
    });
}

function copyCommand() {
    const command = document.getElementById('setupCommand').textContent;
    navigator.clipboard.writeText(command).then(() => {
        alert('✓ Comandă copiată în clipboard!');
    }).catch(err => {
        alert('✗ Eroare la copiere: ' + err);
    });
}

function showWindowsDocs() {
    document.getElementById('windowsDocsModal').classList.remove('hidden');
}

function closeWindowsDocs() {
    document.getElementById('windowsDocsModal').classList.add('hidden');
}

function showLinuxDocs() {
    document.getElementById('linuxDocsModal').classList.remove('hidden');
}

function closeLinuxDocs() {
    document.getElementById('linuxDocsModal').classList.add('hidden');
}

function copyToClipboard(text, btn) {
    navigator.clipboard.writeText(text).then(() => {
        const originalText = btn.innerHTML;
        btn.innerHTML = '<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="M5 13l4 4L19 7"></path></svg>';
        btn.classList.remove('bg-gray-600');
        btn.classList.add('bg-green-600');
        setTimeout(() => {
            btn.innerHTML = originalText;
            btn.classList.remove('bg-green-600');
            btn.classList.add('bg-gray-600');
        }, 2000);
    });
}

// Auto-refresh status every 30 seconds
setInterval(refreshStatus, 30000);
</script>
@endpush
</x-admin-layout>
