/* ========== 全局变量 ========== */
:root {
  --primary: #1890ff;
  --primary-dark: #096dd9;
  --primary-light: #e6f7ff;
  --success: #52c41a;
  --success-dark: #389e0d;
  --success-light: #f6ffed;
  --warning: #faad14;
  --warning-light: #fffbe6;
  --error: #ff4d4f;
  --error-light: #fff1f0;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #333333;
  --text-secondary: #999999;
  --border: #e8e8e8;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

/* ========== Reset ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  user-select: none;
  -webkit-user-select: none;
}

input {
  user-select: text;
  -webkit-user-select: text;
}

/* ========== 页面切换 ========== */
.page {
  display: none;
  min-height: 100vh;
}

.page.active {
  display: block;
}

/* ========== 登录页 ========== */
.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
}

.logo-icon {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  margin: 0 auto 16px;
}

.login-logo h1 {
  color: #fff;
  font-size: 22px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.login-form {
  background: #fff;
  padding: 32px 24px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}

.login-form input {
  width: 100%;
  height: 52px;
  margin-bottom: 14px;
  padding: 0 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 17px;
  outline: none;
  transition: border-color 0.2s;
  background: #fafafa;
}

.login-form input:focus {
  border-color: var(--primary);
  background: #fff;
}

.login-hint {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 16px;
}

/* ========== 按钮 ========== */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-large {
  width: 100%;
  height: 56px;
  font-size: 18px;
  font-weight: 600;
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  height: 44px;
  padding: 0 16px;
}

.btn-danger-text {
  color: var(--error);
  border-color: #ffccc7;
}

.btn-action {
  width: 100%;
  height: 120px;
  flex-direction: column;
  gap: 8px;
  font-size: 24px;
  font-weight: 600;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: #fff;
  border: none;
}

.btn-inbound {
  background: linear-gradient(135deg, #52c41a 0%, #389e0d 100%);
}

.btn-outbound {
  background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
}

.btn-icon-arrow {
  font-size: 40px;
  line-height: 1;
}

/* ========== 顶部导航 ========== */
.app-header {
  background: #fff;
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h2 {
  font-size: 17px;
  flex: 1;
  text-align: center;
  font-weight: 600;
}

.btn-back {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text);
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-spacer {
  width: 40px;
}

/* ========== 首页 ========== */
.home-main {
  padding: 24px 16px;
}

.welcome {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  text-align: center;
}

.welcome strong {
  color: var(--text);
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 32px;
}

.secondary-buttons {
  display: flex;
  gap: 10px;
}

.secondary-buttons .btn {
  flex: 1;
  font-size: 14px;
}

/* ========== 在线状态 ========== */
.status-indicator {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
}

.status-indicator::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-indicator.online {
  background: var(--success-light);
  color: var(--success-dark);
}

.status-indicator.online::before {
  background: var(--success);
}

.status-indicator.offline {
  background: var(--error-light);
  color: var(--error);
}

.status-indicator.offline::before {
  background: var(--error);
}

/* ========== 扫描区域 ========== */
.scan-container {
  padding: 16px;
  padding-bottom: 80px;
}

.scan-input-wrapper {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.scan-input {
  flex: 1;
  height: 56px;
  padding: 0 16px;
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 18px;
  outline: none;
  background: #fff;
  caret-color: var(--primary);
}

.scan-input::placeholder {
  color: var(--text-secondary);
}

.btn-camera {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-camera:active {
  background: var(--primary-dark);
}

/* ========== 扫码确定按钮（手机手动输入兜底） ========== */
.btn-submit {
  width: 76px;
  height: 56px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--success);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}

.btn-submit:active {
  background: var(--success-dark);
}

/* ========== 摄像头渲染容器（html5-qrcode） ========== */
.camera-reader {
  width: 100%;
  max-width: 360px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}

.camera-reader video,
.camera-reader img {
  width: 100% !important;
  height: auto !important;
  display: block;
  border-radius: 8px;
}

/* ========== 计数显示 ========== */
.count-display {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.count-label {
  font-size: 14px;
  color: var(--text-secondary);
  display: inline;
}

.count-number {
  display: block;
  font-size: 56px;
  font-weight: 700;
  color: var(--primary);
  margin: 4px 0;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ========== 扫描列表 ========== */
.scan-list {
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

.scan-list-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

.scan-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

.scan-item:last-child {
  border-bottom: none;
}

.scan-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.scan-index {
  font-size: 12px;
  color: var(--text-secondary);
  width: 28px;
  flex-shrink: 0;
}

.scan-code {
  font-size: 15px;
  font-weight: 500;
  word-break: break-all;
  flex: 1;
  min-width: 0;
}

.scan-time {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 8px;
}

/* ========== 出库双入口 ========== */
.outbound-row {
  display: flex;
  gap: 12px;
}

.btn-half {
  flex: 1;
  height: 100px;
  font-size: 20px;
  gap: 6px;
}

.btn-half .btn-icon-arrow {
  font-size: 32px;
}

/* ========== 出库快递单阶段 ========== */
.phase-prompt {
  text-align: center;
  padding: 40px 16px 24px;
}

.prompt-icon {
  font-size: 56px;
  margin-bottom: 16px;
}

.phase-prompt p {
  font-size: 18px;
  color: var(--text);
  font-weight: 500;
}

.prompt-sub {
  font-size: 14px !important;
  color: var(--text-secondary) !important;
  font-weight: 400 !important;
  margin-top: 4px;
}

/* ========== 客户选择 ========== */
.customer-select-wrapper {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.customer-select {
  flex: 1;
  height: 56px;
  padding: 0 12px;
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 18px;
  background: #fff;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%231890ff' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
}

.btn-add-customer-inline {
  width: 72px;
  height: 56px;
  border: 2px dashed var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}

.btn-add-customer-inline:active {
  background: #bae7ff;
}

.customer-inline-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.customer-inline-form input {
  flex: 1;
  height: 48px;
  padding: 0 12px;
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
}

.btn-sm {
  height: 48px;
  padding: 0 16px;
  font-size: 14px;
}

/* ========== 出库信息条 ========== */
.customer-info-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--success-light);
  border: 1px solid #b7eb8f;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.customer-info-bar .info-label {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.customer-info-bar .info-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--success-dark);
  flex: 1;
  word-break: break-all;
}

.outbound-info-bars {
  margin-bottom: 16px;
}

.info-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.info-bar-row:first-child {
  background: var(--success-light);
  border: 1px solid #b7eb8f;
}

.info-bar-row:last-child {
  background: var(--primary-light);
  border: 1px solid #91d5ff;
}

.info-bar-row .info-label {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.info-bar-row .info-value {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  word-break: break-all;
}

.info-bar-row:first-child .info-value {
  color: var(--success-dark);
}

.info-bar-row:last-child .info-value {
  color: var(--primary);
}

.info-bar-express {
  background: var(--primary-light);
  border: 1px solid #91d5ff;
  margin-bottom: 16px;
}

.info-bar-express .info-value {
  color: var(--primary);
}

.btn-rescan {
  background: #fff;
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}

/* ========== 确认按钮 ========== */
.btn-confirm {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  width: auto;
  box-shadow: 0 4px 16px rgba(24,144,255,0.4);
  z-index: 5;
}

/* ========== 档案查询 ========== */
.records-container {
  padding: 16px;
}

.records-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.summary-card {
  flex: 1;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}

.summary-num {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summary-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.summary-card.all .summary-num { color: var(--text); }
.summary-card.in .summary-num { color: var(--success); }
.summary-card.out .summary-num { color: var(--primary); }

.records-table-wrap {
  overflow-x: auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

.records-table th {
  background: #fafafa;
  padding: 12px 10px;
  text-align: left;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.records-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.records-table tr:last-child td {
  border-bottom: none;
}

.records-table .empty-row {
  text-align: center;
  padding: 48px;
  color: var(--text-secondary);
}

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.status-badge.s-pending {
  background: #f0f0f0;
  color: #999;
}

.status-badge.s-in {
  background: var(--success-light);
  color: var(--success-dark);
}

.status-badge.s-out {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ========== Toast 提示 ========== */
#toast-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast {
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transform: scale(0.85);
  transition: all 0.25s;
  max-width: 300px;
  line-height: 1.4;
}

.toast.show {
  opacity: 1;
  transform: scale(1);
}

.toast-success { background: rgba(82,196,26,0.92); }
.toast-error { background: rgba(255,77,79,0.92); }
.toast-warning { background: rgba(250,173,20,0.92); }

/* ========== 摄像头弹窗 ========== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 2000;
}

.modal.active {
  display: flex;
}

.camera-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#camera-video {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

.camera-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  max-width: 360px;
  aspect-ratio: 3/2;
  pointer-events: none;
}

.camera-frame {
  width: 100%;
  height: 100%;
  border: 2px solid rgba(255,255,255,0.5);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.camera-frame::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--success);
  box-shadow: 0 0 12px var(--success);
  animation: scanLine 2s ease-in-out infinite;
}

@keyframes scanLine {
  0%, 100% { top: 10%; }
  50% { top: 90%; }
}

.camera-hint {
  color: rgba(255,255,255,0.8);
  font-size: 14px;
  margin-top: 16px;
}

.btn-modal-close {
  position: absolute;
  bottom: 48px;
  width: 120px;
  height: 44px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}

/* ========== 客户管理页 ========== */
.customers-container {
  padding: 16px;
}

.customer-add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.customer-add-form input {
  flex: 1;
  height: 48px;
  padding: 0 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
}

.customer-add-form input:focus {
  border-color: var(--primary);
}

.customer-add-form .btn {
  height: 48px;
  padding: 0 20px;
  font-size: 15px;
}

.customer-list {
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.customer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.customer-item:last-child {
  border-bottom: none;
}

.customer-name {
  font-size: 16px;
  font-weight: 500;
}

.btn-delete-customer {
  background: var(--error-light);
  border: 1px solid #ffccc7;
  color: var(--error);
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.btn-delete-customer:active {
  background: #ffccc7;
}

/* ========== 响应式 ========== */
@media (min-width: 480px) {
  .scan-container, .home-main, .records-container, .customers-container {
    max-width: 480px;
    margin: 0 auto;
  }
}
