<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Purchase Order - {{PO_NUMBER}}</title>
  <style>
    /* ====================================
       GLOBAL STYLES (matching invoiceTemplate2)
    ==================================== */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: Arial, sans-serif;
    }

    body {
      background: #f2f2f2;
      padding: 20px;
    }

    .po-container {
      width: 1000px;
      margin: auto;
      background: #fff;
      padding: 20px;
      border: 1px solid #000;
    }

    /* ====================================
       COMMON (matching invoice)
    ==================================== */
    table {
      width: 100%;
      border-collapse: collapse;
    }

    td, th {
      border: 1px solid #000;
      padding: 3px 6px;
      vertical-align: top;
      font-size: 13px;
    }

    .text-center {
      text-align: center;
    }

    .text-right {
      text-align: right;
    }

    .text-left {
      text-align: left;
    }

    /* ====================================
       HEADER (exact match to invoice)
    ==================================== */
    .top-header {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      margin-bottom: 10px;
    }

    .logo {
      width: 100px;
      height: auto;      /* maintain aspect ratio, height matches invoice logo area */
      display: block;
    }

    .company-details {
      flex: 1;
      text-align: center;
      margin-right: 70px;    /* matches invoice margin-right */
    }

    .company-details h1 {
      font-size: 18px;
      margin-bottom: 2px;
      font-weight: 700;
    }

    .company-details p {
      font-size: 13px;
      line-height: 1.3;
    }

    /* ====================================
       PO TITLE (matching invoice title style)
    ==================================== */
    .po-title {
      text-align: center;
      font-size: 26px;
      font-weight: 700;
      margin: 10px 0;
    }

    /* ====================================
       PO DATE ROW (subtle alignment)
    ==================================== */
    .po-date-row {
      text-align: right;
      font-size: 13px;
      margin-bottom: 8px;
      color: #333;
    }
    .po-date-row span {
      font-weight: 600;
      color: #111;
    }

    /* ====================================
       3-COLUMN INFO SECTION
       Colors, borders, typography match invoice address-card style
    ==================================== */
    .info-row {
      display: flex;
      gap: 0;
      margin-top: 10px;
      width: 100%;
    }

    .info-card {
      flex: 1;
      border: 1px solid #cfcfcf;
      padding: 8px 8px;
      background: #fff;
      vertical-align: top;
    }

    /* mimic address-card style */
    .info-card-title {
      font-size: 13px;
      font-weight: 700;
      color: #666;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      margin-bottom: 5px;
    }

    .info-card .co-name {
      font-size: 14px;
      font-weight: 700;
      color: #111;
      line-height: 20px;
      margin-bottom: 6px;
    }

    .info-card p {
      font-size: 13px;
      color: #333;
      line-height: 18px;
      margin-bottom: 2px;
    }

    .info-card .lbl {
      color: #6c757d;
      font-weight: normal;
    }
    .info-card .val {
      font-weight: 600;
      color: #111;
    }

    /* ====================================
       SECTION HEADER (similar to product table headings)
    ==================================== */
    .section-hdr {
      font-size: 13px;
      font-weight: 700;
      text-transform: uppercase;
      color: #444;
      letter-spacing: 0.5px;
      margin: 12px 0 6px 0;
      border-bottom: none;
      padding-bottom: 0;
    }

    /* ====================================
       PRODUCT TABLE (exactly matches invoice product-table)
    ==================================== */
    .product-table {
      width: 100%;
      border-collapse: collapse;
      table-layout: fixed;
      margin-top: 12px;
    }

    .product-table th {
      background: #f3f3f3;
      border: 1px solid #cfcfcf;
      padding: 8px 10px;
      font-size: 13px;
      font-weight: 700;
      text-transform: uppercase;
      text-align: left;
      color: #444;
      letter-spacing: 0.5px;
    }

    .product-table td {
      border: 1px solid #d8d8d8;
      padding: 8px 10px;
      font-size: 13px;
      color: #222;
      line-height: 18px;
    }

    /* column widths matching the invoice's product feel, adjusted for extra columns */
    .col-sl   { width: 5%; text-align: center; }
    .col-code { width: 10%; }
    .col-name { width: 14%; }
    .col-desc { width: 14%; }
    .col-qty  { width: 7%; text-align: center; }
    .col-uom  { width: 6%; text-align: center; }
    .col-rate { width: 9%; text-align: right; }
    .col-tax  { width: 6%; text-align: center; }
    .col-cgst { width: 8%; text-align: right; }
    .col-sgst { width: 8%; text-align: right; }
    .col-tot  { width: 10%; text-align: right; }

    /* center class for th content */
    .product-table th.text-center {
      text-align: center;
    }
    .product-table th.text-right {
      text-align: right;
    }

    /* ====================================
       TERMS & SUMMARY (exactly matches invoice summary wrapper)
    ==================================== */
    .bottom-row {
      width: 100%;
      margin-top: 14px;
      display: flex;
      gap: 0;
      table-layout: fixed;
    }

    .terms-box {
      flex: 55%;
      border: 1px solid #cfcfcf;
      padding: 12px 14px;
      background: #fff;
    }

    .summary-box {
      flex: 45%;
      border: 1px solid #cfcfcf;
      background: #fff;
    }

    .terms-title {
      font-size: 13px;
      font-weight: 700;
      text-transform: uppercase;
      color: #666;
      letter-spacing: 0.7px;
      margin-bottom: 10px;
    }

    .terms-content {
      font-size: 13px;
      line-height: 20px;
      color: #333;
    }

    .summary-table {
      width: 100%;
      border-collapse: collapse;
    }

    .summary-table td {
      padding: 8px 12px;
      font-size: 13px;
      color: #222;
      border: 1px solid #d8d8d8;
    }

    .summary-table .lbl-cell {
      font-weight: normal;
      color: #222;
    }
    .summary-table .val-cell {
      text-align: right;
      font-weight: 600;
    }

    .total-row td {
      font-size: 14px;
      font-weight: 700;
      background: #f5f5f5;
      color: #111;
    }
    .total-row .val-cell {
      color: #111;
    }

    /* ====================================
       AMOUNT WORDS (matching invoice box)
    ==================================== */
    .amount-words-box {
      margin-top: 14px;
      border: 1px solid #cfcfcf;
      padding: 10px 14px;
      font-size: 13px;
      line-height: 20px;
    }
    .amount-label {
      font-weight: 700;
      color: #111;
    }
    .amount-text {
      color: #333;
    }

    /* ====================================
       SIGNATURE (matches invoice signature style)
    ==================================== */
    .signatory-box {
      width: 100%;
      border: 1px solid #cfcfcf;
      padding: 12px;
      margin-top: 14px;
      vertical-align: top;
      text-align: right;
      background: #fff;
    }
    .signatory-for {
      font-size: 13px;
      font-weight: 700;
      color: #111;
      margin-bottom: 25px;
    }
    .signatory-role {
      font-size: 13px;
      color: #666;
      text-transform: uppercase;
      letter-spacing: 0.6px;
    }

    /* ====================================
       FOOTER (exact match)
    ==================================== */
    .footer-note {
      margin-top: 12px;
      text-align: center;
      font-size: 12px;
      color: #666;
      border-top: 1px solid #dcdcdc;
      padding-top: 8px;
    }

    /* ====================================
       PRINT (mirror invoice)
    ==================================== */
    @media print {
      body {
        background: #fff;
        padding: 0;
      }
      .po-container {
        border: none;
      }
    }
  </style>
