/*
 * labels.css — the carton manifest label and the A4 sheet. Millimetres only.
 * The screen preview and the printer both read this file, so what is on
 * screen is the page.
 *
 * Sheet 297 x 210 (A4 landscape): two columns of 148.5, two rows of 105.
 *   2 x 148.5 = 297   2 x 105 = 210   — no margin, no gutter: the labels are
 * the page, and the cut line is the border they already share.
 * Label 148.5 x 105 with a 0.5mm cut border and 5mm of clear space inside it,
 * then a 0.45mm slate frame with 1.2mm corners around the printed matter
 * (136.6 x 93.1):
 *   head 19 + table 65.1 + company strip 9 = 93.1
 *   table = header 7.2 + 4 x 12.35 lines + total 8.5 = 65.1
 *   columns 62.6 + 21 + 24 + ~29 = 136.6
 *
 * Ink is the slate ramp, not flat black: #0f172a data, #334155 captions,
 * #475569 strong rules, #cbd5e1 hairlines, #f1f5f9 bands, #fafaf9 zebra rows.
 * The outer border stays black because it is the cut guide, not artwork.
 */

.sheet {
  width: 297mm;
  height: 210mm;
  box-sizing: border-box;
  padding: 0;
  background: #fff;
  display: grid;
  grid-template-columns: 148.5mm 148.5mm;
  grid-template-rows: 105mm 105mm;
  color: #0f172a;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.slot-empty {
  width: 148.5mm;
  height: 105mm;
}

.label {
  box-sizing: border-box;
  width: 148.5mm;
  height: 105mm;
  /* The cut line: straight, black, on the sheet edge. Nothing else is black. */
  border: 0.5mm solid #000;
  /* 5mm of clear space between the cut line and the frame, so a cut a
     millimetre off centre still misses no text. */
  padding: 5mm;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: Arial, Helvetica, "Liberation Sans", sans-serif;
  color: #0f172a;
  background: #fff;
}

.label *,
.label *::before,
.label *::after {
  box-sizing: border-box;
}

/* The printed outline of the label, 5mm inside the cut line. overflow:hidden
   clips the tinted bands and the zebra rows to its rounded corners. */
.m-box {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 0.45mm solid #1e293b;
  border-radius: 1.2mm;
  overflow: hidden;
  background: #fff;
}

/* ---------------------------------------------------- header: ATT TO + logo */

.m-head {
  flex: none;
  height: 19mm;
  padding: 2mm 4mm;
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Long ATT TO names shrink to fit their own box, so this gap is the only
     thing keeping them off the logo. */
  gap: 4mm;
  border-bottom: 0.4mm solid #334155;
  background: #fff;
}

.m-att {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 84mm;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.8mm;
}

.m-att-cap {
  flex: none;
  font-size: 2.5mm;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.3mm;
  text-transform: uppercase;
  color: #64748b;
}

.m-att-val {
  display: block;
  min-width: 0;
  font-size: 4.6mm;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: 0.09mm;
  color: #0f172a;
}

/* One brand per label: the logo keeps a fixed plate so every label in the
   batch lines up, and hugs the right edge of the band. */
.m-logo {
  flex: none;
  width: 48mm;
  height: 14mm;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: hidden;
}

/* An inline <svg> with a viewBox has an intrinsic ratio, so a fixed height
   gives a natural width and the mark is never stretched. */
.m-logo .logo-svg,
.m-logo .logo-raster {
  display: block;
  flex: none;
  width: auto;
  height: 13.5mm;
  max-width: 46mm;
  object-fit: contain;
}

.m-logo .logo-fallback {
  width: 100%;
  font-size: 5mm;
  font-weight: 700;
  letter-spacing: 0.1mm;
  line-height: 1;
  text-align: right;
  color: #0f172a;
  overflow: hidden;
}

.m-logo.empty {
  justify-content: center;
  border: 0.4mm dashed #94a3b8;
  border-radius: 0.8mm;
}

.m-logo-hint {
  font-size: 3mm;
  font-weight: 700;
  letter-spacing: 0.36mm;
  color: #94a3b8;
}

/* Per-brand ink. normalize.js paints every kept shape with the literal
   attribute fill="#000", and a CSS rule beats a presentation attribute, so
   the colour is applied here without touching the logo pipeline. !important
   keeps older logos that still carry an inline paint style tinting too. */
