<style id="style">
    @import url($font_url);

    :root {
        --primary-color: $primary_color;
        --secondary-color: $secondary_color;
        --line-height: 1.6;
    }

    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        font-family: $font_name, Helvetica, sans-serif;
        font-size: "$font_size";
        zoom: 80%;
    }

    html {
        width: 210mm;
        height: 200mm;     
    }

    @page {
        margin-left: $global_margin;
        margin-right: $global_margin;
        margin-top: 0;
        margin-bottom: 0;
        size: $page_size $page_layout;

    }

    p {
        margin: 0;
        padding: 0;
    }

    .header-wrapper {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        line-height: var(--line-height);
    }

    .company-logo {
        max-width: 65%;
    }

    .header-wrapper #company-address {
        display: flex;
        flex-direction: column;
        line-height: var(--line-height);
    }

    .header-wrapper #entity-details {
        margin-top: 0.5rem;
        text-align: left;
        width: 100%;
    }

    .header-wrapper #entity-details > tr,
    .header-wrapper #entity-details th {
        font-weight: normal;
        padding-left: 0.9rem;
        padding-top: 0.3rem;
        padding-bottom: 0.3rem;
    }

    .header-wrapper
    #entity-details
    [data-element='entity-balance-due-label'],
    .header-wrapper
    #entity-details
    [data-element='entity-balance-due'] {
        background-color: #e6e6e6;
    }

    #client-details {
        display: flex;
        flex-direction: column;
        line-height: var(--line-height);
    }

    [data-ref="table"] {
        margin-top: 1rem;
        min-width: 100%;
        table-layout: fixed;
        overflow-wrap: break-word;
        margin-bottom: 50px; 
    }

    .task-time-details {
        display: block;
        margin-top: 5px;
        color: grey;
    }

    [data-ref="table"] > thead {
        text-align: left;
    }

    [data-ref="table"] > thead > tr > th {
        padding: 0.5rem;
        background-color: #e6e6e6;
    }

    [data-ref="table"] > thead > tr > th:last-child {
        text-align: right;
    }

    [data-ref="table"] > tbody > tr > td {
        border-bottom: 1px solid #e6e6e6;
        padding: 0.75rem;
    }

    [data-ref="table"] > tbody > tr > td:last-child {
        text-align: right;
    }

    #table-totals {
        margin-top: 0rem;
        display: grid;
        grid-template-columns: 2fr 1fr;
        padding-top: .5rem;
        padding-left: 1rem;
        margin-right: .75rem;
        gap: 80px;
        page-break-inside:auto;
        overflow: visible !important;
    }

    #table-totals .totals-table-right-side>* {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    #table-totals>.totals-table-right-side>*> :nth-child(1) {
        text-align: $dir_text_align;
        margin-top: .25rem;
        padding-left: 7px;
    }

    #table-totals>.totals-table-right-side> * > :not([hidden]) ~ :not([hidden]) {
        --tw-space-y-reverse: 0;
        margin-top: calc(.25rem * calc(1 - var(--tw-space-y-reverse)));
        margin-bottom: calc(.25rem * var(--tw-space-y-reverse));
    }

    #table-totals>.totals-table-right-side>*> :nth-child(2) {
        text-align: right;
        padding-right: 7px;
    }

    #table-totals
    > *
    [data-element='total-table-balance-due-label'],
    #table-totals
    > *
    [data-element='total-table-balance-due'] {
        font-weight: bold;
    }

    #table-totals > * > :last-child {
        text-align: right;
        padding-right: 1rem;
    }

    [data-ref="total_table-footer"] {
        padding-left: 1rem
    }

    #footer {
        margin-top: 30px;
    }

    [data-ref="totals_table-outstanding"] {
        color: var(--primary-color)
    }

    /** Markdown-specific styles. **/
    [data-ref="table"] h3 {
        font-size: 1rem;
        margin-bottom: 0;
    }

    [data-ref="totals_table-outstanding-label"],
    [data-ref="totals_table-outstanding"] {
        background-color: #e6e6e6;
        color: black;
        padding-top: 7px;
        padding-bottom: 7px;
        padding-right: 7px;
    }

    [data-ref="statement-totals"] {
        margin-top: 1rem;
        text-align: right;
        margin-right: .75rem;
    }

    [data-ref*=".line_total-td"] {
        white-space: nowrap;
    }

    /** .repeating-header,
    .repeating-header-space, **/
    .repeating-footer,
    .repeating-footer-space {
        height: 10px;
    }
    .repeating-header {
        position: fixed;
        top: 0;
    }
    .repeating-footer {
        position: fixed;
        bottom: 0;
    }

    [data-element='product_table-product.description-td'], td {
        min-width:100%;
        max-width: 300px;
        overflow-wrap: break-word; 
    }

    .stamp {
      transform: rotate(12deg);
        color: #555;
        font-size: 3rem;
        font-weight: 700;
        border: 0.25rem solid #555;
        display: inline-block;
        padding: 0.25rem 1rem;
        text-transform: uppercase;
        border-radius: 1rem;
        font-family: 'Courier';
        mix-blend-mode: multiply;
        z-index:200 !important;
        position:  fixed;
        text-align: center;
    }

    .is-paid {
        color:  #D23;
        border: 1rem double  #D23;
        transform: rotate(-5deg);
        font-size: 6rem;
        font-family: "Open sans", Helvetica, Arial, sans-serif;
        border-radius: 0;
        padding: 0.5rem;
        opacity: 0.2;
        z-index:200 !important;
        position:  fixed;
    }

    .project-header {
        font-size: 1.2em;
        margin-top: 0.1em;
        margin-bottom: 0;
        padding-bottom: 0;
        margin-left: 0;
        margin-right: 0;
        font-weight: bold;
        color: #505050;
    } 

    .pqrcode {
        
    }
    /** Useful snippets, uncomment to enable. **/

    /** Hide company logo **/
    /* .company-logo { display: none } */

    /* Hide company details */
    /* #company-details > * { display: none } */

    /* Hide company address */
    /* #company-address > * { display: none } */

    /* Hide public notes */
    /* [data-ref="total_table-public_notes"] { display: none } */

    /* Hide terms label */
    /* [data-ref="total_table-terms-label"] { display: none } */

    /* Hide totals table */
    /* #table-totals { display: none } */

    /* Hide totals table left side */
    /* #table-totals div:first-child > * { display: none !important } */

    /* Hide totals table right side */
    /* .totals-table-right-side { display: none } */

    /** For more info, please check our docs: https://invoiceninja.github.io **/
    /** To find out selectors on your own: https://invoiceninja.github.io/docs/custom-fields/#snippets **/
