<?php
session_start();
require_once 'config.php';

// SEO Meta Variables
$page_title = "Contact Shubank - Get Expert Satta Matka Support & Assistance | Shubank";
$page_description = "Contact Shubank for expert satta matka support, queries, and assistance. Reach our team via WhatsApp, email, or contact form. Quick response guaranteed for all matka-related inquiries.";
$page_keywords = "contact shubank, satta matka support, matka help, customer service, whatsapp support, matka assistance, shubank contact number, matka expert help, satta king support";
$canonical_url = "https://shubank.co/contact.php";

// Initialize variables
$form_submitted = false;
$form_errors = [];
$success_message = '';

// Process form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['submit_contact']) || !empty($_POST['name']))) {
    // Sanitize and validate input
    $name = trim(filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING));
    $phone = trim(filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_STRING));
    $subject = trim(filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_STRING));
    $message = trim(filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING));
    $preferred_contact = filter_input(INPUT_POST, 'preferred_contact', FILTER_SANITIZE_STRING);
    
    // Validation
    if (empty($name) || strlen($name) < 2) {
        $form_errors['name'] = 'Please enter a valid name (minimum 2 characters)';
    }
    
    if (empty($phone) || !preg_match('/^[+]?[0-9\s\-\(\)]{10,15}$/', $phone)) {
        $form_errors['phone'] = 'Please enter a valid phone number';
    }
    
    if (empty($subject) || strlen($subject) < 5) {
        $form_errors['subject'] = 'Please enter a subject (minimum 5 characters)';
    }
    
    if (empty($message) || strlen($message) < 20) {
        $form_errors['message'] = 'Please enter a detailed message (minimum 20 characters)';
    }
    
    if (empty($preferred_contact)) {
        $form_errors['preferred_contact'] = 'Please select your preferred contact method';
    }
    
    error_log("Validation completed. Errors: " . count($form_errors) . " found");
    
    // If no errors, process the form
    if (empty($form_errors)) {
        // Store contact details in session
        $_SESSION['contact_form'] = [
            'name' => $name,
            'phone' => $phone,
            'subject' => $subject,
            'message' => $message,
            'preferred_contact' => $preferred_contact,
            'submitted_at' => date('Y-m-d H:i:s'),
            'ip_address' => $_SERVER['REMOTE_ADDR'] ?? 'Unknown'
        ];
        
        // Save to database and insert contact form data
        $stmt = mysqli_prepare($link, "INSERT INTO contacts (name, phone, subject, message, preferred_contact, ip_address) VALUES (?, ?, ?, ?, ?, ?)");
        if ($stmt) {
            $ip = $_SERVER['REMOTE_ADDR'] ?? 'Unknown';
            mysqli_stmt_bind_param($stmt, 'ssssss', $name, $phone, $subject, $message, $preferred_contact, $ip);
            
            if (mysqli_stmt_execute($stmt)) {
                $form_submitted = true;
                $success_message = 'Thank you for contacting us! We will get back to you soon.';
            } else {
                error_log("Failed to insert contact: " . mysqli_error($link));
                $form_errors['database'] = 'There was an error saving your message. Please try again.';
            }
            mysqli_stmt_close($stmt);
        } else {
            error_log("Failed to prepare contact statement: " . mysqli_error($link));
            $form_errors['database'] = 'There was an error processing your request. Please try again.';
        }
        
        // Only proceed with session and WhatsApp if database insert was successful
        if ($form_submitted) {
            // Generate WhatsApp message for user
            $whatsapp_message = "🎯 *New Contact from Shubank Website*\n\n";
            $whatsapp_message .= "👤 *Name:* " . $name . "\n";
            $whatsapp_message .= "📱 *Phone:* " . $phone . "\n";
            $whatsapp_message .= "📋 *Subject:* " . $subject . "\n";
            $whatsapp_message .= "💬 *Message:* " . $message . "\n";
            $whatsapp_message .= "📞 *Preferred Contact:* " . ucfirst($preferred_contact) . "\n";
            $whatsapp_message .= "🕒 *Time:* " . date('d M Y, h:i A') . "\n\n";
            $whatsapp_message .= "Please respond promptly to this inquiry.";
            
            // Generate admin notification for WhatsApp
            $admin_whatsapp_message = "🚨 *NEW CONTACT INQUIRY - SHUBANK*\n\n";
            $admin_whatsapp_message .= "👤 *Customer:* " . $name . "\n";
            $admin_whatsapp_message .= "📱 *Phone:* " . $phone . "\n";
            $admin_whatsapp_message .= "📋 *Subject:* " . $subject . "\n";
            $admin_whatsapp_message .= "💬 *Message:* " . $message . "\n";
            $admin_whatsapp_message .= "📞 *Preferred Contact:* " . ucfirst($preferred_contact) . "\n";
            $admin_whatsapp_message .= "🕒 *Received:* " . date('d M Y, h:i A') . "\n";
            $admin_whatsapp_message .= "🌐 *Source:* Shubank Contact Form\n\n";
            $admin_whatsapp_message .= "⚡ *Action Required:* Please respond to customer inquiry";
            
            $_SESSION['whatsapp_message'] = urlencode($whatsapp_message);
            $_SESSION['admin_whatsapp_message'] = urlencode($admin_whatsapp_message);
            $_SESSION['contact_success'] = true;
            $_SESSION['success_message'] = $success_message;
            
            // Redirect to prevent form resubmission (POST-Redirect-GET pattern)
            header("Location: " . $_SERVER['PHP_SELF'] . "?success=1");
            exit();
        }
    }
}

