<template>
  <el-dialog :visible.sync="visibleSync" title="会员画像" :width="'1400px'" append-to-body
    custom-class="member-portrait-dialog" :close-on-click-modal="false" @closed="handleClosed">
    <div v-loading="loading" class="portrait-wrapper">
      <!-- 顶部：基础信息栏 -->
      <div class="portrait-header">
        <div class="header-main">
          <div class="member-name">{{ baseInfo.MemberName || '—' }}</div>
          <div class="member-meta">
            <span class="meta-item">
              <i class="el-icon-phone"></i>
              {{ baseInfo.Mobile || '—' }}
            </span>
            <span class="meta-item">
              <i class="el-icon-office-building"></i>
              {{ baseInfo.StoreName || '—' }}
            </span>
            <span class="meta-item" v-if="baseInfo.Channel">
              <i class="el-icon-connection"></i>
              {{ baseInfo.Channel }}
            </span>
          </div>
        </div>
        <div class="header-stats">
          <div class="stat-item">
            <div class="stat-label">剩余权益</div>
            <div class="stat-value highlight">￥{{ formatMoney(behaviorSummary.RemainingRightsAmount) }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">累计开单</div>
            <div class="stat-value">￥{{ formatMoney(behaviorSummary.TotalBillingAmount) }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">累计消耗</div>
            <div class="stat-value">￥{{ formatMoney(behaviorSummary.TotalConsumeAmount) }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">沉睡天数</div>
            <div class="stat-value" :class="{ 'text-warning': baseInfo.SleepDays > 30 }">
              {{ baseInfo.SleepDays || 0 }} 天
            </div>
          </div>
        </div>
      </div>

      <!-- 基础信息区域（独立于标签页） -->
      <div class="base-info-section">
        <div class="base-info-layout">
          <!-- 会员类型 -->
          <div class="card-section">
            <div class="section-title">
              <i class="el-icon-collection-tag"></i>
              会员类型
            </div>
            <div class="tag-list">
              <div v-for="type in baseInfo.MemberTypes" :key="type.TypeName" class="member-type-item">
                <el-tag :type="getMemberTypeTagType(type.TypeName)" size="medium" class="member-type-tag">
                  {{ type.TypeName }}
                </el-tag>
                <span class="member-type-date" v-if="type.BecomeTime">
                  {{ formatDate(type.BecomeTime) }}
                </span>
              </div>
              <span v-if="!baseInfo.MemberTypes || baseInfo.MemberTypes.length === 0" class="text-muted">无</span>
            </div>
          </div>

          <!-- 基础信息 -->
          <div class="card-section">
            <div class="section-title">
              <i class="el-icon-info"></i>
              基础信息
            </div>
            <div class="info-list">
              <div class="info-item">
                <span class="info-label">会员编码：</span>
                <span class="info-value">{{ baseInfo.MemberCode || '—' }}</span>
              </div>
              <div class="info-item">
                <span class="info-label">首次到店：</span>
                <span class="info-value">{{ formatDateTime(baseInfo.FirstVisitTime) }}</span>
              </div>
              <div class="info-item">
                <span class="info-label">最后到店：</span>
                <span class="info-value">{{ formatDateTime(baseInfo.LastVisitTime) }}</span>
              </div>
              <div class="info-item">
                <span class="info-label">消费等级：</span>
                <span class="info-value">{{ getConsumeLevelText(baseInfo.ConsumeLevel) }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 选项卡内容 -->
      <el-tabs v-model="activeTab" class="portrait-tabs">
        <!-- 概览 -->
        <el-tab-pane label="概览" name="overview">
          <div class="tab-content">
            <!-- 消费行为 -->
            <div class="card-section">
              <div class="section-title">
                <i class="el-icon-shopping-cart-full"></i>
                消费行为
              </div>
              <div class="behavior-grid">
                <div class="behavior-item">
                  <div class="behavior-label">开单次数</div>
                  <div class="behavior-value">{{ behaviorSummary.BillingCount || 0 }}</div>
                </div>
                <div class="behavior-item">
                  <div class="behavior-label">消耗次数</div>
                  <div class="behavior-value">{{ behaviorSummary.ConsumeCount || 0 }}</div>
                </div>
                <div class="behavior-item">
                  <div class="behavior-label">退卡次数</div>
                  <div class="behavior-value">{{ behaviorSummary.RefundCount || 0 }}</div>
                </div>
                <div class="behavior-item">
                  <div class="behavior-label">平均开单金额</div>
                  <div class="behavior-value">￥{{ formatMoney(behaviorSummary.AvgBillingAmount) }}</div>
                </div>
                <div class="behavior-item">
                  <div class="behavior-label">平均消耗金额</div>
                  <div class="behavior-value">￥{{ formatMoney(behaviorSummary.AvgConsumeAmount) }}</div>
                </div>
                <div class="behavior-item">
                  <div class="behavior-label">最近开单</div>
                  <div class="behavior-value">{{ formatDateTime(behaviorSummary.LastBillingTime) }}</div>
                </div>
                <div class="behavior-item">
                  <div class="behavior-label">最近消耗</div>
                  <div class="behavior-value">{{ formatDateTime(behaviorSummary.LastConsumeTime) }}</div>
                </div>
                <div class="behavior-item">
                  <div class="behavior-label">首次开单</div>
                  <div class="behavior-value">{{ formatDateTime(behaviorSummary.FirstBillingTime) }}</div>
                </div>
                <div class="behavior-item">
                  <div class="behavior-label">首次消耗</div>
                  <div class="behavior-value">{{ formatDateTime(behaviorSummary.FirstConsumeTime) }}</div>
                </div>
              </div>
            </div>

            <!-- 近12个月趋势图 -->
            <div class="card-section">
              <div class="section-title">
                <i class="el-icon-data-line"></i>
                近12个月消费趋势
              </div>
              <div ref="trendChart" class="trend-chart"></div>
            </div>

            <!-- 消费分析 -->
            <div v-if="consumptionAnalysis" class="card-section">
              <div class="section-title">
                <i class="el-icon-data-analysis"></i>
                消费分析
              </div>
              <div class="analysis-layout">
                <div class="analysis-item">
                  <div class="analysis-label">消费频率</div>
                  <div class="analysis-value">{{ formatMoney(consumptionAnalysis.ConsumeFrequency) }} 次/月</div>
                </div>
                <div class="analysis-item">
                  <div class="analysis-label">开单频率</div>
                  <div class="analysis-value">{{ formatMoney(consumptionAnalysis.BillingFrequency) }} 次/月</div>
                </div>
                <div class="analysis-item">
                  <div class="analysis-label">消费活跃度</div>
                  <div class="analysis-value">
                    <el-tag :type="consumptionAnalysis.IsActive ? 'success' : 'info'" size="small">
                      {{ consumptionAnalysis.IsActive ? '活跃' : '不活跃' }}
                    </el-tag>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-tab-pane>

        <!-- 权益明细 -->
        <el-tab-pane label="权益明细" name="assets">
          <div class="tab-content">
            <div class="card-section">
              <div class="section-title">
                <i class="el-icon-wallet"></i>
                权益明细
              </div>
              <el-table :data="remainingItems" size="small" border stripe>
                <el-table-column prop="ItemName" label="品项名称" min-width="140" />
                <el-table-column prop="SourceType" label="来源类型" width="90" />
                <el-table-column prop="UnitPrice" label="单价" width="90">
                  <template slot-scope="scope">￥{{ formatMoney(scope.row.UnitPrice) }}</template>
                </el-table-column>
                <el-table-column prop="TotalQuantity" label="总数量" width="80" />
                <el-table-column prop="ConsumedQuantity" label="已消费" width="80" />
                <el-table-column prop="RefundedQuantity" label="已退款" width="80" />
                <el-table-column prop="DeductedQuantity" label="已扣除" width="80" />
                <el-table-column prop="RemainingQuantity" label="剩余" width="80" />
                <el-table-column prop="RemainingValue" label="剩余价值" width="120">
                  <template slot-scope="scope">￥{{ formatMoney(scope.row.RemainingValue) }}</template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-tab-pane>

        <!-- 开单列表 -->
        <el-tab-pane label="开单列表" name="billing">
          <div class="tab-content">
            <el-table v-loading="billingLoading" :data="billingList" size="small" border stripe>
              <el-table-column prop="BillingDate" label="开单日期" width="160">
                <template slot-scope="scope">{{ formatDateTime(scope.row.BillingDate) }}</template>
              </el-table-column>
              <el-table-column prop="StoreName" label="门店" width="150" />
              <el-table-column prop="Amount" label="实付金额" width="120">
                <template slot-scope="scope">￥{{ formatMoney(scope.row.Amount) }}</template>
              </el-table-column>
              <el-table-column prop="DebtAmount" label="欠款金额" width="120">
                <template slot-scope="scope">￥{{ formatMoney(scope.row.DebtAmount) }}</template>
              </el-table-column>
              <el-table-column prop="ActivityName" label="活动名称" min-width="150" />
            </el-table>
            <div class="pagination-bar">
              <el-pagination layout="total, sizes, prev, pager, next" :page-sizes="[10, 20, 50]"
                :total="billingPagination.total" :current-page="billingPagination.pageIndex"
                :page-size="billingPagination.pageSize" @size-change="handleBillingSizeChange"
                @current-change="handleBillingPageChange" />
            </div>
          </div>
        </el-tab-pane>

        <!-- 消耗列表 -->
        <el-tab-pane label="消耗列表" name="consume">
          <div class="tab-content">
            <el-table v-loading="consumeLoading" :data="consumeList" size="small" border stripe>
              <el-table-column prop="ConsumeDate" label="消耗日期" width="160">
                <template slot-scope="scope">{{ formatDateTime(scope.row.ConsumeDate) }}</template>
              </el-table-column>
              <el-table-column prop="StoreName" label="门店" width="150" />
              <el-table-column prop="Amount" label="消耗金额" width="120">
                <template slot-scope="scope">￥{{ formatMoney(scope.row.Amount) }}</template>
              </el-table-column>
              <el-table-column prop="LaborCost" label="手工费" width="120">
                <template slot-scope="scope">￥{{ formatMoney(scope.row.LaborCost) }}</template>
              </el-table-column>
            </el-table>
            <div class="pagination-bar">
              <el-pagination layout="total, sizes, prev, pager, next" :page-sizes="[10, 20, 50]"
                :total="consumePagination.total" :current-page="consumePagination.pageIndex"
                :page-size="consumePagination.pageSize" @size-change="handleConsumeSizeChange"
                @current-change="handleConsumePageChange" />
            </div>
          </div>
        </el-tab-pane>

        <!-- 退卡列表 -->
        <el-tab-pane label="退卡列表" name="refund">
          <div class="tab-content">
            <el-table v-loading="refundLoading" :data="refundList" size="small" border stripe>
              <el-table-column prop="RefundDate" label="退卡日期" width="160">
                <template slot-scope="scope">{{ formatDateTime(scope.row.RefundDate) }}</template>
              </el-table-column>
              <el-table-column prop="StoreName" label="门店" width="150" />
              <el-table-column prop="RefundAmount" label="退卡金额" width="120">
                <template slot-scope="scope">￥{{ formatMoney(scope.row.RefundAmount) }}</template>
              </el-table-column>
              <el-table-column prop="ActualRefundAmount" label="实际退款" width="120">
                <template slot-scope="scope">￥{{ formatMoney(scope.row.ActualRefundAmount) }}</template>
              </el-table-column>
              <el-table-column prop="RefundReason" label="退卡原因" min-width="150" />
            </el-table>
            <div class="pagination-bar">
              <el-pagination layout="total, sizes, prev, pager, next" :page-sizes="[10, 20, 50]"
                :total="refundPagination.total" :current-page="refundPagination.pageIndex"
                :page-size="refundPagination.pageSize" @size-change="handleRefundSizeChange"
                @current-change="handleRefundPageChange" />
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </el-dialog>
</template>

<script>
import request from '@/utils/request'
import * as echarts from 'echarts'

export default {
  name: 'MemberPortraitDialog',
  props: {
    visible: { type: Boolean, default: false },
    memberId: { type: String, default: '' }
  },
  data() {
    return {
      visibleSync: false,
      loading: false,
      activeTab: 'overview',
      baseInfo: {},
      behaviorSummary: {},
      remainingItems: [],
      monthlyTrend: [],
      consumptionAnalysis: null,
      trendChart: null,
      // 开单列表
      billingList: [],
      billingLoading: false,
      billingPagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0
      },
      // 消耗列表
      consumeList: [],
      consumeLoading: false,
      consumePagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0
      },
      // 退卡列表
      refundList: [],
      refundLoading: false,
      refundPagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  watch: {
    visible: {
      immediate: true,
      handler(v) {
        this.visibleSync = v
        if (v && this.memberId) {
          this.fetchData()
        }
      }
    },
    memberId: {
      handler(newVal) {
        if (newVal && this.visibleSync) {
          this.fetchData()
        }
      }
    },
    activeTab(newVal) {
      if (newVal === 'billing' && this.billingList.length === 0) {
        this.fetchBillingList()
      } else if (newVal === 'consume' && this.consumeList.length === 0) {
        this.fetchConsumeList()
      } else if (newVal === 'refund' && this.refundList.length === 0) {
        this.fetchRefundList()
      }
    }
  },
  methods: {
    async fetchData() {
      if (!this.memberId) {
        this.$message.warning('会员ID不能为空')
        return
      }

      this.loading = true
      try {
        const res = await request({
          url: '/api/Extend/MemberPortrait/overview',
          method: 'GET',
          params: { memberId: this.memberId }
        })

        if (res.code === 200 && res.data) {
          this.baseInfo = res.data.BaseInfo || {}
          this.behaviorSummary = res.data.BehaviorSummary || {}
          this.remainingItems = (res.data.Assets && res.data.Assets.RemainingItems) || []
          this.monthlyTrend = res.data.MonthlyTrend || []
          this.consumptionAnalysis = res.data.ConsumptionAnalysis || null

          this.$nextTick(() => {
            this.renderTrendChart()
          })
        } else {
          this.$message.error(res.msg || '获取会员画像数据失败')
        }
      } catch (error) {
        console.error('获取会员画像数据失败:', error)
        this.$message.error('获取会员画像数据失败: ' + (error.message || '未知错误'))
      } finally {
        this.loading = false
      }
    },
    async fetchBillingList() {
      if (!this.memberId) return

      this.billingLoading = true
      try {
        const res = await request({
          url: '/api/Extend/MemberPortrait/billing-list',
          method: 'GET',
          params: {
            memberId: this.memberId,
            pageIndex: this.billingPagination.pageIndex,
            pageSize: this.billingPagination.pageSize
          }
        })

        if (res.code === 200 && res.data) {
          this.billingList = res.data.List || []
          this.billingPagination.total = res.data.Total || 0
        } else {
          this.$message.error(res.msg || '获取开单列表失败')
        }
      } catch (error) {
        console.error('获取开单列表失败:', error)
        this.$message.error('获取开单列表失败: ' + (error.message || '未知错误'))
      } finally {
        this.billingLoading = false
      }
    },
    async fetchConsumeList() {
      if (!this.memberId) return

      this.consumeLoading = true
      try {
        const res = await request({
          url: '/api/Extend/MemberPortrait/consume-list',
          method: 'GET',
          params: {
            memberId: this.memberId,
            pageIndex: this.consumePagination.pageIndex,
            pageSize: this.consumePagination.pageSize
          }
        })

        if (res.code === 200 && res.data) {
          this.consumeList = res.data.List || []
          this.consumePagination.total = res.data.Total || 0
        } else {
          this.$message.error(res.msg || '获取消耗列表失败')
        }
      } catch (error) {
        console.error('获取消耗列表失败:', error)
        this.$message.error('获取消耗列表失败: ' + (error.message || '未知错误'))
      } finally {
        this.consumeLoading = false
      }
    },
    async fetchRefundList() {
      if (!this.memberId) return

      this.refundLoading = true
      try {
        const res = await request({
          url: '/api/Extend/MemberPortrait/refund-list',
          method: 'GET',
          params: {
            memberId: this.memberId,
            pageIndex: this.refundPagination.pageIndex,
            pageSize: this.refundPagination.pageSize
          }
        })

        if (res.code === 200 && res.data) {
          this.refundList = res.data.List || []
          this.refundPagination.total = res.data.Total || 0
        } else {
          this.$message.error(res.msg || '获取退卡列表失败')
        }
      } catch (error) {
        console.error('获取退卡列表失败:', error)
        this.$message.error('获取退卡列表失败: ' + (error.message || '未知错误'))
      } finally {
        this.refundLoading = false
      }
    },
    handleBillingPageChange(page) {
      this.billingPagination.pageIndex = page
      this.fetchBillingList()
    },
    handleBillingSizeChange(size) {
      this.billingPagination.pageSize = size
      this.billingPagination.pageIndex = 1
      this.fetchBillingList()
    },
    handleConsumePageChange(page) {
      this.consumePagination.pageIndex = page
      this.fetchConsumeList()
    },
    handleConsumeSizeChange(size) {
      this.consumePagination.pageSize = size
      this.consumePagination.pageIndex = 1
      this.fetchConsumeList()
    },
    handleRefundPageChange(page) {
      this.refundPagination.pageIndex = page
      this.fetchRefundList()
    },
    handleRefundSizeChange(size) {
      this.refundPagination.pageSize = size
      this.refundPagination.pageIndex = 1
      this.fetchRefundList()
    },
    renderTrendChart() {
      if (!this.$refs.trendChart) return

      if (this.trendChart) {
        this.trendChart.dispose()
      }

      this.trendChart = echarts.init(this.$refs.trendChart)

      const months = this.monthlyTrend.map(item => item.Month)
      const billingData = this.monthlyTrend.map(item => item.BillingAmount || 0)
      const consumeData = this.monthlyTrend.map(item => item.ConsumeAmount || 0)
      const refundData = this.monthlyTrend.map(item => item.RefundAmount || 0)

      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: { type: 'cross' }
        },
        legend: {
          data: ['开单金额', '消耗金额', '退卡金额'],
          bottom: 0
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '15%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: months,
          axisLabel: {
            rotate: 45
          }
        },
        yAxis: {
          type: 'value',
          axisLabel: {
            formatter: value => '￥' + this.formatMoney(value)
          }
        },
        series: [
          {
            name: '开单金额',
            type: 'line',
            data: billingData,
            itemStyle: { color: '#409EFF' }
          },
          {
            name: '消耗金额',
            type: 'line',
            data: consumeData,
            itemStyle: { color: '#67C23A' }
          },
          {
            name: '退卡金额',
            type: 'line',
            data: refundData,
            itemStyle: { color: '#F56C6C' }
          }
        ]
      }

      this.trendChart.setOption(option)

      // 响应式调整
      window.addEventListener('resize', this.handleChartResize)
    },
    handleChartResize() {
      if (this.trendChart) {
        this.trendChart.resize()
      }
    },
    formatMoney(amount) {
      if (amount === null || amount === undefined || amount === '') return '0.00'
      return Number(amount).toFixed(2)
    },
    formatDateTime(timestamp) {
      if (!timestamp) return '无'
      if (typeof timestamp === 'number') {
        const date = new Date(timestamp)
        return date.toLocaleString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit'
        })
      }
      return timestamp
    },
    formatDate(timestamp) {
      if (!timestamp) return ''
      if (typeof timestamp === 'number') {
        const date = new Date(timestamp)
        return date.toLocaleDateString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit'
        })
      }
      return timestamp
    },
    getConsumeLevelText(level) {
      const levelMap = {
        0: '普通',
        1: '银卡',
        2: '金卡',
        3: '钻石',
        4: 'VIP'
      }
      return levelMap[level] || '普通'
    },
    getMemberTypeTagType(typeName) {
      const typeMap = {
        '生美': 'success',
        '医美': 'warning',
        '科技部': 'primary',
        '教育部': 'info'
      }
      return typeMap[typeName] || 'info'
    },
    handleClosed() {
      if (this.trendChart) {
        window.removeEventListener('resize', this.handleChartResize)
        this.trendChart.dispose()
        this.trendChart = null
      }
      this.$emit('update:visible', false)
      this.$emit('closed')
    }
  },
  beforeDestroy() {
    if (this.trendChart) {
      window.removeEventListener('resize', this.handleChartResize)
      this.trendChart.dispose()
    }
  }
}
</script>

