/* =========================================================
   S DESIGNS — JOB WORK INVOICE (A4 PORTRAIT PRINT)
   Mirrors invoice_cash.css so both invoice types render with
   the same theme. Only the label text inside the PDF page
   differs ("JOB WORK INVOICE" vs "CASH INVOICE").

   A4 PORTRAIT: 210mm × 297mm (8.27in × 11.69in)
   Single copy per A4 page.
   Font: 'Cera Pro' ONLY (loaded via main.css @font-face) — no fallback fonts

   MOBILE ADDITION — screen-only scaling so the fixed-width A4
   invoice fits inside narrow phone viewports. Print rules are
   untouched.
   ========================================================= */

:root {
  --ink:   #292929;
  --muted: #777;
  --line:  #d7d7d7;
  --pale:  #f0f1f4;
  --panel: #f7f7f7;
}

html, body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font-family: 'Cera Pro';
}

body { background: #ececec; }

/* ---------- Page shell ---------- */
.invoice {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  margin: 12px auto;
  padding: 8.5mm 10mm 7mm;
  background: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: 'Cera Pro';
  font-size: 11.4pt;
  color: var(--ink);
}

/* ---------- Cera Pro ONLY ---------- */
.invoice,
.invoice *,
.invoice *::before,
.invoice *::after {
  font-family: 'Cera Pro';
  font-synthesis: none;
}

/* ---------- Header (3-column grid) ---------- */
.invoice .top {
  display: grid;
  grid-template-columns: 0.76fr 1.44fr 27mm;
  gap: 1.6mm;
  align-items: stretch;
  min-height: 21mm;
  position: relative;
}

.invoice .invoice-meta {
  padding-right: 1.6mm;
  line-height: 1.5;
  font-size: 10.4pt;
  font-weight: 500;
}

.invoice .invoice-meta .heading {
  display: inline-block;
  font-size: 13.5pt;
  font-weight: 700;
  text-decoration: underline;
  margin-bottom: 2.1mm;
}

.invoice .meta-line {
  margin-top: 1.3mm;
  white-space: nowrap;
}

.invoice .invoice-meta .meta-line strong { font-weight: 700; }

.invoice .billed {
  position: relative;
  align-self: start;
  line-height: 1.5;
  padding-right: 16.3mm;
  font-size: 10.8pt;
  min-width: 0;
  font-weight: 500;
}

.invoice .billed::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3.5mm;
  width: 0.5mm;
  background: var(--line);
}

.invoice .billed,
.invoice .billed * { overflow-wrap: anywhere; }

.invoice .billed .label {
  font-size: 9.7pt;
  letter-spacing: 0.04em;
  margin-bottom: 0.25mm;
}

.invoice .billed .customer {
  font-size: 14.9pt;
  line-height: 1.25;
  font-weight: 700;
  margin-bottom: 0.25mm;
}

.invoice .billed > div:nth-child(n+3) { display: inline; }
.invoice .billed > div:nth-child(n+4)::before { content: " "; }

.invoice .billed > div.addr {
  display: block;
  font-family: 'Cera Pro';
  font-weight: 400;
}

.invoice .logo-wrap {
  text-align: center;
  position: relative;
  left: -9.9mm;
}

.invoice .logo {
  display: block;
  width: 20.5mm;
  height: 39.2mm;
  margin: 0 auto 1.4mm;
}

/* ---------- Quote band ---------- */
.invoice .tagline {
  position: relative;
  display: flex;
  align-items: flex-end;
  border-bottom: 0.5mm solid var(--line);
  margin: 0 -10mm 8.5mm;
  padding: 0 10mm 0;
  color: #d7d8d9;
  font-size: 18.5pt;
  font-weight: 700;
  letter-spacing: 0.09em;
  white-space: nowrap;
  line-height: 0.7;
}

.invoice .tagline-agency {
  position: absolute;
  right: 34mm;
  bottom: 0;
  transform: translate(50%, 50%);
  background: #fff;
  padding: 0 3.5mm;
  color: var(--ink);
  font-size: 10.7pt;
  font-weight: 700;
  letter-spacing: normal;
  line-height: 1;
}

/* ---------- Items table ---------- */
.invoice .items {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 10.4pt;
}

.invoice .items th {
  background: var(--pale);
  text-align: left;
  padding: 2.8mm 2.3mm;
  border: 0.35mm solid var(--line);
  font-size: 9.9pt;
  font-weight: 700;
}

.invoice .items td {
  padding: 2.8mm 2.3mm;
  border: 0.35mm solid #dedede;
  line-height: 1.25;
  vertical-align: middle;
  overflow-wrap: anywhere;
  font-weight: 400;
}

