:root {
  --bg: #f2f6fb;
  --surface: #ffffff;
  --surface-soft: #f7faff;
  --ink: #10213f;
  --muted: #6f7f98;
  --line: #e3eaf3;
  --blue: #1769e0;
  --blue-dark: #0d3f91;
  --cyan: #23a6d5;
  --navy: #123f70;
  --orange: #f08b3e;
  --shadow: 0 10px 30px rgba(30, 66, 112, 0.08);
  --radius: 18px;
  --font: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, #eaf2ff 0, #f5f8fc 220px, var(--bg) 100%);
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { max-width: 1600px; margin: 0 auto; padding: 18px 26px 34px; }

.topbar {
  position: sticky;
  top: 10px;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 72px;
  padding: 0 22px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 38px rgba(22, 70, 133, 0.1);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, var(--blue), var(--blue-dark));
  box-shadow: 0 8px 16px rgba(23, 105, 224, 0.22);
  font-weight: 800;
}
.brand div { display: grid; gap: 2px; }
.brand strong { font-size: 16px; letter-spacing: 0.02em; }
.brand span:last-child { color: #8b99ad; font-size: 9px; letter-spacing: 0.12em; }

.nav-tabs { display: flex; align-self: stretch; gap: 34px; }
.nav-tab {
  position: relative;
  padding: 0 3px;
  border: 0;
  color: #65748b;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
}
.nav-tab::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--blue);
  transform: scaleX(0);
  transition: transform 160ms ease;
}
.nav-tab.active { color: var(--blue); }
.nav-tab.active::after { transform: scaleX(1); }

.topbar-status {
  display: flex;
  justify-self: end;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #29b978;
  box-shadow: 0 0 0 5px rgba(41, 185, 120, 0.1);
}

