<script setup>
import AdminLayout from '@/Layouts/AdminLayout.vue';
import { Head, router, useForm } from '@inertiajs/vue3';
import { ref, computed, watch, onMounted } from 'vue';

const props = defineProps({
    settings: Object,
    features: Array,
    testimonials: Array,
    pendingTestimonialsCount: Number,
    stats: Array,
    socialLinks: Array,
    plans: Array,
    availableIcons: Object,
    platformOptions: Array,
});

// Active tab - check URL params
const activeTab = ref('hero');
const tabs = [
    { id: 'hero', name: 'Hero', icon: '🏠' },
    { id: 'features', name: 'Características', icon: '✨' },
    { id: 'stats', name: 'Estadísticas', icon: '📊' },
    { id: 'plans', name: 'Planes', icon: '💳' },
    { id: 'testimonials', name: 'Testimonios', icon: '💬', badge: props.pendingTestimonialsCount },
    { id: 'blog', name: 'Blog', icon: '📝' },
    { id: 'cta', name: 'CTA Final', icon: '🚀' },
    { id: 'social', name: 'Redes Sociales', icon: '🔗' },
    { id: 'footer', name: 'Footer', icon: '📄' },
    { id: 'colors', name: 'Colores', icon: '🎨' },
    { id: 'general', name: 'General', icon: '⚙️' },
];

// Check URL for tab parameter
onMounted(() => {
    const urlParams = new URLSearchParams(window.location.search);
    const tabParam = urlParams.get('tab');
    if (tabParam && tabs.some(t => t.id === tabParam)) {
        activeTab.value = tabParam;
    }
});

// Testimonial filter
const testimonialFilter = ref('all');

// Filtered testimonials
const filteredTestimonials = computed(() => {
    if (testimonialFilter.value === 'all') return props.testimonials;
    if (testimonialFilter.value === 'pending') return props.testimonials.filter(t => t.status === 'pending');
    if (testimonialFilter.value === 'approved') return props.testimonials.filter(t => t.status === 'approved');
    if (testimonialFilter.value === 'rejected') return props.testimonials.filter(t => t.status === 'rejected');
    if (testimonialFilter.value === 'coach') return props.testimonials.filter(t => t.source === 'coach');
    if (testimonialFilter.value === 'admin') return props.testimonials.filter(t => t.source === 'admin' || !t.source);
    return props.testimonials;
});

// Reject modal
const showRejectModal = ref(false);
const rejectingTestimonial = ref(null);
const rejectReason = ref('');

const openRejectModal = (testimonial) => {
    rejectingTestimonial.value = testimonial;
    rejectReason.value = '';
    showRejectModal.value = true;
};

const approveTestimonial = (testimonial) => {
    if (confirm('¿Aprobar y publicar este testimonio?')) {
        router.post(route('admin.landing.testimonials.approve', testimonial.id), {}, {
            preserveScroll: true,
        });
    }
};

const rejectTestimonial = () => {
    router.post(route('admin.landing.testimonials.reject', rejectingTestimonial.value.id), {
        rejection_reason: rejectReason.value,
    }, {
        preserveScroll: true,
        onSuccess: () => {
            showRejectModal.value = false;
            rejectingTestimonial.value = null;
            rejectReason.value = '';
        },
    });
};

// Forms for each section
const heroForm = useForm({ ...props.settings.hero });
const benefitsForm = useForm({ ...props.settings.benefits });
const plansSectionForm = useForm({ ...props.settings.plans_section });
const testimonialsSectionForm = useForm({ ...props.settings.testimonials_section });
const blogSectionForm = useForm({ ...props.settings.blog_section });
const ctaSectionForm = useForm({ ...props.settings.cta_section });
const footerForm = useForm({ ...props.settings.footer });
const colorsForm = useForm({ ...props.settings.colors });
const generalForm = useForm({ ...props.settings.general });

// Modal states
const showFeatureModal = ref(false);
const showTestimonialModal = ref(false);
const showStatModal = ref(false);
const showSocialModal = ref(false);
const editingItem = ref(null);

// Emoji mapping for icons
const iconEmojis = {
    'users': '👥',
    'chart-bar': '📊',
    'calendar': '📅',
    'clipboard': '📋',
    'heart': '❤️',
    'lightning-bolt': '⚡',
    'star': '⭐',
    'shield-check': '🛡️',
    'device-mobile': '📱',
    'globe': '🌍',
    'currency-dollar': '💵',
    'clock': '🕐',
    'chat': '💬',
    'document': '📄',
    'photograph': '📷',
    'video-camera': '🎥',
    'music-note': '🎵',
    'fire': '🔥',
    'sparkles': '✨',
    'trophy': '🏆',
    'academic-cap': '🎓',
    'beaker': '🧪',
    'briefcase': '💼',
    'cake': '🎂',
    'chip': '💾',
    'cube': '📦',
    'database': '🗄️',
    'desktop-computer': '🖥️',
    'emoji-happy': '😊',
    'finger-print': '👆',
    'gift': '🎁',
    'hand': '✋',
    'home': '🏠',
    'key': '🔑',
    'light-bulb': '💡',
    'location-marker': '📍',
    'lock-closed': '🔒',
    'mail': '📧',
    'map': '🗺️',
    'microphone': '🎤',
    'moon': '🌙',
    'newspaper': '📰',
    'paper-airplane': '✈️',
    'pencil': '✏️',
    'phone': '📞',
    'play': '▶️',
    'puzzle': '🧩',
    'qrcode': '📲',
    'receipt-tax': '🧾',
    'refresh': '🔄',
    'save': '💾',
};

const getIconEmoji = (icon) => {
    return iconEmojis[icon] || '✨';
};

// Avatar preview for testimonial
const testimonialAvatarPreview = ref(null);
const testimonialAvatarFile = ref(null);

// Item forms
const featureForm = useForm({
    icon: 'star',
    title: '',
    description: '',
    is_active: true,
});

const testimonialForm = useForm({
    name: '',
    role: '',
    content: '',
    avatar: '',
    rating: 5,
    is_active: true,
});

const statForm = useForm({
    label: '',
    value: '',
    icon: 'users',
    is_active: true,
});

