<template>
	<!-- 我的钱包 -->
	<view class="wallet-page">
		<view class="wallet-bg">
			<view class="wallet-aura aura-purple"></view>
			<view class="wallet-aura aura-blue"></view>
			<view class="wallet-aura aura-pink"></view>
		</view>

		<view class="wallet-nav" :style="{'padding-top': navSafeTop + 'px'}">
			<view class="back-btn" @tap="back">
				<text>‹</text>
			</view>
			<view class="nav-title-wrap">
				<view class="title-name">我的钱包</view>
				<view class="wallet-subtitle">管理你的每一份收益 <text class="subtitle-spark">✨</text></view>
			</view>
		</view>

		<scroll-view scroll-y class="wallet-scroll" :show-scrollbar="false" @scrolltolower="loadMoreFlow">
			<view class="wallet-content">
				<view class="heading-illus enter-card">
					<text class="illus-main">👛</text>
					<text class="illus-star">✦</text>
				</view>

				<!-- 用户余额主卡 -->
				<view class="hero-card enter-card" :class="{active: activeWalletType === 'user'}" @tap="switchWallet('user')">
					<view class="hero-watermark">WALLET</view>
					<view class="hero-copy">
						<view class="hero-label" @tap.stop="toggleBalance">
							<text>用户余额</text>
							<view class="eye-badge" :class="{closed: !showBalance}">
								<view class="eye-line" v-if="showBalance"></view>
								<text class="eye-emoji" v-else>🙈</text>
							</view>
						</view>
						<view class="hero-amount amount-roll">
							{{ showBalance ? formatMoney(balanceUser.depoBal) : '••••' }}
						</view>
						<view class="hero-safe">
							<text class="safe-shield">🛡</text>
							<text>钱包安全保障中 ›</text>
						</view>
					</view>
					<view class="withdraw-btn" @tap.stop="userCommion('user', balanceUser.depoBal, balanceUser)">
						<text>提现</text>
						<!-- <view class="btn-arrow">↑</view> -->
					</view>
				</view>

				<!-- 配送 & 商家子卡 -->
				<view class="identity-grid">
					<!-- 配送兼职佣金卡片 -->
					<view v-if="hasWorkerWallet" class="identity-card worker-card enter-card" :class="{active: activeWalletType === 'worker'}" @tap="switchWallet('worker')">
						<view class="card-title">配送可提现佣金</view>
						<view class="card-value">{{ showBalance ? formatMoney(balanceWorker.depoBalRel) : '••••' }}</view>
						<view class="worker-today-line">
							今日佣金{{ showBalance ? formatMoney(balanceWorker.depoBal) : '••••' }}<text>次日可提现</text> 
						</view>
						<view class="card-link-btn" @tap.stop="userCommion('worker', balanceWorker.depoBalRel, balanceWorker)">提现</view>
						<view class="card-illus">🛵</view>
					</view>

					<!-- 店铺余额卡片 -->
					<view v-if="hasShopWallet" class="identity-card shop-card enter-card" :class="{active: activeWalletType === 'shop'}" @tap="switchWallet('shop')">
						<view class="card-title">{{currentShopName}}余额</view>
						<view class="card-value">{{ showBalance ? formatMoney(currentShopBalance) : '••••' }}</view>
						<view class="card-today" v-if="shopWallets.length > 1">当前第 {{activeShopIndex + 1}} / {{shopWallets.length}} 个店铺</view>
						<view class="card-link-btn" @tap.stop="userCommion('shop', currentShopBalance, currentShop)">提现</view>
						<view class="card-illus shop-image-illus">
							<image class="shop-illus-img" src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/f19689fe650a4a439f7d9096d354b47e.png" mode="aspectFit"></image>
						</view>
					</view>
				</view>
				<scroll-view v-if="hasShopWallet && shopWallets.length > 1" scroll-x class="shop-switch-scroll" :show-scrollbar="false">
					<view class="shop-switch-list">
						<view class="shop-switch-item" :class="{active: activeWalletType === 'shop' && activeShopIndex === index}"
							v-for="(shop,index) in shopWallets" :key="index" @tap="switchShop(index)">
							{{getShopName(shop, index)}}
						</view>
					</view>
				</scroll-view>

				<!-- 余额明细面板 -->
				<view class="flow-panel enter-card">
					<view class="section-head">
						<view class="flow-tabs">
							<view class="flow-tab active">余额明细</view>
						</view>
						<view class="flow-filter">点击不同身份查看余额明细</view>
					</view>

					<view class="timeline-list">
						<view class="flow-card" :class="{clickable: canOpenShopOrder(item)}" v-for="(item,index) in displayRewardLists" :key="index" :style="{animationDelay: item.delay}" @tap="handleFlowTap(item)">
							<view class="flow-icon" :class="'type-' + item.flowIconKey">
								<text>{{item.flowEmoji}}</text>
							</view>
							<view class="flow-main">
								<view class="flow-title">{{item.dealingsWay || '余额变动'}}</view>
								<view class="flow-subtitle">{{dealingsSubtitle(item)}}</view>
							</view>
							<view class="flow-right">
								<view class="flow-amount" :class="item.amountClass">
									{{item.amountText}}
								</view>
								<view class="flow-time">{{formatFlowTime(item.createTime)}}</view>
							</view>
						</view>
						<view class="empty-card" v-if="!rewardLists.length && loadStatus !== 'loading'">
							最近还没有余额流水
						</view>
					</view>

					<uni-load-more :status="loadStatus" />
				</view>

				<view class="bottom-space"></view>
			</view>
		</scroll-view>

		<!-- 底部固定小提示 -->
		<view class="tip-banner">
			<view class="tip-left">
				<text class="tip-icon">📢</text>
				<text class="tip-text"><text class="tip-bold">小提示：</text>努力兼职，钱包会鼓鼓的哦 💪</text>
			</view>
			<!-- <view class="tip-arrow">→</view> -->
		</view>

		<!-- 出层 -->
		<uni-popup ref="payPopup" background-color="transparent">
			<view class="withdraw-popup">
				<view class="popup-title">提现到支付宝</view>
				<view class="popup-field">
					<text>支付宝实名</text>
					<input type="text" v-model="aliName" placeholder="请输入姓名" />
				</view>
				<view class="popup-field">
					<text>支付宝认证手机号</text>
					<input type="digit" v-model="aliAccount" placeholder="请输入手机号" />
				</view>
				<view class="popup-field">
					<text>提现金额</text>
					<input type="digit" v-model="commionAmount" placeholder="请输入金额" />
				</view>
				<view class="popup-btn" :style="{opacity: submittingWithdraw ? 0.6 : 1}" @tap="wxPayment">
					{{submittingWithdraw ? '提现中...' : '确认提现'}}
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				menuButtonInfo: {},
				balanceUser:{},
				loadStatus: 'more',
				balanceWorker:{},
				rewardLists:[],
				aliName:'',
				aliAccount:'',
				commionType:'',
				shopId:'',
				workerId:'',
				userId:'',
				searchForm:{
					pageNum:1,
					pageSize:10
				},
				indicatorDots: false,
				interval: 4000,
				onlineWorkerInterval:4000,
				totalPages: 1,
				commionUrl:'',
				commionAmount:0,
				withdrawMaxAmount: 0,
				linkId:'',
				activeWalletType: 'user',
				activeShopIndex: 0,
				targetWalletType: '',
				autoplay: true,
				balanceShop:[],
				submittingWithdraw: false,
				withdrawRequestId: '',
				showBalance: true,
				resolvingSettlementOrderId: false,
				skipWalletRefreshOnShow: false,
			}
		},
		computed: {
			navSafeTop() {
				const top = Number(this.menuButtonInfo && this.menuButtonInfo.top)
				return top && top > 20 ? top : 44
			},
			shopWallets() {
				if (Array.isArray(this.balanceShop)) return this.balanceShop
				return this.balanceShop && typeof this.balanceShop === 'object' ? [this.balanceShop] : []
			},
			hasWorkerWallet() {
				return !!(this.balanceWorker && (this.balanceWorker.workerId || this.balanceWorker.id || this.balanceWorker.depoBal || this.balanceWorker.depoBalRel))
			},
			hasShopWallet() {
				return this.shopWallets.length > 0
			},
			walletTabs() {
				const tabs = [{ key: 'user', name: '用户钱包' }]
				if (this.hasWorkerWallet) tabs.push({ key: 'worker', name: '配送钱包' })
				if (this.hasShopWallet) tabs.push({ key: 'shop', name: '商家钱包' })
				return tabs
			},
			currentShop() {
				return this.shopWallets[this.activeShopIndex] || this.shopWallets[0] || {}
			},
			currentShopName() {
				return this.getShopName(this.currentShop, this.activeShopIndex)
			},
			currentShopBalance() {
				const shop = this.currentShop || {}
				return shop.balance != null ? shop.balance : (shop.depoBal != null ? shop.depoBal : 0)
			},
			workerTodayCommission() {
				if (!this.balanceWorker) return 0
				if (this.balanceWorker.todayCommission != null) return this.balanceWorker.todayCommission
				if (this.balanceWorker.todayIncome != null) return this.balanceWorker.todayIncome
				return this.balanceWorker.commissionToday || 0
			},
			shopTotalBalance() {
				return this.shopWallets.reduce((total, shop) => {
					return total + (Number(shop.balance) || 0)
				}, 0)
			},
			displayRewardLists() {
				return (this.rewardLists || []).map((item, index) => {
					const amountClass = this.amountClass(item)
					return Object.assign({}, item, {
						amountClass,
						amountText: this.formatSignedAmount(item),
						flowIconKey: this.flowIconKey(item.dealingsWay),
						flowEmoji: this.flowEmoji(item.dealingsWay),
						delay: (index * 0.04) + 's'
					})
				})
			}
		},
		onLoad(option) {
			if (option && option.walletType) {
				this.targetWalletType = option.walletType
			}
		},
		onShow() {
			this.menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			if (this.skipWalletRefreshOnShow) {
				this.skipWalletRefreshOnShow = false
				return
			}
			this.balanceUser = 0
			this.balanceWorker = 0
			this.balanceShop = []
			this.beginData();
		},
		onReachBottom() {
			if (this.searchForm.pageNum >= this.totalPages) return;
			this.searchForm.pageNum+=1;
			this.rewardList();
		},
		methods: {
			beginData(){
				this.NB.sendRequest("/worker/getAllDepo/", {
					userId:uni.getStorageSync('id')
				}, false, 'get', 'application/json').then((res) => {
					if (res.code == 200) {
						if(res.result.user){
							this.balanceUser = res.result.user
						}
						if(res.result.worker){
							this.balanceWorker = res.result.worker
						}
						if(res.result.shop){
							this.balanceShop = Array.isArray(res.result.shop) ? res.result.shop : [res.result.shop]
						}
						this.syncActiveWallet()
						this.$forceUpdate();
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						return
					}
					uni.hideLoading()
				}).catch((res) => {});
			},
			//提现
			withDraw(){
				uni.showToast({
					title:'提现成功'
				})
			},
			userCommion(type,commion,item){
				const withdrawAmount = Number(commion) || 0
				if(type=='user'){
					this.commionUrl = '/app/returnCommission/handleReturnUser'
				}else if(type=='worker'){
					this.commionUrl = '/app/returnCommission/handleReturnWorker'
				}else{
					this.commionUrl = '/app/returnCommission/handleReturn'
					this.shopId = item && item.id
				}
				this.commionAmount = this.formatMoney(withdrawAmount)
				this.withdrawMaxAmount = withdrawAmount
				this.commionType = type
				this.submittingWithdraw = false
				this.withdrawRequestId = this.createWithdrawRequestId()
				this.$refs.payPopup.open();
			},
			createWithdrawRequestId(){
				return `${Date.now()}${Math.floor(Math.random() * 1000000)}`
			},
			syncActiveWallet(){
				if (this.targetWalletType) {
					const targetIndex = this.walletTabs.findIndex(tab => tab.key === this.targetWalletType)
					if (targetIndex >= 0) {
						this.activeWalletType = this.targetWalletType
						this.targetWalletType = ''
					}
				}
				const currentIndex = this.walletTabs.findIndex(tab => tab.key === this.activeWalletType)
				if (currentIndex < 0) {
					this.activeWalletType = 'user'
				}
				if (this.activeWalletType === 'shop' && this.activeShopIndex >= this.shopWallets.length) {
					this.activeShopIndex = 0
				}
				if (this.activeWalletType !== 'shop') {
					this.activeShopIndex = 0
				}
				this.setCurrentLinkId()
			},
			setCurrentLinkId(){
				if (this.activeWalletType === 'worker') {
					this.linkId = this.balanceWorker.workerId
				} else if (this.activeWalletType === 'shop') {
					this.linkId = this.currentShop.id
				} else {
					this.linkId = this.balanceUser.id
				}
				this.searchForm.pageNum = 1
				if (!this.linkId) {
					this.rewardLists = []
					this.loadStatus = 'nomore'
					return
				}
				this.rewardList()
			},
			switchWallet(type){
				if (this.activeWalletType === type) return
				this.activeWalletType = type
				if (type === 'shop' && this.activeShopIndex >= this.shopWallets.length) {
					this.activeShopIndex = 0
				}
				this.setCurrentLinkId()
			},
			switchShop(index){
				if (this.activeShopIndex === index) return
				this.activeShopIndex = index
				this.activeWalletType = 'shop'
				this.setCurrentLinkId()
			},
			getShopName(shop, index) {
				if (!shop) return `店铺${index + 1}`
				return shop.shopName || shop.name || shop.storeName || shop.merchantName || `店铺${index + 1}`
			},
			loadMoreFlow(){
				if (this.searchForm.pageNum >= this.totalPages) return
				this.searchForm.pageNum += 1
				this.rewardList()
			},
			wxPayment(){
				let that = this
				if (this.submittingWithdraw) {
					uni.showToast({
						title: '提现处理中，请勿重复提交',
						icon: 'none'
					});
					return
				}
				const amount = Number(this.commionAmount)
				const maxAmount = Number(this.withdrawMaxAmount) || 0
				if(!amount || amount < 1){
					uni.showToast({
						title: '提现金额不能小于1元',
						icon: 'none'
					});
					return
				}
				if(amount > 5000){
					uni.showToast({
						title: '单笔提现金额不能超过5000元',
						icon: 'none'
					});
					return
				}
				if(amount > maxAmount){
					uni.showToast({
						title: '提现金额不能超过可提现金额',
						icon: 'none'
					});
					return
				}
				if(!this.aliName){
					uni.showToast({
						title: '支付宝实名名称不能为空',
						icon: 'none'
					});
					return
				}
				if(!this.aliAccount){
					uni.showToast({
						title: '支付宝手机号不能为空',
						icon: 'none'
					});
					return
				}
				this.submittingWithdraw = true
				let data = {
					id:this.withdrawRequestId || this.createWithdrawRequestId(),
					commission:amount,
					aliName:this.aliName,
					aliAccount:this.aliAccount
				}
				if(this.commionType == 'user'){
					data.userId = this.balanceUser.id
				}else if(this.commionType == 'worker'){
					data.workerId = this.balanceWorker.workerId
				}else{
					data.shopId = this.shopId
				}
				this.NB.sendRequest(this.commionUrl, data, false, 'POST', 'application/json').then((res) => {
					if (res.code == 200) {
						this.$refs.payPopup.close();
						this.withdrawRequestId = ''
						this.beginData();
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
						that.submittingWithdraw = false
						return
					}
					that.submittingWithdraw = false
					uni.hideLoading()
				}).catch((res) => {
					that.submittingWithdraw = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
				});
			},
			chooseLinkId(type,item){
				if(type == 'user'){
					this.linkId = this.balanceUser.id
				}else if(type == 'worker'){
					this.linkId = this.balanceWorker.workerId
				}else{
					this.linkId = item.id
				}
				this.searchForm.pageNum = 1
				if (!this.linkId) return
				this.rewardList();
			},
			formatMoney(value){
				const num = Number(value)
				if (!isFinite(num)) return '0.00'
				return num.toFixed(2)
			},
			isIncomeFlow(item){
				return item && Number(item.dealingsType) === 0
			},
			amountClass(item){
				return this.isIncomeFlow(item) ? 'income' : 'outcome'
			},
			formatSignedAmount(item){
				const num = Number(item && item.amount)
				if (!isFinite(num)) return '+0.00'
				const prefix = this.isIncomeFlow(item) ? '+' : '-'
				return prefix + Math.abs(num).toFixed(2)
			},
			flowIconKey(title) {
				const text = title || ''
				if (text.indexOf('提现') !== -1) return 'withdraw'
				if (text.indexOf('配送') !== -1) return 'worker'
				if (text.indexOf('商家') !== -1 || text.indexOf('结算') !== -1 || text.indexOf('店铺') !== -1) return 'shop'
				if (text.indexOf('抽奖') !== -1 || text.indexOf('奖励') !== -1) return 'reward'
				return 'bill'
			},
			flowEmoji(title) {
				const text = title || ''
				if (text.indexOf('提现') !== -1) return '💳'
				if (text.indexOf('配送') !== -1) return '🛵'
				if (text.indexOf('商家') !== -1 || text.indexOf('结算') !== -1 || text.indexOf('店铺') !== -1) return '🏪'
				if (text.indexOf('抽奖') !== -1 || text.indexOf('奖励') !== -1) return '🎁'
				return '📄'
			},
			dealingsSubtitle(item) {
				if (item.remark) return item.remark
				if (item.orderNo) return '订单号: #' + item.orderNo
				const text = item.dealingsWay || ''
				if (text.indexOf('提现') !== -1) return '提现至支付宝'
				if (text.indexOf('配送') !== -1) return '配送订单收益'
				if (text.indexOf('商家') !== -1 || text.indexOf('店铺') !== -1 || text.indexOf('结算') !== -1) return '店铺订单收益'
				if (text.indexOf('抽奖') !== -1 || text.indexOf('奖励') !== -1) return '校内推广活动奖励'
				return '余额变动明细'
			},
			formatFlowTime(timeStr) {
				if (!timeStr) return '刚刚'
				const parts = timeStr.split(' ')
				if (parts.length >= 2) {
					const dateParts = parts[0].split('-')
					const timeParts = parts[1].split(':')
					if (dateParts.length >= 3 && timeParts.length >= 2) {
						return `${dateParts[1]}-${dateParts[2]} ${timeParts[0]}:${timeParts[1]}`
					}
				}
				return timeStr
			},
			toggleBalance() {
				this.showBalance = !this.showBalance
			},
			canOpenShopOrder(item) {
				if (this.activeWalletType !== 'shop' || !item || !item.linkId) return false
				const text = item.dealingsWay || ''
				return text.indexOf('商家结算') !== -1 || text.indexOf('商家退款') !== -1 || text.indexOf('售后扣款') !== -1
			},
			handleFlowTap(item) {
				if (!this.canOpenShopOrder(item)) return
				if (this.resolvingSettlementOrderId) return
				this.resolvingSettlementOrderId = true
				this.NB.sendRequest("/mall/order/orderIdBySettlementRecord/" + item.linkId, {}, false, 'GET', 'application/json').then((res) => {
					if (res.code == 200) {
						this.skipWalletRefreshOnShow = true
						uni.navigateTo({
							url: '/package2/shop/orderDetail?id=' + res.result,
							fail: () => {
								this.skipWalletRefreshOnShow = false
							}
						})
					} else {
						uni.showToast({
							title: res.message || '未找到关联订单',
							icon: 'none'
						});
					}
					this.resolvingSettlementOrderId = false
				}).catch((res) => {
					uni.showToast({
						title: res && res.message ? res.message : '未找到关联订单',
						icon: 'none'
					});
					this.resolvingSettlementOrderId = false
				});
			},
			rewardList(){
				this.loadStatus = 'loading'
				let that = this
				const params = Object.assign({}, this.searchForm, {
					linkUserId: this.linkId
				})
				if (this.activeWalletType === 'user') {
					params.excludeDealingsWay = '免单奖励'
				}
				this.NB.sendRequest("/mall/coupon/selectRewardByRegionId", params, false, 'POST', 'application/json').then((res) => {
					that.loadStatus = 'nomore';
					if (res.code == 200) {
						that.totalPages = res.result.pages
						if (that.searchForm.pageNum == 1) {
							that.rewardLists = res.result.records
						} else {
							that.rewardLists = [...that.rewardLists, ...res.result.records]
						}
						that.$forceUpdate()
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
						return
					}
					uni.hideLoading()
				}).catch((res) => {});
			},
			back() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		font-size: 24rpx;
		background: #F3FFF8;
		color: #153A2E;
		overflow: hidden;
	}

	.wallet-page {
		width: 100%;
		height: 100vh;
		position: relative;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		background:
			radial-gradient(circle at 18% 8%, rgba(205, 255, 206, 0.78), rgba(205, 255, 206, 0) 220rpx),
			radial-gradient(circle at 88% 10%, rgba(142, 239, 255, 0.5), rgba(142, 239, 255, 0) 300rpx),
			linear-gradient(180deg, #EFFFF6 0%, #F3FFF8 42%, #F9FFF7 100%);
	}

	/* ---------- 背景光斑 ---------- */
	.wallet-bg {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		height: 980rpx;
		pointer-events: none;
		overflow: hidden;
		z-index: 0;
	}

	.wallet-aura {
		position: absolute;
		border-radius: 50%;
		filter: blur(6rpx);
		opacity: 0.8;
		animation: auraFloat 7s ease-in-out infinite alternate;
	}

	.aura-purple {
		width: 560rpx;
		height: 560rpx;
		right: -200rpx;
		top: -60rpx;
		background: radial-gradient(circle, rgba(124,234,194,0.32), rgba(124,234,194,0));
	}

	.aura-blue {
		width: 520rpx;
		height: 520rpx;
		left: -190rpx;
		top: 260rpx;
		background: radial-gradient(circle, rgba(137,238,255,0.26), rgba(137,238,255,0));
		animation-delay: -2s;
	}

	.aura-pink {
		width: 420rpx;
		height: 420rpx;
		left: -80rpx;
		top: -100rpx;
		background: radial-gradient(circle, rgba(255,198,121,0.18), rgba(255,198,121,0));
		animation-delay: -4s;
	}

	/* ---------- 导航 ---------- */
	.wallet-nav {
		position: relative;
		z-index: 2;
		flex: none;
		min-height: 132rpx;
		display: flex;
		align-items: center;
		padding-left: 32rpx;
		padding-right: 32rpx;
		padding-bottom: 10rpx;
		box-sizing: content-box;
	}

	.back-btn {
		width: 72rpx;
		height: 72rpx;
		border-radius: 50%;
		background: rgba(255,255,255,0.8);
		box-shadow: 0 8rpx 22rpx rgba(28, 122, 91, 0.08);
		display: flex;
		align-items: center;
		justify-content: center;
		backdrop-filter: blur(14rpx);
		border: 1rpx solid rgba(255, 255, 255, 0.9);
	}

	.back-btn text {
		font-size: 52rpx;
		line-height: 52rpx;
		color: #153A2E;
		transform: translateY(-2rpx);
	}

	.nav-title-wrap {
		margin-left: 22rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		min-width: 0;
	}

	.wallet-scroll {
		position: relative;
		z-index: 1;
		flex: 1;
		height: 0;
		min-height: 0;
	}

	.wallet-content {
		padding: 0 32rpx;
		position: relative;
		z-index: 1;
	}

	.title-name {
		font-size: 44rpx;
		font-weight: 900;
		letter-spacing: 1rpx;
		color: #153A2E;
	}

	.wallet-subtitle {
		margin-top: 8rpx;
		font-size: 23rpx;
		font-weight: 600;
		color: rgba(21, 58, 46, 0.52);
	}

	.subtitle-spark {
		margin-left: 4rpx;
	}

	.heading-illus {
		position: absolute;
		right: 28rpx;
		top: -16rpx;
		width: 150rpx;
		height: 150rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		pointer-events: none;
	}

	.illus-main {
		font-size: 120rpx;
		filter: drop-shadow(0 16rpx 28rpx rgba(44, 174, 127, 0.22));
		animation: illusFloat 4.5s ease-in-out infinite alternate;
	}

	.illus-star {
		position: absolute;
		left: -14rpx;
		top: 4rpx;
		font-size: 34rpx;
		color: #FFB85C;
		animation: starTwinkle 2.4s ease-in-out infinite alternate;
	}

	/* ---------- 用户余额主卡 ---------- */
	.hero-card {
		position: relative;
		height: 324rpx;
		border-radius: 40rpx;
		padding: 40rpx 40rpx 36rpx;
		overflow: hidden;
		box-sizing: border-box;
		background: linear-gradient(120deg, #19C889 0%, #38DFA5 52%, #8BF08D 100%);
		box-shadow: 0 24rpx 52rpx rgba(34, 198, 137, 0.25);
		border: 2rpx solid rgba(255, 255, 255, 0.14);
		transition: transform 0.25s ease, box-shadow 0.25s ease;
	}

	.hero-card.active {
		transform: translateY(-4rpx);
		box-shadow: 0 28rpx 60rpx rgba(34, 198, 137, 0.34);
	}

	.hero-card::before {
		content: '';
		position: absolute;
		right: -90rpx;
		top: -130rpx;
		width: 340rpx;
		height: 340rpx;
		border-radius: 50%;
		background: radial-gradient(circle, rgba(255,255,255,0.22), rgba(255,255,255,0));
		pointer-events: none;
	}

	.hero-watermark {
		position: absolute;
		right: 30rpx;
		top: 118rpx;
		font-size: 72rpx;
		font-weight: 900;
		letter-spacing: 6rpx;
		color: rgba(255, 255, 255, 0.12);
		font-style: italic;
		pointer-events: none;
	}

	.hero-copy {
		position: relative;
		z-index: 1;
		display: flex;
		flex-direction: column;
		height: 100%;
		justify-content: space-between;
	}

	.hero-label {
		display: flex;
		align-items: center;
		gap: 14rpx;
		font-size: 28rpx;
		font-weight: 700;
		color: rgba(255, 255, 255, 0.85);
	}

	.eye-badge {
		width: 42rpx;
		height: 42rpx;
		border-radius: 50%;
		background: rgba(6, 94, 66, 0.22);
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		border: 1rpx solid rgba(255, 255, 255, 0.25);
	}

	.eye-line {
		width: 24rpx;
		height: 14rpx;
		border: 3rpx solid rgba(255, 255, 255, 0.9);
		border-radius: 50%;
		position: relative;
		box-sizing: border-box;
	}

	.eye-line::after {
		content: '';
		position: absolute;
		left: 50%;
		top: 50%;
		width: 7rpx;
		height: 7rpx;
		border-radius: 50%;
		background: #FFFFFF;
		transform: translate(-50%, -50%);
	}

	.eye-badge.closed .eye-line {
		height: 3rpx;
		border-width: 0;
		border-radius: 999rpx;
		background: rgba(255, 255, 255, 0.92);
	}

	.eye-badge.closed .eye-line::after {
		display: none;
	}

	.eye-emoji {
		font-size: 23rpx;
		line-height: 1;
	}

	.hero-amount {
		font-size: 88rpx;
		line-height: 96rpx;
		font-weight: 900;
		letter-spacing: -1rpx;
		color: #FFFFFF;
		margin-top: 6rpx;
		margin-bottom: auto;
	}

	.hero-safe {
		display: inline-flex;
		align-items: center;
		gap: 8rpx;
		padding: 12rpx 26rpx;
		border-radius: 999rpx;
		background: rgba(255, 255, 255, 0.16);
		border: 1rpx solid rgba(255, 255, 255, 0.2);
		font-size: 23rpx;
		font-weight: 700;
		color: #FFFFFF;
		width: fit-content;
	}

	.safe-shield {
		font-size: 24rpx;
	}

	.withdraw-btn {
		position: absolute;
		right: 36rpx;
		bottom: 46rpx;
		z-index: 2;
		min-width: 192rpx;
		height: 88rpx;
		border-radius: 999rpx;
		background: #FFFFFF;
		color: #138B63;
		font-size: 30rpx;
		font-weight: 800;
		box-shadow: 0 14rpx 30rpx rgba(11, 128, 84, 0.2);
		transition: transform 0.16s ease;
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 12rpx;
	}

	.btn-arrow {
		width: 40rpx;
		height: 40rpx;
		border-radius: 50%;
		background: #138B63;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 24rpx;
		font-weight: 900;
	}

	.withdraw-btn:active,
	.popup-btn:active,
	.identity-card:active {
		transform: scale(0.96);
	}

	/* ---------- 配送 & 商家子卡 ---------- */
	.identity-grid {
		margin-top: 24rpx;
		display: grid;
		grid-template-columns: repeat(2, 1fr);
		gap: 20rpx;
	}

	.identity-card {
		position: relative;
		min-height: 238rpx;
		border-radius: 34rpx;
		padding: 26rpx 22rpx 68rpx;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		background: #FFFFFF;
		box-shadow: 0 14rpx 34rpx rgba(28, 122, 91, 0.06);
		border: 2rpx solid rgba(255, 255, 255, 0.9);
		transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
	}

	.identity-card.worker-card {
		background: linear-gradient(150deg, #E6FFF0 0%, #F3FFF8 66%, #FFFFFF 100%);
	}

	.identity-card.shop-card {
		background: linear-gradient(150deg, #E9FBF4 0%, #FFF8E9 70%, #FFFFFF 100%);
	}

	.identity-card.worker-card.active {
		border-color: rgba(18, 183, 106, 0.35);
		box-shadow: 0 18rpx 42rpx rgba(18, 183, 106, 0.14);
		transform: translateY(-4rpx);
	}

	.identity-card.shop-card.active {
		border-color: rgba(255, 151, 68, 0.38);
		box-shadow: 0 18rpx 42rpx rgba(255, 151, 68, 0.14);
		transform: translateY(-4rpx);
	}

	.card-title {
		display: flex;
		align-items: center;
		gap: 8rpx;
		font-size: 22rpx;
		font-weight: 700;
		color: rgba(21, 58, 46, 0.62);
	}

	.info-icon {
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		border: 2rpx solid rgba(21, 58, 46, 0.2);
		color: rgba(21, 58, 46, 0.42);
		font-size: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.card-value {
		margin-top: 12rpx;
		font-size: 46rpx;
		line-height: 50rpx;
		font-weight: 900;
		letter-spacing: -1rpx;
		color: #153A2E;
	}

	.card-today {
		margin-top: 8rpx;
		font-size: 22rpx;
		font-weight: 700;
		color: #12B76A;
	}

	.worker-today-line {
		margin-top: 8rpx;
		max-width: 230rpx;
		font-size: 20rpx;
		line-height: 26rpx;
		font-weight: 900;
		color: #12B76A;
		white-space: nowrap;
		position: relative;
		z-index: 1;
	}

	.worker-today-line text {
		margin-left: 6rpx;
		font-size: 18rpx;
		font-weight: 700;
		color: rgba(18, 183, 106, 0.66);
	}

	.card-link-btn {
		margin-top: auto;
		width: fit-content;
		padding: 9rpx 22rpx;
		border-radius: 999rpx;
		background: #FFFFFF;
		box-shadow: 0 8rpx 20rpx rgba(28, 122, 91, 0.08);
		font-size: 23rpx;
		font-weight: 800;
		color: #137A5A;
		position: absolute;
		left: 22rpx;
		bottom: 18rpx;
		z-index: 2;
	}

	.card-illus {
		position: absolute;
		right: 8rpx;
		bottom: 8rpx;
		font-size: 72rpx;
		line-height: 1;
		filter: drop-shadow(0 10rpx 18rpx rgba(28, 122, 91, 0.14));
		animation: illusFloat 5s ease-in-out infinite alternate;
		pointer-events: none;
		opacity: 0.9;
	}

	.shop-image-illus {
		right: -16rpx;
		bottom: -20rpx;
		width: 120rpx;
		height: 120rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 0;
	}

	.shop-illus-img {
		width: 120rpx;
		height: 120rpx;
		display: block;
	}

	.shop-switch-scroll {
		width: 100%;
		margin-top: 18rpx;
		white-space: nowrap;
	}

	.shop-switch-list {
		display: inline-flex;
		gap: 16rpx;
		padding: 0 2rpx 4rpx;
	}

	.shop-switch-item {
		max-width: 240rpx;
		height: 60rpx;
		line-height: 60rpx;
		padding: 0 24rpx;
		border-radius: 999rpx;
		background: rgba(255, 255, 255, 0.72);
		color: rgba(21, 58, 46, 0.58);
		font-size: 24rpx;
		font-weight: 800;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		box-shadow: inset 0 0 0 1rpx rgba(21, 58, 46, 0.06);
	}

	.shop-switch-item.active {
		background: linear-gradient(90deg, #19C889, #65E08D);
		color: #fff;
		box-shadow: 0 10rpx 22rpx rgba(18, 183, 106, 0.18);
	}

	/* ---------- 余额明细面板 ---------- */
	.flow-panel {
		margin-top: 28rpx;
		padding: 34rpx 30rpx 16rpx;
		border-radius: 40rpx;
		background: #FFFFFF;
		box-shadow: 0 16rpx 40rpx rgba(28, 122, 91, 0.05);
	}

	.section-head {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.flow-tabs {
		display: flex;
		align-items: center;
		gap: 44rpx;
	}

	.flow-tab {
		position: relative;
		padding-bottom: 16rpx;
		font-size: 30rpx;
		font-weight: 800;
		color: rgba(21, 58, 46, 0.36);
	}

	.flow-tab.active {
		color: #153A2E;
	}

	.flow-tab.active::after {
		content: '';
		position: absolute;
		left: 50%;
		bottom: 0;
		width: 52rpx;
		height: 8rpx;
		border-radius: 999rpx;
		background: linear-gradient(90deg, #19C889, #FFB84D);
		transform: translateX(-50%);
	}

	.flow-filter {
		flex: none;
		padding: 12rpx 26rpx;
		border-radius: 999rpx;
		background: #F2FFF8;
		border: 1rpx solid rgba(28, 122, 91, 0.06);
		font-size: 20rpx;
		font-weight: 700;
		color: rgba(21, 58, 46, 0.58);
		display: flex;
		align-items: center;
		gap: 6rpx;
	}

	.filter-caret {
		font-size: 20rpx;
		color: rgba(21, 58, 46, 0.42);
	}

	.timeline-list {
		margin-top: 20rpx;
	}

	.flow-card {
		min-height: 132rpx;
		display: flex;
		align-items: center;
		padding: 26rpx 0;
		box-sizing: border-box;
		border-bottom: 1rpx solid rgba(21, 58, 46, 0.06);
	}

	.flow-card:last-child {
		border-bottom: 0;
	}

	.flow-card.clickable:active {
		opacity: 0.72;
	}

	.flow-icon {
		flex: none;
		width: 88rpx;
		height: 88rpx;
		border-radius: 26rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 24rpx;
		font-size: 44rpx;
	}

	.flow-icon.type-worker {
		background: #E4FFF0;
	}

	.flow-icon.type-shop {
		background: #FFF1DA;
	}

	.flow-icon.type-reward {
		background: #E9FFF1;
	}

	.flow-icon.type-withdraw {
		background: #FFF1DA;
	}

	.flow-icon.type-bill {
		background: #EFFAF4;
	}

	.flow-main {
		flex: 1;
		min-width: 0;
	}

	.flow-title {
		font-size: 29rpx;
		font-weight: 800;
		color: #153A2E;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.flow-subtitle {
		margin-top: 10rpx;
		font-size: 23rpx;
		color: rgba(21, 58, 46, 0.4);
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.flow-right {
		text-align: right;
		margin-left: 20rpx;
		flex: none;
	}

	.flow-amount {
		font-size: 33rpx;
		font-weight: 900;
	}

	.flow-amount.income {
		color: #12B76A;
	}

	.flow-amount.outcome {
		color: #F97316;
	}

	.flow-time {
		margin-top: 10rpx;
		font-size: 22rpx;
		color: rgba(21, 58, 46, 0.4);
	}

	.empty-card {
		padding: 66rpx 24rpx;
		text-align: center;
		color: rgba(21, 58, 46, 0.42);
		font-weight: 700;
	}

	/* ---------- 底部小提示 ---------- */
	.tip-banner {
		position: fixed;
		left: 32rpx;
		right: 32rpx;
		bottom: calc(18rpx + env(safe-area-inset-bottom));
		z-index: 20;
		background: linear-gradient(90deg, #F3FFF4 0%, #FFF4DC 100%);
		border-radius: 999rpx;
		padding: 20rpx 20rpx 20rpx 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-shadow: 0 14rpx 34rpx rgba(28, 122, 91, 0.14);
		border: 2rpx solid rgba(255, 255, 255, 0.86);
	}

	.tip-left {
		display: flex;
		align-items: center;
		gap: 14rpx;
		min-width: 0;
	}

	.tip-icon {
		flex: none;
		font-size: 38rpx;
		filter: drop-shadow(0 6rpx 12rpx rgba(255, 151, 68, 0.22));
	}

	.tip-text {
		font-size: 24rpx;
		font-weight: 600;
		color: #2F614E;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.tip-bold {
		font-weight: 900;
		color: #153A2E;
	}

	.tip-arrow {
		flex: none;
		width: 52rpx;
		height: 52rpx;
		border-radius: 50%;
		background: linear-gradient(135deg, #19C889, #FFB84D);
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-weight: 900;
		box-shadow: 0 8rpx 18rpx rgba(28, 122, 91, 0.24);
	}

	/* ---------- 提现弹层 ---------- */
	.withdraw-popup {
		width: 650rpx;
		border-radius: 40rpx;
		padding: 44rpx 40rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		box-shadow: 0 24rpx 64rpx rgba(21, 58, 46, 0.16);
	}

	.popup-title {
		font-size: 36rpx;
		font-weight: 900;
		color: #153A2E;
		margin-bottom: 32rpx;
		text-align: center;
	}

	.popup-field {
		margin-bottom: 24rpx;
		padding: 22rpx 28rpx;
		border-radius: 26rpx;
		background: #F3FFF8;
	}

	.popup-field text {
		display: block;
		margin-bottom: 12rpx;
		font-size: 24rpx;
		font-weight: 700;
		color: rgba(21, 58, 46, 0.5);
	}

	.popup-field input {
		height: 54rpx;
		min-height: 54rpx;
		font-size: 30rpx;
		font-weight: 800;
		color: #153A2E;
	}

	.popup-btn {
		margin-top: 36rpx;
		width: 100%;
		height: 96rpx;
		line-height: 96rpx;
		border-radius: 999rpx;
		text-align: center;
		font-size: 30rpx;
		font-weight: 900;
		color: #FFFFFF;
		background: linear-gradient(90deg, #19C889, #65E08D);
		box-shadow: 0 14rpx 30rpx rgba(28, 122, 91, 0.22);
		transition: transform 0.16s ease;
	}

	/* ---------- 动画 ---------- */
	.enter-card {
		animation: cardIn 0.46s ease both;
	}

	.amount-roll {
		animation: amountPop 0.72s cubic-bezier(0.18, 0.82, 0.22, 1.1) both;
	}

	.bottom-space {
		height: 170rpx;
	}

	@keyframes cardIn {
		0% {
			opacity: 0;
			transform: translateY(22rpx);
		}
		100% {
			opacity: 1;
			transform: translateY(0);
		}
	}

	@keyframes amountPop {
		0% {
			opacity: 0;
			transform: translateY(16rpx) scale(0.96);
		}
		100% {
			opacity: 1;
			transform: translateY(0) scale(1);
		}
	}

	@keyframes auraFloat {
		0% {
			transform: translate3d(0, 0, 0) scale(1);
		}
		100% {
			transform: translate3d(18rpx, -18rpx, 0) scale(1.06);
		}
	}

	@keyframes illusFloat {
		0% {
			transform: translateY(0) rotate(-2deg);
		}
		100% {
			transform: translateY(-12rpx) rotate(4deg);
		}
	}

	@keyframes starTwinkle {
		0% {
			opacity: 0.35;
			transform: scale(0.85);
		}
		100% {
			opacity: 1;
			transform: scale(1.1);
		}
	}
</style>
