<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8"/>
  <style>
    /* keep all existing styles, add these */
    .no-print {
      text-align: right;
      padding: 10px 20px;
      background: #f3f4f6;
      margin-bottom: 20px;
    }
    .no-print button {
      padding: 8px 20px;
      background: #4f46e5;
      color: white;
      border: none;
      border-radius: 6px;
      cursor: pointer;
      font-size: 14px;
      margin-left: 8px;
    }
    .no-print a {
      padding: 8px 16px;
      background: #e5e7eb;
      color: #333;
      border-radius: 6px;
      text-decoration: none;
      font-size: 14px;
    }
    @media print {
      .no-print { display: none; }
    }

    /* paste all your existing invoice CSS here */
    * { margin: 0; padding: 0; box-sizing: border-box; }
    body { font-family: Arial, sans-serif; font-size: 13px; color: #333; padding: 20mm; }
    .header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; }
    .business-name { font-size: 24px; font-weight: bold; color: #1a1a1a; }
    .business-info { font-size: 12px; color: #666; margin-top: 4px; line-height: 1.6; }
    .invoice-title { font-size: 28px; font-weight: bold; color: #4f46e5; text-align: right; }
    .invoice-meta { text-align: right; font-size: 12px; margin-top: 6px; line-height: 1.8; }
    .divider { border-top: 2px solid #4f46e5; margin: 20px 0; }
    .parties { display: flex; justify-content: space-between; margin-bottom: 30px; }
    .party-block { width: 48%; }
    .party-label { font-size: 11px; text-transform: uppercase; color: #999; letter-spacing: 1px; margin-bottom: 6px; }
    .party-name { font-size: 15px; font-weight: bold; margin-bottom: 3px; }
    .party-info { font-size: 12px; color: #666; line-height: 1.6; }
    table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
    thead tr { background-color: #4f46e5; color: white; }
    thead th { padding: 10px 12px; text-align: left; font-size: 12px; }
    thead th.right { text-align: right; }
    tbody tr { border-bottom: 1px solid #eee; }
    tbody tr:nth-child(even) { background: #f9f9f9; }
    tbody td { padding: 10px 12px; font-size: 13px; }
    tbody td.right { text-align: right; }
    .totals { margin-left: auto; width: 280px; }
    .totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px solid #eee; }
    .totals-row.total { font-size: 16px; font-weight: bold; color: #4f46e5; border-top: 2px solid #4f46e5; border-bottom: none; padding-top: 10px; margin-top: 4px; }
    .totals-row.paid { color: #16a34a; }
    .totals-row.balance { color: #dc2626; font-weight: bold; }
    .status-badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; }
    .status-unpaid { background: #fee2e2; color: #dc2626; }
    .status-partial { background: #fef9c3; color: #ca8a04; }
    .status-paid { background: #dcfce7; color: #16a34a; }
    .status-cancelled { background: #f3f4f6; color: #6b7280; }
    .note-box { background: #f9f9f9; border-left: 4px solid #4f46e5; padding: 10px 14px; margin-top: 20px; font-size: 12px; color: #555; }
    .footer { margin-top: 40px; text-align: center; font-size: 11px; color: #aaa; border-top: 1px solid #eee; padding-top: 14px; }
  </style>
</head>
<body>

  <!-- Print Controls -->
  <div class="no-print">
    <a href="javascript:history.back()">← Back</a>
    <button onclick="window.print()">🖨 Print Invoice</button>
  </div>

  <!-- rest of your invoice template stays exactly the same -->
  <div class="header">
    <div>
      <div class="business-name">{{ business.name }}</div>
      <div class="business-info">
        {% if business.address %}{{ business.address }}<br/>{% endif %}
        {% if business.phone %}Tel: {{ business.phone }}<br/>{% endif %}
        {% if business.email %}{{ business.email }}<br/>{% endif %}
        {% if business.tax_pin %}TIN: {{ business.tax_pin }}{% endif %}
      </div>
    </div>
    <div>
      <div class="invoice-title">INVOICE</div>
      <div class="invoice-meta">
        <div><strong>{{ invoice.reference }}</strong></div>
        <div>Issue Date: {{ invoice.issue_date|date:"d M Y" }}</div>
        {% if invoice.due_date %}
          <div>Due Date: {{ invoice.due_date|date:"d M Y" }}</div>
        {% endif %}
        <div style="margin-top:6px;">
          <span class="status-badge status-{{ invoice.status }}">
            {{ invoice.get_status_display }}
          </span>
        </div>
      </div>
    </div>
  </div>

  <div class="divider"></div>

  <div class="parties">
    <div class="party-block">
      <div class="party-label">Bill To</div>
      <div class="party-name">{{ invoice.customer_display }}</div>
      <div class="party-info">
        {% if invoice.customer_phone %}Tel: {{ invoice.customer_phone }}<br/>{% endif %}
        {% if invoice.customer_email %}{{ invoice.customer_email }}<br/>{% endif %}
        {% if invoice.customer_address %}{{ invoice.customer_address }}{% endif %}
      </div>
    </div>
  </div>

  <table>
    <thead>
      <tr>
        <th>#</th>
        <th>Description</th>
        <th class="right">Qty</th>
        <th class="right">Unit Price</th>
        <th class="right">Total</th>
      </tr>
    </thead>
    <tbody>
      {% for item in invoice.items.all %}
      <tr>
        <td>{{ forloop.counter }}</td>
        <td>{{ item.description }}</td>
        <td class="right">{{ item.quantity }}</td>
        <td class="right">{{ business.currency }} {{ item.unit_price|floatformat:0 }}</td>
        <td class="right">{{ business.currency }} {{ item.line_total|floatformat:0 }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>

  <div class="totals">
    <div class="totals-row">
      <span>Subtotal</span>
      <span>{{ business.currency }} {{ invoice.subtotal|floatformat:0 }}</span>
    </div>
    {% if invoice.discount %}
    <div class="totals-row">
      <span>Discount</span>
      <span>- {{ business.currency }} {{ invoice.discount|floatformat:0 }}</span>
    </div>
    {% endif %}
    <div class="totals-row total">
      <span>Total</span>
      <span>{{ business.currency }} {{ invoice.total|floatformat:0 }}</span>
    </div>
    {% if invoice.total_paid %}
    <div class="totals-row paid">
      <span>Amount Paid</span>
      <span>{{ business.currency }} {{ invoice.total_paid|floatformat:0 }}</span>
    </div>
    <div class="totals-row balance">
      <span>Balance Due</span>
      <span>{{ business.currency }} {{ invoice.balance_due|floatformat:0 }}</span>
    </div>
    {% endif %}
  </div>

  {% if invoice.note %}
  <div class="note-box">
    <strong>Note:</strong> {{ invoice.note }}
  </div>
  {% endif %}

  <div class="footer">
    <div>{{ business.name }} — {{ business.phone }} — {{ business.email }}</div>
    <div style="margin-top:4px;">{% now "d M Y H:i" %}</div>
  </div>

</body>
</html>
