# -*- coding: utf-8 -*-
"""board-customer.html 各维度精细调整 v2"""
import pathlib, re

TARGET = pathlib.Path(__file__).resolve().parents[2] / "docs/h5_ui/pages/board-customer.html"
html = TARGET.read_text(encoding="utf-8")

# ── 通用：跟/弃 badge 向下偏移 ──
# 在 CSS 中把 assistant-badge 的 transform 改为向下多移一点
html = html.replace(
    "transform: translateY(-0.5px);",
    "transform: translateY(1.5px);"
)

def avatar(cf, ct, ch):
    return f'''<div class="w-9 h-9 rounded-xl bg-gradient-to-br from-{cf} to-{ct} flex items-center justify-center shrink-0">
                        <span class="text-white font-semibold text-sm">{ch}</span>
                    </div>'''

# 助教行
def cr(c):
    return f'''            <div class="text-xs border-t border-gray-1 pt-2 ml-11">
                <span class="text-gray-6">助教:</span>
                {c}
            </div>'''

CA = '''<span class="assistant-tag">❤️ <span class="assistant-assignee">小燕</span><span class="assistant-badge assistant-badge-follow">跟</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-normal">泡芙</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-abandoned">Amy</span><span class="assistant-badge assistant-badge-drop">弃</span></span>'''
CB = '''<span class="assistant-tag">❤️ <span class="assistant-normal">Amy</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-normal">小燕</span></span>'''
CC = '''<span class="assistant-tag">❤️ <span class="assistant-assignee">泡芙</span><span class="assistant-badge assistant-badge-follow">跟</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-normal">小燕</span></span>'''
CD = '''<span class="assistant-tag">❤️ <span class="assistant-normal">泡芙</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-assignee">小燕</span><span class="assistant-badge assistant-badge-follow">跟</span></span>'''
CE = '''<span class="assistant-tag">❤️ <span class="assistant-normal">Amy</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-abandoned">泡芙</span><span class="assistant-badge assistant-badge-drop">弃</span></span>'''
CF = '''<span class="assistant-tag">❤️ <span class="assistant-normal">小燕</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-normal">泡芙</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-abandoned">Amy</span><span class="assistant-badge assistant-badge-drop">弃</span></span>'''
CG = '''<span class="assistant-tag">❤️ <span class="assistant-assignee">小燕</span><span class="assistant-badge assistant-badge-follow">跟</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-normal">泡芙</span></span>'''
CH = '''<span class="assistant-tag">❤️ <span class="assistant-normal">泡芙</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-normal">Amy</span></span>'''
CI = '''<span class="assistant-tag">❤️ <span class="assistant-assignee">小燕</span><span class="assistant-badge assistant-badge-follow">跟</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-abandoned">泡芙</span><span class="assistant-badge assistant-badge-drop">弃</span></span>'''
CJ = '''<span class="assistant-tag">❤️ <span class="assistant-assignee">Amy</span><span class="assistant-badge assistant-badge-follow">跟</span></span>
                <span class="assistant-sep">|</span>
                <span class="assistant-tag">❤️ <span class="assistant-normal">小燕</span></span>'''

# ══ 维度1: 最应召回 — 去掉进度条，重新设计 ══
DIM_RECALL = '''
    <!-- ==================== 最应召回（默认） ==================== -->
    <div id="dim-recall" class="dim-container active p-4 pt-1 space-y-3">
        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("amber-400","orange-500","王") + '''
                    <div>
                        <span class="font-semibold text-gray-13">王先生</span>
                        <div class="flex items-center gap-1.5 mt-0.5">
                            <span class="text-xs text-gray-6">理想 <span class="text-gray-11 font-medium">7天</span></span>
                            <span class="text-xs text-gray-6">已过 <span class="text-error font-bold">15天</span></span>
                        </div>
                    </div>
                </div>
                <span class="px-2.5 py-1 bg-error/10 text-error text-sm font-bold rounded-lg">超期 8天</span>
            </div>
            <div class="flex flex-wrap gap-x-4 gap-y-1 text-sm ml-11 mb-2">
                <div class="text-gray-6">30天到店 <span class="text-gray-11 font-medium">5次</span></div>
                <div class="text-gray-6">余额 <span class="text-gray-11 font-medium">¥8,000</span></div>
                <div class="text-gray-6">召回指数 <span class="text-primary font-bold">0.92</span></div>
            </div>