.invoice .items .num,
.invoice .items .date,
.invoice .items .qty,
.invoice .items .rate,
.invoice .items .amount { white-space: nowrap; }

.invoice .items .num        { width: 7%; }
.invoice .items .date       { width: 13.5%; }
.invoice .items .particular { width: 38.5%; }
.invoice .items .qty        { width: 10%; text-align: right; }
.invoice .items .rate       { width: 14%; text-align: right; }
.invoice .items .amount     { width: 17%; text-align: right; }

.invoice .items th.qty,
.invoice .items th.rate,
.invoice .items th.amount { text-align: right; }

.invoice .items .empty-cell {
  text-align: center;
  color: #999;
  padding: 7mm 2.8mm;
}

/* ---------- Totals ---------- */
.invoice .items tfoot td {
  font-size: 10.7pt;
  font-weight: 400;
  color: var(--ink);
  background: #fff;
}

.invoice .items tfoot td.label {
  text-align: right;
  color: #777;
}

.invoice .items tfoot tr.grand td {
  font-weight: 500;
  color: #222;
  background: #fafafa;
}

.invoice .items tfoot td.words-cell {
  background: #fff;
  padding: 0;
  vertical-align: bottom;
}

.invoice .items tfoot td.words-cell .words {
  margin: 0;
  border: 0;
  border-radius: 0;
  min-height: 0;
  background: transparent;
  padding: 3.5mm 4.2mm 2.8mm;
}

/* ---------- Amount in words (standalone variant) ---------- */
.invoice .words {
  margin-top: 4.2mm;
  border: 0.43mm dashed #cfcfcf;
  border-radius: 2.8mm;
  background: #f8f8f8;
  padding: 3.5mm 4.2mm;
  min-height: 17mm;
}

.invoice .words .label {
  color: #777;
  font-weight: 700;
  font-size: 9.9pt;
  margin-bottom: 1.7mm;
}

.invoice .words .value {
  font-size: 11.8pt;
  line-height: 1.25;
  font-weight: 400;
}

/* ---------- Spacer + Jurisdiction ---------- */
.invoice .spacer { flex: 1; min-height: 2.8mm; }

.invoice .jurisdiction {
  font-size: 8.7pt;
  margin: 1.4mm 0 2.8mm;
  font-weight: 400;
}

.invoice .jurisdiction strong { font-weight: 700; }

/* ---------- Footer ---------- */
.invoice .footer {
  border-top: 0.5mm solid var(--line);
  margin: 0 -10mm;
  padding: 3.5mm 10mm 0;
  display: grid;
  grid-template-columns: 1fr 1.15fr 0.7fr;
  gap: 3.5mm;
  min-height: 28mm;
  align-items: stretch;
}

.invoice .bank {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2.8mm;
  align-items: stretch;
  height: 28mm;
  font-size: 8.1pt;
  line-height: 1;
  font-weight: 500;
}

.invoice .bank > div {
  display: flex;
  flex-direction: column;
  min-height: 0;
  align-self: center;
}

.invoice .qr {
  box-sizing: border-box;
  display: block;
  width: 28mm !important;
  height: 28mm !important;
  min-width: 28mm;
  min-height: 28mm;
  max-width: 28mm;
  max-height: 28mm;
  object-fit: fill;
  border: 0.28mm solid #eee;
}

.invoice .bank-title {
  font-weight: 700;
  margin-bottom: 2.1mm;
}

.invoice .bank-details {
  display: grid;
  grid-template-columns: max-content auto 1fr;
  align-items: start;
  align-content: start;
  row-gap: 2.1mm;
  flex: 1;
}

.invoice .bank-details .k {
  white-space: nowrap;
  font-weight: 700;
}

.invoice .bank-details .s {
  padding: 0 1.1mm;
  white-space: nowrap;
}

.invoice .bank-details .v { white-space: nowrap; }

.invoice .address {
  position: relative;
  padding-left: 4mm;
  padding-right: 4mm;
  margin-left: 1.4mm;
  box-sizing: border-box;
  height: 28mm;
  font-size: 8.1pt;
  line-height: calc(1 * 8.1pt + 2.1mm);
  --addr-shift: calc((28mm - (5 * 8.1pt + 4 * 2.1mm)) / 2 - 1.05mm);
  top: var(--addr-shift);
  font-weight: 500;
}

.invoice .address strong { font-weight: 700; }

.invoice .address::before {
  content: "";
  position: absolute;
  top: calc(-1 * var(--addr-shift));
  left: 0;
  width: 0.42mm;
  height: 100%;
  background: var(--line);
}

