<?php 
date_default_timezone_set('Asia/Kolkata');
$current_time = date('M d, Y, g:i:s A', time());
?>

<?php 
include('includes/config.php');
if(isset($_SESSION['loggedin']) == true){
    ?>
    <script> 
    window.setTimeout(function() {
    window.location.href = "crs/index";
    }, 1500);
    </script>
    <?php
}  
?>

<?php include('a.php'); ?>

<!-- Close the containers left open by a.php -->
</div>
</app-validatecertificate>
</mat-sidenav-container>

<style>
/* Critical Reset - Fix all layout issues */
* {
    box-sizing: border-box;
}

/* Force hide loading screen */
.app-loading {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Reset problematic parent containers */
.mat-drawer-container,
.mat-sidenav-container,
mat-sidenav-container,
.example-container {
    display: block !important;
    overflow: visible !important;
    height: auto !important;
    min-height: auto !important;
    position: static !important;
    transform: none !important;
}

.mat-drawer-content,
mat-sidenav-content,
.mat-sidenav-content {
    display: block !important;
    overflow: visible !important;
    height: auto !important;
    position: static !important;
    transform: none !important;
    margin: 0 !important;
}

/* Hide the background overlay */
.mat-drawer-backdrop {
    display: none !important;
}

app-root,
._layOut,
.content-body,
app-validatecertificate {
    display: block !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    position: static !important;
}

/* Fix all sections positioning */
section {
    display: block !important;
    position: relative !important;
    width: 100% !important;
    float: none !important;
    clear: both !important;
    margin: 0 !important;
    z-index: 1 !important;
}

.hero-section,
.features-section,
.stats-section,
.services-section,
.how-it-works,
.cta-section {
    display: block !important;
    position: relative !important;
    clear: both !important;
    width: 100% !important;
    overflow: visible !important;
    float: none !important;
    z-index: 1 !important;
}

/* Fix content body */
body {
    overflow-x: hidden;
    overflow-y: auto !important;
}
</style>

<script>
// Hide loading spinner immediately
document.addEventListener('DOMContentLoaded', function() {
    var loadingEl = document.querySelector('.app-loading');
    if(loadingEl) {
        loadingEl.style.display = 'none';
        loadingEl.style.visibility = 'hidden';
        loadingEl.style.opacity = '0';
    }
});
// Also hide immediately without waiting
(function() {
    var style = document.createElement('style');
    style.textContent = '.app-loading { display: none !important; visibility: hidden !important; opacity: 0 !important; }';
    document.head.appendChild(style);
})();
</script>

<div class="main-content-wrapper" style="display: block !important; position: relative !important; z-index: 1 !important; width: 100% !important;">

<style>
/* Global Layout Fixes */
body {
    font-family: 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    min-height: 100vh;
}

html {
    overflow-x: hidden;
    scroll-behavior: smooth;
}

/* Main Content Area */
.main-content-wrapper {
    display: block !important;
    width: 100% !important;
    position: relative !important;
    z-index: 1 !important;
    clear: both !important;
    float: none !important;
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Header and Navigation Fixes */
.mat-toolbar {
    position: relative;
    z-index: 100;
}

/* Spacing fixes for main content */
.content-body {
    padding-top: 0;
    margin-top: 0;
}

/* Container and layout improvements */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
    width: 100%;
    box-sizing: border-box;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -15px;
}

.col-lg-3, .col-lg-4, .col-lg-6, .col-lg-12,
.col-md-6, .col-md-12 {
    padding: 0 15px;
    box-sizing: border-box;
}

/* Specific column widths */
.col-lg-3 { width: 25%; }
.col-lg-4 { width: 33.333333%; }
.col-lg-6 { width: 50%; }
.col-lg-12, .col-12 { width: 100%; }
.col-md-6 { width: 50%; }

@media (max-width: 992px) {
    .col-lg-3, .col-lg-4, .col-lg-6 {
        width: 50%;
    }
}

@media (max-width: 768px) {
    .col-lg-3, .col-lg-4, .col-lg-6, .col-md-6 {
        width: 100%;
    }
}

/* Custom Hero Section */
.hero-section {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 80px 0;
    position: relative !important;
    overflow: hidden;
    z-index: 1;
    display: block !important;
    clear: both !important;
    width: 100% !important;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('assets/images/hero-pattern.svg') no-repeat center center;
    background-size: cover;
    opacity: 0.1;
}

.hero-content {
    position: relative;
    z-index: 2;
}

.hero-title {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.hero-subtitle {
    font-size: 1.25rem;
    margin-bottom: 30px;
    opacity: 0.9;
}

/* Certificate Verification Card */
.verify-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    color: #333;
    position: relative;
    z-index: 2;
}

/* Features Section */
.features-section {
    padding: 80px 0;
    background: #f8f9fa;
}

.feature-card {
    text-align: center;
    padding: 40px 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    margin-bottom: 30px;
    height: 100%;
}

.feature-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.15);
}

