<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= esc($meta_title ?? $settings['seo_meta_title'] ?? 'Jasper Phytoextracts - Clinical Science') ?></title>
    <meta name="description" content="<?= esc($meta_description ?? $settings['seo_meta_description'] ?? 'Precision Nature. Clinical Science.') ?>">
    <link rel="icon" type="image/png" href="<?= base_url('assets/images/logo.png') ?>">
    
    <!-- Google Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;600;700&display=swap" rel="stylesheet">
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">
    
    <!-- Custom CSS -->
    <link href="<?= base_url('assets/css/style.css') ?>" rel="stylesheet">
    
    <!-- AOS CSS for scroll animations -->
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
    
    <?= $this->renderSection('styles') ?>
</head>
<body>

<!-- Navbar -->
<nav class="navbar navbar-expand-lg sticky-top glass-navbar">
    <div class="container d-flex justify-content-between align-items-center">
        <!-- Logo -->
        <a class="navbar-brand d-flex align-items-center" href="<?= base_url() ?>">
            <img src="<?= base_url('assets/images/logo.png') ?>" alt="Jasper Phytoextracts" style="height: 60px;" class="me-2">
        </a>
        
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        
        <!-- Center Links -->
        <div class="collapse navbar-collapse justify-content-center" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link <?= url_is('products*') ? 'active' : '' ?>" href="<?= base_url('products') ?>">Products</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= url_is('about') ? 'active' : '' ?>" href="<?= base_url('about') ?>">About Us</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= url_is('gallery') ? 'active' : '' ?>" href="<?= base_url('gallery') ?>">Gallery</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="<?= base_url('/#mission') ?>">Mission</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link <?= url_is('certification') ? 'active' : '' ?>" href="<?= base_url('certification') ?>">Certifications</a>
                </li>
            </ul>
        </div>
        
        <!-- Right Actions -->
        <div class="d-none d-lg-flex align-items-center gap-3">
            <form action="<?= base_url('products') ?>" method="GET" class="position-relative mb-0">
                <i class="bi bi-search position-absolute top-50 start-0 translate-middle-y ms-2 text-muted" style="font-size: 0.8rem;"></i>
                <input type="text" name="search" class="search-input ps-4" placeholder="Search extracts..." value="<?= esc($search ?? '') ?>">
            </form>
            <a class="btn btn-primary-custom" href="<?= base_url('contact') ?>">Contact Us</a>
        </div>
    </div>
</nav>

<!-- Main Content -->
<main>
    <?= $this->renderSection('content') ?>
</main>

<!-- CTA Pre-Footer -->
<section class="footer-cta text-center">
    <div class="container">
        <h3 class="font-serif fw-bold mb-3">Ready to source excellence?</h3>
        <p class="text-secondary mb-4">Connect with our procurement specialists for technical specifications and volume pricing.</p>
        <form id="sampleRequestForm" class="d-flex justify-content-center gap-2 flex-wrap align-items-center">
            <?= csrf_field() ?>
            <?php if (isset($product['id'])): ?>
                <input type="hidden" name="product_id" value="<?= esc($product['id']) ?>">
            <?php endif; ?>
            <input type="email" name="email" id="sampleEmail" placeholder="Professional Email Address" required>
            <button type="submit" class="btn btn-gold text-white fw-bold shadow-sm">Request Samples <i class="bi bi-envelope ms-1"></i></button>
        </form>
        <div id="sampleRequestMessage" class="mt-3 font-serif fw-semibold" style="display: none; font-size: 1.1rem; color: #10B981; transition: all 0.3s ease;"></div>
        <p class="mt-4 text-uppercase fw-semibold" style="font-size: 0.75rem; letter-spacing: 1px; color: var(--text-muted);">24/7 Global Logistics Support</p>
    </div>
