
<div class="w-full" style="font-size:14px; display:flex; flex-direction:column; gap:16px;">

    <div class="flex items-center justify-between gap-4">
        <a href="<?php echo e(route('license_tokens.index')); ?>" wire:navigate
           class="inline-flex items-center gap-1.5 text-[13px] font-semibold" style="color:var(--text-link);">
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m15 18-6-6 6-6"/></svg>
            Licencias
        </a>
    </div>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = ['success' => 'success', 'warning' => 'warning', 'error' => 'danger']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $clave => $color): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session($clave)): ?>
            <div class="rounded-lg px-4 py-2.5 text-[13px]"
                 style="background:var(--<?php echo e($color); ?>-50); color:var(--<?php echo e($color); ?>-500);">
                <?php echo e(session($clave)); ?>

            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    
    <section class="rounded-xl border px-6 py-5"
             style="background:var(--surface-card); border-color:var(--border-subtle);"
             x-data="{ copiado: false }">

        <div class="flex flex-wrap items-start justify-between gap-6">
            <div class="min-w-0 flex-1">
                <div class="flex flex-wrap items-center gap-2.5">
                    <h1 style="font-family:'Plus Jakarta Sans',sans-serif; font-size:22px; font-weight:700; letter-spacing:-0.02em; color:var(--text-strong); margin:0;">
                        <?php echo e($licenseToken->name ?: 'Licencia sin nombre'); ?>

                    </h1>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($situacion['apagada']): ?>
                        <span class="rounded-full px-2.5 py-0.5 text-[11.5px] font-semibold"
                              style="color:#fff; background:var(--neutral-700);">Apagada</span>
                    <?php elseif($situacion['caducada']): ?>
                        <span class="rounded-full px-2.5 py-0.5 text-[11.5px] font-semibold"
                              style="color:var(--danger-500); background:var(--danger-50);">Caducada</span>
                    <?php else: ?>
                        <span class="rounded-full px-2.5 py-0.5 text-[11.5px] font-semibold"
                              style="color:var(--success-500); background:var(--success-50);">Activa</span>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>

                
                <div class="mt-1 text-[13px]" style="color:var(--text-muted);">
                    <?php if($situacion['apagada']): ?>
                        Sin servicio: apagada a mano
                        <?php if($licenseToken->deactivated_at): ?>
                            el <?php echo e($licenseToken->deactivated_at->format('d/m/Y')); ?>

                        <?php endif; ?>
                        <?php if($licenseToken->deactivatedBy): ?>
                            por <?php echo e($licenseToken->deactivatedBy->name); ?>

                        <?php endif; ?>
                        <?php if($licenseToken->deactivation_reason): ?>
                            — «<?php echo e($licenseToken->deactivation_reason); ?>»
                        <?php endif; ?>
                    <?php elseif($situacion['caducada']): ?>
                        Sin servicio: caducó el <?php echo e($licenseToken->end_at->format('d/m/Y')); ?> — se renueva para reactivarla
                    <?php else: ?>
                        Dando servicio a
                        <?php echo e(count($entornos) > 0 ? count($entornos) : 'ningún'); ?>

                        entorno<?php echo e(count($entornos) === 1 ? '' : 's'); ?>

                        <?php echo e($licenseToken->end_at ? 'hasta el ' . $licenseToken->end_at->format('d/m/Y') : '· sin caducidad'); ?>

                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($licenseToken->client): ?>
                        · Cliente:
                        <a href="<?php echo e(route('clients.show', $licenseToken->client)); ?>" wire:navigate
                           class="font-semibold" style="color:var(--text-link);"><?php echo e($licenseToken->client->name); ?></a>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>

                
                
                <div class="mt-3.5 flex flex-wrap items-center gap-2" x-data="{ visible: false }">
                    <code class="rounded-lg border px-3.5 py-2 font-mono text-[14px]"
                          style="color:var(--text-strong); background:var(--surface-sunken); border-color:var(--border-subtle); letter-spacing:0.02em; word-break:break-all;">
                        <span x-show="! visible"><?php echo e($licenseToken->token_corto); ?></span>
                        <span x-show="visible" x-cloak><?php echo e($licenseToken->token); ?></span>
                    </code>

                    <button type="button" x-on:click="visible = ! visible"
                            class="flex border-none bg-transparent p-1"
                            style="color:var(--text-subtle);"
                            x-bind:title="visible ? 'Ocultar el token' : 'Ver el token completo'">
                        <svg x-show="! visible" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
                        <svg x-show="visible" x-cloak width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.53 13.53 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
                    </button>
                    <button type="button"
                            @click="copiarAlPortapapeles('<?php echo e($licenseToken->token); ?>').then(ok => { if (ok) { copiado = true; setTimeout(() => copiado = false, 2000) } })"
                            class="flex items-center gap-1.5 rounded-lg border px-3 py-2 text-[12.5px] font-semibold"
                            style="border-color:var(--border-default); background:var(--surface-page); color:var(--text-body);">
                        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
                        Copiar
                    </button>
                    <span x-show="copiado" x-cloak class="text-[12px] font-semibold" style="color:var(--success-500);">
                        Copiado al portapapeles
                    </span>
                </div>
            </div>

            
            <div class="flex flex-none flex-col items-end gap-2">
                <div class="flex flex-wrap justify-end gap-2">
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.edit')): ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($situacion['apagada']): ?>
                            <button type="button" wire:click="abrirCambioDeEstado"
                                    class="rounded-lg border-none px-4 py-2.5 text-[13px] font-semibold text-white"
                                    style="background:var(--success-500);">
                                Volver a activar…
                            </button>
                        <?php else: ?>
                            
                            <button type="button" wire:click="pedirRenovacion(12)"
                                    class="rounded-lg border-none px-4 py-2.5 text-[13px] font-semibold text-white"
                                    style="background:var(--orange-500);"
                                    onmouseover="this.style.background='var(--orange-600)'"
                                    onmouseout="this.style.background='var(--orange-500)'">
                                Renovar 1 año
                            </button>
                            <button type="button" wire:click="pedirRenovacion(6)"
                                    class="rounded-lg border px-3.5 py-2.5 text-[13px] font-semibold"
                                    style="border-color:var(--border-default); background:var(--surface-page); color:var(--text-body);">
                                6 meses
                            </button>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                        <a href="<?php echo e(route('license_tokens.edit', $licenseToken)); ?>" wire:navigate
                           class="rounded-lg border px-3.5 py-2.5 text-[13px] font-semibold"
                           style="border-color:var(--border-default); background:var(--surface-page); color:var(--text-body);">
                            Editar
                        </a>

                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if (! ($situacion['apagada'])): ?>
                            
                            <button type="button" wire:click="abrirCambioDeEstado"
                                    class="rounded-lg border px-3.5 py-2.5 text-[13px] font-semibold"
                                    style="border-color:var(--danger-500); background:var(--surface-page); color:var(--danger-500);"
                                    title="<?php echo e(count($entornos)); ?> entorno(s) dejarían de recibir contenido">
                                Desactivar…
                            </button>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    <?php endif; ?>
                </div>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if (! ($situacion['apagada'])): ?>
                    <div class="max-w-[280px] text-right text-[11.5px]" style="color:var(--text-subtle);">
                        La renovación alinea solo los productos que acaban antes que la licencia.
                    </div>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
        </div>

        
        <div class="mt-4 grid grid-cols-2 gap-5 border-t pt-4 md:grid-cols-4"
             style="border-color:var(--divider);">

            <div>
                <div class="text-[11px] font-semibold uppercase tracking-[0.06em]" style="color:var(--text-muted);">Creada</div>
                <div class="mt-[3px] text-[13px]"><?php echo e($licenseToken->created_at?->format('d/m/Y') ?? '—'); ?></div>
                <div class="mt-0.5 text-[12px]" style="color:var(--text-muted);">
                    por <?php echo e($licenseToken->creator?->name ?? '—'); ?>

                </div>
            </div>

            <div>
                <div class="text-[11px] font-semibold uppercase tracking-[0.06em]" style="color:var(--text-muted);">Vigencia</div>
                <div class="mt-[3px] text-[13px]">
                    <?php echo e($licenseToken->start_at?->format('d/m/Y') ?? '—'); ?>

                    –
                    <?php echo e($licenseToken->end_at?->format('d/m/Y') ?? 'sin caducidad'); ?>

                </div>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($situacion['caducada']): ?>
                    <div class="mt-0.5 text-[12px] font-semibold" style="color:var(--danger-500);">
                        Caducada hace <?php echo e(abs($situacion['dias'])); ?> día(s)
                    </div>
                <?php elseif($situacion['pronto']): ?>
                    <div class="mt-0.5 text-[12px] font-semibold" style="color:var(--warning-500);">
                        Caduca en <?php echo e($situacion['dias']); ?> día(s)
                    </div>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>

            
            <div>
                <div class="text-[11px] font-semibold uppercase tracking-[0.06em]" style="color:var(--text-muted);">Modo</div>
                <div class="mt-[3px] text-[13px]">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($licenseToken->mode === 'full'): ?>
                        <strong class="font-semibold" style="color:var(--text-strong);">full</strong> — sin restricciones de servicio
                    <?php elseif($licenseToken->mode === 'trial'): ?>
                        <strong class="font-semibold" style="color:var(--info-500);">trial</strong> — evaluación
                    <?php else: ?>
                        <span class="font-semibold" style="color:var(--warning-500);">Sin definir</span>
                        — se comporta como full; conviene fijarlo
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
            </div>

            <div>
                <div class="text-[11px] font-semibold uppercase tracking-[0.06em]" style="color:var(--text-muted);">Entornos servidos</div>
                <div class="mt-[3px] text-[13px] font-semibold" style="color:var(--text-strong);">
                    <?php echo e(count($entornos) > 0 ? count($entornos) : 'Ninguno'); ?>

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

        
        <div class="mt-3.5 flex flex-wrap items-start gap-6 rounded-lg px-4 py-3.5"
             style="background:var(--surface-alt);">
            <div class="min-w-[320px] flex-1">
                <div class="flex flex-wrap items-center justify-between gap-3">
                    <div class="text-[11px] font-semibold uppercase tracking-[0.06em]" style="color:var(--text-muted);">
                        Límite de peticiones
                    </div>
                    
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.edit')): ?>
                        <button type="button" wire:click="abrirLimite"
                                class="flex flex-none items-center gap-1.5 text-[12.5px] font-semibold"
                                style="color:var(--text-link);">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>
                            <?php echo e($limite['porDefecto'] ? 'Poner un límite' : 'Cambiar el límite'); ?>

                        </button>
                    <?php endif; ?>
                </div>
                <div class="mt-1 text-[13px]">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($limite['porDefecto']): ?>
                        Sin límite propio. Se aplica el techo por defecto de
                        <strong class="font-semibold" style="color:var(--text-strong);"><?php echo e(number_format($limite['techoPorDefecto'], 0, ',', '.')); ?> peticiones por minuto</strong>,
                        que en la práctica es no tener límite.
                    <?php else: ?>
                        <strong class="font-semibold" style="color:var(--text-strong);"><?php echo e(number_format($limite['tope'], 0, ',', '.')); ?> peticiones por minuto</strong>,
                        propio de esta licencia — sobrescribe el techo por defecto.
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
                <div class="mt-1.5 text-[12px]" style="color:var(--text-muted);">
                    Este límite cuenta <strong>por licencia</strong>. La API tiene además otro que cuenta
                    <strong>por dirección IP</strong>, para frenar bucles y abuso —incluidos los de quien
                    llama con un token que no existe—: ese no se configura aquí, va en la configuración
                    del Manager. Si un cliente recibe un 429, el mensaje dice cuál de los dos ha cortado.
                </div>
            </div>

            <div class="flex flex-none gap-7">
                <div>
                    <div class="text-[11px] font-semibold uppercase tracking-[0.06em]" style="color:var(--text-muted);">Minuto en curso</div>
                    <div style="font-family:'Plus Jakarta Sans',sans-serif; font-size:20px; font-weight:700; color:var(--text-strong); margin-top:2px;">
                        <?php echo e(number_format($limite['consumidas'], 0, ',', '.')); ?>

                    </div>
                    <div class="text-[11.5px]" style="color:var(--text-subtle);">vuelve a cero cada minuto</div>
                </div>
                <div>
                    <div class="text-[11px] font-semibold uppercase tracking-[0.06em]" style="color:var(--text-muted);">Cortes (7 días)</div>
                    <div style="font-family:'Plus Jakarta Sans',sans-serif; font-size:20px; font-weight:700; margin-top:2px; color:<?php echo e($limite['cortes'] > 0 ? 'var(--danger-500)' : 'var(--text-strong)'); ?>;">
                        <?php echo e(number_format($limite['cortes'], 0, ',', '.')); ?>

                    </div>
                    <div class="text-[11.5px]" style="color:var(--text-subtle);">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($limite['cortes'] > 0): ?>
                            última vez <?php echo e(\Carbon\Carbon::parse($limite['ultimoCorte'])->diffForHumans()); ?>

                        <?php else: ?>
                            nunca ha cortado
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($licenseToken->observation): ?>
            <div class="mt-3 rounded-lg px-3.5 py-2.5 text-[12.5px]"
                 style="background:var(--surface-alt); color:var(--text-muted);">
                <strong class="font-semibold" style="color:var(--text-body);">Observaciones:</strong>
                <?php echo e($licenseToken->observation); ?>

            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </section>

    
    <section class="overflow-hidden rounded-xl border"
             style="background:var(--surface-card); border-color:var(--border-subtle);"
             x-data="{ anadiendo: false }">

        <div class="flex items-baseline justify-between gap-4 px-5 pb-2.5 pt-3.5">
            <div class="flex items-baseline gap-2.5">
                <h2 style="font-family:'Plus Jakarta Sans',sans-serif; font-size:15px; font-weight:700; color:var(--text-strong); margin:0;">
                    Productos incluidos
                </h2>
                <span class="text-[12px]" style="color:var(--text-muted);"><?php echo e(count($vigencias)); ?></span>
            </div>
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.edit')): ?>
                <button type="button" @click="anadiendo = !anadiendo"
                        class="border-none bg-transparent p-0 text-[12.5px] font-semibold"
                        style="color:var(--text-link);">
                    <span x-show="!anadiendo">Añadir producto</span>
                    <span x-show="anadiendo" x-cloak>Cerrar</span>
                </button>
            <?php endif; ?>
        </div>

        
        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.edit')): ?>
            <div x-show="anadiendo" x-cloak class="mx-5 mb-3 rounded-lg border p-3"
                 style="border-color:var(--border-default); background:var(--surface-alt);">
                <?php
                    $yaIncluidos = $licenseToken->products->pluck('id')->all();
                    $disponibles = $allProducts->whereNotIn('id', $yaIncluidos);
                ?>

                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($disponibles->isEmpty()): ?>
                    <div class="text-[12.5px]" style="color:var(--text-muted);">
                        Esta licencia ya incluye todos los productos del catálogo.
                    </div>
                <?php else: ?>
                    <div class="flex flex-wrap gap-2">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $disponibles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $producto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <button type="button" wire:click="anadirProducto(<?php echo e($producto->id); ?>)"
                                    class="flex items-center gap-2 rounded-lg border px-2.5 py-1.5 text-[12.5px] font-semibold"
                                    style="border-color:var(--border-default); background:var(--surface-page); color:var(--text-body);">
                                <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="M12 5v14"/></svg>
                                <?php echo e($producto->name); ?>

                            </button>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </div>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
        <?php endif; ?>

        
        <?php
            $desalineados = collect($vigencias)->whereIn('estado', ['caducado', 'antes', 'inactivo']);
        ?>

        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($desalineados->isNotEmpty()): ?>
            <div class="mx-5 mb-3 rounded-lg px-4 py-3 text-[12.5px]"
                 style="background:var(--warning-50); border:1px solid var(--warning-500); color:var(--text-body);">
                <p class="font-semibold">
                    Ojo: <?php echo e($desalineados->count()); ?> producto(s) no siguen la fecha de la licencia.
                </p>
                <p class="mt-1 text-[12px]" style="color:var(--text-muted);">
                    Cada producto puede tener su propia vigencia dentro de la licencia. Si un producto
                    está caducado, ese plugin <strong>deja de funcionar aunque la licencia esté
                    vigente</strong>, y el Moodle recibe
                    «<em>Licence does not include this plugin</em>»,
                    que parece un problema de productos y es de fechas.
                    <strong>Renovar la licencia no cambia estas fechas.</strong>
                </p>
            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(count($vigencias) > 0): ?>
            <div class="lic-prod-grid hidden border-b px-5 py-1.5 text-[11px] font-semibold uppercase tracking-[0.06em] md:grid"
                 style="color:var(--text-muted); border-color:var(--divider);">
                <span>Producto</span>
                <span>Vigencia propia</span>
                <span>Estado</span>
                <span></span>
            </div>

            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $vigencias; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $vigencia): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php
                    $producto = $vigencia['producto'];
                    // Los cinco estados que ya calculaba el componente. `inactivo` y
                    // `caducado` van apagados: el producto no se está sirviendo.
                    $apagado = in_array($vigencia['estado'], ['inactivo', 'caducado'], true);

                    [$color, $fondo] = match ($vigencia['estado']) {
                        'vigente', 'sin_fecha' => ['var(--success-500)', 'var(--success-50)'],
                        'antes' => ['var(--warning-500)', 'var(--warning-50)'],
                        'caducado' => ['var(--danger-500)', 'var(--danger-50)'],
                        default => ['var(--neutral-600)', 'var(--surface-sunken)'],
                    };
                ?>

                <div class="lic-prod-grid items-center border-b px-5 py-2.5 text-[12.5px] transition-colors hover:bg-[var(--surface-alt)]"
                     style="border-color:var(--divider); opacity:<?php echo e($apagado ? '0.65' : '1'); ?>;">

                    <div class="flex min-w-0 items-center gap-2">
                        <?php if (isset($component)) { $__componentOriginal8685aa302c3ddaba5d15945e3d14b127 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal8685aa302c3ddaba5d15945e3d14b127 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.product-icons','data' => ['products' => [$producto],'class' => 'flex-none']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('product-icons'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['products' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute([$producto]),'class' => 'flex-none']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal8685aa302c3ddaba5d15945e3d14b127)): ?>
<?php $attributes = $__attributesOriginal8685aa302c3ddaba5d15945e3d14b127; ?>
<?php unset($__attributesOriginal8685aa302c3ddaba5d15945e3d14b127); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal8685aa302c3ddaba5d15945e3d14b127)): ?>
<?php $component = $__componentOriginal8685aa302c3ddaba5d15945e3d14b127; ?>
<?php unset($__componentOriginal8685aa302c3ddaba5d15945e3d14b127); ?>
<?php endif; ?>
                        <span class="truncate font-semibold" style="color:var(--text-strong);">
                            <?php echo e($producto->name); ?>

                        </span>
                    </div>

                    <span style="color:var(--text-body);">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($vigencia['desde'] || $vigencia['hasta']): ?>
                            <?php echo e($vigencia['desde'] ?? '—'); ?> – <?php echo e($vigencia['hasta'] ?? 'sin fin'); ?>

                        <?php else: ?>
                            <span style="color:var(--text-subtle);">La de la licencia</span>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </span>

                    <span>
                        <span class="rounded-full px-2.5 py-0.5 text-[11px] font-semibold"
                              style="color:<?php echo e($color); ?>; background:<?php echo e($fondo); ?>;">
                            <?php echo e($vigencia['texto']); ?>

                        </span>
                    </span>

                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.edit')): ?>
                        <div class="flex justify-end gap-3">
                            
                            <button type="button"
                                    wire:click="$dispatch('openModal', { component: 'license-tokens.product-removal-modal', arguments: { licenseTokenId: <?php echo e($licenseToken->id); ?>, productId: <?php echo e($producto->id); ?> } })"
                                    class="border-none bg-transparent p-0 text-[11.5px] font-semibold"
                                    style="color:var(--text-muted);"
                                    title="Elige entre dejar de servirlo al final del periodo o quitarlo ahora">
                                Quitar…
                            </button>
                        </div>
                    <?php endif; ?>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        <?php else: ?>
            <div class="mx-5 mb-4 rounded-lg border border-dashed p-4 text-center text-[12.5px]"
                 style="border-color:var(--border-default); color:var(--text-muted);">
                Esta licencia no incluye ningún producto, así que no sirve contenido a nadie.
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.edit')): ?>
                    <button type="button" @click="anadiendo = true"
                            class="border-none bg-transparent p-0 text-[12.5px] font-semibold"
                            style="color:var(--text-link);">Añadir el primero</button>
                <?php endif; ?>
            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </section>

    
    <section class="overflow-hidden rounded-xl border"
             style="background:var(--surface-card); border-color:var(--border-subtle);">

        <div class="flex flex-wrap items-baseline justify-between gap-4 px-5 pb-2.5 pt-3.5">
            <h2 style="font-family:'Plus Jakarta Sans',sans-serif; font-size:15px; font-weight:700; color:var(--text-strong); margin:0;">
                Entornos que usan esta licencia
            </h2>
            <div class="flex gap-3.5">
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.manage-environments')): ?>
                    
                    <button type="button" wire:click="abrirAsociarEntorno"
                            class="border-none bg-transparent p-0 text-[12.5px] font-semibold"
                            style="color:var(--text-link);">
                        Asociar entorno
                    </button>
                <?php endif; ?>
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.environments.create')): ?>
                    
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($licenseToken->client): ?>
                        <a href="<?php echo e(route('environments.create-from-client', $licenseToken->client)); ?>" wire:navigate
                           class="text-[12.5px] font-semibold" style="color:var(--text-link);">
                            Crear entorno
                        </a>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                <?php endif; ?>
            </div>
        </div>


        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $entornos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $entorno): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php
                // La paleta la da el catálogo de usos: era la misma lista copiada en seis vistas.
                $coloresEnv = \App\Models\Environments\Env::colores();
                [$colorEnv, $fondoEnv] = $coloresEnv[$entorno['env']] ?? $coloresEnv['local'];
            ?>

            <div class="lic-env-grid items-center border-t px-5 py-2.5 text-[12.5px] transition-colors hover:bg-[var(--surface-alt)]"
                 style="border-color:var(--divider);">

                
                <a href="<?php echo e(route('environments.edit', $entorno['id'])); ?>" wire:navigate class="min-w-0">
                    <span class="block truncate font-semibold" style="color:var(--text-strong);">
                        <?php echo e($entorno['nombre'] ?: $entorno['dominio']); ?>

                    </span>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($entorno['nombre'] && $entorno['dominio']): ?>
                        <span class="block truncate text-[11.5px]" style="color:var(--text-muted);">
                            <?php echo e($entorno['dominio']); ?>

                        </span>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </a>

                <span class="justify-self-start rounded px-[7px] py-px text-[10.5px] font-semibold"
                      style="color:<?php echo e($colorEnv); ?>; background:<?php echo e($fondoEnv); ?>;">
                    <?php echo e($entorno['env']); ?>

                </span>

                <span class="truncate" style="color:var(--text-body);">
                    <?php echo e($entorno['tipo'] ? $entorno['tipo'] . ' ' : ''); ?><?php echo e($entorno['version'] ?? '—'); ?>

                </span>

                <span class="truncate">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($entorno['nunca']): ?>
                        <span class="font-semibold" style="color:var(--warning-500);">Nunca sincronizado</span>
                    <?php elseif($entorno['sinSenal']): ?>
                        <span class="font-semibold" style="color:var(--danger-500);">
                            Sin señal · hace <?php echo e($entorno['dias']); ?> día(s)
                        </span>
                    <?php else: ?>
                        <span style="color:var(--text-muted);">Sincronizado <?php echo e($entorno['fecha']); ?></span>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </span>

                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.manage-environments')): ?>
                    
                    
                    <button type="button" wire:click="pedirDesasociar(<?php echo e($entorno['id']); ?>)"
                            class="justify-self-end border-none bg-transparent p-0 text-[11.5px] font-semibold"
                            style="color:var(--text-muted);">
                        Desasociar
                    </button>
                <?php endif; ?>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            
            <div class="mx-5 mb-4 rounded-lg border p-4 text-[12.5px]"
                 style="border:1.5px dashed var(--warning-500); background:var(--warning-50); color:var(--text-body);">
                <strong class="font-semibold">Ningún entorno usa esta licencia.</strong>
                Es un contrato firmado que nadie ha instalado — conversación comercial pendiente.
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.license-tokens.manage-environments')): ?>
                    <button type="button" wire:click="abrirAsociarEntorno"
                            class="border-none bg-transparent p-0 text-[12.5px] font-semibold"
                            style="color:var(--text-link);">Asociar un entorno</button>
                <?php endif; ?>
            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </section>
</div><?php /**PATH /var/www/html/resources/views/livewire/license-tokens/show.blade.php ENDPATH**/ ?>