PNG  IHDR pHYs   OiCCPPhotoshop ICC profilexڝSgTS=BKKoR RB&*! J!QEEȠQ, !{kּ> H3Q5 B.@ $pd!s#~<<+"x M0B\t8K@zB@F&S`cbP-`'{[! eDh;VEX0fK9-0IWfH  0Q){`##xFW<+*x<$9E[-qWW.(I+6aa@.y24x6_-"bbϫp@t~,/;m%h^ uf@Wp~<5j>{-]cK'Xto(hw?G%fIq^D$.Tʳ?D*A, `6B$BB dr`)B(Ͱ*`/@4Qhp.U=pa( Aa!ڈbX#!H$ ɈQ"K5H1RT UH=r9\F;2G1Q= C7F dt1r=6Ыhڏ>C03l0.B8, c˱" VcϱwE 6wB aAHXLXNH $4 7 Q'"K&b21XH,#/{C7$C2'ITFnR#,4H#dk9, +ȅ3![ b@qS(RjJ4e2AURݨT5ZBRQ4u9̓IKhhitݕNWGw Ljg(gwLӋT071oUX**| J&*/Tު UUT^S}FU3S ԖUPSSg;goT?~YYLOCQ_ cx,!k u5&|v*=9C3J3WRf?qtN (~))4L1e\kXHQG6EYAJ'\'GgSSݧ M=:.kDwn^Loy}/TmG X $ <5qo</QC]@Caaᄑ.ȽJtq]zۯ6iܟ4)Y3sCQ? 0k߬~OCOg#/c/Wװwa>>r><72Y_7ȷOo_C#dz%gA[z|!?:eAAA!h쐭!ΑiP~aa~ 'W?pX15wCsDDDޛg1O9-J5*>.j<74?.fYXXIlK9.*6nl {/]py.,:@LN8A*%w% yg"/6шC\*NH*Mz쑼5y$3,幄'L Lݛ:v m2=:1qB!Mggfvˬen/kY- BTZ(*geWf͉9+̳ې7ᒶKW-X潬j9(xoʿܔĹdff-[n ڴ VE/(ۻCɾUUMfeI?m]Nmq#׹=TR+Gw- 6 U#pDy  :v{vg/jBFS[b[O>zG499?rCd&ˮ/~јѡ򗓿m|x31^VwwO| (hSЧc3- cHRMz%u0`:o_F@8N ' p @8N@8}' p '#@8N@8N pQ9p!i~}|6-ӪG` VP.@*j>[ K^<֐Z]@8N'KQ<Q(`s" 'hgpKB`R@Dqj '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u456810272/domains/etfcareer.org/public_html/admin/sample3/dashboard2.php

<?php
// ============================================
// ETF CAREER - DASHBOARD
// ============================================

session_start();
ob_start();

// Check if user is logged in
if (!isset($_SESSION['admin_id']) || empty($_SESSION['admin_id'])) {
    header("Location: index.php");
    exit;
}

// ============================================
// DATABASE CONFIGURATION
// ============================================
$host = "localhost";
$dbname = "u456810272_etfcareer";
$username = "u456810272_etfcareer";
$password = "Global@#980";

// Create database connection
try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}

// ============================================
// CREATE ALL TABLES IF NOT EXISTS
// ============================================
function createAllTables($pdo) {
    // Create admin table if not exists
    $pdo->exec("CREATE TABLE IF NOT EXISTS admins (
        id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(100) NOT NULL,
        email VARCHAR(255) NOT NULL UNIQUE,
        password VARCHAR(255) NOT NULL,
        role ENUM('admin','staff') DEFAULT 'admin',
        status TINYINT(1) DEFAULT 1,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    ) ENGINE=InnoDB");
    
    // Create products table
    $pdo->exec("CREATE TABLE IF NOT EXISTS products (
        id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(255) NOT NULL,
        category VARCHAR(100),
        price DECIMAL(10,2),
        stock INT DEFAULT 0,
        description TEXT,
        status ENUM('active','inactive','out-of-stock') DEFAULT 'active',
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    ) ENGINE=InnoDB");
    
    // Create users/customers table
    $pdo->exec("CREATE TABLE IF NOT EXISTS users (
        id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(150) NOT NULL,
        email VARCHAR(255) UNIQUE NOT NULL,
        phone VARCHAR(50),
        address TEXT,
        role ENUM('customer','employee','admin') DEFAULT 'customer',
        status ENUM('active','inactive','blocked') DEFAULT 'active',
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    ) ENGINE=InnoDB");
    
    // Create orders table
    $pdo->exec("CREATE TABLE IF NOT EXISTS orders (
        id INT AUTO_INCREMENT PRIMARY KEY,
        order_number VARCHAR(50) UNIQUE,
        user_id INT,
        total_amount DECIMAL(10,2),
        payment_method VARCHAR(50),
        payment_status ENUM('pending','paid','failed') DEFAULT 'pending',
        order_status ENUM('pending','processing','completed','cancelled') DEFAULT 'pending',
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    ) ENGINE=InnoDB");
    
    // Insert default data if tables are empty
    // Check and insert sample products
    $productCount = $pdo->query("SELECT COUNT(*) FROM products")->fetchColumn();
    if ($productCount == 0) {
        $sampleProducts = [
            ['Laptop Pro X1', 'Electronics', 1299.99, 25, 'High-performance laptop'],
            ['Wireless Mouse', 'Electronics', 29.99, 150, 'Ergonomic wireless mouse'],
            ['Office Chair', 'Furniture', 199.99, 50, 'Comfortable office chair'],
            ['Desk Lamp', 'Home', 39.99, 100, 'LED desk lamp'],
            ['Notebook Set', 'Stationery', 24.99, 200, 'Premium notebook set']
        ];
        
        foreach ($sampleProducts as $product) {
            $stmt = $pdo->prepare("INSERT INTO products (name, category, price, stock, description) VALUES (?, ?, ?, ?, ?)");
            $stmt->execute($product);
        }
    }
    
    // Check and insert sample customers
    $customerCount = $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'customer'")->fetchColumn();
    if ($customerCount == 0) {
        $sampleCustomers = [
            ['John Smith', 'john@example.com', '555-0101', '123 Main St'],
            ['Sarah Johnson', 'sarah@example.com', '555-0102', '456 Oak Ave'],
            ['Mike Wilson', 'mike@example.com', '555-0103', '789 Pine Rd'],
            ['Emma Davis', 'emma@example.com', '555-0104', '321 Elm St']
        ];
        
        foreach ($sampleCustomers as $customer) {
            $hashedPassword = password_hash('password123', PASSWORD_DEFAULT);
            $stmt = $pdo->prepare("INSERT INTO users (name, email, phone, address, password, role) VALUES (?, ?, ?, ?, ?, 'customer')");
            $stmt->execute([$customer[0], $customer[1], $customer[2], $customer[3], $hashedPassword]);
        }
    }
}

