<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Invoice - {{ invoice_number }}</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            background-color: #ffffff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .header {
            text-align: center;
            padding-bottom: 20px;
            border-bottom: 1px solid #eee;
        }
        .header h1 {
            color: #2c3e50;
            margin: 0;
        }
        .content {
            padding: 20px 0;
        }
        .invoice-details {
            background-color: #ecf0f1;
            padding: 15px;
            border-radius: 5px;
            margin: 20px 0;
        }
        .invoice-details h2 {
            margin-top: 0;
            color: #3498db;
        }
        .detail-row {
            display: flex;
            justify-content: space-between;
            padding: 5px 0;
            border-bottom: 1px solid #ddd;
        }
        .detail-row:last-child {
            border-bottom: none;
            font-weight: bold;
            margin-top: 10px;
            padding-top: 10px;
            border-top: 2px solid #3498db;
        }
        .detail-label {
            font-weight: bold;
        }
        .cta-button {
            display: inline-block;
            background-color: #27ae60;
            color: #ffffff;
            padding: 12px 24px;
            text-decoration: none;
            border-radius: 5px;
            font-weight: bold;
            text-align: center;
            margin: 20px 0;
        }
        .footer {
            text-align: center;
            padding-top: 20px;
            border-top: 1px solid #eee;
            color: #7f8c8d;
            font-size: 14px;
        }
        .note {
            background-color: #fff3cd;
            border-left: 4px solid #ffc107;
            padding: 10px;
            margin: 15px 0;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>Invoice</h1>
        </div>
        <div class="content">
            <p>Dear {{ customer_name }},</p>
            <p>Thank you for your business with {{ company_name }}. Please find your invoice details below:</p>
            
            <div class="invoice-details">
                <h2>Invoice Details</h2>
                <div class="detail-row">
                    <span class="detail-label">Invoice Number:</span>
                    <span>{{ invoice_number }}</span>
                </div>
                <div class="detail-row">
                    <span class="detail-label">Invoice Date:</span>
                    <span>{{ invoice_date }}</span>
                </div>
                <div class="detail-row">
                    <span class="detail-label">Due Date:</span>
                    <span>{{ due_date }}</span>
                </div>
                {% if sales_order %}
                <div class="detail-row">
                    <span class="detail-label">Related Sales Order:</span>
                    <span>{{ sales_order }}</span>
                </div>
                {% endif %}
                <div class="detail-row">
                    <span class="detail-label">Invoice Total:</span>
                    <span>{{ grand_total }}</span>
                </div>
                {% if paid_amount and paid_amount != "$0.00" %}
                <div class="detail-row">
                    <span class="detail-label">Amount Paid:</span>
                    <span>{{ paid_amount }}</span>
                </div>
                {% endif %}
                <div class="detail-row">
                    <span class="detail-label">Amount Due:</span>
                    <span>{{ outstanding_amount }}</span>
                </div>
            </div>
            
            {% if payment_url and outstanding_amount != "$0.00" %}
            <div class="note">
                <strong>Payment Required:</strong> There is an outstanding balance on this invoice. Please click the button below to make a secure payment.
            </div>
            <a href="{{ payment_url }}" class="cta-button">Pay Now</a>
            {% else %}
            <div class="note">
                <strong>Paid in Full:</strong> This invoice has been paid in full. Thank you!
            </div>
            {% endif %}
            
            <p>If you have any questions about this invoice, please don't hesitate to contact us.</p>
            <p>Best regards,<br>The Team at {{ company_name }}</p>
        </div>
        <div class="footer">
            <p>This is an automated email. Please do not reply directly.</p>
        </div>
    </div>
</body>
</html>