"""
Management command to seed default email templates.

These templates are created for new businesses and can be customized.
Platform templates are shared across all tenants.

Usage:
    # Seed templates for all schemas
    python manage.py seed_email_templates

    # Seed templates for a specific schema
    python manage.py seed_email_templates --schema=demo

    # Force reset to defaults (overwrites existing)
    python manage.py seed_email_templates --reset
"""
from django.core.management.base import BaseCommand
from django.db import connection
from django_tenants.utils import schema_context, get_tenant_model


class Command(BaseCommand):
    help = 'Seed default email templates for tenants'

    def add_arguments(self, parser):
        parser.add_argument(
            '--schema',
            type=str,
            help='Specific tenant schema to seed (default: all tenants)',
        )
        parser.add_argument(
            '--reset',
            action='store_true',
            help='Reset templates to defaults (overwrites existing)',
        )

    def handle(self, *args, **options):
        schema = options.get('schema')
        reset = options.get('reset', False)

        if schema:
            # Seed specific schema
            self.seed_schema(schema, reset)
        else:
            # Seed all tenant schemas
            Tenant = get_tenant_model()
            tenants = Tenant.objects.exclude(schema_name='public')

            for tenant in tenants:
                self.seed_schema(tenant.schema_name, reset)

        self.stdout.write(self.style.SUCCESS('Email templates seeded successfully!'))

    def seed_schema(self, schema_name, reset=False):
        """Seed templates for a specific schema"""
        self.stdout.write(f'Seeding templates for schema: {schema_name}')

        with schema_context(schema_name):
            from schedule.models import EmailTemplate

            if reset:
                # Delete all existing templates first
                deleted_count = EmailTemplate.objects.all().delete()[0]
                self.stdout.write(f'  Deleted {deleted_count} existing templates')

            templates = self.get_default_templates()

            for template_data in templates:
                name = template_data['name']

                if reset:
                    # Already deleted above, just create
                    EmailTemplate.objects.create(**template_data)
                    self.stdout.write(f'  Created: {name}')
                else:
                    # Only create if doesn't exist
                    _, created = EmailTemplate.objects.get_or_create(
                        name=name,
                        defaults=template_data
                    )
                    if created:
                        self.stdout.write(f'  Created: {name}')
                    else:
                        self.stdout.write(f'  Skipped (exists): {name}')

    def get_default_templates(self):
        """Return list of default email templates"""
        return [
            # ========== CONFIRMATION TEMPLATES ==========
            {
                'name': 'Appointment Confirmation - Modern Blue',
                'description': 'Clean, corporate style with rounded corners and blue hero header. Ideal for medical, tech, or professional services.',
                'category': 'CONFIRMATION',
                'scope': 'BUSINESS',
                'subject': 'Your appointment at {{BUSINESS_NAME}} is confirmed!',
                'html_content': self.get_confirmation_modern_blue(),
                'text_content': self.get_confirmation_text(),
            },
            {
                'name': 'Appointment Confirmation - Classic Serif',
                'description': 'Elegant style with serif fonts, warm beige background. Perfect for law firms, salons, or luxury brands.',
                'category': 'CONFIRMATION',
                'scope': 'BUSINESS',
                'subject': 'Appointment Confirmation - {{BUSINESS_NAME}}',
                'html_content': self.get_confirmation_classic_serif(),
                'text_content': self.get_confirmation_text(),
            },
            {
                'name': 'Appointment Confirmation - Bold Dark',
                'description': 'High contrast dark mode with vibrant pink accents. Great for gyms, barbershops, or nightlife venues.',
                'category': 'CONFIRMATION',
                'scope': 'BUSINESS',
                'subject': 'Confirmed! Your appointment at {{BUSINESS_NAME}}',
                'html_content': self.get_confirmation_bold_dark(),
                'text_content': self.get_confirmation_text(),
            },

            # ========== REMINDER TEMPLATES ==========
            {
                'name': 'Appointment Reminder - Soft Clean',
                'description': 'Minimalist style with soft pink/rose colors. Friendly and non-intrusive.',
                'category': 'REMINDER',
                'scope': 'BUSINESS',
                'subject': 'Reminder: Your appointment at {{BUSINESS_NAME}} is coming up!',
                'html_content': self.get_reminder_soft_clean(),
                'text_content': self.get_reminder_text(),
            },
            {
                'name': 'Appointment Reminder - Urgent Bold',
                'description': 'Bold red accents with "Action Required" styling to reduce no-shows.',
                'category': 'REMINDER',
                'scope': 'BUSINESS',
                'subject': 'ACTION REQUIRED: Your appointment at {{BUSINESS_NAME}}',
                'html_content': self.get_reminder_urgent_bold(),
                'text_content': self.get_reminder_text(),
            },

            # ========== MARKETING TEMPLATES ==========
            {
                'name': 'Welcome - Vibrant',
                'description': 'High energy welcome email with gradient top bar and image collages. Designed to excite new customers.',
                'category': 'MARKETING',
                'scope': 'BUSINESS',
                'subject': 'Welcome to {{BUSINESS_NAME}}!',
                'html_content': self.get_marketing_welcome_vibrant(),
                'text_content': self.get_welcome_text(),
            },
            {
                'name': 'Promo - Minimalist',
                'description': 'Black and white monospace design with bold typography. Perfect for flash sales and limited offers.',
                'category': 'MARKETING',
                'scope': 'BUSINESS',
                'subject': 'Limited Time Offer from {{BUSINESS_NAME}}',
                'html_content': self.get_marketing_minimalist_promo(),
                'text_content': self.get_promo_text(),
            },
            {
                'name': 'Newsletter - Grid Layout',
                'description': 'Magazine-style newsletter with featured content, staff spotlight, and community events.',
                'category': 'MARKETING',
                'scope': 'BUSINESS',
                'subject': '{{BUSINESS_NAME}} Monthly Newsletter',
                'html_content': self.get_marketing_newsletter_grid(),
                'text_content': self.get_newsletter_text(),
            },

            # ========== REPORT TEMPLATES ==========
            {
                'name': 'Report - Monthly Data',
                'description': 'Utility-focused layout with data grid and performance metrics. Designed for clarity and readability.',
                'category': 'REPORT',
                'scope': 'BUSINESS',
                'subject': 'Monthly Performance Report - {{BUSINESS_NAME}}',
                'html_content': self.get_report_monthly_data(),
                'text_content': self.get_monthly_report_text(),
            },
            {
                'name': 'Report - Weekly Snapshot',
                'description': 'Dark themed card layout showing key weekly metrics: revenue, bookings, ratings, and cancellations.',
                'category': 'REPORT',
                'scope': 'BUSINESS',
                'subject': 'Weekly Snapshot - {{BUSINESS_NAME}}',
                'html_content': self.get_report_weekly_cards(),
                'text_content': self.get_weekly_report_text(),
            },
            {
                'name': 'Report - Staff Leaderboard',
                'description': 'Staff performance rankings with appointment counts and revenue. Great for team motivation.',
                'category': 'REPORT',
                'scope': 'BUSINESS',
                'subject': 'Staff Performance Report - {{BUSINESS_NAME}}',
                'html_content': self.get_report_staff_leaderboard(),
                'text_content': self.get_staff_report_text(),
            },

            # ========== NOTIFICATION TEMPLATES ==========
            {
                'name': 'Appointment Rescheduled',
                'description': 'Sent when an appointment is rescheduled',
                'category': 'NOTIFICATION',
                'scope': 'BUSINESS',
                'subject': 'Your appointment at {{BUSINESS_NAME}} has been rescheduled',
                'html_content': self.get_appointment_rescheduled_html(),
                'text_content': self.get_appointment_rescheduled_text(),
            },
            {
                'name': 'Appointment Cancelled',
                'description': 'Sent when an appointment is cancelled',
                'category': 'NOTIFICATION',
                'scope': 'BUSINESS',
                'subject': 'Your appointment at {{BUSINESS_NAME}} has been cancelled',
                'html_content': self.get_appointment_cancelled_html(),
                'text_content': self.get_appointment_cancelled_text(),
            },
            {
                'name': 'Thank You - Appointment Complete',
                'description': 'Sent after an appointment is completed',
                'category': 'NOTIFICATION',
                'scope': 'BUSINESS',
                'subject': 'Thank you for visiting {{BUSINESS_NAME}}!',
                'html_content': self.get_thank_you_html(),
                'text_content': self.get_thank_you_text(),
            },

            # ========== TICKET NOTIFICATIONS ==========
            {
                'name': 'Ticket Assigned',
                'description': 'Notification when a ticket is assigned to a staff member',
                'category': 'NOTIFICATION',
                'scope': 'BUSINESS',
                'subject': '[Ticket #{{TICKET_ID}}] You have been assigned: {{TICKET_SUBJECT}}',
                'html_content': self.get_ticket_assigned_html(),
                'text_content': self.get_ticket_assigned_text(),
            },
            {
                'name': 'Ticket Status Changed',
                'description': 'Notification when ticket status changes',
                'category': 'NOTIFICATION',
                'scope': 'BUSINESS',
                'subject': '[Ticket #{{TICKET_ID}}] Status updated: {{TICKET_STATUS}}',
                'html_content': self.get_ticket_status_changed_html(),
                'text_content': self.get_ticket_status_changed_text(),
            },
            {
                'name': 'Ticket Reply - Staff Notification',
                'description': 'Notification to staff when customer replies to ticket',
                'category': 'NOTIFICATION',
                'scope': 'BUSINESS',
                'subject': '[Ticket #{{TICKET_ID}}] New reply from customer: {{TICKET_SUBJECT}}',
                'html_content': self.get_ticket_reply_staff_html(),
                'text_content': self.get_ticket_reply_staff_text(),
            },
            {
                'name': 'Ticket Reply - Customer Notification',
                'description': 'Notification to customer when staff replies to ticket',
                'category': 'NOTIFICATION',
                'scope': 'BUSINESS',
                'subject': '[Ticket #{{TICKET_ID}}] {{BUSINESS_NAME}} has responded to your request',
                'html_content': self.get_ticket_reply_customer_html(),
                'text_content': self.get_ticket_reply_customer_text(),
            },
            {
                'name': 'Ticket Resolved',
                'description': 'Notification when a ticket is resolved/closed',
                'category': 'NOTIFICATION',
                'scope': 'BUSINESS',
                'subject': '[Ticket #{{TICKET_ID}}] Your request has been resolved',
                'html_content': self.get_ticket_resolved_html(),
                'text_content': self.get_ticket_resolved_text(),
            },
        ]

    # ========== CONFIRMATION TEMPLATES ==========

    def get_confirmation_modern_blue(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Appointment Confirmed</title>
</head>
<body style="margin: 0; padding: 0; background-color: #f3f4f6; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 40px 0;">
                <table width="600" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #ffffff; border-radius: 16px; overflow: hidden; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);">
                    <!-- Hero Image Section -->
                    <tr>
                        <td style="background-color: #4f46e5; padding: 40px; text-align: center;">
                            <h1 style="margin: 0; color: #ffffff; font-size: 28px; font-weight: 700;">Appointment Confirmed</h1>
                        </td>
                    </tr>

                    <!-- Content Section -->
                    <tr>
                        <td style="padding: 40px;">
                            <h1 style="margin: 0 0 20px; color: #111827; font-size: 24px; font-weight: 700; line-height: 1.2;">
                                You're All Set, {{CUSTOMER_NAME}}!
                            </h1>
                            <p style="margin: 0 0 24px; color: #4b5563; font-size: 16px; line-height: 1.6;">
                                We are excited to see you at <strong>{{BUSINESS_NAME}}</strong>. Your appointment has been confirmed for the following time:
                            </p>

                            <!-- Appointment Card -->
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #f9fafb; border-radius: 12px; border: 1px solid #e5e7eb;">
                                <tr>
                                    <td style="padding: 24px;">
                                        <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                            <tr>
                                                <td style="padding-bottom: 16px; border-bottom: 1px solid #e5e7eb;">
                                                    <p style="margin: 0; color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;">Service</p>
                                                    <p style="margin: 4px 0 0; color: #111827; font-size: 18px; font-weight: 600;">{{APPOINTMENT_SERVICE}}</p>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="padding-top: 16px;">
                                                    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                                        <tr>
                                                            <td width="50%" valign="top">
                                                                <p style="margin: 0; color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;">Date</p>
                                                                <p style="margin: 4px 0 0; color: #111827; font-size: 16px;">{{APPOINTMENT_DATE}}</p>
                                                            </td>
                                                            <td width="50%" valign="top">
                                                                <p style="margin: 0; color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;">Time</p>
                                                                <p style="margin: 4px 0 0; color: #111827; font-size: 16px;">{{APPOINTMENT_TIME}}</p>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>

                            <!-- CTA Button -->
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="margin-top: 32px;">
                                <tr>
                                    <td align="center">
                                        <a href="#" style="display: inline-block; background-color: #4f46e5; color: #ffffff; font-size: 16px; font-weight: 600; text-decoration: none; padding: 12px 32px; border-radius: 8px;">
                                            Manage Appointment
                                        </a>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #1f2937; padding: 32px; text-align: center;">
                            <p style="margin: 0 0 8px; color: #9ca3af; font-size: 14px;">
                                {{BUSINESS_NAME}}
                            </p>
                            <p style="margin: 0; color: #6b7280; font-size: 12px;">
                                {{BUSINESS_PHONE}} • {{BUSINESS_EMAIL}}
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_confirmation_classic_serif(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Appointment Confirmed</title>
</head>
<body style="margin: 0; padding: 0; background-color: #faf9f6; font-family: 'Georgia', 'Times New Roman', serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 40px 0;">
                <table width="600" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #ffffff; border: 1px solid #e7e5e4; border-top: 4px solid #1c1917;">
                    <!-- Header -->
                    <tr>
                        <td style="padding: 40px 40px 20px; text-align: center;">
                            <h2 style="margin: 0; color: #1c1917; font-size: 24px; font-weight: 400; letter-spacing: 0.05em;">{{BUSINESS_NAME}}</h2>
                        </td>
                    </tr>

                    <!-- Content -->
                    <tr>
                        <td style="padding: 20px 60px 40px;">
                            <h1 style="margin: 0 0 24px; color: #1c1917; font-size: 28px; font-weight: 400; text-align: center; letter-spacing: -0.02em;">
                                Appointment Confirmation
                            </h1>
                            <p style="margin: 0 0 24px; color: #44403c; font-size: 16px; line-height: 1.8; text-align: center;">
                                Dear {{CUSTOMER_NAME}},<br><br>
                                We are pleased to confirm your appointment with {{BUSINESS_NAME}}. Please review the details below.
                            </p>

                            <!-- Divider -->
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                <tr>
                                    <td style="border-bottom: 1px solid #e7e5e4; padding-bottom: 20px; margin-bottom: 20px;"></td>
                                </tr>
                            </table>

                            <!-- Details -->
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="margin-top: 20px;">
                                <tr>
                                    <td style="padding: 12px 0; color: #78716c; font-family: 'Arial', sans-serif; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em;">Service</td>
                                    <td style="padding: 12px 0; text-align: right; color: #1c1917; font-size: 16px;">{{APPOINTMENT_SERVICE}}</td>
                                </tr>
                                <tr>
                                    <td style="border-bottom: 1px solid #f5f5f4; padding: 0;" colspan="2"></td>
                                </tr>
                                <tr>
                                    <td style="padding: 12px 0; color: #78716c; font-family: 'Arial', sans-serif; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em;">Date</td>
                                    <td style="padding: 12px 0; text-align: right; color: #1c1917; font-size: 16px;">{{APPOINTMENT_DATE}}</td>
                                </tr>
                                <tr>
                                    <td style="border-bottom: 1px solid #f5f5f4; padding: 0;" colspan="2"></td>
                                </tr>
                                <tr>
                                    <td style="padding: 12px 0; color: #78716c; font-family: 'Arial', sans-serif; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em;">Time</td>
                                    <td style="padding: 12px 0; text-align: right; color: #1c1917; font-size: 16px;">{{APPOINTMENT_TIME}}</td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #1c1917; padding: 30px; text-align: center;">
                            <p style="margin: 0; color: #d6d3d1; font-family: 'Arial', sans-serif; font-size: 13px; line-height: 1.6;">
                                {{BUSINESS_NAME}}<br>
                                {{BUSINESS_PHONE}} | {{BUSINESS_EMAIL}}
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_confirmation_bold_dark(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Appointment Confirmed</title>
</head>
<body style="margin: 0; padding: 0; background-color: #000000; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 20px;">
                <table width="600" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #111111; border-radius: 24px; overflow: hidden;">
                    <!-- Header -->
                    <tr>
                        <td style="background-color: #db2777; padding: 40px; text-align: center;">
                            <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: 800; letter-spacing: -0.03em;">CONFIRMED</h1>
                        </td>
                    </tr>

                    <!-- Content -->
                    <tr>
                        <td style="padding: 48px 40px;">
                            <h1 style="margin: 0 0 16px; color: #ffffff; font-size: 32px; font-weight: 800; letter-spacing: -0.03em;">
                                Ready for you, {{CUSTOMER_NAME}}.
                            </h1>
                            <p style="margin: 0 0 40px; color: #a1a1aa; font-size: 18px; line-height: 1.5;">
                                Your slot is locked in. We've got everything prepared for your upcoming visit.
                            </p>

                            <!-- Grid Layout for Details -->
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                <tr>
                                    <td width="48%" style="background-color: #18181b; padding: 24px; border-radius: 16px; vertical-align: top;">
                                        <p style="margin: 0 0 8px; color: #db2777; font-size: 12px; font-weight: 700; text-transform: uppercase;">Service</p>
                                        <p style="margin: 0; color: #ffffff; font-size: 16px; font-weight: 600;">{{APPOINTMENT_SERVICE}}</p>
                                    </td>
                                    <td width="4%"></td>
                                    <td width="48%" style="background-color: #18181b; padding: 24px; border-radius: 16px; vertical-align: top;">
                                        <p style="margin: 0 0 8px; color: #db2777; font-size: 12px; font-weight: 700; text-transform: uppercase;">When</p>
                                        <p style="margin: 0; color: #ffffff; font-size: 16px; font-weight: 600;">{{APPOINTMENT_DATE}}<br><span style="color: #a1a1aa; font-weight: 400;">{{APPOINTMENT_TIME}}</span></p>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                        <td style="padding: 0 40px 40px; text-align: center;">
                            <p style="margin: 0; color: #52525b; font-size: 14px;">
                                {{BUSINESS_NAME}} • {{BUSINESS_PHONE}}
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_confirmation_text(self):
        return '''Your Appointment is Confirmed!

Hi {{CUSTOMER_NAME}},

Great news! Your appointment at {{BUSINESS_NAME}} has been confirmed.

APPOINTMENT DETAILS
-------------------
Date: {{APPOINTMENT_DATE}}
Time: {{APPOINTMENT_TIME}}
Service: {{APPOINTMENT_SERVICE}}

Need to make changes?
If you need to reschedule or cancel, please contact us as soon as possible.

See you soon!
The {{BUSINESS_NAME}} Team

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''

    # ========== REMINDER TEMPLATES ==========

    def get_reminder_soft_clean(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Appointment Reminder</title>
</head>
<body style="margin: 0; padding: 0; background-color: #fff1f2; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 60px 0;">
                <table width="500" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #ffffff; border-radius: 20px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.01);">
                    <!-- Circle Icon -->
                    <tr>
                        <td align="center" style="padding-top: 40px;">
                            <div style="width: 120px; height: 120px; background-color: #fb7185; border-radius: 50%; display: inline-block; line-height: 120px; text-align: center;">
                                <span style="color: #ffffff; font-size: 48px;">⏰</span>
                            </div>
                        </td>
                    </tr>

                    <!-- Content -->
                    <tr>
                        <td style="padding: 30px 50px 50px; text-align: center;">
                            <h1 style="margin: 0 0 16px; color: #881337; font-size: 24px; font-weight: 600;">
                                Just a Friendly Reminder
                            </h1>
                            <p style="margin: 0 0 32px; color: #4c0519; font-size: 16px; line-height: 1.6;">
                                Hi {{CUSTOMER_NAME}}, your appointment with {{BUSINESS_NAME}} is coming up soon!
                            </p>

                            <div style="background-color: #fff1f2; border-radius: 12px; padding: 20px;">
                                <p style="margin: 0 0 8px; color: #be123c; font-size: 18px; font-weight: 700;">{{APPOINTMENT_DATE}}</p>
                                <p style="margin: 0; color: #9f1239; font-size: 24px; font-weight: 300;">{{APPOINTMENT_TIME}}</p>
                            </div>

                            <p style="margin: 32px 0 0; color: #9ca3af; font-size: 13px;">
                                Need to make changes? <a href="#" style="color: #fb7185; text-decoration: underline;">Reschedule here</a>
                            </p>
                        </td>
                    </tr>
                </table>

                <!-- Simple Footer -->
                <table width="500" cellpadding="0" cellspacing="0" role="presentation">
                    <tr>
                        <td style="padding-top: 20px; text-align: center;">
                            <p style="margin: 0; color: #f43f5e; font-size: 12px;">
                                {{BUSINESS_NAME}}
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_reminder_urgent_bold(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Appointment Reminder</title>
</head>
<body style="margin: 0; padding: 0; background-color: #fef2f2; font-family: 'Arial Black', 'Arial Bold', sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 20px;">
                <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="max-width: 600px; border-left: 8px solid #ef4444; background-color: #ffffff;">
                    <tr>
                        <td style="padding: 40px;">
                            <p style="margin: 0 0 10px; color: #ef4444; font-size: 14px; letter-spacing: 1px; text-transform: uppercase;">Action Required</p>
                            <h1 style="margin: 0 0 30px; color: #111827; font-size: 36px; line-height: 1;">
                                Don't Forget<br>Your Visit.
                            </h1>

                            <p style="margin: 0 0 20px; color: #374151; font-family: 'Arial', sans-serif; font-size: 16px; line-height: 1.6;">
                                <strong>{{CUSTOMER_NAME}}</strong>, we're holding your spot for <strong>{{APPOINTMENT_SERVICE}}</strong>.
                            </p>

                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #111827; color: #ffffff;">
                                <tr>
                                    <td align="center" style="padding: 20px;">
                                        <p style="margin: 0; font-size: 20px; font-family: 'Arial', sans-serif;">{{APPOINTMENT_DATE}} @ {{APPOINTMENT_TIME}}</p>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="background-color: #f3f4f6; padding: 20px; text-align: center;">
                            <p style="margin: 0; color: #6b7280; font-family: 'Arial', sans-serif; font-size: 12px;">
                                {{BUSINESS_NAME}} - {{BUSINESS_PHONE}}
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_reminder_text(self):
        return '''Reminder: Your Appointment is Coming Up!

Hi {{CUSTOMER_NAME}},

This is a friendly reminder that your appointment at {{BUSINESS_NAME}} is coming up soon.

APPOINTMENT DETAILS
-------------------
Date: {{APPOINTMENT_DATE}}
Time: {{APPOINTMENT_TIME}}
Service: {{APPOINTMENT_SERVICE}}

We recommend arriving 5-10 minutes early to ensure a smooth check-in.

Need to reschedule?
Please contact us as soon as possible if you need to make any changes.

See you soon!
The {{BUSINESS_NAME}} Team

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''

    # ========== MARKETING TEMPLATES ==========

    def get_marketing_welcome_vibrant(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome</title>
</head>
<body style="margin: 0; padding: 0; background-color: #ffffff; font-family: 'Verdana', sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <!-- Colorful Top Bar -->
        <tr>
            <td height="8" style="background: linear-gradient(90deg, #8b5cf6 0%, #ec4899 100%);"></td>
        </tr>

        <tr>
            <td align="center" style="padding: 40px 20px;">
                <table width="600" cellpadding="0" cellspacing="0" role="presentation">
                    <!-- Logo -->
                    <tr>
                        <td align="center" style="padding-bottom: 40px;">
                            <div style="width: 80px; height: 80px; background-color: #8b5cf6; border-radius: 50%; line-height: 80px; text-align: center;">
                                <span style="color: #ffffff; font-size: 32px; font-weight: bold;">S</span>
                            </div>
                        </td>
                    </tr>

                    <!-- Hero -->
                    <tr>
                        <td align="center">
                            <h1 style="margin: 0 0 20px; color: #111827; font-size: 42px; font-weight: 900; letter-spacing: -1px;">
                                Welcome to the family.
                            </h1>
                            <p style="margin: 0 0 40px; color: #6b7280; font-size: 18px; max-width: 480px;">
                                Thanks for joining <strong>{{BUSINESS_NAME}}</strong>! We're thrilled to have you on board.
                            </p>
                        </td>
                    </tr>

                    <!-- Features Grid -->
                    <tr>
                        <td style="padding: 40px 0;">
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                <tr>
                                    <td width="33%" valign="top" style="padding-right: 10px;">
                                        <h3 style="margin: 0 0 8px; color: #111827; font-size: 16px;">Expert Staff</h3>
                                        <p style="margin: 0; color: #6b7280; font-size: 14px; line-height: 1.5;">Top-tier professionals ready to serve.</p>
                                    </td>
                                    <td width="33%" valign="top" style="padding: 0 10px;">
                                        <h3 style="margin: 0 0 8px; color: #111827; font-size: 16px;">Easy Booking</h3>
                                        <p style="margin: 0; color: #6b7280; font-size: 14px; line-height: 1.5;">Schedule anytime, anywhere.</p>
                                    </td>
                                    <td width="33%" valign="top" style="padding-left: 10px;">
                                        <h3 style="margin: 0 0 8px; color: #111827; font-size: 16px;">Best Value</h3>
                                        <p style="margin: 0; color: #6b7280; font-size: 14px; line-height: 1.5;">Premium service at great rates.</p>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <!-- CTA -->
                    <tr>
                        <td align="center" style="padding-top: 20px;">
                            <a href="#" style="background-color: #111827; color: #ffffff; padding: 16px 40px; border-radius: 50px; text-decoration: none; font-weight: 600; font-size: 16px; display: inline-block;">Book Your First Visit</a>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_marketing_minimalist_promo(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Special Offer</title>
</head>
<body style="margin: 0; padding: 0; background-color: #ffffff; font-family: 'Courier New', Courier, monospace;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 40px 20px;">
                <table width="600" cellpadding="0" cellspacing="0" role="presentation" style="border: 2px solid #000000;">
                    <!-- Big Hero -->
                    <tr>
                        <td style="background-color: #000000; padding: 60px 40px; text-align: center;">
                            <h1 style="margin: 0; color: #ffffff; font-size: 48px; font-weight: 900; letter-spacing: 4px;">FLASH SALE</h1>
                        </td>
                    </tr>

                    <!-- Content -->
                    <tr>
                        <td style="padding: 40px; text-align: center;">
                            <h1 style="margin: 0 0 20px; color: #000000; font-size: 36px; font-weight: 700; text-transform: uppercase; letter-spacing: 2px;">
                                limited time only
                            </h1>
                            <p style="margin: 0 0 40px; color: #333333; font-size: 16px; line-height: 1.6; font-family: 'Helvetica', sans-serif;">
                                Treat yourself to something special. For the next 48 hours, get exclusive access to our VIP booking slots and a special discount.
                            </p>

                            <!-- Coupon Code Box -->
                            <div style="border: 2px dashed #000000; padding: 20px; display: inline-block; margin-bottom: 40px;">
                                <p style="margin: 0 0 5px; font-size: 12px; color: #666; font-family: sans-serif;">USE CODE:</p>
                                <span style="font-size: 32px; font-weight: 900; color: #d946ef;">VIP20</span>
                            </div>

                            <br>

                            <a href="#" style="background-color: #000000; color: #ffffff; padding: 18px 40px; text-decoration: none; font-weight: bold; font-size: 14px; text-transform: uppercase; display: inline-block;">
                                Claim Offer
                            </a>
                        </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                        <td style="border-top: 2px solid #000000; padding: 20px; text-align: center;">
                            <p style="margin: 0; font-size: 12px; color: #000000;">
                                {{BUSINESS_NAME}}
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_marketing_newsletter_grid(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Newsletter</title>
</head>
<body style="margin: 0; padding: 0; background-color: #e5e7eb; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <!-- Top Bar -->
        <tr>
            <td style="background-color: #374151; padding: 10px 0; text-align: center; color: #d1d5db; font-size: 12px;">
                View this email in your browser
            </td>
        </tr>

        <tr>
            <td align="center" style="padding: 40px 20px;">
                <!-- Logo Header -->
                <table width="640" cellpadding="0" cellspacing="0" role="presentation" style="margin-bottom: 20px;">
                    <tr>
                        <td align="center">
                            <h1 style="margin: 0; color: #1f2937; font-size: 28px; font-weight: 300; letter-spacing: 1px;">{{BUSINESS_NAME}} <span style="color: #3b82f6; font-weight: 700;">MONTHLY</span></h1>
                        </td>
                    </tr>
                </table>

                <!-- Main Feature -->
                <table width="640" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #ffffff; margin-bottom: 20px;">
                    <tr>
                        <td style="background-color: #3b82f6; padding: 40px; text-align: center;">
                            <h2 style="margin: 0; color: #ffffff; font-size: 28px;">New Service Launch</h2>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding: 30px;">
                            <h2 style="margin: 0 0 10px; color: #111827; font-size: 24px;">Introducing Our New Premium Service</h2>
                            <p style="margin: 0 0 20px; color: #4b5563; line-height: 1.6;">
                                We've been listening to your feedback and are excited to announce a brand new way to experience {{BUSINESS_NAME}}. Our new premium tier offers extended hours and dedicated support.
                            </p>
                            <a href="#" style="color: #3b82f6; text-decoration: none; font-weight: 600;">Read more →</a>
                        </td>
                    </tr>
                </table>

                <!-- Two Column Grid -->
                <table width="640" cellpadding="0" cellspacing="0" role="presentation">
                    <tr>
                        <td width="310" valign="top" style="background-color: #ffffff; padding-bottom: 20px;">
                            <div style="background-color: #10b981; padding: 30px; text-align: center;">
                                <span style="color: #ffffff; font-size: 24px;">★</span>
                            </div>
                            <div style="padding: 20px;">
                                <h3 style="margin: 0 0 10px; color: #111827; font-size: 18px;">Employee of the Month</h3>
                                <p style="margin: 0 0 15px; color: #6b7280; font-size: 14px; line-height: 1.5;">
                                    Meet our lead specialist who has gone above and beyond this month.
                                </p>
                            </div>
                        </td>
                        <td width="20"><!-- Gutter --></td>
                        <td width="310" valign="top" style="background-color: #ffffff; padding-bottom: 20px;">
                            <div style="background-color: #f59e0b; padding: 30px; text-align: center;">
                                <span style="color: #ffffff; font-size: 24px;">♥</span>
                            </div>
                            <div style="padding: 20px;">
                                <h3 style="margin: 0 0 10px; color: #111827; font-size: 18px;">Community Events</h3>
                                <p style="margin: 0 0 15px; color: #6b7280; font-size: 14px; line-height: 1.5;">
                                    Join us this weekend for our local charity drive.
                                </p>
                            </div>
                        </td>
                    </tr>
                </table>

                <!-- Footer -->
                <table width="640" cellpadding="0" cellspacing="0" role="presentation" style="margin-top: 40px;">
                    <tr>
                        <td align="center">
                            <p style="margin: 0 0 10px; color: #9ca3af; font-size: 12px;">
                                © {{TODAY}} {{BUSINESS_NAME}}. All rights reserved.
                            </p>
                            <p style="margin: 0; color: #9ca3af; font-size: 12px;">
                                {{BUSINESS_ADDRESS}}
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_welcome_text(self):
        return '''Welcome to {{BUSINESS_NAME}}!

Hi {{CUSTOMER_NAME}},

Welcome! We're thrilled to have you join our community at {{BUSINESS_NAME}}.

Your account is all set up!

Here's what you can do:
- Book appointments online anytime
- View and manage your upcoming appointments
- Update your contact information and preferences

Ready to book your first appointment?
We can't wait to see you!

Best regards,
The {{BUSINESS_NAME}} Team

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''

    def get_promo_text(self):
        return '''LIMITED TIME OFFER from {{BUSINESS_NAME}}

FLASH SALE - 48 HOURS ONLY

Treat yourself to something special!

Get exclusive access to our VIP booking slots and a special discount.

USE CODE: VIP20

Visit us online or call to claim this offer.

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''

    def get_newsletter_text(self):
        return '''{{BUSINESS_NAME}} MONTHLY NEWSLETTER

INTRODUCING OUR NEW PREMIUM SERVICE

We've been listening to your feedback and are excited to announce a brand new way to experience {{BUSINESS_NAME}}. Our new premium tier offers extended hours and dedicated support.

EMPLOYEE OF THE MONTH
Meet our lead specialist who has gone above and beyond this month.

COMMUNITY EVENTS
Join us this weekend for our local charity drive.

---
© {{TODAY}} {{BUSINESS_NAME}}. All rights reserved.
{{BUSINESS_ADDRESS}}
'''

    # ========== REPORT TEMPLATES ==========

    def get_report_monthly_data(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Monthly Report</title>
</head>
<body style="margin: 0; padding: 0; background-color: #f8fafc; font-family: 'Roboto', 'Helvetica', sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 20px;">
                <!-- Header -->
                <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="max-width: 800px; margin-bottom: 20px;">
                    <tr>
                        <td style="padding: 20px 0;">
                            <h1 style="margin: 0; color: #0f172a; font-size: 20px; font-weight: 500;">
                                <span style="color: #3b82f6; font-weight: 700;">Smooth</span>Schedule Report
                            </h1>
                        </td>
                        <td align="right">
                            <p style="margin: 0; color: #64748b; font-size: 14px;">{{TODAY}}</p>
                        </td>
                    </tr>
                </table>

                <!-- Main Card -->
                <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="max-width: 800px; background-color: #ffffff; border: 1px solid #e2e8f0; border-radius: 8px;">
                    <tr>
                        <td style="padding: 30px;">
                            <h2 style="margin: 0 0 20px; color: #0f172a; font-size: 18px;">Performance Summary</h2>

                            <!-- Summary Stats -->
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #f1f5f9; border-radius: 8px; margin-bottom: 30px;">
                                <tr>
                                    <td style="padding: 20px; text-align: center; border-right: 1px solid #e2e8f0;">
                                        <p style="margin: 0 0 5px; color: #64748b; font-size: 12px; text-transform: uppercase;">Revenue</p>
                                        <p style="margin: 0; color: #0f172a; font-size: 24px; font-weight: 700;">{{TOTAL_REVENUE}}</p>
                                    </td>
                                    <td style="padding: 20px; text-align: center; border-right: 1px solid #e2e8f0;">
                                        <p style="margin: 0 0 5px; color: #64748b; font-size: 12px; text-transform: uppercase;">Appointments</p>
                                        <p style="margin: 0; color: #0f172a; font-size: 24px; font-weight: 700;">{{TOTAL_APPOINTMENTS}}</p>
                                    </td>
                                    <td style="padding: 20px; text-align: center;">
                                        <p style="margin: 0 0 5px; color: #64748b; font-size: 12px; text-transform: uppercase;">New Customers</p>
                                        <p style="margin: 0; color: #0f172a; font-size: 24px; font-weight: 700;">{{NEW_CUSTOMERS}}</p>
                                    </td>
                                </tr>
                            </table>

                            <p style="margin: 20px 0 0; color: #64748b; font-size: 14px;">
                                This report was automatically generated for <strong>{{BUSINESS_NAME}}</strong>.
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <td style="background-color: #f1f5f9; padding: 15px 30px; text-align: center; border-top: 1px solid #e2e8f0;">
                            <a href="#" style="color: #3b82f6; font-size: 14px; text-decoration: none; font-weight: 500;">View Full Report in Dashboard →</a>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_report_weekly_cards(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Weekly Snapshot</title>
</head>
<body style="margin: 0; padding: 0; background-color: #1e293b; font-family: 'Roboto', sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 40px 20px;">
                <table width="600" cellpadding="0" cellspacing="0" role="presentation">
                    <!-- Header -->
                    <tr>
                        <td style="padding-bottom: 30px;">
                            <h1 style="margin: 0; color: #ffffff; font-size: 24px;">Weekly Snapshot</h1>
                            <p style="margin: 5px 0 0; color: #94a3b8;">Week of {{TODAY}}</p>
                        </td>
                    </tr>

                    <!-- Stats Grid -->
                    <tr>
                        <td>
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                <tr>
                                    <!-- Card 1 -->
                                    <td width="290" style="background-color: #334155; border-radius: 8px; padding: 25px; vertical-align: top;">
                                        <div style="width: 40px; height: 40px; background-color: #3b82f6; border-radius: 8px; text-align: center; line-height: 40px; margin-bottom: 15px;">
                                            <span style="color: #ffffff; font-size: 20px;">$</span>
                                        </div>
                                        <p style="margin: 0 0 5px; color: #94a3b8; font-size: 13px; text-transform: uppercase;">Revenue</p>
                                        <p style="margin: 0; color: #ffffff; font-size: 28px; font-weight: 700;">{{WEEKLY_REVENUE}}</p>
                                        <p style="margin: 5px 0 0; color: #4ade80; font-size: 12px;">{{REVENUE_CHANGE}}</p>
                                    </td>
                                    <td width="20"></td>
                                    <!-- Card 2 -->
                                    <td width="290" style="background-color: #334155; border-radius: 8px; padding: 25px; vertical-align: top;">
                                        <div style="width: 40px; height: 40px; background-color: #8b5cf6; border-radius: 8px; text-align: center; line-height: 40px; margin-bottom: 15px;">
                                            <span style="color: #ffffff; font-size: 20px;">#</span>
                                        </div>
                                        <p style="margin: 0 0 5px; color: #94a3b8; font-size: 13px; text-transform: uppercase;">Bookings</p>
                                        <p style="margin: 0; color: #ffffff; font-size: 28px; font-weight: 700;">{{WEEKLY_BOOKINGS}}</p>
                                        <p style="margin: 5px 0 0; color: #94a3b8; font-size: 12px;">{{BOOKINGS_CHANGE}}</p>
                                    </td>
                                </tr>
                                <tr><td height="20"></td></tr>
                                <tr>
                                    <!-- Card 3 -->
                                    <td width="290" style="background-color: #334155; border-radius: 8px; padding: 25px; vertical-align: top;">
                                        <div style="width: 40px; height: 40px; background-color: #f59e0b; border-radius: 8px; text-align: center; line-height: 40px; margin-bottom: 15px;">
                                            <span style="color: #ffffff; font-size: 20px;">★</span>
                                        </div>
                                        <p style="margin: 0 0 5px; color: #94a3b8; font-size: 13px; text-transform: uppercase;">Avg Rating</p>
                                        <p style="margin: 0; color: #ffffff; font-size: 28px; font-weight: 700;">{{AVG_RATING}}</p>
                                    </td>
                                    <td width="20"></td>
                                    <!-- Card 4 -->
                                    <td width="290" style="background-color: #334155; border-radius: 8px; padding: 25px; vertical-align: top;">
                                        <div style="width: 40px; height: 40px; background-color: #ef4444; border-radius: 8px; text-align: center; line-height: 40px; margin-bottom: 15px;">
                                            <span style="color: #ffffff; font-size: 20px;">!</span>
                                        </div>
                                        <p style="margin: 0 0 5px; color: #94a3b8; font-size: 13px; text-transform: uppercase;">Cancellations</p>
                                        <p style="margin: 0; color: #ffffff; font-size: 28px; font-weight: 700;">{{CANCELLATIONS}}</p>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                        <td style="padding-top: 40px; text-align: center;">
                            <a href="#" style="color: #3b82f6; text-decoration: none; font-size: 14px;">View detailed analytics</a>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_report_staff_leaderboard(self):
        return '''<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Staff Performance</title>
</head>
<body style="margin: 0; padding: 0; background-color: #f3f4f6; font-family: 'Arial', sans-serif;">
    <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
        <tr>
            <td align="center" style="padding: 40px 20px;">
                <table width="600" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #ffffff; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);">
                    <!-- Header -->
                    <tr>
                        <td style="padding: 30px; border-bottom: 1px solid #e5e7eb;">
                            <h1 style="margin: 0; color: #111827; font-size: 20px;">Staff Performance</h1>
                            <p style="margin: 5px 0 0; color: #6b7280; font-size: 14px;">Top performers for {{TODAY}}</p>
                        </td>
                    </tr>

                    <!-- Leaderboard List -->
                    <tr>
                        <td style="padding: 0 30px;">
                            <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                <!-- Top Performer -->
                                <tr>
                                    <td style="padding: 20px 0; border-bottom: 1px solid #f3f4f6;">
                                        <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                            <tr>
                                                <td width="50">
                                                    <div style="width: 40px; height: 40px; background-color: #10b981; border-radius: 50%; text-align: center; line-height: 40px;">
                                                        <span style="color: #ffffff; font-weight: bold;">1</span>
                                                    </div>
                                                </td>
                                                <td>
                                                    <p style="margin: 0; font-weight: 600; color: #111827;">{{TOP_STAFF_1_NAME}}</p>
                                                    <p style="margin: 2px 0 0; font-size: 12px; color: #6b7280;">{{TOP_STAFF_1_APPOINTMENTS}} Appointments</p>
                                                </td>
                                                <td align="right" width="100">
                                                    <p style="margin: 0; font-weight: 700; color: #10b981;">{{TOP_STAFF_1_REVENUE}}</p>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <!-- Second Place -->
                                <tr>
                                    <td style="padding: 20px 0; border-bottom: 1px solid #f3f4f6;">
                                        <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                            <tr>
                                                <td width="50">
                                                    <div style="width: 40px; height: 40px; background-color: #3b82f6; border-radius: 50%; text-align: center; line-height: 40px;">
                                                        <span style="color: #ffffff; font-weight: bold;">2</span>
                                                    </div>
                                                </td>
                                                <td>
                                                    <p style="margin: 0; font-weight: 600; color: #111827;">{{TOP_STAFF_2_NAME}}</p>
                                                    <p style="margin: 2px 0 0; font-size: 12px; color: #6b7280;">{{TOP_STAFF_2_APPOINTMENTS}} Appointments</p>
                                                </td>
                                                <td align="right" width="100">
                                                    <p style="margin: 0; font-weight: 700; color: #111827;">{{TOP_STAFF_2_REVENUE}}</p>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <!-- Third Place -->
                                <tr>
                                    <td style="padding: 20px 0;">
                                        <table width="100%" cellpadding="0" cellspacing="0" role="presentation">
                                            <tr>
                                                <td width="50">
                                                    <div style="width: 40px; height: 40px; background-color: #6b7280; border-radius: 50%; text-align: center; line-height: 40px;">
                                                        <span style="color: #ffffff; font-weight: bold;">3</span>
                                                    </div>
                                                </td>
                                                <td>
                                                    <p style="margin: 0; font-weight: 600; color: #111827;">{{TOP_STAFF_3_NAME}}</p>
                                                    <p style="margin: 2px 0 0; font-size: 12px; color: #6b7280;">{{TOP_STAFF_3_APPOINTMENTS}} Appointments</p>
                                                </td>
                                                <td align="right" width="100">
                                                    <p style="margin: 0; font-weight: 700; color: #111827;">{{TOP_STAFF_3_REVENUE}}</p>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                        <td style="background-color: #f9fafb; padding: 20px 30px; border-radius: 0 0 12px 12px;">
                            <p style="margin: 0; font-size: 13px; color: #6b7280; text-align: center;">
                                Great work team!
                            </p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>'''

    def get_monthly_report_text(self):
        return '''MONTHLY PERFORMANCE REPORT - {{BUSINESS_NAME}}

Date: {{TODAY}}

PERFORMANCE SUMMARY
-------------------
Total Revenue: {{TOTAL_REVENUE}}
Appointments: {{TOTAL_APPOINTMENTS}}
New Customers: {{NEW_CUSTOMERS}}

This report was automatically generated for {{BUSINESS_NAME}}.

View full report in your dashboard.

---
{{BUSINESS_NAME}}
'''

    def get_weekly_report_text(self):
        return '''WEEKLY SNAPSHOT - {{BUSINESS_NAME}}

Week of {{TODAY}}

KEY METRICS
-----------
Revenue: {{WEEKLY_REVENUE}} ({{REVENUE_CHANGE}})
Bookings: {{WEEKLY_BOOKINGS}} ({{BOOKINGS_CHANGE}})
Avg Rating: {{AVG_RATING}}
Cancellations: {{CANCELLATIONS}}

View detailed analytics in your dashboard.

---
{{BUSINESS_NAME}}
'''

    def get_staff_report_text(self):
        return '''STAFF PERFORMANCE REPORT - {{BUSINESS_NAME}}

Top Performers for {{TODAY}}

1. {{TOP_STAFF_1_NAME}}
   Appointments: {{TOP_STAFF_1_APPOINTMENTS}}
   Revenue: {{TOP_STAFF_1_REVENUE}}

2. {{TOP_STAFF_2_NAME}}
   Appointments: {{TOP_STAFF_2_APPOINTMENTS}}
   Revenue: {{TOP_STAFF_2_REVENUE}}

3. {{TOP_STAFF_3_NAME}}
   Appointments: {{TOP_STAFF_3_APPOINTMENTS}}
   Revenue: {{TOP_STAFF_3_REVENUE}}

Great work team!

---
{{BUSINESS_NAME}}
'''

    # ========== NOTIFICATION TEMPLATES ==========

    def get_email_wrapper_start(self, title=''):
        return f'''<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{title}</title>
    <style>
        body {{
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }}
        .container {{
            background-color: #ffffff;
            border-radius: 8px;
            padding: 40px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }}
        .header {{
            text-align: center;
            margin-bottom: 30px;
        }}
        .business-name {{
            font-size: 24px;
            font-weight: bold;
            color: #6366f1;
        }}
        h1 {{
            color: #1f2937;
            font-size: 24px;
            margin-bottom: 20px;
        }}
        p {{
            color: #4b5563;
            margin-bottom: 15px;
        }}
        .highlight-box {{
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
            border-radius: 12px;
            padding: 25px;
            margin: 25px 0;
            color: white;
        }}
        .info-row {{
            display: flex;
            margin-bottom: 10px;
        }}
        .info-label {{
            font-weight: 600;
            margin-right: 10px;
        }}
        .cta-button {{
            display: inline-block;
            background-color: #6366f1;
            color: #ffffff !important;
            text-decoration: none;
            padding: 14px 32px;
            border-radius: 8px;
            font-weight: 600;
            font-size: 16px;
            margin: 20px 0;
        }}
        .footer {{
            text-align: center;
            margin-top: 40px;
            padding-top: 20px;
            border-top: 1px solid #e5e7eb;
            color: #9ca3af;
            font-size: 14px;
        }}
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="business-name">{{{{BUSINESS_NAME}}}}</div>
        </div>
'''

    def get_email_wrapper_end(self):
        return '''
        <div class="footer">
            <p>
                This email was sent by {{BUSINESS_NAME}}.<br>
                If you have questions, please contact us at {{BUSINESS_EMAIL}}.
            </p>
        </div>
    </div>
</body>
</html>
'''

    def get_appointment_rescheduled_html(self):
        return self.get_email_wrapper_start('Appointment Rescheduled') + '''
        <h1>Your Appointment Has Been Rescheduled</h1>

        <p>Hi {{CUSTOMER_NAME}},</p>

        <p>
            Your appointment at <strong>{{BUSINESS_NAME}}</strong> has been rescheduled.
            Please note the new date and time below.
        </p>

        <div class="highlight-box">
            <div class="info-row">
                <span class="info-label">📅 New Date:</span>
                <span>{{APPOINTMENT_DATE}}</span>
            </div>
            <div class="info-row">
                <span class="info-label">🕐 New Time:</span>
                <span>{{APPOINTMENT_TIME}}</span>
            </div>
            <div class="info-row">
                <span class="info-label">💼 Service:</span>
                <span>{{APPOINTMENT_SERVICE}}</span>
            </div>
        </div>

        <p>
            If this new time doesn't work for you, please contact us to find an alternative.
        </p>

        <p>Thank you for your understanding!</p>
        <p><strong>The {{BUSINESS_NAME}} Team</strong></p>
''' + self.get_email_wrapper_end()

    def get_appointment_rescheduled_text(self):
        return '''Your Appointment Has Been Rescheduled

Hi {{CUSTOMER_NAME}},

Your appointment at {{BUSINESS_NAME}} has been rescheduled.

NEW APPOINTMENT DETAILS
-----------------------
Date: {{APPOINTMENT_DATE}}
Time: {{APPOINTMENT_TIME}}
Service: {{APPOINTMENT_SERVICE}}

If this new time doesn't work for you, please contact us to find an alternative.

Thank you for your understanding!
The {{BUSINESS_NAME}} Team

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''

    def get_appointment_cancelled_html(self):
        return self.get_email_wrapper_start('Appointment Cancelled') + '''
        <h1>Your Appointment Has Been Cancelled</h1>

        <p>Hi {{CUSTOMER_NAME}},</p>

        <p>
            We're writing to confirm that your appointment at <strong>{{BUSINESS_NAME}}</strong>
            has been cancelled.
        </p>

        <div style="background-color: #fef3c7; border: 1px solid #fcd34d; border-radius: 8px; padding: 15px; margin: 20px 0;">
            <p style="margin: 0; color: #92400e;">
                <strong>Cancelled Appointment:</strong><br>
                {{APPOINTMENT_DATE}} at {{APPOINTMENT_TIME}}<br>
                Service: {{APPOINTMENT_SERVICE}}
            </p>
        </div>

        <p>
            We'd love to see you! Would you like to book a new appointment?
            Visit our booking page or give us a call.
        </p>

        <p>Thank you!</p>
        <p><strong>The {{BUSINESS_NAME}} Team</strong></p>
''' + self.get_email_wrapper_end()

    def get_appointment_cancelled_text(self):
        return '''Your Appointment Has Been Cancelled

Hi {{CUSTOMER_NAME}},

We're writing to confirm that your appointment at {{BUSINESS_NAME}} has been cancelled.

CANCELLED APPOINTMENT
---------------------
Date: {{APPOINTMENT_DATE}}
Time: {{APPOINTMENT_TIME}}
Service: {{APPOINTMENT_SERVICE}}

We'd love to see you! Would you like to book a new appointment?
Visit our booking page or give us a call.

Thank you!
The {{BUSINESS_NAME}} Team

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''

    def get_thank_you_html(self):
        return self.get_email_wrapper_start('Thank You') + '''
        <h1>Thank You for Visiting!</h1>

        <p>Hi {{CUSTOMER_NAME}},</p>

        <p>
            Thank you for choosing <strong>{{BUSINESS_NAME}}</strong>!
            We hope you had a wonderful experience with us.
        </p>

        <div style="background-color: #ecfdf5; border: 1px solid #6ee7b7; border-radius: 8px; padding: 20px; margin: 20px 0; text-align: center;">
            <p style="margin: 0; color: #065f46; font-size: 18px;">
                We'd Love Your Feedback!
            </p>
            <p style="margin: 10px 0 0 0; color: #047857;">
                Your opinion helps us improve and helps others find great services.
            </p>
        </div>

        <p>
            Ready to book your next appointment? We're here whenever you need us!
        </p>

        <p>See you again soon!</p>
        <p><strong>The {{BUSINESS_NAME}} Team</strong></p>
''' + self.get_email_wrapper_end()

    def get_thank_you_text(self):
        return '''Thank You for Visiting!

Hi {{CUSTOMER_NAME}},

Thank you for choosing {{BUSINESS_NAME}}! We hope you had a wonderful experience with us.

We'd Love Your Feedback!
Your opinion helps us improve and helps others find great services.

Ready to book your next appointment? We're here whenever you need us!

See you again soon!
The {{BUSINESS_NAME}} Team

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''

    # ========== TICKET NOTIFICATION TEMPLATES ==========

    def get_ticket_assigned_html(self):
        return self.get_email_wrapper_start('Ticket Assigned') + '''
        <h1>New Ticket Assigned to You</h1>

        <p>Hi {{ASSIGNEE_NAME}},</p>

        <p>
            A ticket has been assigned to you and requires your attention.
        </p>

        <div class="highlight-box">
            <div class="info-row">
                <span class="info-label">🎫 Ticket:</span>
                <span>#{{TICKET_ID}}</span>
            </div>
            <div class="info-row">
                <span class="info-label">📋 Subject:</span>
                <span>{{TICKET_SUBJECT}}</span>
            </div>
            <div class="info-row">
                <span class="info-label">⚡ Priority:</span>
                <span>{{TICKET_PRIORITY}}</span>
            </div>
            <div class="info-row">
                <span class="info-label">👤 From:</span>
                <span>{{TICKET_CUSTOMER_NAME}}</span>
            </div>
        </div>

        <div style="background-color: #f3f4f6; border-radius: 8px; padding: 15px; margin: 20px 0;">
            <p style="margin: 0 0 10px 0; font-weight: 600; color: #374151;">Message:</p>
            <p style="margin: 0; color: #4b5563;">{{TICKET_MESSAGE}}</p>
        </div>

        <p style="text-align: center;">
            <a href="{{TICKET_URL}}" class="cta-button">View Ticket</a>
        </p>

        <p>Please respond as soon as possible.</p>
        <p><strong>{{BUSINESS_NAME}}</strong></p>
''' + self.get_email_wrapper_end()

    def get_ticket_assigned_text(self):
        return '''New Ticket Assigned to You

Hi {{ASSIGNEE_NAME}},

A ticket has been assigned to you and requires your attention.

TICKET DETAILS
--------------
Ticket: #{{TICKET_ID}}
Subject: {{TICKET_SUBJECT}}
Priority: {{TICKET_PRIORITY}}
From: {{TICKET_CUSTOMER_NAME}}

Message:
{{TICKET_MESSAGE}}

View ticket: {{TICKET_URL}}

Please respond as soon as possible.

---
{{BUSINESS_NAME}}
'''

    def get_ticket_status_changed_html(self):
        return self.get_email_wrapper_start('Ticket Status Updated') + '''
        <h1>Ticket Status Updated</h1>

        <p>Hi {{RECIPIENT_NAME}},</p>

        <p>
            The status of ticket <strong>#{{TICKET_ID}}</strong> has been updated.
        </p>

        <div class="highlight-box">
            <div class="info-row">
                <span class="info-label">🎫 Ticket:</span>
                <span>#{{TICKET_ID}}</span>
            </div>
            <div class="info-row">
                <span class="info-label">📋 Subject:</span>
                <span>{{TICKET_SUBJECT}}</span>
            </div>
            <div class="info-row">
                <span class="info-label">📊 New Status:</span>
                <span>{{TICKET_STATUS}}</span>
            </div>
        </div>

        <p style="text-align: center;">
            <a href="{{TICKET_URL}}" class="cta-button">View Ticket</a>
        </p>

        <p><strong>{{BUSINESS_NAME}}</strong></p>
''' + self.get_email_wrapper_end()

    def get_ticket_status_changed_text(self):
        return '''Ticket Status Updated

Hi {{RECIPIENT_NAME}},

The status of ticket #{{TICKET_ID}} has been updated.

TICKET DETAILS
--------------
Ticket: #{{TICKET_ID}}
Subject: {{TICKET_SUBJECT}}
New Status: {{TICKET_STATUS}}

View ticket: {{TICKET_URL}}

---
{{BUSINESS_NAME}}
'''

    def get_ticket_reply_staff_html(self):
        return self.get_email_wrapper_start('New Customer Reply') + '''
        <h1>New Reply on Ticket #{{TICKET_ID}}</h1>

        <p>Hi {{ASSIGNEE_NAME}},</p>

        <p>
            <strong>{{TICKET_CUSTOMER_NAME}}</strong> has replied to ticket <strong>#{{TICKET_ID}}</strong>.
        </p>

        <div style="background-color: #f3f4f6; border-radius: 8px; padding: 15px; margin: 20px 0;">
            <p style="margin: 0 0 10px 0; font-weight: 600; color: #374151;">
                Subject: {{TICKET_SUBJECT}}
            </p>
            <p style="margin: 0; color: #4b5563;">{{REPLY_MESSAGE}}</p>
        </div>

        <p style="text-align: center;">
            <a href="{{TICKET_URL}}" class="cta-button">View & Reply</a>
        </p>

        <p><strong>{{BUSINESS_NAME}}</strong></p>
''' + self.get_email_wrapper_end()

    def get_ticket_reply_staff_text(self):
        return '''New Reply on Ticket #{{TICKET_ID}}

Hi {{ASSIGNEE_NAME}},

{{TICKET_CUSTOMER_NAME}} has replied to ticket #{{TICKET_ID}}.

Subject: {{TICKET_SUBJECT}}

Reply:
{{REPLY_MESSAGE}}

View & reply: {{TICKET_URL}}

---
{{BUSINESS_NAME}}
'''

    def get_ticket_reply_customer_html(self):
        return self.get_email_wrapper_start('Response to Your Request') + '''
        <h1>We've Responded to Your Request</h1>

        <p>Hi {{CUSTOMER_NAME}},</p>

        <p>
            We've replied to your support request.
        </p>

        <div class="highlight-box">
            <div class="info-row">
                <span class="info-label">🎫 Ticket:</span>
                <span>#{{TICKET_ID}}</span>
            </div>
            <div class="info-row">
                <span class="info-label">📋 Subject:</span>
                <span>{{TICKET_SUBJECT}}</span>
            </div>
        </div>

        <div style="background-color: #f3f4f6; border-radius: 8px; padding: 15px; margin: 20px 0;">
            <p style="margin: 0 0 10px 0; font-weight: 600; color: #374151;">Our Response:</p>
            <p style="margin: 0; color: #4b5563;">{{REPLY_MESSAGE}}</p>
        </div>

        <p>
            <strong>Need to reply?</strong><br>
            Simply reply to this email or click the button below.
        </p>

        <p style="text-align: center;">
            <a href="{{TICKET_URL}}" class="cta-button">View Full Conversation</a>
        </p>

        <p>Thank you for contacting us!</p>
        <p><strong>The {{BUSINESS_NAME}} Team</strong></p>
''' + self.get_email_wrapper_end()

    def get_ticket_reply_customer_text(self):
        return '''We've Responded to Your Request

Hi {{CUSTOMER_NAME}},

We've replied to your support request.

TICKET DETAILS
--------------
Ticket: #{{TICKET_ID}}
Subject: {{TICKET_SUBJECT}}

Our Response:
{{REPLY_MESSAGE}}

Need to reply?
Simply reply to this email or visit: {{TICKET_URL}}

Thank you for contacting us!
The {{BUSINESS_NAME}} Team

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''

    def get_ticket_resolved_html(self):
        return self.get_email_wrapper_start('Ticket Resolved') + '''
        <h1>Your Request Has Been Resolved</h1>

        <p>Hi {{CUSTOMER_NAME}},</p>

        <p>
            Great news! Your support request has been resolved.
        </p>

        <div style="background-color: #ecfdf5; border: 1px solid #6ee7b7; border-radius: 8px; padding: 20px; margin: 20px 0; text-align: center;">
            <p style="margin: 0; font-size: 18px; color: #065f46;">
                ✅ Ticket #{{TICKET_ID}} - Resolved
            </p>
        </div>

        <div style="background-color: #f3f4f6; border-radius: 8px; padding: 15px; margin: 20px 0;">
            <p style="margin: 0 0 10px 0; font-weight: 600; color: #374151;">
                Subject: {{TICKET_SUBJECT}}
            </p>
            <p style="margin: 0; color: #4b5563; font-size: 14px;">
                Resolution: {{RESOLUTION_MESSAGE}}
            </p>
        </div>

        <p>
            <strong>Not satisfied with the resolution?</strong><br>
            You can reopen this ticket by replying to this email within the next 7 days.
        </p>

        <p style="text-align: center;">
            <a href="{{TICKET_URL}}" class="cta-button">View Ticket History</a>
        </p>

        <p>Thank you for your patience!</p>
        <p><strong>The {{BUSINESS_NAME}} Team</strong></p>
''' + self.get_email_wrapper_end()

    def get_ticket_resolved_text(self):
        return '''Your Request Has Been Resolved

Hi {{CUSTOMER_NAME}},

Great news! Your support request has been resolved.

Ticket #{{TICKET_ID}} - RESOLVED

Subject: {{TICKET_SUBJECT}}
Resolution: {{RESOLUTION_MESSAGE}}

Not satisfied with the resolution?
You can reopen this ticket by replying to this email within the next 7 days.

View ticket history: {{TICKET_URL}}

Thank you for your patience!
The {{BUSINESS_NAME}} Team

---
{{BUSINESS_NAME}}
{{BUSINESS_EMAIL}}
{{BUSINESS_PHONE}}
'''
