:root {
  --bg: #f1f3f6;
  --panel: #ffffff;
  --ink: #162136;
  --muted: #687386;
  --line: #dde2e9;
  --accent: #e6522c;
  --accent-dark: #bd3e20;
  --accent-soft: #fff0eb;
  --success: #16785d;
  --warning: #ad651b;
  --danger: #b42318;
  --radius: 14px;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--bg); }
button, select, input { font: inherit; }
button, select { min-height: 42px; }
button { cursor: pointer; }

.shell { display: grid; grid-template-columns: 72px 1fr; min-height: 100dvh; }
.rail {
  position: sticky; top: 0; height: 100dvh; padding: 20px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 30px;
  color: #fff; background: #172234;
}
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; font-weight: 800; font-size: 22px; background: var(--accent);
}
.rail nav { display: grid; gap: 12px; }
.nav-icon {
  width: 40px; border: 0; border-radius: 12px; color: #aeb8c8; background: transparent;
}
.nav-icon.active, .nav-icon:hover { color: #fff; background: #2a384e; }
.rail-foot { margin-top: auto; writing-mode: vertical-rl; letter-spacing: .16em; font-size: 10px; color: #7f8da1; }

main { width: min(1500px, 100%); margin: 0 auto; padding: 32px 36px 20px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.kicker { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .18em; }
h1 { margin: 0; font-size: clamp(28px, 3vw, 42px); letter-spacing: -.04em; }
.subtitle { margin: 8px 0 0; color: var(--muted); }
.status-panel { text-align: right; }
.api-status { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px rgba(22,120,93,.12); }
.api-status.success { color: var(--success); }
.api-status.loading { color: var(--warning); }
.api-status.error { color: var(--danger); }
#updatedAt { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

.controls {
  display: flex; align-items: end; gap: 14px; padding: 16px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.controls label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
select { min-width: 150px; padding: 0 36px 0 12px; color: var(--ink); border: 1px solid #cfd5dd; border-radius: 9px; background: #fff; }
.toggle-row { grid-template-columns: auto auto; align-items: center; margin-left: auto; padding-bottom: 11px; }
.toggle-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.primary-button {
  padding: 0 18px; border: 0; border-radius: 9px; color: #fff; font-weight: 800; background: var(--accent);
}
.primary-button:hover { background: var(--accent-dark); }
.primary-button:active { transform: translateY(1px); }

.error-banner {
  margin-top: 16px; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between;
  border: 1px solid #f3b6af; border-radius: var(--radius); color: var(--danger); background: #fff4f2;
}
.error-banner p { margin: 4px 0 0; font-size: 13px; }
.error-banner button { border: 1px solid currentColor; border-radius: 8px; color: inherit; background: transparent; }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.metric {
  min-height: 130px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.metric-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-value { margin: 13px 0 8px; font-size: clamp(22px, 2.1vw, 31px); font-weight: 800; letter-spacing: -.035em; white-space: nowrap; }
.metric-note { color: var(--success); font-size: 12px; }

.analysis-grid, .table-grid { display: grid; gap: 14px; margin-top: 14px; }
.analysis-grid { grid-template-columns: minmax(0, 2fr) minmax(280px, .8fr); }
.table-grid { grid-template-columns: 1.2fr .8fr; }
.panel { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.panel-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; font-size: 17px; }
.panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.legend { color: var(--muted); font-size: 12px; }
.sales-key { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 3px; background: var(--accent); }

.trend-chart { height: 230px; display: grid; grid-template-columns: repeat(var(--points, 12), 1fr); align-items: end; gap: 8px; border-bottom: 1px solid var(--line); }
.trend-column { height: 100%; display: flex; flex-direction: column; justify-content: end; align-items: center; gap: 7px; }
.trend-bar { width: min(28px, 70%); min-height: 3px; border-radius: 5px 5px 0 0; background: var(--accent); transition: height .35s ease; }
.trend-label { color: var(--muted); font-size: 10px; white-space: nowrap; }

.alerts { display: grid; gap: 12px; }
.alert { padding: 14px; border-left: 3px solid var(--warning); border-radius: 8px; background: #fff8ed; }
.alert.info { border-left-color: var(--success); background: #edf8f4; }
.alert strong { display: block; font-size: 13px; }
.alert p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 0 10px 10px; color: var(--muted); text-align: right; font-size: 11px; }
th:first-child, td:first-child { text-align: left; }
td { padding: 13px 10px; border-top: 1px solid #edf0f3; text-align: right; white-space: nowrap; }
.product-list { display: grid; }
.product-row { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid #edf0f3; }
.product-row:first-child { border-top: 0; }
.rank { color: var(--muted); font-weight: 800; }
.product-name { font-size: 13px; font-weight: 700; }
.product-sales { color: var(--muted); font-size: 12px; }
.pill { padding: 4px 8px; border-radius: 999px; color: var(--success); font-size: 11px; font-weight: 800; background: #edf8f4; }
.pill.关注 { color: var(--warning); background: #fff5e6; }
.pill.观察 { color: var(--danger); background: #fff0ee; }

.skeleton { position: relative; overflow: hidden; color: transparent; background: #e8ebef; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.72), transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { 100% { transform: translateX(100%); } }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 20px 2px 0; color: var(--muted); font-size: 11px; }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .table-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .rail { position: static; width: 100%; height: 58px; padding: 8px 14px; flex-direction: row; justify-content: space-between; }
  .rail nav { display: flex; }
  .rail-foot { display: none; }
  main { padding: 22px 14px; }
  .topbar { align-items: start; }
  .status-panel { text-align: left; }
  .controls { align-items: stretch; flex-direction: column; }
  .toggle-row { margin-left: 0; padding: 5px 0; }
  select { width: 100%; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analysis-grid { grid-template-columns: 1fr; }
  .trend-chart { gap: 3px; }
  footer, .topbar { flex-direction: column; }
}
@media (max-width: 390px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric { min-height: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
