:root {
  --ink: #111;
  --muted: #5d6470;
  --line: #d7dbe2;
  --panel: #fff;
  --page: #f4f6f8;
  --accent: #9c1d34;
  --focus: #245f9f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 360px) auto;
  gap: 20px;
  align-items: end;
  max-width: 1260px;
  margin: 0 auto 20px;
}

.brand-heading {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  display: block;
  width: min(178px, 34vw);
  height: auto;
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

.toolbar p,
.order-summary,
.preview-heading span {
  color: var(--muted);
  font-size: 14px;
}

.order-form label {
  display: block;
  margin-bottom: 7px;
  color: #2b313a;
  font-size: 13px;
  font-weight: 700;
}

.lookup-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input[type="text"],
input[inputmode="numeric"] {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #b9c0ca;
  border-radius: 6px;
  background: #fff;
}

input:focus,
button:focus-visible {
  outline: 3px solid rgba(36, 95, 159, .24);
  outline-offset: 2px;
}

button {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid #20242a;
  border-radius: 6px;
  color: #fff;
  background: #20242a;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.print-button {
  min-width: 130px;
  background: var(--focus);
  border-color: var(--focus);
}

.logout-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  border: 1px solid #b9c0ca;
  border-radius: 6px;
  color: #20242a;
  background: #fff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(430px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.auth-logo {
  width: 190px;
  margin-bottom: 18px;
}

.auth-card h1 {
  margin-bottom: 10px;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.45;
}

.auth-card code {
  color: #20242a;
  font-family: Consolas, Monaco, monospace;
}

.google-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  margin-top: 18px;
  padding: 9px 15px;
  border: 1px solid #20242a;
  border-radius: 6px;
  color: #fff;
  background: #20242a;
  font-weight: 700;
  text-decoration: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 20px;
  max-width: 1260px;
  margin: 0 auto;
}

.carton-panel,
.preview-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.carton-panel {
  align-self: start;
  padding: 16px;
}

.panel-heading,
.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.select-all,
.carton-option {
  display: flex;
  gap: 9px;
  align-items: center;
}

.select-all {
  font-size: 13px;
  font-weight: 700;
}

.carton-list {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.carton-option {
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
  font-size: 13px;
}

.carton-option span {
  overflow-wrap: anywhere;
}

.preview-panel {
  padding: 16px;
  overflow-x: auto;
}

.label-preview {
  display: grid;
  gap: 18px;
  justify-items: start;
}

.empty-state {
  min-height: 260px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed #b8c0cc;
  border-radius: 8px;
}

.label {
  width: 4in;
  height: 6in;
  display: grid;
  grid-template-rows: .72in .92in .66in 1.2in 1fr;
  border: 2px solid #111;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  page-break-after: always;
  break-after: page;
  font-family: Arial, Helvetica, sans-serif;
}

.label-row {
  display: grid;
  min-height: 0;
  border-bottom: 2px solid #111;
}

.label-row:last-child {
  border-bottom: 0;
}

.top-row {
  grid-template-columns: 1.05fr 2fr;
}

.ship-row {
  grid-template-columns: 2fr 1.15fr;
}

.po-row {
  grid-template-columns: 1fr;
}

.facility-row {
  grid-template-columns: 1.55fr 1fr;
}

.label-cell {
  position: relative;
  min-width: 0;
  padding: 6px 8px;
  border-right: 2px solid #111;
  overflow: hidden;
}

.label-cell:last-child {
  border-right: 0;
}

.label-caption {
  display: block;
  margin-bottom: 2px;
  font-size: 9px;
  line-height: 1;
  font-weight: 800;
  text-transform: uppercase;
}

.field-mark {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  display: none;
  place-items: center;
  color: #fff;
  background: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.address-block {
  white-space: pre-line;
  font-size: 11px;
  line-height: 1.14;
  font-weight: 700;
}

.from-address {
  font-size: 10px;
  line-height: 1.08;
}

.to-address {
  margin-top: -2px;
  text-align: center;
  font-size: 12px;
  line-height: 1.08;
}

.carrier-block {
  font-size: 12px;
  line-height: 1.2;
}

.carrier-name {
  display: block;
  margin-bottom: 2px;
  font-size: 17px;
  line-height: 1;
  font-weight: 800;
}

.po-value {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 26px 0;
  font-size: 24px;
  line-height: 1;
  font-weight: 900;
}

.po-value span:first-child {
  font-size: 22px;
}

.carton-count {
  position: absolute;
  right: 10px;
  bottom: 6px;
  font-size: 13px;
  font-weight: 800;
}

.barcode-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
  height: 100%;
}

.barcode-wrap canvas {
  max-width: 100%;
  max-height: 100%;
}

.zip-cell,
.facility-barcode-cell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  row-gap: 1px;
}

.zip-cell .barcode-wrap {
  height: auto;
  overflow: hidden;
}

.zip-cell .barcode-wrap canvas,
.facility-barcode-cell .barcode-wrap canvas {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.zip-cell .barcode-wrap,
.facility-barcode-cell .barcode-wrap {
  position: relative;
  min-height: 0;
}

.zip-cell .barcode-wrap canvas,
.facility-barcode-cell .barcode-wrap canvas {
  position: absolute;
  inset: 0;
  margin: auto;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

.zip-human,
.facility-barcode-human,
.sscc-human {
  margin-top: 0;
  text-align: center;
  font-size: 12px;
  line-height: 1;
  font-weight: 800;
}

.facility-human {
  display: grid;
  place-content: center;
  height: calc(100% - 14px);
  text-align: left;
  font-size: 23px;
  line-height: 1.05;
}

.facility-human span:first-child {
  font-size: 22px;
}

.sscc-cell {
  padding: 6px 10px 8px;
}

.sscc-cell .barcode-wrap {
  height: calc(100% - 24px);
}

.sscc-human {
  font-size: 13px;
}

.barcode-error {
  width: 100%;
  padding: 8px;
  border: 1px solid #111;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
}

@media (max-width: 900px) {
  .toolbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .brand-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .print-button {
    width: 100%;
  }
}

@media print {
  @page {
    size: 4in 6in;
    margin: 0;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  html,
  body {
    width: 4in !important;
    min-width: 4in !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
  }

  .toolbar,
  .carton-panel,
  .preview-heading {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .preview-panel,
  .label-preview {
    display: block;
    width: 4in !important;
    max-width: none !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: #fff !important;
    overflow: visible !important;
  }

  .label {
    width: 4in !important;
    height: 6in !important;
    margin: 0 !important;
    border-radius: 0 !important;
    transform: none !important;
  }
}
