:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e7ef;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #1f5fd0;
  --primary-dark: #17489f;
  --ok: #0f8a5f;
  --warn: #b45309;
  --err: #c02a2a;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: linear-gradient(180deg, #22345a, #1b2a49);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; white-space: nowrap; }
.brand small { font-weight: 400; opacity: .7; font-size: 12px; margin-left: 6px; }
.topbar .spacer { flex: 1; }
.topbar a, .topbar .user { color: #dbe6ff; font-size: 13px; }
.topbar .user { opacity: .9; }

nav.mainnav {
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 0 10px;
  position: sticky;
  top: 46px;
  z-index: 30;
  scrollbar-width: none;
}
nav.mainnav::-webkit-scrollbar { display: none; }
nav.mainnav a {
  padding: 11px 12px;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
nav.mainnav a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
nav.mainnav a:hover { text-decoration: none; color: var(--primary); }

/* ---------- 布局 ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px 14px 90px; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { font-size: 19px; margin: 0; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.card h2 .more { float: right; font-size: 12px; font-weight: 400; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 260px; min-width: 0; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.5px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; }

/* ---------- 表格 ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; background: #fafbfd; white-space: nowrap; }
table.list tr:hover td { background: #f8fafd; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list .code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: #334155; }
table.list .muted { color: var(--muted); font-size: 12px; }

/* ---------- 徽标 ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; line-height: 1.7; border: 1px solid transparent; white-space: nowrap; }
.badge.ok { background: #e7f6ef; color: var(--ok); border-color: #bfe6d5; }
.badge.warn { background: #fdf3e3; color: var(--warn); border-color: #f4ddb5; }
.badge.err { background: #fdeceb; color: var(--err); border-color: #f6c9c6; }
.badge.gray { background: #f1f3f7; color: var(--muted); border-color: #e6e9f0; }
.badge.blue { background: #eaf1fd; color: var(--primary); border-color: #cbdcf8; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font-size: 14px; cursor: pointer;
  text-decoration: none; white-space: nowrap; font-family: inherit;
}
.btn:hover { background: #f6f8fc; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--err); border-color: #f0c4c1; }
.btn.danger:hover { background: #fdf0ef; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
label.field { display: block; font-size: 13px; color: var(--muted); }
label.field span { display: block; margin-bottom: 4px; }
label.field.req span::after { content: " *"; color: var(--err); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d5dbe6; border-radius: 8px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,95,208,.12); }
textarea { resize: vertical; min-height: 70px; }
input[type=file] { font-size: 13px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form > * { flex: 0 1 auto; }

/* ---------- 提示 ---------- */
.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; border: 1px solid; }
.flash.ok { background: #eaf7f1; border-color: #bfe6d5; color: #0b6b4a; }
.flash.err { background: #fdeceb; border-color: #f6c9c6; color: #9d2222; }
.flash.warn { background: #fdf5e7; border-color: #f2ddb6; color: #8a4b06; }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }

/* ---------- 产品图片 ---------- */
.thumb {
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover;
  background: #eef1f6; border: 1px solid var(--line); display: block;
}
.thumb.blank { display: flex; align-items: center; justify-content: center; color: #b6bfcc; font-size: 11px; }
.hero-img {
  width: 100%; max-width: 320px; aspect-ratio: 1/1; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--line); background: #eef1f6;
}
.hero-blank {
  width: 100%; max-width: 320px; aspect-ratio: 1/1; border-radius: 12px;
  border: 1px dashed #c9d2e0; display: flex; flex-direction: column; gap: 6px;
  align-items: center; justify-content: center; color: var(--muted); font-size: 13px; background: #fbfcfe;
}

/* ---------- 单据明细编辑 ---------- */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { font-size: 12px; color: var(--muted); text-align: left; padding: 5px 4px; font-weight: 600; }
.items-table td { padding: 4px 4px; vertical-align: top; }
.items-table input, .items-table select { padding: 7px 8px; font-size: 14px; }
.items-table .col-qty { width: 90px; }
.items-table .col-unit { width: 80px; }
.items-table .col-del { width: 38px; }
.icon-btn { border: none; background: none; color: var(--err); font-size: 18px; cursor: pointer; padding: 4px 6px; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 14px; border-radius: 20px; background: #fff; border: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabs a:hover { text-decoration: none; }

/* ---------- 移动端底部操作条 ---------- */
.mobile-bar {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: #fff; border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.mobile-bar a {
  flex: 1; text-align: center; font-size: 11px; color: var(--muted);
  padding: 4px 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.mobile-bar a b { font-size: 17px; font-weight: 400; line-height: 1; }
.mobile-bar a.active { color: var(--primary); }
.mobile-bar a:hover { text-decoration: none; }

/* ---------- 拍照上传 ---------- */
.shot-box {
  border: 2px dashed #c3cddd; border-radius: 14px; padding: 22px 14px;
  text-align: center; background: #fbfcfe; cursor: pointer;
}
.shot-box .big { font-size: 34px; line-height: 1; margin-bottom: 8px; }
.shot-box p { margin: 4px 0; font-size: 14px; }
.shot-box .hint { color: var(--muted); font-size: 12px; }
.preview-img { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--line); }

/* ---------- 行情/清单小卡 ---------- */
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.hr { height: 1px; background: var(--line); margin: 12px 0; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  body { font-size: 14px; }
  .wrap { padding: 12px 10px 96px; }
  .topbar { padding: 9px 12px; }
  .brand { font-size: 15px; }
  .brand small { display: none; }
  nav.mainnav { top: 44px; }
  .mobile-bar { display: flex; }
  .page-head h1 { font-size: 17px; }
  table.list { font-size: 13px; }
  table.list th, table.list td { padding: 8px 6px; }
  .hide-sm { display: none; }
  .stat .v { font-size: 21px; }
}

@media print {
  .topbar, nav.mainnav, .mobile-bar, .no-print { display: none !important; }
  body { background: #fff; }
  .wrap { padding: 0; max-width: none; }
}