<?php
include 'includes/db.php';

// Get visa details based on slug
$country = null;
if (isset($_GET['slug'])) {
    $slug = mysqli_real_escape_string($conn, $_GET['slug']);
    $result = mysqli_query($conn, "SELECT * FROM countries WHERE slug = '$slug'");
    $country = mysqli_fetch_assoc($result);

    if ($country) {
        $id = $country['id'];
        $requirements = mysqli_query($conn, "SELECT * FROM visa_requirements WHERE country_id = $id");
        $steps = mysqli_query($conn, "SELECT * FROM visa_steps WHERE country_id = $id ORDER BY step_number ASC");
        $highlights = mysqli_query($conn, "SELECT * FROM visa_highlights WHERE country_id = $id");
        $faqs = mysqli_query($conn, "SELECT * FROM visa_faqs WHERE country_id = $id");
        $notes = mysqli_query($conn, "SELECT * FROM visa_notes WHERE country_id = $id");
    }
}

if (!$country) {
    header("Location: visas.php");
    exit();
}

include 'includes/header.php';
include 'includes/sidebar.php';

// Prepare WhatsApp Link
$siteName = htmlspecialchars($settings['site_name'] ?? 'CFD Travels');
$whatsappMsg = urlencode("Hi {$siteName}! I'm interested in the " . $country['name'] . " " . $country['visa_type'] . ". Please guide me through the process.");
$waNumber = $country['whatsapp_number'] ?: $settings['whatsapp'];
$waLink = "https://wa.me/" . (str_replace(['+', ' '], '', $waNumber)) . "?text=" . $whatsappMsg;
?>