// Check if we're displaying success after redirect
if (isset($_GET['success']) && $_GET['success'] == '1' && isset($_SESSION['contact_success'])) {
    $form_submitted = true;
    $success_message = $_SESSION['success_message'];
    // Clear the session flags
    unset($_SESSION['contact_success']);
    unset($_SESSION['success_message']);
}

// Create contacts table if it doesn't exist (do this first)
$create_table_query = "CREATE TABLE IF NOT EXISTS contacts (
    id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(100) NOT NULL,
    phone VARCHAR(20) NOT NULL,
    subject VARCHAR(200) NOT NULL,
    message TEXT NOT NULL,
    preferred_contact VARCHAR(20) NOT NULL,
    ip_address VARCHAR(45),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    status ENUM('new', 'replied', 'resolved') DEFAULT 'new'
)";

if (!mysqli_query($link, $create_table_query)) {
    error_log("Failed to create contacts table: " . mysqli_error($link));
}

// Get contact stats for display
$total_contacts = 0;
$avg_response_time = "< 1 hour";
$satisfaction_rate = "99%";

$count_query = "SELECT COUNT(*) as total FROM contacts WHERE created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)";
$result = mysqli_query($link, $count_query);
if ($result) {
    $row = mysqli_fetch_assoc($result);
    $total_contacts = $row['total'] ?? 0;
} else {
    // If query fails, use default value
    $total_contacts = 0;
}
?>
<!DOCTYPE html>
<html lang="en-IN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <!-- Primary SEO Meta Tags -->
    <title><?php echo $page_title; ?></title>
    <meta name="description" content="<?php echo $page_description; ?>">
    <meta name="keywords" content="<?php echo $page_keywords; ?>">
    <link rel="canonical" href="<?php echo $canonical_url; ?>">
    
    <!-- Open Graph Meta Tags -->
    <meta property="og:title" content="Contact Shubank - Expert Satta Matka Support | Shubank">
    <meta property="og:description" content="<?php echo $page_description; ?>">
    <meta property="og:type" content="website">
    <meta property="og:url" content="<?php echo $canonical_url; ?>">
    <meta property="og:image" content="https://shubank.co/images/shubank-contact-og.jpg">
    <meta property="og:image:width" content="1200">
    <meta property="og:image:height" content="630">
    <meta property="og:image:alt" content="Contact Shubank - Expert Matka Support">
    <meta property="og:site_name" content="Shubank">
    <meta property="og:locale" content="en_IN">
    
    <!-- Twitter Card Meta Tags -->
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="Contact Shubank - Expert Satta Matka Support">
    <meta name="twitter:description" content="<?php echo $page_description; ?>">
    <meta name="twitter:image" content="https://shubank.co/images/shubank-contact-twitter.jpg">
    <meta name="twitter:image:alt" content="Contact Shubank">
    
    <!-- Additional SEO Meta Tags -->
    <meta name="robots" content="index, follow, max-snippet:-1, max-image-preview:large">
    <meta name="author" content="Shubank">
    <meta name="geo.region" content="IN">
    <meta name="geo.country" content="India">
    <meta name="rating" content="general">
    <meta name="revisit-after" content="7 days">
    
    <!-- Structured Data -->
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "ContactPage",
        "name": "Contact Shubank - Expert Satta Matka Support",
        "description": "<?php echo $page_description; ?>",
        "url": "<?php echo $canonical_url; ?>",
        "inLanguage": "en-IN",
        "isPartOf": {
            "@type": "WebSite",
            "name": "Shubank",
            "url": "https://shubank.co/"
        },
        "breadcrumb": {
            "@type": "BreadcrumbList",
            "itemListElement": [
                {
                    "@type": "ListItem",
                    "position": 1,
                    "name": "Home",
                    "item": "https://shubank.co/"
                },
                {
                    "@type": "ListItem",
                    "position": 2,
                    "name": "Contact",
                    "item": "<?php echo $canonical_url; ?>"
                }
            ]
        }
    }
    </script>
    
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "Organization",
        "name": "Shubank",
        "url": "https://shubank.co/",
        "logo": "https://shubank.co/images/shubank-logo.png",
        "contactPoint": {
            "@type": "ContactPoint",
            "telephone": "+91-9759907027",
            "contactType": "customer service",
            "availableLanguage": ["English", "Hindi"],
            "areaServed": "IN"
        },
        "sameAs": [
            "https://wa.me/919759907027"
        ]
    }
    </script>
    
    <link rel="stylesheet" href="style.css">
    
    <!-- Contact Page Specific Styles -->
    <style>
    /* Contact Page Professional Styling */
    
    /* Hero Section */
    .contact-hero {
        background: linear-gradient(135deg, #005c97 0%, #17a2b8 50%, #667eea 100%);
        padding: 5rem 0;
        color: white;
        text-align: center;
        position: relative;
        overflow: hidden;
    }
    
    .contact-hero::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: url('images/shubank-bg.png') center/cover no-repeat;
        opacity: 0.1;
        z-index: 1;
    }
    
    .contact-hero-content {
        position: relative;
        z-index: 2;
        max-width: 800px;
        margin: 0 auto;
        padding: 0 20px;
    }
    
    .contact-hero .eyebrow {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        background: rgba(255, 255, 255, 0.15);
        padding: 0.5rem 1rem;
        border-radius: 2rem;
        font-size: 0.9rem;
        font-weight: 600;
        margin-bottom: 1.5rem;
        backdrop-filter: blur(10px);
    }
    
    .contact-hero h1 {
        font-size: clamp(2.5rem, 5vw, 4rem);
        font-weight: 800;
        margin-bottom: 1.5rem;
        background: linear-gradient(45deg, #fff, #ffd700);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        line-height: 1.2;
    }
    
    .contact-hero p {
        font-size: 1.1rem;
        color: rgba(255, 255, 255, 0.95);
        margin-bottom: 2rem;
        line-height: 1.6;
        max-width: 600px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .contact-stats {
        display: flex;
        justify-content: center;
        gap: 3rem;
        margin-top: 2rem;
    }
    
    .stat-item {
        text-align: center;
        padding: 1rem;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 1rem;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    .stat-number {
        font-size: 2rem;
        font-weight: 800;
        color: #ffd700;
        display: block;
        margin-bottom: 0.25rem;
    }
    
    .stat-label {
        font-size: 0.9rem;
        color: rgba(255, 255, 255, 0.9);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    /* Main Contact Section */
    .contact-main {
        padding: 5rem 0;
        background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    }
    
    .contact-container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 0 20px;
    }
    
    .contact-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 4rem;
        align-items: start;
    }
    
    /* Contact Form */
    .contact-form-section {
        background: white;
        padding: 3rem;
        border-radius: 2rem;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.3);
    }
    
    .contact-form-section h2 {
        color: #2c3e50;
        margin-bottom: 1rem;
        font-size: 2rem;
        font-weight: 700;
    }
    
    .contact-form-section p {
        color: #6c757d;
        margin-bottom: 2rem;
        line-height: 1.6;
    }
    
    .form-group {
        margin-bottom: 1.5rem;
    }
    
    .form-group label {
        display: block;
        margin-bottom: 0.5rem;
        color: #2c3e50;
        font-weight: 600;
        font-size: 0.9rem;
    }
    
    .form-control {
        width: 100%;
        padding: 1rem;
        border: 2px solid #e9ecef;
        border-radius: 0.75rem;
        font-size: 1rem;
        transition: all 0.3s ease;
        background: #f8f9fa;
        box-sizing: border-box;
    }
    
    .form-control:focus {
        outline: none;
        border-color: #17a2b8;
        background: white;
        box-shadow: 0 0 0 4px rgba(23, 162, 184, 0.1);
    }
    
    .form-control.error {
        border-color: #dc3545;
        background: #fff5f5;
    }
    
    .error-message {
        color: #dc3545;
        font-size: 0.85rem;
        margin-top: 0.25rem;
        display: flex;
        align-items: center;
        gap: 0.25rem;
    }
    
    .success-message {
        background: #d4edda;
        color: #155724;
        padding: 1rem;
        border-radius: 0.75rem;
        margin-bottom: 1.5rem;
        border: 1px solid #c3e6cb;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
    
    textarea.form-control {
        min-height: 120px;
        resize: vertical;
    }
    
    .radio-group {
        display: flex;
        gap: 1rem;
        flex-wrap: wrap;
    }
    
    .radio-item {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    .radio-item input[type="radio"] {
        width: auto;
        margin: 0;
    }
    
    .submit-btn {
        background: linear-gradient(135deg, #17a2b8 0%, #005c97 100%);
        color: white;
        padding: 1rem 2rem;
        border: none;
        border-radius: 0.75rem;
        font-size: 1.1rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        width: 100%;
        position: relative;
        overflow: hidden;
    }
    
    .submit-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 30px rgba(23, 162, 184, 0.4);
    }
    
    .submit-btn:disabled {
        opacity: 0.6;
        cursor: not-allowed;
        transform: none;
    }
    
    /* Contact Info Section */
    .contact-info-section {
        display: flex;
        flex-direction: column;
        gap: 2rem;
    }
    
    .contact-info-card {
        background: white;
        padding: 2rem;
        border-radius: 1.5rem;
        box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.3);
        transition: all 0.3s ease;
    }
    
    .contact-info-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
    }
    
    .contact-info-card h3 {
        color: #2c3e50;
        margin-bottom: 1rem;
        font-size: 1.3rem;
        font-weight: 700;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    .contact-method {
        display: flex;
        align-items: center;
        gap: 1rem;
        padding: 1rem;
        background: #f8f9fa;
        border-radius: 1rem;
        margin-bottom: 1rem;
        transition: all 0.3s ease;
    }
    
    .contact-method:hover {
        background: #e9ecef;
        transform: translateX(5px);
    }
    
    .contact-icon {
        width: 50px;
        height: 50px;
        background: linear-gradient(135deg, #17a2b8 0%, #ffd600 100%);
        border-radius: 1rem;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        color: #005c97;
        flex-shrink: 0;
    }
    
    .contact-details h4 {
        color: #2c3e50;
        margin-bottom: 0.25rem;
        font-size: 1rem;
        font-weight: 600;
    }
    
    .contact-details p {
        color: #6c757d;
        margin: 0;
        font-size: 0.9rem;
    }
    
    .contact-details a {
        color: #17a2b8;
        text-decoration: none;
        font-weight: 600;
    }
    
    .contact-details a:hover {
        color: #005c97;
        text-decoration: underline;
    }
    
    /* WhatsApp Integration */
    .whatsapp-section {
        background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
        color: white;
        padding: 2rem;
        border-radius: 1.5rem;
        text-align: center;
        margin-top: 2rem;
    }
    
    .whatsapp-section h3 {
        margin-bottom: 1rem;
        font-size: 1.5rem;
        font-weight: 700;
    }
    
    .whatsapp-btn {
        background: rgba(255, 255, 255, 0.2);
        color: white;
        padding: 1rem 2rem;
        border: 2px solid rgba(255, 255, 255, 0.3);
        border-radius: 0.75rem;
        font-size: 1.1rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        backdrop-filter: blur(10px);
        margin: 0.5rem;
    }
    
    .whatsapp-btn:hover {
        background: rgba(255, 255, 255, 0.3);
        transform: translateY(-2px);
        color: white;
        text-decoration: none;
    }
    
    .whatsapp-buttons {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: wrap;
        gap: 1rem;
        margin-top: 1rem;
    }
    
    .whatsapp-btn.admin-btn {
        background: linear-gradient(135deg, #ff6b6b 0%, #ff4757 100%);
        border: 2px solid rgba(255, 255, 255, 0.4);
    }
    
    .whatsapp-btn.admin-btn:hover {
        background: linear-gradient(135deg, #ff5252 0%, #ff3742 100%);
        transform: translateY(-2px);
    }
    
    /* FAQ Section */
    .contact-faq-section {
        padding: 4rem 0;
        background: white;
    }
    
    .contact-faq-section h2 {
        text-align: center;
        color: #2c3e50;
        margin-bottom: 3rem;
        font-size: 2.5rem;
        font-weight: 700;
    }
    
    .faq-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
        gap: 2rem;
        max-width: 1200px;
        margin: 0 auto;
    }
    
    .faq-item {
        background: #f8f9fa;
        padding: 2rem;
        border-radius: 1rem;
        border-left: 4px solid #17a2b8;
        transition: all 0.3s ease;
    }
    
    .faq-item:hover {
        transform: translateY(-5px);
        box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    }
    
    .faq-item h3 {
        color: #17a2b8;
        margin-bottom: 1rem;
        font-size: 1.2rem;
        font-weight: 600;
    }
    
    .faq-item p {
        color: #6c757d;
        line-height: 1.6;
        margin: 0;
    }
    
    /* Mobile Responsiveness */
    @media (max-width: 1024px) {
        .contact-grid {
            grid-template-columns: 1fr;
            gap: 3rem;
        }
        
        .contact-stats {
            gap: 2rem;
        }
        
        .stat-item {
            padding: 0.75rem;
        }
        
        .stat-number {
            font-size: 1.5rem;
        }
    }
    
    @media (max-width: 768px) {
        .contact-hero {
            padding: 3rem 0;
        }
        
        .contact-main {
            padding: 3rem 0;
        }
        
        .contact-form-section {
            padding: 2rem;
        }
        
        .form-row {
            grid-template-columns: 1fr;
        }
        
        .contact-stats {
            flex-direction: column;
            gap: 1rem;
        }
        
        .radio-group {
            flex-direction: column;
            gap: 0.5rem;
        }
        
        .contact-faq-section {
            padding: 3rem 0;
        }
        
        .faq-grid {
            grid-template-columns: 1fr;
        }
    }
    
    @media (max-width: 480px) {
        .contact-hero,
        .contact-main,
        .contact-faq-section {
            padding: 2rem 0;
        }
        
        .contact-form-section,
        .contact-info-card {
            padding: 1.5rem;
        }
        
        .contact-method {
            flex-direction: column;
            text-align: center;
            gap: 0.5rem;
        }
        
        .contact-icon {
            width: 40px;
            height: 40px;
            font-size: 1.2rem;
        }
    }
    </style>
</head>
<body>

<?php include 'header.php'; ?>

<!-- Breadcrumb Navigation -->
<nav class="breadcrumb-nav" aria-label="Breadcrumb">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="index.php">Home</a></li>
            <li aria-current="page">Contact Us</li>
        </ol>
    </div>
</nav>

<!-- Hero Section -->
<section class="contact-hero">
    <div class="contact-hero-content">
        <div class="eyebrow">
            <span>📞</span>
            Get Expert Support
        </div>
        <h1>Contact Shubank - Your Trusted Matka Partner</h1>
        <p>Need help with <strong>satta matka strategies</strong>, have questions about our platform, or require expert assistance? Our dedicated support team is here to help you succeed with personalized guidance and quick solutions.</p>
        
        <div class="contact-stats">
            <div class="stat-item">
                <span class="stat-number"><?php echo $avg_response_time; ?></span>
                <span class="stat-label">Average Response</span>
            </div>
            <div class="stat-item">
                <span class="stat-number"><?php echo $satisfaction_rate; ?></span>
                <span class="stat-label">Satisfaction Rate</span>
            </div>
            <div class="stat-item">
                <span class="stat-number"><?php echo $total_contacts + 150; ?>+</span>
                <span class="stat-label">Happy Customers</span>
            </div>
        </div>
    </div>
</section>

<!-- Main Contact Section -->
<section class="contact-main">
    <div class="contact-container">
        
        <?php if ($form_submitted && $success_message): ?>
        <!-- Success Message - Prominent Position -->
        <div class="success-message-banner" id="successBanner" style="background: linear-gradient(135deg, #28a745, #20c997); color: white; padding: 20px; margin: 20px 0; border-radius: 10px; text-align: center; box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3); animation: slideDown 0.5s ease-out;">
            <div style="font-size: 24px; margin-bottom: 10px;">🎉 Success!</div>
            <div style="font-size: 18px; margin-bottom: 15px;"><?php echo htmlspecialchars($success_message); ?></div>
            <div style="font-size: 14px; opacity: 0.9;">Our team will contact you within 1 hour during business hours.</div>
        </div>
        <?php endif; ?>
        
        <div class="contact-grid">
            
            <!-- Contact Form -->
            <div class="contact-form-section">
                <h2>🚀 Send Us a Message</h2>
                <p>Fill out the form below and our expert team will get back to you with personalized assistance for all your <strong>matka-related queries</strong>.</p>
                
                <?php if (isset($form_errors['database'])): ?>
                <div class="error-message" style="background: #f8d7da; color: #721c24; padding: 1rem; border-radius: 0.75rem; margin-bottom: 1.5rem; border: 1px solid #f5c6cb;">
                    <span>⚠️</span>
                    <?php echo htmlspecialchars($form_errors['database']); ?>
                </div>
                <?php endif; ?>
                
                <form method="POST" action="" id="contactForm" novalidate>
                    <div class="form-row">
                        <div class="form-group">
                            <label for="name">Full Name *</label>
                            <input type="text" id="name" name="name" class="form-control <?php echo isset($form_errors['name']) ? 'error' : ''; ?>" 
                                   value="<?php echo (isset($_GET['success']) && $_GET['success'] == '1') ? '' : htmlspecialchars($_POST['name'] ?? ''); ?>" 
                                   placeholder="Enter your full name" required>
                            <?php if (isset($form_errors['name'])): ?>
                            <div class="error-message">⚠️ <?php echo $form_errors['name']; ?></div>
                            <?php endif; ?>
                        </div>
                        
                        <div class="form-group">
                            <label for="phone">Phone Number *</label>
                            <input type="tel" id="phone" name="phone" class="form-control <?php echo isset($form_errors['phone']) ? 'error' : ''; ?>" 
                                   value="<?php echo (isset($_GET['success']) && $_GET['success'] == '1') ? '' : htmlspecialchars($_POST['phone'] ?? ''); ?>" 
                                   placeholder="+91 8905245890" required>
                            <?php if (isset($form_errors['phone'])): ?>
                            <div class="error-message">⚠️ <?php echo $form_errors['phone']; ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label for="subject">Subject *</label>
                        <input type="text" id="subject" name="subject" class="form-control <?php echo isset($form_errors['subject']) ? 'error' : ''; ?>" 
                               value="<?php echo (isset($_GET['success']) && $_GET['success'] == '1') ? '' : htmlspecialchars($_POST['subject'] ?? ''); ?>" 
                               placeholder="Brief subject of your inquiry" required>
                        <?php if (isset($form_errors['subject'])): ?>
                        <div class="error-message">⚠️ <?php echo $form_errors['subject']; ?></div>
                        <?php endif; ?>
                    </div>
                    
                    <div class="form-group">
                        <label for="message">Your Message *</label>
                        <textarea id="message" name="message" class="form-control <?php echo isset($form_errors['message']) ? 'error' : ''; ?>" 
                                  placeholder="Please describe your inquiry in detail. Include any specific questions about matka strategies, account issues, or technical support needed." required><?php echo (isset($_GET['success']) && $_GET['success'] == '1') ? '' : htmlspecialchars($_POST['message'] ?? ''); ?></textarea>
                        <?php if (isset($form_errors['message'])): ?>
                        <div class="error-message">⚠️ <?php echo $form_errors['message']; ?></div>
                        <?php endif; ?>
                    </div>
                    
                    <div class="form-group">
                        <label>Preferred Contact Method *</label>
                        <div class="radio-group">
                            <div class="radio-item">
                                <input type="radio" id="contact_phone" name="preferred_contact" value="phone" 
                                       <?php echo (isset($_GET['success']) && $_GET['success'] == '1') ? '' : ((($_POST['preferred_contact'] ?? '') === 'phone') ? 'checked' : ''); ?>>
                                <label for="contact_phone">📱 Phone Call</label>
                            </div>
                            <div class="radio-item">
                                <input type="radio" id="contact_whatsapp" name="preferred_contact" value="whatsapp" 
                                       <?php echo (isset($_GET['success']) && $_GET['success'] == '1') ? '' : ((($_POST['preferred_contact'] ?? '') === 'whatsapp') ? 'checked' : ''); ?>>
                                <label for="contact_whatsapp">💬 WhatsApp</label>
                            </div>
                        </div>
                        <?php if (isset($form_errors['preferred_contact'])): ?>
                        <div class="error-message">⚠️ <?php echo $form_errors['preferred_contact']; ?></div>
                        <?php endif; ?>
                    </div>
                    
                    <button type="submit" name="submit_contact" class="submit-btn" id="submitBtn">
                        🚀 Send Message & Get Expert Help
                    </button>
                </form>
            </div>
            
            <!-- Contact Information -->
            <div class="contact-info-section">
                
                <!-- Direct Contact Methods -->
                <div class="contact-info-card">
                    <h3>📞 Direct Contact</h3>
                    
                    <div class="contact-method">
                        <div class="contact-icon">📱</div>
                        <div class="contact-details">
                            <h4>WhatsApp Support</h4>
                            <p><a href="https://wa.me/919759907027?text=Hi%20Shubank!%20I%20need%20help%20with%20matka%20strategies" target="_blank">+91 00000 00000</a></p>
                        </div>
                    </div>
                    
                    <div class="contact-method">
                        <div class="contact-icon"></div>
                        <div class="contact-details">
                            <h4>Support Hours</h4>
                            <p>24/7 Available</p>
                        </div>
                    </div>
                </div>
                
                <!-- Quick Help -->
                <div class="contact-info-card">
                    <h3>⚡ Quick Help</h3>
                    
                    <div class="contact-method">
                        <div class="contact-icon">📊</div>
                        <div class="contact-details">
                            <h4>Strategy Consultation</h4>
                            <p>Get personalized matka strategies</p>
                        </div>
                    </div>
                    
                    <div class="contact-method">
                        <div class="contact-icon">🔧</div>
                        <div class="contact-details">
                            <h4>Technical Support</h4>
                            <p>Account & platform assistance</p>
                        </div>
                    </div>
                    
                    <div class="contact-method">
                        <div class="contact-icon">💰</div>
                        <div class="contact-details">
                            <h4>Payment Issues</h4>
                            <p>Transaction & wallet support</p>
                        </div>
                    </div>
                </div>
                
                <?php if ($form_submitted && isset($_SESSION['whatsapp_message'])): ?>
                <!-- WhatsApp Integration -->
                <div class="whatsapp-section">
                    <h3>💬 Share on WhatsApp</h3>
                    <p>Your contact details have been saved. Click below to share this inquiry on WhatsApp for faster response:</p>
                    <div class="whatsapp-buttons">
                        <a href="https://wa.me/919759907027?text=<?php echo $_SESSION['whatsapp_message']; ?>" 
                           target="_blank" class="whatsapp-btn">
                            <span>📱</span> Send to WhatsApp
                        </a>
                        
                        <?php if (isset($_SESSION['admin_whatsapp_message'])): ?>
                        <a href="https://wa.me/919759907027?text=<?php echo $_SESSION['admin_whatsapp_message']; ?>" 
                           target="_blank" class="whatsapp-btn admin-btn" 
                           onclick="notifyAdmin(); return true;">
                            <span>🚨</span> Notify Admin
                        </a>
                        <?php endif; ?>
                    </div>
                </div>
                <?php 
                unset($_SESSION['whatsapp_message']); 
                unset($_SESSION['admin_whatsapp_message']); 
                ?>
                <?php endif; ?>
                
            </div>
        </div>
    </div>
</section>

<!-- FAQ Section -->
<section class="contact-faq-section">
    <div class="contact-container">
        <h2>❓ Frequently Asked Questions</h2>
        <div class="faq-grid">
            <div class="faq-item">
                <h3>How quickly do you respond to inquiries?</h3>
                <p>Our expert support team typically responds within 1 hour during business hours. For urgent <strong>matka strategy</strong> questions, we offer immediate WhatsApp support 24/7.</p>
            </div>
            <div class="faq-item">
                <h3>What kind of support do you provide?</h3>
                <p>We provide comprehensive support including <strong>personalized matka strategies</strong>, technical assistance, account help, payment support, and expert guidance for all <strong>satta matka markets</strong>.</p>
            </div>
            <div class="faq-item">
                <h3>Is your support available 24/7?</h3>
                <p>Yes! Our WhatsApp support is available 24/7 for urgent queries. Phone support is also available during business hours with immediate assistance.</p>
            </div>
            <div class="faq-item">
                <h3>Do you provide strategy consultation?</h3>
                <p>Absolutely! Our expert team offers personalized <strong>matka strategy consultation</strong> based on your experience level and preferred markets like <strong>Disawar, Delhi Bazaar</strong>, and more.</p>
            </div>
            <div class="faq-item">
                <h3>Is there any fee for consultation?</h3>
                <p>Basic support and guidance are completely <strong>free of charge</strong>. For advanced <strong>premium strategy sessions</strong> and detailed market analysis, we offer affordable consultation packages with guaranteed results.</p>
            </div>
            <div class="faq-item">
                <h3>How secure is my personal information?</h3>
                <p>Your privacy is our top priority! All contact details and conversations are <strong>100% confidential</strong>. We use advanced encryption and never share your information with third parties.</p>
            </div>
        </div>
    </div>
</section>

<!-- Enhanced JavaScript -->
<script>
document.addEventListener('DOMContentLoaded', function() {
    const form = document.getElementById('contactForm');
    const submitBtn = document.getElementById('submitBtn');
    
    // Real-time form validation
    const inputs = form.querySelectorAll('input, textarea');
    inputs.forEach(input => {
        input.addEventListener('input', function() {
            validateField(this);
        });
        
        input.addEventListener('blur', function() {
            validateField(this);
        });
    });
    
    // Form submission handling
    form.addEventListener('submit', function(e) {
        // Always allow form submission - server-side validation will handle errors
        // Show loading state
        submitBtn.disabled = true;
        submitBtn.innerHTML = '⏳ Sending Message...';
        
        // Optional: Add a small delay to show loading state
        setTimeout(function() {
            // Form will submit naturally after this
        }, 100);
    });
    
    function validateField(field) {
        const value = field.value.trim();
        const fieldName = field.name;
        let isValid = true;
        let errorMessage = '';
        
        // Remove existing error styling
        field.classList.remove('error');
        const existingError = field.parentNode.querySelector('.error-message');
        if (existingError) {
            existingError.remove();
        }
        
        // Validation rules
        switch(fieldName) {
            case 'name':
                if (value.length < 2) {
                    isValid = false;
                    errorMessage = 'Name must be at least 2 characters long';
                }
                break;
                
            case 'phone':
                const phonePattern = /^[+]?[0-9\s\-\(\)]{10,15}$/;
                if (!phonePattern.test(value)) {
                    isValid = false;
                    errorMessage = 'Please enter a valid phone number';
                }
                break;
                
            case 'subject':
                if (value.length < 5) {
                    isValid = false;
                    errorMessage = 'Subject must be at least 5 characters long';
                }
                break;
                
            case 'message':
                if (value.length < 20) {
                    isValid = false;
                    errorMessage = 'Message must be at least 20 characters long';
                }
                break;
        }
        
        // Show error if validation failed
        if (!isValid && value !== '') {
            field.classList.add('error');
            const errorDiv = document.createElement('div');
            errorDiv.className = 'error-message';
            errorDiv.innerHTML = `⚠️ ${errorMessage}`;
            field.parentNode.appendChild(errorDiv);
        }
        
        return isValid;
    }
    
    function validateForm() {
        let isFormValid = true;
        
        // Validate all required fields
        inputs.forEach(input => {
            if (!validateField(input)) {
                isFormValid = false;
            }
        });
        
        // Check if preferred contact method is selected
        const preferredContact = form.querySelector('input[name="preferred_contact"]:checked');
        if (!preferredContact) {
            isFormValid = false;
            // Add error handling for radio buttons if needed
        }
        
        return isFormValid;
    }
    
    // Auto-save form data to localStorage
    const formData = {};
    inputs.forEach(input => {
        input.addEventListener('input', function() {
            formData[this.name] = this.value;
            localStorage.setItem('shubank_contact_form', JSON.stringify(formData));
        });
    });
    
    // Restore form data from localStorage
    const savedData = localStorage.getItem('shubank_contact_form');
    if (savedData && !form.querySelector('.success-message')) {
        const data = JSON.parse(savedData);
        Object.keys(data).forEach(key => {
            const field = form.querySelector(`[name="${key}"]`);
            if (field && field.type !== 'radio') {
                field.value = data[key];
            }
        });
    }
    
    // Clear saved data on successful submission
    if (form.querySelector('.success-message')) {
        localStorage.removeItem('shubank_contact_form');
    }
    
    // Phone number formatting
    const phoneInput = document.getElementById('phone');
    if (phoneInput) {
        phoneInput.addEventListener('input', function() {
            let value = this.value.replace(/\D/g, '');
            if (value.length > 0 && !value.startsWith('91') && value.length === 10) {
                value = '91' + value;
            }
            this.value = '+' + value;
        });
    }
    
    // Character counter for message field
    const messageField = document.getElementById('message');
    if (messageField) {
        const counter = document.createElement('div');
        counter.style.cssText = 'font-size: 0.85rem; color: #6c757d; text-align: right; margin-top: 0.25rem;';
        messageField.parentNode.appendChild(counter);
        
        function updateCounter() {
            const length = messageField.value.length;
            const minLength = 20;
            counter.textContent = `${length}/${minLength} characters minimum`;
            counter.style.color = length >= minLength ? '#28a745' : '#6c757d';
        }
        
        messageField.addEventListener('input', updateCounter);
        updateCounter();
    }
    
    // Auto-scroll to success message if present
    const successBanner = document.getElementById('successBanner');
    if (successBanner) {
        // Smooth scroll to success message
        setTimeout(function() {
            successBanner.scrollIntoView({ 
                behavior: 'smooth', 
                block: 'center' 
            });
        }, 100);
        
        // Add pulse effect
        setTimeout(function() {
            successBanner.style.transform = 'scale(1.02)';
            setTimeout(function() {
                successBanner.style.transform = 'scale(1)';
            }, 200);
        }, 600);
    }
    
    // Admin notification function
    function notifyAdmin() {
        // Show notification that admin has been notified
        setTimeout(function() {
            const notification = document.createElement('div');
            notification.innerHTML = '🚨 Admin has been notified via WhatsApp!';
            notification.style.cssText = `
                position: fixed;
                top: 20px;
                right: 20px;
                background: linear-gradient(135deg, #ff6b6b 0%, #ff4757 100%);
                color: white;
                padding: 1rem 1.5rem;
                border-radius: 0.75rem;
                box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
                z-index: 10000;
                font-weight: 600;
                animation: slideInRight 0.3s ease;
            `;
            document.body.appendChild(notification);
            
            // Remove notification after 3 seconds
            setTimeout(function() {
                notification.remove();
            }, 3000);
        }, 500);
    }
    
    // Make function global
    window.notifyAdmin = notifyAdmin;
});

// CSS for notification animation
const style = document.createElement('style');
style.textContent = `
    @keyframes slideInRight {
        from {
            opacity: 0;
            transform: translateX(100px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }
`;
document.head.appendChild(style);
</script>

<style>
/* Success banner animation */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Smooth transitions for success banner */
.success-message-banner {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.success-message-banner:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4) !important;
}
</style>

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