:root {
  --ink: #101010;
  --muted: #686868;
  --line: #d8d8d2;
  --paper: #f7f7f3;
  --panel: #ffffff;
  --accent: #f4c430;
  --accent-dark: #b98a00;
  --success: #16885b;
  --label-margin-top: 1.5mm;
  --label-margin-right: 1.5mm;
  --label-margin-bottom: 1.5mm;
  --label-margin-left: 1.5mm;
  --slot-gap: 2mm;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(rgb(16 16 16 / 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgb(16 16 16 / 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
}

button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgb(244 196 48 / 0.45);
  outline-offset: 2px;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px clamp(20px, 4vw, 56px);
  color: white;
  background: #121212;
  border-bottom: 4px solid var(--accent);
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--accent);
  color: var(--ink);
  font-size: 25px;
  font-weight: 900;
  transform: skew(-7deg);
}

.eyebrow, .step {
  margin: 0 0 3px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
  color: var(--accent-dark);
}

.topbar .eyebrow { color: var(--accent); }
.topbar h1 { margin: 0; font-size: clamp(18px, 2vw, 24px); line-height: 1.1; }

.status-pill {
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid #444;
  border-radius: 999px;
  color: #d7d7d7;
  font-size: 12px;
}

.status-pill span {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--success);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  max-width: 1600px;
  min-height: calc(100vh - 130px);
  margin: 0 auto;
}

