<?php /* Document quick-view popup modal — include before footer.php */ ?>
<div id="docPopupOverlay" onclick="closeDocPopup()" style="display:none;position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:9998;"></div>
<div id="docPopupModal" style="display:none;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:min(860px,95vw);height:88vh;background:#fff;border-radius:10px;z-index:9999;box-shadow:0 24px 64px rgba(0,0,0,.25);flex-direction:column;">
    <div style="display:flex;justify-content:space-between;align-items:center;padding:12px 18px;border-bottom:1px solid #e2e8f0;background:#f8fafc;border-radius:10px 10px 0 0;flex-shrink:0;">
        <span id="docPopupTitle" style="font-weight:600;font-size:14px;color:#1e293b;"></span>
        <button onclick="closeDocPopup()" style="background:none;border:none;cursor:pointer;font-size:22px;color:#94a3b8;line-height:1;" title="Close (Esc)">&times;</button>
    </div>
    <iframe id="docPopupFrame" src="" style="flex:1;border:none;width:100%;border-radius:0 0 10px 10px;"></iframe>
</div>
<script>
function openDocPopup(type, id, title) {
    var base = '<?= BASE_URL ?>';
    var urls = {
        sale:       base + '/sales/popup_view.php?id=',
        purchase:   base + '/purchases/popup_view.php?id=',
        pur_return: base + '/purchase_returns/popup_view.php?id=',
        sal_return: base + '/sales_return/popup_view.php?id=',
        master:     base + '/master_sales/popup_view.php?id='
    };
    if (!urls[type]) return;
    document.getElementById('docPopupFrame').src = urls[type] + id;
    document.getElementById('docPopupTitle').textContent = title || '';
    document.getElementById('docPopupOverlay').style.display = 'block';
    var m = document.getElementById('docPopupModal');
    m.style.display = 'flex';
}
function closeDocPopup() {
    document.getElementById('docPopupOverlay').style.display = 'none';
    document.getElementById('docPopupModal').style.display = 'none';
    document.getElementById('docPopupFrame').src = '';
}
document.addEventListener('keydown', function(e){ if(e.key === 'Escape') closeDocPopup(); });
</script>
