/* Letterhead rendering (sizes in em so it scales with the paper) */
.lh-head,.lh-foot{--lh-color:#0b63ce;color:#1b2433;-webkit-print-color-adjust:exact;print-color-adjust:exact}
.lh-head{display:grid;align-items:center;gap:1.2em;padding-bottom:1em}
.lh-identity{display:flex;flex-direction:column;gap:.15em;min-width:0}
.lh-office{font-size:1.3em;font-weight:800;line-height:1.45;color:var(--lh-color)}
.lh-role{font-size:.88em;font-weight:700;color:#1b2433}
.lh-license{font-size:.74em;font-weight:600;color:#6b7585}
.lh-logo{display:grid;place-items:center;width:4.6em;height:4.6em;flex-shrink:0}
.lh-logo img{width:100%;height:100%;object-fit:contain}
.lh-monogram{width:100%;height:100%;border-radius:50%;display:grid;place-items:center;border:.14em solid var(--lh-color);box-shadow:inset 0 0 0 .22em #fff,inset 0 0 0 .3em var(--lh-color);color:var(--lh-color);font-size:1.9em;font-weight:800;line-height:1}
.lh-contacts{display:flex;flex-wrap:wrap;gap:.35em 1.4em;font-size:.74em;font-weight:600;color:#3c4657}
.lh-contact{display:inline-flex;align-items:center;gap:.5em}
.lh-contact i{color:var(--lh-color);font-size:.9em}
.lh-foot{display:flex;flex-direction:column;align-items:center;gap:.45em;padding-top:.8em}
.lh-note{font-size:.68em;color:#6b7585;font-weight:600;text-align:center}

/* Classic bilingual */
.lh-head.lh-classic{grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);border-bottom:.28em double var(--lh-color)}
.lh-english{display:flex;flex-direction:column;gap:.15em;text-align:left;font-family:Cairo,Georgia,serif}
.lh-english strong{font-size:.95em;font-weight:800;color:var(--lh-color);line-height:1.45}
.lh-english small{font-size:.72em;font-weight:600;color:#6b7585}
.lh-foot.lh-classic{border-top:.28em double var(--lh-color)}

/* Modern */
.lh-head.lh-modern{grid-template-columns:minmax(0,1fr) auto;border-top:.55em solid var(--lh-color);padding-top:1.1em;border-bottom:1px solid #d5dbe5}
.lh-brand{display:flex;align-items:center;gap:1em;min-width:0}
.lh-modern .lh-logo{width:4em;height:4em}
.lh-head.lh-modern .lh-contacts{flex-direction:column;gap:.3em;padding-inline-start:1.2em;border-inline-start:.2em solid var(--lh-color)}
.lh-foot.lh-modern{border-bottom:.55em solid var(--lh-color);padding-bottom:.6em;border-top:1px solid #d5dbe5}

/* Formal centered */
.lh-head.lh-minimal{justify-items:center;text-align:center;gap:.6em;border-bottom:1px solid #d5dbe5;position:relative}
.lh-head.lh-minimal::after{content:"";position:absolute;bottom:-.14em;left:50%;width:5em;height:.28em;margin-left:-2.5em;background:var(--lh-color);border-radius:1em}
.lh-minimal .lh-identity{align-items:center}
.lh-english-line{font-size:.74em;font-weight:700;color:#6b7585;letter-spacing:.02em}
.lh-foot.lh-minimal{border-top:1px solid #d5dbe5}

/* Paper content */
.paper-body{padding-top:1.6em;flex:1}
.paper-meta{display:flex;justify-content:space-between;gap:1em;font-size:.8em;font-weight:600;color:#4b5563;margin-bottom:1.4em}
.paper-title{font-size:1.05em;font-weight:800;text-align:center;margin-bottom:1.2em;color:#1b2433}
.paper-text{white-space:pre-line;font-size:.9em;line-height:2;color:#1b2433;text-align:justify}

/* Letterhead page */
.letterhead-layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.1fr);gap:20px;align-items:start}
.letterhead-form{display:flex;flex-direction:column;gap:14px}
.lh-section{padding:18px 20px}
.lh-section-title{display:flex;align-items:flex-start;gap:12px;margin-bottom:16px}
.lh-section-title>span{width:36px;height:36px;border-radius:50%;display:grid;place-items:center;background:var(--soft);color:var(--primary);flex-shrink:0}
.lh-section-title h2{font-size:16px;font-weight:800}
.lh-section-title p{font-size:13px;color:var(--muted)}
.template-options{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
.template-option{position:relative;display:flex;flex-direction:column;gap:2px;margin:0;padding:10px;border:1px solid var(--line);border-radius:12px;cursor:pointer;transition:border-color .2s,background .2s}
.template-option:hover{border-color:var(--soft-2)}
.template-option:has(input:checked){border-color:var(--primary);background:var(--soft);box-shadow:0 0 0 1px var(--primary)}
.template-option:has(input:focus-visible){outline:2px solid var(--primary);outline-offset:2px}
.template-option strong{font-size:13.5px;color:var(--ink)}
.template-option small{font-size:11.5px;color:var(--muted);font-weight:500}
.template-thumb{display:flex;align-items:center;justify-content:space-between;gap:6px;height:54px;margin-bottom:8px;padding:8px;border-radius:8px;background:#fff;border:1px solid var(--line)}
.template-thumb i{display:block;width:34%;height:14px;border-radius:3px;background:repeating-linear-gradient(#c3cddd 0 3px,transparent 3px 6px)}
.template-thumb b{display:block;width:20px;height:20px;border-radius:50%;border:2px solid var(--primary)}
.thumb-classic{border-bottom:4px double var(--primary)}
.thumb-modern{border-top:6px solid var(--primary);justify-content:flex-start}
.thumb-modern i{width:46%}
.thumb-minimal{flex-direction:column;justify-content:center;gap:4px;border-bottom:2px solid var(--primary)}
.thumb-minimal b{width:16px;height:16px}
.thumb-minimal i{width:50%;height:6px}
.color-options{display:flex;flex-wrap:wrap;gap:10px}
.color-option{position:relative;margin:0;cursor:pointer}
.color-option>span:first-of-type{display:block;width:36px;height:36px;border-radius:50%;background:var(--swatch);box-shadow:0 0 0 3px #fff,0 0 0 4px var(--line)}
.color-option:has(input:checked)>span:first-of-type{box-shadow:0 0 0 3px #fff,0 0 0 5px var(--swatch)}
.color-option:has(input:focus-visible)>span:first-of-type{outline:2px solid var(--primary);outline-offset:6px}
.lh-fields{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
.lh-field.wide{grid-column:1/-1}
.lh-field label small{font-weight:500;color:var(--faint)}
.logo-uploader{display:flex;align-items:center;gap:16px}
.logo-preview{width:84px;height:84px;padding:8px;border-radius:12px;border:1px dashed var(--line-strong);background:var(--bg);display:grid;place-items:center;font-size:12px;--lh-color:var(--primary)}
.logo-preview .lh-logo{width:100%;height:100%;font-size:12px}
.logo-actions{display:flex;flex-wrap:wrap;gap:8px}
.logo-actions label{margin:0;cursor:pointer}
.logo-actions button:disabled{opacity:.5;cursor:not-allowed}
.switch-row{position:relative;display:flex;align-items:center;gap:12px;margin:18px 0 0;padding-top:16px;border-top:1px solid var(--line);font-size:14px;cursor:pointer}
.switch-row input,.template-option input,.color-option input{position:absolute;top:0;inset-inline-start:0;width:1px;height:1px;opacity:0;margin:0}
.switch{position:relative;width:42px;height:24px;border-radius:999px;background:var(--line-strong);flex-shrink:0;transition:background .2s}
.switch::after{content:"";position:absolute;top:3px;right:3px;width:18px;height:18px;border-radius:50%;background:#fff;box-shadow:var(--shadow-sm);transition:transform .2s}
.switch-row input:checked+.switch{background:var(--primary)}
.switch-row input:checked+.switch::after{transform:translateX(-18px)}
.switch-row input:focus-visible+.switch{outline:2px solid var(--primary);outline-offset:2px}
.lh-actions{position:sticky;bottom:0;display:flex;justify-content:flex-end;flex-wrap:wrap;gap:10px;padding:14px 0;background:linear-gradient(transparent,var(--bg) 30%)}
.letterhead-preview{position:sticky;top:84px;display:flex;flex-direction:column;border:1px solid var(--line);border-radius:var(--radius);background:#e9edf3;overflow:hidden}
.preview-toolbar{display:flex;align-items:center;justify-content:space-between;padding:10px 16px;background:#fff;border-bottom:1px solid var(--line);font-size:13.5px;font-weight:700;color:var(--ink)}
.preview-toolbar i{color:var(--primary);margin-inline-end:6px}
.preview-toolbar small{color:var(--muted);font-weight:600}
.paper-stage{padding:22px;container-type:inline-size}
.paper{display:flex;flex-direction:column;aspect-ratio:210/297;padding:2.6em 3em 2em;background:#fff;box-shadow:0 14px 30px -16px rgba(16,24,40,.35);font-size:2.05cqw;overflow:hidden}
.paper .lh-foot{margin-top:auto}

/* Print: only the prepared sheet */
.print-root{display:none}
@media print{
  @page{size:A4;margin:14mm 16mm 12mm}
  html,body{background:#fff!important}
  body>*:not(.print-root){display:none!important}
  .print-root{display:block;font-family:Cairo,Tahoma,sans-serif;font-size:11.5pt;color:#000}
  .print-sheet{width:100%;border-collapse:collapse}
  .print-sheet td{padding:0;border:0;white-space:normal;text-align:start!important;font-weight:400}
  .print-sheet thead .lh-head{margin-bottom:6mm}
  .print-foot{position:fixed;left:0;right:0;bottom:0;background:#fff}
  .print-foot-space{height:24mm}
  .paper-body{padding-top:0}
  .paper-text{font-size:1em;line-height:2}
  .print-pdf-page{display:flex;flex-direction:column;align-items:center;justify-content:space-between;height:270mm;break-after:page;page-break-after:always}
  .print-pdf-page:last-child{break-after:auto;page-break-after:auto}
  .print-pdf-page img{display:block;max-width:100%;max-height:259mm;object-fit:contain;border:.2mm solid #e5e9f0}
  .print-pdf-caption{display:flex;justify-content:space-between;gap:6mm;width:100%;margin-top:2.5mm;padding-top:2mm;border-top:.3mm solid #d5dbe5;font-size:8pt;font-weight:600;color:#6b7585}
}

@media (max-width:1100px){
  .letterhead-layout{grid-template-columns:minmax(0,1fr)}
  .letterhead-preview{position:static;order:-1}
}
@media (max-width:720px){
  .template-options{grid-template-columns:minmax(0,1fr)}
  .template-option{flex-direction:row;flex-wrap:wrap;align-items:center;gap:4px 12px}
  .template-thumb{width:96px;margin:0}
  .lh-fields{grid-template-columns:minmax(0,1fr)}
  .lh-section{padding:16px}
  .paper-stage{padding:12px}
  .lh-actions .button{flex:1}
}
