/* Shared print + preview system for every report and Emergency Mode.
   - On screen the reports show as an A4 "paper" preview with a branded header and footer.
   - On paper / Save-as-PDF every page gets a running header and footer with page numbers (Chrome and Edge 131+ use
     @page margin boxes; other browsers still print the in-page header and footer block). */

@page{
  size:A4;
  margin:21mm 14mm 19mm;
  @top-left{content:"Family Financial Map";font:700 8pt/1 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:#245d89;vertical-align:bottom;padding-bottom:2.2mm;border-bottom:.6pt solid #b9c6d6}
  @top-right{content:var(--ffm-print-title,"");font:8pt/1 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:#4d5c6e;vertical-align:bottom;padding-bottom:2.2mm;border-bottom:.6pt solid #b9c6d6}
  @bottom-left{width:42%;content:"CONFIDENTIAL \00B7  not encrypted \00B7  " var(--ffm-print-family,"") ;font:7.5pt/1 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:#4d5c6e;vertical-align:top;padding-top:2.4mm;border-top:.6pt solid #b9c6d6}
  @bottom-center{width:34%;content:var(--ffm-print-stamp,"");font:7.5pt/1 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:#4d5c6e;vertical-align:top;padding-top:2.4mm;border-top:.6pt solid #b9c6d6}
  @bottom-right{content:"Page " counter(page) " of " counter(pages);font:600 7.5pt/1 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:#4d5c6e;vertical-align:top;padding-top:2.4mm;border-top:.6pt solid #b9c6d6}
}

/* Page 1 carries the full branded header inside the document, so the running header starts on page 2. */
@page :first{
  margin-top:14mm;
  @top-left{content:none;border:0}
  @top-right{content:none;border:0}
}

/* ---------- Report pages: on-screen paper preview ---------- */
.print-confidential{display:none}
@media screen{
  body.report-page{background:#e9eef4!important;padding:0 0 2rem!important;max-width:none!important;margin:0!important;font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:#17283c}
  body.report-page .no-print{position:sticky;top:0;z-index:20;margin:0!important;padding:.6rem max(1rem,calc((100% - 210mm)/2));background:rgba(255,255,255,.97);border-bottom:1px solid #d9e2ec;box-shadow:0 2px 10px rgba(25,51,75,.06);backdrop-filter:blur(8px)}
  .report-sheet{width:min(210mm,calc(100% - 1.5rem));min-height:297mm;margin:1.1rem auto 0;background:#fff;padding:14mm 14mm 10mm;box-shadow:0 1px 3px rgba(20,40,70,.12),0 12px 34px rgba(20,40,70,.12);border-radius:3px;box-sizing:border-box;display:flex;flex-direction:column}
  .report-sheet>.report-body{flex:1 1 auto}
  .report-hint{width:min(210mm,calc(100% - 1.5rem));margin:.6rem auto 0;font-size:.78rem;color:#5a6c80;text-align:center}
}
.report-head{display:flex;align-items:center;gap:.8rem;padding-bottom:.55rem;margin-bottom:.9rem;border-bottom:2.5px solid #245d89}
.report-head img{width:38px;height:38px;border-radius:9px}
.report-head .rh-brand{font-weight:800;font-size:1.05rem;color:#17283c;letter-spacing:-.01em;line-height:1.15}
.report-head .rh-sub{font-size:.76rem;color:#5a6c80}
.report-head .rh-right{margin-left:auto;text-align:right;font-size:.76rem;color:#4d5c6e;line-height:1.35}
.report-head .rh-right strong{display:block;color:#17283c;font-size:.86rem}
.report-foot{margin-top:1.4rem;padding-top:.6rem;border-top:1px solid #c9d4e0;display:grid;grid-template-columns:1.6fr 1fr;gap:.2rem 1rem;font-size:.72rem;line-height:1.45;color:#4d5c6e}
.report-foot .rf-warn{grid-column:1/-1;background:#fff7ec;border:1px solid #f0d3a8;border-radius:6px;padding:.4rem .6rem;color:#6a4a14}
.report-foot .rf-right{text-align:right}
.report-sheet h1{font-size:1.45rem;font-weight:800;letter-spacing:-.02em;border-bottom:0!important;padding-bottom:0!important;margin:.1rem 0 .15rem}
.report-sheet h2{font-size:1.02rem;font-weight:700;color:#245d89!important;margin:1.15rem 0 .35rem!important;padding-bottom:.25rem;border-bottom:1px solid #dbe4ee!important}
.report-sheet table{width:100%;border-collapse:collapse;font-size:.84rem}
.report-sheet th{background:#eef3f9!important;color:#2b3d52;font-weight:700;text-align:left}
.report-sheet th,.report-sheet td{border:1px solid #d3dce7!important;padding:.32rem .5rem!important;vertical-align:top}
.report-sheet tbody tr:nth-child(even) td{background:#fafcfe}

/* ---------- Paper / PDF ---------- */
@media print{
  html,body{background:#fff!important;color:#172033!important;height:auto!important;overflow:visible!important}
  body{max-width:none!important;margin:0!important;padding:0!important;font-size:9.5pt!important;line-height:1.4!important;-webkit-print-color-adjust:exact;print-color-adjust:exact}
  .no-print,.screen-only,.btn,.toolbar,.report-toolbar,.report-hint{display:none!important}
  body.report-page .report-sheet{width:auto;min-height:0;margin:0;padding:0;box-shadow:none;border-radius:0;display:block}
  .report-head{padding-bottom:3mm;margin-bottom:5mm}
  h1{font-size:18pt!important;break-after:avoid-page}
  h2,h3{break-after:avoid-page}
  p,li{orphans:3;widows:3}
  table{width:100%!important;border-collapse:collapse!important;font-size:8pt!important;break-inside:auto}
  thead{display:table-header-group}
  tr{break-inside:avoid-page}
  th,td{padding:3.5pt 5pt!important;border:.6pt solid #b9c6d6!important;overflow-wrap:anywhere}
  .card,.box,.note,.kpi,.kpi-row,.section,.report-section,.report-foot{break-inside:avoid-page;box-shadow:none!important}
  a{color:inherit!important;text-decoration:none!important}
  code{white-space:normal!important;overflow-wrap:anywhere}
  .report-foot{margin-top:7mm}
  .print-confidential{display:block!important;border-top:1px solid #9aa6b5;padding-top:5pt;margin-top:12pt;font-size:8pt;color:#455468}
}

/* ---------- Create New Map: printable recovery-key sheet (built on demand by page-create.js) ---------- */
#rk-sheet{display:none}
@media print{
  body.print-keys>*:not(#rk-sheet){display:none!important}
  body.print-keys{background:#fff!important}
  #rk-sheet{display:block;font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:#172033;font-size:9.5pt;line-height:1.4}
  .rks-head{display:flex;align-items:center;gap:4mm;padding-bottom:3mm;border-bottom:2.2pt solid #245d89;margin-bottom:4mm}
  .rks-head img{width:11mm;height:11mm;border-radius:2.5mm}
  .rks-brand{font-weight:800;font-size:13pt;line-height:1.1}.rks-sub{font-size:9pt;color:#245d89;font-weight:700;letter-spacing:.06em;text-transform:uppercase}
  .rks-meta{margin-left:auto;text-align:right;font-size:8.5pt;color:#4d5c6e;line-height:1.35}.rks-meta strong{display:block;color:#172033;font-size:10.5pt}
  .rks-alert{border:1pt solid #c4554a;background:#fdf0ee!important;color:#7a2018;border-radius:1.5mm;padding:2.5mm 3.5mm;font-size:9pt;margin-bottom:4mm}
  #rk-sheet h2{font-size:13pt;margin:0 0 1mm;color:#172033}
  #rk-sheet h3{font-size:10pt;margin:0 0 1.5mm;color:#245d89}
  .rks-note{margin:0 0 3.5mm;color:#354254}
  .rks-grid{display:grid;grid-template-columns:1fr 1fr;gap:3.5mm;margin-bottom:5mm}
  .rks-card{border:1pt dashed #6b7c90;border-radius:2mm;padding:2.6mm 3.4mm 3mm;break-inside:avoid}
  .rks-card:last-child{grid-column:1/-1}
  .rks-card-top{display:flex;justify-content:space-between;font-size:7pt;font-weight:700;letter-spacing:.08em;color:#5a6c80;margin-bottom:1.5mm}
  .rks-cut{font-weight:600;letter-spacing:0;color:#8a98a8}
  .rks-key{white-space:nowrap;font:700 13pt/1.2 ui-monospace,"SFMono-Regular",Menlo,Consolas,"Courier New",monospace;letter-spacing:.035em;padding:2.2mm 0;text-align:center;background:#f2f6fb!important;border-radius:1.5mm;color:#10233a}
  .rks-lines{display:grid;grid-template-columns:1fr 1fr;gap:4mm;margin-top:3mm;font-size:8pt;color:#4d5c6e}
  .rks-lines div,.rks-file{display:flex;align-items:flex-end;gap:2mm}
  .rks-lines i,.rks-file i{flex:1;border-bottom:.7pt solid #8a98a8;height:5mm}
  .rks-cols{display:grid;grid-template-columns:1fr 1fr;gap:6mm;margin-bottom:5mm;font-size:8.8pt}
  .rks-cols ol,.rks-cols ul{margin:0;padding-left:4.5mm}.rks-cols li{margin-bottom:1mm}
  .rks-file{font-size:9pt;margin-bottom:6mm}
  .rks-foot{border-top:.6pt solid #b9c6d6;padding-top:2.5mm;font-size:7.5pt;color:#5a6c80}
  #rk-sheet code{font-size:.95em;background:#eef2f7!important;padding:0 1mm;border-radius:.8mm}
}
