* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --label-width: 100mm;
  --label-height: 76mm;
  --print-label-height: 75.8mm;
  --screen-label-gap: 12px;
  --screen-layout-width: calc(var(--label-width) * 2 + var(--screen-label-gap));
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f3f4f6;
  color: #111827;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

h1 {
  margin-top: 0;
  margin-bottom: 16px;
  max-width: var(--screen-layout-width);
  margin-left: auto;
  margin-right: auto;
  font-size: 1.5rem;
}

.controls {
  padding: 14px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
}

.controls,
.labels {
  max-width: var(--screen-layout-width);
  margin-left: auto;
  margin-right: auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.875rem;
  gap: 6px;
}

input,
select {
  height: 34px;
  padding: 4px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
}

.actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid #94a3b8;
  background: #0f172a;
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  background: #1e293b;
}

.labels {
  display: flex;
  flex-wrap: wrap;
  gap: var(--screen-label-gap);
  margin-top: 16px;
}

.label-page {
  display: block;
  flex: 0 0 auto;
}

.label {
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
  width: var(--label-width);
  height: var(--label-height);
  padding-top: 3.5mm;
  padding-bottom: 3mm;
  border: 1px dashed #9ca3af;
  background: #fff;
  overflow: hidden;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.label-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5mm;
}

.lot-title {
  font-size: 7mm;
  line-height: 1;
  color: #000;
}

.lot-line {
  width: 100%;
  border-top: 0.8mm solid #000;
}

.label-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.lot-logo {
  height: 16.00mm;
  width: auto;
  object-fit: contain;
}

.label-qr {
  position: absolute;
  right: 3mm;
  bottom: 5mm;
  width: 46px;
  height: 46px;
  background: #fff;
  z-index: 2;
  display: block;
  object-fit: contain;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.label-qr canvas,
.label-qr img {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.label-qr table {
  width: 100% !important;
  height: 100% !important;
  border-collapse: collapse;
}

.label-qr-fallback {
  border: 0.6mm solid #000;
  font-size: 3mm;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.label-footer {
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.seq {
  line-height: 1;
  color: #000;
  letter-spacing: 0;
  white-space: nowrap;
  font-weight: 700;
}

@media print {
  .labels {
    max-width: none;
  }

  html,
  body {
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .no-print {
    display: none !important;
  }

  .app {
    width: auto;
    height: auto;
    max-width: none;
    padding: 0;
    margin: 0;
  }

  h1 {
    display: none;
  }

  .label-qr {
    width: 12mm;
    height: 12mm;
  }

  .label-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5mm;
  }

  .label-center {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .label-footer {
    display: flex;
    justify-content: center;
    align-items: flex-end;
  }

  .lot-title,
  .lot-line,
  .lot-logo,
  .label-qr,
  .seq {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body[data-print-mode="label"] .labels {
    display: block;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
  }

  body[data-print-mode="label"] .label {
    display: grid;
    grid-template-rows: auto 1fr auto;
    width: 100mm;
    height: var(--print-label-height);
    padding-top: 3.5mm;
    padding-bottom: 3mm;
    border: 0;
    margin: 0;
    overflow: hidden;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body[data-print-mode="label"] .label-page {
    display: block;
    break-inside: avoid;
    page-break-inside: avoid;
    break-after: page;
    page-break-after: always;
  }

  body[data-print-mode="label"] .label-page:first-child {
    break-before: auto;
    page-break-before: auto;
  }

  body[data-print-mode="label"] .label-page + .label-page {
    break-before: page;
    page-break-before: always;
  }

  body[data-print-mode="label"] .label-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  body[data-print-mode="a4"] .app {
    max-width: none;
  }

  body[data-print-mode="a4"] .labels {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    justify-content: flex-start;
    gap: 0;
    margin: 0;
    padding: 0;
  }

  body[data-print-mode="a4"] .label {
    display: grid;
    grid-template-rows: auto 1fr auto;
    width: 100mm;
    height: 76mm;
    padding-top: 3.5mm;
    padding-bottom: 3mm;
    border: 0.2mm dotted #b0b0b0;
    margin: 0;
    overflow: hidden;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body[data-print-mode="a4"] .label-page {
    break-after: auto;
    page-break-after: auto;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body[data-print-mode="a4"] .label + .label {
    break-before: auto;
  }

}
