/*
 * WeasyPrint Print Compatibility Layer — Shared
 *
 * Loaded with media="print" in prototype HTML files. Applies only during PDF
 * rendering (WeasyPrint) and browser print dialogs; never affects browser
 * screen preview.
 *
 * Ownership contract
 * ------------------
 * - Page geometry, @page, A4 sizing, and the .page:not(:last-child) page-break
 *   contract are all owned by assets/common/css/master.css. Do not redefine
 *   them here.
 * - This file owns only WeasyPrint engine-specific overrides that cannot live
 *   in master.css without affecting browser screen rendering.
 * - Brand-local print overrides belong in
 *   assets/brands/<brand>/css/weasyprint.css, not here.
 *
 * Load order in prototype HTML files
 * ------------------------------------
 *  1. assets/common/css/master.css           (screen + print baseline)
 *  2. assets/brands/<brand>/css/theme.css    (brand screen theme)
 *  3. assets/common/css/weasyprint.css       ← this file (shared print compat)
 *  4. assets/brands/<brand>/css/weasyprint.css  (brand print compat, if present)
 *
 * Upcoming changes
 * ----------------
 * Phase 2 will add color-mix() fallbacks here. WeasyPrint stable does not
 * support CSS color-mix(), so declarations in master.css that rely on it need
 * explicit fallback values in this file for the PDF rendering path.
 */

