/* ==========================================================================
   Codes per zone: "Xong khu" sheet (zd-*) and the printable QR tags of a zone (zt-* / ztag-*)
   ========================================================================== */

/* ---------- "Xong khu" sheet ---------- */
.zd {
  gap: 12px;
}
.zd-loading {
  display: grid;
  gap: 10px;
}
.zd-sk {
  height: 58px;
}
.zd-sk.lg {
  height: 76px;
}
.zd-hero {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.zd-hero-ic {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--brand-soft);
  color: var(--brand);
}
.zd-hero-ic .icon {
  width: 22px;
  height: 22px;
}
.zd-hero.none .zd-hero-ic {
  background: var(--surface-3);
  color: var(--muted);
}
.zd-hero.ok .zd-hero-ic {
  background: var(--ok-soft);
  color: var(--ok);
}
.zd-hero > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.zd-hero-n {
  font-size: 19px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.zd-hero-s {
  font-size: 13px;
  color: var(--muted);
}
.zd-alert {
  font-size: 13.5px;
}
.zd-alert ul {
  margin: 4px 0 0;
  padding-left: 18px;
  color: var(--text-2);
}
.zd-alert li + li {
  margin-top: 2px;
}
.zd-sec {
  display: grid;
  gap: 6px;
}
.zd-h {
  margin: 4px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.zd-n {
  font-size: 11.5px;
  background: var(--surface-3);
  color: var(--text-2);
  border-radius: 99px;
  padding: 0 7px;
  letter-spacing: 0;
}
.zd-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
}
.zd-item {
  padding: 10px 12px;
  display: grid;
  gap: 3px;
}
.zd-item + .zd-item,
.zd-lot + .zd-lot {
  border-top: 1px solid var(--line);
}
.zd-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.zd-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.zd-badge {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  border-radius: 99px;
  padding: 1px 9px;
  background: var(--primary-soft);
  color: var(--ink);
  white-space: nowrap;
}
.zd-badge.zero {
  background: var(--surface-3);
  color: var(--muted);
  font-weight: 500;
}
.zd-badge.over {
  background: var(--bad-soft);
  color: var(--bad);
}
.zd-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
}
.zd-meta .icon {
  width: 13px;
  height: 13px;
}
.zd-owner {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  color: var(--text-2);
}
.zd-bad {
  color: var(--warn);
  font-weight: 600;
}
.zd-codes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.zd-code {
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--text-2);
  overflow-wrap: anywhere;
}
.zd-code.broken {
  border-color: var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
}
.zd-lot {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
  font-size: 14px;
}
.zd-lot .zd-name {
  font-weight: 500;
}
.zd-q {
  font-weight: 600;
  color: var(--text-2);
}
.zd-foot {
  margin: 0;
}

