<?php
if (!defined('ABSPATH')) {
    exit;
}

class GW_Elementor_License
{

    public function __construct()
    {
        // Ya no necesitamos handle_license_actions (sin formulario manual)
        // Comprobación diaria automática
        add_action('admin_init', [$this, 'scheduled_license_check']);
        
        // Auto-registro si no hay licencia guardada
        add_action('admin_init', [$this, 'check_and_register']);
    }
    
    /**
     * Verifica si hay licencia, si no, intenta registrarse automáticamente
     */
    public function check_and_register()
    {
        error_log('🔵 GW License: check_and_register() llamado');
        
        // Solo ejecutar una vez por sesión
        if (get_transient('gw_license_init_check')) {
            error_log('🟡 GW License: Ya se verificó en esta sesión (transient existe)');
            return;
        }
        
        error_log('🟢 GW License: Primera verificación de esta sesión');
        
        // Marcar que ya se verificó (dura 1 hora)
        set_transient('gw_license_init_check', true, HOUR_IN_SECONDS);
        
        // Si no hay license_key guardada, intentar auto-registro
        $existing_key = get_option('gw_license_key');
        error_log('🔍 GW License: Licencia existente: ' . ($existing_key ? $existing_key : 'NINGUNA'));
        
        if (!$existing_key) {
            error_log('🚀 GW License: Iniciando auto-registro...');
            $this->auto_register_on_activation();
        }
    }

    /**
     * AUTO-REGISTRO: Se ejecuta al activar el plugin
     * Llama a la API con el dominio para obtener/crear licencia
     */
    public function auto_register_on_activation()
    {
        error_log('🔵 GW License: auto_register_on_activation() iniciado');
        
        // Si ya tiene una licencia guardada, no hacer nada
        $existing_key = get_option('gw_license_key');
        if ($existing_key) {
            error_log('🟡 GW License: Ya existe una licencia: ' . $existing_key);
            return;
        }

        error_log('🟢 GW License: No hay licencia, llamando a la API...');
        // Llamar a la API para auto-registro
        $this->validate_license_remote();
    }

    /**
     * EL PORTERO: Devuelve true si la licencia es válida según la API
     */
    public function is_active()
    {
        // Verificar si el estado guardado es válido
        $status = get_option('gw_license_status');
        return $status === 'valid';
    }

    /**
     * Obtiene información de la licencia guardada localmente
     */
    public function get_license_info()
    {
        return [
            'status' => get_option('gw_license_status', 'unknown'),
            'license_key' => get_option('gw_license_key', ''),
            'type' => get_option('gw_license_type', 'trial'),
            'expires_at' => get_option('gw_license_expires_at', ''),
            'payment_url' => get_option('gw_license_payment_url', ''),
            'message' => get_option('gw_license_message', '')
        ];
    }

    /**
     * Calcula días restantes desde la fecha de expiración
     */
    public function get_days_left()
    {
        $expires_at = get_option('gw_license_expires_at');
        if (!$expires_at) {
            return 0;
        }

        $expiry_timestamp = strtotime($expires_at);
        $now = time();
        $diff = $expiry_timestamp - $now;

        if ($diff <= 0) {
            return 0;
        }

        return ceil($diff / (60 * 60 * 24));
    }

    /**
     * Obtiene el tiempo restante en formato detallado (días, horas, minutos)
     */
    public function get_time_remaining()
    {
        $expires_at = get_option('gw_license_expires_at');
        if (!$expires_at) {
            return ['days' => 0, 'hours' => 0, 'minutes' => 0, 'seconds' => 0];
        }

        $expiry_timestamp = strtotime($expires_at);
        $now = time();
        $diff = $expiry_timestamp - $now;

        if ($diff <= 0) {
            return ['days' => 0, 'hours' => 0, 'minutes' => 0, 'seconds' => 0];
        }

        $days = floor($diff / (60 * 60 * 24));
        $hours = floor(($diff % (60 * 60 * 24)) / (60 * 60));
        $minutes = floor(($diff % (60 * 60)) / 60);
        $seconds = $diff % 60;

        return [
            'days' => $days,
            'hours' => $hours,
            'minutes' => $minutes,
            'seconds' => $seconds
        ];
    }

    /**
     * Obtiene el tiempo restante formateado como texto
     */
    public function get_time_remaining_text()
    {
        $time = $this->get_time_remaining();
        
        if ($time['days'] == 0 && $time['hours'] == 0 && $time['minutes'] == 0) {
            return 'Expirado';
        }

        $parts = [];
        
        if ($time['days'] > 0) {
            $parts[] = $time['days'] . ' día' . ($time['days'] != 1 ? 's' : '');
        }
        
        if ($time['hours'] > 0) {
            $parts[] = $time['hours'] . ' hora' . ($time['hours'] != 1 ? 's' : '');
        }
        
        if ($time['minutes'] > 0 || empty($parts)) {
            $parts[] = $time['minutes'] . ' minuto' . ($time['minutes'] != 1 ? 's' : '');
        }

        return implode(', ', $parts);
    }

    /**
     * Validación remota AUTOMÁTICA (solo envía dominio)
     * La API devuelve la licencia asociada a ese dominio
     */
    public function validate_license_remote()
    {
        $domain = home_url();
        $url = GW_API_URL . "?domain=" . urlencode($domain);
        
        error_log('🌐 GW License: Llamando a API...');
        error_log('   URL: ' . $url);
        error_log('   Dominio: ' . $domain);

        $response = wp_remote_get($url, [
            'timeout' => 15,
            'sslverify' => false, // Desactivar verificación SSL para desarrollo
            'headers' => [
                'User-Agent' => 'GW-Elementor-Analytics/2.2.1'
            ]
        ]);
        
        error_log('📡 GW License: Respuesta recibida');

        if (is_wp_error($response)) {
            $error_message = $response->get_error_message();
            error_log('❌ GW License ERROR: ' . $error_message);
            
            // Si hay error de conexión, mantener estado anterior por 24h
            // Solo actualizar si no hay cache
            if (!get_transient('gw_license_check_cache')) {
                update_option('gw_license_status', 'error');
                update_option('gw_license_message', 'Error de conexión: ' . $error_message);
            }
            return;
        }

        $body = wp_remote_retrieve_body($response);
        error_log('📦 GW License: Body recibido: ' . substr($body, 0, 200));
        
        $data = json_decode($body, true);
        
        if (!$data) {
            error_log('❌ GW License: Error al parsear JSON');
            error_log('   Body completo: ' . $body);
            return;
        }
        
        error_log('✅ GW License: JSON parseado correctamente');
        error_log('   Status: ' . ($data['status'] ?? 'N/A'));
        error_log('   License Key: ' . ($data['license_key'] ?? 'N/A'));
        error_log('   Type: ' . ($data['type'] ?? 'N/A'));
        error_log('   Expires: ' . ($data['expires_at'] ?? 'N/A'));

        // Guardar cache por 1 hora (más dinámico para cambios manuales)
        set_transient('gw_license_check_cache', true, HOUR_IN_SECONDS);

        // Procesar respuesta según el status
        if (isset($data['status'])) {
            switch ($data['status']) {
                case 'valid':
                    error_log('✅ GW License: Guardando licencia VÁLIDA');
                    // Licencia válida (trial o pro)
                    update_option('gw_license_status', 'valid');
                    update_option('gw_license_key', $data['license_key'] ?? '');
                    update_option('gw_license_type', $data['type'] ?? 'trial');
                    update_option('gw_license_expires_at', $data['expires_at'] ?? '');
                    update_option('gw_license_message', $data['message'] ?? 'Licencia válida');
                    update_option('gw_license_payment_url', $data['payment_url'] ?? '');
                    
                    error_log('💾 GW License: Datos guardados en WordPress');
                    error_log('   Key guardada: ' . get_option('gw_license_key'));
                    error_log('   Expires guardada: ' . get_option('gw_license_expires_at'));
                    break;

                case 'expired':
                    // Licencia expirada - BLOQUEAR FUNCIONES
                    update_option('gw_license_status', 'expired');
                    update_option('gw_license_message', $data['message'] ?? 'La licencia ha caducado');
                    update_option('gw_license_payment_url', $data['payment_url'] ?? '');
                    break;

                case 'blocked':
                    // Licencia bloqueada
                    update_option('gw_license_status', 'blocked');
                    update_option('gw_license_message', $data['message'] ?? 'Licencia suspendida');
                    break;

                case 'error':
                    // Error desde la API
                    update_option('gw_license_status', 'error');
                    update_option('gw_license_message', $data['message'] ?? 'Error desconocido');
                    break;

                default:
                    // Estado desconocido
                    update_option('gw_license_status', 'invalid');
                    update_option('gw_license_message', 'Respuesta inválida del servidor');
                    break;
            }
        } else {
            // Respuesta malformada
            update_option('gw_license_status', 'error');
            update_option('gw_license_message', 'Respuesta inválida del servidor');
        }
    }