main { padding-top: 28px; }
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 0 4px;
}
.eyebrow, .panel-kicker {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
}
.page-heading h1 { margin: 0; font-size: 30px; letter-spacing: -0.03em; }
.page-heading p:last-child { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.heading-meta { display: flex; gap: 9px; align-items: center; padding: 0; border: none; border-radius: 0; color: var(--muted); background: transparent; font-size: 13px; }
.panel-unit, .ai-badge {
  padding: 6px 10px;
  border: 1px solid #dce6f4;
  border-radius: 999px;
  color: #61738f;
  background: #f8fbff;
  font-size: 11px;
}

.filter-panel {
  display: grid;
  grid-template-columns: 1.5fr 1.15fr 1.15fr 1fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.filter-panel label { display: grid; gap: 7px; }
.filter-panel label span { color: #586a85; font-size: 12px; font-weight: 600; }
/* 日期范围：两个原生date框合并成一个外框 */
.date-range {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 10px;
  border: 1px solid #dce5f1;
  border-radius: 10px;
  background: #fbfdff;
}
.date-range:focus-within { border-color: #79aef1; box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.08); }
.date-range input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.date-range input:focus { border: 0; box-shadow: none; }
.date-range em { flex: 0 0 auto; color: #8a98aa; font-style: normal; font-size: 12px; }
input, select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #dce5f1;
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  background: #fbfdff;
}
input:focus, select:focus { border-color: #79aef1; box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.08); }
.custom-select-wrap { position: relative; width: 100%; }
.custom-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  display: none;
  width: 100%;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: 6px 0;
  border: 1px solid #dce5f1;
  border-radius: 10px;
  list-style: none;
  color: var(--ink);
  background: #fbfdff;
  box-shadow: 0 8px 24px rgba(22, 70, 133, 0.12);
}
.custom-dropdown.open { display: block; }
.custom-dropdown li {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 12px;
}
.custom-dropdown li:hover { background: #eaf3ff; }
.custom-dropdown .no-match { color: #8a98aa; cursor: default; }
.custom-dropdown .no-match:hover { background: transparent; }
.primary-button {
  height: 42px;
  padding: 0 22px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, #1e72e8, #1257bc);
  box-shadow: 0 8px 18px rgba(23, 105, 224, 0.2);
  font-weight: 700;
}

.metric-grid { display: grid; grid-template-columns: 1fr 1fr 1fr 1.35fr; gap: 14px; }
.metric-grid.three { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
.metric-grid.four { grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; }
.metric-card {
  position: relative;
  display: flex;
  min-height: 164px;
  overflow: hidden;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metric-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--blue);
}
.metric-card.cyan::before { background: var(--cyan); }
.metric-card.navy::before { background: var(--navy); }
.metric-card.insight-card::before { background: var(--orange); }
.metric-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  margin-right: 16px;
  border-radius: 14px;
  color: var(--blue);
  background: #eaf3ff;
  font-size: 20px;
  font-weight: 800;
}
.cyan .metric-icon { color: #1284ae; background: #e6f8fd; }
.navy .metric-icon { color: var(--navy); background: #e9f0f8; }
.metric-content { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.metric-label { color: #5d6f89; font-size: 13px; font-weight: 650; }
.metric-content strong { margin-top: 12px; font-size: clamp(27px, 2.2vw, 38px); letter-spacing: -0.035em; }
.metric-content small { margin-top: auto; color: #7b8aa0; font-size: 11px; }
.mini-progress { height: 5px; margin: 9px 0 8px; overflow: hidden; border-radius: 5px; background: #e7eef7; }
.mini-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--cyan); }
.quarter-progress {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}
.quarter-labels {
  position: relative;
  height: 16px;
}
.quarter-labels span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  color: #1a3350;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.quarter-labels span:first-child {
  transform: translateX(-30%);
}
.quarter-labels span:last-child {
  transform: translateX(-70%);
}
.quarter-track-single {
  display: flex;
  height: 12px;
  overflow: hidden;
  border-radius: 12px;
}
.quarter-seg {
  height: 100%;
}
.quarter-seg.seg-1 {
  background: linear-gradient(90deg, #196fe5, #67adfa);
}
.quarter-seg.seg-2 {
  background: linear-gradient(90deg, #1592c0, #58c5df);
}
.quarter-seg.seg-3 {
  background: linear-gradient(90deg, #e67e22, #f39c12);
}
.quarter-seg.seg-4 {
  background: linear-gradient(90deg, #27ae60, #2ecc71);
}
.insight-card { background: linear-gradient(145deg, #f9fbff, #fffaf6); }
.insight-title { display: flex; align-items: center; justify-content: space-between; }
.ai-badge { border-color: #ffe1cb; color: #bd6424; background: #fff6ef; }
.insight-card p { margin: 16px 0 12px; color: #30435f; font-size: 14px; font-weight: 600; line-height: 1.65; }

.dashboard-row { display: grid; gap: 14px; margin-top: 14px; }
.two-column { grid-template-columns: 1fr 1fr; }
.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-head h2 { margin: 0; font-size: 19px; letter-spacing: -0.02em; }
.rank-chart { display: grid; gap: 10px; min-height: 360px; align-content: start; }
.rank-row {
  display: grid;
  grid-template-columns: 28px minmax(130px, 0.72fr) 1.3fr 96px;
  gap: 10px;
  align-items: center;
  min-height: 38px;
}
.rank-number {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  color: #75859d;
  background: #f0f4f9;
  font-size: 11px;
  font-weight: 700;
}
.rank-row:nth-child(-n+3) .rank-number { color: #fff; background: var(--blue); }
.rank-label { min-width: 0; }
.rank-name { overflow: hidden; color: #263956; font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.rank-meta { overflow: hidden; margin-top: 3px; color: #8a98aa; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; overflow: hidden; border-radius: 9px; background: #edf2f7; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #196fe5, #55a3ff); }
.realtime .bar-fill { background: linear-gradient(90deg, #126eae, #38b8d8); }
.rank-value { color: #243751; font-size: 12px; font-weight: 750; text-align: right; }
.empty-state {
  display: grid;
  place-items: center;
  min-height: 320px;
  padding: 30px;
  border: 1px dashed #d7e1ee;
  border-radius: 14px;
  color: #7d8ca2;
  background: #fafcff;
  text-align: center;
  line-height: 1.6;
}

.trend-row .panel { min-height: 420px; }
.trend-chart { height: 330px; }
.industry-chart {
  display: grid;
  gap: 12px;
  min-height: 330px;
  align-content: start;
}
.chart-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.axis-line { stroke: #dfe7f0; stroke-width: 1; }
.grid-line { stroke: #edf1f6; stroke-width: 1; stroke-dasharray: 4 5; }
.axis-label { fill: #8492a6; font-size: 10px; }
.value-label { fill: #263a57; font-size: 10px; font-weight: 700; }
.mom-label { fill: #1682a8; font-size: 9px; font-weight: 800; }
.trend-line { fill: none; stroke: var(--blue); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.trend-area { fill: url(#areaGradient); }
.trend-point { fill: #fff; stroke: var(--blue); stroke-width: 3; }
.industry-row {
  display: grid;
  grid-template-columns: 32px minmax(118px, 0.8fr) minmax(120px, 1.2fr) 92px;
  gap: 10px;
  align-items: center;
  min-height: 28px;
}
.industry-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  color: #2474d8;
  background: #eaf3ff;
}
.industry-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.industry-name {
  overflow: hidden;
  color: #30435f;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.industry-row strong {
  color: #263956;
  font-size: 11px;
  text-align: right;
}

.secondary-view .panel { margin-top: 0; }
.summary-card { min-height: 124px; }
.summary-card strong { font-size: 30px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 12px 10px; border-bottom: 1px solid #edf1f6; text-align: left; white-space: nowrap; }
th { color: #687a94; background: #f8faff; font-size: 11px; }
td { color: #30425d; }
.status-normal { color: #158a5a; font-weight: 700; }
.customer-distribution-head,
.customer-distribution-row {
  display: grid;
  grid-template-columns: minmax(250px, 1.45fr) 82px 112px 112px;
  gap: 14px;
  align-items: center;
}
.customer-distribution-head {
  margin: -4px 0 10px;
  padding: 0 8px 10px;
  border-bottom: 1px solid #edf1f6;
  color: #7b8ba1;
  font-size: 10px;
  font-weight: 700;
  text-align: right;
}
.customer-distribution-head span:first-child { text-align: left; }
.range-inline {
  margin-left: 10px;
  padding: 3px 10px;
  border: 1px solid #c8d4e3;
  border-radius: 999px;
  background: #f5f8fc;
  color: #4a6fa5;
  font-size: 11px;
  font-weight: 600;
}
.customer-distribution { display: grid; gap: 9px; }
.customer-distribution-row {
  min-height: 42px;
  padding: 3px 8px;
  border-bottom: 1px solid #f1f4f8;
}
.customer-distribution-row {
  grid-template-columns: 26px minmax(140px, 0.72fr) minmax(110px, 1fr) 72px 102px 102px;
}
.customer-industry-label {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  color: #30435f;
  font-size: 12px;
  font-weight: 700;
}
.customer-industry-label > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.customer-distribution-row > strong {
  color: #263956;
  font-size: 11px;
  text-align: right;
}

.error-banner {
  margin-bottom: 14px;
  padding: 12px 15px;
  border: 1px solid #ffd1ca;
  border-radius: 12px;
  color: #b33a2e;
  background: #fff6f4;
  font-size: 13px;
}
.loading-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(238, 244, 252, 0.7);
  backdrop-filter: blur(5px);
}
.loading-card {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 18px 22px;
  border: 1px solid #dfe8f5;
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid #dbe9fa;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: 1fr auto; }
  .nav-tabs { grid-row: 2; grid-column: 1 / -1; justify-content: center; height: 46px; margin-top: 4px; }
  .topbar-status { grid-column: 2; grid-row: 1; }
  .filter-panel { grid-template-columns: repeat(3, 1fr); }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
  .app-shell { padding: 10px 12px 26px; }
  .topbar { top: 5px; padding: 12px 14px 0; }
  .brand span:last-child, .topbar-status { display: none; }
  .nav-tabs { gap: 22px; overflow-x: auto; justify-content: flex-start; }
  main { padding-top: 20px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 12px; }
  .filter-panel { grid-template-columns: repeat(2, 1fr); }
  .two-column { grid-template-columns: 1fr; }
  .rank-row { grid-template-columns: 25px minmax(120px, 0.9fr) 1fr 78px; gap: 7px; }
  .metric-grid.three, .metric-grid.four { grid-template-columns: repeat(2, 1fr); }
  .customer-distribution-head { display: none; }
  .customer-distribution-row {
    grid-template-columns: 26px minmax(120px, 1fr) 84px 84px;
  }
  .customer-distribution-row .bar-track { grid-column: 2 / -1; grid-row: 2; }
  .customer-distribution-row > strong:nth-of-type(1) { grid-column: 3; grid-row: 1; }
  .customer-distribution-row > strong:nth-of-type(2) { grid-column: 2 / 4; grid-row: 3; text-align: left; }
  .customer-distribution-row > strong:nth-of-type(2)::before { content: "总消耗 "; color: #8a98aa; font-weight: 500; }
  .customer-distribution-row > strong:nth-of-type(3) { grid-column: 4; grid-row: 3; }
  .customer-distribution-row > strong:nth-of-type(3)::before { content: "客均 "; color: #8a98aa; font-weight: 500; }
}

@media (max-width: 540px) {
  .filter-panel, .metric-grid, .metric-grid.three, .metric-grid.four { grid-template-columns: 1fr; }
  .heading-meta { display: none; }
  .metric-card { min-height: 132px; }
  .rank-row { grid-template-columns: 25px minmax(0, 1fr) 70px; }
  .rank-row .bar-track { grid-column: 2 / -1; }
  .rank-value { grid-column: 3; grid-row: 1; }
  .industry-row { grid-template-columns: 28px minmax(100px, 1fr) 76px; }
  .industry-row .bar-track { grid-column: 2 / -1; }
  .industry-row strong { grid-column: 3; grid-row: 1; }
  .customer-distribution-row {
    grid-template-columns: 26px minmax(0, 1fr) 70px;
  }
  .customer-distribution-row > strong:nth-of-type(1) { grid-column: 3; }
  .customer-distribution-row > strong:nth-of-type(2) { grid-column: 2 / -1; }
  .customer-distribution-row > strong:nth-of-type(3) { grid-column: 2 / -1; grid-row: 4; text-align: left; }
}
