{
  "$schema": "https://www.cooki-ui.design/schema/registry-item.json",
  "name": "invoice-printer",
  "type": "registry:ui",
  "title": "Invoice Printer",
  "description": "Tactile thermal receipt printer generating physical-style receipts with sound synthesis, extrusion motion, tear-off physics, and barcodes.",
  "category": "cards",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/cards/invoice-printer/invoice-printer.tsx",
      "type": "registry:ui",
      "target": "components/ui/invoice-printer.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useEffect, useRef, useId } from \"react\";\nimport { motion, AnimatePresence } from \"framer-motion\";\nimport { Printer, Scissors, RefreshCw, Check, Download, Volume2, VolumeX, FileText, Barcode as BarcodeIcon, QrCode as QrCodeIcon } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\n// ============================================================================\n// TYPES & INTERFACES\n// ============================================================================\n\nexport interface InvoiceItem {\n  id: string;\n  description: string;\n  hsnCode?: string;\n  qty: number;\n  rate: number;\n  total: number;\n}\n\nexport interface BankDetails {\n  bankName?: string;\n  accountNumber?: string;\n  ifscOrSwift?: string;\n  upiId?: string;\n  branch?: string;\n}\n\nexport interface InvoiceData {\n  /** Document title: e.g. \"TAX INVOICE\", \"INVOICE\", \"PROFORMA INVOICE\", \"BILL OF SUPPLY\" */\n  invoiceTitle?: string;\n  invoiceNumber: string;\n  issueDate: string;\n  dueDate?: string;\n  time?: string;\n  poNumber?: string;\n  paymentTerms?: string;\n\n  // Company / Seller details\n  companyName: string;\n  companySubtitle?: string;\n  companyAddress?: string;\n  companyGstin?: string; // GSTIN or Tax Identification Number (e.g. 33AAACL1234F1Z5)\n  companyEmail?: string;\n  companyPhone?: string;\n  companyWebsite?: string;\n  companyLogo?: string; // Image URL for brand logo\n  companyLogoBadge?: string; // Text badge fallback (e.g. \"CK\")\n\n  // Client / Buyer details\n  clientName: string;\n  clientRef?: string;\n  clientAddress?: string;\n  clientGstin?: string; // Client GSTIN / Tax ID\n  clientEmail?: string;\n  clientPhone?: string;\n\n  // Currency & Items\n  currency?: string;\n  currencySymbol?: string;\n  items: InvoiceItem[];\n\n  // Financial Breakdown\n  subtotal: number;\n  taxRate?: number;\n  taxAmount?: number;\n  cgstAmount?: number;\n  sgstAmount?: number;\n  igstAmount?: number;\n  discount?: number;\n  shippingAmount?: number;\n  total: number;\n\n  // Payment & Banking\n  paymentMethod?: string;\n  transactionId?: string;\n  authCode?: string;\n  bankDetails?: BankDetails;\n\n  // Sign-off & Notes\n  authorizedSignatoryName?: string;\n  authorizedSignatoryTitle?: string;\n  signatureImageUrl?: string;\n  termsAndConditions?: string;\n  footerNote?: string;\n}\n\nexport interface InvoicePrinterProps {\n  /** Custom invoice data to render on the receipt or A4 sheet */\n  invoiceData?: Partial<InvoiceData>;\n  /** Printer format mode: corporate A4 sheet (default, primary) or compact Thermal POS receipt (secondary) */\n  format?: \"a4\" | \"thermal\";\n  /** Visual theme mode: light, dark, or system matching container/class */\n  theme?: \"light\" | \"dark\" | \"system\";\n  /** Print speed multiplier (0.5x slow-mo for social reels, 1x normal, 2x fast) */\n  speed?: number;\n  /** Whether procedural Web Audio mechanical sound effects are enabled */\n  soundEnabled?: boolean;\n  /** Whether to automatically trigger printing on mount */\n  autoPrint?: boolean;\n  /** Whether to stamp a rubber \"PAID\" mark upon completion */\n  showStamp?: boolean;\n  /** Custom text for the stamp (default: \"PAID IN FULL\") */\n  stampText?: string;\n  /** Custom stamp color class or hex */\n  stampType?: \"paid\" | \"verified\" | \"approved\";\n  /** Stamp placement position */\n  stampPosition?: \"bottom-right\" | \"center\" | \"top-right\";\n  /** Whether interactive receipt tearing is permitted */\n  allowTear?: boolean;\n  /** Whether to render the tactile action control bar at the outer bottom */\n  showControls?: boolean;\n  /** Optional class name for the outer container */\n  className?: string;\n  /** Optional class name for the printer hardware chassis */\n  printerClassName?: string;\n  /** Optional class name for the emerging paper element */\n  receiptClassName?: string;\n  /** Callback fired when the printing animation begins */\n  onPrintStart?: () => void;\n  /** Callback fired when the paper feed finishes printing */\n  onPrintComplete?: (data: InvoiceData) => void;\n  /** Callback fired when the paper is torn off */\n  onTear?: () => void;\n  /** Callback fired when download/PDF action is clicked */\n  onDownload?: (data: InvoiceData) => void;\n  /** Callback fired when brand logo badge or image is clicked */\n  onLogoClick?: () => void;\n}\n\nexport type PrinterStatus = \"idle\" | \"preparing\" | \"printing\" | \"completed\" | \"torn\";\n\n// ============================================================================\n// DEFAULT INVOICE DATA\n// ============================================================================\n\nexport const defaultInvoiceData: InvoiceData = {\n  invoiceTitle: \"TAX INVOICE\",\n  invoiceNumber: \"INV-2026-089\",\n  issueDate: \"04 SEP 2026\",\n  dueDate: \"18 SEP 2026\",\n  time: \"12:45 IST\",\n  poNumber: \"PO-LW-9921\",\n  paymentTerms: \"NET 14 DAYS\",\n  companyName: \"COOKI UI ARCHITECTURE LABS\",\n  companySubtitle: \"INTERACTIVE MOTION & DESIGN LABS\",\n  companyAddress: \"ONE INFINITE LOOP, SUITE 400, CA 95014\",\n  companyGstin: \"GSTIN: 33AAACL1234F1Z5\",\n  companyEmail: \"billing@cooki-ui.design\",\n  companyPhone: \"+1 (800) 555-0199\",\n  companyWebsite: \"https://www.cooki-ui.design\",\n  companyLogoBadge: \"CK\",\n  clientName: \"ENTERPRISE CLIENT CORP\",\n  clientRef: \"ACC #88219-B\",\n  clientAddress: \"742 EVERGREEN TERRACE, SEATTLE, WA 98101\",\n  clientGstin: \"GSTIN: 27ABCDE1234F1Z8\",\n  clientEmail: \"procurement@enterprise.io\",\n  currency: \"USD\",\n  currencySymbol: \"$\",\n  items: [\n    {\n      id: \"1\",\n      description: \"UI Motion Physics Kit & Shader Engine\",\n      hsnCode: \"998313\",\n      qty: 1,\n      rate: 450.00,\n      total: 450.00,\n    },\n    {\n      id: \"2\",\n      description: \"Sound Design & Procedural Audio Engine\",\n      hsnCode: \"998314\",\n      qty: 1,\n      rate: 250.00,\n      total: 250.00,\n    },\n  ],\n  subtotal: 700.00,\n  taxRate: 10,\n  taxAmount: 70.00,\n  discount: 0,\n  total: 770.00,\n  paymentMethod: \"APPLE PAY (TAP TO PAY)\",\n  transactionId: \"TXN_998124098\",\n  authCode: \"AUTH_OK_7719\",\n  bankDetails: {\n    bankName: \"SILICON VALLEY BANK\",\n    accountNumber: \"•••• •••• •••• 8842\",\n    ifscOrSwift: \"SVBUS6S\",\n    upiId: \"cooki@okhdfcbank\",\n  },\n  authorizedSignatoryName: \"MUHILAN K.\",\n  authorizedSignatoryTitle: \"DIRECTOR & LEAD ARCHITECT\",\n  termsAndConditions: \"Payment is due within 14 days of invoice date. All intellectual property remains with Cooki UI System until full clearance.\",\n  footerNote: \"THANK YOU FOR YOUR BUSINESS\",\n};\n\n// ============================================================================\n// PROCEDURAL WEB AUDIO SYNTHESIZER (ZERO EXTERNAL ASSETS)\n// ============================================================================\n\nclass ProceduralPrinterAudio {\n  private ctx: AudioContext | null = null;\n  private isMuted: boolean = false;\n  private printingInterval: number | null = null;\n  private motorOsc: OscillatorNode | null = null;\n  private motorGain: GainNode | null = null;\n\n  private initContext() {\n    if (typeof window === \"undefined\") return;\n    if (!this.ctx) {\n      const AudioCtx = window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext;\n      if (AudioCtx) {\n        this.ctx = new AudioCtx();\n      }\n    }\n    if (this.ctx && this.ctx.state === \"suspended\") {\n      this.ctx.resume().catch(() => {});\n    }\n  }\n\n  public setMuted(muted: boolean) {\n    this.isMuted = muted;\n    if (muted) {\n      this.stopPrintingSound();\n    }\n  }\n\n  public getMuted(): boolean {\n    return this.isMuted;\n  }\n\n  // Tactile mechanical switch click\n  public playButtonClick() {\n    if (this.isMuted || typeof window === \"undefined\") return;\n    try {\n      this.initContext();\n      if (!this.ctx) return;\n\n      const now = this.ctx.currentTime;\n      const osc = this.ctx.createOscillator();\n      const gain = this.ctx.createGain();\n\n      osc.type = \"triangle\";\n      osc.frequency.setValueAtTime(420, now);\n      osc.frequency.exponentialRampToValueAtTime(110, now + 0.04);\n\n      gain.gain.setValueAtTime(0.25, now);\n      gain.gain.exponentialRampToValueAtTime(0.001, now + 0.04);\n\n      osc.connect(gain);\n      gain.connect(this.ctx.destination);\n\n      osc.start(now);\n      osc.stop(now + 0.045);\n    } catch {\n      // AudioContext fallback\n    }\n  }\n\n  // Thermal stepper motor and printhead buzz\n  public startPrintingSound(speedMultiplier: number = 1) {\n    if (this.isMuted || typeof window === \"undefined\") return;\n    try {\n      this.initContext();\n      if (!this.ctx) return;\n\n      const now = this.ctx.currentTime;\n      this.motorOsc = this.ctx.createOscillator();\n      this.motorGain = this.ctx.createGain();\n\n      this.motorOsc.type = \"sawtooth\";\n      this.motorOsc.frequency.setValueAtTime(180 * speedMultiplier, now);\n\n      const filter = this.ctx.createBiquadFilter();\n      filter.type = \"bandpass\";\n      filter.frequency.setValueAtTime(450, now);\n      filter.Q.setValueAtTime(3.5, now);\n\n      this.motorGain.gain.setValueAtTime(0.06, now);\n\n      this.motorOsc.connect(filter);\n      filter.connect(this.motorGain);\n      this.motorGain.connect(this.ctx.destination);\n\n      this.motorOsc.start(now);\n\n      const stepInterval = Math.max(60, Math.floor(130 / speedMultiplier));\n      this.printingInterval = window.setInterval(() => {\n        if (!this.ctx || this.isMuted) return;\n        const tickTime = this.ctx.currentTime;\n\n        const bufferSize = Math.floor(this.ctx.sampleRate * 0.025);\n        const buffer = this.ctx.createBuffer(1, bufferSize, this.ctx.sampleRate);\n        const data = buffer.getChannelData(0);\n        for (let i = 0; i < bufferSize; i++) {\n          data[i] = (Math.random() * 2 - 1) * Math.sin((i / bufferSize) * Math.PI);\n        }\n\n        const noise = this.ctx.createBufferSource();\n        noise.buffer = buffer;\n\n        const noiseFilter = this.ctx.createBiquadFilter();\n        noiseFilter.type = \"highpass\";\n        noiseFilter.frequency.setValueAtTime(1800, tickTime);\n\n        const noiseGain = this.ctx.createGain();\n        noiseGain.gain.setValueAtTime(0.08, tickTime);\n        noiseGain.gain.exponentialRampToValueAtTime(0.001, tickTime + 0.022);\n\n        noise.connect(noiseFilter);\n        noiseFilter.connect(noiseGain);\n        noiseGain.connect(this.ctx.destination);\n\n        noise.start(tickTime);\n      }, stepInterval);\n    } catch {\n      // AudioContext fallback\n    }\n  }\n\n  // Office Laser paper roll advance sweep sound\n  public startOfficePrinterSound(speedMultiplier: number = 1) {\n    if (this.isMuted || typeof window === \"undefined\") return;\n    try {\n      this.initContext();\n      if (!this.ctx) return;\n\n      const now = this.ctx.currentTime;\n      this.motorOsc = this.ctx.createOscillator();\n      this.motorGain = this.ctx.createGain();\n\n      this.motorOsc.type = \"sine\";\n      this.motorOsc.frequency.setValueAtTime(120 * speedMultiplier, now);\n\n      const filter = this.ctx.createBiquadFilter();\n      filter.type = \"lowpass\";\n      filter.frequency.setValueAtTime(320, now);\n\n      this.motorGain.gain.setValueAtTime(0.08, now);\n\n      this.motorOsc.connect(filter);\n      filter.connect(this.motorGain);\n      this.motorGain.connect(this.ctx.destination);\n\n      this.motorOsc.start(now);\n\n      const intervalMs = Math.max(80, Math.floor(180 / speedMultiplier));\n      this.printingInterval = window.setInterval(() => {\n        if (!this.ctx || this.isMuted) return;\n        const tickTime = this.ctx.currentTime;\n\n        const bufferSize = Math.floor(this.ctx.sampleRate * 0.04);\n        const buffer = this.ctx.createBuffer(1, bufferSize, this.ctx.sampleRate);\n        const data = buffer.getChannelData(0);\n        for (let i = 0; i < bufferSize; i++) {\n          data[i] = (Math.random() * 2 - 1) * Math.sin((i / bufferSize) * Math.PI);\n        }\n\n        const sweep = this.ctx.createBufferSource();\n        sweep.buffer = buffer;\n\n        const sweepFilter = this.ctx.createBiquadFilter();\n        sweepFilter.type = \"bandpass\";\n        sweepFilter.frequency.setValueAtTime(800 + Math.random() * 200, tickTime);\n        sweepFilter.Q.setValueAtTime(2, tickTime);\n\n        const sweepGain = this.ctx.createGain();\n        sweepGain.gain.setValueAtTime(0.08, tickTime);\n        sweepGain.gain.exponentialRampToValueAtTime(0.001, tickTime + 0.038);\n\n        sweep.connect(sweepFilter);\n        sweepFilter.connect(sweepGain);\n        sweepGain.connect(this.ctx.destination);\n\n        sweep.start(tickTime);\n      }, intervalMs);\n    } catch {\n      // AudioContext fallback\n    }\n  }\n\n  public stopPrintingSound() {\n    if (this.printingInterval !== null) {\n      clearInterval(this.printingInterval);\n      this.printingInterval = null;\n    }\n    if (this.motorOsc) {\n      try {\n        this.motorOsc.stop();\n        this.motorOsc.disconnect();\n      } catch {\n        // Ignored\n      }\n      this.motorOsc = null;\n    }\n    if (this.motorGain) {\n      this.motorGain.disconnect();\n      this.motorGain = null;\n    }\n  }\n\n  // Realistic paper tear rip effect\n  public playTearSound() {\n    if (this.isMuted || typeof window === \"undefined\") return;\n    try {\n      this.initContext();\n      if (!this.ctx) return;\n\n      const now = this.ctx.currentTime;\n      const duration = 0.16;\n      const bufferSize = Math.floor(this.ctx.sampleRate * duration);\n      const buffer = this.ctx.createBuffer(1, bufferSize, this.ctx.sampleRate);\n      const data = buffer.getChannelData(0);\n\n      for (let i = 0; i < bufferSize; i++) {\n        const progress = i / bufferSize;\n        const envelope = Math.sin(progress * Math.PI) * (1 - progress * 0.6);\n        const stutter = Math.sin(i * 0.08) > 0 ? 1 : 0.4;\n        data[i] = (Math.random() * 2 - 1) * envelope * stutter;\n      }\n\n      const noise = this.ctx.createBufferSource();\n      noise.buffer = buffer;\n\n      const filter = this.ctx.createBiquadFilter();\n      filter.type = \"bandpass\";\n      filter.frequency.setValueAtTime(2200, now);\n      filter.frequency.linearRampToValueAtTime(800, now + duration);\n      filter.Q.setValueAtTime(1.8, now);\n\n      const gain = this.ctx.createGain();\n      gain.gain.setValueAtTime(0.3, now);\n      gain.gain.exponentialRampToValueAtTime(0.01, now + duration);\n\n      noise.connect(filter);\n      filter.connect(gain);\n      gain.connect(this.ctx.destination);\n\n      noise.start(now);\n    } catch {\n      // AudioContext fallback\n    }\n  }\n\n  // Heavy rubber stamp \"THUD\" sound\n  public playStampSound() {\n    if (this.isMuted || typeof window === \"undefined\") return;\n    try {\n      this.initContext();\n      if (!this.ctx) return;\n\n      const now = this.ctx.currentTime;\n      const osc = this.ctx.createOscillator();\n      const gain = this.ctx.createGain();\n\n      osc.type = \"sine\";\n      osc.frequency.setValueAtTime(160, now);\n      osc.frequency.exponentialRampToValueAtTime(35, now + 0.12);\n\n      gain.gain.setValueAtTime(0.4, now);\n      gain.gain.exponentialRampToValueAtTime(0.001, now + 0.14);\n\n      osc.connect(gain);\n      gain.connect(this.ctx.destination);\n\n      osc.start(now);\n      osc.stop(now + 0.15);\n    } catch {\n      // AudioContext fallback\n    }\n  }\n}\n\n// Global audio singleton instance\nconst printerAudio = new ProceduralPrinterAudio();\n\n// ============================================================================\n// THERMAL RECEIPT DOCUMENT COMPONENT\n// ============================================================================\n\nexport interface ThermalReceiptProps {\n  data: InvoiceData;\n  isCompleted?: boolean;\n  showStamp?: boolean;\n  stampText?: string;\n  stampType?: \"paid\" | \"verified\" | \"approved\";\n  stampPosition?: \"bottom-right\" | \"center\" | \"top-right\";\n  isTorn?: boolean;\n  className?: string;\n  onLogoClick?: () => void;\n}\n\nexport const ThermalReceipt: React.FC<ThermalReceiptProps> = ({\n  data,\n  isCompleted = false,\n  showStamp = true,\n  stampText = \"PAID IN FULL\",\n  stampType = \"paid\",\n  stampPosition = \"center\",\n  isTorn = false,\n  className,\n  onLogoClick,\n}) => {\n  return (\n    <div\n      className={cn(\n        \"relative w-full max-w-[320px] select-none text-neutral-900 bg-[#fbfbf9] transition-all duration-300 shadow-2xl\",\n        className\n      )}\n    >\n      {/* Serrated Top Edge - ONLY shown when torn or detached */}\n      {isTorn && (\n        <div className=\"w-full h-2 overflow-hidden text-[#fbfbf9] relative -mt-[1px]\">\n          <svg\n            viewBox=\"0 0 320 8\"\n            className=\"w-full h-2 fill-current\"\n            preserveAspectRatio=\"none\"\n          >\n            <path d=\"M0,8 L5,0 L10,8 L15,0 L20,8 L25,0 L30,8 L35,0 L40,8 L45,0 L50,8 L55,0 L60,8 L65,0 L70,8 L75,0 L80,8 L85,0 L90,8 L95,0 L100,8 L105,0 L110,8 L115,0 L120,8 L125,0 L130,8 L135,0 L140,8 L145,0 L150,8 L155,0 L160,8 L165,0 L170,8 L175,0 L180,8 L185,0 L190,8 L195,0 L200,8 L205,0 L210,8 L215,0 L220,8 L225,0 L230,8 L235,0 L240,8 L245,0 L250,8 L255,0 L260,8 L265,0 L270,8 L275,0 L280,8 L285,0 L290,8 L295,0 L300,8 L305,0 L310,8 L315,0 L320,8 Z\" />\n          </svg>\n        </div>\n      )}\n\n      {/* Main Thermal Receipt Content */}\n      <div\n        className={cn(\n          \"px-5 py-3 font-mono text-[11px] leading-snug text-[#111111] relative\",\n          !isTorn && \"pt-3\"\n        )}\n      >\n        {/* Compact Brand Header */}\n        <div className=\"text-center pb-2\">\n          {data.companyLogo ? (\n            <img\n              src={data.companyLogo}\n              alt={data.companyName}\n              onClick={onLogoClick}\n              className={cn(\n                \"w-8 h-8 object-contain mx-auto mb-1 rounded\",\n                onLogoClick && \"cursor-pointer hover:opacity-80 transition-opacity\"\n              )}\n              title={onLogoClick ? \"Click to change brand logo\" : undefined}\n            />\n          ) : (\n            <div\n              onClick={onLogoClick}\n              className={cn(\"flex justify-center mb-1\", onLogoClick && \"cursor-pointer hover:scale-105 transition-transform\")}\n              title={onLogoClick ? \"Click to change brand logo\" : undefined}\n            >\n              <div className=\"w-6 h-6 rounded-full border border-black flex items-center justify-center space-x-[1.5px] p-0.5\">\n                <span className=\"w-[1.5px] h-2.5 bg-black\" />\n                <span className=\"w-[1.5px] h-4 bg-black\" />\n                <span className=\"w-[1.5px] h-2 bg-black\" />\n                <span className=\"w-[1.5px] h-3 bg-black\" />\n              </div>\n            </div>\n          )}\n          {data.invoiceTitle && (\n            <p className=\"text-[8.5px] tracking-widest text-neutral-500 font-bold uppercase mb-0.5\">\n              {data.invoiceTitle}\n            </p>\n          )}\n          <h3 className=\"font-extrabold text-sm tracking-wider uppercase\">\n            {data.companyName}\n          </h3>\n          {data.companySubtitle && (\n            <p className=\"text-[9px] tracking-widest text-neutral-600 uppercase\">\n              {data.companySubtitle}\n            </p>\n          )}\n          {data.companyAddress && (\n            <p className=\"text-[8.5px] text-neutral-500 font-mono leading-tight mt-0.5 max-w-[240px] mx-auto\">\n              {data.companyAddress}\n            </p>\n          )}\n          {data.companyGstin && (\n            <div className=\"text-[8.5px] font-mono font-bold text-neutral-800 tracking-tight mt-0.5\">\n              {data.companyGstin}\n            </div>\n          )}\n        </div>\n\n        {/* Metadata Bar */}\n        <div className=\"border-y border-dashed border-neutral-400 py-1.5 my-1 text-[9px] flex justify-between tracking-tight text-neutral-700\">\n          <span>{data.invoiceNumber}</span>\n          <span>{data.issueDate}</span>\n          <span className=\"font-bold text-black\">{data.clientName}</span>\n        </div>\n\n        {/* Client Extended Details (Address & GSTIN) */}\n        {(data.clientAddress || data.clientGstin) && (\n          <div className=\"text-[8.5px] font-mono text-neutral-600 pb-1.5 border-b border-dashed border-neutral-300 space-y-0.5 text-left\">\n            {data.clientAddress && <div>ADDR: {data.clientAddress}</div>}\n            {data.clientGstin && (\n              <div className=\"font-bold text-black\">BUYER GST: {data.clientGstin}</div>\n            )}\n          </div>\n        )}\n\n        {/* Itemized Table */}\n        <div className=\"py-2\">\n          <div className=\"flex justify-between font-bold border-b border-neutral-300 pb-1 text-[10px] uppercase\">\n            <span>ITEM DESCRIPTION</span>\n            <span>TOTAL</span>\n          </div>\n\n          <div className=\"divide-y divide-neutral-200/80\">\n            {data.items.map((item) => (\n              <div key={item.id} className=\"py-1.5 flex justify-between items-center\">\n                <div className=\"pr-2 truncate\">\n                  <div className=\"font-bold truncate text-[10.5px]\">\n                    {item.description}\n                  </div>\n                  <div className=\"text-[9px] text-neutral-500 font-normal\">\n                    {item.hsnCode && <span className=\"mr-1.5 text-[8px] text-neutral-400\">HSN:{item.hsnCode}</span>}\n                    {item.qty} × {data.currencySymbol || \"$\"}{item.rate.toFixed(2)}\n                  </div>\n                </div>\n                <div className=\"font-bold text-right text-[10.5px] whitespace-nowrap\">\n                  {data.currencySymbol || \"$\"}{item.total.toFixed(2)}\n                </div>\n              </div>\n            ))}\n          </div>\n        </div>\n\n        {/* Financial Summary */}\n        <div className=\"border-t border-dashed border-neutral-400 pt-1.5 space-y-0.5 text-[10px]\">\n          <div className=\"flex justify-between text-neutral-600\">\n            <span>SUBTOTAL</span>\n            <span>{data.currencySymbol || \"$\"}{data.subtotal.toFixed(2)}</span>\n          </div>\n          {data.taxRate !== undefined && (\n            <div className=\"flex justify-between text-neutral-600\">\n              <span>TAX ({data.taxRate}%)</span>\n              <span>{data.currencySymbol || \"$\"}{(data.taxAmount || 0).toFixed(2)}</span>\n            </div>\n          )}\n          <div className=\"flex justify-between font-extrabold text-xs text-black border-t border-black pt-1 mt-1\">\n            <span>TOTAL DUE</span>\n            <span>{data.currencySymbol || \"$\"}{data.total.toFixed(2)}</span>\n          </div>\n        </div>\n\n        {/* Payment & Bank Details */}\n        <div className=\"border-t border-dotted border-neutral-300 pt-2 mt-2 text-[9px] text-neutral-500 space-y-0.5\">\n          <div className=\"flex justify-between\">\n            <span>PAID: {data.paymentMethod || \"ELECTRONIC\"}</span>\n            <span>{data.authCode || \"AUTH OK\"}</span>\n          </div>\n          {data.bankDetails?.upiId && (\n            <div className=\"text-right text-[8px] font-bold text-neutral-600\">\n              UPI ID: {data.bankDetails.upiId}\n            </div>\n          )}\n        </div>\n\n        {/* Crisp Barcode */}\n        <div className=\"pt-2 pb-1 flex flex-col items-center\">\n          <div className=\"w-full flex items-end justify-center space-x-[2px] h-6 overflow-hidden px-4\">\n            <span className=\"w-[1.5px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[2.5px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[3px] h-full bg-black\" />\n            <span className=\"w-[1.5px] h-full bg-black\" />\n            <span className=\"w-[2px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[3.5px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[2px] h-full bg-black\" />\n            <span className=\"w-[1.5px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[3px] h-full bg-black\" />\n            <span className=\"w-[2px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[2px] h-full bg-black\" />\n            <span className=\"w-[3px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[1.5px] h-full bg-black\" />\n            <span className=\"w-[2px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[3.5px] h-full bg-black\" />\n            <span className=\"w-[1.5px] h-full bg-black\" />\n            <span className=\"w-[2px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[2.5px] h-full bg-black\" />\n            <span className=\"w-[1px] h-full bg-black\" />\n            <span className=\"w-[3px] h-full bg-black\" />\n            <span className=\"w-[1.5px] h-full bg-black\" />\n            <span className=\"w-[2px] h-full bg-black\" />\n          </div>\n          <span className=\"text-[8px] tracking-widest text-neutral-400 mt-0.5\">\n            *{data.invoiceNumber.replace(/[^a-zA-Z0-9]/g, \"\")}*\n          </span>\n        </div>\n\n        {/* Footer Note */}\n        {data.footerNote && (\n          <div className=\"text-center text-[8.5px] text-neutral-400 tracking-wider pt-1 uppercase\">\n            *** {data.footerNote} ***\n          </div>\n        )}\n\n        {/* Rubber Ink Stamp */}\n        <AnimatePresence>\n          {isCompleted && showStamp && (\n            <motion.div\n              key=\"thermal-rubber-stamp\"\n              initial={{ scale: 2.2, opacity: 0, rotate: -18 }}\n              animate={{ scale: 1, opacity: 0.88, rotate: -12 }}\n              exit={{ opacity: 0, scale: 0.8 }}\n              transition={{\n                type: \"spring\",\n                stiffness: 450,\n                damping: 18,\n                delay: 0.1,\n              }}\n              className={cn(\n                \"pointer-events-none z-20\",\n                stampPosition === \"bottom-right\"\n                  ? \"absolute bottom-12 right-6\"\n                  : \"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2\"\n              )}\n            >\n              <div\n                className={cn(\n                  \"px-4 py-1.5 border-4 border-dashed rounded-lg text-center tracking-widest font-black uppercase text-base shadow-sm transform -rotate-6\",\n                  stampType === \"verified\"\n                    ? \"border-emerald-700 text-emerald-800\"\n                    : stampType === \"approved\"\n                    ? \"border-sky-700 text-sky-800\"\n                    : \"border-red-600 text-red-700\"\n                )}\n                style={{\n                  textShadow: \"1px 1px 0px rgba(0,0,0,0.1)\",\n                }}\n              >\n                {stampText}\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n\n      {/* Serrated Bottom Edge */}\n      <div className=\"w-full h-2 overflow-hidden text-[#fbfbf9] relative -mb-[1px]\">\n        <svg\n          viewBox=\"0 0 320 8\"\n          className=\"w-full h-2 fill-current\"\n          preserveAspectRatio=\"none\"\n        >\n          <path d=\"M0,0 L5,8 L10,0 L15,8 L20,0 L25,8 L30,0 L35,8 L40,0 L45,8 L50,0 L55,8 L60,0 L65,8 L70,0 L75,8 L80,0 L85,8 L90,0 L95,8 L100,0 L105,8 L110,0 L115,8 L120,0 L125,8 L130,0 L135,8 L140,0 L145,8 L150,0 L155,8 L160,0 L165,8 L170,0 L175,8 L180,0 L185,8 L190,0 L195,8 L200,0 L205,8 L210,0 L215,8 L220,0 L225,8 L230,0 L235,8 L240,0 L245,8 L250,0 L255,8 L260,0 L265,8 L270,0 L275,8 L280,0 L285,8 L290,0 L295,8 L300,0 L305,8 L310,0 L315,8 L320,0 Z\" />\n        </svg>\n      </div>\n    </div>\n  );\n};\n\n// ============================================================================\n// CORPORATE A4 INVOICE SHEET COMPONENT\n// ============================================================================\n\nexport interface A4InvoiceSheetProps {\n  data: InvoiceData;\n  isCompleted?: boolean;\n  showStamp?: boolean;\n  stampText?: string;\n  stampType?: \"paid\" | \"verified\" | \"approved\";\n  stampPosition?: \"bottom-right\" | \"center\" | \"top-right\";\n  className?: string;\n  onLogoClick?: () => void;\n}\n\nexport const A4InvoiceSheet: React.FC<A4InvoiceSheetProps> = ({\n  data,\n  isCompleted = false,\n  showStamp = true,\n  stampText = \"PAID IN FULL\",\n  stampType = \"paid\",\n  stampPosition = \"bottom-right\",\n  className,\n  onLogoClick,\n}) => {\n  return (\n    <div\n      className={cn(\n        \"relative w-full max-w-[480px] bg-white text-neutral-900 select-none shadow-2xl rounded-sm border border-neutral-200/80 transition-all duration-300 font-sans\",\n        className\n      )}\n    >\n      {/* Header Accent Bar */}\n      <div className=\"h-2 w-full bg-neutral-900 rounded-t-sm\" />\n\n      {/* Main A4 Document Body */}\n      <div className=\"p-7 text-xs leading-relaxed text-neutral-800 relative\">\n        {/* Top Header: Brand Identity & Title */}\n        <div className=\"flex justify-between items-start pb-5 border-b border-neutral-200\">\n          <div>\n            <div className=\"flex items-center space-x-2.5 mb-2\">\n              {data.companyLogo ? (\n                <div className=\"relative group/logo\">\n                  <img\n                    src={data.companyLogo}\n                    alt={data.companyName}\n                    onClick={onLogoClick}\n                    className={cn(\n                      \"w-10 h-10 object-contain rounded-lg border border-neutral-200 p-0.5 shadow-sm bg-white\",\n                      onLogoClick && \"cursor-pointer hover:ring-2 hover:ring-black/20 hover:scale-105 transition-all\"\n                    )}\n                    title={onLogoClick ? \"Click to customize brand logo\" : undefined}\n                  />\n                  {onLogoClick && (\n                    <span className=\"absolute -bottom-1 -right-1 w-3.5 h-3.5 bg-neutral-900 text-white rounded-full flex items-center justify-center text-[8px] opacity-0 group-hover/logo:opacity-100 transition-opacity shadow pointer-events-none\">\n                      ✎\n                    </span>\n                  )}\n                </div>\n              ) : (\n                <div className=\"relative group/logo\">\n                  <div\n                    onClick={onLogoClick}\n                    className={cn(\n                      \"w-10 h-10 rounded-lg bg-black text-white flex items-center justify-center font-black text-sm shadow-sm tracking-tight\",\n                      onLogoClick && \"cursor-pointer hover:ring-2 hover:ring-black/30 hover:scale-105 transition-all\"\n                    )}\n                    title={onLogoClick ? \"Click to customize brand logo\" : undefined}\n                  >\n                    {data.companyLogoBadge || data.companyName.slice(0, 2).toUpperCase()}\n                  </div>\n                  {onLogoClick && (\n                    <span className=\"absolute -bottom-1 -right-1 w-3.5 h-3.5 bg-neutral-800 text-white rounded-full flex items-center justify-center text-[8px] opacity-0 group-hover/logo:opacity-100 transition-opacity shadow pointer-events-none\">\n                      ✎\n                    </span>\n                  )}\n                </div>\n              )}\n              <div>\n                <h2 className=\"font-extrabold text-sm tracking-tight text-black leading-snug\">\n                  {data.companyName}\n                </h2>\n                {data.companySubtitle && (\n                  <p className=\"text-[10px] text-neutral-500 font-mono tracking-tight\">\n                    {data.companySubtitle}\n                  </p>\n                )}\n              </div>\n            </div>\n\n            {data.companyAddress && (\n              <p className=\"text-[9.5px] text-neutral-500 font-mono leading-tight max-w-[260px]\">\n                {data.companyAddress}\n              </p>\n            )}\n\n            {data.companyGstin && (\n              <div className=\"inline-flex items-center space-x-1 mt-1.5 px-2 py-0.5 rounded bg-neutral-100 border border-neutral-200 text-[9px] font-mono font-bold text-neutral-800\">\n                <span>{data.companyGstin}</span>\n              </div>\n            )}\n\n            {(data.companyEmail || data.companyPhone) && (\n              <p className=\"text-[9px] text-neutral-400 font-mono mt-0.5\">\n                {[data.companyEmail, data.companyPhone].filter(Boolean).join(\" • \")}\n              </p>\n            )}\n          </div>\n\n          {/* Invoice Title & Number */}\n          <div className=\"text-right\">\n            <h1 className=\"font-black text-2xl tracking-tight text-neutral-900 mb-0.5 uppercase\">\n              {data.invoiceTitle || \"TAX INVOICE\"}\n            </h1>\n            <p className=\"text-[10.5px] font-mono text-neutral-500 font-bold tracking-wider\">\n              {data.invoiceNumber}\n            </p>\n\n            <div className=\"flex flex-col items-end space-y-1 mt-2\">\n              <div className=\"inline-flex items-center space-x-1.5 px-2.5 py-0.5 bg-neutral-100 rounded text-[9.5px] font-mono text-neutral-700\">\n                <span className=\"text-neutral-400 font-semibold\">DATE:</span>\n                <span className=\"font-bold\">{data.issueDate}</span>\n              </div>\n              {data.dueDate && (\n                <div className=\"inline-flex items-center space-x-1.5 px-2.5 py-0.5 bg-amber-500/10 border border-amber-500/20 rounded text-[9.5px] font-mono text-amber-700 font-bold\">\n                  <span className=\"opacity-70\">DUE:</span>\n                  <span>{data.dueDate}</span>\n                </div>\n              )}\n              {data.poNumber && (\n                <span className=\"text-[9px] font-mono text-neutral-400 font-medium\">\n                  PO: {data.poNumber}\n                </span>\n              )}\n            </div>\n          </div>\n        </div>\n\n        {/* Bill To & Details Grid */}\n        <div className=\"grid grid-cols-2 gap-4 py-4 border-b border-neutral-100 text-[11px]\">\n          <div>\n            <span className=\"text-[9px] font-mono font-bold text-neutral-400 uppercase tracking-widest block mb-1\">\n              BILLED TO (BUYER):\n            </span>\n            <p className=\"font-extrabold text-neutral-900 text-xs leading-tight\">{data.clientName}</p>\n            {data.clientRef && <p className=\"text-[10px] text-neutral-500 font-mono\">{data.clientRef}</p>}\n            {data.clientAddress && (\n              <p className=\"text-[9.5px] text-neutral-600 font-mono leading-tight mt-0.5 max-w-[210px]\">\n                {data.clientAddress}\n              </p>\n            )}\n            {data.clientGstin && (\n              <div className=\"mt-1.5 font-mono text-[9px] text-neutral-800 font-bold bg-neutral-100 px-2 py-0.5 rounded inline-flex items-center border border-neutral-200\">\n                <span className=\"text-neutral-400 mr-1\">BUYER GST:</span>\n                <span>{data.clientGstin}</span>\n              </div>\n            )}\n            {data.clientEmail && (\n              <p className=\"text-[9px] text-neutral-400 font-mono mt-0.5\">{data.clientEmail}</p>\n            )}\n          </div>\n\n          <div className=\"text-right\">\n            <span className=\"text-[9px] font-mono font-bold text-neutral-400 uppercase tracking-widest block mb-1\">\n              PAYMENT & TERMS:\n            </span>\n            <p className=\"font-mono text-neutral-800 font-bold text-xs\">{data.paymentMethod || \"ELECTRONIC TRANSFER\"}</p>\n            {data.paymentTerms && (\n              <p className=\"text-[9.5px] font-mono text-neutral-600 font-semibold\">{data.paymentTerms}</p>\n            )}\n            {data.authCode && <p className=\"text-[9px] text-neutral-400 font-mono\">{data.authCode}</p>}\n\n            {/* Bank / UPI Details */}\n            {data.bankDetails && (\n              <div className=\"mt-2 text-[8.5px] font-mono text-neutral-600 bg-neutral-50 p-2 rounded-lg border border-neutral-200/80 text-right leading-tight space-y-0.5\">\n                {data.bankDetails.bankName && <div className=\"font-bold text-neutral-800\">{data.bankDetails.bankName}</div>}\n                {data.bankDetails.accountNumber && <div>A/C: {data.bankDetails.accountNumber}</div>}\n                {data.bankDetails.ifscOrSwift && <div>IFSC/SWIFT: {data.bankDetails.ifscOrSwift}</div>}\n                {data.bankDetails.upiId && <div className=\"text-emerald-700 font-bold\">UPI: {data.bankDetails.upiId}</div>}\n              </div>\n            )}\n          </div>\n        </div>\n\n        {/* Itemized Table */}\n        <div className=\"py-3\">\n          <table className=\"w-full text-left border-collapse\">\n            <thead>\n              <tr className=\"border-b-2 border-neutral-900 text-[10px] font-mono font-bold uppercase text-neutral-600\">\n                <th className=\"py-2\">Description</th>\n                <th className=\"py-2 text-center w-12\">Qty</th>\n                <th className=\"py-2 text-right w-24\">Rate</th>\n                <th className=\"py-2 text-right w-28\">Amount</th>\n              </tr>\n            </thead>\n            <tbody className=\"divide-y divide-neutral-200\">\n              {data.items.map((item) => (\n                <tr key={item.id} className=\"text-[11px]\">\n                  <td className=\"py-2.5 pr-2\">\n                    <div className=\"font-bold text-neutral-900 leading-snug\">{item.description}</div>\n                    {item.hsnCode && (\n                      <span className=\"text-[9px] font-mono text-neutral-400 block\">\n                        HSN/SAC: {item.hsnCode}\n                      </span>\n                    )}\n                  </td>\n                  <td className=\"py-2.5 text-center font-mono text-neutral-600\">\n                    {item.qty}\n                  </td>\n                  <td className=\"py-2.5 text-right font-mono text-neutral-600\">\n                    {data.currencySymbol || \"$\"}{item.rate.toFixed(2)}\n                  </td>\n                  <td className=\"py-2.5 text-right font-mono font-bold text-neutral-900\">\n                    {data.currencySymbol || \"$\"}{item.total.toFixed(2)}\n                  </td>\n                </tr>\n              ))}\n            </tbody>\n          </table>\n        </div>\n\n        {/* Summary Breakdown */}\n        <div className=\"border-t border-neutral-200 pt-3 flex justify-end\">\n          <div className=\"w-56 space-y-1.5 text-[11px]\">\n            <div className=\"flex justify-between text-neutral-600\">\n              <span>Subtotal</span>\n              <span className=\"font-mono\">{data.currencySymbol || \"$\"}{data.subtotal.toFixed(2)}</span>\n            </div>\n            {data.taxRate !== undefined && (\n              <div className=\"flex justify-between text-neutral-600\">\n                <span>Tax ({data.taxRate}%)</span>\n                <span className=\"font-mono\">{data.currencySymbol || \"$\"}{(data.taxAmount || 0).toFixed(2)}</span>\n              </div>\n            )}\n            {data.discount !== undefined && data.discount > 0 && (\n              <div className=\"flex justify-between text-emerald-600\">\n                <span>Discount</span>\n                <span className=\"font-mono\">-{data.currencySymbol || \"$\"}{data.discount.toFixed(2)}</span>\n              </div>\n            )}\n            <div className=\"flex justify-between font-black text-sm text-neutral-900 border-t-2 border-neutral-900 pt-2 mt-1\">\n              <span>Grand Total</span>\n              <span className=\"font-mono\">{data.currencySymbol || \"$\"}{data.total.toFixed(2)}</span>\n            </div>\n          </div>\n        </div>\n\n        {/* Footer & Signature */}\n        <div className=\"border-t border-neutral-200 pt-4 mt-4 flex justify-between items-end text-[10px] text-neutral-500\">\n          <div className=\"max-w-[240px]\">\n            {data.termsAndConditions ? (\n              <p className=\"text-[8.5px] text-neutral-400 font-mono leading-tight\">\n                <span className=\"font-bold text-neutral-600\">TERMS: </span>\n                {data.termsAndConditions}\n              </p>\n            ) : (\n              <div>\n                <p className=\"font-bold text-neutral-800\">Authorized Electronic Receipt</p>\n                <p className=\"font-mono text-[9px]\">{data.transactionId}</p>\n              </div>\n            )}\n          </div>\n\n          <div className=\"text-right\">\n            {data.authorizedSignatoryName && (\n              <div className=\"text-[10px] font-bold text-neutral-800 tracking-wide uppercase mb-0.5\">\n                {data.authorizedSignatoryName}\n              </div>\n            )}\n            <div className=\"w-28 border-b border-neutral-400 mb-1 ml-auto\" />\n            <span className=\"text-[8.5px] font-mono uppercase tracking-widest text-neutral-400\">\n              {data.authorizedSignatoryTitle || \"AUTHORIZED SIGNATORY\"}\n            </span>\n          </div>\n        </div>\n\n        {/* Rubber Stamp */}\n        <AnimatePresence>\n          {isCompleted && showStamp && (\n            <motion.div\n              key=\"a4-rubber-stamp\"\n              initial={{ scale: 2.2, opacity: 0, rotate: -22 }}\n              animate={{ scale: 1, opacity: 0.88, rotate: -12 }}\n              exit={{ opacity: 0, scale: 0.8 }}\n              transition={{\n                type: \"spring\",\n                stiffness: 450,\n                damping: 18,\n                delay: 0.1,\n              }}\n              className={cn(\n                \"pointer-events-none z-20\",\n                stampPosition === \"center\"\n                  ? \"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2\"\n                  : stampPosition === \"top-right\"\n                  ? \"absolute top-20 right-8\"\n                  : \"absolute bottom-14 right-8\"\n              )}\n            >\n              <div\n                className={cn(\n                  \"px-5 py-2 border-4 border-dashed rounded-lg text-center tracking-widest font-black uppercase text-lg shadow-sm transform -rotate-6\",\n                  stampType === \"verified\"\n                    ? \"border-emerald-700 text-emerald-800\"\n                    : stampType === \"approved\"\n                    ? \"border-sky-700 text-sky-800\"\n                    : \"border-red-600 text-red-700\"\n                )}\n                style={{ textShadow: \"1px 1px 0px rgba(0,0,0,0.1)\" }}\n              >\n                {stampText}\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n};\n\n// ============================================================================\n// ISOLATED INVOICE PRINT & DOWNLOAD ENGINE (PRINT ONLY THE INVOICE)\n// ============================================================================\n\n/**\n * Generates clean, self-contained HTML for printing or downloading ONLY the\n * invoice receipt or corporate A4 sheet with zero external dependencies.\n */\nexport function generateInvoicePrintHtml(\n  data: InvoiceData,\n  format: \"a4\" | \"thermal\" = \"a4\",\n  showStamp: boolean = true,\n  stampText: string = \"PAID IN FULL\",\n  stampType: \"paid\" | \"verified\" | \"approved\" = \"paid\",\n  stampPosition: \"bottom-right\" | \"center\" | \"top-right\" = \"bottom-right\"\n): string {\n  const isThermal = format === \"thermal\";\n  const currSym = data.currencySymbol || \"$\";\n\n  const stampColor =\n    stampType === \"verified\"\n      ? { border: \"#047857\", text: \"#065f46\" }\n      : stampType === \"approved\"\n      ? { border: \"#0284c7\", text: \"#0369a1\" }\n      : { border: \"#dc2626\", text: \"#b91c1c\" };\n\n  const barcodePattern = [\n    2, 1, 3, 1, 4, 2, 2, 1, 4, 1, 2, 2, 1, 4, 2, 1, 3, 4, 1, 2, 3, 1, 4, 2, 3, 1, 3, 1, 4, 2, 3\n  ];\n  const barcodeSpans = barcodePattern\n    .map(\n      (w) =>\n        `<span style=\"display:inline-block;width:${w}px;height:24px;background:#000;margin-right:1.5px;\"></span>`\n    )\n    .join(\"\");\n\n  const thermalItemsHtml = data.items\n    .map(\n      (item) => `\n      <div style=\"display:flex;justify-content:space-between;align-items:flex-start;padding:6px 0;border-bottom:1px solid #e5e5e5;\">\n        <div style=\"flex:1;padding-right:8px;\">\n          <div style=\"font-weight:700;font-size:11.5px;color:#000;\">${item.description}</div>\n          <div style=\"font-size:9.5px;color:#555;\">\n            ${item.hsnCode ? `<span style=\"margin-right:6px;font-size:8.5px;color:#888;\">HSN:${item.hsnCode}</span>` : \"\"}\n            ${item.qty} × ${currSym}${item.rate.toFixed(2)}\n          </div>\n        </div>\n        <div style=\"font-weight:700;font-size:11.5px;text-align:right;white-space:nowrap;color:#000;\">\n          ${currSym}${item.total.toFixed(2)}\n        </div>\n      </div>\n    `\n    )\n    .join(\"\");\n\n  const a4ItemsHtml = data.items\n    .map(\n      (item) => `\n      <tr style=\"border-bottom:1px solid #e5e7eb;font-size:11px;\">\n        <td style=\"padding:9px 4px;\">\n          <div style=\"font-weight:700;color:#111827;line-height:1.3;\">${item.description}</div>\n          ${item.hsnCode ? `<div style=\"font-size:9px;color:#9ca3af;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;margin-top:1px;\">HSN/SAC: ${item.hsnCode}</div>` : \"\"}\n        </td>\n        <td style=\"padding:9px 4px;text-align:center;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;color:#4b5563;\">${item.qty}</td>\n        <td style=\"padding:9px 4px;text-align:right;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;color:#4b5563;\">${currSym}${item.rate.toFixed(2)}</td>\n        <td style=\"padding:9px 4px;text-align:right;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-weight:700;color:#111827;\">${currSym}${item.total.toFixed(2)}</td>\n      </tr>\n    `\n    )\n    .join(\"\");\n\n  const thermalContent = `\n    <div class=\"thermal-receipt\">\n      <div class=\"receipt-header\">\n        ${data.companyLogo ? `<img src=\"${data.companyLogo}\" style=\"width:32px;height:32px;object-fit:contain;margin:0 auto 4px;display:block;\" />` : `\n          <div class=\"logo-ring\">\n            <span style=\"display:inline-block;width:2px;height:10px;background:#000;margin:0 1px;\"></span>\n            <span style=\"display:inline-block;width:2px;height:16px;background:#000;margin:0 1px;\"></span>\n            <span style=\"display:inline-block;width:2px;height:8px;background:#000;margin:0 1px;\"></span>\n            <span style=\"display:inline-block;width:2px;height:13px;background:#000;margin:0 1px;\"></span>\n          </div>\n        `}\n        ${data.invoiceTitle ? `<div style=\"font-size:9px;letter-spacing:1.5px;color:#666;font-weight:700;text-transform:uppercase;\">${data.invoiceTitle}</div>` : \"\"}\n        <h2 style=\"margin:2px 0;font-size:15px;font-weight:800;letter-spacing:1.5px;text-transform:uppercase;\">${data.companyName}</h2>\n        ${data.companySubtitle ? `<div style=\"font-size:9.5px;letter-spacing:2px;color:#555;text-transform:uppercase;\">${data.companySubtitle}</div>` : \"\"}\n        ${data.companyAddress ? `<div style=\"font-size:9px;color:#666;margin-top:2px;\">${data.companyAddress}</div>` : \"\"}\n        ${data.companyGstin ? `<div style=\"font-size:9px;font-weight:700;color:#111;margin-top:2px;\">${data.companyGstin}</div>` : \"\"}\n      </div>\n\n      <div class=\"divider-dashed\">\n        <span>${data.invoiceNumber}</span>\n        <span>${data.issueDate}</span>\n        <span style=\"font-weight:700;color:#000;\">${data.clientName}</span>\n      </div>\n\n      ${(data.clientAddress || data.clientGstin) ? `\n        <div style=\"font-size:8.5px;color:#555;padding-bottom:5px;border-bottom:1px dashed #777;margin-bottom:6px;\">\n          ${data.clientAddress ? `<div>ADDR: ${data.clientAddress}</div>` : \"\"}\n          ${data.clientGstin ? `<div style=\"font-weight:700;color:#000;\">BUYER GST: ${data.clientGstin}</div>` : \"\"}\n        </div>\n      ` : \"\"}\n\n      <div style=\"margin:8px 0;\">\n        <div style=\"display:flex;justify-content:space-between;font-weight:800;border-bottom:1px solid #bbb;padding-bottom:4px;font-size:10px;text-transform:uppercase;\">\n          <span>ITEM DESCRIPTION</span>\n          <span>TOTAL</span>\n        </div>\n        ${thermalItemsHtml}\n      </div>\n\n      <div class=\"totals-section\">\n        <div style=\"display:flex;justify-content:space-between;color:#555;margin-bottom:3px;\">\n          <span>SUBTOTAL</span>\n          <span>${currSym}${data.subtotal.toFixed(2)}</span>\n        </div>\n        ${\n          data.taxRate !== undefined\n            ? `\n          <div style=\"display:flex;justify-content:space-between;color:#555;margin-bottom:3px;\">\n            <span>TAX (${data.taxRate}%)</span>\n            <span>${currSym}${(data.taxAmount || 0).toFixed(2)}</span>\n          </div>\n        `\n            : \"\"\n        }\n        <div class=\"total-due\">\n          <span>TOTAL DUE</span>\n          <span>${currSym}${data.total.toFixed(2)}</span>\n        </div>\n      </div>\n\n      <div class=\"payment-details\">\n        <span>PAID: ${data.paymentMethod || \"ELECTRONIC\"}</span>\n        <span>${data.authCode || \"AUTH OK\"}</span>\n      </div>\n\n      ${data.bankDetails?.upiId ? `<div style=\"font-size:8.5px;text-align:right;color:#333;margin-top:3px;font-weight:700;\">UPI: ${data.bankDetails.upiId}</div>` : \"\"}\n\n      <div class=\"barcode-area\">\n        <div class=\"barcode-bars\">\n          ${barcodeSpans}\n        </div>\n        <div class=\"barcode-text\">*${data.invoiceNumber.replace(/[^a-zA-Z0-9]/g, \"\")}*</div>\n      </div>\n\n      ${data.footerNote ? `<div class=\"footer-note\">*** ${data.footerNote} ***</div>` : \"\"}\n\n      ${\n        showStamp\n          ? `\n        <div class=\"rubber-stamp rubber-stamp-${stampPosition}\" style=\"border-color:${stampColor.border};color:${stampColor.text};\">\n          ${stampText}\n        </div>\n      `\n          : \"\"\n      }\n    </div>\n  `;\n\n  const a4Content = `\n    <div class=\"a4-card\">\n      <div class=\"a4-accent-bar\"></div>\n\n      <div class=\"a4-body\">\n        <div class=\"a4-top-header\">\n          <div class=\"a4-brand-col\">\n            <div class=\"a4-brand-row\">\n              ${data.companyLogo ? `\n                <img src=\"${data.companyLogo}\" class=\"a4-logo-img\" />\n              ` : `\n                <div class=\"a4-logo-badge\">${data.companyLogoBadge || data.companyName.slice(0, 2).toUpperCase()}</div>\n              `}\n              <div>\n                <h2 class=\"a4-company-name\">${data.companyName}</h2>\n                ${data.companySubtitle ? `<div class=\"a4-company-subtitle\">${data.companySubtitle}</div>` : \"\"}\n              </div>\n            </div>\n            ${data.companyAddress ? `<div class=\"a4-company-address\">${data.companyAddress}</div>` : \"\"}\n            ${data.companyGstin ? `<div class=\"a4-gstin-badge\">${data.companyGstin}</div>` : \"\"}\n            ${(data.companyEmail || data.companyPhone) ? `<div class=\"a4-company-contact\">${[data.companyEmail, data.companyPhone].filter(Boolean).join(\" • \")}</div>` : \"\"}\n          </div>\n\n          <div class=\"a4-invoice-meta-col\">\n            <h1 class=\"a4-invoice-title\">${data.invoiceTitle || \"TAX INVOICE\"}</h1>\n            <div class=\"a4-invoice-num\">${data.invoiceNumber}</div>\n            <div class=\"a4-date-pill\">\n              <span style=\"color:#9ca3af;font-weight:600;margin-right:4px;\">DATE:</span>\n              <strong>${data.issueDate}</strong>\n            </div>\n            ${data.dueDate ? `<div class=\"a4-due-pill\"><span style=\"opacity:0.75;margin-right:3px;\">DUE:</span>${data.dueDate}</div>` : \"\"}\n            ${data.poNumber ? `<div class=\"a4-po-num\">PO: ${data.poNumber}</div>` : \"\"}\n          </div>\n        </div>\n\n        <div class=\"a4-details-grid\">\n          <div>\n            <div class=\"a4-field-label\">BILLED TO (BUYER):</div>\n            <div class=\"a4-client-name\">${data.clientName}</div>\n            ${data.clientRef ? `<div class=\"a4-client-ref\">${data.clientRef}</div>` : \"\"}\n            ${data.clientAddress ? `<div class=\"a4-client-address\">${data.clientAddress}</div>` : \"\"}\n            ${data.clientGstin ? `<div class=\"a4-gstin-badge\" style=\"margin-top:4px;\">BUYER GST: ${data.clientGstin}</div>` : \"\"}\n            ${data.clientEmail ? `<div style=\"font-size:9px;color:#9ca3af;font-family:ui-monospace,monospace;margin-top:3px;\">${data.clientEmail}</div>` : \"\"}\n          </div>\n\n          <div style=\"text-align:right;\">\n            <div class=\"a4-field-label\">PAYMENT & TERMS:</div>\n            <div class=\"a4-payment-method\">${data.paymentMethod || \"ELECTRONIC TRANSFER\"}</div>\n            ${data.paymentTerms ? `<div class=\"a4-payment-terms\">${data.paymentTerms}</div>` : \"\"}\n            ${data.authCode ? `<div style=\"font-size:9px;color:#9ca3af;font-family:ui-monospace,monospace;margin-top:1px;\">${data.authCode}</div>` : \"\"}\n            ${data.bankDetails ? `\n              <div class=\"a4-bank-box\">\n                ${data.bankDetails.bankName ? `<div style=\"font-weight:700;color:#111827;\">${data.bankDetails.bankName}</div>` : \"\"}\n                ${data.bankDetails.accountNumber ? `<div>A/C: ${data.bankDetails.accountNumber}</div>` : \"\"}\n                ${data.bankDetails.ifscOrSwift ? `<div>IFSC/SWIFT: ${data.bankDetails.ifscOrSwift}</div>` : \"\"}\n                ${data.bankDetails.upiId ? `<div style=\"color:#047857;font-weight:700;\">UPI: ${data.bankDetails.upiId}</div>` : \"\"}\n              </div>\n            ` : \"\"}\n          </div>\n        </div>\n\n        <div class=\"a4-table-wrap\">\n          <table class=\"a4-table\">\n            <thead>\n              <tr>\n                <th style=\"text-align:left;\">Description</th>\n                <th style=\"text-align:center;width:48px;\">Qty</th>\n                <th style=\"text-align:right;width:85px;\">Rate</th>\n                <th style=\"text-align:right;width:95px;\">Amount</th>\n              </tr>\n            </thead>\n            <tbody>\n              ${a4ItemsHtml}\n            </tbody>\n          </table>\n        </div>\n\n        <div class=\"a4-totals-row\">\n          <div class=\"a4-totals-box\">\n            <div class=\"a4-total-line\">\n              <span>Subtotal</span>\n              <span class=\"a4-mono\">${currSym}${data.subtotal.toFixed(2)}</span>\n            </div>\n            ${\n              data.taxRate !== undefined\n                ? `\n              <div class=\"a4-total-line\">\n                <span>Tax (${data.taxRate}%)</span>\n                <span class=\"a4-mono\">${currSym}${(data.taxAmount || 0).toFixed(2)}</span>\n              </div>\n            `\n                : \"\"\n            }\n            ${\n              data.discount !== undefined && data.discount > 0\n                ? `\n              <div class=\"a4-total-line\" style=\"color:#047857;\">\n                <span>Discount</span>\n                <span class=\"a4-mono\">-${currSym}${data.discount.toFixed(2)}</span>\n              </div>\n            `\n                : \"\"\n            }\n            <div class=\"a4-grand-total-line\">\n              <span>Grand Total</span>\n              <span class=\"a4-mono\">${currSym}${data.total.toFixed(2)}</span>\n            </div>\n          </div>\n        </div>\n\n        <div class=\"a4-footer-row\">\n          <div class=\"a4-footer-left\">\n            ${data.termsAndConditions ? `\n              <div style=\"font-size:8.5px;color:#6b7280;font-family:ui-monospace,monospace;line-height:1.35;\">\n                <strong style=\"color:#111827;\">TERMS:</strong> ${data.termsAndConditions}\n              </div>\n            ` : `\n              <div style=\"font-weight:700;color:#1f2937;\">Authorized Electronic Receipt</div>\n              <div style=\"font-family:ui-monospace,monospace;font-size:9px;color:#6b7280;\">${data.transactionId || \"\"}</div>\n            `}\n          </div>\n          <div class=\"a4-footer-right\">\n            ${data.authorizedSignatoryName ? `<div style=\"font-weight:700;color:#111827;font-size:10px;text-transform:uppercase;margin-bottom:3px;\">${data.authorizedSignatoryName}</div>` : \"\"}\n            <div class=\"a4-sign-line\"></div>\n            <div class=\"a4-sign-label\">\n              ${data.authorizedSignatoryTitle || \"AUTHORIZED SIGNATORY\"}\n            </div>\n          </div>\n        </div>\n\n        ${\n          showStamp\n            ? `\n          <div class=\"a4-stamp a4-stamp-${stampPosition}\" style=\"border-color:${stampColor.border};color:${stampColor.text};\">\n            ${stampText}\n          </div>\n        `\n            : \"\"\n        }\n      </div>\n    </div>\n  `;\n\n  return `<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n    <title>Invoice - ${data.invoiceNumber}</title>\n    <style>\n      @page {\n        size: ${isThermal ? \"80mm auto\" : \"A4 portrait\"};\n        margin: 0mm;\n      }\n      * {\n        box-sizing: border-box;\n        -webkit-print-color-adjust: exact !important;\n        print-color-adjust: exact !important;\n      }\n      html, body {\n        margin: 0;\n        padding: 0;\n        background: #ffffff;\n        color: #111827;\n        -webkit-font-smoothing: antialiased;\n      }\n      body {\n        font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n        display: flex;\n        justify-content: center;\n        align-items: flex-start;\n        padding: ${isThermal ? \"4mm\" : \"12mm 15mm\"};\n        min-height: ${isThermal ? \"auto\" : \"297mm\"};\n      }\n      /* Thermal POS Styles */\n      .thermal-receipt {\n        position: relative;\n        width: 100%;\n        max-width: 72mm;\n        padding: 10px 8px;\n        background: #ffffff;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Courier New\", monospace;\n        color: #111111;\n        border: 1px dashed #e5e7eb;\n      }\n      .receipt-header {\n        text-align: center;\n        padding-bottom: 6px;\n      }\n      .logo-ring {\n        display: inline-flex;\n        align-items: center;\n        justify-content: center;\n        width: 26px;\n        height: 26px;\n        border: 1px solid #000;\n        border-radius: 50%;\n        margin-bottom: 4px;\n      }\n      .divider-dashed {\n        border-top: 1px dashed #777;\n        border-bottom: 1px dashed #777;\n        padding: 5px 0;\n        margin: 8px 0;\n        font-size: 9.5px;\n        display: flex;\n        justify-content: space-between;\n        color: #444;\n      }\n      .totals-section {\n        border-top: 1px dashed #777;\n        padding-top: 6px;\n        font-size: 10px;\n      }\n      .total-due {\n        display: flex;\n        justify-content: space-between;\n        font-weight: 900;\n        font-size: 13px;\n        border-top: 1px solid #000;\n        padding-top: 5px;\n        margin-top: 5px;\n        color: #000;\n      }\n      .payment-details {\n        border-top: 1px dotted #aaa;\n        margin-top: 8px;\n        padding-top: 6px;\n        font-size: 9px;\n        display: flex;\n        justify-content: space-between;\n        color: #555;\n      }\n      .barcode-area {\n        margin-top: 10px;\n        text-align: center;\n      }\n      .barcode-bars {\n        display: flex;\n        justify-content: center;\n        align-items: flex-end;\n        height: 24px;\n        overflow: hidden;\n      }\n      .barcode-text {\n        font-size: 8px;\n        letter-spacing: 1.5px;\n        color: #666;\n        margin-top: 2px;\n      }\n      .footer-note {\n        text-align: center;\n        font-size: 8.5px;\n        color: #555;\n        margin-top: 8px;\n        text-transform: uppercase;\n      }\n      /* Rubber Stamp for Thermal POS */\n      .rubber-stamp {\n        position: absolute;\n        pointer-events: none;\n        border: 3.5px dashed;\n        border-radius: 8px;\n        padding: 5px 14px;\n        font-size: 14px;\n        font-weight: 900;\n        letter-spacing: 2px;\n        text-transform: uppercase;\n        opacity: 0.88;\n      }\n      .rubber-stamp-bottom-right {\n        bottom: 35px;\n        right: 12px;\n        transform: rotate(-10deg);\n      }\n      .rubber-stamp-center {\n        top: 50%;\n        left: 50%;\n        transform: translate(-50%, -50%) rotate(-12deg);\n      }\n      .rubber-stamp-top-right {\n        top: 60px;\n        right: 12px;\n        transform: rotate(-10deg);\n      }\n\n      /* Corporate A4 Sheet Styles (Matches UI 1:1) */\n      .a4-card {\n        position: relative;\n        width: 100%;\n        max-width: 175mm;\n        background: #ffffff;\n        border: 1px solid #e5e7eb;\n        border-radius: 4px;\n        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);\n        box-sizing: border-box;\n        display: flex;\n        flex-direction: column;\n      }\n      .a4-accent-bar {\n        height: 8px;\n        width: 100%;\n        background: #111827;\n        border-top-left-radius: 4px;\n        border-top-right-radius: 4px;\n        flex-shrink: 0;\n      }\n      .a4-body {\n        position: relative;\n        padding: 24px 28px 22px 28px;\n        font-size: 12px;\n        line-height: 1.45;\n        color: #1f2937;\n        display: flex;\n        flex-direction: column;\n      }\n      .a4-top-header {\n        display: flex;\n        justify-content: space-between;\n        align-items: flex-start;\n        padding-bottom: 18px;\n        border-bottom: 1px solid #e5e7eb;\n      }\n      .a4-brand-col {\n        max-width: 62%;\n      }\n      .a4-brand-row {\n        display: flex;\n        align-items: center;\n        margin-bottom: 6px;\n      }\n      .a4-logo-badge {\n        width: 36px;\n        height: 36px;\n        border-radius: 8px;\n        background: #000000;\n        color: #ffffff;\n        display: flex;\n        align-items: center;\n        justify-content: center;\n        font-weight: 900;\n        font-size: 13px;\n        letter-spacing: -0.5px;\n        margin-right: 10px;\n        flex-shrink: 0;\n      }\n      .a4-logo-img {\n        width: 38px;\n        height: 38px;\n        object-fit: contain;\n        border-radius: 8px;\n        border: 1px solid #e5e7eb;\n        padding: 2px;\n        background: #ffffff;\n        margin-right: 10px;\n        flex-shrink: 0;\n      }\n      .a4-company-name {\n        margin: 0;\n        font-size: 14px;\n        font-weight: 800;\n        letter-spacing: -0.3px;\n        color: #000000;\n        line-height: 1.25;\n        text-transform: uppercase;\n      }\n      .a4-company-subtitle {\n        font-size: 9.5px;\n        color: #6b7280;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        letter-spacing: 0.2px;\n        margin-top: 1px;\n      }\n      .a4-company-address {\n        font-size: 9.5px;\n        color: #6b7280;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        line-height: 1.35;\n        max-width: 270px;\n        margin-top: 4px;\n      }\n      .a4-gstin-badge {\n        display: inline-flex;\n        align-items: center;\n        margin-top: 6px;\n        padding: 2px 7px;\n        background: #f3f4f6;\n        border: 1px solid #e5e7eb;\n        border-radius: 4px;\n        font-size: 9px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        font-weight: 700;\n        color: #1f2937;\n      }\n      .a4-company-contact {\n        font-size: 9px;\n        color: #9ca3af;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        margin-top: 3px;\n      }\n      .a4-invoice-meta-col {\n        text-align: right;\n        display: flex;\n        flex-direction: column;\n        align-items: flex-end;\n      }\n      .a4-invoice-title {\n        margin: 0 0 2px 0;\n        font-size: 24px;\n        font-weight: 900;\n        letter-spacing: -0.5px;\n        color: #111827;\n        text-transform: uppercase;\n        line-height: 1.1;\n      }\n      .a4-invoice-num {\n        font-size: 11px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        font-weight: 700;\n        color: #6b7280;\n        letter-spacing: 0.5px;\n      }\n      .a4-date-pill {\n        display: inline-flex;\n        align-items: center;\n        margin-top: 8px;\n        padding: 2.5px 8px;\n        background: #f3f4f6;\n        border-radius: 4px;\n        font-size: 9.5px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        color: #374151;\n      }\n      .a4-due-pill {\n        display: inline-flex;\n        align-items: center;\n        margin-top: 4px;\n        padding: 2.5px 8px;\n        background: rgba(245, 158, 11, 0.1);\n        border: 1px solid rgba(245, 158, 11, 0.25);\n        border-radius: 4px;\n        font-size: 9.5px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        color: #b45309;\n        font-weight: 700;\n      }\n      .a4-po-num {\n        font-size: 9px;\n        color: #9ca3af;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        margin-top: 4px;\n      }\n      .a4-details-grid {\n        display: grid;\n        grid-template-columns: 1fr 1fr;\n        gap: 20px;\n        padding: 14px 0;\n        border-bottom: 1px solid #f3f4f6;\n        font-size: 11px;\n      }\n      .a4-field-label {\n        font-size: 9px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        font-weight: 700;\n        color: #9ca3af;\n        text-transform: uppercase;\n        letter-spacing: 1px;\n        margin-bottom: 3px;\n      }\n      .a4-client-name {\n        font-size: 12.5px;\n        font-weight: 800;\n        color: #111827;\n        line-height: 1.25;\n      }\n      .a4-client-ref {\n        font-size: 10px;\n        color: #6b7280;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        margin-top: 1px;\n      }\n      .a4-client-address {\n        font-size: 9.5px;\n        color: #4b5563;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        line-height: 1.35;\n        max-width: 220px;\n        margin-top: 3px;\n      }\n      .a4-payment-method {\n        font-size: 12px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        font-weight: 700;\n        color: #1f2937;\n      }\n      .a4-payment-terms {\n        font-size: 9.5px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        color: #4b5563;\n        font-weight: 600;\n        margin-top: 2px;\n      }\n      .a4-bank-box {\n        margin-top: 8px;\n        padding: 6px 8px;\n        background: #f9fafb;\n        border: 1px solid #e5e7eb;\n        border-radius: 6px;\n        font-size: 8.5px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        color: #4b5563;\n        line-height: 1.35;\n        text-align: right;\n      }\n      .a4-table-wrap {\n        padding: 12px 0 6px 0;\n      }\n      .a4-table {\n        width: 100%;\n        border-collapse: collapse;\n      }\n      .a4-table thead tr {\n        border-bottom: 2px solid #111827;\n        font-size: 10px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        font-weight: 700;\n        text-transform: uppercase;\n        color: #4b5563;\n      }\n      .a4-table th {\n        padding: 8px 4px;\n      }\n      .a4-table tbody tr {\n        border-bottom: 1px solid #e5e7eb;\n        font-size: 11px;\n      }\n      .a4-table td {\n        padding: 9px 4px;\n      }\n      .a4-totals-row {\n        display: flex;\n        justify-content: flex-end;\n        border-top: 1px solid #e5e7eb;\n        padding-top: 10px;\n        margin-top: 2px;\n      }\n      .a4-totals-box {\n        width: 220px;\n        font-size: 11px;\n      }\n      .a4-total-line {\n        display: flex;\n        justify-content: space-between;\n        color: #4b5563;\n        margin-bottom: 4px;\n      }\n      .a4-grand-total-line {\n        display: flex;\n        justify-content: space-between;\n        font-weight: 900;\n        font-size: 14px;\n        color: #111827;\n        border-top: 2px solid #111827;\n        padding-top: 8px;\n        margin-top: 4px;\n      }\n      .a4-mono {\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n      }\n      .a4-footer-row {\n        border-top: 1px solid #e5e7eb;\n        margin-top: 16px;\n        padding-top: 14px;\n        display: flex;\n        justify-content: space-between;\n        align-items: flex-end;\n        font-size: 10px;\n        color: #6b7280;\n      }\n      .a4-footer-left {\n        max-width: 240px;\n      }\n      .a4-footer-right {\n        text-align: right;\n      }\n      .a4-sign-line {\n        width: 120px;\n        border-bottom: 1px solid #9ca3af;\n        margin-bottom: 3px;\n        margin-left: auto;\n      }\n      .a4-sign-label {\n        font-size: 8.5px;\n        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n        text-transform: uppercase;\n        letter-spacing: 1px;\n        color: #9ca3af;\n      }\n\n      /* Rubber Stamp for Corporate A4 */\n      .a4-stamp {\n        position: absolute;\n        pointer-events: none;\n        border: 3.5px dashed;\n        border-radius: 8px;\n        padding: 6px 18px;\n        font-size: 17px;\n        font-weight: 900;\n        letter-spacing: 2.5px;\n        text-transform: uppercase;\n        opacity: 0.88;\n        white-space: nowrap;\n      }\n      .a4-stamp-bottom-right {\n        bottom: 16px;\n        right: 28px;\n        transform: rotate(-7deg);\n      }\n      .a4-stamp-center {\n        top: 50%;\n        left: 50%;\n        transform: translate(-50%, -50%) rotate(-10deg);\n      }\n      .a4-stamp-top-right {\n        top: 80px;\n        right: 28px;\n        transform: rotate(-10deg);\n      }\n    </style>\n  </head>\n  <body>\n    ${isThermal ? thermalContent : a4Content}\n  </body>\n</html>`;\n}\n\n/**\n * Triggers browser print/PDF preview exclusively for the invoice document\n * by isolating it in a temporary iframe. This prevents the parent webpage,\n * navbar, sidebar, or UI controls from appearing in the print output.\n */\nexport function printInvoiceDocument(\n  data: InvoiceData,\n  format: \"a4\" | \"thermal\" = \"a4\",\n  showStamp: boolean = true,\n  stampText: string = \"PAID IN FULL\",\n  stampType: \"paid\" | \"verified\" | \"approved\" = \"paid\",\n  stampPosition: \"bottom-right\" | \"center\" | \"top-right\" = \"bottom-right\"\n): void {\n  if (typeof window === \"undefined\") return;\n\n  const iframe = document.createElement(\"iframe\");\n  iframe.id = \"invoice-printer-isolated-frame\";\n  iframe.setAttribute(\n    \"style\",\n    \"position:fixed;right:0;bottom:0;width:0;height:0;border:none;visibility:hidden;z-index:-9999;\"\n  );\n  document.body.appendChild(iframe);\n\n  const doc = iframe.contentWindow?.document;\n  if (!doc) return;\n\n  const html = generateInvoicePrintHtml(data, format, showStamp, stampText, stampType, stampPosition);\n\n  doc.open();\n  doc.write(html);\n  doc.close();\n\n  setTimeout(() => {\n    try {\n      iframe.contentWindow?.focus();\n      iframe.contentWindow?.print();\n    } catch (err) {\n      console.error(\"Invoice printing failed:\", err);\n    } finally {\n      setTimeout(() => {\n        try {\n          if (iframe.parentNode) {\n            iframe.parentNode.removeChild(iframe);\n          } else if (iframe.remove) {\n            iframe.remove();\n          }\n        } catch {\n          // ignore already removed\n        }\n      }, 2500);\n    }\n  }, 250);\n}\n\n/**\n * Directly downloads the standalone HTML invoice document.\n */\nexport function downloadInvoiceHtml(\n  data: InvoiceData,\n  format: \"a4\" | \"thermal\" = \"a4\",\n  showStamp: boolean = true,\n  stampText: string = \"PAID IN FULL\",\n  stampType: \"paid\" | \"verified\" | \"approved\" = \"paid\",\n  stampPosition: \"bottom-right\" | \"center\" | \"top-right\" = \"bottom-right\"\n): void {\n  if (typeof window === \"undefined\") return;\n\n  const html = generateInvoicePrintHtml(data, format, showStamp, stampText, stampType, stampPosition);\n  const blob = new Blob([html], { type: \"text/html;charset=utf-8\" });\n  const url = URL.createObjectURL(blob);\n  const link = document.createElement(\"a\");\n  link.href = url;\n  link.download = `${data.invoiceNumber || \"invoice\"}.html`;\n  document.body.appendChild(link);\n  link.click();\n  URL.revokeObjectURL(url);\n}\n\n// ============================================================================\n// MAIN COMPONENT: INVOICE PRINTER\n// ============================================================================\n\nexport function InvoicePrinter({\n  invoiceData: customData,\n  format = \"a4\",\n  theme = \"system\",\n  speed = 1,\n  soundEnabled = true,\n  autoPrint = false,\n  showStamp = true,\n  stampText = \"PAID IN FULL\",\n  stampType = \"paid\",\n  stampPosition = \"bottom-right\",\n  allowTear = true,\n  showControls = true,\n  className,\n  printerClassName,\n  receiptClassName,\n  onPrintStart,\n  onPrintComplete,\n  onTear,\n  onDownload,\n  onLogoClick,\n}: InvoicePrinterProps) {\n  // Merge customized invoice data with defaults\n  const data: InvoiceData = {\n    ...defaultInvoiceData,\n    ...customData,\n  };\n\n  const [status, setStatus] = useState<PrinterStatus>(\"idle\");\n  const [isTorn, setIsTorn] = useState<boolean>(false);\n  const [printPercentage, setPrintPercentage] = useState<number>(0);\n  const [isMuted, setIsMuted] = useState<boolean>(!soundEnabled);\n  const componentId = useId();\n\n  // Sync mute state with prop\n  useEffect(() => {\n    setIsMuted(!soundEnabled);\n    printerAudio.setMuted(!soundEnabled);\n  }, [soundEnabled]);\n\n  // Determine light/dark theme\n  const [resolvedTheme, setResolvedTheme] = useState<\"light\" | \"dark\">(\"dark\");\n\n  useEffect(() => {\n    if (theme === \"light\") {\n      setResolvedTheme(\"light\");\n    } else if (theme === \"dark\") {\n      setResolvedTheme(\"dark\");\n    } else {\n      // System or dark class on document element\n      const isDocDark = typeof document !== \"undefined\" && document.documentElement.classList.contains(\"dark\");\n      setResolvedTheme(isDocDark ? \"dark\" : \"light\");\n\n      if (typeof document === \"undefined\") return;\n      const observer = new MutationObserver(() => {\n        const isDarkNow = document.documentElement.classList.contains(\"dark\");\n        setResolvedTheme(isDarkNow ? \"dark\" : \"light\");\n      });\n\n      observer.observe(document.documentElement, {\n        attributes: true,\n        attributeFilter: [\"class\"],\n      });\n\n      return () => observer.disconnect();\n    }\n  }, [theme]);\n\n  const isLight = resolvedTheme === \"light\";\n  const printDuration = format === \"a4\" ? 4.8 / speed : 4.0 / speed;\n\n  // Print execution handler\n  const handleStartPrint = () => {\n    if (status === \"printing\") return;\n\n    printerAudio.playButtonClick();\n    setStatus(\"preparing\");\n    setIsTorn(false);\n    setPrintPercentage(0);\n    onPrintStart?.();\n\n    setTimeout(() => {\n      setStatus(\"printing\");\n      if (format === \"a4\") {\n        printerAudio.startOfficePrinterSound(speed);\n      } else {\n        printerAudio.startPrintingSound(speed);\n      }\n\n      const start = Date.now();\n      const interval = setInterval(() => {\n        const elapsed = (Date.now() - start) / 1000;\n        const pct = Math.min(100, Math.floor((elapsed / printDuration) * 100));\n        setPrintPercentage(pct);\n        if (pct >= 100) {\n          clearInterval(interval);\n        }\n      }, 40);\n\n      setTimeout(() => {\n        clearInterval(interval);\n        setPrintPercentage(100);\n        printerAudio.stopPrintingSound();\n        printerAudio.playStampSound();\n        setStatus(\"completed\");\n        onPrintComplete?.(data);\n      }, printDuration * 1000);\n    }, 380);\n  };\n\n  // Tear-off execution handler\n  const handleTear = () => {\n    if (status !== \"completed\" || isTorn || !allowTear) return;\n    printerAudio.playTearSound();\n    setIsTorn(true);\n    setStatus(\"torn\");\n    onTear?.();\n  };\n\n  // Reset handler\n  const handleReset = () => {\n    printerAudio.playButtonClick();\n    printerAudio.stopPrintingSound();\n    setStatus(\"idle\");\n    setIsTorn(false);\n    setPrintPercentage(0);\n  };\n\n  // Download / Print PDF handler (Prints ONLY the isolated invoice)\n  const handleDownload = () => {\n    printerAudio.playButtonClick();\n    if (onDownload) {\n      onDownload(data);\n    } else {\n      printInvoiceDocument(data, format, showStamp, stampText, stampType, stampPosition);\n    }\n  };\n\n  // Auto-print on mount if requested\n  useEffect(() => {\n    if (autoPrint) {\n      const timer = setTimeout(() => {\n        handleStartPrint();\n      }, 500);\n      return () => clearTimeout(timer);\n    }\n  }, [autoPrint]);\n\n  // Clean up audio on unmount\n  useEffect(() => {\n    return () => {\n      printerAudio.stopPrintingSound();\n    };\n  }, []);\n\n  // Keyboard shortcut listener: Space to print, T to tear\n  useEffect(() => {\n    const handleKeyDown = (e: KeyboardEvent) => {\n      if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) return;\n      if (e.code === \"Space\") {\n        e.preventDefault();\n        if (status === \"idle\" || status === \"torn\" || status === \"completed\") {\n          handleStartPrint();\n        }\n      }\n      if (e.code === \"KeyT\") {\n        if (status === \"completed\" && !isTorn && allowTear) {\n          handleTear();\n        }\n      }\n    };\n    window.addEventListener(\"keydown\", handleKeyDown);\n    return () => window.removeEventListener(\"keydown\", handleKeyDown);\n  }, [status, isTorn, allowTear]);\n\n  // ==========================================================================\n  // RENDER: THERMAL POS RECEIPT PRINTER\n  // ==========================================================================\n  if (format === \"thermal\") {\n    return (\n      <div className={cn(\"flex flex-col items-center justify-start w-full max-w-xl mx-auto select-none py-2\", className)}>\n        {/* =====================================================================\n            PRINTER CHASSIS (OUTLET SLIT IS THE EXACT PHYSICAL BOTTOM END)\n            ===================================================================== */}\n        <div className={cn(\"relative w-full max-w-md z-30 flex flex-col items-center\", printerClassName)}>\n          {/* Ambient Desk Occlusion Shadow */}\n          <div\n            className=\"absolute -bottom-6 left-6 right-6 h-10 rounded-full blur-2xl pointer-events-none -z-10 transition-opacity duration-300\"\n            style={{\n              backgroundColor: isLight ? \"rgba(0, 0, 0, 0.16)\" : \"rgba(0, 0, 0, 0.95)\",\n            }}\n          />\n\n          {/* Printer Main Housing */}\n          <motion.div\n            animate={\n              status === \"printing\"\n                ? {\n                    x: [-0.4, 0.4, -0.2, 0.2, 0],\n                    y: [-0.15, 0.15, -0.1, 0.1, 0],\n                  }\n                : { x: 0, y: 0 }\n            }\n            transition={{\n              repeat: status === \"printing\" ? Infinity : 0,\n              duration: 0.1,\n              ease: \"linear\",\n            }}\n            className={cn(\n              \"w-full relative rounded-t-3xl overflow-hidden border-t-2 border-x-2 transition-all duration-300\",\n              isLight\n                ? \"bg-gradient-to-b from-[#ffffff] via-[#f8fafc] to-[#edf2f7] border-slate-300/90 shadow-[0_20px_40px_-15px_rgba(0,0,0,0.12)]\"\n                : \"bg-gradient-to-b from-[#27272a] via-[#18181b] to-[#101013] border-neutral-700/60 shadow-[0_25px_50px_-15px_rgba(0,0,0,0.9)]\"\n            )}\n          >\n            {/* PRINTER TOP LID: Paper Roll Compartment, Status LEDs & Latch */}\n            <div className=\"p-4 pb-3 flex items-center justify-between\">\n              {/* Smoked Roll Inspection Window */}\n              <div className=\"flex items-center space-x-3\">\n                <div\n                  className={cn(\n                    \"relative w-14 h-7 rounded-lg border overflow-hidden flex items-center justify-center shadow-inner\",\n                    isLight ? \"bg-slate-200/90 border-slate-300\" : \"bg-black/80 border-neutral-800\"\n                  )}\n                >\n                  <div className=\"flex items-center space-x-0.5\">\n                    <div className={cn(\"w-1 h-4 rounded-sm\", isLight ? \"bg-slate-400\" : \"bg-neutral-600\")} />\n                    <div\n                      className={cn(\n                        \"w-8 h-4 rounded-sm flex items-center justify-center shadow-sm\",\n                        isLight ? \"bg-white text-slate-800\" : \"bg-neutral-100 text-neutral-800\"\n                      )}\n                    >\n                      <span className=\"text-[7px] font-mono font-extrabold tracking-tighter\">80mm</span>\n                    </div>\n                    <div className={cn(\"w-1 h-4 rounded-sm\", isLight ? \"bg-slate-400\" : \"bg-neutral-600\")} />\n                  </div>\n                </div>\n\n                <div>\n                  <span className={cn(\"block text-xs font-bold tracking-wide\", isLight ? \"text-slate-900\" : \"text-white\")}>\n                    THERMAL POS PRINTER\n                  </span>\n                  <div className=\"flex items-center space-x-1.5 mt-0.5\">\n                    <span\n                      className={cn(\n                        \"w-1.5 h-1.5 rounded-full\",\n                        status === \"printing\"\n                          ? \"bg-amber-400 animate-ping\"\n                          : status === \"completed\"\n                          ? \"bg-emerald-500\"\n                          : \"bg-emerald-500/70\"\n                      )}\n                    />\n                    <span className={cn(\"text-[9px] font-mono font-semibold\", isLight ? \"text-slate-500\" : \"text-neutral-400\")}>\n                      {status === \"idle\" && \"ROLL: 94% • READY\"}\n                      {status === \"preparing\" && \"HEATING HEAD...\"}\n                      {status === \"printing\" && `FEEDING... ${printPercentage}%`}\n                      {status === \"completed\" && \"PRINT COMPLETE\"}\n                      {status === \"torn\" && \"READY FOR NEXT\"}\n                    </span>\n                  </div>\n                </div>\n              </div>\n\n              {/* Hardware LED Cluster & Latch */}\n              <div className=\"flex items-center space-x-3\">\n                <div className=\"flex flex-col items-center space-y-0.5\">\n                  <div className=\"flex space-x-1.5\">\n                    <span\n                      title=\"Power\"\n                      className={cn(\"w-2 h-2 rounded-full\", isLight ? \"bg-emerald-600 shadow-[0_0_6px_rgba(5,150,105,0.6)]\" : \"bg-emerald-500 shadow-[0_0_8px_rgba(16,185,129,0.8)]\")}\n                    />\n                    <span\n                      title=\"Busy\"\n                      className={cn(\n                        \"w-2 h-2 rounded-full\",\n                        status === \"printing\"\n                          ? \"bg-amber-400 animate-pulse shadow-[0_0_8px_rgba(251,191,36,0.9)]\"\n                          : isLight\n                          ? \"bg-slate-300\"\n                          : \"bg-neutral-800\"\n                      )}\n                    />\n                    <span\n                      title=\"Paper\"\n                      className={cn(\"w-2 h-2 rounded-full\", isLight ? \"bg-blue-500 shadow-[0_0_6px_rgba(59,130,246,0.5)]\" : \"bg-blue-400 shadow-[0_0_8px_rgba(96,165,250,0.7)]\")}\n                    />\n                  </div>\n                  <span className={cn(\"text-[7.5px] font-mono font-bold tracking-widest\", isLight ? \"text-slate-400\" : \"text-neutral-600\")}>\n                    PWR • ERR • PAP\n                  </span>\n                </div>\n\n                <div\n                  className={cn(\n                    \"w-3 h-5 rounded-sm border shadow-inner flex items-center justify-center\",\n                    isLight ? \"bg-slate-300/80 border-slate-400/80\" : \"bg-neutral-800 border-neutral-700\"\n                  )}\n                >\n                  <span className={cn(\"w-1.5 h-1 rounded-[1px]\", isLight ? \"bg-slate-500\" : \"bg-neutral-500\")} />\n                </div>\n              </div>\n            </div>\n\n            {/* CUTTER MOUTH & SERRATED TEETH (Exact Bottom Edge) */}\n            <div\n              className={cn(\n                \"relative w-full px-6 pt-1 pb-0 border-t flex flex-col justify-end\",\n                isLight ? \"bg-[#e2e8f0] border-slate-300/90\" : \"bg-[#111114] border-neutral-800\"\n              )}\n            >\n              {/* Recessed Discharge Throat */}\n              <div\n                className={cn(\n                  \"relative w-full h-3 rounded-t-sm shadow-inner flex items-center justify-center overflow-hidden\",\n                  isLight ? \"bg-slate-800\" : \"bg-black\"\n                )}\n              >\n                {/* Internal Rubber Pinch Roller */}\n                <div\n                  className={cn(\n                    \"w-full h-1 rounded-full opacity-60\",\n                    isLight ? \"bg-slate-600\" : \"bg-neutral-800\"\n                  )}\n                />\n              </div>\n\n              {/* Stainless Steel Serrated Cutter Blade Teeth */}\n              <div className=\"w-full h-2 overflow-hidden text-neutral-400 relative z-30\">\n                <svg\n                  viewBox=\"0 0 340 8\"\n                  className={cn(\"w-full h-2 fill-current\", isLight ? \"text-slate-400\" : \"text-neutral-600\")}\n                  preserveAspectRatio=\"none\"\n                >\n                  <path d=\"M0,0 L5,8 L10,0 L15,8 L20,0 L25,8 L30,0 L35,8 L40,0 L45,8 L50,0 L55,8 L60,0 L65,8 L70,0 L75,8 L80,0 L85,8 L90,0 L95,8 L100,0 L105,8 L110,0 L115,8 L120,0 L125,8 L130,0 L135,8 L140,0 L145,8 L150,0 L155,8 L160,0 L165,8 L170,0 L175,8 L180,0 L185,8 L190,0 L195,8 L200,0 L205,8 L210,0 L215,8 L220,0 L225,8 L230,0 L235,8 L240,0 L245,8 L250,0 L255,8 L260,0 L265,8 L270,0 L275,8 L280,0 L285,8 L290,0 L295,8 L300,0 L305,8 L310,0 L315,8 L320,0 L325,8 L330,0 L335,8 L340,0 Z\" />\n                </svg>\n              </div>\n            </div>\n          </motion.div>\n        </div>\n\n        {/* =====================================================================\n            PHYSICS PAPER FEED EMERGENCE (Straight Out from Cutter Teeth)\n            ===================================================================== */}\n        <div className=\"relative w-full max-w-md z-20 flex flex-col items-center -mt-[2px]\">\n          <AnimatePresence mode=\"wait\">\n            {(status === \"printing\" || status === \"completed\") && !isTorn && (\n              <motion.div\n                key=\"attached-receipt\"\n                initial={{\n                  height: 0,\n                  opacity: 1,\n                  rotateX: 10,\n                  transformOrigin: \"top center\",\n                }}\n                animate={{\n                  height: \"auto\",\n                  opacity: 1,\n                  rotateX: 0,\n                }}\n                exit={{\n                  opacity: 0,\n                  transition: { duration: 0.15 },\n                }}\n                transition={{\n                  duration: printDuration,\n                  ease: [0.16, 1, 0.3, 1],\n                }}\n                className={cn(\"w-full flex justify-center overflow-hidden\", receiptClassName)}\n                style={{\n                  perspective: 1200,\n                }}\n              >\n                <motion.div\n                  animate={{\n                    boxShadow: isLight\n                      ? \"0 18px 36px -10px rgba(0, 0, 0, 0.18), 0 8px 16px -6px rgba(0, 0, 0, 0.1)\"\n                      : \"0 28px 56px -12px rgba(0, 0, 0, 0.85), 0 12px 24px -6px rgba(0, 0, 0, 0.6)\",\n                  }}\n                  className=\"w-full max-w-[320px] transition-shadow duration-500\"\n                >\n                  <ThermalReceipt\n                    data={data}\n                    isCompleted={status === \"completed\"}\n                    showStamp={showStamp}\n                    stampText={stampText}\n                    stampType={stampType}\n                    stampPosition={stampPosition}\n                    isTorn={false}\n                    onLogoClick={onLogoClick}\n                  />\n                </motion.div>\n              </motion.div>\n            )}\n\n            {isTorn && (\n              <motion.div\n                key=\"detached-receipt\"\n                initial={{\n                  y: 0,\n                  rotate: 0,\n                  scale: 1,\n                  opacity: 1,\n                }}\n                animate={{\n                  y: 18,\n                  rotate: -2.5,\n                  scale: 0.98,\n                  opacity: 1,\n                }}\n                transition={{\n                  type: \"spring\",\n                  stiffness: 300,\n                  damping: 20,\n                }}\n                className={cn(\"w-full flex justify-center pt-2\", receiptClassName)}\n              >\n                <div\n                  className=\"w-full max-w-[320px] rounded-sm transition-shadow duration-300\"\n                  style={{\n                    boxShadow: isLight\n                      ? \"0 20px 35px -10px rgba(0, 0, 0, 0.22)\"\n                      : \"0 30px 60px -15px rgba(0, 0, 0, 0.95)\",\n                  }}\n                >\n                  <ThermalReceipt\n                    data={data}\n                    isCompleted={true}\n                    showStamp={showStamp}\n                    stampText={stampText}\n                    stampType={stampType}\n                    stampPosition={stampPosition}\n                    isTorn={true}\n                    onLogoClick={onLogoClick}\n                  />\n                </div>\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n\n        {/* =====================================================================\n            OUTER BOTTOM ACTION CONTROLS BAR\n            ===================================================================== */}\n        {showControls && (\n          <div className=\"w-full max-w-md mt-6 flex flex-col items-center space-y-3 z-40\">\n            <div className=\"flex items-center space-x-2.5 w-full justify-center\">\n              {status === \"idle\" && (\n                <button\n                  type=\"button\"\n                  onClick={handleStartPrint}\n                  className={cn(\n                    \"flex-1 max-w-[280px] flex items-center justify-center space-x-2 py-3 px-6 rounded-2xl font-bold text-sm shadow-xl transition-all duration-200 cursor-pointer active:scale-95 group\",\n                    isLight\n                      ? \"bg-slate-900 text-white hover:bg-slate-800 shadow-slate-900/20\"\n                      : \"bg-white text-black hover:bg-neutral-200 shadow-white/10\"\n                  )}\n                >\n                  <Printer size={16} className=\"group-hover:scale-110 transition-transform\" />\n                  <span>PRINT INVOICE</span>\n                  <kbd\n                    className={cn(\n                      \"ml-1 text-[10px] px-1.5 py-0.5 rounded border opacity-60 font-mono\",\n                      isLight ? \"border-slate-700 bg-slate-800 text-slate-300\" : \"border-neutral-300 bg-neutral-100 text-neutral-700\"\n                    )}\n                  >\n                    Space\n                  </kbd>\n                </button>\n              )}\n\n              {status === \"preparing\" && (\n                <button\n                  type=\"button\"\n                  disabled\n                  className={cn(\n                    \"flex-1 max-w-[280px] flex items-center justify-center space-x-2 py-3 px-6 rounded-2xl font-bold text-sm shadow-xl opacity-90 cursor-wait\",\n                    isLight ? \"bg-slate-800 text-white\" : \"bg-neutral-800 text-neutral-300\"\n                  )}\n                >\n                  <RefreshCw size={15} className=\"animate-spin text-amber-400\" />\n                  <span>WARMING UP...</span>\n                </button>\n              )}\n\n              {status === \"printing\" && (\n                <button\n                  type=\"button\"\n                  disabled\n                  className={cn(\n                    \"flex-1 max-w-[280px] flex items-center justify-center space-x-2 py-3 px-6 rounded-2xl font-bold text-sm shadow-xl cursor-wait\",\n                    isLight ? \"bg-slate-900 text-white\" : \"bg-neutral-900 text-white border border-neutral-700\"\n                  )}\n                >\n                  <RefreshCw size={15} className=\"animate-spin text-amber-400\" />\n                  <span>PRINTING... {printPercentage}%</span>\n                </button>\n              )}\n\n              {status === \"completed\" && !isTorn && (\n                <div className=\"flex items-center space-x-2 w-full justify-center\">\n                  {allowTear && (\n                    <button\n                      type=\"button\"\n                      onClick={handleTear}\n                      className=\"flex-1 max-w-[200px] flex items-center justify-center space-x-2 py-3 px-5 rounded-2xl font-bold text-sm bg-gradient-to-r from-red-600 to-rose-600 text-white hover:from-red-500 hover:to-rose-500 shadow-xl shadow-red-600/25 transition-all cursor-pointer active:scale-95 group\"\n                    >\n                      <Scissors size={15} className=\"group-hover:scale-110 transition-transform\" />\n                      <span>TEAR RECEIPT</span>\n                      <kbd className=\"ml-1 text-[10px] px-1 py-0.5 rounded bg-red-800/60 font-mono\">\n                        T\n                      </kbd>\n                    </button>\n                  )}\n\n                  <button\n                    type=\"button\"\n                    onClick={handleDownload}\n                    className={cn(\n                      \"p-3 rounded-2xl border transition-all cursor-pointer shadow-sm hover:scale-105 active:scale-95\",\n                      isLight ? \"bg-white border-slate-300 text-slate-800 hover:bg-slate-100\" : \"bg-neutral-900 border-neutral-700 text-neutral-200 hover:text-white\"\n                    )}\n                    title=\"Download / Print PDF\"\n                  >\n                    <Download size={16} />\n                  </button>\n\n                  <button\n                    type=\"button\"\n                    onClick={handleReset}\n                    className={cn(\n                      \"p-3 rounded-2xl border transition-all cursor-pointer shadow-sm hover:scale-105 active:scale-95\",\n                      isLight ? \"bg-white border-slate-300 text-slate-800 hover:bg-slate-100\" : \"bg-neutral-900 border-neutral-700 text-neutral-200 hover:text-white\"\n                    )}\n                    title=\"Reset Printer\"\n                  >\n                    <RefreshCw size={16} />\n                  </button>\n                </div>\n              )}\n\n              {status === \"torn\" && (\n                <div className=\"flex items-center space-x-2 w-full justify-center\">\n                  <button\n                    type=\"button\"\n                    onClick={handleStartPrint}\n                    className={cn(\n                      \"flex-1 max-w-[220px] flex items-center justify-center space-x-2 py-3 px-5 rounded-2xl font-bold text-sm shadow-xl transition-all cursor-pointer active:scale-95 group\",\n                      isLight ? \"bg-slate-900 text-white hover:bg-slate-800\" : \"bg-white text-black hover:bg-neutral-200\"\n                    )}\n                  >\n                    <Printer size={15} className=\"group-hover:scale-110 transition-transform\" />\n                    <span>PRINT ANOTHER</span>\n                  </button>\n\n                  <button\n                    type=\"button\"\n                    onClick={handleDownload}\n                    className={cn(\n                      \"flex items-center space-x-1.5 py-3 px-4 rounded-2xl border transition-all cursor-pointer text-xs font-bold shadow-sm\",\n                      isLight ? \"bg-white border-slate-300 text-slate-800 hover:bg-slate-100\" : \"bg-neutral-900 border-neutral-700 text-neutral-200 hover:text-white\"\n                    )}\n                  >\n                    <Download size={14} />\n                    <span>PDF</span>\n                  </button>\n                </div>\n              )}\n            </div>\n          </div>\n        )}\n      </div>\n    );\n  }\n\n  // ==========================================================================\n  // RENDER: CORPORATE A4 SHEET PRINTER\n  // ==========================================================================\n  return (\n    <div className={cn(\"flex flex-col items-center justify-start w-full max-w-2xl mx-auto select-none py-2\", className)}>\n      {/* A4 Desktop Office Laser Printer Chassis */}\n      <div className={cn(\"relative w-full max-w-lg z-30 flex flex-col items-center\", printerClassName)}>\n        {/* Soft Ambient Contact Shadow */}\n        <div\n          className=\"absolute -bottom-8 left-10 right-10 h-12 rounded-full blur-2xl pointer-events-none -z-10\"\n          style={{\n            backgroundColor: isLight ? \"rgba(0, 0, 0, 0.16)\" : \"rgba(0, 0, 0, 0.95)\",\n          }}\n        />\n\n        {/* Top Paper In-Feed Tray (Paper Stack Behind) */}\n        <div\n          className={cn(\n            \"w-[75%] h-8 rounded-t-xl border-t border-x flex items-center justify-center relative -mb-1\",\n            isLight ? \"bg-slate-200 border-slate-300 shadow-inner\" : \"bg-neutral-800 border-neutral-700 shadow-inner\"\n          )}\n        >\n          {/* Staged blank A4 sheets in tray */}\n          <div className=\"w-[85%] h-5 bg-white rounded-t border-t border-x border-neutral-300 shadow-sm flex items-center justify-center\">\n            <div className=\"w-full flex justify-between px-3 text-[8px] font-mono text-neutral-400 font-bold\">\n              <span>A4 // 80 GSM</span>\n              <span>READY</span>\n            </div>\n          </div>\n        </div>\n\n        {/* Main Office Printer Housing */}\n        <motion.div\n          animate={\n            status === \"printing\"\n              ? {\n                  x: [-0.3, 0.3, -0.2, 0.2, 0],\n                  y: [-0.1, 0.1, 0],\n                }\n              : { x: 0, y: 0 }\n          }\n          transition={{\n            repeat: status === \"printing\" ? Infinity : 0,\n            duration: 0.15,\n            ease: \"linear\",\n          }}\n          className={cn(\n            \"w-full relative rounded-2xl overflow-hidden border-2 transition-all duration-300\",\n            isLight\n              ? \"bg-gradient-to-b from-white via-slate-50 to-slate-100 border-slate-300/80 shadow-[0_20px_45px_-12px_rgba(0,0,0,0.12)]\"\n              : \"bg-gradient-to-b from-[#242428] via-[#1a1a1d] to-[#121214] border-neutral-700 shadow-[0_25px_50px_-15px_rgba(0,0,0,0.9)]\"\n          )}\n        >\n          {/* Front Control Fascia */}\n          <div className=\"p-4 pb-3 flex items-center justify-between\">\n            <div className=\"flex items-center space-x-2.5\">\n              <div\n                className={cn(\n                  \"w-8 h-8 rounded-lg flex items-center justify-center shadow-inner\",\n                  isLight ? \"bg-slate-200 text-slate-800\" : \"bg-black text-white\"\n                )}\n              >\n                <Printer size={16} />\n              </div>\n              <div>\n                <span className={cn(\"block text-xs font-bold tracking-wide\", isLight ? \"text-slate-900\" : \"text-white\")}>\n                  INVOICE PRINTER\n                </span>\n                <span className={cn(\"text-[9px] font-mono font-medium\", isLight ? \"text-slate-500\" : \"text-neutral-400\")}>\n                  DESKTOP LASERJET • 600 DPI\n                </span>\n              </div>\n            </div>\n\n            {/* Diagnostic readout */}\n            <div className=\"flex items-center space-x-2\">\n              <div\n                className={cn(\n                  \"px-2.5 py-1 rounded-md text-[9.5px] font-mono border\",\n                  isLight\n                    ? \"bg-slate-100 border-slate-300 text-slate-700\"\n                    : \"bg-black/70 border-neutral-800 text-neutral-300\"\n                )}\n              >\n                {status === \"idle\" && \"READY\"}\n                {status === \"preparing\" && \"PROCESSING...\"}\n                {status === \"printing\" && `PRINTING ${printPercentage}%`}\n                {status === \"completed\" && \"COMPLETED\"}\n              </div>\n              <span\n                className={cn(\n                  \"w-2 h-2 rounded-full\",\n                  status === \"printing\"\n                    ? \"bg-amber-400 animate-ping\"\n                    : status === \"completed\"\n                    ? \"bg-emerald-500\"\n                    : \"bg-emerald-500/80\"\n                )}\n              />\n            </div>\n          </div>\n\n          {/* Front Output Ejection Slot */}\n          <div\n            className={cn(\n              \"w-full px-6 pt-1 pb-0 border-t flex flex-col justify-end\",\n              isLight ? \"bg-slate-200/80 border-slate-300\" : \"bg-neutral-900 border-neutral-800\"\n            )}\n          >\n            <div\n              className={cn(\n                \"relative w-full h-3 rounded-t-sm shadow-inner flex items-center justify-center overflow-hidden\",\n                isLight ? \"bg-slate-800\" : \"bg-black\"\n              )}\n            >\n              <div className={cn(\"w-full h-1 rounded-full opacity-60\", isLight ? \"bg-slate-600\" : \"bg-neutral-800\")} />\n            </div>\n          </div>\n        </motion.div>\n      </div>\n\n      {/* A4 Sheet Emergence Animation */}\n      <div className=\"relative w-full max-w-lg z-20 flex flex-col items-center -mt-[2px]\">\n        <AnimatePresence>\n          {(status === \"printing\" || status === \"completed\") && (\n            <motion.div\n              key=\"a4-sheet-emergence\"\n              initial={{ height: 0, opacity: 1, rotateX: 6 }}\n              animate={{ height: \"auto\", opacity: 1, rotateX: 0 }}\n              exit={{ opacity: 0, height: 0, transition: { duration: 0.2 } }}\n              transition={{\n                duration: printDuration,\n                ease: [0.16, 1, 0.3, 1],\n              }}\n              className={cn(\"w-full flex justify-center overflow-hidden pt-1\", receiptClassName)}\n            >\n              <A4InvoiceSheet\n                data={data}\n                isCompleted={status === \"completed\"}\n                showStamp={showStamp}\n                stampText={stampText}\n                stampType={stampType}\n                stampPosition={stampPosition}\n                onLogoClick={onLogoClick}\n              />\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n\n      {/* Action Controls for A4 */}\n      {showControls && (\n        <div className=\"w-full max-w-lg mt-6 flex flex-col items-center space-y-3 z-40\">\n          <div className=\"flex items-center space-x-2.5 w-full justify-center\">\n            {status === \"idle\" && (\n              <button\n                type=\"button\"\n                onClick={handleStartPrint}\n                className={cn(\n                  \"flex-1 max-w-[280px] flex items-center justify-center space-x-2 py-3 px-6 rounded-2xl font-bold text-sm shadow-xl transition-all duration-200 cursor-pointer active:scale-95 group\",\n                  isLight\n                    ? \"bg-slate-900 text-white hover:bg-slate-800 shadow-slate-900/20\"\n                    : \"bg-white text-black hover:bg-neutral-200 shadow-white/10\"\n                )}\n              >\n                <Printer size={16} className=\"group-hover:scale-110 transition-transform\" />\n                <span>PRINT INVOICE</span>\n                <kbd\n                  className={cn(\n                    \"ml-1 text-[10px] px-1.5 py-0.5 rounded border opacity-60 font-mono\",\n                    isLight ? \"border-slate-700 bg-slate-800 text-slate-300\" : \"border-neutral-300 bg-neutral-100 text-neutral-700\"\n                  )}\n                >\n                  Space\n                </kbd>\n              </button>\n            )}\n\n            {status === \"preparing\" && (\n              <button\n                type=\"button\"\n                disabled\n                className={cn(\n                  \"flex-1 max-w-[280px] flex items-center justify-center space-x-2 py-3 px-6 rounded-2xl font-bold text-sm shadow-xl opacity-90 cursor-wait\",\n                  isLight ? \"bg-slate-800 text-white\" : \"bg-neutral-800 text-neutral-300\"\n                )}\n              >\n                <RefreshCw size={15} className=\"animate-spin text-amber-400\" />\n                <span>WARMING UP...</span>\n              </button>\n            )}\n\n            {status === \"printing\" && (\n              <button\n                type=\"button\"\n                disabled\n                className={cn(\n                  \"flex-1 max-w-[280px] flex items-center justify-center space-x-2 py-3 px-6 rounded-2xl font-bold text-sm shadow-xl cursor-wait\",\n                  isLight ? \"bg-slate-900 text-white\" : \"bg-neutral-900 text-white border border-neutral-700\"\n                )}\n              >\n                <RefreshCw size={15} className=\"animate-spin text-amber-400\" />\n                <span>PRINTING A4... {printPercentage}%</span>\n              </button>\n            )}\n\n            {status === \"completed\" && (\n              <div className=\"flex items-center space-x-2 w-full justify-center\">\n                <button\n                  type=\"button\"\n                  onClick={handleDownload}\n                  className=\"flex-1 max-w-[200px] flex items-center justify-center space-x-2 py-3 px-5 rounded-2xl font-bold text-sm bg-gradient-to-r from-emerald-600 to-teal-600 text-white hover:from-emerald-500 hover:to-teal-500 shadow-xl shadow-emerald-600/25 transition-all cursor-pointer active:scale-95 group\"\n                >\n                  <Download size={15} className=\"group-hover:scale-110 transition-transform\" />\n                  <span>DOWNLOAD PDF</span>\n                </button>\n\n                <button\n                  type=\"button\"\n                  onClick={handleReset}\n                  className={cn(\n                    \"p-3 rounded-2xl border transition-all cursor-pointer shadow-sm hover:scale-105 active:scale-95\",\n                    isLight ? \"bg-white border-slate-300 text-slate-800 hover:bg-slate-100\" : \"bg-neutral-900 border-neutral-700 text-neutral-200 hover:text-white\"\n                  )}\n                  title=\"Reset Printer\"\n                >\n                  <RefreshCw size={16} />\n                </button>\n              </div>\n            )}\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default InvoicePrinter;\n"
    }
  ]
}