<?php
/**
 * Admin Email Settings Management
 * Handles SMTP configuration, email templates, and notification settings
 */

// Prevent any output before headers
error_reporting(E_ALL);
ini_set('display_errors', 0); // Don't display errors to output
ini_set('log_errors', 1); // Log errors instead

// Define TONSUI_LOADED constant to use session_init
define('TONSUI_LOADED', true);

// Set JSON header before session_init
header('Content-Type: application/json');

try {
    // Include centralized session initialization (handles CORS and session)
    require_once __DIR__ . '/session_init.php';
} catch (Exception $e) {
    echo json_encode(['success' => false, 'error' => 'Session init failed: ' . $e->getMessage()]);
    exit;
}

// Check admin authentication manually for better error messages
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    if (!isset($_SESSION['admin_id'])) {
        echo json_encode([
            'success' => false, 
            'error' => 'Unauthorized: Not logged in as admin',
            'debug' => [
                'admin_logged_in' => $_SESSION['admin_logged_in'] ?? 'not set',
                'admin_id' => $_SESSION['admin_id'] ?? 'not set',
                'session_id' => session_id()
            ]
        ]);
        exit;
    }
}

// Database connection
require_once __DIR__ . '/db.php';

try {
    $db = Database::getInstance();
    $conn = $db->getConnection();
    if (!$conn) {
        echo json_encode(['success' => false, 'error' => 'Database connection failed']);
        exit;
    }
} catch (Exception $e) {
    echo json_encode(['success' => false, 'error' => 'Database error: ' . $e->getMessage()]);
    exit;
}

// Get or create email_config table
try {
    createEmailConfigTable($conn);
} catch (Exception $e) {
    error_log("Failed to create email_config table: " . $e->getMessage());
    // Continue anyway, table might already exist
}

// Handle different actions
$method = $_SERVER['REQUEST_METHOD'];

if ($method === 'GET') {
    // Load email configuration
    $config = loadEmailConfig($conn);
    echo json_encode([
        'success' => true,
        'smtp' => $config['smtp'] ?? [],
        'settings' => $config['settings'] ?? [],
        'templates' => $config['templates'] ?? []
    ]);
    exit;
}

if ($method === 'POST') {
    try {
        $input = json_decode(file_get_contents('php://input'), true);
        
        if (!$input) {
            echo json_encode(['success' => false, 'error' => 'Invalid JSON input']);
            exit;
        }
        
        $action = $input['action'] ?? '';

        switch ($action) {
            case 'save_smtp':
                $result = saveSmtpConfig($conn, $input['config']);
                echo json_encode($result);
                break;

            case 'save_settings':
                $result = saveEmailSettings($conn, $input['settings']);
                echo json_encode($result);
                break;

            case 'save_template':
                $result = saveEmailTemplate($conn, $input['template'], $input['data']);
                echo json_encode($result);
                break;

            case 'restore_template':
                $tplKey = (string)($input['template'] ?? '');
                $defaults = getDefaultTemplates();
                if (!$tplKey || !isset($defaults[$tplKey])) {
                    echo json_encode(['success' => false, 'error' => 'Unknown template']);
                    break;
                }
                $save = saveEmailTemplate($conn, $tplKey, $defaults[$tplKey]);
                if (!empty($save['success'])) {
                    echo json_encode(['success' => true, 'template' => $defaults[$tplKey]]);
                } else {
                    echo json_encode(['success' => false, 'error' => ($save['error'] ?? 'Failed to restore')]);
                }
                break;

            case 'test_smtp':
                $result = testSmtpConnection($conn, $input['email']);
                echo json_encode($result);
                break;

            default:
                echo json_encode(['success' => false, 'error' => 'Invalid action']);
        }
    } catch (Exception $e) {
        echo json_encode(['success' => false, 'error' => 'Server error: ' . $e->getMessage()]);
    }
    exit;
}

// ==================== Helper Functions ====================

function createEmailConfigTable($conn) {
    $sql = "CREATE TABLE IF NOT EXISTS email_config (
        id INT AUTO_INCREMENT PRIMARY KEY,
        config_key VARCHAR(100) UNIQUE NOT NULL,
        config_value TEXT,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    )";
    
    try {
        $conn->exec($sql);
    } catch (PDOException $e) {
        error_log("Email config table creation error: " . $e->getMessage());
    }
}

function loadEmailConfig($conn) {
    try {
        $stmt = $conn->query("SELECT config_key, config_value FROM email_config");
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        
        $config = [
            'smtp' => getDefaultSmtpConfig(),
            'settings' => getDefaultEmailSettings(),
            'templates' => getDefaultTemplates()
        ];
        
        foreach ($rows as $row) {
            $key = $row['config_key'];
            $value = json_decode($row['config_value'], true);
            
            if ($key === 'smtp_config') {
                $config['smtp'] = $value;
            } elseif ($key === 'email_settings') {
                $config['settings'] = $value;
            } elseif (strpos($key, 'template_') === 0) {
                $templateName = str_replace('template_', '', $key);
                $config['templates'][$templateName] = $value;
            }
        }
        
        return $config;
    } catch (PDOException $e) {
        error_log("Load email config error: " . $e->getMessage());
        return [
            'smtp' => getDefaultSmtpConfig(),
            'settings' => getDefaultEmailSettings(),
            'templates' => getDefaultTemplates()
        ];
    }
}

function saveSmtpConfig($conn, $config) {
    try {
        $stmt = $conn->prepare("\n            INSERT INTO email_config (config_key, config_value) \n            VALUES ('smtp_config', :config)\n            ON DUPLICATE KEY UPDATE config_value = :config2\n        ");
        $json = json_encode($config);
        $stmt->execute([
            'config' => $json,
            'config2' => $json
        ]);
        
        return ['success' => true];
    } catch (PDOException $e) {
        return ['success' => false, 'error' => $e->getMessage()];
    }
}

function saveEmailSettings($conn, $settings) {
    try {
        $stmt = $conn->prepare("\n            INSERT INTO email_config (config_key, config_value) \n            VALUES ('email_settings', :settings)\n            ON DUPLICATE KEY UPDATE config_value = :settings2\n        ");
        $json = json_encode($settings);
        $stmt->execute([
            'settings' => $json,
            'settings2' => $json
        ]);
        
        return ['success' => true];
    } catch (PDOException $e) {
        return ['success' => false, 'error' => $e->getMessage()];
    }
}

function saveEmailTemplate($conn, $templateName, $data) {
    try {
        $stmt = $conn->prepare("\n            INSERT INTO email_config (config_key, config_value) \n            VALUES (:key, :data)\n            ON DUPLICATE KEY UPDATE config_value = :data2\n        ");
        $json = json_encode($data);
        $stmt->execute([
            'key' => 'template_' . $templateName,
            'data' => $json,
            'data2' => $json
        ]);
        
        return ['success' => true];
    } catch (PDOException $e) {
        return ['success' => false, 'error' => $e->getMessage()];
    }
}