    /**
     * Comprobación programada cada 24 horas
     */
    public function scheduled_license_check()
    {
        // Si hay cache válido, no verificar
        if (get_transient('gw_license_check_cache')) {
            return;
        }

        // Revalidar con la API
        $this->validate_license_remote();
    }

    /**
     * Botón manual para refrescar licencia (útil después de pagar)
     */
    public function force_refresh()
    {
        delete_transient('gw_license_check_cache');
        $this->validate_license_remote();
    }

    /**
     * Renderiza el banner de aviso según el estado
     */
    public function render_trial_notice()
    {
        $info = $this->get_license_info();
        $status = $info['status'];

        // Si la licencia es válida y es PRO, no mostrar nada
        if ($status === 'valid' && $info['type'] === 'pro') {
            return;
        }

        // Si la licencia es válida y es TRIAL, mostrar contador
        if ($status === 'valid' && $info['type'] === 'trial') {
            $days_left = $this->get_days_left();
            $expires_at = $info['expires_at'];
            
            // Calcular tiempo restante preciso
            $expiry_timestamp = strtotime($expires_at);
            $remaining_seconds = $expiry_timestamp - time();
            
            if ($remaining_seconds < 0) {
                $remaining_seconds = 0;
            }

            $d = floor($remaining_seconds / (24 * 60 * 60));
            $h = floor(($remaining_seconds % (24 * 60 * 60)) / 3600);
            $m = floor(($remaining_seconds % 3600) / 60);

            $time_left_text = sprintf('%d días, %d horas y %d min', $d, $h, $m);
            
            // Calcular porcentaje (30 días = 100%)
            $trial_total_seconds = 30 * 24 * 60 * 60;
            $percent = 100 - (($remaining_seconds / $trial_total_seconds) * 100);
            if ($percent > 100) $percent = 100;

            ?>
            <div style="background: #fff8e5; border: 1px solid #f0c33c; border-radius: 8px; padding: 15px 20px; margin-bottom: 25px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 5px rgba(0,0,0,0.05);">
                <div style="display:flex; align-items:center; gap:15px;">
                    <div style="background:#ffba00; color:#fff; width:40px; height:40px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:20px;">⏳</div>
                    <div>
                        <h4 style="margin:0 0 4px 0; color:#b76e00; font-size:14px;">Periodo de Prueba Activo</h4>
                        <p style="margin:0; font-size:13px; color:#7a4b05;">Te quedan <strong><?php echo $time_left_text; ?></strong> para disfrutar de todas las funciones.</p>
                    </div>
                </div>
                <div style="display:flex; align-items:center; gap:20px;">
                    <div style="width: 150px; height: 8px; background: #eaddb8; border-radius: 4px; overflow: hidden;">
                        <div style="width: <?php echo $percent; ?>%; height: 100%; background: #ffba00;"></div>
                    </div>
                    <?php if (!empty($info['payment_url'])): ?>
                        <a href="<?php echo esc_url($info['payment_url']); ?>" class="button button-primary" target="_blank">Actualizar a PRO</a>
                    <?php endif; ?>
                </div>
            </div>
            <?php
            return;
        }

        // Si la licencia está EXPIRADA, mostrar aviso crítico
        if ($status === 'expired') {
            ?>
            <div style="background: #fbeaea; border: 2px solid #dc3232; border-radius: 8px; padding: 20px; margin-bottom: 25px; box-shadow: 0 2px 10px rgba(220,50,50,0.2);">
                <div style="display:flex; align-items:start; gap:15px;">
                    <div style="background:#dc3232; color:#fff; width:50px; height:50px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:24px; flex-shrink:0;">⚠️</div>
                    <div style="flex:1;">
                        <h3 style="margin:0 0 10px 0; color:#dc3232; font-size:18px;">Tu periodo de prueba ha finalizado</h3>
                        <p style="margin:0 0 15px 0; font-size:14px; color:#7a0b0b; line-height:1.6;">
                            <?php echo esc_html($info['message']); ?>
                        </p>
                        <?php if (!empty($info['payment_url'])): ?>
                            <a href="<?php echo esc_url($info['payment_url']); ?>" class="button button-primary button-hero" target="_blank" 
                               style="background: #e01d75; border-color: #e01d75; box-shadow: 0 4px 15px rgba(224,29,117,0.4); text-shadow: none;">
                                🚀 Suscríbete Ahora y Continúa Usando el Plugin
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <?php
            return;
        }

        // Si hay error de conexión
        if ($status === 'error') {
            ?>
            <div style="background: #fff3cd; border: 1px solid #ffc107; border-radius: 8px; padding: 15px 20px; margin-bottom: 25px;">
                <div style="display:flex; align-items:center; gap:15px;">
                    <span style="font-size:24px;">⚠️</span>
                    <div>
                        <h4 style="margin:0 0 4px 0; color:#856404; font-size:14px;">Error de Conexión</h4>
                        <p style="margin:0; font-size:13px; color:#856404;"><?php echo esc_html($info['message']); ?></p>
                    </div>
                </div>
            </div>
            <?php
            return;
        }

        // Si está bloqueada
        if ($status === 'blocked') {
            ?>
            <div style="background: #fbeaea; border: 2px solid #dc3232; border-radius: 8px; padding: 20px; margin-bottom: 25px;">
                <div style="display:flex; align-items:center; gap:15px;">
                    <span style="font-size:32px;">🚫</span>
                    <div>
                        <h4 style="margin:0 0 4px 0; color:#dc3232; font-size:16px;">Licencia Suspendida</h4>
                        <p style="margin:0; font-size:13px; color:#7a0b0b;"><?php echo esc_html($info['message']); ?></p>
                    </div>
                </div>
            </div>
            <?php
            return;
        }
    }

