:root {
  --bg: #f3f8fb;
  --surface: #ffffff;
  --surface-soft: #eaf5fa;
  --ink: #142230;
  --muted: #657383;
  --line: #d4e5ef;
  --accent: #269DD0;
  --accent-2: #1f6fb2;
  --warn: #b45309;
  --good: #15803d;
  --bad: #b91c1c;
  --shadow: 0 12px 30px rgba(20, 64, 92, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  color: #f8fafc;
  background: #132b3b;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 4px;
  color: #a9b6c3;
  font-size: 12px;
}

.panel-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  color: #dbe7f1;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.nav-item.active {
  color: #ffffff;
  background: rgba(38, 157, 208, 0.95);
}

.nav-item:disabled {
  color: #788899;
  cursor: not-allowed;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.2;
}

.topbar p,
.panel-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.sync-button {
  height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(38, 157, 208, 0.42);
  border-radius: 8px;
  color: #ffffff;
  background: #269dd0;
  font-weight: 700;
  cursor: pointer;
}

.sync-button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.sync-status {
  color: #64748b;
}

.sync-status.running {
  color: #b45309;
}

.sync-status.success {
  color: #047857;
}

.sync-status.failed {
  color: #dc2626;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

.filters,
.summary-strip,
.kpi-grid,
.content-grid,
.section-head {
  margin-bottom: 16px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(190px, 1fr));
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.filter-group {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.date-group {
  grid-column: span 2;
}

.filter-group.wide {
  grid-column: span 2;
}

.hidden-control {
  display: none;
}

.filter-group label,
.table-tools label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.date-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.date-pair span {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 6px;
  max-height: 98px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  color: var(--ink);
  font-weight: 500;
}

.check-grid input {
  width: 14px;
  min-height: 14px;
  flex: 0 0 auto;
}

.check-grid span {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.section-head h2 {
  font-size: 18px;
}

.section-head p {
  color: var(--muted);
  font-size: 13px;
}

.ad-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.ad-block:first-child {
  grid-column: 1 / -1;
}

.ad-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.subsection-title {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.summary-item,
.kpi-card,
.chart-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-item {
  min-height: 64px;
  padding: 12px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-item strong {
  display: block;
  overflow: visible;
  margin-top: 8px;
  font-size: 16px;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi-card {
  min-height: 120px;
  padding: 15px;
}

.kpi-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-value {
  margin-top: 12px;
  font-size: 23px;
  font-weight: 850;
  line-height: 1.15;
}

.kpi-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.delta {
  font-weight: 800;
}

.delta.good {
  color: var(--good);
}

.delta.bad {
  color: var(--bad);
}

.delta.neutral {
  color: var(--muted);
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.span-2 {
  grid-column: span 2;
}

.chart-panel,
.table-panel {
  padding: 12px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head.stacked {
  align-items: flex-start;
  flex-direction: column;
}

.panel-head h2 {
  font-size: 17px;
}

.panel-head select {
  max-width: 132px;
}

.metric-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.metric-checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font-size: 12px;
  cursor: pointer;
}

.metric-group {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  padding-right: 8px;
}

.metric-group > strong {
  color: var(--accent-2);
  font-size: 12px;
}

.calc-badge {
  display: inline-grid;
  width: 14px;
  height: 14px;
  margin-left: 3px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--accent);
  font-size: 10px;
  font-weight: 900;
  cursor: help;
}

.metric-checks input {
  width: 14px;
  min-height: 14px;
}

canvas {
  display: block;
  width: 100%;
  height: 280px;
}

#trendChart,
#storeTrendChart {
  height: 320px;
}

.rank-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 12px;
  align-items: stretch;
}

.rank-layout.scroll-rank {
  max-height: 430px;
  overflow-y: auto;
  padding-right: 4px;
}

.rank-layout.scroll-rank::-webkit-scrollbar {
  width: 8px;
}

.rank-layout.scroll-rank::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #cbd5e1;
}

.rank-side {
  overflow: visible;
  border: 0;
  background: transparent;
  position: relative;
}

.rank-side-head,
.rank-side-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rank-side-head {
  position: absolute;
  top: -22px;
  left: 0;
  right: 0;
  min-height: 26px;
  padding: 0 2px;
  color: #334155;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}

.rank-side-body {
  display: grid;
  height: 100%;
  padding: 12px 0 10px;
}

.rank-side-row {
  min-height: 0;
  padding: 0 2px;
  border-top: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.2;
  align-items: center;
}

.rank-side-row span {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
}

.chart-tooltip {
  position: fixed;
  z-index: 50;
  display: none;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.92);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.2);
  font-size: 12px;
  pointer-events: none;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 4px;
}

.table-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.table-tools select {
  width: 118px;
}

.table-tools input {
  width: 180px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.analysis-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.analysis-tools label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.analysis-tools input,
.analysis-tools select {
  min-height: 34px;
  width: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
}

.selected-products {
  min-height: 32px;
  padding: 7px 10px;
  border: 1px dashed rgba(38, 157, 208, 0.55);
  border-radius: 8px;
  color: #1f6fb2;
  background: rgba(38, 157, 208, 0.08);
  font-size: 12px;
  font-weight: 800;
}

.product-id-button,
.category-button,
.product-name-button {
  border: 0;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--accent-2);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.product-id-button:hover,
.product-id-button.selected,
.category-button:hover,
.category-button.selected,
.product-name-button:hover,
.product-name-button.selected {
  color: #ffffff;
  background: var(--accent);
}

.product-link {
  color: #1f6fb2;
  font-weight: 800;
  text-decoration: none;
}

.product-id-link {
  margin-left: 6px;
  color: #1f6fb2;
  font-weight: 800;
  text-decoration: none;
}

.product-link:hover,
.product-id-link:hover {
  color: #269dd0;
  text-decoration: underline;
}

.product-trend-table-wrap {
  max-height: 56vh;
}

.product-trend-table {
  min-width: 2520px;
}

.product-trend-table thead th {
  position: sticky;
  top: 0;
  z-index: 16;
}

.product-trend-parent td {
  background: #f7fbfd;
  font-weight: 800;
}

.product-trend-child td:first-child {
  padding-left: 28px;
  color: var(--muted);
}

.model-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.model-table-wrap {
  overflow: auto;
  max-height: 430px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.model-table {
  min-width: 1120px;
}

.text-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.text-button:hover {
  background: #1f84b0;
}

.detail-delta-panel {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 10px 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fbfd;
}

.detail-delta-panel > span {
  flex: 0 0 auto;
  padding-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-delta-panel .metric-checks {
  flex: 1;
}

.model-delta-panel {
  display: block;
  width: 100%;
}

.model-delta-panel summary {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.model-delta-panel .metric-checks {
  margin-top: 8px;
}

.table-wrap {
  overflow: auto;
  max-height: 70vh;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.category-table-wrap {
  max-height: 48vh;
}

table {
  width: 100%;
  min-width: 1320px;
  table-layout: auto;
  border-collapse: collapse;
}

.model-table {
  min-width: 1120px;
}

.volume-table {
  min-width: 1280px;
}

.volume-table-wrap {
  max-height: 62vh;
}

.volume-reference-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.volume-reference-grid .table-panel:first-child {
  grid-row: span 2;
}

.volume-mini-table-wrap {
  max-height: 360px;
}

.compact-volume-table {
  min-width: 760px;
}

.volume-table th:nth-child(n),
.volume-table td:nth-child(n) {
  left: auto;
  width: auto;
  min-width: 0;
  box-shadow: none;
}

.volume-table th:first-child,
.volume-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  width: 180px;
  min-width: 180px;
  background: #ffffff;
  text-align: left;
  box-shadow: 8px 0 12px rgba(15, 23, 42, 0.08);
}

.volume-table th:first-child {
  z-index: 13;
  background: var(--surface-soft);
}

.volume-table .table-summary-row td:first-child {
  z-index: 10;
  background: #e5f4fb;
}

.volume-select-row {
  cursor: pointer;
}

.volume-select-row:hover td {
  background: rgba(38, 157, 208, 0.06);
}

.volume-select-row.selected td {
  background: rgba(38, 157, 208, 0.13);
}

.model-table th:nth-child(-n + 4),
.model-table td:nth-child(-n + 4) {
  left: auto;
  box-shadow: none;
}

.model-table td:nth-child(2) {
  max-width: none;
  white-space: normal;
  min-width: 280px;
}

.model-row {
  cursor: pointer;
}

.model-row:hover td {
  background: rgba(38, 157, 208, 0.06);
}

.model-row.selected td {
  background: rgba(38, 157, 208, 0.12);
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font-size: 12px;
  cursor: pointer;
}

.model-chip span:nth-child(2) {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
}

.chip-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 999px;
}

th,
td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-size: 12px;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

th {
  position: sticky;
  top: 0;
  z-index: 8;
  color: #334155;
  background: var(--surface-soft);
  font-size: 12px;
}

td:first-child,
td:nth-child(2),
td:nth-child(3),
td:nth-child(4),
th:first-child,
th:nth-child(2),
th:nth-child(3),
th:nth-child(4) {
  text-align: left;
}

td:nth-child(2) {
  max-width: none;
  overflow: visible;
  text-overflow: clip;
}

th:nth-child(-n + 4),
td:nth-child(-n + 4) {
  position: sticky;
  z-index: 2;
  background: #ffffff;
}

th:nth-child(-n + 4) {
  z-index: 12;
  background: var(--surface-soft);
}

th:nth-child(1),
td:nth-child(1) {
  left: 0;
  width: 120px;
  min-width: 120px;
}

th:nth-child(2),
td:nth-child(2) {
  left: 120px;
  width: 240px;
  min-width: 240px;
}

th:nth-child(3),
td:nth-child(3) {
  left: 360px;
  width: 100px;
  min-width: 100px;
}

th:nth-child(4),
td:nth-child(4) {
  left: 460px;
  width: 100px;
  min-width: 100px;
  box-shadow: 8px 0 12px rgba(15, 23, 42, 0.08);
}

.fixed-cols-1 th:nth-child(n + 2),
.fixed-cols-1 td:nth-child(n + 2),
.fixed-cols-3 th:nth-child(n + 4),
.fixed-cols-3 td:nth-child(n + 4) {
  position: static;
  box-shadow: none;
  text-align: right;
}

.fixed-cols-1 th:nth-child(1),
.fixed-cols-1 td:nth-child(1) {
  width: 180px;
  min-width: 180px;
}

.fixed-cols-3 th:nth-child(1),
.fixed-cols-3 td:nth-child(1) {
  width: 260px;
  min-width: 260px;
}

.fixed-cols-3 th:nth-child(2),
.fixed-cols-3 td:nth-child(2) {
  left: 260px;
  width: 150px;
  min-width: 150px;
}

.fixed-cols-3 th:nth-child(3),
.fixed-cols-3 td:nth-child(3) {
  left: 410px;
  width: 110px;
  min-width: 110px;
  box-shadow: 8px 0 12px rgba(15, 23, 42, 0.08);
}

.fixed-cols-1 td:nth-child(1),
.fixed-cols-3 td:nth-child(1),
.fixed-cols-4 td:nth-child(2) {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.metric-col {
  width: auto;
  min-width: 98px;
}

.metric-delta {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 4px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  vertical-align: middle;
}

.metric-delta.good {
  color: var(--good);
  background: rgba(21, 128, 61, 0.1);
}

.metric-delta.bad {
  color: var(--bad);
  background: rgba(185, 28, 28, 0.1);
}

.metric-delta.neutral {
  color: var(--muted);
  background: rgba(100, 116, 139, 0.12);
}

.table-summary-row td {
  position: sticky;
  bottom: 0;
  z-index: 7;
  border-top: 2px solid rgba(38, 157, 208, 0.24);
  color: #0f3f56;
  background: #eef8fc;
  font-weight: 900;
}

.table-summary-row td:nth-child(-n + 4) {
  z-index: 9;
  background: #e5f4fb;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .panel-nav {
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    overflow: auto;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .filters,
  .summary-strip,
  .kpi-grid,
  .kpi-grid.compact,
  .ad-sections,
  .volume-reference-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .rank-layout {
    grid-template-columns: 1fr;
  }

  .filter-group.wide,
  .date-group,
  .span-2 {
    grid-column: auto;
  }

  .date-pair {
    grid-template-columns: 1fr;
  }
}


.metric-col-base {
  background: #ffffff;
}

.metric-col-engagement {
  background: #f2fbff;
}

.metric-col-total {
  background: #eef8fc;
}

.metric-col-onsite {
  background: #fff7ed;
}

.metric-col-offsite {
  background: #f8fafc;
}

th.metric-col-base,
th.metric-col-engagement,
th.metric-col-total,
th.metric-col-onsite,
th.metric-col-offsite {
  color: #0f172a;
  font-weight: 700;
}

th.metric-col-engagement {
  box-shadow: inset 3px 0 0 #269DD0;
}

th.metric-col-total {
  box-shadow: inset 3px 0 0 #0f766e;
}

th.metric-col-onsite {
  box-shadow: inset 3px 0 0 #f59e0b;
}

th.metric-col-offsite {
  box-shadow: inset 3px 0 0 #64748b;
}
