<?php 
require_once __DIR__ . '/includes/pdo.php';
include 'includes/url-helper.php';

// Get current city and service from URL parameters
$citySlug    = $_GET['city'] ?? '';
$serviceSlug = $_GET['service'] ?? '';

// Validate parameters
if (!$citySlug || !$serviceSlug) {
    header("Location: services.php");
    exit;
}

// If accessed via old URL format (direct city-service.php), redirect to SEO-friendly URL
if (isset($_GET['city']) && isset($_GET['service']) && 
    strpos($_SERVER['REQUEST_URI'], 'city-service.php') !== false && 
    strpos($_SERVER['REQUEST_URI'], '?') !== false) {
    redirectToSeoUrl($citySlug, $serviceSlug);
}

// Fetch the current page data
$stmt = $pdo->prepare("
    SELECT cs.*, c.name as city_name, c.slug as city_slug, s.name as service_name, s.slug as service_slug
    FROM city_service cs
    JOIN cities c ON cs.city_id = c.id
    JOIN services s ON cs.service_id = s.id
    WHERE c.slug = ? AND s.slug = ?
");
$stmt->execute([$citySlug, $serviceSlug]);
$page = $stmt->fetch();

if (!$page) {
    http_response_code(404);
    header("Location: services.php");
    exit;
}

// Enhanced SEO variables
$serviceName = $page['service_name'];
$cityName = $page['city_name'];
$currentYear = date('Y');

// Advanced SEO title and description
$pageTitle = $page['seo_title'] ?: "Best $serviceName Services in $cityName $currentYear | Finggu Infotech";
$pageDescription = $page['seo_description'] ?: "★★★★★ Top-rated $serviceName services in $cityName. 500+ projects completed. Get free consultation. Call +91-8655442429. Expert team, affordable prices.";
$pageKeywords = strtolower($serviceName) . " " . strtolower($cityName) . ", " . strtolower($serviceName) . " services " . strtolower($cityName) . ", " . strtolower($serviceName) . " company " . strtolower($cityName) . ", best " . strtolower($serviceName) . " " . strtolower($cityName) . ", affordable " . strtolower($serviceName) . " " . strtolower($cityName);

// Get related services for internal linking
$relatedServices = $pdo->prepare("
    SELECT s.slug, s.name 
    FROM city_service cs
    JOIN services s ON cs.service_id = s.id
    JOIN cities c ON cs.city_id = c.id
    WHERE c.slug = ? AND s.slug != ?
    ORDER BY s.name
    LIMIT 6
");
$relatedServices->execute([$citySlug, $serviceSlug]);
$relatedServicesData = $relatedServices->fetchAll();

// Get same service in nearby cities
$nearbyCities = $pdo->prepare("
    SELECT c.slug, c.name 
    FROM city_service cs
    JOIN cities c ON cs.city_id = c.id
    JOIN services s ON cs.service_id = s.id
    WHERE s.slug = ? AND c.slug != ?
    ORDER BY c.name
    LIMIT 8
");
$nearbyCities->execute([$serviceSlug, $citySlug]);
$nearbyCitiesData = $nearbyCities->fetchAll();

include 'includes/header.php'; 
?>

<!-- Enhanced SEO Meta Tags -->
<meta name="robots" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1">
<meta name="googlebot" content="index, follow">
<link rel="canonical" href="<?= getCanonicalUrl($citySlug, $serviceSlug) ?>">

<!-- Open Graph Enhanced -->
<meta property="og:locale" content="en_US">
<meta property="og:type" content="website">
<meta property="og:title" content="<?= htmlspecialchars($pageTitle) ?>">
<meta property="og:description" content="<?= htmlspecialchars($pageDescription) ?>">
<meta property="og:url" content="<?= getOgUrl($citySlug, $serviceSlug) ?>">
<meta property="og:site_name" content="Finggu Infotech">
<meta property="og:image" content="<?php echo $baseUrl; ?>/assets/images/<?= $serviceSlug ?>-<?= $citySlug ?>.jpg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">

<!-- Twitter Card Enhanced -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="<?= htmlspecialchars($pageTitle) ?>">
<meta name="twitter:description" content="<?= htmlspecialchars($pageDescription) ?>">
<meta name="twitter:image" content="<?php echo $baseUrl; ?>/assets/images/<?= $serviceSlug ?>-<?= $citySlug ?>.jpg">

<!-- Structured Data - LocalBusiness + Service -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "LocalBusiness",
  "name": "Finggu Infotech - <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>",
  "image": "<?php echo $baseUrl; ?>/assets/images/logo.png",
  "description": "<?= htmlspecialchars($pageDescription) ?>",
  "url": "<?= getCityServiceUrl($citySlug, $serviceSlug) ?>",
  "telephone": "+91-8655442429",
  "email": "info@fingguinfotech.com",
  "address": {
    "@type": "PostalAddress",
    "streetAddress": "A-402, Channur Bhavan CHS., Ghanshyam Near Station",
    "addressLocality": "<?= htmlspecialchars($cityName) ?>",
    "addressRegion": "Maharashtra", 
    "postalCode": "421202",
    "addressCountry": "IN"
  },
  "geo": {
    "@type": "GeoCoordinates",
    "latitude": "19.2183",
    "longitude": "73.0856"
  },
  "openingHoursSpecification": {
    "@type": "OpeningHoursSpecification",
    "dayOfWeek": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
    "opens": "09:00",
    "closes": "20:00"
  },
  "priceRange": "₹₹",
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "4.9",
    "reviewCount": "200",
    "bestRating": "5",
    "worstRating": "1"
  },
  "review": [
    {
      "@type": "Review",
      "author": {
        "@type": "Person",
        "name": "Rahul Sharma"
      },
      "reviewRating": {
        "@type": "Rating",
        "ratingValue": "5",
        "bestRating": "5"
      },
      "reviewBody": "Excellent <?= htmlspecialchars($serviceName) ?> services in <?= htmlspecialchars($cityName) ?>. Professional team and great results!"
    }
  ],
  "hasOfferCatalog": {
    "@type": "OfferCatalog",
    "name": "<?= htmlspecialchars($serviceName) ?> Services",
    "itemListElement": [
      {
        "@type": "Offer",
        "itemOffered": {
          "@type": "Service",
          "name": "<?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>",
          "description": "Professional <?= htmlspecialchars($serviceName) ?> services in <?= htmlspecialchars($cityName) ?>"
        }
      }
    ]
  },
  "areaServed": {
    "@type": "City",
    "name": "<?= htmlspecialchars($cityName) ?>"
  },
  "serviceType": "<?= htmlspecialchars($serviceName) ?>",
  "sameAs": [
    "https://www.facebook.com/fingguinfotech",
    "https://www.linkedin.com/company/finggu-infotech",
    "https://www.instagram.com/fingguinfotech"
  ]
}
</script>

<!-- Breadcrumb Structured Data -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {
      "@type": "ListItem",
      "position": 1,
      "name": "Home",
      "item": "<?php echo $baseUrl; ?>"
    },
    {
      "@type": "ListItem", 
      "position": 2,
      "name": "Services",
      "item": "<?php echo $baseUrl; ?>/services.php"
    },
    {
      "@type": "ListItem",
      "position": 3,
      "name": "<?= htmlspecialchars($cityName) ?>",
      "item": "<?= getCityServicesUrl($citySlug) ?>"
    },
    {
      "@type": "ListItem",
      "position": 4,
      "name": "<?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>",
      "item": "<?= getCityServiceUrl($citySlug, $serviceSlug) ?>"
    }
  ]
}
</script>

