/* ============================================================
   Mirath: Document Styles (css/print.css)
   Owner: DOCUMENTS agent (BUILD-CONTRACT.md §Documents API)

   Two regimes for one markup:
   · On-screen preview: .legal-doc rendered as a sheet of paper
     inside the app, themed with css/tokens.css custom properties,
     with a screen-only DRAFT watermark and banner.
   · @media print: Letter size, 1in margins, Georgia/serif stack,
     near-black ink (var(--iron-gall), fallback #23201A, the token
     value, never pure black). Paper background is the paper itself;
     no background color is printed. The DRAFT watermark does not
     print: the running disclaimer line at the head of the document
     carries the draft status on paper instead.

   Article numbering: article numbers are written into the markup
   (legal documents must survive copy-paste with their numbering),
   and clause lists (.clauses) are styled ordered lists.
   ============================================================ */

/* ------------------------------------------------------------
   On-screen preview: the sheet
   ------------------------------------------------------------ */

.legal-doc {
  position: relative;
  max-width: 8.5in;
  margin: var(--space-6, 24px) auto;
  padding: var(--space-12, 48px);
  background: var(--color-surface);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 8px);
  box-shadow: var(--shadow-raised);
  font-family: Georgia, 'Times New Roman', 'EB Garamond', serif;
  font-size: 1rem;
  line-height: 1.65;
  overflow-wrap: break-word;
}

/* DRAFT watermark: screen preview only; removed in print below. */
.legal-doc::before {
  content: 'DRAFT';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18vmin;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--color-commit);
  opacity: 0.06;
  transform: rotate(-28deg);
  pointer-events: none;
  z-index: 0;
}

.legal-doc > * {
  position: relative;
  z-index: 1;
}

/* Screen-only draft banner. Colored with --color-error rather than
   --color-commit: wax-seal red stays reserved for the three sanctioned
   commitment moments, and the dark commit tone fails contrast on the
   lamplight preview surface. The quiet --color-bg chip keeps the text
   WCAG AA in both modes (light 7.4:1 on linen; dark 4.98:1 on walnut,
   since the raised lamplight paper alone would sit a hair under 4.5:1). */
.legal-doc .draft-banner {
  background: var(--color-bg);
  border: 1px solid var(--color-error);
  color: var(--color-error);
  border-radius: var(--radius-sm, 8px);
  padding: var(--space-3, 12px) var(--space-4, 16px);
  margin-bottom: var(--space-6, 24px);
  font-family: var(--font-sans, sans-serif);
  font-size: var(--text-footnote, 0.8125rem);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* Print-only running disclaimer line: hidden on screen */
.legal-doc .print-disclaimer-line {
  display: none;
}

/* AMJA-pending gate banner (trust): advisory register, scholar amber */
.legal-doc .gate-banner {
  border: 1px solid var(--color-scholar);
  border-left-width: 4px;
  color: var(--color-scholar);
  border-radius: var(--radius-sm, 8px);
  padding: var(--space-3, 12px) var(--space-4, 16px);
  margin-bottom: var(--space-6, 24px);
  font-family: var(--font-sans, sans-serif);
  font-size: var(--text-subhead, 0.9375rem);
}

/* ------------------------------------------------------------
   Document header
   ------------------------------------------------------------ */

.legal-doc .doc-header {
  text-align: center;
  margin-bottom: var(--space-8, 32px);
  padding-bottom: var(--space-4, 16px);
  border-bottom: 1px solid var(--color-border);
}

.legal-doc .doc-title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 var(--space-2, 8px);
  color: var(--color-text-primary);
}

.legal-doc .doc-subtitle {
  font-size: 1.0625rem;
  font-style: italic;
  margin: 0 0 var(--space-3, 12px);
  color: var(--color-text-secondary);
}

.legal-doc .doc-meta,
.legal-doc .madhab-label {
  font-size: var(--text-subhead, 0.9375rem);
  color: var(--color-text-secondary);
  margin: var(--space-1, 4px) 0;
}

.legal-doc .madhab-label {
  font-weight: 600;
  color: var(--color-text-primary);
}

/* Bismillah: the threshold. Arabic type, centered, once per suite. */
.legal-doc .bismillah {
  font-family: var(--font-arabic, serif);
  font-size: 1.75rem;
  text-align: center;
  margin: 0 0 var(--space-1, 4px);
  color: var(--color-arabic-ink, inherit);
}

.legal-doc .bismillah-translation {
  text-align: center;
  font-size: var(--text-footnote, 0.8125rem);
  font-style: italic;
  color: var(--color-text-secondary);
  margin: 0 0 var(--space-5, 20px);
}

/* ------------------------------------------------------------
   Articles and clauses
   ------------------------------------------------------------ */

.legal-doc .article {
  margin-bottom: var(--space-6, 24px);
}

