<?php
// app/views/layout.php
?>
<!doctype html>
<html lang="es">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?= h($title ?? 'Inventarios') ?></title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
  <style>
    body { background: #2f5fa3; }
    .card { border-radius: 14px; }
    .badge-status { font-size: 90%; }
    .table thead th { position: sticky; top: 0; background: #1f4f92; color: #fff; }
    .row-orange { background: rgba(255,165,0,0.22); }
    .row-green { background: rgba(0,255,0,0.10); }
    .row-yellow { background: rgba(255,255,0,0.18); }
  </style>
</head>
<body>
<nav class="navbar navbar-expand navbar-dark" style="background:#1f4f92;">
  <a class="navbar-brand" href="dashboard.php">Inventarios</a>
  <div class="navbar-nav">
    <?php if (!empty($user)): ?>
      <a class="nav-item nav-link" href="dashboard.php">Inventario</a>
      <?php if ($user['role']==='admin'): ?>
        <a class="nav-item nav-link" href="users.php">Usuarios</a>
        <a class="nav-item nav-link" href="reports.php">Reportes</a>
        <a class="nav-item nav-link" href="settings.php">Configuración</a>
      <?php endif; ?>
      <?php if ($user['role']==='admin' || $user['role']==='monitor'): ?>
        <a class="nav-item nav-link" href="assign.php">Asignaciones</a>
        <a class="nav-item nav-link" href="monitor.php">Mesa Monitor</a>
      <?php endif; ?>
      <?php if ($user['role']==='empleado'): ?>
        <a class="nav-item nav-link" href="my_tasks.php">Mis tareas</a>
      <?php endif; ?>
    <?php endif; ?>
  </div>
  <div class="ml-auto navbar-nav">
    <?php if (!empty($user)): ?>
      <span class="navbar-text mr-3"><?= h($user['username']) ?> (<?= h($user['role']) ?>)</span>
      <a class="nav-item nav-link" href="logout.php">Salir</a>
    <?php endif; ?>
  </div>
</nav>

<div class="container-fluid py-3">
  <?php if (!empty($flash_success)): ?>
    <div class="alert alert-success"><?= h($flash_success) ?></div>
  <?php endif; ?>
  <?php if (!empty($flash_error)): ?>
    <div class="alert alert-danger"><?= h($flash_error) ?></div>
  <?php endif; ?>

  <?= $content ?>
</div>

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