:root {
  --brand-orange: #ea580c;
  --brand-orange-light: #fff7ed;
  --brand-orange-mid: #fed7aa;
  --brand-orange-dark: #c2410c;
  --brand-dark: #3d3d3d;
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-strong: #111827;
  --muted: #6b7280;
  --muted2: #9ca3af;
  --star: #f59e0b;
  --margin-high: #065f46;
  --margin-mid: #92400e;
  --margin-low: #991b1b;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --crit: #dc2626;
  --crit-bg: #fff1f2;
  --crit-border: #fecdd3;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { border: 0; background: none; color: inherit; cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 52px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-logo { display: flex; align-items: center; gap: 10px; }
.brand-logo img { width: 40px; height: 40px; object-fit: contain; flex-shrink: 0; display: block; }
.brand-name { color: var(--text-strong); font-size: 14px; font-weight: 700; letter-spacing: .2px; }
.brand-tag { color: var(--muted); font-size: 11px; margin-top: 1px; }
.nav-actions { display: flex; align-items: center; gap: 10px; }
.nav-btn {
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 14px;
}
.nav-btn:hover { background: #e5e7eb; }
.nav-btn.primary { background: var(--brand-orange); border-color: var(--brand-orange); color: #fff; font-weight: 600; }

.summary-bar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  min-height: 61px;
  display: flex;
  align-items: stretch;
  gap: 0;
}
.alert-stat-btn {
  min-width: 220px;
  padding: 11px 24px;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  border-right: 1px solid var(--border);
  transition: background .15s;
}
.alert-stat-btn:hover,
.alert-stat-btn.active-spread,
.alert-stat-btn.active-lowstar { background: var(--brand-orange-light); }
.alert-stat-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f3f4f6;
  color: var(--brand-orange-dark);
  font-weight: 800;
}
.alert-stat-value { color: var(--text-strong); font-size: 22px; font-weight: 800; line-height: 1; }
.alert-stat-label { color: var(--muted); font-size: 11px; letter-spacing: .2px; margin-top: 3px; }
.alert-stat-label span { font-size: 10px; font-weight: 400; opacity: .75; }
.alert-stat-divider { width: 0; }
.sync-text { margin-left: auto; padding: 0 24px; display: flex; align-items: center; color: var(--muted); font-size: 12px; }
.sync-text strong { color: var(--text); margin-left: 4px; }

.alert-banner {
  padding: 9px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid;
  font-size: 12px;
  flex-wrap: wrap;
}
.alert-banner.warn { background: var(--warn-bg); border-color: var(--warn-border); color: #92400e; }
.alert-banner.crit { background: var(--crit-bg); border-color: var(--crit-border); color: #991b1b; }
.alert-banner-title { font-weight: 800; }
.alert-chips { display: flex; gap: 5px; flex-wrap: wrap; }
.alert-chip {
  background: #fff;
  border: 1px solid currentColor;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.alert-dismiss { margin-left: auto; font-size: 16px; opacity: .45; cursor: pointer; }

.main { display: flex; height: calc(100vh - 113px); min-height: 620px; }
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
}
.sidebar-section { margin-bottom: 20px; }
.sidebar-title {
  color: var(--muted2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .4px;
  padding: 0 16px 6px;
}
.sidebar-item {
  width: 100%;
  min-height: 33px;
  padding: 8px 16px 8px 19px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-left: 3px solid transparent;
  color: var(--text);
  text-align: left;
}
.sidebar-item:hover { background: var(--brand-orange-light); color: var(--brand-orange-dark); }
.sidebar-item.active {
  background: var(--brand-orange-light);
  border-left-color: var(--brand-orange);
  color: var(--brand-orange-dark);
  font-weight: 700;
}
.sidebar-badge {
  background: #e5e7eb;
  color: var(--muted);
  border-radius: 10px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
}
.sidebar-item.active .sidebar-badge { background: var(--brand-orange-mid); color: var(--brand-orange-dark); }
.rating-count.high { color: var(--margin-high); background: #dcfce7; }
.rating-count.mid { color: var(--margin-mid); background: #fef9c3; }
.rating-count.low { color: var(--margin-low); background: #fee2e2; }
.sidebar-item.active .rating-count.high { background: #bbf7d0; color: var(--margin-high); }
.sidebar-item.active .rating-count.mid { background: #fde68a; color: var(--margin-mid); }
.sidebar-item.active .rating-count.low { background: #fecaca; color: var(--margin-low); }

.content { flex: 1; overflow-y: auto; padding: 24px; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-box {
  flex: 1;
  min-width: 200px;
  max-width: 300px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; }
.search-box:focus-within { border-color: var(--brand-orange); box-shadow: 0 0 0 2px var(--brand-orange-mid); }
.filter-select {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  outline: 0;
}
.view-toggle { display: flex; background: #fff; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.view-btn { padding: 8px 12px; color: var(--muted); }
.view-btn.active { background: var(--brand-orange); color: #fff; }
.export-btn {
  margin-left: auto;
  background: var(--brand-orange);
  border-radius: 6px;
  color: #fff;
  font-weight: 700;
  padding: 8px 16px;
}
.export-btn:hover { background: var(--brand-orange-dark); }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.product-list { display: flex; flex-direction: column; gap: 12px; }
.product-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow .2s, transform .15s;
}
.product-card:hover { box-shadow: 0 6px 20px rgba(0,0,0,.09); transform: translateY(-2px); }
.product-card.selected { border-color: var(--brand-orange); box-shadow: 0 0 0 3px var(--brand-orange-mid); }
.card-img {
  width: 100%;
  height: 110px;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.card-img svg { width: 56px; height: 56px; opacity: .65; }
.product-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.product-img-card { width: 100%; height: 100%; padding: 8px; }
.product-img-list { width: 100%; height: 100%; padding: 6px; }
.product-img-panel { width: 100%; height: 100%; padding: 12px; }
.img-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
}
.rating-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
}
.rating-pill.high { background: #dcfce7; color: #15803d; }
.rating-pill.mid { background: #fef9c3; color: #a16207; }
.rating-pill.low { background: #fee2e2; color: #b91c1c; }
.card-body { padding: 12px 14px; }
.card-sku { color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .4px; margin-bottom: 2px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-name { color: var(--text-strong); font-size: 13px; font-weight: 700; line-height: 1.35; margin-bottom: 8px; min-height: 35px; }
.kpi-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.kpi-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f8fafc;
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 12px;
}
.kpi-chip.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; font-weight: 700; font-size: 11px; }
.kpi-label { color: var(--muted); font-size: 11px; }
.kpi-val { font-weight: 800; }
.stars { color: var(--star); }

.ch-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ch-table th {
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .4px;
  padding: 4px 6px;
  text-align: left;
  text-transform: uppercase;
}
.ch-table th:last-child { text-align: right; }
.ch-table td { border-bottom: 1px solid #f1f5f9; padding: 5px 6px; }
.ch-table tr:last-child td { border: 0; }
.ch-name-cell { display: flex; align-items: center; gap: 5px; }
.ch-dot, .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.price-cell { color: var(--text); font-weight: 800; }
.na-cell { color: #cbd5e1; }
.rating-cell { text-align: right; font-weight: 900; }
.compact-rating { white-space: nowrap; }
.rating-reviews { color: var(--muted); font-size: 10px; margin-left: 3px; }
.margin-cell { text-align: right; }
.margin-bar-wrap { display: flex; align-items: center; gap: 5px; justify-content: flex-end; }
.margin-bar-bg { width: 48px; height: 5px; background: #e2e8f0; border-radius: 3px; overflow: hidden; }
.margin-bar-fill { height: 100%; border-radius: 3px; }
.margin-text { min-width: 36px; text-align: right; font-size: 12px; font-weight: 800; }
.m-high { color: var(--margin-high); }
.m-mid { color: var(--margin-mid); }
.m-low { color: var(--margin-low); }
.card-footer {
  background: #fafafa;
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cogs-label { color: var(--muted); font-size: 11px; }
.detail-link { color: var(--brand-orange); font-size: 11px; font-weight: 700; }
.spread-alert-strip {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 8px;
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}
.spread-alert-strip.warn { background: var(--warn-bg); border-color: var(--warn-border); color: #92400e; }
.spread-alert-strip.crit { background: var(--crit-bg); border-color: var(--crit-border); color: #991b1b; }

.spread-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 1px solid;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
}
.spread-badge.warn { background: var(--warn-bg); border-color: var(--warn-border); color: #92400e; }
.spread-badge.crit { background: var(--crit-bg); border-color: var(--crit-border); color: #991b1b; }
.list-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  gap: 12px;
  cursor: pointer;
}
.list-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,.07); }
.list-img {
  width: 86px;
  height: 86px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.list-img svg { width: 48px; height: 48px; opacity: .65; }
.list-body { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 14px; min-width: 0; }
.list-name { color: var(--text-strong); font-weight: 800; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-sku { color: var(--muted); font-size: 11px; margin-top: 2px; }
.list-kpis { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.list-channels { display: flex; gap: 7px; flex-wrap: wrap; }
.list-ch-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #f8fafc;
  padding: 3px 6px;
  font-size: 11px;
}
.lch-name { color: var(--muted); }
.lch-price, .lch-rating { font-weight: 800; }
.list-summary { min-width: 120px; text-align: right; }
.list-best-margin, .list-best-rating { font-size: 24px; font-weight: 900; }
.list-best-label { color: var(--muted); font-size: 11px; letter-spacing: .2px; }

.detail-panel {
  width: 420px;
  max-width: 42vw;
  background: #fff;
  border-left: 1px solid var(--border);
  display: none;
  overflow-y: auto;
  flex-shrink: 0;
}
.detail-panel.open { display: block; }
.panel-header {
  height: 52px;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
}
.panel-title { font-size: 13px; font-weight: 800; letter-spacing: .4px; }
.close-btn { color: var(--muted); font-size: 22px; line-height: 1; }
.panel-img { height: 140px; display: grid; place-items: center; }
.panel-img svg { width: 76px; height: 76px; opacity: .68; }
.panel-body { padding: 18px; }
.panel-sku { color: var(--muted); font-size: 11px; font-weight: 600; margin-bottom: 3px; display: flex; align-items: center; gap: 8px; }
.panel-name { color: var(--text-strong); font-size: 19px; font-weight: 800; line-height: 1.25; margin-bottom: 8px; }
.panel-kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.panel-kpi {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 8px;
  text-align: center;
  background: #fafafa;
}
.panel-kpi-val { font-size: 17px; font-weight: 900; }
.panel-kpi-lbl { color: var(--muted); font-size: 10px; margin-top: 2px; }
.panel-section { margin-top: 18px; }
.panel-section-title { color: var(--text-strong); font-size: 12px; font-weight: 900; letter-spacing: .4px; margin-bottom: 10px; }
.margin-summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.msummary-card { border: 1px solid var(--border); border-radius: 8px; background: #f8fafc; padding: 10px; }
.msummary-val { font-size: 18px; font-weight: 900; }
.msummary-lbl { color: var(--muted); font-size: 11px; margin-top: 2px; }
.panel-ch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}
.panel-ch-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.panel-ch-info { flex: 1; min-width: 0; }
.panel-ch-name { font-weight: 900; }
.panel-ch-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 900;
  text-align: left;
}
.panel-ch-link::after {
  content: "↗";
  color: var(--muted2);
  font-size: 10px;
  font-weight: 800;
}
.panel-ch-link:hover {
  text-decoration: underline;
}
.panel-ch-rating { color: var(--muted); font-size: 11px; margin-top: 3px; }
.panel-ch-right { min-width: 118px; text-align: right; }
.panel-ch-price { font-size: 15px; font-weight: 900; }
.panel-alert-box { border: 1px solid; border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; }
.panel-alert-box.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.panel-alert-box.crit { background: var(--crit-bg); border-color: var(--crit-border); }
.panel-alert-title { font-size: 12px; font-weight: 900; margin-bottom: 8px; }
.panel-alert-box.warn .panel-alert-title { color: var(--warn); }
.panel-alert-box.crit .panel-alert-title { color: var(--crit); }
.panel-alert-row { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid rgba(0,0,0,.05); padding: 4px 0; font-size: 12px; }
.panel-alert-row span:first-child { color: var(--muted); }
.panel-alert-row span:last-child { font-weight: 800; text-align: right; }
.panel-alert-rec { margin-top: 8px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.brand-badge {
  border: 1px solid;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  letter-spacing: .2px;
  white-space: nowrap;
}
.empty-state {
  grid-column: 1 / -1;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

@media (max-width: 960px) {
  .main { height: auto; min-height: calc(100vh - 113px); }
  .sidebar { display: none; }
  .detail-panel { position: fixed; inset: 52px 0 0 auto; width: min(420px, 100vw); max-width: none; z-index: 120; box-shadow: -20px 0 40px rgba(0,0,0,.12); }
  .summary-bar { flex-wrap: wrap; }
  .sync-text { width: 100%; min-height: 34px; justify-content: flex-end; border-top: 1px solid var(--border); }
}