.m-logo [fill="#000"] {
  fill: var(--logo-ink, #000) !important;
}

.m-logo [stroke="#000"] {
  stroke: var(--logo-ink, #000) !important;
}

/* -------------------------------------------------------------- the table */

.m-table {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  /* STYLE, SHOES and MATERIAL are exact; QUANTITY takes the remainder, so a
     browser rounding the sub-millimetre borders to whole pixels cannot push
     the grid through the frame and leaves no untinted strip at the right. */
  grid-template-columns: 62.6mm 21mm 24mm minmax(0, 1fr);
  grid-template-rows: 7.2mm repeat(4, 1fr) 8.5mm;
}

.m-ch,
.m-c {
  min-width: 0;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.m-ch {
  align-items: center;
  justify-content: center;
  padding: 0 1.5mm;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  color: #334155;
  background: #f1f5f9;
  border-bottom: 0.35mm solid #475569;
}

.m-ch.m-c-style {
  justify-content: flex-start;
  padding: 0 4mm;
}

.m-ch.m-c-qty {
  justify-content: flex-end;
  padding: 0 4mm;
}

.m-ch .fit {
  font-size: 2.8mm;
  line-height: 1;
  letter-spacing: 0.22mm;
  color: #334155;
}

/* Column rules: stronger under the header band, hairline through the rows. */
.m-ch.m-c-shoes,
.m-ch.m-c-material,
.m-ch.m-c-qty {
  border-left: 0.25mm solid #cbd5e1;
}

.m-c {
  align-items: center;
  padding: 0 2mm;
  font-weight: 700;
  color: #0f172a;
  border-bottom: 0.25mm solid #cbd5e1;
}

.m-c.m-c-shoes,
.m-c.m-c-material,
.m-c.m-c-qty {
  border-left: 0.25mm solid #e2e8f0;
}

/* Rows 2 and 4 sit on stone so four lines read as four lines. */
.m-r2,
.m-r4 {
  background: #fafaf9;
}

/* The last line is separated from the total by the total's own rule. */
.m-r4 {
  border-bottom: 0;
}

.m-style {
  justify-content: flex-start;
  padding: 0 4mm;
}

.m-style .fit {
  font-size: 4.4mm;
  line-height: 1.15;
  letter-spacing: 0.13mm;
  color: #0f172a;
}

.m-qty {
  justify-content: flex-end;
  padding: 0 4mm;
}

.m-qty .fit {
  font-size: 4.4mm;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #0f172a;
}

/* Spare lines stay empty but ruled, so a packer can write on the label. The
   .blank hook marks them without changing what a filled row prints. */
.m-tickcell {
  justify-content: center;
  padding: 0;
}

/* 10 units = 4.5mm, so the SVG box keeps its rounded corners at any zoom. */
.tick {
  width: 4.5mm;
  height: 4.5mm;
  display: block;
  flex: none;
}

/* ---- total row ---- */

/* The caption runs under STYLE+SHOES+MATERIAL so it prints at full size
   instead of being squeezed into one column. */
.m-total-cap,
.m-total-val {
  border-top: 0.35mm solid #475569;
  border-bottom: 0;
  background: #f1f5f9;
  justify-content: flex-end;
  color: #334155;
}

.m-total-cap {
  grid-column: 1 / 4;
  padding: 0 3mm;
}

.m-total-val {
  padding: 0 4mm;
}

.m-total-cap .fit {
  font-size: 3mm;
  letter-spacing: 0.24mm;
  line-height: 1;
  text-transform: uppercase;
  color: #334155;
}

.m-total-val .fit {
  font-size: 4.4mm;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #0f172a;
}

/* --------------------------------------------------------- company strip */

.m-org {
  flex: none;
  height: 9mm;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 0.35mm solid #334155;
  font-weight: 700;
  text-align: center;
  padding: 0 4mm;
  overflow: hidden;
  background: #fff;
}

.m-org .fit {
  font-size: 2.8mm;
  font-weight: 700;
  letter-spacing: 0.39mm;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  color: #475569;
}

/* Long values are measured and shrunk by Labels.fitAll; only a string that
   still would not fit at the floor size is allowed to wrap. Fitted text is a
   block that never shrinks as a flex item, so scrollWidth is the real text
   width and the fitter can compare it with the cell's own content box. */
.fit {
  display: block;
  flex: none;
  min-width: 0;
  white-space: nowrap;
}

.fit.wrap {
  flex: 0 1 auto;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.08;
}
