<?php
// 1. IDENTIFICAÇÃO DE ONDE O USUÁRIO ESTÁ
$uri = $_SERVER['REQUEST_URI'];

// Verificação simplificada de módulos
$is_loja      = (strpos($uri, '/loja/') !== false);
$is_casa      = (strpos($uri, '/casa/') !== false);
$is_jogos     = (strpos($uri, '/jogos/') !== false);
$is_saude     = (strpos($uri, '/saude/') !== false);
$is_escola    = (strpos($uri, '/escola/') !== false);
$is_apostas   = (strpos($uri, '/apostas/') !== false);
$is_copa26    = (strpos($uri, '/copa26/') !== false);
$is_desejos   = (strpos($uri, '/listadedesejos/') !== false);
$is_loterias  = (strpos($uri, '/loterias/') !== false);

// Se não estiver em nenhuma pasta, é a HOME (raiz)
$is_home = (!$is_loja && !$is_casa && !$is_jogos && !$is_saude && !$is_escola && !$is_apostas && !$is_copa26 && !$is_desejos && !$is_loterias);

// TÍTULO DINÂMICO
$titulo_modulo = "PAINEL GERAL";
if($is_loja) $titulo_modulo = "SISTEMA DE GESTÃO - LOJA";
if($is_casa) $titulo_modulo = "GESTÃO FINANCEIRA - CASA";
if($is_jogos) $titulo_modulo = "CENTRAL DE JOGOS";
if($is_saude) $titulo_modulo = "CONTROLE DE SAÚDE";
if($is_escola) $titulo_modulo = "CONTROLE ESCOLAR";
if($is_apostas) $titulo_modulo = "CENTRAL DE APOSTAS";
if($is_copa26) $titulo_modulo = "COPA DO MUNDO 2026";
if($is_desejos) $titulo_modulo = "LISTA DE DESEJOS";
if($is_loterias) $titulo_modulo = "GERENCIADOR DE LOTERIAS";
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $titulo_modulo; ?></title>
    
    <link rel="icon" type="image/png" href="/icon-192.png?v=30">
    <link rel="apple-touch-icon" href="/icon-192.png?v=30">
    <link rel="manifest" href="/manifest.json?v=30">
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">

   <style>
    body { 
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
        font-size: 10px; 
        margin: 0; 
        padding: 0; 
        background-color: #f0f0f0; 
        text-transform: uppercase; 
        height: 100vh; 
        display: flex; 
        flex-direction: column; 
        overflow-x: hidden; 
    }
    
    .top-category-bar { 
        background-color: #e0e0e0; 
        display: flex; 
        gap: 1px; 
        padding: 0 5px; 
        border-bottom: 1px solid #ccc; 
        overflow-x: auto; 
        white-space: nowrap; 
        -webkit-overflow-scrolling: touch; 
    }
    
    .category-item { 
        padding: 8px 10px; 
        font-weight: bold; 
        font-size: 9px; 
        color: #555; 
        text-decoration: none; 
        cursor: pointer; 
        border: 1px solid transparent; 
        border-bottom: none; 
        transition: 0.2s; 
        flex-shrink: 0; 
    }
    
    .category-item:hover { background-color: #f9f9f9; color: #00569e; }
    .category-item.active { background-color: #00569e; color: white; border-color: #00569e; }
    .category-item.home-active { background-color: #333; color: white; border-color: #333; }
    .category-item.saude-active { background-color: #d32f2f; color: white; border-color: #d32f2f; }
    .category-item.escola-active { background-color: #2e7d32; color: white; border-color: #2e7d32; }
    .category-item.apostas-active { background-color: #6a1b9a; color: white; border-color: #6a1b9a; }
    .category-item.copa-active { background-color: #1b5e20; color: white; border-color: #1b5e20; }
    .category-item.desejos-active { background-color: #e91e63; color: white; border-color: #e91e63; }
    .category-item.loterias-active { background-color: #28a745; color: white; border-color: #28a745; }
    
    .system-title-bar { 
        background-color: #00569e; 
        color: white; 
        padding: 5px 12px; 
        display: flex; 
        justify-content: space-between; 
        align-items: center; 
        font-weight: bold; 
    }
    
    .is-home-bar { background-color: #333 !important; }
    .is-saude-bar { background-color: #d32f2f !important; }
    .is-escola-bar { background-color: #2e7d32 !important; }
    .is-apostas-bar { background-color: #6a1b9a !important; }
    .is-copa-bar { background-color: #1b5e20 !important; }
    .is-desejos-bar { background-color: #e91e63 !important; }
    .is-loterias-bar { background-color: #28a745 !important; }

    .ribbon-bar { 
        background-color: #fff; 
        border-bottom: 1px solid #ccc; 
        padding: 3px; 
        display: flex; 
        gap: 4px; 
        flex-wrap: wrap; 
        height: auto; 
        min-height: 65px;
    }

    .ribbon-group { 
        border: 1px solid #ccc; 
        padding: 2px; 
        display: flex; 
        gap: 1px; 
        position: relative; 
        padding-bottom: 12px; 
        min-width: fit-content; 
        flex-shrink: 0; 
        background-color: #fcfcfc;
    }

    .ribbon-group-label { 
        position: absolute; 
        bottom: 1px; 
        left: 0; 
        right: 0; 
        font-size: 6px; 
        color: #888; 
        text-align: center; 
        font-weight: bold; 
        background: rgba(255,255,255,0.8);
    }

    .ribbon-button { 
        display: flex; 
        flex-direction: column; 
        align-items: center; 
        justify-content: center; 
        width: 42px; 
        height: 50px; 
        border: 1px solid transparent; 
        cursor: pointer; 
        text-align: center; 
        color: #333; 
        text-decoration: none; 
        transition: 0.1s; 
        flex-shrink: 0; 
        padding: 2px; 
    }
    
    .ribbon-button:hover { background-color: #f0f4f8; border-color: #c0d0e0; border-radius: 2px; }
    .ribbon-icon { font-size: 16px; } 
    
    .ribbon-label { 
        font-size: 7px; 
        margin-top: 1px; 
        font-weight: bold; 
        line-height: 1.1; 
        overflow: hidden; 
        text-overflow: ellipsis; 
        white-space: normal; 
        width: 100%; 
        display: -webkit-box; 
        -webkit-line-clamp: 2; 
        -webkit-box-orient: vertical; 
    }

    .main-content { 
        flex: 1; 
        display: block; 
        overflow-y: auto; 
        background-color: #fff; 
        padding: 10px; 
        width: 100%; 
        box-sizing: border-box; 
    }
    
    @media (max-width: 600px) { 
        .ribbon-button { width: 46px; height: 48px; } 
        .ribbon-icon { font-size: 14px; } 
    }
</style>
</head>
<body>

<div class="top-category-bar">
    <a href="/index.php" class="category-item <?php echo $is_home ? 'home-active' : ''; ?>">🏠 HOME</a>
    <a href="/loja/index.php" class="category-item <?php echo $is_loja ? 'active' : ''; ?>">🛒 LOJA</a>
    <a href="/casa/index.php" class="category-item <?php echo $is_casa ? 'active' : ''; ?>">🏠 CASA</a>
    <a href="/saude/index.php" class="category-item <?php echo $is_saude ? 'saude-active' : ''; ?>">🏥 SAÚDE</a>
    <a href="/escola/index.php" class="category-item <?php echo $is_escola ? 'escola-active' : ''; ?>">🏫 ESCOLA</a>
    <a href="/jogos/index.php" class="category-item <?php echo $is_jogos ? 'active' : ''; ?>">🎮 JOGOS</a>
    <a href="/loterias/index.php" class="category-item <?php echo $is_loterias ? 'loterias-active' : ''; ?>">🍀 LOTERIAS</a>
    <a href="/apostas/index.php" class="category-item <?php echo $is_apostas ? 'apostas-active' : ''; ?>">🎲 APOSTAS</a>
    <a href="/copa26/index.php" class="category-item <?php echo $is_copa26 ? 'copa-active' : ''; ?>">⚽ COPA 2026</a>
    <a href="/listadedesejos/index.php" class="category-item <?php echo $is_desejos ? 'desejos-active' : ''; ?>">✨ DESEJOS</a>
</div>

<div class="system-title-bar <?php 
    echo $is_home ? 'is-home-bar' : 
    ($is_saude ? 'is-saude-bar' : 
    ($is_escola ? 'is-escola-bar' : 
    ($is_apostas ? 'is-apostas-bar' : 
    ($is_copa26 ? 'is-copa-bar' : 
    ($is_desejos ? 'is-desejos-bar' : 
    ($is_loterias ? 'is-loterias-bar' : '')))))); ?>">
    <div><?php echo $titulo_modulo; ?></div>
    <div style="font-size: 9px;"><?php echo date('d/m/Y H:i'); ?></div>
</div>

<div class="ribbon-bar">
    <?php if ($is_loja): ?>
        <div class="ribbon-group">
            <a href="/loja/index.php" class="ribbon-button"><span class="ribbon-icon">🏠</span><span class="ribbon-label">INÍCIO</span></a>
            <span class="ribbon-group-label">LOJA</span>
        </div>
        <div class="ribbon-group">
            <a href="/loja/lancamentos.php" class="ribbon-button"><span class="ribbon-icon">📝</span><span class="ribbon-label">LANÇAR</span></a>
            <a href="/loja/consulta_precos.php" class="ribbon-button"><span class="ribbon-icon">🔍</span><span class="ribbon-label">PREÇOS</span></a>
            <a href="/loja/saidas.php" class="ribbon-button"><span class="ribbon-icon">📉</span><span class="ribbon-label">SAÍDAS</span></a>
            <span class="ribbon-group-label">OPERAÇÕES</span>
        </div>
        <div class="ribbon-group">
            <a href="/loja/produtos.php" class="ribbon-button"><span class="ribbon-icon">📦</span><span class="ribbon-label">PROD.</span></a>
            <a href="/loja/clientes.php" class="ribbon-button"><span class="ribbon-icon">👥</span><span class="ribbon-label">CLIEN.</span></a>
            <a href="/loja/usuarios.php" class="ribbon-button"><span class="ribbon-icon">👤</span><span class="ribbon-label">USER</span></a>
            <a href="/loja/folha_ponto.php" class="ribbon-button"><span class="ribbon-icon">📅</span><span class="ribbon-label">PONTO</span></a>
            <a href="/loja/dados_loja.php" class="ribbon-button"><span class="ribbon-icon">⚙️</span><span class="ribbon-label">DADOS</span></a>
            <a href="/loja/nf.php" class="ribbon-button"><span class="ribbon-icon">🧾</span><span class="ribbon-label">NOTAS</span></a>
            <span class="ribbon-group-label">CADASTROS</span>
        </div>
        <div class="ribbon-group">
            <a href="/loja/livro_caixa.php" class="ribbon-button"><span class="ribbon-icon">📖</span><span class="ribbon-label">L. CAIXA</span></a>
            <a href="/loja/caixas.php" class="ribbon-button"><span class="ribbon-icon">🏦</span><span class="ribbon-label">CAIXAS</span></a>
            <a href="/loja/comprovantes_pagamento.php" class="ribbon-button"><span class="ribbon-icon">📜</span><span class="ribbon-label">RECIBO</span></a>
            <a href="/loja/cupom.php" class="ribbon-button"><span class="ribbon-icon">🎟️</span><span class="ribbon-label">CUPOM</span></a>
            <a href="/loja/fiado.php" class="ribbon-button"><span class="ribbon-icon">🔴</span><span class="ribbon-label">FIADO</span></a>
			<a href="/loja/filhos.php" class="ribbon-button"><span class="ribbon-icon">👦</span><span class="ribbon-label">FILHOS</span></a>
            <a href="/loja/credito.php" class="ribbon-button"><span class="ribbon-icon">💰</span><span class="ribbon-label">CRÉDITO</span></a>
            <span class="ribbon-group-label">FINANCEIRO</span>
        </div>
        <div class="ribbon-group">
            <a href="/loja/relatorios.php" class="ribbon-button"><span class="ribbon-icon">📊</span><span class="ribbon-label">RELAT.</span></a>
            <a href="/loja/maisvendidos.php" class="ribbon-button"><span class="ribbon-icon">🏆</span><span class="ribbon-label">TOP+</span></a>
            <a href="/loja/vendasdodia.php" class="ribbon-button"><span class="ribbon-icon">📈</span><span class="ribbon-label">VENDAS</span></a>
            <a href="/loja/linksuteis.php" class="ribbon-button"><span class="ribbon-icon">🔗</span><span class="ribbon-label">LINKS</span></a>
			<a href="/loja/relatorio_zap.php" class="ribbon-button"><span class="ribbon-icon">💬</span><span class="ribbon-label">RELAT. ZAP</span></a>
            <span class="ribbon-group-label">ANÁLISE</span>
        </div>
    <?php endif; ?>

    <?php if ($is_casa): ?>
        <div class="ribbon-group">
            <a href="/casa/index.php" class="ribbon-button"><span class="ribbon-icon">🏠</span><span class="ribbon-label">INÍCIO</span></a>
            <span class="ribbon-group-label">CASA</span>
        </div>
        <div class="ribbon-group">
            <a href="/casa/caixadecasa.php" class="ribbon-button"><span class="ribbon-icon">📖</span><span class="ribbon-label">CAIXA</span></a>
            <a href="/casa/contas.php" class="ribbon-button"><span class="ribbon-icon">💸</span><span class="ribbon-label">CONTAS</span></a>
            <a href="/casa/comparador.php" class="ribbon-button"><span class="ribbon-icon">🔍</span><span class="ribbon-label">COMPRADOR</span></a>
            <a href="/casa/projecao.php" class="ribbon-button"><span class="ribbon-icon">📊</span><span class="ribbon-label">PROJEÇÃO</span></a>
            <a href="/casa/notasdecasa.php" class="ribbon-button"><span class="ribbon-icon">🧾</span><span class="ribbon-label">NOTAS</span></a>
            <span class="ribbon-group-label">CONTROLE</span>
        </div>
        <div class="ribbon-group">
            <a href="/casa/manutencaoveiculos.php" class="ribbon-button"><span class="ribbon-icon">🚗</span><span class="ribbon-label">MANUT.</span></a>
            <a href="/casa/exibir_cartao.php" class="ribbon-button"><span class="ribbon-icon">💳</span><span class="ribbon-label">CARTÃO</span></a>
            <span class="ribbon-group-label">VEÍCULOS/CARTÃO</span>
        </div>
    <?php endif; ?>

    <?php if ($is_jogos): ?>
        <div class="ribbon-group">
            <a href="/jogos/index.php" class="ribbon-button"><span class="ribbon-icon">🏠</span><span class="ribbon-label">HOME</span></a>
            <a href="/jogos/mexemexe.php" class="ribbon-button"><span class="ribbon-icon">🎴</span><span class="ribbon-label">MEXE</span></a>
            <a href="/jogos/uno.php" class="ribbon-button"><span class="ribbon-icon">🎴</span><span class="ribbon-label">UNO</span></a>
            <a href="/jogos/lotofacil.php" class="ribbon-button"><span class="ribbon-icon">🍀</span><span class="ribbon-label">LOTOFÁCIL</span></a>
            <span class="ribbon-group-label">JOGOS</span>
        </div>
    <?php endif; ?>

   <?php if ($is_loterias): ?>
    <div class="ribbon-group">
        <a href="/loterias/index.php" class="ribbon-button"><span class="ribbon-icon">🏠</span><span class="ribbon-label">INÍCIO</span></a>
        <span class="ribbon-group-label">LOTERIAS</span>
    </div>
    <div class="ribbon-group">
        <a href="/loterias/lotofacil.php" class="ribbon-button"><span class="ribbon-icon">🍀</span><span class="ribbon-label">LOTOFÁCIL</span></a>
        <a href="/loterias/lotofacilcalculos.php" class="ribbon-button"><span class="ribbon-icon">📊</span><span class="ribbon-label">ANÁLISE</span></a>
        <a href="/loterias/resultados.php" class="ribbon-button"><span class="ribbon-icon">📜</span><span class="ribbon-label">RESULTADOS</span></a>
        <span class="ribbon-group-label">CONTROLE</span>
    </div>
<?php endif; ?>

    <?php if ($is_saude): ?>
        <div class="ribbon-group">
            <a href="/saude/index.php" class="ribbon-button"><span class="ribbon-icon">🏠</span><span class="ribbon-label">INÍCIO</span></a>
            <span class="ribbon-group-label">SAÚDE</span>
        </div>
        <div class="ribbon-group">
            <a href="/saude/cadastros.php#paciente" class="ribbon-button"><span class="ribbon-icon">👤</span><span class="ribbon-label">CADASTRO</span></a>
            <span class="ribbon-group-label">CADASTROS</span>
        </div>
         <div class="ribbon-group">
            <a href="/saude/marcacao.php" class="ribbon-button"><span class="ribbon-icon">🩺</span><span class="ribbon-label">MARCAR</span></a>
            <span class="ribbon-group-label">MARCAÇÃO</span>
        </div>
         <div class="ribbon-group">
            <a href="/saude/fichas.php" class="ribbon-button"><span class="ribbon-icon">📂</span><span class="ribbon-label">FICHAS</span></a>
            <a href="/saude/notassaude.php" class="ribbon-button"><span class="ribbon-icon">🧾</span><span class="ribbon-label">NOTAS</span></a>
            <span class="ribbon-group-label">HISTÓRICO</span>
        </div>
    <?php endif; ?>

    <?php if ($is_escola): ?>
        <div class="ribbon-group">
            <a href="/escola/index.php" class="ribbon-button"><span class="ribbon-icon">🏠</span><span class="ribbon-label">INÍCIO</span></a>
            <span class="ribbon-group-label">ESCOLA</span>
        </div>
        <div class="ribbon-group">
            <a href="/escola/lançar_escola.php" class="ribbon-button"><span class="ribbon-icon">📝</span><span class="ribbon-label">LANÇAR</span></a>
            <a href="/escola/boletim.php" class="ribbon-button"><span class="ribbon-icon">📊</span><span class="ribbon-label">BOLETIM</span></a>
            <span class="ribbon-group-label">REGISTROS</span>
        </div>
    <?php endif; ?>

    <?php if ($is_apostas): ?>
        <div class="ribbon-group">
            <a href="/apostas/index.php" class="ribbon-button"><span class="ribbon-icon">🏠</span><span class="ribbon-label">INÍCIO</span></a>
            <span class="ribbon-group-label">APOSTAS</span>
        </div>
        <div class="ribbon-group">
            <a href="/apostas/resultados.php" class="ribbon-button"><span class="ribbon-icon">📜</span><span class="ribbon-label">RESULT.</span></a>
            <a href="/apostas/ranking.php" class="ribbon-button"><span class="ribbon-icon">🏆</span><span class="ribbon-label">RANKING</span></a>
            <a href="/apostas/em_qual_jogar.php" class="ribbon-button"><span class="ribbon-icon">🎲</span><span class="ribbon-label">PALPITE</span></a>
            <a href="/apostas/arquivo.php" class="ribbon-button"><span class="ribbon-icon">📂</span><span class="ribbon-label">ARQUIVO</span></a>
            <span class="ribbon-group-label">FERRAMENTAS</span>
        </div>
    <?php endif; ?>

    <?php if ($is_copa26): ?>
        <div class="ribbon-group">
            <a href="/copa26/index.php" class="ribbon-button"><span class="ribbon-icon">🏠</span><span class="ribbon-label">INÍCIO</span></a>
            <span class="ribbon-group-label">COPA 2026</span>
        </div>
    <?php endif; ?>
    
    <?php if ($is_desejos): ?>
        <div class="ribbon-group">
            <a href="/listadedesejos/index.php" class="ribbon-button"><span class="ribbon-icon">➕</span><span class="ribbon-label">NOVO</span></a>
            <a href="/listadedesejos/pedidos.php" class="ribbon-button"><span class="ribbon-icon">📋</span><span class="ribbon-label">ATIVOS</span></a>
            <span class="ribbon-group-label">ENTRADAS</span>
        </div>
        <div class="ribbon-group">
            <a href="/listadedesejos/realizados.php" class="ribbon-button"><span class="ribbon-icon">🏆</span><span class="ribbon-label">FEITOS</span></a>
            <a href="/listadedesejos/desistencias.php" class="ribbon-button"><span class="ribbon-icon">✋</span><span class="ribbon-label">DESISTI</span></a>
            <span class="ribbon-group-label">HISTÓRICO</span>
        </div>
    <?php endif; ?>

    <div class="ribbon-group" style="background-color: #fff9e6; border-color: #ffeeba;">
        <a href="/gerar_backup.php" class="ribbon-button"><span class="ribbon-icon">💾</span><span class="ribbon-label">BACKUP</span></a>
        <span class="ribbon-group-label">SISTEMA</span>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>

<div class="main-content">