/* ============================================================================
   EcoMender report documents — screen preview + clean A4 print.

   Scope: everything under .report-document (rendered by Shared/Reports/*).
   Colors and typography come from brand-tokens.css custom properties; the
   light values are re-declared locally on .report-document so app dark mode
   can never leak into a printout or its on-screen preview.
   ============================================================================ */

/* The report is laid out on A4 pages by Paged.js (scripts/report-paging.js, css/report-paged.css), each page box with
   the margins inside it: the printed sheet has none of its own. */
@page {
    size: A4 portrait;
    margin: 0;
}

.report-document {
    /* Reports are always light regardless of app theme. */
    --report-text: var(--color-neutral-dark, #333333);
    --report-text-secondary: var(--color-neutral-mid, #888888);
    --report-accent: var(--color-gold-base, #CDBC6B);
    --report-accent-light: var(--color-gold-lighter, #EEE8CC);
    --report-secondary: var(--color-teal-base, #73AFBA);
    --report-hairline: var(--color-neutral-light, #F2F2F2);
    --report-surface: #FFFFFF;

    font-family: var(--typography-fontFamily-body, 'DM Sans', sans-serif);
    font-size: 10pt;
    font-weight: 400;
    line-height: 1.45;
    color: var(--report-text);
    background: var(--report-surface);
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}

/* Neutralize app/bootstrap resets that would bleed into the document. */
.report-document table {
    border-collapse: collapse;
    width: 100%;
}

.report-document h1,
.report-document h2,
.report-document h3 {
    font-family: var(--typography-fontFamily-heading, 'Raleway', sans-serif);
    letter-spacing: var(--typography-letterSpacing-heading, -0.02em);
    color: var(--report-text);
    margin: 0;
}

.report-document h1 { font-size: 20pt; font-weight: 900; }
.report-document h2 { font-size: 13pt; font-weight: 700; }
.report-document h3 { font-size: 11pt; font-weight: 700; }

/* ---- Header / footer ------------------------------------------------------ */

.report-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12mm;
    padding-bottom: 4mm;
    border-bottom: 1.2mm solid var(--report-accent);
    margin-bottom: 6mm;
}

.report-header__logo img {
    height: 11mm;
    width: auto;
}

.report-header__meta {
    display: grid;
    grid-template-columns: auto auto;
    gap: 1mm 6mm;
    font-size: 8pt;
    color: var(--report-text-secondary);
}

.report-header__meta dt {
    font-weight: 500;
    color: var(--report-text);
}

.report-header__meta dd {
    margin: 0;
}

.report-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6mm;
    font-size: 7.5pt;
    color: var(--report-text-secondary);
    border-top: 0.3mm solid var(--report-hairline);
    padding-top: 2mm;
    margin-top: 8mm;
}

.report-footer img {
    height: 5mm;
    width: auto;
    opacity: 0.85;
}

/* ---- Sections ------------------------------------------------------------- */

.report-section {
    margin-bottom: 6mm;
}

.report-section > h2 {
    border-left: 1.4mm solid var(--report-accent);
    padding-left: 3mm;
    margin-bottom: 3mm;
}

/* ---- Key-value grid ------------------------------------------------------- */

.report-kv {
    display: grid;
    grid-template-columns: 42% 1fr;
    font-size: 9.5pt;
}

.report-kv > div {
    display: contents;
}

.report-kv dt,
.report-kv dd {
    padding: 1.1mm 2mm;
    margin: 0;
    border-bottom: 0.25mm solid var(--report-hairline);
}

.report-kv dt {
    color: var(--report-text-secondary);
}

.report-kv dd {
    font-weight: 500;
}

.report-kv .report-kv__unit {
    color: var(--report-text-secondary);
    font-weight: 400;
    margin-left: 1mm;
}

/* ---- Tables --------------------------------------------------------------- */

.report-table {
    font-size: 8.5pt;
}

.report-table caption {
    caption-side: top;
    text-align: left;
    font-family: var(--typography-fontFamily-heading, 'Raleway', sans-serif);
    font-size: 10pt;
    font-weight: 700;
    color: var(--report-text);
    padding-bottom: 1.5mm;
}

.report-table th {
    background: var(--report-accent-light);
    font-weight: 700;
    text-align: left;
    padding: 1.4mm 2mm;
    border-bottom: 0.4mm solid var(--report-accent);
}

.report-table td {
    padding: 1.1mm 2mm;
    border-bottom: 0.25mm solid var(--report-hairline);
    vertical-align: top;
}

.report-table th.num,
.report-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.report-table__unit {
    font-weight: 400;
    font-size: 7.5pt;
    color: var(--report-text-secondary);
}

.report-text {
    font-size: 9.5pt;
    margin: 0 0 2mm;
}

/* ---- Charts --------------------------------------------------------------- */

.report-chart {
    break-inside: avoid;
    margin: 2mm 0;
}

/* ---- Stamps (#267): the draft stamp and the trial stamp, one rotated column ---- */

.report-stamps {
    position: fixed;
    inset: 0;
    display: none;
    pointer-events: none;
    z-index: 10;
    align-items: center;
    justify-content: center;
}

.report-stamps__block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16mm;
    transform: rotate(-35deg);
}

.report-stamp {
    font-family: var(--typography-fontFamily-heading, 'Raleway', sans-serif);
    font-weight: 900;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.report-stamp--draft {
    font-size: 20pt;
    color: rgb(164 38 44 / 0.24);
}

.report-stamp--trial {
    font-size: 34pt;
    color: rgb(51 51 51 / 0.13);
}

.report-document--stamped .report-stamps {
    display: flex;
}

.report-trial-note {
    font-size: 7.5pt;
    color: #a4262c;
    margin-top: 1mm;
}

/* ---- Screen preview: simulate paper --------------------------------------- */

@media screen {
    .report-preview-surface {
        background: var(--color-neutral-lighter, #F7F7F7);
        padding: 24px 8px;
        overflow-y: auto;
    }

    .report-document {
        width: 210mm;
        min-height: 297mm;
        max-width: 100%;
        margin: 0 auto;
        padding: 18mm 16mm 20mm 16mm;
        box-shadow: 0 2px 12px rgb(0 0 0 / 0.15);
    }

    /* The stamps are fixed-position for print; contain them to the sheet on screen. */
    .report-document {
        position: relative;
    }

    .report-stamps {
        position: absolute;
    }
}

/* ---- Pages (Paged.js): the preview shows the printout's pages ------------- */

/* Blazor renders the reports here; a copy flows into the pages. Shown only if the layout failed. */
.report-paged__source {
    display: none;
}

.report-paged--failed .report-paged__source {
    display: block;
}

.report-paged .pagedjs_page {
    position: relative;
    background: #fff;
}

/* Inside a page the document is content only: the page box is the paper */
.report-paged__pages .report-document {
    width: auto;
    max-width: none;
    min-height: 0;
    margin: 0;
    padding: 0;
    box-shadow: none;
}

/* The stamps on every page, over the whole sheet */
.report-page-stamps {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 10;
}

/* The footer on every page, in the bottom margin, with the page number */
.report-page-footer {
    position: absolute;
    left: 16mm;
    right: 16mm;
    bottom: 8mm;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6mm;
    font-family: var(--typography-fontFamily-body, 'DM Sans', sans-serif);
    font-size: 7.5pt;
    color: var(--color-neutral-mid, #888888);
    border-top: 0.3mm solid var(--color-neutral-light, #F2F2F2);
    padding-top: 2mm;
}

.report-page-footer img {
    height: 5mm;
    width: auto;
    opacity: 0.85;
}

.report-page-footer__number {
    white-space: nowrap;
}

@media screen {
    .report-paged .pagedjs_pages {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 24px;
    }

    .report-paged .pagedjs_page {
        box-shadow: 0 2px 12px rgb(0 0 0 / 0.15);
    }
}

@media print {
    .report-paged .pagedjs_page {
        margin: 0;
        box-shadow: none;
        break-after: page;
    }

    .report-paged .pagedjs_page:last-child {
        break-after: auto;
    }
}

/* ---- Print ---------------------------------------------------------------- */

@media print {
    /* The print route renders on EmptyLayout; kill any remaining chrome. */
    body * {
        visibility: visible;
    }

    .report-preview-surface {
        padding: 0;
        overflow: visible;
    }

    .report-document {
        width: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .report-no-print {
        display: none !important;
    }

    .report-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin-top: 0;
        background: #fff;
    }

    /* Reserve room so flowing content never runs under the fixed footer. */
    .report-document {
        padding-bottom: 10mm;
    }

    .report-section {
        break-inside: avoid-page;
    }

    .report-section--flow {
        break-inside: auto;
    }

    .report-table thead {
        display: table-header-group;
    }

    .report-table tr,
    .report-kv dt,
    .report-kv dd {
        break-inside: avoid;
    }

    .report-document h2,
    .report-document h3 {
        break-after: avoid-page;
    }
}