''' + cr(CA) + '''
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("pink-400","rose-500","李") + '''
                    <div>
                        <span class="font-semibold text-gray-13">李女士</span>
                        <div class="flex items-center gap-1.5 mt-0.5">
                            <span class="text-xs text-gray-6">理想 <span class="text-gray-11 font-medium">10天</span></span>
                            <span class="text-xs text-gray-6">已过 <span class="text-error font-bold">20天</span></span>
                        </div>
                    </div>
                </div>
                <span class="px-2.5 py-1 bg-warning/10 text-warning text-sm font-bold rounded-lg">超期 10天</span>
            </div>
            <div class="flex flex-wrap gap-x-4 gap-y-1 text-sm ml-11 mb-2">
                <div class="text-gray-6">30天到店 <span class="text-gray-11 font-medium">3次</span></div>
                <div class="text-gray-6">余额 <span class="text-gray-11 font-medium">¥12,500</span></div>
                <div class="text-gray-6">召回指数 <span class="text-primary font-bold">0.88</span></div>
            </div>
''' + cr(CB) + '''
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("blue-400","indigo-500","张") + '''
                    <div>
                        <span class="font-semibold text-gray-13">张先生</span>
                        <div class="flex items-center gap-1.5 mt-0.5">
                            <span class="text-xs text-gray-6">理想 <span class="text-gray-11 font-medium">7天</span></span>
                            <span class="text-xs text-gray-6">已过 <span class="text-error font-bold">18天</span></span>
                        </div>
                    </div>
                </div>
                <span class="px-2.5 py-1 bg-error/10 text-error text-sm font-bold rounded-lg">超期 11天</span>
            </div>
            <div class="flex flex-wrap gap-x-4 gap-y-1 text-sm ml-11 mb-2">
                <div class="text-gray-6">30天到店 <span class="text-gray-11 font-medium">2次</span></div>
                <div class="text-gray-6">余额 <span class="text-gray-11 font-medium">¥3,200</span></div>
                <div class="text-gray-6">召回指数 <span class="text-primary font-bold">0.85</span></div>
            </div>
''' + cr(CC) + '''
        </a>
    </div>
'''

# ══ 维度2: 最大消费潜力 — 卡片内文字增大 ══
DIM_POTENTIAL = '''
    <!-- ==================== 最大消费潜力 ==================== -->
    <div id="dim-potential" class="dim-container p-4 pt-1 space-y-3">
        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("rose-400","pink-500","赵") + '''
                    <span class="font-semibold text-gray-13">赵女士</span>
                </div>
                <div class="text-right shrink-0">
                    <div class="text-primary font-bold">0.95</div>
                    <div class="text-[10px] text-gray-6 -mt-0.5">消费潜力</div>
                </div>
            </div>
            <div class="ml-11 mb-2 bg-gradient-to-r from-primary/5 to-blue-50 rounded-lg p-3">
                <div class="flex items-center gap-2 mb-2">
                    <span class="text-sm font-bold text-primary">🔥 S级潜力</span>
                    <span class="text-xs text-gray-6">高频 · 高客单 · 高余额</span>
                </div>
                <div class="grid grid-cols-3 gap-2 text-center">
                    <div><p class="text-sm font-bold text-gray-13">¥4,800</p><p class="text-xs text-gray-6">近30天消费</p></div>
                    <div><p class="text-sm font-bold text-gray-13">8次</p><p class="text-xs text-gray-6">月均到店</p></div>
                    <div><p class="text-sm font-bold text-success">¥15,000</p><p class="text-xs text-gray-6">余额</p></div>
                </div>
            </div>
''' + cr(CD) + '''
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("green-400","emerald-500","刘") + '''
                    <span class="font-semibold text-gray-13">刘先生</span>
                </div>
                <div class="text-right shrink-0">
                    <div class="text-primary font-bold">0.87</div>
                    <div class="text-[10px] text-gray-6 -mt-0.5">消费潜力</div>
                </div>
            </div>
            <div class="ml-11 mb-2 bg-gradient-to-r from-primary/5 to-blue-50 rounded-lg p-3">
                <div class="flex items-center gap-2 mb-2">
                    <span class="text-sm font-bold text-primary">⭐ A级潜力</span>
                    <span class="text-xs text-gray-6">中频 · 高客单</span>
                </div>
                <div class="grid grid-cols-3 gap-2 text-center">
                    <div><p class="text-sm font-bold text-gray-13">¥3,500</p><p class="text-xs text-gray-6">近30天消费</p></div>
                    <div><p class="text-sm font-bold text-gray-13">5次</p><p class="text-xs text-gray-6">月均到店</p></div>
                    <div><p class="text-sm font-bold text-success">¥6,800</p><p class="text-xs text-gray-6">余额</p></div>
                </div>
            </div>
