:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-weak: #eff4ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: 13px; color: inherit; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 196px; flex: 0 0 196px; background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.brand .dot { width: 18px; height: 18px; border-radius: 4px; background: var(--primary); }
.menu { padding: 8px; overflow-y: auto; flex: 1; }
.menu-group { margin-bottom: 4px; }
.menu-title { font-size: 12px; color: var(--muted); padding: 8px 10px 4px; }
.menu-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--radius);
  color: var(--text); cursor: pointer; white-space: nowrap;
}
.menu-item:hover { background: #f3f4f6; }
.menu-item.active { background: var(--primary-weak); color: var(--primary); font-weight: 600; }
.menu-item .ico { width: 16px; text-align: center; opacity: .75; }
.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 48px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .crumb { font-size: 13px; color: var(--muted); }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--primary-weak); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
.content { padding: 14px 16px 40px; }

/* ---------- 通用组件 ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 17px; font-weight: 600; }
.page-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  height: 30px; padding: 0 12px; border: 1px solid var(--border-strong); background: #fff;
  border-radius: var(--radius); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-link { border: none; background: none; color: var(--primary); cursor: pointer; padding: 0 4px; height: auto; }
.btn-link.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.inp, .sel, .ta {
  height: 30px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: #fff; outline: none; min-width: 0;
}
.inp:focus, .sel:focus, .ta:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-weak); }
.ta { height: auto; padding: 6px 8px; resize: vertical; }
.sel { padding-right: 4px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.panel + .panel { margin-top: 12px; }

/* 筛选栏 */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 12px; }
.filters .f-label { font-size: 12px; color: var(--muted); }
.filters .inp, .filters .sel { min-width: 120px; }
.filters .spacer { flex: 1; }