// Create tables if they don't exist
createAllTables($pdo);

// ============================================
// HANDLE POST REQUESTS
// ============================================
$success_msg = '';
$error_msg = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Handle Product Add
    if (isset($_POST['add_product'])) {
        $name = trim($_POST['name'] ?? '');
        $category = trim($_POST['category'] ?? '');
        $price = floatval($_POST['price'] ?? 0);
        $stock = intval($_POST['stock'] ?? 0);
        $description = trim($_POST['description'] ?? '');
        
        if (!empty($name) && $price > 0) {
            $stmt = $pdo->prepare("INSERT INTO products (name, category, price, stock, description) VALUES (?, ?, ?, ?, ?)");
            if ($stmt->execute([$name, $category, $price, $stock, $description])) {
                $success_msg = "Product added successfully!";
            } else {
                $error_msg = "Failed to add product.";
            }
        } else {
            $error_msg = "Please provide product name and valid price.";
        }
    }
    
    // Handle Customer Add
    if (isset($_POST['add_customer'])) {
        $name = trim($_POST['name'] ?? '');
        $email = trim($_POST['email'] ?? '');
        $phone = trim($_POST['phone'] ?? '');
        $address = trim($_POST['address'] ?? '');
        
        if (!empty($name) && !empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
            // Check if email exists
            $stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
            $stmt->execute([$email]);
            
            if (!$stmt->fetch()) {
                $hashedPassword = password_hash('password123', PASSWORD_DEFAULT);
                $stmt = $pdo->prepare("INSERT INTO users (name, email, phone, address, password, role) VALUES (?, ?, ?, ?, ?, 'customer')");
                if ($stmt->execute([$name, $email, $phone, $address, $hashedPassword])) {
                    $success_msg = "Customer added successfully!";
                } else {
                    $error_msg = "Failed to add customer.";
                }
            } else {
                $error_msg = "Email already exists.";
            }
        } else {
            $error_msg = "Please provide valid name and email.";
        }
    }
    
    // Handle Order Create
    if (isset($_POST['create_order'])) {
        $user_id = intval($_POST['user_id'] ?? 0);
        $total_amount = floatval($_POST['total_amount'] ?? 0);
        $order_number = 'ORD' . date('YmdHis') . rand(100, 999);
        
        if ($user_id > 0 && $total_amount > 0) {
            $stmt = $pdo->prepare("INSERT INTO orders (order_number, user_id, total_amount) VALUES (?, ?, ?)");
            if ($stmt->execute([$order_number, $user_id, $total_amount])) {
                $success_msg = "Order created successfully! Order #: " . $order_number;
            } else {
                $error_msg = "Failed to create order.";
            }
        } else {
            $error_msg = "Please select customer and enter valid amount.";
        }
    }
    
    // Handle AI Chat Message
    if (isset($_POST['ai_message'])) {
        $message = trim($_POST['message'] ?? '');
        
        if (!empty($message)) {
            // Simple AI responses
            $responses = [
                "Hello! I'm your AI assistant. How can I help you with your business today?",
                "I can assist you with product management, customer queries, and business analytics.",
                "For sales reports, go to the Reports section in your dashboard.",
                "To manage your products, use the Products section.",
                "You can track your business performance in the Dashboard overview.",
                "Need help with customer management? Check the Customers section.",
                "I'm here to help with any business-related questions you have.",
                "For payment processing, visit the Payment Gateway section.",
                "Check the HR & Payroll section to manage your employees.",
                "You can configure your business settings in the Settings section."
            ];
            
            $reply = $responses[array_rand($responses)];
            
            // In a real implementation, you would save this to a database table
            $success_msg = "AI assistant replied to your message.";
        }
    }
}

// ============================================
// FETCH DATA FOR DASHBOARD
// ============================================

// Fetch Dashboard Statistics
$stats = [
    'products' => $pdo->query("SELECT COUNT(*) FROM products")->fetchColumn() ?: 0,
    'customers' => $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'customer'")->fetchColumn() ?: 0,
    'orders' => $pdo->query("SELECT COUNT(*) FROM orders")->fetchColumn() ?: 0,
    'revenue' => $pdo->query("SELECT SUM(total_amount) FROM orders WHERE payment_status = 'paid'")->fetchColumn() ?: 0,
    'pending_orders' => $pdo->query("SELECT COUNT(*) FROM orders WHERE order_status = 'pending'")->fetchColumn() ?: 0
];

// Fetch Recent Data
$products = $pdo->query("SELECT * FROM products ORDER BY id DESC LIMIT 10")->fetchAll();
$customers = $pdo->query("SELECT * FROM users WHERE role = 'customer' ORDER BY id DESC LIMIT 10")->fetchAll();
$orders = $pdo->query("SELECT o.*, u.name as customer_name FROM orders o LEFT JOIN users u ON o.user_id = u.id ORDER BY o.id DESC LIMIT 10")->fetchAll();

// Fetch all customers for dropdowns
$all_customers = $pdo->query("SELECT id, name, email FROM users WHERE role = 'customer' ORDER BY name")->fetchAll();

