:root {
  --bg: #0f1117; --bg2: #161a23; --bg3: #1e2430; --card: #181d28;
  --border: #2a3140; --text: #e6e9f0; --text2: #9aa3b2; --accent: #4c8dff;
  --red: #ff5a5f; --red-bg: rgba(255, 90, 95, .13);
  --green: #2fbf71; --green-bg: rgba(47, 191, 113, .13);
  --yellow: #f5b942; --yellow-bg: rgba(245, 185, 66, .13);
  --gray: #8a93a6; --gray-bg: rgba(138, 147, 166, .16);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif; font-size: 14px; line-height: 1.5; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #333b4a; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 20px; background: rgba(15,17,23,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar .logo { font-size: 17px; font-weight: 700; color: #fff; }
.topbar .logo span { color: var(--accent); }
.topbar .sub { color: var(--text2); font-size: 12px; }
.topbar .spacer { flex: 1; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--bg3); color: var(--text); border: 1px solid var(--border); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; transition: .15s; }
.btn:hover { border-color: var(--accent); color: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
select.input, input.input, textarea.input { background: var(--bg3); color: var(--text); border: 1px solid var(--border); padding: 7px 10px; border-radius: 8px; font-size: 13px; outline: none; }
input.input:focus, select.input:focus, textarea.input:focus { border-color: var(--accent); }

.wrap { max-width: 1520px; margin: 0 auto; padding: 18px 20px 70px; }
.section { margin-bottom: 22px; }
.section-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; color: #fff; display: flex; align-items: center; gap: 8px; }
.section-title .hint { font-size: 12px; color: var(--text2); font-weight: 400; }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px; text-align: center; cursor: pointer; transition: .15s; background: var(--card); }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--bg2); }
.dropzone .big { font-size: 15px; font-weight: 600; }
.dropzone .small { color: var(--text2); margin-top: 6px; font-size: 13px; }
.filelist { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; justify-content: center; }
.filechip { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.filechip .del { cursor: pointer; color: var(--text2); margin-left: 2px; }
.filechip .del:hover { color: var(--red); }

.progress { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin: 12px 0; display: none; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-week { margin-bottom: 12px; padding: 8px 14px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 13px; }
.stat-week b { color: var(--accent); font-size: 14px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; color: #fff; }
.kpi .l { font-size: 12px; color: var(--text2); margin-top: 2px; }
.kpi .sub { font-size: 11px; color: var(--text2); margin-top: 4px; opacity: .85; }
.kpi.red .v { color: var(--red); }
.kpi.green .v { color: var(--green); }
.kpi.yellow .v { color: var(--yellow); }
.kpi.gray .v { color: var(--gray); }

/* 货品卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: .15s; display: flex; flex-direction: column; }
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.card.abn { border-color: rgba(255,90,95,.5); }
.card.exc { border-color: rgba(47,191,113,.5); }
.card.np { border-color: rgba(245,185,66,.55); }
.card.mid { border-color: rgba(76,141,255,.55); }
.card .c-img { height: 130px; background: var(--bg3); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.card .c-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.card .c-img .ph { position: absolute; color: var(--text2); font-size: 12px; }
.card .c-body { padding: 10px 12px; }
.card .c-id { font-size: 12px; color: var(--text2); font-family: monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .c-cat { font-size: 12px; color: var(--text); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c-meta { font-size: 13px; margin-top: 3px; }
.card .c-series { font-size: 12px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c-metrics { display: flex; gap: 10px; margin-top: 7px; flex-wrap: wrap; }
.card .m { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.card .m.abn { background: var(--red-bg); color: var(--red); }
.card .m.exc { background: var(--green-bg); color: var(--green); }
.card .m.np { background: var(--yellow-bg); color: var(--yellow); }
.card .m.mid { background: rgba(76, 141, 255, .16); color: #4c8dff; }

/* Tab */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tab { padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; background: var(--bg3); color: var(--text2); border: 1px solid transparent; }
.tab:hover { color: #fff; }
.tab.active { background: var(--accent); color: #fff; }
.tab .badge { display: inline-block; margin-left: 5px; background: rgba(0,0,0,.25); border-radius: 10px; padding: 0 7px; font-size: 11px; }

/* 表格 */
.table-scroll { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
table.grid { border-collapse: collapse; width: 100%; font-size: 12.5px; white-space: nowrap; }
table.grid th, table.grid td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: right; }
table.grid th { position: sticky; top: 0; background: var(--bg3); color: var(--text2); font-weight: 600; z-index: 2; text-align: center; border-bottom: 2px solid var(--border); }
table.grid td:first-child, table.grid th:first-child { position: sticky; left: 0; background: var(--card); text-align: left; z-index: 1; }
table.grid th:first-child { z-index: 3; background: var(--bg3); }
table.grid tr:hover td { background: var(--bg2); }
table.grid tr.row-abn td { background: var(--red-bg); }
table.grid tr.row-exc td { background: var(--green-bg); }
table.grid tr.row-delist td { background: var(--gray-bg); }
table.grid tr.row-mean td { background: var(--bg3); font-weight: 700; border-top: 2px solid var(--border); }
table.grid td.left { text-align: left; }
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: #fff; background: #2a3342; }
table.grid th .sort-arrow { font-size: 10px; margin-left: 3px; color: var(--accent); }
/* 货品id 超链接：异常总览卡片 + 明细表首列 */
a.c-id { color: var(--text2); text-decoration: none; cursor: pointer; }
a.c-id:hover { color: var(--accent); text-decoration: underline; }
.grid a.pid-link { color: var(--text); text-decoration: none; cursor: pointer; font-family: "SF Mono", Consolas, monospace; }
.grid a.pid-link:hover { color: var(--accent); text-decoration: underline; }
.ver-badge { display: inline-block; margin-left: 4px; padding: 0 5px; font-size: 10px; line-height: 15px; border-radius: 8px; color: #fff; background: var(--accent, #2F3A4C); vertical-align: middle; cursor: help; }
.card .ver-badge { background: var(--accent, #2F3A4C); }
/* 货号标签（来源：主图商品id.xlsx E列「货品编码」） */
.c-code { display: inline-block; margin-left: 6px; padding: 0 5px; font-size: 10px; line-height: 15px; border-radius: 8px; color: var(--text2); background: var(--bg3); border: 1px solid var(--border); vertical-align: middle; font-family: "SF Mono", Consolas, monospace; }
input[type="date"].input::-webkit-calendar-picker-indicator { filter: invert(0.7); cursor: pointer; }
.c-red { color: var(--red); } .c-green { color: var(--green); } .c-yellow { color: var(--yellow); } .c-gray { color: var(--gray); }
.mono { font-family: "SF Mono", Consolas, monospace; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.tag.abn { background: var(--red-bg); color: var(--red); }
.tag.exc { background: var(--green-bg); color: var(--green); }
.tag.nrm { background: var(--bg3); color: var(--text2); }
.tag.unk { background: var(--yellow-bg); color: var(--yellow); }
.tag.np { background: var(--yellow-bg); color: var(--yellow); }
.tag.delist { background: var(--gray-bg); color: var(--gray); }
.tag.mid { background: rgba(76, 141, 255, .16); color: #4c8dff; }

/* 图表 */
.chart { width: 100%; height: 340px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }

/* 筛选器 */
.filters { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }
.filters #prodSelects, .filters #ovSelects, .filters #dimSelects { display: contents; }

/* 多选下拉组件 */
.ms { position: relative; display: inline-block; }
.ms-trigger { display: inline-flex; align-items: center; gap: 5px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; min-width: 120px; max-width: 250px; color: var(--text); }
.ms-trigger:hover { border-color: var(--accent); }
.ms-placeholder { color: var(--text2); }
.ms-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; max-width: 180px; }
.ms-tag { display: inline-flex; align-items: center; gap: 4px; background: var(--accent); color: #fff; border-radius: 5px; padding: 1px 6px; font-size: 12px; }
.ms-tag .ms-x { cursor: pointer; opacity: .85; font-weight: 700; }
.ms-tag .ms-x:hover { opacity: 1; }
.ms-arrow { color: var(--text2); font-size: 10px; margin-left: auto; }
.ms-drop { position: absolute; top: calc(100% + 4px); left: 0; z-index: 60; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; min-width: 240px; max-width: 320px; display: flex; flex-direction: column; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.ms-search { margin: 8px 8px 4px; padding: 7px 10px; background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 13px; outline: none; }
.ms-search:focus { border-color: var(--accent); }
.ms-options { overflow: auto; max-height: 240px; padding: 4px 8px; }
.ms-opt { display: flex; align-items: center; gap: 8px; padding: 6px 6px; cursor: pointer; font-size: 13px; border-radius: 6px; color: var(--text); }
.ms-opt:hover { background: var(--bg3); }
.ms-opt.checked { background: var(--bg3); }
.ms-opt input { margin: 0; accent-color: var(--accent); cursor: pointer; }
.ms-opt-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-opt-count { color: var(--text2); font-size: 12px; }
.ms-empty { color: var(--text2); padding: 12px; text-align: center; font-size: 13px; }
.ms-actions { border-top: 1px solid var(--border); padding: 6px 8px; text-align: right; }
.ms-clear { background: transparent; border: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 3px 6px; border-radius: 4px; }
.ms-clear:hover { text-decoration: underline; }

/* 模态 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; display: none; align-items: center; justify-content: center; }
.modal-mask.show { display: flex; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 22px; width: 600px; max-width: 94vw; max-height: 88vh; overflow: auto; }
.modal.wide { width: 1200px; }
.weekly-sub { font-size: 11px; color: var(--text2); opacity: .8; margin-left: 4px; }
.modal h3 { margin: 0 0 16px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 5px; }
.form-row .inp { width: 100%; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.hint-text { font-size: 12px; color: var(--text2); margin-top: 4px; word-break: break-all; }
.hint-text code { background: var(--bg3); padding: 2px 6px; border-radius: 4px; }

/* 历史 */
.hist-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--card); cursor: pointer; }
.hist-item:hover { border-color: var(--accent); }
.hist-item .meta { flex: 1; }
.hist-item .t { font-weight: 600; }
.hist-item .s { font-size: 12px; color: var(--text2); }

/* 详情弹窗 */
.detail-head { display: flex; gap: 14px; }
.detail-head img { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; background: var(--bg3); }

.help-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px; font-size: 13px; line-height: 1.9; }
.empty { text-align: center; color: var(--text2); padding: 40px; }
.muted { color: var(--text2); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text2); margin-bottom: 10px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 200; display: none; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast.err { background: var(--red); }
