:root {
  --ink: #191b20;
  --muted: #737985;
  --line: #e6e8ec;
  --canvas: #f4f5f7;
  --card: #ffffff;
  --sidebar: #111318;
  --sidebar-soft: #1b1e25;
  --primary: #5b5ce2;
  --primary-soft: #eeeeff;
  --cyan: #0f9f9a;
  --amber: #d68b16;
  --rose: #d64d6f;
  --red: #d74242;
  --green: #218a63;
  --shadow: 0 1px 2px rgba(15, 17, 21, 0.05), 0 8px 30px rgba(15, 17, 21, 0.04);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, select, input { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 18px 22px;
  background: var(--sidebar);
  color: #f7f7f8;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 30px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: #f0a23c; color: #111318; font-size: 18px; font-weight: 900;
}
.brand strong { display: block; letter-spacing: 0.12em; font-size: 13px; }
.brand span { display: block; margin-top: 3px; color: #888e9b; font-size: 8px; letter-spacing: 0.22em; }

.nav { display: grid; gap: 6px; }
.nav-item {
  width: 100%; padding: 12px 14px; border: 0; border-radius: 11px;
  display: flex; align-items: center; gap: 12px; color: #989eaa; background: transparent; text-align: left;
  transition: 160ms ease;
}
.nav-item:hover { color: #fff; background: #181b21; }
.nav-item.active { color: #fff; background: var(--sidebar-soft); box-shadow: inset 3px 0 #f0a23c; }
.nav-icon { width: 22px; font-size: 17px; text-align: center; }

.sidebar-bottom { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid #252932; }
.demo-badge { color: #d8dbe2; font-size: 10px; letter-spacing: 0.13em; font-weight: 700; }
.demo-badge span { display: inline-block; width: 7px; height: 7px; background: #f0a23c; border-radius: 50%; margin-right: 6px; }
.sidebar-bottom p { margin: 10px 0 0; color: #6f7582; font-size: 11px; line-height: 1.6; }

.workspace { min-width: 0; }
.topbar {
  height: 72px; padding: 0 34px; position: sticky; top: 0; z-index: 9;
  background: rgba(255, 255, 255, 0.95); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.mobile-brand { display: none; font-weight: 900; letter-spacing: 0.1em; }
.store-switcher { display: flex; align-items: center; gap: 11px; }
.store-avatar { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: #111318; color: #fff; font-size: 10px; font-weight: 800; }
.store-switcher strong, .store-switcher small { display: block; }
.store-switcher strong { font-size: 13px; }
.store-switcher small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.chevron { color: var(--muted); margin-left: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.sync-state { display: grid; grid-template-columns: auto auto; column-gap: 6px; align-items: center; }
.sync-state i { width: 7px; height: 7px; background: #36a478; border-radius: 50%; grid-row: span 2; }
.sync-state span { font-size: 11px; font-weight: 650; }
.sync-state small { color: var(--muted); font-size: 9px; }
.icon-button, .user-button {
  width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
.icon-button { font-size: 18px; }
.user-button { border-color: #272a31; background: #272a31; color: #fff; font-size: 11px; font-weight: 750; }

.content { max-width: 1560px; margin: 0 auto; padding: 32px 34px 64px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 7px; color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(25px, 3vw, 34px); line-height: 1.12; letter-spacing: -0.035em; }
.page-subtitle { margin: 9px 0 0; color: var(--muted); line-height: 1.55; }
.head-actions { display: flex; gap: 10px; }
.select, .secondary-button, .primary-button {
  height: 38px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 0 13px; color: var(--ink);
}
.primary-button { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 650; }
.secondary-button:hover, .select:hover { border-color: #c9ccd3; }

.grid { display: grid; gap: 16px; }
.kpi-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 16px; }
.main-grid { grid-template-columns: minmax(0, 1.7fr) minmax(330px, 0.8fr); margin-bottom: 16px; }
.two-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.diagnosis-grid { grid-template-columns: 290px minmax(0, 1fr); align-items: start; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.kpi-card { padding: 17px 18px; min-height: 118px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { color: var(--muted); font-size: 11px; font-weight: 650; }
.kpi-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.kpi-value { margin-top: 15px; font-size: 25px; font-weight: 760; letter-spacing: -0.04em; }
.delta { display: inline-flex; gap: 3px; align-items: center; margin-top: 7px; font-size: 10px; font-weight: 700; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--muted); }
.delta-note { color: #a0a4ad; font-weight: 450; margin-left: 4px; }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.card-head h2 { margin: 0; font-size: 15px; letter-spacing: -0.01em; }
.card-head p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 10px; }
.legend span::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 5px; background: var(--primary); }
.legend span:last-child::before { background: #cfd2d9; }

.trend-card { min-height: 350px; }
.chart-wrap { width: 100%; height: 250px; }
.chart-wrap svg { width: 100%; height: 100%; overflow: visible; }
.chart-grid-line { stroke: #eceef2; stroke-width: 1; }
.chart-axis-label { fill: #9ba0aa; font-size: 9px; }
.chart-axis-unit { fill: var(--primary); font-size: 9px; font-weight: 700; }
.chart-axis-unit.secondary { fill: #8e929c; }
.chart-area { fill: rgba(91, 92, 226, 0.09); }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.chart-secondary-line { fill: none; stroke: #a8acb6; stroke-width: 1.8; stroke-dasharray: 4 4; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { fill: #fff; stroke: var(--primary); stroke-width: 2; }

.alert-list { display: grid; gap: 10px; }
.alert-item { padding: 13px 14px; display: grid; grid-template-columns: 8px 1fr; gap: 12px; border: 1px solid var(--line); border-radius: 11px; }
.alert-bar { width: 8px; border-radius: 6px; background: var(--amber); }
.alert-item.critical .alert-bar { background: var(--red); }
.alert-item.high .alert-bar { background: var(--rose); }
.alert-item h3 { margin: 0; font-size: 12px; }
.alert-item p { margin: 5px 0 8px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.text-link { border: 0; padding: 0; color: var(--primary); background: none; font-size: 10px; font-weight: 700; }

.table-card { overflow: hidden; }
.table-card .card-head { padding: 20px 20px 0; }
.data-table { width: 100%; border-collapse: collapse; }
.ads-table-card { overflow-x: auto; }
.ads-table { min-width: 1320px; }
.daily-funnel-card { overflow-x: auto; }
.daily-funnel-table { min-width: 820px; }
.ad-daily-funnel-table { min-width: 1080px; }
.ad-daily-funnel-card .card-head { align-items: flex-end; gap: 16px; }
.ad-daily-funnel-card .campaign-select { max-width: 420px; }
.campaign-row { cursor: pointer; }
.campaign-row.selected { background: #f1f1ff; }
.daily-funnel-metric strong, .daily-funnel-metric small { display: block; }
.daily-funnel-metric strong { font-size: 12px; }
.daily-funnel-metric small { margin-top: 4px; color: var(--muted); font-size: 8px; white-space: nowrap; }
.data-table th { padding: 10px 14px; color: var(--muted); background: #fafafb; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; text-align: right; }
.data-table th:first-child, .data-table td:first-child { text-align: left; padding-left: 20px; }
.data-table td { padding: 14px; border-bottom: 1px solid #f0f1f3; text-align: right; font-size: 11px; }
.data-table tbody tr { transition: background 120ms ease; }
.data-table tbody tr:hover { background: #fafaff; }
.product-cell { display: flex; align-items: center; gap: 11px; min-width: 220px; }
.product-glyph { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 11px; background: var(--primary); }
.product-glyph.cyan { background: var(--cyan); }
.product-glyph.amber { background: var(--amber); }
.product-glyph.rose { background: var(--rose); }
.product-glyph.red { background: var(--red); }
.product-cell strong, .product-cell small { display: block; }
.product-cell strong { font-size: 11px; }
.product-cell small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.status-pill { padding: 4px 7px; border-radius: 999px; background: #f1f2f4; color: #686e78; font-size: 9px; font-weight: 700; }
.status-pill.紧急 { background: #fff0f0; color: var(--red); }
.status-pill.需优化, .status-pill.高消耗, .status-pill.需关注 { background: #fff7e8; color: #a9690d; }
.score { font-weight: 780; }
.score.high { color: var(--red); }

.funnel { display: grid; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 52px minmax(0, 1fr) 72px; gap: 10px; align-items: center; }
.funnel-label { color: var(--muted); font-size: 10px; }
.funnel-track { height: 26px; background: #f0f1f5; border-radius: 7px; overflow: hidden; }
.funnel-fill { height: 100%; min-width: 7px; background: var(--primary); border-radius: 7px; }
.funnel-value { text-align: right; font-size: 11px; font-weight: 700; }

.product-list { padding: 9px; position: sticky; top: 92px; }
.product-list-title { padding: 11px 11px 8px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.product-list-button { width: 100%; border: 0; background: transparent; padding: 11px; border-radius: 11px; display: flex; gap: 10px; align-items: center; text-align: left; }
.product-list-button:hover { background: #f6f6f8; }
.product-list-button.active { background: var(--primary-soft); }
.product-list-button .product-glyph { width: 32px; height: 32px; flex: none; }
.product-list-button strong { display: block; font-size: 11px; }
.product-list-button small { display: block; color: var(--muted); font-size: 9px; margin-top: 3px; }

.product-hero { padding: 22px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.product-identity { display: flex; gap: 14px; align-items: center; }
.product-identity .product-glyph { width: 50px; height: 50px; border-radius: 13px; font-size: 14px; }
.product-identity h2 { margin: 0; font-size: 18px; }
.product-identity p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.hero-stat { display: flex; gap: 26px; }
.hero-stat div { text-align: right; }
.hero-stat small, .hero-stat strong { display: block; }
.hero-stat small { color: var(--muted); font-size: 9px; }
.hero-stat strong { margin-top: 5px; font-size: 16px; }

.price-overview { margin: -4px 0 16px; padding: 16px 18px; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
.price-metric { padding-right: 12px; border-right: 1px solid var(--line); }
.price-metric:nth-of-type(6) { border-right: 0; }
.price-metric small, .price-metric strong, .price-metric span { display: block; }
.price-metric small { color: var(--muted); font-size: 9px; }
.price-metric strong { margin-top: 7px; font-size: 15px; }
.price-metric.primary strong { color: var(--primary); }
.price-metric.unavailable strong { color: #a7abb4; }
.price-metric span { margin-top: 4px; color: var(--muted); font-size: 8px; }
.price-note { grid-column: 1 / -1; margin: 0; padding-top: 11px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; line-height: 1.5; }

.mini-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.mini-card { padding: 15px 16px; }
.mini-card span { color: var(--muted); font-size: 10px; }
.mini-card strong { display: block; margin-top: 10px; font-size: 20px; }

.ai-card { padding: 20px; border-left: 4px solid var(--primary); }
.ai-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.ai-title { display: flex; align-items: center; gap: 9px; font-weight: 750; }
.ai-spark { width: 25px; height: 25px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.confidence { padding: 4px 7px; border-radius: 999px; background: #eef8f3; color: var(--green); font-size: 9px; font-weight: 750; }
.ai-summary { margin: 15px 0 12px; line-height: 1.7; font-size: 13px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 5px 8px; border-radius: 7px; background: #f3f4f6; color: #686e78; font-size: 9px; }

.timeline { position: relative; display: grid; gap: 12px; padding-left: 18px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 1px; background: #dfe1e6; }
.timeline-item { position: relative; padding: 12px 14px; background: #fafafb; border: 1px solid #eceef1; border-radius: 10px; }
.timeline-item::before { content: ""; position: absolute; left: -18px; top: 17px; width: 9px; height: 9px; border: 2px solid #fff; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 1px #dfe1e6; }
.timeline-title { display: flex; align-items: center; gap: 7px; }
.timeline-item strong { font-size: 11px; }
.timeline-title span { padding: 2px 5px; border-radius: 5px; background: var(--primary-soft); color: var(--primary); font-size: 8px; font-weight: 700; }
.timeline-item small { margin-left: auto; color: var(--muted); font-size: 9px; }
.timeline-item p { margin: 7px 0 0; color: var(--muted); font-size: 10px; }
.timeline-note { margin: 12px 0 0; padding: 9px 11px; border-radius: 8px; background: #f5f6f8; color: var(--muted); font-size: 9px; line-height: 1.5; }
.compact-empty { min-height: 170px; }
.compact-empty .timeline-note { max-width: 310px; text-align: center; }

.source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.source-card { padding: 17px; }
.source-card .source-name { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.source-quality { padding: 2px 6px; border-radius: 999px; background: #f1f2f4; color: #686e78; font-size: 8px; font-weight: 700; }
.source-card.complete .source-quality { background: #eaf7f1; color: var(--green); }
.source-card.residual .source-quality { background: #fff7e8; color: #a9690d; }
.source-share { font-size: 24px; font-weight: 780; margin: 13px 0 8px; }
.source-bar { height: 5px; border-radius: 4px; background: #eceef2; overflow: hidden; }
.source-bar span { display: block; height: 100%; background: var(--primary); }
.source-card.residual .source-bar span { background: var(--amber); }
.source-delta { min-height: 14px; margin-top: 7px; color: var(--muted); font-size: 8px; }
.source-meta { margin-top: 12px; display: flex; justify-content: space-between; font-size: 9px; color: var(--muted); }
.data-gap-note { padding: 13px 14px; border: 1px dashed #d9dbe1; border-radius: 11px; background: #fafafb; }
.data-gap-note strong { font-size: 10px; }
.data-gap-note p { margin: 5px 0 0; color: var(--muted); font-size: 9px; line-height: 1.55; }

.health-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.health-card { padding: 20px; }
.health-top { display: flex; justify-content: space-between; align-items: center; }
.health-indicator { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px #eaf7f1; }
.health-card h3 { margin: 17px 0 5px; font-size: 14px; text-transform: capitalize; }
.health-card p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.progress { margin-top: 15px; height: 5px; background: #eceef2; border-radius: 5px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--green); }

.empty-state, .loading-state { min-height: 480px; display: grid; place-items: center; align-content: center; color: var(--muted); }
.loader { width: 30px; height: 30px; border: 3px solid #e2e4e8; border-top-color: var(--primary); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; background: #202229; color: #fff; border-radius: 10px; padding: 11px 15px; font-size: 11px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: 180ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }

.notice {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(214, 139, 22, .28);
  border-radius: 12px;
  background: rgba(214, 139, 22, .08);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .source-grid, .health-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding: 22px 10px; }
  .brand { justify-content: center; padding: 0 0 26px; }
  .brand > div:last-child, .nav-item span:last-child, .sidebar-bottom p { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .sidebar-bottom { padding: 14px 0 0; text-align: center; }
  .demo-badge { font-size: 0; }
  .main-grid, .two-grid, .diagnosis-grid { grid-template-columns: 1fr; }
  .product-list { position: static; display: flex; overflow-x: auto; }
  .product-list-title { display: none; }
  .product-list-button { min-width: 190px; }
}

@media (max-width: 640px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: 62px; padding: 7px 12px; flex-direction: row; z-index: 30; }
  .brand, .sidebar-bottom { display: none; }
  .nav { width: 100%; grid-template-columns: repeat(5, 1fr); gap: 2px; }
  .nav-item { padding: 7px; display: grid; place-items: center; gap: 0; }
  .nav-item span:last-child { display: block; font-size: 8px; }
  .nav-icon { font-size: 15px; }
  .nav-item.active { box-shadow: inset 0 -2px #f0a23c; }
  .topbar { height: 60px; padding: 0 16px; }
  .store-switcher, .sync-state { display: none; }
  .mobile-brand { display: block; }
  .content { padding: 24px 16px 90px; }
  .page-head { display: block; }
  .head-actions { margin-top: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mini-metrics, .source-grid, .health-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data-table { min-width: 760px; }
  .table-card { overflow-x: auto; }
  .product-hero { display: block; }
  .hero-stat { margin-top: 20px; justify-content: flex-start; }
  .hero-stat div { text-align: left; }
  .price-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .price-metric { border-right: 0; }
}
