function previewDocx(filePath) {
const container = document.getElementById('docxContainer');
const modal = document.getElementById('docxModal');
document.getElementById('docxTitle').innerText = filePath.split('/').pop();
container.innerHTML = "<p style='color: white;'>Загрузка...</p>";
modal.style.display = 'block';
fetch(`/download/${filePath}`)
.then(response => response.arrayBuffer())
.then(arrayBuffer => mammoth.convertToHtml({arrayBuffer: arrayBuffer}))
.then(result => {
// Оборачиваем весь текст в класс "docx-page", который мы стилизовали под А4
container.innerHTML = `<div class="docx-page">${result.value}</div>`;
})
.catch(err => {
container.innerHTML = `<p style="color:red;">Ошибка: ${err.message}</p>`;
});
}
function closeDocx() {
document.getElementById('docxModal').style.display = 'none';
}