/* ==========================================================================
   THE INVOICE
   A faithful HTML/CSS recreation of the Ironvale Heavy Equipment template in
   PLANTILLA/image_plantilla.png, laid out on US Letter (8.5 x 11 in).

   All colours below were sampled directly from the template image.
   Sizes are in CSS pixels; 96px = 1in, so the sheet is 816 x 1056px.
   ========================================================================== */

.sheet {
  /* ---- brand palette (sampled from the template) ---- */
  --i-navy:       #1c4568;   /* section bars, table head            */
  --i-navy-deep:  #14304f;   /* TOTAL bar, footer band              */
  --i-navy-ink:   #0b2545;   /* "INVOICE" wordmark, strong text     */
  --i-gold:       #fac314;   /* TOTAL column head, rules, accents   */
  --i-yellow:     #fedd48;   /* grand total value cell              */
  --i-yellow-pale:#fbf6df;   /* tinted TOTAL column / office box    */
  --i-red:        #d42026;   /* invoice number                      */
  --i-paper:      #ffffff;
  --i-panel:      #edf1f5;   /* light grey panels                   */
  --i-panel-2:    #e3e9ef;
  --i-row:        #f7f9fb;   /* alternating table row               */
  --i-line:       #ccd6e0;
  --i-line-soft:  #dbe2ea;
  --i-text:       #16233a;
  --i-muted:      #4a5768;

  /* ---- shared table geometry (label + value columns must line up
          exactly with UNIT PRICE and TOTAL further down the page) ---- */
  --c-qty:   10.8%;
  --c-desc:  57.8%;
  --c-price: 15.8%;
  --c-total: 15.6%;

  --pad-x: 30px;   /* left / right body margin */

  /* One .sheet element is one physical US Letter page. The height is fixed,
     not a minimum: js/app.js fills each page by measurement, so the browser
     never has to decide where to cut. */
  width: 816px;
  height: 1056px;
  background: var(--i-paper);
  color: var(--i-text);
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 12px;
  line-height: 1.25;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 18px rgba(16, 30, 54, .18);
  overflow: hidden;

  /* Make sure the navy / gold fills actually appear in the PDF. */
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ==========================================================================
   HEADER
   ========================================================================== */

.inv-head {
  position: relative;
  height: 166px;
  flex: 0 0 auto;
  background: linear-gradient(160deg, #fbfcfe 0%, #f2f5f9 55%, #eaeff4 100%);
  border-bottom: 1px solid #e2e8ee;
  overflow: hidden;
}

/* The slanted light-grey panel behind the INVOICE wordmark. */
.inv-head__wedge {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #e7edf3 0%, #dde5ed 100%);
  clip-path: polygon(73.4% 0, 100% 0, 100% 100%, 62.7% 100%);
}

.inv-head__logo {
  position: absolute;
  left: var(--pad-x);
  top: 26px;
  width: 250px;
}
.inv-head__logo img {
  display: block;
  width: 100%;
  height: auto;
}

/* ---- contact block ---- */
.inv-head__contact {
  position: absolute;
  left: 305px;
  top: 32px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.ct {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.ct__icon {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  margin-top: 1px;
  fill: var(--i-navy-ink);
}
.ct__icon .ct__hole   { fill: #f4f7fa; }
.ct__icon .ct__stroke { fill: none; stroke: #f4f7fa; stroke-width: 1.7; }

.ct__text {
  font-size: 12.5px;
  line-height: 1.32;
  color: #22303f;
}

/* ---- INVOICE wordmark ---- */
.inv-head__title {
  position: absolute;
  right: var(--pad-x);
  top: 24px;
  width: 232px;
  text-align: center;
}

.inv-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--i-red);
  letter-spacing: .5px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  margin-bottom: 2px;
}

.inv-word {
  font-size: 50px;
  font-weight: 800;
  line-height: 1;
  color: var(--i-navy-ink);
  letter-spacing: .5px;
}

.inv-rule {
  height: 4px;
  background: var(--i-gold);
  margin: 7px 4px 6px;
  border-radius: 1px;
}

.inv-subword {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 2.4px;
  color: #3d4a5c;
}

/* ==========================================================================
   CONTINUATION MASTHEAD  (page 2 onwards)
   Built only from the existing palette and type of the full header above, so a
   continuation page is unmistakably the same invoice - it is simply short, to
   leave the rest of the page for line items.
   ========================================================================== */

.inv-conthead {
  position: relative;
  flex: 0 0 auto;
  height: 66px;
  display: flex;
  align-items: center;
  padding: 0 var(--pad-x);
  background: linear-gradient(160deg, #fbfcfe 0%, #f2f5f9 55%, #eaeff4 100%);
  border-bottom: 3px solid var(--i-gold);
  overflow: hidden;
}

.inv-conthead__logo { width: 118px; flex: 0 0 auto; }
.inv-conthead__logo img { display: block; width: 100%; height: auto; }

.inv-conthead__title {
  margin-left: auto;
  text-align: right;
}

.inv-conthead__line {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .4px;
  color: var(--i-navy-ink);
}

.inv-conthead__num { color: var(--i-red); }

.inv-conthead__page {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.6px;
  color: var(--i-muted);
  margin-top: 4px;
}

/* ==========================================================================
   BODY
   ========================================================================== */

.inv-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  padding: 8px var(--pad-x) 0;
  min-height: 0;
}

/* Blocks keep their natural height so an over-full page really does overflow
   (that is what the paginator measures). Only the spacer may absorb slack. */
.inv-body > * { flex: 0 0 auto; }
.inv-grow     { flex: 1 1 0; min-height: 0; }

/* Page x of y - only rendered when the invoice needs more than one page. */
.inv-pageno {
  flex: 0 0 auto;
  text-align: right;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.6px;
  color: var(--i-muted);
  padding: 0 2px 4px;
}

/* ---- CUSTOMER / MISC cards ---------------------------------------------- */

.inv-cards {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
}

.pcard {
  border: 1px solid var(--i-line-soft);
  border-radius: 5px;
  overflow: hidden;
  background: #fdfefe;
}

.pcard__bar {
  background: var(--i-navy);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 7px 12px;
}

.pcard__body { padding: 9px 12px 10px; }

/* customer rows */
.crow {
  display: grid;
  grid-template-columns: 62px 1fr;
  align-items: end;
  column-gap: 8px;
  min-height: 21px;
}

.crow--split {
  grid-template-columns: 62px 1fr 96px 78px;
}

.crow__label {
  font-size: 12px;
  color: var(--i-muted);
  padding-bottom: 3px;
}

.crow__value {
  font-size: 13px;
  font-weight: 700;
  color: var(--i-navy-ink);
  border-bottom: 1px solid var(--i-line);
  padding: 0 2px 3px;
  min-height: 18px;
  overflow-wrap: anywhere;
}

.crow__value--mid,
.crow__value--end { text-align: left; }

/* misc rows */
.mrow {
  display: grid;
  grid-template-columns: 92px 1fr;
  align-items: end;
  column-gap: 8px;
  min-height: 25px;
}

.mrow__label {
  font-size: 12.5px;
  color: var(--i-muted);
  padding-bottom: 3px;
}

.mrow__box {
  border: 1px solid var(--i-navy);
  border-radius: 3px;
  height: 21px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--i-navy-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.mrow__line {
  border-bottom: 1px solid var(--i-line);
  min-height: 18px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--i-navy-ink);
  padding: 0 3px 3px;
  overflow-wrap: anywhere;
}

/* ---- ITEMS TABLE -------------------------------------------------------- */

.itbl {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: 16px;
}

.itbl th {
  background: var(--i-navy);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .8px;
  padding: 7px 8px;
  text-align: center;
  border-right: 1px solid rgba(255, 255, 255, .18);
}
.itbl th:last-child { border-right: 0; }

.itbl__qty   { width: var(--c-qty); }
.itbl__desc  { width: var(--c-desc); }
.itbl__price { width: var(--c-price); }
.itbl__total {
  width: var(--c-total);
  background: var(--i-gold) !important;
  color: var(--i-navy-ink) !important;
}

.itbl td {
  height: 23px;
  padding: 3px 8px;
  font-size: 12px;
  border-bottom: 1px solid #e8edf2;
  border-right: 1px solid #e8edf2;
  vertical-align: middle;
}
.itbl td:last-child { border-right: 0; }

.itbl tbody tr:nth-child(odd)  td { background: var(--i-row); }
.itbl tbody tr:nth-child(even) td { background: #fff; }

.itbl .td-qty   { text-align: center; font-weight: 700; color: var(--i-navy-ink); }
/* pre-wrap keeps the line breaks the employee typed inside a description. */
.itbl .td-desc  { text-align: left; overflow-wrap: anywhere; white-space: pre-wrap; }
.itbl .td-price { text-align: right; font-variant-numeric: tabular-nums; }
.itbl .td-total {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--i-navy-ink);
  background: var(--i-yellow-pale) !important;
  border-left: 1px solid #f0e6c4;
}

.itbl tbody tr.is-filler td { color: transparent; }

/* ---- TERMS + TOTALS ----------------------------------------------------- */

.inv-totals {
  display: grid;
  grid-template-columns: calc(var(--c-qty) + var(--c-desc)) calc(var(--c-price) + var(--c-total));
  align-items: stretch;
}

.inv-terms {
  background: var(--i-panel);
  border-right: 1px solid #dde4eb;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.65;
  color: #2a3646;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.inv-sums { display: flex; flex-direction: column; }

.srow {
  display: grid;
  /* 15.8% : 15.6% of the page = 50.3% : 49.7% inside this block */
  grid-template-columns: 50.3% 1fr;
  align-items: center;
  flex: 1 1 auto;
  min-height: 27px;
}

.srow__label {
  text-align: right;
  padding-right: 10px;
  font-size: 12.5px;
  color: #2a3646;
  background: var(--i-panel);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-bottom: 1px solid #dde4eb;
}

.srow__value {
  text-align: right;
  padding-right: 9px;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: #f6f8fa;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-bottom: 1px solid #dde4eb;
  border-left: 1px solid #e4eaf0;
}

/* The word EXPORT stands in for a tax amount; the recorded payment is shown
   as a deduction. Both use the existing type and palette. */
.srow--tax .srow__value {
  font-weight: 700;
  letter-spacing: .6px;
  color: var(--i-navy-ink);
}

.srow--grand { min-height: 36px; }

.srow--grand .srow__label {
  background: var(--i-navy-deep);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .6px;
  border-bottom: 0;
  justify-content: center;
  padding-right: 0;
}

.srow--grand .srow__value {
  background: var(--i-yellow);
  color: var(--i-navy-ink);
  font-size: 15px;
  font-weight: 700;
  border-bottom: 0;
  border-left: 0;
}

/* ---- INSTRUCTIONS + OFFICE USE ------------------------------------------ */

.inv-bottom {
  display: grid;
  grid-template-columns: 1fr 348px;
  gap: 16px;
  margin-top: 18px;
}

.pcard--instructions .pcard__bar { font-size: 12.5px; }

.pcard__body--lines {
  padding: 7px 12px 8px;
  min-height: 82px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0;
}

.pcard__body--lines .iline {
  border-bottom: 1px solid var(--i-line-soft);
  min-height: 19px;
  font-size: 12px;
  color: var(--i-text);
  padding: 0 2px 2px;
  overflow-wrap: anywhere;
}

.inv-bottom__right { display: flex; flex-direction: column; }

.freight {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
  padding-top: 3px;
}

.freight__label {
  font-size: 12.5px;
  color: #2a3646;
  white-space: nowrap;
}

.freight__box {
  flex: 1 1 auto;
  border: 1px solid var(--i-navy);
  border-radius: 3px;
  height: 22px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--i-navy-ink);
  display: flex;
  align-items: center;
  padding: 0 8px;
  background: #fff;
  overflow-wrap: anywhere;
}

.office {
  flex: 1 1 auto;
  background: var(--i-yellow-pale);
  border: 1px solid #f0e7c2;
  border-radius: 4px;
  padding: 9px 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #3a4351;
  white-space: pre-wrap;
  overflow: hidden;
  min-height: 78px;
}

.office.is-placeholder {
  color: #6a7382;
  white-space: pre;
}

/* ---- PAYABLE / THANK YOU ------------------------------------------------ */

.payable {
  background: var(--i-panel-2);
  border-radius: 5px;
  text-align: center;
  font-style: italic;
  font-size: 13px;
  line-height: 1.65;
  color: #23303f;
  padding: 10px 16px;
  margin-top: 6px;
}

.thanks {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 4px 11px;
}

.thanks__rule {
  flex: 1 1 auto;
  height: 2px;
  background: var(--i-navy);
}

.thanks__text {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--i-navy-ink);
  white-space: nowrap;
}

/* ==========================================================================
   FOOTER BAND
   ========================================================================== */

.inv-foot {
  position: relative;
  flex: 0 0 auto;
  height: 48px;
  background: var(--i-navy-deep);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 var(--pad-x);
  overflow: hidden;
}

/* The yellow slanted accent in the bottom-left corner. */
.inv-foot__accent {
  position: absolute;
  left: 0;
  top: 0;
  width: 26%;
  height: 38%;
  background: var(--i-gold);
  clip-path: polygon(0 0, 100% 0, 94% 100%, 0 100%);
}

.inv-foot__tag {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 1.1px;
  color: #ffffff;
}

.inv-foot__tag strong { color: var(--i-gold); }

/* ==========================================================================
   PRINT
   ========================================================================== */

@media print {
  .sheet {
    box-shadow: none !important;
    margin: 0 !important;
    width: 8.5in;
    height: 11in;
  }

  /* Exactly one page break between sheets - and crucially none after the last
     one, which is what would otherwise produce a trailing blank page. */
  .sheet { break-after: page; page-break-after: always; }
  .sheet:last-child { break-after: auto; page-break-after: auto; }

  /* Belt and braces: the paginator already guarantees that nothing straddles a
     boundary, so these only matter if a browser ignores the breaks above. */
  .itbl tr,
  .inv-cards,
  .inv-totals,
  .inv-bottom,
  .payable,
  .thanks { break-inside: avoid; page-break-inside: avoid; }
}