''' + cr(CE) + '''
        </a>
    </div>
'''

# ══ 维度3: 最高余额 — 余额小2号，去进度条，预计可用放余额右侧，其他大2号 ══
DIM_BALANCE = '''
    <!-- ==================== 最高余额 ==================== -->
    <div id="dim-balance" class="dim-container p-4 pt-1 space-y-3">
        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-1">
                <div class="flex items-center gap-2">
                    ''' + avatar("rose-400","pink-500","赵") + '''
                    <span class="font-semibold text-gray-13">赵女士</span>
                </div>
            </div>
            <div class="ml-11 mb-2">
                <div class="flex items-baseline gap-2">
                    <span class="text-lg font-bold text-warning">¥25,000</span>
                    <span class="text-xs text-gray-6">余额</span>
                    <span class="text-xs text-gray-5">·</span>
                    <span class="text-sm font-medium text-success">可用约8个月</span>
                </div>
                <div class="flex items-center gap-4 mt-2 text-sm">
                    <div class="text-gray-6">60天消费 <span class="text-gray-11 font-medium">¥6,200</span></div>
                    <div class="text-gray-6">月均消耗 <span class="text-gray-11 font-medium">¥3,100</span></div>
                </div>
                <div class="flex items-center gap-4 mt-1 text-sm">
                    <div class="text-gray-6">最近到店 <span class="text-gray-11 font-medium">12天前</span></div>
                    <div class="text-gray-6">理想间隔 <span class="text-gray-11 font-medium">10天</span></div>
                </div>
            </div>
''' + cr(CF) + '''
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-1">
                <div class="flex items-center gap-2">
                    ''' + avatar("purple-400","violet-500","陈") + '''
                    <span class="font-semibold text-gray-13">陈先生</span>
                </div>
            </div>
            <div class="ml-11 mb-2">
                <div class="flex items-baseline gap-2">
                    <span class="text-lg font-bold text-warning">¥18,500</span>
                    <span class="text-xs text-gray-6">余额</span>
                    <span class="text-xs text-gray-5">·</span>
                    <span class="text-sm font-medium text-success">可用约9.7个月</span>
                </div>
                <div class="flex items-center gap-4 mt-2 text-sm">
                    <div class="text-gray-6">60天消费 <span class="text-gray-11 font-medium">¥3,800</span></div>
                    <div class="text-gray-6">月均消耗 <span class="text-gray-11 font-medium">¥1,900</span></div>
                </div>
                <div class="flex items-center gap-4 mt-1 text-sm">
                    <div class="text-gray-6">最近到店 <span class="text-gray-11 font-medium">8天前</span></div>
                    <div class="text-gray-6">理想间隔 <span class="text-gray-11 font-medium">14天</span></div>
                </div>
            </div>
''' + cr(CG) + '''
        </a>
    </div>
