:root {
  --bg: #f6f5f2; --card: #ffffff; --soft: #efede8; --text: #1d1c1a; --sub: #63625e; --muted: #96948e;
  --line: #e2e0d9; --line2: #cfccc3; --accent: #1f6f5c; --accent-h: #185a4a; --on-accent: #ffffff;
  --accent-bg: #e1f1ea; --accent-text: #175445; --danger: #b3261e; --danger-bg: #fbe9e7; --flash: #fff1b8;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514; --card: #1f1f1d; --soft: #292927; --text: #ecebe7; --sub: #aeaca6; --muted: #7b7973;
    --line: #32312e; --line2: #46443f; --accent: #58bfa2; --accent-h: #6fd0b4; --on-accent: #0c2a22;
    --accent-bg: #1c3a31; --accent-text: #8fdcc5; --danger: #f2877f; --danger-bg: #3d1f1c; --flash: #5a4a12;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; text-align: inherit; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
.boot { padding: 80px 20px; text-align: center; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line2); border-radius: var(--r); background: var(--card); white-space: nowrap; font-weight: 500;
}
.btn:hover { background: var(--soft); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn.danger { color: var(--danger); border-color: transparent; background: none; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; font-weight: 400; color: var(--sub); border-color: var(--line); background: none; }
.btn.sm:hover { background: var(--soft); color: var(--text); }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=search], input[type=password], input[type=number], select {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line2); border-radius: var(--r);
  background: var(--card); font-size: 16px; -webkit-appearance: none; appearance: none; min-width: 0;
}
select { padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 18px, calc(100% - 10px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
input::-webkit-search-cancel-button { display: none; }

/* 顶栏 */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right));
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-size: 17px; font-weight: 600; white-space: nowrap; }
.search { position: relative; flex: 1; min-width: 0; max-width: 620px; }
.search input { padding-left: 38px; padding-right: 38px; border-radius: 21px; }
.search svg { position: absolute; left: 13px; top: 12px; width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.search .clear { position: absolute; right: 4px; top: 4px; width: 34px; height: 34px; border-radius: 50%; text-align: center; color: var(--muted); font-size: 20px; line-height: 1; }
.search .clear:hover { background: var(--soft); }
.top .spacer { flex: 1; }
.offline { background: var(--danger-bg); color: var(--danger); text-align: center; font-size: 13px; padding: 6px 12px; }

/* 布局 */
.body { display: grid; grid-template-columns: 210px minmax(0, 1fr); align-items: start; max-width: 1280px; }
#side { position: sticky; top: 63px; padding: 14px 10px 14px 16px; max-height: calc(100vh - 63px); overflow-y: auto; }
#main { padding: 16px 20px 80px; min-width: 0; }
.zone { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; padding: 9px 12px; border-radius: var(--r); color: var(--sub); }
.zone:hover { background: var(--soft); }
.zone.on { background: var(--accent-bg); color: var(--accent-text); font-weight: 600; }
.zone .n { font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.zone.on .n { color: var(--accent-text); }
.zone .zn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zone.add { color: var(--muted); }

.head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.head h1 { font-size: 20px; font-weight: 600; }
.head .meta { color: var(--muted); font-size: 13px; }
.racks { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.rack { padding: 7px 14px; border: 1px solid var(--line2); border-radius: 20px; background: var(--card); color: var(--sub); white-space: nowrap; }
.rack small { color: var(--muted); font-size: 12px; margin-left: 4px; }
.rack:hover { border-color: var(--accent); }
.rack.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.rack.on small { color: inherit; opacity: 0.85; }
.rack.add { border-style: dashed; color: var(--muted); background: none; }

.shelf { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.shelfh { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 2px solid var(--line2); }
.shelfh h2 { font-size: 16px; font-weight: 600; }
.shelfh .meta { color: var(--muted); font-size: 13px; }
.lv { padding: 10px 16px 14px; border-bottom: 2px solid var(--line2); }
.lv:last-child { border-bottom: 0; }
.lvh { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; min-height: 32px; }
.lvn { font-size: 13px; font-weight: 600; color: var(--sub); margin-right: auto; }
.lvn small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.it { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; min-height: 36px; padding: 4px 6px 4px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); }
.it:hover { border-color: var(--accent); }
.itn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.itq { min-width: 26px; padding: 1px 7px; border-radius: 7px; background: var(--soft); color: var(--sub); font-size: 13px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.it.zero .itq { background: var(--danger-bg); color: var(--danger); }
.it.flash, .res.flash { background: var(--flash); border-color: var(--accent); }
.box { border: 1.5px dashed var(--line2); border-radius: 12px; padding: 6px 8px 8px; max-width: 100%; }
.boxh { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.boxn { font-size: 13px; color: var(--sub); font-weight: 600; padding: 4px 6px; border-radius: 6px; }
.boxn:hover { background: var(--soft); }
.boxadd { width: 30px; height: 30px; border-radius: 6px; text-align: center; color: var(--muted); font-size: 18px; line-height: 1; }
.boxadd:hover { background: var(--soft); color: var(--text); }
.none { color: var(--muted); font-size: 13px; }

.blank { text-align: center; padding: 56px 20px; color: var(--sub); }
.blank h2 { font-size: 18px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.blank p { margin-bottom: 16px; }

/* 搜索结果 */
.count { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.res { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.res:last-child { border-bottom: 0; }
.resm { flex: 1; min-width: 0; }
.resn { font-size: 16px; font-weight: 600; display: block; max-width: 100%; overflow-wrap: anywhere; }
.resn:hover { color: var(--accent); }
.loc { display: inline-block; margin-top: 2px; color: var(--accent); font-size: 14px; overflow-wrap: anywhere; }
.loc:hover { text-decoration: underline; }
.note { color: var(--sub); font-size: 13px; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.tag { font-size: 12px; padding: 2px 9px; border-radius: 10px; background: var(--accent-bg); color: var(--accent-text); }
.tag.off { background: var(--soft); color: var(--sub); }
.qty { display: flex; align-items: center; gap: 4px; flex: none; }
.qty b { min-width: 44px; text-align: center; font-size: 16px; font-variant-numeric: tabular-nums; }
.stepb { width: 40px; height: 40px; border: 1px solid var(--line2); border-radius: 50%; text-align: center; font-size: 20px; line-height: 1; background: var(--card); }
.stepb:hover { background: var(--soft); }
.stepb:active { transform: scale(0.94); }

/* 弹窗 */
#modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.45); overflow-y: auto; }
.dlg { width: 100%; max-width: 460px; max-height: 100%; overflow-y: auto; background: var(--card); border-radius: 16px; padding: 20px; margin: auto; }
.dlg h2 { font-size: 18px; font-weight: 600; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.dlg .x { width: 34px; height: 34px; border-radius: 50%; text-align: center; font-size: 22px; line-height: 1; color: var(--muted); font-weight: 400; }
.dlg .x:hover { background: var(--soft); }
.f { display: block; margin-bottom: 12px; }
.f > span { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stepper { display: flex; gap: 8px; align-items: center; }
.stepper input { text-align: center; font-weight: 600; }
.stepper .stepb { flex: none; width: 42px; height: 42px; }
.acts { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.acts .gap { flex: 1; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 0; }
.kv { display: grid; grid-template-columns: 64px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.menu button, .menu a { display: flex; width: 100%; align-items: center; min-height: 46px; padding: 0 12px; border-radius: var(--r); color: inherit; text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--soft); }
.menu .who { padding: 0 12px 12px; color: var(--sub); font-size: 13px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.urow { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.urow .un { flex: 1; min-width: 80px; font-weight: 600; overflow-wrap: anywhere; }
.urow select { width: 110px; height: 36px; font-size: 14px; }
.sub { font-size: 13px; color: var(--sub); margin: 16px 0 8px; font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; max-width: 90vw; padding: 10px 16px; border-radius: 22px; background: var(--text); color: var(--bg); font-size: 14px; text-align: center; }

/* 登录 */
.login { max-width: 360px; margin: 0 auto; padding: 14vh 20px 40px; }
.login h1 { font-size: 26px; font-weight: 600; margin-bottom: 4px; }
.login p { color: var(--sub); margin-bottom: 22px; }
.login .btn { width: 100%; height: 46px; margin-top: 6px; }

@media (max-width: 760px) {
  .brand, .top .spacer { display: none; }
  .top .btn.primary span { display: none; }
  .top .btn { padding: 0 12px; }
  .body { display: block; }
  #side { position: static; display: flex; gap: 6px; overflow-x: auto; max-height: none; padding: 10px 12px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #side::-webkit-scrollbar { display: none; }
  .zone { width: auto; flex: none; border: 1px solid var(--line); padding: 6px 12px; border-radius: 18px; background: var(--card); }
  .zone.on { border-color: transparent; }
  #main { padding: 6px 12px 90px; }
  .lv, .shelfh, .res { padding-left: 12px; padding-right: 12px; }
  .it { min-height: 40px; }
  #modal { align-items: flex-end; padding: 0; }
  .dlg { max-width: none; border-radius: 18px 18px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; }
}
