<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CADOSYS Ersatzdarstellung</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
            font-size: 12px;
            line-height: 1.4;
        }

        /* Ensure Tailwind-like margin-top utilities are not neutralized by the global reset */
        .mt-8 {
            margin-top: 2rem !important;
        }

        .appendix * {
            padding: 2px;
        }

        body {
            margin: 0;
            padding: 20px;
            background: #e5e5e5;
        }

        /* A4 Page dimensions */
        .page {
            width: 210mm;
            height: 297mm;
            margin: 0 auto 20px;
            background: white;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            position: relative;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            padding: 15mm;
            box-sizing: border-box;
        }

        .divider {
            color: #FF6300;
            font-family: arial;
            font-size: small;
            width: 100%;
            text-align: center;
            margin: 10px 0;
        }

            .divider::before {
                content: "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––";
            }

            .divider.right {
                color: #19255A;
                text-align: right;
            }

        .long-divider {
            color: #FF6300;
            font-family: arial;
            font-size: small;
            width: 100%;
            text-align: center;
            margin: 10px 0;
        }

            .long-divider::before {
                content: "––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––";
            }

        table tr td,
        table tr th {
            padding: 3px;
        }

        .position-table {
            width: 100%;
            border-collapse: collapse;
        }

            .position-table th {
                text-align: left;
                padding: 5px 3px;
            }

            .position-table td {
                padding: 3px;
            }

        /* Original content - will be hidden after processing */
        #original-content {
            display: none;
        }

        /* Measuring container */
        #measuring-container {
            position: absolute;
            left: -9999px;
            width: 180mm; /* 210mm - 15mm - 15mm */
            visibility: hidden;
        }

        /* For print */
        @media print {
            body {
                margin: 0;
                padding: 0;
                background: white;
            }

            .page {
                margin: 0;
                box-shadow: none;
                page-break-after: always;
                page-break-inside: avoid;
            }

                .page:last-child {
                    page-break-after: auto;
                }
        }

        @layer utilities {
            /* Appendix: fehlende Utility-Klassen ergänzen, damit die HTML-Templates wirken */
            .table-fixed {
                table-layout: fixed;
            }

            .align-top {
                vertical-align: top;
            }

            .whitespace-pre-wrap {
                white-space: pre-wrap;
            }

            .whitespace-nowrap {
                white-space: nowrap;
            }

            /* Robuste Wort-/Zeilenumbrüche für lange, untrennbare Strings */
            .break-words {
                overflow-wrap: anywhere; /* moderne Browser */
                word-wrap: break-word; /* legacy alias */
                word-break: normal;
            }

            .break-all {
                word-break: break-all;
            }

            .overflow-x-hidden {
                overflow-x: hidden;
            }

            /* Zusätzliche Sicherheitsnetze für Tabellen im Appendix-Bereich */
            .appendix table {
                width: 100%;
                max-width: 100%;
                table-layout: fixed;
            }
        }
    </style>
    <style>
        /*! tailwindcss v4.1.11 | MIT License | https://tailwindcss.com */
        @layer properties;
        @layer theme, base, components, utilities;
        @layer theme {
            :root, :host {
                --font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
                "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
                --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
                "Courier New", monospace;
                --color-red-500: oklch(63.7% 0.237 25.331);
                --color-orange-50: oklch(98% 0.016 73.684);
                --color-orange-500: oklch(70.5% 0.213 47.604);
                --color-orange-600: oklch(64.6% 0.222 41.116);
                --color-yellow-50: oklch(98.7% 0.026 102.212);
                --color-yellow-200: oklch(94.5% 0.129 101.54);
                --color-yellow-800: oklch(47.6% 0.114 61.907);
                --color-blue-50: oklch(97% 0.014 254.604);
                --color-blue-500: oklch(62.3% 0.214 259.815);
                --color-blue-800: oklch(42.4% 0.199 265.638);
                --color-blue-900: oklch(37.9% 0.146 265.522);
                --color-gray-50: oklch(98.5% 0.002 247.839);
                --color-gray-100: oklch(96.7% 0.003 264.542);
                --color-gray-200: oklch(92.8% 0.006 264.531);
                --color-gray-300: oklch(87.2% 0.01 258.338);
                --color-gray-400: oklch(70.7% 0.022 261.325);
                --color-gray-500: oklch(55.1% 0.027 264.364);
                --color-gray-600: oklch(44.6% 0.03 256.802);
                --color-gray-700: oklch(37.3% 0.034 259.733);
                --color-gray-800: oklch(27.8% 0.033 256.848);
                --color-gray-900: oklch(21% 0.034 264.665);
                --color-white: #fff;
                --spacing: 0.25rem;
                --container-5xl: 64rem;
                --text-xs: 0.75rem;
                --text-xs--line-height: calc(1 / 0.75);
                --text-sm: 0.875rem;
                --text-sm--line-height: calc(1.25 / 0.875);
                --text-lg: 1.125rem;
                --text-lg--line-height: calc(1.75 / 1.125);
                --text-xl: 1.25rem;
                --text-xl--line-height: calc(1.75 / 1.25);
                --text-2xl: 1.5rem;
                --text-2xl--line-height: calc(2 / 1.5);
                --text-3xl: 1.875rem;
                --text-3xl--line-height: calc(2.25 / 1.875);
                --font-weight-semibold: 600;
                --font-weight-bold: 700;
                --radius-lg: 0.5rem;
                --blur-sm: 8px;
                --default-transition-duration: 150ms;
                --default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
                --default-font-family: var(--font-sans);
                --default-mono-font-family: var(--font-mono);
            }
        }
        @layer base {
            *, ::after, ::before, ::backdrop, ::file-selector-button {
                box-sizing: border-box;
                margin: 0;
                padding: 0;
                border: 0 solid;
            }
            html, :host {
                line-height: 1.5;
                -webkit-text-size-adjust: 100%;
                tab-size: 4;
                font-family: var(--default-font-family, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
                font-feature-settings: var(--default-font-feature-settings, normal);
                font-variation-settings: var(--default-font-variation-settings, normal);
                -webkit-tap-highlight-color: transparent;
            }
            hr {
                height: 0;
                color: inherit;
                border-top-width: 1px;
            }
            abbr:where([title]) {
                -webkit-text-decoration: underline dotted;
                text-decoration: underline dotted;
            }
            h1, h2, h3, h4, h5, h6 {
                font-size: inherit;
                font-weight: inherit;
            }
            a {
                color: inherit;
                -webkit-text-decoration: inherit;
                text-decoration: inherit;
            }
            b, strong {
                font-weight: bolder;
            }
            code, kbd, samp, pre {
                font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);
                font-feature-settings: var(--default-mono-font-feature-settings, normal);
                font-variation-settings: var(--default-mono-font-variation-settings, normal);
                font-size: 1em;
            }
            small {
                font-size: 80%;
            }
            sub, sup {
                font-size: 75%;
                line-height: 0;
                position: relative;
                vertical-align: baseline;
            }
            sub {
                bottom: -0.25em;
            }
            sup {
                top: -0.5em;
            }
            table {
                text-indent: 0;
                border-color: inherit;
                border-collapse: collapse;
            }
            :-moz-focusring {
                outline: auto;
            }
            progress {
                vertical-align: baseline;
            }
            summary {
                display: list-item;
            }
            ol, ul, menu {
                list-style: none;
            }
            img, svg, video, canvas, audio, iframe, embed, object {
                display: block;
                vertical-align: middle;
            }
            img, video {
                max-width: 100%;
                height: auto;
            }
            button, input, select, optgroup, textarea, ::file-selector-button {
                font: inherit;
                font-feature-settings: inherit;
                font-variation-settings: inherit;
                letter-spacing: inherit;
                color: inherit;
                border-radius: 0;
                background-color: transparent;
                opacity: 1;
            }
            :where(select:is([multiple], [size])) optgroup {
                font-weight: bolder;
            }
            :where(select:is([multiple], [size])) optgroup option {
                padding-inline-start: 20px;
            }
            ::file-selector-button {
                margin-inline-end: 4px;
            }
            ::placeholder {
                opacity: 1;
            }
            @supports (not (-webkit-appearance: -apple-pay-button))  or (contain-intrinsic-size: 1px) {
                ::placeholder {
                    color: currentcolor;
                    @supports (color: color-mix(in lab, red, red)) {
                        color: color-mix(in oklab, currentcolor 50%, transparent);
                    }
                }
            }
            textarea {
                resize: vertical;
            }
            ::-webkit-search-decoration {
                -webkit-appearance: none;
            }
            ::-webkit-date-and-time-value {
                min-height: 1lh;
                text-align: inherit;
            }
            ::-webkit-datetime-edit {
                display: inline-flex;
            }
            ::-webkit-datetime-edit-fields-wrapper {
                padding: 0;
            }
            ::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {
                padding-block: 0;
            }
            :-moz-ui-invalid {
                box-shadow: none;
            }
            button, input:where([type="button"], [type="reset"], [type="submit"]), ::file-selector-button {
                appearance: button;
            }
            ::-webkit-inner-spin-button, ::-webkit-outer-spin-button {
                height: auto;
            }
            [hidden]:where(:not([hidden="until-found"])) {
                display: none !important;
            }
        }
        @layer utilities {
            .visible {
                visibility: visible;
            }
            .relative {
                position: relative;
            }
            .static {
                position: static;
            }
            .container {
                width: 100%;
                @media (width >= 40rem) {
                    max-width: 40rem;
                }
                @media (width >= 48rem) {
                    max-width: 48rem;
                }
                @media (width >= 64rem) {
                    max-width: 64rem;
                }
                @media (width >= 80rem) {
                    max-width: 80rem;
                }
                @media (width >= 96rem) {
                    max-width: 96rem;
                }
            }
            .mx-auto {
                margin-inline: auto;
            }
            .mt-1 {
                margin-top: calc(var(--spacing) * 1);
            }
            .mt-2 {
                margin-top: calc(var(--spacing) * 2);
            }
            .mt-8 {
                margin-top: calc(var(--spacing) * 8);
            }
            .mt-auto {
                margin-top: auto;
            }
            .mb-1 {
                margin-bottom: calc(var(--spacing) * 1);
            }
            .mb-2 {
                margin-bottom: calc(var(--spacing) * 2);
            }
            .mb-3 {
                margin-bottom: calc(var(--spacing) * 3);
            }
            .mb-4 {
                margin-bottom: calc(var(--spacing) * 4);
            }
            .mb-6 {
                margin-bottom: calc(var(--spacing) * 6);
            }
            .mb-8 {
                margin-bottom: calc(var(--spacing) * 8);
            }
            .block {
                display: block;
            }
            .flex {
                display: flex;
            }
            .grid {
                display: grid;
            }
            .hidden {
                display: none;
            }
            .table {
                display: table;
            }
            .h-5 {
                height: calc(var(--spacing) * 5);
            }
            .h-16 {
                height: calc(var(--spacing) * 16);
            }
            .h-32 {
                height: calc(var(--spacing) * 32);
            }
            .min-h-80 {
                min-height: calc(var(--spacing) * 80);
            }
            .w-1\/2 {
                width: calc(1/2 * 100%);
            }
            .w-1\/3 {
                width: calc(1/3 * 100%);
            }
            .w-1\/4 {
                width: calc(1/4 * 100%);
            }
            .w-2\/3 {
                width: calc(2/3 * 100%);
            }
            .w-3\/4 {
                width: calc(3/4 * 100%);
            }
            .w-5 {
                width: calc(var(--spacing) * 5);
            }
            .w-full {
                width: 100%;
            }
            .flex-1 {
                flex: 1;
            }
            .flex-none {
                flex: none;
            }
            .border-collapse {
                border-collapse: collapse;
            }
            .resize {
                resize: both;
            }
            .grid-cols-1 {
                grid-template-columns: repeat(1, minmax(0, 1fr));
            }
            .flex-col {
                flex-direction: column;
            }
            .flex-row {
                flex-direction: row;
            }
            .flex-wrap {
                flex-wrap: wrap;
            }
            .items-center {
                align-items: center;
            }
            .items-start {
                align-items: flex-start;
            }
            .justify-between {
                justify-content: space-between;
            }
            .justify-end {
                justify-content: flex-end;
            }
            .gap-2 {
                gap: calc(var(--spacing) * 2);
            }
            .gap-4 {
                gap: calc(var(--spacing) * 4);
            }
            .gap-6 {
                gap: calc(var(--spacing) * 6);
            }
            .space-y-1 {
                :where(& > :not(:last-child)) {
                    --tw-space-y-reverse: 0;
                    margin-block-start: calc(calc(var(--spacing) * 1) * var(--tw-space-y-reverse));
                    margin-block-end: calc(calc(var(--spacing) * 1) * calc(1 - var(--tw-space-y-reverse)));
                }
            }
            .space-y-2 {
                :where(& > :not(:last-child)) {
                    --tw-space-y-reverse: 0;
                    margin-block-start: calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));
                    margin-block-end: calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)));
                }
            }
            .overflow-x-auto {
                overflow-x: auto;
            }
            .rounded {
                border-radius: 0.25rem;
            }
            .rounded-lg {
                border-radius: var(--radius-lg);
            }
            .rounded-t-lg {
                border-top-left-radius: var(--radius-lg);
                border-top-right-radius: var(--radius-lg);
            }
            .rounded-b-lg {
                border-bottom-right-radius: var(--radius-lg);
                border-bottom-left-radius: var(--radius-lg);
            }
            .border {
                border-style: var(--tw-border-style);
                border-width: 1px;
            }
            .border-t {
                border-top-style: var(--tw-border-style);
                border-top-width: 1px;
            }
            .border-t-2 {
                border-top-style: var(--tw-border-style);
                border-top-width: 2px;
            }
            .border-b {
                border-bottom-style: var(--tw-border-style);
                border-bottom-width: 1px;
            }
            .border-b-2 {
                border-bottom-style: var(--tw-border-style);
                border-bottom-width: 2px;
            }
            .border-l-4 {
                border-left-style: var(--tw-border-style);
                border-left-width: 4px;
            }
            .border-blue-500 {
                border-color: var(--color-blue-500);
            }
            .border-gray-200 {
                border-color: var(--color-gray-200);
            }
            .border-gray-300 {
                border-color: var(--color-gray-300);
            }
            .border-orange-500 {
                border-color: var(--color-orange-500);
            }
            .border-white {
                border-color: var(--color-white);
            }
            .border-yellow-200 {
                border-color: var(--color-yellow-200);
            }
            .bg-\[\#19255A\] {
                background-color: #19255A;
            }
            .bg-\[\#FF6300\] {
                background-color: #FF6300;
            }
            .bg-blue-50 {
                background-color: var(--color-blue-50);
            }
            .bg-gray-50 {
                background-color: var(--color-gray-50);
            }
            .bg-gray-100 {
                background-color: var(--color-gray-100);
            }
            .bg-gray-200 {
                background-color: var(--color-gray-200);
            }
            .bg-gray-400 {
                background-color: var(--color-gray-400);
            }
            .bg-orange-50 {
                background-color: var(--color-orange-50);
            }
            .bg-white {
                background-color: var(--color-white);
            }
            .bg-white\/10 {
                background-color: color-mix(in srgb, #fff 10%, transparent);
                @supports (color: color-mix(in lab, red, red)) {
                    background-color: color-mix(in oklab, var(--color-white) 10%, transparent);
                }
            }
            .bg-white\/20 {
                background-color: color-mix(in srgb, #fff 20%, transparent);
                @supports (color: color-mix(in lab, red, red)) {
                    background-color: color-mix(in oklab, var(--color-white) 20%, transparent);
                }
            }
            .bg-yellow-50 {
                background-color: var(--color-yellow-50);
            }
            .p-2 {
                padding: calc(var(--spacing) * 2);
            }
            .p-3 {
                padding: calc(var(--spacing) * 3);
            }
            .p-4 {
                padding: calc(var(--spacing) * 4);
            }
            .p-5 {
                padding: calc(var(--spacing) * 5);
            }
            .p-6 {
                padding: calc(var(--spacing) * 6);
            }
            .p-8 {
                padding: calc(var(--spacing) * 8);
            }
            .py-1 {
                padding-block: calc(var(--spacing) * 1);
            }
            .pt-2 {
                padding-top: calc(var(--spacing) * 2);
            }
            .pt-6 {
                padding-top: calc(var(--spacing) * 6);
            }
            .pr-4 {
                padding-right: calc(var(--spacing) * 4);
            }
            .pb-6 {
                padding-bottom: calc(var(--spacing) * 6);
            }
            .text-left {
                text-align: left;
            }
            .text-right {
                text-align: right;
            }
            .text-2xl {
                font-size: var(--text-2xl);
                line-height: var(--tw-leading, var(--text-2xl--line-height));
            }
            .text-3xl {
                font-size: var(--text-3xl);
                line-height: var(--tw-leading, var(--text-3xl--line-height));
            }
            .text-lg {
                font-size: var(--text-lg);
                line-height: var(--tw-leading, var(--text-lg--line-height));
            }
            .text-sm {
                font-size: var(--text-sm);
                line-height: var(--tw-leading, var(--text-sm--line-height));
            }
            .text-xl {
                font-size: var(--text-xl);
                line-height: var(--tw-leading, var(--text-xl--line-height));
            }
            .text-xs {
                font-size: var(--text-xs);
                line-height: var(--tw-leading, var(--text-xs--line-height));
            }
            .font-bold {
                --tw-font-weight: var(--font-weight-bold);
                font-weight: var(--font-weight-bold);
            }
            .font-semibold {
                --tw-font-weight: var(--font-weight-semibold);
                font-weight: var(--font-weight-semibold);
            }
            .text-blue-800 {
                color: var(--color-blue-800);
            }
            .text-blue-900 {
                color: var(--color-blue-900);
            }
            .text-gray-500 {
                color: var(--color-gray-500);
            }
            .text-gray-600 {
                color: var(--color-gray-600);
            }
            .text-gray-700 {
                color: var(--color-gray-700);
            }
            .text-gray-800 {
                color: var(--color-gray-800);
            }
            .text-gray-900 {
                color: var(--color-gray-900);
            }
            .text-orange-600 {
                color: var(--color-orange-600);
            }
            .text-white {
                color: var(--color-white);
            }
            .text-white\/90 {
                color: color-mix(in srgb, #fff 90%, transparent);
                @supports (color: color-mix(in lab, red, red)) {
                    color: color-mix(in oklab, var(--color-white) 90%, transparent);
                }
            }
            .text-white\/95 {
                color: color-mix(in srgb, #fff 95%, transparent);
                @supports (color: color-mix(in lab, red, red)) {
                    color: color-mix(in oklab, var(--color-white) 95%, transparent);
                }
            }
            .text-yellow-200 {
                color: var(--color-yellow-200);
            }
            .text-yellow-800 {
                color: var(--color-yellow-800);
            }
            .uppercase {
                text-transform: uppercase;
            }
            .shadow-lg {
                --tw-shadow: 0 10px 15px -3px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 4px 6px -4px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
                box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
            }
            .backdrop-blur-sm {
                --tw-backdrop-blur: blur(var(--blur-sm));
                -webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
                backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
            }
            .hover\:bg-gray-50 {
                &:hover {
                    @media (hover: hover) {
                        background-color: var(--color-gray-50);
                    }
                }
            }
            .md\:w-96 {
                @media (width >= 48rem) {
                    width: calc(var(--spacing) * 96);
                }
            }
            .md\:grid-cols-2 {
                @media (width >= 48rem) {
                    grid-template-columns: repeat(2, minmax(0, 1fr));
                }
            }
            .md\:grid-cols-3 {
                @media (width >= 48rem) {
                    grid-template-columns: repeat(3, minmax(0, 1fr));
                }
            }
            .md\:p-8 {
                @media (width >= 48rem) {
                    padding: calc(var(--spacing) * 8);
                }
            }
            .md\:text-2xl {
                @media (width >= 48rem) {
                    font-size: var(--text-2xl);
                    line-height: var(--tw-leading, var(--text-2xl--line-height));
                }
            }
        }
        @property --tw-space-y-reverse {
            syntax: "*";
            inherits: false;
            initial-value: 0;
        }
        @property --tw-border-style {
            syntax: "*";
            inherits: false;
            initial-value: solid;
        }
        @property --tw-font-weight {
            syntax: "*";
            inherits: false;
        }
        @property --tw-shadow {
            syntax: "*";
            inherits: false;
            initial-value: 0 0 #0000;
        }
        @property --tw-shadow-color {
            syntax: "*";
            inherits: false;
        }
        @property --tw-shadow-alpha {
            syntax: "<percentage>";
            inherits: false;
            initial-value: 100%;
        }
        @property --tw-inset-shadow {
            syntax: "*";
            inherits: false;
            initial-value: 0 0 #0000;
        }
        @property --tw-inset-shadow-color {
            syntax: "*";
            inherits: false;
        }
        @property --tw-inset-shadow-alpha {
            syntax: "<percentage>";
            inherits: false;
            initial-value: 100%;
        }
        @property --tw-ring-color {
            syntax: "*";
            inherits: false;
        }
        @property --tw-ring-shadow {
            syntax: "*";
            inherits: false;
            initial-value: 0 0 #0000;
        }
        @property --tw-inset-ring-color {
            syntax: "*";
            inherits: false;
        }
        @property --tw-inset-ring-shadow {
            syntax: "*";
            inherits: false;
            initial-value: 0 0 #0000;
        }
        @property --tw-ring-inset {
            syntax: "*";
            inherits: false;
        }
        @property --tw-ring-offset-width {
            syntax: "<length>";
            inherits: false;
            initial-value: 0px;
        }
        @property --tw-ring-offset-color {
            syntax: "*";
            inherits: false;
            initial-value: #fff;
        }
        @property --tw-ring-offset-shadow {
            syntax: "*";
            inherits: false;
            initial-value: 0 0 #0000;
        }
        @property --tw-backdrop-blur {
            syntax: "*";
            inherits: false;
        }
        @property --tw-backdrop-brightness {
            syntax: "*";
            inherits: false;
        }
        @property --tw-backdrop-contrast {
            syntax: "*";
            inherits: false;
        }
        @property --tw-backdrop-grayscale {
            syntax: "*";
            inherits: false;
        }
        @property --tw-backdrop-hue-rotate {
            syntax: "*";
            inherits: false;
        }
        @property --tw-backdrop-invert {
            syntax: "*";
            inherits: false;
        }
        @property --tw-backdrop-opacity {
            syntax: "*";
            inherits: false;
        }
        @property --tw-backdrop-saturate {
            syntax: "*";
            inherits: false;
        }
        @property --tw-backdrop-sepia {
            syntax: "*";
            inherits: false;
        }
        @layer properties {
            @supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
                *, ::before, ::after, ::backdrop {
                    --tw-space-y-reverse: 0;
                    --tw-border-style: solid;
                    --tw-font-weight: initial;
                    --tw-shadow: 0 0 #0000;
                    --tw-shadow-color: initial;
                    --tw-shadow-alpha: 100%;
                    --tw-inset-shadow: 0 0 #0000;
                    --tw-inset-shadow-color: initial;
                    --tw-inset-shadow-alpha: 100%;
                    --tw-ring-color: initial;
                    --tw-ring-shadow: 0 0 #0000;
                    --tw-inset-ring-color: initial;
                    --tw-inset-ring-shadow: 0 0 #0000;
                    --tw-ring-inset: initial;
                    --tw-ring-offset-width: 0px;
                    --tw-ring-offset-color: #fff;
                    --tw-ring-offset-shadow: 0 0 #0000;
                    --tw-backdrop-blur: initial;
                    --tw-backdrop-brightness: initial;
                    --tw-backdrop-contrast: initial;
                    --tw-backdrop-grayscale: initial;
                    --tw-backdrop-hue-rotate: initial;
                    --tw-backdrop-invert: initial;
                    --tw-backdrop-opacity: initial;
                    --tw-backdrop-saturate: initial;
                    --tw-backdrop-sepia: initial;
                }
            }
        }
    </style>
</head>

<body>
    <div id="original-content">
        <div id="header-template">
            <div>
                <div class="hidden"></div>
                <!-- Top row with two equal boxes -->
                <div class="flex gap-4 mb-4">
                    <div class="flex flex-col w-1/2 gap-4 bg-gray-50 p-4">
                        <div class="text-sm bg-gray-100 p-4">{{SenderNameDocument}}, {{SenderStreetDocument}}, {{SenderZipDocument}} {{SenderCityDocument}}</div>
                        <div class="space-y-1">
                            <div>{{ReceiverCompany}}</div>
                            <div>{{ReceiverName}}</div>
                            <div>{{ReceiverDepartment}}</div>
                            <div>{{ReceiverStreet}}</div>
                            <div>{{ReceiverZip}} {{ReceiverCity}}</div>
                            <div>{{ReceiverCountry}}</div>
                        </div>
                    </div>
                    <div class="flex flex-col w-1/2 gap-4 bg-gray-50 p-4">
                        <div class="text-sm bg-gray-200 p-4 w-full"><strong>{{Doctype}}</strong></div>
                        <div>
                            <table class="w-full">
                                <tr>
                                    <td class="py-1 pr-4"><strong>{{InvoiceNumberLabel}}</strong></td>
                                    <td class="py-1">{{InvoiceNumber}}</td>
                                </tr>
                                <tr>
                                    <td class="py-1 pr-4"><strong>{{InvoiceDateLabel}}</strong></td>
                                    <td class="py-1">{{InvoiceDate}}</td>
                                </tr>
                                <tr>
                                    <td class="py-1 pr-4"><strong>{{ServicePeriodLabel}}</strong></td>
                                    <td class="py-1">{{ServicePeriodStart}}-{{ServicePeriodEnd}}</td>
                                </tr>
                                <tr>
                                    <td class="py-1 pr-4"><strong>{{ProjectNumberLabel}}</strong></td>
                                    <td class="py-1">{{ProjectNumber}}</td>
                                </tr>
                                <tr>
                                    <td class="py-1 pr-4"><strong>{{OrderNumberLabel}}</strong></td>
                                    <td class="py-1">{{OrderNumber}}</td>
                                </tr>
                                <tr>
                                    <td class="py-1 pr-4"><strong>{{JobNumberLabel}}</strong></td>
                                    <td class="py-1">{{JobNumber}}</td>
                                </tr>
                                <tr>
                                    <td class="py-1 pr-4"><strong>{{VatIdLabel}}</strong></td>
                                    <td class="py-1">{{SenderVatIdDocument}}</td>
                                </tr>
                                <tr>
                                    <td class="py-1 pr-4"><strong>{{AccountLabel}}</strong></td>
                                    <td class="py-1">{{PostingAccount}}</td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="divider"></div>
            </div>
        </div>

        <div id="footer-template">
            <div class="mt-auto">
                <div class="long-divider"></div>
                <div class="flex text-xs text-gray-500 relative">
                    <div class="flex-none" style="width: 20%;">
                        <div>{{SenderNameDocument}}</div>
                        <div>{{SenderStreetDocument}}</div>
                        <div>{{SenderZipDocument}} {{SenderCityDocument}}</div>
                        <div>{{SenderCountryDocument}}</div>
                    </div>
                    <div class="flex-none" style="width: 35%;">
                        <table style="table-layout: fixed; width: 100%;">
                            <tr>
                                <td style="width: 30%; padding-right: 5px;"><strong>{{PhoneLabel}}</strong></td>
                                <td style="width: 70%;">{{SenderPhoneDocument}}</td>
                            </tr>
                            <tr>
                                <td style="width: 30%; padding-right: 5px;"><strong>{{EmailLabel}}</strong></td>
                                <td style="width: 70%; word-wrap: break-word; font-size: 10px;">{{SenderEmailDocument}}</td>
                            </tr>
                        </table>
                    </div>
                    <div class="flex-1" style="width: 45%;">
                        <table style="table-layout: fixed; width: 100%;">
                            <tr>
                                <td style="width: 40%; padding-right: 5px;"><strong>{{IbanLabel}}</strong></td>
                                <td style="width: 60%;">{{SenderIban1Document}}</td>
                            </tr>
                            <tr>
                                <td style="width: 40%; padding-right: 5px;"><strong>{{FooterVatIdLabel}}</strong></td>
                                <td style="width: 60%;">{{FooterVatIdLabel}}</td>
                            </tr>
                            <tr>
                                <td style="width: 40%; padding-right: 5px;"><strong>{{TaxNumberLabel}}</strong></td>
                                <td style="width: 60%;">{{SenderTaxNoDocument}}</td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="flex justify-end mt-2">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 140 32" width="140" height="32">
                        <path id="Vector" d="M9.08555 4.77212C11.5462 4.77212 13.0433 5.80457 14.2134 7.06071L16.3299 4.04941C14.5575 2.01892 12.2689 0.934853 8.77582 0.934853C3.83727 0.934853 0 4.11824 0 9.28048V22.8916C0 28.3119 3.78565 31.0651 8.82744 31.0651C12.1829 31.0651 14.4715 30.2392 16.2267 28.3119L14.2994 25.4211C13.0949 26.6256 11.4602 27.2279 9.22321 27.2279C6.41839 27.2279 4.35349 25.6276 4.35349 22.6679V9.50418C4.35349 6.57891 6.19469 4.77212 9.08555 4.77212Z" fill="#19255A" />
                        <path id="Vector_2" d="M31.3004 19.0199H25.622L28.5472 6.88862L31.3004 19.0199ZM38.4932 30.6349L30.9563 1.0725H26.1726L18.2055 30.6349H22.9376L24.7444 22.7195H32.1436L33.8644 30.6349H38.476H38.4932Z" fill="#19255A" />
                        <path id="Vector_3" d="M55.4425 21.9796C55.4425 25.3351 52.9819 26.7633 49.9705 26.7633H47.1313V5.28836H50.2287C52.9819 5.28836 55.4425 6.88865 55.4425 10.1065V21.9796ZM59.796 21.8936V10.1409C59.796 4.2387 55.6662 1.36505 50.2459 1.36505H42.8466V30.635H49.9878C55.4081 30.635 59.796 27.8302 59.796 21.8936Z" fill="#19255A" />
                        <path id="Vector_4" d="M79.034 22.6679C79.034 25.5071 77.1756 27.1935 74.5084 27.1935H73.8201C71.0669 27.1935 69.2085 25.5588 69.2085 22.6679V9.45255C69.2085 6.52728 71.1357 4.84095 73.7685 4.84095H74.4912C77.1239 4.84095 79.0168 6.5617 79.0168 9.48697V22.6507L79.034 22.6679ZM83.4219 22.7539V9.36652C83.4219 4.11824 79.6362 0.934853 74.5084 0.934853H73.7857C68.7095 0.934853 64.8722 4.08382 64.8722 9.36652V22.7539C64.8722 28.0883 68.5718 31.0651 73.8201 31.0651H74.5084C79.7223 31.0651 83.4219 28.0538 83.4219 22.7539Z" fill="#19255A" />
                        <path id="Vector_5" d="M96.8781 14.3567C93.9873 12.3778 91.974 11.2938 91.974 8.59218C91.974 5.89061 93.4883 4.89257 95.7597 4.89257C97.8245 4.89257 99.3732 5.78736 100.543 7.47369L102.952 4.75491C101.232 2.31145 98.7021 0.934853 95.5532 0.934853C91.2513 0.934853 87.7582 3.42994 87.8442 8.67822C87.8958 12.9457 91.0792 15.3891 94.5207 17.6777C97.0674 19.4845 98.9602 20.3965 98.9602 23.2702C98.9602 25.7652 97.1535 27.1074 94.9509 27.1074C92.972 27.1074 90.8211 26.3331 89.651 23.9585L87.0182 26.4535C88.5669 29.5165 91.8363 31.0651 95.1058 31.0651C100.01 31.0651 102.987 27.8301 102.935 23.1841C102.935 19.4329 100.905 16.9034 96.8609 14.3567" fill="#19255A" />
                        <path id="Vector_6" d="M111.642 30.635H116.03V19.3985L122.569 1.36505H117.837L113.845 15.0106L109.921 1.36505H105.224L111.642 19.3985V30.635Z" fill="#19255A" />
                        <path id="Vector_7" d="M133.926 14.3567C131.035 12.3778 129.022 11.2938 129.022 8.59218C129.022 5.89061 130.536 4.89257 132.807 4.89257C134.872 4.89257 136.421 5.78736 137.591 7.47369L140 4.75491C138.262 2.31145 135.733 0.934853 132.584 0.934853C128.282 0.934853 124.789 3.42994 124.875 8.67822C124.926 12.9457 128.11 15.3891 131.551 17.6777C134.098 19.4845 135.991 20.3965 135.991 23.2702C135.991 25.7652 134.184 27.1074 131.981 27.1074C130.002 27.1074 127.852 26.3331 126.681 23.9585L124.049 26.4535C125.597 29.5165 128.867 31.0651 132.136 31.0651C137.04 31.0651 140.017 27.8301 139.966 23.1841C139.966 19.4329 137.935 16.9034 133.891 14.3567" fill="#19255A" />
                    </svg>
                </div>
            </div>
        </div>

        <div id="content-template">
            {{LineItemBlock}}

            <!-- Row with unequal boxes (1/3 and 2/3) -->
            <div id="summary-section" class="flex flex-row gap-4 mb-4 mt-8">
                <div class="h-32 w-1/4">
                    <table>
                        <tr>
                            <td><strong>{{DueDateLabel}}</strong></td>
                            <td>{{PaymentDueDate}}</td>
                        </tr>
                        <tr>
                            <td>{{PaymentConditionDocument}}</td>
                        </tr>
                    </table>
                </div>
                <div class="h-32 w-3/4 flex">
                    <div class="w-full">
                        <table class="amounts-table">
                            <tr>
                                <td><strong>{{Net19Label}}</strong></td>
                                <td class="text-right">{{Net19Value}} {{CurrencyUnit}}</td>
                                <td><strong>{{Vat19Label}}</strong></td>
                                <td class="text-right">{{Vat19Value}} {{CurrencyUnit}}</td>
                                <td><strong>{{Rate19Label}}</strong></td>
                                <td class="text-right">{{Gross19Value}} {{CurrencyUnit}}</td>
                            </tr>
                            <tr>
                                <td><strong>{{Net7Label}}</strong></td>
                                <td class="text-right">{{Net7Value}} {{CurrencyUnit}}</td>
                                <td><strong>{{Vat7Label}}</strong></td>
                                <td class="text-right">{{Vat7Value}} {{CurrencyUnit}}</td>
                                <td><strong>{{Rate7Label}}</strong></td>
                                <td class="text-right">{{Gross7Value}} {{CurrencyUnit}}</td>
                            </tr>
                            <tr>
                                <td><strong>{{Net0Label}}</strong></td>
                                <td class="text-right">{{Net0Value}} {{CurrencyUnit}}</td>
                                <td><strong>{{Vat0Label}}</strong></td>
                                <td class="text-right">{{Vat0Value}} {{CurrencyUnit}}</td>
                                <td><strong>{{Rate0Label}}</strong></td>
                                <td class="text-right">{{Gross0Value}} {{CurrencyUnit}}</td>
                            </tr>
                            <tr>
                                <td><strong>{{TotalNetLabel}}</strong></td>
                                <td class="text-right"><strong>{{NetTotal}} {{CurrencyUnit}}</strong></td>
                                <td><strong>{{VatAmountLabel}}</strong></td>
                                <td class="text-right"><strong>{{VatTotal}} {{CurrencyUnit}}</strong></td>
                                <td><strong>{{TotalGrossLabel}}</strong></td>
                                <td class="text-right"><strong>{{Gross}} {{CurrencyUnit}}</strong></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Measuring container for calculating element heights -->
    <div id="measuring-container"></div>

    <!-- Pages will be generated here by JavaScript -->
    <div id="pages-container">

    </div>

    <div id="appendix-container">
        {{AppendixHTML}}
    </div>

    <script>
        // Convert mm to pixels (96 DPI assumed)
        function mmToPixels(mm) {
            return (mm * 96) / 25.4;
        }

        // Function to remove duplicate consecutive lines in header
        function removeDuplicatesInHeader() {
            const headerTemplate = document.getElementById('header-template');
            if (!headerTemplate) return;

            // Find all div elements that might contain duplicate text
            const addressDivs = headerTemplate.querySelectorAll('div > div > div');

            let previousText = '';
            const toRemove = [];

            addressDivs.forEach((div) => {
                const currentText = div.textContent.trim();

                // Check if current text is non-empty and same as previous
                if (currentText && currentText === previousText) {
                    toRemove.push(div);
                } else {
                    previousText = currentText;
                }
            });

            // Remove duplicate elements
            toRemove.forEach(div => {
                div.remove();
            });

            console.log(`Removed ${toRemove.length} duplicate header elements`);
        }

        // Create pagination
        function createPages() {
            // Remove duplicates before processing
            removeDuplicatesInHeader();

            // Get templates
            const headerTemplate = document.getElementById('header-template').innerHTML;
            const footerTemplate = document.getElementById('footer-template').innerHTML;

            // Dimensions in pixels
            const pageHeight = mmToPixels(297);
            const pagePadding = mmToPixels(15);
            const availableHeight = pageHeight - (pagePadding * 2);

            // Get content elements
            const contentDiv = document.querySelector('#content-template > .min-h-80');
            const introTable = contentDiv ? contentDiv.querySelector('table:first-child') : null;
            const mainTable = document.querySelector('#main-table');
            const dividerRight = document.querySelector('#content-template > .divider.right');
            const summarySection = document.querySelector('#summary-section');

            // Get table rows
            let thead = null;
            let tbody = null;
            let rows = [];

            if (mainTable) {
                const theadEl = mainTable.querySelector('thead');
                const tbodyEl = mainTable.querySelector('tbody');

                if (theadEl) thead = theadEl.cloneNode(true);
                if (tbodyEl) {
                    tbody = tbodyEl;
                    rows = Array.from(tbody.querySelectorAll('tr'));
                }
            }

            // Container for pages
            const pagesContainer = document.getElementById('pages-container');
            pagesContainer.innerHTML = '';

            // Measuring container
            const measuringContainer = document.getElementById('measuring-container');

            let currentPage = null;
            let currentPageHeight = 0;
            let pageNumber = 1;
            let currentTable = null;
            let currentTbody = null;

            // Function to measure element height
            function measureHeight(element) {
                measuringContainer.innerHTML = '';
                const clone = element.cloneNode(true);
                measuringContainer.appendChild(clone);
                return clone.offsetHeight;
            }

            // Measure header and footer heights
            const headerDiv = document.createElement('div');
            headerDiv.innerHTML = headerTemplate;
            const headerHeight = measureHeight(headerDiv) + 90;

            const footerDiv = document.createElement('div');
            footerDiv.innerHTML = footerTemplate;
            const footerHeight = measureHeight(footerDiv);

            // Calculate content area height
            const contentAreaHeight = availableHeight - headerHeight - footerHeight - 20; // Extra margin

            // Function to create a new page
            function createNewPage() {
                currentPage = document.createElement('div');
                currentPage.className = 'page';

                // Add header
                const pageHeader = document.createElement('div');
                pageHeader.innerHTML = headerTemplate;
                currentPage.appendChild(pageHeader.firstElementChild || pageHeader);

                // Add content container
                const contentContainer = document.createElement('div');
                contentContainer.className = 'flex-1';
                currentPage.appendChild(contentContainer);

                currentPageHeight = 0;
                pageNumber++;

                pagesContainer.appendChild(currentPage);

                // Reset current table for new page
                currentTable = null;
                currentTbody = null;

                return contentContainer;
            }

            // Function to add footer to current page
            function addFooterToPage() {
                if (currentPage) {
                    const pageFooter = document.createElement('div');
                    pageFooter.innerHTML = footerTemplate;
                    currentPage.appendChild(pageFooter.firstElementChild || pageFooter);
                }
            }

            // Start with first page
            let currentContent = createNewPage();

            // Add intro table on first page
            if (introTable) {
                const introClone = introTable.cloneNode(true);
                const introHeight = measureHeight(introClone);

                if (currentPageHeight + introHeight <= contentAreaHeight) {
                    currentContent.appendChild(introClone);
                    currentPageHeight += introHeight;
                }
            }
            let rowsProcessed = 0;

            // Only process rows if main table exists
            if (mainTable && thead && rows.length > 0) {
                for (let i = 0; i < rows.length; i++) {
                    const row = rows[i];

                    // Check if we need a new table structure
                    if (!currentTable) {
                        currentTable = document.createElement('table');
                        currentTable.className = 'w-full text-sm position-table';

                        // Add thead to every table
                        currentTable.appendChild(thead.cloneNode(true));

                        currentTbody = document.createElement('tbody');
                        currentTable.appendChild(currentTbody);

                        // Measure table with header
                        const tableHeight = measureHeight(currentTable);

                        // Check if table fits on current page
                        if (currentPageHeight + tableHeight > contentAreaHeight) {
                            addFooterToPage();
                            currentContent = createNewPage();
                            currentPageHeight = 0;

                            // Recreate table for new page
                            currentTable = document.createElement('table');
                            currentTable.className = 'w-full text-sm position-table';
                            currentTable.appendChild(thead.cloneNode(true));
                            currentTbody = document.createElement('tbody');
                            currentTable.appendChild(currentTbody);
                        }

                        currentContent.appendChild(currentTable);
                        currentPageHeight += tableHeight;
                    }

                    // Measure row height
                    const rowClone = row.cloneNode(true);
                    const rowHeight = measureHeight(rowClone);

                    // Check if row fits on current page
                    if (currentPageHeight + rowHeight > contentAreaHeight) {
                        // Finish current page
                        addFooterToPage();

                        // Create new page
                        currentContent = createNewPage();
                        currentPageHeight = 0;

                        // Create new table on new page
                        currentTable = document.createElement('table');
                        currentTable.className = 'w-full text-sm position-table';
                        currentTable.appendChild(thead.cloneNode(true));
                        currentTbody = document.createElement('tbody');
                        currentTable.appendChild(currentTbody);
                        currentContent.appendChild(currentTable);
                        currentPageHeight = measureHeight(currentTable);
                    }

                    // Add row to current table
                    currentTbody.appendChild(rowClone);
                    currentPageHeight += rowHeight;
                    rowsProcessed++;
                }
            }

            // Add summary section
            const summaryElements = [];

            if (dividerRight) {
                summaryElements.push(dividerRight.cloneNode(true));
            }

            if (summarySection) {
                summaryElements.push(summarySection.cloneNode(true));
            }

            // Measure total summary height
            let totalSummaryHeight = 0;
            summaryElements.forEach(el => {
                totalSummaryHeight += measureHeight(el);
            });

            // Check if summary fits on current page
            if (currentPageHeight + totalSummaryHeight > contentAreaHeight) {
                addFooterToPage();
                currentContent = createNewPage();
            }

            // Add summary elements
            summaryElements.forEach(el => {
                currentContent.appendChild(el);
            });

            // Add footer to last page
            addFooterToPage();

            // Append and paginate appendix content (can span multiple pages)
            const appendixContainer = document.getElementById('appendix-container');

            function paginateAppendix() {
                if (!appendixContainer) return;

                // Try to find the provided appendix page block
                const appendixPage = appendixContainer.querySelector('.page.appendix') || appendixContainer;
                const appendixTable = appendixPage.querySelector('table');

                // If there is no table or no rows, fall back to previous behavior (append as-is)
                if (!appendixTable) {
                    pagesContainer.innerHTML = pagesContainer.innerHTML + appendixContainer.innerHTML;
                    return;
                }

                const appendixNotice = appendixPage.querySelector('.mt-8.pt-6.border-t.border-gray-200');

                const appendixContentAreaHeight = availableHeight - 20;

                const colgroup = appendixTable.querySelector('colgroup');
                const thead = appendixTable.querySelector('thead');
                const rows = Array.from(appendixTable.querySelectorAll('tbody > tr'));

                if (!thead || rows.length === 0) {
                    // Fallback: append original HTML if structure is unexpected
                    pagesContainer.innerHTML = pagesContainer.innerHTML + appendixContainer.innerHTML;
                    return;
                }

                // Helper zum Erstellen einer Appendix-Seite
                function createAppendixPage() {
                    currentPage = document.createElement('div');
                    currentPage.className = 'page appendix';

                    // Nur Inhaltsbereich (kein Header/Footer)
                    const contentContainer = document.createElement('div');
                    contentContainer.className = 'flex-1';
                    currentPage.appendChild(contentContainer);

                    currentPageHeight = 0;
                    pageNumber++;

                    pagesContainer.appendChild(currentPage);

                    // Reset etwaiger Tabellenzustand (aus dem Hauptteil)
                    currentTable = null;
                    currentTbody = null;

                    return contentContainer;
                }

                // Start a fresh page for the appendix
                let currentContent = createAppendixPage();
                currentPageHeight = 0;

                // Helper to create a new appendix table with header (and colgroup if present)
                function createAppendixTable() {
                    const table = document.createElement('table');
                    table.className = appendixTable.getAttribute('class') || 'w-full text-sm position-table';
                    if (colgroup) table.appendChild(colgroup.cloneNode(true));
                    table.appendChild(thead.cloneNode(true));
                    const tbody = document.createElement('tbody');
                    table.appendChild(tbody);
                    return { table, tbody };
                }

                // Measure header-only height in a realistic context (table with thead/colgroup, empty tbody)
                function measureAppendixHeaderHeight() {
                    const temp = document.createElement('table');
                    temp.className = appendixTable.getAttribute('class') || 'w-full text-sm position-table';
                    if (colgroup) temp.appendChild(colgroup.cloneNode(true));
                    temp.appendChild(thead.cloneNode(true));
                    temp.appendChild(document.createElement('tbody'));
                    return measureHeight(temp);
                }

                // Measure a single row height within a table context that applies the same widths/wrapping
                function measureAppendixRowHeight(rowEl) {
                    const temp = document.createElement('table');
                    temp.className = appendixTable.getAttribute('class') || 'w-full text-sm position-table';
                    if (colgroup) temp.appendChild(colgroup.cloneNode(true));
                    temp.appendChild(thead.cloneNode(true));
                    const tb = document.createElement('tbody');
                    tb.appendChild(rowEl.cloneNode(true));
                    temp.appendChild(tb);
                    const total = measureHeight(temp);
                    // subtract header-only height to get the row height under same layout constraints
                    return total - headerOnlyHeight;
                }

                // header-only height estimate using separate measurement to avoid DOM side effects
                const headerOnlyHeight = measureAppendixHeaderHeight();

                // Append appendix notice on the FIRST appendix page at the TOP
                if (appendixNotice) {
                    const noticeCloneTop = appendixNotice.cloneNode(true);
                    const noticeHeightTop = measureHeight(noticeCloneTop);
                    if (currentPageHeight + noticeHeightTop > appendixContentAreaHeight) {
                        // Start a new appendix page if the notice does not fit on the current one
                        currentContent = createAppendixPage();
                        currentPageHeight = 0;
                    }
                    currentContent.appendChild(noticeCloneTop);
                    currentPageHeight += noticeHeightTop;
                }

                // Ensure we have an initial table on the page (after placing the notice)
                let { table: currentTableA, tbody: currentTbodyA } = createAppendixTable();

                if (currentPageHeight + headerOnlyHeight > appendixContentAreaHeight) {
                    currentContent = createAppendixPage();
                    currentPageHeight = 0;
                }

                currentContent.appendChild(currentTableA);
                currentPageHeight += headerOnlyHeight;

                // Add rows with pagination
                for (let i = 0; i < rows.length; i++) {
                    const row = rows[i];
                    const rowHeight = measureAppendixRowHeight(row);

                    if (currentPageHeight + rowHeight > appendixContentAreaHeight) {
                        // Neue Appendix-Seite (ohne Footer auf der vorherigen)
                        currentContent = createAppendixPage();
                        currentPageHeight = 0;

                        // New table on the new page (with header)
                        ({ table: currentTableA, tbody: currentTbodyA } = createAppendixTable());

                        // Place table and account for its header height
                        currentContent.appendChild(currentTableA);
                        currentPageHeight += headerOnlyHeight;
                    }

                    currentTbodyA.appendChild(row.cloneNode(true));
                    currentPageHeight += rowHeight;
                }

                // Notice has already been appended to the first appendix page at the top
            }

            paginateAppendix();

            // Clean up
            appendixContainer.remove();
            measuringContainer.remove();

            console.log(`Created ${pageNumber - 1} pages with ${rowsProcessed} rows`);
        }

        // Run pagination when DOM is ready
        document.addEventListener('DOMContentLoaded', createPages);

        // Re-paginate on window resize (optional)
        window.addEventListener('resize', createPages);
    </script>
</body>

</html>