/* ═══════════════════════════════════════════════════════════════
   SBLA — Feuille de style de l'export PDF
   ---------------------------------------------------------------
   Le PDF n'est PAS une impression du site : ExportModule construit
   un document dédié (#pdf-doc) composé de pages A4 fixes, et cette
   feuille masque tout le reste à l'impression.

   • Géométrie : @page sans marge + pages de 296 mm → le nombre de
     feuilles imprimées est exactement le nombre de .pdf-page (2 ou 3).
     Marges 0 : Chrome n'a plus de place pour ses en-têtes/pieds
     (URL, date) qui pollueraient la mise en page.
   • Robustesse : les informations portées par un fond coloré sont
     toujours doublées par du texte ou un tracé SVG, pour rester
     lisibles si l'utilisateur imprime sans « Graphiques d'arrière-plan ».
   • Aperçu écran (dev) : ExportModule.preview() pose .pdf-preview sur
     <body> et affiche les pages à l'écran, sans imprimer.
   ═══════════════════════════════════════════════════════════════ */

#pdf-doc {
    display: none;

    /* Palette autonome (mêmes valeurs que app.css, sans dépendre de la cascade). */
    --pdf-ink: #1d3540;
    --pdf-ink-2: #53676f;
    --pdf-muted: #8598a0;
    --pdf-line: #dde5e9;
    --pdf-line-soft: #edf2f4;
    --pdf-surface: #f7fafb;
    --pdf-accent: #c81e3a;
    --pdf-green: #2e7d5b;
    --pdf-orange: #a9791f;
    --pdf-red: #c0463b;

    --pdf-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', system-ui, sans-serif;
    --pdf-mono: ui-monospace, 'SF Mono', 'SFMono-Regular', 'Cascadia Code', 'Roboto Mono', Menlo, monospace;
}

