<!doctype html>
<html lang="<%= lang %>" dir="<%= dir %>">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><%= t('invoice.title') %> #<%= order.id %> · Apple Supplier</title>
  <link rel="icon" type="image/svg+xml" href="/logo.svg">
  <style>
    :root { --border: #d2d2d7; --border-soft: #e8e8ed; --muted: #6e6e73; --text: #1d1d1f; --accent: #0071e3; }
    * { box-sizing: border-box; }
    body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; background: #f5f5f7; color: var(--text); }
    .toolbar { display: flex; justify-content: center; gap: .6rem; padding: 1rem; }
    .btn { appearance: none; border: 1px solid var(--border); background: #fff; color: var(--text); padding: .55rem 1rem; border-radius: 980px; font: inherit; font-weight: 600; cursor: pointer; }
    .btn-primary { background: #0071e3; border-color: #0071e3; color: #fff; }
    .btn:hover { text-decoration: none; opacity: .92; }
    .hint { text-align: center; color: var(--muted); font-size: .8rem; margin: 0 0 1rem; }
    .sheet { width: min(760px, 100% - 2rem); margin: 0 auto 2.5rem; background: #fff; border-radius: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 18px 40px -30px rgba(0,0,0,.35); padding: 2rem; }
    header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 1px solid var(--border-soft); padding-bottom: 1.1rem; margin-bottom: 1.3rem; }
    .brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; }
    .brand img { width: 30px; height: 30px; }
    h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
    .meta { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 2rem; margin-bottom: 1.4rem; font-size: .88rem; }
    .meta dt { color: var(--muted); font-size: .74rem; margin-bottom: .15rem; }
    .meta dd { margin: 0; font-weight: 600; }
    table { width: 100%; border-collapse: collapse; font-size: .9rem; }
    th { text-align: start; color: var(--muted); font-size: .72rem; font-weight: 500; border-bottom: 1px solid var(--border); padding: .55rem .5rem; }
    td { padding: .7rem .5rem; border-bottom: 1px solid var(--border-soft); }
    .total-row td { border-bottom: 0; font-weight: 700; font-size: 1rem; padding-top: .9rem; }
    .total-row td:last-child { color: var(--accent); }
    footer { margin-top: 1.6rem; border-top: 1px solid var(--border-soft); padding-top: .9rem; color: var(--muted); font-size: .76rem; }
    @media print {
      body { background: #fff; }
      .toolbar, .hint { display: none; }
      .sheet { box-shadow: none; width: 100%; border-radius: 0; padding: 0; margin: 0; }
    }
  </style>
</head>
<body>
  <div class="toolbar">
    <button class="btn btn-primary" onclick="window.print()"><%= t('invoice.download') %></button>
  </div>
  <p class="hint"><%= t('invoice.print_hint') %></p>
  <section class="sheet">
    <header>
      <div class="brand"><img src="/logo.svg" alt="">Apple Supplier</div>
      <div style="text-align: end">
        <h1><%= t('invoice.title') %> #<%= order.id %></h1>
        <div style="color: var(--muted); font-size: .8rem"><%= (order.service_date || order.created_at).slice(0, 16) %></div>
      </div>
    </header>

    <dl class="meta">
      <div>
        <dt><%= t('invoice.billed_to') %></dt>
        <dd><%= order.customer_name %><br><span class="muted" style="font-weight:400"><%= order.email %></span></dd>
      </div>
      <div>
        <dt><%= t('invoice.order_no') %></dt>
        <dd class="mono">ORDER-<%= order.id %></dd>
        <dt style="margin-top:.5rem"><%= t('common.status') %></dt>
        <dd><%= STATUS_LABELS[order.status] %></dd>
      </div>
    </dl>

    <table>
      <thead>
        <tr>
          <th><%= t('invoice.service') %></th>
          <th><%= t('invoice.device') %></th>
          <th style="text-align:end"><%= t('invoice.amount') %></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>
            <%= svcName(order) %>
            <% if (order.device_model) { %><div class="muted" style="font-size:.78rem"><%= t('invoice.model') %>: <%= modelName(order.device_model) %></div><% } %>
          </td>
          <td class="mono"><%= order.device_info %></td>
          <td class="mono" style="text-align:end"><%= fmt(order.price) %></td>
        </tr>
        <tr class="total-row">
          <td colspan="2"><%= t('invoice.total') %></td>
          <td class="mono" style="text-align:end"><%= fmt(order.price) %></td>
        </tr>
      </tbody>
    </table>

    <footer>
      <p><%= t('invoice.thanks') %></p>
      <p><%= t('footer.disclaimer') %></p>
    </footer>
  </section>
</body>
</html>
