<?php 
require_once __DIR__ . '/includes/pdo.php';
include 'includes/url-helper.php';
include 'includes/content-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 = $page['seo_keywords'] ?: (strtolower($serviceName) . " " . strtolower($cityName) . ", " . strtolower($serviceName) . " services " . strtolower($cityName) . ", " . strtolower($serviceName) . " company " . strtolower($cityName) . ", best " . strtolower($serviceName) . " " . strtolower($cityName) . ", affordable " . strtolower($serviceName) . " " . strtolower($cityName));

// Determine best Open Graph image with fallbacks
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
$host = 'www.finggu.com';
$baseUrl = $protocol . '://' . $host;
$ogCandidates = [
    "assets/images/{$serviceSlug}-{$citySlug}.jpg",
    "assets/images/{$serviceSlug}-{$citySlug}.png",
    "assets/images/{$serviceSlug}.jpg",
    "assets/images/{$serviceSlug}.png",
    "assets/images/hero.png",
];
$ogImageRel = 'assets/images/hero.png';
foreach ($ogCandidates as $rel) {
    if (file_exists(__DIR__ . '/' . $rel)) { $ogImageRel = $rel; break; }
}
$ogImageUrl = $baseUrl . '/' . $ogImageRel;

// 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="<?= htmlspecialchars($ogImageUrl) ?>">
<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="<?= htmlspecialchars($ogImageUrl) ?>">

<!-- 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@finggu.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">
                ⭐ Trusted <?= htmlspecialchars($serviceName) ?> experts in <?= htmlspecialchars($cityName) ?>. 
                Delivering high-performance <?= strtolower(htmlspecialchars($serviceName)) ?> solutions starting from affordable rates.
            </p>
            
            <!-- Trust indicators - Dynamic Variation -->
            <?php 
            $seed = crc32($serviceName . $cityName);
            $clients = 450 + ($seed % 100);
            $years = 7 + ($seed % 5);
            $rating = 4.7 + (($seed % 3) / 10);
            ?>
            <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"><?= $rating ?>/5 Rating</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-users mr-2"></i>
                    <span><?= $clients ?>+ Happy Clients</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-clock mr-2"></i>
                    <span><?= $years ?>+ Years Experience</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-headset mr-2"></i>
                    <span>Dedicated 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 Now
                </a>
            </div>
            
            <!-- Quick benefits -->
            <div class="grid grid-cols-2 md:grid-cols-4 gap-4 text-center text-red-100 text-sm">
                <div>✓ Expert Team</div>
                <div>✓ Custom Solutions</div>
                <div>✓ Timely Delivery</div>
                <div>✓ Local Expertise</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">
                        <?php if (strpos($page['content'], 'AI_FULL_CONTENT') !== false): ?>
                            <!-- Full AI Enhanced Content Mode -->
                            <div class="prose prose-lg max-w-none text-gray-700 leading-relaxed ai-processed-content">
                                <?= sanitize_rich_content($page['content']) ?>
                            </div>
                        <?php else: ?>
                            <!-- Classic/Legacy Mode with Template Sections -->
                            <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 mb-12">
                                <?= sanitize_rich_content($page['content']) ?>
                            </div>
                            
                            <!-- Why Choose Us Block (Legacy) -->
                            <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) ?>?</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) ?>.</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 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">Expert Team</h4><p class="text-gray-600 text-sm">Dedicated professionals for <?= htmlspecialchars($serviceName) ?> 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-headset text-red-600"></i></div>
                                        <div><h4 class="font-semibold mb-2">24/7 Support</h4><p class="text-gray-600 text-sm">Always available for your business needs.</p></div>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Process (Legacy) -->
                            <div class="mb-12">
                                <h3 class="text-2xl font-bold mb-6">Our Implementation Process</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">Analysis</h4><p class="text-gray-600">We analyze your project 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</h4><p class="text-gray-600">Custom strategy for <?= htmlspecialchars($serviceName) ?>.</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">Execution</h4><p class="text-gray-600">Execution with quality standards.</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">Success</h4><p class="text-gray-600">Launch and ongoing support.</p></div>
                                    </div>
                                </div>
                            </div>
                        <?php endif; ?>
                    </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@finggu.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 text-sm text-red-700">
                            <ul class="space-y-2">
                                <li class="flex items-center"><i class="fas fa-check-circle mr-2 opacity-70"></i> Verified Professionals</li>
                                <li class="flex items-center"><i class="fas fa-check-circle mr-2 opacity-70"></i> Local Service Experts</li>
                                <li class="flex items-center"><i class="fas fa-check-circle mr-2 opacity-70"></i> Dedicated Support</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<?php if (strpos($page['content'], 'AI_FULL_CONTENT') === false): ?>
<!-- FAQ Section (Legacy) -->
<section class="py-16 bg-white border-t">
    <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</h2>
            <div class="space-y-6">
                <!-- FAQ Items abbreviated for brevity - only shown in Legacy Mode -->
                <div class="border border-gray-200 rounded-xl overflow-hidden p-6 bg-gray-50">
                    <h3 class="font-bold mb-2">Cost and Timeline?</h3>
                    <p class="text-gray-600 text-sm">We provide competitive pricing and efficient timelines specifically for <?= htmlspecialchars($serviceName) ?> in <?= htmlspecialchars($cityName) ?>.</p>
                </div>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>


<!-- 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>

<?php if (strpos($page['content'], 'AI_FULL_CONTENT') === false): ?>
<!-- Additional SEO Content (Legacy) -->
<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. Our expert team has successfully delivered 500+ projects with a 4.9/5 client satisfaction rating.
                </p>
                <p>
                    Contact us today at +91-8655442429 for a free consultation and discover why businesses in <?= htmlspecialchars($cityName) ?> trust Finggu Infotech. 
                </p>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>

<style>
    .faq-content { transition: all 0.3s ease-in-out; }
    .faq-toggle svg { transition: transform 0.3s ease; }
    .rotate-180 { transform: rotate(180deg); }
</style>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // FAQ Toggle Functionality (Improved for AI Content)
    document.addEventListener('click', function(e) {
        const toggle = e.target.closest('.faq-toggle');
        if (!toggle) return;
        
        const content = toggle.nextElementSibling;
        const icon = toggle.querySelector('svg');
        
        // Toggle active state
        content.classList.toggle('hidden');
        if (icon) icon.classList.toggle('rotate-180');
        
        // Optional: Close other FAQs
        const allToggles = document.querySelectorAll('.faq-toggle');
        allToggles.forEach(t => {
            if (t !== toggle) {
                t.nextElementSibling.classList.add('hidden');
                const otherIcon = t.querySelector('svg');
                if (otherIcon) otherIcon.classList.remove('rotate-180');
            }
        });
    });
});
</script>

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