    public function render_tab()
    {
        $info = $this->get_license_info();
        $is_valid = $info['status'] === 'valid';
        $is_pro = $info['type'] === 'pro';
        $is_trial = $info['type'] === 'trial';
        $is_full = $info['type'] === 'full';

        ?>
        <style>
            .gw-btn-primary {
                display: inline-flex;
                align-items: center;
                gap: 10px;
                background: #e01d75;
                color: white;
                border: none;
                padding: 14px 32px;
                border-radius: 8px;
                font-size: 15px;
                font-weight: 600;
                cursor: pointer;
                transition: all 0.3s ease;
                box-shadow: 0 4px 15px rgba(224, 29, 117, 0.3);
                text-decoration: none;
            }

            .gw-btn-primary:hover {
                transform: translateY(-2px);
                box-shadow: 0 8px 25px rgba(224, 29, 117, 0.4);
                background: #c91a6a;
                color: white;
            }

            .gw-btn-secondary {
                background: #6c757d;
                box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
            }

            .gw-btn-secondary:hover {
                background: #5a6268;
                box-shadow: 0 8px 25px rgba(108, 117, 125, 0.4);
            }

            .gw-settings-container {
                position: relative;
            }
        </style>
        <div class="gw-settings-container" style="max-width: 600px; margin-top: 40px;">

            <?php if (!$is_full): ?>
            <div class="gw-settings-header" style="justify-content: center; text-align: center; margin-bottom: 40px;">
                <h2 style="flex-direction: column; gap: 10px;">
                    <span class="dashicons dashicons-admin-network" style="font-size: 40px; width: 40px; height: 40px; color: var(--gw-brand);"></span>
                    Estado de la Licencia
                </h2>
            </div>
            <?php endif; ?>

            <?php if ($is_valid && $is_full): ?>
                <!-- LICENCIA FULL - DISEÑO BRUTAL -->
                <div class="gw-full-license-container" style="margin-top: 0;">
                    <!-- Partículas de fondo -->
                    <div class="gw-particles-bg">
                        <div class="particle"></div>
                        <div class="particle"></div>
                        <div class="particle"></div>
                        <div class="particle"></div>
                        <div class="particle"></div>
                        <div class="particle"></div>
                    </div>
                    
                    <!-- Contenido principal -->
                    <div class="gw-full-content">
                        <!-- Icono épico con múltiples anillos -->
                        <div class="gw-epic-icon-wrapper">
                            <div class="gw-ring ring-1"></div>
                            <div class="gw-ring ring-2"></div>
                            <div class="gw-ring ring-3"></div>
                            <div class="gw-icon-circle">
                                <span class="dashicons dashicons-awards"></span>
                                <div class="gw-shine"></div>
                            </div>
                        </div>
                        
                        <!-- Badge premium -->
                        <div class="gw-premium-badge">
                            <span class="badge-icon">👑</span>
                            <span class="badge-text">LICENCIA FULL</span>
                            <div class="badge-shine"></div>
                        </div>
                        
                        <h3 class="gw-full-title">∞ Acceso Ilimitado Activado</h3>
                        <p class="gw-full-subtitle">Eres parte de un grupo exclusivo. Gracias por confiar en nosotros.</p>
                        
                        <!-- Features exclusivos -->
                        <div class="gw-full-features">
                            <div class="feature-item">
                                <span class="dashicons dashicons-yes-alt"></span>
                                <span>Sin límite de tiempo</span>
                            </div>
                            <div class="feature-item">
                                <span class="dashicons dashicons-yes-alt"></span>
                                <span>Todas las funciones</span>
                            </div>
                            <div class="feature-item">
                                <span class="dashicons dashicons-yes-alt"></span>
                                <span>Soporte prioritario</span>
                            </div>
                            <div class="feature-item">
                                <span class="dashicons dashicons-yes-alt"></span>
                                <span>Actualizaciones gratis</span>
                            </div>
                        </div>
                        
                        <div class="gw-divider"></div>
                        
                        <!-- Datos de la licencia -->
                        <div class="gw-license-data">
                            <div class="data-row">
                                <span class="data-label">🔑 Clave</span>
                                <span class="data-value"><?php echo esc_attr($info['license_key']); ?></span>
                            </div>
                            <div class="data-row">
                                <span class="data-label">🌐 Dominio</span>
                                <span class="data-value"><?php echo parse_url(home_url(), PHP_URL_HOST); ?></span>
                            </div>
                            <div class="data-row">
                                <span class="data-label">⏰ Validez</span>
                                <span class="data-value">∞ Ilimitada</span>
                            </div>
                        </div>
                        
                        <div class="gw-divider"></div>
                        
                        <!-- Llamada a acción para compartir -->
                        <div class="gw-share-section">
                            <h4 class="share-title">✨ ¿Te gusta GW Analytics?</h4>
                            <p class="share-subtitle">Ayúdanos a crecer compartiéndolo en redes sociales</p>
                            
                            <div class="gw-social-buttons">
                                <a href="https://twitter.com/intent/tweet?text=Estoy%20usando%20GW%20Analytics%20para%20optimizar%20mis%20formularios%20de%20Elementor%20%F0%9F%9A%80&url=https://gwanalytics.generacionweb.es" target="_blank" class="social-btn twitter">
                                    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
                                    Twitter
                                </a>
                                <a href="https://www.facebook.com/sharer/sharer.php?u=https://gwanalytics.generacionweb.es" target="_blank" class="social-btn facebook">
                                    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z"/></svg>
                                    Facebook
                                </a>
                                <a href="https://www.linkedin.com/sharing/share-offsite/?url=https://gwanalytics.generacionweb.es" target="_blank" class="social-btn linkedin">
                                    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>
                                    LinkedIn
                                </a>
                                <a href="https://gwanalytics.generacionweb.es" target="_blank" class="social-btn website">
                                    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm0 2c1.478 0 2.866.316 4.117.88-1.117.866-2.522 1.745-4.117 2.492-1.595-.747-3-.1626-4.117-2.492A9.942 9.942 0 0 1 12 2zm0 18c-5.523 0-10-4.477-10-10 0-1.11.181-2.18.516-3.182C3.657 7.843 5.22 9.115 7.168 10.37c-1.254 1.231-2.163 2.79-2.61 4.548A9.935 9.935 0 0 0 12 22c2.13 0 4.102-.667 5.726-1.799-.447-1.758-1.356-3.317-2.61-4.548 1.948-1.255 3.511-2.527 4.652-3.552A9.941 9.941 0 0 1 12 20z"/></svg>
                                    Web
                                </a>
                            </div>
                        </div>
                        
                        <!-- Botón refrescar -->
                        <form method="post" style="margin-top: 30px;">
                            <?php wp_nonce_field('gw_license_refresh'); ?>
                            <button type="submit" name="gw_refresh_license" class="gw-btn-refresh-full">
                                <span class="dashicons dashicons-update"></span>
                                <span>Refrescar Estado</span>
                            </button>
                        </form>
                    </div>
                </div>
                
                <!-- ESTILOS BRUTALES PARA LICENCIA FULL -->
                <style>
                    /* Fondo del body cuando es FULL */
                    body {
                        background-color: #e8e7ff !important;
                    }
                    
                    /* Contenedor principal */
                    .gw-full-license-container {
                        position: relative;
                        background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #7c3aed 100%);
                        border-radius: 20px;
                        padding: 50px 40px;
                        overflow: hidden;
                        box-shadow: 
                            0 20px 60px rgba(124, 58, 237, 0.4),
                            0 0 100px rgba(139, 92, 246, 0.3),
                            inset 0 1px 0 rgba(255, 255, 255, 0.1);
                    }
                    
                    /* Partículas animadas de fondo */
                    .gw-particles-bg {
                        position: absolute;
                        top: 0;
                        left: 0;
                        width: 100%;
                        height: 100%;
                        overflow: hidden;
                        pointer-events: none;
                    }
                    
                    .gw-particles-bg .particle {
                        position: absolute;
                        background: radial-gradient(circle, rgba(167, 139, 250, 0.4) 0%, transparent 70%);
                        border-radius: 50%;
                        animation: float 20s infinite ease-in-out;
                    }
                    
                    .particle:nth-child(1) { width: 120px; height: 120px; top: 10%; left: 10%; animation-delay: 0s; }
                    .particle:nth-child(2) { width: 180px; height: 180px; top: 60%; right: 5%; animation-delay: 3s; }
                    .particle:nth-child(3) { width: 90px; height: 90px; bottom: 15%; left: 60%; animation-delay: 6s; }
                    .particle:nth-child(4) { width: 150px; height: 150px; top: 30%; right: 20%; animation-delay: 2s; }
                    .particle:nth-child(5) { width: 100px; height: 100px; bottom: 40%; left: 20%; animation-delay: 5s; }
                    .particle:nth-child(6) { width: 130px; height: 130px; top: 80%; right: 40%; animation-delay: 4s; }
                    
                    @keyframes float {
                        0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.3; }
                        25% { transform: translate(40px, -40px) scale(1.1); opacity: 0.5; }
                        50% { transform: translate(-40px, 40px) scale(0.9); opacity: 0.3; }
                        75% { transform: translate(30px, 30px) scale(1.05); opacity: 0.4; }
                    }
                    
