<!doctype html>
<html lang="{{lang}}">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{{documentTitle}} {{invoiceNumber}}</title>
  <style>
    * { box-sizing: border-box; }
    body {
      margin: 0;
      font-family: "Segoe UI", Arial, Helvetica, sans-serif;
      background: #f4f6fb;
      color: #1f2937;
      font-size: 13px;
      line-height: 1.5;
    }
    .page {
      max-width: 860px;
      margin: 28px auto;
      background: #ffffff;
      border: 1px solid #dbe3f0;
      border-radius: 20px;
      overflow: hidden;
      box-shadow: none;
    }
    .hero {
      padding: 34px 38px 28px;
      background: linear-gradient(135deg, #102347 0%, #173b73 52%, #2563eb 100%);
      color: #ffffff;
    }
    .hero-grid {
      display: flex;
      justify-content: space-between;
      gap: 24px;
      align-items: flex-start;
    }
    .hero-brand {
      display: grid;
      gap: 14px;
      min-width: 0;
    }
    .hero-logo:empty {
      display: none;
    }
    .hero-logo img {
      display: block;
      max-height: 72px;
      max-width: 220px;
      object-fit: contain;
    }
    .hero h1 {
      margin: 0;
      font-size: 31px;
      font-weight: 800;
      letter-spacing: -0.03em;
    }
    .hero p {
      margin: 8px 0 0;
      max-width: 420px;
      color: rgba(255, 255, 255, 0.82);
    }
    .invoice-card {
      min-width: 220px;
      padding: 18px 20px;
      border-radius: 18px;
      background: rgba(255, 255, 255, 0.12);
      border: 1px solid rgba(255, 255, 255, 0.18);
      text-align: right;
    }
    .invoice-card .eyebrow {
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.16em;
      color: rgba(255, 255, 255, 0.72);
    }
    .invoice-card .number {
      margin-top: 8px;
      font-size: 24px;
      font-weight: 800;
    }
    .content {
      padding: 30px 38px 36px;
    }
    .info-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 18px;
      margin-bottom: 24px;
    }
    .info-card {
      padding: 18px;
      border: 1px solid #dbe3f0;
      border-radius: 18px;
      background: #f8fafc;
    }
    .info-card h2 {
      margin: 0 0 10px;
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.18em;
      color: #64748b;
    }
    .info-card p {
      margin: 0;
    }
    .highlight {
      font-weight: 700;
      color: #0f172a;
    }
    .meta-lines {
      display: grid;
      gap: 6px;
    }
    .meta-line {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      flex-wrap: wrap;
      gap: 16px;
      min-width: 0;
    }
    .meta-label {
      color: #64748b;
      flex: 1 1 auto;
      min-width: 0;
      padding-right: 12px;
    }
    .meta-line .highlight,
    .meta-line .status-pill {
      flex: 0 0 auto;
      text-align: right;
    }
    .status-pill {
      display: inline-flex;
      align-items: center;
      padding: 5px 10px;
      border-radius: 999px;
      background: #dbeafe;
      color: #1d4ed8;
      font-size: 11px;
      font-weight: 700;
      letter-spacing: 0.08em;
      text-transform: uppercase;
    }
    .tax-banner {
      margin-bottom: 22px;
      padding: 15px 18px;
      border: 1px solid #c7d2fe;
      border-radius: 18px;
      background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 100%);
    }
    .tax-banner-title {
      margin: 0 0 6px;
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.16em;
      color: #4f46e5;
      font-weight: 700;
    }
    .tax-banner p {
      margin: 0;
      color: #334155;
    }
    .tax-banner:empty {
      display: none;
    }
    .reverse-charge-note {
      margin-bottom: 22px;
      padding: 15px 18px;
      border: 1px solid #fdba74;
      border-radius: 18px;
      background: linear-gradient(180deg, #fff7ed 0%, #fffbeb 100%);
    }
    .reverse-charge-note p {
      margin: 0;
      color: #9a3412;
    }
    .is-hidden {
      display: none !important;
    }
    .items-table {
      width: 100%;
      border-collapse: collapse;
      overflow: hidden;
      border-radius: 18px;
      border: 1px solid #dbe3f0;
      margin-bottom: 24px;
    }
    .items-table thead th {
      padding: 12px 14px;
      background: #e2e8f0;
      color: #334155;
      text-align: left;
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.14em;
    }
    .items-table thead th:nth-child(3),
    .items-table thead th:nth-child(4),
    .items-table thead th:nth-child(5),
    .items-table tbody td:nth-child(3),
    .items-table tbody td:nth-child(4),
    .items-table tbody td:nth-child(5) {
      text-align: right;
    }
    .items-table tbody td {
      padding: 12px 14px;
      border-top: 1px solid #e2e8f0;
      background: #ffffff;
    }
    .summary-grid {
      display: grid;
      grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.9fr);
      gap: 20px;
      align-items: start;
    }
    .payment-card,
    .totals-card {
      padding: 20px;
      border: 1px solid #dbe3f0;
      border-radius: 18px;
      background: #f8fafc;
    }
    .payment-card h3,
    .totals-card h3 {
      margin: 0 0 12px;
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.16em;
      color: #64748b;
    }
    .payment-card p {
      margin: 0 0 12px;
      color: #334155;
    }
    .bank-list {
      margin-top: 14px;
      display: grid;
      gap: 8px;
    }
    .bank-row {
      display: flex;
      justify-content: space-between;
      gap: 16px;
    }
    .bank-label {
      color: #64748b;
    }
    .bank-value {
      text-align: right;
      color: #0f172a;
      font-weight: 600;
    }
    .totals-row {
      display: flex;
      justify-content: space-between;
      gap: 16px;
      padding: 7px 0;
      color: #475569;
    }
    .totals-row strong {
      color: #0f172a;
    }
    .totals-row.total {
      margin-top: 8px;
      padding-top: 12px;
      border-top: 2px solid #cbd5e1;
      font-size: 16px;
      font-weight: 800;
      color: #0f172a;
    }
    .footer {
      margin-top: 24px;
      padding-top: 18px;
      border-top: 1px solid #e2e8f0;
      color: #64748b;
      font-size: 11px;
      text-align: center;
      line-height: 1.6;
    }
    @media (max-width: 760px) {
      .hero,
      .content {
        padding-left: 22px;
        padding-right: 22px;
      }
      .hero-grid,
      .summary-grid,
      .info-grid {
        grid-template-columns: 1fr;
        display: grid;
      }
      .invoice-card {
        text-align: left;
      }
    }
    @page {
      size: A4;
      margin: 12mm;
    }
    @media print {
      html,
      body {
        width: 210mm;
      }
      body {
        background: #ffffff;
        color: #111827;
        font-size: 10.8px;
        line-height: 1.3;
      }
      .page {
        max-width: none;
        width: 100%;
        margin: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        overflow: visible;
      }
      .hero {
        padding: 14px 16px 12px;
      }
      .hero h1 {
        font-size: 22px;
      }
      .invoice-card {
        min-width: 160px;
        padding: 10px 12px;
      }
      .invoice-card .number {
        font-size: 18px;
      }
      .content {
        padding: 14px 16px 16px;
      }
      .info-grid,
      .summary-grid {
        gap: 10px;
      }
      .info-grid {
        margin-bottom: 10px;
      }
      .info-card,
      .payment-card,
      .totals-card,
      .tax-banner {
        padding: 10px;
      }
      .tax-banner {
        margin-bottom: 10px;
      }
      .items-table {
        margin-bottom: 10px;
      }
      .items-table thead th,
      .items-table tbody td {
        padding: 6px 7px;
      }
      .bank-list {
        margin-top: 8px;
        gap: 4px;
      }
      .totals-row {
        padding: 4px 0;
      }
      .totals-row.total {
        margin-top: 3px;
        padding-top: 6px;
      }
      .footer {
        margin-top: 10px;
        padding-top: 8px;
        font-size: 9.4px;
      }
      .hero,
      .info-grid,
      .info-card,
      .tax-banner,
      .summary-grid,
      .payment-card,
      .totals-card,
      .footer {
        page-break-inside: avoid;
        break-inside: avoid;
      }
      .summary-grid {
        grid-template-columns: 1fr;
      }
      .items-table {
        page-break-inside: auto;
      }
      .items-table thead {
        display: table-header-group;
      }
      .items-table tr {
        page-break-inside: avoid;
        break-inside: avoid;
      }
    }
  </style>