'''

# ══ 维度4: 最近充值 — 数据字号大2号，本年充值→最近3个月充值 ══
DIM_RECHARGE = '''
    <!-- ==================== 最近充值 ==================== -->
    <div id="dim-recharge" class="dim-container p-4 pt-1 space-y-3">
        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center gap-2 mb-2">
                ''' + avatar("indigo-400","blue-500","吴") + '''
                <div class="flex-1 min-w-0">
                    <span class="font-semibold text-gray-13">吴先生</span>
                </div>
                <span class="text-[10px] text-gray-6">2天前充值</span>
            </div>
            <div class="ml-11 mb-2 bg-gradient-to-r from-emerald-50 to-green-50 rounded-lg p-2.5 border border-emerald-100/50">
                <div class="flex items-center justify-between">
                    <div>
                        <span class="text-lg font-bold text-success">+¥5,000</span>
                        <span class="text-[10px] text-gray-6 ml-1">充值</span>
                    </div>
                    <div class="text-right">
                        <div class="text-xs text-gray-6">充后余额</div>
                        <div class="text-sm font-bold text-gray-13">¥8,200</div>
                    </div>
                </div>
            </div>
            <div class="flex flex-wrap gap-x-4 gap-y-1 text-sm ml-11 mb-2">
                <div class="text-gray-6">最近到店 <span class="text-gray-11 font-medium">2天前</span></div>
                <div class="text-gray-6">理想间隔 <span class="text-gray-11 font-medium">7天</span></div>
                <div class="text-gray-6">近3月充值 <span class="text-success font-medium">3次</span></div>
            </div>
''' + cr(CB) + '''
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center gap-2 mb-2">
                ''' + avatar("orange-400","amber-500","郑") + '''
                <div class="flex-1 min-w-0">
                    <span class="font-semibold text-gray-13">郑女士</span>
                </div>
                <span class="text-[10px] text-gray-6">5天前充值</span>
            </div>
            <div class="ml-11 mb-2 bg-gradient-to-r from-emerald-50 to-green-50 rounded-lg p-2.5 border border-emerald-100/50">
                <div class="flex items-center justify-between">
                    <div>
                        <span class="text-lg font-bold text-success">+¥3,000</span>
                        <span class="text-[10px] text-gray-6 ml-1">充值</span>
                    </div>
                    <div class="text-right">
                        <div class="text-xs text-gray-6">充后余额</div>
                        <div class="text-sm font-bold text-gray-13">¥6,500</div>
                    </div>
                </div>
            </div>
            <div class="flex flex-wrap gap-x-4 gap-y-1 text-sm ml-11 mb-2">
                <div class="text-gray-6">最近到店 <span class="text-gray-11 font-medium">5天前</span></div>
                <div class="text-gray-6">理想间隔 <span class="text-gray-11 font-medium">10天</span></div>
                <div class="text-gray-6">近3月充值 <span class="text-success font-medium">2次</span></div>
            </div>
''' + cr(CC) + '''
        </a>
    </div>
'''

# ══ 维度5: 最高消费 近60天 — 消费金额小2号，去余额，到店+次均放一行，去排名icon ══
DIM_SPEND60 = '''
    <!-- ==================== 最高消费 近60天 ==================== -->
    <div id="dim-spend60" class="dim-container p-4 pt-1 space-y-3">
        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("pink-400","rose-500","李") + '''
                    <span class="font-semibold text-gray-13">李女士</span>
                </div>
            </div>
            <div class="ml-11 mb-2">
                <div class="flex items-baseline gap-3">
                    <div>
                        <span class="text-lg font-bold text-warning">¥12,800</span>
                        <span class="text-xs text-gray-6 ml-1">近60天消费</span>
                    </div>
                    <span class="text-xs text-gray-5">·</span>
                    <span class="text-sm text-gray-9">18次到店</span>
                    <span class="text-xs text-gray-5">·</span>
                    <span class="text-sm text-gray-9">次均¥711</span>
                </div>
            </div>
''' + cr(CA) + '''
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("amber-400","orange-500","王") + '''
                    <span class="font-semibold text-gray-13">王先生</span>
                </div>
            </div>
            <div class="ml-11 mb-2">
                <div class="flex items-baseline gap-3">
                    <div>
                        <span class="text-lg font-bold text-warning">¥9,500</span>
                        <span class="text-xs text-gray-6 ml-1">近60天消费</span>
                    </div>
                    <span class="text-xs text-gray-5">·</span>
                    <span class="text-sm text-gray-9">12次到店</span>
                    <span class="text-xs text-gray-5">·</span>
                    <span class="text-sm text-gray-9">次均¥792</span>
                </div>
            </div>