                    /* Contenido */
                    .gw-full-content {
                        position: relative;
                        z-index: 1;
                        text-align: center;
                    }
                    
                    /* Icono épico con anillos */
                    .gw-epic-icon-wrapper {
                        position: relative;
                        display: inline-block;
                        margin-bottom: 30px;
                    }
                    
                    .gw-icon-circle {
                        position: relative;
                        z-index: 2;
                        width: 140px;
                        height: 140px;
                        margin: 10px;
                        background: linear-gradient(135deg, #c026d3 0%, #a855f7 50%, #ec4899 100%);
                        border-radius: 50%;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        box-shadow: 
                            0 15px 50px rgba(192, 38, 211, 0.6),
                            0 0 80px rgba(168, 85, 247, 0.4),
                            inset 0 2px 0 rgba(255, 255, 255, 0.2);
                        animation: iconPulse 3s ease-in-out infinite;
                        overflow: hidden;
                    }
                    
                    .gw-icon-circle .dashicons {
                        font-size: 70px;
                        width: 70px;
                        height: 70px;
                        color: white;
                        filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
                        animation: iconRotate 10s linear infinite;
                    }
                    
                    @keyframes iconPulse {
                        0%, 100% { transform: scale(1); }
                        50% { transform: scale(1.05); }
                    }
                    
                    @keyframes iconRotate {
                        0%, 100% { transform: scale(1); }
                        50% { transform: scale(1.15); }
                    }
                    
                    /* Brillo del icono */
                    .gw-shine {
                        position: absolute;
                        top: -50%;
                        left: -50%;
                        width: 200%;
                        height: 200%;
                        background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
                        animation: shine 4s linear infinite;
                    }
                    
                    @keyframes shine {
                        0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
                        100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
                    }
                    
                    /* Anillos pulsantes */
                    .gw-ring {
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        transform: translate(-50%, -50%);
                        border: 3px solid rgba(192, 38, 211, 0.6);
                        border-radius: 50%;
                        animation: ringPulse 3s ease-out infinite;
                    }
                    
                    .ring-1 { width: 140px; height: 140px; animation-delay: 0s; }
                    .ring-2 { width: 140px; height: 140px; animation-delay: 1s; }
                    .ring-3 { width: 140px; height: 140px; animation-delay: 2s; }
                    
                    @keyframes ringPulse {
                        0% { width: 140px; height: 140px; opacity: 1; }
                        100% { width: 240px; height: 240px; opacity: 0; }
                    }
                    
                    /* Badge premium */
                    .gw-premium-badge {
                        display: inline-block;
                        position: absolute;
                        top: -30px;
                        right: -20px;
                        background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
                        color: #78350f;
                        padding: 8px 20px;
                        border-radius: 30px;
                        font-weight: 800;
                        font-size: 12px;
                        letter-spacing: 2px;
                        text-transform: uppercase;
                        box-shadow: 0 8px 25px rgba(251, 191, 36, 0.5);
                        overflow: hidden;
                        z-index: 10;
                    }
                    
                    .badge-icon {
                        font-size: 18px;
                        margin-right: 8px;
                        animation: badgeBounce 2s ease-in-out infinite;
                    }
                    
                    @keyframes badgeBounce {
                        0%, 100% { transform: translateY(0); }
                        50% { transform: translateY(-3px); }
                    }
                    
                    .badge-shine {
                        position: absolute;
                        top: 0;
                        left: -100%;
                        width: 100%;
                        height: 100%;
                        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
                        animation: badgeShine 3s linear infinite;
                    }
                    
                    @keyframes badgeShine {
                        0% { left: -100%; }
                        100% { left: 100%; }
                    }
                    
                    /* Título y subtítulo */
                    .gw-full-title {
                        font-size: 32px;
                        font-weight: 800;
                        background: linear-gradient(135deg, #fbbf24 0%, #ffffff 50%, #a78bfa 100%);
                        -webkit-background-clip: text;
                        -webkit-text-fill-color: transparent;
                        background-clip: text;
                        margin: 0 0 15px 0;
                        line-height: 1.4;
                        animation: titleGlow 3s ease-in-out infinite;
                    }
                    
                    @keyframes titleGlow {
                        0%, 100% { filter: brightness(1); }
                        50% { filter: brightness(1.3); }
                    }
                    
                    .gw-full-subtitle {
                        color: rgba(255, 255, 255, 0.8);
                        font-size: 16px;
                        margin-bottom: 35px;
                        line-height: 1.5;
                    }
                    
                    /* Features exclusivos */
                    .gw-full-features {
                        display: grid;
                        grid-template-columns: repeat(2, 1fr);
                        gap: 15px;
                        margin-bottom: 35px;
                    }
                    
                    .feature-item {
                        background: rgba(255, 255, 255, 0.1);
                        padding: 15px;
                        border-radius: 12px;
                        border: 1px solid rgba(255, 255, 255, 0.2);
                        display: flex;
                        align-items: center;
                        gap: 10px;
                        color: white;
                        font-weight: 600;
                        font-size: 14px;
                        transition: all 0.3s ease;
                    }
                    
                    .feature-item:hover {
                        background: rgba(255, 255, 255, 0.15);
                        transform: translateY(-2px);
                    }
                    
                    .feature-item .dashicons {
                        color: #fbbf24;
                        font-size: 20px;
                    }
                    
                    /* Divider */
                    .gw-divider {
                        height: 1px;
                        background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.3) 50%, transparent 100%);
                        margin: 30px 0;
                    }
                    
                    /* Datos de la licencia */
                    .gw-license-data {
                        background: rgba(255, 255, 255, 0.1);
                        border-radius: 15px;
                        padding: 20px;
                        border: 1px solid rgba(255, 255, 255, 0.2);
                    }
                    
                    .data-row {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        padding: 12px 0;
                        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
                    }
                    
                    .data-row:last-child {
                        border-bottom: none;
                    }
                    
                    .data-label {
                        color: rgba(255, 255, 255, 0.7);
                        font-size: 14px;
                        font-weight: 600;
                    }
                    
