:root {
  --bg: #F4F3EF;
  --card: #FFFFFF;
  --ink: #1E2320;
  --muted: #5E6660;
  --line: #E2DFD7;
  --line2: #EEECE6;
  --border: #D4D1C8;
  --primary: #2F3B33;
  --chip-on-bg: #F3E6CC;
  --chip-on-ink: #6B4410;
  --green-bg: #E3EFE6;
  --green-ink: #2F6B45;
  --red-bg: #F6E1DA;
  --red-ink: #8C2E1A;
  --photo: #DCD3C2;
  --nav-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Hiragino Sans GB", sans-serif;
  font-size: 15px; line-height: 1.45;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: #8A5A12; }
#app { max-width: 520px; margin: 0 auto; min-height: 100vh; position: relative; }

/* 页面骨架 */
.page { padding: 0 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.page.has-bar { padding-bottom: calc(var(--nav-h) + 96px + env(safe-area-inset-bottom)); }
.head { padding: 20px 4px 12px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.head .sub { font-size: 13px; color: var(--muted); }
.head h1 { margin: 2px 0 0; font-size: 24px; font-weight: 700; line-height: 1.25; }
.back { display: inline-flex; align-items: center; gap: 4px; height: 44px; padding: 0 4px; margin: 4px 0 -8px -4px; color: var(--muted); background: none; border: none; font-size: 15px; cursor: pointer; }
.card { background: var(--card); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 10px; font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }

/* 按钮 */
.btn { height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--primary); background: var(--card); color: var(--primary); font-size: 15px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.danger { border-color: var(--red-ink); color: var(--red-ink); }
.btn.ghost { border-color: var(--border); color: var(--ink); }
.btn.sm { height: 36px; padding: 0 12px; border-radius: 8px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btns { display: flex; gap: 8px; }
.btns > .btn { flex: 1; }

/* 筛选小圆块 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--border); background: var(--card); color: var(--ink); font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.chip.on { background: var(--chip-on-bg); color: var(--chip-on-ink); border-color: var(--chip-on-bg); font-weight: 600; }
.chip .n { font-size: 12px; opacity: .7; }
.seg { display: flex; gap: 8px; }
.seg > button { flex: 1; height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); font-size: 15px; cursor: pointer; }
.seg > button.on { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.scroll-x { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.scroll-x > * { flex-shrink: 0; }

/* 表单 */
.field { margin-bottom: 14px; }
.field > label, .field > .lab { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input { width: 100%; height: 48px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: #fff; font-size: 16px; outline: none; }
.input:focus { border-color: var(--primary); }
textarea.input { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; }
.unit { position: relative; }
.unit .input { padding-right: 40px; }
.unit span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.secret { background: var(--chip-on-bg); color: var(--chip-on-ink); font-size: 12px; padding: 6px 10px; border-radius: 8px; }
.err { color: var(--red-ink); font-size: 13px; }

/* 状态小标 */
.badge { display: inline-flex; align-items: center; font-size: 12px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; font-weight: 500; }
.st-green { background: var(--green-bg); color: var(--green-ink); }
.st-amber { background: var(--chip-on-bg); color: var(--chip-on-ink); }
.st-red { background: var(--red-bg); color: var(--red-ink); }
.st-gray { background: var(--line2); color: var(--muted); }

/* 货品列表 */
.list-item { display: flex; gap: 12px; padding: 12px; background: var(--card); border-radius: 12px; margin-bottom: 10px; cursor: pointer; align-items: center; border: 2px solid transparent; }
.list-item.sel { border-color: var(--primary); }
.thumb { width: 72px; height: 72px; border-radius: 8px; background: var(--photo); flex-shrink: 0; object-fit: cover; display: flex; align-items: center; justify-content: center; font-size: 11px; color: #4E4636; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.code { font-size: 12px; color: var(--muted); letter-spacing: .2px; }
.title { font-size: 15px; font-weight: 500; }
.price { font-size: 16px; font-weight: 700; }
.check { width: 26px; height: 26px; border-radius: 13px; border: 2px solid var(--border); flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: #fff; }
.check.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 详情 */
.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: 12px; scrollbar-width: none; }
.gallery::-webkit-scrollbar { display: none; }
.gallery > .slide { flex: 0 0 100%; aspect-ratio: 1 / 1; scroll-snap-align: start; background: var(--photo); border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; color: #4E4636; position: relative; }
.gallery img, .gallery video { width: 100%; height: 100%; object-fit: contain; background: #1E2320; }
.gallery .idx { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.kv { display: flex; padding: 10px 0; border-bottom: 1px solid var(--line2); font-size: 15px; gap: 8px; }
.kv:last-child { border-bottom: none; }
.kv > .k { width: 76px; flex-shrink: 0; color: var(--muted); }
.kv > .v { flex: 1; min-width: 0; word-break: break-word; }
.thumbs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.thumbs .t { position: relative; aspect-ratio: 1 / 1; border-radius: 8px; overflow: hidden; background: var(--photo); display: flex; align-items: center; justify-content: center; font-size: 11px; color: #4E4636; text-align: center; }
.thumbs .t img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs .t .x { position: absolute; top: 2px; right: 2px; width: 28px; height: 28px; border-radius: 14px; border: none; background: rgba(0,0,0,.6); color: #fff; font-size: 16px; line-height: 1; cursor: pointer; }
.thumbs .t .tag { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 8px; }
.progress { height: 6px; background: var(--line2); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .2s; }

/* 底部操作条、导航 */
.actionbar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); max-width: 520px; margin: 0 auto; padding: 10px 16px; background: var(--card); border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; z-index: 20; }
.actionbar > .btn { flex: 1; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); display: flex; z-index: 30; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 12px; }
.nav a svg { width: 24px; height: 24px; }
.nav a.on { color: var(--primary); font-weight: 600; }
.nav a.plus .dot { width: 44px; height: 32px; border-radius: 10px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; }

/* 首页大按钮 */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: 12px; padding: 14px; min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; text-decoration: none; color: var(--ink); border: none; text-align: left; cursor: pointer; }
.tile .n { font-size: 26px; font-weight: 700; line-height: 1; }
.tile .t { font-size: 14px; font-weight: 600; }
.tile .d { font-size: 12px; color: var(--muted); }
.tile.dark { background: var(--primary); color: #fff; }
.tile.dark .d { color: #C9D1CB; }
.tile.warn .n { color: var(--red-ink); }

/* 弹层 */
.mask { position: fixed; inset: 0; background: rgba(20, 24, 21, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; background: var(--bg); border-radius: 16px 16px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet h3 { margin: 4px 0 14px; font-size: 18px; }
.dialog { margin: auto 16px; width: 100%; max-width: 360px; background: var(--card); border-radius: 14px; padding: 20px 16px 16px; align-self: center; }
.dialog p { margin: 0 0 18px; font-size: 16px; line-height: 1.6; white-space: pre-line; }
.toast { position: fixed; left: 50%; top: 20px; transform: translateX(-50%); z-index: 60; background: var(--primary); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 15px; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.toast.err { background: var(--red-ink); }

/* 后台表格 */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 0 0 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex-shrink: 0; height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--border); background: var(--card); cursor: pointer; font-size: 14px; }
.tabs button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.line-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line2); }
.line-row:last-child { border-bottom: none; }
.perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.perm-grid label { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: 36px; }
.perm-grid input, .line-row input[type=checkbox] { width: 20px; height: 20px; }

.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; }
.login h1 { font-size: 28px; margin: 0 0 4px; }
.nav-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--chip-on-ink); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; }
.nav-badge.hot { background: #C2361B; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.18); } }
@media (prefers-reduced-motion: reduce) { .nav-badge.hot { animation: none; } }
.chip { white-space: nowrap; }
.chips.sm { gap: 6px; }
.chips.sm .chip { min-height: 32px; padding: 0 11px; font-size: 13px; }

/* 问 AI */
.ai-fab { position: fixed; right: max(16px, calc(50% - 260px + 16px)); bottom: calc(var(--nav-h) + 96px + env(safe-area-inset-bottom)); z-index: 25; width: 56px; height: 56px; border-radius: 28px; border: none; background: var(--chip-on-ink); color: #fff; font-size: 14px; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.18); cursor: pointer; }
.ai-sheet { max-height: none; height: 92vh; margin-top: auto; display: flex; flex-direction: column; }
.ai-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.ai-msg { display: flex; flex-direction: column; margin-bottom: 12px; }
.ai-msg.user { align-items: flex-end; }
.ai-msg.assistant { align-items: flex-start; }
.ai-bubble { max-width: 88%; padding: 10px 12px; border-radius: 12px; font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; background: #fff; }
.ai-msg.user .ai-bubble { background: var(--primary); color: #fff; }
.ai-bubble.err { background: var(--red-bg); color: var(--red-ink); }

/* 打印（直播串词等）：只留内容 */
@media print {
  .nav, .ai-fab, .actionbar, .no-print, .toast, .back { display: none !important; }
  body, .page { background: #fff; padding: 0; }
  .card { box-shadow: none; padding: 0; margin: 0 0 8px; }
}

/* 直播话术 */
.talk-part { margin-bottom: 14px; }
.talk-h { font-weight: 700; margin-bottom: 4px; color: var(--chip-on-ink); }
.talk-line { line-height: 1.8; font-size: 15px; }
.talk-do { color: var(--muted); font-size: 13px; }
.chk { background: var(--chip-on-bg); color: var(--chip-on-ink); border-radius: 4px; padding: 0 2px; }

/* 看大图 */
.viewer { position: fixed; inset: 0; z-index: 300; background: #0d0f0e; color: #f2f2f2; display: flex; flex-direction: column; }
.viewer-top { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 14px; }
.viewer-x { background: none; border: 0; color: #fff; font-size: 30px; line-height: 1; padding: 0 6px; cursor: pointer; }
.viewer-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: pan-y pinch-zoom; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.viewer-stage.zoom { overflow: auto; display: block; touch-action: auto; }
.viewer-stage.zoom img { max-width: none; max-height: none; width: 250%; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12); border: 0; color: #fff; font-size: 30px; width: 40px; height: 56px; border-radius: 8px; cursor: pointer; }
.viewer-nav.l { left: 6px; } .viewer-nav.r { right: 6px; }
.viewer-bar { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.viewer-dl { background: rgba(255,255,255,.08); border-radius: 8px; padding: 10px; font-size: 14px; width: 100%; }
.viewer .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); background: transparent; }
