/* === CSS Variables & Reset === */
:root {
  --bg-deep: #080c18;
  --bg-card: #0f1528;
  --bg-card-hover: #141b33;
  --bg-elevated: #1a2340;
  --border: rgba(99, 130, 255, 0.08);
  --border-hover: rgba(99, 130, 255, 0.18);

  --text-primary: #e8ecf4;
  --text-secondary: #8892aa;
  --text-muted: #4e5872;

  --blue: #4c7cff;
  --blue-light: #6b99ff;
  --blue-glow: rgba(76, 124, 255, 0.15);
  --green: #34d399;
  --green-glow: rgba(52, 211, 153, 0.12);
  --amber: #f5a623;
  --amber-glow: rgba(245, 166, 35, 0.12);
  --purple: #a78bfa;
  --purple-glow: rgba(167, 139, 250, 0.12);
  --red: #f87171;

  --funnel-1: #4c7cff;
  --funnel-2: #38bdf8;
  --funnel-3: #34d399;
  --funnel-4: #f5a623;
  --funnel-5: #f87171;

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow-card: 0 2px 20px rgba(0,0,0,0.35), 0 0 0 1px var(--border);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle background mesh */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 10%, rgba(76,124,255,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 90%, rgba(167,139,250,0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.dashboard {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}

/* === Header === */
.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.header-name {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1;
}

.header-cn {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin-left: 10px;
  vertical-align: baseline;
  letter-spacing: 0.08em;
}

.header-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 5px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.updated-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.refresh-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.refresh-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-glow);
}
.refresh-btn.spinning svg {
  animation: spin 0.8s ease;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === KPI Grid === */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: cardIn 0.5s ease both;
}
.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card), 0 8px 32px rgba(0,0,0,0.2);
}

.kpi-accent {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}
[data-accent="blue"] .kpi-accent { background: linear-gradient(90deg, var(--blue), var(--blue-light)); }
[data-accent="green"] .kpi-accent { background: linear-gradient(90deg, #22c55e, var(--green)); }
[data-accent="amber"] .kpi-accent { background: linear-gradient(90deg, #f59e0b, var(--amber)); }
[data-accent="purple"] .kpi-accent { background: linear-gradient(90deg, #8b5cf6, var(--purple)); }

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 500;
  margin-bottom: 10px;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.9rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
}
[data-accent="green"] .kpi-value { color: var(--green); }
[data-accent="amber"] .kpi-value { color: var(--amber); }

.kpi-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
  font-family: var(--font-mono);
}

/* === Cards === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-card);
  animation: cardIn 0.5s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.card-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  background: var(--blue-glow);
  color: var(--blue);
  border: 1px solid rgba(76,124,255,0.15);
}

/* === Main Grid: Funnel + Distribution === */
.main-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* Funnel */
.funnel-card {
  animation-delay: 0.2s;
}

.funnel-summary {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.funnel-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.funnel-stage {
  display: grid;
  grid-template-columns: 100px 1fr 90px;
  align-items: center;
  gap: 14px;
  height: 38px;
  animation: funnelBarIn 0.6s ease both;
}
.funnel-stage:nth-child(1) { animation-delay: 0.3s; }
.funnel-stage:nth-child(2) { animation-delay: 0.38s; }
.funnel-stage:nth-child(3) { animation-delay: 0.46s; }
.funnel-stage:nth-child(4) { animation-delay: 0.54s; }
.funnel-stage:nth-child(5) { animation-delay: 0.62s; }

@keyframes funnelBarIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

.funnel-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-align: right;
  font-weight: 500;
}

.funnel-bar-track {
  height: 28px;
  background: var(--bg-elevated);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.funnel-bar-fill {
  height: 100%;
  border-radius: 6px;
  position: relative;
  min-width: 4px;
  transition: width 1s cubic-bezier(0.22, 0.61, 0.36, 1);
  display: flex;
  align-items: center;
  padding-left: 10px;
}

.funnel-bar-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
}

.funnel-amount {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-align: right;
  font-weight: 500;
}

.funnel-opps {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.funnel-opps-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
  font-weight: 600;
}

.opp-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 3px;
  transition: background 0.15s;
}
.opp-item:hover {
  background: var(--bg-elevated);
}

.opp-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.opp-customer {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.opp-amount {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--blue-light);
}

.opp-status {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 100px;
  font-weight: 500;
  white-space: nowrap;
}
.opp-status[data-status="需求引导"] { background: rgba(76,124,255,0.12); color: var(--blue); }
.opp-status[data-status="客户立项"] { background: rgba(56,189,248,0.12); color: #38bdf8; }
.opp-status[data-status="客户选定"] { background: rgba(52,211,153,0.12); color: var(--green); }
.opp-status[data-status="客户成交"] { background: rgba(245,166,35,0.12); color: var(--amber); }
.opp-status[data-status="机会失败"] { background: rgba(248,113,113,0.08); color: var(--red); }

/* Distribution */
.dist-card {
  animation-delay: 0.25s;
  display: flex;
  flex-direction: column;
}

.dist-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-elevated);
  border-radius: 6px;
  padding: 2px;
}

.dist-tab {
  font-size: 0.72rem;
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-body);
  font-weight: 500;
}
.dist-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.dist-tab:hover:not(.active) {
  color: var(--text-secondary);
}

.dist-chart-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 10px 0;
}

