/**
 * Custom Modal Fix
 * Corrige problemas específicos com modais customizados
 */

/* Modal sizing fixes */
.modal-dialog {
    max-width: 600px;
    margin: 1.75rem auto;
}

.modal-lg {
    max-width: 800px;
}

.modal-xl {
    max-width: 1140px;
}

.modal-sm {
    max-width: 400px;
}

/* Modal content fixes */
.modal-content {
    border-radius: 0.5rem;
    border: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

/* Modal header */
.modal-header {
    border-bottom: 1px solid #e9ecef;
    padding: 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 0.5rem 0.5rem 0 0;
}

.modal-header .close,
.modal-header .btn-close {
    color: white;
    opacity: 0.8;
    text-shadow: none;
}

.modal-header .close:hover,
.modal-header .btn-close:hover {
    opacity: 1;
}

/* Modal body */
.modal-body {
    padding: 1.5rem;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* Modal footer */
.modal-footer {
    border-top: 1px solid #e9ecef;
    padding: 1rem 1.5rem;
    background-color: #f8f9fa;
    border-radius: 0 0 0.5rem 0.5rem;
}

/* Form in modal fixes */
.modal-body .form-group {
    margin-bottom: 1rem;
}

.modal-body .form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #495057;
}

/* Select2 in modal fix */
.select2-container {
    z-index: 9999 !important;
}

.select2-dropdown {
    z-index: 9999 !important;
}

/* Flatpickr in modal fix */
.flatpickr-calendar {
    z-index: 9999 !important;
}

/* Modal animation improvements */
.modal.fade .modal-dialog {
    transform: scale(0.8);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.show .modal-dialog {
    transform: scale(1);
    opacity: 1;
}

/* Prevent modal jump */
.modal-open {
    overflow: hidden;
}

.modal-open .modal {
    overflow-x: hidden;
    overflow-y: auto;
}

/* Fix modal scrollbar */
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive modal */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }
}

/* Fix button spacing in modal footer */
.modal-footer .btn + .btn {
    margin-left: 0.5rem;
}

/* Loading state in modal */
.modal-body.loading {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Error state styling */
.modal-body .alert {
    margin-bottom: 1rem;
}

/* CodeMirror in modal fix */
.modal-body .CodeMirror {
    height: auto;
    min-height: 300px;
    border: 1px solid #ddd;
    border-radius: 4px;
}
