/* ═══════════════════════════════════════════════
   Dossier print stylesheet (#129, A2)
   ───────────────────────────────────────────────
   Ships a printable archive document derived from
   the visitor's pinned clues. The DOM lives at
   .dossier-printable and is hidden on screen; the
   @media print block hides everything else and
   surfaces the dossier with the picked cosmetic
   variants.

   Tested page-break behaviour in Chromium and
   Firefox; ".dossier-clue" uses break-inside:avoid
   so individual clue cards never split.
   ═══════════════════════════════════════════════ */

/* ── On-screen: never visible. The only path to display is print. ── */
.dossier-printable {
  display: none;
}

/* ── Print-mode isolation via body class (#240) ──
   Toggled by js/faldone-stampa.js on the browser's beforeprint /
   afterprint events. This bypasses @media print entirely: regardless
   of cascade quirks or print-stylesheet activation, the body class
   forces the printable visible and everything else hidden. */
body.is-printing-dossier > *:not(.dossier-printable) {
  display: none !important;
}
body.is-printing-dossier > .dossier-printable {
  display: block !important;
  background: #fbf6e9;
  color: #1a1208;
}
body.is-printing-dossier {
  background: #fbf6e9 !important;
}

/* Force backgrounds, gradients, and colours to render in the print
   preview (#241). By default print previews suppress background
   colours / images / gradients to save ink — but the entire dossier
   visual identity (wax seal, dossier-stamp circle, paper textures,
   cartouche stamp pseudo-element) lives in CSS backgrounds and
   gradients. print-color-adjust:exact instructs the browser to
   render them anyway. Applied on the printable and every descendant
   so every nested element keeps its colours. */
.dossier-printable,
.dossier-printable * {
  -webkit-print-color-adjust: exact !important;
          print-color-adjust: exact !important;
}

/* ── On-screen variant picker modal ── */
.stampa-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.stampa-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.stampa-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 14, 6, 0.72);
}

.stampa-panel {
  position: relative;
  margin: 4rem auto;
  /* Widened from 540px (#231) to accommodate the 50%-larger fonts
     without awkward wrapping. */
  max-width: 760px;
  background: linear-gradient(180deg, #f6efe0 0%, #ede2c9 100%);
  border: 1px solid rgba(120, 90, 40, 0.45);
  border-radius: 2px;
  padding: 2rem 2.25rem;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
  color: #2a1f12;
  font-family: var(--font-display, 'EB Garamond', Georgia, serif);
}

.stampa-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: 0;
  font-size: 2.625rem;
  line-height: 1;
  color: rgba(40, 30, 20, 0.6);
  cursor: pointer;
}
.stampa-close:hover { color: #2a1f12; }

.stampa-title {
  font-size: 2.25rem;
  font-weight: 400;
  margin: 0 0 0.5rem;
  letter-spacing: 0.02em;
}

.stampa-intro {
  font-size: 1.40625rem;
  font-style: italic;
  margin: 0 0 1.25rem;
  color: rgba(40, 30, 20, 0.75);
}

.stampa-row {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 1rem;
  align-items: start;
  margin-bottom: 0.875rem;
  font-size: 1.40625rem;
}

.stampa-row-label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 1.125rem;
  color: rgba(40, 30, 20, 0.6);
  padding-top: 0.25rem;
}

.stampa-row-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.stampa-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid rgba(120, 90, 40, 0.3);
  border-radius: 2px;
  cursor: pointer;
  background: rgba(255, 250, 240, 0.4);
}

.stampa-option:has(input:checked) {
  border-color: rgba(120, 90, 40, 0.85);
  background: rgba(255, 250, 240, 0.85);
}

.stampa-option input {
  appearance: none;
  width: 0;
  height: 0;
  margin: 0;
  position: absolute;
  opacity: 0;
}

.stampa-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid rgba(40, 30, 20, 0.25);
}

