/* The printed work order (app/views/pages/work-order/print/), from the
   designer's prototype (.ui-spec/docs/prototype/work-order-print.html). A
   framer reads it standing at a bench, so what is looked for first is biggest:
   who it is for, the store and priority the CPF sorts by, and the barcode.

   Shown on screen as the sheet of paper it prints on, a US Letter page with
   half-inch margins, so the preview is what comes off the printer. The page
   size is named for these sheets alone (@page cp-wo-letter); other printouts
   keep theirs. */

.cp-wo-sheet-pages {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.cp-wo-sheet {
  display: flex;
  flex: none;
  flex-direction: column;
  box-sizing: border-box;
  width: 8.5in;
  min-height: 11in;
  margin: 0 auto;
  padding: 0.5in;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  box-shadow: 0 1px 2px rgb(0 0 0 / 8%), 0 4px 12px rgb(0 0 0 / 10%);
  font-size: 0.8125rem;
  line-height: 1.45;

  & dl,
  & dd {
    margin: 0;
  }

  & dt {
    color: var(--bs-secondary-color);
    font-size: 0.6875rem;
    font-weight: 400;
  }
}

/* stylelint-disable-next-line plugin/no-unsupported-browser-features -- Safari before 18.2
   ignores the page size and prints on the printer's own paper and margins, which in the shop
   is Letter anyway. */
@page cp-wo-letter {
  size: letter;
  margin: 0.5in;
}

.cp-wo-sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
}

.cp-wo-sheet-who {
  flex: 1 1 auto;
  min-width: 0;
}

.cp-wo-sheet-customer {
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.2;
}

/* Store and Priority, what the CPF sorts the paperwork by, as large as the
   customer's name. */
.cp-wo-sheet-sort {
  display: flex;
  flex: none;
  gap: 1.5rem;

  & dd {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.15;
  }
}

.cp-wo-sheet-store {
  min-width: 2.75rem;
  height: 1.85rem;
  padding: 0 0.55rem;
  border-radius: 6px;
  font-size: 1.125rem;
  vertical-align: middle;
}

.cp-wo-sheet-store-name {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.6875rem;
  font-weight: 400;
}

.cp-wo-sheet-id {
  text-align: right;
}

/* The bars fill this box (see code39Barcode()). Wide enough that each bar of
   a short number stays well above what a handheld scanner resolves. */
.cp-wo-sheet-barcode {
  display: block;
  width: 1.75in;
  height: 42px;
  margin-left: auto;
}

.cp-wo-sheet-number {
  margin-top: 0.25rem;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Due, Qty and Order Taken: one row, all the same size, edge to edge. */
.cp-wo-sheet-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-top: 1.25rem !important;
  padding: 0.75rem 0;
  border-top: 1px dotted var(--bs-secondary-color);
  border-bottom: 1px dotted var(--bs-secondary-color);

  & dd {
    font-weight: 600;
  }
}

/* Board work left, frame work right, as on the work order screen. minmax(0,
   1fr) rather than 1fr, whose minimum is its content's, so a long unbroken
   word or table can't push a column past half the page. */
.cp-wo-sheet-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0 2.25rem;
}

.cp-wo-sheet-section {
  margin-top: 1.25rem;
  /* stylelint-disable-next-line plugin/no-unsupported-browser-features -- caniuse files
     break-inside under "multicolumn"; the partial support it flags is about multi-column
     layout, and this only matters when printing. */
  break-inside: avoid;
}

.cp-wo-sheet-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 0.35rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid currentcolor;
  font-size: 0.8125rem;
  font-weight: 700;
}

.cp-wo-sheet-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.15rem 0;
}

.cp-wo-sheet-key {
  flex: 0 0 6.5rem;
  color: var(--bs-secondary-color);
}

