<?php
if (session_status() === PHP_SESSION_NONE) session_start();
if (!isset($_SESSION['usuario_id'])) {
    header("Location: " . (defined('BASE_PATH') ? BASE_PATH : '/sistema_licolico/') . "auth/login.php");
    exit;
}
require_once __DIR__ . '/../config/conexao.php';
require_once __DIR__ . '/../config/app.php';

// Dados da empresa
// Busca empresa (sem quebrar se faltar coluna)
$empresa = [
    'logo' => '',
    'nome' => 'Lico Lico',
    'nome_fantasia' => ''
];

try {
    $stmt_emp = $pdo->query("SELECT * FROM empresa LIMIT 1");
    $result = $stmt_emp->fetch(PDO::FETCH_ASSOC);

    if ($result) {
        $empresa['logo'] = $result['logo'] ?? '';
        $empresa['nome'] = $result['nome'] ?? 'Lico Lico';
        $empresa['nome_fantasia'] = $result['nome_fantasia'] ?? '';
    }
} catch (Exception $e) {
    // evita quebrar o sistema
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>LicoLico ERP</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#020617">
<link rel="stylesheet" href="<?= base_url('assets/css/style.css') ?>?v=<?= time(); ?>">
<link rel="icon" href="<?= base_url('assets/img/favicon.png') ?>">
</head>
<body>

<!-- Botão hamburguer mobile -->
<button class="menu-toggle" onclick="toggleSidebar()">&#9776;</button>

<!-- Overlay mobile -->
<div class="sidebar-overlay" id="sidebarOverlay" onclick="toggleSidebar()"></div>

<?php require_once __DIR__ . '/menu.php'; ?>

<div class="main">
<div class="topbar">
    <div class="empresa-info">
        <?php if (!empty($empresa['logo'])): ?>
            <img src="<?= base_url('uploads/' . sanitize($empresa['logo'])) ?>" alt="Logo">
        <?php endif; ?>
        <div>
            <div class="nome"><?= sanitize($empresa['nome_fantasia'] ?: $empresa['nome']) ?></div>
            <div class="sub"><?= sanitize($empresa['nome']) ?></div>
        </div>
    </div>
    <div class="user-info">
        <span class="user-name"><?= sanitize($_SESSION['usuario_nome']) ?></span>
        <a href="<?= base_url('auth/logout.php') ?>" class="btn-sair">Sair</a>
    </div>
</div>
<div class="content">