</style>

<table style="min-width: 100%">
   <thead>
      <tr>
         <td>
            <div class="repeating-header-space">&nbsp;</div>
         </td>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td>
            <div id="body">
               <div class="header-wrapper">
                  <div id="company-details"></div>
                  <div id="company-address"></div>
                  <div>
                     <img
                        class="company-logo"
                        src="$company.logo"
                        alt="$company.name logo"
                        />
                     <table id="entity-details" cellspacing="0" dir="$dir"></table>
                  </div>
               </div>
               <div id="client-details"></div>
               <div id="vendor-details"></div>
               <table id="product-table" cellspacing="0" data-ref="table"></table>
               <table id="task-table" cellspacing="0" data-ref="table"></table>
               <table id="delivery-note-table" cellspacing="0" data-ref="table"></table>
               <table id="statement-invoice-table" cellspacing="0" data-ref="table"></table>
               <div id="statement-invoice-table-totals" data-ref="statement-totals"></div>
               <table id="statement-payment-table" cellspacing="0" data-ref="table"></table>
               <div id="statement-payment-table-totals" data-ref="statement-totals"></div>
               <table id="statement-aging-table" cellspacing="0" data-ref="table"></table>
               <div id="statement-aging-table-totals" data-ref="statement-totals"></div>
               <div id="table-totals" cellspacing="0"></div>
            </div>
         </td>
      </tr>
   </tbody>
   <tfoot>
      <tr>
         <td>
            <div class="repeating-footer-space">&nbsp;</div>
         </td>
      </tr>
   </tfoot>
</table>

<div class="repeating-header" id="header"></div>

$entity_images

<div class="repeating-footerx" id="footer">
   <p data-ref="total_table-footer">$entity_footer</p>

        <script>
            // Clear up space a bit, if [product-table, tasks-table, delivery-note-table] isn't present.
            document.addEventListener('DOMContentLoaded', () => {
                let tables = [
                    'product-table', 'task-table', 'delivery-note-table',
                    'statement-invoice-table', 'statement-payment-table', 'statement-aging-table-totals',
                    'statement-invoice-table-totals', 'statement-payment-table-totals', 'statement-aging-table',
                    'client-details','vendor-details'
                ];

                tables.forEach((tableIdentifier) => {
                    console.log(document.getElementById(tableIdentifier));

                    document.getElementById(tableIdentifier)?.childElementCount === 0
                        ? document.getElementById(tableIdentifier).style.setProperty('display', 'none', 'important')
                        : '';
                });
            });
        </script>
</div>