/* NEX-T POS - price labels (js/backoffice/labels.js): the label itself - the same element on screen (the preview, at
   true size) and on paper - and its print. A direct-thermal label printer (Xprinter XP-365B class, 203 dpi = 8 dots a
   mm) prints one label a page: each size has its own named page with no margins, and a page break follows every label.
   Everything is black on white; nothing is drawn outside the label.
   Sizes (the label's width × height): 30 × 20 mm (the owner's rolls: about 240 × 160 dots), 40 × 30, 50 × 30.
   A label is the product's name and its price - no barcode, no SKU, no box - aligned to the top LEFT (the owner's
   choice), inside the label's padding: the name bold from the top-left corner, up to 3 lines ("…" beyond; 4 without
   the price), the price large right under it, starting at the same left edge (smaller when long, never cut off). Not
   centred, across or down: a one-line name sits at the top, and any room left over is at the bottom. Each size has its
   own fixed sizes, so the rows never pass the label: padding + 3 name lines + the gap + the price's line fit its height
   with room to spare (test/labels.test.js adds them up and checks the alignment).
   A label is 0.1 mm shorter than its page, so rounding never pushes it onto a second page. */

/* ------------------------------------------------------------------ the label (screen and print) */
/* (top-left: the rows stack from the top - justify-content: flex-start, the room left over stays at the bottom - and
   every line starts at the left padding) */
.lbl { box-sizing: border-box; position: relative; display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch;
  flex: none; overflow: hidden; color: #000; background: #fff; font-family: Arial, "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  font-weight: 400; text-align: left; letter-spacing: 0; }
.lbl * { box-sizing: border-box; }
/* the name: bold, as many lines as the size allows (-webkit-line-clamp, "…" at the end of the last one), long words
   broken rather than cut off; max-height = lines × line-height keeps it to those lines even where the clamp is ignored */
.lbl-name { flex: none; overflow: hidden; font-weight: 700; }
.lbl-name-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; max-width: 100%; overflow: hidden; overflow-wrap: anywhere; }
/* the price: Arial Bold - 700, never more (800 / 900 is Arial Black on Windows, far wider). As big as its row allows,
   but never wider than the label: labels.js sets --chars (the price's length) and each size caps the font at its
   content width / (chars × 0.6 em) - Arial Bold's "RM 1,234.50" is under 0.55 em a character -, so a long price is
   set smaller instead of cut off: RM 100,000.00 (the highest price) fits every size; "RM 320.00" keeps the full size */
.lbl-price { flex: none; overflow: hidden; white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; }
.lbl-meta { flex: none; overflow: hidden; white-space: nowrap; }

/* 30 × 20 mm (content 28 × 17.9): 1 + name 3 × 3.45 + 0.9 + price 5.9 + 1 = 19.15 of 19.9 */
.lbl-30x20 { width: 30mm; height: 19.9mm; padding: 1mm 1mm; }
.lbl-30x20 .lbl-name { font-size: 3mm; line-height: 3.45mm; max-height: 10.35mm; }
.lbl-30x20 .lbl-price { height: 5.9mm; margin-top: 0.9mm; font-size: min(5.1mm, calc(28mm / (var(--chars, 9) * 0.6))); line-height: 5.9mm; }
.lbl-30x20 .lbl-meta { height: 2.4mm; font-size: 2mm; line-height: 2.4mm; }

/* 40 × 30 mm (content 37 × 26.9): 1.5 + name 3 × 4.85 + 1.2 + price 7.9 + 1.5 = 26.65 of 29.9 */
.lbl-40x30 { width: 40mm; height: 29.9mm; padding: 1.5mm 1.5mm; }
.lbl-40x30 .lbl-name { font-size: 4.2mm; line-height: 4.85mm; max-height: 14.55mm; }
.lbl-40x30 .lbl-price { height: 7.9mm; margin-top: 1.2mm; font-size: min(6.8mm, calc(37mm / (var(--chars, 9) * 0.6))); line-height: 7.9mm; }
.lbl-40x30 .lbl-meta { height: 3mm; font-size: 2.5mm; line-height: 3mm; }

/* 50 × 30 mm (content 46 × 26.9): 1.5 + name 3 × 5.1 + 1.2 + price 9.2 + 1.5 = 28.7 of 29.9 */
.lbl-50x30 { width: 50mm; height: 29.9mm; padding: 1.5mm 2mm; }
.lbl-50x30 .lbl-name { font-size: 4.4mm; line-height: 5.1mm; max-height: 15.3mm; }
.lbl-50x30 .lbl-price { height: 9.2mm; margin-top: 1.2mm; font-size: min(8mm, calc(46mm / (var(--chars, 9) * 0.6))); line-height: 9.2mm; }
.lbl-50x30 .lbl-meta { height: 3mm; font-size: 2.6mm; line-height: 3mm; }