@media print {
  /* Keep the screen grid shell out of the paged-media layout path. WeasyPrint's
     grid support is intentionally partial, and the full static report currently
     crashes during pagination when the outer .document wrapper remains a grid. */
  .document {
    display: block;
  }

  /* Override --accent-gradient to remove color-mix(), which WeasyPrint stable does not
     support. The gradient end stop uses --accent-gradient-end, a precomputed token
     defined in master.css :root (HBC aging default: #f2d4e9, i.e. 50% --report-accent-aging
     mixed with white). Brand themes override --accent-gradient-end for their own accent;
     BlueZones overrides are in assets/brands/bluezones/css/weasyprint.css (Phase 3). */
  :root {
    --accent-gradient: linear-gradient(
      90deg,
      var(--cover-accent, var(--report-accent-aging)) 0%,
      var(--accent-gradient-end) 100%
    );
  }

  /* Ensure the page background colour prints rather than being left transparent
     by WeasyPrint's default page-fill behaviour. */
  body {
    background: var(--paper);
  }

  /* --------------------------------------------------------------------------
     Shared print tokens
     Centralise the few alpha-tuned colours used across table borders, header
     backgrounds, and surface-lift borders so hard-coded rgba() values do not
     scatter across unrelated rules below.
     -------------------------------------------------------------------------- */
  :root {
    /* Table header tint: transparent avoids the grey-wash artefact WeasyPrint
       produces when alpha-compositing a semi-transparent fill over paged paper
       without the browser blending context. Visual row separation is preserved
       by the surrounding border rule. */
    --print-table-header-bg: transparent;

    /* Row and card borders inside interventions / results-overview tables. */
    --print-table-border: rgba(0, 32, 96, 0.1);

    /* Info-box surface-lift border: replaces the screen-only box-shadow that
       WeasyPrint ignores, so info-boxes remain visually separated from the page. */
    --print-surface-border: rgba(0, 32, 96, 0.12);
  }

  /* --------------------------------------------------------------------------
     Accent bars
     WeasyPrint can render the gradient but the color-mix()-based end-stop makes
     it unreliable in stable builds. Explicitly painting the solid accent colour
     here (rather than relying on background-color propagation from the parent)
     guarantees the bar is visible. The background shorthand also clears
     background-image in one declaration, so no extra rule is needed.
     -------------------------------------------------------------------------- */
  .section__accent-bar,
  .cover__accent-bar,
  .back__accent-bar {
    /* Explicitly set the solid accent so WeasyPrint does not inherit a stale
       or missing background-color from the parent element. */
    background: var(--cover-accent, var(--report-accent-aging));
  }

  /* --------------------------------------------------------------------------
     Epigenetic intro page (foreword) — bullet handling
     WeasyPrint ::before pseudo-element bullets can disappear or mis-position.
     Use native list markers instead and apply the accent colour via ::marker,
     which WeasyPrint supports reliably.
     -------------------------------------------------------------------------- */
  .page--section[data-page-id="foreword"] .epigenetic-intro__list {
    padding: 0 0 0 4.4mm;
    list-style: disc outside;
  }

  .page--section[data-page-id="foreword"] .epigenetic-intro__item {
    padding-left: 0;
  }

  .page--section[data-page-id="foreword"] .epigenetic-intro__item::before {
    content: none;
  }

  .page--section[data-page-id="foreword"] .epigenetic-intro__item::marker {
    color: var(--cover-accent, var(--report-accent-aging));
  }

  /* --------------------------------------------------------------------------
     Intro page — subsection title and personal-info row tightening
     WeasyPrint measures fonts slightly wider than Chromium. Without this
     override "Persönliche Informationen" and "Analysierte Parameter" both wrap
     to two lines, pushing content below the info-box boundary.
     -------------------------------------------------------------------------- */
  .page--section[data-page-id="intro"] .section__subsection-title {
    font-size: 4.4mm;
    line-height: 1;
    white-space: nowrap;
  }

  .page--section[data-page-id="intro"] .info-table__row {
    padding: 2.2mm 0;
  }

  /* --------------------------------------------------------------------------
     ASPA / LINE-1 / IL-6 / TNF-alpha marker pages — collision reduction
     These four pages carry extra above-fold content that pushes the result
     band and interpretation box down, causing the recommendations box to
     collide with the interpretation area in print. The fixes below pull the
     result band up and compress the gauge/interpretation boxes to fit.
     TNF-alpha (tnfa) is included here so its gauge-subtitle layout is
     consistent with the other methylation marker pages.
     -------------------------------------------------------------------------- */
  .page--section[data-page-id="aspa"] .marker__result-row,
  .page--section[data-page-id="line-1"] .marker__result-row,
  .page--section[data-page-id="il-6"] .marker__result-row,
  .page--section[data-page-id="tnfa"] .marker__result-row {
    top: 64.5mm;
  }

  .page--section[data-page-id="aspa"] .marker__gauge-box,
  .page--section[data-page-id="line-1"] .marker__gauge-box,
  .page--section[data-page-id="il-6"] .marker__gauge-box,
  .page--section[data-page-id="tnfa"] .marker__gauge-box,
  .page--section[data-page-id="aspa"] .marker__interpretation,
  .page--section[data-page-id="line-1"] .marker__interpretation,
  .page--section[data-page-id="il-6"] .marker__interpretation,
  .page--section[data-page-id="tnfa"] .marker__interpretation {
    height: 58mm;
    padding: 5.5mm 6mm;
  }

  .page--section[data-page-id="aspa"] .marker__gauge-box,
  .page--section[data-page-id="line-1"] .marker__gauge-box,
  .page--section[data-page-id="il-6"] .marker__gauge-box,
  .page--section[data-page-id="tnfa"] .marker__gauge-box {
    gap: 1.3mm;
  }

  /* Reserve a fixed two-line area for gauge titles so the subtitle never
     collides, regardless of whether the title wraps. Titles are free to wrap
     naturally (no white-space: nowrap). The min-height of 9.6mm equals
     2 lines × 4mm font-size × 1.2 line-height. */
  .page--section[data-page-id="aspa"] .marker__gauge-title,
  .page--section[data-page-id="line-1"] .marker__gauge-title,
  .page--section[data-page-id="il-6"] .marker__gauge-title,
  .page--section[data-page-id="tnfa"] .marker__gauge-title {
    font-size: 4mm;
    line-height: 1.2;
    min-height: 9.6mm;
  }

  .page--section[data-page-id="aspa"] .marker__gauge-subtitle,
  .page--section[data-page-id="line-1"] .marker__gauge-subtitle,
  .page--section[data-page-id="il-6"] .marker__gauge-subtitle,
  .page--section[data-page-id="tnfa"] .marker__gauge-subtitle {
    font-size: 2.55mm;
    line-height: 1.18;
  }

  .page--section[data-page-id="aspa"] .marker__interpretation,
  .page--section[data-page-id="line-1"] .marker__interpretation,
  .page--section[data-page-id="il-6"] .marker__interpretation,
  .page--section[data-page-id="tnfa"] .marker__interpretation {
    justify-content: flex-start;
  }

  .page--section[data-page-id="aspa"] .marker__interpretation-text,
  .page--section[data-page-id="line-1"] .marker__interpretation-text,
  .page--section[data-page-id="il-6"] .marker__interpretation-text,
  .page--section[data-page-id="tnfa"] .marker__interpretation-text {
    font-size: 3.7mm;
    line-height: 1.18;
  }

  .page--section[data-page-id="aspa"] .marker__recommendations,
  .page--section[data-page-id="line-1"] .marker__recommendations,
  .page--section[data-page-id="il-6"] .marker__recommendations,
  .page--section[data-page-id="tnfa"] .marker__recommendations {
    top: 136.5mm;
  }

  /* --------------------------------------------------------------------------
     Interventions / results-overview tables — border painting and hyphenation
     WeasyPrint paints borders inconsistently on overflow: hidden containers.
     Switching to visible overflow and explicit per-side borders avoids clipped
     separators. Hyphenation is disabled because WeasyPrint can produce broken
     glyphs in narrow table cells; overflow-wrap: anywhere handles long words
     without hyphen characters.
     -------------------------------------------------------------------------- */
  .section__info-box--interventions,
  .section__info-box--results-overview {
    overflow: visible;
  }

  .interventions__header,
  .results-overview__header {
    border: 0.35mm solid var(--print-table-border);
    /* Use background-color (not background shorthand) so the explicit token value
       reliably overrides any background-image set by master.css header rules. */
    background-color: var(--print-table-header-bg);
  }

  .interventions__card,
  .results-overview__row {
    margin-top: 0;
    border-top: none;
    border-left: 0.35mm solid var(--print-table-border);
    border-right: 0.35mm solid var(--print-table-border);
    border-bottom: 0.35mm solid var(--print-table-border);
  }

  /* The 4th results-overview row starts a new visual group; restore a heavier
     top border to preserve the section break that margin-top provided on screen. */
  .results-overview__row:nth-child(4) {
    margin-top: 1.2mm;
    border-top: 0.5mm solid rgba(0, 32, 96, 0.2);
  }

  .interventions__sources,
  .interventions__dose,
  .interventions__notes,
  .interventions__label,
  .results-overview__reference {
    hyphens: none;
    overflow-wrap: anywhere;
    word-break: normal;
  }

  /* --------------------------------------------------------------------------
     Info-box surface lift
     WeasyPrint ignores box-shadow, so info-boxes become indistinguishable from
     the page background. A thin border replaces the shadow to preserve the
     visual separation. Gauge boxes and chart boxes are excluded: they render
     inside an already-bordered info-box, and adding a second border produces an
     ugly double-frame.
     -------------------------------------------------------------------------- */
  .section__info-box:not(.section__info-box--interventions):not(
      .section__info-box--results-overview
    ):not(.section__info-box--chart) {
    border: 0.3mm solid var(--print-surface-border);
  }

  /* --------------------------------------------------------------------------
     Page shell print resets
     Remove screen-only decorative effects that WeasyPrint would otherwise apply
     to each page shell, producing unexpected grey halos or rounded corners in
     the PDF.
     -------------------------------------------------------------------------- */
  .page {
    border-radius: 0;
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