.legal-doc .article-heading {
  font-size: 1.0625rem;
  font-weight: 700;
  font-variant: small-caps;
  letter-spacing: 0.05em;
  text-align: center;
  margin: var(--space-8, 32px) 0 var(--space-3, 12px);
  color: var(--color-text-primary);
}

.legal-doc p {
  margin: 0 0 var(--space-3, 12px);
  text-align: justify;
  hyphens: auto;
}

.legal-doc .preamble {
  text-indent: 0;
}

.legal-doc ol.clauses {
  margin: 0 0 var(--space-3, 12px);
  padding-left: var(--space-8, 32px);
}

.legal-doc ol.clauses > li {
  margin-bottom: var(--space-2, 8px);
  text-align: justify;
}

.legal-doc ol.choice-list {
  list-style: lower-alpha;
}

.legal-doc ul.family-list {
  margin: 0 0 var(--space-3, 12px);
  padding-left: var(--space-8, 32px);
  list-style: square;
}

.legal-doc ul.family-list > li {
  margin-bottom: var(--space-1, 4px);
}

.legal-doc .faraid-formula {
  border-left: 3px solid var(--color-accent);
  padding-left: var(--space-4, 16px);
  margin-left: 0;
}

/* ------------------------------------------------------------
   Ruled blanks and free-write lines: unfilled fields must be
   unmistakable; nothing silent survives into a signed document.
   ------------------------------------------------------------ */

.legal-doc .ruled-blank {
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--color-awl);
}

.legal-doc .filled-field {
  font-weight: 600;
}

.legal-doc .ruled-line {
  border-bottom: 1px solid var(--color-text-faint);
  height: 1.8em;
  margin: 0 0 var(--space-1, 4px);
}

/* ------------------------------------------------------------
   Tables: heir schedule, document locations, Schedule A
   ------------------------------------------------------------ */

.legal-doc table.heir-schedule {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-3, 12px) 0;
  font-size: var(--text-subhead, 0.9375rem);
}

.legal-doc table.heir-schedule th,
.legal-doc table.heir-schedule td {
  border: 1px solid var(--color-border);
  padding: var(--space-2, 8px) var(--space-3, 12px);
  text-align: left;
  vertical-align: top;
}

.legal-doc table.heir-schedule th {
  font-variant: small-caps;
  letter-spacing: 0.04em;
  font-weight: 700;
  background: var(--color-surface-raised);
}

.legal-doc table.heir-schedule td.share-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.legal-doc table.heir-schedule tr.rationale-row td {
  border-top: 0;
  font-size: var(--text-footnote, 0.8125rem);
  font-style: italic;
  color: var(--color-text-secondary);
}

.legal-doc .table-note {
  font-size: var(--text-footnote, 0.8125rem);
  color: var(--color-text-secondary);
  text-align: left;
}

.legal-doc .scholar-note {
  color: var(--color-scholar);
  border-left: 3px solid var(--color-scholar);
  padding-left: var(--space-3, 12px);
}

.legal-doc .trace-cite {
  font-size: var(--text-caption, 0.75rem);
  color: var(--color-text-faint);
}

/* ------------------------------------------------------------
   Disclosures and the Louisiana notice
   ------------------------------------------------------------ */

.legal-doc .disclosure-section {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 8px);
  padding: var(--space-4, 16px) var(--space-5, 20px);
  background: var(--color-surface-raised);
}

.legal-doc .la-notice {
  border: 1px solid var(--color-scholar);
  border-left-width: 4px;
  border-radius: var(--radius-sm, 8px);
  padding: var(--space-4, 16px) var(--space-5, 20px);
}

.legal-doc .la-advisory {
  font-weight: 700;
}

.legal-doc .execution-note {
  font-size: var(--text-footnote, 0.8125rem);
  font-style: italic;
  color: var(--color-text-secondary);
}

/* ------------------------------------------------------------
   Signature, witness, and notary blocks
   ------------------------------------------------------------ */

.legal-doc .signature-block {
  margin: var(--space-8, 32px) 0 var(--space-5, 20px);
  max-width: 28rem;
  break-inside: avoid;
  page-break-inside: avoid;
}

.legal-doc .sig-line {
  border-bottom: 1px solid var(--color-text-primary);
  height: 2.2em;
}

.legal-doc .sig-caption {
  font-size: var(--text-subhead, 0.9375rem);
  margin: var(--space-1, 4px) 0 0;
  text-align: left;
}

.legal-doc .witness-section {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6, 24px);
  margin: var(--space-5, 20px) 0;
}

.legal-doc .witness-block {
  flex: 1 1 16rem;
  min-width: 14rem;
  break-inside: avoid;
  page-break-inside: avoid;
}

.legal-doc .notary-block {
  margin: var(--space-6, 24px) 0;
  padding: var(--space-4, 16px) var(--space-5, 20px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 8px);
  max-width: 34rem;
  break-inside: avoid;
  page-break-inside: avoid;
}