<style lang="scss" scoped>
.member-portrait-dialog {
  .el-dialog {
    border-radius: 14px;
    overflow: hidden;
  }

  .el-dialog__header {
    padding: 16px 20px;
    border-bottom: 1px solid #ebeef5;
  }

  .el-dialog__body {
    padding: 20px;
    background: #f5f7fa;
    color: #303133;
    overflow-y: auto;
    max-height: calc(90vh - 100px);
  }
}

.portrait-wrapper {
  .portrait-header {
    background: #fff;
    border: 1px solid #ebeef5;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);

    .header-main {
      flex: 1;

      .member-name {
        font-size: 22px;
        font-weight: 600;
        color: #303133;
        margin-bottom: 10px;
      }

      .member-meta {
        display: flex;
        gap: 16px;
        flex-wrap: wrap;

        .meta-item {
          font-size: 13px;
          color: #606266;
          display: flex;
          align-items: center;
          gap: 6px;

          i {
            color: #909399;
          }
        }
      }
    }

    .header-stats {
      display: flex;
      gap: 24px;

      .stat-item {
        text-align: center;

        .stat-label {
          font-size: 12px;
          color: #909399;
          margin-bottom: 6px;
        }

        .stat-value {
          font-size: 16px;
          font-weight: 600;
          color: #303133;

          &.highlight {
            color: #409EFF;
          }

          &.text-warning {
            color: #E6A23C;
          }
        }
      }
    }
  }

  .base-info-section {
    margin-bottom: 12px;

    .base-info-layout {
      display: flex;
      gap: 12px;

      .card-section {
        flex: 1;
        padding: 10px 12px;
        margin-bottom: 0;

        .section-title {
          font-size: 13px;
          margin-bottom: 8px;
        }

        .tag-list {
          gap: 6px;

          .member-type-item {
            padding: 6px 8px;
            font-size: 12px;

            .member-type-tag {
              font-size: 12px;
              padding: 2px 10px;
            }

            .member-type-date {
              font-size: 11px;
            }
          }
        }

        .info-list {
          .info-item {
            padding: 4px 0;
            font-size: 12px;

            .info-label {
              width: 75px;
              font-size: 12px;
            }

            .info-value {
              font-size: 12px;
            }
          }
        }
      }
    }
  }

  .portrait-tabs {
    ::v-deep .el-tabs__header {
      margin-bottom: 16px;
    }

    ::v-deep .el-tabs__content {
      .tab-content {
        .analysis-layout {
          display: flex;
          gap: 20px;
          flex-wrap: wrap;

          .analysis-item {
            min-width: 150px;
            padding: 12px;
            background: #f8f9fa;
            border-radius: 6px;
            border: 1px solid #ebeef5;

            .analysis-label {
              font-size: 12px;
              color: #909399;
              margin-bottom: 6px;
            }

            .analysis-value {
              font-size: 14px;
              color: #303133;
              font-weight: 500;
            }
          }
        }
      }
    }
  }

  .card-section {
    background: #fff;
    border: 1px solid #ebeef5;
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);

    .section-title {
      font-size: 14px;
      font-weight: 600;
      color: #303133;
      margin-bottom: 12px;
      display: flex;
      align-items: center;
      gap: 6px;

      i {
        color: #409EFF;
      }
    }
  }

  .behavior-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;

    .behavior-item {
      background: #f8f9fa;
      padding: 10px;
      border-radius: 6px;
      border: 1px solid #ebeef5;

      .behavior-label {
        font-size: 12px;
        color: #909399;
        margin-bottom: 6px;
      }

      .behavior-value {
        font-size: 13px;
        color: #303133;
        font-weight: 500;
      }
    }
  }

  .tag-list {
    display: flex;
    flex-direction: column;
    gap: 8px;

    .member-type-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px;
      background: #f8f9fa;
      border-radius: 6px;
      border-left: 3px solid #409EFF;

      .member-type-tag {
        font-weight: 600;
        font-size: 13px;
        padding: 4px 12px;
      }

      .member-type-date {
        font-size: 12px;
        color: #909399;
        margin-left: auto;
      }
    }
  }

  .info-list {
    .info-item {
      display: flex;
      padding: 6px 0;
      border-bottom: 1px solid #f0f0f0;

      &:last-child {
        border-bottom: none;
      }

      .info-label {
        font-size: 13px;
        color: #909399;
        width: 90px;
        flex-shrink: 0;
      }

      .info-value {
        font-size: 13px;
        color: #303133;
        flex: 1;
      }
    }
  }

  .trend-chart {
    width: 100%;
    height: 350px;
  }

  .pagination-bar {
    display: flex;
    justify-content: flex-end;
    padding: 10px 0 4px 0;
    margin-top: 12px;
  }

  .text-muted {
    color: #909399;
    font-size: 13px;
  }
}
</style>
