<?php
require_once __DIR__ . '/../db/config.php';
session_start();

$user = null;
if (isset($_SESSION['user_id'])) {
    $stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
    $stmt->execute([$_SESSION['user_id']]);
    $user = $stmt->fetch();
}

$lang = $_GET['lang'] ?? $_SESSION['lang'] ?? 'en';
if (!in_array($lang, ['en', 'zh'])) {
    $lang = 'en';
}
$_SESSION['lang'] = $lang;

function mt($key) {
    global $lang;
    $translations = [
        'en' => [
            'Home' => 'Home', 'Spot' => 'Spot', 'Perpetual' => 'Perpetual', 'Markets' => 'Markets', 'Exchange' => 'Exchange',
            'Login' => 'Login', 'Register' => 'Register', 'Profile' => 'Profile', 'Logout' => 'Logout',
            'Deposit' => 'Deposit', 'Withdraw' => 'Withdraw', 'Assets' => 'Assets', 'Security' => 'Security',
            'Buy' => 'Buy', 'Sell' => 'Sell', 'Limit' => 'Limit', 'Market' => 'Market', 'Price' => 'Price',
            'Amount' => 'Amount', 'Total' => 'Total', 'Available' => 'Available', 'Trade' => 'Trade',
            'Market Trends' => 'Market Trends', 'Real-time Prices' => 'Real-time Prices', 'High' => 'High', 'Low' => 'Low',
            'Download App' => 'Download App', 'Customer Service' => 'Customer Service',
            'Identity Verification' => 'Identity Verification', 'Trading Password' => 'Trading Password',
            'Success' => 'Success', 'Error' => 'Error', 'Matching Account' => 'Matching Account',
            'Establishing secure connection with liquidity provider...' => 'Establishing secure connection with liquidity provider...',
            'Awaiting merchant confirmation...' => 'Awaiting merchant confirmation...',
            'Matching in progress' => 'Matching in progress',
            'The specialized account for this transaction will be provided by our agent shortly.' => 'The specialized account for this transaction will be provided by our agent shortly.',
            'Transfer the exact amount. Upload proof below.' => 'Transfer the exact amount. Upload proof below.',
            'Bank Name' => 'Bank Name', 'Account Number' => 'Account Number', 'Beneficiary' => 'Beneficiary', 'Reference' => 'Reference',
            'Copy' => 'Copy', 'Upload Proof' => 'Upload Proof', 'Selected' => 'Selected', 'Transfer Completed' => 'Transfer Completed',
            'Your transfer is being reviewed. ETA: 10-20 mins.' => 'Your transfer is being reviewed. ETA: 10-20 mins.',
            'Back to Wallet' => 'Back to Wallet', 'Matched & Active' => 'Matched & Active',
            'Services' => 'Services', 'Spot Trading' => 'Spot Trading', 'Futures Trading' => 'Futures Trading',
            'Support' => 'Support', 'Help Center' => 'Help Center', 'About Us' => 'About Us', 'Privacy Policy' => 'Privacy Policy', 'Terms of Service' => 'Terms of Service',
            'System Status' => 'System Status', 'Normal' => 'Normal', 'Overview' => 'Overview', 'Full Name' => 'Full Name', 'ID Number' => 'ID Number', 'Submit' => 'Submit', 'Next-Gen Trading Engine' => 'Next-Gen Trading Engine',
            'Experience ultra-low latency and institutional-grade liquidity on our professional K-line trading platform.' => 'Experience ultra-low latency and institutional-grade liquidity on our professional K-line trading platform.',
            'Register Now' => 'Register Now', 'Start Trading' => 'Start Trading', 'Go to Futures' => 'Go to Futures', 'Global Crypto Hub' => 'Global Crypto Hub',
            'Access real-time global market data and execute trades across multiple asset classes with one unified account.' => 'Access real-time global market data and execute trades across multiple asset classes with one unified account.',
            'Secure Asset Custody' => 'Secure Asset Custody', 'Your funds are safe with our institutional-grade security, multi-sig cold storage, and comprehensive insurance fund.' => 'Your funds are safe with our institutional-grade security, multi-sig cold storage, and comprehensive insurance fund.',
            'Security Center' => 'Security Center', '24/7 Global Support' => '24/7 Global Support', 'Our dedicated professional support team is available around the clock to assist you in multiple languages.' => 'Our dedicated professional support team is available around the clock to assist you in multiple languages.',
            'Contact Support' => 'Contact Support', 'Asset' => 'Asset', '24h Change' => '24h Change', '24h High' => '24h High', 'Action' => 'Action', 'All Markets' => 'All Markets',
            'Real-time updates from global exchanges' => 'Real-time updates from global exchanges', 'Safe & Secure' => 'Safe & Secure', 'Industry-leading encryption and multi-signature cold storage for your digital assets.' => 'Industry-leading encryption and multi-signature cold storage for your digital assets.',
            'Instant Execution' => 'Instant Execution', 'Advanced matching engine processing over 100,000 transactions per second.' => 'Advanced matching engine processing over 100,000 transactions per second.',
            'Verification' => 'Verification', 'Reviewing...' => 'Reviewing...', 'Verified' => 'Verified', 'Unverified' => 'Unverified', 'Pending' => 'Pending', 'Approved' => 'Approved', 'Rejected' => 'Rejected',
            'Front Side' => 'Front Side', 'Back Side' => 'Back Side', 'Selfie with ID' => 'Selfie with ID',
            'Change Login Password' => 'Change Login Password', 'Change Trading Password' => 'Change Trading Password',
            'digits' => 'digits', 'Current Password' => 'Current Password', 'New Password' => 'New Password', 'Confirm New Password' => 'Confirm New Password',
            'Save Changes' => 'Save Changes', 'Cancel' => 'Cancel', 'Account Overview' => 'Account Overview', 'Total Balance' => 'Total Balance',
            'Recent Activities' => 'Recent Activities', 'Time' => 'Time', 'Account Login' => 'Account Login', 'Assets Overview' => 'Assets Overview',
            'Total Net Value' => 'Total Net Value', 'Yesterday Profit/Loss' => 'Yesterday Profit/Loss', 'Security Settings' => 'Security Settings',
            'Last updated' => 'Last updated', 'Recently' => 'Recently', 'Required for withdrawals' => 'Required for withdrawals', 'Link' => 'Link',
            'Enter your real name' => 'Enter your real name', 'Enter ID/Passport Number' => 'Enter ID/Passport Number', 'Change' => 'Change',
            'Name' => 'Name', 'Price' => 'Price', 'Trade' => 'Trade', 'View All' => 'View All', 'Market Trends' => 'Market Trends', 'Stay updated with real-time price changes' => 'Stay updated with real-time price changes',
            'Get Started' => 'Get Started', 'View Markets' => 'View Markets', 'The World\'s Leading' => 'The World\'s Leading', 'Crypto Exchange' => 'Crypto Exchange',
            'Secure & Trusted' => 'Secure & Trusted', 'Institutional Grade' => 'Institutional Grade', 'Deep Liquidity' => 'Deep Liquidity', 'Global Access' => 'Global Access',
            'Perpetual Contracts' => 'Perpetual Contracts', '100x Leverage' => '100x Leverage', 'Join the Elite' => 'Join the Elite', 'Trust BITCrypto' => 'Trust BITCrypto',
            'Funds' => 'Funds', 'Recharge' => 'Recharge', 'Withdrawal' => 'Withdrawal', 'Stop-Loss' => 'Stop-Loss', 'Take-Profit' => 'Take-Profit', 'Search' => 'Search', 'Search Pairs' => 'Search Pairs', 'Open Orders' => 'Open Orders', 'Order History' => 'Order History', 'Positions' => 'Positions', 'No open orders' => 'No open orders', 'Lots' => 'Lots', 'Cancel' => 'Cancel', 'Order submitted successfully!' => 'Order submitted successfully!', 'Please enter a valid amount.' => 'Please enter a valid amount.', 'Username' => 'Username', 'Password' => 'Password', 'Sign In' => 'Sign In', 'Sign Up' => 'Sign Up', 'Email' => 'Email', 'Already have an account?' => 'Already have an account?', 'Don\'t have an account?' => 'Don\'t have an account?', 'Confirm Password' => 'Confirm Password', 'Create Account' => 'Create Account',
            'Trade Bitcoin, Ethereum, and hundreds of other cryptocurrencies with the lowest fees in the industry.' => 'Trade Bitcoin, Ethereum, and hundreds of other cryptocurrencies with the lowest fees in the industry.',
            'Why Choose BITCrypto?' => 'Why Choose BITCrypto?', 'Experience the most professional trading environment with institutional-grade security and liquidity.' => 'Experience the most professional trading environment with institutional-grade security and liquidity.',
            'Multi-sig Cold Storage' => 'Multi-sig Cold Storage', 'DDoS Protection' => 'DDoS Protection', '2FA Security' => '2FA Security',
            'Ultra-low Latency' => 'Ultra-low Latency', 'High Liquidity' => 'High Liquidity', 'Zero Slippage' => 'Zero Slippage',
            'Multi-language Support' => 'Multi-language Support', 'Live Chat' => 'Live Chat', 'Fast Response' => 'Fast Response',
            'Trade Anywhere, Anytime' => 'Trade Anywhere, Anytime', 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.' => 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.',
            'Download on the' => 'Download on the', 'Get it on' => 'Get it on', 'Scan to download' => 'Scan to download', 'Compatible with iOS and Android devices.' => 'Compatible with iOS and Android devices.',
            'Global Trust' => 'Global Trust', 'Our Global Partners' => 'Our Global Partners', 'Smart Contracts' => 'Smart Contracts', 'Primary Network' => 'Primary Network', 'Security Audit' => 'Security Audit', 'Financial Partner' => 'Financial Partner', 'Strategic Advisor' => 'Strategic Advisor',
            'Please fill in all fields.' => 'Please fill in all fields.', 'Invalid username or password.' => 'Invalid username or password.', 'Login failed.' => 'Login failed.', 'Login to BITCrypto' => 'Login to BITCrypto', 'Enter username' => 'Enter username', 'Enter password' => 'Enter password', 'Remember me' => 'Remember me', 'Forgot password?' => 'Forgot password?', 'Passwords do not match.' => 'Passwords do not match.', 'You must agree to the terms and privacy policy.' => 'You must agree to the terms and privacy policy.', 'Username already exists.' => 'Username already exists.', 'Username / Email' => 'Username / Email', 'Repeat password' => 'Repeat password', 'I have read and agree to the' => 'I have read and agree to the', 'Join the world\'s leading crypto exchange' => 'Join the world\'s leading crypto exchange', 'Search assets...' => 'Search assets...', 'No assets found' => 'No assets found', 'Pair' => 'Pair', 'Side' => 'Side', 'Filled' => 'Filled',
            'Receipt uploaded successfully. Waiting for admin approval.' => 'Receipt uploaded successfully. Waiting for admin approval.',
            'Deposit Assets' => 'Deposit Assets', 'Choose your preferred method to fund your account' => 'Choose your preferred method to fund your account',
            'Crypto Deposit' => 'Crypto Deposit', 'Fiat Deposit' => 'Fiat Deposit', 'Instant' => 'Instant', 'Regional Support' => 'Regional Support',
            'Select Currency' => 'Select Currency', 'Network' => 'Network', 'Deposit Address' => 'Deposit Address', 'Scan QR code to deposit' => 'Scan QR code to deposit',
            'Deposit Amount' => 'Deposit Amount', 'Upload screenshot of your transaction' => 'Upload screenshot of your transaction', 'Submit Deposit' => 'Submit Deposit',
            'Select Fiat Currency' => 'Select Fiat Currency', 'We will match you with a local merchant to facilitate your deposit in your local currency.' => 'We will match you with a local merchant to facilitate your deposit in your local currency.',
            'Est. Arrival' => 'Est. Arrival', 'Processing Time: 10-30 mins' => 'Processing Time: 10-30 mins', 'Exchange Rate' => 'Exchange Rate',
            'Service Fee' => 'Service Fee', 'Free' => 'Free', 'Confirm Deposit' => 'Confirm Deposit', 'Secure Payment' => 'Secure Payment',
            'All transactions are encrypted' => 'All transactions are encrypted', 'Fast Arrival' => 'Fast Arrival', 'Most deposits arrive in mins' => 'Most deposits arrive in mins',
            'Address copied to clipboard' => 'Address copied to clipboard', 'Withdrawal Address' => 'Withdrawal Address', 'Notes' => 'Notes',
            'Withdrawals are processed within 10-30 minutes.' => 'Withdrawals are processed within 10-30 minutes.',
            'Minimum withdrawal amount is 10 USDT.' => 'Minimum withdrawal amount is 10 USDT.',
            'Ensure the receiving address supports the TRC20 network.' => 'Ensure the receiving address supports the TRC20 network.',
            'Current password incorrect.' => 'Current password incorrect.',
            'Identity verification submitted and is under review.' => 'Identity verification submitted and is under review.',
            'New passwords do not match.' => 'New passwords do not match.', 'Password must be at least 6 characters.' => 'Password must be at least 6 characters.',
            'Password updated successfully.' => 'Password updated successfully.', 'Update failed' => 'Update failed',
            'Login Password' => 'Login Password', '2FA Authentication' => '2FA Authentication', 'Google Authenticator' => 'Google Authenticator',
            'Your identity documents are being verified by our team.' => 'Your identity documents are being verified by our team.',
            'Submitted Details' => 'Submitted Details', 'Verified Identity' => 'Verified Identity',
            'Your account is fully verified for all features.' => 'Your account is fully verified for all features.',
            'Current Trading Password' => 'Current Trading Password', 'New Trading Password' => 'New Trading Password',
            'Confirm New Trading Password' => 'Confirm New Trading Password', 'Withdrawal request submitted successfully.' => 'Withdrawal request submitted successfully.',
            'Insufficient balance.' => 'Insufficient balance.', 'Why Choose BITCrypto?' => 'Why Choose BITCrypto?',
            'Experience the most professional trading environment with institutional-grade security and liquidity.' => 'Experience the most professional trading environment with institutional-grade security and liquidity.',
            'Multi-sig Cold Storage' => 'Multi-sig Cold Storage', 'DDoS Protection' => 'DDoS Protection', '2FA Security' => '2FA Security',
            'Ultra-low Latency' => 'Ultra-low Latency', 'High Liquidity' => 'High Liquidity', 'Zero Slippage' => 'Zero Slippage',
            'Multi-language Support' => 'Multi-language Support', 'Live Chat' => 'Live Chat', 'Fast Response' => 'Fast Response',
            'Trade Anywhere, Anytime' => 'Trade Anywhere, Anytime', 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.' => 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.',
            'Download on the' => 'Download on the', 'Get it on' => 'Get it on', 'Scan to download' => 'Scan to download', 'Compatible with iOS and Android devices.' => 'Compatible with iOS and Android devices.',
            'Global Trust' => 'Global Trust', 'Our Global Partners' => 'Our Global Partners', 'Smart Contracts' => 'Smart Contracts', 'Primary Network' => 'Primary Network', 'Security Audit' => 'Security Audit', 'Financial Partner' => 'Financial Partner', 'Strategic Advisor' => 'Strategic Advisor'
        ],
        'zh' => [
            'Home' => '首页', 'Spot' => '币币交易', 'Perpetual' => '合约交易', 'Markets' => '行情', 'Exchange' => '交易',
            'Login' => '登录', 'Register' => '注册', 'Profile' => '个人中心', 'Logout' => '退出登录',
            'Deposit' => '充值', 'Withdraw' => '提现', 'Assets' => '资产', 'Security' => '安全',
            'Buy' => '买入', 'Sell' => '卖出', 'Limit' => '限价', 'Market' => '市价', 'Price' => '价格',
            'Amount' => '数量', 'Total' => '总额', 'Available' => '可用', 'Trade' => '交易',
            'Market Trends' => '市场趋势', 'Real-time Prices' => '实时价格', 'High' => '最高', 'Low' => '最低',
            'Download App' => '下载APP', 'Customer Service' => '客服中心',
            'Identity Verification' => '实名认证', 'Trading Password' => '交易密码',
            'Success' => '成功', 'Error' => '错误', 'Matching Account' => '匹配账号',
            'Establishing secure connection with liquidity provider...' => '正在与流动性提供商建立安全连接...',
            'Awaiting merchant confirmation...' => '等待商家确认...',
            'Matching in progress' => '正在匹配中',
            'The specialized account for this transaction will be provided by our agent shortly.' => '交易专用账号将由我们的代理稍后提供。',
            'Transfer the exact amount. Upload proof below.' => '请转入准确金额，并在下方上传凭证。',
            'Bank Name' => '银行名称', 'Account Number' => '账号', 'Beneficiary' => '收款人', 'Reference' => '备注',
            'Copy' => '复制', 'Upload Proof' => '上传凭证', 'Selected' => '已选择', 'Transfer Completed' => '转账已完成',
            'Your transfer is being reviewed. ETA: 10-20 mins.' => '您的转账正在审核中，预计 10-20 分钟。',
            'Back to Wallet' => '返回钱包', 'Matched & Active' => '已匹配并激活',
            'Services' => '服务', 'Spot Trading' => '币币交易', 'Futures Trading' => '合约交易',
            'Support' => '支持', 'Help Center' => '帮助中心', 'About Us' => '关于我们', 'Privacy Policy' => '隐私政策', 'Terms of Service' => '服务条款',
            'System Status' => '系统状态', 'Normal' => '正常', 'Overview' => '概览', 'Full Name' => '姓名', 'ID Number' => '身份证号', 'Submit' => '提交', 'Next-Gen Trading Engine' => '次世代交易引擎',
            'Experience ultra-low latency and institutional-grade liquidity on our professional K-line trading platform.' => '在我们的专业K线交易平台上体验极低延迟和机构级流动性。',
            'Register Now' => '立即注册', 'Start Trading' => '开始交易', 'Go to Futures' => '前往合约', 'Global Crypto Hub' => '全球加密枢纽',
            'Access real-time global market data and execute trades across multiple asset classes with one unified account.' => '通过一个统一账户访问实时全球市场数据并执行跨多个资产类别的交易。',
            'Secure Asset Custody' => '安全资产托管', 'Your funds are safe with our institutional-grade security, multi-sig cold storage, and comprehensive insurance fund.' => '您的资金在我们的机构级安全、多重签名冷存储和全面保险基金的保护下非常安全。',
            'Security Center' => '安全中心', '24/7 Global Support' => '24/7 全球支持', 'Our dedicated professional support team is available around the clock to assist you in multiple languages.' => '我们专业的支持团队全天候为您提供多种语言的帮助。',
            'Contact Support' => '联系支持', 'Asset' => '资产', '24h Change' => '24h涨跌', '24h High' => '24h最高', 'Action' => '操作', 'All Markets' => '所有市场',
            'Real-time updates from global exchanges' => '来自全球交易所的实时更新', 'Safe & Secure' => '安全可靠', 'Industry-leading encryption and multi-signature cold storage for your digital assets.' => '为您的数字资产提供行业领先的加密和多重签名冷存储。',
            'Instant Execution' => '即时执行', 'Advanced matching engine processing over 100,000 transactions per second.' => '先进的撮合引擎，每秒处理超过100,000笔交易。',
            'Verification' => '实名认证', 'Reviewing...' => '审核中...', 'Verified' => '已认证', 'Unverified' => '未认证', 'Pending' => '审核中', 'Approved' => '已通过', 'Rejected' => '已拒绝',
            'Front Side' => '正面', 'Back Side' => '反面', 'Selfie with ID' => '手持证件照',
            'Change Login Password' => '修改登录密码', 'Change Trading Password' => '修改交易密码',
            'digits' => '位数字', 'Current Password' => '当前密码', 'New Password' => '新密码', 'Confirm New Password' => '确认新密码',
            'Save Changes' => '保存修改', 'Cancel' => '取消', 'Account Overview' => '账户概览', 'Total Balance' => '总余额',
            'Recent Activities' => '最近活动', 'Time' => '时间', 'Account Login' => '账号登录', 'Assets Overview' => '资产概览',
            'Total Net Value' => '总净值', 'Yesterday Profit/Loss' => '昨日盈亏', 'Security Settings' => '安全设置',
            'Last updated' => '最后更新', 'Recently' => '最近', 'Required for withdrawals' => '提现必填', 'Link' => '去绑定',
            'Enter your real name' => '输入真实姓名', 'Enter ID/Passport Number' => '输入证件号码', 'Change' => '去修改',
            'Name' => '币种', 'Price' => '价格', 'Trade' => '去交易', 'View All' => '查看全部', 'Market Trends' => '市场趋势', 'Stay updated with real-time price changes' => '实时掌握价格动态',
            'Get Started' => '立即开始', 'View Markets' => '查看行情', 'The World\'s Leading' => '全球领先的', 'Crypto Exchange' => '数字货币交易所',
            'Secure & Trusted' => '安全可信', 'Institutional Grade' => '机构级水准', 'Deep Liquidity' => '深度流动性', 'Global Access' => '全球访问',
            'Perpetual Contracts' => '永续合约', '100x Leverage' => '100倍杠杆', 'Join the Elite' => '加入精英行列', 'Trust BITCrypto' => '信赖 BITCrypto',
            'Funds' => '资金', 'Recharge' => '充值', 'Withdrawal' => '提现', 'Stop-Loss' => '止损', 'Take-Profit' => '止盈', 'Search' => '搜索', 'Search Pairs' => '搜索币对', 'Open Orders' => '当前委托', 'Order History' => '历史委托', 'Positions' => '当前持仓', 'No open orders' => '暂无挂单', 'Lots' => '张数', 'Cancel' => '撤单', 'Order submitted successfully!' => '订单提交成功！', 'Please enter a valid amount.' => '请输入有效数量。', 'Username' => '用户名', 'Password' => '密码', 'Sign In' => '登录', 'Sign Up' => '注册', 'Email' => '电子邮箱', 'Already have an account?' => '已有账号？', 'Don\'t have an account?' => '还没有账号？', 'Confirm Password' => '确认密码', 'Create Account' => '创建账号',
            'Trade Bitcoin, Ethereum, and hundreds of other cryptocurrencies with the lowest fees in the industry.' => '以行业最低的费用交易比特币、以太坊和数百种其他加密货币。',
            'Why Choose BITCrypto?' => '为什么选择 BITCrypto？', 'Experience the most professional trading environment with institutional-grade security and liquidity.' => '体验最专业的交易环境，拥有机构级的安全性和流动性。',
            'Multi-sig Cold Storage' => '多重签名冷存储', 'DDoS Protection' => 'DDoS 防护', '2FA Security' => '双重身份验证',
            'Ultra-low Latency' => '极低延迟', 'High Liquidity' => '高流动性', 'Zero Slippage' => '零滑点',
            'Multi-language Support' => '多语言支持', 'Live Chat' => '在线聊天', 'Fast Response' => '快速响应',
            'Trade Anywhere, Anytime' => '随时随地交易', 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.' => '在您的移动设备上体验我们交易所的全部功能。轻松进行现货和合约交易。',
            'Download on the' => '在 App Store 下载', 'Get it on' => '在 Google Play 获取', 'Scan to download' => '扫描下载', 'Compatible with iOS and Android devices.' => '兼容 iOS 和 Android 设备。',
            'Global Trust' => '全球信任', 'Our Global Partners' => '我们的全球合作伙伴', 'Smart Contracts' => '智能合约', 'Primary Network' => '主网', 'Security Audit' => '安全审计', 'Financial Partner' => '金融合作伙伴', 'Strategic Advisor' => '战略顾问',
            'Please fill in all fields.' => '请填写所有字段。', 'Invalid username or password.' => '用户名或密码无效。', 'Login failed.' => '登录失败。', 'Login to BITCrypto' => '登录到 BITCrypto', 'Enter username' => '输入用户名', 'Enter password' => '输入密码', 'Remember me' => '记住我', 'Forgot password?' => '忘记密码？', 'Passwords do not match.' => '密码不匹配。', 'You must agree to the terms and privacy policy.' => '您必须同意服务条款和隐私政策。', 'Username already exists.' => '用户名已存在。', 'Username / Email' => '用户名 / 邮箱', 'Repeat password' => '重复密码', 'I have read and agree to the' => '我已阅读并同意', 'Join the world\'s leading crypto exchange' => '加入全球领先的加密交易所', 'Search assets...' => '搜索资产...', 'No assets found' => '未找到资产', 'Pair' => '交易对', 'Side' => '方向', 'Filled' => '已成交',
            'Receipt uploaded successfully. Waiting for admin approval.' => '凭证上传成功。等待管理员审核。',
            'Deposit Assets' => '充值资产', 'Choose your preferred method to fund your account' => '选择您喜欢的充值方式',
            'Crypto Deposit' => '数字货币充值', 'Fiat Deposit' => '法币充值', 'Instant' => '即时', 'Regional Support' => '地区支持',
            'Select Currency' => '选择币种', 'Network' => '网络', 'Deposit Address' => '充值地址', 'Scan QR code to deposit' => '扫描二维码进行充值',
            'Deposit Amount' => '充值金额', 'Upload screenshot of your transaction' => '上传您的交易截图', 'Submit Deposit' => '提交充值',
            'Select Fiat Currency' => '选择法币', 'We will match you with a local merchant to facilitate your deposit in your local currency.' => '我们将为您匹配当地商家，以便您以当地货币进行充值。',
            'Est. Arrival' => '预计到账', 'Processing Time: 10-30 mins' => '处理时间：10-30 分钟', 'Exchange Rate' => '汇率',
            'Service Fee' => '服务费', 'Free' => '免费', 'Confirm Deposit' => '确认充值', 'Secure Payment' => '安全支付',
            'All transactions are encrypted' => '所有交易均已加密', 'Fast Arrival' => '快速到账', 'Most deposits arrive in mins' => '大多数充值在几分钟内到账',
            'Address copied to clipboard' => '地址已复制到剪贴板', 'Withdrawal Address' => '提现地址', 'Notes' => '注意事项',
            'Withdrawals are processed within 10-30 minutes.' => '提现将在 10-30 分钟内处理。',
            'Minimum withdrawal amount is 10 USDT.' => '最低提现金额为 10 USDT。',
            'Ensure the receiving address supports the TRC20 network.' => '确保接收地址支持 TRC20 网络。',
            'Current password incorrect.' => '当前密码错误。',
            'Identity verification submitted and is under review.' => '身份认证已提交，正在审核中。',
            'New passwords do not match.' => '新密码不匹配。', 'Password must be at least 6 characters.' => '密码长度必须至少为 6 个字符。',
            'Password updated successfully.' => '密码更新成功。', 'Update failed' => '更新失败',
            'Login Password' => '登录密码', '2FA Authentication' => '双重身份验证', 'Google Authenticator' => '谷歌身份验证器',
            'Your identity documents are being verified by our team.' => '我们的团队正在验证您的身份文件。',
            'Submitted Details' => '已提交详情', 'Verified Identity' => '已验证身份',
            'Your account is fully verified for all features.' => '您的账户已完全通过验证，可以使用所有功能。',
            'Current Trading Password' => '当前交易密码', 'New Trading Password' => '新交易密码',
            'Confirm New Trading Password' => '确认新交易密码', 'Withdrawal request submitted successfully.' => '提现申请提交成功。',
            'Insufficient balance.' => '余额不足。', 'Why Choose BITCrypto?' => '为什么选择 BITCrypto？',
            'Experience the most professional trading environment with institutional-grade security and liquidity.' => '体验最专业的交易环境，拥有机构级的安全性和流动性。',
            'Multi-sig Cold Storage' => '多重签名冷存储', 'DDoS Protection' => 'DDoS 防护', '2FA Security' => '双重身份验证',
            'Ultra-low Latency' => '极低延迟', 'High Liquidity' => '高流动性', 'Zero Slippage' => '零滑点',
            'Multi-language Support' => '多语言支持', 'Live Chat' => '在线聊天', 'Fast Response' => '快速响应',
            'Trade Anywhere, Anytime' => '随时随地交易', 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.' => '在您的移动设备上体验我们交易所的全部功能。轻松进行现货和合约交易。',
            'Download on the' => '在 App Store 下载', 'Get it on' => '在 Google Play 获取', 'Scan to download' => '扫描下载', 'Compatible with iOS and Android devices.' => '兼容 iOS 和 Android 设备。',
            'Global Trust' => '全球信任', 'Our Global Partners' => '我们的全球合作伙伴', 'Smart Contracts' => '智能合约', 'Primary Network' => '主网', 'Security Audit' => '安全审计', 'Financial Partner' => '金融合作伙伴', 'Strategic Advisor' => '战略顾问'
        ]
    ];
    return $translations[$lang][$key] ?? $key;
}

