@media print {
    /* Basic Print Styles */
    /* For A4 with 0.82in margins on left/right: available width is 6.63in */
    /* But the first page has no margins (full bleed cover) */
    body {
        background-color: #fff !important;
        color: #000 !important;
        margin: 0;
        padding: 0;
        width: 100%;
    }

    .back-link {
        display: none !important;
    }

    /* Hide unnecessary elements */
    nav,
    footer,
    .no-print {
        display: none !important;
    }

    .sidebar-toc.no-print {
        display: none !important;
    }
    /* If the sidebar is removed, you might want the main content to use the full width */
    .main-layout {
        display: block; /* remove flex to allow normal flow */
    }
    .content-wrapper {
        /* Let it auto-size within page margins - don't force width */
    }

    /* Header for Every Page */
    @page {
        size: A4;

        /* Only top/bottom margins via @page - left/right handled by container padding */
        margin: 0.82in 0 1in 0;

        /* Top header */
        @top-center {
            /*content: "zkSecurity Audit Report";*/
            display: block; /* Make it a block so width & margin can take effect */
            width: 50%; /* Border and content only 50% of page width */
            margin: 0 auto; /* Center it horizontally */
            font-weight: bold;
            text-align: center;
            padding: 0;
            /* border-bottom: 1px solid #ccc;*/
            /*margin-bottom: 10px;*/
        }

        /* Removed excessive left/right margins that were causing content clipping
        @page :left {
            margin-left: 4in;
        }

        @page :right {
            margin-right: 4in;
        }
        */

        /* Bottom footer */
        @bottom-center {
            content: counter(page) " / " counter(pages);
            display: block;
            font-family: "Inter", sans-serif;
            font-size: 9pt;
            width: 50%;
            margin: 0 auto;
            color: rgba(0, 0, 0, 0.4);
            border-top: 1px solid rgba(0, 0, 0, 0.1);

            margin-top: 10px;
            margin-bottom: 30px;
            padding-top: 10px;
        }
    }

    @page :first {
        margin: 0;
        @top-center {
            content: "";
            border: 0;
        }
        @bottom-center {
            border: 0;
            content: "";
        }
    }

    /* Better table formatting */
    table {
        width: 100%;
        border-collapse: collapse;
        font-size: 10pt;
    }

    table th,
    table td {
        padding: 6px;
    }

    /* Prevent page breaks within table rows */
    table tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Also prevent breaking table cells */
    table td,
    table th {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Code block formatting */
    pre[class*="language-"],
    code[class*="language-"] {
        font-size: 10pt;
    }

    /* Prevent headings from being orphaned at the bottom of a page */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        break-after: avoid;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Also prevent widows and orphans in paragraphs */
    p {
        orphans: 3;
        widows: 3;
    }

    /* Prevent long URLs from breaking awkwardly */
    /* p a[href^="http"] {
        display: inline-block;
    } */

    p a[href^="http"] {
        word-break: break-all; /* Break long URLs */
        overflow-wrap: anywhere;
    }

    /* Disable justify on paragraphs to prevent stretched spacing before links */
    p {
        text-align: left;
    }

    /* Start each finding on a new page */
    .finding {
        page-break-before: always;
        break-before: page;
    }

    .cover-page {
        position: relative;
        width: 100%;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding: 2rem;
    }

    /* Full bleed cover page for print */
    .cover-page.new-cover {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        page-break-after: always;
        box-sizing: border-box;
    }

    .cover-page.new-cover .cover-inner {
        width: 100% !important;
        max-width: none !important;
        height: 100%;
        padding: 100px !important;
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
    }

    /* Remove the extra page break div for print */
    .cover-page.new-cover ~ div[style*="page-break-after"] {
        display: none !important;
    }

    /* Make canvas square for print */
    .cover-page.new-cover .canvas-wrapper {
        width: 100%;
        aspect-ratio: 1 / 1;
        height: auto !important;
        max-height: 100%;
        flex-shrink: 1;
    }

    /* Title on first page should stand out */
    .cover-title {
        font-size: 3rem;
        font-weight: bold;
        text-align: center;
    }

    .cover-content {
        text-align: center;
        margin-top: 2rem;
        margin-bottom: 2rem;
    }

    /* Ensure all pages have space around content */
    /* Left/right padding on container, top/bottom via @page margins */
    .container {
        margin: 0;
        padding: 0 1.2in !important; /* Only left/right padding */
        text-align: justify;
        width: 100%;
        box-sizing: border-box;
    }
}
