<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
/* ═══════════════════════════════════════════════
   PROPOSAL — Premium PandaDoc/HoneyBook Style
   ═══════════════════════════════════════════════ */

/* ── Print-ready page setup ── */
@page {
    size: {{ style.page_format | default('A4') }};
    margin: {{ style.margin_top | default('18mm') }} {{ style.margin_right | default('18mm') }} {{ style.margin_bottom | default('18mm') }} {{ style.margin_left | default('18mm') }};
    @bottom-center {
        content: "Page " counter(page) " of " counter(pages);
        font-size: 9px;
        color: #94a3b8;
        font-family: {{ style.font_family | default('Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif') }};
    }
}

:root {
    --primary: {{ style.primary_color | default('#2563eb') }};
    --primary-dark: {{ style.primary_dark | default('#1e40af') }};
    --primary-light: {{ style.primary_light | default('#dbeafe') }};
    --primary-faint: {{ style.primary_faint | default('#eff6ff') }};
    --font: {{ style.font_family | default('Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif') }};
    --text-heading: {{ style.text_primary | default('#0f172a') }};
    --text-body: {{ style.text_secondary | default('#475569') }};
    --text-muted: {{ style.text_tertiary | default('#94a3b8') }};
    --border: {{ style.border_color | default('#e2e8f0') }};
    --bg-subtle: {{ style.bg_subtle | default('#f8fafc') }};
    --bg-card: #ffffff;
}

/* ── Print color preservation ── */
*, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    -print-color-adjust: exact !important;
    color-adjust: exact !important;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    font-size: 11.5px;
    color: var(--text-body);
    line-height: 1.65;
    background: #eef2f7;
    padding: 20px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ═══════════════════════════════════════════════
   DOCUMENT SHELL
   ═══════════════════════════════════════════════ */
.document {
    max-width: 740px;
    margin: 0 auto;
    background: var(--bg-card);
    overflow: hidden;
    box-shadow: 0 0.5px 0 rgba(0,0,0,0.08);
}

/* ═══════════════════════════════════════════════
   COVER / HERO SECTION
   ═══════════════════════════════════════════════ */
.cover {
    position: relative;
    padding: 52px 48px 44px;
    background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #ffffff;
    overflow: hidden;
}

/* Decorative background elements */
.cover::before {
    content: '';
    position: absolute;
    top: -120px;
    right: -80px;
    width: 360px;
    height: 360px;
    background: radial-gradient(circle, rgba(255,255,255,0.10) 0%, transparent 70%);
    border-radius: 50%;
}

.cover::after {
    content: '';
    position: absolute;
    bottom: -100px;
    left: -60px;
    width: 280px;
    height: 280px;
    background: radial-gradient(circle, rgba(255,255,255,0.06) 0%, transparent 70%);
    border-radius: 50%;
}

.cover-inner {
    position: relative;
    z-index: 1;
}

/* Top bar with logo & company */
.cover-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 36px;
}

.cover-brand {
    flex: 1;
}

.cover-logo {
    max-width: 150px;
    max-height: 44px;
    margin-bottom: 14px;
    display: block;
    filter: brightness(0) invert(1);
    opacity: 0.92;
}

.cover-company-name {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.2px;
    opacity: 0.95;
}

.cover-company-detail {
    font-size: 11px;
    font-weight: 300;
    opacity: 0.75;
    line-height: 1.55;
    margin-top: 4px;
}

/* Client info on right */
.cover-client {
    text-align: right;
    max-width: 240px;
}

.cover-client .label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    opacity: 0.6;
    margin-bottom: 4px;
}

.cover-client .name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.cover-client .detail {
    font-size: 10.5px;
    font-weight: 300;
    opacity: 0.78;
    line-height: 1.5;
}

/* Document title area */
.cover-title-area {
    margin-bottom: 28px;
}

.cover-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    opacity: 0.55;
    margin-bottom: 6px;
}

.cover-title {
    font-size: 38px;
    font-weight: 800;
    letter-spacing: 4px;
    text-transform: uppercase;
    line-height: 1.05;
}

.cover-doc-number {
    font-size: 13px;
    font-weight: 400;
    opacity: 0.7;
    margin-top: 6px;
    letter-spacing: 0.3px;
}

/* Meta row under title */
.cover-meta {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
}

.cover-meta-item {
    min-width: 100px;
}

.cover-meta-item .label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.5;
    margin-bottom: 2px;
}

.cover-meta-item .value {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.85;
}

