/* ═══ 基础重置 ═══ */
* { margin:0; padding:0; box-sizing:border-box; }
html { font-size:15px; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #e6f2ff;
  color: #1a1a1a;
  min-height: 100vh;
}
input, select, button, textarea {
  font-family: inherit;
  font-size: 0.93rem;
}
a { color: #1677ff; text-decoration: none; }

/* ═══ 页面切换 ═══ */
.page { display: none; }
.page.active { display: block; }
.view-content { display: none; }
.view-content.active { display: block; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ═══ 登录/注册 ═══ */
.auth-container {
  max-width: 400px;
  margin: 80px auto;
  padding: 32px 28px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.auth-container h1 {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 24px;
}
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #d9d9d9;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: #fafafa;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
}
.tab-btn.active {
  background: #1677ff;
  color: #fff;
}
.auth-container h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}
.auth-container input,
.auth-container select {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
}
.auth-container input:focus,
.auth-container select:focus {
  border-color: #1677ff;
}
.captcha-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.captcha-row input { flex: 1; margin-bottom: 0; }
.captcha-row span { font-weight: 600; color: #e04040; font-size: 1.1rem; }
.captcha-row button { background: none; border: none; cursor: pointer; font-size: 1.2rem; }
.hint { color: #888; font-size: 0.85rem; margin-bottom: 12px; }
.footer-hint { text-align: center; color: #aaa; font-size: 0.8rem; margin-top: 20px; }

/* ═══ 按钮 ═══ */
.btn-primary {
  background: #1677ff;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.2s;
}
.btn-primary:hover { background: #0958d9; }
.btn-primary:disabled { background: #bbb; cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-sm {
  background: #f0f0f0;
  color: #333;
  border: 1px solid #d9d9d9;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-sm:hover { background: #e0e0e0; }
.btn-danger {
  background: #ff4d4f;
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-success {
  background: #52c41a;
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-photo {
  background: #1890ff;
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
}
.btn-photo:hover { background: #096dd9; }
.btn-danger:hover { background: #d9363e; }

.ai-count-result {
  grid-column: 1 / -1;
  background: #e6f7ff;
  border: 1px solid #91d5ff;
  border-radius: 6px;
  padding: 6px 10px;
  margin-top: 6px;
  font-size: 0.95rem;
  color: #096dd9;
}
.ai-count-result strong { font-size: 1.1rem; }
.ai-count-result small { color: #999; font-size: 0.75rem; }

/* ═══ 消息 ═══ */
.msg {
  padding: 8px 12px;
  border-radius: 6px;
  margin-top: 8px;
  font-size: 0.9rem;
  display: none;
}
.msg.error { display: block; background: #fff2f0; color: #ff4d4f; border: 1px solid #ffccc7; }
.msg.success { display: block; background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.msg.warning { display: block; background: #fffbe6; color: #faad14; border: 1px solid #ffe58f; }

/* ═══ Toast ═══ */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 9999;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show { display: block; animation: fadeInOut 3s ease; }
.toast.error { background: #fff2f0; color: #ff4d4f; border: 1px solid #ffccc7; }
.toast.success { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.toast.warning { background: #fffbe6; color: #faad14; border: 1px solid #ffe58f; }
.toast.info { background: #e6f7ff; color: #1677ff; border: 1px solid #91caff; }

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  10% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ═══ Header ═══ */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 1.3rem; }
.header-title { font-size: 1rem; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 10px; }
.status-dot { font-size: 0.7rem; }
.status-dot.online { color: #52c41a; }
.status-dot.offline { color: #ff4d4f; }
.user-badge {
  background: #f0f5ff;
  color: #1677ff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.82rem;
}

/* ═══ 视图切换栏 ═══ */
.view-tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
}
.view-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.93rem;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}
.view-btn.active {
  color: #1677ff;
  border-bottom-color: #1677ff;
  font-weight: 600;
}

/* ═══ 工具栏 ═══ */
.toolbar {
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
}
.toolbar-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.toolbar-row:last-child { margin-bottom: 0; }
.toolbar select, .toolbar input[type="date"], .toolbar input[type="text"] {
  padding: 7px 10px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  outline: none;
}
.toolbar select:focus, .toolbar input:focus {
  border-color: #1677ff;
}
#slot-search { flex: 1; min-width: 180px; }
.stats-bar {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  color: #555;
  flex-wrap: wrap;
}
.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stat-num { font-weight: 700; color: #1677ff; }

/* ═══ 批量签认栏 ═══ */
.batch-bar {
  padding: 8px 16px;
  background: #fff7e6;
  border-bottom: 1px solid #ffd591;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ═══ 卡片网格 ═══ */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: 80px;
  overflow: auto;
  max-height: calc(100vh - 200px);
}
.slot-card {
  background: #fff;
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border: 1px solid #f0f0f0;
  transition: box-shadow 0.2s;
}
.slot-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.slot-card.loaded { border-left: 3px solid #52c41a; }
.slot-card.empty { opacity: 0.6; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.card-pos {
  font-weight: 700;
  font-size: 1.05rem;
  color: #1677ff;
}
.card-signoff-badge {
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 10px;
}
.badge-signed { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.badge-pending { background: #fff7e6; color: #faad14; border: 1px solid #ffd591; }
.badge-unsigned { background: #f5f5f5; color: #999; border: 1px solid #e0e0e0; }

.card-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 0.88rem;
}
.card-label { color: #888; white-space: nowrap; }
.card-value { font-weight: 500; word-break: break-all; }
.card-value.warn { color: #ff4d4f; }

.card-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.card-actions .btn-sm { font-size: 0.82rem; padding: 5px 10px; }

/* ═══ 底部操作栏 ═══ */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  padding: 10px 16px;
  border-top: 1px solid #e8e8e8;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
}
#slot-changes-count, #ledger-changes-count {
  font-size: 0.85rem;
  color: #faad14;
}

/* ═══ 对照表 ═══ */
.line-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.line-btn {
  padding: 7px 16px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 0.88rem;
  transition: all 0.2s;
}
.line-btn.active {
  background: #1677ff;
  color: #fff;
  border-color: #1677ff;
}
.filter-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 5px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  font-size: 0.82rem;
}
.filter-btn.active {
  background: #e6f7ff;
  color: #1677ff;
  border-color: #91caff;
}

/* ═══ 导入区域 ═══ */
.import-area {
  padding: 16px;
  background: #fafafa;
  border: 1px dashed #d9d9d9;
  border-radius: 8px;
  margin: 12px 16px;
}
.import-area h3 { margin-bottom: 12px; font-size: 1rem; }
.import-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.import-row label { font-size: 0.88rem; color: #555; }
.import-row input[type="file"] { font-size: 0.85rem; }

/* ═══ 数据表格 ═══ */
.table-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  margin: 8px 12px;
  padding-bottom: 8px;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e8e8e8;
  max-height: calc(100vh - 260px);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  white-space: nowrap;
}
.data-table thead {
  background: #fafafa;
  position: sticky;
  top: 0;
  z-index: 10;
}
.data-table th {
  padding: 4px 6px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid #d0d0d0;
  color: #555;
  font-size: 0.75rem;
}
.data-table td {
  padding: 3px 6px;
  border: 1px solid #e0e0e0;
}
.data-table tr:hover { background: #f5f9ff; }
.data-table td.editable {
  cursor: text;
  min-width: 50px;
}
.data-table td.editable:focus {
  outline: 2px solid #1677ff;
  outline-offset: -1px;
  background: #e6f7ff;
}
.data-table td.readonly { color: #999; background: #fafafa; }
#ledger-table { min-width: auto; table-layout: auto; width: auto; }
#ledger-table th, #ledger-table td {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
#ledger-table th:nth-child(2), #ledger-table td:nth-child(2) { max-width: 160px; } /* 品名 */
.data-table td.loaded { background: #f6ffed; }
.data-table td.changed { background: #fff7e6; }

/* ═══ 侧边栏 ═══ */
.sidebar {
  position: fixed;
  top: 0;
  right: -320px;
  width: 300px;
  height: 100vh;
  background: #fff;
  box-shadow: -2px 0 12px rgba(0,0,0,0.1);
  z-index: 200;
  transition: right 0.3s ease;
  overflow-y: auto;
}
.sidebar.open { right: 0; }
.sidebar-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: #999;
}
.sidebar-content { padding: 20px; }
.sidebar-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f0f0f0;
}
.sidebar-section h3 {
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: #333;
}
.sidebar-section p {
  font-size: 0.88rem;
  color: #555;
  line-height: 1.6;
}
.sidebar-toggle {
  position: fixed;
  bottom: 70px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #1677ff;
  color: #fff;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(22,119,255,0.3);
  z-index: 150;
}

/* 审批卡片 */
.pending-card {
  background: #fafafa;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.pending-card .name { font-weight: 600; }
.pending-card .info { font-size: 0.82rem; color: #888; margin: 4px 0; }
.pending-card .actions { display: flex; gap: 6px; margin-top: 6px; }

/* 设备卡片 */
.device-card {
  background: #fafafa;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

/* ═══ 弹窗 ═══ */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.modal-content.modal-lg { max-width: 600px; max-height: 85vh; overflow-y: auto; }
.modal-content h3 { margin-bottom: 16px; }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}
.modal-content input,
.modal-content select {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 10px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  outline: none;
}
.modal-content input:focus { border-color: #1677ff; }
.edit-field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.edit-field-row label {
  min-width: 80px;
  font-size: 0.88rem;
  color: #555;
}
.edit-field-row input { flex: 1; margin-bottom: 0; min-width: 0; }
.edit-field-row input[type="datetime-local"] { font-size: 0.82rem; padding: 6px 4px; }

/* ═══ 计数器模式 ═══ */
.counter-row { gap: 4px; }
.btn-counter {
  width: 40px; height: 40px; border: none; border-radius: 8px;
  font-size: 1.3rem; font-weight: bold; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.btn-counter-plus { background: #52c41a; color: #fff; }
.btn-counter-plus:active { background: #389e0d; }
.btn-counter-minus { background: #ff4d4f; color: #fff; }
.btn-counter-minus:active { background: #cf1322; }
.counter-row input { text-align: center; font-size: 1.1rem; }

/* ═══ 预填充高亮 ═══ */
input.prefilled {
  background: #f6ffed !important;
  border-color: #b7eb8f !important;
}

/* ═══ 语音输入按钮 ═══ */
.btn-voice {
  width: 34px; height: 34px; border: 1px solid #d9d9d9;
  border-radius: 8px; background: #fff; cursor: pointer;
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-voice:active { background: #e6f7ff; border-color: #1677ff; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ═══ 常用模板栏 ═══ */
.edit-tpl-bar {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px; margin-bottom: 12px; padding: 8px;
  background: #fafafa; border-radius: 8px; border: 1px solid #eee;
}
.tpl-label { font-size: 0.85rem; color: #666; }
.btn-tpl {
  padding: 4px 12px; border: 1px solid #d9d9d9; border-radius: 6px;
  background: #fff; font-size: 0.82rem; cursor: pointer;
  transition: all 0.15s;
}
.btn-tpl:hover { border-color: #1677ff; color: #1677ff; }
.btn-tpl-save { border-color: #faad14; color: #faad14; }
.btn-tpl-save:hover { background: #fffbe6; }

/* ═══ 点袋弹窗 ═══ */
.modal-full {
  max-width: 95vw !important;
  max-height: 90vh;
  width: 95vw;
  height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  overflow: hidden;
}
.modal-diandai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #1a1a1a;
  color: #e0e0e0;
  font-weight: 600;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.modal-diandai-header button {
  background: #333;
  color: #ccc;
  border: 1px solid #555;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
#diandai-iframe { min-height: 0; }

/* ═══ 响应式 ═══ */
@media (max-width: 768px) {
  .card-grid { grid-template-columns: 1fr; }
  .auth-container { margin: 40px 16px; }
  .data-table { font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 5px 6px; }
  .toolbar-row { gap: 6px; }
}

/* ═══ 加载动画 ═══ */
.loading {
  text-align: center;
  padding: 40px;
  color: #999;
}
.loading::after {
  content: "";
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #d9d9d9;
  border-top-color: #1677ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ 签认时间显示 ═══ */
.signoff-time {
  font-size: 0.78rem;
  color: #888;
  margin-top: 2px;
}

/* ═══ 历史记录 ═══ */
.btn-history {
  background: #f0f0f0;
  color: #555;
  font-size: 0.8rem;
}
.btn-history:hover {
  background: #e0e0e0;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.history-table th,
.history-table td {
  border: 1px solid #d0d0d0;
  padding: 4px 8px;
  white-space: nowrap;
}
.history-table th {
  background: #f5f5f5;
  font-weight: 600;
  position: sticky;
  top: 0;
}
.history-current {
  background: #e6f7ff;
  font-weight: 600;
}

/* ═══ 仓储费 ═══ */
.storage-summary {
  padding: 12px 16px;
  background: #fff7e6;
  border: 1px solid #ffd591;
  border-radius: 8px;
  margin-top: 8px;
}
.storage-summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.95rem;
}
.storage-summary-row span {
  white-space: nowrap;
}
#storage-table th,
#storage-table td {
  text-align: center;
}
#storage-table td:nth-child(3),
#storage-table td:nth-child(5),
#storage-table td:nth-child(6) {
  text-align: right;
}