.feature-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
}

/* Statistics Section */
.stats-section {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 60px 0;
}

.stat-item {
    text-align: center;
    margin-bottom: 30px;
}

.stat-number {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 10px;
    display: block;
}

.stat-label {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Services Section */
.services-section {
    padding: 80px 0;
}

.service-card {
    background: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    border-left: 4px solid #007bff;
    transition: all 0.3s ease;
}

.service-card:hover {
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    transform: translateY(-5px);
}

/* How It Works Section */
.how-it-works {
    background: #f8f9fa;
    padding: 80px 0;
}

.step-item {
    text-align: center;
    margin-bottom: 40px;
}

.step-number {
    width: 60px;
    height: 60px;
    background: #007bff;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    margin: 0 auto 20px;
}

/* CTA Section */
.cta-section {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 80px 0;
    text-align: center;
}

/* Modern Buttons */
.btn-modern {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    padding: 15px 30px;
    font-size: 1.1rem;
    border-radius: 50px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
}

.btn-modern:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
    color: white;
    text-decoration: none;
}

.btn-modern:focus, .btn-modern:active {
    color: white;
    text-decoration: none;
    outline: none;
}

.btn-outline-modern {
    border: 2px solid white;
    color: white;
    background: transparent;
    padding: 15px 30px;
    font-size: 1.1rem;
    border-radius: 50px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
}

.btn-outline-modern:hover {
    background: white;
    color: #1e3c72;
    transform: translateY(-3px);
    text-decoration: none;
}

.btn-outline-modern:focus, .btn-outline-modern:active {
    background: white;
    color: #1e3c72;
    text-decoration: none;
    outline: none;
}

/* Register Button Style */
.btn-register {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    border: none;
    color: white;
    padding: 15px 30px;
    font-size: 1.1rem;
    border-radius: 50px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
}

.btn-register:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(17, 153, 142, 0.5);
    color: white;
    text-decoration: none;
}

.btn-register:focus, .btn-register:active {
    color: white;
    text-decoration: none;
    outline: none;
}

/* CTA Section Buttons */
.btn-cta-register {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    border: none;
    color: white;
    padding: 18px 40px;
    font-size: 1.2rem;
    border-radius: 50px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
}

.btn-cta-register:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(17, 153, 142, 0.5);
    color: white;
    text-decoration: none;
}

.btn-cta-login {
    background: white;
    border: 2px solid white;
    color: #1e3c72;
    padding: 18px 40px;
    font-size: 1.2rem;
    border-radius: 50px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.3);
}

.btn-cta-login:hover {
    background: transparent;
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(255, 255, 255, 0.4);
    text-decoration: none;
}

.btn-cta-login:focus, .btn-cta-register:focus {
    outline: none;
    text-decoration: none;
}

/* Gap utility for flex */
.gap-3 {
    gap: 1rem;
}

/* Bootstrap and Material UI Compatibility */
.btn, .mat-button {
    cursor: pointer;
}

.row {
    margin: 0;
}

/* Fix for any loading issues */
body {
    position: relative;
}

