/* Documento CdC — frontend styles */
:root {
    --doccdc-ink: #2a2320;
    --doccdc-parchment: #fdfbf7;
    /* Rainbow palette for headings */
    --doccdc-r1: #e53935; /* red */
    --doccdc-r2: #fb8c00; /* orange */
    --doccdc-r3: #f4b400; /* yellow-gold */
    --doccdc-r4: #43a047; /* green */
    --doccdc-r5: #1e88e5; /* blue */
    --doccdc-r6: #3949ab; /* indigo */
    --doccdc-r7: #8e24aa; /* violet */
}

body .doccdc-document { color: var(--doccdc-ink); }

.doccdc-document { max-width: 880px; margin: 2rem auto; padding: 0 1rem; line-height: 1.55; }

/* PDF header banner — shown only on the first page.
   Sits inside the natural content flow at the very top, so it appears on
   page 1 and never repeats on subsequent pages. */
.doccdc-pdf-header {
    margin: 0 0 24px;
    text-align: center;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.doccdc-pdf-header img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    border-bottom: 1px solid #cfc9bd;
    padding-bottom: 8px;
}
@media print {
    .doccdc-pdf-header {
        margin: 0 0 14px;
        page-break-after: avoid;
        break-after: avoid;
    }
    .doccdc-pdf-header img {
        border-bottom: 0.5pt solid #999;
    }
}
.doccdc-eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .8rem; color: var(--doccdc-r1); font-weight: 600; margin: 0 0 .25rem; }
.doccdc-title {
    font-size: 2.4rem; margin: 0 0 1rem; font-weight: 800; line-height: 1.15;
    background: linear-gradient(90deg, var(--doccdc-r1), var(--doccdc-r2), var(--doccdc-r3), var(--doccdc-r4), var(--doccdc-r5), var(--doccdc-r6), var(--doccdc-r7));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.doccdc-meta-grid { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; padding: 1rem 1.25rem; border: 1px solid #e5e5e5; border-radius: 8px; background: #fafafa; }
.doccdc-meta-grid dt { font-weight: 600; }
.doccdc-meta-grid dd { margin: 0; }

.doccdc-section { margin: 2.25rem 0; }
.doccdc-section > h2 {
    font-size: 1.4rem; padding-bottom: .35rem; margin-bottom: .9rem; font-weight: 800;
    border-bottom: 3px solid currentColor;
}
/* Rainbow cycle for section headings (h2) */
.doccdc-document .doccdc-section:nth-of-type(7n+1) > h2 { color: var(--doccdc-r1); }
.doccdc-document .doccdc-section:nth-of-type(7n+2) > h2 { color: var(--doccdc-r2); }
.doccdc-document .doccdc-section:nth-of-type(7n+3) > h2 { color: var(--doccdc-r3); }
.doccdc-document .doccdc-section:nth-of-type(7n+4) > h2 { color: var(--doccdc-r4); }
.doccdc-document .doccdc-section:nth-of-type(7n+5) > h2 { color: var(--doccdc-r5); }
.doccdc-document .doccdc-section:nth-of-type(7n+6) > h2 { color: var(--doccdc-r6); }
.doccdc-document .doccdc-section:nth-of-type(7n+7) > h2 { color: var(--doccdc-r7); }
.doccdc-page-ref { color: inherit; opacity: .75; font-size: .82em; white-space: nowrap; font-weight: 600; }
.doccdc-section-body { font-size: 1rem; text-align: justify; hyphens: auto; }
.doccdc-scheda-grid dd { text-align: justify; hyphens: auto; }

/* Indice (TOC) */
.doccdc-toc { page-break-after: always; break-after: page; }
.doccdc-toc-list { list-style: decimal inside; padding: 0; margin: 0; counter-reset: toc; }
.doccdc-toc-list li {
    padding: 0; margin: 0;
    border-bottom: 1px dotted #d0d0d0;
    font-size: .98rem;
}
.doccdc-toc-link {
    display: flex; align-items: baseline; gap: .5rem;
    padding: .45rem 0;
    text-decoration: none; color: inherit;
    transition: background-color .15s ease;
}
.doccdc-toc-link:hover { background: #f4f6ff; color: var(--doccdc-r5); }
.doccdc-toc-title { font-weight: 600; flex: 0 1 auto; }
.doccdc-toc-dots { flex: 1 1 auto; border-bottom: 2px dotted #b8b8b8; transform: translateY(-4px); min-width: 1rem; }
.doccdc-toc-page { flex: 0 0 auto; font-variant-numeric: tabular-nums; color: #555; font-weight: 600; }

.doccdc-table { width: 100%; border-collapse: collapse; margin: .5rem 0 1rem; font-size: .95rem; }
.doccdc-table th, .doccdc-table td { border: 1px solid #d8d8d8; padding: .55rem .7rem; vertical-align: top; text-align: left; }
.doccdc-table th { background: #f1f1f1; }

.doccdc-scheda { border: 1px solid #e2e2e2; border-radius: 8px; padding: 1rem 1.25rem; margin: 1rem 0; background: #fff; border-top: 5px solid var(--doccdc-r1); }
.doccdc-scheda h3 { margin: 0 0 .75rem; font-size: 1.15rem; font-weight: 800; color: var(--doccdc-r1); }
/* Rainbow cycle for schede headings */
.doccdc-scheda:nth-of-type(7n+1) { border-top-color: var(--doccdc-r1); } .doccdc-scheda:nth-of-type(7n+1) h3 { color: var(--doccdc-r1); }
.doccdc-scheda:nth-of-type(7n+2) { border-top-color: var(--doccdc-r2); } .doccdc-scheda:nth-of-type(7n+2) h3 { color: var(--doccdc-r2); }
.doccdc-scheda:nth-of-type(7n+3) { border-top-color: var(--doccdc-r3); } .doccdc-scheda:nth-of-type(7n+3) h3 { color: var(--doccdc-r3); }
.doccdc-scheda:nth-of-type(7n+4) { border-top-color: var(--doccdc-r4); } .doccdc-scheda:nth-of-type(7n+4) h3 { color: var(--doccdc-r4); }
.doccdc-scheda:nth-of-type(7n+5) { border-top-color: var(--doccdc-r5); } .doccdc-scheda:nth-of-type(7n+5) h3 { color: var(--doccdc-r5); }
.doccdc-scheda:nth-of-type(7n+6) { border-top-color: var(--doccdc-r6); } .doccdc-scheda:nth-of-type(7n+6) h3 { color: var(--doccdc-r6); }
.doccdc-scheda:nth-of-type(7n+7) { border-top-color: var(--doccdc-r7); } .doccdc-scheda:nth-of-type(7n+7) h3 { color: var(--doccdc-r7); }
.doccdc-scheda-grid { display: grid; grid-template-columns: minmax(180px, 220px) 1fr; gap: .35rem 1rem; margin: 0; }
.doccdc-scheda-grid dt { font-weight: 600; }
.doccdc-scheda-grid dd { margin: 0; }
@media (max-width: 600px) {
    .doccdc-meta-grid, .doccdc-scheda-grid { grid-template-columns: 1fr; }
    .doccdc-scheda-grid dt { margin-top: .5rem; }
}

.doccdc-footer { margin-top: 2.5rem; font-style: italic; }
.doccdc-list { list-style: none; padding: 0; }
.doccdc-list li { padding: .5rem 0; border-bottom: 1px solid #eee; }
.doccdc-list-meta { color: #666; font-size: .9rem; }

/* Toolbar */
.doccdc-toolbar { display: flex; justify-content: flex-end; margin: 0 0 1rem; }
.doccdc-print-btn {
    background: #222; color: #fff; border: 0; border-radius: 6px;
    padding: .55rem 1rem; font-size: .9rem; cursor: pointer;
}
.doccdc-print-btn:hover { background: #000; }

/* Hint sotto il pulsante di stampa */
.doccdc-print-hint {
    margin: 0 0 1.5rem;
    padding: 10px 14px;
    background: #fff8e1;
    border-left: 3px solid #f4b400;
    border-radius: 0 6px 6px 0;
    color: #5a4a1a;
    font-size: .88rem;
    line-height: 1.5;
}
.doccdc-print-hint strong { color: #8a6d1a; }
.doccdc-print-hint em { font-style: normal; font-weight: 600; background: #fff; padding: 1px 5px; border-radius: 3px; border: 1px solid #e6d29a; }

/* Print: clean PDF-friendly output */
@page {
    size: A4;
    /* Margini più ampi in alto/basso per far posto a header/footer custom */
    margin: 22mm 15mm 20mm;

    /* Header di ogni pagina: solo il titolo del documento.
       Chrome 131+, Safari 18.2+ e altri motori Paged Media supportano
       le margin box con `content`. Firefox le ignora e mostrerà nulla. */
    @top-center {
        content: string(doctitle);
        font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
        font-size: 9pt;
        color: #666;
        vertical-align: bottom;
        padding-bottom: 4mm;
    }

    /* Footer di ogni pagina: solo il numero di pagina. */
    @bottom-center {
        content: "Pagina " counter(page) " di " counter(pages);
        font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
        font-size: 9pt;
        color: #666;
        vertical-align: top;
        padding-top: 3mm;
    }
}

/* Sulla prima pagina il titolo è già visibile nel body: evitiamo di ripeterlo in header. */
@page :first {
    @top-center { content: none; }
}

@media print {
    /* Imposta la stringa "doctitle" a partire dal titolo del documento
       (viene ripetuta nel @top-center di ogni pagina successiva). */
    .doccdc-title { string-set: doctitle content(text); }

    body { background: #fff !important; color: #000 !important; font-size: 11pt; }
    .no-print,
    header.site-header, footer.site-footer,
    #wpadminbar, .site-header, .site-footer,
    nav, aside, .sidebar, .widget-area,
    .doccdc-toolbar { display: none !important; }
    .doccdc-document { max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
    .doccdc-section { page-break-inside: avoid; break-inside: avoid; margin: 1.2rem 0; }
    .doccdc-title, .doccdc-section > h2, .doccdc-scheda h3, .doccdc-eyebrow { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .doccdc-section > h2 { border-bottom: 1.5pt solid currentColor; }

    .doccdc-scheda { page-break-inside: avoid; break-inside: avoid; border-color: #888; background: #fff; }
    .doccdc-table { font-size: 10pt; }
    .doccdc-table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    a { color: #000; text-decoration: none; }
    /* TOC anche in stampa: link neri, senza sfondo */
    .doccdc-toc-link { color: #000 !important; background: transparent !important; }
}

/* UDA section */
.doccdc-uda-intro { font-size: 1.05em; margin: 0 0 18px; text-align: justify; }
.doccdc-uda-table { width: 100%; border-collapse: collapse; margin: 0 0 22px; page-break-inside: avoid; break-inside: avoid; }
.doccdc-uda-table th, .doccdc-uda-table td { border: 1px solid #b8a888; padding: 10px 14px; vertical-align: top; text-align: left; }
.doccdc-uda-table th { width: 32%; background: #f4ead8; font-weight: 600; color: #6b2c1a; }
.doccdc-uda-table td { text-align: justify; background: #fffdf7; }
@media print {
  .doccdc-uda-table th { background: #f4ead8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Schede disciplinari */
.doccdc-scheda h4 { margin: 1rem 0 .35rem; font-size: 1rem; font-weight: 700; }
.doccdc-scheda-body { text-align: justify; hyphens: auto; margin: 0 0 .5rem; }
.doccdc-moduli-table th { background: #f1f1f1; }
.doccdc-firma-block { margin-top: 1.2rem; display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; }
.doccdc-firma-label { font-weight: 600; font-size: .9rem; color: #555; }
.doccdc-firma-img { max-height: 80px; width: auto; }

/* Griglia valutazione competenze trasversali */
.doccdc-griglia-trasversali { table-layout: fixed; }
.doccdc-griglia-trasversali th, .doccdc-griglia-trasversali td { border: 1px solid #333; padding: 10px 8px; vertical-align: top; text-align: center; }
.doccdc-griglia-trasversali thead th { background: #f1f1f1; font-weight: 700; }
.doccdc-griglia-punteggio { display: inline-block; margin-top: 4px; font-weight: 700; }
.doccdc-griglia-descrittore { text-align: left; font-weight: 700; background: #fafafa; }
.doccdc-griglia-formula { text-align: left; font-style: italic; }
.doccdc-griglia-totale { text-align: right; font-weight: 700; }

/* Simulazione — PDF allegati */
.doccdc-pdf-list { list-style: none; margin: 12px 0 0; padding: 0; }
.doccdc-pdf-list li { margin: 4px 0; }
.doccdc-pdf-link { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid #d0d5dd; border-radius: 6px; text-decoration: none; background: #fafafa; }
.doccdc-pdf-link:hover { background: #f0f4ff; }

/* Slot per PDF incorporati DENTRO la sezione di simulazione */
.doccdc-pdf-embed-slot { margin-top: 8px; }
.doccdc-pdf-embed-slot:empty { display: none; }
.doccdc-embedded-pdf { margin-top: 16px; page-break-before: always; break-before: page; }
.doccdc-embedded-file-title {
    font-size: 1.05rem; font-weight: 700; margin: 0 0 10px;
    padding-bottom: .3rem; border-bottom: 1px dashed #b8b8b8;
    color: #444;
}
.doccdc-embedded-page {
    display: block;
    width: 100%;
    height: auto;
    margin: 0 auto 16px;
    page-break-inside: avoid;
    break-inside: avoid;
    page-break-after: always;
    break-after: page;
}
.doccdc-embedded-page:last-child { page-break-after: auto; break-after: auto; }

/* A schermo: nascondi lo slot dopo il rendering se ci sono immagini pesanti */
@media screen {
    .doccdc-pdf-embed-slot .doccdc-embedded-pdf { border: 1px dashed #ddd; padding: 8px; margin-top: 12px; }
}

@media print {
    /* Non stampare i link ai PDF: sono già incorporati come pagine */
    .doccdc-simulazione .doccdc-pdf-list,
    .doccdc-allegato-extra .doccdc-pdf-list { display: none !important; }
    /* Le sezioni simulazione/allegati con embed devono poter attraversare più pagine */
    .doccdc-simulazione,
    .doccdc-allegato-extra { page-break-inside: auto; break-inside: auto; }
    .doccdc-embedded-pdf { page-break-inside: auto; break-inside: auto; }
    .doccdc-embedded-file-title { color: #000 !important; }
}

/* Allegato con file immagine (invece che PDF): stampa l'immagine centrata */
.doccdc-allegato-image {
    text-align: center;
    margin-top: 16px;
    page-break-inside: avoid;
    break-inside: avoid;
}
.doccdc-allegato-image img {
    max-width: 100%;
    height: auto;
    display: inline-block;
    border: 1px solid #cfc9bd;
}

/* Classe di misurazione: usata SOLO al momento del calcolo dei numeri di pagina
   dell'INDICE, forza una larghezza vicina a quella di stampa A4 per rendere
   l'offsetTop dei blocchi rappresentativo del PDF finale. */
.doccdc-measuring .doccdc-document {
    max-width: 180mm !important;
    width: 180mm !important;
    margin: 0 auto !important;
    padding: 0 !important;
    font-size: 11pt !important;
}
.doccdc-measuring .doccdc-toolbar { display: none !important; }