$current_page = basename($_SERVER['PHP_SELF']);
$is_home = $current_page === 'index.php';
?>
<!DOCTYPE html>
<html lang="<?php echo $lang; ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>BITCrypto | Professional Crypto Exchange</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
    <link rel="icon" type="image/png" href="favicon.png">
    <style>
        :root {
            --primary-bg: #101216; 
            --secondary-bg: #181a20;
            --accent-color: #f0b90b;
            --text-main: #eaecef;
            --text-muted: #848e9c;
            --success: #0ecb81;
            --danger: #f6465d;
            --okx-blue: #0046ff;
            --bit-gradient: linear-gradient(45deg, #0046ff, #00ff96);
        }

        body {
            background-color: var(--primary-bg);
            color: var(--text-main);
            padding-bottom: 70px; 
        }

        @media (min-width: 992px) {
            body { padding-bottom: 0; }
        }

        .navbar { background: var(--primary-bg); border-bottom: 1px solid #2b2f36; padding: 0.8rem 0; }
        .logo-text {
            font-size: 1.5rem;
            font-weight: 800;
            background: var(--bit-gradient);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            letter-spacing: -0.5px;
        }
        .logo-img {
            height: 40px;
            margin-right: 12px;
            background: transparent !important;
            border: none !important;
            display: block;
            box-shadow: none !important;
            object-fit: contain;
        }

        .back-button {
            display: <?php echo $is_home ? 'none' : 'flex'; ?>;
            align-items: center;
            gap: 8px;
            color: var(--text-muted);
            text-decoration: none;
            font-weight: 600;
            padding: 8px 16px;
            border-radius: 20px;
            background: rgba(255,255,255,0.05);
            transition: all 0.3s;
            margin-right: 15px;
        }
        .back-button:hover { background: rgba(255,255,255,0.1); color: white; }

        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 65px;
            background: rgba(16, 18, 22, 0.98);
            backdrop-filter: blur(20px);
            border-top: 1px solid rgba(255,255,255,0.05);
            display: flex;
            justify-content: space-around;
            align-items: center;
            z-index: 2001;
            padding-bottom: env(safe-area-inset-bottom);
        }
        .nav-item-mobile {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: #848e9c;
            text-decoration: none !important;
            font-size: 0.65rem;
            font-weight: 500;
            transition: all 0.2s;
            flex: 1;
        }
        .nav-item-mobile i {
            font-size: 1.3rem;
            margin-bottom: 4px;
        }
        .nav-item-mobile.active {
            color: white;
        }
        .nav-item-mobile.active i {
            color: var(--okx-blue);
        }

        .floating-chat {
            position: fixed;
            bottom: 85px;
            right: 20px;
            z-index: 2000;
            width: 50px;
            height: 50px;
            background: var(--bit-gradient);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.3rem;
            box-shadow: 0 8px 20px rgba(0, 70, 255, 0.3);
            cursor: pointer;
            text-decoration: none;
        }

        @media (min-width: 992px) {
            .bottom-nav { display: none; }
            .floating-chat { bottom: 30px; right: 30px; width: 65px; height: 65px; font-size: 1.8rem; }
        }

        .mobile-top-bar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 15px;
            background: var(--primary-bg);
            border-bottom: 1px solid rgba(255,255,255,0.05);
        }
        @media (min-width: 992px) {
            .mobile-top-bar { display: none; }
        }

        @media (min-width: 992px) {
            .navbar .container {
                max-width: 100%;
                padding-left: 20px;
                padding-right: 20px;
            }
            .navbar-nav {
                margin-left: 20px !important;
            }
        }
        
        .nav-link {
            font-weight: 500;
            color: #eaecef !important;
            padding: 0.5rem 1rem !important;
        }
        .nav-link:hover, .nav-link.active {
            color: var(--okx-blue) !important;
        }
        .dropdown-menu {
            background-color: var(--secondary-bg);
            border: 1px solid #2b2f36;
            border-radius: 12px;
            padding: 10px 0;
            margin-top: 10px;
        }
        .dropdown-item {
            color: #eaecef;
            padding: 10px 20px;
            font-size: 0.9rem;
            transition: all 0.2s;
        }
        .dropdown-item:hover {
            background-color: rgba(255,255,255,0.05);
            color: var(--okx-blue);
        }
    </style>