.app-loading {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    z-index: 9999 !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .hero-title {
        font-size: 2.5rem;
    }
    
    .hero-subtitle {
        font-size: 1.1rem;
    }
    
    .stat-number {
        font-size: 2.5rem;
    }
    
    .verify-card {
        padding: 20px;
    }
    
    .feature-card {
        margin-bottom: 20px;
    }
    
    .service-card {
        margin-bottom: 20px;
    }
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in-up {
    animation: fadeInUp 0.6s ease forwards;
}

/* Login Modal Styling */
.modal-content {
    border-radius: 15px;
    border: none;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.modal-header {
    border-bottom: none;
    padding: 30px 30px 0;
}

.modal-body {
    padding: 30px;
}

.form-control {
    border-radius: 10px;
    border: 2px solid #e9ecef;
    padding: 12px 15px;
    font-size: 1rem;
}

.form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}
</style>

<!-- Hero Section -->
<section class="hero-section" style="margin-top: 0; padding-top: 80px;">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-lg-6">
                <div class="hero-content animate-fade-in-up">
                    <h1 class="hero-title">Digital Certificate Validation</h1>
                    <p class="hero-subtitle">Secure, Fast & Reliable Certificate Verification System by Government of India</p>
                    <div class="mt-4 d-flex flex-wrap gap-3">
                        <a href="general-public.php" class="btn btn-modern">
                            <i class="fas fa-sign-in-alt me-2"></i>Login Now
                        </a>
                        <a href="register.php" class="btn btn-register">
                            <i class="fas fa-user-plus me-2"></i>Register
                        </a>
                        <a href="#verify-section" class="btn btn-outline-modern">
                            <i class="fas fa-search me-2"></i>Verify Certificate
                        </a>
                    </div>
                </div>
            </div>
            <div class="col-lg-6">
                <div class="verify-card animate-fade-in-up" id="verify-section">
                    <h3 class="text-center mb-4">
                        <i class="fas fa-certificate text-primary me-2"></i>
                        Quick Certificate Verification
                    </h3>
                    <form>
                        <div class="mb-3">
                            <label for="cert-number" class="form-label">Certificate Number</label>
                            <input type="text" class="form-control" id="cert-number" placeholder="Enter certificate number">
                        </div>
                        <div class="mb-3">
                            <label for="cert-type" class="form-label">Certificate Type</label>
                            <select class="form-control" id="cert-type">
                                <option value="">Select Certificate Type</option>
                                <option value="birth">Birth Certificate</option>
                                <option value="death">Death Certificate</option>
                                <option value="caste">Caste Certificate</option>
                                <option value="income">Income Certificate</option>
                            </select>
                        </div>
                        <button type="submit" class="btn btn-modern w-100">
                            <i class="fas fa-check-circle me-2"></i>Verify Now
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Features Section -->
<section class="features-section">
    <div class="container">
        <div class="row">
            <div class="col-12 text-center mb-5">
                <h2 class="display-4 fw-bold mb-3">Why Choose Our Platform?</h2>
                <p class="lead text-muted">Experience the most advanced certificate validation system in India</p>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-3 col-md-6 mb-4">
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fas fa-shield-alt"></i>
                    </div>
                    <h4>100% Secure</h4>
                    <p>Bank-level security with end-to-end encryption for all your certificate data.</p>
                </div>
            </div>
            <div class="col-lg-3 col-md-6 mb-4">
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fas fa-bolt"></i>
                    </div>
                    <h4>Instant Results</h4>
                    <p>Get your certificate verification results in seconds, not days.</p>
                </div>
            </div>
            <div class="col-lg-3 col-md-6 mb-4">
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fas fa-mobile-alt"></i>
                    </div>
                    <h4>Mobile Friendly</h4>
                    <p>Access from anywhere, anytime with our responsive mobile design.</p>
                </div>
            </div>
            <div class="col-lg-3 col-md-6 mb-4">
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fas fa-headset"></i>
                    </div>
                    <h4>24/7 Support</h4>
                    <p>Round-the-clock customer support for all your queries and assistance.</p>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Statistics Section -->
<section class="stats-section">
    <div class="container">
        <div class="row">
            <div class="col-12 text-center mb-5">
                <h2 class="display-4 fw-bold mb-3">Trusted by Millions</h2>
                <p class="lead">Our platform has served citizens across India</p>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-3 col-md-6">
                <div class="stat-item">
                    <span class="stat-number">10M+</span>
                    <div class="stat-label">Certificates Verified</div>
                </div>
            </div>
            <div class="col-lg-3 col-md-6">
                <div class="stat-item">
                    <span class="stat-number">50K+</span>
                    <div class="stat-label">Active Users</div>
                </div>
            </div>
            <div class="col-lg-3 col-md-6">
                <div class="stat-item">
                    <span class="stat-number">99.9%</span>
                    <div class="stat-label">Uptime</div>
                </div>
            </div>
            <div class="col-lg-3 col-md-6">
                <div class="stat-item">
                    <span class="stat-number">35</span>
                    <div class="stat-label">States Covered</div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Services Section -->
<section class="services-section">
    <div class="container">
        <div class="row">
            <div class="col-12 text-center mb-5">
                <h2 class="display-4 fw-bold mb-3">Our Services</h2>
                <p class="lead text-muted">Comprehensive certificate management solutions</p>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="service-card">
                    <div class="d-flex align-items-center mb-3">
                        <i class="fas fa-baby text-primary fs-1 me-3"></i>
                        <h4 class="mb-0">Birth Certificates</h4>
                    </div>
                    <p class="text-muted">Apply for and verify birth certificates online with instant processing and validation.</p>
                    <a href="#" class="btn btn-outline-primary">Learn More</a>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="service-card">
                    <div class="d-flex align-items-center mb-3">
                        <i class="fas fa-cross text-primary fs-1 me-3"></i>
                        <h4 class="mb-0">Death Certificates</h4>
                    </div>
                    <p class="text-muted">Quick and secure death certificate applications with government-approved validation.</p>
                    <a href="#" class="btn btn-outline-primary">Learn More</a>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="service-card">
                    <div class="d-flex align-items-center mb-3">
                        <i class="fas fa-users text-primary fs-1 me-3"></i>
                        <h4 class="mb-0">Caste Certificates</h4>
                    </div>
                    <p class="text-muted">Apply for caste certificates with proper documentation and instant verification.</p>
                    <a href="#" class="btn btn-outline-primary">Learn More</a>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- How It Works Section -->
<section class="how-it-works">
    <div class="container">
        <div class="row">
            <div class="col-12 text-center mb-5">
                <h2 class="display-4 fw-bold mb-3">How It Works</h2>
                <p class="lead text-muted">Simple steps to get your certificates verified</p>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-3 col-md-6 mb-4">
                <div class="step-item">
                    <div class="step-number">1</div>
                    <h4>Register Account</h4>
                    <p class="text-muted">Create your secure account with valid credentials and documents.</p>
                </div>
            </div>
            <div class="col-lg-3 col-md-6 mb-4">
                <div class="step-item">
                    <div class="step-number">2</div>
                    <h4>Upload Documents</h4>
                    <p class="text-muted">Submit required documents and fill the application form online.</p>
                </div>
            </div>
            <div class="col-lg-3 col-md-6 mb-4">
                <div class="step-item">
                    <div class="step-number">3</div>
                    <h4>Pay Fees</h4>
                    <p class="text-muted">Make secure online payment using multiple payment options.</p>
                </div>
            </div>
            <div class="col-lg-3 col-md-6 mb-4">
                <div class="step-item">
                    <div class="step-number">4</div>
                    <h4>Download Certificate</h4>
                    <p class="text-muted">Receive your verified digital certificate instantly via email.</p>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- CTA Section -->
<section class="cta-section">
    <div class="container">
        <div class="row">
            <div class="col-12 text-center">
                <h2 class="display-4 fw-bold mb-4">Ready to Get Started?</h2>
                <p class="lead mb-5">Join millions of satisfied users who trust our platform for their certificate needs.</p>
                <div class="d-flex flex-wrap justify-content-center gap-3">
                    <a href="register.php" class="btn btn-cta-register btn-lg">
                        <i class="fas fa-user-plus me-2"></i>Create Account
                    </a>
                    <a href="general-public.php" class="btn btn-cta-login btn-lg">
                        <i class="fas fa-sign-in-alt me-2"></i>Login Now
                    </a>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
// DOM ready functions
document.addEventListener('DOMContentLoaded', function() {
    // Ensure all elements are visible after DOM loads
    document.body.style.visibility = 'visible';
    
    // Initialize any interactive elements
    initializeInteractiveElements();
});

// Initialize interactive elements
function initializeInteractiveElements() {
    // Initialize tooltips if Bootstrap is available
    if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip) {
        var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
        var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
            return new bootstrap.Tooltip(tooltipTriggerEl);
        });
    }
    
    // Fix any potential CSS conflicts
    fixStyleConflicts();
}

