<?php
/**
 * About Us Page
 */
require_once 'config/config.php';
require_once 'config/database.php';
require_once 'includes/functions.php';

$pageTitle = 'About Us';
$content = getSetting('page_about', '');
$siteName = getSetting('site_name', APP_NAME);

// Default content if empty
if (empty($content)) {
    $content = '<h2>Welcome to ' . htmlspecialchars($siteName) . '</h2>
<p>We are a leading binary options and CFD trading platform providing professional trading services.</p>
<h3>Our Mission</h3>
<p>To provide a secure, transparent, and user-friendly trading environment for traders worldwide.</p>
<h3>Why Choose Us?</h3>
<ul>
<li>Fast trade execution</li>
<li>Secure and regulated platform</li>
<li>24/7 customer support</li>
<li>Multiple payment options</li>
<li>Educational resources</li>
</ul>';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $pageTitle ?> - <?= htmlspecialchars($siteName) ?></title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root{--bg:#0a0e17;--card:#151c28;--border:#1f2937;--green:#00d09c;--text:#fff;--muted:#6b7280}
        *{margin:0;padding:0;box-sizing:border-box}
        body{font-family:'Inter',sans-serif;background:var(--bg);color:var(--text);line-height:1.7}
        .navbar{background:var(--card);padding:1rem 2rem;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid var(--border)}
        .logo{color:var(--green);font-size:1.5rem;font-weight:700;text-decoration:none}
        .nav-links a{color:var(--text);text-decoration:none;margin-left:1.5rem;font-size:.9rem}
        .nav-links a:hover{color:var(--green)}
        .btn-login{background:var(--green);color:#000;padding:.5rem 1.25rem;border-radius:8px;font-weight:600}
        .container{max-width:900px;margin:0 auto;padding:3rem 1.5rem}
        .page-title{font-size:2.5rem;font-weight:700;margin-bottom:2rem;color:var(--green)}
        .content{background:var(--card);border-radius:16px;padding:2rem;border:1px solid var(--border)}
        .content h2,.content h3{color:var(--green);margin:1.5rem 0 1rem}
        .content h2:first-child{margin-top:0}
        .content p{color:var(--muted);margin-bottom:1rem}
        .content ul{color:var(--muted);margin-left:1.5rem;margin-bottom:1rem}
        .content li{margin-bottom:.5rem}
        .footer{background:var(--card);padding:2rem;text-align:center;color:var(--muted);border-top:1px solid var(--border);margin-top:3rem}
        .footer-links{margin-bottom:1rem}
        .footer-links a{color:var(--muted);text-decoration:none;margin:0 1rem;font-size:.9rem}
        .footer-links a:hover{color:var(--green)}
        
        /* Live Support Button */
        .live-support{position:fixed;bottom:20px;right:20px;z-index:1000}
        .support-btn{width:60px;height:60px;background:var(--green);border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;box-shadow:0 4px 15px rgba(0,208,156,.4);transition:transform .2s}
        .support-btn:hover{transform:scale(1.1)}
        .support-btn i{font-size:1.5rem;color:#000}
        .chat-window{position:fixed;bottom:90px;right:20px;width:350px;max-width:90vw;height:450px;background:var(--card);border-radius:16px;border:1px solid var(--border);display:none;flex-direction:column;overflow:hidden;z-index:1001}
        .chat-window.open{display:flex}
        .chat-header{background:var(--green);color:#000;padding:1rem;font-weight:600;display:flex;justify-content:space-between;align-items:center}
        .chat-close{background:none;border:none;font-size:1.25rem;cursor:pointer;color:#000}
        .chat-messages{flex:1;padding:1rem;overflow-y:auto}
        .chat-message{margin-bottom:1rem;max-width:80%}
        .chat-message.user{margin-left:auto;text-align:right}
        .chat-message .bubble{display:inline-block;padding:.75rem 1rem;border-radius:12px;font-size:.9rem}
        .chat-message.bot .bubble{background:rgba(255,255,255,.1);color:var(--text)}
        .chat-message.user .bubble{background:var(--green);color:#000}
        .chat-message .time{font-size:.7rem;color:var(--muted);margin-top:.25rem}
        .chat-input{display:flex;padding:1rem;border-top:1px solid var(--border);gap:.5rem}
        .chat-input input{flex:1;padding:.75rem;background:rgba(255,255,255,.05);border:1px solid var(--border);border-radius:8px;color:var(--text)}
        .chat-input button{padding:.75rem 1rem;background:var(--green);border:none;border-radius:8px;color:#000;font-weight:600;cursor:pointer}
        
        @media(max-width:768px){
            .navbar{padding:1rem}
            .nav-links a{margin-left:1rem;font-size:.8rem}
            .container{padding:2rem 1rem}
            .page-title{font-size:1.75rem}
        }
    </style>
</head>
<body>
    <nav class="navbar">
        <a href="index.php" class="logo"><?= htmlspecialchars($siteName) ?></a>
        <div class="nav-links">
            <a href="about.php">About</a>
            <a href="faq.php">FAQ</a>
            <a href="user/login.php">Login</a>
            <a href="user/register.php" class="btn-login">Register</a>
        </div>
    </nav>
    
    <div class="container">
        <h1 class="page-title"><?= $pageTitle ?></h1>
        <div class="content">
            <?= $content ?>
        </div>
    </div>
    
    <footer class="footer">
        <div class="footer-links">
            <a href="about.php">About Us</a>
            <a href="terms.php">Terms & Conditions</a>
            <a href="privacy.php">Privacy Policy</a>
            <a href="faq.php">FAQ</a>
        </div>
        <p>&copy; <?= date('Y') ?> <?= htmlspecialchars($siteName) ?>. All rights reserved.</p>
    </footer>
    
    <!-- Live Support -->
    <div class="live-support">
        <div class="support-btn" onclick="toggleChat()">
            <i class="fas fa-comments"></i>
        </div>
        <div class="chat-window" id="chatWindow">
            <div class="chat-header">
                <span><i class="fas fa-headset"></i> Live Support</span>
                <button class="chat-close" onclick="toggleChat()">&times;</button>
            </div>
            <div class="chat-messages" id="chatMessages">
                <div class="chat-message bot">
                    <div class="bubble">Hello! How can we help you today?</div>
                    <div class="time"><?= date('H:i') ?></div>
                </div>
            </div>
            <form class="chat-input" onsubmit="sendMessage(event)">
                <input type="text" id="chatInput" placeholder="Type your message..." autocomplete="off">
                <button type="submit"><i class="fas fa-paper-plane"></i></button>
            </form>
        </div>
    </div>
    
    <script>
        function toggleChat() {
            document.getElementById('chatWindow').classList.toggle('open');
        }
        
        function sendMessage(e) {
            e.preventDefault();
            const input = document.getElementById('chatInput');
            const msg = input.value.trim();
            if (!msg) return;
            
            const messages = document.getElementById('chatMessages');
            const time = new Date().toLocaleTimeString('en-US', {hour: '2-digit', minute: '2-digit'});
            
            // Add user message
            messages.innerHTML += `
                <div class="chat-message user">
                    <div class="bubble">${escapeHtml(msg)}</div>
                    <div class="time">${time}</div>
                </div>
            `;
            
            input.value = '';
            messages.scrollTop = messages.scrollHeight;
            
            // Send to server
            fetch('api/support/send.php', {
                method: 'POST',
                headers: {'Content-Type': 'application/json'},
                body: JSON.stringify({message: msg, page: 'about'})
            }).then(r => r.json()).then(data => {
                if (data.reply) {
                    messages.innerHTML += `
                        <div class="chat-message bot">
                            <div class="bubble">${data.reply}</div>
                            <div class="time">${time}</div>
                        </div>
                    `;
                    messages.scrollTop = messages.scrollHeight;
                }
            });
        }
        
        function escapeHtml(text) {
            const div = document.createElement('div');
            div.textContent = text;
            return div.innerHTML;
        }
    </script>
</body>
</html>
