<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>New Purchase Order - {{po_number}}</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            line-height: 1.6;
            color: #333333;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
        }
        .email-container {
            max-width: 600px;
            margin: 20px auto;
            background-color: #ffffff;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }
        .header {
            background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
            color: #ffffff;
            padding: 30px 20px;
            text-align: center;
        }
        .header h1 {
            margin: 0;
            font-size: 24px;
            font-weight: 600;
        }
        .header p {
            margin: 8px 0 0 0;
            font-size: 14px;
            opacity: 0.9;
        }
        .content {
            padding: 30px 20px;
        }
        .greeting {
            font-size: 16px;
            margin-bottom: 20px;
        }
        .info-box {
            background-color: #F9FAFB;
            border-left: 4px solid #4F46E5;
            padding: 16px;
            margin: 20px 0;
            border-radius: 4px;
        }
        .info-box h3 {
            margin: 0 0 12px 0;
            font-size: 14px;
            font-weight: 600;
            text-transform: uppercase;
            color: #6B7280;
        }
        .info-row {
            display: flex;
            justify-content: space-between;
            padding: 8px 0;
            border-bottom: 1px solid #E5E7EB;
        }
        .info-row:last-child {
            border-bottom: none;
        }
        .info-label {
            font-weight: 500;
            color: #6B7280;
        }
        .info-value {
            font-weight: 600;
            color: #111827;
        }
        .items-table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        .items-table thead {
            background-color: #F3F4F6;
        }
        .items-table th {
            padding: 12px;
            text-align: left;
            font-size: 13px;
            font-weight: 600;
            color: #6B7280;
            text-transform: uppercase;
            border-bottom: 2px solid #E5E7EB;
        }
        .items-table td {
            padding: 12px;
            border-bottom: 1px solid #E5E7EB;
            font-size: 14px;
        }
        .items-table tbody tr:last-child td {
            border-bottom: none;
        }
        .items-table tbody tr:hover {
            background-color: #F9FAFB;
        }
        .text-right {
            text-align: right;
        }
        .total-row {
            background-color: #F3F4F6;
            font-weight: 600;
            font-size: 16px;
        }
        .total-row td {
            padding: 16px 12px;
            border-top: 2px solid #4F46E5;
        }
        .cta-button {
            display: inline-block;
            background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
            color: #ffffff;
            text-decoration: none;
            padding: 14px 28px;
            border-radius: 6px;
            font-weight: 600;
            font-size: 14px;
            margin: 20px 0;
            text-align: center;
            box-shadow: 0 4px 6px rgba(79, 70, 229, 0.2);
        }
        .cta-button:hover {
            opacity: 0.9;
        }
        .notes {
            background-color: #FEF3C7;
            border-left: 4px solid #F59E0B;
            padding: 16px;
            margin: 20px 0;
            border-radius: 4px;
        }
        .notes h4 {
            margin: 0 0 8px 0;
            font-size: 14px;
            font-weight: 600;
            color: #92400E;
        }
        .notes p {
            margin: 0;
            font-size: 14px;
            color: #78350F;
        }
        .footer {
            background-color: #F9FAFB;
            padding: 20px;
            text-align: center;
            font-size: 12px;
            color: #6B7280;
            border-top: 1px solid #E5E7EB;
        }
        .footer p {
            margin: 4px 0;
        }
        .footer a {
            color: #4F46E5;
            text-decoration: none;
        }
        @media only screen and (max-width: 600px) {
            .email-container {
                margin: 0;
                border-radius: 0;
            }
            .content {
                padding: 20px 16px;
            }
            .items-table th,
            .items-table td {
                padding: 8px;
                font-size: 12px;
            }
        }
    </style>
</head>
<body>
    <div class="email-container">
        <!-- Header -->
        <div class="header">
            <h1>📦 New Purchase Order</h1>
            <p>Order #{{po_number}}</p>
        </div>

        <!-- Content -->
        <div class="content">
            <div class="greeting">
                <p>Dear {{supplier_name}},</p>
                <p>We would like to place the following purchase order:</p>
            </div>

            <!-- Order Information -->
            <div class="info-box">
                <h3>Order Details</h3>
                <div class="info-row">
                    <span class="info-label">PO Number:</span>
                    <span class="info-value">{{po_number}}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">Order Date:</span>
                    <span class="info-value">{{order_date}}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">Required Delivery:</span>
                    <span class="info-value">{{required_delivery_date}}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">Delivery Address:</span>
                    <span class="info-value">{{delivery_address}}</span>
                </div>
            </div>

            <!-- Order Items -->
            <table class="items-table">
                <thead>
                    <tr>
                        <th>Product</th>
                        <th class="text-right">Quantity</th>
                        <th class="text-right">Unit Price</th>
                        <th class="text-right">Total</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in items %}
                    <tr>
                        <td>{{item.product_name}}</td>
                        <td class="text-right">{{item.ordered_quantity}} {{item.unit_of_measure}}</td>
                        <td class="text-right">{{currency_symbol}}{{item.unit_price}}</td>
                        <td class="text-right">{{currency_symbol}}{{item.line_total}}</td>
                    </tr>
                    {% endfor %}
                </tbody>
                <tfoot>
                    <tr class="total-row">
                        <td colspan="3" class="text-right">Total Amount:</td>
                        <td class="text-right">{{currency_symbol}}{{total_amount}}</td>
                    </tr>
                </tfoot>
            </table>

            <!-- Call to Action -->
            <div style="text-align: center;">
                <p style="margin-bottom: 10px;">Please confirm receipt of this order:</p>
                <a href="mailto:{{bakery_email}}?subject=RE: PO {{po_number}} - Confirmation" class="cta-button">
                    Confirm Order
                </a>
            </div>

            <!-- Important Notes -->
            {% if notes %}
            <div class="notes">
                <h4>⚠️ Important Notes</h4>
                <p>{{notes}}</p>
            </div>
            {% endif %}

            <!-- Payment & Delivery Instructions -->
            <div class="info-box" style="margin-top: 30px;">
                <h3>Payment & Delivery</h3>
                <p style="margin: 0; font-size: 14px; color: #6B7280;">
                    • Payment Terms: {{payment_terms}}<br>
                    • Delivery Instructions: {{delivery_instructions}}<br>
                    • Contact Person: {{contact_person}}<br>
                    • Phone: {{contact_phone}}
                </p>
            </div>

            <!-- Footer Message -->
            <p style="margin-top: 30px; font-size: 14px; color: #6B7280;">
                Thank you for your continued partnership. If you have any questions about this order,
                please don't hesitate to contact us.
            </p>

            <p style="font-size: 14px; color: #6B7280;">
                Best regards,<br>
                <strong>{{bakery_name}}</strong>
            </p>
        </div>

        <!-- Footer -->
        <div class="footer">
            <p><strong>{{bakery_name}}</strong></p>
            <p>{{bakery_address}}</p>
            <p>Phone: {{bakery_phone}} | Email: <a href="mailto:{{bakery_email}}">{{bakery_email}}</a></p>
            <p style="margin-top: 16px; font-size: 11px; color: #9CA3AF;">
                This is an automated email. Please do not reply directly to this message.
            </p>
        </div>
    </div>
</body>
</html>
