<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Encuesta Tecnológica - Descarga eBooks Gratis</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f9f9f9;
        }
        header {
            text-align: center;
            padding: 30px 0;
            background: linear-gradient(135deg, #3498db, #2c3e50);
            color: white;
            border-radius: 10px;
            margin-bottom: 30px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        h1 {
            margin: 0;
            font-size: 2.2em;
        }
        h2 {
            color: #3498db;
            border-bottom: 2px solid #3498db;
            padding-bottom: 5px;
            margin-top: 0;
        }
        .ebook-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            gap: 25px;
            margin-bottom: 40px;
        }
        .ebook {
            flex: 1;
            min-width: 300px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            padding: 20px;
            transition: transform 0.3s, box-shadow 0.3s;
        }
        .ebook:hover {
            transform: translateY(-5px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.15);
        }
        .ebook img {
            width: 100%;
            height: 200px;
            object-fit: cover;
            border-radius: 5px;
            border: 1px solid #eee;
        }
        .price {
            font-size: 24px;
            font-weight: bold;
            color: #e74c3c;
            margin: 15px 0;
        }
        .cta-button {
            display: inline-block;
            background: #3498db;
            color: white;
            padding: 12px 25px;
            text-decoration: none;
            border-radius: 5px;
            font-weight: bold;
            margin-top: 15px;
            transition: all 0.3s;
            border: none;
            cursor: pointer;
            font-size: 16px;
            width: 100%;
            text-align: center;
        }
        .cta-button:hover {
            background: #2980b9;
            transform: translateY(-2px);
        }
        footer {
            text-align: center;
            margin-top: 50px;
            padding: 20px;
            background: #2c3e50;
            color: white;
            border-radius: 10px;
        }
        /* Estilos para el modal */
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0,0,0,0.7);
        }
        .modal-content {
            background-color: #fefefe;
            margin: 8% auto;
            padding: 25px;
            border-radius: 10px;
            width: 85%;
            max-width: 600px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.3);
            animation: modalopen 0.4s;
        }
        @keyframes modalopen {
            from {opacity: 0; transform: translateY(-50px);}
            to {opacity: 1; transform: translateY(0);}
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
            transition: color 0.3s;
        }
        .close:hover {
            color: #333;
        }
        .survey-question {
            margin-bottom: 25px;
        }
        .survey-question label {
            display: block;
            margin-bottom: 10px;
            font-weight: bold;
            color: #2c3e50;
        }
        .survey-question input[type="text"],
        .survey-question input[type="email"],
        .survey-question select,
        .survey-question textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-sizing: border-box;
            font-size: 16px;
            transition: border 0.3s;
        }
        .survey-question input:focus,
        .survey-question select:focus,
        .survey-question textarea:focus {
            border-color: #3498db;
            outline: none;
            box-shadow: 0 0 5px rgba(52,152,219,0.3);
        }
        .survey-question input[type="radio"],
        .survey-question input[type="checkbox"] {
            margin-right: 10px;
            transform: scale(1.2);
        }
        .survey-options {
            margin-left: 5px;
        }
        .survey-options label {
            display: block;
            margin-bottom: 10px;
            font-weight: normal;
            cursor: pointer;
        }
        .download-link {
            display: none;
            margin-top: 30px;
            text-align: center;
            padding: 20px;
            background: #f0f8ff;
            border-radius: 8px;
        }
        .error-message {
            color: #e74c3c;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
        .required-field::after {
            content: " *";
            color: #e74c3c;
        }
    </style>
</head>
<body>
    <header>
        <h1>Descarga Nuestros eBooks Exclusivos sobre Tecnología</h1>
        <p>Completa nuestra breve encuesta tecnológica para acceder a los eBooks</p>
    </header>

    <div class="ebook-container">
        <div class="ebook">
            <img src="https://images.unsplash.com/photo-1620712943543-bcc4688e7485?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1000&q=80" alt="Inteligencia Artificial">
            <h2>Inteligencia Artificial para Principiantes</h2>
            <p>Aprende los conceptos básicos de IA, machine learning y cómo estas tecnologías están transformando el mundo.</p>
            <div class="price">GRATIS</div>
            <button class="cta-button open-survey" data-ebook="ia">Descargar eBook</button>
        </div>

        <div class="ebook">
            <img src="https://images.unsplash.com/photo-1620712943543-bcc4688e7485?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1000&q=80" alt="Ciberseguridad">
            <h2>Ciberseguridad en la Era Digital</h2>
            <p>Protege tus datos y privacidad con las mejores prácticas de seguridad digital actualizadas.</p>
            <div class="price">GRATIS</div>
            <button class="cta-button open-survey" data-ebook="seguridad">Descargar eBook</button>
        </div>

        <div class="ebook">
            <img src="https://images.unsplash.com/photo-1639762681057-408e52192e55?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1000&q=80" alt="Metaverso">
            <h2>El Metaverso: Guía Completa</h2>
            <p>Explora las oportunidades y tecnologías detrás de esta nueva frontera digital.</p>
            <div class="price">GRATIS</div>
            <button class="cta-button open-survey" data-ebook="metaverso">Descargar eBook</button>
        </div>
    </div>

    <!-- Modal de Encuesta - CONEXIÓN A TU GOOGLE FORM -->
    <div id="surveyModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <h2>Encuesta Tecnológica Básica</h2>
            <p>Por favor, responde estas breves preguntas para descargar el eBook. Todos los campos son obligatorios.</p>
            
            <!-- FORMULARIO CON TUS IDs REALES -->
            <form id="techSurvey" 
                  action="https://docs.google.com/forms/d/e/1FAIpQLSfE8nuIDhQyAFtfagn2glnqxjNQWJi3h0vizSc4Y6BCk_NYhQ/formResponse" 
                  method="POST" 
                  target="_blank">
                
                <!-- Campo oculto para identificar el eBook seleccionado -->
                <input type="hidden" name="entry.123456789" id="ebook-type" value="">
                
                <!-- Pregunta 1: Email -->
                <div class="survey-question">
                    <label for="email" class="required-field">Dirección de correo electrónico:</label>
                    <input type="email" 
                           id="email" 
                           name="entry.2140443410" 
                           required
                           placeholder="tucorreo@ejemplo.com">
                    <div class="error-message" id="email-error">Por favor ingresa un correo válido</div>
                </div>
                
                <!-- Pregunta 2: Nivel de conocimiento -->
                <div class="survey-question">
                    <label class="required-field">¿Cómo calificarías tu conocimiento sobre tecnología?</label>
                    <div class="survey-options">
                        <label>
                            <input type="radio" 
                                   name="entry.2136942447" 
                                   value="Principiante" 
                                   required>
                            Principiante
                        </label>
                        <label>
                            <input type="radio" 
                                   name="entry.2136942447" 
                                   value="Intermedio">
                            Intermedio
                        </label>
                        <label>
                            <input type="radio" 
                                   name="entry.2136942447" 
                                   value="Avanzado">
                            Avanzado
                        </label>
                    </div>
                </div>
                
                <!-- Pregunta 3: Dispositivo principal -->
                <div class="survey-question">
                    <label for="device" class="required-field">¿Qué dispositivo usas principalmente?</label>
                    <select id="device" 
                            name="entry.1091381290" 
                            required>
                        <option value="">-- Selecciona una opción --</option>
                        <option value="Smartphone">Smartphone</option>
                        <option value="Laptop">Laptop</option>
                        <option value="Tablet">Tablet</option>
                        <option value="PC de escritorio">PC de escritorio</option>
                        <option value="Otro">Otro</option>
                    </select>
                </div>
                
                <!-- Pregunta 4: Áreas de interés -->
                <div class="survey-question">
                    <label class="required-field">¿Qué área tecnológica te interesa más? (Marca todas las que apliquen)</label>
                    <div class="survey-options">
                        <label>
                            <input type="checkbox" 
                                   name="entry.1863668956" 
                                   value="Inteligencia Artificial">
                            Inteligencia Artificial
                        </label>
                        <label>
                            <input type="checkbox" 
                                   name="entry.1863668956" 
                                   value="Ciberseguridad">
                            Ciberseguridad
                        </label>
                        <label>
                            <input type="checkbox" 
                                   name="entry.1863668956" 
                                   value="Realidad Virtual">
                            Realidad Virtual/Metaverso
                        </label>
                        <label>
                            <input type="checkbox" 
                                   name="entry.1863668956" 
                                   value="Programación">
                            Programación
                        </label>
                        <label>
                            <input type="checkbox" 
                                   name="entry.1863668956" 
                                   value="Análisis de datos">
                            Análisis de datos
                        </label>
                    </div>
                </div>
                
                <!-- Pregunta 5: Expectativas -->
                <div class="survey-question">
                    <label for="comments">¿Qué esperas aprender con este eBook?</label>
                    <textarea id="comments" 
                              name="entry.2058033166" 
                              rows="4"
                              placeholder="Escribe tus expectativas..."></textarea>
                </div>
                
                <button type="submit" class="cta-button">Enviar encuesta</button>
            </form>
            
            <!-- Sección de descarga (aparece después de enviar) -->
            <div id="downloadSection" class="download-link">
                <h3>¡Gracias por completar la encuesta!</h3>
                <p>Aquí está tu enlace de descarga directa:</p>
                <a id="downloadLink" href="#" class="cta-button" style="background: #2ecc71; display: inline-block; width: auto; padding: 12px 30px;">Descargar eBook</a>
                <p style="margin-top: 15px;">También hemos enviado una copia a tu correo electrónico.</p>
            </div>
        </div>
    </div>

    <footer>
        <p>© 2023 eBooks Tecnológicos. Todos los derechos reservados.</p>
        <p><a href="mailto:contacto@ebookstecnologicos.com" style="color: #3498db;">contacto@ebookstecnologicos.com</a></p>
    </footer>

    <script>
        // Variables globales
        let selectedEbook = '';
        
        // Elementos del DOM
        const openSurveyButtons = document.querySelectorAll('.open-survey');
        const modal = document.getElementById('surveyModal');
        const closeButton = document.querySelector('.close');
        const surveyForm = document.getElementById('techSurvey');
        const downloadSection = document.getElementById('downloadSection');
        const downloadLink = document.getElementById('downloadLink');
        const emailInput = document.getElementById('email');
        const emailError = document.getElementById('email-error');
        
        // Abrir modal de encuesta
        openSurveyButtons.forEach(button => {
            button.addEventListener('click', function() {
                selectedEbook = this.getAttribute('data-ebook');
                modal.style.display = 'block';
                surveyForm.style.display = 'block';
                downloadSection.style.display = 'none';
                surveyForm.reset();
                
                // Establecer el tipo de eBook en el campo oculto
                document.getElementById('ebook-type').value = selectedEbook;
            });
        });
        
        // Cerrar modal
        closeButton.addEventListener('click', function() {
            modal.style.display = 'none';
        });
        
        // Cerrar al hacer clic fuera del modal
        window.addEventListener('click', function(event) {
            if (event.target == modal) {
                modal.style.display = 'none';
            }
        });
        
        // Validar email en tiempo real
        emailInput.addEventListener('input', function() {
            if (!this.value.includes('@') || !this.value.includes('.')) {
                emailError.style.display = 'block';
            } else {
                emailError.style.display = 'none';
            }
        });
        
        // Enviar formulario
        surveyForm.addEventListener('submit', function(e) {
            e.preventDefault();
            
            // Validación final del email
            if (!emailInput.value || !emailInput.value.includes('@') || !emailInput.value.includes('.')) {
                emailError.style.display = 'block';
                emailInput.focus();
                return false;
            }
            
            // Validar que al menos un checkbox esté marcado
            const checkboxes = document.querySelectorAll('input[name="entry.1863668956"]:checked');
            if (checkboxes.length === 0) {
                alert('Por favor selecciona al menos un área de interés');
                return false;
            }
            
            // Mostrar carga (opcional)
            const submitButton = this.querySelector('button[type="submit"]');
            submitButton.disabled = true;
            submitButton.innerHTML = 'Enviando... <i class="fa fa-spinner fa-spin"></i>';
            
            // Enviar el formulario a Google Forms
            setTimeout(() => {
                this.submit();
                
                // Mostrar enlace de descarga
                surveyForm.style.display = 'none';
                downloadSection.style.display = 'block';
                
                // Configurar el enlace de descarga según el eBook
                switch(selectedEbook) {
                    case 'ia':
                        downloadLink.href = 'IA_Para_Principiantes.pdf';
                        downloadLink.textContent = 'Descargar "Inteligencia Artificial para Principiantes"';
                        break;
                    case 'seguridad':
                        downloadLink.href = 'Ciberseguridad_Era_Digital.pdf';
                        downloadLink.textContent = 'Descargar "Ciberseguridad en la Era Digital"';
                        break;
                    case 'metaverso':
                        downloadLink.href = 'Metaverso_Guia_Completa.pdf';
                        downloadLink.textContent = 'Descargar "El Metaverso: Guía Completa"';
                        break;
                }
                
                // Restaurar botón
                submitButton.disabled = false;
                submitButton.innerHTML = 'Enviar encuesta';
            }, 1000);
            
            return false;
        });
    </script>
</body>
</html>