const socialForm = useForm({
    platform: 'instagram',
    url: '',
    is_active: true,
});

// Handle avatar upload for testimonial
const handleTestimonialAvatarChange = async (event) => {
    const file = event.target.files[0];
    if (!file) return;
    
    // Validate
    if (file.size > 2 * 1024 * 1024) {
        alert('La imagen no puede superar 2MB');
        return;
    }
    if (!['image/jpeg', 'image/png', 'image/jpg'].includes(file.type)) {
        alert('Solo se permiten imágenes JPG o PNG');
        return;
    }
    
    testimonialAvatarFile.value = file;
    testimonialAvatarPreview.value = URL.createObjectURL(file);
    
    // Upload immediately
    const formData = new FormData();
    formData.append('image', file);
    formData.append('type', 'testimonial');
    
    try {
        const response = await fetch(route('admin.landing.upload-image'), {
            method: 'POST',
            headers: {
                'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
            },
            body: formData,
        });
        const data = await response.json();
        testimonialForm.avatar = data.url;
    } catch (error) {
    }
};

// Save settings
const saveSection = (section, form) => {
    router.post(route('admin.landing.settings.update'), {
        section: section,
        settings: form.data(),
    }, {
        preserveScroll: true,
        onSuccess: () => {
            // Show success
        },
    });
};

// Feature CRUD
const openFeatureModal = (feature = null) => {
    editingItem.value = feature;
    if (feature) {
        featureForm.icon = feature.icon;
        featureForm.title = feature.title;
        featureForm.description = feature.description;
        featureForm.is_active = feature.is_active;
    } else {
        featureForm.reset();
        featureForm.icon = 'star';
        featureForm.is_active = true;
    }
    showFeatureModal.value = true;
};

const saveFeature = () => {
    if (editingItem.value) {
        featureForm.put(route('admin.landing.features.update', editingItem.value.id), {
            preserveScroll: true,
            onSuccess: () => {
                showFeatureModal.value = false;
                editingItem.value = null;
            },
        });
    } else {
        featureForm.post(route('admin.landing.features.store'), {
            preserveScroll: true,
            onSuccess: () => {
                showFeatureModal.value = false;
                featureForm.reset();
            },
        });
    }
};

const deleteFeature = (feature) => {
    if (confirm('¿Eliminar esta característica?')) {
        router.delete(route('admin.landing.features.destroy', feature.id), {
            preserveScroll: true,
        });
    }
};

// Testimonial CRUD
const openTestimonialModal = (testimonial = null) => {
    editingItem.value = testimonial;
    if (testimonial) {
        testimonialForm.name = testimonial.name;
        testimonialForm.role = testimonial.role;
        testimonialForm.content = testimonial.content;
        testimonialForm.avatar = testimonial.avatar;
        testimonialForm.rating = testimonial.rating;
        testimonialForm.is_active = testimonial.is_active;
    } else {
        testimonialForm.reset();
        testimonialForm.rating = 5;
        testimonialForm.is_active = true;
    }
    showTestimonialModal.value = true;
};

const saveTestimonial = () => {
    if (editingItem.value) {
        testimonialForm.put(route('admin.landing.testimonials.update', editingItem.value.id), {
            preserveScroll: true,
            onSuccess: () => {
                showTestimonialModal.value = false;
                editingItem.value = null;
            },
        });
    } else {
        testimonialForm.post(route('admin.landing.testimonials.store'), {
            preserveScroll: true,
            onSuccess: () => {
                showTestimonialModal.value = false;
                testimonialForm.reset();
            },
        });
    }
};

const deleteTestimonial = (testimonial) => {
    if (confirm('¿Eliminar este testimonio?')) {
        router.delete(route('admin.landing.testimonials.destroy', testimonial.id), {
            preserveScroll: true,
        });
    }
};

// Stat CRUD
const openStatModal = (stat = null) => {
    editingItem.value = stat;
    if (stat) {
        statForm.label = stat.label;
        statForm.value = stat.value;
        statForm.icon = stat.icon;
        statForm.is_active = stat.is_active;
    } else {
        statForm.reset();
        statForm.icon = 'users';
        statForm.is_active = true;
    }
    showStatModal.value = true;
};

const saveStat = () => {
    if (editingItem.value) {
        statForm.put(route('admin.landing.stats.update', editingItem.value.id), {
            preserveScroll: true,
            onSuccess: () => {
                showStatModal.value = false;
                editingItem.value = null;
            },
        });
    } else {
        statForm.post(route('admin.landing.stats.store'), {
            preserveScroll: true,
            onSuccess: () => {
                showStatModal.value = false;
                statForm.reset();
            },
        });
    }
};

const deleteStat = (stat) => {
    if (confirm('¿Eliminar esta estadística?')) {
        router.delete(route('admin.landing.stats.destroy', stat.id), {
            preserveScroll: true,
        });
    }
};

// Social CRUD
const openSocialModal = (link = null) => {
    editingItem.value = link;
    if (link) {
        socialForm.platform = link.platform;
        socialForm.url = link.url;
        socialForm.is_active = link.is_active;
    } else {
        socialForm.reset();
        socialForm.platform = 'instagram';
        socialForm.is_active = true;
    }
    showSocialModal.value = true;
};

const saveSocial = () => {
    if (editingItem.value) {
        socialForm.put(route('admin.landing.social-links.update', editingItem.value.id), {
            preserveScroll: true,
            onSuccess: () => {
                showSocialModal.value = false;
                editingItem.value = null;
            },
        });
    } else {
        socialForm.post(route('admin.landing.social-links.store'), {
            preserveScroll: true,
            onSuccess: () => {
                showSocialModal.value = false;
                socialForm.reset();
            },
        });
    }
};

const deleteSocial = (link) => {
    if (confirm('¿Eliminar esta red social?')) {
        router.delete(route('admin.landing.social-links.destroy', link.id), {
            preserveScroll: true,
        });
    }
};

