﻿@media print {
  /*
   * Default @page margin is 0 so Home History matches on PC and mobile even when
   * named pages are ignored (common on some mobile WebKits). Post-cover inset is
   * owned by .home-history-print-after-cover (0.5in + box-decoration-break: clone)
   * so every page fragment matches for Default and None.
   * Named pages (home-history, qr-label, letter-sheet) still set their own margins.
   */
  @page {
    size: letter;
    margin: 0;
    @top-left { content: none; }
    @top-center { content: none; }
    @top-right { content: none; }
    @bottom-left { content: none; }
    @bottom-center { content: none; }
    @bottom-right { content: none; }
    marks: none;
  }

  /*
   * Zero @page margin so browser "Default" and "None" match.
   * Non-cover pages get inset from .home-history-print-after-cover; cover stays full-bleed.
   */
  @page home-history {
    size: letter;
    margin: 0;
    @top-left { content: none; }
    @top-center { content: none; }
    @top-right { content: none; }
    @bottom-left { content: none; }
    @bottom-center { content: none; }
    @bottom-right { content: none; }
    marks: none;
  }

  @page qr-label {
    size: 3in 2in;
    margin: 0;
  }

  @page letter-sheet {
    size: letter;
    margin: 0.25in;
  }

  html,
  body {
    width: 100%;
    height: auto;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #root,
  #root > div {
    background: white !important;
  }

  .print-hide {
    display: none !important;
  }

  /* QR: hide page chrome when a print wrapper is present */
  body > #root > div:has(.print-only-wrapper) > *:not(.print-only-wrapper),
  body > #root > div:has(.print-sheet-wrapper) > *:not(.print-sheet-wrapper) {
    display: none !important;
  }

  /* ------------------------------------------------------------------ */
  /* Home History Report                                                */
  /* ------------------------------------------------------------------ */

  header.sticky,
  header[class*="sticky"] {
    display: none !important;
  }

  body:has(#full-home-history-report) > #root > div {
    display: block !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
  }

  body:has(#full-home-history-report) main,
  body:has(#full-home-history-report) main > .max-w-5xl,
  body:has(#full-home-history-report) main > div.mx-auto {
    display: block !important;
    max-width: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
  }

  body:has(#full-home-history-report) main > div > div.mb-8 {
    display: none !important;
  }

  /* Site chrome must not appear in the PDF (Header already has print-hide) */
  body:has(#full-home-history-report) .site-footer-shell,
  body:has(#full-home-history-report) #app-nav-header {
    display: none !important;
  }

  /* Iframe print shell (report is body-only; also zeroes live-page wrappers) */
  .home-history-print-shell,
  .home-history-print-main {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
    width: 100% !important;
    background: white !important;
    min-height: 0 !important;
  }

  #full-home-history-report {
    page: home-history;
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    overflow: visible !important;
    position: relative !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Page 1: header + split cover as one full-bleed unit, then force a break */
  #full-home-history-report .home-history-print-page-cover {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    break-after: page !important;
    page-break-after: always !important;
  }

  #full-home-history-report * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Light mode for print */
  #full-home-history-report [class*="dark:bg-slate"],
  #full-home-history-report [class*="dark:bg-gray"],
  #full-home-history-report [class*="bg-slate-800"],
  #full-home-history-report [class*="bg-slate-900"] {
    background-color: white !important;
    color: #1e293b !important;
  }

  #full-home-history-report [class*="dark:text-slate-100"],
  #full-home-history-report [class*="dark:text-slate-200"],
  #full-home-history-report [class*="dark:text-slate-300"] {
    color: #1e293b !important;
  }

  #full-home-history-report [class*="dark:text-slate-400"],
  #full-home-history-report [class*="dark:text-slate-500"],
  #full-home-history-report [class*="dark:text-slate-600"] {
    color: #475569 !important;
  }

  #full-home-history-report [class*="dark:text-slate-700"] {
    color: #334155 !important;
  }

  #full-home-history-report [class*="dark:border-slate"] {
    border-color: #e2e8f0 !important;
  }

  #full-home-history-report [class*="bg-gradient-to-b"][class*="from-slate-50"],
  #full-home-history-report [class*="bg-slate-50"],
  #full-home-history-report [class*="bg-gray"] {
    background: white !important;
  }

  /* Header band — theme tokens (emerald/teal utilities → --wh-*; aurora remaps to blue) */
  #full-home-history-report > header,
  #full-home-history-report .home-history-print-page-cover > header {
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background: linear-gradient(
      to bottom right,
      var(--wh-brand-500),
      var(--wh-accent-600),
      var(--wh-accent-500)
    ) !important;
    color: white !important;
    break-inside: avoid;
    page-break-inside: avoid;
    page-break-after: avoid;
  }

  #full-home-history-report > header > div,
  #full-home-history-report .home-history-print-page-cover > header > div {
    padding: 0.35in 0.5in !important;
  }

  /* Header type — lock desktop sizes (mobile viewport would otherwise keep text-3xl / text-lg) */
  #full-home-history-report > header h1,
  #full-home-history-report .home-history-print-page-cover > header h1 {
    font-size: 1.5rem !important;
    line-height: 2rem !important;
  }

  #full-home-history-report > header h2,
  #full-home-history-report .home-history-print-page-cover > header h2 {
    font-size: 2.25rem !important;
    line-height: 2.5rem !important;
  }

  #full-home-history-report > header p,
  #full-home-history-report .home-history-print-page-cover > header p {
    font-size: 1.125rem !important;
    line-height: 1.75rem !important;
  }

  #full-home-history-report > header .flex.flex-wrap,
  #full-home-history-report .home-history-print-page-cover > header .flex.flex-wrap {
    gap: 1.5rem !important;
  }

  /*
   * Cover / body layout locks for print. Primary path is a 1024px print iframe
   * (so md: utilities match desktop); these rules still force geometry if print
   * runs against a narrow viewport.
   */

  /* Cover split — always 2-col like desktop (ignore mobile single-column grid) */
  #full-home-history-report > div.grid,
  #full-home-history-report .home-history-print-cover {
    display: grid !important;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr) !important;
    width: 100% !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  #full-home-history-report > div.grid > *,
  #full-home-history-report .home-history-print-cover > * {
    min-width: 0 !important;
    width: auto !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 0.35in 0.4in !important;
    /* If cover still spills, continued fragments keep the same top inset */
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
  }

  /*
   * Cover narrative — absolute sizes so mobile (text-sm) and desktop (text-base)
   * print identically.
   */
  #full-home-history-report > div.grid > div:first-child,
  #full-home-history-report .home-history-print-cover > div:first-child {
    font-size: 1rem !important;
  }

  #full-home-history-report > div.grid > div:first-child p,
  #full-home-history-report .home-history-print-cover > div:first-child p {
    font-size: 0.9rem !important;
    line-height: 1.45 !important;
  }

  #full-home-history-report > div.grid > div:first-child [class*="space-y"] > * + *,
  #full-home-history-report .home-history-print-cover > div:first-child [class*="space-y"] > * + * {
    margin-top: 0.7rem !important;
  }

  #full-home-history-report > div.grid > div:first-child .flex.items-start,
  #full-home-history-report .home-history-print-cover > div:first-child .flex.items-start {
    gap: 1rem !important;
  }

  #full-home-history-report > div.grid > div:first-child svg,
  #full-home-history-report .home-history-print-cover > div:first-child svg {
    width: 1.35rem !important;
    height: 1.35rem !important;
  }

  /*
   * Right cover column — theme accent gradient + compact print type
   * so the 2-col cover stays on page 1. Pin last-child and gradient classes.
   */
  #full-home-history-report > div.grid > div:last-child,
  #full-home-history-report .home-history-print-cover > div:last-child,
  #full-home-history-report > div.grid > div[class*="from-teal-600"],
  #full-home-history-report > div.grid > div[class*="bg-gradient-to-br"],
  #full-home-history-report .home-history-print-cover > div[class*="from-teal-600"],
  #full-home-history-report .home-history-print-cover > div[class*="bg-gradient-to-br"] {
    background: linear-gradient(
      to bottom right,
      var(--wh-accent-600),
      var(--wh-brand-500),
      var(--wh-accent-700)
    ) !important;
    color: white !important;
    font-size: 0.85em !important;
  }

  #full-home-history-report > div.grid > div:last-child h3,
  #full-home-history-report .home-history-print-cover > div:last-child h3,
  #full-home-history-report > div.grid > div[class*="from-teal-600"] h3,
  #full-home-history-report > div.grid > div[class*="bg-gradient-to-br"] h3,
  #full-home-history-report .home-history-print-cover > div[class*="from-teal-600"] h3,
  #full-home-history-report .home-history-print-cover > div[class*="bg-gradient-to-br"] h3 {
    font-size: 0.9em !important;
  }

  #full-home-history-report > div.grid > div:last-child p,
  #full-home-history-report .home-history-print-cover > div:last-child p,
  #full-home-history-report > div.grid > div[class*="from-teal-600"] p,
  #full-home-history-report > div.grid > div[class*="bg-gradient-to-br"] p,
  #full-home-history-report .home-history-print-cover > div[class*="from-teal-600"] p,
  #full-home-history-report .home-history-print-cover > div[class*="bg-gradient-to-br"] p {
    font-size: 0.85em !important;
  }

  #full-home-history-report .home-history-print-business-rule {
    display: block !important;
    width: auto !important;
    height: auto !important;
    margin: 1.5rem -0.4in 0 -0.4in !important;
    padding: 2.75rem 0 0 0 !important;
    border: none !important;
    border-top: 1px solid rgba(255, 255, 255, 0.35) !important;
    background: none !important;
    overflow: visible !important;
  }

  #full-home-history-report .home-history-print-business-card {
    width: 100% !important;
    margin-top: 0 !important;
    padding-top: 0 !important;
    border: none !important;
  }

  #full-home-history-report .home-history-print-business-card-paper {
    background: #ffffff !important;
    color: #1e293b !important;
    box-shadow: none !important;
    border: 0.5pt solid #d6d3d1 !important;
    border-radius: 2px !important;
    padding: 0 !important;
    min-height: 6.2rem !important;
    display: flex !important;
  }

  #full-home-history-report .home-history-print-business-mark-wrap {
    width: 32% !important;
    max-width: 32% !important;
    flex: 0 0 32% !important;
    flex-shrink: 0 !important;
    position: relative !important;
    align-self: stretch !important;
  }

  #full-home-history-report .home-history-print-business-copy {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: auto !important;
    max-width: none !important;
  }

  #full-home-history-report .home-history-print-business-copy p {
    color: inherit !important;
    width: 100% !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: unset !important;
    overflow-wrap: break-word !important;
    word-break: normal !important;
  }

  #full-home-history-report .home-history-print-business-card .home-history-print-business-mark {
    width: 100% !important;
    height: 100% !important;
    font-size: 0.85rem !important;
  }

  #full-home-history-report .home-history-print-business-card p {
    font-size: 0.72em !important;
    line-height: 1.25 !important;
  }

  /* Image gallery — same 2/3-col layout as desktop print */
  #full-home-history-report .grid.grid-cols-2 {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  #full-home-history-report .grid[class*="md:grid-cols-3"] {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  #full-home-history-report img {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  #full-home-history-report [style*="aspectRatio"] {
    aspect-ratio: 4/3 !important;
  }

  #full-home-history-report [class*="object-cover"] {
    object-fit: cover !important;
    width: 100% !important;
    height: 100% !important;
  }

  /* Section titles — keep with following content; lock print size */
  #full-home-history-report h2.font-lora {
    font-size: 1.25rem !important;
    line-height: 1.75rem !important;
  }

  #full-home-history-report .home-history-print-section-header {
    break-after: avoid !important;
    page-break-after: avoid !important;
  }

  #full-home-history-report footer {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  #full-home-history-report p {
    orphans: 3;
    widows: 3;
  }

  /* Sticky tax column must not pin during print on any device */
  #full-home-history-report [class*="sticky"] {
    position: static !important;
    top: auto !important;
  }

  /* Ownership / tax: always side-by-side like desktop print (mobile keeps flex-col on screen) */
  #full-home-history-report .home-history-print-ownership,
  #full-home-history-report [class*="print:flex"] {
    display: flex !important;
  }

  #full-home-history-report .home-history-print-ownership,
  #full-home-history-report [class*="print:flex-row"] {
    flex-direction: row !important;
    align-items: flex-start !important;
  }

  #full-home-history-report .home-history-print-ownership > *,
  #full-home-history-report [class*="print:w-1/2"] {
    flex: 1 1 50% !important;
    width: 50% !important;
    max-width: 50% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  #full-home-history-report [class*="print:pr-6"] {
    padding-right: 1.5rem !important;
  }

  #full-home-history-report [class*="print:pl-6"] {
    padding-left: 1.5rem !important;
  }

  #full-home-history-report .home-history-print-images .grid {
    max-width: 85% !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  /*
   * Single inset source for every sheet after the cover (Full Picture → footer).
   * @page margin stays 0 so printer Default and None match. box-decoration-break:
   * clone reapplies the same 0.5in padding on each page fragment — including
   * Inventory/footer continuations that previously lost inset under slice.
   * Children must not add their own print padding (would double).
   */
  #full-home-history-report .home-history-print-after-cover {
    box-sizing: border-box !important;
    width: 100% !important;
    padding: 0.5in !important;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
  }

  /* Full Picture — flows after cover; inset owned by after-cover */
  #full-home-history-report .home-history-print-images {
    box-sizing: border-box !important;
    padding: 0 !important;
  }

  /* Public records, tax, projects & assets — inset owned by after-cover */
  #full-home-history-report .home-history-report-body {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Ownership/Tax, Improvements — page break only; inset from after-cover clone */
  #full-home-history-report .home-history-print-section--new-page {
    break-before: page !important;
    page-break-before: always !important;
    padding-top: 0 !important;
  }

  /* Press-style left-rule entries — follow active data-color-theme (aurora → blue) */
  #full-home-history-report article[class*="border-l-4"] {
    border-left-width: 4px !important;
    border-left-style: solid !important;
    border-left-color: var(--wh-brand-600) !important;
    padding-left: 1.5rem !important;
    background: linear-gradient(
      to right,
      var(--wh-brand-50),
      var(--wh-accent-50)
    ) !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  #full-home-history-report [class*="print:border-l"] {
    border-left: 1px solid #e2e8f0 !important;
  }

  /* ------------------------------------------------------------------ */
  /* Single QR card (3×2 in)                                            */
  /* ------------------------------------------------------------------ */

  .print-only-wrapper {
    page: qr-label;
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex !important;
    justify-content: center;
    align-items: center;
    background-color: transparent !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .print-only-wrapper > div > *:not(#qr-card-to-print) {
    display: none !important;
  }

  #qr-card-to-print {
    width: 3in !important;
    height: 2in !important;
    box-sizing: border-box !important;
    border: none !important;
    box-shadow: none !important;
    color: #000000 !important;
    background-color: white !important;
    margin: 0 !important;
    display: flex !important;
    flex-direction: row !important;
    page-break-inside: avoid;
  }

  /* ------------------------------------------------------------------ */
  /* Bulk QR sheet                                                      */
  /* ------------------------------------------------------------------ */

  .print-sheet-wrapper {
    page: letter-sheet;
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block !important;
    background: white !important;
  }

  .print-sheet-wrapper > div > *:not(#qr-sheet-to-print) {
    display: none !important;
  }

  #qr-sheet-to-print {
    display: grid !important;
    grid-template-columns: repeat(2, 3in) !important;
    grid-auto-rows: 2in !important;
    column-gap: 0.8in !important;
    row-gap: 0.333in !important;
    width: auto !important;
    height: auto !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    margin: auto !important;
    padding: 0.5in !important;
  }

  .bulk-qr-card {
    width: 3in !important;
    height: 2in !important;
    box-sizing: border-box !important;
    border: 1px solid #e5e7eb !important;
    overflow: hidden;
    display: flex !important;
    flex-direction: row !important;
    background-color: white !important;
    page-break-inside: avoid;
    color: #000000 !important;
  }

  /* ------------------------------------------------------------------ */
  /* Builder pitch deck                                                 */
  /* ------------------------------------------------------------------ */

  body:has(#builder-pitch-print) {
    background: white !important;
  }

  body:has(#builder-pitch-print) > #root > div {
    display: block !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
  }

  @page pitch-deck {
    size: 11in 8.5in;
    margin: 0;
    @top-left { content: none; }
    @top-center { content: none; }
    @top-right { content: none; }
    @bottom-left { content: none; }
    @bottom-center { content: none; }
    @bottom-right { content: none; }
    marks: none;
  }

  #builder-pitch-print {
    page: pitch-deck;
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
    box-shadow: none !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #builder-pitch-print .pitch-slide-body {
    transform: none !important;
    width: 100% !important;
  }

  #builder-pitch-print .pitch-close-body {
    display: grid !important;
    grid-template-columns: 1.1fr 0.9fr !important;
    grid-template-rows: none !important;
    height: auto !important;
  }

  #builder-pitch-print .pitch-close-copy,
  #builder-pitch-print .pitch-close-founders,
  #builder-pitch-print .pitch-close-founders-list {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  #builder-pitch-print .pitch-slide-frame {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    min-height: 8.5in !important;
    height: 8.5in !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: white !important;
    transform: none !important;
    break-after: page !important;
    page-break-after: always !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  #builder-pitch-print .pitch-slide-frame:last-child {
    break-after: auto !important;
    page-break-after: auto !important;
  }

  #builder-pitch-print .pitch-slide-frame > .pitch-slide,
  #builder-pitch-print .pitch-slide {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    min-height: 8.5in !important;
    height: 100% !important;
  }

  #builder-pitch-print .pitch-blueprint-layer,
  #builder-pitch-print .pitch-caret,
  #builder-pitch-print .pitch-cycle-arrow,
  #builder-pitch-print .pitch-cycle-heart,
  #builder-pitch-print iframe {
    display: none !important;
  }

  #builder-pitch-print .pitch-lifecycle-body {
    justify-content: center !important;
  }

  #builder-pitch-print .pitch-lifecycle {
    display: grid !important;
    flex: 0 1 auto !important;
    grid-template-columns: 1fr 1fr 1fr !important;
    grid-template-rows: none !important;
    grid-template-areas: none !important;
    align-content: start !important;
    gap: 0.75rem !important;
    margin-top: 1.25rem !important;
  }

  #builder-pitch-print .pitch-cycle-s1,
  #builder-pitch-print .pitch-cycle-s2,
  #builder-pitch-print .pitch-cycle-s3,
  #builder-pitch-print .pitch-cycle-s4,
  #builder-pitch-print .pitch-cycle-s5,
  #builder-pitch-print .pitch-cycle-s6 {
    grid-area: auto !important;
  }

  #builder-pitch-print .pitch-cycle-card,
  #builder-pitch-print .pitch-cycle-card.is-active {
    height: auto !important;
    min-height: 0 !important;
    padding: 1rem !important;
    transform: none !important;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05) !important;
    border-color: #e2e8f0 !important;
    background: #fff !important;
    animation: none !important;
  }

  #builder-pitch-print .pitch-cycle-head {
    margin-bottom: 0.5rem !important;
    gap: 0.625rem !important;
  }

  #builder-pitch-print .pitch-cycle-step {
    font-size: 10px !important;
    letter-spacing: 0.16em !important;
  }

  #builder-pitch-print .pitch-cycle-icon {
    width: 1.75rem !important;
    height: 1.75rem !important;
    background: transparent !important;
  }

  #builder-pitch-print .pitch-cycle-icon svg {
    width: 1.75rem !important;
    height: 1.75rem !important;
    color: #059669 !important;
  }

  #builder-pitch-print .pitch-cycle-card h3 {
    font-size: 1.125rem !important;
    line-height: 1.25 !important;
    color: #0f172a !important;
  }

  #builder-pitch-print .pitch-cycle-card > p {
    font-size: 0.95rem !important;
    line-height: 1.625 !important;
    color: #475569 !important;
  }

  #builder-pitch-print * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