/* ─────────────────────────── Page A4 ─────────────────────────── */
.pdf-page {
    box-sizing: border-box;
    width: 210mm;
    height: 296mm;              /* < 297 mm : évite une page blanche par arrondi */
    padding: 11mm 13mm 8mm;
    overflow: hidden;           /* garde-fou : rien ne déborde sur une 4e page */
    display: flex;
    flex-direction: column;
    background: #fff;
    color: var(--pdf-ink);
    font-family: var(--pdf-sans);
    font-size: 9pt;
    line-height: 1.38;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.pdf-page__body { flex: 1 1 auto; min-height: 0; }

/* ─────────────────── En-tête & pied de page ─────────────────── */
.pdf-head {
    display: flex;
    align-items: center;
    gap: 3mm;
    padding-bottom: 2.5mm;
    border-bottom: 0.6mm solid var(--pdf-accent);
    margin-bottom: 6mm;
}
.pdf-cross {
    position: relative;
    width: 6mm; height: 6mm;
    flex: none;
    background: var(--pdf-accent);
    border-radius: 1mm;
}
.pdf-cross::before, .pdf-cross::after {
    content: ""; position: absolute; background: #fff;
}
.pdf-cross::before { width: 2.8mm; height: 0.8mm; top: 2.6mm; left: 1.6mm; }
.pdf-cross::after  { height: 2.8mm; width: 0.8mm; left: 2.6mm; top: 1.6mm; }
.pdf-head__brand { font-size: 11pt; font-weight: 800; letter-spacing: -0.01em; }
.pdf-head__doc {
    font-size: 8pt; font-weight: 600; color: var(--pdf-ink-2);
    text-transform: uppercase; letter-spacing: 0.09em;
}
.pdf-head__sep { color: var(--pdf-line); }
.pdf-head__date { margin-left: auto; font-size: 7.5pt; color: var(--pdf-muted); }

/* Filet de rappel sur les pages 2 et 3 (plus discret que l'en-tête complet). */
.pdf-runhead {
    display: flex; gap: 3mm; align-items: baseline;
    padding-bottom: 2mm; margin-bottom: 6mm;
    border-bottom: 0.25mm solid var(--pdf-line);
    font-size: 7.5pt; color: var(--pdf-muted);
}
.pdf-runhead strong { color: var(--pdf-ink-2); font-weight: 600; }
.pdf-runhead span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-runhead__right { margin-left: auto; }

.pdf-foot {
    display: flex; gap: 4mm; align-items: baseline;
    flex: none;
    margin-top: 4mm; padding-top: 2mm;
    border-top: 0.25mm solid var(--pdf-line);
    font-size: 7pt; color: var(--pdf-muted);
}
.pdf-foot span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-foot__page { margin-left: auto; flex: none; font-variant-numeric: tabular-nums; }

/* ──────────────────── Identification de l'analyse ──────────────────── */
/* Les clamps de lignes bornent les textes de longueur libre (adresse, texte IA) :
   la page étant en overflow:hidden, mieux vaut une ellipse maîtrisée qu'un bloc
   entier repoussé hors de la feuille. */
.pdf-title {
    font-size: 16pt; font-weight: 800; line-height: 1.15;
    letter-spacing: -0.02em; margin-bottom: 1.5mm;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pdf-meta { font-size: 9pt; color: var(--pdf-ink-2); }
.pdf-meta__sep { color: var(--pdf-line); padding: 0 1mm; }
.pdf-coords { font-family: var(--pdf-mono); font-size: 7.5pt; color: var(--pdf-muted); }
.pdf-geo {
    margin-top: 2.5mm; padding: 1.6mm 2.4mm;
    border-left: 0.8mm solid var(--pdf-orange);
    background: rgba(169, 121, 31, 0.07);
    font-size: 7.5pt; color: var(--pdf-ink-2);
}
.pdf-geo--ok { border-left-color: var(--pdf-green); background: rgba(46, 125, 91, 0.07); }

/* ─────────────────────── Intertitres ─────────────────────── */
.pdf-h2 {
    display: flex; align-items: baseline; gap: 2.5mm;
    margin: 7mm 0 3mm;
    font-size: 7.5pt; font-weight: 700; color: var(--pdf-muted);
    text-transform: uppercase; letter-spacing: 0.12em;
}
.pdf-h2::after {
    content: ""; flex: 1 1 auto; height: 0.25mm; background: var(--pdf-line);
}
.pdf-h2:first-child { margin-top: 0; }

/* ────────────────────── Bloc verdict ────────────────────── */
.pdf-verdict {
    display: flex; align-items: center; gap: 6mm;
    padding: 5mm 5mm;
    border: 0.3mm solid var(--pdf-line);
    border-radius: 2mm;
    background: var(--pdf-surface);
}
.pdf-ring { width: 32mm; height: 32mm; flex: none; }
.pdf-ring__val { font-family: var(--pdf-mono); font-size: 26px; font-weight: 700; }
.pdf-ring__max { font-size: 10px; fill: var(--pdf-muted); }

.pdf-verdict__body { min-width: 0; }
.pdf-verdict__label {
    font-size: 13pt; font-weight: 800; letter-spacing: -0.01em;
    display: flex; align-items: center; gap: 2mm;
}
.pdf-dot { width: 2.6mm; height: 2.6mm; border-radius: 50%; flex: none; }
.pdf-take { margin-top: 1.5mm; font-size: 9pt; color: var(--pdf-ink); }
.pdf-profile { margin-top: 1.5mm; font-size: 7.5pt; color: var(--pdf-muted); }

/* ───────────────────── Tableau des piliers ───────────────────── */
.pdf-pillars { width: 100%; border-collapse: collapse; table-layout: fixed; }
.pdf-pillars th {
    font-size: 6.5pt; font-weight: 600; color: var(--pdf-muted);
    text-transform: uppercase; letter-spacing: 0.08em;
    text-align: right; padding: 0 0 1.2mm;
    border-bottom: 0.25mm solid var(--pdf-line);
}
.pdf-pillars th:first-child, .pdf-pillars td:first-child { text-align: left; }
.pdf-pillars td {
    padding: 2.3mm 0;
    border-bottom: 0.25mm solid var(--pdf-line-soft);
    text-align: right;
    vertical-align: middle;
}
.pdf-pillars tr:last-child td { border-bottom: 0; }
.pdf-pillars__name { font-weight: 600; }
.pdf-pillars__bar { width: 46%; padding-left: 4mm !important; padding-right: 4mm !important; }
.pdf-bar { display: block; width: 100%; height: 2.4mm; }
.pdf-pillars__score {
    width: 14mm; font-family: var(--pdf-mono); font-weight: 700; font-size: 10pt;
    font-variant-numeric: tabular-nums;
}
.pdf-pillars__score small { font-size: 6.5pt; font-weight: 400; color: var(--pdf-muted); }
.pdf-pillars__weight { width: 14mm; color: var(--pdf-ink-2); font-variant-numeric: tabular-nums; }
.pdf-pillars__lever {
    width: 16mm; font-family: var(--pdf-mono); font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.pdf-lever--up { color: var(--pdf-green); }
.pdf-lever--down { color: var(--pdf-red); }
.pdf-lever--flat { color: var(--pdf-muted); }
.pdf-note { margin-top: 2mm; font-size: 7pt; color: var(--pdf-muted); line-height: 1.35; }

/* ───────────────────── Chiffres clés (tuiles) ───────────────────── */
.pdf-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2.5mm; }
.pdf-tile {
    border: 0.3mm solid var(--pdf-line);
    border-radius: 1.5mm;
    padding: 2.8mm 2.5mm 2.4mm;
    min-height: 19mm;
    display: flex; flex-direction: column; justify-content: space-between;
}
.pdf-tile__val {
    font-family: var(--pdf-mono); font-size: 11.5pt; font-weight: 700;
    letter-spacing: -0.02em; line-height: 1.1;
    overflow-wrap: anywhere;
}
.pdf-tile__lbl {
    margin-top: 1.5mm; font-size: 6.8pt; line-height: 1.25; color: var(--pdf-ink-2);
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* ───────────────── Détail par thème (page 2) ───────────────── */
.pdf-theme { margin-bottom: 6mm; }
.pdf-theme:last-child { margin-bottom: 0; }
.pdf-theme__head {
    display: flex; align-items: center; gap: 2.5mm;
    padding-bottom: 1.2mm; margin-bottom: 2mm;
    border-bottom: 0.25mm solid var(--pdf-line);
}
.pdf-theme__title { font-size: 9.5pt; font-weight: 700; }
.pdf-theme__score {
    margin-left: auto; display: flex; align-items: center; gap: 2mm;
    font-size: 8pt; color: var(--pdf-muted);
}
.pdf-theme__score b {
    font-family: var(--pdf-mono); font-size: 9.5pt; color: var(--pdf-ink);
    font-variant-numeric: tabular-nums;
}
.pdf-theme__bar { width: 18mm; height: 2mm; }

.pdf-rows { display: grid; grid-template-columns: 1fr 1fr; column-gap: 8mm; }
.pdf-row {
    display: flex; align-items: baseline; gap: 1.5mm;
    padding: 1.4mm 0;
    border-bottom: 0.25mm solid var(--pdf-line-soft);
    font-size: 8pt;
}
.pdf-row__lbl {
    color: var(--pdf-ink-2);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pdf-row__dots { flex: 1 1 auto; border-bottom: 0.25mm dotted var(--pdf-line); }
.pdf-row__val {
    font-family: var(--pdf-mono); font-weight: 700; white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ───────────────── Réserves, méthode, sources ───────────────── */
.pdf-caveats {
    border-left: 0.8mm solid var(--pdf-orange);
    background: rgba(169, 121, 31, 0.06);
    padding: 2.4mm 3mm;
    font-size: 7.5pt; color: var(--pdf-ink-2);
}
.pdf-caveats__title { font-weight: 700; color: var(--pdf-ink); margin-bottom: 1mm; }
.pdf-caveats ul { margin: 0; padding-left: 4mm; }
.pdf-caveats li { margin-bottom: 0.6mm; }

.pdf-method { font-size: 7pt; color: var(--pdf-muted); line-height: 1.4; }
.pdf-method p { margin: 0 0 1.4mm; }
.pdf-method p:last-child { margin-bottom: 0; }
.pdf-method strong { color: var(--pdf-ink-2); }

/* ───────────────── Analyse rédigée (page 3) ───────────────── */
.pdf-lede {
    font-size: 9.5pt; line-height: 1.45;
    padding: 3mm 3.5mm;
    background: var(--pdf-surface);
    border: 0.3mm solid var(--pdf-line);
    border-radius: 1.5mm;
    display: -webkit-box; -webkit-line-clamp: 10; -webkit-box-orient: vertical; overflow: hidden;
}
.pdf-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; }
.pdf-block { margin-top: 5mm; }
.pdf-block__title {
    font-size: 7.5pt; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--pdf-muted);
    padding-bottom: 1.2mm; margin-bottom: 1.6mm;
    border-bottom: 0.25mm solid var(--pdf-line);
}
.pdf-list { margin: 0; padding: 0; list-style: none; font-size: 8.5pt; }
.pdf-list li {
    position: relative; padding-left: 4mm; margin-bottom: 1.6mm; line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.pdf-list li::before {
    content: ""; position: absolute; left: 0.6mm; top: 1.5mm;
    width: 1.6mm; height: 1.6mm; border-radius: 50%; background: var(--pdf-muted);
}
.pdf-list--good li::before { background: var(--pdf-green); }
.pdf-list--risk li::before { background: var(--pdf-red); }
.pdf-list--reco li::before { background: var(--pdf-orange); }
.pdf-para {
    font-size: 8.5pt; line-height: 1.45;
    display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}

/* ═══════════════════ Impression ═══════════════════ */
@media print {
    @page { size: A4; margin: 0; }

    /* Ne garder QUE le document PDF : tout le reste de l'app disparaît.
       Conditionné à .pdf-printing (posé par ExportModule quand la maquette est
       construite) : sans analyse en mémoire, l'impression navigateur reste
       celle de la page, jamais une feuille blanche. */
    body.pdf-printing > *:not(#pdf-doc) { display: none !important; }
    body.pdf-printing #pdf-doc { display: block !important; }

    html, body {
        background: #fff !important;
        background-image: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }
    .pdf-page {
        margin: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
        break-inside: avoid;
        break-after: page;
    }
    .pdf-page:last-child { break-after: auto; }
}

/* ═══════════ Aperçu à l'écran (dev : ExportModule.preview()) ═══════════
   Strictement @media screen : ces règles ne doivent JAMAIS fuir dans le PDF
   (fond gris + marges) si l'utilisateur imprime alors que l'aperçu est actif. */
@media screen {
    body.pdf-preview #pdf-doc {
        display: block;
        background: #6b7b83;
        padding: 8mm 0;
    }
    body.pdf-preview .pdf-page {
        margin: 0 auto 8mm;
        box-shadow: 0 2px 12px rgba(15, 23, 42, 0.35);
    }
}
