/* The invoice: on screen, in print (A4) and as the source of the PDF.
   Sizes use em, so the whole invoice scales with the font size set on .invoice. */

.invoice-actions {
  display: grid;
  gap: 0.75rem;
  margin: 0 0 1rem;
}

.invoice-actions .button {
  width: 100%;
  text-decoration: none;
}

.invoice-paper {
  overflow-x: auto; /* with very large text the invoice scrolls inside its box, not the whole page */
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #fff;
}

.invoice {
  --accent: #0b4f9c;
  --accent-light: #e8f0fa;
  --line: #6b7c93;
  container-type: inline-size;
  color: #000;
  background: #fff;
  font-size: 0.8125rem;
  line-height: 1.35;
}

.invoice p {
  margin: 0;
}

/* Bilingual text: English and Arabic side by side; Arabic is always right-to-left. */
.bi {
  display: inline-flex;
  align-items: baseline;
  gap: 0.6em;
}

.bi__ar {
  unicode-bidi: isolate;
}

.bi--stacked {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 1.25;
}

/* Top: the garage */

.invoice__seller {
  display: flex;
  align-items: flex-start;
  gap: 0.75em;
  padding-bottom: 0.6em;
  border-bottom: 2px solid var(--accent);
}

.invoice__logo {
  flex: none;
  max-width: 6em;
  max-height: 6em;
  object-fit: contain;
}

.invoice__seller-text {
  flex: 1;
  min-width: 0;
}

.invoice__name {
  margin: 0;
  color: var(--accent);
  font-size: 1.35em;
  font-weight: 700;
  line-height: 1.25;
}

.invoice__name--ar {
  text-align: start;
}

.invoice__contact {
  display: flex;
  align-items: center;
  gap: 0.3em;
}

.icon {
  flex: none;
  width: 1.15em;
  height: 1.15em;
}

.invoice__address,
.invoice__free-notes,
.invoice__value {
  overflow-wrap: anywhere;
}

/* Title and number */

.invoice__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.6em 0;
  padding: 0.35em 0.75em;
  background: var(--accent);
  color: #fff;
  font-size: 1.3em;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.invoice__title-ar {
  letter-spacing: 0;
}

.invoice__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25em 1em;
  margin-bottom: 0.6em;
}

.invoice__number {
  color: #c00018; /* red, like the paper invoice book */
  font-size: 1.2em;
}

/* Customer and vehicle */

.invoice__parties {
  display: grid;
  gap: 0.5em 1.5em;
  margin-bottom: 0.6em;
}

.invoice__details {
  margin: 0;
}

.invoice__detail {
  display: grid;
  grid-template-columns: 7.5em 1fr;
  gap: 0.5em;
  padding: 0.2em 0;
  border-bottom: 1px dotted var(--line);
}

.invoice__detail dt {
  color: var(--accent);
  font-weight: 600;
}

.invoice__detail dt .bi {
  display: flex;
  flex-direction: column;
  gap: 0;
  line-height: 1.25;
}

.invoice__detail dt .bi__ar {
  align-self: flex-end;
}

.invoice__detail dd {
  margin: 0;
}

.invoice__value {
  display: block;
  font-weight: 600;
}

@container (min-width: 32em) {
  .invoice__parties {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* Items table */

.invoice__table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.invoice__table th,
.invoice__table td {
  padding: 0.3em 0.4em;
  border: 1px solid var(--line);
  vertical-align: top;
}

.invoice__table thead th {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.9em;
  vertical-align: middle;
  overflow-wrap: normal; /* headers wrap between words, never inside a word */
}

.col-no {
  width: 2.2em;
  text-align: center;
}

.col-qty {
  width: 3.4em;
}

.col-rate {
  width: 5em;
}

.col-dirhams {
  width: 5.2em;
}

.col-fils {
  width: 2.8em;
}

.col-desc {
  overflow-wrap: anywhere;
}

.invoice__table td.num {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

.invoice__table td.num--fils {
  text-align: center;
}

.invoice__table tfoot th {
  background: #fff;
  color: #000;
  text-align: start;
  font-weight: 600;
}

.invoice__table tfoot th .bi {
  display: flex;
  justify-content: space-between;
}

.totals-row td {
  font-weight: 600;
}

.totals-row--total th,
.totals-row--total td {
  background: var(--accent-light);
  font-size: 1.1em;
  font-weight: 700;
}

/* Narrow screens (a phone): narrower number columns so the description has room. */
@container (max-width: 31.99em) {
  .col-no {
    width: 1.7em;
  }

  .col-qty {
    width: 2.8em;
  }

  .col-rate {
    width: 4em;
  }

  .col-dirhams {
    width: 4em;
  }

  .col-fils {
    width: 2.3em;
  }

  .invoice__table th,
  .invoice__table td {
    padding: 0.3em 0.25em;
  }
}

/* Payment, notes and thanks */

.invoice__notes {
  display: grid;
  gap: 0.2em;
  margin-top: 0.6em;
}

.invoice__price-note {
  color: #333;
  font-size: 0.9em;
}

.invoice__thanks {
  margin-top: 0.8em;
  padding-top: 0.5em;
  border-top: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  text-align: center;
}

.invoice__thanks .bi {
  justify-content: center;
}

/* Long invoices: smaller type and tighter rows so they still fit one page. */
.invoice--dense .invoice__table th,
.invoice--dense .invoice__table td {
  padding: 0.15em 0.35em;
}

.invoice--dense .invoice__title {
  margin: 0.4em 0;
}

/* Print: A4, small margins, only the invoice. */

@page {
  size: A4;
  margin: 8mm;
}

@media print {
  .app-header,
  .notice,
  .bottom-nav,
  .no-print {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .app-main {
    max-width: none;
    padding: 0;
  }

  .invoice-paper {
    overflow: visible;
    padding: 0;
    border: 0;
    border-radius: 0;
  }

  .invoice {
    font-size: 10pt;
    break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .invoice--dense {
    font-size: 8.5pt;
  }
}

/* The hidden copy of the invoice that is drawn into the PDF: A4 content width (194 mm), print-sized type.
   It is parked off-screen, and moved into view only inside the copy html2canvas draws.
   It must NOT be hidden in print mode: the PDF can be drawn while the print screen is open, and a hidden
   box would be drawn empty. Parked far off the page, it never appears on paper anyway. */

.pdf-capture {
  position: fixed;
  top: 0;
  left: -20000px;
  width: 734px;
  background: #fff;
}

.pdf-capture--drawing {
  left: 0;
}

.pdf-capture .invoice {
  font-size: 10pt;
}

.pdf-capture .invoice--dense {
  font-size: 8.5pt;
}