                    .data-value {
                        color: white;
                        font-size: 14px;
                        font-weight: 700;
                        font-family: 'Courier New', monospace;
                        background: rgba(255, 255, 255, 0.1);
                        padding: 6px 12px;
                        border-radius: 6px;
                    }
                    
                    /* Sección compartir */
                    .gw-share-section {
                        text-align: center;
                    }
                    
                    .share-title {
                        color: white;
                        font-size: 20px;
                        font-weight: 700;
                        margin: 0 0 10px 0;
                    }
                    
                    .share-subtitle {
                        color: rgba(255, 255, 255, 0.7);
                        font-size: 14px;
                        margin-bottom: 20px;
                    }
                    
                    /* Botones sociales */
                    .gw-social-buttons {
                        display: grid;
                        grid-template-columns: repeat(2, 1fr);
                        gap: 12px;
                    }
                    
                    .social-btn {
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        gap: 10px;
                        padding: 14px 20px;
                        border-radius: 10px;
                        font-weight: 600;
                        font-size: 14px;
                        text-decoration: none;
                        transition: all 0.3s ease;
                        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
                    }
                    
                    .social-btn:hover {
                        transform: translateY(-3px);
                        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
                    }
                    
                    .social-btn.twitter {
                        background: #1DA1F2;
                        color: white;
                    }
                    
                    .social-btn.facebook {
                        background: #1877F2;
                        color: white;
                    }
                    
                    .social-btn.linkedin {
                        background: #0A66C2;
                        color: white;
                    }
                    
                    .social-btn.website {
                        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
                        color: white;
                    }
                    
                    /* Botón refrescar FULL */
                    .gw-btn-refresh-full {
                        width: 100%;
                        padding: 16px 24px;
                        background: rgba(255, 255, 255, 0.15);
                        border: 2px solid rgba(255, 255, 255, 0.3);
                        border-radius: 12px;
                        color: white;
                        font-weight: 600;
                        font-size: 15px;
                        cursor: pointer;
                        transition: all 0.3s ease;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        gap: 10px;
                    }
                    
                    .gw-btn-refresh-full:hover {
                        background: rgba(255, 255, 255, 0.25);
                        border-color: rgba(255, 255, 255, 0.5);
                        transform: translateY(-2px);
                        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
                    }
                    
                    .gw-btn-refresh-full .dashicons {
                        font-size: 20px;
                        transition: transform 0.6s ease;
                    }
                    
                    .gw-btn-refresh-full:hover .dashicons {
                        transform: rotate(180deg);
                    }
                    
                    /* Responsive */
                    @media (max-width: 768px) {
                        .gw-full-license-container {
                            padding: 35px 20px;
                        }
                        
                        .gw-premium-badge {
                            position: static;
                            margin: 0 auto 20px auto;
                            display: block;
                            width: fit-content;
                        }
                        
                        .gw-icon-circle {
                            width: 100px;
                            height: 100px;
                        }
                        
                        .gw-icon-circle .dashicons {
                            font-size: 50px;
                            width: 50px;
                            height: 50px;
                        }
                        
                        .gw-full-title {
                            font-size: 24px;
                            line-height: 1.3;
                        }
                        
                        .gw-full-features {
                            grid-template-columns: 1fr;
                        }
                        
                        .gw-social-buttons {
                            grid-template-columns: 1fr;
                        }
                    }
                </style>

            <?php elseif ($is_valid && $is_pro): ?>
                <!-- LICENCIA PRO ACTIVA -->
                <div class="gw-card" style="text-align: center; border-top: 4px solid #46b450;">
                    <div style="margin-bottom: 20px;">
                        <div style="background: #e7f6e8; color: #46b450; width: 80px; height: 80px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto;">
                            <span class="dashicons dashicons-yes-alt" style="font-size: 40px; width: 40px; height: 40px;"></span>
                        </div>
                    </div>

                    <h3 style="margin: 0 0 10px 0; font-size: 20px; color: #1d2327;">🎉 Licencia PRO Activa</h3>
                    <p style="color: #646970; margin-bottom: 30px;">Suscripción mensual activa. Tu plugin está completamente funcional.</p>

                    <div class="gw-input-group" style="text-align: left;">
                        <label class="gw-label">Clave de Producto</label>
                        <input type="text" value="<?php echo esc_attr($info['license_key']); ?>" class="gw-input" readonly
                            style="background: #f0f0f1; color: #666; cursor: not-allowed; text-align: center; font-family: monospace; letter-spacing: 1px;">
                    </div>

                    <div class="gw-input-group" style="text-align: left;">
                        <label class="gw-label">Dominio Autorizado</label>
                        <div style="padding: 12px; background: #f9f9f9; border: 1px solid #e5e5e5; border-radius: 8px; color: #50575e; font-weight: 500; display:flex; align-items:center; gap:8px;">
                            <span class="dashicons dashicons-admin-site-alt3"></span> <?php echo home_url(); ?>
                        </div>
                    </div>

                    <div class="gw-input-group" style="text-align: left;">
                        <label class="gw-label">Renovación Mensual</label>
                        <div style="padding: 12px; background: #f9f9f9; border: 1px solid #e5e5e5; border-radius: 8px; color: #50575e; font-weight: 500;">
                            Próxima: <?php echo date('d/m/Y', strtotime($info['expires_at'])); ?>
                        </div>
                    </div>

                    <form method="post" style="margin-top: 30px;">
                        <?php wp_nonce_field('gw_license_refresh'); ?>
                        <button type="submit" name="gw_refresh_license" class="gw-btn-refresh" style="width: 100%; padding: 14px 20px; border: 2px solid #e5e7eb; background: white; color: #6b7280; font-weight: 600; border-radius: 10px; cursor: pointer; transition: all 0.3s ease; display: flex; align-items: center; justify-content: center; gap: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
                            <span class="dashicons dashicons-update" style="font-size: 18px; width: 18px; height: 18px;"></span>
                            <span>Refrescar Estado</span>
                        </button>
                    </form>
                    
                    <style>
                        .gw-btn-refresh:hover {
                            background: #f9fafb !important;
                            border-color: #d1d5db !important;
                            transform: translateY(-2px);
                            box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important;
                        }
                        
                        .gw-btn-refresh:active {
                            transform: translateY(0);
                            box-shadow: 0 2px 4px rgba(0,0,0,0.05) !important;
                        }
                        
                        .gw-btn-refresh .dashicons {
                            transition: transform 0.6s ease;
                        }
                        
                        .gw-btn-refresh:hover .dashicons {
                            transform: rotate(180deg);
                        }
                    </style>
                </div>

            <?php elseif ($is_valid && $is_trial): ?>
                <!-- LICENCIA TRIAL ACTIVA -->
                <div class="gw-card" style="text-align: center; border-top: 4px solid #ffba00; background: linear-gradient(135deg, #ffffff 0%, #fffbf0 100%); position: relative; overflow: hidden;">
                    
                    <!-- Decoración de fondo -->
                    <div style="position: absolute; top: -50px; right: -50px; width: 150px; height: 150px; background: radial-gradient(circle, rgba(255,186,0,0.1) 0%, transparent 70%); border-radius: 50%;"></div>
                    <div style="position: absolute; bottom: -30px; left: -30px; width: 100px; height: 100px; background: radial-gradient(circle, rgba(224,29,117,0.08) 0%, transparent 70%); border-radius: 50%;"></div>
                    
