:root {
  --bg: #f2f4f8; --panel: #ffffff; --line: #e6e9f0;
  --text: #1c2430; --sub: #6b7484; --muted: #9aa4b5;
  --primary: #164cc8; --primary-d: #1040a8; --primary-l: #e8eeff;
  --green: #16a34a; --green-l: #e6f6ec; --red: #dc2626; --red-l: #fdeaea;
  --orange: #ea8600; --orange-l: #fef4e6; --purple: #7c3aed; --purple-l: #f1eafe;
  --radius: 12px; --shadow: 0 2px 10px rgba(16,40,120,.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "PingFang SC","Microsoft YaHei","Helvetica Neue",Arial,sans-serif; background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 13px; color: var(--text); }

/* ---------- 登录 ---------- */
#login { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg,#0a1b45 0%,#164cc8 60%,#2f6bff 100%); padding: 24px; }
.lg-wrap { width: 400px; max-width: 94vw; }
.lg-cover { text-align: center; color: #fff; padding: 28px 0 22px; }
.lg-logo { width: 66px; height: 66px; margin: 0 auto 12px; border-radius: 20px; background: linear-gradient(145deg,#ffffff,#cfe0ff); display:flex; align-items:center; justify-content:center; font-size: 32px; font-weight: 800; color: #164cc8; box-shadow: 0 8px 24px rgba(0,0,0,.28); }
.lg-title { font-size: 24px; font-weight: 700; letter-spacing: 2px; }
.lg-sub { font-size: 12.5px; color: rgba(255,255,255,.82); margin-top: 8px; line-height: 1.7; }
.lg-card { background: #fff; border-radius: 16px; padding: 26px 24px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.lg-card h3 { font-size: 17px; margin-bottom: 18px; color: #0a1b45; }
.lg-item { margin-bottom: 13px; }
.lg-item label { display: block; font-size: 12.5px; color: var(--sub); margin-bottom: 5px; }
.lg-item input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; outline: none; }
.lg-item input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-l); }
.lg-btn { width: 100%; padding: 11px; background: var(--primary); color: #fff; border: none; border-radius: 9px; font-size: 15px; letter-spacing: 4px; font-weight: 600; }
.lg-btn:hover { background: var(--primary-d); }
.lg-err { color: var(--red); font-size: 12.5px; margin-top: 10px; text-align: center; min-height: 16px; }
.lg-foot { text-align: center; color: rgba(255,255,255,.75); font-size: 12px; margin-top: 16px; }

/* ---------- 布局 ---------- */
#app { display: flex; height: 100vh; }
.sidebar { width: 210px; background: #0e1430; color: #cdd6f4; padding: 14px 12px; overflow-y: auto; flex-shrink: 0; }
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 18px; color: #fff; }
.sb-logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(145deg,#fff,#cfe0ff); color:#164cc8; display:flex;align-items:center;justify-content:center;font-weight:800;font-size:18px; }
.sb-brand b { font-size: 15px; letter-spacing: 1px; }
.sb-brand small { display:block; font-weight:400; color:#8b96c9; font-size:11px; }
.sb-group { font-size: 11px; color: #6670a0; padding: 12px 10px 5px; letter-spacing: 1px; display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; }
.sb-group:hover { color: #9aa6d8; }
.sb-arrow { font-size: 10px; color: #6670a0; }
.sb-group.sb-folded .sb-arrow { transform: rotate(-90deg); }
.sb-group-items.sb-hide { display: none; }
.sb-item { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: #cdd6f4; font-size: 13.5px; margin-bottom: 2px; }
.sb-item:hover { background: rgba(255,255,255,.06); color:#fff; }
.sb-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.sb-ico { width: 20px; text-align: center; flex-shrink: 0; }
.sb-item .sb-tag { margin-left: auto; font-size: 10.5px; background: var(--red); color:#fff; border-radius: 8px; padding: 1px 6px; }
.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h2 { font-size: 17px; font-weight: 700; }
.topbar-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 20px; line-height: 1; color: var(--sub); }
.top-actions, #top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.topbar-search { position: relative; display: flex; align-items: center; }
.topbar-search input { width: 220px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 13px; color: #2a3444; outline: none; }
.topbar-search input:focus { border-color: var(--primary); }
.gs-res { position: absolute; top: calc(100% + 6px); right: 0; left: 0; z-index: 300; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(10,18,40,.15); max-height: 320px; overflow-y: auto; }
.gs-item { padding: 9px 12px; font-size: 13px; color: #2a3444; cursor: pointer; border-bottom: 1px solid #f0f2f7; }
.gs-item:hover { background: #f4f7fd; }
.gs-item:last-child { border-bottom: none; }
.gs-empty { color: var(--sub); cursor: default; }
.role-badge { font-size: 12px; color: #fff; background: var(--primary); border-radius: 10px; padding: 3px 10px; }
#main { flex: 1; overflow-y: auto; padding: 18px 20px 30px; }

/* ---------- 通用组件 ---------- */
.card { background: var(--panel); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h3 { font-size: 14.5px; margin-bottom: 12px; color: #121a2b; }
.btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 13px; color: var(--text); }
.btn:hover { border-color: #c9d2e6; background: #f7f9ff; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-d); }
.btn.success { background: var(--green); color: #fff; border-color: var(--green); }
.btn.warn { background: var(--orange); color: #fff; border-color: var(--orange); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--sub); }
.btn.tiny { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: 12px; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit,minmax(280px,1fr)); gap: 12px; }
.kpi { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.k-label { font-size: 12px; color: var(--sub); }
.k-value { font-size: 21px; font-weight: 700; margin-top: 5px; }
.money { font-variant-numeric: tabular-nums; }
.c-red { color: var(--red); } .c-green { color: var(--green); } .c-orange { color: var(--orange); } .c-blue { color: var(--primary); } .c-purple { color: var(--purple); }
.empty { text-align: center; color: var(--muted); padding: 28px 0; font-size: 13px; }
.row-list { display: flex; flex-direction: column; gap: 8px; }
.li-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); }
.li-head { display: flex; align-items: center; justify-content: space-between; }
.li-title { font-weight: 600; font-size: 14px; }
.li-meta { font-size: 12px; color: var(--sub); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; }
.tag.blue { background: var(--primary-l); color: var(--primary); }
.tag.green { background: var(--green-l); color: var(--green); }
.tag.red { background: var(--red-l); color: var(--red); }
.tag.orange { background: var(--orange-l); color: var(--orange); }
.tag.gray { background: #eef1f6; color: var(--sub); }
.tag.purple { background: var(--purple-l); color: var(--purple); }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; padding: 8px 10px; color: var(--sub); font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--line); background: #f8fafd; white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid #f0f2f7; vertical-align: middle; }
.tbl tr:hover td { background: #f7f9ff; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.p-cell b { font-weight: 600; } .p-spec { color: var(--muted); font-size: 11.5px; margin-left: 6px; }

/* 商品图片 */
.prod-cell { display: flex; align-items: center; gap: 10px; }
.prod-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); background: #fff; flex: none; cursor: pointer; }
.prod-thumb.empty { display: flex; align-items: center; justify-content: center; color: #cfd6e2; font-size: 16px; }
.img-lightbox { background: rgba(8,12,28,.78); cursor: zoom-out; }
.img-lightbox img { max-width: 90vw; max-height: 88vh; border-radius: 10px; box-shadow: 0 16px 48px rgba(0,0,0,.5); display: block; }
.grp-pick { position: relative; display: flex; align-items: center; }
.grp-pick .ipt { flex: 1; padding-right: 36px; }
.grp-pick-btn { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border: none; background: none; color: var(--muted); font-size: 13px; cursor: pointer; line-height: 1; }
.grp-pick-menu { position: fixed; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(15,23,42,.14); z-index: 200; max-height: 200px; overflow-y: auto; display: none; }
.grp-pick-menu.open { display: block; }
.grp-pick-opt { padding: 10px 12px; cursor: pointer; font-size: 13px; }
.grp-pick-opt:hover { background: #f2f6ff; }
.prod-img { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--line); object-fit: contain; }
.img-upload { display: flex; align-items: flex-start; gap: 10px; }
.img-preview { width: 76px; height: 76px; border-radius: 8px; border: 1px dashed var(--line); background: #f8fafd; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; overflow: hidden; flex: none; }
.img-preview img { width: 100%; height: 100%; object-fit: cover; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; }
.form-item { }
.form-item label { display: block; font-size: 12.5px; color: var(--sub); margin-bottom: 5px; }
.ipt, select.ipt, textarea.ipt { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; outline: none; }
.ipt:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-l); }
textarea.ipt { min-height: 60px; resize: vertical; }
.hint { font-size: 12px; color: var(--sub); line-height: 1.7; }

/* 筛选条 */
.bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.bar .ipt { width: auto; min-width: 130px; }
.seg { display: inline-flex; background: #eef1f6; border-radius: 8px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 6px 14px; border-radius: 6px; font-size: 13px; color: var(--sub); }
.seg button.on { background: #fff; color: var(--primary); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* 弹层 */
.overlay { position: fixed; inset: 0; background: rgba(10,18,40,.46); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.sheet { background: #fff; border-radius: 14px; width: 720px; max-width: 96vw; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.sheet.small { width: 420px; }
.sheet.large { width: 920px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { font-size: 16px; }
.sheet-x { border: none; background: none; font-size: 22px; color: var(--muted); line-height: 1; }
.sheet-body { padding: 18px 20px; overflow-y: auto; }
.sheet-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* 明细编辑 */
.item-edit { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #fbfcfe; }
.ie-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.ie-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ie-row .ipt { flex: 1; min-width: 80px; }
.ie-amt { font-weight: 700; color: var(--primary); }
.pick-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 13px; }
.pick-btn .pb-txt { color: var(--primary); font-weight: 600; }

/* Toast */
#toast-box { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 500; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: rgba(20,30,60,.92); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: fadeUp .25s ease; }
.toast.err { background: var(--red); }
@keyframes fadeUp { from { opacity:0; transform: translateY(-8px);} to { opacity:1; transform:none;} }

/* 工作台宫格 */
.home-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(110px,1fr)); gap: 10px; }
.quick-cell { background: var(--panel); border-radius: 10px; padding: 14px 10px; text-align: center; box-shadow: var(--shadow); cursor: pointer; }
.quick-cell:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(16,40,120,.12); }
.quick-cell i { display: block; font-size: 24px; font-style: normal; }
.quick-cell span { display: block; font-size: 12.5px; margin-top: 6px; color: var(--text); }

/* 详情页元信息 */
.partner-line { display:flex; align-items:center; justify-content:space-between; }
.status-dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }

/* 打印预览 */
.print-preview { background:#fff; border:1px solid var(--line); padding:24px; font-size:13px; }
.pp-head { text-align:center; font-size:18px; font-weight:700; margin-bottom:10px; }
.pp-head-sub { text-align:center; font-size:22px; font-weight:700; color:#222; margin:0 0 10px; }
.pp-meta { margin:10px 0; color:var(--sub); font-size:12px; line-height:1.8; }
.pp-total { text-align:right; font-size:14px; font-weight:600; margin-top:12px; }
.pp-handler { text-align:right; font-size:13px; margin-top:14px; }

@media (max-width: 860px) {
  .sidebar { width: 60px; } .sb-item span:not(.sb-ico), .sb-group, .sb-brand b, .sb-brand small { display:none; }
  .sb-group-items.sb-hide { display: block; }
  .form-grid, .home-grid { grid-template-columns: 1fr; }
}

/* ---------- 手机版适配（≤640px） ---------- */
@media (max-width: 640px) {
  /* 侧边栏 → 抽屉（默认收起，点菜单打开） */
  #app { display: block; height: 100vh; overflow: hidden; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 250px; z-index: 200;
    transform: translateX(-105%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after { content:''; position: fixed; inset:0; background: rgba(10,18,40,.4); z-index: 150; }
  .sb-brand { display: flex; }
  .sb-group { display: flex; } .sb-item span:not(.sb-ico) { display: block; }
  .sb-group-items.sb-hide { display: none; }
  #btn-menu { display: block !important; }
  .main-col { height: 100vh; display: flex; flex-direction: column; }
  .topbar { padding: 10px 12px; }
  .topbar h2 { font-size: 15px; }
  .role-badge { display: none; }
  #main { flex: 1; overflow-y: auto; padding: 12px 12px 16px; -webkit-overflow-scrolling: touch; }
  .grid-kpi { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid, .ie-grid, .home-grid { grid-template-columns: 1fr; }
  .bar .ipt { width: 100%; min-width: 0; }
  /* 更大触控目标 */
  .btn { padding: 10px 14px; font-size: 14px; }
  .btn.tiny { padding: 8px 11px; font-size: 12.5px; }
  .ipt, select.ipt, textarea.ipt { padding: 11px; font-size: 14px; }
  .pick-btn { padding: 10px 11px; font-size: 14px; }
  /* 弹层 → 底部全屏抽屉 */
  .overlay { padding: 0; align-items: flex-end; }
  .sheet { width: 100vw; max-width: 100vw; max-height: 94vh; border-radius: 16px 16px 0 0; }
  .sheet.small, .sheet.large { width: 100vw; }
  .sheet-head { padding: 14px 16px; }
  .sheet-body { padding: 14px 16px; }
  .sheet-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  /* 表格横向滚动 */
  .tbl-wrap { -webkit-overflow-scrolling: touch; }
  table.tbl { min-width: 560px; }
  /* FAB 上移，避开底部 */
  .fab { right: 14px !important; bottom: 22px !important; }
  /* 工作台快捷宫格 */
  .quick-grid { grid-template-columns: repeat(3, 1fr); }
}