.legal-doc .notary-venue {
  font-variant: small-caps;
  letter-spacing: 0.04em;
}

.legal-doc .notary-seal {
  font-size: var(--text-footnote, 0.8125rem);
  font-style: italic;
  color: var(--color-text-faint);
}

.legal-doc .execution-section,
.legal-doc .affidavit-section {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-5, 20px);
}

/* ------------------------------------------------------------
   UPL disclaimer block
   ------------------------------------------------------------ */

.legal-doc .upl-disclaimer {
  margin-top: var(--space-10, 40px);
  padding-top: var(--space-4, 16px);
  border-top: 2px solid var(--color-border);
  font-size: var(--text-footnote, 0.8125rem);
  color: var(--color-text-secondary);
}

.legal-doc .upl-disclaimer .article-heading {
  font-size: var(--text-subhead, 0.9375rem);
  margin-top: 0;
}

.legal-doc .upl-disclaimer .prepared-line {
  font-style: italic;
  text-align: center;
  color: var(--color-text-faint);
}

.legal-doc .methodology-footer p {
  font-size: var(--text-subhead, 0.9375rem);
  color: var(--color-text-secondary);
}

/* Narrow screens: the sheet keeps its margins honest */
@media (max-width: 700px) {
  .legal-doc {
    padding: var(--space-5, 20px);
  }
  .legal-doc::before {
    font-size: 26vmin;
  }
}

/* ------------------------------------------------------------
   Print: Letter, 1in margins, near-black token ink on paper.
   The watermark does not print; the disclaimer line does.
   ------------------------------------------------------------ */

@page {
  size: letter;
  margin: 1in;
}

@media print {
  /* App chrome never prints. View files place .legal-doc previews
     inside the document view; generic chrome selectors guard the rest. */
  nav,
  header.top-bar,
  .top-bar,
  .bottom-nav,
  .sidebar,
  .sheet,
  .scholar-banner,
  .progress-segments,
  .no-print {
    display: none;
  }

  .legal-doc {
    max-width: 100%;
    margin: 0;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    color: var(--iron-gall, #23201A);
    font-size: 11.5pt;
    line-height: 1.55;
  }

  /* Watermark is a screen affordance; on paper the disclaimer line
     speaks instead (a printed watermark invites re-printing). */
  .legal-doc::before {
    content: none;
  }

  .legal-doc .draft-banner {
    display: none;
  }

  .legal-doc .print-disclaimer-line {
    display: block;
    text-align: center;
    font-size: 8.5pt;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-bottom: 0.5pt solid var(--iron-gall, #23201A);
    padding-bottom: 4pt;
    margin-bottom: 14pt;
    color: var(--iron-gall, #23201A);
  }

  /* Ink discipline: every themed color resolves to printer ink. */
  .legal-doc .doc-title,
  .legal-doc .doc-subtitle,
  .legal-doc .doc-meta,
  .legal-doc .madhab-label,
  .legal-doc .article-heading,
  .legal-doc .bismillah,
  .legal-doc .bismillah-translation,
  .legal-doc .table-note,
  .legal-doc .execution-note,
  .legal-doc .sig-caption,
  .legal-doc .notary-seal,
  .legal-doc .trace-cite,
  .legal-doc .upl-disclaimer,
  .legal-doc .upl-disclaimer .prepared-line,
  .legal-doc .methodology-footer p,
  .legal-doc table.heir-schedule tr.rationale-row td,
  .legal-doc .ruled-blank,
  .legal-doc .gate-banner,
  .legal-doc .scholar-note,
  .legal-doc .la-notice,
  .legal-doc .draft-banner {
    color: var(--iron-gall, #23201A);
  }

  .legal-doc .gate-banner,
  .legal-doc .la-notice,
  .legal-doc .disclosure-section,
  .legal-doc .notary-block {
    border-color: var(--iron-gall, #23201A);
    background: none;
    border-radius: 0;
  }

  .legal-doc table.heir-schedule th,
  .legal-doc table.heir-schedule td {
    border-color: var(--iron-gall, #23201A);
  }

  .legal-doc table.heir-schedule th {
    background: none;
  }

  .legal-doc .sig-line,
  .legal-doc .ruled-line {
    border-color: var(--iron-gall, #23201A);
  }

  .legal-doc .faraid-formula,
  .legal-doc .scholar-note {
    border-color: var(--iron-gall, #23201A);
  }

  /* Page-break discipline */
  .legal-doc .article-heading {
    break-after: avoid;
    page-break-after: avoid;
  }

  .legal-doc .signature-block,
  .legal-doc .witness-block,
  .legal-doc .notary-block,
  .legal-doc .doc-header {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .legal-doc table.heir-schedule tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .legal-doc .execution-section {
    break-before: auto;
  }

  .legal-doc p,
  .legal-doc ol.clauses > li {
    orphans: 3;
    widows: 3;
  }
}