                    <div style="position: relative; z-index: 1;">
                        <!-- Icono con animación -->
                        <div style="margin-bottom: 25px; position: relative;">
                            <div style="background: linear-gradient(135deg, #fff8e5 0%, #ffedd5 100%); width: 100px; height: 100px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto; box-shadow: 0 8px 25px rgba(255,186,0,0.25); border: 3px solid #fff; animation: pulse 2s ease-in-out infinite;">
                                <span style="font-size: 50px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));">⏳</span>
                            </div>
                            <!-- Badge de tiempo restante -->
                            <?php 
                            $time_remaining = $this->get_time_remaining();
                            $badge_text = '';
                            if ($time_remaining['days'] > 0) {
                                $badge_text = $time_remaining['days'] . 'd ' . $time_remaining['hours'] . 'h ' . $time_remaining['minutes'] . 'm';
                            } elseif ($time_remaining['hours'] > 0) {
                                $badge_text = $time_remaining['hours'] . 'h ' . $time_remaining['minutes'] . 'm';
                            } else {
                                $badge_text = $time_remaining['minutes'] . ' minutos';
                            }
                            ?>
                            <div id="gw-countdown-badge" style="position: absolute; top: -10px; right: 50%; transform: translateX(calc(50% + 60px)); background: linear-gradient(135deg, #e01d75 0%, #c91a6a 100%); color: white; padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 700; box-shadow: 0 4px 15px rgba(224,29,117,0.4); white-space: nowrap;">
                                <?php echo $badge_text; ?>
                            </div>
                        </div>

                        <h3 style="margin: 0 0 8px 0; font-size: 24px; color: #1d2327; font-weight: 700;">Periodo de Prueba Activo</h3>
                        <p style="color: #646970; margin-bottom: 30px; font-size: 15px;">Te quedan <strong style="color: #b76e00;"><span id="gw-countdown-text"><?php echo $this->get_time_remaining_text(); ?></span></strong> de prueba gratuita.</p>
                        
                        <!-- Script para actualizar el contador en tiempo real -->
                        <script>
                        (function() {
                            // Fecha de expiración desde PHP
                            const expirationDate = new Date('<?php echo date('c', strtotime($info['expires_at'])); ?>').getTime();
                            
                            function updateCountdown() {
                                const now = new Date().getTime();
                                const distance = expirationDate - now;
                                
                                if (distance < 0) {
                                    document.getElementById('gw-countdown-badge').textContent = 'Expirado';
                                    document.getElementById('gw-countdown-text').textContent = 'Expirado';
                                    return;
                                }
                                
                                // Calcular tiempo
                                const days = Math.floor(distance / (1000 * 60 * 60 * 24));
                                const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                                const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                                const seconds = Math.floor((distance % (1000 * 60)) / 1000);
                                
                                // Actualizar badge
                                let badgeText = '';
                                if (days > 0) {
                                    badgeText = days + 'd ' + hours + 'h ' + minutes + 'm';
                                } else if (hours > 0) {
                                    badgeText = hours + 'h ' + minutes + 'm ' + seconds + 's';
                                } else {
                                    badgeText = minutes + 'm ' + seconds + 's';
                                }
                                document.getElementById('gw-countdown-badge').textContent = badgeText;
                                
                                // Actualizar texto largo
                                let parts = [];
                                if (days > 0) parts.push(days + ' día' + (days !== 1 ? 's' : ''));
                                if (hours > 0) parts.push(hours + ' hora' + (hours !== 1 ? 's' : ''));
                                if (minutes > 0 || parts.length === 0) parts.push(minutes + ' minuto' + (minutes !== 1 ? 's' : ''));
                                if (days === 0 && hours === 0) parts.push(seconds + ' segundo' + (seconds !== 1 ? 's' : ''));
                                
                                document.getElementById('gw-countdown-text').textContent = parts.join(', ');
                            }
                            
                            // Actualizar inmediatamente
                            updateCountdown();
                            
                            // Actualizar cada segundo
                            setInterval(updateCountdown, 1000);
                        })();
                        </script>

                        <!-- Barra de progreso -->
                        <?php 
                        $days_left = $this->get_days_left();
                        $progress = (($days_left / 30) * 100);
                        $progress = max(0, min(100, $progress));
                        ?>
                        <div style="margin: 25px 0; background: #f0f0f1; height: 8px; border-radius: 10px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);">
                            <div style="width: <?php echo $progress; ?>%; height: 100%; background: linear-gradient(90deg, #ffba00 0%, #f59e0b 100%); border-radius: 10px; transition: width 0.5s ease; box-shadow: 0 0 10px rgba(255,186,0,0.5);"></div>
                        </div>
                        <p style="font-size: 12px; color: #8c8f94; margin: -15px 0 25px 0;">
                            <?php echo round($progress); ?>% del periodo de prueba utilizado
                        </p>

                        <!-- Información de la licencia -->
                        <div style="background: white; border-radius: 12px; padding: 20px; margin: 25px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.05); text-align: left;">
                            <div class="gw-input-group" style="margin-bottom: 18px;">
                                <label class="gw-label" style="display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: #50575e; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;">
                                    <span class="dashicons dashicons-admin-network" style="font-size: 16px;"></span>
                                    Clave de Producto
                                </label>
                                <input type="text" value="<?php echo esc_attr($info['license_key']); ?>" class="gw-input" readonly
                                    style="background: #f7f8f9; color: #3c434a; cursor: not-allowed; text-align: center; font-family: 'Courier New', monospace; letter-spacing: 2px; font-size: 16px; font-weight: 600; border: 2px solid #e5e7eb; border-radius: 8px; padding: 12px;">
                            </div>

                            <div class="gw-input-group">
                                <label class="gw-label" style="display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: #50575e; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;">
                                    <span class="dashicons dashicons-calendar-alt" style="font-size: 16px;"></span>
                                    Expira el
                                </label>
                                <div style="padding: 14px; background: linear-gradient(135deg, #fff8e5 0%, #ffedd5 100%); border: 2px solid #f0c33c; border-radius: 8px; color: #b76e00; font-weight: 700; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 8px;">
                                    <span style="font-size: 20px;">📅</span>
                                    <?php echo date('d/m/Y H:i', strtotime($info['expires_at'])); ?>
                                </div>
                            </div>
                        </div>

                        <!-- Botones con mejor diseño -->
                        <?php if (!empty($info['payment_url'])): ?>
                            <a href="<?php echo esc_url($info['payment_url']); ?>" class="gw-btn-primary gw-btn-pro" target="_blank" 
                               style="display: block; width: 100%; margin-top: 10px; text-decoration: none; padding: 16px 20px; font-size: 15px; background: linear-gradient(135deg, #e01d75 0%, #c91a6a 100%); box-shadow: 0 6px 20px rgba(224,29,117,0.35); border: none; border-radius: 8px; position: relative; overflow: hidden; text-align: center; box-sizing: border-box;">
                                <span style="position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;">
                                    <span style="font-size: 18px;">🚀</span>
                                    <span style="white-space: nowrap;">Actualizar a Licencia PRO</span>
                                </span>
                                <div style="position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent); transition: left 0.5s; pointer-events: none;"></div>
                            </a>
                            <style>
                                .gw-btn-pro:hover div {
                                    left: 100% !important;
                                }
                            </style>
                        <?php endif; ?>

