/* ---------------------------------------------------------------
   PRINTABLE DOCUMENTS  (see static/export.js)

   The PDF is made by the browser's own print engine — there is no server and
   no PDF library. PrintDoc paints a document into #print-root and calls
   window.print(); everything below hides the app and shows that document only
   while printing. The screen never changes.

   Deliberately ignores the dark theme: this always prints black-on-white. A
   dark-mode PDF would waste a cartridge and read badly on paper.
   --------------------------------------------------------------- */

/* Off-screen while using the site. Not display:none — some browsers won't
   paginate a subtree that was never laid out. */
#print-root {
    position: absolute;
    left: -10000px;
    top: 0;
    width: 0;
    height: 0;
    overflow: hidden;
}

@media print {
    /* Hide the application shell entirely. */
    body > *:not(#print-root) { display: none !important; }

    #print-root {
        position: static;
        left: auto;
        width: auto;
        height: auto;
        overflow: visible;
        display: block;
    }

    @page { size: letter portrait; margin: 16mm; }
    :root[data-theme="dark"] #print-root { color: #000; }

    html, body {
        background: #fff !important;
        color: #000 !important;
        margin: 0;
        padding: 0;
    }

    .pd-sheet {
        font-family: Georgia, "Times New Roman", serif;
        color: #000;
        font-size: 11pt;
        line-height: 1.45;
        max-width: none;
    }

    /* ---- header ---- */
    .pd-head {
        border-bottom: 2px solid #000;
        padding-bottom: 6pt;
        margin-bottom: 12pt;
    }
    .pd-head h1 {
        font-size: 20pt;
        margin: 0;
        letter-spacing: 0.01em;
    }
    .pd-sub {
        margin: 2pt 0 0;
        font-size: 10.5pt;
        color: #333;
    }

    /* ---- rows of facts ---- */
    .pd-row {
        display: flex;
        gap: 10pt;
        padding: 2.5pt 0;
        border-bottom: 1px dotted #bbb;
        break-inside: avoid;
    }
    .pd-row-block { display: block; }
    .pd-label {
        flex: 0 0 78pt;
        font-weight: 700;
        font-size: 9.5pt;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: #444;
    }
    .pd-name { font-weight: 700; }
    .pd-years, .pd-place { color: #555; }
    .pd-place { font-style: italic; }

    /* A fact we do not have. Print a rule so it can be filled in by hand —
       these gaps are the research to-do list. */
    .pd-blank {
        color: #999;
        font-style: italic;
    }

    .pd-vitals { margin-bottom: 12pt; }
    .pd-parents { margin: 4pt 0 0; padding-left: 16pt; }

    /* ---- marriages ---- */
    .pd-marriage {
        margin: 10pt 0;
        padding: 8pt 10pt;
        border: 1px solid #999;
        break-inside: avoid;          /* never split a family across pages */
    }
    .pd-children {
        margin: 4pt 0 0;
        padding-left: 20pt;
    }
    .pd-children li { padding: 1pt 0; }

    /* ---- sources ---- */
    .pd-sourcebox {
        margin-top: 14pt;
        break-inside: avoid;
    }
    .pd-sourcebox h2 {
        font-size: 11pt;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        border-bottom: 1px solid #000;
        padding-bottom: 3pt;
        margin: 0 0 5pt;
    }
    .pd-sources { margin: 0; padding-left: 20pt; font-size: 10pt; }

    .pd-foot {
        margin-top: 18pt;
        padding-top: 5pt;
        border-top: 1px solid #ccc;
        font-size: 8.5pt;
        color: #666;
        text-align: right;
    }

    /* ---- pedigree chart (landscape) ----
       A named page is the only reliable way to change paper orientation for
       one document but not another — @page can't be toggled from a class. */
    .pd-landscape { page: pedigree; }

    .ped-chart {
        display: flex;
        align-items: stretch;
        gap: 10pt;
        width: 100%;
    }
    .ped-col {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        flex: 1 1 0;
        gap: 4pt;
    }
    .ped-slot {
        flex: 1 1 auto;
        display: flex;
        align-items: center;
    }
    .ped-box {
        width: 100%;
        border: 1px solid #333;
        border-left: 3px solid #333;
        padding: 3pt 5pt;
        font-size: 9pt;
        line-height: 1.25;
        break-inside: avoid;
    }
    .ped-empty {
        border-style: dashed;
        border-color: #bbb;
        border-left-color: #bbb;
    }
    .ped-name { display: block; font-weight: 700; }
    .ped-years { display: block; color: #555; font-size: 8pt; }

    /* Deeper generations get tighter — generation 4 is 8 boxes on one page. */
    .ped-col[data-gen="3"] .ped-box { font-size: 8.5pt; }
    .ped-col[data-gen="4"] .ped-box { font-size: 8pt; padding: 2pt 4pt; }
    .ped-col[data-gen="5"] .ped-box { font-size: 7pt; padding: 1.5pt 3pt; }
}

/* The pedigree wants the long edge of the paper; profile sheets stay portrait.
   `.pd-landscape { page: pedigree }` above opts the chart into this one. */
@page pedigree { size: letter landscape; margin: 12mm; }
