/* public/css/documents/living-will.css — the Living Will: A4 portrait, THREE fixed pages, no letterhead (the
   living will is a service, not the clinic's document — nothing on it names the clinic). A typed legal form in
   9 pt Sarabun: numbered Part headings, justified clauses, dotted blanks that fill their row (label + value never
   wrap apart), tick boxes for the options, two ruled tables whose right-hand cells are SIGNED (Part 4: one
   signature line per condition; Part 6: a Yes line over a No line in a narrow column, so a row is as tall as its
   text), ruled "please specify" blanks (the value over a clipped stack of real dotted rules), the execution blocks
   in a grid (patient | physician, the decision-makers side by side, witness | witness | notary) and the notes in
   small type.
   Pages: each <section class="pg" data-page> is one printed page — `break-before: page` between them (verified
   inside the table skeleton, docs/superpowers/research/print-technique-test/D-forced-breaks.html) and a
   [data-stretch] spacer at the end of each (page 3: before the execution blocks) that editor.js fitPage() grows to
   --page-body, so the screen shows three page-tall sheets and the print never spills. The budget (2026-10-31,
   headless Chrome): page 1 = Parts 1–4, page 2 = Parts 5–8, page 3 = Parts 9–12 + the execution blocks + notes.
   Print: the fixed footer (title · the declarant's initials · the print stamp) repeats on every page; the
   thead/tfoot spacer rows of table.doc-pages reserve the top margin and the footer band. */

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

.living-will { font-family: 'Sarabun', sans-serif; color: #111; font-size: 9pt; line-height: 1.2;
  --page-body: 274mm;  /* A4 297mm minus the 10mm top band and the 10mm footer band, less 3mm: every page ends in a stretched spacer, and print metrics run a hair taller than the screen */
  --pitch: 1.6em;      /* a ruled line of a "please specify" blank (5mm): room to write by hand */
  --rule-lift: .3em; } /* a rule sits this far above the bottom of its line, just under the descenders */
.living-will .doc-body { font-size: 1em; padding: 0; } /* the pages are budgeted at 100 %: the shell's text-size preference does not apply here */
.sheet:has(> .living-will) { padding-left: 12mm; padding-right: 12mm; } /* 12mm side margins (the shell's sheet gives 14mm): three dense pages need the width */

