/* =====================================================================
 * Mise en page des documents (écran : aperçu ; papier : impression).
 * Les dimensions sont en mm : l'aperçu et le papier sont identiques.
 * ===================================================================== */
.page { background: #fff; color: #111; position: relative; overflow: hidden; display: flex; flex-direction: column; font-family: Georgia, "Times New Roman", serif; }
.page-A5 { width: 148mm; min-height: 210mm; padding: 9mm 10mm 8mm; font-size: 10.5pt; }
.page-A4 { width: 210mm; min-height: 297mm; padding: 14mm 16mm 12mm; font-size: 11.5pt; }
.page .ar, .page [lang="ar"] { font-family: var(--arabe, "Noto Naskh Arabic", "Amiri", "Geeza Pro", "Traditional Arabic", serif); font-size: 1.08em; }

/* Filigrane : derrière tout le contenu, ne gêne ni la lecture ni la sélection */
.filigrane { position: absolute; left: 50%; z-index: 0; pointer-events: none; object-fit: contain; max-height: 80%; }
.page:not(.page-calque) > :not(.filigrane) { position: relative; z-index: 1; }

/* En-tête : français à gauche, arabe à droite */
.entete { font-family: var(--entete-police, Georgia), serif; color: #222; }
.entete-grille { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4mm; }
.entete-grille.logo-gauche { grid-template-columns: auto 1fr 1fr; }
.entete-grille.logo-droite { grid-template-columns: 1fr 1fr auto; }
.entete-grille.logo-aucun { grid-template-columns: 1fr 0 1fr; }
.entete-ar { text-align: right; font-family: var(--arabe, "Amiri", serif); }
.entete-nom { font-size: 1.35em; font-weight: 700; color: var(--entete-couleur); }
.entete-spec { font-weight: 600; }
.entete-petit { font-size: .82em; color: #444; }
.entete-cell-logo { text-align: center; }
.entete-logo { max-width: 45mm; object-fit: contain; }
.entete-ligne { height: 0; border-top: 2px solid var(--entete-couleur); margin-top: 3mm; }
.entete-vide { padding: 6mm; border: 1px dashed #c00; color: #c00; font-family: sans-serif; text-align: center; }

.page-corps { flex: 1; padding-top: 4mm; }
.doc-lieu-date { text-align: right; font-size: .92em; }
.doc-lieu-date.bilingue { display: flex; justify-content: space-between; align-items: baseline; gap: 4mm; text-align: start; }
.doc-patient { margin-top: 3mm; padding: 2mm 3mm; background: #f4f6f8; border-radius: 1.5mm; display: flex; justify-content: space-between; gap: 4mm; }
.doc-titre { text-align: center; font-size: 1.3em; letter-spacing: 1px; margin: 5mm 0 3mm; color: #111; }
.doc-titre span { margin-inline-start: 3mm; }
.doc-lignes { padding-inline-start: 6mm; margin: 0; }
.doc-lignes li { margin-bottom: 3.5mm; page-break-inside: avoid; }
.doc-med { display: flex; justify-content: space-between; gap: 4mm; }
.doc-qte { font-size: .85em; color: #444; white-space: nowrap; }
.doc-lignes .ar { text-align: right; color: #222; }
.doc-remarques { margin-top: 4mm; font-style: italic; white-space: pre-line; }

.signature { align-self: flex-end; width: 55mm; text-align: center; font-size: .8em; color: #444; margin: 3mm 0; }
.signature img { display: block; margin: 1mm auto 0; max-width: 55mm; max-height: 30mm; object-fit: contain; }
.pied { font-size: .72em; color: #444; text-align: center; }
.pied-ligne { border-top: 1px solid var(--entete-couleur, #999); margin-bottom: 1.5mm; }
.pied-perso { font-style: italic; }


/* ---------- Certificats ---------- */
.doc-numero { text-align: right; font-size: .8em; color: #555; }
.doc-titre.cert { font-size: 1.2em; line-height: 1.6; }
.doc-texte { text-align: justify; line-height: 1.7; margin: 3mm 0; }
.doc-texte-ar p { text-align: justify; line-height: 1.9; margin: 3mm 0; }
.doc-fait { margin-top: 6mm; text-align: right; }

/* ---------- Demandes d'examens ---------- */
.doc-urgent { text-align: center; color: #b00; font-weight: 700; border: 1.5px solid #b00; padding: 1mm; margin: 0 auto 2mm; width: 50%; }
.doc-intro { margin: 2mm 0; font-style: italic; }
.doc-groupe { margin-bottom: 2mm; page-break-inside: avoid; }
.doc-groupe-titre { font-weight: 700; text-decoration: underline; font-size: .95em; }
.doc-examens { margin: 1mm 0 0; padding-inline-start: 6mm; list-style: "☐  "; }
.doc-examens li { margin: .6mm 0; }
.doc-note { font-weight: 600; margin-top: 3mm; }
.doc-renseignements { margin-top: 3mm; padding: 2mm 3mm; border-left: 2px solid #999; }

/* ---------- Lettres d'orientation ---------- */
.lettre-entete { margin: 4mm 0 3mm; }
.lettre-a { margin-inline-start: 50%; line-height: 1.5; }
.lettre-objet { margin-top: 4mm; }
.lettre-confidentiel { margin-top: 1mm; font-size: .8em; font-style: italic; color: #a00; }
.lettre-texte { line-height: 1.6; text-align: justify; }

/* ---------- Fiches complètes ---------- */
.aide-doc { font-size: .8em; color: #555; text-align: center; margin: 0 0 3mm; font-style: italic; }
table.fiche { width: 100%; border-collapse: collapse; font-size: .92em; margin-bottom: 3mm; }
table.fiche th, table.fiche td { border: 1px solid #999; padding: 1.5mm 2mm; text-align: left; vertical-align: top; }
table.fiche th { width: 40%; background: #f4f6f8; font-weight: 600; }
table.fiche.actes th { width: auto; }
table.fiche .section { background: #dde6ef; font-weight: 700; }

/* ---------- Superposition (calque) : données seules, positions absolues en mm ---------- */
.page-calque { width: 210mm; height: 297mm; min-height: 297mm; padding: 0 !important; position: relative; font-family: "Courier New", monospace; font-size: 10.5pt; }
.page-calque.avec-fond { background-size: 100% 100%; background-repeat: no-repeat; }
.calque-champ { position: absolute; transform: translateY(-50%); white-space: nowrap; color: #000; font-weight: 600; }
.calque-champ.x { font-size: 12pt; transform: translate(-50%, -50%); }
.calque-champ.etiquette { color: #C0392B; font-size: 7.5pt; font-family: Arial, sans-serif; }
.calque-image { position: absolute; max-width: 50mm; max-height: 28mm; transform: translateY(-50%); }
.page-calque.avec-grille { background-image: repeating-linear-gradient(0deg, #0000 0 calc(10mm - 0.2mm), #9db7d1 calc(10mm - 0.2mm) 10mm),
  repeating-linear-gradient(90deg, #0000 0 calc(10mm - 0.2mm), #9db7d1 calc(10mm - 0.2mm) 10mm); }

/* L'aperçu A5 à l'écran est réduit pour tenir dans la colonne */
.apercu-page { zoom: .78; }
@supports not (zoom: 1) { .apercu-page { transform: scale(.78); transform-origin: top center; } }

/* ---------------- IMPRESSION ----------------
 * La taille du papier (A4/A5) est fixée dynamiquement par documents.js (@page size).
 * margin: 0 sur @page => le navigateur n'imprime ni en-tête ni pied de page. */
#zone-impression { display: none; }
@media print {
  @page { margin: 0; }
  html, body { background: #fff !important; margin: 0 !important; }
  body > *:not(#zone-impression) { display: none !important; }
  #zone-impression { display: block !important; }
  #zone-impression .page { box-shadow: none; margin: 0; page-break-after: always; overflow: hidden; }
  #zone-impression .page-A5 { height: 210mm; }
  #zone-impression .page-A4 { height: 297mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Aperçu A4 de l'éditeur d'en-tête : réduit pour tenir dans la colonne */
.apercu-page.apercu-a4 { zoom: .62; }


/* =====================================================================
 * Modèles d'en-tête et mise en page soignée (v2)
 * ===================================================================== */
/* Moderne : bandeau de couleur en haut de page, nom en couleur, spécialité en petites capitales */
.page.modele-moderne::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3.5mm; background: var(--entete-couleur); z-index: 2; }
.page.modele-moderne::after { content: ""; position: absolute; inset: 3.5mm 0 auto 0; height: .8mm; background: color-mix(in srgb, var(--entete-couleur) 35%, #fff); z-index: 2; }
.page-A5.modele-moderne { padding-top: 11mm; }
.page-A4.modele-moderne { padding-top: 17mm; }
.entete-moderne .entete-spec { text-transform: uppercase; letter-spacing: .6px; font-size: .82em; color: color-mix(in srgb, var(--entete-couleur) 75%, #000); }
.entete-moderne .entete-ar .entete-spec { text-transform: none; letter-spacing: 0; font-size: .95em; }
.entete-moderne .entete-ligne { border-top-width: .6mm; margin-top: 3.5mm; }
/* Centré : logo au-dessus, double filet fin */
.entete-centre-logo { text-align: center; margin-bottom: 2mm; }
.entete-centre .entete-grille { grid-template-columns: 1fr 1fr; }
.entete-centre .entete-grille > div:nth-child(2) { display: none; }
.entete-centre .entete-ligne { border-top: .4mm solid var(--entete-couleur); padding-top: .8mm; border-bottom: .2mm solid var(--entete-couleur); height: 0; }
/* Arabe de l'en-tête un peu plus grand pour équilibrer avec le français */
.entete-ar .entete-nom { font-size: 1.45em; }
.entete-ar .entete-spec, .entete-ar .entete-petit { font-size: 1.05em; }
.entete-ar .entete-petit { font-size: .9em; }

/* Bloc patient */
.doc-patient { background: color-mix(in srgb, var(--entete-couleur, #1F4E79) 6%, #fff); border-inline-start: 1mm solid var(--entete-couleur, #1F4E79); border-radius: 1mm; align-items: center; }

/* Titres : couleur de l'en-tête ; ordonnance entre deux filets, autres documents soulignés d'un court trait */
.doc-titre { color: var(--entete-couleur, #111); letter-spacing: 1px; }
.doc-titre::after { content: ""; display: block; width: 18mm; margin: 1.5mm auto 0; border-top: .5mm solid color-mix(in srgb, var(--entete-couleur, #999) 55%, #fff); }
.doc-titre.ordo { display: flex; align-items: center; justify-content: center; gap: 3mm; letter-spacing: 2px; font-size: 1.2em; }
.doc-titre.ordo::before, .doc-titre.ordo::after { content: ""; display: block; flex: 1; width: auto; margin: 0; height: 0; border-top: .3mm solid color-mix(in srgb, var(--entete-couleur, #999) 45%, #fff); }
.doc-titre.ordo span { letter-spacing: 0; font-size: 1.05em; margin: 0; }
/* Groupes d'examens, objet des lettres */
.doc-groupe-titre { color: var(--entete-couleur, #111); text-decoration: none; border-bottom: .3mm solid color-mix(in srgb, var(--entete-couleur, #999) 35%, #fff); padding-bottom: .5mm; margin-bottom: 1mm; }
.lettre-objet b, .lettre-objet strong { color: var(--entete-couleur, #111); }
.doc-renseignements { border-left-color: var(--entete-couleur, #999); background: #fafbfc; }
table.fiche .section { background: color-mix(in srgb, var(--entete-couleur, #1F4E79) 12%, #fff); }

/* Lignes de l'ordonnance : numéro dans une pastille, arabe aligné à droite sous un filet pointillé */
.doc-lignes { list-style: none; padding: 0; counter-reset: ligne; }
.doc-lignes li { counter-increment: ligne; position: relative; padding: 0 0 2.5mm 8mm; margin-bottom: 2.5mm; border-bottom: .2mm dotted #c8ced6; }
.doc-lignes li:last-child { border-bottom: none; }
.doc-lignes li::before { content: counter(ligne); position: absolute; left: 0; top: .3mm; width: 5mm; height: 5mm; border-radius: 50%;
  background: var(--entete-couleur, #1F4E79); color: #fff; font: 700 .75em/5mm Arial, sans-serif; text-align: center; }
.doc-med b { font-size: 1.05em; }
.doc-qte { background: #f1f3f6; border-radius: 1mm; padding: 0 1.5mm; }
.doc-lignes .ar { margin-top: .8mm; color: #333; font-size: 1.12em; line-height: 1.5; }
.doc-remarques { padding: 2mm 3mm; border-inline-start: .6mm solid color-mix(in srgb, var(--entete-couleur, #999) 50%, #fff); background: #fafbfc; font-style: normal; }
.doc-remarques.ar { border-inline-start: none; border-inline-end: .6mm solid color-mix(in srgb, var(--entete-couleur, #999) 50%, #fff); text-align: right; }

/* Signature et pied de page */
.signature > div:first-child { border-top: .2mm solid #bbb; padding-top: 1mm; }
.pied { color: #555; }
.pied-ligne { border-top-width: .4mm; }
