*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f5f5f5;
  color: #222;
}

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.nav-left,
.nav-right {
  width: 60px;
  display: flex;
  align-items: center;
}

.nav-center {
  flex: 1;
  text-align: center;
}

.nav-title {
  font-size: 16px;
  font-weight: 600;
}

.nav-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
}

.page {
  max-width: 800px;
  margin: 0 auto;
  padding: 12px;
}

.top-settings-btn {
  position: fixed;
  right: 16px;
  top: 56px;
  border: none;
  background: #ffffff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

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

.h1 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.query-by-code-row {
  margin-top: 4px;
}
.query-code-label {
  white-space: nowrap;
  font-size: 14px;
  color: #333;
}
.query-code-input {
  flex: 1;
  min-width: 160px;
}

.query-mobile-hint {
  display: none; /* 仅在小屏/手机端显示 */
}

.input {
  flex: 1;
  min-width: 120px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: 14px;
  touch-action: manipulation;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f0f5ff;
  color: #1d39c4;
  font-size: 12px;
}

.batch-import-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.batch-import-btn {
  flex: 1;
  min-width: 120px;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: #1677ff;
  color: #fff;
}

.batch-import-btn.secondary {
  background: #f5f5f5;
  color: #333;
}

.batch-import-btn.success {
  background: #52c41a;
}

.batch-import-btn.danger {
  background: #ff4d4f;
}

.icon {
  font-size: 16px;
}

.list {
  border-top: 1px solid #f0f0f0;
  margin-top: 8px;
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #f5f5f5;
  font-size: 14px;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  background: #1677ff;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  touch-action: manipulation; /* 减少移动端点击延迟 */
}

.btn.secondary {
  background: #f5f5f5;
  color: #333;
}

.btn.danger {
  background: #ff4d4f;
}

.btn-mini {
  padding: 2px 6px;
  font-size: 12px;
}

.hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: #888;
}

/* 分堆列表中煎药号的颜色状态 */
.pile-code {
  font-weight: 500;
}

/* 已经扫过（历史）- 黄色 */
.pile-code-scanned {
  color: #d48806;
}

/* 当前正在扫码/刚扫到 - 红色 */
.pile-code-current {
  color: #cf1322;
}

.pile-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.pile-btn {
  border-radius: 999px;
  border: 1px solid #ddd;
  background: #fafafa;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}

.pile-btn.active {
  background: #e6f4ff;
  border-color: #1677ff;
  color: #1677ff;
}

/* 扫码记录列表项（在弹层内展示） */
.query-record-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}
.query-record-item:last-child {
  border-bottom: none;
}
.query-record-code {
  font-weight: 500;
  font-family: ui-monospace, monospace;
  min-width: 140px;
}
.query-record-time {
  font-size: 12px;
  color: #888;
}
.query-record-found {
  font-size: 12px;
  color: #389e0d;
}
.query-record-notfound {
  font-size: 12px;
  color: #cf1322;
}

.big {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 600;
}

.ocr-progress {
  margin-top: 12px;
  padding: 12px;
  background: #f0f5ff;
  border-radius: 8px;
  border: 1px solid #d4e3ff;
}

.ocr-progress-text {
  font-size: 14px;
  color: #1677ff;
  margin-bottom: 8px;
  font-weight: 500;
}

.ocr-progress-bar {
  width: 100%;
  height: 8px;
  background: #e6f4ff;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.ocr-progress-fill {
  height: 100%;
  background: #1677ff;
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

.ocr-progress-status {
  font-size: 12px;
  color: #666;
}

/* 百度OCR服务状态提示 */
.ocr-service-status {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(59, 130, 246, 0.08);
  color: #0f172a;
}
.ocr-service-status.ok {
  background: rgba(16, 185, 129, 0.10);
  border-color: rgba(16, 185, 129, 0.25);
}
.ocr-service-status.warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.30);
}
.ocr-service-status.err {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.25);
}

