:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e3e9f1;
  --line-soft: #eef2f7;
  --text: #1c2536;
  --text-2: #46536a;
  --muted: #7a879b;
  --accent: #2563eb;
  --accent-soft: #eef3ff;
  --up: #d92d20;
  --down: #12805c;
  --warn: #b45309;
  --warn-soft: #fff4e6;
  --auto: #2563eb;
  --auto-soft: #eaf1ff;
  --manual: #7c3aed;
  --manual-soft: #f3ecff;
  --grey-soft: #f1f4f8;
  --shadow: 0 1px 2px rgba(20, 33, 61, .04), 0 4px 14px rgba(20, 33, 61, .035);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px; letter-spacing: .5px;
}
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: .2px; }
.head-meta { display: flex; align-items: center; gap: 26px; flex: 1; min-width: 0; }
.meta-item { display: flex; flex-direction: column; gap: 1px; white-space: nowrap; }
.meta-label { font-size: 11px; color: var(--muted); }
.meta-item strong { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.head-actions { display: flex; align-items: center; gap: 10px; flex: none; }

.status-pill {
  font-size: 11.5px; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--grey-soft); color: var(--text-2);
  white-space: nowrap;
}
.status-pill.ok { background: #e9f7f1; border-color: #c8e9dc; color: #0f766e; }
.status-pill.loading { background: var(--accent-soft); border-color: #d5e2ff; color: var(--accent); }
.status-pill.error { background: #fdeceb; border-color: #f6cfcc; color: var(--up); }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-2);
  transition: background .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--grey-soft); border-color: #cdd7e5; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 10px; font-size: 12px; }

.error-bar {
  max-width: 1500px;
  margin: 14px auto 0;
  padding: 10px 14px;
  background: #fdeceb;
  border: 1px solid #f4c9c6;
  border-radius: 8px;
  color: #9b241c;
  display: flex; align-items: center; gap: 12px;
  font-size: 12.5px;
}
.error-bar span { flex: 1; }
.error-bar .btn { color: #9b241c; border-color: #eab5b1; }

/* ---------- 标签 ---------- */
.tabs { background: var(--card); border-bottom: 1px solid var(--line); }
.tabs-inner {
  max-width: 1500px; margin: 0 auto; padding: 0 24px;
  display: flex; gap: 4px;
}
.tab {
  border: 0; background: transparent;
  padding: 12px 16px;
  font-size: 13px; font-weight: 550; color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-2); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- 布局 ---------- */
.main { max-width: 1500px; margin: 0 auto; padding: 20px 24px 48px; }
.view { display: none; }
.view.active { display: block; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- 筛选 ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 128px; }
.field label { font-size: 11px; color: var(--muted); font-weight: 550; }
.field select, .field input {
  height: 32px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; font-size: 12.5px;
  outline: none; max-width: 100%;
}
.field select:focus, .field input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.field-grow { flex: 1; min-width: 200px; }
.field-wide { flex: 2; min-width: 260px; }
.align-end { margin-bottom: 1px; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat-label { font-size: 11.5px; color: var(--muted); font-weight: 550; }
.stat-value { font-size: 27px; font-weight: 650; line-height: 1.25; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.accent { color: var(--accent); }
.stat-value.warn { color: var(--warn); }
.stat-foot { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- 表格 ---------- */
.table-card { overflow: hidden; }
.table-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.table-title { font-size: 13.5px; font-weight: 650; }
.count { font-size: 11.5px; color: var(--muted); font-weight: 500; margin-left: 6px; font-variant-numeric: tabular-nums; }
.table-sub { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.table-scroll { max-height: 660px; overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f8fafc; text-align: left;
  padding: 9px 12px; font-size: 11.5px; font-weight: 600; color: var(--text-2);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f9fbfe; }
.col-series { width: 100px; }
.col-name { min-width: 230px; }
.col-sku { width: 132px; }
.col-price { width: 128px; text-align: right; }
.col-change { width: 132px; text-align: right; }
.col-source { width: 74px; }
.col-time { width: 132px; }
.col-link { width: 92px; }
th.col-price, th.col-change { text-align: right; }
td.col-price, td.col-change { text-align: right; font-variant-numeric: tabular-nums; }

.series-name { color: var(--text-2); white-space: nowrap; }
.config-name { color: var(--text); max-width: 420px; }
.sku-link {
  font-variant-numeric: tabular-nums; font-weight: 550;
  color: var(--accent); cursor: pointer; border: 0; background: transparent; padding: 0;
  text-align: left;
}
.sku-link:hover { text-decoration: underline; }
.price-value { font-weight: 650; font-size: 13px; font-variant-numeric: tabular-nums; }
.price-sub { font-size: 10.5px; color: var(--muted); }

.badge {
  display: inline-block; padding: 2px 7px; border-radius: 5px;
  font-size: 11px; font-weight: 550; white-space: nowrap;
}
.badge-oos { background: var(--warn-soft); color: var(--warn); }
.badge-pending { background: #fff6d9; color: #92690a; }
.badge-unclassified { background: var(--grey-soft); color: var(--text-2); }
.badge-none { background: transparent; color: var(--muted); border: 1px dashed #cbd5e1; }
.badge-auto { background: var(--auto-soft); color: var(--auto); }
.badge-manual { background: var(--manual-soft); color: var(--manual); }

.change-up { color: var(--up); font-weight: 600; }
.change-down { color: var(--down); font-weight: 600; }
.change-flat { color: var(--text-2); }
.change-none { color: var(--muted); }
.change-date { display: block; font-size: 10.5px; color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); }
.ext-link { font-size: 11.5px; white-space: nowrap; }
.evidence { max-width: 260px; color: var(--text-2); }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 12.5px; }

/* ---------- 趋势 ---------- */
.sku-head {
  padding: 14px 16px; margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
}
.sku-head-main { min-width: 0; }
.sku-head-title { font-size: 14px; font-weight: 650; }
.sku-head-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.sku-head-facts { display: flex; gap: 22px; flex-wrap: wrap; }
.fact-label { font-size: 10.5px; color: var(--muted); }
.fact-value { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

.trend-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; margin-bottom: 16px; }
.trend-stat { padding: 13px 16px; }
.trend-stat-head { font-size: 11.5px; font-weight: 650; margin-bottom: 8px; display: flex; align-items: center; gap: 7px; }
.trend-stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.trend-stat-cell .k { font-size: 10.5px; color: var(--muted); }
.trend-stat-cell .v { font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
.trend-stat-cell .d { font-size: 10.5px; color: var(--muted); }
.trend-change { margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line-soft); font-size: 12px; }

.chart-card { margin-bottom: 16px; overflow: hidden; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-line { width: 18px; height: 0; border-top: 2px solid var(--auto); display: inline-block; }
.legend-line.manual { border-top: 2px dashed var(--manual); }
.legend-mark { font-weight: 700; color: var(--warn); }
.chart { padding: 10px 14px 4px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart-note { padding: 0 16px 12px; font-size: 11px; color: var(--muted); }
.grid-line { stroke: #e9eef5; stroke-width: 1; }
.axis-line { stroke: #d9e1ec; stroke-width: 1; }
.axis-text { fill: #7a879b; font-size: 10px; font-family: inherit; }
.chart-empty-note { fill: #7a879b; font-size: 12px; font-family: inherit; }
.seg-auto { stroke: var(--auto); stroke-width: 2; fill: none; }
.seg-manual { stroke: var(--manual); stroke-width: 2; stroke-dasharray: 5 4; fill: none; }
.pt { stroke: #fff; stroke-width: 1.5; cursor: pointer; }
.pt-auto { fill: var(--auto); }
.pt-manual { fill: var(--manual); }
.break-mark { fill: var(--warn); font-size: 11px; font-weight: 700; }
.break-mark.muted-mark { fill: #94a3b8; }
.hover-col { fill: transparent; cursor: crosshair; }
.hover-col:hover { fill: rgba(37, 99, 235, .035); }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none;
  background: #1c2536; color: #f8fafc;
  border-radius: 7px; padding: 9px 11px;
  font-size: 11.5px; line-height: 1.6;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .24);
  max-width: 300px;
}
.tooltip .tt-title { font-weight: 650; margin-bottom: 3px; }
.tooltip .tt-row { color: #cbd5e1; }
.tooltip .tt-row b { color: #fff; font-weight: 600; }

/* ---------- 操作说明 ---------- */
.help-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.help-card { padding: 18px 20px; }
.help-card h2 { font-size: 14px; margin: 0 0 14px; font-weight: 650; }
.help-card dl { margin: 0; }
.help-card dt { font-size: 12.5px; font-weight: 650; color: var(--text-2); margin-top: 12px; }
.help-card dt:first-child { margin-top: 0; }
.help-card dd { margin: 3px 0 0; font-size: 12px; color: var(--text-2); line-height: 1.7; }

@media (max-width: 1100px) {
  .head-meta { gap: 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .help-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .head-meta { order: 3; width: 100%; flex-wrap: wrap; }
  .tabs-inner { padding: 0 12px; overflow-x: auto; }
  .main { padding: 16px 12px 32px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