// Fix style conflicts between different CSS frameworks
function fixStyleConflicts() {
    // Ensure proper Z-index for hero section content
    const heroContent = document.querySelector('.hero-content');
    if (heroContent) {
        heroContent.style.position = 'relative';
        heroContent.style.zIndex = '2';
    }
    
    // Ensure verification card is properly positioned
    const verifyCard = document.querySelector('.verify-card');
    if (verifyCard) {
        verifyCard.style.position = 'relative';
        verifyCard.style.zIndex = '3';
    }
}

// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
});

// Animation on scroll
const observerOptions = {
    threshold: 0.1,
    rootMargin: '0px 0px -50px 0px'
};

const observer = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            entry.target.classList.add('animate-fade-in-up');
        }
    });
}, observerOptions);

document.querySelectorAll('.feature-card, .service-card, .step-item').forEach((el) => {
    observer.observe(el);
});

// Counter animation for statistics
function animateCounter(element, target) {
    let current = 0;
    const increment = target / 100;
    const timer = setInterval(() => {
        current += increment;
        if (current >= target) {
            element.textContent = target.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
            if (target > 999) {
                element.textContent = (target / 1000000 >= 1) ? 
                    (target / 1000000).toFixed(1) + 'M+' : 
                    (target / 1000).toFixed(0) + 'K+';
            }
            clearInterval(timer);
        } else {
            element.textContent = Math.floor(current).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        }
    }, 10);
}