.image-preview {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.image-preview-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #ddd;
}

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

.image-preview-item .remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 77, 79, 0.9);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* 扫码记录弹层（仅查看，不可删除） */
.records-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.records-modal-content {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: #fff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.records-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fafafa;
  border-bottom: 1px solid #eee;
}

.records-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #222;
}

.records-modal-header .camera-close-btn {
  color: #666;
}

.records-modal-header .camera-close-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.records-modal-body {
  padding: 12px 16px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.query-record-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.query-record-filter-label {
  font-size: 14px;
  color: #666;
  white-space: nowrap;
}

.query-record-select {
  flex: 1;
  min-width: 0;
  max-width: 160px;
  padding: 6px 10px;
  font-size: 14px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #fff;
}

.query-record-code-input {
  flex: 1;
  min-width: 0;
  max-width: 200px;
  padding: 6px 10px;
  font-size: 14px;
  border-radius: 6px;
  border: 1px solid #ddd;
}

/* 摄像头扫码界面 */
.camera-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-modal-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #000;
}

.camera-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
}

.camera-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.camera-close-btn {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.camera-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.camera-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.camera-overlay::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  clip-path: polygon(
    0% 0%,
    0% 100%,
    calc(50% - 150px) 100%,
    calc(50% - 150px) calc(50% - 80px),
    calc(50% + 150px) calc(50% - 80px),
    calc(50% + 150px) calc(50% + 80px),
    calc(50% - 150px) calc(50% + 80px),
    calc(50% - 150px) 100%,
    100% 100%,
    100% 0%
  );
}

.scan-line {
  width: 300px;
  height: 2px;
  background: #1677ff;
  box-shadow: 0 0 10px #1677ff;
  animation: scan-line 2s linear infinite;
  position: relative;
  z-index: 1;
}

@keyframes scan-line {
  0% {
    transform: translateY(-80px);
    opacity: 1;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translateY(80px);
    opacity: 0;
  }
}

.scan-hint {
  margin-top: 120px;
  color: #fff;
  font-size: 14px;
  text-align: center;
  position: relative;
  z-index: 1;
  background: rgba(0, 0, 0, 0.6);
  padding: 8px 16px;
  border-radius: 20px;
}

.camera-footer {
  padding: 16px;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  gap: 12px;
  justify-content: center;
}

.camera-footer .btn {
  flex: 1;
  max-width: 200px;
}

/* 手机端：查询区域触控优化，避免键盘遮挡 */
@media (max-width: 768px) {
  .query-section .btn {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 15px;
  }
  .query-by-code-row .query-code-input,
  .query-by-code-row .input {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 16px; /* 避免 iOS 聚焦时自动放大 */
  }
  .query-by-code-row .btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 16px;
    min-width: 72px;
  }
  .query-section .big {
    font-size: 18px;
    min-height: 1.5em;
  }
  .query-mobile-hint {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #666;
  }
}

@media (max-width: 480px) {
  .page {
    padding: 10px 10px 20px;
  }

  .section {
    padding: 10px 12px 14px;
  }

  .camera-overlay::before {
    clip-path: polygon(
      0% 0%,
      0% 100%,
      calc(50% - 120px) 100%,
      calc(50% - 120px) calc(50% - 60px),
      calc(50% + 120px) calc(50% - 60px),
      calc(50% + 120px) calc(50% + 60px),
      calc(50% - 120px) calc(50% + 60px),
      calc(50% - 120px) 100%,
      100% 100%,
      100% 0%
    );
  }

  .scan-line {
    width: 240px;
  }

  @keyframes scan-line {
    0% {
      transform: translateY(-60px);
      opacity: 1;
    }
    50% {
      opacity: 1;
    }
    100% {
      transform: translateY(60px);
      opacity: 0;
    }
  }

  .scan-hint {
    margin-top: 100px;
    font-size: 12px;
  }
}


