<div style="text-align: right; padding: 10px; background: #eee; margin-bottom: 20px;">
    Olá, <strong><?php echo $_SESSION['nome']; ?></strong> | 
    <a href="logout.php" style="color: #d9534f; text-decoration: none; font-weight: bold;">[ SAIR DO SISTEMA ]</a>
</div>


<?php
session_start();

// 1. Verifica se o usuário está logado
if (!isset($_SESSION['usuario_id'])) {
    header("Location: index.php");
    exit;
}

// 2. Garante que o arquivo JSON existe antes de ler
$arquivo_pedidos = 'db/pedidos.json';
if (!file_exists($arquivo_pedidos)) {
    file_put_contents($arquivo_pedidos, json_encode([]));
}

$pedidos_brutos = file_get_contents($arquivo_pedidos);
$meus_pedidos = json_decode($pedidos_brutos, true) ?? [];
?>











<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Painel do Cliente | BRT Express</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root { --primary: #003964; --secondary: #001a30; --accent: #00a8ff; }
        body { background-color: #f4f7f6; font-family: 'Segoe UI', sans-serif; }
        
        /* Sidebar Estilizada */
        .sidebar {
            min-width: 250px; max-width: 250px; background: var(--primary);
            color: #fff; min-height: 100vh; transition: all 0.3s;
        }
        .sidebar .nav-link { color: rgba(255,255,255,0.7); padding: 15px 20px; border-radius: 0; }
        .sidebar .nav-link:hover, .sidebar .nav-link.active {
            color: #fff; background: var(--secondary); border-left: 4px solid var(--accent);
        }
        .sidebar-header { padding: 20px; text-align: center; background: var(--secondary); }

        /* Conteúdo */
        .content-area { width: 100%; padding: 20px; }
        .card-custom { border: none; border-radius: 15px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
        .header-top { background: #fff; padding: 15px 30px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
        
        @media (max-width: 768px) {
            .sidebar { display: none; } /* Ocultar sidebar no mobile ou usar menu hambúrguer */
        }
    </style>
</head>
<body>

<div class="d-flex">
    <nav class="sidebar shadow">
        <div class="sidebar-header">
            <h4 class="mb-0">BRT <span class="text-info">Express</span></h4>
            <small>OABCG Soluções</small>
        </div>
        <ul class="nav flex-column mt-3">
            <li class="nav-item">
                <a href="fazer_pedido.php" class="nav-link active">
                    <i class="fas fa-plus-circle me-2"></i> Solicitar Entrega
                </a>
            </li>
            <li class="nav-item">
                <a href="meus_pedidos.php" class="nav-link">
                    <i class="fas fa-box-open me-2"></i> Meus Pedidos
                </a>
            </li>
            <li class="nav-item">
                <a href="perfil.php" class="nav-link">
                    <i class="fas fa-user-cog me-2"></i> Meu Perfil
                </a>
            </li>
            <li class="nav-item">
                <a href="logout.php" class="nav-link text-danger">
                    <i class="fas fa-sign-out-alt me-2"></i> Sair
                </a>
            </li>
        </ul>
    </nav>

    <div class="content-area">
        <div class="header-top d-flex justify-content-between align-items-center mb-4 rounded shadow-sm">
            <h5 class="mb-0 text-muted">Bem-vindo, <b><?php echo $_SESSION['nome']; ?></b></h5>
            <span class="badge bg-primary rounded-pill p-2 px-3">Cliente VIP</span>
        </div>

        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-7 mb-4">
                    <div class="card card-custom p-4">
                        <h4 class="mb-4 text-primary"><i class="fas fa-paper-plane me-2"></i> Nova Solicitação</h4>
                        
                        <form action="processar_pedido.php" method="POST" enctype="multipart/form-data">
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label fw-bold">O que vamos entregar?</label>
                                    <select name="produto" class="form-select shadow-sm" required>
                                        <option value="">Selecione o material...</option>
                                        <option>Banner de Lona</option>
                                        <option>Cartão de Visita</option>
                                        <option>Panfletos Coloridos</option>
                                        <option>Adesivos</option>
                                    </select>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label fw-bold">Estação BRT Destino</label>
                                    <select name="estacao_brt" class="form-select shadow-sm" required>
                                        <option value="">Escolha a Estação...</option>
                                        <option>Alvorada (Barra)</option>
                                        <option>Madureira</option>
                                        <option>Vicente de Carvalho</option>
                                        <option>Santa Cruz</option>
                                        <option>Jardim Oceânico</option>
                                    </select>
                                </div>
                            </div>

                            <div class="mb-3">
                                <label class="form-label fw-bold">Anexar Arte Final (PDF/ZIP)</label>
                                <input type="file" name="arte_arquivo" class="form-control shadow-sm" required>
                                <small class="text-muted">Formatos aceitos: PDF, ZIP, CDR, JPG (Máx. 20MB)</small>
                            </div>

                            <div class="alert alert-info py-2" role="alert">
                                <i class="fas fa-info-circle me-2"></i> O pagamento via Pix será solicitado na próxima etapa.
                            </div>

                            <button type="submit" class="btn btn-primary w-100 py-3 shadow">
                                <i class="fas fa-qrcode me-2"></i> Gerar Pedido e Ver Pix
                            </button>
                        </form>
                    </div>
                </div>

                <div class="col-lg-5">
                    <div class="card card-custom p-4 bg-white shadow-sm">
                        <h5 class="text-muted mb-3"><i class="fas fa-history me-2"></i> Pedidos Recentes</h5>
                        <div class="d-flex align-items-center p-3 mb-2 border rounded">
                            <div class="flex-shrink-0">
                                <i class="fas fa-file-pdf fa-2x text-danger"></i>
                            </div>
                            <div class="ms-3 flex-grow-1">
                                <h6 class="mb-0">Banner 1x1m</h6>
                                <small class="text-muted">Estação Alvorada</small>
                            </div>
                            <div>
                                <span class="badge bg-warning text-dark">Em Rota</span>
                            </div>
                        </div>
                        <a href="meus_pedidos.php" class="btn btn-sm btn-link text-center w-100 mt-2">Ver todos os pedidos</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>