<?php
// Fetch Global Content for the Footer
try {
    $footer_stmt = $pdo->query("SELECT content_key, content_value FROM page_content WHERE page_slug = 'global'");
    $footer_data = $footer_stmt->fetchAll(PDO::FETCH_KEY_PAIR);
} catch (PDOException $e) {
    $footer_data = [];
}

// Fallback helper specifically for the footer
$get_footer = function($key, $default) use ($footer_data) {
    return isset($footer_data[$key]) && trim($footer_data[$key]) !== '' 
        ? $footer_data[$key] 
        : $default;
};
?>

<footer class="relative z-50 w-full bg-[#020617] border-t border-slate-800/60 mt-auto shadow-[0_-10px_30px_rgba(0,0,0,0.5)]">
    <div class="max-w-6xl mx-auto px-6 py-10 md:py-16">
        
        <div class="grid grid-cols-1 text-center md:text-left md:grid-cols-4 gap-8">
            
            <div class="md:col-span-2 flex flex-col items-center md:items-start space-y-4">
                <div class="flex items-center space-x-3">
                    
                    <?php if (!empty($footer_data['footer_logo_image'])): ?>
                        <div class="w-10 h-10 flex items-center justify-center">
                            <img src="<?php echo SITE_URL . '/' . htmlspecialchars($footer_data['footer_logo_image']); ?>" alt="Logo" class="max-w-full max-h-full object-contain">
                        </div>
                    <?php else: ?>
                        <div class="w-10 h-10 bg-emerald-500/10 border border-emerald-500/30 rounded-xl flex items-center justify-center shadow-[0_0_10px_rgba(16,185,129,0.1)]">
                            <svg class="w-5 h-5 text-emerald-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
                        </div>
                    <?php endif; ?>

                    <span class="font-black text-xl tracking-wider text-white uppercase flex flex-col justify-center text-left">
                         Tipspac<span class="text-[10px] text-emerald-400 tracking-widest -mt-1 font-bold">Pro AI Engine</span>
                    </span>
                </div>
                
                <p class="text-xs md:text-sm text-slate-300 leading-relaxed max-w-sm mx-auto md:mx-0">
                    <?php echo nl2br(htmlspecialchars($get_footer('footer_description', 'High-fidelity predictive analytics driven by autonomous machine learning. We process historical data and tactical variables to output high-probability match insights.'))); ?>
                </p>
            </div>

            <div class="flex flex-col items-center md:items-start mt-4 md:mt-0">
                <h4 class="text-white font-black tracking-widest uppercase text-xs mb-4 flex items-center space-x-2">
                    <span class="w-1.5 h-1.5 rounded-full bg-cyan-500"></span>
                    <span>Platform</span>
                </h4>
                <ul class="space-y-3 text-[11px] md:text-xs text-slate-300 font-medium">
                    <li><a href="predictions.php" class="hover:text-cyan-400 transition-colors">Live Predictions</a></li>
                    <li><a href="bet-of-the-day.php" class="hover:text-cyan-400 transition-colors">Bet of the Day</a></li>
                    <li><a href="login-register.php" class="hover:text-amber-400 transition-colors">VIP Access 👑</a></li>
                    <li><a href="login.php" class="hover:text-cyan-400 transition-colors">Client Portal</a></li>
                </ul>
            </div>

            <div class="flex flex-col items-center md:items-start mt-4 md:mt-0">
                <h4 class="text-white font-black tracking-widest uppercase text-xs mb-4 flex items-center space-x-2">
                    <span class="w-1.5 h-1.5 rounded-full bg-blue-500"></span>
                    <span>Support</span>
                </h4>
                <ul class="space-y-3 text-[11px] md:text-xs text-slate-300 font-medium">
                    <li><a href="contact.php" class="hover:text-blue-400 transition-colors">Contact Center</a></li>
                    <li><a href="terms.php" class="hover:text-blue-400 transition-colors">Terms of Service</a></li>
                    <li><a href="privacy.php" class="hover:text-blue-400 transition-colors">Privacy Matrix</a></li>
                </ul>
            </div>
        </div>

        <div class="mt-10 pt-6 border-t border-slate-800/60 flex flex-col items-center gap-3">
            <p class="text-[9px] md:text-xs text-slate-400 font-bold tracking-widest uppercase text-center">
                &copy; <?php echo date('Y'); ?> <?php echo htmlspecialchars($get_footer('footer_copyright', 'Football Pred Pro. All rights reserved.')); ?>
            </p>
            <p class="text-[9px] md:text-[10px] text-slate-500 text-center max-w-2xl leading-relaxed px-4">
                <?php echo htmlspecialchars($get_footer('footer_disclaimer', 'Disclaimer: This platform provides predictive analytics for informational purposes only. Predictions do not guarantee financial outcomes. Please gamble responsibly. 18+ Only.')); ?>
            </p>
        </div>
    </div>
</footer>

</body>
</html>