* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: #F5F6F7;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: #1F2329;
  overscroll-behavior-y: contain;
}

.topbar {
  background: #3370FF;
  color: #fff;
  padding: env(safe-area-inset-top) 16px 12px;
  padding-top: max(env(safe-area-inset-top), 12px);
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

main {
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

.view {
  display: none;
  padding: 12px;
}

.view.active {
  display: block;
}

.card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.label {
  color: #646A73;
  font-size: 12px;
  margin-bottom: 4px;
}

.value {
  color: #1F2329;
  font-size: 16px;
  font-weight: 500;
}

.muted {
  color: #8F959E;
  font-size: 12px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #EFF0F1;
}

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

.row .label {
  margin-bottom: 0;
}

.barcode {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 1px;
  margin: 4px 0;
  word-break: break-all;
}

.btn {
  display: inline-block;
  background: #3370FF;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}

.btn:active { opacity: 0.85; }
.btn:disabled { background: #C9CDD4; }

.btn-secondary {
  background: #fff;
  color: #3370FF;
  border: 1px solid #3370FF;
}

.btn-danger {
  background: #F54A45;
  color: #fff;
}

.btn-link {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

.scan-btn {
  display: block;
  width: 100%;
  background: #3370FF;
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 40px 16px;
  text-align: center;
  margin: 16px 0;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(51,112,255,0.3);
}

.scan-btn:active { transform: scale(0.98); }

.scan-icon {
  font-size: 60px;
  line-height: 1;
  margin-bottom: 8px;
}

.scan-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.scan-hint {
  font-size: 12px;
  opacity: 0.85;
}

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

.row-actions .btn {
  flex: 1 1 0;
  min-width: 90px;
  font-size: 13px;
  padding: 10px;
}

.text-input {
  width: 100%;
  background: #F5F6F7;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  margin-top: 4px;
  font-family: inherit;
  outline: none;
}

.text-input:focus {
  border-color: #3370FF;
  background: #fff;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.qty-btn {
  flex: 0 0 44px;
  height: 40px;
  background: #F0F4FF;
  color: #3370FF;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

.qty-input {
  flex: 1;
  height: 40px;
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  border: 1px solid #E5E6EB;
  border-radius: 6px;
  outline: none;
  -moz-appearance: textfield;
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* 图片上传 */
.img-uploads {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.img-slot {
  display: block;
  position: relative;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
}

.img-slot .img-preview {
  width: 100%;
  aspect-ratio: 1;
  background: #F5F6F7;
  border: 1px dashed #C9CDD4;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.img-slot .img-placeholder {
  text-align: center;
  color: #8F959E;
  font-size: 12px;
  line-height: 1.6;
}

.img-slot .img-placeholder:first-line {
  font-size: 28px;
}

.img-slot.has-image .img-preview {
  border-style: solid;
  border-color: #3370FF;
}

.img-slot.has-image .img-placeholder {
  display: none;
}

.img-slot .img-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-slot.uploading .img-preview::after {
  content: '上传中…';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.img-slot.error .img-preview {
  border-color: #F54A45;
}

.img-slot .img-status {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #3370FF;
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
  display: none;
}

.img-slot.has-image .img-status {
  display: block;
  content: '✓';
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.actions .btn {
  flex: 1;
  font-size: 13px;
  padding: 12px 8px;
}

.empty {
  text-align: center;
  color: #8F959E;
  padding: 40px 0;
  font-size: 13px;
}

.item-card {
  background: #fff;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.item-card .item-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.item-card .name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.item-card .meta {
  color: #8F959E;
  font-size: 12px;
}

.item-card .qty-block {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.item-card .qty-edit-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #F0F4FF;
  color: #3370FF;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}

.item-card .qty-num {
  min-width: 28px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
}
.item-card .qty-num.editable {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  border-bottom: 2px dashed #3370FF;
}
.item-card .qty-num.editable:active {
  background: #F0F4FF;
}

.item-card .link-secondary {
  color: #3370FF;
  font-size: 12px;
  background: none;
  border: none;
  cursor: pointer;
  margin-right: 8px;
}

.item-card .item-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.item-card .link-danger {
  color: #F54A45;
  font-size: 12px;
  background: none;
  border: none;
  cursor: pointer;
}

.ai-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #E5E6EB;
  color: #4E5969;
  font-size: 11px;
  margin-left: 4px;
}
.ai-badge.ok { background: #DDF3E1; color: #1A6E2E; }
.ai-badge.err { background: #FBE4E4; color: #B92E25; }

.item-card .extracted {
  margin-top: 6px;
  padding: 6px 8px;
  background: #F5F6F7;
  border-radius: 4px;
  color: #4E5969;
  font-size: 12px;
  line-height: 1.5;
}

/* 盘点差异 */
.diff-row {
  margin-top: 6px;
}
.diff-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.diff-badge.ok {
  background: #DDF3E1;
  color: #1A6E2E;
}
.diff-badge.err {
  background: #FBE4E4;
  color: #B92E25;
}
.diff-badge.warn {
  background: #FFF3CD;
  color: #8A6D1B;
}
.diff-badge + .diff-badge {
  margin-left: 6px;
}

/* 整张卡片在不一致时高亮 */
.item-card.has-diff {
  border-left: 4px solid #F54A45;
  background: #FFF7F7;
}

/* 复选框行 */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #4E5969;
}
.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #3370FF;
}

/* 进度条 */
.progress-row {
  padding: 8px 0;
  border-bottom: 1px solid #EFF0F1;
}
.progress-row:last-child {
  border-bottom: 0;
}
.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.progress-contract {
  font-size: 14px;
  font-weight: 600;
  color: #1F2329;
}
.progress-text {
  font-size: 13px;
  color: #4E5969;
}
.progress-bar {
  height: 6px;
  background: #EFF0F1;
  border-radius: 3px;
  overflow: hidden;
  margin: 4px 0;
}
.progress-fill {
  height: 100%;
  background: #3370FF;
  transition: width 0.3s;
}
.progress-fill.complete {
  background: #00B96B;
}

/* admin 标记 */
.admin-badge {
  display: inline-block;
  padding: 1px 6px;
  background: #FFF3CD;
  color: #B9690C;
  border-radius: 4px;
  font-size: 10px;
  vertical-align: middle;
  margin-left: 6px;
}

/* viewer 角色隐藏的元素 */
body[data-role="viewer"] [data-require-admin],
body[data-role="viewer"] .link-danger,
body[data-role="viewer"] .qty-edit-btn {
  display: none !important;
}

/* 附件缩略图 */
.att-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.att-thumb {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  background: #F5F6F7;
  border: 1px solid #E5E6EB;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.att-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.att-placeholder {
  font-size: 11px;
  color: #8F959E;
  text-align: center;
  padding: 4px;
}

/* Lightbox 大图预览 */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 300;
  display: none;
  flex-direction: column;
}
.lightbox-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(env(safe-area-inset-top), 12px) 16px 12px;
  color: #fff;
  font-size: 14px;
}
.lightbox img {
  flex: 1;
  width: 100%;
  height: auto;
  object-fit: contain;
  min-height: 0;
}

/* 重复扫描 / 漏扫 提示行 */
.alert-row {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
}
.alert-err {
  background: #FBE4E4;
  color: #B92E25;
  border-left: 3px solid #F54A45;
}
.alert-warn {
  background: #FFF7E6;
  color: #875A12;
  border-left: 3px solid #FF9500;
}

/* 同 FNSKU 多箱提示 */
.dup-hint {
  margin-top: 8px;
  padding: 8px 10px;
  background: #FFF7E6;
  color: #875A12;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.5;
  border-left: 3px solid #FF9500;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: #fff;
  border-top: 1px solid #EFF0F1;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8F959E;
  font-size: 13px;
  cursor: pointer;
}

.tab.active {
  color: #3370FF;
  font-weight: 600;
}

.scanner-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: none;
  flex-direction: column;
}

.scanner-overlay.active {
  display: flex;
}

.scanner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(env(safe-area-inset-top), 12px) 16px 12px;
  color: #fff;
  background: rgba(0,0,0,0.4);
}

#scanner-reader {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner-footer {
  padding: 16px;
  padding-bottom: max(env(safe-area-inset-bottom), 16px);
  text-align: center;
  background: rgba(0,0,0,0.4);
}

.scanner-footer .btn-link {
  font-size: 15px;
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 6px;
}

#scanner-reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

.toast {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 80vw;
  z-index: 200;
  display: none;
  text-align: center;
  white-space: pre-line;
  line-height: 1.5;
}

.toast.show {
  display: block;
  animation: fadeIn 0.2s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