''' + cr(CH) + '''
        </a>
    </div>
'''

# ══ 维度6: 最频繁 近60天 — 左侧放平均间隔+60天消费，去余额，柱状图上标本周天数 ══
DIM_FREQ60 = '''
    <!-- ==================== 最频繁 近60天 ==================== -->
    <div id="dim-freq60" class="dim-container p-4 pt-1 space-y-3">
        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("blue-400","indigo-500","张") + '''
                    <div class="flex-1 min-w-0">
                        <span class="font-semibold text-gray-13">张先生</span>
                        <div class="flex items-center gap-3 mt-0.5 text-xs">
                            <span class="text-gray-6">平均间隔 <span class="text-primary font-medium">3.3天</span></span>
                            <span class="text-gray-6">60天消费 <span class="text-gray-11 font-medium">¥8,600</span></span>
                        </div>
                    </div>
                </div>
                <div class="text-right shrink-0">
                    <div class="text-primary font-bold text-lg">18<span class="text-xs font-normal text-gray-6">天</span></div>
                    <div class="text-[10px] text-gray-6 -mt-0.5">60天到店</div>
                </div>
            </div>
            <div class="ml-11 mb-2">
                <div class="flex items-center justify-between text-[10px] text-gray-5 mb-0.5">
                    <span>8周前</span>
                    <span>本周 <span class="text-primary font-bold text-xs">3</span></span>
                </div>
                <div class="flex items-end gap-0.5 h-6">
                    <div class="flex-1 bg-primary/20 rounded-t" style="height:60%"></div>
                    <div class="flex-1 bg-primary/30 rounded-t" style="height:80%"></div>
                    <div class="flex-1 bg-primary/40 rounded-t" style="height:50%"></div>
                    <div class="flex-1 bg-primary/50 rounded-t" style="height:100%"></div>
                    <div class="flex-1 bg-primary/40 rounded-t" style="height:70%"></div>
                    <div class="flex-1 bg-primary/60 rounded-t" style="height:90%"></div>
                    <div class="flex-1 bg-primary/30 rounded-t" style="height:40%"></div>
                    <div class="flex-1 bg-primary/50 rounded-t" style="height:75%"></div>
                </div>
            </div>
''' + cr(CF) + '''
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center justify-between mb-2">
                <div class="flex items-center gap-2">
                    ''' + avatar("purple-400","violet-500","陈") + '''
                    <div class="flex-1 min-w-0">
                        <span class="font-semibold text-gray-13">陈先生</span>
                        <div class="flex items-center gap-3 mt-0.5 text-xs">
                            <span class="text-gray-6">平均间隔 <span class="text-primary font-medium">4天</span></span>
                            <span class="text-gray-6">60天消费 <span class="text-gray-11 font-medium">¥6,200</span></span>
                        </div>
                    </div>
                </div>
                <div class="text-right shrink-0">
                    <div class="text-primary font-bold text-lg">15<span class="text-xs font-normal text-gray-6">天</span></div>
                    <div class="text-[10px] text-gray-6 -mt-0.5">60天到店</div>
                </div>
            </div>
            <div class="ml-11 mb-2">
                <div class="flex items-center justify-between text-[10px] text-gray-5 mb-0.5">
                    <span>8周前</span>
                    <span>本周 <span class="text-primary font-bold text-xs">2</span></span>
                </div>
                <div class="flex items-end gap-0.5 h-6">
                    <div class="flex-1 bg-primary/20 rounded-t" style="height:40%"></div>
                    <div class="flex-1 bg-primary/30 rounded-t" style="height:60%"></div>
                    <div class="flex-1 bg-primary/40 rounded-t" style="height:70%"></div>
                    <div class="flex-1 bg-primary/30 rounded-t" style="height:50%"></div>
                    <div class="flex-1 bg-primary/50 rounded-t" style="height:80%"></div>
                    <div class="flex-1 bg-primary/40 rounded-t" style="height:65%"></div>
                    <div class="flex-1 bg-primary/60 rounded-t" style="height:90%"></div>
                    <div class="flex-1 bg-primary/50 rounded-t" style="height:70%"></div>
                </div>
            </div>
''' + cr(CJ) + '''
        </a>
    </div>
'''