                        <form method="post" style="margin-top: 12px;">
                            <?php wp_nonce_field('gw_license_refresh'); ?>
                            <button type="submit" name="gw_refresh_license" class="gw-btn-refresh-trial" 
                                    style="width: 100%; padding: 14px; border-radius: 10px; border: 2px solid #fbbf24; background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%); color: #b45309; font-weight: 600; transition: all 0.3s; cursor: pointer; box-shadow: 0 2px 8px rgba(251, 191, 36, 0.15);">
                                <span style="display: flex; align-items: center; justify-content: center; gap: 8px;">
                                    <span class="dashicons dashicons-update" style="font-size: 18px;"></span>
                                    <span>Refrescar Estado</span>
                                </span>
                            </button>
                        </form>
                        
                        <style>
                            .gw-btn-refresh-trial:hover {
                                background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%) !important;
                                border-color: #f59e0b !important;
                                transform: translateY(-2px);
                                box-shadow: 0 4px 16px rgba(251, 191, 36, 0.3) !important;
                            }
                            
                            .gw-btn-refresh-trial:active {
                                transform: translateY(0);
                            }
                            
                            .gw-btn-refresh-trial .dashicons {
                                transition: transform 0.6s ease;
                            }
                            
                            .gw-btn-refresh-trial:hover .dashicons {
                                transform: rotate(180deg);
                            }
                        </style>
                    </div>
                </div>
                
                <style>
                    @keyframes pulse {
                        0%, 100% { transform: scale(1); }
                        50% { transform: scale(1.05); }
                    }
                    .gw-btn-secondary:hover {
                        background: #f8f9fa !important;
                        border-color: #6c757d !important;
                        transform: translateY(-2px);
                        box-shadow: 0 4px 12px rgba(108, 117, 125, 0.2);
                    }
                </style>

            <?php else: ?>
                <!-- LICENCIA EXPIRADA/BLOQUEADA/ERROR - DISEÑO LIMPIO Y MODERNO -->
                <div class="gw-blocked-container" style="max-width: 650px; margin: 0 auto; position: relative; overflow: visible;">
                    
                    <!-- Banner principal limpio -->
                    <div class="gw-blocked-banner">
                        <div class="gw-blocked-icon">
                            <div class="icon-circle">
                                <i class="dashicons dashicons-warning" style="font-size: 80px; width: 80px; height: 80px;"></i>
                            </div>
                            <div class="pulse-ring"></div>
                            <div class="pulse-ring" style="animation-delay: 0.5s;"></div>
                        </div>
                        
                        <h1 class="gw-blocked-title">
                            <?php 
                            if ($info['status'] === 'blocked') {
                                echo '🚫 Licencia Suspendida';
                            } elseif ($info['status'] === 'expired') {
                                echo '⏰ Licencia Expirada';
                            } else {
                                echo '❌ Licencia No Válida';
                            }
                            ?>
                        </h1>
                        
                        <div class="gw-blocked-status">
                            <span class="status-badge <?php echo $info['status']; ?>">
                                ESTADO: <?php echo strtoupper($info['status']); ?>
                            </span>
                        </div>

                        <?php 
                        // Limpiar mensaje de errores técnicos
                        $clean_message = $info['message'];
                        if (strpos($clean_message, 'Error de conexión:') !== false || 
                            strpos($clean_message, 'cURL error') !== false) {
                            $clean_message = 'No se pudo verificar el estado de la licencia. Por favor, contacta con soporte.';
                        }
                        ?>
                        <p class="gw-blocked-message">
                            <?php echo esc_html($clean_message); ?>
                        </p>

                        <!-- Línea divisoria con brillo -->
                        <div class="glow-divider"></div>

                        <!-- Acciones principales -->
                        <div class="gw-blocked-actions">
                            <?php if (!empty($info['payment_url'])): ?>
                                <a href="<?php echo esc_url($info['payment_url']); ?>" 
                                   class="gw-btn-brutal gw-btn-primary-brutal" 
                                   target="_blank"
                                   style="box-sizing: border-box; max-width: 100%;">
                                    <span class="btn-icon">💳</span>
                                    <span class="btn-text" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">Obtener Licencia Ahora</span>
                                    <span class="btn-shine"></span>
                                </a>
                                
                                <!-- Botón verificar solo si hay payment_url -->
                                <form method="post" style="width: 100%; margin-top: 15px;">
                                    <?php wp_nonce_field('gw_license_refresh'); ?>
                                    <button type="submit" 
                                            name="gw_refresh_license" 
                                            class="gw-btn-refresh-blocked"
                                            style="width: 100%; box-sizing: border-box; padding: 16px 28px; border: 2px solid #e5e7eb; background: white; color: #6b7280; font-weight: 600; border-radius: 10px; cursor: pointer; transition: all 0.3s ease; display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);">
                                        <span style="display: flex; align-items: center; gap: 8px; font-size: 15px;">
                                            <span class="dashicons dashicons-update" style="font-size: 20px; width: 20px; height: 20px;"></span>
                                            <span>Refrescar Estado</span>
                                        </span>
                                        <span style="font-size: 11px; font-weight: 400; opacity: 0.6;">Útil después de realizar un pago</span>
                                    </button>
                                </form>
                                
                                <style>
                                    .gw-btn-refresh-blocked:hover {
                                        background: #f9fafb !important;
                                        border-color: #d1d5db !important;
                                        transform: translateY(-2px);
                                        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
                                    }
                                    
                                    .gw-btn-refresh-blocked:active {
                                        transform: translateY(0);
                                        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
                                    }
                                    
                                    .gw-btn-refresh-blocked .dashicons {
                                        transition: transform 0.6s ease;
                                    }
                                    
                                    .gw-btn-refresh-blocked:hover .dashicons {
                                        transform: rotate(180deg);
                                    }
                                </style>
                            <?php else: ?>
                                <!-- Si no hay payment_url, solo mostrar mensaje de contacto -->
                                <div style="background: rgba(224, 29, 117, 0.1); border: 2px solid rgba(224, 29, 117, 0.3); border-radius: 12px; padding: 20px; text-align: center;">
                                    <p style="color: #e0e0e0; margin: 0 0 10px 0;">
                                        <strong>¿Necesitas ayuda?</strong>
                                    </p>
                                    <p style="color: #9ca3af; margin: 0; font-size: 14px;">
                                        Contacta con nuestro equipo de soporte para resolver este problema.
                                    </p>
                                </div>
                            <?php endif; ?>
                        </div>

                        <!-- Información adicional -->
                        <div class="gw-blocked-info">
                            <div class="info-item">
                                <span class="dashicons dashicons-shield-alt"></span>
                                <span>Tus datos están seguros</span>
                            </div>
                            <div class="info-item">
                                <span class="dashicons dashicons-admin-network"></span>
                                <span>Reactiva en segundos</span>
                            </div>
                            <div class="info-item">
                                <span class="dashicons dashicons-yes-alt"></span>
                                <span>Soporte 24/7</span>
                            </div>
                        </div>
                    </div>

                    <!-- Estilos específicos para el diseño limpio y moderno -->
                    <style>
                        .gw-blocked-container {
                            background: linear-gradient(135deg, #ffffff 0%, #fef2f2 100%);
                            border-radius: 16px;
                            padding: 45px 35px;
                            box-shadow: 
                                0 10px 40px rgba(220, 38, 38, 0.12),
                                0 0 0 1px rgba(220, 38, 38, 0.08);
                            position: relative;
                            overflow: hidden;
                        }

                        .gw-blocked-container::before {
                            content: '';
                            position: absolute;
                            top: 0;
                            left: 0;
                            right: 0;
                            height: 4px;
                            background: linear-gradient(90deg, #dc2626 0%, #ef4444 50%, #dc2626 100%);
                            background-size: 200% 100%;
                            animation: shimmer 3s linear infinite;
                        }

                        @keyframes shimmer {
                            0% { background-position: -200% 0; }
                            100% { background-position: 200% 0; }
                        }

                        .gw-blocked-banner {
                            position: relative;
                            z-index: 1;
                            text-align: center;
                        }

                        /* Icono limpio y moderno */
                        .gw-blocked-icon {
                            position: relative;
                            display: inline-block;
                            margin-bottom: 25px;
                        }

                        .icon-circle {
                            width: 120px;
                            height: 120px;
                            background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
                            border-radius: 50%;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            box-shadow: 
                                0 8px 24px rgba(220, 38, 38, 0.15),
                                inset 0 1px 0 rgba(255, 255, 255, 0.8);
                            animation: gentlePulse 3s ease-in-out infinite;
                            position: relative;
                            z-index: 2;
                            border: 3px solid rgba(220, 38, 38, 0.15);
                        }

                        .icon-circle .dashicons {
                            color: #dc2626;
                            filter: drop-shadow(0 2px 4px rgba(220, 38, 38, 0.2));
                        }

                        @keyframes gentlePulse {
                            0%, 100% { 
                                transform: scale(1);
                                box-shadow: 0 8px 24px rgba(220, 38, 38, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.8);
                            }
                            50% { 
                                transform: scale(1.02);
                                box-shadow: 0 12px 32px rgba(220, 38, 38, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.8);
                            }
                        }

                        .pulse-ring {
                            position: absolute;
                            top: 50%;
                            left: 50%;
                            transform: translate(-50%, -50%);
                            width: 120px;
                            height: 120px;
                            border: 2px solid rgba(220, 38, 38, 0.2);
                            border-radius: 50%;
                            animation: ringPulse 3s ease-out infinite;
                        }

                        @keyframes ringPulse {
                            0% {
                                width: 120px;
                                height: 120px;
                                opacity: 0.6;
                            }
                            100% {
                                width: 180px;
                                height: 180px;
                                opacity: 0;
                            }
                        }

                        /* Título limpio */
                        .gw-blocked-title {
                            font-size: 30px;
                            font-weight: 700;
                            color: #1f2937;
                            margin: 0 0 18px 0;
                            line-height: 1.2;
                        }

                        /* Badge de estado limpio */
                        .gw-blocked-status {
                            margin: 18px 0 25px 0;
                        }

                        .status-badge {
                            display: inline-block;
                            padding: 8px 20px;
                            background: white;
                            border: 2px solid #fecaca;
                            border-radius: 20px;
                            color: #dc2626;
                            font-weight: 600;
                            font-size: 13px;
                            letter-spacing: 1px;
                            text-transform: uppercase;
                            box-shadow: 0 2px 8px rgba(220, 38, 38, 0.08);
                        }

                        .status-badge.blocked {
                            border-color: #fecaca;
                            background: #fef2f2;
                        }

                        .status-badge.expired {
                            border-color: #fed7aa;
                            background: #fffbeb;
                            color: #ea580c;
                        }

                        .status-badge.error {
                            border-color: #fca5a5;
                            background: #fef2f2;
                            color: #b91c1c;
                        }

                        /* Mensaje limpio */
                        .gw-blocked-message {
                            color: #6b7280;
                            font-size: 15px;
                            line-height: 1.6;
                            margin: 20px 0 30px 0;
                            padding: 0 20px;
                        }

                        /* Línea divisoria limpia */
                        .glow-divider {
                            height: 1px;
                            background: linear-gradient(90deg, 
                                transparent 0%, 
                                #fecaca 50%, 
                                transparent 100%);
                            margin: 30px 0;
                        }

                        /* Botones limpios y modernos */
                        .gw-blocked-actions {
                            margin: 25px 0;
                            width: 100%;
                        }

                        .gw-btn-brutal {
                            width: 100%;
                            max-width: 100%;
                            padding: 16px 28px;
                            border: none;
                            border-radius: 10px;
                            font-size: 15px;
                            font-weight: 600;
                            cursor: pointer;
                            position: relative;
                            overflow: hidden;
                            transition: all 0.3s ease;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            gap: 10px;
                            text-decoration: none;
                            color: white;
                            box-sizing: border-box;
                        }

                        .gw-btn-primary-brutal {
                            background: linear-gradient(135deg, #e01d75 0%, #d91968 100%);
                            box-shadow: 0 4px 14px rgba(224, 29, 117, 0.25);
                            border: 1px solid rgba(224, 29, 117, 0.3);
                        }

                        .gw-btn-primary-brutal:hover {
                            transform: translateY(-2px);
                            box-shadow: 0 6px 20px rgba(224, 29, 117, 0.35);
                            background: linear-gradient(135deg, #c91a6a 0%, #b91860 100%);
                        }

                        .gw-btn-secondary-brutal {
                            background: white;
                            border: 2px solid #e5e7eb;
                            color: #6b7280;
                            flex-direction: column;
                            gap: 4px;
                            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
                        }

                        .gw-btn-secondary-brutal:hover {
                            background: #f9fafb;
                            border-color: #d1d5db;
                            transform: translateY(-2px);
                            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
                        }

                        .btn-icon {
                            font-size: 20px;
                        }

                        .btn-text {
                            position: relative;
                            z-index: 1;
                        }

                        .btn-subtitle {
                            font-size: 11px;
                            font-weight: 400;
                            opacity: 0.6;
                        }

                        .btn-shine {
                            position: absolute;
                            top: 0;
                            left: -100%;
                            width: 100%;
                            height: 100%;
                            background: linear-gradient(90deg, 
                                transparent, 
                                rgba(255, 255, 255, 0.25), 
                                transparent);
                            transition: left 0.6s ease;
                        }

                        .gw-btn-brutal:hover .btn-shine {
                            left: 100%;
                        }

                        /* Información adicional limpia */
                        .gw-blocked-info {
                            margin-top: 35px;
                            padding-top: 30px;
                            border-top: 1px solid #f3f4f6;
                            display: flex;
                            justify-content: center;
                            gap: 30px;
                            flex-wrap: wrap;
                        }

                        .info-item {
                            display: flex;
                            align-items: center;
                            gap: 8px;
                            color: #9ca3af;
                            font-size: 13px;
                            font-weight: 500;
                        }

                        .info-item .dashicons {
                            color: #e01d75;
                            font-size: 18px;
                            width: 18px;
                            height: 18px;
                        }

                        /* Responsive */
                        @media (max-width: 768px) {
                            .gw-blocked-container {
                                padding: 35px 25px;
                            }

                            .gw-blocked-title {
                                font-size: 26px;
                            }

                            .icon-circle {
                                width: 100px;
                                height: 100px;
                            }

                            .icon-circle .dashicons {
                                font-size: 70px;
                                width: 70px;
                                height: 70px;
                            }

                            .gw-blocked-info {
                                flex-direction: column;
                                align-items: center;
                                gap: 15px;
                            }

                            .gw-btn-brutal {
                                padding: 14px 24px;
                                font-size: 14px;
                            }
                        }
                    </style>
                </div>

            <?php endif; ?>

        </div>

        <?php
        // Manejar refresh manual
        if (isset($_POST['gw_refresh_license']) && check_admin_referer('gw_license_refresh')) {
            $this->force_refresh();
            echo '<script>window.location.reload();</script>';
        }
    }
}