function testSmtpConnection($conn, $testEmail) {
    try {
        $config = loadEmailConfig($conn);
        $smtp = $config['smtp'];
        
        if (!$smtp['enabled']) {
            return ['success' => false, 'error' => 'Email system is disabled'];
        }
        
        $result = sendEmail(
            $smtp,
            $testEmail,
            'SMTP Test Email',
            '<h2>🎉 SMTP Connection Successful!</h2>
            <p>Your email system is configured correctly and working.</p>
            <p>This is a test email from your admin panel.</p>
            <p style="color: #666; font-size: 12px; margin-top: 20px;">
                Sent at: ' . date('Y-m-d H:i:s') . '
            </p>'
        );
        
        return $result;
    } catch (Exception $e) {
        return ['success' => false, 'error' => $e->getMessage()];
    }
}

function sendEmail($smtpConfig, $to, $subject, $body) {
    try {
        require_once __DIR__ . '/PHPMailer/PHPMailer.php';
        require_once __DIR__ . '/PHPMailer/SMTP.php';
        require_once __DIR__ . '/PHPMailer/Exception.php';
        
        $mail = new PHPMailer\PHPMailer\PHPMailer(true);
        
        // Server settings
        $mail->isSMTP();
        $mail->Host = $smtpConfig['host'];
        $mail->SMTPAuth = true;
        $mail->Username = $smtpConfig['username'];
        $mail->Password = $smtpConfig['password'];
        $mail->SMTPSecure = $smtpConfig['encryption'] === 'ssl' ? PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_SMTPS : PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
        $mail->Port = $smtpConfig['port'];
        
        // Recipients
        $mail->setFrom($smtpConfig['fromEmail'], $smtpConfig['fromName']);
        $mail->addAddress($to);
        
        // Content
        $mail->isHTML(true);
        $mail->Subject = $subject;
        $mail->Body = $body;
        $mail->AltBody = strip_tags($body);
        
        $mail->send();
        return ['success' => true];
    } catch (Exception $e) {
        error_log("Email send error: " . $e->getMessage());
        return ['success' => false, 'error' => 'Email could not be sent: ' . $e->getMessage()];
    }
}

// Default configurations
function getDefaultSmtpConfig() {
    return [
        'enabled' => false,
        'host' => '',
        'port' => 465,
        'username' => '',
        'password' => '',
        'fromEmail' => '',
        'fromName' => 'First De France Bank',
        'encryption' => 'ssl'
    ];
}

function getDefaultEmailSettings() {
    return [
        'verificationRequired' => true,
        'verificationExpiry' => 24,
        'sendWelcomeEmail' => true,
        'sendDepositNotifications' => true,
        'sendWithdrawalNotifications' => true,
        'sendKycNotifications' => true,
        'sendTicketNotifications' => true,
        // Branding (can be overridden via .env or edited in Admin UI)
        'brand_name' => 'First De France Bank',
        'brand_email' => 'support@firstdefrance.com',
        'brand_logo_url' => '',
        'brand_address' => ''
    ];
}