# ══ 维度7: 最近到店 — 去进度条，数据大2号，余额→次均消费金额 ══
DIM_RECENT = '''
    <!-- ==================== 最近到店 ==================== -->
    <div id="dim-recent" class="dim-container p-4 pt-1 space-y-3">
        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center gap-2 mb-2">
                ''' + avatar("green-400","emerald-500","刘") + '''
                <div class="flex-1 min-w-0">
                    <span class="font-semibold text-gray-13">刘先生</span>
                </div>
                <div class="flex items-baseline gap-0.5 shrink-0">
                    <span class="text-2xl font-bold text-success">1</span>
                    <span class="text-xs text-gray-6">天前到店</span>
                </div>
            </div>
            <div class="flex flex-wrap gap-x-4 gap-y-1 text-sm ml-11 mb-2">
                <div class="text-gray-6">理想间隔 <span class="text-gray-11 font-medium">7天</span></div>
                <div class="text-gray-6">60天到店 <span class="text-gray-11 font-medium">12天</span></div>
                <div class="text-gray-6">次均消费 <span class="text-gray-11 font-medium">¥450</span></div>
            </div>
''' + cr(CH) + '''
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center gap-2 mb-2">
                ''' + avatar("cyan-400","teal-500","周") + '''
                <div class="flex-1 min-w-0">
                    <span class="font-semibold text-gray-13">周先生</span>
                </div>
                <div class="flex items-baseline gap-0.5 shrink-0">
                    <span class="text-2xl font-bold text-success">2</span>
                    <span class="text-xs text-gray-6">天前到店</span>
                </div>
            </div>
            <div class="flex flex-wrap gap-x-4 gap-y-1 text-sm ml-11 mb-2">
                <div class="text-gray-6">理想间隔 <span class="text-gray-11 font-medium">10天</span></div>
                <div class="text-gray-6">60天到店 <span class="text-gray-11 font-medium">8天</span></div>
                <div class="text-gray-6">次均消费 <span class="text-gray-11 font-medium">¥475</span></div>
            </div>
''' + cr(CI) + '''
        </a>
    </div>
'''

