/**
 * LABEL LAYOUT — แก้ไฟล์นี้แล้ว refresh /label-debug
 *
 * โครงสร้าง (แนวนอน 80×50 mm):
 *   ┌─────────────────────────────────────┐
 *   │ CODE      │ TYPE/COD │ WEIGHT/RECV  │  ← --label-info-h
 *   ├───────────┴──────────┴──────────────┤
 *   │ BOX NO. barcode │ TRACKING barcode  │  ← ส่วนที่เหลือ
 *   └─────────────────────────────────────┘
 * หมุน 90° ลงสติกเกอร์ 50×80 mm ตอนพิมพ์
 *
 * ระวัง: อย่าตั้ง line-height ต่ำกว่า 1.25 บน element ที่มี overflow:hidden
 * เพราะ html2canvas จะตัดหางตัวอักษร
 */
:root {
  /* --font-inter มาจาก next/font ใน layout.tsx */
  --label-font-family: var(--font-inter), Inter, system-ui, -apple-system, "Segoe UI", Roboto,
    sans-serif;

  --label-design-w: 80mm;
  --label-design-h: 50mm;
  --label-pad-y: 2px;
  --label-pad-x: 4px;
  --label-section-gap: 2px;

  /* บรรทัด — ต่ำกว่า 1.25 ตัวอักษรจะโดนตัด */
  --label-line-height: 1.3;

  /* แถวบน — เพิ่มถ้า CODE / Sea / วันที่ โดนตัด */
  --label-info-h: 62px;
  --label-grid-cols: 1.25fr 0.55fr 0.75fr;
  --label-info-pad-y: 2px;
  --label-info-pad-x: 4px;
  --label-value-gap: 1px;
  --label-sub-gap: 2px;

  /* บาร์โค้ด */
  --label-barcode-gap: 4px;
  --label-barcode-h: 42px;
  --label-barcode-slot-pad-y: 2px;
  --label-barcode-slot-pad-x: 2px;
  /* ดันเลข box / tracking ขึ้นจากขอบล่าง — เพิ่มค่านี้ถ้าอยากให้ขึ้นอีก */
  --label-caption-lift: 14px;

  /* ฟอนต์ */
  --label-font-kicker: 8px;
  --label-font-value: 11px;
  --label-font-sub: 10px;
  --label-font-code: 28px;
  --label-font-kind: 12px;
  --label-font-barcode-title: 14px;
  /* เพดานของเลข box / tracking — ของจริงย่อลงอัตโนมัติให้พอดีช่อง */
  --label-font-barcode-caption: 24px;
}

.shipping-label-sheet,
.label-sheet {
  box-sizing: border-box;
  width: var(--label-design-w);
  height: var(--label-design-h);
  min-width: var(--label-design-w);
  min-height: var(--label-design-h);
  max-width: var(--label-design-w);
  max-height: var(--label-design-h);
  display: flex;
  flex-direction: column;
  gap: var(--label-section-gap);
  padding: var(--label-pad-y) var(--label-pad-x);
  overflow: hidden;
  background: #ffffff;
  color: #000000;
  font-family: var(--label-font-family);
}

.label-info-grid {
  display: grid;
  grid-template-columns: var(--label-grid-cols);
  align-items: stretch;
  flex: 0 0 var(--label-info-h);
  height: var(--label-info-h);
  min-height: var(--label-info-h);
  max-height: var(--label-info-h);
  border: 1px solid #000000;
}

.label-info-cell {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: flex-start;
  padding: var(--label-info-pad-y) var(--label-info-pad-x);
  overflow: hidden;
}

.label-info-cell + .label-info-cell {
  border-left: 1px solid #000000;
}

/*
 * line-height is a px length, not a ratio, so auto-shrunk text keeps the same
 * line box and stays vertically centred instead of drifting to the top.
 */
.label-info-kicker {
  margin: 0;
  flex: 0 0 auto;
  height: calc(var(--label-font-kicker) * var(--label-line-height));
  font-size: var(--label-font-kicker);
  font-weight: 600;
  line-height: calc(var(--label-font-kicker) * var(--label-line-height));
  letter-spacing: 0.08em;
  color: rgba(0, 0, 0, 0.45);
  text-align: left;
  overflow: visible;
}

.label-info-value {
  margin: var(--label-value-gap) 0 0;
  flex: 0 0 auto;
  height: calc(var(--label-font-value) * var(--label-line-height));
  overflow: hidden;
  white-space: nowrap;
  font-size: var(--label-font-value);
  font-weight: 500;
  line-height: calc(var(--label-font-value) * var(--label-line-height));
  letter-spacing: -0.02em;
  text-align: left;
  color: #000000;
}

.label-info-value--code {
  height: calc(var(--label-font-code) * var(--label-line-height));
  font-size: var(--label-font-code);
  font-weight: 700;
  line-height: calc(var(--label-font-code) * var(--label-line-height));
  text-transform: uppercase;
  text-align: center;
}

.label-info-value--kind {
  height: calc(var(--label-font-kind) * var(--label-line-height));
  font-size: var(--label-font-kind);
  font-weight: 700;
  line-height: calc(var(--label-font-kind) * var(--label-line-height));
}

.label-info-value--sub {
  height: calc(var(--label-font-sub) * var(--label-line-height));
  font-size: var(--label-font-sub);
  line-height: calc(var(--label-font-sub) * var(--label-line-height));
}

.label-info-kicker--sub {
  margin-top: var(--label-sub-gap);
}

.label-barcodes {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: 1fr 1fr;
  gap: var(--label-barcode-gap);
}

.label-barcode-slot {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid #000000;
  border-radius: 2px;
  padding: var(--label-barcode-slot-pad-y) var(--label-barcode-slot-pad-x);
}

.label-barcode-title {
  margin: 0;
  flex: 0 0 auto;
  height: calc(var(--label-font-barcode-title) * var(--label-line-height));
  overflow: hidden;
  white-space: nowrap;
  font-size: var(--label-font-barcode-title);
  font-weight: 600;
  line-height: calc(var(--label-font-barcode-title) * var(--label-line-height));
  color: #000000;
}

.label-barcode-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  align-items: center;
  justify-content: center;
  margin: 2px 0;
  overflow: hidden;
}

.label-barcode-svg {
  display: block;
  width: 100%;
  height: var(--label-barcode-h);
  max-height: var(--label-barcode-h);
}

.label-barcode-placeholder {
  width: 100%;
  height: 28px;
  border: 1px dashed rgba(0, 0, 0, 0.25);
}

/*
 * No fixed height here — the caption is auto-shrunk to the widest size that
 * fits, and the line box follows it so the barcode keeps whatever is left over.
 */
.label-barcode-caption {
  margin: 0 0 var(--label-caption-lift);
  flex: 0 0 auto;
  overflow: hidden;
  white-space: nowrap;
  font-size: var(--label-font-barcode-caption);
  font-weight: 700;
  line-height: var(--label-line-height);
  letter-spacing: -0.02em;
  text-align: center;
  color: #000000;
}
