
<div class="a4" style="width: 100%; max-width: 760px; min-height: 297mm; height: auto; margin: 0 auto; background: #ffffff; padding: 38px 40px; box-sizing: border-box; position: relative; overflow: visible; font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; color: #242231; font-size: 10.5px; line-height: 1.5">
    <div class="ph" style="display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2.5px solid #6c3fc5; padding-bottom: 14px; margin-bottom: 16px; gap: 20px">
      <div style="flex: 1; min-width: 0">
        {{#if company.logo}}
        <img class="logo-img" src="{{company.logo}}" alt="{{company.legalName}}" onerror="this.style.display='none'; if(this.nextElementSibling) this.nextElementSibling.style.display='grid';" style="max-height: 48px; max-width: 140px; object-fit: contain; margin-bottom: 6px" />
        <div class="logo-badge" style="width: 48px; height: 48px; border-radius: 10px; background: #6c3fc5; color: #fff; display: none; place-items: center; font-size: 20px; font-weight: 700; font-family: 'DM Serif Display', Georgia, serif; margin-bottom: 8px">{{company.badgeLetter}}</div>
        {{else}}
        <div class="logo-badge" style="width: 48px; height: 48px; border-radius: 10px; background: #6c3fc5; color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 700; font-family: 'DM Serif Display', Georgia, serif; margin-bottom: 8px">{{company.badgeLetter}}</div>
        {{/if}}
        <div class="dn" style="font-family: 'DM Serif Display', Georgia, serif; font-size: 18px; color: #191727; line-height: 1.15">{{company.legalName}}</div>
        <div class="dm" style="font-size: 9.5px; color: #6E6B7C; margin-top: 4px; line-height: 1.55">
          {{company.addr}}<br />
          {{#if company.phone}}{{company.phone}} · {{/if}}{{#if company.email}}{{company.email}} · {{/if}}{{company.web}}<br />
          {{#if company.trn}}TRN {{company.trn}}{{/if}}{{#if company.reraNo}} · {{company.reraNo}}{{/if}}
        </div>
      </div>
      <div style="flex: 1; min-width: 0; flex-shrink: 0; text-align: right">
        <div class="dt" style="font-family: 'DM Serif Display', Georgia, serif; font-size: 24px; color: #6c3fc5; text-align: right; line-height: 1">{{docTitle}}</div>
        <div class="dmeta" style="margin-top: 10px; font-size: 9.5px; text-align: right; color: #6E6B7C; white-space: nowrap">
          <div style="margin-top: 3px; white-space: nowrap">Document no <b style="color: #191727; font-family: 'IBM Plex Mono', monospace; font-size: 10px; margin-left: 4px">{{invoiceNumber}}</b></div>
          <div style="margin-top: 3px; white-space: nowrap">Issue date <b style="color: #191727; font-family: 'IBM Plex Mono', monospace; font-size: 10px; margin-left: 4px">{{issueDate}}</b></div>
          <div style="margin-top: 3px; white-space: nowrap">Due date <b style="color: #191727; font-family: 'IBM Plex Mono', monospace; font-size: 10px; margin-left: 4px">{{dueDate}}</b></div>
        </div>
      </div>
    </div>

    <div class="two" style="display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-bottom: 14px">
      <div class="blk">
        <div class="bt" style="font-size: 10px; font-weight: 700; color: #54505E; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 5px; margin-top: 2px">Billed to</div>
        <b style="font-size: 11.5px; color: #191727">{{buyer.name}}</b>
        {{#if buyer.addr}}<div style="color: #54505E; margin-top: 2px; font-size: 10px">{{buyer.addr}}</div>{{/if}}
        {{#if buyer.email}}<div style="color: #54505E; margin-top: 2px; font-size: 10px">{{buyer.email}}</div>{{/if}}
        {{#if buyer.trn}}<div style="color: #54505E; margin-top: 2px; font-size: 10px">TRN {{buyer.trn}}</div>{{/if}}
      </div>
      <div class="blk">
        <div class="bt" style="font-size: 10px; font-weight: 700; color: #54505E; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 5px; margin-top: 2px">For</div>
        <b style="font-size: 11.5px; color: #191727">{{forItem.label}}</b>
      </div>
    </div>

    {{#if propertyCtx.hasContext}}
    <div class="ctx" style="border: 1px solid #E6E4EC; border-radius: 8px; overflow: hidden; margin-bottom: 14px">
      <div class="ctxh" style="background: #F4F1FE; padding: 6px 12px; font-size: 8px; font-weight: 700; color: #6c3fc5; text-transform: uppercase; letter-spacing: .08em">Property & contract</div>
      <div class="ctxg" style="display: grid; grid-template-columns: repeat(4, 1fr)">
        <div class="ctxc" style="padding: 8px 12px; border-right: 1px solid #EFEEF4">
          <div class="ctxl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .06em">Project</div>
          <div class="ctxv" style="font-size: 10.5px; font-weight: 600; color: #191727; margin-top: 2px">{{propertyCtx.project}}</div>
        </div>
        <div class="ctxc" style="padding: 8px 12px; border-right: 1px solid #EFEEF4">
          <div class="ctxl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .06em">Unit</div>
          <div class="ctxv" style="font-size: 10.5px; font-weight: 600; color: #191727; margin-top: 2px">{{propertyCtx.unit}}</div>
        </div>
        <div class="ctxc" style="padding: 8px 12px; border-right: 1px solid #EFEEF4">
          <div class="ctxl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .06em">Sale / SPA</div>
          <div class="ctxv" style="font-size: 10.5px; font-weight: 600; color: #191727; margin-top: 2px">{{propertyCtx.saleRef}}</div>
        </div>
        <div class="ctxc" style="padding: 8px 12px; border-right: 0">
          <div class="ctxl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .06em">{{propertyCtx.transactionLabel}}</div>
          <div class="ctxv" style="font-size: 10.5px; font-weight: 600; color: #191727; margin-top: 2px">{{propertyCtx.transactionValue}}</div>
        </div>
      </div>
    </div>
    {{/if}}

    <table class="it" style="width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 12px">
      <thead>
        <tr>
          <th style="background: #191727; color: #fff; font-size: 8px; text-transform: uppercase; letter-spacing: .07em; padding: 7px 10px; text-align: left; font-weight: 700">Description</th>
          <th style="background: #191727; color: #fff; font-size: 8px; text-transform: uppercase; letter-spacing: .07em; padding: 7px 10px; text-align: center; font-weight: 700">Qty</th>
          <th style="background: #191727; color: #fff; font-size: 8px; text-transform: uppercase; letter-spacing: .07em; padding: 7px 10px; text-align: center; font-weight: 700; white-space: nowrap"><span class="amt" style="white-space:nowrap;display:inline-flex;align-items:center;gap:2px;line-height:1;justify-content:center">Unit price ({{{totals.currencySymbol}}})</span></th>
          <th style="background: #191727; color: #fff; font-size: 8px; text-transform: uppercase; letter-spacing: .07em; padding: 7px 10px; text-align: center; font-weight: 700">VAT</th>
          <th style="background: #191727; color: #fff; font-size: 8px; text-transform: uppercase; letter-spacing: .07em; padding: 7px 10px; text-align: center; font-weight: 700; white-space: nowrap"><span class="amt" style="white-space:nowrap;display:inline-flex;align-items:center;gap:2px;line-height:1;justify-content:center">Amount ({{{totals.currencySymbol}}})</span></th>
        </tr>
      </thead>
      <tbody>
        {{#each lineItems}}
        <tr>
          <td style="padding: 8px 10px; border-bottom: 1px solid #EFEEF4; vertical-align: top; text-align: left">
            <div class="itd" style="font-weight: 600; color: #191727">{{desc}}</div>
            {{#if sub}}<div class="its" style="font-size: 9px; color: #8A8A93; margin-top: 2px">{{sub}}</div>{{/if}}
            {{#if vatReason}}<div class="its" style="font-size: 9px; color: #8A8A93; margin-top: 2px">{{vatReason}}</div>{{/if}}
          </td>
          <td style="padding: 8px 10px; border-bottom: 1px solid #EFEEF4; vertical-align: top; text-align: center; font-family: 'IBM Plex Mono', monospace; font-size: 10px">{{qty}}</td>
          <td style="padding: 8px 10px; border-bottom: 1px solid #EFEEF4; vertical-align: top; text-align: center; font-family: 'IBM Plex Mono', monospace; font-size: 10px">{{price}}</td>
          <td style="padding: 8px 10px; border-bottom: 1px solid #EFEEF4; vertical-align: top; text-align: center; font-family: 'IBM Plex Mono', monospace; font-size: 10px">{{vatRate}}</td>
          <td style="padding: 8px 10px; border-bottom: 1px solid #EFEEF4; vertical-align: top; text-align: center; font-family: 'IBM Plex Mono', monospace; font-size: 10px"><b>{{amount}}</b></td>
        </tr>
        {{/each}}
      </tbody>
    </table>

    <div class="sw" style="display: grid; grid-template-columns: 1fr 260px; gap: 22px; margin-bottom: 14px">
      {{#if scheduleNotes.isPlan}}
      <div class="sched" style="border: 1px solid #E6E4EC; border-radius: 8px; padding: 10px 12px">
        <div class="bt" style="font-size: 8px; font-weight: 700; color: #6c3fc5; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 5px">Position in your payment plan</div>
        <div class="sl" style="display: flex; justify-content: space-between; font-size: 9.5px; padding: 3px 0; color: #54505E"><span>Purchase price</span><b style="font-family: 'IBM Plex Mono', monospace; color: #191727">{{scheduleNotes.purchasePrice}}</b></div>
        <div class="sl" style="display: flex; justify-content: space-between; font-size: 9.5px; padding: 3px 0; color: #54505E"><span>Invoiced before this instalment</span><b style="font-family: 'IBM Plex Mono', monospace; color: #191727">{{scheduleNotes.invoicedBefore}}</b></div>
        <div class="sl hi" style="display: flex; justify-content: space-between; font-size: 9.5px; padding: 3px 0; color: #6c3fc5; font-weight: 700"><span>This instalment ({{scheduleNotes.instalmentLabel}})</span><b style="font-family: 'IBM Plex Mono', monospace; color: #191727">{{scheduleNotes.thisInstalment}}</b></div>
        <div class="sl" style="display: flex; justify-content: space-between; font-size: 9.5px; padding: 3px 0; color: #54505E"><span>Received to date</span><b style="font-family: 'IBM Plex Mono', monospace; color: #191727">{{scheduleNotes.receivedToDate}}</b></div>
        <div class="sl t" style="display: flex; justify-content: space-between; font-size: 9.5px; padding: 3px 0; color: #191727; border-top: 1px solid #EFEEF4; margin-top: 4px; padding-top: 5px; font-weight: 700"><span>Remaining after this instalment</span><b style="font-family: 'IBM Plex Mono', monospace; color: #191727">{{scheduleNotes.remaining}}</b></div>
        <div style="font-size: 8px; color: #8A8A93; margin-top: 6px">Illustrative summary of your plan. The SPA schedule prevails in case of difference.</div>
      </div>
      {{else}}
      <div class="sched" style="border: 1px solid #E6E4EC; border-radius: 8px; padding: 10px 12px">
        <div class="bt" style="font-size: 8px; font-weight: 700; color: #6c3fc5; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 5px">Notes</div>
        <div class="sl" style="display: flex; justify-content: space-between; font-size: 9.5px; padding: 3px 0; color: #54505E"><span>{{scheduleNotes.noteText}}</span></div>
        <div class="sl" style="display: flex; justify-content: space-between; font-size: 9.5px; padding: 3px 0; color: #54505E"><span>Payments are accepted only into the account shown opposite.</span></div>
      </div>
      {{/if}}

      <div class="sum">
        <div class="sr" style="display: flex; justify-content: space-between; font-size: 10px; padding: 3.5px 0; color: #54505E"><span>Taxable basis</span><b style="font-family: 'IBM Plex Mono', monospace; color: #191727">{{totals.taxableBasis}}</b></div>
        <div class="sr" style="display: flex; justify-content: space-between; font-size: 10px; padding: 3.5px 0; color: #54505E"><span>VAT</span><b style="font-family: 'IBM Plex Mono', monospace; color: #191727">{{totals.vat}}</b></div>
        {{#if totals.hasReceived}}
        <div class="sr" style="display: flex; justify-content: space-between; font-size: 10px; padding: 3.5px 0; color: #54505E"><span>Total received</span><b style="font-family: 'IBM Plex Mono', monospace; color: #191727">({{totals.receivedTotal}})</b></div>
        {{/if}}
        <div class="sr t" style="display: flex; justify-content: space-between; align-items: center; font-size: 12px; padding: 9px 12px; color: #fff; background: #6c3fc5; border-radius: 8px; margin-top: 6px; font-weight: 700">
          <span>{{totals.dueLabel}}</span>
          <b class="amt" style="font-family: 'IBM Plex Mono', monospace; color: #fff; white-space:nowrap;display:inline-flex;align-items:center;gap:2px;line-height:1">{{{totals.currencySymbol}}}&nbsp;{{totals.totalDue}}</b>
        </div>
        {{#if totals.vatReasonNote}}
        <div style="font-size: 8px; color: #8A8A93; margin-top: 6px; text-align: right">{{totals.vatReasonNote}}</div>
        {{/if}}
      </div>
    </div>

    <div class="pay" style="border: 1px solid #E6E4EC; border-left: 3.5px solid #6c3fc5; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px">
      <div class="bt" style="font-size: 8px; font-weight: 700; color: #6c3fc5; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 5px">Payment instructions</div>
      {{#if paymentInstructions.hasAccount}}
      <div class="payg" style="display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; margin-top: 6px">
        <div><div class="payl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .05em">Bank</div><div class="payv" style="font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: #191727; font-weight: 600">{{paymentInstructions.bank}}</div></div>
        <div><div class="payl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .05em">Account name</div><div class="payv" style="font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: #191727; font-weight: 600">{{paymentInstructions.accountName}}</div></div>
        <div><div class="payl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .05em">IBAN</div><div class="payv" style="font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: #191727; font-weight: 600">{{paymentInstructions.iban}}</div></div>
        <div><div class="payl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .05em">SWIFT / BIC</div><div class="payv" style="font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: #191727; font-weight: 600">{{paymentInstructions.swift}}</div></div>
        <div style="grid-column: 1/-1"><div class="payl" style="font-size: 8px; color: #8A8A93; text-transform: uppercase; letter-spacing: .05em">Mandatory payment reference</div><div class="payv" style="font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: #191727; font-weight: 600">{{paymentInstructions.reference}}</div></div>
      </div>
      <div class="esc" style="background: #F4F1FE; border-radius: 6px; padding: 6px 9px; margin-top: 8px; font-size: 8.5px; color: #46199A; line-height: 1.45">{{paymentInstructions.note}}</div>
      {{else}}
      <div class="esc err" style="background: #FCE9E7; border-radius: 6px; padding: 6px 9px; margin-top: 8px; font-size: 8.5px; color: #8E1D17; line-height: 1.45">
        <b>No bank account is configured for this project.</b><br />
        Please configure the project bank accounts in Projects &rarr; Advanced &rarr; Bank Accounts.
      </div>
      {{/if}}
    </div>

    {{#if terms}}
    <div class="terms" style="font-size: 8px; color: #6E6B7C; line-height: 1.6; border-top: 1px solid #EFEEF4; padding-top: 9px">
      <b style="color: #191727; display: block; margin-bottom: 2px; font-size: 8.5px">Terms</b>
      {{terms}}
    </div>
    {{/if}}

    <div class="pf" style="display: flex; justify-content: space-between; align-items: flex-end; border-top: 1px solid #EFEEF4; margin-top: 12px; padding-top: 8px; font-size: 8px; color: #8A8A93">
      <div>
        {{footer.legalName}}{{#if footer.reraNo}} · {{footer.reraNo}}{{/if}}{{#if footer.trn}} · TRN {{footer.trn}}{{/if}}<br />
        Document {{footer.invoiceNumber}} · generated {{footer.generatedDate}}
      </div>
      <div style="text-align: right">
        <div class="qr" style="width: 48px; height: 48px; border: 1px solid #E6E4EC; border-radius: 6px; display: grid; place-items: center; font-size: 7px; color: #B9B6C4; text-align: center">QR<br />verify</div>
        <div style="margin-top: 3px">Page 1 of 1</div>
      </div>
    </div>
  </div>
