/* ===== 入厂登记 - 共用样式 ===== */
:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --primary: #0a4d8c;
  --primary-light: #1e88e5;
  --accent: #00bcd4;
  --success: #2e7d32;
  --danger: #c62828;
  --warn: #ef6c00;
  --text: #1a1a1a;
  --text-2: #5a6b7c;
  --border: #e3e8ef;
  --shadow: 0 2px 8px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
  --radius: 14px;
  --radius-sm: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }
a { color: var(--primary-light); text-decoration: none; }

/* ===== 前台 /scan ===== */
.scan-page { max-width: 480px; margin: 0 auto; padding: 16px; }
.scan-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 60%, var(--accent) 100%);
  color: #fff; border-radius: var(--radius);
  padding: 20px 16px 16px; box-shadow: var(--shadow); margin-bottom: 14px;
  text-align: center;
}
.scan-header h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.scan-header .sub { opacity: .85; font-size: 13px; }
.scan-header .company { font-size: 12px; opacity: .75; margin-top: 2px; }

.scan-form { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.field label .req { color: var(--danger); margin-left: 2px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); background: #fff; color: var(--text);
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary-light);
}
.field textarea { resize: vertical; min-height: 60px; }

/* 类型 chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border: 1.5px solid var(--border); border-radius: 999px;
  background: #fff; color: var(--text-2); font-size: 14px;
  transition: all .15s;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 单位 segmented */