.dist-chart-area canvas {
  max-height: 220px;
}

.dist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 8px;
}

.dist-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.dist-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.dist-legend-count {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-primary);
}

.dist-total {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 10px;
  text-align: center;
}

/* === Bottom Grid: Leads + Activity === */
.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Leads */
.leads-card {
  animation-delay: 0.3s;
}

.leads-list {
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elevated) transparent;
}
.leads-list::-webkit-scrollbar { width: 4px; }
.leads-list::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }

.lead-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  animation: fadeInUp 0.4s ease both;
}
.lead-item:last-child { border-bottom: none; }
.lead-item:hover { background: var(--bg-elevated); }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.lead-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber-glow);
}

.lead-info {
  flex: 1;
  min-width: 0;
}

.lead-company {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  gap: 8px;
}

.lead-source {
  font-size: 0.65rem;
  padding: 1px 7px;
  border-radius: 100px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* Activity */
.activity-card {
  animation-delay: 0.35s;
}

.activity-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.activity-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.stat-icon {
  font-size: 0.85rem;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.stat-count {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.activity-timeline {
  max-height: 270px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elevated) transparent;
}
.activity-timeline::-webkit-scrollbar { width: 4px; }
.activity-timeline::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }

.timeline-item {
  display: grid;
  grid-template-columns: 50px 18px 1fr;
  gap: 8px;
  padding: 8px 0;
  align-items: start;
  animation: fadeInUp 0.4s ease both;
}

.timeline-time {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--text-muted);
  text-align: right;
  padding-top: 3px;
}

.timeline-dot-line {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 4px;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
  flex-shrink: 0;
}
.timeline-dot[data-type="电话"] { background: var(--green); }
.timeline-dot[data-type="微信"] { background: #22d3ee; }
.timeline-dot[data-type="线上会议"] { background: var(--purple); }
.timeline-dot[data-type="现场拜访"] { background: var(--amber); }
.timeline-dot[data-type="邮件"] { background: #fb923c; }

.timeline-line {
  width: 1px;
  flex: 1;
  background: var(--border);
  min-height: 20px;
  margin-top: 4px;
}

.timeline-content {
  padding-bottom: 6px;
}

.timeline-type {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--blue);
  margin-bottom: 2px;
}
.timeline-type[data-type="电话"] { color: var(--green); }
.timeline-type[data-type="微信"] { color: #22d3ee; }
.timeline-type[data-type="线上会议"] { color: var(--purple); }
.timeline-type[data-type="现场拜访"] { color: var(--amber); }
.timeline-type[data-type="邮件"] { color: #fb923c; }

.timeline-customer {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
}

.timeline-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Placeholders */
.placeholder-msg {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
}

.error-msg {
  font-size: 0.82rem;
  color: var(--red);
  text-align: center;
  padding: 20px 0;
}

/* Responsive */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .main-grid { grid-template-columns: 1fr; }
  .bottom-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .dashboard { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .header-name { font-size: 1.5rem; }
  .kpi-value { font-size: 1.4rem; }
  .funnel-stage { grid-template-columns: 70px 1fr 70px; }
}