<?php send_csp(); ?>
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title><?= h($title ?? config('app.name')) ?></title>
<meta name="robots" content="noindex,nofollow">
<?php
// Favicon dinâmico
foreach(['favicon.png','favicon.ico','favicon.jpg'] as $_fav)
    if(file_exists(ROOT.'/imgs/'.$_fav)){
        echo '<link rel="icon" href="'.base_url('imgs/'.$_fav).'">';
        break;
    }
?>
<link rel="stylesheet" href="<?= base_url('css/app.css') ?>">
<style>
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0;}
body{font-family:'Inter',sans-serif;background:#030712;color:#f9fafb;min-height:100vh;}
a{color:inherit;text-decoration:none;}
img{-webkit-user-drag:none;user-select:none;}
</style>
<script nonce="<?= nonce() ?>">
// Funções globais — disponíveis para todas as páginas
function showToast(msg) {
  var wrap = document.getElementById('toast-container');
  if (!wrap) return;
  var t = document.createElement('div');
  t.textContent = msg;
  t.style.cssText = 'background:#fff;color:#111827;padding:10px 18px;border-radius:10px;font-size:13px;font-weight:600;box-shadow:0 4px 20px rgba(0,0,0,.35);animation:tin .2s ease,tout .3s ease 1.7s forwards;white-space:nowrap;';
  wrap.appendChild(t);
  setTimeout(function(){ t.remove(); }, 2100);
}
function updateCartBadge(count) {
  var b = document.getElementById('cart-badge');
  if (!b) return;
  b.textContent = count;
  b.style.display = count > 0 ? 'inline' : 'none';
}
</script>
</head>
<body>

<!-- Navbar -->
<nav style="position:sticky;top:0;z-index:40;background:rgba(3,7,18,.85);backdrop-filter:blur(12px);border-bottom:1px solid rgba(255,255,255,.06);">
  <div style="max-width:1280px;margin:0 auto;padding:0 16px;height:56px;display:flex;align-items:center;justify-content:space-between;">
    <a href="<?= base_url() ?>" style="display:flex;align-items:center;gap:8px;">
      <?php
      $logoFound = false;
      foreach(['logo.svg','logo.png','logo.jpg','logo.webp'] as $_l)
        if(file_exists(ROOT.'/imgs/'.$_l)){
          echo '<img src="'.base_url('imgs/'.$_l).'" alt="'.h(config('app.name')).'" style="height:36px;width:auto;object-fit:contain;">';
          $logoFound = true; break;
        }
      if(!$logoFound) echo '<span style="font-size:22px;">📸</span><span style="font-weight:700;font-size:17px;color:#fff;">'.h(config('app.name')).'</span>';
      ?>
    </a>
    <div style="display:flex;align-items:center;gap:16px;">
      <a href="<?= base_url('contactos') ?>"
         style="font-size:13px;color:#9ca3af;transition:color .15s;"
         onmouseover="this.style.color='#fff'" onmouseout="this.style.color='#9ca3af'">
        Contactos
      </a>
      <a href="<?= base_url('carrinho') ?>" id="nav-cart-btn"
       style="display:flex;align-items:center;gap:7px;color:#9ca3af;font-size:14px;font-weight:500;
              padding:7px 14px;border-radius:8px;border:1px solid rgba(255,255,255,.1);
              transition:all .15s;position:relative;"
       onmouseover="this.style.color='#fff';this.style.borderColor='rgba(255,255,255,.25)'"
       onmouseout="this.style.color='#9ca3af';this.style.borderColor='rgba(255,255,255,.1)'">
      <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
          d="M3 3h2l.4 2M7 13h10l4-9H5.4M7 13L5.4 5M7 13l-2.293 2.293c-.63.63-.184 1.707.707 1.707H17m0 0a2 2 0 100 4 2 2 0 000-4zm-8 2a2 2 0 11-4 0 2 2 0 014 0z"/>
      </svg>
      Carrinho
      <?php $cnt = \App\Core\Cart::count(); ?>
      <span id="cart-badge"
            style="background:#6366f1;color:#fff;font-size:10px;font-weight:800;
                   padding:1px 6px;border-radius:999px;<?= $cnt===0?'display:none':'display:inline' ?>">
        <?= $cnt ?>
      </span>
    </a>
  </div>
</nav>

<?php if($m=flash('success')): ?>
<div style="background:rgba(22,163,74,.15);border-bottom:1px solid rgba(22,163,74,.25);color:#4ade80;padding:10px 16px;text-align:center;font-size:13px;"><?= h($m) ?></div>
<?php endif; ?>
<?php if($m=flash('error')): ?>
<div style="background:rgba(239,68,68,.15);border-bottom:1px solid rgba(239,68,68,.25);color:#f87171;padding:10px 16px;text-align:center;font-size:13px;"><?= h($m) ?></div>
<?php endif; ?>

<?= $content ?>

<footer style="border-top:1px solid rgba(255,255,255,.06);margin-top:64px;padding:24px 16px;text-align:center;color:#374151;font-size:13px;">
  © <?= date('Y') ?> <?= h(config('app.name')) ?>
</footer>

<!-- Toast container -->
<div id="toast-container" style="position:fixed;bottom:88px;right:20px;z-index:200;display:flex;flex-direction:column;gap:8px;pointer-events:none;"></div>

<script>
// Animações toast
var _s = document.createElement('style');
_s.textContent = '@keyframes tin{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}@keyframes tout{to{opacity:0}}';
document.head.appendChild(_s);
document.addEventListener('contextmenu', function(e){ if(e.target.tagName==='IMG') e.preventDefault(); });
</script>
<?php if(isset($pageScript)): ?><script nonce="<?= nonce() ?>"><?= $pageScript ?></script><?php endif; ?>
</body>
</html>