<!-- FAQ Structured Data -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "What is the cost of <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "The cost of <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?> varies based on project requirements. Contact Finggu Infotech at +91-8655442429 for a free consultation and customized quote."
      }
    },
    {
      "@type": "Question", 
      "name": "How long does <?= htmlspecialchars($serviceName) ?> take in <?= htmlspecialchars($cityName) ?>?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "<?= htmlspecialchars($serviceName) ?> timeline in <?= htmlspecialchars($cityName) ?> depends on project scope. Typically ranges from 2-8 weeks. We provide detailed timelines during consultation."
      }
    },
    {
      "@type": "Question",
      "name": "Why choose Finggu Infotech for <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>?",
      "acceptedAnswer": {
        "@type": "Answer", 
        "text": "Finggu Infotech offers expert <?= htmlspecialchars($serviceName) ?> services in <?= htmlspecialchars($cityName) ?> with 8+ years experience, 500+ completed projects, 24/7 support, and competitive pricing."
      }
    }
  ]
}
</script>

<!-- Breadcrumb Navigation -->
<nav class="bg-gray-50 py-3 " aria-label="Breadcrumb">
    <div class="container mx-auto px-4">
        <ol class="flex items-center space-x-2 text-sm">
            <?php 
            $breadcrumbs = generateBreadcrumbs($citySlug, $serviceSlug, $cityName, $serviceName);
            $lastIndex = count($breadcrumbs) - 1;
            
            foreach ($breadcrumbs as $index => $crumb): 
            ?>
                <li>
                    <?php if ($index === $lastIndex): ?>
                        <span class="text-gray-600"><?= htmlspecialchars($crumb['name']) ?></span>
                    <?php else: ?>
                        <a href="<?= $crumb['url'] ?>" class="text-blue-600 hover:text-blue-800"><?= htmlspecialchars($crumb['name']) ?></a>
                    <?php endif; ?>
                </li>
                <?php if ($index < $lastIndex): ?>
                    <li><span class="text-gray-400">/</span></li>
                <?php endif; ?>
            <?php endforeach; ?>
        </ol>
    </div>
