/* Ogni pannello misura le colonne sul proprio spazio, anche nei raffronti affiancati.
   La tabella mantiene le larghezze dei col numerici senza redistribuire lo spazio
   residuo sulla prima colonna: un nome lungo non può spostare le altre colonne. */
.tree-table-scroll,
.release-tree-table-wrap {
    container-type: inline-size;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    --tree-name-width: min(55cqw, max(8rem, calc(100cqw - 12rem)));
}

:is(.baseline-compare-card, .compare-rend-card, .compare-doc-tree-root) .tree-table-scroll {
    --tree-name-width: min(48cqw, max(6rem, calc(100cqw - 12rem)));
}

.tree-table-scroll > table.tree-rend-table,
.release-tree-table-wrap > table.release-tree-table {
    table-layout: fixed;
    width: max-content;
    min-width: 0;
}

.tree-table-scroll > .tree-rend-table > colgroup > col:first-child,
.release-tree-table-wrap > .release-tree-table > colgroup > col:first-child {
    width: var(--tree-name-width);
}

.tree-table-scroll > .tree-rend-table > :is(thead, tbody) > tr > :is(th, td):first-child:not([colspan]),
.release-tree-table-wrap > .release-tree-table > :is(thead, tbody) > tr > :is(th, td):first-child:not([colspan]) {
    width: var(--tree-name-width);
    max-width: var(--tree-name-width);
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
}

.tree-table-scroll :is(.wbs-tree-node-content, .budget-tree-node-content, .document-tree-node-content) {
    align-items: flex-start;
    min-width: 0;
}

.tree-table-scroll :is(.wbs-tree-node-label, .budget-tree-node-label, .document-tree-node-label) {
    flex: 0 1 auto;
    min-width: 0;
    max-width: calc(100% - 3rem);
    white-space: normal;
    overflow-wrap: anywhere;
}

.tree-table-scroll :is(.tree-toggle, .tree-node-icon, .tree-caret, .icon-action-button),
.release-tree-element > :is(button, input, i) {
    flex-shrink: 0;
}

/* I renderer gestionali e di rendicontazione usano anche etichette senza wrapper. */
.tree-rend-table > tbody > tr > td:first-child > :is(.tree-node-label, .tree-rend-node-label, .fw-semibold, span:not([class])) {
    display: inline-block;
    max-width: calc(100% - 3rem);
    vertical-align: top;
    white-space: normal;
    overflow-wrap: anywhere;
}

.tree-rend-table > tbody > tr > td:first-child > .d-flex > :is(a, span:last-child),
.release-tree-element > :is(a, span:last-child, div) {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
}

.tree-table-scroll :is(.wbs-tree-meta-label, .budget-tree-dimensioni-label, .document-tree-project-type-label, .document-tree-dimensioni-label) {
    min-width: 0;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

/* Titolo e controlli restano insieme; solo il testo si restringe e va a capo.
   Il nome storico del documentale mantiene lo stesso contratto nel renderer lazy. */
.tree-table-scroll :is(.tree-node-heading, .document-tree-node-heading) {
    display: inline-flex;
    flex: 0 1 auto;
    flex-wrap: nowrap;
    flex-shrink: 1 !important;
    align-items: baseline !important;
    min-width: 0;
    max-width: 100%;
}

.tree-node-label {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
}

.tree-toggle {
    overflow-wrap: anywhere;
}

.tree-table-scroll :is(.tree-node-heading, .document-tree-node-heading) > :is(.tree-node-label, .wbs-tree-node-label, .budget-tree-node-label, .document-tree-node-label, .tree-rend-node-label, .tree-heading-label) {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

.tree-table-scroll :is(.tree-node-heading, .document-tree-node-heading) > :not(:is(.tree-node-label, .wbs-tree-node-label, .budget-tree-node-label, .document-tree-node-label, .tree-rend-node-label, .tree-heading-label)) {
    flex-shrink: 0;
}