/* 表格 */
.table-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-weight: 600; color: var(--muted); background: #fafbfc;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
table.tbl td { padding: 7px 10px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
table.tbl tbody tr:hover { background: #fafbfc; }
table.tbl td.nowrap, table.tbl th.nowrap { white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ops { display: flex; gap: 6px; white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); font-size: 13px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 12px; font-size: 12px; color: var(--muted); }
.pager .pg { min-width: 26px; height: 26px; border: 1px solid var(--border-strong); background: #fff; border-radius: 4px; cursor: pointer; }
.pager .pg.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 标签与徽章 */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 10px; font-size: 12px; background: #f1f3f5; color: #495057; white-space: nowrap; }
.badge.green { background: #e7f6ed; color: #15803d; }
.badge.red { background: #fdecec; color: #b91c1c; }
.badge.orange { background: #fff4e5; color: #b45309; }
.badge.blue { background: var(--primary-weak); color: #1d4ed8; }
.badge.gray { background: #f1f3f5; color: #6b7280; }
.tag-list { display: flex; gap: 4px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ellipsis { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 统计卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 22px; font-weight: 600; margin-top: 2px; }
.card .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
.panel-head { padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.panel-body { padding: 12px; }

/* 弹窗 */
.overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 8px; width: 560px; max-width: 96vw; box-shadow: var(--shadow); }
.modal.wide { width: 900px; }
.modal.xwide { width: 1140px; }
.modal.narrow { width: 420px; }

/* 列设置面板 */
.cols-set-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; font-size: 12px; }
.cols-set-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 6px; max-height: 420px; overflow: auto; }
.col-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 13px; background: #fff; }
.col-item:last-child { border-bottom: none; }
.col-item label { flex: 1; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.col-item .drag { cursor: grab; color: #c0c6d0; letter-spacing: -2px; user-select: none; }
.col-item .col-move { display: flex; gap: 2px; }
.col-item .col-move .btn-link[disabled] { color: #d5d9e0; cursor: default; }
.col-item.dragging { opacity: .4; }
.col-item.over { box-shadow: inset 0 2px 0 var(--primary); }

/* 项目库：明细编辑、汇总、Tab、登记行 */
.danger-text { color: var(--danger); }
.tbl .inp, .tbl .sel { width: 100%; min-width: 56px; padding: 3px 6px; height: 28px; }
.items-tbl td { padding: 4px 8px; }
.sum-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; font-size: 13px; }
.sum-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.sum-row.total { border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 6px; font-size: 14px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { border: none; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.add-row-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }

/* 表头排序 */
.tbl th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.tbl th[data-sort]:hover { background: #f2f4f7; }
.sort-ind { margin-left: 4px; color: var(--primary); font-size: 11px; }
.sort-ind.idle { color: #d5d9e0; }
.modal-head { padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 14px 16px; max-height: calc(100vh - 170px); overflow: auto; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.close-x { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); line-height: 1; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.span2 { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); }
.field .req { color: var(--danger); }
.field .hint { font-size: 11px; color: var(--muted); }
.field .inp, .field .sel, .field .ta { width: 100%; }
.section-title { grid-column: 1 / -1; font-size: 12px; font-weight: 600; color: var(--primary); border-bottom: 1px solid var(--border); padding-bottom: 4px; margin-top: 4px; }

/* 只读详情 */
.kv { display: grid; grid-template-columns: 100px 1fr; gap: 8px 12px; font-size: 13px; align-items: start; }
.kv .k { color: var(--muted); }
.kv > span:last-child { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.kv.span-full { grid-column: 1 / -1; }
.kv-list { display: flex; flex-direction: column; gap: 9px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; align-items: start; }
.kv-grid > .section-title { grid-column: 1 / -1; }

/* 接口密钥 */
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.hint-box { background: #f7f9fc; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; font-size: 12px; color: var(--muted); line-height: 1.7; margin-top: 10px; }
.hint-box.err { background: #fff6f6; border-color: #f3c2c2; color: var(--danger); }
.hint-box code, .code-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.key-box { margin-top: 10px; padding: 10px 12px; border: 1px dashed var(--primary); border-radius: var(--radius); background: #f5f8ff; word-break: break-all; }
.key-box code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; font-weight: 600; }
.code-box { background: #f7f9fc; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-top: 6px; overflow: auto; line-height: 1.6; }
@media (max-width: 900px) { .kv-grid, .form-grid { grid-template-columns: 1fr; } }

/* 产品图片墙 */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; padding: 12px; }
.pcard { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.pcard:hover { box-shadow: var(--shadow); }
.pcard .thumb { height: 130px; background: #f6f7f9; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pcard .thumb img { width: 100%; height: 100%; object-fit: contain; }
.pcard .thumb .ph { color: #c0c4cc; font-size: 12px; }
.pcard .body { padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
.pcard .nm { font-size: 13px; font-weight: 600; line-height: 1.3; height: 34px; overflow: hidden; }
.pcard .meta { font-size: 12px; color: var(--muted); }
.pcard .price { display: flex; align-items: baseline; gap: 6px; }
.pcard .price .cur { color: var(--primary); font-weight: 600; }
.pcard .price .old { color: var(--muted); text-decoration: line-through; font-size: 12px; }
.pcard .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }

/* 产品详情图 */
.pd-images { display: flex; gap: 8px; flex-wrap: wrap; }
.pd-images img { width: 92px; height: 92px; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; background: #fafbfc; }
.pd-hero { width: 100%; max-height: 220px; object-fit: contain; background: #fafbfc; border: 1px solid var(--border); border-radius: 4px; }

/* 视图切换 */
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: none; background: #fff; height: 28px; padding: 0 12px; cursor: pointer; }
.seg button.active { background: var(--primary); color: #fff; }

/* Toast */
.toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1f2328; color: #fff; padding: 8px 14px; border-radius: var(--radius); font-size: 13px; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* 登录页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-box { width: 340px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 26px 24px; box-shadow: var(--shadow); }
.login-box h2 { margin: 0 0 4px; font-size: 18px; }
.login-box .sub { color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.login-box .field { margin-bottom: 12px; }
.login-box .btn { width: 100%; justify-content: center; height: 34px; margin-top: 6px; }
.login-tip { margin-top: 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 10px; line-height: 1.7; }

.chart-bar { display: grid; grid-template-columns: 110px 1fr 40px; gap: 10px; align-items: center; margin-bottom: 7px; font-size: 12px; }
.chart-bar .bar { height: 12px; background: var(--primary); border-radius: 2px; }
.chart-bar .nm { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-bar .bar { min-width: 2px; }
.chart-bar .vl { text-align: right; color: var(--muted); }

.notice-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed #eef0f3; font-size: 13px; }
.notice-row:last-child { border-bottom: none; }