/* ═══════════════════════════════════════════════
   CONTENT AREA
   ═══════════════════════════════════════════════ */
.content {
    padding: 40px 48px 36px;
}

/* ── Section dividers ── */
.section {
    margin-bottom: 36px;
}

.section:last-child {
    margin-bottom: 0;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
}

.section-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.section-subtitle {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: auto;
}

/* ═══════════════════════════════════════════════
   EXECUTIVE SUMMARY
   ═══════════════════════════════════════════════ */
.executive-summary {
    background: linear-gradient(135deg, var(--primary-faint) 0%, var(--bg-subtle) 100%);
    border-left: 3px solid var(--primary);
    border-radius: 0 10px 10px 0;
    padding: 20px 24px;
    font-size: 12px;
    color: var(--text-body);
    line-height: 1.75;
}

/* ═══════════════════════════════════════════════
   INFO CARDS (two-column party info)
   ═══════════════════════════════════════════════ */
.info-grid {
    display: flex;
    gap: 16px;
    margin-bottom: 32px;
}

.info-card {
    flex: 1;
    background: var(--bg-subtle);
    border-radius: 10px;
    padding: 18px 22px;
    border: 1px solid var(--border);
}

.info-card .label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.info-card .name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 4px;
}

.info-card .detail {
    font-size: 11px;
    color: var(--text-body);
    line-height: 1.6;
}

/* ═══════════════════════════════════════════════
   SCOPE OF WORK TABLE
   ═══════════════════════════════════════════════ */
.scope-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.scope-table thead th {
    background: var(--bg-subtle);
    padding: 11px 16px;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.scope-table thead th.right { text-align: right; }

.scope-table tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 11.5px;
    vertical-align: top;
}

.scope-table tbody td.right { text-align: right; }
.scope-table tbody tr:last-child td { border-bottom: none; }
.scope-table tbody tr:nth-child(even) { background: var(--bg-subtle); }

.scope-table .phase-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 9px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ═══════════════════════════════════════════════
   TIMELINE
   ═══════════════════════════════════════════════ */