.control-panel {
  padding: 28px clamp(18px, 3vw, 38px) 36px;
  background: rgb(255 255 255 / 0.93);
  border-right: 1px solid var(--line);
}

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 24px; }
.mode-btn {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  text-align: left;
  color: #5c5c58;
  background: #f2f2ee;
  border: 1px solid var(--line);
  border-radius: 3px;
}
.mode-btn.active { color: var(--ink); background: #fff8db; border: 2px solid var(--accent-dark); }
.mode-number { font-size: 11px; font-weight: 900; color: var(--accent-dark); }
.mode-btn strong, .mode-btn small { display: block; }
.mode-btn strong { font-size: 14px; }
.mode-btn small { margin-top: 3px; font-size: 10px; line-height: 1.25; }

.section-block { padding: 20px 0; border-top: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 10px; }
.section-heading h2, .preview-header h2 { margin: 0; font-size: 19px; }
.helper { margin: 8px 0 12px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.text-button, .clear-button { padding: 0; color: #755b00; background: none; border: 0; font-size: 11px; font-weight: 750; }

textarea {
  width: 100%;
  min-height: 168px;
  resize: vertical;
  padding: 13px;
  color: var(--ink);
  background: #fbfbf8;
  border: 1px solid #bdbdb7;
  border-radius: 2px;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.input-footer { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 11px; }

details summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; list-style: none; font-size: 14px; font-weight: 800; }
details summary::-webkit-details-marker { display: none; }
.chevron { transition: transform 160ms ease; }
details[open] .chevron { transform: rotate(180deg); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 16px; margin-top: 18px; }
.settings-grid label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 700; }
.settings-grid label > span { display: flex; align-items: center; gap: 5px; }
.settings-grid input, .settings-grid select {
  width: 100%;
  min-height: 36px;
  padding: 7px 8px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c6c6c0;
  border-radius: 2px;
  font-size: 12px;
  font-weight: 650;
}

.action-row { padding-top: 20px; }
.primary-button, .print-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  font-weight: 850;
}
.primary-button {
  width: 100%;
  min-height: 48px;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--accent);
  color: var(--ink);
  border-bottom: 3px solid #c59700;
}
.primary-button:hover { background: #ffd94f; }

.preview-panel { min-width: 0; padding: 28px clamp(18px, 3.5vw, 52px) 44px; }
.preview-header { display: flex; justify-content: space-between; align-items: end; gap: 18px; }
.preview-actions { display: flex; gap: 8px; }
.search-field { position: relative; }
.search-field span { position: absolute; left: 11px; top: 8px; color: var(--muted); }
.search-field input { width: 180px; min-height: 36px; padding: 8px 10px 8px 31px; border: 1px solid var(--line); background: white; }
.print-button { min-height: 36px; padding: 8px 14px; color: white; background: #171717; }
.print-button:disabled { cursor: not-allowed; opacity: .38; }

.batch-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; padding: 11px 14px; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--accent); }
.batch-bar strong, .batch-bar span { display: block; }
.batch-bar strong { font-size: 12px; }
.batch-bar span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.batch-nav { display: flex; gap: 6px; }
.batch-nav button, .batch-nav select { min-height: 31px; border: 1px solid var(--line); background: #f8f8f4; font-size: 11px; }
.batch-nav button { width: 32px; }
.batch-nav select { padding: 0 9px; }

.empty-state { min-height: 520px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.empty-state h3 { margin: 20px 0 6px; color: #333; font-size: 16px; }
.empty-state p { margin: 0; font-size: 12px; }
.empty-icon { width: 85px; aspect-ratio: 7 / 4; display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; padding: 10px; border: 2px dashed #bdbdb6; }
.empty-icon span { background: #dcdcd5; }
.spec-line { display: flex; align-items: center; gap: 8px; width: 170px; margin-top: 30px; font-size: 10px; }
.spec-line i { flex: 1; border-top: 1px solid #bbb; }

.labels-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 22px; margin-top: 22px; }
.preview-card { min-width: 0; }
.preview-meta { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font-size: 10px; }
.label-stage { padding: 16px; background: #e7e7e1; border: 1px solid #d0d0ca; overflow: auto; }

.zebra-label {
  width: 70mm;
  height: 40mm;
  position: relative;
  overflow: hidden;
  display: flex;
  flex: 0 0 auto;
  padding: var(--label-margin-top) var(--label-margin-right) var(--label-margin-bottom) var(--label-margin-left);
  color: #000;
  background: #fff;
  font-family: Arial, Helvetica, sans-serif;
}
.label-stage .zebra-label { transform-origin: left top; }

.location-label { gap: var(--slot-gap); }
.location-slot { min-width: 0; flex: 1; display: grid; grid-template-rows: minmax(0, 1fr) auto; align-items: center; justify-items: center; padding: 1mm; border: .25mm dashed #b8b8b8; }
.location-slot:only-child { max-width: calc((100% - var(--slot-gap)) / 2); margin-inline: auto; }
.location-text { max-width: 100%; overflow: hidden; font-size: 4.2mm; font-weight: 900; line-height: 1; letter-spacing: -.1mm; white-space: nowrap; text-overflow: clip; }
.barcode-svg { width: 100%; height: 20mm; }

.product-label { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1.5mm; }
.product-label.qr-1 { grid-template-columns: auto 1fr; }
.product-label.qr-3 { grid-template-columns: auto 1fr auto; }
.product-copy { min-width: 0; text-align: center; }
.product-caption { margin: 0 0 .5mm; font-size: 2mm; font-weight: 800; letter-spacing: .16em; }
.product-sku { margin: 0 0 1mm; font-size: 4.2mm; font-weight: 900; line-height: .95; white-space: nowrap; }
.product-name { margin: 0; font-size: 2.7mm; font-weight: 800; line-height: 1.05; text-transform: uppercase; }
.product-um { display: inline-block; margin-top: 1.1mm; padding: .5mm 1.2mm; border: .35mm solid #000; font-size: 2.4mm; font-weight: 900; }
.qr-box { width: 18mm; height: 18mm; display: grid; place-items: center; }
.qr-box img, .qr-box canvas { width: 100% !important; height: 100% !important; image-rendering: pixelated; }
.product-label.qr-1 .qr-box { width: 24mm; height: 24mm; }
.product-label.qr-3 .qr-primary { width: 14mm; height: 14mm; align-self: start; }
.product-label.qr-3 .qr-secondary { width: 22mm; height: 22mm; }
.product-label.qr-3 .product-sku { font-size: 3.8mm; }
.product-label.qr-3 .product-name { font-size: 2.4mm; }
.qr-third { position: absolute; left: var(--label-margin-left); bottom: var(--label-margin-bottom); width: 14mm !important; height: 14mm !important; }

.footer-note { display: flex; justify-content: space-between; gap: 20px; padding: 12px clamp(20px, 4vw, 56px); color: #ddd; background: #161616; font-size: 10px; }
#printArea { display: none; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 340px; padding: 12px 15px; color: white; background: #171717; border-left: 4px solid var(--accent); box-shadow: 0 10px 30px rgb(0 0 0 / .2); font-size: 12px; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .control-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .empty-state { min-height: 360px; }
}

@media (max-width: 620px) {
  .topbar { align-items: flex-start; }
  .status-pill { display: none; }
  .mode-switch, .settings-grid { grid-template-columns: 1fr; }
  .preview-header { align-items: stretch; flex-direction: column; }
  .preview-actions { flex-direction: column; }
  .search-field input { width: 100%; }
  .batch-bar { align-items: flex-start; flex-direction: column; }
  .footer-note { flex-direction: column; }
}

@page { size: 70mm 40mm; margin: 0; }

@media print {
  html, body { width: 70mm; margin: 0 !important; padding: 0 !important; background: white !important; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  #printArea .zebra-label {
    width: 70mm !important;
    height: 40mm !important;
    margin: 0 !important;
    break-after: page;
    page-break-after: always;
    box-shadow: none !important;
  }
  #printArea .zebra-label:last-child { break-after: auto; page-break-after: auto; }
  .location-slot { border-color: transparent; }
}
