:root {
  --ink: #1d1d1f;
  --ink2: #6e6e73;
  --ink3: #a1a1a6;
  --line: #e6e6e8;
  --soft: #f4f4f5;
  --bg: #ffffff;
  --accent: #1f2a44;
  --red: #d93025;
  --green: #1e7a46;
  --amber-bg: #fff6e5;
  --amber: #8a5300;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px; line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
input { font: inherit; }
.noselect, button, .card, .chip, .opt { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

#app { max-width: 520px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(var(--safe-b) + 120px); }

/* 顶栏 */
.top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin-bottom: 8px; }
.top h1 { font-size: 20px; font-weight: 700; margin: 0; }
.top .back { font-size: 17px; color: var(--accent); padding: 8px 12px 8px 0; }
.top .links { display: flex; gap: 4px; }
.top .links button { color: var(--ink2); font-size: 15px; padding: 8px 10px; border-radius: 8px; }
.top .links button:active { background: var(--soft); }
.meta { color: var(--ink2); font-size: 14px; text-align: right; }

/* 首页大按钮 */
.big2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 4px 0 14px; }
.bigbtn { height: 92px; border-radius: 18px; font-size: 26px; font-weight: 700; letter-spacing: 4px; }
.bigbtn.in { background: var(--accent); color: #fff; }
.bigbtn.out { background: var(--soft); color: var(--ink); border: 1.5px solid #d6d6da; }
.bigbtn:active { transform: scale(.98); opacity: .9; }

.factory-bar { display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: var(--amber-bg); color: var(--amber); border-radius: 14px; padding: 14px 16px; font-size: 17px; font-weight: 600; }
.factory-bar.empty { background: var(--soft); color: var(--ink2); font-weight: 400; }
.factory-bar .arrow { font-size: 20px; opacity: .6; }

.pool-head { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 10px; }
.pool-head h2 { font-size: 20px; margin: 0; }
.pool-head span { color: var(--ink2); font-size: 15px; }

.filters { display: flex; gap: 8px; align-items: center; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; min-width: 48px; height: 38px; padding: 0 12px; border-radius: 19px; background: var(--soft); font-size: 15px; font-weight: 600; }
.chip.on { background: var(--ink); color: #fff; }
.chip.icon { min-width: 42px; padding: 0; margin-left: auto; display: grid; place-items: center; }
.chip.icon svg { width: 18px; height: 18px; }
.search { width: 100%; height: 44px; margin-top: 10px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 14px; outline: none; font-size: 16px; }
.search:focus { border-color: var(--accent); }

.group { margin-top: 18px; }
.group-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; }
.group-title span { color: var(--ink2); font-weight: 400; font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card { border-radius: 14px; padding: 10px 10px 8px; aspect-ratio: 1 / .82; display: flex; flex-direction: column; justify-content: space-between; text-align: left; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.card:active { transform: scale(.97); }
.card .brand { font-size: 26px; font-weight: 800; letter-spacing: .5px; line-height: 1.1; }
.card .row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; gap: 4px; }
.card .row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .row b { font-size: 15px; white-space: nowrap; }
.card .row b.low { color: #fff; background: var(--red); padding: 0 6px; border-radius: 6px; }
.empty-note { color: var(--ink3); text-align: center; padding: 40px 0; }

/* 表单页 */
.sec { margin-top: 20px; }
.sec-title { font-size: 15px; color: var(--ink2); margin-bottom: 8px; display: flex; justify-content: space-between; }
.sec-title b { color: var(--ink); font-size: 17px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { min-height: 50px; padding: 0 16px; border-radius: 12px; background: var(--soft); font-size: 17px; font-weight: 600; border: 2px solid transparent; }
.opt.big { min-height: 64px; font-size: 20px; }
.opt.on { background: var(--ink); color: #fff; }
.opt.add { background: #fff; border: 2px dashed #cfcfd4; color: var(--ink2); font-size: 22px; font-weight: 400; min-width: 56px; }
.opt.dis { opacity: .35; }
.opt small { font-weight: 400; font-size: 13px; opacity: .7; margin-left: 4px; }

.swatch-btn { height: 58px; border-radius: 12px; font-size: 15px; font-weight: 600; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); position: relative; }
.swatch-btn .badge { position: absolute; top: -6px; right: -6px; background: var(--ink); color: #fff; font-size: 12px; min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; padding: 0 5px; box-shadow: 0 0 0 2px #fff; }
.hint { color: var(--ink3); font-size: 14px; padding: 6px 0; }

.lrow { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lrow .sw { width: 34px; height: 34px; border-radius: 9px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.lrow .txt { flex: 1; min-width: 0; }
.lrow .txt .t1 { font-weight: 600; }
.lrow .txt .t2 { color: var(--ink2); font-size: 13px; }
.stepper { display: flex; align-items: center; flex: none; }
.stepper button { width: 46px; height: 46px; border-radius: 12px; background: var(--soft); font-size: 26px; line-height: 1; font-weight: 500; }
.stepper button:active { background: #e3e3e6; }
.stepper button:disabled { opacity: .3; }
.stepper .n { width: 44px; text-align: center; font-size: 20px; font-weight: 700; }
.stepper .n.zero { color: var(--ink3); font-weight: 400; }

.summary { background: var(--soft); border-radius: 14px; padding: 12px 14px; }
.summary .srow { display: flex; justify-content: space-between; padding: 4px 0; }
.summary .total { border-top: 1px solid #dcdce0; margin-top: 6px; padding-top: 8px; font-weight: 700; }
.kg { width: 100%; height: 52px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 14px; font-size: 20px; outline: none; }
.kg:focus { border-color: var(--accent); }

.submit-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(var(--safe-b) + 10px); background: rgba(255,255,255,.94); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-top: 1px solid var(--line); }
.submit-bar button { display: block; width: 100%; max-width: 488px; margin: 0 auto; height: 60px; border-radius: 16px; background: var(--accent); color: #fff; font-size: 20px; font-weight: 700; }
.submit-bar button:disabled { background: #c9ccd3; }
.submit-bar .why { text-align: center; color: var(--ink2); font-size: 13px; margin-bottom: 6px; }

/* 加工厂 / 记录 */
.box { border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.box-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.box-head .t { font-size: 18px; font-weight: 700; }
.box-head .d { color: var(--ink2); font-size: 14px; white-space: nowrap; }
.box .sub { color: var(--ink2); font-size: 14px; margin: 2px 0 6px; }
.box .acts { display: flex; gap: 10px; margin-top: 12px; }
.box .acts button { flex: 1; height: 48px; border-radius: 12px; background: var(--soft); font-weight: 600; font-size: 16px; }
.box .acts button.pri { background: var(--accent); color: #fff; }
.tag { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 6px; margin-right: 6px; }
.tag.in { background: #e3f3e9; color: var(--green); }
.tag.out { background: #e8ecf5; color: var(--accent); }
.tag.return { background: var(--amber-bg); color: var(--amber); }
.tag.done { background: var(--soft); color: var(--ink2); }
.box.undone { opacity: .5; }
.box.undone .lines-mini { text-decoration: line-through; }
.undone-note { color: var(--red); font-size: 13px; margin-top: 6px; }
.lines-mini { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.lines-mini .lm { display: flex; align-items: center; gap: 5px; font-size: 14px; background: var(--soft); border-radius: 8px; padding: 3px 8px 3px 4px; }
.lines-mini .lm i { width: 16px; height: 16px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.undo-btn { color: var(--ink2); font-size: 14px; padding: 6px 10px; border-radius: 8px; background: var(--soft); }

.detail-hero { border-radius: 20px; padding: 18px; margin-bottom: 16px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.detail-hero .brand { font-size: 40px; font-weight: 800; }
.detail-hero .info { font-size: 16px; margin-top: 4px; }
.detail-hero .num { font-size: 32px; font-weight: 800; margin-top: 12px; }
.hist { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.hist .l { min-width: 0; }
.hist .l .s { color: var(--ink2); font-size: 13px; }
.hist .r { font-size: 18px; font-weight: 700; white-space: nowrap; }
.hist.undone { opacity: .45; text-decoration: line-through; }

/* 设置 */
.set-sec { margin-top: 22px; }
.set-sec h3 { font-size: 16px; margin: 0 0 8px; }
.set-sec .tip { color: var(--ink3); font-size: 13px; margin-top: 6px; }
.wide-btn { width: 100%; height: 52px; border-radius: 14px; background: var(--soft); font-size: 17px; font-weight: 600; margin-top: 8px; }

/* 登录 */
.login { padding-top: 12vh; text-align: center; }
.login h1 { font-size: 28px; margin: 0 0 6px; }
.login p { color: var(--ink2); margin: 0 0 28px; }
.login input { width: 100%; height: 56px; border: 1.5px solid var(--line); border-radius: 14px; text-align: center; font-size: 22px; letter-spacing: 4px; outline: none; }
.login input:focus { border-color: var(--accent); }
.login .go { width: 100%; height: 56px; border-radius: 14px; background: var(--accent); color: #fff; font-size: 19px; font-weight: 700; margin-top: 14px; }
.login .who { display: grid; gap: 12px; }
.login .who button { height: 72px; border-radius: 16px; background: var(--soft); font-size: 22px; font-weight: 700; }
.err { color: var(--red); margin-top: 12px; min-height: 22px; }

/* 底部弹层 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 18px 16px calc(var(--safe-b) + 16px); max-height: 88vh; overflow-y: auto; animation: up .2s ease-out; }
.sheet h3 { margin: 0 0 14px; font-size: 19px; }
.sheet p { color: var(--ink2); margin: 0 0 14px; }
.sheet .field { width: 100%; height: 52px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 14px; font-size: 18px; outline: none; margin-bottom: 12px; }
.sheet .field:focus { border-color: var(--accent); }
.sheet .btns { display: grid; gap: 10px; margin-top: 8px; }
.sheet .btns.two { grid-template-columns: 1fr 1fr; }
.sheet .btns button { height: 52px; border-radius: 14px; background: var(--soft); font-size: 17px; font-weight: 600; }
.sheet .btns button.pri { background: var(--accent); color: #fff; }
.sheet .btns button.danger { color: var(--red); }
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; margin-bottom: 14px; }
.palette button { aspect-ratio: 1; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.palette button.on { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--ink); }
.preview { height: 56px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; margin-bottom: 12px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

#toast { position: fixed; left: 50%; top: calc(var(--safe-t) + 20px); transform: translate(-50%, -20px); background: rgba(29,29,31,.92); color: #fff; padding: 12px 20px; border-radius: 14px; font-size: 16px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--red); }
.loading { color: var(--ink3); text-align: center; padding: 60px 0; }