// Image upload
const uploadImage = async (event, type, form, field) => {
    const file = event.target.files[0];
    if (!file) return;

    const formData = new FormData();
    formData.append('image', file);
    formData.append('type', type);

    try {
        const response = await fetch(route('admin.landing.upload-image'), {
            method: 'POST',
            headers: {
                'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
            },
            body: formData,
        });
        const data = await response.json();
        form[field] = data.url;
    } catch (error) {
    }
};

// Preview
const openPreview = () => {
    window.open(route('admin.landing.preview'), '_blank');
};

// Platform labels
const platformLabels = {
    facebook: 'Facebook',
    instagram: 'Instagram',
    twitter: 'X (Twitter)',
    youtube: 'YouTube',
    tiktok: 'TikTok',
    linkedin: 'LinkedIn',
};
</script>

<template>
    <Head title="Editor Landing Page" />

    <AdminLayout>
        <template #header>
            <div class="flex flex-col sm:flex-row sm:justify-between sm:items-center gap-4">
                <div>
                    <h2 class="text-2xl font-bold text-gray-900 dark:text-white flex items-center gap-2">
                        <span class="text-3xl">🎨</span>
                        Editor Landing Page
                    </h2>
                    <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">Personaliza tu página de inicio</p>
                </div>
                <div class="flex gap-3">
                    <a :href="route('admin.landing.preview')" target="_blank"
                       class="inline-flex items-center gap-2 px-4 py-2.5 bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-200 rounded-xl text-sm font-medium hover:bg-gray-200 dark:hover:bg-gray-600 transition">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
                        </svg>
                        Vista Previa
                    </a>
                    <a href="/" target="_blank"
                       class="inline-flex items-center gap-2 px-4 py-2.5 bg-blue-600 text-white rounded-xl text-sm font-medium hover:bg-blue-700 transition">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
                        </svg>
                        Ver Landing
                    </a>
                </div>
            </div>
        </template>

        <div class="py-6">
            <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
                <div class="flex flex-col lg:flex-row gap-6">
                    <!-- Tabs Sidebar -->
                    <div class="lg:w-64 flex-shrink-0">
                        <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 overflow-hidden sticky top-6">
                            <div class="p-4 border-b border-gray-100 dark:border-gray-700">
                                <h3 class="font-semibold text-gray-900 dark:text-white">Secciones</h3>
                            </div>
                            <nav class="p-2">
                                <button 
                                    v-for="tab in tabs" 
                                    :key="tab.id"
                                    @click="activeTab = tab.id"
                                    :class="[
                                        'w-full flex items-center gap-3 px-4 py-3 rounded-xl text-left text-sm font-medium transition-all',
                                        activeTab === tab.id
                                            ? 'bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300'
                                            : 'text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700/50'
                                    ]"
                                >
                                    <span class="text-lg">{{ tab.icon }}</span>
                                    {{ tab.name }}
                                </button>
                            </nav>
                        </div>
                    </div>

                    <!-- Content Area -->
                    <div class="flex-1">
                        <!-- Hero Section -->
                        <div v-show="activeTab === 'hero'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
                                <span>🏠</span> Sección Hero
                            </h3>
                            
                            <div class="space-y-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Título Principal</label>
                                    <input v-model="heroForm.title" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Subtítulo</label>
                                    <textarea v-model="heroForm.subtitle" rows="3" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white"></textarea>
                                </div>

                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Texto Botón Principal</label>
                                        <input v-model="heroForm.cta_text" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Enlace Botón Principal</label>
                                        <input v-model="heroForm.cta_link" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                </div>

                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Texto Botón Secundario</label>
                                        <input v-model="heroForm.secondary_cta_text" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Enlace Botón Secundario</label>
                                        <input v-model="heroForm.secondary_cta_link" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Imagen de Fondo</label>
                                    <div class="flex items-center gap-4">
                                        <div v-if="heroForm.background_image" class="w-32 h-20 rounded-lg overflow-hidden bg-gray-100">
                                            <img :src="heroForm.background_image" class="w-full h-full object-cover" />
                                        </div>
                                        <label class="cursor-pointer px-4 py-2 bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition">
                                            <span>Subir imagen</span>
                                            <input type="file" class="hidden" accept="image/*" @change="uploadImage($event, 'hero', heroForm, 'background_image')" />
                                        </label>
                                    </div>
                                </div>

                                <div class="flex items-center gap-2">
                                    <input type="checkbox" v-model="heroForm.show_stats" class="rounded border-gray-300 text-blue-600" id="show_stats" />
                                    <label for="show_stats" class="text-sm text-gray-700 dark:text-gray-300">Mostrar estadísticas en el hero</label>
                                </div>

                                <div class="pt-4 border-t dark:border-gray-700">
                                    <button @click="saveSection('hero', heroForm)" 
                                            :disabled="heroForm.processing"
                                            class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                        {{ heroForm.processing ? 'Guardando...' : 'Guardar Cambios' }}
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- Features Section -->
                        <div v-show="activeTab === 'features'" class="space-y-6">
                            <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                                <div class="flex justify-between items-center mb-6">
                                    <h3 class="text-lg font-bold text-gray-900 dark:text-white flex items-center gap-2">
                                        <span>✨</span> Características / Beneficios
                                    </h3>
                                    <button @click="openFeatureModal()" class="px-4 py-2 bg-blue-600 text-white rounded-xl text-sm font-medium hover:bg-blue-700 transition">
                                        + Agregar
                                    </button>
                                </div>

                                <!-- Section settings -->
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6 pb-6 border-b dark:border-gray-700">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Título de la Sección</label>
                                        <input v-model="benefitsForm.title" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Subtítulo</label>
                                        <input v-model="benefitsForm.subtitle" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                </div>

                                <!-- Features list -->
                                <div class="space-y-3">
                                    <div v-for="feature in features" :key="feature.id" 
                                         class="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-700/50 rounded-xl">
                                        <div class="flex items-center gap-4">
                                            <div class="w-10 h-10 rounded-lg bg-blue-100 dark:bg-blue-900/50 flex items-center justify-center">
                                                <span class="text-lg">{{ getIconEmoji(feature.icon) }}</span>
                                            </div>
                                            <div>
                                                <h4 class="font-medium text-gray-900 dark:text-white">{{ feature.title }}</h4>
                                                <p class="text-sm text-gray-500 dark:text-gray-400 line-clamp-1">{{ feature.description }}</p>
                                            </div>
                                        </div>
                                        <div class="flex items-center gap-2">
                                            <span :class="[
                                                'px-2 py-1 text-xs rounded-full',
                                                feature.is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600'
                                            ]">
                                                {{ feature.is_active ? 'Activo' : 'Inactivo' }}
                                            </span>
                                            <button @click="openFeatureModal(feature)" class="p-2 text-gray-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg">
                                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                                                </svg>
                                            </button>
                                            <button @click="deleteFeature(feature)" class="p-2 text-gray-500 hover:text-red-600 hover:bg-red-50 rounded-lg">
                                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
                                                </svg>
                                            </button>
                                        </div>
                                    </div>
                                    <div v-if="!features.length" class="text-center py-8 text-gray-500 dark:text-gray-400">
                                        No hay características. Agrega la primera.
                                    </div>
                                </div>

                                <div class="pt-4 mt-4 border-t dark:border-gray-700">
                                    <button @click="saveSection('benefits', benefitsForm)" 
                                            :disabled="benefitsForm.processing"
                                            class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                        Guardar Títulos
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- Stats Section -->
                        <div v-show="activeTab === 'stats'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <div class="flex justify-between items-center mb-6">
                                <h3 class="text-lg font-bold text-gray-900 dark:text-white flex items-center gap-2">
                                    <span>📊</span> Estadísticas
                                </h3>
                                <button @click="openStatModal()" class="px-4 py-2 bg-blue-600 text-white rounded-xl text-sm font-medium hover:bg-blue-700 transition">
                                    + Agregar
                                </button>
                            </div>

                            <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
                                <div v-for="stat in stats" :key="stat.id" 
                                     class="relative p-4 bg-gradient-to-br from-blue-50 to-purple-50 dark:from-blue-900/30 dark:to-purple-900/30 rounded-xl">
                                    <div class="text-3xl font-bold text-gray-900 dark:text-white">{{ stat.value }}</div>
                                    <div class="text-sm text-gray-600 dark:text-gray-400">{{ stat.label }}</div>
                                    <div class="absolute top-2 right-2 flex gap-1">
                                        <button @click="openStatModal(stat)" class="p-1.5 text-gray-400 hover:text-blue-600 rounded">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                                            </svg>
                                        </button>
                                        <button @click="deleteStat(stat)" class="p-1.5 text-gray-400 hover:text-red-600 rounded">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                                            </svg>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <div v-if="!stats.length" class="text-center py-8 text-gray-500 dark:text-gray-400">
                                No hay estadísticas. Agrega la primera.
                            </div>
                        </div>

                        <!-- Plans Section -->
                        <div v-show="activeTab === 'plans'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
                                <span>💳</span> Sección de Planes
                            </h3>

                            <div class="space-y-6">
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Título de la Sección</label>
                                        <input v-model="plansSectionForm.title" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Subtítulo</label>
                                        <input v-model="plansSectionForm.subtitle" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                </div>

                                <div class="flex items-center gap-2">
                                    <input type="checkbox" v-model="plansSectionForm.show_section" class="rounded border-gray-300 text-blue-600" id="show_plans" />
                                    <label for="show_plans" class="text-sm text-gray-700 dark:text-gray-300">Mostrar sección de planes en el landing</label>
                                </div>

                                <div class="border-t dark:border-gray-700 pt-6">
                                    <h4 class="font-medium text-gray-900 dark:text-white mb-4">Planes Disponibles (desde /admin/plans)</h4>
                                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                                        <div v-for="plan in plans" :key="plan.id" 
                                             class="p-4 border border-gray-200 dark:border-gray-600 rounded-xl">
                                            <div class="font-semibold text-gray-900 dark:text-white">{{ plan.name }}</div>
                                            <div class="text-2xl font-bold text-blue-600">${{ plan.price }}</div>
                                            <div class="text-xs text-gray-500 dark:text-gray-400">{{ plan.duration_days }} días</div>
                                        </div>
                                    </div>
                                    <p class="text-sm text-gray-500 dark:text-gray-400 mt-4">
                                        <a :href="route('admin.plans.index')" class="text-blue-600 hover:underline">Gestionar planes →</a>
                                    </p>
                                </div>

                                <div class="pt-4 border-t dark:border-gray-700">
                                    <button @click="saveSection('plans_section', plansSectionForm)" 
                                            :disabled="plansSectionForm.processing"
                                            class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                        Guardar Cambios
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- Testimonials Section -->
                        <div v-show="activeTab === 'testimonials'" class="space-y-6">
                            <!-- Section Settings -->
                            <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                                <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
                                    <span>💬</span> Configuración de Testimonios
                                </h3>
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Título de la Sección</label>
                                        <input v-model="testimonialsSectionForm.title" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Subtítulo</label>
                                        <input v-model="testimonialsSectionForm.subtitle" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                </div>
                                <div class="pt-4 mt-4 border-t dark:border-gray-700">
                                    <button @click="saveSection('testimonials_section', testimonialsSectionForm)" 
                                            :disabled="testimonialsSectionForm.processing"
                                            class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                        Guardar Configuración
                                    </button>
                                </div>
                            </div>

                            <!-- Testimonials List -->
                            <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                                <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6">
                                    <div class="flex items-center gap-3">
                                        <h3 class="text-lg font-bold text-gray-900 dark:text-white">Lista de Testimonios</h3>
                                        <span v-if="pendingTestimonialsCount > 0" 
                                              class="px-2.5 py-1 bg-yellow-100 text-yellow-800 text-xs font-bold rounded-full animate-pulse">
                                            {{ pendingTestimonialsCount }} pendiente{{ pendingTestimonialsCount > 1 ? 's' : '' }}
                                        </span>
                                    </div>
                                    <div class="flex items-center gap-3">
                                        <!-- Filter -->
                                        <select v-model="testimonialFilter" 
                                                class="rounded-lg border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white text-sm">
                                            <option value="all">Todos</option>
                                            <option value="pending">Pendientes</option>
                                            <option value="approved">Aprobados</option>
                                            <option value="rejected">Rechazados</option>
                                            <option value="coach">De coaches</option>
                                            <option value="admin">Creados por admin</option>
                                        </select>
                                        <button @click="openTestimonialModal()" class="px-4 py-2 bg-blue-600 text-white rounded-xl text-sm font-medium hover:bg-blue-700 transition">
                                            + Agregar
                                        </button>
                                    </div>
                                </div>

                                <div class="space-y-4">
                                    <div v-for="testimonial in filteredTestimonials" :key="testimonial.id" 
                                         :class="[
                                             'p-4 rounded-xl border-2 transition-all',
                                             testimonial.status === 'pending' ? 'bg-yellow-50 dark:bg-yellow-900/20 border-yellow-200 dark:border-yellow-800' :
                                             testimonial.status === 'approved' ? 'bg-green-50 dark:bg-green-900/20 border-green-200 dark:border-green-800' :
                                             testimonial.status === 'rejected' ? 'bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800' :
                                             'bg-gray-50 dark:bg-gray-700/50 border-gray-200 dark:border-gray-700'
                                         ]">
                                        <div class="flex justify-between">
                                            <div class="flex items-center gap-3">
                                                <!-- Avatar -->
                                                <div class="w-14 h-14 rounded-full overflow-hidden bg-gradient-to-br from-blue-400 to-purple-500 flex items-center justify-center text-white font-bold flex-shrink-0">
                                                    <img v-if="testimonial.avatar" :src="testimonial.avatar" :alt="testimonial.name" class="w-full h-full object-cover" />
                                                    <span v-else class="text-xl">{{ testimonial.name.charAt(0) }}</span>
                                                </div>
                                                <div>
                                                    <div class="flex items-center gap-2">
                                                        <h4 class="font-medium text-gray-900 dark:text-white">{{ testimonial.name }}</h4>
                                                        <!-- Source badge -->
                                                        <span v-if="testimonial.source === 'coach'" 
                                                              class="px-2 py-0.5 bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300 text-xs rounded-full">
                                                            Coach
                                                        </span>
                                                    </div>
                                                    <p class="text-sm text-gray-500 dark:text-gray-400">{{ testimonial.role }}</p>
                                                    <!-- Coach info if from coach -->
                                                    <p v-if="testimonial.coach" class="text-xs text-gray-400">
                                                        {{ testimonial.coach.email }}
                                                    </p>
                                                </div>
                                            </div>
                                            <div class="flex flex-col items-end gap-2">
                                                <!-- Status badge -->
                                                <span :class="[
                                                    'px-2 py-1 text-xs font-medium rounded-full',
                                                    testimonial.status === 'pending' ? 'bg-yellow-200 text-yellow-800' :
                                                    testimonial.status === 'approved' ? 'bg-green-200 text-green-800' :
                                                    'bg-red-200 text-red-800'
                                                ]">
                                                    {{ testimonial.status === 'pending' ? '⏳ Pendiente' :
                                                       testimonial.status === 'approved' ? '✓ Aprobado' : '✗ Rechazado' }}
                                                </span>
                                                <div class="flex text-yellow-400 text-sm">
                                                    <span v-for="i in testimonial.rating" :key="i">⭐</span>
                                                </div>
                                            </div>
                                        </div>
                                        <p class="mt-3 text-gray-600 dark:text-gray-300 italic">"{{ testimonial.content }}"</p>
                                        
                                        <!-- Rejection reason -->
                                        <p v-if="testimonial.rejection_reason" class="mt-2 text-sm text-red-600 dark:text-red-400">
                                            <strong>Motivo de rechazo:</strong> {{ testimonial.rejection_reason }}
                                        </p>
                                        
                                        <!-- Metadata -->
                                        <div class="mt-3 flex flex-wrap gap-4 text-xs text-gray-500">
                                            <span v-if="testimonial.submitted_at">Enviado: {{ testimonial.submitted_at }}</span>
                                            <span v-if="testimonial.reviewed_at">Revisado: {{ testimonial.reviewed_at }}</span>
                                            <span v-if="testimonial.reviewer">Por: {{ testimonial.reviewer.name }}</span>
                                        </div>
                                        
                                        <!-- Actions -->
                                        <div class="mt-4 flex flex-wrap gap-2 pt-3 border-t border-gray-200 dark:border-gray-600">
                                            <!-- Approval actions for pending testimonials from coaches -->
                                            <template v-if="testimonial.status === 'pending' && testimonial.source === 'coach'">
                                                <button @click="approveTestimonial(testimonial)" 
                                                        class="px-4 py-2 bg-green-600 text-white rounded-lg text-sm font-medium hover:bg-green-700 transition flex items-center gap-2">
                                                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
                                                    </svg>
                                                    Aprobar
                                                </button>
                                                <button @click="openRejectModal(testimonial)" 
                                                        class="px-4 py-2 bg-red-600 text-white rounded-lg text-sm font-medium hover:bg-red-700 transition flex items-center gap-2">
                                                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                                                    </svg>
                                                    Rechazar
                                                </button>
                                            </template>
                                            <button @click="openTestimonialModal(testimonial)" 
                                                    class="px-3 py-2 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg text-sm flex items-center gap-2">
                                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                                                </svg>
                                                Editar
                                            </button>
                                            <button @click="deleteTestimonial(testimonial)" 
                                                    class="px-3 py-2 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-lg text-sm flex items-center gap-2">
                                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
                                                </svg>
                                                Eliminar
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <div v-if="!filteredTestimonials.length" class="text-center py-8 text-gray-500 dark:text-gray-400">
                                    No hay testimonios {{ testimonialFilter !== 'all' ? 'con este filtro' : '' }}. 
                                    <button @click="openTestimonialModal()" class="text-blue-600 hover:underline">Agrega el primero</button>.
                                </div>
                            </div>
                        </div>

                        <!-- Blog Section -->
                        <div v-show="activeTab === 'blog'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
                                <span>📝</span> Sección de Blog
                            </h3>

                            <div class="space-y-6">
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Título de la Sección</label>
                                        <input v-model="blogSectionForm.title" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Subtítulo</label>
                                        <input v-model="blogSectionForm.subtitle" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                </div>

                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Cantidad de Posts</label>
                                        <select v-model="blogSectionForm.posts_count" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white">
                                            <option :value="3">3 posts</option>
                                            <option :value="4">4 posts</option>
                                            <option :value="6">6 posts</option>
                                        </select>
                                    </div>
                                    <div class="flex items-end">
                                        <label class="flex items-center gap-2">
                                            <input type="checkbox" v-model="blogSectionForm.show_section" class="rounded border-gray-300 text-blue-600" />
                                            <span class="text-sm text-gray-700 dark:text-gray-300">Mostrar sección de blog</span>
                                        </label>
                                    </div>
                                </div>

                                <p class="text-sm text-gray-500 dark:text-gray-400">
                                    <a :href="route('admin.posts.index')" class="text-blue-600 hover:underline">Gestionar posts del blog →</a>
                                </p>

                                <div class="pt-4 border-t dark:border-gray-700">
                                    <button @click="saveSection('blog_section', blogSectionForm)" 
                                            :disabled="blogSectionForm.processing"
                                            class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                        Guardar Cambios
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- CTA Section -->
                        <div v-show="activeTab === 'cta'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
                                <span>🚀</span> Call to Action Final
                            </h3>

                            <div class="space-y-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Título</label>
                                    <input v-model="ctaSectionForm.title" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Subtítulo</label>
                                    <input v-model="ctaSectionForm.subtitle" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                </div>

                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Texto del Botón</label>
                                        <input v-model="ctaSectionForm.cta_text" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Enlace del Botón</label>
                                        <input v-model="ctaSectionForm.cta_link" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                    </div>
                                </div>

                                <div class="flex items-center gap-2">
                                    <input type="checkbox" v-model="ctaSectionForm.show_section" class="rounded border-gray-300 text-blue-600" id="show_cta" />
                                    <label for="show_cta" class="text-sm text-gray-700 dark:text-gray-300">Mostrar sección CTA</label>
                                </div>

                                <div class="pt-4 border-t dark:border-gray-700">
                                    <button @click="saveSection('cta_section', ctaSectionForm)" 
                                            :disabled="ctaSectionForm.processing"
                                            class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                        Guardar Cambios
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- Social Links Section -->
                        <div v-show="activeTab === 'social'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <div class="flex justify-between items-center mb-6">
                                <h3 class="text-lg font-bold text-gray-900 dark:text-white flex items-center gap-2">
                                    <span>🔗</span> Redes Sociales
                                </h3>
                                <button @click="openSocialModal()" class="px-4 py-2 bg-blue-600 text-white rounded-xl text-sm font-medium hover:bg-blue-700 transition">
                                    + Agregar
                                </button>
                            </div>

                            <div class="space-y-3">
                                <div v-for="link in socialLinks" :key="link.id" 
                                     class="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-700/50 rounded-xl">
                                    <div class="flex items-center gap-4">
                                        <div class="w-10 h-10 rounded-lg bg-gray-200 dark:bg-gray-600 flex items-center justify-center">
                                            <span class="text-lg">
                                                {{ link.platform === 'facebook' ? '📘' : 
                                                   link.platform === 'instagram' ? '📸' : 
                                                   link.platform === 'twitter' ? '🐦' : 
                                                   link.platform === 'youtube' ? '🎬' : 
                                                   link.platform === 'tiktok' ? '🎵' : '🔗' }}
                                            </span>
                                        </div>
                                        <div>
                                            <h4 class="font-medium text-gray-900 dark:text-white capitalize">{{ platformLabels[link.platform] || link.platform }}</h4>
                                            <p class="text-sm text-gray-500 dark:text-gray-400 truncate max-w-xs">{{ link.url }}</p>
                                        </div>
                                    </div>
                                    <div class="flex items-center gap-2">
                                        <span :class="[
                                            'px-2 py-1 text-xs rounded-full',
                                            link.is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600'
                                        ]">
                                            {{ link.is_active ? 'Activo' : 'Inactivo' }}
                                        </span>
                                        <button @click="openSocialModal(link)" class="p-2 text-gray-500 hover:text-blue-600 hover:bg-blue-50 rounded-lg">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                                            </svg>
                                        </button>
                                        <button @click="deleteSocial(link)" class="p-2 text-gray-500 hover:text-red-600 hover:bg-red-50 rounded-lg">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
                                            </svg>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <div v-if="!socialLinks.length" class="text-center py-8 text-gray-500 dark:text-gray-400">
                                No hay redes sociales. Agrega la primera.
                            </div>
                        </div>

                        <!-- Footer Section -->
                        <div v-show="activeTab === 'footer'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
                                <span>📄</span> Footer
                            </h3>

                            <div class="space-y-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Descripción</label>
                                    <textarea v-model="footerForm.description" rows="3" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white"></textarea>
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Copyright</label>
                                    <input v-model="footerForm.copyright" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                </div>

                                <div class="flex items-center gap-2">
                                    <input type="checkbox" v-model="footerForm.show_social_links" class="rounded border-gray-300 text-blue-600" id="show_social" />
                                    <label for="show_social" class="text-sm text-gray-700 dark:text-gray-300">Mostrar enlaces de redes sociales</label>
                                </div>

                                <div class="pt-4 border-t dark:border-gray-700">
                                    <button @click="saveSection('footer', footerForm)" 
                                            :disabled="footerForm.processing"
                                            class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                        Guardar Cambios
                                    </button>
                                </div>
                            </div>
                        </div>

                        <!-- Colors Section -->
                        <div v-show="activeTab === 'colors'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
                                <span>🎨</span> Paleta de Colores
                            </h3>

                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Color Primario</label>
                                    <div class="flex items-center gap-3">
                                        <input type="color" v-model="colorsForm.primary" class="w-12 h-12 rounded-lg border-0 cursor-pointer" />
                                        <input type="text" v-model="colorsForm.primary" class="flex-1 rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white font-mono" />
                                    </div>
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Color Secundario</label>
                                    <div class="flex items-center gap-3">
                                        <input type="color" v-model="colorsForm.secondary" class="w-12 h-12 rounded-lg border-0 cursor-pointer" />
                                        <input type="text" v-model="colorsForm.secondary" class="flex-1 rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white font-mono" />
                                    </div>
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Color Acento</label>
                                    <div class="flex items-center gap-3">
                                        <input type="color" v-model="colorsForm.accent" class="w-12 h-12 rounded-lg border-0 cursor-pointer" />
                                        <input type="text" v-model="colorsForm.accent" class="flex-1 rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white font-mono" />
                                    </div>
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Color Oscuro</label>
                                    <div class="flex items-center gap-3">
                                        <input type="color" v-model="colorsForm.dark" class="w-12 h-12 rounded-lg border-0 cursor-pointer" />
                                        <input type="text" v-model="colorsForm.dark" class="flex-1 rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white font-mono" />
                                    </div>
                                </div>
                            </div>

                            <!-- Preview -->
                            <div class="mt-6 p-6 rounded-xl border dark:border-gray-700">
                                <h4 class="font-medium text-gray-900 dark:text-white mb-4">Vista Previa</h4>
                                <div class="flex flex-wrap gap-3">
                                    <button :style="{ backgroundColor: colorsForm.primary }" class="px-4 py-2 text-white rounded-lg">Primario</button>
                                    <button :style="{ backgroundColor: colorsForm.secondary }" class="px-4 py-2 text-white rounded-lg">Secundario</button>
                                    <button :style="{ backgroundColor: colorsForm.accent }" class="px-4 py-2 text-white rounded-lg">Acento</button>
                                    <button :style="{ backgroundColor: colorsForm.dark }" class="px-4 py-2 text-white rounded-lg">Oscuro</button>
                                </div>
                            </div>

                            <div class="pt-4 mt-4 border-t dark:border-gray-700">
                                <button @click="saveSection('colors', colorsForm)" 
                                        :disabled="colorsForm.processing"
                                        class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                    Guardar Colores
                                </button>
                            </div>
                        </div>

                        <!-- General Section -->
                        <div v-show="activeTab === 'general'" class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-100 dark:border-gray-700 p-6">
                            <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6 flex items-center gap-2">
                                <span>⚙️</span> Configuración General
                            </h3>

                            <div class="space-y-6">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Nombre del Sitio</label>
                                    <input v-model="generalForm.site_name" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Logo</label>
                                    <div class="flex items-center gap-4">
                                        <div v-if="generalForm.logo" class="h-12 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-700 px-4 flex items-center">
                                            <img :src="generalForm.logo" class="h-8 object-contain" />
                                        </div>
                                        <label class="cursor-pointer px-4 py-2 bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition">
                                            <span>Subir logo</span>
                                            <input type="file" class="hidden" accept="image/*" @change="uploadImage($event, 'logo', generalForm, 'logo')" />
                                        </label>
                                    </div>
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Meta Título (SEO)</label>
                                    <input v-model="generalForm.meta_title" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Meta Descripción (SEO)</label>
                                    <textarea v-model="generalForm.meta_description" rows="3" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white"></textarea>
                                </div>

                                <div class="pt-4 border-t dark:border-gray-700">
                                    <button @click="saveSection('general', generalForm)" 
                                            :disabled="generalForm.processing"
                                            class="px-6 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 disabled:opacity-50 transition">
                                        Guardar Cambios
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Feature Modal -->
        <Teleport to="body">
            <div v-if="showFeatureModal" class="fixed inset-0 z-50 flex items-center justify-center p-4">
                <div class="fixed inset-0 bg-gray-900/60" @click="showFeatureModal = false"></div>
                <div class="relative bg-white dark:bg-gray-800 rounded-2xl shadow-2xl max-w-md w-full p-6">
                    <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6">
                        {{ editingItem ? 'Editar' : 'Nueva' }} Característica
                    </h3>
                    <form @submit.prevent="saveFeature" class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Icono</label>
                            <select v-model="featureForm.icon" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white">
                                <option v-for="(label, key) in availableIcons" :key="key" :value="key">{{ label }}</option>
                            </select>
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Título</label>
                            <input v-model="featureForm.title" type="text" required class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Descripción</label>
                            <textarea v-model="featureForm.description" rows="3" required class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white"></textarea>
                        </div>
                        <label class="flex items-center gap-2">
                            <input type="checkbox" v-model="featureForm.is_active" class="rounded border-gray-300 text-blue-600" />
                            <span class="text-sm text-gray-700 dark:text-gray-300">Activo</span>
                        </label>
                        <div class="flex justify-end gap-3 pt-4">
                            <button type="button" @click="showFeatureModal = false" class="px-4 py-2 text-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl">Cancelar</button>
                            <button type="submit" :disabled="featureForm.processing" class="px-6 py-2 bg-blue-600 text-white rounded-xl hover:bg-blue-700 disabled:opacity-50">
                                {{ featureForm.processing ? 'Guardando...' : 'Guardar' }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </Teleport>

        <!-- Testimonial Modal -->
        <Teleport to="body">
            <div v-if="showTestimonialModal" class="fixed inset-0 z-50 flex items-center justify-center p-4">
                <div class="fixed inset-0 bg-gray-900/60" @click="showTestimonialModal = false"></div>
                <div class="relative bg-white dark:bg-gray-800 rounded-2xl shadow-2xl max-w-md w-full p-6">
                    <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6">
                        {{ editingItem ? 'Editar' : 'Nuevo' }} Testimonio
                    </h3>
                    <form @submit.prevent="saveTestimonial" class="space-y-4">
                        <div class="grid grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Nombre</label>
                                <input v-model="testimonialForm.name" type="text" required class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" />
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Rol/Cargo</label>
                                <input v-model="testimonialForm.role" type="text" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" placeholder="Ej: Coach de Fitness" />
                            </div>
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Testimonio</label>
                            <textarea v-model="testimonialForm.content" rows="4" required class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white"></textarea>
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Calificación</label>
                            <div class="flex gap-2">
                                <button v-for="i in 5" :key="i" type="button" @click="testimonialForm.rating = i" 
                                        :class="['text-2xl transition', i <= testimonialForm.rating ? 'text-yellow-400' : 'text-gray-300']">
                                    ⭐
                                </button>
                            </div>
                        </div>
                        <label class="flex items-center gap-2">
                            <input type="checkbox" v-model="testimonialForm.is_active" class="rounded border-gray-300 text-blue-600" />
                            <span class="text-sm text-gray-700 dark:text-gray-300">Activo</span>
                        </label>
                        <div class="flex justify-end gap-3 pt-4">
                            <button type="button" @click="showTestimonialModal = false" class="px-4 py-2 text-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl">Cancelar</button>
                            <button type="submit" :disabled="testimonialForm.processing" class="px-6 py-2 bg-blue-600 text-white rounded-xl hover:bg-blue-700 disabled:opacity-50">
                                {{ testimonialForm.processing ? 'Guardando...' : 'Guardar' }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </Teleport>

        <!-- Stat Modal -->
        <Teleport to="body">
            <div v-if="showStatModal" class="fixed inset-0 z-50 flex items-center justify-center p-4">
                <div class="fixed inset-0 bg-gray-900/60" @click="showStatModal = false"></div>
                <div class="relative bg-white dark:bg-gray-800 rounded-2xl shadow-2xl max-w-md w-full p-6">
                    <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6">
                        {{ editingItem ? 'Editar' : 'Nueva' }} Estadística
                    </h3>
                    <form @submit.prevent="saveStat" class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Valor</label>
                            <input v-model="statForm.value" type="text" required class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" placeholder="Ej: 500+" />
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Etiqueta</label>
                            <input v-model="statForm.label" type="text" required class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" placeholder="Ej: Coaches Activos" />
                        </div>
                        <label class="flex items-center gap-2">
                            <input type="checkbox" v-model="statForm.is_active" class="rounded border-gray-300 text-blue-600" />
                            <span class="text-sm text-gray-700 dark:text-gray-300">Activo</span>
                        </label>
                        <div class="flex justify-end gap-3 pt-4">
                            <button type="button" @click="showStatModal = false" class="px-4 py-2 text-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl">Cancelar</button>
                            <button type="submit" :disabled="statForm.processing" class="px-6 py-2 bg-blue-600 text-white rounded-xl hover:bg-blue-700 disabled:opacity-50">
                                {{ statForm.processing ? 'Guardando...' : 'Guardar' }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </Teleport>

        <!-- Social Modal -->
        <Teleport to="body">
            <div v-if="showSocialModal" class="fixed inset-0 z-50 flex items-center justify-center p-4">
                <div class="fixed inset-0 bg-gray-900/60" @click="showSocialModal = false"></div>
                <div class="relative bg-white dark:bg-gray-800 rounded-2xl shadow-2xl max-w-md w-full p-6">
                    <h3 class="text-lg font-bold text-gray-900 dark:text-white mb-6">
                        {{ editingItem ? 'Editar' : 'Nueva' }} Red Social
                    </h3>
                    <form @submit.prevent="saveSocial" class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Plataforma</label>
                            <select v-model="socialForm.platform" class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white">
                                <option v-for="platform in platformOptions" :key="platform" :value="platform">
                                    {{ platformLabels[platform] || platform }}
                                </option>
                            </select>
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">URL</label>
                            <input v-model="socialForm.url" type="url" required class="w-full rounded-xl border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-white" placeholder="https://" />
                        </div>
                        <label class="flex items-center gap-2">
                            <input type="checkbox" v-model="socialForm.is_active" class="rounded border-gray-300 text-blue-600" />
                            <span class="text-sm text-gray-700 dark:text-gray-300">Activo</span>
                        </label>
                        <div class="flex justify-end gap-3 pt-4">
                            <button type="button" @click="showSocialModal = false" class="px-4 py-2 text-gray-600 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl">Cancelar</button>
                            <button type="submit" :disabled="socialForm.processing" class="px-6 py-2 bg-blue-600 text-white rounded-xl hover:bg-blue-700 disabled:opacity-50">
                                {{ socialForm.processing ? 'Guardando...' : 'Guardar' }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </Teleport>

        <!-- Modal Rechazar Testimonio -->
        <Teleport to="body">
            <div v-if="showRejectModal" class="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
                <div class="bg-white dark:bg-gray-800 rounded-2xl p-6 w-full max-w-md shadow-2xl">
                    <div class="flex items-center justify-between mb-6">
                        <h3 class="text-xl font-bold text-gray-900 dark:text-white">Rechazar Testimonio</h3>
                        <button @click="showRejectModal = false" class="p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-full">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                            </svg>
                        </button>
                    </div>
                    
                    <div v-if="rejectingTestimonial" class="mb-4 p-3 bg-gray-50 dark:bg-gray-700 rounded-lg">
                        <p class="text-sm text-gray-600 dark:text-gray-400">Testimonio de:</p>
                        <p class="font-semibold text-gray-900 dark:text-white">{{ rejectingTestimonial.name }}</p>
                    </div>
                    
                    <div class="mb-6">
                        <label class="block text-sm font-medium mb-2 text-gray-700 dark:text-gray-300">
                            Razón del rechazo (opcional)
                        </label>
                        <textarea
                            v-model="rejectReason"
                            rows="3"
                            class="w-full px-4 py-3 rounded-xl border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-red-500 focus:border-transparent"
                            placeholder="Explica brevemente por qué rechazas este testimonio..."
                        ></textarea>
                        <p class="mt-1 text-xs text-gray-500">Esta información se enviará al coach por correo.</p>
                    </div>
                    
                    <div class="flex justify-end gap-3">
                        <button 
                            type="button" 
                            @click="showRejectModal = false" 
                            class="px-4 py-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl"
                        >
                            Cancelar
                        </button>
                        <button 
                            type="button" 
                            @click="rejectTestimonial" 
                            class="px-6 py-2 bg-red-600 text-white rounded-xl hover:bg-red-700"
                        >
                            Rechazar Testimonio
                        </button>
                    </div>
                </div>
            </div>
        </Teleport>
    </AdminLayout>
</template>
