</main>
    <footer class="bg-white border-top py-5">
        <div class="container">
            <div class="row g-4">
                <div class="col-lg-4">
                    <a class="navbar-brand fw-bold text-success d-flex align-items-center" href="/">
                        <?php if (get_setting('site_icon')): ?>
                            <img src="/<?php echo get_setting('site_icon'); ?>" alt="Logo" class="me-2" style="height: 30px;">
                        <?php else: ?>
                            <i class="bi bi-robot"></i>
                        <?php endif; ?>
                        <?php echo htmlspecialchars(get_setting('site_name', 'ApkNusa')); ?>
                    </a>
                    <p class="text-muted mt-3 pe-lg-5">
                        <?php echo htmlspecialchars(get_setting('site_name', 'ApkNusa')); ?> <?php echo __('footer_about'); ?>
                    </p>
                </div>
                <div class="col-6 col-lg-2">
                    <h6 class="fw-bold mb-3"><?php echo __('popular'); ?></h6>
                    <ul class="list-unstyled">
                        <li><a href="/" class="text-muted text-decoration-none py-1 d-block small"><?php echo __('top_games'); ?></a></li>
                        <li><a href="/" class="text-muted text-decoration-none py-1 d-block small"><?php echo __('top_apps'); ?></a></li>
                        <li><a href="/" class="text-muted text-decoration-none py-1 d-block small"><?php echo __('new_releases'); ?></a></li>
                    </ul>
                </div>
                <div class="col-6 col-lg-2">
                    <h6 class="fw-bold mb-3"><?php echo __('resources'); ?></h6>
                    <ul class="list-unstyled">
                        <li><a href="/blog" class="text-muted text-decoration-none py-1 d-block small">Blog</a></li>
                        <li><a href="/help-center" class="text-muted text-decoration-none py-1 d-block small"><?php echo __('support_center'); ?></a></li>
                        <li><a href="/terms-of-service" class="text-muted text-decoration-none py-1 d-block small"><?php echo __('terms_of_service'); ?></a></li>
                        <li><a href="/privacy-policy" class="text-muted text-decoration-none py-1 d-block small"><?php echo __('privacy_policy'); ?></a></li>
                        <li><a href="/contact" class="text-muted text-decoration-none py-1 d-block small">Contact Us</a></li>
                    </ul>
                </div>
                <div class="col-lg-4">
                    <h6 class="fw-bold mb-3"><?php echo __('subscribe'); ?></h6>
                    <p class="text-muted small"><?php echo __('subscribe_text'); ?></p>
                    <form class="newsletter-form">
                        <div class="input-group">
                            <input type="email" class="form-control border-light-subtle newsletter-email" placeholder="<?php echo __('email_placeholder'); ?>">
                            <button class="btn btn-success px-3 newsletter-submit-btn" type="button"><?php echo __('subscribe'); ?></button>
                        </div>
                        <div class="newsletter-msg mt-2 small"></div>
                    </form>
                </div>
            </div>
            <hr class="my-5 text-black-50 opacity-25">
            <div class="row align-items-center">
                <div class="col-md-6 text-center text-md-start">
                    <span class="text-muted small">&copy; <?php echo date('Y'); ?> <?php echo htmlspecialchars(get_setting('site_name', 'ApkNusa')); ?>. <?php echo __('all_rights_reserved'); ?></span>
                </div>
                <div class="col-md-6 text-center text-md-end mt-3 mt-md-0">
                    <div class="d-flex justify-content-center justify-content-md-end gap-3">
                        <?php if ($fb = get_setting('facebook_url')): ?>
                            <a href="<?php echo $fb; ?>" target="_blank" class="text-muted"><i class="bi bi-facebook"></i></a>
                        <?php endif; ?>
                        <?php if ($tw = get_setting('twitter_url')): ?>
                            <a href="<?php echo $tw; ?>" target="_blank" class="text-muted"><i class="bi bi-twitter-x"></i></a>
                        <?php endif; ?>
                        <?php if ($ig = get_setting('instagram_url')): ?>
                            <a href="<?php echo $ig; ?>" target="_blank" class="text-muted"><i class="bi bi-instagram"></i></a>
                        <?php endif; ?>
                        <?php if ($gh = get_setting('github_url')): ?>
                            <a href="<?php echo $gh; ?>" target="_blank" class="text-muted"><i class="bi bi-github"></i></a>
                        <?php endif; ?>
                        <?php if ($tg = get_setting('telegram_url')): ?>
                            <a href="<?php echo $tg; ?>" target="_blank" class="text-muted"><i class="bi bi-telegram"></i></a>
                        <?php endif; ?>
                        <?php if ($wa = get_setting('whatsapp_url')): ?>
                            <a href="<?php echo $wa; ?>" target="_blank" class="text-muted"><i class="bi bi-whatsapp"></i></a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </footer>

    <!-- Mobile Bottom Navigation -->
    <nav class="mobile-bottom-nav">
        <a href="/" class="mobile-nav-item <?php echo $_SERVER['REQUEST_URI'] == '/' ? 'active' : ''; ?>">
            <i class="bi bi-house-door"></i>
            <span><?php echo __('home'); ?></span>
        </a>
        <a href="#" class="mobile-nav-item" id="mobile-search-trigger">
            <i class="bi bi-search"></i>
            <span><?php echo __('search'); ?></span>
        </a>
        <a href="/blog" class="mobile-nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/blog') !== false ? 'active' : ''; ?>">
            <i class="bi bi-newspaper"></i>
            <span>Blog</span>
        </a>
        <a href="<?php echo isset($_SESSION['user_id']) ? '/profile' : '/login'; ?>" class="mobile-nav-item <?php echo (strpos($_SERVER['REQUEST_URI'], '/profile') !== false || strpos($_SERVER['REQUEST_URI'], '/login') !== false) ? 'active' : ''; ?>">
            <i class="bi bi-person"></i>
            <span><?php echo __('profile'); ?></span>
        </a>
    </nav>

    <!-- WhatsApp FAB (Mobile) -->
    <?php if ($wa = get_setting('whatsapp_url')): ?>
        <a href="<?php echo $wa; ?>" target="_blank" class="whatsapp-fab">
            <i class="bi bi-whatsapp fs-3"></i>
        </a>
    <?php endif; ?>

    <!-- Back to Top -->
    <a href="#" class="back-to-top" id="back-to-top">
        <i class="bi bi-arrow-up"></i>
    </a>

    <!-- Search Overlay -->
    <div class="search-overlay" id="search-overlay">
        <button class="btn-close-search" id="close-search-overlay">
            <i class="bi bi-x-lg"></i>
        </button>
        <div class="mt-5">
            <h4 class="fw-bold mb-4">Search APKs</h4>
            <form action="/" method="GET" id="ajax-search-form">
                <div class="input-group input-group-lg border rounded-pill overflow-hidden shadow-sm">
                    <span class="input-group-text bg-white border-0 ps-3">
                        <i class="bi bi-search text-muted"></i>
                    </span>
                    <input type="text" name="search" class="form-control border-0 ps-1" placeholder="Search for apps or games..." autofocus>
                    <button class="btn btn-success px-4" type="submit">Go</button>
                </div>
            </form>
            
            <div class="mt-5">
                <h6 class="text-muted small fw-bold text-uppercase mb-3">Popular Categories</h6>
                <div class="d-flex flex-wrap gap-2">
                    <?php 
                        $db = db();
                        $popCats = $db->query("SELECT * FROM categories LIMIT 6")->fetchAll();
                        foreach ($popCats as $cat):
                    ?>
                        <a href="/?category=<?php echo $cat['slug']; ?>" class="btn btn-light btn-sm rounded-pill px-3 ajax-cat-link" data-category="<?php echo $cat['slug']; ?>"><?php echo $cat['name']; ?></a>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    </div>

    <!-- AI Chat Assistant -->
    <div id="ai-chat-wrapper" class="fixed-bottom p-3 d-flex flex-column align-items-end" style="z-index: 1050; pointer-events: none;">
        <div id="ai-chat-window" class="card shadow-lg border-0 mb-3 d-none" style="width: 350px; max-width: 90vw; height: 450px; pointer-events: auto; border-radius: 20px;">
            <div class="card-header bg-success text-white py-3 d-flex justify-content-between align-items-center" style="border-radius: 20px 20px 0 0;">
                <div class="d-flex align-items-center">
                    <div class="bg-white rounded-circle p-1 me-2">
                        <i class="bi bi-robot text-success"></i>
                    </div>
                    <span class="fw-bold">ApkNusa AI</span>
                </div>
                <button type="button" class="btn-close btn-close-white" id="close-ai-chat"></button>
            </div>
            <div class="card-body overflow-auto p-3" id="ai-chat-messages" style="background: var(--subtle-bg);">
                <div class="mb-3">
                    <div class="bg-white p-3 rounded-4 shadow-sm small" style="max-width: 85%; border-bottom-left-radius: 0 !important;">
                        Hello! How can I help you today?
                    </div>
                </div>
            </div>
            <div class="card-footer bg-white border-0 p-3" style="border-radius: 0 0 20px 20px;">
                <div class="input-group">
                    <input type="text" id="ai-chat-input" class="form-control border-light-subtle rounded-pill-start px-3" placeholder="Type a message...">
                    <button class="btn btn-success rounded-pill-end px-3" id="send-ai-chat">
                        <i class="bi bi-send-fill"></i>
                    </button>
                </div>
            </div>
        </div>
        <button class="btn btn-success shadow-lg d-flex align-items-center justify-content-center p-0 rounded-circle" id="toggle-ai-chat" style="width: 60px; height: 60px; pointer-events: auto;">
            <i class="bi bi-chat-dots-fill fs-3"></i>
        </button>
    </div>

    <style>
        #ai-chat-messages::-webkit-scrollbar {
            width: 4px;
        }
        #ai-chat-messages::-webkit-scrollbar-thumb {
            background: #10B981;
            border-radius: 10px;
        }
    </style>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="/assets/js/main.js?v=<?php echo time(); ?>"></script>
    <?php echo get_setting('body_js'); ?>
</body>
</html>