<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<style>
  * { margin:0; padding:0; box-sizing:border-box; }
  body { font-family: DejaVu Sans, Arial, sans-serif; font-size:13px; color:#333; background:#fff; }
  .page { padding:40px 50px; }
  .header { border-bottom:3px solid #1F4E79; padding-bottom:14px; margin-bottom:20px; overflow:hidden; }
  .header .empresa { font-size:18px; font-weight:700; color:#1F4E79; }
  .header .sub { font-size:11px; color:#777; margin-top:3px; }
  .numero { float:right; font-size:12px; color:#777; text-align:right; margin-top:4px; }
  .valor-box { background:#1F4E79; color:#fff; border-radius:6px; padding:14px 20px; text-align:center; margin:18px 0; }
  .valor-box .val { font-size:26px; font-weight:700; }
  .valor-box .ext { font-size:12px; margin-top:4px; opacity:.88; }
  table.campos { width:100%; border-collapse:collapse; margin-bottom:14px; }
  table.campos td { padding:7px 0; vertical-align:top; }
  table.campos td.lbl { font-size:10px; text-transform:uppercase; color:#999; font-weight:700; width:130px; }
  table.campos td.val { font-size:13px; color:#222; }
  .obs-box { background:#fffde7; border:1px dashed #e6b800; border-radius:5px; padding:12px 15px; font-size:12px; color:#555; line-height:1.6; margin:16px 0; }
  .assinatura { margin-top:50px; text-align:center; }
  .assinatura .linha { border-top:1px solid #555; display:inline-block; min-width:280px; padding-top:6px; font-size:12px; }
  .rodape { margin-top:30px; border-top:1px solid #eee; padding-top:10px; font-size:10px; color:#aaa; text-align:center; }
</style>
</head>
<body>
<div class="page">

  <!-- Cabeçalho -->
  <div class="header">
    <div class="numero">Recibo Nº <?php echo $numero ?></div>
    <div class="empresa"><?php echo htmlspecialchars($setting->company_name ?? 'Breno Paiva Advocacia') ?></div>
    <div class="sub">
      <?php echo htmlspecialchars($setting->company_address ?? '') ?>
      <?php if (!empty($setting->company_phone)): ?> &nbsp;|&nbsp; <?php echo $setting->company_phone ?><?php endif; ?>
      <?php if (!empty($setting->company_email)): ?> &nbsp;|&nbsp; <?php echo $setting->company_email ?><?php endif; ?>
    </div>
  </div>

  <!-- Valor -->
  <div class="valor-box">
    <div class="val">R$ <?php echo number_format($lancamento->valor, 2, ',', '.') ?></div>
    <div class="ext"><?php echo $valor_extenso ?></div>
  </div>

  <!-- Campos -->
  <table class="campos">
    <tr>
      <td class="lbl">Recebi de</td>
      <td class="val"><strong><?php echo htmlspecialchars($cliente->name ?? '—') ?></strong></td>
    </tr>
    <tr>
      <td class="lbl">CPF / CNPJ</td>
      <td class="val"><?php echo htmlspecialchars($cliente->contact ?? '—') ?></td>
    </tr>
    <tr>
      <td class="lbl">Referente a</td>
      <td class="val"><?php echo htmlspecialchars($lancamento->descricao ?? $lancamento->categoria ?? '—') ?>
        <?php if (!empty($lancamento->competencia_mes)): ?> — <?php echo $lancamento->competencia_mes ?><?php endif; ?>
      </td>
    </tr>
    <tr>
      <td class="lbl">Forma de Pagamento</td>
      <td class="val"><?php echo htmlspecialchars($lancamento->forma_pagamento ?? '—') ?></td>
    </tr>
    <tr>
      <td class="lbl">Data do Pagamento</td>
      <td class="val"><?php echo $lancamento->data_pagamento ? date('d/m/Y', strtotime($lancamento->data_pagamento)) : date('d/m/Y') ?></td>
    </tr>
    <?php if (!empty($lancamento->numero_documento)): ?>
    <tr>
      <td class="lbl">Nº Documento</td>
      <td class="val"><?php echo htmlspecialchars($lancamento->numero_documento) ?></td>
    </tr>
    <?php endif; ?>
  </table>

  <!-- Texto livre -->
  <?php if (!empty($texto_livre)): ?>
  <div class="obs-box"><?php echo nl2br(htmlspecialchars($texto_livre)) ?></div>
  <?php endif; ?>

  <!-- Assinatura -->
  <div class="assinatura">
    <br><br>
    <div class="linha">
      <?php echo htmlspecialchars($setting->company_name ?? 'Breno Paiva Advocacia') ?><br>
      <span style="font-size:11px;color:#777"><?php echo htmlspecialchars($setting->company_email ?? '') ?></span>
    </div>
  </div>

  <!-- Rodapé -->
  <div class="rodape">
    Documento gerado em <?php echo date('d/m/Y \à\s H:i') ?> &nbsp;|&nbsp; <?php echo $numero ?>
  </div>

</div>
</body>
</html>