/* Wax-seal swatches (visual hint of what each tier looks like). */
.stampa-swatch-wax-gold       { background: radial-gradient(circle, #d4a64c 0%, #8a6b1f 80%); }
.stampa-swatch-wax-wine       { background: radial-gradient(circle, #8a2a2a 0%, #4d1212 80%); }
.stampa-swatch-wax-violet     { background: radial-gradient(circle, #6a3a8a 0%, #321852 80%); }
.stampa-swatch-wax-black-gold { background: radial-gradient(circle, #d4a64c 0%, #1a1208 80%); }

/* Letterhead swatches. */
.stampa-swatch-letterhead-personale { background: #f0e4cc; }
.stampa-swatch-letterhead-diocesano { background: linear-gradient(180deg, #e8dcb8 0%, #d4c294 100%); }
.stampa-swatch-letterhead-curia     { background: linear-gradient(180deg, #e0d4a4 0%, #b89c5c 100%); }
.stampa-swatch-letterhead-riservato { background: repeating-linear-gradient(45deg, #1a1208, #1a1208 4px, #2a1f12 4px, #2a1f12 8px); }

/* Paper swatches. */
.stampa-swatch-paper-foolscap     { background: #f4ecd8; }
.stampa-swatch-paper-pergamena    { background: linear-gradient(135deg, #e8dab6 0%, #d4c294 100%); }
.stampa-swatch-paper-archivistico { background: linear-gradient(135deg, #d6c08c 0%, #a88848 100%); }

/* Stamp swatches. */
.stampa-swatch-stamp-dcs           { background: #8a6b1f; }
.stampa-swatch-stamp-postulazione  { background: #4d1212; }
.stampa-swatch-stamp-confidenziale { background: #1a1208; }

.stampa-mastery-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  font-size: 1.3125rem;
  color: rgba(40, 30, 20, 0.75);
  cursor: pointer;
}

.stampa-mastery-checkbox {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #5a2a2a;
}

.stampa-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.stampa-cancel,
.stampa-confirm {
  font-family: inherit;
  font-size: 1.40625rem;
  padding: 0.75rem 1.5rem;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.stampa-cancel {
  background: none;
  border: 1px solid rgba(120, 90, 40, 0.35);
  color: rgba(40, 30, 20, 0.7);
}

.stampa-confirm {
  background: linear-gradient(180deg, #5a2a2a 0%, #3a1212 100%);
  color: #f6efe0;
  border: 1px solid rgba(80, 20, 20, 0.7);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1) inset;
}

.stampa-confirm:hover {
  background: linear-gradient(180deg, #6a3232 0%, #4a1818 100%);
}

/* On-screen Faldone Stampa button. */
.eb-stampa-button {
  display: block;
  margin: 1.5rem auto 0;
  font-family: var(--font-display, 'EB Garamond', Georgia, serif);
  font-size: 1.40625rem;
  letter-spacing: 0.05em;
  background: none;
  color: rgba(220, 200, 160, 0.75);
  border: 1px solid rgba(180, 140, 60, 0.4);
  padding: 0.875rem 1.75rem;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.2s ease, color 0.2s ease;
}

.eb-stampa-button:hover,
.eb-stampa-button:focus-visible {
  background: rgba(180, 140, 60, 0.12);
  color: #f6efe0;
}

.eb-stampa-button:focus-visible {
  outline: 2px solid rgba(232, 210, 160, 0.95);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .stampa-modal { transition: none; }
}

/* ═══ @media print — the actual dossier document ═══ */
@media print {
  /* Hide screen UI. */
  body > * { display: none !important; }

  /* But surface the dossier. */
  .dossier-printable {
    display: block !important;
    position: static;
    background: #fbf6e9;
    color: #1a1208;
    font-family: 'EB Garamond', Georgia, serif;
    font-size: 11pt;
    line-height: 1.45;
    padding: 0;
    margin: 0;
  }

  @page {
    size: A4;
    margin: 18mm 16mm;
  }

  .dossier-letterhead {
    display: flex;
    align-items: flex-start;
    gap: 12mm;
    padding-bottom: 6mm;
    border-bottom: 0.4mm solid rgba(40, 30, 20, 0.55);
  }

  .dossier-stamp {
    width: 22mm;
    height: 22mm;
    flex-shrink: 0;
    background: radial-gradient(circle, #8a6b1f 0%, #4d3812 80%);
    border-radius: 50%;
    box-shadow: 0 0 0 1mm rgba(40, 30, 20, 0.15);
  }

  .dossier-letterhead-text { flex: 1; }

  .dossier-letterhead-line {
    font-family: 'Cinzel', serif;
    font-size: 13pt;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #2a1f12;
  }
  .dossier-letterhead-line::before {
    content: attr(data-line);
  }

  /* Letterhead text content per variant */
  .dossier-letterhead-personale .dossier-letterhead-line::before { content: 'Archivio personale del Bishop'; }
  .dossier-letterhead-diocesano .dossier-letterhead-line::before { content: 'Atti dell’Archivio Diocesano'; }
  .dossier-letterhead-curia     .dossier-letterhead-line::before { content: 'Curia Generalitia — Causae Sanctorum'; }
  .dossier-letterhead-riservato .dossier-letterhead-line::before { content: 'Riservato al Sacro Concilio'; }

  /* Paper grade — texture overlay via background. */
  .dossier-paper-foolscap     { background: #fbf6e9; }
  .dossier-paper-pergamena    { background: linear-gradient(135deg, #f4e8c8 0%, #e8d8a8 100%); }
  .dossier-paper-archivistico {
    background: linear-gradient(135deg, #f0e0b8 0%, #d8b878 100%);
  }
  .dossier-paper-archivistico .dossier-cartouche {
    border-color: rgba(40, 30, 20, 0.7);
  }

  /* Stamp variant — overlays on top-right of cartouche.
     !important on every declaration that collides with screen rules
     in css/dossier.css. css/dossier.css doesn't have @media gating,
     so it competes in the print cascade — even after the load-order
     swap (#238), some browsers / cache states still ran the screen
     rules in print, rendering text in light-gold-on-white. Force
     wins with !important. */
  .dossier-cartouche {
    margin-top: 6mm !important;
    padding: 4mm 6mm !important;
    border: 0.3mm solid rgba(40, 30, 20, 0.55) !important;
    background: rgba(255, 255, 255, 0.4) !important;
    position: relative !important;
    text-align: left !important;
    border-bottom: 0.3mm solid rgba(40, 30, 20, 0.55) !important;
    margin-bottom: 0 !important;
    page-break-after: avoid;
  }
  .dossier-cartouche-rank {
    font-family: 'Cinzel', serif !important;
    font-size: 10pt !important;
    font-weight: 400 !important;
    letter-spacing: 0.22em !important;
    text-transform: uppercase !important;
    color: rgba(40, 30, 20, 0.7) !important;
    margin: 0 0 1mm !important;
  }
  .dossier-cartouche-nomen {
    font-family: 'EB Garamond', serif !important;
    font-size: 16pt !important;
    font-weight: 400 !important;
    font-style: italic !important;
    color: #1a1208 !important;
    margin: 0 !important;
    line-height: 1.2 !important;
  }
  .dossier-cartouche-diocese {
    font-size: 10pt !important;
    color: rgba(40, 30, 20, 0.7) !important;
    margin: 1mm 0 0 !important;
    letter-spacing: 0 !important;
  }
  .dossier-cartouche::after {
    content: '';
    position: absolute;
    top: 4mm;
    right: 6mm;
    width: 18mm;
    height: 18mm;
    transform: rotate(-12deg);
    border: 0.4mm solid currentColor;
    border-radius: 2mm;
    opacity: 0.55;
    background-position: center;
    background-repeat: no-repeat;
  }
  .dossier-stamp-dcs           .dossier-cartouche::after { color: #8a6b1f; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 60'><text x='30' y='34' font-family='Cinzel' font-size='12' text-anchor='middle' fill='%238a6b1f'>D.C.S.</text></svg>"); }
  .dossier-stamp-postulazione  .dossier-cartouche::after { color: #4d1212; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 60'><text x='30' y='27' font-family='Cinzel' font-size='8' text-anchor='middle' fill='%234d1212'>POSTUL.</text><text x='30' y='38' font-family='Cinzel' font-size='8' text-anchor='middle' fill='%234d1212'>GEN.</text></svg>"); }
  .dossier-stamp-confidenziale .dossier-cartouche::after { color: #1a1208; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 60'><text x='30' y='34' font-family='Cinzel' font-size='8.5' text-anchor='middle' fill='%231a1208'>CONFID.</text></svg>"); }

  /* Three category columns. */
  .dossier-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6mm;
    margin-top: 6mm;
  }
  .dossier-col {
    border-top: 0.3mm solid rgba(40, 30, 20, 0.4);
    padding-top: 3mm;
  }
  .dossier-col-real       { border-top-color: #5a1212; }
  .dossier-col-neutral    { border-top-color: rgba(40, 30, 20, 0.4); }
  .dossier-col-apparition { border-top-color: #8a6b1f; }
  .dossier-col-label {
    font-family: 'Cinzel', serif;
    font-size: 9pt;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(40, 30, 20, 0.7);
    margin: 0 0 3mm;
  }
  .dossier-clue {
    margin-bottom: 4mm;
    padding-bottom: 3mm;
    border-bottom: 0.15mm dashed rgba(40, 30, 20, 0.25);
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .dossier-clue:last-child {
    border-bottom: 0;
  }
  .dossier-clue-source {
    font-size: 8.5pt;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(40, 30, 20, 0.6);
    margin-bottom: 1mm;
  }
  .dossier-clue-text {
    font-size: 10pt;
    font-style: italic;
    color: #1a1208;
  }

  /* Mastery markers — visitor's private summary. Six rows in a tight
     two-column dl. Page-break-avoiding so the panel always stays
     together. */
  .dossier-mastery {
    margin: 8mm 0 0 !important;
    padding: 4mm 6mm !important;
    border: 0.2mm dashed rgba(40, 30, 20, 0.45) !important;
    background: rgba(255, 255, 255, 0.35) !important;
    page-break-inside: avoid;
  }
  .dossier-mastery-label {
    font-family: 'Cinzel', serif;
    font-size: 9pt;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(40, 30, 20, 0.7);
    margin: 0 0 3mm;
    border-bottom: 0.15mm solid rgba(40, 30, 20, 0.3);
    padding-bottom: 1mm;
  }
  .dossier-mastery-list {
    display: grid !important;
    grid-template-columns: 50mm 1fr !important;
    gap: 1.5mm 6mm !important;
    margin: 0 !important;
    font-size: 9.5pt !important;
    max-width: none !important;
  }
  .dossier-mastery-list dt {
    font-family: 'Cinzel', serif !important;
    font-size: 8.5pt !important;
    font-weight: 400 !important;
    letter-spacing: 0.1em !important;
    text-transform: uppercase !important;
    color: rgba(40, 30, 20, 0.65) !important;
  }
  .dossier-mastery-list dd {
    margin: 0 !important;
    font-size: 9.5pt !important;
    font-style: italic !important;
    color: #1a1208 !important;
  }
  .dossier-mastery-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 0 0 3mm !important;
    font-size: 9.5pt !important;
  }
  .dossier-mastery-table th,
  .dossier-mastery-table td {
    text-align: left !important;
    padding: 1mm 2mm !important;
    border-bottom: 0.15mm solid rgba(40, 30, 20, 0.25) !important;
    color: #1a1208 !important;
  }
  .dossier-mastery-table thead th {
    font-family: 'Cinzel', serif !important;
    font-size: 8pt !important;
    letter-spacing: 0.1em !important;
    text-transform: uppercase !important;
    color: rgba(40, 30, 20, 0.65) !important;
  }
  .dossier-mastery-rare-note {
    margin: 4mm 0 0 !important;
    padding-top: 2mm !important;
    border-top: 0.15mm dashed rgba(40, 30, 20, 0.3) !important;
    font-style: italic !important;
    font-size: 9.5pt !important;
    color: rgba(40, 30, 20, 0.85) !important;
    text-align: left !important;
    max-width: none !important;
  }

  /* Wax seal — bottom-right, just above the footer. */
  .dossier-seal {
    width: 26mm;
    height: 26mm;
    margin: 8mm 0 8mm auto;
    border-radius: 50%;
    position: relative;
    box-shadow: 0 0 0 0.4mm rgba(40, 30, 20, 0.4),
                0 1mm 1mm rgba(0, 0, 0, 0.15) inset;
    page-break-inside: avoid;
  }
  .dossier-seal::after {
    content: '';
    position: absolute;
    inset: 3mm;
    border: 0.3mm dashed rgba(255, 255, 255, 0.4);
    border-radius: 50%;
  }
  .dossier-wax-gold       .dossier-seal { background: radial-gradient(circle at 35% 30%, #e8c478 0%, #8a6b1f 90%); }
  .dossier-wax-wine       .dossier-seal { background: radial-gradient(circle at 35% 30%, #c04848 0%, #4d1212 90%); }
  .dossier-wax-violet     .dossier-seal { background: radial-gradient(circle at 35% 30%, #9a6abc 0%, #321852 90%); }
  .dossier-wax-black-gold .dossier-seal {
    background: radial-gradient(circle at 35% 30%, #e8c478 0%, #8a6b1f 30%, #1a1208 90%);
  }

  /* Coronae footer — epitheta in italic, no count. */
  .dossier-footer {
    border-top: 0.3mm solid rgba(40, 30, 20, 0.5);
    padding-top: 3mm;
    font-size: 9pt;
    color: rgba(40, 30, 20, 0.7);
    page-break-inside: avoid;
  }
  .dossier-coronae-label {
    font-family: 'Cinzel', serif;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    margin-right: 2mm;
  }
  .dossier-coronae-list {
    font-style: italic;
  }
}

/* ═══════════════════════════════════════════════
   Auditor Externus — codice di presenza (#136)
   ═══════════════════════════════════════════════ */
.stampa-codice-row {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(120, 90, 40, 0.25);
}

.stampa-codice-label {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: 1.125rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(40, 30, 20, 0.6);
  margin-bottom: 0.5rem;
}

.stampa-codice-controls {
  display: flex;
  gap: 0.5rem;
}

.stampa-codice-input {
  flex: 1;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 1.3125rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 250, 240, 0.65);
  border: 1px solid rgba(120, 90, 40, 0.4);
  border-radius: 2px;
  color: #2a1f12;
  outline: none;
  transition: border-color 0.2s ease;
}

.stampa-codice-input:focus-visible {
  border-color: rgba(120, 90, 40, 0.85);
}

.stampa-codice-submit {
  font-family: inherit;
  font-size: 1.3125rem;
  padding: 0.75rem 1.5rem;
  background: rgba(180, 140, 60, 0.15);
  color: #2a1f12;
  border: 1px solid rgba(120, 90, 40, 0.5);
  border-radius: 2px;
  cursor: pointer;
}

.stampa-codice-submit:hover:not(:disabled) {
  background: rgba(180, 140, 60, 0.3);
}

.stampa-codice-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.stampa-codice-hint {
  margin: 0.5rem 0 0;
  font-size: 1.21875rem;
  font-style: italic;
  color: rgba(40, 30, 20, 0.5);
}

/* ═══════════════════════════════════════════════
   Auditor Externus — flash notification
   ═══════════════════════════════════════════════ */
.auditor-externus-flash {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(-1rem);
  max-width: min(560px, calc(100vw - 2rem));
  padding: 0.875rem 1.25rem;
  background: linear-gradient(180deg, #f6efe0 0%, #ede2c9 100%);
  color: #2a1f12;
  border: 1px solid rgba(120, 90, 40, 0.55);
  border-radius: 2px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 0.9375rem;
  font-style: italic;
  text-align: center;
  z-index: 1200;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.auditor-externus-flash.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.auditor-externus-flash-err {
  border-left: 3px solid #5a1212;
  color: #5a1212;
}

.auditor-externus-flash-ok {
  border-left: 3px solid #6a4a14;
}

@media (prefers-reduced-motion: reduce) {
  .auditor-externus-flash {
    transition: none;
    transform: translateX(-50%);
  }
  .auditor-externus-flash.is-visible {
    transform: translateX(-50%);
  }
}