</head>
<body>

<div class="mobile-top-bar d-lg-none sticky-top">
    <div class="d-flex align-items-center">
        <?php if ($user): ?>
            <a href="profile.php" class="rounded-circle bg-secondary d-flex align-items-center justify-content-center text-white fw-bold me-3" style="width: 32px; height: 32px; font-size: 0.8rem;">
                <?php echo strtoupper(substr($user['username'], 0, 1)); ?>
            </a>
        <?php else: ?>
            <a href="login.php" class="text-muted me-3" style="font-size: 1.2rem;"><i class="fas fa-user-circle"></i></a>
        <?php endif; ?>
        <div class="search-box bg-white bg-opacity-5 rounded-pill px-3 py-1 d-flex align-items-center" style="width: 150px;">
            <i class="fas fa-search text-muted me-2" style="font-size: 0.8rem;"></i>
            <span class="text-muted x-small"><?php echo mt('Search'); ?></span>
        </div>
    </div>
    <div class="d-flex align-items-center gap-3">
        <a href="chat.php" class="text-muted" style="font-size: 1.1rem;"><i class="fas fa-headset"></i></a>
        <a href="#" class="text-muted" style="font-size: 1.1rem;"><i class="fas fa-bell"></i></a>
    </div>
</div>

<nav class="navbar navbar-expand-lg navbar-dark d-none d-lg-block sticky-top">
    <div class="container">
        <div class="d-flex align-items-center">
            <a href="javascript:history.back()" class="back-button">
                <i class="fas fa-chevron-left"></i>
            </a>
            <a class="navbar-brand d-flex align-items-center" href="index.php">
                <img src="assets/images/logo.png" alt="Logo" class="logo-img">
                <span class="logo-text">BITCrypto</span>
            </a>
        </div>
        
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                <li class="nav-item"><a class="nav-link <?php echo $current_page == 'index.php' ? 'active' : ''; ?>" href="index.php"><?php echo mt('Home'); ?></a></li>
                <li class="nav-item"><a class="nav-link <?php echo $current_page == 'market.php' ? 'active' : ''; ?>" href="market.php"><?php echo mt('Markets'); ?></a></li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle <?php echo $current_page == 'trade.php' ? 'active' : ''; ?>" href="#" id="tradeDropdown" role="button" data-bs-toggle="dropdown">
                        <?php echo mt('Trade'); ?>
                    </a>
                    <ul class="dropdown-menu shadow-lg">
                        <li><a class="dropdown-item" href="trade.php?type=spot"><i class="fas fa-exchange-alt me-2"></i> <?php echo mt('Spot'); ?></a></li>
                        <li><a class="dropdown-item" href="trade.php?type=contract"><i class="fas fa-bolt me-2"></i> <?php echo mt('Perpetual'); ?></a></li>
                    </ul>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="fundsDropdown" role="button" data-bs-toggle="dropdown">
                        <?php echo mt('Funds'); ?>
                    </a>
                    <ul class="dropdown-menu shadow-lg">
                        <li><a class="dropdown-item" href="deposit.php"><i class="fas fa-arrow-down me-2"></i> <?php echo mt('Recharge'); ?></a></li>
                        <li><a class="dropdown-item" href="withdraw.php"><i class="fas fa-arrow-up me-2"></i> <?php echo mt('Withdrawal'); ?></a></li>
                    </ul>
                </li>
            </ul>
            
            <ul class="navbar-nav align-items-center">
                <li class="nav-item dropdown me-2">
                    <a class="nav-link dropdown-toggle" href="#" id="langDropdown" role="button" data-bs-toggle="dropdown">
                        <i class="fas fa-globe me-1"></i> <?php echo $lang == 'zh' ? '简体中文' : 'English'; ?>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-end shadow-lg">
                        <li><a class="dropdown-item" href="?lang=en">English</a></li>
                        <li><a class="dropdown-item" href="?lang=zh">简体中文</a></li>
                    </ul>
                </li>
                
                <?php if ($user): ?>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <div class="rounded-circle bg-primary d-flex align-items-center justify-content-center text-white fw-bold me-2" style="width: 32px; height: 32px; font-size: 0.8rem; background: var(--bit-gradient) !important;">
                                <?php echo strtoupper(substr($user['username'], 0, 1)); ?>
                            </div>
                            <?php echo htmlspecialchars($user['username']); ?>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end shadow-lg">
                            <li class="px-3 py-2 small text-muted border-bottom border-secondary mb-1">UID: <?php echo str_pad($user['uid'] ?? 0, 6, '0', STR_PAD_LEFT); ?></li>
                            <li><a class="dropdown-item" href="profile.php"><i class="fas fa-wallet me-2"></i> <?php echo mt('Assets'); ?></a></li>
                            <li><a class="dropdown-item" href="profile.php?tab=security"><i class="fas fa-user-shield me-2"></i> <?php echo mt('Security'); ?></a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item text-danger" href="logout.php"><i class="fas fa-sign-out-alt me-2"></i> <?php echo mt('Logout'); ?></a></li>
                        </ul>
                    </li>
                <?php else: ?>
                    <li class="nav-item"><a class="nav-link px-3" href="login.php"><?php echo mt('Login'); ?></a></li>
                    <li class="nav-item"><a class="btn btn-primary px-4 ms-2 border-0" style="background: var(--okx-blue);" href="register.php"><?php echo mt('Register'); ?></a></li>
                <?php endif; ?>
            </ul>
        </div>
    </div>
