* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  font-size: 14px;
  color: #222;
  background: #f5f6f8;
}

header {
  background: #2c3e50;
  color: #fff;
  padding: 10px 20px;
}

header h1 {
  margin: 0 0 8px;
  font-size: 20px;
}

nav button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #dfe6ee;
  padding: 6px 16px;
  margin-right: 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

nav button.active {
  background: #fff;
  color: #2c3e50;
  font-weight: bold;
}

main {
  padding: 16px 20px 40px;
  max-width: 1280px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

.panel {
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}

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

.toolbar .spacer { flex: 1; }

button.btn {
  background: #2c6fbb;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 14px;
}

button.btn:hover { background: #245e9e; }
button.btn.secondary { background: #6b7a8d; }
button.btn.secondary:hover { background: #59687a; }
button.btn.danger { background: #c0392b; }
button.btn.danger:hover { background: #a93226; }
button.btn:disabled { background: #b9c0c7; cursor: not-allowed; }

button.link {
  background: none;
  border: none;
  color: #2c6fbb;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 13px;
}

button.link.danger { color: #c0392b; }

input[type="text"], input[type="number"], input[type="date"], input[type="time"], select {
  border: 1px solid #c9d0d8;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 14px;
  background: #fff;
}

input[type="number"] { width: 90px; text-align: right; }
input[type="time"] { width: 96px; }

table {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
}

th, td {
  border: 1px solid #e1e4e8;
  padding: 6px 8px;
  text-align: center;
}

th { background: #eef1f5; font-weight: bold; }
td.left { text-align: left; }
th.left { text-align: left; }

.muted { color: #888; font-size: 13px; }
.right { text-align: right; }

.empty-state {
  text-align: center;
  padding: 40px 0;
  color: #666;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.form-grid label {
  display: block;
  font-size: 13px;
  color: #555;
  margin-bottom: 4px;
}

.form-grid input, .form-grid select { width: 100%; }

.msg-ok { color: #2e7d32; }
.msg-err { color: #b3261e; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  background: #e8f0e9;
  color: #2e7d32;
}
.badge.inactive { background: #eee; color: #777; }

/* 表格内的快速溯源链接 */
a.trace-link {
  color: #2c6fbb;
  cursor: pointer;
  text-decoration: none;
}
a.trace-link:hover { text-decoration: underline; }

/* 货物明细子表 */
table.cargo td, table.cargo th { padding: 4px 6px; }
table.cargo input[type="text"] { width: 100%; }
table.cargo input.c-qty { width: 80px; text-align: right; }

tr.total td { background: #fff8e1; font-weight: bold; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
}

.filter-bar label { font-size: 13px; color: #555; }

footer {
  text-align: center;
  padding: 12px;
}

h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }

@media print {
  header, footer, .toolbar, .filter-bar { display: none; }
  main { padding: 0; }
  .panel { border: none; }
}

/* 服务器版：登录与用户 */
.login-overlay {
  position: fixed;
  inset: 0;
  background: #f5f6f8;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box { width: 320px; }
.login-label { display: block; font-size: 13px; color: #555; margin: 10px 0 4px; }
.login-box input { width: 100%; }

header { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
header h1 { margin: 0; }
header nav { width: 100%; }
#user-box { color: #dfe6ee; font-size: 13px; margin-left: auto; }
#user-box .link { color: #ffd699; }

/* operator 角色隐藏管理入口（服务端仍强制 403 拦截） */
body[data-role="operator"] .admin-only { display: none !important; }

/* 超时预警：运输时长 ≥ 6 小时（基地→仓库目标 < 6 小时） */
tr.warn td { background: #fdecea; }
.badge-warn {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 12px;
  background: #f5c6cb;
  color: #b3261e;
  margin-left: 4px;
}

/* 发车/到货照片 */
.photo-slots { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.photo-slot {
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 150px;
  background: #fff;
}
.photo-slot-title { font-size: 13px; color: #555; margin-bottom: 6px; }
.photo-preview { min-height: 48px; margin-bottom: 6px; display: flex; align-items: center; }
.photo-slot-actions { display: flex; align-items: center; gap: 6px; }
.photo-cell { line-height: 1.6; white-space: nowrap; }
.thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #e1e4e8;
  vertical-align: middle;
}

/* ---------- 手机端适配（≤860px） ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 860px) {
  header { padding: 8px 10px; }
  header h1 { font-size: 17px; }
  #user-box { font-size: 12px; margin-left: 0; }
  nav { display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  nav button { flex: 0 0 auto; padding: 6px 12px; font-size: 13px; margin: 6px 6px 0 0; }

  main { padding: 10px 8px 30px; }
  .panel { padding: 10px; margin-bottom: 10px; }
  .toolbar { gap: 6px; }
  .toolbar .btn { flex: 1 1 40%; padding: 9px 4px; font-size: 13px; }

  .filter-bar { align-items: stretch; gap: 6px; }
  .filter-bar label { margin-top: 2px; }
  .filter-bar input, .filter-bar select { flex: 1 1 100%; width: 100%; }

  /* 运输记录列表卡片化：每趟车一张卡片，字段纵向排列 */
  table.rec-table, table.rec-table tbody, table.rec-table tr, table.rec-table td { display: block; width: 100%; }
  table.rec-table thead { display: none; }
  table.rec-table tr { border: 1px solid #e1e4e8; border-radius: 6px; margin-bottom: 10px; background: #fff; overflow: hidden; }
  table.rec-table tr.warn { background: #fdecea; }
  table.rec-table tr.warn td { background: transparent; }
  table.rec-table td { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: none; border-bottom: 1px solid #f0f2f5; text-align: right; padding: 7px 10px; }
  table.rec-table td.left { text-align: right; }
  table.rec-table td::before { content: attr(data-label); flex: 0 0 auto; font-weight: bold; color: #555; font-size: 12px; text-align: left; }
  table.rec-table td[data-label="货物明细"], table.rec-table td[data-label="备注"] { align-items: flex-start; }
  .photo-cell { display: flex; align-items: center; gap: 6px; }
  .photo-cell br { display: none; }
}

@media (max-width: 420px) {
  .toolbar .btn { flex: 1 1 100%; }
  header h1 { font-size: 16px; }
}
