/* Default Markdown Styles (Github-like) */
.markdown-body {
    font-family: var(--font-body, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif);
    font-size: 11pt;
    line-height: 1.5;
    word-wrap: break-word;
    color: var(--text-color, #24292e);
}

.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    font-family: var(--font-heading, inherit);
}

.markdown-body h1:first-of-type {
    margin-top: 0;
}

.markdown-body p {
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body ul, .markdown-body ol {
    padding-left: 2em;
    margin-bottom: 16px;
}

.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(27,31,35,0.05);
    border-radius: 3px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

.markdown-body pre {
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: #f6f8fa;
    border-radius: 3px;
    margin-bottom: 16px;
}

.markdown-body pre code {
    background-color: transparent;
    padding: 0;
}

.markdown-body img {
    max-width: 100%;
    box-sizing: border-box;
}

.markdown-body table {
    display: table;
    width: 100%;
    max-width: 100%;
    border-spacing: 0;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.markdown-body table th,
.markdown-body table td {
    padding: 6px 13px;
    border: 1px solid #dfe2e5;
}

.markdown-body table tr:nth-child(2n) {
    background-color: #f6f8fa;
}

/* ================================================
   PAGED.JS PRINT STYLES
   ================================================ */

/* Running elements - these get "moved" into the margin boxes by Paged.js */
.print-logo {
    position: running(logo);
    max-height: 40px;
    width: auto;
}

.print-footer-left {
    position: running(footerLeft);
    font-size: 9pt;
    color: #666;
}

/* Page setup with margin boxes */
@page {
    size: A4;
    margin: 25mm 20mm 25mm 20mm;

    /* Logo in top-right on first page only - handled via @page:first */
    
    /* Footer left - company/confidential */
    @bottom-left {
        content: element(footerLeft);
        vertical-align: middle;
    }

    /* Footer right - page numbers */
    @bottom-right {
        content: "Page " counter(page) " of " counter(pages);
        font-size: 9pt;
        color: #666;
        vertical-align: middle;
    }
}

/* First page gets the logo */
@page:first {
    @top-right {
        content: element(logo);
        vertical-align: middle;
    }
}

/* Paged.js generated elements styling */
.pagedjs_page {
    background: white;
    margin-bottom: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* ================================================
   PAGE BREAK RULES
   ================================================ */

/* Headings should never be orphaned at the bottom of a page */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    break-after: avoid;      /* Don't break right after a heading */
    break-inside: avoid;     /* Don't break inside a heading */
    page-break-after: avoid; /* Legacy support */
}

/* Keep at least 2-3 lines together before/after breaks */
.markdown-body p,
.markdown-body li {
    orphans: 3;              /* Min lines at bottom of page */
    widows: 3;               /* Min lines at top of next page */
}

/* Don't break inside these elements */
.markdown-body pre,
.markdown-body blockquote,
.markdown-body table,
.markdown-body figure,
.markdown-body img {
    break-inside: avoid;
    page-break-inside: avoid; /* Legacy support */
}

/* Optional: Force major sections to start on new page */
/* Uncomment if you want h1s to always start a new page:
.markdown-body h1 {
    break-before: page;
}
*/

/* TOC Styles */
.toc {
    margin-bottom: 2em;
    padding: 1em;
    background: #f9fafb;
    border-radius: 4px;
}

.toc h2 {
    margin-top: 0;
    font-size: 1.2em;
}

.toc ul {
    list-style: none;
    padding-left: 0;
}

.toc ul ul {
    padding-left: 1.5em;
}

.toc li {
    margin: 0.5em 0;
}

.toc a {
    text-decoration: none;
    color: var(--primary-color, #1e3a8a);
}

.toc a:hover {
    text-decoration: underline;
}

/* Print-specific overrides */
@media print {
    /* Hide UI elements - buttons and editor */
    .app-header, .editor-pane, #return-btn, #print-btn {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .pagedjs_page {
        box-shadow: none;
        margin-bottom: 0;
    }
}

/* Screen preview styling for Paged.js output */
@media screen {
    #print-output {
        background: #e5e7eb;
        padding: 20px;
        min-height: 100vh;
    }
    
    .pagedjs_pages {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
}
