/* Document Theme - Styling for document content rendering
   Provides consistent typography and spacing for rendered documents */

/* Base document typography */
.a4-page {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
                 Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    color: #1e293b;
    line-height: 1.75;
    font-size: 1rem;
}

/* Headings */
.a4-page h1 {
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    color: #0f172a;
    page-break-after: avoid;
}

.a4-page h2 {
    font-size: 1.875rem;
    font-weight: 600;
    line-height: 1.3;
    margin-top: 1.25em;
    margin-bottom: 0.625em;
    color: #1e293b;
    page-break-after: avoid;
}

.a4-page h3 {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.4;
    margin-top: 1em;
    margin-bottom: 0.5em;
    color: #334155;
    page-break-after: avoid;
}

.a4-page h4 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.5;
    margin-top: 0.875em;
    margin-bottom: 0.5em;
    color: #475569;
    page-break-after: avoid;
}

.a4-page h5 {
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.5;
    margin-top: 0.75em;
    margin-bottom: 0.5em;
    color: #64748b;
    page-break-after: avoid;
}

.a4-page h6 {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.5;
    margin-top: 0.625em;
    margin-bottom: 0.5em;
    color: #64748b;
    page-break-after: avoid;
}

/* Paragraphs */
.a4-page p {
    margin: 0.75em 0;
    orphans: 3;
    widows: 3;
    text-align: justify;
}

/* Lists */
.a4-page ul, .a4-page ol {
    margin: 0.75em 0;
    padding-left: 2em;
}

.a4-page li {
    margin: 0.25em 0;
    page-break-inside: avoid;
    orphans: 2;
    widows: 2;
}

.a4-page ul {
    list-style-type: disc;
}

.a4-page ol {
    list-style-type: decimal;
}

.a4-page ul ul, .a4-page ol ol, .a4-page ul ol, .a4-page ol ul {
    margin-top: 0.25em;
    margin-bottom: 0.25em;
}

/* Tables */
.a4-page table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    page-break-inside: auto;
}

.a4-page table th,
.a4-page table td,
.a4-page .rendered-table th,
.a4-page .rendered-table td,
.a4-page .tc-table th,
.a4-page .tc-table td,
.a4-page .tc-table .tc-row th,
.a4-page .tc-table .tc-row td,
.a4-page .tc-table .tc-cell {
    padding: 0.5em;
    border: 1px solid #e2e8f0;
    text-align: left;
    /* CRITICAL: Prevent vertical text rendering - ensure horizontal layout */
    writing-mode: horizontal-tb !important;
    text-orientation: mixed !important;
    white-space: normal !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    /* CRITICAL: Ensure cells have minimum width to prevent collapsing */
    min-width: 50px !important;
    width: auto !important;
    display: table-cell !important;
    vertical-align: top !important;
    direction: ltr !important;
    unicode-bidi: normal !important;
    transform: none !important;
}

.a4-page table th {
    background-color: #f8fafc;
    font-weight: 600;
}

.a4-page table tr {
    page-break-inside: avoid;
    page-break-after: auto;
}

.a4-page table thead {
    display: table-header-group;
}

.a4-page table tfoot {
    display: table-footer-group;
}

/* Images */
.a4-page img {
    max-width: 100%;
    height: auto;
    page-break-inside: avoid;
    margin: 1em 0;
    display: block;
}

/* Links */
.a4-page a {
    color: #3b82f6;
    text-decoration: underline;
}

.a4-page a:hover {
    color: #2563eb;
}

/* Code blocks */
.a4-page pre {
    background-color: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 1em;
    overflow-x: auto;
    page-break-inside: avoid;
    margin: 1em 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.875rem;
    line-height: 1.5;
}

.a4-page code {
    background-color: #f1f5f9;
    padding: 0.125em 0.25em;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.875em;
}

.a4-page pre code {
    background-color: transparent;
    padding: 0;
}

/* Blockquotes */
.a4-page blockquote {
    border-left: 4px solid #3b82f6;
    padding-left: 1em;
    margin: 1em 0;
    font-style: italic;
    color: #64748b;
    page-break-inside: avoid;
}

/* Horizontal rules */
.a4-page hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 2em 0;
    page-break-after: avoid;
}

/* Columns layout */
.a4-page .columns-layout {
    display: grid;
    gap: 20px;
    margin: 20px 0;
    page-break-inside: avoid;
}

.a4-page .columns-layout.two-columns {
    grid-template-columns: 1fr 1fr;
}

.a4-page .columns-layout.three-columns {
    grid-template-columns: 1fr 1fr 1fr;
}

.a4-page .columns-layout .column {
    min-width: 0;
    page-break-inside: avoid;
}

/* Page numbers and headers/footers */
.a4-page .document-header,
.a4-page .document-footer {
    width: 100%;
    padding: 0.5em 0;
    font-size: 0.875rem;
    color: #64748b;
}

.a4-page .document-header {
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 1em;
}

.a4-page .document-footer {
    border-top: 1px solid #e2e8f0;
    margin-top: 1em;
}

/* Print-specific adjustments */
@media print {
    .a4-page {
        font-size: 12pt;
    }
    
    .a4-page h1 {
        font-size: 18pt;
    }
    
    .a4-page h2 {
        font-size: 16pt;
    }
    
    .a4-page h3 {
        font-size: 14pt;
    }
    
    .a4-page h4 {
        font-size: 12pt;
    }
    
    .a4-page h5 {
        font-size: 11pt;
    }
    
    .a4-page h6 {
        font-size: 10pt;
    }
}
