@media print {

    /* --- PAGE SETUP --- */
    @page {
        size: A4 portrait;
        margin: 1.5cm 1cm 1.5cm 1cm;
        /* Increased top/bottom for header/footer */
        marks: none;
    }

    /* --- GLOBAL RESETS --- */
    body {
        display: block;
        background-color: white;
        color: black;
        font-family: 'Roboto', sans-serif;
        font-size: 8pt !important;
        line-height: 1.3 !important;
        width: 100%;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Explicit overrides for elements with fixed px in style.css */
    p,
    ul,
    li,
    td,
    th {
        font-size: 8pt !important;
        line-height: 1.3 !important;
    }

    h1 {
        font-size: 20pt !important;
    }

    h2 {
        font-size: 16pt !important;
    }

    h3 {
        font-size: 12pt !important;
    }

    /* --- HIDE UI ELEMENTS --- */
    .sidebar,
    .sidebar-bottom,
    .skip-link,
    .switch-container,
    .theme-buttons,
    .nav-item,
    .low-sat-warning,
    #snapshot-controls,
    #snapshot-overlay,
    button {
        display: none !important;
    }

    /* --- MAIN CONTENT & SLIDES --- */
    .main-content {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        overflow: visible !important;
    }

    .slide {
        display: block !important;
        opacity: 1 !important;
        position: relative !important;
        page-break-before: always;
        padding-top: 10px;
        clear: both;
    }

    /* Fix for Slide 6 (Dynamic Content) */
    #qi-page-container {
        display: block !important;
        width: 100% !important;
    }

    #qi-page-container>div {
        display: block !important;
        page-break-inside: avoid;
        /* Prevent breaking simplified blocks */
        margin-bottom: 25px;
        border-bottom: 1px dashed #eee;
        /* Visual separator */
        padding-bottom: 15px;
    }

    /* First page (Copertina) handling */
    #copertina {
        page-break-before: avoid !important;
        page-break-after: always;
        /* Ensure it ends the page */
        margin-top: 0 !important;
        height: 180mm;
        /* Safe height for A4 Landscape (210mm - margins) */
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        /* Center horizontally too */
    }

    #copertina h1 {
        font-size: 20pt;
        /* Smaller font */
        border-bottom: none;
        color: #009640;
        margin-bottom: 15px;
        text-align: center;
    }

    #copertina img {
        max-height: 90px;
        /* Reduced logo size */
        width: auto;
        margin-bottom: 15px;
    }

    #copertina .card {
        border: none !important;
        box-shadow: none !important;
        margin-bottom: 0 !important;
    }

    /* Stats rows in copertina */
    #copertina .grid-50 {
        gap: 10px;
        margin-top: 20px;
    }

    /* ... dashboard hiding ... */
    #dashboard {
        display: none !important;
    }

    /* ... typography ... */

    /* Charts */
    /* --- CHART SWAPPING FOR PRINT --- */
    .no-print {
        display: none !important;
    }

    .print-only {
        display: block !important;
        width: 100% !important;
        max-width: 800px;
        /* Sensible max width for A4 */
        height: auto !important;
        margin: 0 auto;
    }

    .chart-wrapper {
        display: block;
        height: auto !important;
        max-height: 350px;
        /* Reduced from default to fit better */
        width: 100% !important;
        position: relative;
        background-color: white !important;
        page-break-inside: avoid;
        margin-bottom: 20px !important;
        padding: 5px !important;
        border: none !important;
        box-shadow: none !important;
    }

    /* --- PIE CHART SIDE-BY-SIDE --- */
    .pie-container {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    .pie-chart-area {
        flex: 0 0 35% !important;
        max-width: 250px !important;
    }

    .custom-legend-container {
        flex: 1 !important;
        margin-left: 15px !important;
    }

    .custom-legend-table {
        font-size: 8pt !important;
        width: 100% !important;
    }

    .custom-legend-table td {
        padding: 2px 4px !important;
    }

    /* --- TABLES --- */
    table {
        width: 100%;
        border-collapse: collapse;
        font-size: 10pt;
        margin-bottom: 10px;
        page-break-inside: avoid;
        border: none !important;
        /* No outer border */
    }

    th,
    td {
        padding: 6px 8px !important;
        border: none !important;
        /* NO VISIBLE BORDERS as requested */
        text-align: left;
    }

    th {
        background-color: #2c3e50 !important;
        color: white !important;
        font-weight: bold;
        font-size: 9pt;
    }

    /* Numeric columns right aligned usually looks better */
    td:not(:first-child),
    th:not(:first-child) {
        text-align: center;
    }

    /* Preserve row background colors - Forza stampa colori */
    tr.area-media-nazionale-light,
    tr.area-media-nazionale,
    tr.area-riciclo,
    tr.area-audit,
    tr.area-amministrazione,
    tr.area-comunicazione,
    tr.area-sistemi,
    tr.area-segreteria,
    tr.area-rd,
    tr.cat-convenzionati,
    tr.cat-piattaforme,
    tr.cat-cartiere,
    tr.total-row {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    /* Forza stampa colori anche sulle celle */
    table tr td,
    table tr th {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    /* --- DEFINIZIONE ESPLICITA COLORI PER STAMPA --- */
    /* Riga Media - Opacità aumentata per visibilità stampa */
    tr.area-media-nazionale-light {
        background-color: rgba(0, 102, 153, 0.08) !important;
    }

    tr.area-media-nazionale {
        background-color: rgba(0, 102, 153, 0.15) !important;
    }

    /* Modalità Azienda - Verde schiarito per stampa */
    body.view-mode-company tr.area-media-nazionale {
        background-color: rgba(0, 150, 80, 0.15) !important;
        /* Verde più chiaro rispetto al web (#006837) */
    }

    /* Aree Operative - Opacità 0.08 per stampa */
    tr.area-riciclo {
        background-color: rgba(39, 174, 96, 0.08) !important;
    }

    tr.area-audit {
        background-color: rgba(243, 156, 18, 0.08) !important;
    }

    tr.area-amministrazione {
        background-color: rgba(41, 128, 185, 0.08) !important;
    }

    tr.area-comunicazione {
        background-color: rgba(230, 126, 34, 0.08) !important;
    }

    tr.area-sistemi {
        background-color: rgba(142, 68, 173, 0.08) !important;
    }

    tr.area-segreteria {
        background-color: rgba(149, 165, 166, 0.08) !important;
    }

    tr.area-rd {
        background-color: rgba(22, 160, 133, 0.08) !important;
    }

    /* Categorie (Tipologia) - Opacità 0.08 per stampa */
    tr.cat-convenzionati {
        background-color: rgba(102, 126, 234, 0.08) !important;
    }

    tr.cat-piattaforme {
        background-color: rgba(79, 172, 254, 0.08) !important;
    }

    tr.cat-cartiere {
        background-color: rgba(250, 112, 154, 0.08) !important;
    }

    /* Riga Totale */
    tr.total-row {
        background-color: rgba(241, 241, 241, 1) !important;
    }

    /* --- RESET SELETTIVO DEGLI SFONDI (NON le tabelle!) --- */
    body,
    html,
    .main-content,
    .slide,
    .chart-wrapper,
    section,
    div:not(.table-container):not(.compact-table),
    p,
    h1,
    h2,
    h3,
    h4 {
        background-color: transparent !important;
    }

    /* Sfondo bianco per elementi principali */
    body,
    html,
    .main-content,
    .slide {
        background-color: #ffffff !important;
        background: #ffffff !important;
    }

    /* --- COVER PAGE FIX (SINGLE PAGE) --- */
    #copertina {
        page-break-before: avoid !important;
        page-break-after: always !important;
        margin: 0 !important;
        padding: 0 !important;
        height: 100vh !important;
        /* Use viewport height to fill page */
        min-height: 180mm;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
    }

    #copertina h1 {
        margin-top: 0 !important;
        font-size: 20pt !important;
        /* Smaller title */
        margin-bottom: 15px !important;
    }

    #copertina img {
        max-height: 70px !important;
        /* Smaller logo */
    }

    #copertina .grid-50 {
        margin-top: 10px !important;
        gap: 15px !important;
    }

    /* --- COMPACT COMMENTS SECTION --- */
    #conclusioni .quote-box {
        font-size: 9pt !important;
        /* Smaller font */
        padding: 5px 10px !important;
        margin-bottom: 5px !important;
        border-left-width: 3px !important;
        break-inside: avoid !important;
    }

    #conclusioni .quote-author {
        font-size: 8pt !important;
        margin-top: 2px !important;
    }

    /* Use 4 columns for comments container */
    #conclusioni div[style*="columns: 2"] {
        column-count: 4 !important;
        column-gap: 10px !important;
    }

    /* Ensure comments title doesn't break flow badly */
    #conclusioni h2 {
        margin-top: 10px !important;
        margin-bottom: 10px !important;
        font-size: 14pt !important;
        page-break-after: avoid;
    }

    /* --- VIEW MODES --- */
    body.view-mode-respondent .view-company-only {
        display: none !important;
    }

    body.view-mode-company .view-respondent-only {
        display: none !important;
    }

    /* --- PRINT AESTHETICS REFINEMENTS --- */

    /* 1. Reduce Card Size in Chapter 4 (and generally) */
    /* 1. Reduce Card Size in Chapter 4 (and Chapter 6) */
    .area-card,
    /* Target Ch.6 Cards (generic div with specific inline styles or unique parent) */
    #qualitativa div[style*="background: white; border-radius: 8px;"] {
        padding: 5px !important;
        /* Minimal padding */
        border: 1px solid #eee !important;
        box-shadow: none !important;
        page-break-inside: avoid;
        margin-bottom: 10px !important;
    }

    .area-card h4,
    #qualitativa div[style*="background: white"] h3 {
        font-size: 14px !important;
        margin-bottom: 2px !important;
    }

    .area-card div[style*="font-size: 32px"],
    #qualitativa div[style*="background: white"] div[style*="font-size: 2.5em"] {
        font-size: 18px !important;
        /* Smaller big number */
        margin: 2px 0 !important;
    }

    /* Hide large icons/emojis in Ch.6 cards for print to save space */
    #qualitativa div[style*="background: white"] div[style*="font-size: 2em"] {
        display: none !important;
    }

    .area-stats {
        margin-top: 5px !important;
    }

    .stat-box .stat-val {
        font-size: 12px !important;
    }

    .stat-box .stat-lbl {
        font-size: 10px !important;
    }

    /* 2. Collapse Padding & Remove Radius Globally */
    .chart-wrapper,
    .table-container,
    .card,
    .text-box,
    .area-card {
        border-radius: 0 !important;
        box-shadow: none !important;
        border: none !important;
        /* Borders removed as requested */
    }

    .chart-wrapper {
        padding: 0 !important;
        /* Zero padding for charts */
        margin-bottom: 10px !important;
    }

    .table-container {
        padding: 0 !important;
        /* Zero padding for tables */
        margin-bottom: 10px !important;
    }

    table {
        margin-bottom: 0 !important;
    }

    th,
    td {
        padding: 4px 6px !important;
        /* Tighter table cells */
    }

    /* --- BRANDING HEADER & FOOTER --- */
    #print-header {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 1.2cm;
        background: white !important;
        z-index: 1000;
    }

    .print-header-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 5px 0;
    }

    .print-header-content img {
        height: 25px;
        width: auto;
    }

    .header-line {
        width: 100%;
        height: 1px;
        background-color: #009640 !important;
        /* Comieco Green */
        margin-top: 2px;
    }

    #print-footer {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 1cm;
        background: white !important;
        z-index: 1000;
        font-size: 8pt;
        color: #666;
    }

    .footer-line {
        width: 100%;
        height: 1px;
        background-color: #ddd !important;
        margin-bottom: 5px;
    }

    .print-footer-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* Page Counter Hack for Chrome/Edge PDF */
    body {
        counter-reset: page;
    }

    .slide {
        counter-increment: page;
    }

    .page-counter::after {
        content: "Pagina " counter(page);
    }

    /* Adjust main content for header/footer */
    .slide {
        padding-top: 0.5cm !important;
    }
}