</nav>

<!-- Hero Section -->
<section class="relative pt-16 pb-20 bg-gradient-to-r from-red-600 to-red-700 text-white overflow-hidden">
    <div class="container mx-auto px-4 relative z-10">
        <div class="text-center max-w-5xl mx-auto">
            <!-- Main Heading with SEO optimization -->
            <h1 class="text-4xl md:text-5xl lg:text-6xl font-bold leading-tight mb-6">
                Best <?= htmlspecialchars($serviceName) ?> Services in <?= htmlspecialchars($cityName) ?> <?= $currentYear ?>
            </h1>
            
            <!-- Enhanced description with keywords -->
            <p class="text-xl text-red-100 mb-6 max-w-4xl mx-auto">
                ⭐ Top-rated <?= htmlspecialchars($serviceName) ?> company in <?= htmlspecialchars($cityName) ?> with 500+ successful projects. 
                Get professional <?= htmlspecialchars($serviceName) ?> services at affordable prices. Free consultation available!
            </p>
            
            <!-- Trust indicators -->
            <div class="flex flex-wrap justify-center items-center gap-6 mb-8 text-red-100">
                <div class="flex items-center">
                    <i class="fas fa-star text-yellow-400 mr-1"></i>
                    <span class="font-semibold">4.9/5 Rating</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-users mr-2"></i>
                    <span>500+ Happy Clients</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-clock mr-2"></i>
                    <span>8+ Years Experience</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-headset mr-2"></i>
                    <span>24/7 Support</span>
                </div>
            </div>
            
            <!-- CTA Buttons -->
            <div class="flex flex-col sm:flex-row gap-4 justify-center mb-8">
                <a href="http://finggu.com/contact.php" class="bg-white hover:bg-gray-100 text-red-600 px-8 py-4 rounded-md font-semibold inline-block text-center transition-all transform hover:-translate-y-1 shadow-lg">
                    <i class="fas fa-gift mr-2"></i>Get FREE Consultation
                </a>
                <a href="tel:+918655442429" class="bg-white/10 hover:bg-white/20 text-white border border-white/30 px-8 py-4 rounded-md font-medium inline-block text-center transition-all transform hover:-translate-y-1">
                    <i class="fas fa-phone-alt mr-2"></i>Call: +91-8655442429
                </a>
            </div>
            
            <!-- Quick benefits -->
            <div class="grid grid-cols-2 md:grid-cols-4 gap-4 text-center text-red-100 text-sm">
                <div>✓ Free Consultation</div>
                <div>✓ Affordable Pricing</div>
                <div>✓ Quick Delivery</div>
                <div>✓ 100% Satisfaction</div>
            </div>
        </div>
    </div>
