:root {
  --bg: #f4f6fb; --card: #fff; --text: #1a2233; --muted: #6b7489; --line: #e5e8f0;
  --primary: #1f5eff; --primary-weak: #e8efff; --ok: #12a150; --ok-weak: #e3f6eb;
  --warn: #d97706; --warn-weak: #fdf1df; --bad: #dc2626; --bad-weak: #fde8e8; --gray-weak: #eef0f4;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1420; --card: #182030; --text: #e8ecf5; --muted: #95a0b8; --line: #283246;
    --primary: #5b8cff; --primary-weak: #1d2b4d; --ok-weak: #123524; --warn-weak: #3a2a10; --bad-weak: #3a1616; --gray-weak: #232c3d; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* 布局 */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--card); border-bottom: 1px solid var(--line); }
.topbar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { font-size: 22px; line-height: 1; padding: 0 6px 0 0; color: var(--text); background: none; border: 0; cursor: pointer; }
.wrap { max-width: 920px; margin: 0 auto; padding: 14px 16px calc(90px + var(--safe-b)); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabbar a { flex: 1; padding: 8px 0 6px; text-align: center; font-size: 12px; color: var(--muted); }
.tabbar a .ic { display: block; font-size: 20px; line-height: 1.2; }
.tabbar a.on { color: var(--primary); font-weight: 600; }

/* 卡片 & 表单 */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card h3 .sp { flex: 1; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); font: inherit; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
textarea { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
.sp { flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 13px; font-size: 16px; }
.actions { position: sticky; bottom: calc(60px + var(--safe-b)); display: flex; gap: 10px; padding: 10px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.actions .btn { flex: 1; padding: 13px; font-size: 16px; }

/* 状态标签 */
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-draft { background: var(--gray-weak); color: var(--muted); }
.s-pushed { background: var(--primary-weak); color: var(--primary); }
.s-producing { background: var(--warn-weak); color: var(--warn); }
.s-ready { background: var(--ok-weak); color: var(--ok); }
.s-completed { background: var(--gray-weak); color: var(--ok); }
.s-cancelled { background: var(--bad-weak); color: var(--bad); }
.t-urgent { background: var(--bad); color: #fff; }
.t-ali { background: #ff6a00; color: #fff; }

/* 统计 */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; cursor: pointer; }
.stat b { display: block; font-size: 24px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }
.alert { padding: 10px 12px; border-radius: 10px; background: var(--warn-weak); color: var(--warn); font-size: 14px; margin-bottom: 12px; }
.alert.bad { background: var(--bad-weak); color: var(--bad); }

/* 订单列表 */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 14px; cursor: pointer; color: var(--text); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.order { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.order .cover { width: 64px; height: 64px; border-radius: 10px; flex: none; background: var(--gray-weak) center/cover no-repeat; display: grid; place-items: center; font-size: 24px; color: var(--muted); }
.order .info { flex: 1; min-width: 0; }
.order .t { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-weight: 600; }
.order .p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 50px 0; }

/* 产品明细 */
.item { display: grid; grid-template-columns: 76px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.item:last-child { border-bottom: 0; }
.imgpick { width: 76px; height: 76px; border-radius: 10px; border: 1.5px dashed var(--line); background: var(--gray-weak) center/cover no-repeat;
  display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; cursor: pointer; position: relative; overflow: hidden; }
.imgpick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.item .fields { display: grid; grid-template-columns: 1fr 90px 70px; gap: 6px; }
.item .fields .name { grid-column: 1 / -1; position: relative; }
.item .fields .rm { grid-column: 1 / -1; display: flex; gap: 6px; }
.suggest { position: absolute; left: 0; right: 0; top: 100%; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden; }
.suggest div { display: flex; gap: 8px; align-items: center; padding: 8px 10px; cursor: pointer; font-size: 14px; }
.suggest div:hover { background: var(--primary-weak); }
.suggest i { width: 32px; height: 32px; border-radius: 6px; background: var(--gray-weak) center/cover; flex: none; }

.vitem { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.vitem:last-child { border-bottom: 0; }
.vitem .img { width: 72px; height: 72px; border-radius: 10px; background: var(--gray-weak) center/cover no-repeat; flex: none; cursor: zoom-in; display: grid; place-items: center; color: var(--muted); }
.vitem .qty { font-size: 20px; font-weight: 700; color: var(--primary); white-space: nowrap; }

/* 附件 */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.file { position: relative; aspect-ratio: 1; border-radius: 10px; background: var(--gray-weak) center/cover no-repeat; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; font-size: 12px; padding: 6px; cursor: pointer; overflow: hidden; word-break: break-all; color: var(--text); }
.file .ext { font-size: 22px; font-weight: 800; color: var(--primary); }
.file .x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; border: 0; font-size: 13px; line-height: 22px; cursor: pointer; padding: 0; }
.upbtn { aspect-ratio: 1; border: 1.5px dashed var(--line); border-radius: 10px; display: grid; place-items: center; color: var(--muted); position: relative; text-align: center; font-size: 13px; cursor: pointer; }
.upbtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pending-list { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* 时间线 */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 12px 18px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; left: 7px; top: 16px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }

.steps { display: flex; margin: 4px 0 2px; }
.steps div { flex: 1; text-align: center; font-size: 12px; color: var(--muted); position: relative; padding-top: 18px; }
.steps div::before { content: ""; position: absolute; top: 4px; left: 50%; transform: translateX(-50%); width: 10px; height: 10px; border-radius: 50%; background: var(--line); z-index: 1; }
.steps div::after { content: ""; position: absolute; top: 8px; left: -50%; width: 100%; height: 2px; background: var(--line); }
.steps div:first-child::after { display: none; }
.steps div.on { color: var(--primary); font-weight: 600; }
.steps div.on::before, .steps div.on::after { background: var(--primary); }

.kv { display: grid; grid-template-columns: 88px 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.calc { background: var(--primary-weak); color: var(--primary); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }

/* 登录 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 22px; }
.login .logo { width: 64px; height: 64px; margin: 0 auto 10px; display: block; border-radius: 16px; }
.login h2 { text-align: center; margin: 0 0 20px; }

/* 弹层 */
#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 100; pointer-events: none; }
#toast div { background: rgba(20,24,35,.92); color: #fff; padding: 10px 16px; border-radius: 10px; margin-top: 6px; font-size: 14px; max-width: 86vw; animation: fade .2s; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.viewer { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 20px; }
.viewer img { max-height: 90vh; object-fit: contain; }
.modal-bg { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 90vh; overflow: auto; }
@media (min-width: 640px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t td, table.t th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.t th { color: var(--muted); font-weight: 500; font-size: 13px; }

@media (min-width: 900px) {
  .tabbar { top: 0; bottom: 0; right: auto; width: 84px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding-top: 14px; }
  .tabbar a { flex: none; padding: 14px 0; }
  body { padding-left: 84px; }
  .actions { bottom: 0; }
}
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, 1fr); } }
