:root {
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --border: #ddd;
  --accent: #1f6f3f;
  --bg: #fafafa;

  /* Label size in millimetres. Default matches Brother DK-1201 (29mm x 90mm).
     If using different label stock (e.g. DK-2205 62mm continuous), change these
     two values and reload the page. */
  --label-width: 90mm;
  --label-height: 29mm;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 640px;
  margin: 0 auto;
}

/* iPad and other touch screens: bigger everything, easier to tap without looking */
@media (pointer: coarse) {
  #barcodeInput {
    font-size: 1.6rem;
    padding: 20px 18px;
  }

  .settings-row .hint,
  .queue-count {
    font-size: 1.05rem;
  }

  .print-btn,
  .clear-btn {
    padding: 22px;
    font-size: 1.3rem;
  }

  .history-list {
    font-size: 1.05rem;
  }
}

.app-header h1 {
  margin: 0 0 4px 0;
  font-size: 1.4rem;
}

.subtitle {
  margin: 0 0 20px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.scan-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

#barcodeInput {
  flex: 1;
  font-size: 1.3rem;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  outline: none;
}

#barcodeInput:focus {
  border-color: var(--accent);
}

.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.idle { background: #ccc; }
.status-dot.ok { background: #2e9e4f; }
.status-dot.error { background: #d64545; }
.status-dot.loading { background: #e0a92f; }

.message {
  min-height: 22px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  color: var(--muted);
}

.message.error { color: #b3261e; }
.message.ok { color: var(--accent); }

.settings-row {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: var(--muted);
}

.settings-row .hint {
  font-size: 0.82rem;
  color: #999;
}

.queue-count {
  font-weight: 600;
  color: var(--ink);
}

.button-row {
  display: flex;
  gap: 10px;
  margin-bottom: 28px;
}

.print-btn {
  flex: 1;
}

.clear-btn {
  padding: 14px 20px;
  font-size: 1.05rem;
  font-weight: 600;
  background: white;
  color: #b3261e;
  border: 2px solid #d64545;
  border-radius: 8px;
  cursor: pointer;
}

.clear-btn:disabled {
  color: #aaa;
  border-color: #ddd;
  cursor: not-allowed;
}

.label-preview-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  padding: 20px;
  background: #f0f0f0;
  border-radius: 10px;
}

.label {
  width: var(--label-width);
  height: var(--label-height);
  background: white;
  border: 1px solid #999;
  padding: 2.5mm 4mm;
  display: flex;
  flex-direction: column;
  gap: 1mm;
}

.label-name {
  font-size: 2.4mm;
  font-weight: 600;
  line-height: 1.15;
  overflow: hidden;
  max-height: 5mm;
  flex-shrink: 0;
}

.label-main-row {
  display: flex;
  align-items: stretch;
  gap: 3mm;
  flex: 1;
  min-height: 0;
}

.label-price-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
}

.label-price {
  font-size: 7.5mm;
  font-weight: 700;
  line-height: 1.1;
}

.label-sku {
  font-size: 2.8mm;
  color: #444;
}

.label-barcode-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.label-barcode {
  width: 100%;
  height: 100%;
}

.print-btn {
  display: block;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.print-btn:disabled {
  background: #b9b9b9;
  cursor: not-allowed;
}

.history-title {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.9rem;
}

.history-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.history-list .hist-name {
  color: var(--ink);
}

.history-list .hist-meta {
  color: var(--muted);
}

/* Sits off-screen during normal use; only shown when printing (see @media
   print below). This is where the actual batch of labels gets built and
   printed from, one per queued item, in scan order. */
.print-batch {
  position: absolute;
  left: -9999px;
  top: -9999px;
}

/* Print rules: only the label prints, sized to the label stock, no margins.
   IMPORTANT: @page does not support CSS custom properties (var()) in most
   browsers, including Chrome, so these values are written out literally here.
   If you change --label-width / --label-height above for different label
   stock, update these two numbers to match, or you'll get the printer
   defaulting to a full page size and repeating the label down the roll. */
@media print {
  @page {
    size: 90mm 29mm;
    margin: 0;
  }

  body * {
    visibility: hidden;
  }

  .print-batch,
  .print-batch * {
    visibility: visible;
  }

  .print-batch {
    position: static;
    left: auto;
    top: auto;
  }

  .print-batch .label {
    border: none;
    break-after: page;
    page-break-after: always;
  }

  /* No trailing blank label after the last one */
  .print-batch .label:last-child {
    break-after: auto;
    page-break-after: auto;
  }
}
