/* ====================================================================
   MODAL SCROLLING - Configurazione Globale
   ==================================================================== */

/* 
   Limita l'altezza massima delle modal e abilita scroll verticale
   quando il contenuto supera l'80% dell'altezza viewport
*/

.modal-dialog {
    max-height: 85vh;
    margin: 1.75rem auto;
}

/* 
   Assicura che il contenuto della modal possa scrollare
   mantenendo header e footer fissi
*/
.modal-content {
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

/* Header fisso */
.modal-header {
    flex-shrink: 0;
    border-bottom: 1px solid #dee2e6;
}

/* Body con scroll */
.modal-body {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(85vh - 120px); /* Sottrai header + footer */
}

/* Footer fisso */
.modal-footer {
    flex-shrink: 0;
    border-top: 1px solid #dee2e6;
}

/* 
   Stile per scrollbar personalizzata (WebKit browsers)
*/
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 
   Scrollbar per Firefox
*/
.modal-body {
    scrollbar-width: thin;
    scrollbar-color: #888 #f1f1f1;
}

/* 
   Centra le modal verticalmente quando sono più piccole
*/
.modal-dialog-centered {
    min-height: calc(100% - 3.5rem);
}

/* 
   Modal Large con scroll ottimizzato
*/
.modal-lg .modal-body,
.modal-xl .modal-body {
    max-height: calc(85vh - 140px);
}

/* 
   Modal Small con scroll
*/
.modal-sm .modal-body {
    max-height: calc(85vh - 100px);
}

/* 
   Responsive: mobile devices
*/
@media (max-width: 576px) {
    .modal-dialog {
        max-height: 95vh;
        margin: 0.5rem;
    }
    
    .modal-content {
        max-height: 95vh;
    }
    
    .modal-body {
        max-height: calc(95vh - 100px);
    }
}

/* 
   Tablet devices
*/
@media (min-width: 577px) and (max-width: 991px) {
    .modal-dialog {
        max-height: 90vh;
    }
    
    .modal-content {
        max-height: 90vh;
    }
    
    .modal-body {
        max-height: calc(90vh - 110px);
    }
}

/* 
   Animazione smooth per lo scroll
*/
.modal-body {
    scroll-behavior: smooth;
}

/* 
   Padding extra per evitare che il contenuto
   vada sotto la scrollbar
*/
.modal-body {
    padding-right: 1rem !important;
}

/* 
   Fix per modal con form lunghi
*/
.modal-body form {
    overflow: visible;
}

/* 
   Indicatore visivo quando c'è più contenuto da scrollare
*/
.modal-body::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.95));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-body.has-scroll::after {
    opacity: 1;
}

/* 
   Fix per alert all'interno delle modal
*/
.modal-body .alert {
    margin-bottom: 1rem;
}

/* 
   Fix per card all'interno delle modal
*/
.modal-body .card {
    margin-bottom: 1rem;
}

.modal-body .card:last-child {
    margin-bottom: 0;
}

/* 
   Miglioramento accessibilità focus
*/
.modal-body:focus {
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
}

/* 
   Print: rimuovi scrolling per la stampa
*/
@media print {
    .modal-dialog,
    .modal-content,
    .modal-body {
        max-height: none !important;
        overflow: visible !important;
    }
}
