# 🤖 AI Chatbot Setup Guide

## ✅ Installation Complete!

AI Chatbot with Admin Chat has been implemented!

## 📋 Setup Steps:

### 1. **Database Setup**
```sql
-- Run this SQL file
mysql -u root mobile_aadhaar_platform < chat_migration.sql
```

Or import via phpMyAdmin:
- Open phpMyAdmin
- Select `mobile_aadhaar_platform` database
- Import `chat_migration.sql`

### 2. **Get Gemini API Key**

1. Visit: https://makersuite.google.com/app/apikey
2. Click "Create API Key"
3. Copy your API key

### 3. **Configure API Key**

Open `api/chat_api.php` and replace:
```php
define('GEMINI_API_KEY', 'YOUR_API_KEY_HERE');
```

With your actual key:
```php
define('GEMINI_API_KEY', 'AIzaSyC...');
```

### 4. **Add Chat Widget to Pages**

Add this line before closing `</body>` tag in your pages:

```php
<?php include 'chat_widget.php'; ?>
```

**Already added to:**
- ✅ dashboard.php
- ✅ profile.php
- ✅ search.php
- ✅ history.php

## 🎨 Features:

### AI Chat Mode:
- 🤖 Powered by Google Gemini AI
- 💬 Context-aware responses
- 📊 Knows user's recent searches
- 🎯 Platform-specific help

### Admin Chat Mode:
- 👨‍💼 Direct chat with admin
- 💾 Messages saved in database
- 📱 Real-time messaging
- ✉️ Admin can respond later

## 🎯 Usage:

1. **Floating Button**: Click purple chat button (bottom right)
2. **Switch Modes**: Toggle between AI and Admin
3. **Send Messages**: Type and press Enter or click send
4. **Chat History**: Auto-loads previous conversations

## 🔧 Customization:

### Change Colors:
Edit `chat_widget.php` CSS:
```css
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
```

### Change Position:
```css
.chat-float-btn {
    bottom: 90px;  /* Change this */
    right: 20px;   /* Change this */
}
```

## 📱 Mobile Optimized:

- ✅ Responsive design
- ✅ Touch-friendly
- ✅ Smooth animations
- ✅ Auto-scroll messages

## 🚀 Ready to Use!

Your AI chatbot is now live! Users can:
- Ask questions to AI
- Chat with admin
- Get instant help
- View chat history

**Test it now on any page!** 🎉