// Trigger counter animation when stats section is visible
const statsObserver = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            const counters = entry.target.querySelectorAll('.stat-number');
            const targets = [10000000, 50000, 99.9, 35];
            counters.forEach((counter, index) => {
                animateCounter(counter, targets[index]);
            });
            statsObserver.unobserve(entry.target);
        }
    });
});

const statsSection = document.querySelector('.stats-section');
if (statsSection) {
    statsObserver.observe(statsSection);
}
</script>

<?php
// Process login if form is submitted
if(isset($_POST['secret']) && $_POST['secret'] == "ahkwebsolutions" && !empty($_POST['username']) && !empty($_POST['password'])){
    $username = mysqli_real_escape_string($conn,$_POST['username']);
    $password = mysqli_real_escape_string($conn,$_POST['password']);

    $res = mysqli_query($conn,"SELECT * FROM `usertable` WHERE phone='$username'  OR emailid='$username' OR userid='$username' ");

    if(mysqli_num_rows($res) == 1 ){
        $userdata = mysqli_fetch_assoc($res);
        $vpass = password_verify($password,$userdata['password']);
        if($vpass){
            if($userdata['status'] == "verified"){
                ?>
                <script>
                    $(function(){
                        Swal.fire(
                            'Success!',
                            'You Are Logged In Successfully!',
                            'success'
                        )
                    });
                </script>
                <?php
                $_SESSION['loggedin'] = true;
                $_SESSION['userid'] = $userdata['userid'];
                $_SESSION['name'] = $userdata['name'];
                $_SESSION['emailid'] = $userdata['emailid'];
                $_SESSION['phone'] = $userdata['phone'];
                $_SESSION['walletamount'] = $userdata['walletamount'];
                $_SESSION['usertype'] = $userdata['usertype'];
                ?>
                <script>
                window.setTimeout(function() {
                window.location.href = "crs/index";
                }, 1500);
                </script>
                <?php
            }else{
                ?>
                <script>
                    $(function(){
                        Swal.fire(
                            'Opps!',
                            'Your Account is Blocked or inactive Please Contact With Admin',
                            'error'
                        )
                    });
                </script>
                <?php
            }
        }else{
            ?>
            <script>
                $(function(){
                    Swal.fire(
                        'Opps!',
                        'Password Wrong!',
                        'error'
                    )
                });
            </script>
            <?php
        }
    }else{
        ?>
        <script>
            $(function(){
                Swal.fire(
                    'Opps!',
                    'Entered username Wrong or Not Exist',
                    'error'
                )
            });
        </script>
        <?php
    }
}
?>

</div> <!-- Close main-content-wrapper -->

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<?php include('k.php'); ?>