        </div>
    </div>
</div>

<div id="toast-container"></div>

<?php
$message = getAndClearMessage();
if ($message):
?>
<script>
    showToast("<?php echo htmlspecialchars($message['text']); ?>", "<?php echo $message['type']; ?>");
</script>
<?php endif; ?>

<script>
function showToast(msg, type = 'success') {
    const c = document.getElementById('toast-container');
    const icons = {
        success: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#3DB87A" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg>',
        error: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#E05252" stroke-width="2.5"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',
        info: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#4A8FD4" stroke-width="2.5"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>'
    };
    const el = document.createElement('div');
    el.className = `toast ${type}`;
    el.innerHTML = (icons[type] || '') + '<span>' + msg + '</span>';
    c.appendChild(el);
    setTimeout(() => {
        el.classList.add('hide');
        setTimeout(() => el.remove(), 300);
    }, 3200);
}

function updateSidebarStats() {
    fetch('<?php echo APP_URL; ?>/api/get-today-stats.php')
        .then(r => r.json())
        .then(d => {
            document.getElementById('sb-revenue-today').textContent = d.revenue + ' lei';
            document.getElementById('sb-orders-today').textContent = d.orders + ' comenzi';
        });
}

// Update every 30 seconds
setInterval(updateSidebarStats, 30000);
updateSidebarStats();
</script>

</body>
</html>