</section>

<!-- Main Content -->
<section class="py-16 bg-white">
    <div class="container mx-auto px-4">
        <div class="max-w-6xl mx-auto">
            <div class="grid lg:grid-cols-3 gap-12">
                <!-- Main Content -->
                <div class="lg:col-span-2">
                    <!-- Service Overview -->
                    <div class="mb-12">
                        <h2 class="text-3xl font-bold mb-6">Professional <?= htmlspecialchars($serviceName) ?> Services in <?= htmlspecialchars($cityName) ?></h2>
                        <div class="prose prose-lg max-w-none text-gray-700 leading-relaxed">
                            <?= nl2br(htmlspecialchars($page['content'])) ?>
                        </div>
                    </div>
                    
                    <!-- Why Choose Us -->
                    <div class="mb-12 bg-gray-50 rounded-xl p-8">
                        <h3 class="text-2xl font-bold mb-6">Why Choose Finggu Infotech for <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>?</h3>
                        <div class="grid md:grid-cols-2 gap-6">
                            <div class="flex items-start">
                                <div class="bg-red-100 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-medal text-red-600"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-2">8+ Years Experience</h4>
                                    <p class="text-gray-600 text-sm">Proven expertise in <?= htmlspecialchars($serviceName) ?> with hundreds of successful projects in <?= htmlspecialchars($cityName) ?>.</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-red-100 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-users text-red-600"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-2">500+ Happy Clients</h4>
                                    <p class="text-gray-600 text-sm">Trusted by businesses across <?= htmlspecialchars($cityName) ?> for reliable <?= htmlspecialchars($serviceName) ?> solutions.</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-red-100 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-rupee-sign text-red-600"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-2">Affordable Pricing</h4>
                                    <p class="text-gray-600 text-sm">Competitive rates for <?= htmlspecialchars($serviceName) ?> services in <?= htmlspecialchars($cityName) ?> without compromising quality.</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-red-100 p-2 rounded-lg mr-4 flex-shrink-0">
                                    <i class="fas fa-headset text-red-600"></i>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-2">24/7 Support</h4>
                                    <p class="text-gray-600 text-sm">Round-the-clock technical support for all <?= htmlspecialchars($serviceName) ?> projects in <?= htmlspecialchars($cityName) ?>.</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Process -->
                    <div class="mb-12">
                        <h3 class="text-2xl font-bold mb-6">Our <?= htmlspecialchars($serviceName) ?> Process in <?= htmlspecialchars($cityName) ?></h3>
                        <div class="space-y-6">
                            <div class="flex items-start">
                                <div class="bg-blue-100 text-blue-600 w-8 h-8 rounded-full flex items-center justify-center font-bold mr-4 flex-shrink-0">1</div>
                                <div>
                                    <h4 class="font-semibold mb-2">Consultation & Analysis</h4>
                                    <p class="text-gray-600">We understand your <?= htmlspecialchars($serviceName) ?> requirements and analyze your business needs in <?= htmlspecialchars($cityName) ?>.</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-blue-100 text-blue-600 w-8 h-8 rounded-full flex items-center justify-center font-bold mr-4 flex-shrink-0">2</div>
                                <div>
                                    <h4 class="font-semibold mb-2">Strategy & Planning</h4>
                                    <p class="text-gray-600">Create a customized <?= htmlspecialchars($serviceName) ?> strategy tailored for your <?= htmlspecialchars($cityName) ?> market.</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-blue-100 text-blue-600 w-8 h-8 rounded-full flex items-center justify-center font-bold mr-4 flex-shrink-0">3</div>
                                <div>
                                    <h4 class="font-semibold mb-2">Implementation</h4>
                                    <p class="text-gray-600">Execute the <?= htmlspecialchars($serviceName) ?> project with regular updates and quality checks.</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-blue-100 text-blue-600 w-8 h-8 rounded-full flex items-center justify-center font-bold mr-4 flex-shrink-0">4</div>
                                <div>
                                    <h4 class="font-semibold mb-2">Launch & Support</h4>
                                    <p class="text-gray-600">Launch your project and provide ongoing support for your <?= htmlspecialchars($serviceName) ?> needs.</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Sidebar -->
                <div class="lg:col-span-1">
                    <!-- Contact Card -->
                    <div class="bg-red-50 rounded-xl p-6 mb-8 sticky top-8">
                        <h3 class="text-xl font-bold mb-4 text-red-800">Get Free Consultation</h3>
                        <p class="text-red-700 mb-4 text-sm">Ready to start your <?= htmlspecialchars($serviceName) ?> project in <?= htmlspecialchars($cityName) ?>?</p>
                        <div class="space-y-3">
                            <a href="tel:+918655442429" class="block bg-red-600 hover:bg-red-700 text-white text-center py-3 px-4 rounded-md font-medium transition-colors">
                                <i class="fas fa-phone-alt mr-2"></i>Call: +91-8655442429
                            </a>
                            <a href="mailto:info@fingguinfotech.com" class="block bg-white hover:bg-gray-50 text-red-600 border border-red-200 text-center py-3 px-4 rounded-md font-medium transition-colors">
                                <i class="fas fa-envelope mr-2"></i>Email Us
                            </a>
                            <a href="https://wa.me/918655442429?text=Hi, I need <?= urlencode($serviceName) ?> services in <?= urlencode($cityName) ?>" target="_blank" class="block bg-green-500 hover:bg-green-600 text-white text-center py-3 px-4 rounded-md font-medium transition-colors">
                                <i class="fab fa-whatsapp mr-2"></i>WhatsApp
                            </a>
                        </div>
                        
                        <!-- Quick Info -->
                        <div class="mt-6 pt-6 border-t border-red-200">
                            <div class="space-y-2 text-sm text-red-700">
                                <div class="flex items-center">
                                    <i class="fas fa-clock w-4 mr-2"></i>
                                    <span>Response within 2 hours</span>
                                </div>
                                <div class="flex items-center">
                                    <i class="fas fa-gift w-4 mr-2"></i>
                                    <span>Free consultation</span>
                                </div>
                                <div class="flex items-center">
                                    <i class="fas fa-shield-alt w-4 mr-2"></i>
                                    <span>100% satisfaction guarantee</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Service Areas -->
                    <div class="bg-gray-50 rounded-xl p-6">
                        <h4 class="font-bold mb-4">Service Areas in <?= htmlspecialchars($cityName) ?></h4>
                        <div class="text-sm text-gray-600 space-y-1">
                            <?php
                            // Generate some common area names for the city
                            $areas = [
                                "Central " . $cityName,
                                "North " . $cityName, 
                                "South " . $cityName,
                                "East " . $cityName,
                                "West " . $cityName,
                                $cityName . " CBD",
                                "Greater " . $cityName
                            ];
                            foreach ($areas as $area) {
                                echo "<div>• " . htmlspecialchars($area) . "</div>";
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- FAQ Section -->
<section class="py-16 bg-white">
    <div class="container mx-auto px-4">
        <div class="max-w-4xl mx-auto">
            <h2 class="text-3xl font-bold text-center mb-12">Frequently Asked Questions - <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?></h2>
            
            <div class="space-y-6">
                <div class="border border-gray-200 rounded-xl overflow-hidden">
                    <button class="faq-toggle w-full flex justify-between items-center p-6 text-left hover:bg-gray-50 transition-colors">
                        <h3 class="text-lg font-semibold">What is the cost of <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>?</h3>
                        <svg class="w-5 h-5 text-red-600 transform transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                        </svg>
                    </button>
                    <div class="faq-content px-6 pb-6 hidden">
                        <p class="text-gray-600">The cost of <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?> varies based on project requirements, complexity, and timeline. We offer competitive pricing starting from ₹15,000. Contact us at +91-8655442429 for a free consultation and customized quote for your <?= htmlspecialchars($serviceName) ?> project.</p>
                    </div>
                </div>

                <div class="border border-gray-200 rounded-xl overflow-hidden">
                    <button class="faq-toggle w-full flex justify-between items-center p-6 text-left hover:bg-gray-50 transition-colors">
                        <h3 class="text-lg font-semibold">How long does <?= htmlspecialchars($serviceName) ?> take in <?= htmlspecialchars($cityName) ?>?</h3>
                        <svg class="w-5 h-5 text-red-600 transform transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                        </svg>
                    </button>
                    <div class="faq-content px-6 pb-6 hidden">
                        <p class="text-gray-600"><?= htmlspecialchars($serviceName) ?> timeline in <?= htmlspecialchars($cityName) ?> typically ranges from 2-8 weeks depending on project scope and complexity. Simple projects can be completed in 2-3 weeks, while complex solutions may take 6-8 weeks. We provide detailed project timelines during our initial consultation.</p>
                    </div>
                </div>

                <div class="border border-gray-200 rounded-xl overflow-hidden">
                    <button class="faq-toggle w-full flex justify-between items-center p-6 text-left hover:bg-gray-50 transition-colors">
                        <h3 class="text-lg font-semibold">Why choose Finggu Infotech for <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>?</h3>
                        <svg class="w-5 h-5 text-red-600 transform transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                        </svg>
                    </button>
                    <div class="faq-content px-6 pb-6 hidden">
                        <p class="text-gray-600">Finggu Infotech is the leading <?= htmlspecialchars($serviceName) ?> company in <?= htmlspecialchars($cityName) ?> with 8+ years of experience, 500+ completed projects, 4.9/5 client rating, 24/7 support, competitive pricing, and 100% satisfaction guarantee. We understand the local <?= htmlspecialchars($cityName) ?> market and deliver results that drive business growth.</p>
                    </div>
                </div>

                <div class="border border-gray-200 rounded-xl overflow-hidden">
                    <button class="faq-toggle w-full flex justify-between items-center p-6 text-left hover:bg-gray-50 transition-colors">
                        <h3 class="text-lg font-semibold">Do you provide <?= htmlspecialchars($serviceName) ?> support after project completion in <?= htmlspecialchars($cityName) ?>?</h3>
                        <svg class="w-5 h-5 text-red-600 transform transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                        </svg>
                    </button>
                    <div class="faq-content px-6 pb-6 hidden">
                        <p class="text-gray-600">Yes, we provide comprehensive post-project support for all <?= htmlspecialchars($serviceName) ?> clients in <?= htmlspecialchars($cityName) ?>. This includes 3 months free support, regular maintenance, updates, and 24/7 technical assistance. We also offer extended support packages for long-term partnerships.</p>
                    </div>
                </div>

                <div class="border border-gray-200 rounded-xl overflow-hidden">
                    <button class="faq-toggle w-full flex justify-between items-center p-6 text-left hover:bg-gray-50 transition-colors">
                        <h3 class="text-lg font-semibold">Can I get a free consultation for <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>?</h3>
                        <svg class="w-5 h-5 text-red-600 transform transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                        </svg>
                    </button>
                    <div class="faq-content px-6 pb-6 hidden">
                        <p class="text-gray-600">Absolutely! We offer free consultation for all <?= htmlspecialchars($serviceName) ?> inquiries in <?= htmlspecialchars($cityName) ?>. Our experts will analyze your requirements, provide recommendations, and create a customized proposal. Call +91-8655442429 or fill our contact form to schedule your free consultation today.</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Related Services -->
<section class="py-16 bg-gray-50">
    <div class="container mx-auto px-4">
        <div class="max-w-6xl mx-auto">
            <div class="grid md:grid-cols-2 gap-12">
                <!-- Other Services in Same City -->
                <div>
                    <h3 class="text-2xl font-bold mb-6">Other Digital Services in <?= htmlspecialchars($cityName) ?></h3>
                    <p class="text-gray-600 mb-6">Explore our complete range of digital solutions available in <?= htmlspecialchars($cityName) ?></p>
                    <div class="space-y-3">
                        <?php foreach ($relatedServicesData as $row): ?>
                            <a href='<?= getCityServiceUrl($citySlug, $row['slug']) ?>' class='block p-4 bg-white rounded-lg shadow-sm hover:shadow-md transition-all hover:-translate-y-1 border-l-4 border-red-500 group'>
                                <h4 class='font-semibold text-gray-900 group-hover:text-red-600 transition-colors'><?= htmlspecialchars($row['name']) ?> in <?= htmlspecialchars($cityName) ?></h4>
                                <p class='text-sm text-gray-600 mt-1'>Professional <?= htmlspecialchars($row['name']) ?> services with expert team and proven results in <?= htmlspecialchars($cityName) ?></p>
                                <div class="text-xs text-red-600 mt-2 font-medium">Learn More →</div>
                            </a>
                        <?php endforeach; ?>
                        
                        <div class="mt-6 text-center">
                            <a href="<?= getCityServicesUrl($citySlug) ?>" class="inline-flex items-center text-red-600 hover:text-red-800 font-medium">
                                View All Services in <?= htmlspecialchars($cityName) ?>
                                <i class="fas fa-arrow-right ml-2"></i>
                            </a>
                        </div>
                    </div>
                </div>

                <!-- Same Service in Other Cities -->
                <div>
                    <h3 class="text-2xl font-bold mb-6"><?= htmlspecialchars($serviceName) ?> in Other Cities</h3>
                    <p class="text-gray-600 mb-6">We provide <?= htmlspecialchars($serviceName) ?> services across major Indian cities</p>
                    <div class="space-y-3">
                        <?php foreach ($nearbyCitiesData as $row): ?>
                            <a href='<?= getCityServiceUrl($row['slug'], $serviceSlug) ?>' class='block p-4 bg-white rounded-lg shadow-sm hover:shadow-md transition-all hover:-translate-y-1 border-l-4 border-blue-500 group'>
                                <h4 class='font-semibold text-gray-900 group-hover:text-blue-600 transition-colors'><?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($row['name']) ?></h4>
                                <p class='text-sm text-gray-600 mt-1'>Get expert <?= htmlspecialchars($serviceName) ?> solutions in <?= htmlspecialchars($row['name']) ?> with local market expertise</p>
                                <div class="text-xs text-blue-600 mt-2 font-medium">Explore →</div>
                            </a>
                        <?php endforeach; ?>
                        
                        <div class="mt-6 text-center">
                            <a href="<?= getServiceCitiesUrl($serviceSlug) ?>" class="inline-flex items-center text-blue-600 hover:text-blue-800 font-medium">
                                View <?= htmlspecialchars($serviceName) ?> in All Cities
                                <i class="fas fa-arrow-right ml-2"></i>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- CTA Section -->
<section class="py-16 bg-gradient-to-r from-red-600 to-red-700 text-white">
    <div class="container mx-auto px-4 text-center">
        <div class="max-w-4xl mx-auto">
            <h2 class="text-3xl md:text-4xl font-bold mb-6">
                Need <?= htmlspecialchars($page['service_name']) ?> in <?= htmlspecialchars($page['city_name']) ?>?
            </h2>
            <p class="text-xl mb-8 max-w-3xl mx-auto">
                Contact Finggu Infotech today and let our experts help you achieve your digital goals with professional <?= htmlspecialchars($page['service_name']) ?> services.
            </p>
            <div class="flex flex-col sm:flex-row justify-center gap-4">
                <a href="contact.php" class="bg-white hover:bg-gray-100 text-red-600 font-semibold py-3 px-8 rounded-md transition-colors inline-flex items-center justify-center">
                    Get Started Today
                </a>
                <a href="tel:+918655442429" class="bg-transparent hover:bg-red-700 text-white border-2 border-white font-semibold py-3 px-8 rounded-md transition-colors inline-flex items-center justify-center">
                    <i class="fas fa-phone-alt mr-2"></i> +91 86554 42429
                </a>
            </div>
        </div>
    </div>
</section>

<!-- Additional SEO Content -->
<section class="py-12 bg-white border-t">
    <div class="container mx-auto px-4">
        <div class="max-w-4xl mx-auto text-center">
            <h2 class="text-2xl font-bold mb-6">About <?= htmlspecialchars($serviceName) ?> Services in <?= htmlspecialchars($cityName) ?></h2>
            <div class="text-gray-600 leading-relaxed">
                <p class="mb-4">
                    Finggu Infotech is the leading <?= htmlspecialchars($serviceName) ?> company in <?= htmlspecialchars($cityName) ?>, serving businesses across all areas including Central <?= htmlspecialchars($cityName) ?>, North <?= htmlspecialchars($cityName) ?>, South <?= htmlspecialchars($cityName) ?>, East <?= htmlspecialchars($cityName) ?>, and West <?= htmlspecialchars($cityName) ?>. Our expert team has successfully delivered 500+ <?= htmlspecialchars($serviceName) ?> projects with a 4.9/5 client satisfaction rating.
                </p>
                <p class="mb-4">
                    We understand the unique business landscape of <?= htmlspecialchars($cityName) ?> and provide customized <?= htmlspecialchars($serviceName) ?> solutions that drive real results. Whether you're a startup, SME, or enterprise in <?= htmlspecialchars($cityName) ?>, our affordable <?= htmlspecialchars($serviceName) ?> services are designed to help you achieve your digital goals.
                </p>
                <p>
                    Contact us today at +91-8655442429 for a free consultation and discover why businesses in <?= htmlspecialchars($cityName) ?> trust Finggu Infotech for their <?= htmlspecialchars($serviceName) ?> needs. We offer competitive pricing, quick turnaround, and 100% satisfaction guarantee.
                </p>
            </div>
        </div>
    </div>
</section>

<script>
// FAQ Toggle Functionality
document.addEventListener('DOMContentLoaded', function() {
    const faqToggles = document.querySelectorAll('.faq-toggle');
    
    faqToggles.forEach(toggle => {
        toggle.addEventListener('click', function() {
            const content = this.nextElementSibling;
            const icon = this.querySelector('svg');
            
            // Toggle content
            content.classList.toggle('hidden');
            
            // Toggle icon rotation
            icon.classList.toggle('rotate-180');
            
            // Close other open FAQs
            faqToggles.forEach(otherToggle => {
                if (otherToggle !== toggle) {
                    otherToggle.nextElementSibling.classList.add('hidden');
                    otherToggle.querySelector('svg').classList.remove('rotate-180');
                }
            });
        });
    });
});

// SEO Enhancements
document.addEventListener('DOMContentLoaded', function() {
    // Add click tracking for internal links
    const internalLinks = document.querySelectorAll('a[href*="city-service.php"], a[href*="city-services.php"]');
    internalLinks.forEach(link => {
        link.addEventListener('click', function() {
            // Track internal link clicks for SEO analytics
            if (typeof gtag !== 'undefined') {
                gtag('event', 'click', {
                    'event_category': 'Internal Link',
                    'event_label': this.href
                });
            }
        });
    });
    
    // Lazy load images for better performance
    const images = document.querySelectorAll('img[data-src]');
    const imageObserver = new IntersectionObserver((entries, observer) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                const img = entry.target;
                img.src = img.dataset.src;
                img.classList.remove('lazy');
                imageObserver.unobserve(img);
            }
        });
    });
    
    images.forEach(img => imageObserver.observe(img));
});
</script>

<?php include 'includes/footer.html'; ?>
