@media print {
    @page { 
        size: letter landscape; 
        margin: 0; 
    }
    
    body { 
        background: white; 
        -webkit-print-color-adjust: exact; 
        print-color-adjust: exact;
        display: block; 
        margin: 0;
        padding: 0;
    }
    
    #web-interface { display: none !important; }
    #print-layer { display: block !important; width: 100%; height: 100%; }

    .print-page {
        width: 27.94cm;
        height: 21.59cm;
        page-break-after: always;
        position: relative;
        background: white;
        overflow: hidden;
        box-sizing: border-box;
    }

    /* --- LAYOUT EN CM --- */
    .print-header {
        position: absolute;
        top: 0.5cm;      
        left: 0.5cm; 
        right: 0.5cm; 
        height: 1.5cm;
        border-bottom: 2px solid #C3A26E; 
        display: flex; justify-content: space-between; align-items: center;
        z-index: 10;
    }

    .print-content {
        position: absolute;
        top: 2.2cm;      
        bottom: 1.2cm;   
        left: 0.5cm;    
        right: 0.5cm;
        display: flex; 
        justify-content: center; 
        align-items: center; 
        overflow: hidden;
        width: auto;
        height: auto;
    }

    .print-footer {
        position: absolute;
        bottom: 0.5cm;   
        left: 0.5cm; 
        right: 0.5cm;
        border-top: 1px solid #ccc; padding-top: 2px;
        display: flex; justify-content: space-between;
        font-size: 8pt; color: #666;
        z-index: 10;
    }

    /* Portada */
    .cover-page {
        display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
        border: 15px solid #0B3E23;
        height: 21.59cm; 
        padding: 0;
    }
    .cover-title { font-size: 3rem; color: #0B3E23; font-weight: 800; margin-bottom: 10px; }
    .cover-subtitle { font-size: 1.5rem; color: #C3A26E; text-transform: uppercase; letter-spacing: 4px; }

    .toc-container {
        position: absolute; 
        top: 3.5cm; 
        bottom: 3cm; 
        left: 1.5cm; 
        right: 1.5cm;
        padding: 20px 0; column-count: 2; column-gap: 60px;
    }

    /* --- ÁRBOL DE IMPRESIÓN --- */
    .print-content .tree {
        display: inline-block !important;
        width: max-content !important;
        margin: 0 auto;
    }
    
    .print-content .tree ul {
        display: flex !important;
        flex-wrap: nowrap !important;
        justify-content: center;
        padding-top: 25px; 
        position: relative;
    }
    
    .print-content .tree li {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        flex: 0 0 auto;
        padding: 10px 1px;
        position: relative;
    }

    /* Conectores */
    .print-content .tree li::before, 
    .print-content .tree li::after {
        content: ''; position: absolute; top: 0; right: 50%;
        border-top: 1px solid #000 !important; 
        width: 50%; height: 25px; 
        z-index: 0;
    }
    .print-content .tree li::after { 
        right: auto; left: 50%; 
        border-left: 1px solid #000 !important;
    }
    .print-content .tree li:only-child::after, 
    .print-content .tree li:only-child::before { display: none; }
    .print-content .tree li:only-child { padding-top: 0; }
    .print-content .tree li:first-child::before, 
    .print-content .tree li:last-child::after { border: 0 none !important; }
    .print-content .tree li:last-child::before { 
        border-right: 1px solid #000 !important; border-radius: 0 10px 0 0; 
    }
    .print-content .tree li:first-child::after { 
        border-radius: 10px 0 0 0; 
    }
    .print-content .tree ul ul::before {
        content: ''; position: absolute; top: 0; left: 50%;
        border-left: 1px solid #000 !important; 
        width: 0; height: 25px;
        z-index: 0;
    }

    /* --- CORRECCIÓN GHOST NODE PARA PDF --- */
    .print-content .ghost-li {
        padding-top: 0 !important;
        position: relative;
    }
    .print-content .ghost-li::after { border-left: none !important; }
    
    .print-content .ghost-li > ul {
        /* Ajuste fino para alinear con tarjetas de impresión */
        padding-top: 95px !important; /* Antes 140px */
        position: relative;
    }
    
    .print-content .ghost-li > ul::before {
        content: ''; position: absolute; top: 0 !important; left: 50%;
        height: 95px !important; /* Igualar al padding-top */
        border-left: 1px solid #000 !important;
        width: 0; z-index: 0;
    }

    /* --- TARJETAS OPTIMIZADAS --- */
    .print-content .card {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        box-shadow: none !important;
        border: 1px solid #666 !important;
        background: white !important;
        border-radius: 4px;
        
        width: 100px !important; 
        min-height: auto !important;
        padding: 4px 2px !important; 
        
        position: relative;
        z-index: 5;
    }
    
    .print-content .card-role { 
        color: #0B3E23 !important; 
        font-size: 8pt !important; 
        font-weight: 700 !important;
        margin-bottom: 2px !important; 
        line-height: 1.1 !important;
        
        white-space: normal !important;
        word-wrap: break-word !important;
        hyphens: auto;
    }
    
    .print-content .card-name { 
        color: #000 !important; 
        font-size: 7.5pt !important; 
        font-weight: 500 !important;
        padding-top: 2px !important; 
        border-top: 0.5px solid #ccc !important; 
        line-height: 1.1 !important;
        white-space: normal !important;
    }
    
    .print-content .type-root { 
        background-color: #0B3E23 !important; 
        border: 1px solid #000 !important; 
    }
    .print-content .type-root .card-role,
    .print-content .type-root .card-name { color: white !important; border-color: rgba(255,255,255,0.3) !important; }
    
    .toc-item { break-inside: avoid; border-bottom: 1px dotted #999; }
}