
/* --- FULLSCREEN MODE FOR COMMESSE CONSUNTIVO --- */
body.fullscreen-active .sidebar {
    display: none !important;
}
body.fullscreen-active .top-header {
    display: none !important;
}
body.fullscreen-active .main-content {
    flex: 0 0 100vw !important;
    width: 100vw !important;
    max-width: 100vw !important;
}
body.fullscreen-active .views-container {
    padding: 0 !important;
}
body.fullscreen-active #view-commesse {
    padding: 20px 40px !important;
}


/* --- NUOVO HEADER CONSUNTIVO --- */
.consuntivo-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 40px);
}

.consuntivo-header {
    background: #111;
    border: 1px solid #222;
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-back-mini {
    width: 28px;
    height: 28px;
    border-radius: 50% !important;
    border: 1px solid #333 !important;
    background: #222 !important;
    color: #888 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    font-size: 12px;
}
.btn-back-mini:hover {
    background: var(--mu-accent) !important;
    color: #000 !important;
    border-color: var(--mu-accent) !important;
}

.info-main {
    display: flex;
    flex-direction: column;
}

.info-main .top-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9em;
}

.info-main .bottom-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.info-main .label { color: #555; font-weight: bold; font-size: 0.75em; }
.info-main .val { font-weight: bold; }
.info-main .sep { color: #222; }
.info-main .descr { color: #888; font-size: 0.85em; margin-left: 5px; }

.header-center {
    flex: 1;
    padding: 0 40px;
}

.orders-box {
    background: rgba(255,255,255,0.02);
    border: 1px solid #222;
    padding: 6px 12px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
}
.orders-box .label { font-size: 0.7em; color: #555; margin-bottom: 2px; }
.orders-box .val { font-family: monospace; font-size: 0.85em; color: var(--mu-blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }

.header-right {
    display: flex;
    gap: 20px;
}

.kpi-mini {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.kpi-mini .l { font-size: 0.7em; color: #555; font-weight: bold; }
.kpi-mini .v { font-size: 1.1em; font-weight: 800; }
.kpi-mini.total .v { font-size: 1.3em; line-height: 1; }

/* BARRA RICERCA ALBERO */
.tree-search-bar {
    position: relative;
    margin-bottom: 10px;
}
.tree-search-bar i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #444;
}
.tree-search-bar input {
    width: 100%;
    background: #0a0a0a;
    border: 1px solid #1a1a1a;
    border-radius: 10px;
    padding: 10px 15px 10px 40px;
    color: #eee;
    font-size: 0.9em;
    transition: all 0.2s;
}
.tree-search-bar input:focus {
    outline: none;
    border-color: var(--mu-accent);
    background: #111;
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.1);
}

.tree-table-wrapper {
    flex: 1;
    overflow: auto;
    border: 1px solid #222;
    border-radius: 12px;
    background: #080808;
}



/* --- HEADER ULTRA COMPATTO (SINGOLA RIGA) --- */
.consuntivo-header-ultra {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 20px;
    background: #000;
    border-bottom: 2px solid var(--mu-accent);
    color: #fff;
    font-size: 13px;
}

.consuntivo-header-ultra .h-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.h-main-data {
    display: flex;
    align-items: center;
    gap: 10px;
}

.h-comm { color: var(--mu-accent); font-size: 16px; }
.h-cli { color: #888; font-size: 14px; }
.h-art { color: var(--mu-blue); font-size: 14px; }
.h-art small { color: #666; font-size: 11px; margin-left: 5px; }
.h-ord { color: var(--mu-yellow); font-size: 13px; font-family: 'JetBrains Mono', monospace; }
.h-sep { color: #333; margin: 0 5px; }

.consuntivo-header-ultra .h-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.h-kpi {
    font-size: 12px;
    color: #888;
}
.h-kpi strong { color: #fff; font-size: 14px; margin-left: 5px; }
.h-kpi.h-total strong { color: var(--mu-accent); font-size: 18px; }
.h-kpi strong.green { color: #4CAF50; }
.h-kpi strong.yellow { color: #ffcc00; }
.h-kpi strong.red { color: #f44336; }

/* --- TREE VIEW STYLES (MATCHING ACCESS-LIKE STRUCTURE) --- */
.tree-row-master {
    background: rgba(255,255,255,0.02);
    font-weight: 700;
}

.tree-row-child {
    background: transparent;
}
.tree-row-child td {
    border-bottom: 1px solid #111 !important;
}

.loading-spinner {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #555;
}

/* Tabella ad alta densità per consuntivo */
.mu-table-dense {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px; /* Più piccola per far stare tutto */
}
.mu-table-dense th {
    position: sticky;
    top: 0;
    background: #1a1a1a;
    padding: 10px 8px;
    text-align: left;
    border-bottom: 2px solid var(--mu-accent);
    z-index: 10;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.mu-table-dense td {
    padding: 6px 8px;
    border-bottom: 1px solid #111;
    white-space: nowrap;
}
.mu-table-dense tr:hover {
    background: rgba(255, 204, 0, 0.03);
}
/* --- BADGES & SOURCE TAGS --- */
.badge-art, .badge-mat, .badge-lab {
    font-size: 9px;
    padding: 2px 4px;
    border-radius: 4px;
    margin-right: 5px;
    font-weight: bold;
    text-transform: uppercase;
}
.badge-art { background: rgba(0, 122, 255, 0.2); color: #007aff; border: 1px solid rgba(0, 122, 255, 0.3); }
.badge-mat { background: rgba(76, 175, 80, 0.2); color: #4CAF50; border: 1px solid rgba(76, 175, 80, 0.3); }
.badge-lab { background: rgba(255, 152, 0, 0.2); color: #ff9800; border: 1px solid rgba(255, 152, 0, 0.3); }

.source-tag {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 12px;
    background: #1a1a1a;
    color: #666;
    border: 1px solid #333;
}
.source-tag.fattura { background: rgba(76, 175, 80, 0.1); color: #4CAF50; border-color: rgba(76, 175, 80, 0.2); }
.source-tag.ddt { background: rgba(0, 122, 255, 0.1); color: #007aff; border-color: rgba(0, 122, 255, 0.2); }
.source-tag.ordine { background: rgba(255, 193, 7, 0.1); color: #ffc107; border-color: rgba(255, 193, 7, 0.2); }
.source-tag.storico { background: rgba(158, 158, 158, 0.1); color: #9e9e9e; border-color: rgba(158, 158, 158, 0.2); }

.loading-mini {
    color: #444;
    font-size: 1.2em;
}

/* Fix per allineamento icone */
.tree-row-master i {
    transition: transform 0.2s;
}
.tree-row-master.collapsed i {
    transform: rotate(-90deg);
}

/* --- FULLSCREEN OVERLAY FOR COMPARISON & JUMP --- */
.mu-commesse-fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, #111 0%, #000 100%);
    z-index: 9999;
    color: #fff;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-out;
}

.mu-overlay-close {
    position: absolute;
    top: 25px;
    right: 40px;
    background: #ffcc00;
    color: #000;
    padding: 12px 25px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: 900;
    z-index: 10001;
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
    transition: all 0.2s;
    text-transform: uppercase;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.mu-overlay-close:hover {
    transform: scale(1.05) translateY(-2px);
    background: #ffdb4d;
}

#compare-content-container, #jump-content-container {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    scrollbar-width: thin;
    scrollbar-color: #333 #000;
}

.premium-header-box {
    background: linear-gradient(90deg, #ffcc00, #ffaa00);
    border-radius: 12px;
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #000;
    box-shadow: 0 10px 30px rgba(255, 204, 0, 0.15);
    margin-bottom: 30px;
}

.compare-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.fade-in {
    animation: slideInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- PRINT STYLES FOR CONSUNTIVO COMMESSA --- */
@media print {
    /* Set landscape page printing with 1cm margins */
    @page {
        size: A4 landscape;
        margin: 1cm;
    }

    /* Reset global colors for print */
    html, body {
        background: #ffffff !important;
        color: #000000 !important;
        font-family: Arial, sans-serif !important;
    }

    /* Hide background elements when overlay jump mode is printing */
    body:has(#mu-commesse-jump-overlay) > :not(#mu-commesse-jump-overlay) {
        display: none !important;
    }
    
    #mu-commesse-jump-overlay {
        display: block !important;
        position: static !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        background: #ffffff !important;
        color: #000000 !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        z-index: auto !important;
    }
    
    #mu-commesse-jump-overlay #jump-content-container {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Hide background elements when inline fullscreen is active */
    body.fullscreen-active > :not(.main-content) {
        display: none !important;
    }
    body.fullscreen-active .main-content > :not(.views-container) {
        display: none !important;
    }
    body.fullscreen-active .views-container > :not(#view-commesse) {
        display: none !important;
    }
    body.fullscreen-active #view-commesse > :not(#commesse-results) {
        display: none !important;
    }

    /* Hide all typical non-printable layout parts */
    .sidebar, 
    .mu-sidebar,
    .top-header,
    .tree-controls-bar,
    .mu-overlay-close,
    .mu-modal-overlay,
    .context-menu,
    .print-hide,
    button,
    input {
        display: none !important;
    }
    
    /* Reset main-content constraints */
    .main-content {
        flex: 1 1 100% !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        background: #ffffff !important;
    }
    
    .consuntivo-wrapper {
        height: auto !important;
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* Stack grid layout vertically */
    .consuntivo-main-grid {
        display: block !important; 
    }
    
    .consuntivo-charts-sidebar {
        width: 100% !important;
        margin-top: 20px !important;
        page-break-inside: avoid !important;
    }

    #gantt-chart-box {
        background: #ffffff !important;
        border: 1px solid #ddd !important;
        box-shadow: none !important;
        page-break-inside: avoid !important;
        margin-bottom: 20px !important;
    }

    .chart-box {
        background: #ffffff !important;
        border: 1px solid #ddd !important;
        box-shadow: none !important;
        page-break-inside: avoid !important;
    }

    .premium-header-box {
        background: #f3f4f6 !important;
        border: 1px solid #d1d5db !important;
        color: #000000 !important;
        box-shadow: none !important;
        padding: 10px 20px !important;
        page-break-inside: avoid !important;
    }
    
    .premium-header-box span, 
    .premium-header-box label {
        color: #000000 !important;
    }

    .stats-grid-complex {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
        margin-bottom: 20px !important;
        page-break-inside: avoid !important;
    }
    
    .stat-card-premium {
        background: #ffffff !important;
        border: 1px solid #d1d5db !important;
        border-top: 3px solid #000000 !important;
        color: #000000 !important;
        box-shadow: none !important;
        padding: 8px !important;
    }
    
    .stat-card-premium label,
    .stat-card-premium span,
    .stat-card-premium .sub,
    .stat-card-premium .sub-raw {
        color: #000000 !important;
    }

    /* Expand tree container and table wrappers to fit all rows in print */
    .tree-table-wrapper,
    .mu-table-container,
    #tree-container {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        background: #ffffff !important;
        border: none !important;
    }
    
    .mu-table-dense {
        font-size: 10px !important;
        width: 100% !important;
    }

    .mu-table-dense th {
        background: #f3f4f6 !important;
        color: #000000 !important;
        border-bottom: 2px solid #000000 !important;
        position: static !important;
    }
    
    .mu-table-dense td {
        border-bottom: 1px solid #e5e7eb !important;
        color: #000000 !important;
    }
    
    .mu-table-dense tr {
        background: #ffffff !important;
        page-break-inside: avoid !important;
    }

    .tree-row-master {
        background: #f9fafb !important;
        font-weight: bold;
    }
    
    .tree-row-child {
        background: #ffffff !important;
    }
    
    .pdm-link {
        color: #000000 !important;
        text-decoration: none !important;
        cursor: default !important;
    }
    
    .badge-art { background: #e5e7eb !important; color: #000000 !important; border: 1px solid #d1d5db !important; }
    .badge-mat { background: #e5e7eb !important; color: #000000 !important; border: 1px solid #d1d5db !important; }
    .badge-lab { background: #e5e7eb !important; color: #000000 !important; border: 1px solid #d1d5db !important; }
    
    .source-tag {
        background: #ffffff !important;
        color: #333333 !important;
        border: 1px solid #999999 !important;
    }
    
    .fa-circle {
        display: none !important;
    }
}



