<?php require_once 'includes/i18n.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>NovaEx | Leading Crypto Exchange</title>
    <link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        .logo-text { font-size: 1.8rem; font-weight: 800; color: white; letter-spacing: -1px; display: flex; align-items: center; gap: 8px; font-family: 'Inter', sans-serif; }
        .logo-svg { width: 32px; height: 32px; fill: #4facfe; }
        
        /* Floating CS Chat */
        .floating-service { position: fixed; bottom: 85px; right: 20px; width: 50px; height: 50px; background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-size: 1.2rem; cursor: pointer; box-shadow: 0 10px 25px rgba(0,242,254,0.3); z-index: 999; transition: transform 0.3s ease; }
        
        #cs-chat-window { position: fixed; bottom: 0; left: 0; right: 0; top: 0; width: 100%; height: 100%; background: #161a1e; display: none; flex-direction: column; z-index: 2100; }
        #cs-chat-window iframe { border: none; width: 100%; height: 100%; }
        .chat-header { background: #2b3139; padding: 15px; display: flex; justify-content: space-between; align-items: center; color: white; }

        @media (min-width: 993px) {
            #cs-chat-window { bottom: 100px; right: 30px; left: auto; top: auto; width: 380px; height: 500px; border-radius: 16px; border: 1px solid #2b3139; overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.5); }
            .floating-service { bottom: 30px; right: 30px; width: 60px; height: 60px; font-size: 1.5rem; }
        }

        /* Mobile Sidebar Links */
        .sidebar-links a { display: flex; align-items: center; gap: 15px; padding: 15px 10px; color: white; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 1.1rem; }
        .sidebar-links a i { width: 25px; text-align: center; }
    </style>
</head>
<body>

<!-- Sidebar Overlay -->
<div class="sidebar-overlay" id="sidebarOverlay" onclick="toggleSidebar()"></div>

<!-- Mobile Sidebar -->
<div class="mobile-sidebar" id="mobileSidebar">
    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px;">
        <div class="logo-text" style="font-size: 1.5rem;">NovaEx</div>
        <i class="fas fa-times" style="font-size: 1.5rem; cursor: pointer;" onclick="toggleSidebar()"></i>
    </div>
    
    <div class="sidebar-links">
        <a href="index.php"><i class="fas fa-home" style="color: #5d5dff;"></i> <?php echo __('nav_home'); ?></a>
        <a href="markets.php"><i class="fas fa-chart-line" style="color: #00e676;"></i> <?php echo __('nav_market'); ?></a>
        <a href="options.php"><i class="fas fa-clock" style="color: #fbc02d;"></i> <?php echo __('nav_options'); ?></a>
        <a href="spot.php"><i class="fas fa-coins" style="color: #ffd600;"></i> <?php echo __('nav_spot'); ?></a>
        <a href="futures.php"><i class="fas fa-file-contract" style="color: #ff3d00;"></i> <?php echo __('nav_futures'); ?></a>
        <a href="convert.php"><i class="fas fa-bolt" style="color: #fbc02d;"></i> <?php echo __('nav_convert'); ?></a>
        <a href="mining.php"><i class="fas fa-pickaxe" style="color: #8e24aa;"></i> <?php echo __('nav_mining'); ?></a>
        <a href="app.php"><i class="fas fa-mobile-alt" style="color: #4facfe;"></i> <?php echo __('nav_app_download', 'APP Download'); ?></a>
        <hr style="border: none; border-top: 1px solid rgba(255,255,255,0.1); margin: 15px 0;">
        <div style="padding: 10px;">
            <div style="color: var(--text-muted); font-size: 12px; margin-bottom: 15px;"><?php echo __('language', 'Language'); ?></div>
            <div style="display: flex; gap: 10px;">
                <a href="?lang=en" style="padding: 8px 15px; background: #1e2329; border-radius: 6px; font-size: 14px; flex: 1; border: none; justify-content: center;">English</a>
                <a href="?lang=zh" style="padding: 8px 15px; background: #1e2329; border-radius: 6px; font-size: 14px; flex: 1; border: none; justify-content: center;">简体中文</a>
            </div>
        </div>
    </div>
</div>

<div class="floating-service" onclick="toggleCSChat()" title="Customer Service">
    <i class="fas fa-headset"></i>
</div>

<div id="cs-chat-window">
    <div class="chat-header">
        <span>NovaEx Support</span>
        <i class="fas fa-times" onclick="toggleCSChat()" style="cursor: pointer;"></i>
    </div>
    <iframe src="chat_iframe.php"></iframe>
</div>

<nav class="navbar">
    <div style="display: flex; align-items: center; gap: 1rem;">
        <!-- Mobile Menu Toggle -->
        <i class="fas fa-bars" id="mobileMenuBtn" style="font-size: 1.2rem; cursor: pointer; display: none;" onclick="toggleSidebar()"></i>
        
        <a href="index.php" style="text-decoration: none;">
            <div class="logo-text">
                <svg class="logo-svg" viewBox="0 0 100 100">
                    <rect x="10" y="10" width="80" height="80" rx="20" fill="url(#grad1)"/>
                    <path d="M30 30 L70 70 M70 30 L30 70" stroke="white" stroke-width="12" stroke-linecap="round"/>
                    <defs>
                        <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">
                            <stop offset="0%" style="stop-color:#4facfe;stop-opacity:1" />
                            <stop offset="100%" style="stop-color:#00f2fe;stop-opacity:1" />
                        </linearGradient>
                    </defs>
                </svg>
                <span class="logo-name">NovaEx</span>
            </div>
        </a>
        <div class="nav-links">
            <a href="index.php"><?php echo __('nav_home'); ?></a>
            <a href="markets.php"><?php echo __('nav_market'); ?></a>
            <a href="options.php"><?php echo __('nav_options'); ?></a>
            <a href="spot.php"><?php echo __('nav_spot'); ?></a>
            <a href="futures.php"><?php echo __('nav_futures'); ?></a>
            <a href="mining.php"><?php echo __('nav_mining'); ?></a>
            <a href="profile.php"><?php echo __('nav_assets'); ?></a>
        </div>
    </div>
    
    <div style="display: flex; gap: 1rem; align-items: center;">
        <div class="dropdown desktop-only">
            <a href="#" style="color: white; display: flex; align-items: center; gap: 5px;">
                <i class="fas fa-globe"></i>
                <span style="font-size: 13px;"><?php echo strtoupper($lang); ?></span>
            </a>
            <div class="dropdown-content" style="right: 0; min-width: 120px;">
                <a href="?lang=en" style="display: flex; align-items: center; gap: 10px;">
                    <img src="https://flagcdn.com/w20/us.png" width="20" alt="English"> English
                </a>
                <a href="?lang=zh" style="display: flex; align-items: center; gap: 10px;">
                    <img src="https://flagcdn.com/w20/cn.png" width="20" alt="Chinese"> 简体中文
                </a>
            </div>
        </div>
        
        <?php if(isset($_SESSION['user_id'])): ?>
            <div class="dropdown">
                <a href="#" style="color: white; display: flex; align-items: center; gap: 8px;">
                    <i class="fas fa-user-circle" style="font-size: 1.5rem;"></i>
                    <i class="fas fa-chevron-down desktop-only" style="font-size: 10px;"></i>
                </a>
                <div class="dropdown-content user-profile-dropdown" style="right: 0;">
                    <div class="user-info-header">
                        <div style="font-weight: bold; margin-bottom: 4px;"><?php echo $_SESSION['username'] ?? 'User'; ?></div>
                        <div class="uid-badge">UID: <?php echo $_SESSION['uid'] ?? '------'; ?></div>
                    </div>
                    <a href="profile.php"><i class="fas fa-wallet" style="color: #03a9f4;"></i> <?php echo __('nav_assets'); ?></a>
                    <a href="deposit.php"><i class="fas fa-plus-circle" style="color: #00f2fe;"></i> <?php echo __('nav_deposit'); ?></a>
                    <a href="security.php"><i class="fas fa-shield-alt" style="color: #ffd600;"></i> <?php echo __('nav_security', 'Security'); ?></a>
                    <a href="logout.php" style="color: var(--danger-color); border-top: 1px solid rgba(255,255,255,0.05);"><i class="fas fa-sign-out-alt"></i> <?php echo __('nav_logout'); ?></a>
                </div>
            </div>
        <?php else: ?>
            <a href="login.php" class="desktop-only" style="color: white; text-decoration: none; font-size: 14px;"><?php echo __('nav_login'); ?></a>
            <a href="register.php" class="btn-primary" style="padding: 6px 15px; font-size: 13px;"><?php echo __('nav_register'); ?></a>
        <?php endif; ?>
    </div>
</nav>

<!-- Mobile Bottom Navigation -->
<div class="mobile-bottom-nav">
    <a href="index.php" class="mobile-nav-item <?php echo basename($_SERVER['PHP_SELF']) == 'index.php' ? 'active' : ''; ?>">
        <i class="fas fa-home"></i>
        <span><?php echo __('nav_home'); ?></span>
    </a>
    <a href="markets.php" class="mobile-nav-item <?php echo basename($_SERVER['PHP_SELF']) == 'markets.php' ? 'active' : ''; ?>">
        <i class="fas fa-chart-line"></i>
        <span><?php echo __('nav_market'); ?></span>
    </a>
    <a href="options.php" class="mobile-nav-item <?php echo in_array(basename($_SERVER['PHP_SELF']), ['options.php', 'spot.php', 'futures.php']) ? 'active' : ''; ?>">
        <i class="fas fa-exchange-alt"></i>
        <span><?php echo __('nav_trade', 'Trade'); ?></span>
    </a>
    <a href="mining.php" class="mobile-nav-item <?php echo basename($_SERVER['PHP_SELF']) == 'mining.php' ? 'active' : ''; ?>">
        <i class="fas fa-pickaxe"></i>
        <span><?php echo __('nav_mining'); ?></span>
    </a>
    <a href="profile.php" class="mobile-nav-item <?php echo basename($_SERVER['PHP_SELF']) == 'profile.php' ? 'active' : ''; ?>">
        <i class="fas fa-wallet"></i>
        <span><?php echo __('nav_assets'); ?></span>
    </a>
</div>

<style>
    @media (max-width: 992px) {
        #mobileMenuBtn { display: block !important; }
        .desktop-only { display: none !important; }
        .logo-name { font-size: 1.4rem; }
    }
</style>

<script>
    function toggleSidebar() {
        const sidebar = document.getElementById('mobileSidebar');
        const overlay = document.getElementById('sidebarOverlay');
        sidebar.classList.toggle('open');
        overlay.classList.toggle('open');
        document.body.style.overflow = sidebar.classList.contains('open') ? 'hidden' : '';
    }

    function toggleCSChat() {
        const chat = document.getElementById('cs-chat-window');
        chat.style.display = chat.style.display === 'flex' ? 'none' : 'flex';
        document.body.style.overflow = chat.style.display === 'flex' ? 'hidden' : '';
    }
</script>