/* ==========================================================================
   Advoke CV — Print & PDF stylesheet
   Guarantees clean A4 / US Letter output, correct page breaks,
   no clipped content, no blank trailing pages.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. PAGE SETUP
   -------------------------------------------------------------------------- */
@page {
  size: A4;
  margin: 0;
}

@page :first {
  margin: 0;
}

@page letter {
  size: letter;
  margin: 0;
}

/* Paper class added by JS on <html> before printing */
html.paper-letter {
  --paper-w: 8.5in;
  --paper-h: 11in;
}

html.paper-a4 {
  --paper-w: 210mm;
  --paper-h: 297mm;
}

/* --------------------------------------------------------------------------
   2. GLOBAL PRINT RESET
   -------------------------------------------------------------------------- */
@media print {
  /* Hide interface chrome */
  .site-header,
  .site-footer,
  .editor-shell__header,
  .editor-shell__panel,
  .editor-tabbar,
  .export-bar,
  .preview-toolbar,
  .skip-link,
  .toast-region,
  .app-error-banner,
  .reading-progress,
  .mobile-drawer,
  .action-bar,
  .no-print,
  nav,
  [role="navigation"],
  [role="banner"],
  [role="contentinfo"] {
    display: none !important;
  }

  html,
  body {
    background: #fff !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    font-size: 10.5pt;
  }

  /* Remove layout that only serves the screen */
  .page,
  .editor-shell,
  .editor-shell__body,
  .editor-shell__preview,
  .preview-scaler {
    display: block !important;
    min-height: 0 !important;
    height: auto !important;
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
    transform: none !important;
    overflow: visible !important;
  }

  /* Remove shadows and rounded corners on paper */
  .preview-paper,
  .adv-resume {
    width: 100% !important;
    min-height: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    transform: none !important;
    margin: 0 !important;
  }

  /* Show only the resume root when printing from the editor */
  body.printing-resume > * {
    display: none !important;
  }

  body.printing-resume #print-root {
    display: block !important;
  }

  /* The print root itself must be edge-to-edge */
  #print-root {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    background: #fff;
  }

  /* --------------------------------------------------------------------------
     3. RESUME PRINT SURFACE
     -------------------------------------------------------------------------- */
  .adv-resume {
    --rs-line: 1.4;
    color: #000 !important;
    background: #fff !important;
    font-size: 10.5pt !important;
    line-height: 1.4 !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box !important;
  }

  /* Preserve accent colours (they were chosen by the user) */
  .adv-resume,
  .adv-resume * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* --------------------------------------------------------------------------
     4. PAGE BREAK CONTROL
     -------------------------------------------------------------------------- */

  /* Never split an entry across pages */
  .adv-entry,
  .adv-section,
  .adv-timeline > .adv-entry,
  .adv-bullets li,
  .adv-skills--chips span,
  .adv-pub-list li {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Keep section titles with at least their first entry */
  .adv-section__title {
    break-after: avoid;
    page-break-after: avoid;
  }

  /* Keep entry head with its body */
  .adv-entry__head {
    break-after: avoid;
    page-break-after: avoid;
  }

  /* Break before major sections when the section is long enough
     to need its own page (only as a fallback — browsers handle
     orphan control better on their own) */
  .adv-section--breakable {
    break-before: auto;
    page-break-before: auto;
  }

  /* Avoid orphaned single lines */
  .adv-bullets li:last-child,
  .adv-pub-list li:last-child {
    orphans: 2;
    widows: 2;
  }

  /* --------------------------------------------------------------------------
     5. MULTI-PAGE HANDLING
     -------------------------------------------------------------------------- */

  /* Browsers naturally paginate block-level content inside a page container.
     We only need to prevent a "blank last page" caused by a trailing margin. */
  .adv-resume > :last-child {
    margin-bottom: 0 !important;
  }

  .adv-resume > *:last-child > *:last-child {
    margin-bottom: 0 !important;
  }

  /* Remove the paper min-height in print so short resumes don't emit a second page */
  .preview-paper,
  .adv-resume {
    min-height: 0 !important;
  }

  /* --------------------------------------------------------------------------
     6. LINKS
     -------------------------------------------------------------------------- */
  .adv-resume a {
    color: inherit !important;
    text-decoration: none !important;
  }

  /* --------------------------------------------------------------------------
     7. HIDDEN HELPERS
     -------------------------------------------------------------------------- */
  [aria-hidden="true"],
  .sr-only,
  .visually-hidden {
    display: none !important;
  }

  /* --------------------------------------------------------------------------
     8. PAPER SIZE — Letter override
     -------------------------------------------------------------------------- */
  html.paper-letter .adv-resume {
    /* Letter-specific tweaks (slightly wider measure). The @page rule
       is set dynamically by the exporter; this keeps typography close. */
    --rs-line: 1.4;
  }
}

/* --------------------------------------------------------------------------
   9. SAFARI / WEBKIT PRINT QUIRKS
   -------------------------------------------------------------------------- */
@media print and (-webkit-min-device-pixel-ratio: 0) {
  .adv-resume {
    /* Safari prints slightly smaller than Chrome; nudge up */
    font-size: 11pt !important;
  }
}

/* --------------------------------------------------------------------------
   10. FIREFOX PRINT QUIRKS
   -------------------------------------------------------------------------- */
@-moz-document url-prefix() {
  @media print {
    .adv-resume {
      /* Firefox ignores some inline padding on first page */
      padding: 0 !important;
    }

    .adv-layout--sidebar .adv-sheet {
      /* Firefox sometimes drops the grid template in print */
      display: table !important;
      width: 100% !important;
      table-layout: fixed !important;
    }

    .adv-layout--sidebar .adv-aside,
    .adv-layout--sidebar .adv-main {
      display: table-cell !important;
      vertical-align: top !important;
    }

    .adv-layout--sidebar .adv-aside {
      width: 32% !important;
    }
  }
}

/* --------------------------------------------------------------------------
   11. FORCED-COLOURS (accessibility print)
   -------------------------------------------------------------------------- */
@media print and (forced-colors: active) {
  .adv-resume,
  .adv-resume * {
    color: CanvasText !important;
    background: Canvas !important;
    border-color: CanvasText !important;
  }
}