</head>
<body>
<div class="po-container">

  <!-- HEADER: logo + company details (matching invoiceTemplate2 exactly) -->
  <div class="top-header">
    <img src="{{COMPANY_LOGO}}" class="logo" alt="logo" onerror="this.style.display='none'" />
    <div class="company-details">
      <h1>{{COMPANY_NAME}}</h1>
      <p>{{COMPANY_ADDRESS_LINE1}}</p>
      <p>PAN : {{COMPANY_PAN}} &nbsp;|&nbsp; GSTIN : {{COMPANY_GST}}</p>
      <p>CIN : {{COMPANY_CIN}}</p>
      <p>{{COMPANY_EMAIL}} &nbsp;|&nbsp; {{COMPANY_PHONE}}</p>
    </div>
  </div>

  <!-- TITLE (same as invoice) -->
  <div class="po-title">PURCHASE ORDER</div>
  <div class="po-date-row">Date : <span>{{PO_DATE}}</span></div>

  <!-- 3-COLUMN INFO ROW (card styles matching address-table/info-table borders) -->
  <div class="info-row">
    <!-- Supply To (Company) -->
    <div class="info-card">
      <div class="info-card-title">Supply To</div>
      <div class="co-name">{{COMPANY_NAME}}</div>
      <div class="address-text">{{COMPANY_ADDRESS_LINE1}}</div>
      <p><span class="lbl">GSTIN :</span> <span class="val">{{COMPANY_GST}}</span></p>
      <p><span class="lbl">CIN :</span> <span class="val">{{COMPANY_CIN}}</span></p>
    </div>

    <!-- Vendor To -->
    <div class="info-card">
      <div class="info-card-title">Vendor (To)</div>
      <div class="co-name">{{VENDOR_NAME}}</div>
      <div class="address-text">{{VENDOR_ADDRESS}}</div>
      <p><span class="lbl">Phone :</span> <span class="val">{{VENDOR_PHONE}}</span></p>
      <p><span class="lbl">Email :</span> <span class="val">{{VENDOR_EMAIL}}</span></p>
      <p><span class="lbl">GSTIN :</span> <span class="val">{{VENDOR_GST}}</span></p>
    </div>

    <!-- PO Details -->
    <div class="info-card">
      <div class="info-card-title">PO Details</div>
      <p><span class="lbl">PO No :</span> <span class="val">{{PO_NUMBER}}</span></p>
      <p><span class="lbl">PO Date :</span> <span class="val">{{PO_DATE}}</span></p>
      <p><span class="lbl">Due Date :</span> <span class="val">{{PO_DUE_DATE}}</span></p>
      <p><span class="lbl">PR No :</span> <span class="val">{{PR_NUMBER}}</span></p>
      <p><span class="lbl">Department :</span> <span class="val">{{DEPARTMENT}}</span></p>
      <p><span class="lbl">Requested By :</span> <span class="val">{{REQUESTED_BY}}</span></p>
    </div>
  </div>

  <!-- Items Table (styled exactly like invoice product-table) -->
  <div class="section-hdr">Item Details</div>
  <table class="product-table">
    <thead>
      <tr>
        <th class="col-sl text-center">Sl.</th>
        <th class="col-code">Item Code</th>
        <th class="col-name">Item Name</th>
        <th class="col-desc">Description</th>
        <th class="col-qty text-center">Qty</th>
        <th class="col-uom text-center">UOM</th>
        <th class="col-rate text-right">Rate (₹)</th>
        <th class="col-tax text-center">Tax %</th>
        <th class="col-cgst text-right">CGST (₹)</th>
        <th class="col-sgst text-right">SGST (₹)</th>
        <th class="col-tot text-right">Total (₹)</th>
      </tr>
    </thead>
    <tbody>
      {{ITEMS_ROWS}}
      <!-- optional empty row placeholder for spacing if needed (similar to invoice) -->
      <!-- but dynamic rows from backend will populate -->
    </tbody>
  </table>

  <!-- Terms + Summary (identical style to invoiceTemplate2 .invoice-summary-wrapper) -->
  <div class="bottom-row">
    <!-- Terms Section -->
    <div class="terms-box">
      <div class="terms-title">Terms &amp; Conditions</div>
      <div class="terms-content">
        {{TERMS_CONTENT}}
      </div>
    </div>

    <!-- Summary Section (matching .summary-table) -->
    <div class="summary-box">
      <table class="summary-table">
        <tr>
          <td class="lbl-cell">Gross Amount</td>
          <td class="val-cell">₹ {{GROSS_AMOUNT}}</td>
        </tr>
        <tr>
          <td class="lbl-cell">Net Value</td>
          <td class="val-cell">₹ {{NET_VALUE}}</td>
        </tr>
        <tr>
          <td class="lbl-cell">CGST</td>
          <td class="val-cell">₹ {{CGST_AMOUNT}}</td>
        </tr>
        <tr>
          <td class="lbl-cell">SGST</td>
          <td class="val-cell">₹ {{SGST_AMOUNT}}</td>
        </tr>
        <tr>
          <td class="lbl-cell">Round Off</td>
          <td class="val-cell">{{ROUND_OFF}}</td>
        </tr>
        <tr class="total-row">
          <td class="lbl-cell">Total Value</td>
          <td class="val-cell">INR {{TOTAL_VALUE}}</td>
        </tr>
      </table>
    </div>
  </div>

  <!-- Amount in Words (exact match) -->
  <div class="amount-words-box">
    <span class="amount-text">Rupees in words</span>
    <span class="amount-label">{{AMOUNT_IN_WORDS}}</span>
     <span class="amount-text">Only</span>
  </div>

  <!-- Signature (same structure as invoice signature-table but simplified row to match PO style but preserving fonts/colors) -->
  <div class="signatory-box">
    <div class="signatory-for">For {{COMPANY_NAME}}</div>
    <div class="signatory-role">Authorised Signatory</div>
  </div>

  <!-- Footer note (identical) -->
  <div class="footer-note">
    This is a computer generated document and does not require a physical signature.
  </div>

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