/* "Show the price" off: the name alone, larger, up to 4 lines */
.lbl-noprice .lbl-name-text { -webkit-line-clamp: 4; }
.lbl-30x20.lbl-noprice .lbl-name { font-size: 3.4mm; line-height: 3.95mm; max-height: 15.8mm; }
.lbl-40x30.lbl-noprice .lbl-name { font-size: 4.6mm; line-height: 5.3mm; max-height: 21.2mm; }
.lbl-50x30.lbl-noprice .lbl-name { font-size: 5mm; line-height: 5.75mm; max-height: 23mm; }

/* the test label: a frame 0.5 mm inside the edges (cut off or uneven = the paper size or the gap calibration is off),
   one line of name, the size, a price at the full size - top-left like every label; on 30 × 20 a little more padding,
   so the text keeps clear of the frame (0.5 + 0.25 mm) */
.lbl-30x20.lbl-test { padding: 1.3mm 1.3mm; }
.lbl-test .lbl-name-text { -webkit-line-clamp: 1; }
.lbl-test .lbl-price { margin-top: 0.4mm; }
.lbl-frame { position: absolute; inset: 0.5mm; border: 0.25mm solid #000; pointer-events: none; }

/* ------------------------------------------------------------------ on screen: the preview (paper look, true size) */
@media screen {
  .lbl-preview .lbl { border-radius: 1.5mm; box-shadow: 0 0 0 1px #c6cbd3, 0 2px 8px rgba(0, 0, 0, .14); }
}
.lbl-preview { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px 16px; padding: 14px; border-radius: var(--radius-sm, 8px);
  background: var(--surface-3, #e6e9ee); overflow: auto; }
.lbl-preview.is-zoomed .lbl { zoom: 2; }
/* (a card is as wide as its label: the line under it wraps) */
.lbl-card { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; width: min-content; margin: 0; }
.lbl-card figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; width: 100%; font-size: 12.5px; line-height: 1.3; color: var(--text); }
.lbl-card .badge { white-space: normal; text-align: left; }
.lbl-card-count { font-weight: 800; font-variant-numeric: tabular-nums; }
.lbl-card.is-zero .lbl { opacity: .45; }
.lbl-card-why { color: var(--muted); }

/* ------------------------------------------------------------------ the Price labels screen */
/* the settings and the preview side by side above the list (the list gets the page's whole width); a phone: one under
   the other */
.lbl-layout { display: flex; flex-direction: column; gap: 14px; }
.lbl-layout > * { min-width: 0; }
.lbl-side { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 14px; align-items: start; }
.lbl-side > .card + .card { margin-top: 0; }
.lbl-side .lbl-preview { max-height: 300px; min-height: 120px; }
.lbl-side .hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.lbl-modes { margin: 0 0 12px; }
.lbl-selbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 0 0 10px; }
.lbl-selbar .check { font-weight: 600; }
.lbl-pick { display: inline-flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.lbl-pick input[type="checkbox"] { flex: none; width: 20px; height: 20px; margin: 0; }
.lbl-qty { width: 72px; text-align: right; font-variant-numeric: tabular-nums; }
.lbl-count-note { display: block; font-size: 12px; color: var(--muted); }
.lbl-zero { color: var(--muted); }
.lbl-settings .field + .field, .lbl-settings .field + .bo-switch-field, .lbl-settings .bo-switch-field + .bo-switch-field { margin-top: 12px; }
.lbl-preview-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 10px; }
.lbl-preview-more { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

@media (max-width: 800px) {
  .lbl-side { grid-template-columns: minmax(0, 1fr); }
  .lbl-side .lbl-preview { max-height: 420px; }
}

/* ------------------------------------------------------------------ print: one label a page */
@page label-30x20 { size: 30mm 20mm; margin: 0; }
@page label-40x30 { size: 40mm 30mm; margin: 0; }
@page label-50x30 { size: 50mm 30mm; margin: 0; }
/* (#print-root is laid out off screen at the label's width before printing too, like a receipt) */
#print-root.lbl-print-30x20 { width: 30mm; }
#print-root.lbl-print-40x30 { width: 40mm; }
#print-root.lbl-print-50x30 { width: 50mm; }
#print-root .lbl-sheet { display: block; margin: 0; padding: 0; }
@media print {
  html.pos-printing #print-root.lbl-print { margin: 0; padding: 0; }
  html.pos-printing #print-root.lbl-print-30x20 { page: label-30x20; }
  html.pos-printing #print-root.lbl-print-40x30 { page: label-40x30; }
  html.pos-printing #print-root.lbl-print-50x30 { page: label-50x30; }
  html.pos-printing #print-root .lbl { margin: 0; border: 0; border-radius: 0; break-inside: avoid; page-break-inside: avoid; }
  html.pos-printing #print-root .lbl:not(:last-child) { break-after: page; page-break-after: always; }
  html.pos-printing #print-root .lbl-frame { border-color: #000 !important; }
}