</section>

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-5 pe-lg-5 mb-4">
                <div class="mb-3">
                    <img src="<?= base_url('assets/images/logo.png') ?>" alt="Jasper Phytoextracts" style="height: 50px;">
                </div>
                <p style="font-size: 0.95rem; line-height: 1.7;">Laboratory Certified Botanical Excellence. Serving the food, pharmaceutical, and cosmetic industries with pure plant power.</p>
                <div class="d-flex gap-3 mt-4">
                    <a href="#" style="background: var(--bg-surface); border: 1px solid var(--border-color); width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 50%; box-shadow: 0 4px 10px rgba(0,0,0,0.03);"><i class="bi bi-globe" style="font-size: 1.1rem;"></i></a>
                    <a href="#" style="background: var(--bg-surface); border: 1px solid var(--border-color); width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 50%; box-shadow: 0 4px 10px rgba(0,0,0,0.03);"><i class="bi bi-linkedin" style="font-size: 1.1rem;"></i></a>
                    <a href="#" style="background: var(--bg-surface); border: 1px solid var(--border-color); width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 50%; box-shadow: 0 4px 10px rgba(0,0,0,0.03);"><i class="bi bi-twitter" style="font-size: 1.1rem;"></i></a>
                </div>
            </div>
            
            <div class="col-lg-3 col-md-6 mb-4">
                <h6>Navigation</h6>
                <ul class="list-unstyled">
                    <li class="mb-3"><a href="#">Quality Assurance</a></li>
                    <li class="mb-3"><a href="#">Sourcing Ethics</a></li>
                    <li class="mb-3"><a href="#">Sustainability</a></li>
                </ul>
            </div>
            
            <div class="col-lg-3 col-md-6 mb-4">
                <h6>Legal</h6>
                <ul class="list-unstyled">
                    <li class="mb-3"><a href="#">Privacy Policy</a></li>
                    <li class="mb-3"><a href="#">Terms of Service</a></li>
                    <li class="mb-3"><a href="#">Certifications</a></li>
                </ul>
            </div>
        </div>
        
        <div class="footer-bottom">
            <p class="mb-0">&copy; <?= date('Y') ?> Jasper Phytoextracts, Laboratory Certified Botanical Excellence.</p>
        </div>
    </div>
</footer>

<!-- Bootstrap 5 JS Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- jQuery (For custom animations/AJAX if needed) -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<!-- AOS JS for scroll animations -->
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script>
    AOS.init({
        duration: 800,
        once: true,
        offset: 50
    });
</script>

<script>
$(document).ready(function() {
    $('#sampleRequestForm').on('submit', function(e) {
        e.preventDefault();
        
        var $form = $(this);
        var $btn = $form.find('button[type="submit"]');
        var $input = $form.find('input[type="email"]');
        var $msg = $('#sampleRequestMessage');
        
        var email = $input.val();
        var productId = $form.find('input[name="product_id"]').val() || null;
        var csrfName = $form.find('input[type="hidden"][name^="csrf_"]').attr('name');
        var csrfHash = $form.find('input[type="hidden"][name^="csrf_"]').val();
        
        // Disable form elements
        $btn.prop('disabled', true).html('Sending... <span class="spinner-border spinner-border-sm ms-1" role="status" aria-hidden="true"></span>');
        $input.prop('disabled', true);
        
        var postData = {
            email: email,
            product_id: productId
        };
        if (csrfName && csrfHash) {
            postData[csrfName] = csrfHash;
        }
        
        $.ajax({
            url: '<?= base_url('request-samples') ?>',
            type: 'POST',
            data: postData,
            dataType: 'json',
            success: function(response) {
                if (response.status === 'success') {
                    $msg.removeClass('text-danger').addClass('text-success')
                        .html('<i class="bi bi-check-circle-fill me-1"></i> ' + response.message).fadeIn();
                    $form.fadeOut(300, function() {
                        $(this).hide();
                    });
                } else {
                    $msg.removeClass('text-success').addClass('text-danger')
                        .html('<i class="bi bi-exclamation-triangle-fill me-1"></i> ' + response.message).fadeIn();
                    // Re-enable form elements
                    $btn.prop('disabled', false).html('Request Samples <i class="bi bi-envelope ms-1"></i>');
                    $input.prop('disabled', false);
                }
            },
            error: function(xhr, status, error) {
                var errorMsg = 'An error occurred. Please try again.';
                if (xhr.responseJSON && xhr.responseJSON.message) {
                    errorMsg = xhr.responseJSON.message;
                }
                $msg.removeClass('text-success').addClass('text-danger')
                    .html('<i class="bi bi-exclamation-triangle-fill me-1"></i> ' + errorMsg).fadeIn();
                // Re-enable form elements
                $btn.prop('disabled', false).html('Request Samples <i class="bi bi-envelope ms-1"></i>');
                $input.prop('disabled', false);
            }
        });
    });
});
</script>

<?= $this->renderSection('scripts') ?>
</body>
</html>