.timeline-text {
    font-size: 12px;
    color: var(--text-body);
    line-height: 1.8;
    padding: 16px 20px;
    background: var(--bg-subtle);
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════
   INVESTMENT / PRICING TABLE
   ═══════════════════════════════════════════════ */
.pricing-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

.pricing-table thead th {
    background: var(--bg-subtle);
    padding: 11px 16px;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.pricing-table thead th.right { text-align: right; }

.pricing-table tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 11.5px;
}

.pricing-table tbody td.right { text-align: right; font-variant-numeric: tabular-nums; }
.pricing-table tbody tr:last-child td { border-bottom: none; }
.pricing-table tbody tr:nth-child(even) { background: var(--bg-subtle); }

/* ── Totals Box ── */
.totals-box {
    display: flex;
    justify-content: flex-end;
    page-break-inside: avoid;
}

.totals-inner {
    background: var(--bg-subtle);
    border-radius: 10px;
    padding: 16px 24px;
    min-width: 260px;
    border: 1px solid var(--border);
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 12px;
    color: var(--text-body);
}

.totals-row .amount {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.totals-row.grand-total {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    padding-top: 12px;
    margin-top: 8px;
    border-top: 2px solid var(--primary);
}

.totals-row.grand-total .amount {
    font-weight: 800;
    letter-spacing: -0.3px;
}

/* ═══════════════════════════════════════════════
   TERMS & CONDITIONS
   ═══════════════════════════════════════════════ */
.terms-block {
    font-size: 10.5px;
    color: var(--text-body);
    line-height: 1.75;
    padding: 18px 22px;
    background: var(--bg-subtle);
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════
   SIGNATURE BLOCKS
   ═══════════════════════════════════════════════ */
.signatures {
    display: flex;
    gap: 48px;
    margin-top: 40px;
    page-break-inside: avoid;
}

.signature-block {
    flex: 1;
}

.signature-block .sig-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.signature-block .sig-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 2px;
}

.signature-block .sig-role {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.signature-line {
    border-top: 1.5px solid var(--border);
    margin-bottom: 6px;
    margin-top: 36px;
}

.signature-block .sig-field {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.signature-block .sig-line-field {
    border-bottom: 1px solid var(--border);
    display: inline-block;
    min-width: 160px;
    padding: 2px 0;
    margin-top: 4px;
    font-size: 10px;
    color: var(--text-muted);
}

/* ═══════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════ */
.footer {
    padding: 24px 48px;
    background: var(--bg-subtle);
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.6;
}

.footer .footer-brand {
    font-weight: 600;
    color: var(--text-heading);
}

.footer .footer-message {
    margin-top: 4px;
    font-size: 10px;
}

/* ═══════════════════════════════════════════════
   PAGE BREAKS
   ═══════════════════════════════════════════════ */
.totals-box, .signatures, .info-card {
    page-break-inside: avoid;
}

.scope-table tbody tr, .pricing-table tbody tr {
    page-break-inside: avoid;
}

/* ═══════════════════════════════════════════════
   WATERMARK
   ═══════════════════════════════════════════════ */
.watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-35deg);
    font-size: 72px;
    font-weight: 900;
    color: var(--primary);
    opacity: 0.06;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 8px;
}

{% if style.show_watermark | default(false) | to_bool %}
<div class="watermark">{{ style.watermark_text | default('DRAFT') }}</div>
{% endif %}
</style>
</head>
<body>
<div class="document">

    <!-- ════════════════════════════════════════
         COVER SECTION
         ════════════════════════════════════════ -->
    <div class="cover">
        <div class="cover-inner">
            <!-- Top row: brand left, client right -->
            <div class="cover-top">
                <div class="cover-brand">
                    {% if style.logo_url %}
                    <img src="{{ style.logo_url }}" alt="Logo" class="cover-logo">
                    {% endif %}
                    <div class="cover-company-name">{{ data.from.name }}</div>
                    {% if data.from.address %}
                    <div class="cover-company-detail">{{ data.from.address | nl2br }}</div>
                    {% endif %}
                    {% if data.from.email %}
                    <div class="cover-company-detail">{{ data.from.email }}</div>
                    {% endif %}
                </div>
                <div class="cover-client">
                    <div class="label">Prepared For</div>
                    <div class="name">{{ data.to.name }}</div>
                    {% if data.to.address %}
                    <div class="detail">{{ data.to.address | nl2br }}</div>
                    {% endif %}
                    {% if data.to.email %}
                    <div class="detail">{{ data.to.email }}</div>
                    {% endif %}
                </div>
            </div>

            <!-- Document title -->
            <div class="cover-title-area">
                <div class="cover-label">Project</div>
                <div class="cover-title">PROPOSAL</div>
                {% if data.document_number %}
                <div class="cover-doc-number">#{{ data.document_number }}</div>
                {% endif %}
            </div>

            <!-- Meta row -->
            <div class="cover-meta">
                <div class="cover-meta-item">
                    <div class="label">Date</div>
                    <div class="value">{{ data.issue_date | date_format }}</div>
                </div>
                {% if data.valid_until %}
                <div class="cover-meta-item">
                    <div class="label">Valid Until</div>
                    <div class="value">{{ data.valid_until | date_format }}</div>
                </div>
                {% endif %}
                {% if data.project_name %}
                <div class="cover-meta-item">
                    <div class="label">Project</div>
                    <div class="value">{{ data.project_name }}</div>
                </div>
                {% endif %}
            </div>
        </div>
    </div>

    <div class="content">

        <!-- ════════════════════════════════════
             EXECUTIVE SUMMARY
             ════════════════════════════════════ -->
        {% if data.executive_summary %}
        <div class="section">
            <div class="section-header">
                <div class="section-icon">&#9830;</div>
                <div class="section-title">Executive Summary</div>
            </div>
            <div class="executive-summary">
                {{ data.executive_summary | nl2br }}
            </div>
        </div>
        {% endif %}

        <!-- ════════════════════════════════════
             SCOPE OF WORK
             ════════════════════════════════════ -->
        {% if data.scope_items %}
        <div class="section">
            <div class="section-header">
                <div class="section-icon">&#9679;</div>
                <div class="section-title">Scope of Work</div>
            </div>
            <table class="scope-table">
                <thead>
                    <tr>
                        <th style="width:18%;">Phase</th>
                        <th style="width:46%;">Description</th>
                        <th class="right" style="width:36%;">Deliverables</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in data.scope_items %}
                    <tr>
                        <td>
                            {% if item.phase %}
                            <span class="phase-badge">{{ item.phase }}</span>
                            {% else %}
                            <span class="phase-badge">{{ loop.index }}</span>
                            {% endif %}
                        </td>
                        <td>{{ item.description | default('') }}</td>
                        <td class="right">{{ item.deliverables | default('') }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% endif %}

        <!-- ════════════════════════════════════
             TIMELINE
             ════════════════════════════════════ -->
        {% if data.timeline %}
        <div class="section">
            <div class="section-header">
                <div class="section-icon">&#9200;</div>
                <div class="section-title">Project Timeline</div>
            </div>
            <div class="timeline-text">
                {{ data.timeline | nl2br }}
            </div>
        </div>
        {% endif %}

        <!-- ════════════════════════════════════
             INVESTMENT / PRICING
             ════════════════════════════════════ -->
        {% if data.line_items %}
        <div class="section">
            <div class="section-header">
                <div class="section-icon">&#9830;</div>
                <div class="section-title">Investment</div>
            </div>
            <table class="pricing-table">
                <thead>
                    <tr>
                        <th>Description</th>
                        {% if data.line_items[0] and data.line_items[0].quantity is defined %}
                        <th class="right">Qty</th>
                        <th class="right">Unit Price</th>
                        {% endif %}
                        <th class="right">Amount</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in data.line_items %}
                    <tr>
                        <td>{{ item.description | default('') }}</td>
                        {% if data.line_items[0] and data.line_items[0].quantity is defined %}
                        <td class="right">{{ item.quantity | default(1) }}</td>
                        <td class="right">{{ item.unit_price | currency }}</td>
                        {% endif %}
                        <td class="right">{{ item.amount | currency }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>

            <!-- Totals -->
            <div class="totals-box">
                <div class="totals-inner">
                    <div class="totals-row">
                        <span>Subtotal</span>
                        <span class="amount">{{ data.subtotal | currency }}</span>
                    </div>
                    {% if data.tax_rate and data.tax_rate > 0 %}
                    <div class="totals-row">
                        <span>Tax ({{ data.tax_rate | percent }})</span>
                        <span class="amount">{{ (data.tax or data.tax_amount or 0) | currency }}</span>
                    </div>
                    {% endif %}
                    {% if data.discount and data.discount > 0 %}
                    <div class="totals-row">
                        <span>Discount</span>
                        <span class="amount">-{{ data.discount | currency }}</span>
                    </div>
                    {% endif %}
                    <div class="totals-row grand-total">
                        <span>Total</span>
                        <span class="amount">{{ data.total | currency }}</span>
                    </div>
                </div>
            </div>
        </div>
        {% endif %}

        <!-- ════════════════════════════════════
             TERMS & CONDITIONS
             ════════════════════════════════════ -->
        {% if data.terms %}
        <div class="section">
            <div class="section-header">
                <div class="section-icon">&#9733;</div>
                <div class="section-title">Terms &amp; Conditions</div>
            </div>
            <div class="terms-block">
                {{ data.terms | nl2br }}
            </div>
        </div>
        {% endif %}

        <!-- ════════════════════════════════════
             SIGNATURE BLOCKS
             ════════════════════════════════════ -->
        <div class="signatures">
            <div class="signature-block">
                <div class="sig-label">Provider</div>
                <div class="sig-name">{{ data.from.name }}</div>
                <div class="sig-role">{{ data.from.title | default('Authorized Signatory') }}</div>
                <div class="signature-line"></div>
                <div class="sig-field">Printed Name</div>
                <div class="sig-line-field">{{ data.from.name }}</div>
                <br>
                <div class="sig-field">Date</div>
                <div class="sig-line-field">{{ data.issue_date | date_format }}</div>
            </div>
            <div class="signature-block">
                <div class="sig-label">Client</div>
                <div class="sig-name">{{ data.to.name }}</div>
                <div class="sig-role">{{ data.to.title | default('Authorized Signatory') }}</div>
                <div class="signature-line"></div>
                <div class="sig-field">Printed Name</div>
                <div class="sig-line-field">&nbsp;</div>
                <br>
                <div class="sig-field">Date</div>
                <div class="sig-line-field">&nbsp;</div>
            </div>
        </div>

    </div>

    <!-- ════════════════════════════════════════
         FOOTER
         ════════════════════════════════════════ -->
    <div class="footer">
        <div class="footer-brand">{{ data.from.name }}</div>
        <div class="footer-message">Thank you for considering {{ data.from.name }} for your project.</div>
        {% if data.from.email %}<div class="footer-message">Questions? {{ data.from.email }}{% if data.from.phone %} &middot; {{ data.from.phone }}{% endif %}</div>{% endif %}
    </div>

</div>
</body>
</html>
