<div>
    
    <div class="w-full flex flex-col gap-2 mb-8">
        <h1 class="text-3xl font-bold text-gray-900 tracking-tight">API Logs</h1>
        <p class="mt-1 text-gray-500">Monitorización y diagnóstico de peticiones a la API (POST /api/v1/).</p>
    </div>

    <div class="space-y-6">
        
        <div class="bg-white rounded-2xl border border-gray-200 shadow-sm overflow-hidden" x-data="{ filtersOpen: false }">
            <div class="px-5 py-4 border-b border-gray-100 bg-gray-50/50 cursor-pointer hover:bg-gray-50/70 transition-colors"
                 role="button"
                 tabindex="0"
                 @click="filtersOpen = ! filtersOpen"
                 @keydown.enter.prevent="filtersOpen = ! filtersOpen"
                 @keydown.space.prevent="filtersOpen = ! filtersOpen"
                 x-bind:aria-expanded="filtersOpen">
                <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-3">
                    <h2 class="text-sm font-semibold text-gray-800 flex items-center gap-2">
                        <span class="w-8 h-8 rounded-lg bg-gray-200 flex items-center justify-center">
                            <svg class="w-4 h-4 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"/></svg>
                        </span>
                        Filtros
                        <?php $counts = $this->appliedFiltersCounts; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($counts['total'] > 0): ?>
                            <span class="inline-flex items-center justify-center min-w-[1.25rem] h-5 px-1.5 rounded-full text-xs font-semibold bg-orange-100 text-orange-800"><?php echo e($counts['total']); ?></span>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <svg class="w-4 h-4 text-gray-500 transition-transform ml-1" :class="filtersOpen ? 'rotate-90' : '-rotate-90'" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/></svg>
                    </h2>
                    <div class="flex flex-wrap items-center gap-3" @click.stop>
                        <div class="flex flex-wrap items-center gap-2">
                            <select wire:model.live="rangePreset" class="rounded-xl border-2 border-gray-200 px-4 py-2.5 text-sm font-medium text-gray-700 focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400 transition-shadow">
                                <option value="24h">Últimas 24 h</option>
                                <option value="7d">Últimos 7 días</option>
                                <option value="30d">Últimos 30 días</option>
                                <option value="custom">Personalizado</option>
                            </select>
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($rangePreset === 'custom'): ?>
                                <input type="datetime-local" wire:model.live="dateFrom" class="rounded-xl border-2 border-gray-200 px-3 py-2.5 text-xs md:text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                                <span class="text-gray-500 text-xs md:text-sm">hasta</span>
                                <input type="datetime-local" wire:model.live="dateTo" class="rounded-xl border-2 border-gray-200 px-3 py-2.5 text-xs md:text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </div>
                        <div class="flex flex-wrap items-center gap-2">
                            <button type="button" wire:click="resetFilters"
                                class="inline-flex items-center gap-2 rounded-lg border-2 border-gray-200 px-4 py-2.5 text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 hover:border-gray-300 transition-colors">
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="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"/></svg>
                                Reset filtros
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div x-show="filtersOpen" x-collapse class="p-5 space-y-6">
                
                <div class="rounded-xl border border-gray-200 bg-gray-50/30 p-4">
                    <h3 class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 flex items-center gap-2">
                        <svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
                        Cliente y entorno
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($counts['cliente_entorno'] > 0): ?>
                            <span class="inline-flex items-center justify-center min-w-[1.25rem] h-5 px-1.5 rounded-full text-xs font-semibold bg-orange-100 text-orange-800"><?php echo e($counts['cliente_entorno']); ?></span>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
                        <div>
                            <label class="block text-xs font-medium text-gray-500 mb-1.5">Cliente</label>
                            <select wire:model.live="clientId" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                                <option value="">— Todos —</option>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = \App\Models\Clients\Client::orderBy('name')->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($c->id); ?>"><?php echo e($c->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </select>
                        </div>
                        <div>
                            <label class="block text-xs font-medium text-gray-500 mb-1.5">Sitio (entorno)</label>
                            <select wire:model.live="environmentId" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                                <option value="">— Todos —</option>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = \App\Models\Environments\Environment::orderBy('name')->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $e): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($e->id); ?>"><?php echo e($e->name); ?> (<?php echo e($e->domain); ?>)</option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </select>
                        </div>
                        <div>
                            <label class="block text-xs font-medium text-gray-500 mb-1.5">Token licencia (ID)</label>
                            <input type="number" wire:model.live.debounce.300ms="licenseTokenId" placeholder="ID"
                                class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                        </div>
                        <div class="flex items-end">
                            <label class="flex items-center gap-2.5 cursor-pointer rounded-xl border-2 border-gray-200 px-4 py-2.5 w-full hover:bg-gray-50 transition-colors">
                                <input type="checkbox" wire:model.live="onlyWithoutEnvironment" class="rounded border-gray-300 text-orange-600 focus:ring-orange-300">
                                <span class="text-sm font-medium text-gray-700">Solo peticiones sin sitio reconocido</span>
                            </label>
                        </div>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($host): ?>
                            <div class="md:col-span-2 lg:col-span-4 flex items-center gap-2">
                                <span class="text-xs font-medium text-gray-500">Filtro por host (no reconocido):</span>
                                <span class="inline-flex items-center gap-1.5 rounded-lg bg-amber-50 border border-amber-200 px-3 py-1.5 text-sm font-medium text-amber-800">
                                    <?php echo e(Str::limit($host, 40)); ?>

                                    <button type="button" wire:click="clearHostFilter" class="rounded p-0.5 hover:bg-amber-200 transition-colors" aria-label="Quitar filtro host">
                                        <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="M6 18L18 6M6 6l12 12"/></svg>
                                    </button>
                                </span>
                            </div>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </div>
                </div>

                
                <div class="rounded-xl border border-gray-200 bg-gray-50/30 p-4">
                    <h3 class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 flex items-center gap-2">
                        <svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
                        Petición y respuesta
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($counts['peticion_respuesta'] > 0): ?>
                            <span class="inline-flex items-center justify-center min-w-[1.25rem] h-5 px-1.5 rounded-full text-xs font-semibold bg-orange-100 text-orange-800"><?php echo e($counts['peticion_respuesta']); ?></span>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
                        <div>
                            <label class="block text-xs font-medium text-gray-500 mb-1.5">Action</label>
                            <select wire:model.live="action" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                                <option value="">— Todas —</option>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $actionOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $val => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($val); ?>"><?php echo e($label); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </select>
                        </div>
                        <div class="md:col-span-2 lg:col-span-3">
                            <label class="block text-xs font-medium text-gray-500 mb-2">Estados HTTP</label>
                            <div class="flex flex-wrap gap-2">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = [200,400,401,403,404,422,429,500]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <label class="inline-flex items-center gap-1.5 rounded-full border border-gray-200 px-3 py-1.5 text-xs font-medium text-gray-700 bg-white hover:bg-gray-50 cursor-pointer">
                                        <input type="checkbox" value="<?php echo e($status); ?>" wire:model.live="httpStatuses" class="rounded border-gray-300 text-orange-600 focus:ring-orange-300">
                                        <span><?php echo e($status); ?></span>
                                    </label>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </div>
                        </div>
                        <div>
                            <label class="block text-xs font-medium text-gray-500 mb-1.5">Duración (ms) min / max</label>
                            <div class="flex gap-2">
                                <input type="number" wire:model.live.debounce.300ms="durationMin" placeholder="min" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                                <input type="number" wire:model.live.debounce.300ms="durationMax" placeholder="max" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                            </div>
                        </div>
                        <div>
                            <label class="block text-xs font-medium text-gray-500 mb-1.5">Tamaño respuesta (bytes)</label>
                            <div class="flex gap-2">
                                <input type="number" wire:model.live.debounce.300ms="responseSizeMin" placeholder="min" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                                <input type="number" wire:model.live.debounce.300ms="responseSizeMax" placeholder="max" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                            </div>
                        </div>
                    </div>
                </div>

                
                <div class="rounded-xl border border-gray-200 bg-gray-50/30 p-4">
                    <h3 class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 flex items-center gap-2">
                        <svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4"/></svg>
                        Filtros avanzados
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($counts['avanzados'] > 0): ?>
                            <span class="inline-flex items-center justify-center min-w-[1.25rem] h-5 px-1.5 rounded-full text-xs font-semibold bg-orange-100 text-orange-800"><?php echo e($counts['avanzados']); ?></span>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
                        <div>
                            <label class="block text-xs font-medium text-gray-500 mb-1.5">IP</label>
                            <input type="text" wire:model.live.debounce.300ms="ip" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                        </div>
                        <div>
                            <label class="block text-xs font-medium text-gray-500 mb-1.5">Request UUID</label>
                            <input type="text" wire:model.live.debounce.300ms="requestUuid" placeholder="UUID" class="w-full rounded-xl border-2 border-gray-200 px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-orange-300 focus:border-orange-400">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        
        <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-6 gap-4">
            <div class="bg-white rounded-2xl border border-gray-200 shadow-sm p-5 flex flex-col">
                <span class="text-xs font-medium text-gray-500 uppercase tracking-wide">Requests</span>
                <span class="mt-2 text-2xl font-bold text-gray-900"><?php echo e(number_format($total)); ?></span>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($prevTotal !== null): ?>
                    <span class="mt-1 text-xs <?php echo e($total >= $prevTotal ? 'text-gray-500' : 'text-emerald-600'); ?>">Anterior: <?php echo e(number_format($prevTotal)); ?></span>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
            <div class="bg-white rounded-2xl border border-gray-200 shadow-sm p-5 flex flex-col">
                <span class="text-xs font-medium text-gray-500 uppercase tracking-wide">% errores</span>
                <span class="mt-2 text-2xl font-bold <?php echo e($errorPct > 10 ? 'text-red-600' : ($errorPct > 0 ? 'text-amber-600' : 'text-gray-900')); ?>"><?php echo e($errorPct); ?>%</span>
                <span class="mt-1 text-xs text-gray-500">4xx: <?php echo e($count4xx); ?> · 5xx: <?php echo e($count5xx); ?></span>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($prevErrorPct !== null): ?>
                    <span class="mt-0.5 text-xs <?php echo e($errorPct <= $prevErrorPct ? 'text-emerald-600' : 'text-red-600'); ?>">Anterior: <?php echo e($prevErrorPct); ?>%</span>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
            <div class="bg-white rounded-2xl border border-gray-200 shadow-sm p-5 flex flex-col">
                <span class="text-xs font-medium text-gray-500 uppercase tracking-wide">P50 (ms)</span>
                <span class="mt-2 text-2xl font-bold text-gray-900"><?php echo e($p50 !== null ? number_format($p50) : '—'); ?></span>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($prevP50 !== null): ?>
                    <span class="mt-1 text-xs text-gray-500">Anterior: <?php echo e(number_format($prevP50)); ?></span>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
            <div class="bg-white rounded-2xl border border-gray-200 shadow-sm p-5 flex flex-col">
                <span class="text-xs font-medium text-gray-500 uppercase tracking-wide">P95 (ms)</span>
                <span class="mt-2 text-2xl font-bold text-gray-900"><?php echo e($p95 !== null ? number_format($p95) : '—'); ?></span>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($prevP95 !== null): ?>
                    <span class="mt-1 text-xs text-gray-500">Anterior: <?php echo e(number_format($prevP95)); ?></span>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
            <div class="bg-white rounded-2xl border border-gray-200 shadow-sm p-5 flex flex-col">
                <span class="text-xs font-medium text-gray-500 uppercase tracking-wide">Top actions</span>
                <ul class="mt-2 space-y-1 text-sm font-medium text-gray-800">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $topActions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <li class="flex justify-between"><span><?php echo e($row->action); ?></span><span class="text-gray-500"><?php echo e($row->c); ?></span></li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <li class="text-gray-400">—</li>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </ul>
            </div>
            <div class="bg-white rounded-2xl border border-gray-200 shadow-sm p-5 flex flex-col">
                <span class="text-xs font-medium text-gray-500 uppercase tracking-wide">Top clientes</span>
                <ul class="mt-2 space-y-1 text-sm font-medium text-gray-800">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $topClients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <li class="flex justify-between truncate"><span class="truncate mr-2"><?php echo e($row->client->name ?? 'ID '.$row->client_id); ?></span><span class="text-gray-500 shrink-0"><?php echo e($row->c); ?></span></li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <li class="text-gray-400">—</li>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </ul>
            </div>
        </div>

        
        <div class="bg-white rounded-2xl border border-gray-200 shadow-sm overflow-hidden">
            <div class="px-5 py-4 border-b border-gray-100 bg-gray-50/50">
                <h2 class="text-sm font-semibold text-gray-800">Sitios con mayor tasa de error</h2>
            </div>
            <ul class="divide-y divide-gray-100">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $sitesErrorRate; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <li class="px-5 py-3 flex items-center justify-between hover:bg-gray-50/50 transition-colors">
                        <span class="text-sm font-medium text-gray-800"><?php echo e($row->environment->name ?? $row->host ?? 'ID '.$row->environment_id); ?></span>
                        <span class="flex items-center gap-2">
                            <span class="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold <?php echo e($row->error_pct >= 50 ? 'bg-red-100 text-red-800' : ($row->error_pct >= 10 ? 'bg-amber-100 text-amber-800' : 'bg-gray-100 text-gray-700')); ?>"><?php echo e($row->error_pct); ?>%</span>
                            <span class="text-xs text-gray-500"><?php echo e($row->errors); ?>/<?php echo e($row->total); ?></span>
                        </span>
                    </li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <li class="px-5 py-6 text-center text-sm text-gray-500">Ningún sitio con errores en el rango</li>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </ul>
        </div>

        
        <div class="bg-white rounded-2xl border border-gray-200 shadow-sm overflow-hidden">
            <div class="px-5 py-4 border-b border-gray-100 bg-gray-50/50">
                <h2 class="text-sm font-semibold text-gray-800">Registros</h2>
            </div>
            <div class="overflow-x-auto">
                <table class="min-w-full">
                    <thead>
                        <tr class="bg-gray-50 border-b border-gray-200">
                            <th class="px-5 py-3.5 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Fecha</th>
                            <th class="px-5 py-3.5 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Cliente</th>
                            <th class="px-5 py-3.5 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Sitio</th>
                            <th class="px-5 py-3.5 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Action</th>
                            <th class="px-5 py-3.5 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">HTTP</th>
                            <th class="px-5 py-3.5 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Duración</th>
                            <th class="px-5 py-3.5 text-right text-xs font-semibold text-gray-600 uppercase tracking-wider">Acciones</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-100">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $logs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr class="hover:bg-orange-50/30 transition-colors">
                                <td class="px-5 py-3.5 text-sm text-gray-700 whitespace-nowrap"><?php echo e($log->started_at?->format('d/m/Y H:i:s')); ?></td>
                                <td class="px-5 py-3.5 text-sm text-gray-800"><?php echo e($log->client?->name ?? '—'); ?></td>
                                <td class="px-5 py-3.5 text-sm text-gray-800 max-w-[200px] truncate" title="<?php echo e($log->host); ?>"><?php echo e($log->site?->name ?? $log->host ?? '—'); ?></td>
                                <td class="px-5 py-3.5"><span class="inline-flex items-center rounded-lg bg-gray-100 px-2 py-1 text-xs font-medium text-gray-700"><?php echo e($log->action ?? '—'); ?></span></td>
                                <td class="px-5 py-3.5" <?php if($log->error_code || $log->error): ?> title="<?php echo e(($log->error_code ? $log->error_code . ' – ' : '') . ($log->error ?? '')); ?>" <?php endif; ?>>
                                    <span class="inline-flex items-center rounded-lg px-2.5 py-1 text-xs font-semibold <?php echo e($log->http_status >= 500 ? 'bg-red-100 text-red-800' : ($log->http_status >= 400 ? 'bg-amber-100 text-amber-800' : 'bg-emerald-100 text-emerald-800')); ?>"><?php echo e($log->http_status); ?></span>
                                </td>
                                <td class="px-5 py-3.5 text-sm text-gray-700"><?php echo e($log->duration_ms); ?> ms</td>
                                <td class="px-5 py-3.5 text-right">
                                    <div class="flex items-center justify-end gap-1.5">
                                        <button type="button" wire:click="openLogModal(<?php echo e($log->id); ?>)" class="inline-flex items-center rounded-lg px-2.5 py-1.5 text-xs font-medium text-orange-700 bg-orange-50 hover:bg-orange-100 transition-colors">Ver detalle</button>
                                        <button type="button" wire:click="copyUuid(<?php echo e(json_encode($log->request_uuid)); ?>)" class="inline-flex items-center rounded-lg px-2.5 py-1.5 text-xs font-medium text-gray-600 bg-gray-100 hover:bg-gray-200 transition-colors">Copiar UUID</button>
                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($log->environment_id || $log->host): ?>
                                            <button type="button" wire:click="filterBySiteOrHost(<?php echo e($log->environment_id ?? 'null'); ?>, <?php echo e(json_encode($log->host ?? '')); ?>)" class="inline-flex items-center rounded-lg px-2.5 py-1.5 text-xs font-medium text-gray-600 bg-gray-100 hover:bg-gray-200 transition-colors"><?php echo e($log->environment_id ? 'Mismo sitio' : 'Mismo host'); ?></button>
                                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="7" class="px-5 py-12 text-center text-gray-500">No hay registros en el rango seleccionado.</td>
                            </tr>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </tbody>
                </table>
            </div>
            <div class="px-5 py-3 border-t border-gray-100 bg-gray-50/30">
                <?php echo e($logs->links('livewire.components.table-pagination')); ?>

            </div>
        </div>
    </div>

        <?php
        $__scriptKey = '1369237307-0';
        ob_start();
    ?>
    <script>
        $wire.on('copy-to-clipboard', (e) => {
            if (navigator.clipboard && navigator.clipboard.writeText) {
                navigator.clipboard.writeText(e.text);
            }
        });
    </script>
        <?php
        $__output = ob_get_clean();

        \Livewire\store($this)->push('scripts', $__output, $__scriptKey)
    ?>
</div><?php /**PATH /var/www/html/resources/views/livewire/api-logs/index.blade.php ENDPATH**/ ?>