/* Layout: control column on the left (products + print settings), labels at true printed size on the right. */
:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #18212b;
  --muted: #5d6b7a;
  --line: #d3dae2;
  --accent: #1f4fd1;
  --accent-ink: #ffffff;
  --warn: #b3261e;
  --warn-bg: #fdecea;
  --note: #6b4e00;
  --note-bg: #fff4d6;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-brand: "Times New Roman", Times, serif;
  --font-tag: "Barlow Semi Condensed", Bahnschrift, "IBM Plex Sans", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12171d;
    --panel: #1b222b;
    --ink: #e7ecf2;
    --muted: #9aa7b5;
    --line: #2e3945;
    --accent: #86a6ff;
    --accent-ink: #0d1320;
    --warn: #ff9b91;
    --warn-bg: #3a1f1d;
    --note: #ffd98a;
    --note-bg: #3a3018;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
}
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
header { display: flex; flex-direction: column; gap: 4px; }
h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
header p { margin: 0; color: var(--muted); max-width: 70ch; }

.work {
  display: grid;
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) { .work { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}
.group { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 14px 0 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.group legend { padding: 0 8px 0 0; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
textarea, select, input[type="number"], input[type="text"] {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
textarea {
  font-family: var(--font-mono);
  font-size: 13px;
  min-height: 220px;
  resize: vertical;
  white-space: pre;
  overflow: auto;
}
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings .wide { grid-column: 1 / -1; }
.check { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
[hidden], .is-hidden { display: none !important; }

button {
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.out { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.summary { font-size: 14px; color: var(--muted); }
.summary strong { color: var(--ink); font-weight: 600; }
.summary .bad { color: var(--warn); font-weight: 600; }
.bar-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.card.problem { border-color: var(--warn); }
.stage {
  background: var(--bg);
  border-radius: 6px;
  padding: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  min-height: 96px;
}
.stage .lbl { box-shadow: 0 0 0 1px var(--line), 0 1px 3px rgba(0, 0, 0, 0.12); flex: none; }
.meta { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta code { font-family: var(--font-mono); font-size: 13px; color: var(--ink); overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 1px 8px; color: var(--note); background: var(--note-bg); }
.chip.bad { color: var(--warn); background: var(--warn-bg); }
.err { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 10px; font-size: 13px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.card-actions button { padding: 5px 10px; font-size: 12.5px; }
.empty { border: 1px dashed var(--line); border-radius: 10px; padding: 28px 16px; color: var(--muted); text-align: center; }
.toast {
  position: sticky;
  bottom: 16px;
  align-self: center;
  background: var(--ink);
  color: var(--bg);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13.5px;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.toast.on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ---------- the label itself: sized in mm, same rules on screen and on paper ---------- */
.lbl {
  --k: 1;
  background: #fff;
  color: #000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5mm;
  padding: 1mm;
  font-family: var(--font-body);
  line-height: 1.15;
  text-align: center;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.lbl svg { display: block; flex: none; }
.lbl-line { font-size: 6.5pt; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; }
.lbl-price { font-size: 8pt; font-weight: 600; font-variant-numeric: tabular-nums; max-width: 100%; white-space: nowrap; overflow: hidden; flex: none; }
.lbl-blank { visibility: hidden; }

/* Side padding is 1mm so a barcode has the width to itself; the text lines keep a further 2mm clear of the edge. */
.lbl.tag { font-family: var(--font-tag); justify-content: flex-start; gap: 0; padding: calc(8.2mm * var(--k)) 1mm calc(2.6mm * var(--k)); }
.tag-name, .tag-fabric, .tag-colour, .tag-foot { box-sizing: border-box; padding-left: 2mm; padding-right: 2mm; }
.tag-brand {
  font-family: var(--font-brand);
  font-size: calc(21pt * var(--k));
  font-weight: 400;
  letter-spacing: 0.24em;
  padding-left: 0.24em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
  flex: none;
}
.tag-name { font-size: calc(12pt * var(--k)); font-weight: 600; line-height: 1.15; text-transform: uppercase; margin-top: calc(6mm * var(--k)); max-width: 100%; overflow-wrap: anywhere; text-wrap: balance; flex: none; }
.tag-fabric, .tag-colour { font-size: calc(6.3pt * var(--k)); font-weight: 500; line-height: 1.15; text-transform: uppercase; max-width: 100%; overflow-wrap: anywhere; flex: none; }
.tag-fabric { margin-top: calc(1.6mm * var(--k)); }
.tag-colour { margin-top: calc(2.1mm * var(--k)); }
.tag-size { font-size: calc(17.5pt * var(--k)); font-weight: 700; line-height: 1; margin-top: calc(2mm * var(--k)); flex: none; }
.tag-price { font-size: calc(11.7pt * var(--k)); line-height: 1; margin-top: calc(3mm * var(--k)); font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }
.tag-spacer { flex: 1 1 0; min-height: 1mm; }
.tag-codes { display: flex; flex-direction: column; align-items: center; gap: 1mm; flex: none; }
.tag-foot { font-size: calc(5.1pt * var(--k)); letter-spacing: 0.1em; text-transform: uppercase; line-height: 1.15; margin-top: calc(1.2mm * var(--k)); flex: none; }

/* Product ticket: follows the Maud 40 x 57 mm ticket artwork, with the barcode at the foot. */
.lbl.ticket {
  justify-content: flex-start;
  gap: 0;
  padding: calc(2.6mm * var(--k)) 1mm calc(1.4mm * var(--k));
  font-family: "Helvetica Now Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-transform: uppercase;
}
.tk-name { font-size: calc(3.4mm * var(--k)); font-weight: 700; line-height: 1.17; max-width: 100%; padding: 0 1mm; overflow-wrap: anywhere; text-wrap: balance; flex: none; }
.tk-name + .tk-detail { margin-top: calc(0.8mm * var(--k)); }
.tk-detail { font-size: calc(2.5mm * var(--k)); line-height: 1.3; max-width: 100%; white-space: nowrap; overflow: hidden; flex: none; }
.tk-gap { flex: 1 1 0; min-height: calc(0.9mm * var(--k)); max-height: calc(3.5mm * var(--k)); }
.tk-sizes { display: flex; justify-content: space-between; align-items: center; width: calc(32mm * var(--k)); max-width: 100%; flex: none; }
.tk-sizes.lone { justify-content: center; }
.tk-size {
  box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  min-width: calc(5mm * var(--k)); height: calc(5mm * var(--k));
  padding: 0 calc(0.9mm * var(--k));
  border: 0.26mm solid transparent; border-radius: calc(2.5mm * var(--k));
  font-size: calc(1.96mm * var(--k)); line-height: 1; white-space: nowrap;
}
.tk-size.on { border-color: #000; }
.tk-rule { align-self: stretch; margin: calc(1.1mm * var(--k)) -1mm calc(1.3mm * var(--k)); border-top: 0.26mm solid #000; flex: none; }
.tk-price { font-size: calc(4.6mm * var(--k)); font-weight: 700; line-height: 1; white-space: nowrap; flex: none; }
.tk-icons { display: flex; align-items: center; justify-content: center; gap: calc(1mm * var(--k)); flex: none; }
.tk-codes { display: flex; flex-direction: column; align-items: center; gap: 1mm; flex: none; }

/* ---------- print: only the #printRoot container reaches the paper ---------- */
#printRoot { display: none; }
@media print {
  html, body { background: #fff !important; margin: 0; padding: 0; }
  .page { display: none !important; }
  #printRoot { display: block; }
  #printRoot .lbl { box-shadow: none; }
  #printRoot.single .lbl { break-after: page; page-break-after: always; }
  #printRoot.single .lbl:last-child { break-after: auto; page-break-after: auto; }
  #printRoot .sheet {
    width: 210mm;
    height: 296.5mm;
    overflow: hidden;
    display: grid;
    align-content: start;
    justify-content: start;
    break-after: page;
    page-break-after: always;
  }
  #printRoot .sheet:last-child { break-after: auto; page-break-after: auto; }
  #printRoot .lbl.cut { outline: 0.15mm dashed #9a9a9a; outline-offset: -0.075mm; }
}