.invoice .address::after {
  content: "";
  position: absolute;
  top: calc(-1 * var(--addr-shift));
  right: 0;
  width: 0.42mm;
  height: 100%;
  background: var(--line);
}

.invoice .sign {
  box-sizing: border-box;
  height: 28mm;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  font-size: 9.5pt;
  font-weight: 500;
}

.invoice .sign .for { white-space: nowrap; }

.invoice .sign .for strong {
  font-size: 11.9pt;
  text-decoration: underline;
  font-weight: 700;
}

.invoice .signature {
  display: block;
  width: 39.7mm;
  height: 15.6mm;
  margin: 1.4mm auto 1.4mm;
  object-fit: contain;
}

.invoice .sign .role {
  font-size: 9.9pt;
  font-weight: 500;
}

/* ---------- Screen ---------- */
@media screen {
  /* Only `body` is clipped horizontally. Setting overflow on `html` would
     make the root a scroll container and break `position: sticky` on the
     CRM sidebar (.crm-sidebar), which caused a light gap below the sidebar
     on tall invoice pages. `body { overflow-x: hidden; }` is already in
     foundation.css and is sufficient to prevent horizontal scrolling. */
  body { overflow-x: hidden; }

  .invoice {
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.15);
    max-width: 100%;
  }

  .print-sheet {
    max-width: 100%;
    overflow-x: hidden;
  }
}

/* ---------- Page + print ---------- */
@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html, body {
    width: 210mm;
    height: 296.5mm;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff;
    overflow: hidden;
  }

  .invoice {
    width: 210mm;
    height: 296.5mm;
    min-height: 296.5mm;
    margin: 0;
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  thead { display: table-header-group; }
  tr, .words, .footer { break-inside: avoid; page-break-inside: avoid; }
}

/* =========================================================
   ACTION TOOLBAR — Print / Download PDF / WhatsApp
   ========================================================= */
.invoice-actions {
  box-sizing: border-box;
  width: 210mm;
  max-width: 100%;
  margin: 14px auto;
  padding: 0 4mm;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.invoice-actions,
.invoice-actions * {
  font-family: 'Cera Pro';
  font-synthesis: none;
}

.invoice-actions.top-actions    { margin-bottom: 6px; }
.invoice-actions.bottom-actions { margin-top: 6px; }

@media print {
  .invoice-actions {
    display: none !important;
    visibility: hidden !important;
  }
}

@media (max-width: 768px) {
  .invoice-actions {
    width: 100%;
    padding: 0 14px;
    gap: 8px;
  }
  .invoice-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

/* =========================================================
   SINGLE-COPY PRINT SHEET  (A4 portrait = 210mm x 297mm)
   ========================================================= */
.print-copy { display: none; }

@media print {
  .print-sheet {
    position: relative;
    display: block;
    width: 210mm;
    height: 296.5mm;
    margin: 0;
    padding: 0;
    overflow: hidden;
    break-inside: avoid;
    page-break-inside: avoid;
    break-after: avoid;
    page-break-after: avoid;
  }

  .print-sheet .invoice {
    width: 210mm;
    height: 296.5mm;
    min-height: 296.5mm;
    margin: 0;
    box-shadow: none;
  }

  .print-copy {
    display: none !important;
    visibility: hidden !important;
  }
}

/* =========================================================
   PDF EXPORT (html2pdf)
   ========================================================= */
.invoice.pdf-export {
  width: 210mm;
  min-height: 296.5mm;
  margin: 0;
  box-shadow: none;
}

.invoice.pdf-export .billed > .customer,
.invoice.pdf-export .billed > div:nth-child(3) {
  display: block;
  width: 100%;
  clear: both;
}


/* =========================================================
   MOBILE SCREEN SCALING  (screen only — print untouched)
   ---------------------------------------------------------
   The invoice is a fixed 210mm (≈794 px) sheet. Phones are
   narrower, so we proportionally scale it with `zoom`. Print
   rules are not affected because everything is screen-only.
   ========================================================= */
@media screen and (max-width: 900px) { .invoice { zoom: 0.92; } }

@media screen and (max-width: 768px) { .invoice { zoom: 0.82; } }

@media screen and (max-width: 640px) { .invoice { zoom: 0.70; } }

@media screen and (max-width: 480px) {
  .invoice { zoom: 0.58; }
  body { padding: 8px; }
}

@media screen and (max-width: 430px) { .invoice { zoom: 0.54; } }

@media screen and (max-width: 390px) { .invoice { zoom: 0.50; } }

@media screen and (max-width: 375px) { .invoice { zoom: 0.48; } }

@media screen and (max-width: 360px) { .invoice { zoom: 0.46; } }

@media screen and (max-width: 320px) { .invoice { zoom: 0.40; } }