.segmented { display: flex; background: #f0f3f7; border-radius: var(--radius-sm); padding: 3px; }
.segmented button {
  flex: 1; padding: 8px 0; border: none; background: transparent;
  border-radius: 6px; color: var(--text-2); font-size: 14px; font-weight: 500;
  transition: all .15s;
}
.segmented button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
#inMode button.active { background: var(--success); color: #fff; font-weight: 700; box-shadow: 0 2px 6px rgba(46,125,50,.4); }

/* 皮重切换 */
.tare-tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tare-tabs button {
  flex: 1; padding: 8px; border: 1.5px solid var(--border);
  background: #fff; color: var(--text-2); border-radius: var(--radius-sm); font-size: 13px;
}
.tare-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 照片 */
.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-add {
  width: 84px; height: 84px; border: 2px dashed var(--border); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; color: var(--text-2);
  font-size: 28px; cursor: pointer; background: #fafbfc;
}
.photo-add input { display: none; }
.photo-item {
  width: 84px; height: 84px; border-radius: var(--radius-sm); position: relative; overflow: hidden;
  background: #f0f3f7;
}
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item .rm {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px;
  background: rgba(0,0,0,.5); color: #fff; border-radius: 50%; border: none;
  display: flex; align-items: center; justify-content: center; font-size: 13px; line-height: 1;
}

/* 提交按钮 */
.submit-btn {
  width: 100%; padding: 14px; border: none; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff; font-size: 16px; font-weight: 600; box-shadow: var(--shadow);
  transition: transform .1s;
}
.submit-btn:active { transform: scale(0.99); }
.submit-btn:disabled { opacity: .55; }

/* 成功页 */
.success-page { padding: 30px 16px; text-align: center; }
.success-icon {
  width: 80px; height: 80px; margin: 0 auto 16px; border-radius: 50%;
  background: var(--success); color: #fff; font-size: 40px;
  display: flex; align-items: center; justify-content: center;
}
.success-page h2 { margin: 0 0 8px; color: var(--success); }
.success-page .meta { color: var(--text-2); font-size: 14px; margin-bottom: 24px; }
.success-page .meta b { color: var(--text); font-weight: 600; }
.success-page .actions { display: flex; flex-direction: column; gap: 10px; }
.success-page .actions button { padding: 12px; border-radius: var(--radius-sm); border: none; font-size: 15px; }
.success-page .actions .primary { background: var(--primary); color: #fff; }
.success-page .actions .secondary { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }

/* 提示 */
.hint { background: #fff8e1; border-left: 3px solid var(--warn); padding: 8px 12px; border-radius: 6px; font-size: 12px; color: #7a5a00; margin-top: 6px; }
.footer-note { text-align: center; color: var(--text-2); font-size: 12px; padding: 20px 0 8px; }

/* ===== 后台 /admin ===== */
.admin-wrap { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: linear-gradient(180deg, var(--primary), #0a3a6c);
  color: #fff; padding: 18px 0; flex-shrink: 0;
}
.sidebar .brand { padding: 0 18px 18px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 12px; }
.sidebar .brand .name { font-size: 17px; font-weight: 600; }
.sidebar .brand .role { font-size: 11px; opacity: .7; margin-top: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px; color: rgba(255,255,255,.85); font-size: 14px;
  cursor: pointer; transition: all .12s;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.13); color: #fff; border-left: 3px solid var(--accent); }
.nav-item .ico { font-size: 18px; width: 22px; text-align: center; }

.main { flex: 1; padding: 24px 32px; overflow-x: auto; }
.page-title { font-size: 22px; font-weight: 600; margin: 0 0 18px; color: var(--text); }
.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.user-info { font-size: 13px; color: var(--text-2); }
.user-info .logout { color: var(--danger); cursor: pointer; margin-left: 12px; }

/* 卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card .label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.card .value { font-size: 26px; font-weight: 700; color: var(--primary); }
.card .sub { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.card.success .value { color: var(--success); }
.card.accent  .value { color: var(--accent); }

/* 表格 */
.panel { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel-title { font-size: 15px; font-weight: 600; margin: 0 0 14px; display: flex; justify-content: space-between; align-items: center; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--border); }
th { background: #fafbfc; color: var(--text-2); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: #fafbfc; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: #e3f2fd; color: var(--primary); }
.tag.danger { background: #ffebee; color: var(--danger); }
.tag.ok { background: #e8f5e9; color: var(--success); }
.op { color: var(--primary-light); cursor: pointer; font-size: 13px; }
.op.danger { color: var(--danger); }
.op + .op { margin-left: 12px; }

/* 按钮 */
.btn { padding: 8px 14px; border: none; border-radius: var(--radius-sm); font-size: 14px; transition: all .12s; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.accent  { background: var(--accent); color: #fff; }
.btn.ghost   { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn.danger  { background: var(--danger); color: #fff; }
.btn.small   { padding: 5px 10px; font-size: 12px; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); padding: 22px;
  min-width: 380px; max-width: 560px; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal .field { margin-bottom: 12px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* 筛选条 */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filter-bar input, .filter-bar select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px;
}
.filter-bar input[type=date] { min-width: 130px; }

/* 登录页 */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary), var(--accent)); padding: 16px; }
.login-card { background: #fff; border-radius: var(--radius); padding: 30px; width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.18); }
.login-card h1 { margin: 0 0 6px; text-align: center; font-size: 22px; }
.login-card .sub { text-align: center; color: var(--text-2); font-size: 13px; margin-bottom: 24px; }
.login-card .field { margin-bottom: 14px; }
.login-card .field input { padding: 12px; }
.login-card .submit-btn { margin-top: 8px; }
.login-card .err { color: var(--danger); font-size: 13px; text-align: center; margin-top: 10px; min-height: 18px; }
.login-card .hint-bottom { text-align: center; font-size: 12px; color: var(--text-2); margin-top: 14px; }

/* toast */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 18px; background: rgba(0,0,0,.82); color: #fff;
  border-radius: 999px; font-size: 14px; z-index: 200; opacity: 0; transition: opacity .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== 分类看板 ===== */
.board-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.type-board {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column;
}
.tb-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; color: #fff;
}
.tb-icon { font-size: 22px; line-height: 1; }
.tb-name { font-size: 16px; font-weight: 600; }
.tb-body { padding: 6px 16px; }
.tb-row {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px dashed var(--border);
}
.tb-row:last-child { border-bottom: none; }
.tb-lab { font-size: 12px; color: var(--text-2); width: 40px; flex-shrink: 0; }
.tb-val { font-size: 13px; color: var(--text); flex: 1; text-align: right; padding-right: 12px; }
.tb-val b { font-size: 15px; }
.tb-kg { font-size: 13px; color: var(--text); min-width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.tb-foot { padding: 10px 16px 14px; }
.tb-bar { height: 6px; background: #f0f3f7; border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.tb-bar-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.tb-foot-txt { font-size: 11px; color: var(--text-2); }

/* 饼图/柱图 - canvas */
.chart-box { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.chart-box h3 { margin: 0 0 12px; font-size: 14px; color: var(--text-2); }
.chart-canvas-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.chart-canvas-wrap canvas { flex-shrink: 0; }
.legend { flex: 1; min-width: 180px; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

@media (max-width: 768px) {
  .admin-wrap { flex-direction: column; }
  .sidebar { width: 100%; padding: 8px 0; }
  .nav-item { padding: 10px 14px; font-size: 13px; }
  .nav-item .ico { display: none; }
  .sidebar .nav { display: flex; overflow-x: auto; }
  .sidebar .brand { display: none; }
  .main { padding: 14px; }
}

/* ===== 照片灯箱 ===== */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.88);
  display: none; align-items: center; justify-content: center; z-index: 300;
}
.lightbox.show { display: flex; }
.lightbox .lb-img { max-width: 92vw; max-height: 88vh; border-radius: 8px; object-fit: contain; }
.lightbox .lb-close {
  position: absolute; top: 16px; right: 22px; width: 40px; height: 40px;
  color: #fff; font-size: 30px; line-height: 40px; text-align: center; cursor: pointer;
  background: rgba(255,255,255,.12); border-radius: 50%; user-select: none;
}
.lightbox .lb-prev, .lightbox .lb-next {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; color: #fff; font-size: 30px; line-height: 44px; text-align: center;
  cursor: pointer; background: rgba(255,255,255,.12); border-radius: 50%; user-select: none;
}
.lightbox .lb-prev { left: 16px; }
.lightbox .lb-next { right: 16px; }
.lightbox .lb-count {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 14px; background: rgba(0,0,0,.4); padding: 4px 14px; border-radius: 999px;
}

/* ===== 出入厂：模式切换 + 在厂记录选择 ===== */
.mode-tabs { display: flex; gap: 10px; margin-bottom: 12px; }
.mode-tab {
  flex: 1; padding: 12px; border: none; border-radius: var(--radius-sm);
  background: #fff; color: var(--text-2); font-size: 15px; font-weight: 600; box-shadow: var(--shadow);
}
.mode-tab.active { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #fff; }

.rec-list { max-height: 260px; overflow-y: auto; }
.rec-item {
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer; background: #fff; transition: all .15s;
}
.rec-item.active { border-color: var(--primary); background: #e3f2fd; }
.rec-item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rec-item-top b { font-size: 14px; }
.rec-weight { color: var(--primary); font-weight: 600; font-size: 14px; white-space: nowrap; }
.rec-item-sub { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.rec-empty { color: #999; padding: 14px; text-align: center; font-size: 13px; background: #fafbfc; border-radius: var(--radius-sm); border: 1px dashed var(--border); }

.tag.warn { background: #fff8e1; color: var(--warn); }