<style>
    :root {
        --primary: <?php echo $settings['primary_color'] ?? '#27d8e2'; ?>;
        --primary-dark: <?php echo $settings['secondary_color'] ?? '#0099a5'; ?>;
        --primary-gradient: linear-gradient(135deg, <?php echo $settings['primary_color'] ?? '#27d8e2'; ?> 0%, <?php echo $settings['secondary_color'] ?? '#0099a5'; ?> 100%);
        --text-dark: #1e293b;
        --text-muted: #64748b;
        --bg-light: #f8fafc;
        --glass-bg: rgba(255, 255, 255, 0.95);
        --shadow-premium: 0 20px 40px rgba(0,0,0,0.06);
    }

    body { background: var(--bg-light); color: var(--text-dark); }

    /* Hero Section - Matching Landing Page Branding */
    .premium-hero {
        position: relative;
        padding: 160px 0 140px;
        display: flex;
        align-items: center;
        overflow: hidden;
        background: #001a1d; /* Matching header dark base */
        color: white;
    }

    .hero-parallax {
        position: absolute;
        top: 0; left: 0; width: 100%; height: 100%;
        background-image: url('<?php echo $country['hero_image'] ?: 'img/hero-bg.jpg'; ?>');
        background-size: cover;
        background-position: center;
        opacity: 0.4; /* Darker for light text visibility */
        z-index: 1;
    }

    .hero-gradient {
        position: absolute;
        top: 0; left: 0; width: 100%; height: 100%;
        background: linear-gradient(135deg, rgba(0,26,29,0.9) 0%, rgba(0,139,148,0.4) 100%);
        z-index: 2;
    }

    .hero-content-wrapper { position: relative; z-index: 3; text-align: center; max-width: 900px; margin: 0 auto; }

    .country-badge {
        display: inline-flex;
        align-items: center;
        gap: 12px;
        background: rgba(255,255,255,0.1);
        backdrop-filter: blur(10px);
        padding: 10px 25px;
        border-radius: 100px;
        border: 1px solid rgba(255,255,255,0.2);
        margin-bottom: 30px;
        text-transform: uppercase;
        letter-spacing: 2px;
        font-weight: 700;
        font-size: 0.8rem;
    }

    .hero-title {
        font-size: clamp(2.5rem, 6vw, 4rem);
        font-weight: 800;
        line-height: 1.1;
        margin-bottom: 25px;
        color: #ffffff; /* Explicit light text */
    }

    .hero-title span {
        background: var(--primary-gradient);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .hero-subtitle {
        font-size: 1.25rem;
        opacity: 0.9;
        max-width: 700px;
        margin: 0 auto;
        line-height: 1.6;
        color: rgba(255,255,255,0.9); /* Explicit light text */
    }

    /* Stats Bar */
    .stats-float { margin-top: -60px; position: relative; z-index: 10; }
    .stats-card {
        background: #ffffff;
        border-radius: 24px;
        padding: 35px;
        box-shadow: 0 15px 40px rgba(0,0,0,0.1);
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 30px;
        border: 1px solid #f1f5f9;
    }

    .stat-item { padding: 0 20px; border-right: 1px solid #f1f5f9; }
    .stat-item:last-child { border-right: none; }
    .stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 8px; display: block; }
    .stat-value { font-size: 1.1rem; color: var(--text-dark); font-weight: 800; display: block; }

    /* Content Layout */
    .detail-grid { display: grid; grid-template-columns: 1fr 380px; gap: 50px; padding: 80px 0; }

    /* Tabs */
    .premium-tabs {
        background: white;
        padding: 6px;
        border-radius: 100px;
        display: flex;
        gap: 5px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.03);
        margin-bottom: 40px;
        border: 1px solid #f1f5f9;
        max-width: 600px;
    }

    .tab-trigger {
        flex: 1;
        padding: 12px 20px;
        border-radius: 100px;
        border: none;
        background: transparent;
        font-weight: 700;
        color: var(--text-muted);
        cursor: pointer;
        transition: all 0.3s ease;
        font-size: 0.9rem;
    }

    .tab-trigger.active {
        background: var(--primary-gradient);
        color: white;
        box-shadow: 0 8px 15px rgba(39, 216, 226, 0.3);
    }

    /* Cards */
    .req-item-premium {
        background: white;
        padding: 22px;
        border-radius: 20px;
        border: 1px solid #f1f5f9;
        display: flex;
        gap: 15px;
        align-items: center;
        transition: var(--transition);
    }
    .req-item-premium:hover { transform: translateY(-5px); border-color: var(--primary); box-shadow: var(--card-shadow); }
    .req-item-premium i { color: var(--primary); font-size: 1.3rem; }

    /* Sticky Price Widget */
    .sticky-sidebar { position: sticky; top: 100px; }
    .price-widget {
        background: #ffffff;
        color: var(--text-dark); /* Explicit dark text */
        border-radius: 30px;
        padding: 45px 35px;
        text-align: center;
        border: 1px solid #f1f5f9;
        box-shadow: 0 25px 50px rgba(0,0,0,0.08);
    }

    .price-widget .amount { font-size: 3.2rem; font-weight: 800; margin: 15px 0; display: block; color: var(--text-dark); }
    .price-widget .currency { font-size: 1rem; color: var(--text-muted); font-weight: 700; margin-right: 5px; }

    .btn-apply-wa {
        display: block;
        padding: 20px;
        background: var(--primary-gradient);
        color: white;
        text-decoration: none;
        border-radius: 100px;
        font-weight: 800;
        font-size: 1.1rem;
        transition: var(--transition);
        box-shadow: 0 10px 20px rgba(39, 216, 226, 0.2);
    }
    .btn-apply-wa:hover { transform: translateY(-3px); box-shadow: 0 15px 30px rgba(39, 216, 226, 0.3); }

    /* Workflow Steps */
    .step-item-premium { display: flex; gap: 30px; margin-bottom: 40px; }
    .step-num-blob {
        width: 55px; height: 55px;
        background: var(--primary-gradient);
        color: white;
        border-radius: 18px;
        display: flex; align-items: center; justify-content: center;
        font-size: 1.3rem; font-weight: 800; flex-shrink: 0;
        box-shadow: 0 8px 15px rgba(39, 216, 226, 0.2);
    }

    /* FAQ */
    .faq-item-premium { background: white; border-radius: 15px; border: 1px solid #f1f5f9; margin-bottom: 12px; }
    .faq-q-trigger { padding: 22px 25px; font-weight: 700; cursor: pointer; display: flex; justify-content: space-between; align-items: center; color: var(--text-dark); }

    /* Responsive */
    @media (max-width: 1024px) {
        .detail-grid { grid-template-columns: 1fr; }
        .stats-card { grid-template-columns: repeat(2, 1fr); }
    }
    @media (max-width: 768px) {
        .premium-hero { padding: 140px 0 100px; }
        .hero-title { font-size: 2.5rem; }
        .stats-card { padding: 25px; gap: 15px; }
        .stat-item { border-right: none; border-bottom: 1px solid #f1f5f9; padding-bottom: 15px; }
    }
</style>

<!-- Premium Hero -->
<section class="premium-hero">
    <div class="hero-parallax"></div>
    <div class="hero-gradient"></div>
    <div class="container hero-content-wrapper">
        <div class="country-badge">
            <img src="<?php echo $country['flag_icon']; ?>" style="width: 28px; border-radius: 3px;" alt="Flag">
            <span><?php echo $country['name']; ?> Visa</span>
        </div>
        <h1 class="hero-title">Experience <span><?php echo $country['name']; ?></span> <br>Like Never Before</h1>
        <p class="hero-subtitle"><?php echo $country['hero_subtitle'] ?: "We provide premium visa consultancy services with a focus on speed, accuracy, and client satisfaction."; ?></p>
    </div>
</section>

<div class="container">
    <!-- Stats Bar -->
    <div class="stats-float">
        <div class="stats-card">
            <div class="stat-item">
                <span class="stat-label">Processing Time</span>
                <span class="stat-value"><?php echo $country['processing_time']; ?></span>
            </div>
            <div class="stat-item">
                <span class="stat-label">Validity</span>
                <span class="stat-value"><?php echo $country['validity']; ?></span>
            </div>
            <div class="stat-item">
                <span class="stat-label">Stay Period</span>
                <span class="stat-value"><?php echo $country['stay_duration']; ?></span>
            </div>
            <div class="stat-item">
                <span class="stat-label">Visa Type</span>
                <span class="stat-value"><?php echo $country['visa_type']; ?></span>
            </div>
        </div>
    </div>

    <div class="detail-grid">
        <!-- Main Content Column -->
        <div class="main-column">
            <!-- Documentation -->
            <div class="section-block" style="margin-bottom: 70px;">
                <h2 class="section-title">Required <span>Documentation</span></h2>
                <p class="section-subtitle" style="margin-bottom: 35px; text-align: left;">Gather these essential documents to start your application process.</p>
                
                <div class="premium-tabs">
                    <button class="tab-trigger active" onclick="switchTab(event, 'standard')">Standard</button>
                    <button class="tab-trigger" onclick="switchTab(event, 'business')">Business</button>
                    <button class="tab-trigger" onclick="switchTab(event, 'job')">Job Holder</button>
                </div>

                <div id="standard" class="tab-pane active">
                    <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 15px;">
                        <?php mysqli_data_seek($requirements, 0); while($req = mysqli_fetch_assoc($requirements)): if($req['category'] == 'Standard'): ?>
                            <div class="req-item-premium"><i class="fas fa-check-circle"></i> <?php echo $req['requirement']; ?></div>
                        <?php endif; endwhile; ?>
                    </div>
                </div>

                <div id="business" class="tab-pane" style="display: none;">
                    <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 15px;">
                        <?php mysqli_data_seek($requirements, 0); while($req = mysqli_fetch_assoc($requirements)): if($req['category'] == 'Business'): ?>
                            <div class="req-item-premium"><i class="fas fa-briefcase"></i> <?php echo $req['requirement']; ?></div>
                        <?php endif; endwhile; ?>
                    </div>
                </div>

                <div id="job" class="tab-pane" style="display: none;">
                    <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 15px;">
                        <?php mysqli_data_seek($requirements, 0); while($req = mysqli_fetch_assoc($requirements)): if($req['category'] == 'Job'): ?>
                            <div class="req-item-premium"><i class="fas fa-user-tie"></i> <?php echo $req['requirement']; ?></div>
                        <?php endif; endwhile; ?>
                    </div>
                </div>
            </div>

            <!-- Important Notes -->
            <?php if (mysqli_num_rows($notes) > 0): ?>
            <div class="section-block" style="margin-bottom: 70px; background: #fff9f2; border: 1px solid #ffe8cc; padding: 40px; border-radius: 24px;">
                <h3 style="color: #92400e; margin-bottom: 20px; font-weight: 800; display: flex; align-items: center; gap: 12px;">
                    <i class="fas fa-exclamation-circle"></i> Important Guidelines
                </h3>
                <ul style="list-style: none; display: flex; flex-direction: column; gap: 12px;">
                    <?php while($note = mysqli_fetch_assoc($notes)): ?>
                    <li style="color: #854d0e; display: flex; gap: 12px; font-weight: 500; font-size: 0.95rem;">
                        <i class="fas fa-info-circle" style="margin-top: 4px; opacity: 0.6;"></i> <?php echo $note['note']; ?>
                    </li>
                    <?php endwhile; ?>
                </ul>
            </div>
            <?php endif; ?>

            <!-- Workflow -->
            <div class="section-block" style="margin-bottom: 70px;">
                <h2 class="section-title">Application <span>Process</span></h2>
                <p class="section-subtitle" style="margin-bottom: 45px; text-align: left;">Our streamlined 3-step process to get your visa approved.</p>
                <div class="steps-vertical">
                    <?php while($step = mysqli_fetch_assoc($steps)): ?>
                    <div class="step-item-premium">
                        <div class="step-num-blob"><?php echo str_pad($step['step_number'], 2, '0', STR_PAD_LEFT); ?></div>
                        <div>
                            <h3 style="font-size: 1.3rem; font-weight: 800; margin-bottom: 8px; color: var(--text-dark);"><?php echo $step['title']; ?></h3>
                            <p style="color: var(--text-muted); line-height: 1.6;"><?php echo $step['description']; ?></p>
                        </div>
                    </div>
                    <?php endwhile; ?>
                </div>
            </div>

            <!-- FAQs -->
            <?php if (mysqli_num_rows($faqs) > 0): ?>
            <div class="section-block">
                <h2 class="section-title">Frequently <span>Asked</span></h2>
                <p class="section-subtitle" style="margin-bottom: 40px; text-align: left;">Clear answers to common questions about <?php echo $country['name']; ?> visa.</p>
                <div class="faq-container">
                    <?php while($faq = mysqli_fetch_assoc($faqs)): ?>
                    <div class="faq-item-premium">
                        <div class="faq-q-trigger" onclick="toggleFaq(this)">
                            <?php echo $faq['question']; ?>
                            <i class="fas fa-plus" style="font-size: 0.8rem; color: var(--primary);"></i>
                        </div>
                        <div class="faq-a-content" style="max-height: 0; overflow: hidden; transition: all 0.3s ease; padding: 0 25px;">
                            <p style="padding-bottom: 25px; color: var(--text-muted); border-top: 1px solid #f8fafc; padding-top: 20px; font-size: 0.95rem;"><?php echo $faq['answer']; ?></p>
                        </div>
                    </div>
                    <?php endwhile; ?>
                </div>
            </div>
            <?php endif; ?>
        </div>

        <!-- Sidebar Widget -->
        <div class="sidebar-column">
            <div class="sticky-sidebar">
                <div class="price-widget">
                    <span style="text-transform: uppercase; letter-spacing: 2px; font-size: 0.75rem; color: var(--text-muted); font-weight: 700;">Service Fee</span>
                    <span class="amount"><span class="currency">PKR</span><?php echo $country['service_fee'] ?: $country['price']; ?></span>
                    <p style="font-size: 0.85rem; color: var(--text-muted); margin-bottom: 35px;">*Taxes & embassy fees excluded</p>
                    
                    <h4 style="font-size: 1.1rem; font-weight: 800; margin-bottom: 20px; color: var(--text-dark);">Ready to Proceed?</h4>
                    <a href="<?php echo $waLink; ?>" target="_blank" class="btn-apply-wa">
                        <i class="fab fa-whatsapp" style="margin-right: 12px; font-size: 1.3rem;"></i> Start Application
                    </a>
                    <a href="tel:<?php echo $country['whatsapp_number'] ?: '923401234567'; ?>" style="display: block; margin-top: 25px; color: var(--text-dark); text-decoration: none; font-weight: 700; font-size: 0.95rem;">
                        <i class="fas fa-phone-alt" style="margin-right: 8px; color: var(--primary);"></i> Talk to an Expert
                    </a>
                </div>

                <div style="margin-top: 30px; display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
                    <div style="background: white; padding: 25px; border-radius: 20px; text-align: center; border: 1px solid #f1f5f9;">
                        <i class="fas fa-check-shield" style="color: var(--primary); font-size: 1.8rem; margin-bottom: 12px; display: block;"></i>
                        <div style="font-size: 0.75rem; font-weight: 800; color: var(--text-dark);">SECURE PROCESS</div>
                    </div>
                    <div style="background: white; padding: 25px; border-radius: 20px; text-align: center; border: 1px solid #f1f5f9;">
                        <i class="fas fa-user-check" style="color: var(--primary); font-size: 1.8rem; margin-bottom: 12px; display: block;"></i>
                        <div style="font-size: 0.75rem; font-weight: 800; color: var(--text-dark);">EXPERT GUIDANCE</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Final CTA -->
<section style="padding: 120px 0; background: var(--primary-gradient); color: white; text-align: center; margin-top: 40px; position: relative; overflow: hidden;">
    <div class="container" style="position: relative; z-index: 2;">
        <h2 style="font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; margin-bottom: 30px;">Let’s Get Your <span>Visa Approved</span></h2>
        <p style="font-size: 1.25rem; opacity: 0.9; max-width: 700px; margin: 0 auto 50px;">Join thousands of satisfied travelers who chose <?= htmlspecialchars($settings['site_name'] ?? 'CFD Travels') ?> for their international journeys.</p>
        <a href="<?php echo $waLink; ?>" style="display: inline-block; padding: 20px 60px; background: #ffffff; color: var(--primary-dark); text-decoration: none; border-radius: 100px; font-weight: 800; font-size: 1.1rem; box-shadow: 0 15px 35px rgba(0,0,0,0.1);">Start Your Application</a>
    </div>
</section>

<script>
    function switchTab(evt, tabId) {
        const panes = document.querySelectorAll('.tab-pane');
        const triggers = document.querySelectorAll('.tab-trigger');
        panes.forEach(p => p.style.display = 'none');
        triggers.forEach(t => t.classList.remove('active'));
        document.getElementById(tabId).style.display = 'block';
        evt.currentTarget.classList.add('active');
    }

    function toggleFaq(trigger) {
        const content = trigger.nextElementSibling;
        const icon = trigger.querySelector('i');
        if (content.style.maxHeight && content.style.maxHeight !== '0px') {
            content.style.maxHeight = '0px';
            icon.classList.replace('fa-minus', 'fa-plus');
        } else {
            document.querySelectorAll('.faq-a-content').forEach(c => c.style.maxHeight = '0px');
            document.querySelectorAll('.faq-q-trigger i').forEach(i => i.classList.replace('fa-minus', 'fa-plus'));
            content.style.maxHeight = content.scrollHeight + 'px';
            icon.classList.replace('fa-plus', 'fa-minus');
        }
    }

    // Smooth Scroll
    window.addEventListener('scroll', () => {
        const parallax = document.querySelector('.hero-parallax');
        let offset = window.pageYOffset;
        if(parallax) parallax.style.transform = `translateY(${offset * 0.4}px)`;
    });
</script>

<?php include 'includes/footer.php'; ?>