</nav>

<div class="bottom-nav">
    <a href="index.php" class="nav-item-mobile <?php echo $current_page == 'index.php' ? 'active' : ''; ?>">
        <i class="fas fa-home"></i>
        <span><?php echo mt('Home'); ?></span>
    </a>
    <a href="market.php" class="nav-item-mobile <?php echo $current_page == 'market.php' ? 'active' : ''; ?>">
        <i class="fas fa-chart-line"></i>
        <span><?php echo mt('Markets'); ?></span>
    </a>
    <a href="trade.php" class="nav-item-mobile <?php echo ($current_page == 'trade.php' && ($_GET['type'] ?? 'spot') == 'spot') ? 'active' : ''; ?>">
        <i class="fas fa-exchange-alt"></i>
        <span><?php echo mt('Trade'); ?></span>
    </a>
    <a href="trade.php?type=contract" class="nav-item-mobile <?php echo ($current_page == 'trade.php' && ($_GET['type'] ?? '') == 'contract') ? 'active' : ''; ?>">
        <i class="fas fa-bolt"></i>
        <span><?php echo mt('Perpetual'); ?></span>
    </a>
    <a href="profile.php" class="nav-item-mobile <?php echo $current_page == 'profile.php' ? 'active' : ''; ?>">
        <i class="fas fa-wallet"></i>
        <span><?php echo mt('Assets'); ?></span>
    </a>
</div>

<a href="chat.php" class="floating-chat d-lg-flex">
    <i class="fas fa-headset"></i>
</a>