.cp-wo-sheet-value {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.cp-wo-sheet-table {
  width: 100%;
  margin-top: 0.25rem;
  border-collapse: collapse;

  & th {
    padding-bottom: 0.35rem;
    border-bottom: 1px dotted var(--bs-secondary-color);
    font-weight: 400;
    text-align: left;
    white-space: nowrap;
  }

  & td {
    padding: 0.35rem 0 0.4rem;
    border-bottom: 1px dotted var(--bs-secondary-color);
    overflow-wrap: anywhere;
    vertical-align: top;
  }

  & tfoot td {
    padding-top: 0.45rem;
    border-top: 1px solid currentcolor;
    border-bottom: 0;
    font-weight: 600;
  }
}

/* Figures right-aligned and sized to their content, which leaves the rest of
   the row to the description column. width: 1% with nowrap is what sizes a
   column to its content. Not width: 100% on the description column instead:
   Firefox widens a table past its container to fit a 100% column beside
   others, which pushed the right-hand columns into the page margin. */
.cp-wo-sheet-num {
  width: 1%;
  padding-left: 0.75rem !important;
  text-align: right !important;
  white-space: nowrap;
}

.cp-wo-sheet-code {
  font-weight: 600;
  white-space: nowrap;
}

.cp-wo-sheet-sketch {
  display: block;
  margin: 0.6rem 0 0;
}

.cp-wo-sheet-sketch-frame {
  fill: var(--bs-body-color);
}

.cp-wo-sheet-sketch-mat {
  fill: var(--bs-body-bg);
  stroke: var(--bs-body-color);
  stroke-width: 0.75;
}

.cp-wo-sheet-sketch-art {
  fill: none;
  stroke: var(--bs-body-color);
  stroke-dasharray: 3 2;
  stroke-width: 0.75;
}

.cp-wo-sheet-tick {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.6875rem;
  font-weight: 400;
}

.cp-wo-sheet-box {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 1.5px solid currentcolor;
  border-radius: 2px;
}

.cp-wo-sheet-notes {
  margin: 0;
  padding: 0;
  list-style: none;

  & li {
    padding: 0.25rem 0;
    border-bottom: 1px dotted var(--bs-secondary-color);
    overflow-wrap: anywhere;
  }

  & li:last-child {
    border-bottom: 0;
  }

  & .cp-wo-sheet-key {
    display: block;
    font-size: 0.6875rem;
  }
}

/* margin-top: auto pins the CPF's sign-off to the foot of the page, however
   much the order fills above it. */
.cp-wo-sheet-cpf {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  margin-top: auto;
  padding: 0.7rem 0.9rem 0.85rem;
  border: 1.5px solid currentcolor;
  border-radius: 4px;

  & .cp-wo-sheet-tick {
    font-size: 0.8125rem;
  }
}

/* A step up from the section headings: the CPF reads this part first. */
.cp-wo-sheet-cpf-heading {
  flex: 0 0 100%;
  margin: 0;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid currentcolor;
  font-size: 1rem;
  font-weight: 700;
}

.cp-wo-sheet-cpf-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
}

.cp-wo-sheet-sign {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.8125rem;
}

.cp-wo-sheet-line {
  display: inline-block;
  width: 5.5rem;
  border-bottom: 1px solid currentcolor;
}

/* Printed, each sheet starts a page, and the half-inch margin is the page's
   own (@page cp-wo-letter) rather than the sheet's padding. Padding is cut
   where a page break falls through a sheet, so a sheet running onto a second
   page would print that page from the paper's edge. The page box repeats its
   margin on every page.

   The name sits on body rather than on the sheets, so the first page carries
   it too. A page takes its name from the first box on it, and anything printed
   ahead of the first sheet would otherwise leave that page on the browser's
   default margins.

   min-height is the page's height less its margins, a hair under, since a
   sheet rounding up past the page would push out a blank page after it. */
@media print {
  body:has(.cp-wo-sheet) {
    page: cp-wo-letter;
  }

  .cp-print-page:has(.cp-wo-sheet) {
    padding: 0 !important;
  }

  .cp-wo-sheet-missing {
    display: none;
  }

  .cp-wo-sheet-pages {
    display: block;
  }

  .cp-wo-sheet {
    width: auto;
    min-height: 9.98in;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }

  .cp-wo-sheet + .cp-wo-sheet {
    /* stylelint-disable-next-line plugin/no-unsupported-browser-features -- the same false
       "multicolumn" flag as break-inside above; this is paged media. */
    break-before: page;
  }
}
