{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document PDF</title>
    <style>
        @page {
            size: A4;
            margin: 2cm;
        }

        * {
            box-sizing: border-box;
        }
        @media print {
            table {
                page-break-inside: avoid; /* Prevent table from breaking across pages */
            }
    
            tr {
                page-break-inside: avoid; /* Prevent table rows from breaking across pages */
                page-break-after: auto;
            }
    
            thead {
                display: table-header-group; /* Ensure table headers repeat on each page */
            }
    
            tfoot {
                display: table-footer-group; /* Ensure table footers repeat on each page */
            }
    
            .page-break {
                page-break-before: always; /* Force a page break before this element */
            }
        }
        body {
            margin: 0;
            padding: 0;
            font-family: sans-serif;
            font-size: 12pt;
            overflow-wrap: break-word;
        }

        .document-container {
            width: 100%;
            max-width: 100%;
            padding: 0;
            margin: 0;
        }

        .document-header {
            margin-bottom: 2rem;
        }

        .document-meta {
            color: #666;
            font-size: 0.9rem;
        }

        .document-content {
            line-height: 1.6;
        }

        .document-title {
            font-size: 2.5rem;
            margin-bottom: 1.5rem;
        }

        .document-subtitle {
            font-size: 2rem;
            margin-bottom: 1.25rem;
        }

        .document-h1 {
            font-size: 1.75rem;
            margin-bottom: 1rem;
        }

        .document-h2 {
            font-size: 1.5rem;
            margin-bottom: 0.75rem;
        }

        .document-h3 {
            font-size: 1.25rem;
            margin-bottom: 0.5rem;
        }

        .document-quote {
            border-left: 4px solid #ccc;
            margin: 1.5rem 0;
            padding-left: 1rem;
            font-style: italic;
        }

        .document-body {
            margin-bottom: 1rem;
        }

        .green { background-color: green; color: white; }
        .lightgreen { background-color: lightgreen; }
        .yellow { background-color: yellow; }
        .orange { background-color: orange; }
        .red { background-color: red; color: white; }

        table {
            width: 100%;
            table-layout: fixed;
            word-wrap: break-word;
            border-collapse: collapse;
        }

        th, td {
            padding: 4px 6px;
            font-size: 10pt;
            text-align: center;
            border: 1px solid #ddd;
            overflow-wrap: break-word;
            word-break: break-word;
        }

        th {
            background-color: #f2f2f2;
            font-weight: bold;
        }

        caption {
            font-weight: bold;
            margin-bottom: 10px;
        }

        .cmmi thead th {
            border-bottom: 1px solid black;
        }

        img {
            max-width: 100%;
            height: auto;
        }

        .page-break {
            page-break-after: always;
        }
    </style>
</head>
<body>
    <div class="document-container">
        {% if error %}
            <p style="color: red;">{{ error }}</p>
        {% endif %}

        <div>
            {{ rendered_html|safe }}
        </div>
    </div>
</body>
</html>