function getDefaultTemplates() {
    return [
        'verification' => [
            'subject' => '🔐 Verify Your Email - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Verify Your Email</title>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 40px 40px 30px; text-align: center;">
                            <div style="margin-bottom: 8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" /></div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700; letter-spacing: -0.5px;">{{brand_name}}</h1>
                        </td>
                    </tr>
                    
                    <!-- Icon -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #E43D30 0%, #ff6b5a 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(228, 61, 48, 0.3);">
                                <span style="font-size: 40px; color: white;">🎉</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <h2 style="margin: 0 0 16px; color: #1a1a2e; font-size: 28px; font-weight: 700; text-align: center;">Welcome to {{brand_name}}!</h2>
                            <p style="margin: 0 0 24px; color: #666; font-size: 16px; line-height: 1.6; text-align: center;">Dear {{user_name}},</p>
                            <p style="margin: 0 0 32px; color: #666; font-size: 16px; line-height: 1.6;">Thank you for joining {{brand_name}}. To unlock all features and start investing, please verify your email address.</p>
                            
                            <!-- CTA Button -->
                            <table width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td align="center" style="padding: 20px 0;">
                                        <a href="{{verification_link}}" style="display: inline-block; padding: 16px 48px; background: linear-gradient(135deg, #E43D30 0%, #ff6b5a 100%); color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 600; box-shadow: 0 4px 12px rgba(228, 61, 48, 0.3); transition: transform 0.2s;">Verify Email Address</a>
                                    </td>
                                </tr>
                            </table>
                            
                            <!-- Info Box -->
                            <div style="background: #f8f9fa; border-left: 4px solid #E43D30; padding: 16px; border-radius: 8px; margin: 24px 0;">
                                <p style="margin: 0; color: #666; font-size: 14px; line-height: 1.6;"><strong>⏰ Important:</strong> This verification link will expire in <strong>{{expiry_hours}} hours</strong>. Please verify your email soon to avoid any disruptions.</p>
                            </div>
                            
                            <p style="margin: 24px 0 0; color: #999; font-size: 14px; line-height: 1.6; text-align: center;">If you didn\'t create this account, you can safely ignore this email.</p>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'welcome' => [
            'subject' => '🚀 Welcome to {{brand_name}} - Let\'s Get Started!',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome to {{brand_name}}</title>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 40px; text-align: center;">
                            <div style="margin-bottom: 8px;">
                                <img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" />
                            </div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700;">{{brand_name}}</h1>
                        </td>
                    </tr>
                    
                    <!-- Success Icon -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #10b981 0%, #34d399 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);">
                                <span style="font-size: 40px; color: white;">✓</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <h2 style="margin: 0 0 16px; color: #1a1a2e; font-size: 28px; font-weight: 700; text-align: center;">Email Verified Successfully!</h2>
                            <p style="margin: 0 0 24px; color: #666; font-size: 16px; line-height: 1.6; text-align: center;">Welcome aboard, <strong>{{user_name}}</strong>! 🎉</p>
                            <p style="margin: 0 0 32px; color: #666; font-size: 16px; line-height: 1.6;">Your email has been verified and your account is now fully activated. You have complete access to all premium features of our investment platform.</p>
                            
                            <!-- Features Grid -->
                            <table width="100%" cellpadding="0" cellspacing="0" style="margin: 32px 0;">
                                <tr>
                                    <td width="50%" style="padding: 16px; vertical-align: top;">
                                        <div style="background: #f8f9fa; padding: 20px; border-radius: 8px; text-align: center;">
                                            <div style="font-size: 32px; margin-bottom: 8px;">💼</div>
                                            <h3 style="margin: 0 0 8px; color: #1a1a2e; font-size: 16px; font-weight: 600;">Investment Plans</h3>
                                            <p style="margin: 0; color: #666; font-size: 13px;">Access diverse investment opportunities</p>
                                        </div>
                                    </td>
                                    <td width="50%" style="padding: 16px; vertical-align: top;">
                                        <div style="background: #f8f9fa; padding: 20px; border-radius: 8px; text-align: center;">
                                            <div style="font-size: 32px; margin-bottom: 8px;">📊</div>
                                            <h3 style="margin: 0 0 8px; color: #1a1a2e; font-size: 16px; font-weight: 600;">Real-Time Analytics</h3>
                                            <p style="margin: 0; color: #666; font-size: 13px;">Track your portfolio performance</p>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                            
                            <!-- CTA Button -->
                            <table width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td align="center" style="padding: 20px 0;">
                                        <a href="{{login_link}}" style="display: inline-block; padding: 16px 48px; background: linear-gradient(135deg, #E43D30 0%, #ff6b5a 100%); color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 600; box-shadow: 0 4px 12px rgba(228, 61, 48, 0.3);">Access Your Dashboard</a>
                                    </td>
                                </tr>
                            </table>
                            
                            <!-- Help Section -->
                            <div style="background: #f8f9fa; padding: 24px; border-radius: 8px; margin: 32px 0; text-align: center;">
                                <p style="margin: 0 0 8px; color: #666; font-size: 14px;">Need help getting started?</p>
                                <p style="margin: 0; color: #E43D30; font-size: 14px; font-weight: 600;">📧 {{support_email}}</p>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'depositRequest' => [
            'subject' => '💰 Deposit Request Received - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Deposit Request Received</title>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 40px; text-align: center;">
                            <div style="margin-bottom: 8px;">
                                <img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" />
                            </div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700;">{{brand_name}}</h1>
                        </td>
                    </tr>
                    
                    <!-- Icon -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);">
                                <span style="font-size: 40px; color: white;">💰</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <h2 style="margin: 0 0 16px; color: #1a1a2e; font-size: 28px; font-weight: 700; text-align: center;">Deposit Request Received</h2>
                            <p style="margin: 0 0 24px; color: #666; font-size: 16px; line-height: 1.6; text-align: center;">Dear {{user_name}},</p>
                            <p style="margin: 0 0 32px; color: #666; font-size: 16px; line-height: 1.6;">Thank you for your deposit request. We have received your transaction and it is currently being processed by our team.</p>
                            
                            <!-- Transaction Details -->
                            <div style="background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); border-radius: 12px; padding: 24px; margin: 24px 0;">
                                <h3 style="margin: 0 0 16px; color: #1a1a2e; font-size: 18px; font-weight: 600; text-align: center;">Transaction Details</h3>
                                <table width="100%" cellpadding="8" cellspacing="0">
                                    <tr>
                                        <td style="padding: 12px 0; border-bottom: 1px solid #dee2e6;">
                                            <span style="color: #666; font-size: 14px;">💵 Amount</span>
                                        </td>
                                        <td align="right" style="padding: 12px 0; border-bottom: 1px solid #dee2e6;">
                                            <span style="color: #1a1a2e; font-size: 18px; font-weight: 700;">{{amount}}</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 12px 0; border-bottom: 1px solid #dee2e6;">
                                            <span style="color: #666; font-size: 14px;">💳 Method</span>
                                        </td>
                                        <td align="right" style="padding: 12px 0; border-bottom: 1px solid #dee2e6;">
                                            <span style="color: #1a1a2e; font-size: 16px; font-weight: 600;">{{method}}</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 12px 0;">
                                            <span style="color: #666; font-size: 14px;">📅 Date</span>
                                        </td>
                                        <td align="right" style="padding: 12px 0;">
                                            <span style="color: #1a1a2e; font-size: 14px; font-weight: 600;">{{date}}</span>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            
                            <!-- Status Info -->
                            <div style="background: #eff6ff; border-left: 4px solid #3b82f6; padding: 16px; border-radius: 8px; margin: 24px 0;">
                                <p style="margin: 0; color: #1e40af; font-size: 14px; line-height: 1.6;"><strong>⏳ Processing Time:</strong> Our team will review your deposit request and update you shortly. Most deposits are processed within 2-4 hours.</p>
                            </div>
                            
                            <p style="margin: 24px 0 0; color: #666; font-size: 14px; line-height: 1.6; text-align: center;">You\'ll receive another email once your deposit is approved and credited to your account.</p>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'depositApproved' => [
            'subject' => '✅ Deposit Approved - Funds Available Now! - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Deposit Approved</title>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); padding: 40px; text-align: center;">
                            <div style="margin-bottom: 8px;">
                                <img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" />
                            </div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700;">{{brand_name}}</h1>
                        </td>
                    </tr>
                    
                    <!-- Success Icon -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #10b981 0%, #34d399 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3); animation: pulse 2s infinite;">
                                <span style="font-size: 40px; color: white;">✓</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <h2 style="margin: 0 0 16px; color: #1a1a2e; font-size: 28px; font-weight: 700; text-align: center;">Deposit Approved!</h2>
                            <p style="margin: 0 0 24px; color: #10b981; font-size: 18px; font-weight: 600; text-align: center;">Your funds are now available 🎉</p>
                            <p style="margin: 0 0 32px; color: #666; font-size: 16px; line-height: 1.6; text-align: center;">Dear {{user_name}},</p>
                            <p style="margin: 0 0 32px; color: #666; font-size: 16px; line-height: 1.6;">Great news! Your deposit has been approved and successfully credited to your account. You can now start investing and growing your portfolio.</p>
                            
                            <!-- Transaction Summary -->
                            <div style="background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%); border-radius: 12px; padding: 24px; margin: 24px 0; border: 2px solid #10b981;">
                                <h3 style="margin: 0 0 16px; color: #065f46; font-size: 18px; font-weight: 600; text-align: center;">✅ Transaction Summary</h3>
                                <table width="100%" cellpadding="8" cellspacing="0">
                                    <tr>
                                        <td style="padding: 12px 0; border-bottom: 1px solid #a7f3d0;">
                                            <span style="color: #065f46; font-size: 14px; font-weight: 600;">💰 Deposited Amount</span>
                                        </td>
                                        <td align="right" style="padding: 12px 0; border-bottom: 1px solid #a7f3d0;">
                                            <span style="color: #065f46; font-size: 20px; font-weight: 700;">{{amount}}</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 12px 0; border-bottom: 1px solid #a7f3d0;">
                                            <span style="color: #065f46; font-size: 14px; font-weight: 600;">💳 Payment Method</span>
                                        </td>
                                        <td align="right" style="padding: 12px 0; border-bottom: 1px solid #a7f3d0;">
                                            <span style="color: #065f46; font-size: 16px; font-weight: 600;">{{method}}</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 12px 0;">
                                            <span style="color: #065f46; font-size: 14px; font-weight: 600;">💼 New Balance</span>
                                        </td>
                                        <td align="right" style="padding: 12px 0;">
                                            <span style="color: #065f46; font-size: 20px; font-weight: 700;">{{balance}}</span>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            
                            <!-- Next Steps -->
                            <div style="background: #f8f9fa; padding: 24px; border-radius: 8px; margin: 24px 0;">
                                <h3 style="margin: 0 0 12px; color: #1a1a2e; font-size: 16px; font-weight: 600;">🚀 Ready to Invest?</h3>
                                <p style="margin: 0; color: #666; font-size: 14px; line-height: 1.6;">Your funds are ready to work for you. Browse our investment plans and start earning returns today!</p>
                            </div>
                            
                            <!-- CTA Button -->
                            <table width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td align="center" style="padding: 20px 0;">
                                        <a href="http://localhost:5173/dashboard" style="display: inline-block; padding: 16px 48px; background: linear-gradient(135deg, #10b981 0%, #059669 100%); color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 600; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">View Dashboard</a>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'withdrawalRequest' => [
            'subject' => '💸 Transfer Request Received - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Transfer Request</title>
    <style>
      @media screen and (max-width: 600px) {
        .stack { display: block !important; width: 100% !important; padding-left: 0 !important; padding-right: 0 !important; }
        .pr-16 { padding-right: 0 !important; }
        .pl-16 { padding-left: 0 !important; }
      }
    </style>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 40px; text-align: center;">
                            <div style="margin-bottom: 8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" /></div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700;">{{brand_name}}</h1>
                        </td>
                    </tr>
                    
                    <!-- Icon -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(245, 158, 11, 0.3);">
                                <span style="font-size: 40px; color: white;">💸</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <p style="margin: 0 0 8px; color: #666; font-size: 14px;">Dear {{user_name}},</p>
                            <h3 style="margin: 0 0 4px; color: #c1121f; font-size: 18px; font-weight: 700;">Thank you for choosing {{brand_name}}</h3>
                            <h2 style="margin: 0 16px 16px 0; color: #1a1a2e; font-size: 20px; font-weight: 700;">Below are your transaction details:</h2>
                            <table width="100%" cellpadding="0" cellspacing="0">
                              <tr>
                                <td class="stack pr-16" valign="top" width="65%" style="padding-right:16px;">
                                  <table width="100%" cellpadding="0" cellspacing="0" style="background:#fafafa; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden;">
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Date/Time:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{date}}</td>
                                    </tr>
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Account Number:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{account_number}}</td>
                                    </tr>
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Description:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Transfer via {{method}} to {{withdrawal_address}}</td>
                                    </tr>
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Amount:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:700; text-align:right;">{{amount}}</td>
                                    </tr>
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Credit/Debit:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Debit</td>
                                    </tr>
                                    <tr>
                                      <td colspan="2" style="padding:0;">
                                        <div style="background:#b91c1c; color:#fff; padding:10px 12px; display:flex; justify-content:space-between;">
                                          <span style="font-weight:600;">Available Balance</span>
                                          <span style="font-weight:700;">{{available_balance}}</span>
                                        </div>
                                      </td>
                                    </tr>
                                  </table>
                                </td>
                                <td class="stack pl-16" valign="top" width="35%" style="padding-left:16px;">
                                  <div style="border-left:3px solid #c1121f; padding-left:12px;">
                                    <h4 style="margin:0 0 8px; color:#c1121f; font-size:14px;">Important Security and Privacy Information</h4>
                                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">We will never ask or direct you to any website that asks for security information.</p>
                                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">Never disclose your user ID, PINs and passwords, card PANs, security questions and answers to anyone.</p>
                                    <p style="margin:0; color:#666; font-size:12px; line-height:1.6;">If you discover any unauthorized activity on your account, contact us at {{fraud_email}}.</p>
                                  </div>
                                </td>
                              </tr>
                            </table>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'withdrawalApproved' => [
            'subject' => '✅ Transfer Approved - Funds on the Way! - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Transfer Approved</title>
    <style>
      @media screen and (max-width: 600px) {
        .stack { display: block !important; width: 100% !important; padding-left: 0 !important; padding-right: 0 !important; }
        .pr-16 { padding-right: 0 !important; }
        .pl-16 { padding-left: 0 !important; }
      }
    </style>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); padding: 40px; text-align: center;">
                            <div style="margin-bottom: 8px;">
                                <img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" />
                            </div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700;">{{brand_name}}</h1>
                        </td>
                    </tr>
                    
                    <!-- Success Icon -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #10b981 0%, #34d399 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);">
                                <span style="font-size: 40px; color: white;">✓</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <p style="margin: 0 0 8px; color: #666; font-size: 14px;">Dear {{user_name}},</p>
                            <h3 style="margin: 0 0 4px; color: #065f46; font-size: 18px; font-weight: 700;">Thank you for choosing {{brand_name}}</h3>
                            <h2 style="margin: 0 16px 16px 0; color: #1a1a2e; font-size: 20px; font-weight: 700;">Below are your transaction details:</h2>
                            <table width="100%" cellpadding="0" cellspacing="0">
                              <tr>
                                <td valign="top" width="65%" style="padding-right:16px;">
                                  <table width="100%" cellpadding="0" cellspacing="0" style="background:#fafafa; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden;">
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Date/Time:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{date}}</td>
                                    </tr>
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Account Number:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{account_number}}</td>
                                    </tr>
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Description:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Transfer via {{method}} to {{withdrawal_address}}</td>
                                    </tr>
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Amount:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:700; text-align:right;">{{amount}}</td>
                                    </tr>
                                    <tr>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Credit/Debit:</td>
                                      <td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Debit</td>
                                    </tr>
                                    <tr>
                                      <td colspan="2" style="padding:0;">
                                        <div style="background:#065f46; color:#fff; padding:10px 12px; display:flex; justify-content:space-between;">
                                          <span style="font-weight:600;">Available Balance</span>
                                          <span style="font-weight:700;">{{available_balance}}</span>
                                        </div>
                                      </td>
                                    </tr>
                                  </table>
                                </td>
                                <td class="stack pl-16" valign="top" width="35%" style="padding-left:16px;">
                                  <div style="border-left:3px solid #065f46; padding-left:12px;">
                                    <h4 style="margin:0 0 8px; color:#065f46; font-size:14px;">Important Security and Privacy Information</h4>
                                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">We will never ask or direct you to any website that asks for security information.</p>
                                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">Never disclose your user ID, PINs and passwords, card PANs, security questions and answers to anyone.</p>
                                    <p style="margin:0; color:#666; font-size:12px; line-height:1.6;">If you discover any unauthorized activity on your account, contact us at {{fraud_email}}.</p>
                                  </div>
                                </td>
                              </tr>
                            </table>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'kycApproved' => [
            'subject' => '🎉 KYC Verification Approved - Full Access Unlocked!',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>KYC Approved</title>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #8b5cf6 0%, #a78bfa 100%); padding: 40px; text-align: center;">
                            <div style="margin-bottom: 8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" /></div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700;">{{brand_name}}</h1>
                        </td>
                    </tr>
                    
                    <!-- Success Badge -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #10b981 0%, #34d399 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);">
                                <span style="font-size: 40px; color: white;">✓</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <h2 style="margin: 0 0 16px; color: #1a1a2e; font-size: 28px; font-weight: 700; text-align: center;">KYC Verification Approved!</h2>
                            <p style="margin: 0 0 24px; color: #10b981; font-size: 18px; font-weight: 600; text-align: center;">Congratulations! 🎉</p>
                            <p style="margin: 0 0 32px; color: #666; font-size: 16px; line-height: 1.6; text-align: center;">Hi <strong>{{user_name}}</strong>,</p>
                            <p style="margin: 0 0 32px; color: #666; font-size: 16px; line-height: 1.6;">Great news! Your identity verification has been successfully completed and approved. Your account now has full access to all premium features of our platform.</p>
                            
                            <!-- Verification Status -->
                            <div style="background: linear-gradient(135deg, #ddd6fe 0%, #ede9fe 100%); border-radius: 12px; padding: 24px; margin: 24px 0; border: 2px solid #8b5cf6; text-align: center;">
                                <div style="margin-bottom: 16px;">
                                    <span style="font-size: 48px;">🛡️</span>
                                </div>
                                <h3 style="margin: 0 0 8px; color: #5b21b6; font-size: 18px; font-weight: 600;">Verification Level</h3>
                                <p style="margin: 0; color: #5b21b6; font-size: 20px; font-weight: 700;">{{verification_level}}</p>
                            </div>
                            
                            <!-- Unlocked Features -->
                            <div style="background: #f8f9fa; padding: 24px; border-radius: 8px; margin: 24px 0;">
                                <h3 style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600; text-align: center;">✨ Unlocked Features</h3>
                                <table width="100%" cellpadding="8" cellspacing="0">
                                    <tr>
                                        <td style="padding: 8px 0;">
                                            <span style="color: #10b981; font-size: 18px; margin-right: 8px;">✓</span>
                                            <span style="color: #666; font-size: 14px;">Higher investment limits</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 8px 0;">
                                            <span style="color: #10b981; font-size: 18px; margin-right: 8px;">✓</span>
                                            <span style="color: #666; font-size: 14px;">Priority withdrawal processing</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 8px 0;">
                                            <span style="color: #10b981; font-size: 18px; margin-right: 8px;">✓</span>
                                            <span style="color: #666; font-size: 14px;">Access to premium investment plans</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 8px 0;">
                                            <span style="color: #10b981; font-size: 18px; margin-right: 8px;">✓</span>
                                            <span style="color: #666; font-size: 14px;">Enhanced account security</span>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            
                            <!-- CTA Button -->
                            <table width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td align="center" style="padding: 20px 0;">
                                        <a href="http://localhost:5173/dashboard" style="display: inline-block; padding: 16px 48px; background: linear-gradient(135deg, #8b5cf6 0%, #a78bfa 100%); color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 600; box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);">Explore Your Account</a>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'kycRejected' => [
            'subject' => '📋 KYC Verification - Action Required',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>KYC Action Required</title>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 40px; text-align: center;">
                            <div style="margin-bottom: 8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" /></div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700;">{{brand_name}}</h1>
                        </td>
                    </tr>
                    
                    <!-- Icon -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(245, 158, 11, 0.3);">
                                <span style="font-size: 40px; color: white;">📋</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <h2 style="margin: 0 0 16px; color: #1a1a2e; font-size: 28px; font-weight: 700; text-align: center;">Additional Information Required</h2>
                            <p style="margin: 0 0 24px; color: #666; font-size: 16px; line-height: 1.6; text-align: center;">Hi <strong>{{user_name}}</strong>,</p>
                            <p style="margin: 0 0 32px; color: #666; font-size: 16px; line-height: 1.6;">Thank you for submitting your KYC verification. After careful review, we need some additional information to complete the verification process.</p>
                            
                            <!-- Reason Box -->
                            <div style="background: #fef3c7; border-left: 4px solid #f59e0b; padding: 20px; border-radius: 8px; margin: 24px 0;">
                                <h3 style="margin: 0 0 12px; color: #78350f; font-size: 16px; font-weight: 600;">📌 Required Action</h3>
                                <p style="margin: 0; color: #78350f; font-size: 14px; line-height: 1.6;">{{reason}}</p>
                            </div>
                            
                            <!-- Next Steps -->
                            <div style="background: #f8f9fa; padding: 24px; border-radius: 8px; margin: 24px 0;">
                                <h3 style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">🔄 Next Steps</h3>
                                <table width="100%" cellpadding="8" cellspacing="0">
                                    <tr>
                                        <td width="40" valign="top">
                                            <div style="width: 32px; height: 32px; background: #E43D30; border-radius: 50%; color: white; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px;">1</div>
                                        </td>
                                        <td style="padding: 8px 0;">
                                            <p style="margin: 0; color: #666; font-size: 14px; line-height: 1.6;">Review the feedback above carefully</p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="40" valign="top">
                                            <div style="width: 32px; height: 32px; background: #E43D30; border-radius: 50%; color: white; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px;">2</div>
                                        </td>
                                        <td style="padding: 8px 0;">
                                            <p style="margin: 0; color: #666; font-size: 14px; line-height: 1.6;">Gather the requested documents or information</p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="40" valign="top">
                                            <div style="width: 32px; height: 32px; background: #E43D30; border-radius: 50%; color: white; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px;">3</div>
                                        </td>
                                        <td style="padding: 8px 0;">
                                            <p style="margin: 0; color: #666; font-size: 14px; line-height: 1.6;">Resubmit your KYC application through your dashboard</p>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            
                            <!-- Important Notes -->
                            <div style="background: #eff6ff; border-left: 4px solid #3b82f6; padding: 16px; border-radius: 8px; margin: 24px 0;">
                                <p style="margin: 0 0 8px; color: #1e40af; font-size: 14px; font-weight: 600;">💡 Important Notes</p>
                                <ul style="margin: 8px 0 0; padding-left: 20px; color: #1e40af; font-size: 13px; line-height: 1.6;">
                                    <li style="margin-bottom: 4px;">Ensure all documents are clear and legible</li>
                                    <li style="margin-bottom: 4px;">Documents must be current and not expired</li>
                                    <li style="margin-bottom: 4px;">Personal information must match across all documents</li>
                                </ul>
                            </div>
                            
                            <!-- CTA Button -->
                            <table width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td align="center" style="padding: 20px 0;">
                                        <a href="http://localhost:5173/dashboard/kyc" style="display: inline-block; padding: 16px 48px; background: linear-gradient(135deg, #E43D30 0%, #ff6b5a 100%); color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 600; box-shadow: 0 4px 12px rgba(228, 61, 48, 0.3);">Update KYC Documents</a>
                                    </td>
                                </tr>
                            </table>
                            
                            <!-- Help Section -->
                            <div style="background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 24px 0; text-align: center;">
                                <p style="margin: 0 0 8px; color: #666; font-size: 14px;">Need assistance?</p>
                                <p style="margin: 0; color: #E43D30; font-size: 14px; font-weight: 600;">📧 {{brand_email}}</p>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'ticketReply' => [
            'subject' => '💬 New Reply to Your Support Ticket #{{ticket_id}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ticket Reply</title>
</head>
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color: #f5f5f5;">
    <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 40px 20px;">
        <tr>
            <td align="center">
                <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); padding: 40px; text-align: center;">
                            <div style="margin-bottom: 8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display: inline-block;" /></div>
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 700;">{{brand_name}}</h1>
                            <p style="margin: 8px 0 0; color: #a0a0a0; font-size: 14px;">Support Team</p>
                        </td>
                    </tr>
                    
                    <!-- Icon -->
                    <tr>
                        <td align="center" style="padding: 40px 40px 20px;">
                            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);">
                                <span style="font-size: 40px; color: white;">💬</span>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Content -->
                    <tr>
                        <td style="padding: 0 40px 40px;">
                            <h2 style="margin: 0 0 16px; color: #1a1a2e; font-size: 28px; font-weight: 700; text-align: center;">New Reply to Your Ticket</h2>
                            <p style="margin: 0 0 24px; color: #666; font-size: 16px; line-height: 1.6; text-align: center;">Hi <strong>{{user_name}}</strong>,</p>
                            <p style="margin: 0 0 24px; color: #666; font-size: 16px; line-height: 1.6;">Our support team has responded to your ticket. We\'re here to help resolve your issue as quickly as possible.</p>
                            
                            <!-- Ticket Info -->
                            <div style="background: #eff6ff; padding: 16px 20px; border-radius: 8px; margin: 24px 0; text-align: center;">
                                <p style="margin: 0 0 4px; color: #1e40af; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;">Ticket Number</p>
                                <p style="margin: 0; color: #1e40af; font-size: 24px; font-weight: 700;">#{{ticket_id}}</p>
                            </div>
                            
                            <!-- Reply Box -->
                            <div style="background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); border-left: 4px solid #E43D30; padding: 24px; border-radius: 8px; margin: 24px 0;">
                                <div style="margin-bottom: 12px;">
                                    <span style="display: inline-block; padding: 4px 12px; background: #E43D30; color: white; border-radius: 12px; font-size: 12px; font-weight: 600;">Support Team Reply</span>
                                </div>
                                <div style="color: #1a1a2e; font-size: 15px; line-height: 1.8; white-space: pre-wrap;">
{{reply}}
                                </div>
                            </div>
                            
                            <!-- Action Needed -->
                            <div style="background: #fef3c7; border-left: 4px solid #f59e0b; padding: 16px; border-radius: 8px; margin: 24px 0;">
                                <p style="margin: 0; color: #78350f; font-size: 14px; line-height: 1.6;"><strong>💡 Tip:</strong> Click the button below to view the full conversation and reply to your ticket.</p>
                            </div>
                            
                            <!-- CTA Button -->
                            <table width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td align="center" style="padding: 20px 0;">
                                        <a href="{{ticket_link}}" style="display: inline-block; padding: 16px 48px; background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%); color: #ffffff; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 600; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);">View Full Ticket</a>
                                    </td>
                                </tr>
                            </table>
                            
                            <!-- Response Time -->
                            <div style="background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 24px 0; text-align: center;">
                                <p style="margin: 0 0 4px; color: #666; font-size: 13px;">⏱️ Average response time</p>
                                <p style="margin: 0; color: #1a1a2e; font-size: 18px; font-weight: 700;">Under 2 hours</p>
                            </div>
                        </td>
                    </tr>
                    
                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f8f9fa; padding: 32px 40px; text-align: center; border-top: 1px solid #e0e0e0;">
                            <p style="margin: 0 0 8px; color: #999; font-size: 14px;">Best regards,</p>
                            <p style="margin: 0 0 16px; color: #1a1a2e; font-size: 16px; font-weight: 600;">{{brand_name}}</p>
                            <p style="margin: 0; color: #999; font-size: 12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'
        ],
        'internalTransferSent' => [
            'subject' => 'Transfer Completed - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Transfer Completed</title>
  <style>
    @media screen and (max-width: 600px) {
      .stack { display: block !important; width: 100% !important; padding-left: 0 !important; padding-right: 0 !important; }
      .pr-16 { padding-right: 0 !important; }
      .pl-16 { padding-left: 0 !important; }
    }
  </style>
</head>
<body style="margin:0; padding:0; font-family:-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color:#f5f5f5;">
  <table width="100%" cellpadding="0" cellspacing="0" style="background-color:#f5f5f5; padding:40px 20px;">
    <tr><td align="center">
      <table width="600" cellpadding="0" cellspacing="0" style="background:#ffffff; border-radius:16px; overflow:hidden; box-shadow:0 4px 6px rgba(0,0,0,0.1);">
        <tr>
          <td style="background:linear-gradient(135deg,#1a1a2e 0%, #16213e 100%); padding:40px; text-align:center;">
            <div style="margin-bottom:8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display:inline-block;" /></div>
            <h1 style="margin:0; color:#fff; font-size:32px; font-weight:700;">{{brand_name}}</h1>
          </td>
        </tr>
        <tr>
          <td style="padding:0 40px 40px;">
            <p style="margin:0 0 8px; color:#666; font-size:14px;">Dear {{user_name}},</p>
            <h3 style="margin:0 0 4px; color:#c1121f; font-size:18px; font-weight:700;">Thank you for choosing {{brand_name}}</h3>
            <h2 style="margin:0 16px 16px 0; color:#1a1a2e; font-size:20px; font-weight:700;">Below are your transaction details:</h2>
            <table width="100%" cellpadding="0" cellspacing="0">
              <tr>
                <td class="stack pr-16" valign="top" width="65%" style="padding-right:16px;">
                  <table width="100%" cellpadding="0" cellspacing="0" style="background:#fafafa; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden;">
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Date/Time:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{date}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Account Number:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{account_number}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Description:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Internal Transfer to {{to_account}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Amount:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:700; text-align:right;">{{amount}} {{currency}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Credit/Debit:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Debit</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Reference:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">{{reference}}</td></tr>
                    <tr><td colspan="2" style="padding:0;"><div style="background:#b91c1c; color:#fff; padding:10px 12px; display:flex; justify-content:space-between;"><span style="font-weight:600;">Available Balance</span><span style="font-weight:700;">{{available_balance}}</span></div></td></tr>
                  </table>
                </td>
                <td class="stack pl-16" valign="top" width="35%" style="padding-left:16px;">
                  <div style="border-left:3px solid #c1121f; padding-left:12px;">
                    <h4 style="margin:0 0 8px; color:#c1121f; font-size:14px;">Important Security and Privacy Information</h4>
                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">We will never ask or direct you to any website that asks for security information.</p>
                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">Never disclose your user ID, PINs and passwords, card PANs, security questions and answers to anyone.</p>
                    <p style="margin:0; color:#666; font-size:12px; line-height:1.6;">If you discover any unauthorized activity on your account, contact us at {{fraud_email}}.</p>
                  </div>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td style="background:#f8f9fa; padding:32px 40px; text-align:center; border-top:1px solid #e0e0e0;">
            <p style="margin:0 0 8px; color:#999; font-size:14px;">Best regards,</p>
            <p style="margin:0 0 16px; color:#1a1a2e; font-size:16px; font-weight:600;">{{brand_name}}</p>
            <p style="margin:0; color:#999; font-size:12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
          </td>
        </tr>
      </table>
    </td></tr>
  </table>
</body>
</html>'
        ],
        'internalTransferReceived' => [
            'subject' => 'Funds Received - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Funds Received</title>
  <style>
    @media screen and (max-width: 600px) {
      .stack { display: block !important; width: 100% !important; padding-left: 0 !important; padding-right: 0 !important; }
      .pr-16 { padding-right: 0 !important; }
      .pl-16 { padding-left: 0 !important; }
    }
  </style>
</head>
<body style="margin:0; padding:0; font-family:-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color:#f5f5f5;">
  <table width="100%" cellpadding="0" cellspacing="0" style="background-color:#f5f5f5; padding:40px 20px;">
    <tr><td align="center">
      <table width="600" cellpadding="0" cellspacing="0" style="background:#ffffff; border-radius:16px; overflow:hidden; box-shadow:0 4px 6px rgba(0,0,0,0.1);">
        <tr>
          <td style="background:linear-gradient(135deg,#1a1a2e 0%, #16213e 100%); padding:40px; text-align:center;">
            <div style="margin-bottom:8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display:inline-block;" /></div>
            <h1 style="margin:0; color:#fff; font-size:32px; font-weight:700;">{{brand_name}}</h1>
          </td>
        </tr>
        <tr>
          <td style="padding:0 40px 40px;">
            <p style="margin:0 0 8px; color:#666; font-size:14px;">Dear {{user_name}},</p>
            <h3 style="margin:0 0 4px; color:#c1121f; font-size:18px; font-weight:700;">Thank you for choosing {{brand_name}}</h3>
            <h2 style="margin:0 16px 16px 0; color:#1a1a2e; font-size:20px; font-weight:700;">Below are your transaction details:</h2>
            <table width="100%" cellpadding="0" cellspacing="0">
              <tr>
                <td class="stack pr-16" valign="top" width="65%" style="padding-right:16px;">
                  <table width="100%" cellpadding="0" cellspacing="0" style="background:#fafafa; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden;">
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Date/Time:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{date}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Account Number:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{account_number}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Description:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Internal Transfer from {{from_user}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Amount:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:700; text-align:right;">{{amount}} {{currency}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Credit/Debit:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Credit</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Reference:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">{{reference}}</td></tr>
                    <tr><td colspan="2" style="padding:0;"><div style="background:#b91c1c; color:#fff; padding:10px 12px; display:flex; justify-content:space-between;"><span style="font-weight:600;">Available Balance</span><span style="font-weight:700;">{{available_balance}}</span></div></td></tr>
                  </table>
                </td>
                <td class="stack pl-16" valign="top" width="35%" style="padding-left:16px;">
                  <div style="border-left:3px solid #c1121f; padding-left:12px;">
                    <h4 style="margin:0 0 8px; color:#c1121f; font-size:14px;">Important Security and Privacy Information</h4>
                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">We will never ask or direct you to any website that asks for security information.</p>
                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">Never disclose your user ID, PINs and passwords, card PANs, security questions and answers to anyone.</p>
                    <p style="margin:0; color:#666; font-size:12px; line-height:1.6;">If you discover any unauthorized activity on your account, contact us at {{fraud_email}}.</p>
                  </div>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td style="background:#f8f9fa; padding:32px 40px; text-align:center; border-top:1px solid #e0e0e0;">
            <p style="margin:0 0 8px; color:#999; font-size:14px;">Best regards,</p>
            <p style="margin:0 0 16px; color:#1a1a2e; font-size:16px; font-weight:600;">{{brand_name}}</p>
            <p style="margin:0; color:#999; font-size:12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
          </td>
        </tr>
      </table>
    </td></tr>
  </table>
</body>
</html>'
        ],
        'applicationSubmitted' => [
            'subject' => 'Application Submitted - {{brand_name}}',
            'body' => '<!DOCTYPE html><html><body style="margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;background:#0b1220;color:#e5e7eb"><table width="100%" cellpadding="0" cellspacing="0" style="padding:24px"><tr><td align="center"><table width="600" cellpadding="0" cellspacing="0" style="background:#0f172a;border-radius:16px;overflow:hidden;border:1px solid #1f2937"><tr><td style="background:linear-gradient(135deg,#8b5cf6,#06b6d4);padding:24px;text-align:center;color:#fff;font-weight:700;font-size:20px">{{brand_name}}</td></tr><tr><td style="padding:28px"><h2 style="margin:0 0 8px;color:#fff">Application Submitted</h2><p style="margin:0 0 16px;color:#9ca3af">Thanks {{user_name}}. Your application is under review. You will be notified once approved.</p><div style="background:#0b1220;border:1px solid #1f2937;border-radius:12px;padding:16px;margin:16px 0"><table width="100%" cellpadding="6" cellspacing="0" style="color:#e5e7eb"><tr><td>Username</td><td align="right">{{username}}</td></tr><tr><td>Email</td><td align="right">{{email}}</td></tr></table></div></td></tr><tr><td style="background:#0b1220;color:#9ca3af;padding:16px;text-align:center;font-size:12px"> © 2025 {{brand_name}}</td></tr></table></td></tr></table></body></html>'
        ],
        'applicationApproved' => [
            'subject' => 'Application Approved - {{brand_name}}',
            'body' => '<!DOCTYPE html><html><body style="margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;background:#0b1220;color:#e5e7eb"><table width="100%" cellpadding="0" cellspacing="0" style="padding:24px"><tr><td align="center"><table width="600" cellpadding="0" cellspacing="0" style="background:#0f172a;border-radius:16px;overflow:hidden;border:1px solid #1f2937"><tr><td style="background:linear-gradient(135deg,#22c55e,#84cc16);padding:24px;text-align:center;color:#fff;font-weight:700;font-size:20px">{{brand_name}}</td></tr><tr><td style="padding:28px"><h2 style="margin:0 0 8px;color:#fff">Welcome aboard!</h2><p style="margin:0 0 16px;color:#9ca3af">Hi {{user_name}}, your banking application has been approved.</p><div style="background:#0b1220;border:1px solid #1f2937;border-radius:12px;padding:16px;margin:16px 0"><table width="100%" cellpadding="6" cellspacing="0" style="color:#e5e7eb"><tr><td>Username</td><td align="right">{{username}}</td></tr><tr><td>Account Number</td><td align="right"><strong>{{account_number}}</strong></td></tr></table></div><div style="text-align:center;margin-top:16px"><a href="{{login_link}}" style="display:inline-block;padding:12px 24px;background:#22c55e;color:#0b1220;border-radius:8px;text-decoration:none;font-weight:700">Go to Login</a></div></td></tr><tr><td style="background:#0b1220;color:#9ca3af;padding:16px;text-align:center;font-size:12px"> © 2025 {{brand_name}}</td></tr></table></td></tr></table></body></html>'
        ],
        'accountCredited' => [
            'subject' => 'Account Credited - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Account Credited</title>
  <style>
    @media screen and (max-width: 600px) {
      .stack { display: block !important; width: 100% !important; padding-left: 0 !important; padding-right: 0 !important; }
      .pr-16 { padding-right: 0 !important; }
      .pl-16 { padding-left: 0 !important; }
    }
  </style>
</head>
<body style="margin:0; padding:0; font-family:-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color:#f5f5f5;">
  <table width="100%" cellpadding="0" cellspacing="0" style="background-color:#f5f5f5; padding:40px 20px;">
    <tr><td align="center">
      <table width="600" cellpadding="0" cellspacing="0" style="background:#ffffff; border-radius:16px; overflow:hidden; box-shadow:0 4px 6px rgba(0,0,0,0.1);">
        <tr>
          <td style="background:linear-gradient(135deg,#1a1a2e 0%, #16213e 100%); padding:40px; text-align:center;">
            <div style="margin-bottom:8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display:inline-block;" /></div>
            <h1 style="margin:0; color:#fff; font-size:32px; font-weight:700;">{{brand_name}}</h1>
          </td>
        </tr>
        <tr>
          <td style="padding:0 40px 40px;">
            <p style="margin:0 0 8px; color:#666; font-size:14px;">Dear {{user_name}},</p>
            <h3 style="margin:0 0 4px; color:#16a34a; font-size:18px; font-weight:700;">Account Credited</h3>
            <h2 style="margin:0 16px 16px 0; color:#1a1a2e; font-size:20px; font-weight:700;">Below are your transaction details:</h2>
            <table width="100%" cellpadding="0" cellspacing="0">
              <tr>
                <td class="stack pr-16" valign="top" width="65%" style="padding-right:16px;">
                  <table width="100%" cellpadding="0" cellspacing="0" style="background:#fafafa; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden;">
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Date/Time:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{date}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Account Number:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{account_number}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Description:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Account Credit</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Amount:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:700; text-align:right;">{{amount}} {{currency}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Credit/Debit:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Credit</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Note:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">{{note}}</td></tr>
                    <tr><td colspan="2" style="padding:0;"><div style="background:#b91c1c; color:#fff; padding:10px 12px; display:flex; justify-content:space-between;"><span style="font-weight:600;">Available Balance</span><span style="font-weight:700;">{{available_balance}}</span></div></td></tr>
                  </table>
                </td>
                <td class="stack pl-16" valign="top" width="35%" style="padding-left:16px;">
                  <div style="border-left:3px solid #c1121f; padding-left:12px;">
                    <h4 style="margin:0 0 8px; color:#c1121f; font-size:14px;">Important Security and Privacy Information</h4>
                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">We will never ask or direct you to any website that asks for security information.</p>
                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">Never disclose your user ID, PINs and passwords, card PANs, security questions and answers to anyone.</p>
                    <p style="margin:0; color:#666; font-size:12px; line-height:1.6;">If you discover any unauthorized activity on your account, contact us at {{fraud_email}}.</p>
                  </div>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td style="background:#f8f9fa; padding:32px 40px; text-align:center; border-top:1px solid #e0e0e0;">
            <p style="margin:0 0 8px; color:#999; font-size:14px;">Best regards,</p>
            <p style="margin:0 0 16px; color:#1a1a2e; font-size:16px; font-weight:600;">{{brand_name}}</p>
            <p style="margin:0; color:#999; font-size:12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
          </td>
        </tr>
      </table>
    </td></tr>
  </table>
</body>
</html>'
        ],
        'accountDebited' => [
            'subject' => 'Account Debited - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Account Debited</title>
  <style>
    @media screen and (max-width: 600px) {
      .stack { display: block !important; width: 100% !important; padding-left: 0 !important; padding-right: 0 !important; }
      .pr-16 { padding-right: 0 !important; }
      .pl-16 { padding-left: 0 !important; }
    }
  </style>
</head>
<body style="margin:0; padding:0; font-family:-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background-color:#f5f5f5;">
  <table width="100%" cellpadding="0" cellspacing="0" style="background-color:#f5f5f5; padding:40px 20px;">
    <tr><td align="center">
      <table width="600" cellpadding="0" cellspacing="0" style="background:#ffffff; border-radius:16px; overflow:hidden; box-shadow:0 4px 6px rgba(0,0,0,0.1);">
        <tr>
          <td style="background:linear-gradient(135deg,#1a1a2e 0%, #16213e 100%); padding:40px; text-align:center;">
            <div style="margin-bottom:8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:40px; display:inline-block;" /></div>
            <h1 style="margin:0; color:#fff; font-size:32px; font-weight:700;">{{brand_name}}</h1>
          </td>
        </tr>
        <tr>
          <td style="padding:0 40px 40px;">
            <p style="margin:0 0 8px; color:#666; font-size:14px;">Dear {{user_name}},</p>
            <h3 style="margin:0 0 4px; color:#c1121f; font-size:18px; font-weight:700;">Account Debited</h3>
            <h2 style="margin:0 16px 16px 0; color:#1a1a2e; font-size:20px; font-weight:700;">Below are your transaction details:</h2>
            <table width="100%" cellpadding="0" cellspacing="0">
              <tr>
                <td class="stack pr-16" valign="top" width="65%" style="padding-right:16px;">
                  <table width="100%" cellpadding="0" cellspacing="0" style="background:#fafafa; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden;">
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Date/Time:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{date}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Account Number:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:600; text-align:right;">{{account_number}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Description:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Account Debit</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Amount:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; font-weight:700; text-align:right;">{{amount}} {{currency}}</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Credit/Debit:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">Debit</td></tr>
                    <tr><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#666; font-size:13px;">Note:</td><td style="padding:10px; border-bottom:1px solid #e5e7eb; color:#111; text-align:right;">{{note}}</td></tr>
                    <tr><td colspan="2" style="padding:0;"><div style="background:#b91c1c; color:#fff; padding:10px 12px; display:flex; justify-content:space-between;"><span style="font-weight:600;">Available Balance</span><span style="font-weight:700;">{{available_balance}}</span></div></td></tr>
                  </table>
                </td>
                <td class="stack pl-16" valign="top" width="35%" style="padding-left:16px;">
                  <div style="border-left:3px solid #c1121f; padding-left:12px;">
                    <h4 style="margin:0 0 8px; color:#c1121f; font-size:14px;">Important Security and Privacy Information</h4>
                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">We will never ask or direct you to any website that asks for security information.</p>
                    <p style="margin:0 0 8px; color:#666; font-size:12px; line-height:1.6;">Never disclose your user ID, PINs and passwords, card PANs, security questions and answers to anyone.</p>
                    <p style="margin:0; color:#666; font-size:12px; line-height:1.6;">If you discover any unauthorized activity on your account, contact us at {{fraud_email}}.</p>
                  </div>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td style="background:#f8f9fa; padding:32px 40px; text-align:center; border-top:1px solid #e0e0e0;">
            <p style="margin:0 0 8px; color:#999; font-size:14px;">Best regards,</p>
            <p style="margin:0 0 16px; color:#1a1a2e; font-size:16px; font-weight:600;">{{brand_name}}</p>
            <p style="margin:0; color:#999; font-size:12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
          </td>
        </tr>
      </table>
    </td></tr>
  </table>
</body>
</html>'
        ],
        'loginOtp' => [
            'subject' => 'Your Login Verification Code - {{brand_name}}',
            'body' => '<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Login Verification Code</title>
  <style>
    @media screen and (max-width: 600px) { .stack { display:block !important; width:100% !important; } }
  </style>
</head>
<body style="margin:0; padding:0; font-family:-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif; background:#f5f5f5;">
  <table width="100%" cellpadding="0" cellspacing="0" style="background:#f5f5f5; padding:40px 20px;">
    <tr><td align="center">
      <table width="600" cellpadding="0" cellspacing="0" style="background:#ffffff; border-radius:16px; overflow:hidden; box-shadow:0 4px 6px rgba(0,0,0,0.1);">
        <tr>
          <td style="background:linear-gradient(135deg,#1a1a2e 0%, #16213e 100%); padding:32px; text-align:center;">
            <div style="margin-bottom:8px;"><img src="{{brand_logo_url}}" alt="{{brand_name}}" style="max-height:36px; display:inline-block;" /></div>
            <h1 style="margin:0; color:#fff; font-size:24px; font-weight:700;">{{brand_name}}</h1>
          </td>
        </tr>
        <tr>
          <td style="padding:28px 40px 36px;">
            <p style="margin:0 0 8px; color:#666; font-size:14px;">Dear {{user_name}},</p>
            <p style="margin:0 0 16px; color:#1a1a2e; font-size:16px;">Use the code below to complete your login. It expires in 60 minutes.</p>
            <div style="text-align:center; margin:20px 0;">
              <div style="display:inline-block; padding:12px 20px; border-radius:8px; background:#111827; color:#fff; font-size:24px; letter-spacing:4px; font-weight:800;">{{otp_code}}</div>
            </div>
            <p style="margin:0; color:#666; font-size:12px;">If this wasn\'t you, please secure your account immediately.</p>
          </td>
        </tr>
        <tr>
          <td style="background:#f8f9fa; padding:24px 40px; text-align:center; border-top:1px solid #e0e0e0;">
            <p style="margin:0 0 8px; color:#999; font-size:14px;">Best regards,</p>
            <p style="margin:0 0 12px; color:#1a1a2e; font-size:16px; font-weight:600;">{{brand_name}}</p>
            <p style="margin:0; color:#999; font-size:12px;">© 2025 {{brand_name}} · {{brand_address}} · {{brand_email}}</p>
          </td>
        </tr>
      </table>
    </td></tr>
  </table>
</body>
</html>'
        ],
    ];
}

$conn = null;
?>