# ══ 维度8: 最专一 — 去右上角专一指数，去进度条，爱心+昵称+数据表格式，去底部数据 ══
DIM_LOYAL = '''
    <!-- ==================== 最专一 ==================== -->
    <div id="dim-loyal" class="dim-container p-4 pt-1 space-y-3">
        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center gap-2 mb-2.5">
                ''' + avatar("teal-400","cyan-500","孙") + '''
                <span class="font-semibold text-gray-13">孙先生</span>
            </div>
            <div class="ml-11 mb-1 space-y-1.5">
                <!-- 表头 -->
                <div class="flex items-center text-[10px] text-gray-5 gap-1">
                    <span class="w-14"></span>
                    <span class="flex-1"></span>
                    <span class="w-12 text-right">次均时长</span>
                    <span class="w-12 text-right">60天时长</span>
                    <span class="w-10 text-right">服务次</span>
                </div>
                <!-- 小燕 -->
                <div class="flex items-center gap-1">
                    <span class="w-14 flex items-center gap-0.5 shrink-0"><span class="text-xs">❤️</span><span class="text-xs font-medium text-error">小燕</span></span>
                    <span class="text-[10px] text-gray-5 shrink-0">0.95</span>
                    <span class="assistant-badge assistant-badge-follow text-[9px] shrink-0">跟</span>
                    <span class="flex-1"></span>
                    <span class="w-12 text-right text-xs font-medium text-gray-11">2.1h</span>
                    <span class="w-12 text-right text-xs font-medium text-gray-11">25.2h</span>
                    <span class="w-10 text-right text-xs font-medium text-gray-11">12</span>
                </div>
                <!-- 泡芙 -->
                <div class="flex items-center gap-1">
                    <span class="w-14 flex items-center gap-0.5 shrink-0"><span class="text-xs">❤️</span><span class="text-xs font-medium text-gray-13">泡芙</span></span>
                    <span class="text-[10px] text-gray-5 shrink-0">0.68</span>
                    <span class="flex-1"></span>
                    <span class="w-12 text-right text-xs font-medium text-gray-11">1.8h</span>
                    <span class="w-12 text-right text-xs font-medium text-gray-11">9.0h</span>
                    <span class="w-10 text-right text-xs font-medium text-gray-11">5</span>
                </div>
                <!-- Amy -->
                <div class="flex items-center gap-1">
                    <span class="w-14 flex items-center gap-0.5 shrink-0"><span class="text-xs">❤️</span><span class="text-xs font-medium text-gray-5">Amy</span></span>
                    <span class="text-[10px] text-gray-5 shrink-0">0.32</span>
                    <span class="assistant-badge assistant-badge-drop text-[9px] shrink-0">弃</span>
                    <span class="flex-1"></span>
                    <span class="w-12 text-right text-xs text-gray-7">1.2h</span>
                    <span class="w-12 text-right text-xs text-gray-7">3.6h</span>
                    <span class="w-10 text-right text-xs text-gray-7">3</span>
                </div>
            </div>
        </a>

        <a href="customer-detail.html" class="block bg-white rounded-2xl p-4 shadow-sm customer-card">
            <div class="flex items-center gap-2 mb-2.5">
                ''' + avatar("rose-400","pink-500","赵") + '''
                <span class="font-semibold text-gray-13">赵女士</span>
            </div>
            <div class="ml-11 mb-1 space-y-1.5">
                <div class="flex items-center text-[10px] text-gray-5 gap-1">
                    <span class="w-14"></span>
                    <span class="flex-1"></span>
                    <span class="w-12 text-right">次均时长</span>
                    <span class="w-12 text-right">60天时长</span>
                    <span class="w-10 text-right">服务次</span>
                </div>
                <div class="flex items-center gap-1">
                    <span class="w-14 flex items-center gap-0.5 shrink-0"><span class="text-xs">❤️</span><span class="text-xs font-medium text-gray-13">Amy</span></span>
                    <span class="text-[10px] text-gray-5 shrink-0">0.88</span>
                    <span class="flex-1"></span>
                    <span class="w-12 text-right text-xs font-medium text-gray-11">2.3h</span>
                    <span class="w-12 text-right text-xs font-medium text-gray-11">32.2h</span>
                    <span class="w-10 text-right text-xs font-medium text-gray-11">14</span>
                </div>
                <div class="flex items-center gap-1">
                    <span class="w-14 flex items-center gap-0.5 shrink-0"><span class="text-xs">❤️</span><span class="text-xs font-medium text-gray-13">泡芙</span></span>
                    <span class="text-[10px] text-gray-5 shrink-0">0.72</span>
                    <span class="flex-1"></span>
                    <span class="w-12 text-right text-xs font-medium text-gray-11">1.5h</span>
                    <span class="w-12 text-right text-xs font-medium text-gray-11">12.0h</span>
                    <span class="w-10 text-right text-xs font-medium text-gray-11">8</span>
                </div>
            </div>
        </a>
    </div>
'''

# ══ 执行替换 ══
ALL_DIMS = DIM_RECALL + DIM_POTENTIAL + DIM_BALANCE + DIM_RECHARGE + DIM_SPEND60 + DIM_FREQ60 + DIM_RECENT + DIM_LOYAL

start_marker = '<div id="dim-recall"'
end_marker = '<!-- 悬浮助手按钮'

start_idx = html.find(start_marker)
end_idx = html.find(end_marker)

if start_idx == -1 or end_idx == -1:
    print(f"ERROR: 找不到替换标记 start={start_idx} end={end_idx}")
    import sys; sys.exit(1)

# 回退到行首
start_idx = html.rfind('\n', 0, start_idx) + 1

new_html = html[:start_idx] + ALL_DIMS + '\n    ' + html[end_idx:]

TARGET.write_text(new_html, encoding="utf-8")
print(f"OK: board-customer.html v2 已重写，共 {len(new_html)} 字符")