// ============================================
// HANDLE LOGOUT
// ============================================
if (isset($_GET['logout'])) {
    session_destroy();
    header("Location: index.php");
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ETF Career - Dashboard</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: #f5f7fa;
            color: #333;
            overflow-x: hidden;
        }
        
        .admin-container {
            display: flex;
            min-height: 100vh;
        }
        
        .sidebar {
            width: 250px;
            background: #1a237e;
            color: white;
            position: fixed;
            height: 100vh;
            overflow-y: auto;
        }
        
        .sidebar-logo {
            padding: 1.5rem;
            text-align: center;
            border-bottom: 1px solid rgba(255,255,255,0.1);
        }
        
        .sidebar-logo h3 {
            color: #ff6f00;
        }
        
        .nav-links {
            padding: 1rem 0;
            list-style: none;
        }
        
        .nav-link {
            display: flex;
            align-items: center;
            padding: 0.8rem 1.5rem;
            color: rgba(255,255,255,0.8);
            text-decoration: none;
            border-left: 4px solid transparent;
            transition: all 0.3s;
        }
        
        .nav-link:hover, .nav-link.active {
            background: rgba(255,255,255,0.1);
            color: white;
            border-left: 4px solid #ff6f00;
        }
        
        .nav-link i {
            width: 20px;
            margin-right: 10px;
        }
        
        .main-content {
            margin-left: 250px;
            padding: 1.5rem;
            flex: 1;
            width: calc(100% - 250px);
        }
        
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem;
            background: white;
            border-radius: 10px;
            margin-bottom: 1.5rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .header-left h2 {
            color: #1a237e;
        }
        
        .header-right {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .user-info {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .user-avatar {
            width: 45px;
            height: 45px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 1.2rem;
        }
        
        .user-details {
            display: flex;
            flex-direction: column;
        }
        
        .user-name {
            font-weight: 600;
            color: #333;
        }
        
        .user-email {
            font-size: 0.9rem;
            color: #666;
        }
        
        .logout-btn {
            background: #ff6f00;
            color: white;
            border: none;
            padding: 0.6rem 1.2rem;
            border-radius: 5px;
            cursor: pointer;
            font-weight: 600;
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: 5px;
            transition: all 0.3s;
        }
        
        .logout-btn:hover {
            background: #ff8f00;
            transform: translateY(-2px);
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1rem;
            margin-bottom: 1.5rem;
        }
        
        .stat-card {
            background: white;
            padding: 1.5rem;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            border-left: 4px solid #283593;
            cursor: pointer;
            transition: transform 0.3s;
        }
        
        .stat-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        
        .card {
            background: white;
            border-radius: 10px;
            padding: 1.5rem;
            margin-bottom: 1.5rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
            padding-bottom: 0.8rem;
            border-bottom: 2px solid #f0f0f0;
        }
        
        .card-header h3 {
            color: #1a237e;
            font-size: 1.3rem;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 1rem;
        }
        
        table th, table td {
            padding: 0.8rem;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        
        table th {
            background: #f8f9fa;
            font-weight: 600;
            color: #555;
        }
        
        table tr:hover {
            background: #f9f9f9;
        }
        
        .badge {
            padding: 0.3rem 0.8rem;
            border-radius: 20px;
            font-size: 0.8rem;
            font-weight: 500;
            display: inline-block;
        }
        
        .badge-success {
            background: #d4edda;
            color: #155724;
        }
        
        .badge-warning {
            background: #fff3cd;
            color: #856404;
        }
        
        .badge-danger {
            background: #f8d7da;
            color: #721c24;
        }
        
        .badge-info {
            background: #d1ecf1;
            color: #0c5460;
        }
        
        .badge-primary {
            background: #cfe2ff;
            color: #084298;
        }
        
        .btn {
            padding: 0.6rem 1.2rem;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 0.95rem;
            font-weight: 500;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            text-decoration: none;
            transition: all 0.3s;
        }
        
        .btn-primary {
            background: #283593;
            color: white;
        }
        
        .btn-primary:hover {
            background: #1a237e;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(40, 53, 147, 0.3);
        }
        
        .btn-success {
            background: #28a745;
            color: white;
        }
        
        .btn-success:hover {
            background: #218838;
            transform: translateY(-2px);
        }
        
        .btn-danger {
            background: #dc3545;
            color: white;
        }
        
        .btn-danger:hover {
            background: #c82333;
            transform: translateY(-2px);
        }
        
        .btn-warning {
            background: #ffc107;
            color: #212529;
        }
        
        .btn-warning:hover {
            background: #e0a800;
            transform: translateY(-2px);
        }
        
        .btn-sm {
            padding: 0.3rem 0.8rem;
            font-size: 0.85rem;
        }
        
        .section {
            display: none;
        }
        
        .section.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        
        /* Modal styles */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            z-index: 2000;
            align-items: center;
            justify-content: center;
            padding: 1rem;
        }
        
        .modal-content {
            background: white;
            padding: 2rem;
            border-radius: 10px;
            width: 90%;
            max-width: 500px;
            max-height: 90vh;
            overflow-y: auto;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        
        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
            padding-bottom: 1rem;
            border-bottom: 2px solid #f0f0f0;
        }
        
        .modal-header h3 {
            color: #1a237e;
            margin: 0;
        }
        
        .close-modal {
            background: none;
            border: none;
            font-size: 1.5rem;
            cursor: pointer;
            color: #666;
            transition: color 0.3s;
        }
        
        .close-modal:hover {
            color: #ff6f00;
        }
        
        .form-group {
            margin-bottom: 1.2rem;
        }
        
        .form-label {
            display: block;
            margin-bottom: 0.5rem;
            color: #555;
            font-weight: 500;
        }
        
        .form-control {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
            transition: border 0.3s;
        }
        
        .form-control:focus {
            outline: none;
            border-color: #283593;
            box-shadow: 0 0 0 3px rgba(40, 53, 147, 0.1);
        }
        
        .form-actions {
            display: flex;
            gap: 10px;
            margin-top: 1.5rem;
            padding-top: 1rem;
            border-top: 1px solid #eee;
        }
        
        .alert {
            padding: 1rem;
            border-radius: 5px;
            margin-bottom: 1rem;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .alert-success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .alert-danger {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .action-buttons {
            display: flex;
            gap: 10px;
            margin-bottom: 1rem;
            flex-wrap: wrap;
        }
        
        .search-box {
            margin-bottom: 1rem;
        }
        
        .search-box input {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
            background: #f8f9fa;
        }
        
        .chart-container {
            height: 300px;
            margin: 1rem 0;
            position: relative;
        }
        
        /* AI Chat Styles */
        .chat-messages {
            height: 300px;
            overflow-y: auto;
            padding: 1rem;
            background: #f8f9fa;
            border-radius: 10px;
            margin-bottom: 1rem;
            border: 1px solid #e9ecef;
        }
        
        .message {
            margin-bottom: 15px;
            max-width: 80%;
        }
        
        .user-message {
            background: #e3f2fd;
            padding: 10px 15px;
            border-radius: 15px 15px 5px 15px;
            margin-left: auto;
        }
        
        .ai-message {
            background: #f1f8e9;
            padding: 10px 15px;
            border-radius: 15px 15px 15px 5px;
        }
        
        .message-sender {
            font-weight: 600;
            margin-bottom: 5px;
            font-size: 0.9rem;
        }
        
        .message-time {
            font-size: 0.8rem;
            color: #666;
            margin-top: 5px;
            text-align: right;
        }
        
        .chat-input {
            display: flex;
            gap: 10px;
        }
        
        .chat-input input {
            flex: 1;
            padding: 0.8rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
        }
        
        /* Back to Home Button */
        .back-home {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            color: #666;
            text-decoration: none;
            margin-bottom: 1rem;
            transition: color 0.3s;
        }
        
        .back-home:hover {
            color: #283593;
        }
        
        @media (max-width: 768px) {
            .sidebar {
                width: 70px;
            }
            .main-content {
                margin-left: 70px;
                width: calc(100% - 70px);
                padding: 1rem;
            }
            .nav-link span {
                display: none;
            }
            .stats-grid {
                grid-template-columns: 1fr;
            }
            .header {
                flex-direction: column;
                gap: 1rem;
                text-align: center;
            }
            .header-right {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="admin-container">
        <!-- Sidebar -->
        <div class="sidebar">
            <div class="sidebar-logo">
                <h3><i class="fas fa-chart-line"></i> ETF Career</h3>
                <small>Dashboard</small>
            </div>
            <ul class="nav-links">
                <li><a href="#dashboard" class="nav-link active"><i class="fas fa-tachometer-alt"></i> <span>Dashboard</span></a></li>
                <li><a href="#products" class="nav-link"><i class="fas fa-box"></i> <span>Products</span></a></li>
                <li><a href="#customers" class="nav-link"><i class="fas fa-users"></i> <span>Customers</span></a></li>
                <li><a href="#orders" class="nav-link"><i class="fas fa-shopping-cart"></i> <span>Orders</span></a></li>
                <li><a href="#payments" class="nav-link"><i class="fas fa-credit-card"></i> <span>Payment Gateway</span></a></li>
                <li><a href="#hr-payroll" class="nav-link"><i class="fas fa-user-tie"></i> <span>HR & Payroll</span></a></li>
                <li><a href="#accounts" class="nav-link"><i class="fas fa-chart-line"></i> <span>Accounts</span></a></li>
                <li><a href="#subscriptions" class="nav-link"><i class="fas fa-calendar-check"></i> <span>Subscriptions</span></a></li>
                <li><a href="#users" class="nav-link"><i class="fas fa-user-circle"></i> <span>User Data</span></a></li>
                <li><a href="#ai-chat" class="nav-link"><i class="fas fa-robot"></i> <span>AI Bot Chat</span></a></li>
                <li><a href="#subscribers" class="nav-link"><i class="fas fa-user-check"></i> <span>Subscribers</span></a></li>
                <li><a href="#support-tickets" class="nav-link"><i class="fas fa-ticket-alt"></i> <span>Support Tickets</span></a></li>
                <li><a href="#contact-messages" class="nav-link"><i class="fas fa-envelope"></i> <span>Contact Messages</span></a></li>
                <li><a href="#seo" class="nav-link"><i class="fas fa-search"></i> <span>SEO</span></a></li>
                <li><a href="#reports" class="nav-link"><i class="fas fa-chart-bar"></i> <span>Reports</span></a></li>
                <li><a href="#languages" class="nav-link"><i class="fas fa-language"></i> <span>Languages</span></a></li>
                <li><a href="#email-smtp" class="nav-link"><i class="fas fa-at"></i> <span>Email SMTP</span></a></li>
                <li><a href="#settings" class="nav-link"><i class="fas fa-cog"></i> <span>Settings</span></a></li>
            </ul>
        </div>
        
        <!-- Main Content -->
        <div class="main-content">
            <!-- Header -->
            <div class="header">
                <div class="header-left">
                    <h2 id="pageTitle">Dashboard Overview</h2>
                    <a href="index.php" class="back-home">
                        <i class="fas fa-home"></i> Back to Home
                    </a>
                </div>
                <div class="header-right">
                    <div class="user-info">
                        <div class="user-avatar">
                            <?php echo strtoupper(substr($_SESSION['admin_name'] ?? 'A', 0, 1)); ?>
                        </div>
                        <div class="user-details">
                            <div class="user-name"><?php echo htmlspecialchars($_SESSION['admin_name'] ?? 'Admin'); ?></div>
                            <div class="user-email"><?php echo htmlspecialchars($_SESSION['admin_email'] ?? 'admin@etfcareer.org'); ?></div>
                        </div>
                    </div>
                    <a href="?logout=1" class="logout-btn">
                        <i class="fas fa-sign-out-alt"></i> Logout
                    </a>
                </div>
            </div>
            
            <!-- Display Messages -->
            <?php if ($success_msg): ?>
            <div class="alert alert-success">
                <i class="fas fa-check-circle"></i> <?php echo htmlspecialchars($success_msg); ?>
            </div>
            <?php endif; ?>
            
            <?php if ($error_msg): ?>
            <div class="alert alert-danger">
                <i class="fas fa-exclamation-circle"></i> <?php echo htmlspecialchars($error_msg); ?>
            </div>
            <?php endif; ?>
            
            <!-- Dashboard Section -->
            <div id="dashboard" class="section active">
                <div class="stats-grid">
                    <?php 
                    $statCards = [
                        ['icon' => 'fa-box', 'count' => $stats['products'], 'label' => 'Total Products', 'color' => '#283593', 'section' => 'products'],
                        ['icon' => 'fa-users', 'count' => $stats['customers'], 'label' => 'Total Customers', 'color' => '#28a745', 'section' => 'customers'],
                        ['icon' => 'fa-shopping-cart', 'count' => $stats['orders'], 'label' => 'Total Orders', 'color' => '#17a2b8', 'section' => 'orders'],
                        ['icon' => 'fa-credit-card', 'count' => '$' . number_format($stats['revenue'], 2), 'label' => 'Total Revenue', 'color' => '#ffc107', 'section' => 'payments'],
                        ['icon' => 'fa-clock', 'count' => $stats['pending_orders'], 'label' => 'Pending Orders', 'color' => '#fd7e14', 'section' => 'orders']
                    ];
                    
                    foreach($statCards as $stat): 
                    ?>
                    <div class="stat-card" onclick="showSection('<?php echo $stat['section']; ?>')">
                        <div style="display: flex; align-items: center;">
                            <div style="width: 60px; height: 60px; background: <?php echo $stat['color']; ?>; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-right: 1rem; color: white; font-size: 1.5rem;">
                                <i class="fas <?php echo $stat['icon']; ?>"></i>
                            </div>
                            <div>
                                <h3 style="margin: 0; color: #333;"><?php echo $stat['count']; ?></h3>
                                <p style="margin: 0; color: #666;"><?php echo $stat['label']; ?></p>
                            </div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                </div>
                
                <div style="display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; margin-top: 1.5rem;">
                    <div>
                        <!-- Revenue Chart -->
                        <div class="card">
                            <div class="card-header">
                                <h3>Revenue Overview</h3>
                                <button class="btn btn-sm btn-primary" onclick="exportChart()">
                                    <i class="fas fa-download"></i> Export
                                </button>
                            </div>
                            <div class="chart-container">
                                <canvas id="revenueChart"></canvas>
                            </div>
                        </div>
                        
                        <!-- Recent Orders -->
                        <div class="card">
                            <div class="card-header">
                                <h3>Recent Orders</h3>
                                <button class="btn btn-sm btn-primary" onclick="openModal('createOrderModal')">
                                    <i class="fas fa-plus"></i> New Order
                                </button>
                            </div>
                            <div class="search-box">
                                <input type="text" id="orderSearch" placeholder="Search orders..." onkeyup="searchTable('orderSearch', 'ordersTable')">
                            </div>
                            <table id="ordersTable">
                                <thead>
                                    <tr>
                                        <th>Order #</th>
                                        <th>Customer</th>
                                        <th>Amount</th>
                                        <th>Status</th>
                                        <th>Date</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if (!empty($orders)): ?>
                                        <?php foreach($orders as $order): ?>
                                        <tr>
                                            <td><strong><?php echo htmlspecialchars($order['order_number'] ?? 'N/A'); ?></strong></td>
                                            <td><?php echo htmlspecialchars($order['customer_name'] ?? 'Guest'); ?></td>
                                            <td><strong>$<?php echo number_format($order['total_amount'], 2); ?></strong></td>
                                            <td>
                                                <span class="badge badge-<?php 
                                                    echo $order['order_status'] == 'completed' ? 'success' : 
                                                           ($order['order_status'] == 'processing' ? 'info' : 
                                                           ($order['order_status'] == 'pending' ? 'warning' : 'danger'));
                                                ?>">
                                                    <?php echo ucfirst($order['order_status']); ?>
                                                </span>
                                            </td>
                                            <td><?php echo date('Y-m-d', strtotime($order['created_at'])); ?></td>
                                        </tr>
                                        <?php endforeach; ?>
                                    <?php else: ?>
                                        <tr>
                                            <td colspan="5" style="text-align: center; padding: 2rem; color: #666;">
                                                <i class="fas fa-shopping-cart fa-2x" style="margin-bottom: 1rem;"></i><br>
                                                No orders found
                                            </td>
                                        </tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                    <div>
                        <!-- Quick Actions -->
                        <div class="card">
                            <div class="card-header">
                                <h3>Quick Actions</h3>
                            </div>
                            <div style="display: flex; flex-direction: column; gap: 10px;">
                                <button class="btn btn-primary" onclick="openModal('addProductModal')">
                                    <i class="fas fa-plus"></i> Add Product
                                </button>
                                <button class="btn btn-success" onclick="openModal('addCustomerModal')">
                                    <i class="fas fa-user-plus"></i> Add Customer
                                </button>
                                <button class="btn btn-warning" onclick="openModal('createOrderModal')">
                                    <i class="fas fa-shopping-cart"></i> Create Order
                                </button>
                                <button class="btn btn-danger" onclick="showSection('ai-chat')">
                                    <i class="fas fa-robot"></i> AI Assistant
                                </button>
                                <button class="btn btn-info" onclick="showSection('reports')">
                                    <i class="fas fa-chart-bar"></i> Generate Report
                                </button>
                            </div>
                        </div>
                        
                        <!-- Recent Activity -->
                        <div class="card" style="margin-top: 1rem;">
                            <div class="card-header">
                                <h3>Recent Activity</h3>
                            </div>
                            <div style="max-height: 300px; overflow-y: auto;">
                                <?php 
                                $activities = [];
                                
                                // Add recent orders
                                foreach(array_slice($orders, 0, 3) as $order) {
                                    $activities[] = [
                                        'icon' => 'fa-shopping-cart',
                                        'color' => '#17a2b8',
                                        'text' => 'New order #' . $order['order_number'] . ' for $' . number_format($order['total_amount'], 2),
                                        'time' => $order['created_at']
                                    ];
                                }
                                
                                // Add recent customers
                                foreach(array_slice($customers, 0, 2) as $customer) {
                                    $activities[] = [
                                        'icon' => 'fa-user-plus',
                                        'color' => '#28a745',
                                        'text' => 'New customer: ' . $customer['name'],
                                        'time' => $customer['created_at']
                                    ];
                                }
                                
                                // Sort activities by time
                                usort($activities, function($a, $b) {
                                    return strtotime($b['time']) - strtotime($a['time']);
                                });
                                
                                if (!empty($activities)):
                                    foreach(array_slice($activities, 0, 5) as $activity):
                                ?>
                                <div style="display: flex; align-items: start; gap: 10px; padding: 10px 0; border-bottom: 1px solid #eee;">
                                    <div style="width: 30px; height: 30px; background: <?php echo $activity['color']; ?>; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white;">
                                        <i class="fas <?php echo $activity['icon']; ?> fa-xs"></i>
                                    </div>
                                    <div style="flex: 1;">
                                        <div style="font-size: 0.9rem;"><?php echo htmlspecialchars($activity['text']); ?></div>
                                        <small style="color: #666;"><?php echo date('M d, H:i', strtotime($activity['time'])); ?></small>
                                    </div>
                                </div>
                                <?php endforeach; else: ?>
                                <div style="text-align: center; padding: 20px; color: #666;">
                                    <i class="fas fa-history fa-2x" style="margin-bottom: 1rem;"></i><br>
                                    No recent activity
                                </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Products Section -->
            <div id="products" class="section">
                <div class="card">
                    <div class="card-header">
                        <h3>Product Management</h3>
                        <button class="btn btn-primary" onclick="openModal('addProductModal')">
                            <i class="fas fa-plus"></i> Add Product
                        </button>
                    </div>
                    
                    <div class="search-box">
                        <input type="text" id="productSearch" placeholder="Search products..." onkeyup="searchTable('productSearch', 'productsTable')">
                    </div>
                    
                    <table id="productsTable">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Name</th>
                                <th>Category</th>
                                <th>Price</th>
                                <th>Stock</th>
                                <th>Status</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($products)): ?>
                                <?php foreach($products as $product): ?>
                                <tr>
                                    <td><?php echo $product['id']; ?></td>
                                    <td><strong><?php echo htmlspecialchars($product['name']); ?></strong></td>
                                    <td><?php echo htmlspecialchars($product['category'] ?? 'Uncategorized'); ?></td>
                                    <td><strong>$<?php echo number_format($product['price'], 2); ?></strong></td>
                                    <td>
                                        <span class="badge <?php echo $product['stock'] > 10 ? 'badge-success' : ($product['stock'] > 0 ? 'badge-warning' : 'badge-danger'); ?>">
                                            <?php echo $product['stock']; ?> units
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge badge-<?php echo $product['status'] == 'active' ? 'success' : 'danger'; ?>">
                                            <?php echo ucfirst($product['status']); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <button class="btn btn-sm btn-primary" onclick="editProduct(<?php echo $product['id']; ?>)">
                                            <i class="fas fa-edit"></i>
                                        </button>
                                        <button class="btn btn-sm btn-danger" onclick="deleteProduct(<?php echo $product['id']; ?>)">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr>
                                    <td colspan="7" style="text-align: center; padding: 2rem; color: #666;">
                                        <i class="fas fa-box fa-2x" style="margin-bottom: 1rem;"></i><br>
                                        No products found
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Customers Section -->
            <div id="customers" class="section">
                <div class="card">
                    <div class="card-header">
                        <h3>Customer Management</h3>
                        <button class="btn btn-primary" onclick="openModal('addCustomerModal')">
                            <i class="fas fa-plus"></i> Add Customer
                        </button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Phone</th>
                                <th>Status</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($customers)): ?>
                                <?php foreach($customers as $customer): ?>
                                <tr>
                                    <td><?php echo $customer['id']; ?></td>
                                    <td><strong><?php echo htmlspecialchars($customer['name']); ?></strong></td>
                                    <td><?php echo htmlspecialchars($customer['email']); ?></td>
                                    <td><?php echo htmlspecialchars($customer['phone'] ?? 'N/A'); ?></td>
                                    <td>
                                        <span class="badge badge-<?php echo $customer['status'] == 'active' ? 'success' : 'danger'; ?>">
                                            <?php echo ucfirst($customer['status']); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <button class="btn btn-sm btn-primary">
                                            <i class="fas fa-edit"></i>
                                        </button>
                                        <button class="btn btn-sm btn-danger">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr>
                                    <td colspan="6" style="text-align: center; padding: 2rem; color: #666;">
                                        <i class="fas fa-users fa-2x" style="margin-bottom: 1rem;"></i><br>
                                        No customers found
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- AI Chat Section -->
            <div id="ai-chat" class="section">
                <div class="card">
                    <div class="card-header">
                        <h3>AI Assistant Chat</h3>
                        <button class="btn btn-primary" onclick="clearChat()">
                            <i class="fas fa-trash"></i> Clear Chat
                        </button>
                    </div>
                    
                    <div class="chat-messages" id="chatMessages">
                        <div class="message ai-message">
                            <div class="message-sender">AI Assistant</div>
                            <div>Hello <?php echo htmlspecialchars($_SESSION['admin_name'] ?? 'Admin'); ?>! I'm your AI assistant. How can I help you with your business today?</div>
                            <div class="message-time"><?php echo date('H:i'); ?></div>
                        </div>
                    </div>
                    
                    <form method="POST" action="" class="chat-input" onsubmit="return sendAIMessage()">
                        <input type="text" name="message" id="aiMessage" placeholder="Ask me anything about your business..." required>
                        <button type="submit" name="ai_message" class="btn btn-primary">
                            <i class="fas fa-paper-plane"></i> Send
                        </button>
                    </form>
                </div>
            </div>
            
            <!-- More sections would follow similarly... -->
            
            <!-- Footer -->
            <div style="text-align: center; padding: 2rem; margin-top: 2rem; color: #666; border-top: 1px solid #eee;">
                <p>ETF Career Dashboard &copy; <?php echo date('Y'); ?> | Logged in as: <?php echo htmlspecialchars($_SESSION['admin_name'] ?? 'Admin'); ?></p>
                <p style="margin-top: 0.5rem; font-size: 0.9rem;">
                    <a href="index.php" style="color: #283593; text-decoration: none;">
                        <i class="fas fa-home"></i> Back to Homepage
                    </a> | 
                    <a href="?logout=1" style="color: #ff6f00; text-decoration: none;">
                        <i class="fas fa-sign-out-alt"></i> Logout
                    </a>
                </p>
            </div>
        </div>
    </div>
    
    <!-- ============================================
    MODALS
    ============================================ -->
    
    <!-- Add Product Modal -->
    <div id="addProductModal" class="modal">
        <div class="modal-content">
            <div class="modal-header">
                <h3>Add New Product</h3>
                <button class="close-modal" onclick="closeModal('addProductModal')">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label class="form-label">Product Name</label>
                    <input type="text" name="name" class="form-control" required placeholder="Enter product name">
                </div>
                <div class="form-group">
                    <label class="form-label">Category</label>
                    <select name="category" class="form-control">
                        <option value="">Select Category</option>
                        <option value="Electronics">Electronics</option>
                        <option value="Clothing">Clothing</option>
                        <option value="Home & Garden">Home & Garden</option>
                        <option value="Books">Books</option>
                        <option value="Sports">Sports</option>
                        <option value="Beauty">Beauty</option>
                    </select>
                </div>
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
                    <div class="form-group">
                        <label class="form-label">Price ($)</label>
                        <input type="number" name="price" class="form-control" step="0.01" required min="0">
                    </div>
                    <div class="form-group">
                        <label class="form-label">Stock Quantity</label>
                        <input type="number" name="stock" class="form-control" required min="0">
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-label">Description</label>
                    <textarea name="description" class="form-control" rows="3" placeholder="Product description"></textarea>
                </div>
                <div class="form-actions">
                    <button type="submit" name="add_product" class="btn btn-primary">Add Product</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addProductModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Add Customer Modal -->
    <div id="addCustomerModal" class="modal">
        <div class="modal-content">
            <div class="modal-header">
                <h3>Add New Customer</h3>
                <button class="close-modal" onclick="closeModal('addCustomerModal')">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label class="form-label">Full Name</label>
                    <input type="text" name="name" class="form-control" required placeholder="Enter customer name">
                </div>
                <div class="form-group">
                    <label class="form-label">Email Address</label>
                    <input type="email" name="email" class="form-control" required placeholder="Enter customer email">
                </div>
                <div class="form-group">
                    <label class="form-label">Phone Number</label>
                    <input type="tel" name="phone" class="form-control" placeholder="Enter phone number">
                </div>
                <div class="form-group">
                    <label class="form-label">Address</label>
                    <textarea name="address" class="form-control" rows="2" placeholder="Enter customer address"></textarea>
                </div>
                <div class="form-actions">
                    <button type="submit" name="add_customer" class="btn btn-primary">Add Customer</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addCustomerModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Create Order Modal -->
    <div id="createOrderModal" class="modal">
        <div class="modal-content">
            <div class="modal-header">
                <h3>Create New Order</h3>
                <button class="close-modal" onclick="closeModal('createOrderModal')">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label class="form-label">Select Customer</label>
                    <select name="user_id" class="form-control" required>
                        <option value="">Select Customer</option>
                        <?php foreach($all_customers as $customer): ?>
                        <option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['name'] . ' - ' . $customer['email']); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">Total Amount ($)</label>
                    <input type="number" name="total_amount" class="form-control" step="0.01" required min="0">
                </div>
                <div class="form-group">
                    <label class="form-label">Payment Method</label>
                    <select name="payment_method" class="form-control">
                        <option value="Cash">Cash</option>
                        <option value="Credit Card">Credit Card</option>
                        <option value="Bank Transfer">Bank Transfer</option>
                        <option value="PayPal">PayPal</option>
                    </select>
                </div>
                <div class="form-actions">
                    <button type="submit" name="create_order" class="btn btn-primary">Create Order</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('createOrderModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <script>
        // Navigation Functions
        function showSection(sectionId) {
            // Hide all sections
            document.querySelectorAll('.section').forEach(section => {
                section.classList.remove('active');
            });
            
            // Show selected section
            const targetSection = document.getElementById(sectionId);
            if (targetSection) {
                targetSection.classList.add('active');
                
                // Update page title
                const pageTitle = document.getElementById('pageTitle');
                if (pageTitle) {
                    const navLink = document.querySelector(`.nav-link[href="#${sectionId}"]`);
                    if (navLink) {
                        const spanText = navLink.querySelector('span').textContent;
                        pageTitle.textContent = spanText;
                    }
                }
                
                // Update active nav link
                document.querySelectorAll('.nav-link').forEach(link => {
                    link.classList.remove('active');
                });
                const activeLink = document.querySelector(`.nav-link[href="#${sectionId}"]`);
                if (activeLink) {
                    activeLink.classList.add('active');
                }
                
                // Update URL hash
                window.location.hash = sectionId;
                
                // Initialize chart if it's dashboard
                if (sectionId === 'dashboard') {
                    initializeCharts();
                }
            }
        }
        
        // Handle hash on page load
        document.addEventListener('DOMContentLoaded', function() {
            // Initialize navigation
            document.querySelectorAll('.nav-link').forEach(link => {
                link.addEventListener('click', function(e) {
                    e.preventDefault();
                    const targetId = this.getAttribute('href').substring(1);
                    showSection(targetId);
                });
            });
            
            // Show section based on hash
            if (window.location.hash) {
                const hash = window.location.hash.substring(1);
                showSection(hash);
            } else {
                // Default to dashboard
                showSection('dashboard');
            }
            
            // Initialize charts
            initializeCharts();
            
            // Add keyboard shortcuts
            document.addEventListener('keydown', function(e) {
                // Ctrl + D for dashboard
                if (e.ctrlKey && e.key === 'd') {
                    e.preventDefault();
                    showSection('dashboard');
                }
                // Ctrl + P for products
                if (e.ctrlKey && e.key === 'p') {
                    e.preventDefault();
                    showSection('products');
                }
                // Ctrl + C for customers
                if (e.ctrlKey && e.key === 'c') {
                    e.preventDefault();
                    showSection('customers');
                }
                // Escape to close modals
                if (e.key === 'Escape') {
                    closeAllModals();
                }
            });
            
            // Auto-focus search when pressing Ctrl + F
            document.addEventListener('keydown', function(e) {
                if (e.ctrlKey && e.key === 'f') {
                    e.preventDefault();
                    const activeSection = document.querySelector('.section.active');
                    if (activeSection) {
                        const searchInput = activeSection.querySelector('input[type="text"]');
                        if (searchInput) {
                            searchInput.focus();
                        }
                    }
                }
            });
        });
        
        // Chart Functions
        function initializeCharts() {
            // Revenue Chart
            const revenueCtx = document.getElementById('revenueChart');
            if (revenueCtx) {
                const ctx = revenueCtx.getContext('2d');
                if (window.revenueChartInstance) {
                    window.revenueChartInstance.destroy();
                }
                window.revenueChartInstance = new Chart(ctx, {
                    type: 'line',
                    data: {
                        labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'],
                        datasets: [{
                            label: 'Revenue ($)',
                            data: [5000, 8000, 6000, 9000, 12000, 15000, 18000],
                            borderColor: '#283593',
                            backgroundColor: 'rgba(40, 53, 147, 0.1)',
                            borderWidth: 3,
                            fill: true,
                            tension: 0.4
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            legend: {
                                display: true,
                                position: 'top'
                            }
                        }
                    }
                });
            }
        }
        
        // Modal Functions
        function openModal(modalId) {
            const modal = document.getElementById(modalId);
            if (modal) {
                modal.style.display = 'flex';
                // Prevent body scrolling
                document.body.style.overflow = 'hidden';
            }
        }
        
        function closeModal(modalId) {
            const modal = document.getElementById(modalId);
            if (modal) {
                modal.style.display = 'none';
                // Restore body scrolling
                document.body.style.overflow = 'auto';
            }
        }
        
        function closeAllModals() {
            document.querySelectorAll('.modal').forEach(modal => {
                modal.style.display = 'none';
            });
            document.body.style.overflow = 'auto';
        }
        
        // Calculate net salary for payroll
        function calculateNetSalary(selectElement) {
            const basicSalary = parseFloat(document.getElementById('basicSalary').value) || 0;
            const overtime = parseFloat(document.getElementById('overtime').value) || 0;
            const bonuses = parseFloat(document.getElementById('bonuses').value) || 0;
            const deductions = parseFloat(document.getElementById('deductions').value) || 0;
            
            const netSalary = basicSalary + overtime + bonuses - deductions;
            document.getElementById('netSalary').value = '$' + netSalary.toFixed(2);
            
            // If an employee was selected and it has a salary, update basic salary
            if (selectElement) {
                const salary = selectElement.options[selectElement.selectedIndex].getAttribute('data-salary');
                if (salary) {
                    document.getElementById('basicSalary').value = salary;
                    // Recalculate with new basic salary
                    calculateNetSalary();
                }
            }
        }
        
        // Close modal when clicking outside
        document.addEventListener('click', function(e) {
            if (e.target.classList.contains('modal')) {
                e.target.style.display = 'none';
                document.body.style.overflow = 'auto';
            }
        });
        
        // Search functionality
        function searchTable(inputId, tableId) {
            const input = document.getElementById(inputId);
            const filter = input.value.toLowerCase();
            const table = document.getElementById(tableId);
            const rows = table.getElementsByTagName('tr');
            
            for (let i = 0; i < rows.length; i++) {
                const cells = rows[i].getElementsByTagName('td');
                let found = false;
                
                for (let j = 0; j < cells.length; j++) {
                    if (cells[j]) {
                        const text = cells[j].textContent || cells[j].innerText;
                        if (text.toLowerCase().indexOf(filter) > -1) {
                            found = true;
                            break;
                        }
                    }
                }
                
                rows[i].style.display = found ? '' : 'none';
            }
        }
        
        // AI Chat Functions
        function sendAIMessage() {
            const messageInput = document.getElementById('aiMessage');
            const message = messageInput.value.trim();
            
            if (message) {
                // Add user message
                const chatMessages = document.getElementById('chatMessages');
                const userMessage = document.createElement('div');
                userMessage.className = 'message user-message';
                userMessage.innerHTML = `
                    <div class="message-sender">You</div>
                    <div>${escapeHtml(message)}</div>
                    <div class="message-time">${new Date().toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}</div>
                `;
                chatMessages.appendChild(userMessage);
                
                // Clear input
                messageInput.value = '';
                
                // Simulate AI thinking
                setTimeout(() => {
                    // Simple AI responses
                    const responses = [
                        "I understand you're asking about " + message + ". I can help you with that in the relevant section of your dashboard.",
                        "That's a great question! For detailed information about " + message + ", please check the corresponding section.",
                        "I recommend checking the dashboard section related to " + message + " for comprehensive data.",
                        "You can find information about " + message + " in your business analytics section.",
                        "For " + message + " management, navigate to the appropriate section in your dashboard."
                    ];
                    
                    const aiResponse = responses[Math.floor(Math.random() * responses.length)];
                    
                    const aiMessage = document.createElement('div');
                    aiMessage.className = 'message ai-message';
                    aiMessage.innerHTML = `
                        <div class="message-sender">AI Assistant</div>
                        <div>${aiResponse}</div>
                        <div class="message-time">${new Date().toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}</div>
                    `;
                    chatMessages.appendChild(aiMessage);
                    
                    // Scroll to bottom
                    chatMessages.scrollTop = chatMessages.scrollHeight;
                }, 1000);
                
                // Scroll to bottom
                chatMessages.scrollTop = chatMessages.scrollHeight;
            }
            
            return false; // Prevent form submission
        }
        
        function clearChat() {
            if (confirm('Are you sure you want to clear the chat history?')) {
                const chatMessages = document.getElementById('chatMessages');
                chatMessages.innerHTML = `
                    <div class="message ai-message">
                        <div class="message-sender">AI Assistant</div>
                        <div>Hello ${document.querySelector('.user-name').textContent}! I'm your AI assistant. How can I help you with your business today?</div>
                        <div class="message-time">${new Date().toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}</div>
                    </div>
                `;
            }
        }
        
        // Helper function to escape HTML
        function escapeHtml(text) {
            const div = document.createElement('div');
            div.textContent = text;
            return div.innerHTML;
        }
        
        // Export Functions
        function exportChart() {
            alert('Chart exported successfully! This would download a PNG file in a real implementation.');
        }
        
        function exportData(type) {
            alert(`${type} data exported successfully! This would generate a CSV/PDF file in a real implementation.`);
        }
        
        // Print Functions
        function printSection(sectionId) {
            const section = document.getElementById(sectionId);
            if (section) {
                const printWindow = window.open('', '_blank');
                printWindow.document.write(`
                    <html>
                        <head>
                            <title>ETF Career - ${document.getElementById('pageTitle').textContent}</title>
                            <style>
                                body { font-family: Arial, sans-serif; padding: 20px; }
                                table { width: 100%; border-collapse: collapse; margin: 20px 0; }
                                th, td { padding: 8px; border: 1px solid #ddd; }
                                th { background: #f5f5f5; }
                                .badge { padding: 2px 6px; border-radius: 3px; font-size: 0.8em; }
                                .badge-success { background: #d4edda; }
                                .badge-warning { background: #fff3cd; }
                                .badge-danger { background: #f8d7da; }
                                .badge-info { background: #d1ecf1; }
                                h1 { color: #1a237e; }
                                .print-header { text-align: center; margin-bottom: 30px; }
                                .print-footer { text-align: center; margin-top: 30px; color: #666; font-size: 0.9em; }
                            </style>
                        </head>
                        <body>
                            <div class="print-header">
                                <h1>ETF Career Dashboard</h1>
                                <p>${document.getElementById('pageTitle').textContent} - Printed on ${new Date().toLocaleDateString()}</p>
                            </div>
                            ${section.innerHTML}
                            <div class="print-footer">
                                <p>Printed by: ${document.querySelector('.user-name').textContent}</p>
                                <p>&copy; ${new Date().getFullYear()} ETF Career Dashboard</p>
                            </div>
                            <script>
                                window.onload = function() { 
                                    window.print(); 
                                    setTimeout(function() { window.close(); }, 1000);
                                }
                            </script>
                        </body>
                    </html>
                `);
                printWindow.document.close();
            }
        }
        
        // CRUD Functions (Placeholders)
        function editProduct(id) {
            alert(`Edit product ${id} - In a full implementation, this would open an edit modal with pre-filled data.`);
        }
        
        function deleteProduct(id) {
            if (confirm('Are you sure you want to delete this product? This action cannot be undone.')) {
                alert(`Delete product ${id} - In a full implementation, this would send an AJAX request to delete.`);
            }
        }
        
        // Dashboard tour for new users
        function startTour() {
            alert('Welcome to ETF Career Dashboard! Let me show you around:\n\n1. Dashboard: Overview of your business\n2. Products: Manage your inventory\n3. Customers: Customer relationship management\n4. Orders: Process and track orders\n5. AI Assistant: Get business insights\n\nClick OK to continue.');
        }
        
        // Auto-start tour for new users (first visit)
        if (!localStorage.getItem('dashboardTourCompleted')) {
            setTimeout(startTour, 1000);
            localStorage.setItem('dashboardTourCompleted', 'true');
        }
    </script>
</body>
</html>
Back to Directory=ceiIENDB`