/*
 * Customer-facing sale receipt — standalone page (no admin shell), loaded
 * at /admin/sales/{id}/receipt. Three paper-size modes; the body class
 * `receipt-paper-58mm` / `receipt-paper-80mm` / `receipt-paper-a4` flips
 * the layout to match what the operator picked at
 * /admin/settings/receipt.
 *
 * Most cashiers print this via the browser's native Print dialog (works
 * for thermal printers via OS-level driver, and "Save as PDF" handles
 * the email/share case). The `.receipt-toolbar` is hidden when printing.
 */

/* Self-contained tokens — the receipt page is intentionally minimal
   and doesn't pull in the full admin CSS chain. Tweak these here if
   you need to brand the on-screen toolbar; the printed receipt itself
   is always black-on-white. */
:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg-page: #F4F4F6;
  --bg-surface: #FFFFFF;
  --bg-hover: #EFEFF1;
  --border-default: #D9D9DC;
  --border-strong: #C5C5C9;
  --text-primary: #1C1C1F;
}

* { box-sizing: border-box; }

/* ── Page chrome (screen only) ─────────────────────────────────── */

.receipt-body {
  margin: 0;
  padding: 24px 16px;
  background: var(--bg-page, #F4F4F6);
  color: var(--text-primary, #1c1c1f);
  font-family: var(--font-sans);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

.receipt-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  margin-bottom: 16px;
}

.receipt-tool-spacer { flex: 1 1 auto; }

.receipt-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border-default, #d9d9dc);
  border-radius: 8px;
  color: var(--text-primary, #1c1c1f);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.receipt-tool-btn:hover {
  background: var(--bg-hover, #efeff1);
  border-color: var(--border-strong, #c5c5c9);
}

/* ── Receipt frame ─────────────────────────────────────────────── */

.receipt {
  background: #fff;
  color: #111;
  padding: 18px 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  width: 100%;
}

/* Thermal modes — narrow, sticky to the top of the page. */
.receipt-paper-58mm .receipt { max-width: 220px; }
.receipt-paper-80mm .receipt { max-width: 300px; }

/* A4 mode — wider, sans-serif, table-like layout. */
.receipt-paper-a4 .receipt {
  max-width: 720px;
  padding: 36px 40px;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Sections ──────────────────────────────────────────────────── */

.rcpt-logo {
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 15px;
  margin-bottom: 6px;
}

.rcpt-logo-img {
  text-align: center;
  margin-bottom: 8px;
}

.rcpt-logo-img img {
  max-width: 60%;
  max-height: 60px;
  object-fit: contain;
}

.rcpt-store { text-align: center; }
.rcpt-store-name { font-weight: 700; font-size: 13px; }
.rcpt-store-addr { font-size: 11px; }
.rcpt-store-tax { font-size: 10.5px; opacity: 0.75; margin-top: 2px; }

.rcpt-header, .rcpt-footer, .rcpt-return {
  white-space: pre-wrap;
  text-align: center;
  font-size: 11px;
  margin: 6px 0;
}

.rcpt-return { font-size: 10.5px; opacity: 0.75; margin-top: 10px; }

.rcpt-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  opacity: 0.8;
  margin: 8px 0;
}

.rcpt-meta strong { font-weight: 700; opacity: 1; }

.rcpt-line { font-size: 11px; }

.rcpt-rule {
  border-top: 1px dashed #888;
  margin: 8px 0;
}

/* ── Items ─────────────────────────────────────────────────────── */

.rcpt-items { display: flex; flex-direction: column; gap: 5px; }

.rcpt-item {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 8px;
  row-gap: 1px;
}

.rcpt-item-name {
  grid-column: 1 / -1;
  font-weight: 600;
  font-size: 11.5px;
  word-break: break-word;
}

.rcpt-item-variant { font-weight: 400; opacity: 0.75; font-size: 10.5px; }

.rcpt-item-qty {
  opacity: 0.75;
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.rcpt-item-total {
  text-align: end;
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
}

.rcpt-item-note {
  grid-column: 1 / -1;
  font-size: 10.5px;
  font-style: italic;
  opacity: 0.7;
}

/* Per-line SKU / HSN code — printed under the item name when the operator
   enables it (Settings → Receipt). Monospace + dimmed so it reads as a
   reference detail, not part of the price line. */
.rcpt-item-code {
  grid-column: 1 / -1;
  font-size: 10px;
  letter-spacing: 0.02em;
  opacity: 0.7;
}

/* Per-line tax — sits in the QTY column, opposite the note column, so
   the line reads "1 × ₹50.00 │ Tax ₹7.63 (incl.)" without pushing the
   line total onto a second row. */
.rcpt-item-tax {
  grid-column: 1 / -1;
  font-size: 10.5px;
  opacity: 0.7;
}
.rcpt-item-tax-incl {
  font-style: italic;
}

/* ── Totals ────────────────────────────────────────────────────── */

.rcpt-totals { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; }

.rcpt-totals > div {
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
}

.rcpt-total {
  font-weight: 700;
  font-size: 13.5px;
  padding-top: 5px;
  margin-top: 4px;
  border-top: 1px dashed #888;
}

.rcpt-tendered { opacity: 0.7; padding-inline-start: 8px; font-size: 11px; }

/* Informational tax line — the gross subtotal above already contains
   this amount, so dim it so the customer reads it as "for your
   reference" rather than another line being added to the total. */
.rcpt-tax-incl { opacity: 0.7; font-size: 11px; }

/* ── HSN-wise tax summary (GST invoices) ───────────────────────── */

.rcpt-hsn { font-size: 10.5px; }

.rcpt-hsn-title {
  font-weight: 700;
  font-size: 11px;
  margin-bottom: 3px;
}

.rcpt-hsn-head,
.rcpt-hsn-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  column-gap: 8px;
  font-variant-numeric: tabular-nums;
}

.rcpt-hsn-head {
  opacity: 0.7;
  font-size: 10px;
  border-bottom: 1px dashed #bbb;
  padding-bottom: 2px;
  margin-bottom: 2px;
}

.rcpt-hsn-head span:not(:first-child),
.rcpt-hsn-row span:not(:first-child) { text-align: end; }

.rcpt-hsn-row { margin-top: 2px; }
.rcpt-hsn-row span:first-child { font-weight: 600; }

/* Per-component split (CGST / SGST / …) beneath its HSN row. */
.rcpt-hsn-comp {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  opacity: 0.7;
  padding-inline-start: 8px;
}

/* ── Barcode + QR stubs ────────────────────────────────────────── */

.rcpt-barcode-stub {
  text-align: center;
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: -1px;
  font-size: 22px;
  line-height: 1;
  margin-top: 10px;
}

/* Real Code 128 SVG barcode — scale to the receipt width, crisp on print. */
.rcpt-barcode {
  text-align: center;
  margin-top: 10px;
}
.rcpt-barcode svg {
  width: 80%;
  max-width: 220px;
  height: 44px;
}

.rcpt-barcode-number {
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.rcpt-qr-stub {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 12px auto 0;
}

.rcpt-qr-box {
  width: 72px;
  height: 72px;
  border: 1px dashed #555;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #666;
}

.rcpt-qr-caption {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
}

/* ── A4-specific tweaks ────────────────────────────────────────── */

.receipt-paper-a4 .rcpt-store-name { font-size: 18px; }
.receipt-paper-a4 .rcpt-meta { font-size: 12.5px; }
.receipt-paper-a4 .rcpt-item-name { font-size: 13px; }
.receipt-paper-a4 .rcpt-item-qty { font-size: 12px; }
.receipt-paper-a4 .rcpt-item-total { font-size: 13px; }
.receipt-paper-a4 .rcpt-total { font-size: 16px; }
.receipt-paper-a4 .rcpt-rule { border-color: #ddd; }

/* ── Print rules ───────────────────────────────────────────────── */

@media print {
  .receipt-toolbar { display: none !important; }
  .receipt-body {
    background: #fff;
    padding: 0;
    min-height: 0;
  }
  .receipt {
    box-shadow: none;
    padding: 4px 8px;
  }

  @page {
    margin: 0;
  }
}

/* Thermal paper sizes — CSS can't conditionally set `@page` (it's a
   page-context at-rule, not selector-scoped). The actual paper size
   ends up controlled by the OS print driver / printer config; the
   `max-width` on `.receipt` is enough to shape the on-screen + on-
   paper layout for thermal vs A4. */