/* ---- footer (a fixed band in print) ---- */
.doc-footer { height: 8mm; display: flex; justify-content: space-between; align-items: flex-end; gap: 4mm; border-top: 1px solid #999; padding: 1mm 0 2mm; box-sizing: border-box; font-size: 6.5pt; color: #444; }
.ft-doc { font-weight: 700; letter-spacing: .3px; color: #222; }
.ft-of { font-weight: 400; letter-spacing: 0; }
.ft-of:has(> .mir:empty) { display: none; } /* no declarant yet (the blank form): just the title */
.ft-init { display: inline-flex; align-items: flex-end; gap: 1.5mm; }
.init-line { display: inline-block; width: 24mm; height: 4.5mm; border-bottom: 1px dotted #555; }

/* ---- pages ---- */
.pg { position: relative; }
.pg + .pg { margin-top: 12mm; }
@media screen { /* a page divider between the three sheets */
  .pg + .pg::before { content: 'page break'; position: absolute; left: 0; right: 0; top: -6.5mm; border-top: 1px dashed #94a3b8; font-size: 7pt; line-height: 1.6; color: #94a3b8; text-align: right; pointer-events: none; }
  .pg.is-over::after { content: 'This page is too full — it would print on an extra sheet. Shorten or remove something above.'; display: block; margin-top: 2mm; padding: 1.5mm 3mm; border: 1px dashed #dc2626; color: #b91c1c; font-size: 8pt; line-height: 1.3; } /* editor.js fitPage flags a [data-page] whose content exceeds --page-body */
}
.run { display: flex; justify-content: space-between; align-items: baseline; gap: 4mm; font-size: 7.5pt; color: #555; margin: 0 0 1.2mm; line-height: 1.2; }
.run-title { font-weight: 600; letter-spacing: .3px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-of:has(> .mir:empty) { display: none; }
.run-page { flex: 0 0 auto; }
.spacer { height: 0; } /* the leftover page height goes here (editor.js fitPage) */

/* ---- title block (page 1) ---- */
.title-block { text-align: center; margin: 0 0 2mm; }
.title { margin: 0; font-size: 2em; font-weight: 700; letter-spacing: 2px; line-height: 1.25; }
.subtitle { font-style: italic; font-size: .95em; color: #222; }
.exec-line { margin-bottom: .8mm; }

/* ---- Part headings and clauses ---- */
.part { margin: 0 0 .9mm; }
.ph { margin: 1.3mm 0 .4mm; font-size: 1.1em; font-weight: 700; line-height: 1.25; letter-spacing: .2px; }
.ph .pn { display: inline-block; min-width: 15mm; margin-right: 1.5mm; }
.ph .hint { font-weight: 400; font-size: .88em; letter-spacing: 0; }
.para { margin: .4mm 0; text-align: justify; }
.para .v { padding: 0 .6mm; } /* a blank inside a sentence sits tight against the comma after it */
.clause { padding-left: 8.5mm; text-indent: -8.5mm; }
.clause .cn { display: inline-block; width: 8.5mm; text-indent: 0; }
.mir:empty { display: inline-block; min-width: 40mm; border-bottom: 1px dotted #777; vertical-align: baseline; } /* no name yet: a blank to write it on */

/* ---- blanks: a dotted value that fills its row; a label and its value never wrap apart ---- */
.lb { white-space: nowrap; }
.v { display: inline-block; border-bottom: 1px dotted #555; min-height: 1.25em; padding: 0 1.5mm; min-width: 12mm; white-space: pre-wrap; overflow-wrap: anywhere; vertical-align: baseline; box-sizing: border-box; }
.ln { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 3mm; margin: .6mm 0; }
.ln .v { min-height: 1.4em; } /* a field line is a little taller than a text line: room to write on the blank form */
.f-inline { display: inline-flex; align-items: baseline; gap: 1.5mm; min-width: 0; max-width: 100%; flex-wrap: nowrap; }
.grow { flex: 1 1 30mm; min-width: 0; }
.v-date { min-width: 26mm; text-align: center; }
.v-cn { min-width: 24mm; text-align: center; }
.v-name { min-width: 40mm; }
.v-lic { min-width: 18mm; text-align: center; }
.ct.ln { display: inline-flex; flex: 1 1 auto; margin: 0; }

/* tick boxes */
.opt { display: inline-flex; align-items: center; gap: 1.2mm; margin-right: 1.5mm; white-space: nowrap; }
.cb { display: inline-block; width: 3.4mm; height: 3.4mm; border: 1px solid #333; box-sizing: border-box; position: relative; background: #fff; flex: 0 0 auto; }
.cb.on::after { content: ''; position: absolute; left: 1mm; top: -.4mm; width: 1mm; height: 2.3mm; border: solid #111; border-width: 0 1.6px 1.6px 0; transform: rotate(40deg); }
.choice { display: flex; align-items: flex-start; gap: 1.5mm; margin: .4mm 0; }
.choice > .opt { margin: .12em 0 0; flex: 0 0 auto; }
.choice:has(.spec) > .opt { margin-top: .3em; } /* beside a ruled "please specify" line, whose label sits on a taller line */
.choice > .ct { flex: 1 1 auto; min-width: 0; text-align: justify; }
.wish { margin: .5mm 0; }
.wish .opt { margin-left: 1mm; }

/* a "please specify" blank: the label floats at the start of the first rule, the answer's lines run on the rules */
.spec { position: relative; display: block; min-width: 0; }
.spec > .v { display: block; min-height: var(--pitch); line-height: var(--pitch); padding: 0 .5em; border-bottom: 0; min-width: 0; }
.spec > .fl { float: left; position: relative; z-index: 2; padding-right: .8em; background: #fff; line-height: var(--pitch); }
.rules { position: absolute; z-index: 1; left: 0; right: 0; top: calc(var(--rule-lift) * -1); bottom: 0; overflow: hidden; pointer-events: none; }
.rules > i { display: block; box-sizing: border-box; height: var(--pitch); border-bottom: 1px dotted #555; }

/* ---- the two signed tables: ruled rows, the signature cell(s) on the right ---- */
.tbl { border: 1px solid #333; margin: .8mm 0 .6mm; }
.trow { display: flex; border-top: 1px solid #333; }
.trow:first-child { border-top: 0; }
.trow.th { background: #eeeeee; font-weight: 700; }
.tx { flex: 1 1 auto; min-width: 0; padding: .5mm 1.6mm; text-align: justify; }
.th .tx { text-align: center; padding: .4mm 1.6mm; }
.th .sc, .th .th-sig { justify-content: center; align-items: center; padding-top: .4mm; padding-bottom: .4mm; }
.sig-line { display: inline-block; border-bottom: 1px dotted #555; }
.sc { flex: 0 0 30mm; border-left: 1px solid #333; display: flex; align-items: flex-end; justify-content: center; padding: .7mm 2mm; }
.sc .sig-line { flex: 1 1 auto; height: 5.5mm; }
.yn { flex: 0 0 30mm; border-left: 1px solid #333; display: flex; flex-direction: column; justify-content: flex-end; padding: .3mm 1.5mm .5mm; } /* Yes over No: a row is as tall as its text */
.yn > span { display: flex; align-items: flex-end; gap: 1.2mm; }
.yn > span + span { margin-top: .3mm; }
.yn .lb { font-weight: 700; min-width: 5.5mm; }
.yn .sig-line { flex: 1 1 auto; height: 3.9mm; min-width: 0; } /* two of these stack inside two text lines: the row stays as tall as its text */
.yn.th-sig { display: flex; flex-direction: row; }
.tx .spec { margin-top: .15em; }

/* ---- Part 8: the two decision-makers side by side ---- */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 6mm; }
.sdm { min-width: 0; }
.sdm h3 { margin: .6mm 0 0; font-size: 1em; font-weight: 700; }
.sdm h3 .sub { font-weight: 400; font-size: .9em; }
.sdm .ln { margin: .4mm 0; }
.sdm .ln .v { min-height: 1.3em; } /* the decision-makers' ten blanks: a notch tighter than Part 1 — page 2 is the full one */

/* ---- the execution blocks ---- */
.exec { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1.5mm 5mm; margin-top: 1.2mm; }
.sigblock { grid-column: span 3; min-width: 0; }
.sigblock.wide { grid-column: span 6; }
.sigblock.third { grid-column: span 2; }
.sigblock h3 { margin: 0 0 .3mm; font-size: 1em; font-weight: 700; text-align: center; letter-spacing: .4px; }
.sigblock h3 .sub { display: block; font-weight: 400; font-size: .85em; letter-spacing: 0; }
.sigblock .para { margin: .3mm 0; }
.sigblock[data-block="physician-declaration"] .para { text-align: left; } /* the inline name and licence blanks would stretch a justified line */
.sigline { display: flex; align-items: flex-end; gap: 2mm; margin-top: 1.2mm; }
.sigline .lb { line-height: 1.2; }
.sigline .sig-line { flex: 1 1 24mm; min-width: 18mm; height: 7.5mm; }
.sigline .v { align-self: flex-end; }
.under { text-align: center; margin: .3mm 0 0; }
.under .role { font-size: .85em; color: #333; margin-left: 1mm; }
.sigblock .ln { margin: .6mm 0 0; }
/* the patient and physician declarations sit side by side: both signature lines at the bottom of the row, aligned */
.sigblock[data-block="patient-declaration"], .sigblock[data-block="physician-declaration"] { display: flex; flex-direction: column; }
.sigblock[data-block="patient-declaration"] .sigline, .sigblock[data-block="physician-declaration"] .sigline { margin-top: auto; padding-top: 1.2mm; }
.sigblock.third .sigline { margin-top: .8mm; }

/* ---- notes ---- */
.notes { margin-top: 1.8mm; font-size: 7.2pt; line-height: 1.25; border-top: 1px solid #999; padding-top: .8mm; }
.notes h3 { margin: 0 0 .2mm; font-size: 1em; font-weight: 700; }
.notes ol { margin: 0; padding-left: 4mm; }
.notes li { margin: 0; padding-left: .5mm; }

/* screen-only helpers used by editor.js */
@media screen {
  .opt { cursor: pointer; user-select: none; }
  .opt:hover .cb { box-shadow: 0 0 0 1.5px #93c5fd; }
}
.empty { font-size: 9pt; color: #6b7280; padding: .4mm 0; display: flex; gap: 3mm; align-items: center; width: 100%; }
.notice.error { color: #b91c1c; font-size: 8pt; }

/* page skeleton: on screen the table is invisible plumbing; in print its thead/tfoot rows repeat on every page */
.doc-pages { width: 100%; border-collapse: collapse; }
.doc-pages > thead > tr > td, .doc-pages > tfoot > tr > td, .doc-pages > tbody > tr > td { padding: 0; vertical-align: top; }
.band { height: 0; }

/* ---------------- print ---------------- */
@media print {
  .doc-footer { position: fixed; bottom: 0; left: 12mm; right: 12mm; height: 8mm; background: #fff; }
  .band-top { height: 10mm; }      /* the top margin — repeated by <thead> on every page */
  .band-bottom { height: 10mm; }   /* 8mm footer + 2mm gap — repeated by <tfoot> on every page */
  .pg + .pg { margin-top: 0; break-before: page; page-break-before: always; }
  .run, .ph, .ln, .choice, .wish, .trow, .sdm, .sigblock, .notes { break-inside: avoid; page-break-inside: avoid; }
  .ph { break-after: avoid; page-break-after: avoid; }
  .v, .rules > i, .sig-line, .init-line { border-bottom-color: #444; }
  .empty, .notice { display: none !important; }
}
