<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ template.name }} - Preview</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            font-size: 11pt;
            line-height: 1.6;
            color: #1f2937;
            padding: 0;
        }

        .preview-banner {
            background: #fef3c7;
            border: 2px solid #f59e0b;
            color: #92400e;
            padding: 12px;
            text-align: center;
            font-weight: bold;
            margin-bottom: 24px;
            border-radius: 4px;
        }

        .header {
            border-bottom: 3px solid #2563eb;
            padding-bottom: 20px;
            margin-bottom: 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .header-left {
            flex: 1;
        }

        .header-right {
            text-align: right;
        }

        .logo {
            max-width: 180px;
            max-height: 60px;
            margin-bottom: 10px;
        }

        .business-name {
            font-size: 24pt;
            font-weight: 700;
            color: #1f2937;
            margin-bottom: 5px;
        }

        .contract-title {
            font-size: 20pt;
            font-weight: 600;
            color: #1f2937;
            margin: 30px 0 20px 0;
            text-align: center;
        }

        .metadata {
            background-color: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 30px;
        }

        .metadata-row {
            display: flex;
            margin-bottom: 8px;
        }

        .metadata-row:last-child {
            margin-bottom: 0;
        }

        .metadata-label {
            font-weight: 600;
            color: #6b7280;
            width: 180px;
        }

        .metadata-value {
            color: #1f2937;
        }

        .content {
            margin: 30px 0;
            line-height: 1.8;
        }

        .content h1 {
            font-size: 16pt;
            margin-top: 24px;
            margin-bottom: 12px;
            color: #1f2937;
        }

        .content h2 {
            font-size: 14pt;
            margin-top: 20px;
            margin-bottom: 10px;
            color: #374151;
        }

        .content p {
            margin-bottom: 12px;
        }

        .content ul, .content ol {
            margin-left: 20px;
            margin-bottom: 12px;
        }

        .signature-section {
            margin-top: 40px;
            padding: 20px;
            background-color: #f3f4f6;
            border: 2px dashed #9ca3af;
            border-radius: 8px;
        }

        .signature-section h2 {
            font-size: 14pt;
            color: #6b7280;
            margin-bottom: 15px;
            text-align: center;
        }

        .signature-placeholder {
            text-align: center;
            color: #9ca3af;
            font-style: italic;
        }

        .footer {
            margin-top: 40px;
            padding-top: 20px;
            border-top: 1px solid #e5e7eb;
            text-align: center;
            font-size: 9pt;
            color: #6b7280;
        }

        .template-info {
            font-size: 9pt;
            color: #6b7280;
        }
    </style>
</head>
<body>
    {% if is_preview %}
    <div class="preview-banner">
        {{ preview_notice }}
    </div>
    {% endif %}

    <div class="header">
        <div class="header-left">
            {% if business_logo_url %}
            <img src="{{ business_logo_url }}" alt="{{ business_name }}" class="logo">
            {% else %}
            <div class="business-name">{{ business_name }}</div>
            {% endif %}
        </div>
        <div class="header-right">
            <div class="template-info">
                <div>Template: <strong>{{ template.name }}</strong></div>
                <div>Version: <strong>{{ template.version }}</strong></div>
                <div>Scope: <strong>{{ template.get_scope_display }}</strong></div>
            </div>
        </div>
    </div>

    <h1 class="contract-title">{{ template.name }}</h1>

    <div class="metadata">
        <div class="metadata-row">
            <span class="metadata-label">Customer:</span>
            <span class="metadata-value">John Smith (sample)</span>
        </div>
        <div class="metadata-row">
            <span class="metadata-label">Customer Email:</span>
            <span class="metadata-value">john.smith@example.com</span>
        </div>
        {% if template.scope == 'APPOINTMENT' %}
        <div class="metadata-row">
            <span class="metadata-label">Appointment:</span>
            <span class="metadata-value">Sample Service - (date will be filled in)</span>
        </div>
        {% endif %}
        <div class="metadata-row">
            <span class="metadata-label">Contract Created:</span>
            <span class="metadata-value">(will be filled when sent)</span>
        </div>
    </div>

    <div class="content">
        {{ content_html|safe }}
    </div>

    <div class="signature-section">
        <h2>Signature Section</h2>
        <p class="signature-placeholder">
            This section will contain:<br>
            • Electronic consent checkboxes<br>
            • Signer name input<br>
            • Full audit trail with IP address, timestamp, and document hash
        </p>
    </div>

    <div class="footer">
        <p>
            This is a preview of contract template "{{ template.name }}" (v{{ template.version }}).<br>
            Variables have been replaced with sample data.
        </p>
    </div>
</body>
</html>