</head>
<body>
  <div class="page">
    <section class="hero">
      <div class="hero-grid">
        <div class="hero-brand">
          <div class="hero-logo">{{companyLogo}}</div>
          <h1>{{documentTitle}}</h1>
        </div>
        <div class="invoice-card">
          <div class="eyebrow">{{invoiceNumberLabel}}</div>
          <div class="number">{{invoiceNumber}}</div>
        </div>
      </div>
    </section>

    <section class="content">
      <div class="info-grid">
        <div class="info-card">
          <h2>{{fromLabel}}</h2>
          <p>
            <span class="highlight">{{companyName}}</span><br>
            {{companyStreet}}<br>
            {{companyPostalCity}}<br>
            {{companyCountry}}
          </p>
        </div>
        <div class="info-card">
          <h2>{{toLabel}}</h2>
          <p>
            <span class="highlight">{{customerName}}</span><br>
            {{customerEmail}}<br>
            {{customerStreet}}<br>
            {{customerPostalCity}}<br>
            {{customerCountry}}
          </p>
        </div>
        <div class="info-card">
          <h2>{{detailsLabel}}</h2>
          <div class="meta-lines">
            <div class="meta-line"><span class="meta-label">{{dateLabel}}</span><span class="highlight">{{issuedAt}}</span></div>
            <div class="meta-line"><span class="meta-label">{{dueDateLabel}}</span><span class="highlight">{{dueAt}}</span></div>
            <div class="meta-line"><span class="meta-label">{{statusLabel}}</span><span class="status-pill">{{invoiceStatus}}</span></div>
          </div>
        </div>
      </div>

      {{orderedByBlock}}

      {{taxTreatmentBlock}}

      <div class="reverse-charge-note {{reverseChargeClass}} {{reverseChargeSectionClass}}">
        <p>{{reverseChargeNoticeText}}</p>
      </div>

      <table class="items-table">
        <thead>
          <tr>
            <th>#</th>
            <th>{{descriptionHeader}}</th>
            <th>{{qtyHeader}}</th>
            <th>{{unitPriceHeader}}</th>
            <th>{{totalHeader}}</th>
          </tr>
        </thead>
        <tbody>
          {{itemsRows}}
        </tbody>
      </table>

      <div class="summary-grid">
        <div class="payment-card">
          <h3>{{paymentInfoTitle}}</h3>
          <p>{{paymentInfoText}}</p>
          <div class="bank-list">
            <div class="bank-row"><span class="bank-label">Account holder</span><span class="bank-value">{{bankAccountHolder}}</span></div>
            <div class="bank-row"><span class="bank-label">IBAN</span><span class="bank-value">{{bankIban}}</span></div>
            <div class="bank-row"><span class="bank-label">BIC</span><span class="bank-value">{{bankBic}}</span></div>
          </div>
        </div>

        <div class="totals-card">
          <h3>Summary</h3>
          <div class="totals-row"><span>{{subtotalLabel}}</span><strong>{{totalNet}}</strong></div>
          <div class="totals-row"><span>{{taxLabel}} ({{vatRateDisplay}})</span><strong>{{totalTax}}</strong></div>
          <div class="totals-row total"><span>{{totalLabel}}</span><span>{{totalGross}}</span></div>
        </div>
      </div>

      <div class="footer">{{footerText}}</div>
    </section>
  </div>
</body>
</html>>