/* ---------- "Xong khu": comparison with the previous count (zv-*) ---------- */
.zv {
  gap: 8px;
}
.zv-head {
  display: grid;
  gap: 2px;
}
.zv-h {
  margin: 0;
}
.zv-h .icon {
  width: 14px;
  height: 14px;
  color: var(--warn);
}
.zv-base {
  font-size: 12.5px;
  color: var(--muted);
}
/* "Cùng lý do cho tất cả" */
.zv-all {
  display: grid;
  gap: 6px;
  padding: 10px 12px 12px;
  border-radius: var(--r);
  background: var(--surface-2);
  border: 1px dashed var(--line-2);
}
.zv-all-h {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.zv-all-hint {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--warn);
}
.zv-all-hint .icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
/* Reason chips: wrap, finger-sized (≥ 44 px) */
.zv-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.zv-chip {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 13px;
  border: 1px solid var(--line-2);
  border-radius: 99px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 0.12s,
    border-color 0.12s,
    color 0.12s;
}
.zv-chip .icon {
  width: 15px;
  height: 15px;
  color: var(--muted);
}
.zv-chip:hover {
  border-color: var(--ink);
}
.zv-chip:focus-visible,
.zv-change:focus-visible,
.zv-link:focus-visible,
.zv-retry:focus-visible,
.zv-toggle:focus-visible,
.zv-ph-x:focus-visible,
.zv-cam:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.zv-chip.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
  font-weight: 600;
}
.zv-chip.on .icon {
  color: inherit;
}
.zv-change {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
/* One line per item */
.zv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.zv-line {
  display: grid;
  gap: 8px;
  padding: 11px 12px 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  position: relative;
  overflow: hidden;
}
/* State band on the left: amber = still missing something, green = complete */
.zv-line::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--line-2);
}
.zv-line.todo {
  border-color: color-mix(in srgb, var(--warn) 40%, var(--line));
}
.zv-line.todo::before {
  background: var(--warn);
}
.zv-line.ok::before {
  background: var(--ok);
}
.zv-line.surplus::before {
  background: var(--info);
}
.zv-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.zv-what {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
}
.zv-name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.zv-qty {
  font-size: 13px;
  color: var(--muted);
}
.zv-qty b {
  color: var(--text-2);
}
.zv-diff {
  flex-shrink: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.zv-diff.neg {
  color: var(--bad);
}
.zv-diff.gone {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.3;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--bad-soft);
  color: var(--bad);
  white-space: nowrap;
}
.zv-diff.pos {
  color: var(--info);
}
.zv-note .input {
  width: 100%;
  min-height: 44px;
  font-size: 15px;
}
.zv-note .input.need {
  border-color: var(--warn);
}
/* Photos: thumbnails + camera tile */
.zv-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.zv-ph {
  position: relative;
  width: 64px;
  height: 64px;
}
.zv-ph a {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--r-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface-3);
}
.zv-ph img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Remove button: small visual, 32 px hit area around the corner */
.zv-ph-x {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.zv-ph-x .icon {
  width: 20px;
  height: 20px;
  padding: 3px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow-sm);
}
.zv-cam {
  height: 64px;
  min-width: 96px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.5px dashed var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.zv-line.todo .zv-cam:not(.busy) {
  border-color: var(--warn);
  color: var(--warn);
  background: var(--warn-soft);
}
.zv-cam .icon {
  width: 20px;
  height: 20px;
}
.zv-cam.busy {
  opacity: 0.6;
  cursor: progress;
}
/* Footer of a line: what is missing, save state, note link */
.zv-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  min-height: 20px;
  font-size: 12.5px;
}
.zv-miss {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  color: var(--warn);
}
.zv-miss .icon {
  width: 14px;
  height: 14px;
}
/* Save state sits on the quantity line so it never changes the height of a line (no jump under the finger) */
.zv-state {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}
.zv-state.ok {
  color: var(--ok);
}
.zv-state .icon {
  width: 14px;
  height: 14px;
}
.zv-retry,
.zv-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  margin: -8px 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.zv-retry {
  color: var(--bad);
}
.zv-link {
  min-height: 44px;
  margin: 0 0 0 auto;
  color: var(--text-2);
}
.zv-retry .icon,
.zv-link .icon {
  width: 14px;
  height: 14px;
}
.zv-inline-ic {
  width: 13px;
  height: 13px;
  vertical-align: -2px;
}
/* "Nhiều hơn kỳ trước": collapsed header */
.zv-toggle {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.zv-toggle .zd-h {
  flex-shrink: 0;
}
.zv-toggle-s {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
}
.zv-chev {
  width: 16px;
  height: 16px;
  color: var(--muted);
  transition: transform 0.15s;
}
.zv-chev.open {
  transform: rotate(90deg);
}
/* Confirm button while shortages still lack a reason / photo: readable, not a faded primary; it takes the room
   of the footer so the counter text fits on the phone */
.sheet-f .btn.main.zv-wait:disabled {
  opacity: 1;
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 45%, var(--line));
  color: var(--warn);
  box-shadow: none;
  white-space: normal;
  line-height: 1.2;
}
@media (max-width: 639px) {
  .sheet-f .btn.main.zv-wait:disabled {
    flex: 2.4;
    padding-inline: 10px;
    font-size: 13.5px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .zv-chip,
  .zv-chev {
    transition: none;
  }
}

/* ---------- Tags page: screen toolbar ---------- */
.zt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.zt-count {
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--muted);
}
.zt-count b {
  font-size: 26px;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.zt-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

/* ---------- Tag sheets: always black on white, A4, 3 × 10 tags of 64 × 28 mm (same decal stock as the
   inventory stickers); mm units so the screen preview and the print match ---------- */
@page ztags {
  size: A4 portrait;
  margin: 8mm;
}
.paper.ztag-sheet {
  page: ztags;
  width: 194mm;
  max-width: none;
  margin-inline: auto;
  overflow: visible;
  box-sizing: content-box;
}
.ztag-sheet.labels {
  height: 281mm;
}
.zt-paper-h {
  display: flex;
  align-items: baseline;
  gap: 4px 12px;
  flex-wrap: wrap;
  border-bottom: 1.5px solid #111;
  padding-bottom: 2mm;
  margin-bottom: 2mm;
  font-size: 9pt;
  color: #333;
}
.zt-paper-h b {
  font-size: 10.5pt;
  letter-spacing: 0.04em;
  color: #111;
}
.zt-paper-h span:last-child {
  margin-left: auto;
}
.ztag-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: 28mm;
}
.ztag-sheet.labels .ztag-grid {
  grid-template-rows: repeat(10, 28.1mm);
}
.zt-group {
  grid-column: 1 / -1;
  align-self: end;
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 0 1mm 1mm;
  border-bottom: 0.5px solid #9a958c;
  font-size: 8.5pt;
  color: #333;
  break-after: avoid;
}
.zt-group b {
  color: #111;
}
.zt-group-n {
  margin-left: auto;
  color: #666;
}
.ztag-grid > .zt-group {
  height: 8mm;
}
.ztag-sheet.grouped .ztag-grid {
  grid-auto-rows: auto;
}
.ztag {
  height: 28mm;
  min-width: 0;
  break-inside: avoid;
}
/* The shared Tem component, reshaped for paper: fixed colours (dark mode too), cut lines, no card chrome */
.ztag .tem {
  height: 100%;
  box-sizing: border-box;
  gap: 2.5mm;
  padding: 2mm 2.5mm 2mm 3.6mm;
  border: 0.5px dashed #9a958c;
  border-radius: 0;
  box-shadow: none;
  background: #fff;
  color: #111;
}
.ztag .tem .band {
  width: 1.6mm;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.ztag .tem .qr,
.ztag .tem .qr:has(svg) {
  width: 20mm;
  height: 20mm;
  padding: 0;
  border-radius: 0;
  background: #fff;
  color: #999;
}
.ztag .tem .txt {
  gap: 0.6mm;
  flex: 1;
}
.ztag .tem .tp {
  font-size: 6.5pt;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ztag .tem .code {
  font-size: 9.5pt;
  font-weight: 600;
  line-height: 1.15;
  color: #111;
  letter-spacing: -0.02em;
}
.ztag .tem .code span {
  color: #888;
}
.ztag .tem .nm {
  font-size: 7pt;
  line-height: 1.25;
  color: #333;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media print {
  /* Dark theme: the page margins print the dark canvas – keep the tag sheets on white paper */
  :root:has(.ztag-sheet) {
    color-scheme: light;
    background: #fff !important;
  }
  .paper.ztag-sheet {
    width: 194mm;
    border-radius: 0 !important;
  }
  .paper.ztag-sheet.labels {
    height: 281mm;
    overflow: hidden;
  }
  .paper.ztag-sheet.labels:last-child {
    break-after: auto;
  }
}
