<?php
/**
 * Admin - Powerful SEO Management System
 * Manage unlimited keywords, meta tags, pages, sitemap, robots.txt
 */
require_once 'includes/header.php';

// Handle form submissions
$message = '';
$messageType = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = $_POST['action'] ?? '';
    
    // Save Global SEO Settings
    if ($action === 'save_global') {
        $settings = [
            'site_title' => $_POST['site_title'] ?? '',
            'site_tagline' => $_POST['site_tagline'] ?? '',
            'meta_description' => $_POST['meta_description'] ?? '',
            'meta_keywords' => $_POST['meta_keywords'] ?? '',
            'og_image' => $_POST['og_image'] ?? '',
            'twitter_handle' => $_POST['twitter_handle'] ?? '',
            'google_analytics' => $_POST['google_analytics'] ?? '',
            'google_search_console' => $_POST['google_search_console'] ?? '',
            'bing_webmaster' => $_POST['bing_webmaster'] ?? '',
            'facebook_pixel' => $_POST['facebook_pixel'] ?? '',
            'schema_type' => $_POST['schema_type'] ?? 'Organization',
            'canonical_url' => $_POST['canonical_url'] ?? '',
        ];
        
        foreach ($settings as $key => $value) {
            dbQuery(
                "INSERT INTO seo_settings (setting_key, setting_value) VALUES (:key, :val) 
                 ON DUPLICATE KEY UPDATE setting_value = :val2",
                ['key' => 'seo_' . $key, 'val' => $value, 'val2' => $value]
            );
        }
        
        $message = 'Global SEO settings saved!';
        $messageType = 'success';
    }
    
    // Add Keyword
    if ($action === 'add_keyword') {
        $keyword = trim($_POST['keyword'] ?? '');
        $volume = (int)($_POST['search_volume'] ?? 0);
        $difficulty = (int)($_POST['difficulty'] ?? 50);
        $priority = $_POST['priority'] ?? 'medium';
        $category = trim($_POST['category'] ?? 'General');
        $targetPage = trim($_POST['target_page'] ?? '');
        
        if (!empty($keyword)) {
            dbInsert('seo_keywords', [
                'keyword' => $keyword,
                'search_volume' => $volume,
                'difficulty' => $difficulty,
                'priority' => $priority,
                'category' => $category,
                'target_page' => $targetPage,
                'status' => 'active'
            ]);
            $message = 'Keyword added successfully!';
            $messageType = 'success';
        }
    }
    
    // Bulk Add Keywords
    if ($action === 'bulk_add_keywords') {
        $keywords = explode("\n", $_POST['bulk_keywords'] ?? '');
        $category = trim($_POST['bulk_category'] ?? 'General');
        $added = 0;
        
        foreach ($keywords as $kw) {
            $kw = trim($kw);
            if (!empty($kw)) {
                // Check if exists
                $exists = dbFetch("SELECT id FROM seo_keywords WHERE keyword = :kw", ['kw' => $kw]);
                if (!$exists) {
                    dbInsert('seo_keywords', [
                        'keyword' => $kw,
                        'category' => $category,
                        'priority' => 'medium',
                        'status' => 'active'
                    ]);
                    $added++;
                }
            }
        }
        
        $message = "{$added} keywords added successfully!";
        $messageType = 'success';
    }
    
    // Delete Keyword
    if ($action === 'delete_keyword') {
        $id = (int)($_POST['keyword_id'] ?? 0);
        dbQuery("DELETE FROM seo_keywords WHERE id = :id", ['id' => $id]);
        $message = 'Keyword deleted!';
        $messageType = 'success';
    }
    
    // Update Keyword
    if ($action === 'update_keyword') {
        $id = (int)($_POST['keyword_id'] ?? 0);
        dbUpdate('seo_keywords', [
            'keyword' => $_POST['keyword'] ?? '',
            'search_volume' => (int)($_POST['search_volume'] ?? 0),
            'difficulty' => (int)($_POST['difficulty'] ?? 50),
            'priority' => $_POST['priority'] ?? 'medium',
            'category' => $_POST['category'] ?? 'General',
            'target_page' => $_POST['target_page'] ?? '',
            'status' => $_POST['status'] ?? 'active'
        ], 'id = :id', ['id' => $id]);
        $message = 'Keyword updated!';
        $messageType = 'success';
    }
    
    // Save Page SEO
    if ($action === 'save_page_seo') {
        $pageId = (int)($_POST['page_id'] ?? 0);
        $data = [
            'page_url' => $_POST['page_url'] ?? '',
            'page_title' => $_POST['page_title'] ?? '',
            'meta_description' => $_POST['meta_description'] ?? '',
            'meta_keywords' => $_POST['meta_keywords'] ?? '',
            'og_title' => $_POST['og_title'] ?? '',
            'og_description' => $_POST['og_description'] ?? '',
            'og_image' => $_POST['og_image'] ?? '',
            'canonical_url' => $_POST['canonical_url'] ?? '',
            'robots' => $_POST['robots'] ?? 'index,follow',
            'schema_markup' => $_POST['schema_markup'] ?? '',
            'h1_tag' => $_POST['h1_tag'] ?? '',
            'focus_keyword' => $_POST['focus_keyword'] ?? '',
            'status' => 'active'
        ];
        
        if ($pageId > 0) {
            dbUpdate('seo_pages', $data, 'id = :id', ['id' => $pageId]);
            $message = 'Page SEO updated!';
        } else {
            dbInsert('seo_pages', $data);
            $message = 'Page SEO added!';
        }
        $messageType = 'success';
    }
    
    // Delete Page SEO
    if ($action === 'delete_page') {
        $id = (int)($_POST['page_id'] ?? 0);
        dbQuery("DELETE FROM seo_pages WHERE id = :id", ['id' => $id]);
        $message = 'Page deleted!';
        $messageType = 'success';
    }
    
    // Save Robots.txt
    if ($action === 'save_robots') {
        $robots = $_POST['robots_content'] ?? '';
        dbQuery(
            "INSERT INTO seo_settings (setting_key, setting_value) VALUES ('robots_txt', :val) 
             ON DUPLICATE KEY UPDATE setting_value = :val2",
            ['val' => $robots, 'val2' => $robots]
        );
        
        // Also save to file
        file_put_contents(ROOT_PATH . '/robots.txt', $robots);
        
        $message = 'Robots.txt saved!';
        $messageType = 'success';
    }
    
    // Generate Sitemap
    if ($action === 'generate_sitemap') {
        $baseUrl = rtrim($_POST['base_url'] ?? SITE_URL, '/');
        $pages = dbFetchAll("SELECT * FROM seo_pages WHERE status = 'active'");
        
        $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
        $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
        
        // Add homepage
        $xml .= "  <url>\n";
        $xml .= "    <loc>{$baseUrl}/</loc>\n";
        $xml .= "    <changefreq>daily</changefreq>\n";
        $xml .= "    <priority>1.0</priority>\n";
        $xml .= "  </url>\n";
        
        // Add pages from database
        foreach ($pages as $page) {
            $url = $baseUrl . '/' . ltrim($page['page_url'], '/');
            $xml .= "  <url>\n";
            $xml .= "    <loc>{$url}</loc>\n";
            $xml .= "    <lastmod>" . date('Y-m-d', strtotime($page['updated_at'])) . "</lastmod>\n";
            $xml .= "    <changefreq>weekly</changefreq>\n";
            $xml .= "    <priority>0.8</priority>\n";
            $xml .= "  </url>\n";
        }
        
        // Add default pages
        $defaultPages = ['user/login.php', 'user/register.php', 'user/trade.php'];
        foreach ($defaultPages as $dp) {
            $xml .= "  <url>\n";
            $xml .= "    <loc>{$baseUrl}/{$dp}</loc>\n";
            $xml .= "    <changefreq>monthly</changefreq>\n";
            $xml .= "    <priority>0.6</priority>\n";
            $xml .= "  </url>\n";
        }
        
        $xml .= '</urlset>';
        
        file_put_contents(ROOT_PATH . '/sitemap.xml', $xml);
        
        $message = 'Sitemap generated successfully!';
        $messageType = 'success';
    }
    
    // Add Redirect
    if ($action === 'add_redirect') {
        dbInsert('seo_redirects', [
            'from_url' => $_POST['from_url'] ?? '',
            'to_url' => $_POST['to_url'] ?? '',
            'redirect_type' => $_POST['redirect_type'] ?? '301',
            'status' => 'active'
        ]);
        $message = 'Redirect added!';
        $messageType = 'success';
    }
    
    // Delete Redirect
    if ($action === 'delete_redirect') {
        $id = (int)($_POST['redirect_id'] ?? 0);
        dbQuery("DELETE FROM seo_redirects WHERE id = :id", ['id' => $id]);
        $message = 'Redirect deleted!';
        $messageType = 'success';
    }
}

// Get data
$tab = $_GET['tab'] ?? 'dashboard';

// Get SEO settings
$seoSettings = [];
$settingsData = dbFetchAll("SELECT * FROM seo_settings WHERE setting_key LIKE 'seo_%'");
foreach ($settingsData as $s) {
    $key = str_replace('seo_', '', $s['setting_key']);
    $seoSettings[$key] = $s['setting_value'];
}

// Get keywords with filters
$keywordFilter = $_GET['kf'] ?? '';
$keywordCategory = $_GET['kc'] ?? '';
$keywordPriority = $_GET['kp'] ?? '';

$keywordWhere = "1=1";
$keywordParams = [];
if ($keywordFilter) {
    $keywordWhere .= " AND keyword LIKE :kf";
    $keywordParams['kf'] = "%{$keywordFilter}%";
}
if ($keywordCategory) {
    $keywordWhere .= " AND category = :kc";
    $keywordParams['kc'] = $keywordCategory;
}
if ($keywordPriority) {
    $keywordWhere .= " AND priority = :kp";
    $keywordParams['kp'] = $keywordPriority;
}

$keywords = dbFetchAll("SELECT * FROM seo_keywords WHERE {$keywordWhere} ORDER BY priority DESC, search_volume DESC", $keywordParams);
$keywordCategories = dbFetchAll("SELECT DISTINCT category FROM seo_keywords ORDER BY category");

// Get pages
$pages = dbFetchAll("SELECT * FROM seo_pages ORDER BY page_url");

// Get redirects
$redirects = dbFetchAll("SELECT * FROM seo_redirects ORDER BY id DESC");

// Get robots.txt
$robotsTxt = dbFetch("SELECT setting_value FROM seo_settings WHERE setting_key = 'robots_txt'");
$robotsContent = $robotsTxt['setting_value'] ?? "User-agent: *\nAllow: /\nDisallow: /admin/\nDisallow: /api/\n\nSitemap: " . SITE_URL . "/sitemap.xml";

// Stats
$stats = [
    'keywords' => dbFetch("SELECT COUNT(*) as c FROM seo_keywords")['c'] ?? 0,
    'pages' => dbFetch("SELECT COUNT(*) as c FROM seo_pages")['c'] ?? 0,
    'redirects' => dbFetch("SELECT COUNT(*) as c FROM seo_redirects")['c'] ?? 0,
    'high_priority' => dbFetch("SELECT COUNT(*) as c FROM seo_keywords WHERE priority = 'high'")['c'] ?? 0,
];
?>

<style>
.seo-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.seo-tab { padding: 0.75rem 1.25rem; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 8px; color: var(--text-primary); text-decoration: none; transition: all 0.3s; display: flex; align-items: center; gap: 0.5rem; }
.seo-tab:hover { border-color: var(--accent-green); }
.seo-tab.active { background: var(--accent-green); color: #000; border-color: var(--accent-green); }
.seo-tab i { font-size: 1rem; }

.keyword-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 12px; padding: 1rem; margin-bottom: 0.75rem; }
.keyword-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 0.5rem; }
.keyword-text { font-weight: 600; font-size: 1rem; word-break: break-word; }
.keyword-meta { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.8rem; color: var(--text-muted); }
.keyword-meta span { display: flex; align-items: center; gap: 0.25rem; }
.keyword-actions { display: flex; gap: 0.5rem; }

.priority-high { color: #ff5252; }
.priority-medium { color: #fbbf24; }
.priority-low { color: #6b7280; }

.difficulty-bar { width: 60px; height: 6px; background: var(--bg-tertiary); border-radius: 3px; overflow: hidden; }
.difficulty-fill { height: 100%; border-radius: 3px; }
.difficulty-easy { background: #00d09c; }
.difficulty-medium { background: #fbbf24; }
.difficulty-hard { background: #ff5252; }

.page-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 12px; padding: 1.25rem; margin-bottom: 1rem; }
.page-url { font-family: var(--font-mono); color: var(--accent-green); font-size: 0.9rem; margin-bottom: 0.5rem; word-break: break-all; }
.page-title { font-weight: 600; margin-bottom: 0.5rem; }
.page-desc { color: var(--text-muted); font-size: 0.85rem; }

.seo-score { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; font-weight: 700; font-size: 0.9rem; }
.score-good { background: rgba(0,208,156,0.2); color: #00d09c; }
.score-ok { background: rgba(251,191,36,0.2); color: #fbbf24; }
.score-bad { background: rgba(255,82,82,0.2); color: #ff5252; }

.bulk-textarea { min-height: 200px; font-family: var(--font-mono); font-size: 0.85rem; }
.robots-textarea { min-height: 300px; font-family: var(--font-mono); font-size: 0.85rem; }

.filter-bar { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { padding: 0.5rem 0.75rem; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 6px; color: var(--text-primary); }

.schema-preview { background: var(--bg-tertiary); padding: 1rem; border-radius: 8px; font-family: var(--font-mono); font-size: 0.8rem; white-space: pre-wrap; max-height: 300px; overflow-y: auto; }

.redirect-item { display: flex; align-items: center; gap: 1rem; padding: 0.75rem; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 8px; margin-bottom: 0.5rem; }
.redirect-from { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.85rem; flex: 1; }
.redirect-arrow { color: var(--accent-green); }
.redirect-to { color: var(--accent-green); font-family: var(--font-mono); font-size: 0.85rem; flex: 1; }
.redirect-type { background: var(--bg-tertiary); padding: 0.25rem 0.5rem; border-radius: 4px; font-size: 0.75rem; }

.keywords-grid { display: grid; gap: 0.75rem; }
@media (min-width: 768px) { .keywords-grid { grid-template-columns: repeat(2, 1fr); } }
</style>

<div class="page-header">
    <h1 class="page-title"><i class="fas fa-search"></i> SEO Management</h1>
</div>

<?php if ($message): ?>
<div class="alert alert-<?= $messageType === 'success' ? 'success' : 'danger' ?> mb-4"><?= $message ?></div>
<?php endif; ?>

<!-- Stats -->
<div class="row mb-4">
    <div class="col-md-3 col-6 mb-3">
        <div class="stat-card">
            <div class="stat-icon" style="background: rgba(99,102,241,0.2); color: #6366f1;"><i class="fas fa-key"></i></div>
            <div class="stat-value"><?= number_format($stats['keywords']) ?></div>
            <div class="stat-label">Total Keywords</div>
        </div>
    </div>
    <div class="col-md-3 col-6 mb-3">
        <div class="stat-card">
            <div class="stat-icon" style="background: rgba(0,208,156,0.2); color: #00d09c;"><i class="fas fa-file-alt"></i></div>
            <div class="stat-value"><?= number_format($stats['pages']) ?></div>
            <div class="stat-label">SEO Pages</div>
        </div>
    </div>
    <div class="col-md-3 col-6 mb-3">
        <div class="stat-card">
            <div class="stat-icon" style="background: rgba(251,191,36,0.2); color: #fbbf24;"><i class="fas fa-directions"></i></div>
            <div class="stat-value"><?= number_format($stats['redirects']) ?></div>
            <div class="stat-label">Redirects</div>
        </div>
    </div>
    <div class="col-md-3 col-6 mb-3">
        <div class="stat-card">
            <div class="stat-icon" style="background: rgba(255,82,82,0.2); color: #ff5252;"><i class="fas fa-fire"></i></div>
            <div class="stat-value"><?= number_format($stats['high_priority']) ?></div>
            <div class="stat-label">High Priority</div>
        </div>
    </div>
</div>

<!-- Tabs -->
<div class="seo-tabs">
    <a href="?tab=dashboard" class="seo-tab <?= $tab === 'dashboard' ? 'active' : '' ?>"><i class="fas fa-tachometer-alt"></i> Dashboard</a>
    <a href="?tab=keywords" class="seo-tab <?= $tab === 'keywords' ? 'active' : '' ?>"><i class="fas fa-key"></i> Keywords</a>
    <a href="?tab=pages" class="seo-tab <?= $tab === 'pages' ? 'active' : '' ?>"><i class="fas fa-file-alt"></i> Pages</a>
    <a href="?tab=global" class="seo-tab <?= $tab === 'global' ? 'active' : '' ?>"><i class="fas fa-globe"></i> Global Settings</a>
    <a href="?tab=sitemap" class="seo-tab <?= $tab === 'sitemap' ? 'active' : '' ?>"><i class="fas fa-sitemap"></i> Sitemap</a>
    <a href="?tab=robots" class="seo-tab <?= $tab === 'robots' ? 'active' : '' ?>"><i class="fas fa-robot"></i> Robots.txt</a>
    <a href="?tab=redirects" class="seo-tab <?= $tab === 'redirects' ? 'active' : '' ?>"><i class="fas fa-directions"></i> Redirects</a>
    <a href="?tab=analytics" class="seo-tab <?= $tab === 'analytics' ? 'active' : '' ?>"><i class="fas fa-chart-line"></i> Analytics</a>
</div>

<!-- Dashboard Tab -->
<?php if ($tab === 'dashboard'): ?>
<div class="row">
    <div class="col-md-6 mb-4">
        <div class="card">
            <div class="card-header"><h3 class="card-title">Quick Actions</h3></div>
            <div class="card-body">
                <a href="?tab=keywords" class="btn btn-primary btn-block mb-2"><i class="fas fa-plus"></i> Add Keywords</a>
                <a href="?tab=pages" class="btn btn-secondary btn-block mb-2"><i class="fas fa-file-plus"></i> Add Page SEO</a>
                <form method="POST" class="mb-2">
                    <input type="hidden" name="action" value="generate_sitemap">
                    <input type="hidden" name="base_url" value="<?= SITE_URL ?>">
                    <button type="submit" class="btn btn-success btn-block"><i class="fas fa-sitemap"></i> Generate Sitemap</button>
                </form>
                <a href="?tab=global" class="btn btn-warning btn-block"><i class="fas fa-cog"></i> Global Settings</a>
            </div>
        </div>
    </div>
    <div class="col-md-6 mb-4">
        <div class="card">
            <div class="card-header"><h3 class="card-title">Top Keywords</h3></div>
            <div class="card-body">
                <?php 
                $topKeywords = dbFetchAll("SELECT * FROM seo_keywords ORDER BY search_volume DESC LIMIT 5");
                foreach ($topKeywords as $kw): 
                ?>
                <div class="d-flex justify-content-between align-items-center mb-2 pb-2" style="border-bottom: 1px solid var(--border-color);">
                    <span><?= htmlspecialchars($kw['keyword']) ?></span>
                    <span class="text-muted"><?= number_format($kw['search_volume']) ?> vol</span>
                </div>
                <?php endforeach; ?>
                <?php if (empty($topKeywords)): ?>
                <p class="text-muted text-center">No keywords yet</p>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- Keywords Tab -->
<?php if ($tab === 'keywords'): ?>
<div class="row">
    <div class="col-lg-4 mb-4">
        <!-- Add Single Keyword -->
        <div class="card mb-4">
            <div class="card-header"><h3 class="card-title"><i class="fas fa-plus"></i> Add Keyword</h3></div>
            <div class="card-body">
                <form method="POST">
                    <input type="hidden" name="action" value="add_keyword">
                    <div class="form-group mb-3">
                        <label class="form-label">Keyword *</label>
                        <input type="text" name="keyword" class="form-control" required placeholder="e.g., binary options trading">
                    </div>
                    <div class="row mb-3">
                        <div class="col-6">
                            <label class="form-label">Search Volume</label>
                            <input type="number" name="search_volume" class="form-control" placeholder="0">
                        </div>
                        <div class="col-6">
                            <label class="form-label">Difficulty (0-100)</label>
                            <input type="number" name="difficulty" class="form-control" min="0" max="100" value="50">
                        </div>
                    </div>
                    <div class="form-group mb-3">
                        <label class="form-label">Priority</label>
                        <select name="priority" class="form-control">
                            <option value="high">🔴 High</option>
                            <option value="medium" selected>🟡 Medium</option>
                            <option value="low">⚪ Low</option>
                        </select>
                    </div>
                    <div class="form-group mb-3">
                        <label class="form-label">Category</label>
                        <input type="text" name="category" class="form-control" placeholder="General" list="categories">
                        <datalist id="categories">
                            <?php foreach ($keywordCategories as $cat): ?>
                            <option value="<?= htmlspecialchars($cat['category']) ?>">
                            <?php endforeach; ?>
                        </datalist>
                    </div>
                    <div class="form-group mb-3">
                        <label class="form-label">Target Page</label>
                        <input type="text" name="target_page" class="form-control" placeholder="/user/trade.php">
                    </div>
                    <button type="submit" class="btn btn-primary btn-block">Add Keyword</button>
                </form>
            </div>
        </div>
        
        <!-- Bulk Add -->
        <div class="card">
            <div class="card-header"><h3 class="card-title"><i class="fas fa-list"></i> Bulk Add Keywords</h3></div>
            <div class="card-body">
                <form method="POST">
                    <input type="hidden" name="action" value="bulk_add_keywords">
                    <div class="form-group mb-3">
                        <label class="form-label">Keywords (one per line)</label>
                        <textarea name="bulk_keywords" class="form-control bulk-textarea" placeholder="binary options trading&#10;crypto trading&#10;forex trading&#10;online trading platform"></textarea>
                    </div>
                    <div class="form-group mb-3">
                        <label class="form-label">Category</label>
                        <input type="text" name="bulk_category" class="form-control" value="General">
                    </div>
                    <button type="submit" class="btn btn-success btn-block">Add All Keywords</button>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-lg-8">
        <!-- Filter -->
        <form class="filter-bar" method="GET">
            <input type="hidden" name="tab" value="keywords">
            <input type="text" name="kf" placeholder="Search keywords..." value="<?= htmlspecialchars($keywordFilter) ?>">
            <select name="kc">
                <option value="">All Categories</option>
                <?php foreach ($keywordCategories as $cat): ?>
                <option value="<?= htmlspecialchars($cat['category']) ?>" <?= $keywordCategory === $cat['category'] ? 'selected' : '' ?>><?= htmlspecialchars($cat['category']) ?></option>
                <?php endforeach; ?>
            </select>
            <select name="kp">
                <option value="">All Priorities</option>
                <option value="high" <?= $keywordPriority === 'high' ? 'selected' : '' ?>>High</option>
                <option value="medium" <?= $keywordPriority === 'medium' ? 'selected' : '' ?>>Medium</option>
                <option value="low" <?= $keywordPriority === 'low' ? 'selected' : '' ?>>Low</option>
            </select>
            <button type="submit" class="btn btn-primary"><i class="fas fa-filter"></i></button>
            <a href="?tab=keywords" class="btn btn-secondary"><i class="fas fa-times"></i></a>
        </form>
        
        <div class="mb-3 text-muted">
            Showing <?= count($keywords) ?> keywords
        </div>
        
        <!-- Keywords List -->
        <div class="keywords-grid">
            <?php foreach ($keywords as $kw): ?>
            <div class="keyword-card">
                <div class="keyword-header">
                    <div class="keyword-text"><?= htmlspecialchars($kw['keyword']) ?></div>
                    <div class="keyword-actions">
                        <button class="btn btn-sm btn-secondary" onclick="editKeyword(<?= htmlspecialchars(json_encode($kw)) ?>)">
                            <i class="fas fa-edit"></i>
                        </button>
                        <form method="POST" style="display:inline" onsubmit="return confirm('Delete this keyword?')">
                            <input type="hidden" name="action" value="delete_keyword">
                            <input type="hidden" name="keyword_id" value="<?= $kw['id'] ?>">
                            <button type="submit" class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></button>
                        </form>
                    </div>
                </div>
                <div class="keyword-meta">
                    <span><i class="fas fa-search"></i> <?= number_format($kw['search_volume']) ?></span>
                    <span>
                        <div class="difficulty-bar">
                            <div class="difficulty-fill <?= $kw['difficulty'] < 40 ? 'difficulty-easy' : ($kw['difficulty'] < 70 ? 'difficulty-medium' : 'difficulty-hard') ?>" style="width: <?= $kw['difficulty'] ?>%"></div>
                        </div>
                    </span>
                    <span class="priority-<?= $kw['priority'] ?>">
                        <?= $kw['priority'] === 'high' ? '🔴' : ($kw['priority'] === 'medium' ? '🟡' : '⚪') ?> <?= ucfirst($kw['priority']) ?>
                    </span>
                    <span><i class="fas fa-folder"></i> <?= htmlspecialchars($kw['category']) ?></span>
                </div>
                <?php if ($kw['target_page']): ?>
                <div class="mt-2 text-muted" style="font-size: 0.75rem;">
                    <i class="fas fa-link"></i> <?= htmlspecialchars($kw['target_page']) ?>
                </div>
                <?php endif; ?>
            </div>
            <?php endforeach; ?>
        </div>
        
        <?php if (empty($keywords)): ?>
        <div class="card">
            <div class="card-body text-center py-5">
                <i class="fas fa-key fa-3x text-muted mb-3"></i>
                <h3>No Keywords Found</h3>
                <p class="text-muted">Add your first keyword to start optimizing!</p>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>

<!-- Edit Keyword Modal -->
<div class="modal" id="editKeywordModal">
    <div class="modal-box">
        <div class="modal-header">
            <h3>Edit Keyword</h3>
            <button class="modal-close" onclick="closeModal('editKeywordModal')">×</button>
        </div>
        <form method="POST">
            <input type="hidden" name="action" value="update_keyword">
            <input type="hidden" name="keyword_id" id="edit_keyword_id">
            <div class="form-group mb-3">
                <label class="form-label">Keyword</label>
                <input type="text" name="keyword" id="edit_keyword" class="form-control" required>
            </div>
            <div class="row mb-3">
                <div class="col-6">
                    <label class="form-label">Search Volume</label>
                    <input type="number" name="search_volume" id="edit_volume" class="form-control">
                </div>
                <div class="col-6">
                    <label class="form-label">Difficulty</label>
                    <input type="number" name="difficulty" id="edit_difficulty" class="form-control" min="0" max="100">
                </div>
            </div>
            <div class="row mb-3">
                <div class="col-6">
                    <label class="form-label">Priority</label>
                    <select name="priority" id="edit_priority" class="form-control">
                        <option value="high">High</option>
                        <option value="medium">Medium</option>
                        <option value="low">Low</option>
                    </select>
                </div>
                <div class="col-6">
                    <label class="form-label">Status</label>
                    <select name="status" id="edit_status" class="form-control">
                        <option value="active">Active</option>
                        <option value="inactive">Inactive</option>
                    </select>
                </div>
            </div>
            <div class="form-group mb-3">
                <label class="form-label">Category</label>
                <input type="text" name="category" id="edit_category" class="form-control">
            </div>
            <div class="form-group mb-3">
                <label class="form-label">Target Page</label>
                <input type="text" name="target_page" id="edit_target" class="form-control">
            </div>
            <button type="submit" class="btn btn-primary btn-block">Update Keyword</button>
        </form>
    </div>
</div>

<script>
function editKeyword(kw) {
    document.getElementById('edit_keyword_id').value = kw.id;
    document.getElementById('edit_keyword').value = kw.keyword;
    document.getElementById('edit_volume').value = kw.search_volume;
    document.getElementById('edit_difficulty').value = kw.difficulty;
    document.getElementById('edit_priority').value = kw.priority;
    document.getElementById('edit_status').value = kw.status;
    document.getElementById('edit_category').value = kw.category;
    document.getElementById('edit_target').value = kw.target_page;
    document.getElementById('editKeywordModal').classList.add('active');
}

function closeModal(id) {
    document.getElementById(id).classList.remove('active');
}
</script>
<?php endif; ?>

<!-- Pages Tab -->
<?php if ($tab === 'pages'): ?>
<div class="row">
    <div class="col-lg-5 mb-4">
        <div class="card">
            <div class="card-header"><h3 class="card-title"><i class="fas fa-plus"></i> Add/Edit Page SEO</h3></div>
            <div class="card-body">
                <form method="POST" id="pageForm">
                    <input type="hidden" name="action" value="save_page_seo">
                    <input type="hidden" name="page_id" id="page_id" value="0">
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Page URL *</label>
                        <input type="text" name="page_url" id="page_url" class="form-control" required placeholder="/user/trade.php">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Page Title *</label>
                        <input type="text" name="page_title" id="page_title" class="form-control" required placeholder="Best Binary Options Trading Platform">
                        <small class="text-muted">Recommended: 50-60 characters</small>
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Meta Description</label>
                        <textarea name="meta_description" id="page_meta_desc" class="form-control" rows="3" placeholder="Trade binary options with real-time charts..."></textarea>
                        <small class="text-muted">Recommended: 150-160 characters</small>
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Meta Keywords</label>
                        <input type="text" name="meta_keywords" id="page_meta_kw" class="form-control" placeholder="binary options, trading, crypto">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Focus Keyword</label>
                        <input type="text" name="focus_keyword" id="page_focus" class="form-control" placeholder="binary options trading">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">H1 Tag</label>
                        <input type="text" name="h1_tag" id="page_h1" class="form-control" placeholder="Binary Options Trading Platform">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">OG Title</label>
                        <input type="text" name="og_title" id="page_og_title" class="form-control">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">OG Description</label>
                        <textarea name="og_description" id="page_og_desc" class="form-control" rows="2"></textarea>
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">OG Image URL</label>
                        <input type="text" name="og_image" id="page_og_img" class="form-control" placeholder="https://...">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Canonical URL</label>
                        <input type="text" name="canonical_url" id="page_canonical" class="form-control">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Robots</label>
                        <select name="robots" id="page_robots" class="form-control">
                            <option value="index,follow">Index, Follow</option>
                            <option value="noindex,follow">No Index, Follow</option>
                            <option value="index,nofollow">Index, No Follow</option>
                            <option value="noindex,nofollow">No Index, No Follow</option>
                        </select>
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Schema Markup (JSON-LD)</label>
                        <textarea name="schema_markup" id="page_schema" class="form-control" rows="4" placeholder='{"@context":"https://schema.org"...}'></textarea>
                    </div>
                    
                    <button type="submit" class="btn btn-primary btn-block">Save Page SEO</button>
                    <button type="button" class="btn btn-secondary btn-block mt-2" onclick="resetPageForm()">Clear Form</button>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-lg-7">
        <h4 class="mb-3">Managed Pages (<?= count($pages) ?>)</h4>
        
        <?php foreach ($pages as $page): ?>
        <div class="page-card">
            <div class="d-flex justify-content-between align-items-start">
                <div style="flex:1">
                    <div class="page-url"><?= htmlspecialchars($page['page_url']) ?></div>
                    <div class="page-title"><?= htmlspecialchars($page['page_title']) ?></div>
                    <div class="page-desc"><?= htmlspecialchars(substr($page['meta_description'], 0, 150)) ?>...</div>
                    <?php if ($page['focus_keyword']): ?>
                    <div class="mt-2"><span class="badge badge-primary"><?= htmlspecialchars($page['focus_keyword']) ?></span></div>
                    <?php endif; ?>
                </div>
                <div class="d-flex gap-2">
                    <button class="btn btn-sm btn-secondary" onclick='editPage(<?= json_encode($page) ?>)'>
                        <i class="fas fa-edit"></i>
                    </button>
                    <form method="POST" onsubmit="return confirm('Delete this page?')">
                        <input type="hidden" name="action" value="delete_page">
                        <input type="hidden" name="page_id" value="<?= $page['id'] ?>">
                        <button type="submit" class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></button>
                    </form>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
        
        <?php if (empty($pages)): ?>
        <div class="card">
            <div class="card-body text-center py-5">
                <i class="fas fa-file-alt fa-3x text-muted mb-3"></i>
                <h3>No Pages Yet</h3>
                <p class="text-muted">Add your first page to optimize its SEO!</p>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>

<script>
function editPage(page) {
    document.getElementById('page_id').value = page.id;
    document.getElementById('page_url').value = page.page_url;
    document.getElementById('page_title').value = page.page_title;
    document.getElementById('page_meta_desc').value = page.meta_description;
    document.getElementById('page_meta_kw').value = page.meta_keywords;
    document.getElementById('page_focus').value = page.focus_keyword;
    document.getElementById('page_h1').value = page.h1_tag;
    document.getElementById('page_og_title').value = page.og_title;
    document.getElementById('page_og_desc').value = page.og_description;
    document.getElementById('page_og_img').value = page.og_image;
    document.getElementById('page_canonical').value = page.canonical_url;
    document.getElementById('page_robots').value = page.robots;
    document.getElementById('page_schema').value = page.schema_markup;
    
    window.scrollTo({top: 0, behavior: 'smooth'});
}

function resetPageForm() {
    document.getElementById('pageForm').reset();
    document.getElementById('page_id').value = '0';
}
</script>
<?php endif; ?>

<!-- Global Settings Tab -->
<?php if ($tab === 'global'): ?>
<div class="card">
    <div class="card-header"><h3 class="card-title"><i class="fas fa-globe"></i> Global SEO Settings</h3></div>
    <div class="card-body">
        <form method="POST">
            <input type="hidden" name="action" value="save_global">
            
            <div class="row">
                <div class="col-md-6">
                    <h5 class="mb-3">Basic Settings</h5>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Site Title</label>
                        <input type="text" name="site_title" class="form-control" value="<?= htmlspecialchars($seoSettings['site_title'] ?? '') ?>" placeholder="BinaryTrade Pro - Best Trading Platform">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Site Tagline</label>
                        <input type="text" name="site_tagline" class="form-control" value="<?= htmlspecialchars($seoSettings['site_tagline'] ?? '') ?>" placeholder="Trade Smarter, Earn More">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Default Meta Description</label>
                        <textarea name="meta_description" class="form-control" rows="3"><?= htmlspecialchars($seoSettings['meta_description'] ?? '') ?></textarea>
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Default Meta Keywords</label>
                        <textarea name="meta_keywords" class="form-control" rows="2"><?= htmlspecialchars($seoSettings['meta_keywords'] ?? '') ?></textarea>
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Default OG Image URL</label>
                        <input type="text" name="og_image" class="form-control" value="<?= htmlspecialchars($seoSettings['og_image'] ?? '') ?>">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Canonical URL Base</label>
                        <input type="text" name="canonical_url" class="form-control" value="<?= htmlspecialchars($seoSettings['canonical_url'] ?? SITE_URL) ?>">
                    </div>
                </div>
                
                <div class="col-md-6">
                    <h5 class="mb-3">Analytics & Verification</h5>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Google Analytics ID</label>
                        <input type="text" name="google_analytics" class="form-control" value="<?= htmlspecialchars($seoSettings['google_analytics'] ?? '') ?>" placeholder="G-XXXXXXXXXX or UA-XXXXXXXX-X">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Google Search Console Verification</label>
                        <input type="text" name="google_search_console" class="form-control" value="<?= htmlspecialchars($seoSettings['google_search_console'] ?? '') ?>" placeholder="Verification code">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Bing Webmaster Verification</label>
                        <input type="text" name="bing_webmaster" class="form-control" value="<?= htmlspecialchars($seoSettings['bing_webmaster'] ?? '') ?>">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Facebook Pixel ID</label>
                        <input type="text" name="facebook_pixel" class="form-control" value="<?= htmlspecialchars($seoSettings['facebook_pixel'] ?? '') ?>">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Twitter Handle</label>
                        <input type="text" name="twitter_handle" class="form-control" value="<?= htmlspecialchars($seoSettings['twitter_handle'] ?? '') ?>" placeholder="@username">
                    </div>
                    
                    <div class="form-group mb-3">
                        <label class="form-label">Schema Type</label>
                        <select name="schema_type" class="form-control">
                            <option value="Organization" <?= ($seoSettings['schema_type'] ?? '') === 'Organization' ? 'selected' : '' ?>>Organization</option>
                            <option value="WebSite" <?= ($seoSettings['schema_type'] ?? '') === 'WebSite' ? 'selected' : '' ?>>WebSite</option>
                            <option value="LocalBusiness" <?= ($seoSettings['schema_type'] ?? '') === 'LocalBusiness' ? 'selected' : '' ?>>Local Business</option>
                        </select>
                    </div>
                </div>
            </div>
            
            <button type="submit" class="btn btn-primary btn-lg"><i class="fas fa-save"></i> Save Global Settings</button>
        </form>
    </div>
</div>
<?php endif; ?>

<!-- Sitemap Tab -->
<?php if ($tab === 'sitemap'): ?>
<div class="row">
    <div class="col-md-6 mb-4">
        <div class="card">
            <div class="card-header"><h3 class="card-title"><i class="fas fa-sitemap"></i> Generate Sitemap</h3></div>
            <div class="card-body">
                <form method="POST">
                    <input type="hidden" name="action" value="generate_sitemap">
                    <div class="form-group mb-3">
                        <label class="form-label">Base URL</label>
                        <input type="text" name="base_url" class="form-control" value="<?= SITE_URL ?>">
                    </div>
                    <button type="submit" class="btn btn-primary btn-block"><i class="fas fa-cogs"></i> Generate Sitemap</button>
                </form>
                
                <hr class="my-4">
                
                <h5>Sitemap Status</h5>
                <?php if (file_exists(ROOT_PATH . '/sitemap.xml')): ?>
                <div class="alert alert-success">
                    <i class="fas fa-check-circle"></i> Sitemap exists!<br>
                    <small>Last modified: <?= date('d M Y H:i', filemtime(ROOT_PATH . '/sitemap.xml')) ?></small>
                </div>
                <a href="<?= SITE_URL ?>/sitemap.xml" target="_blank" class="btn btn-secondary btn-block">
                    <i class="fas fa-external-link-alt"></i> View Sitemap
                </a>
                <?php else: ?>
                <div class="alert alert-warning">
                    <i class="fas fa-exclamation-triangle"></i> Sitemap not generated yet
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card">
            <div class="card-header"><h3 class="card-title">Submit to Search Engines</h3></div>
            <div class="card-body">
                <p class="text-muted mb-3">Submit your sitemap to search engines for faster indexing:</p>
                
                <a href="https://search.google.com/search-console" target="_blank" class="btn btn-secondary btn-block mb-2">
                    <i class="fab fa-google"></i> Google Search Console
                </a>
                <a href="https://www.bing.com/webmasters" target="_blank" class="btn btn-secondary btn-block mb-2">
                    <i class="fab fa-microsoft"></i> Bing Webmaster Tools
                </a>
                <a href="https://webmaster.yandex.com" target="_blank" class="btn btn-secondary btn-block">
                    <i class="fas fa-search"></i> Yandex Webmaster
                </a>
            </div>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- Robots.txt Tab -->
<?php if ($tab === 'robots'): ?>
<div class="card">
    <div class="card-header"><h3 class="card-title"><i class="fas fa-robot"></i> Robots.txt Editor</h3></div>
    <div class="card-body">
        <form method="POST">
            <input type="hidden" name="action" value="save_robots">
            <div class="form-group mb-3">
                <label class="form-label">Robots.txt Content</label>
                <textarea name="robots_content" class="form-control robots-textarea"><?= htmlspecialchars($robotsContent) ?></textarea>
            </div>
            <button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Save Robots.txt</button>
            <a href="<?= SITE_URL ?>/robots.txt" target="_blank" class="btn btn-secondary"><i class="fas fa-external-link-alt"></i> View Current</a>
        </form>
        
        <hr class="my-4">
        
        <h5>Common Directives</h5>
        <div class="row">
            <div class="col-md-6">
                <pre class="schema-preview">User-agent: *
Allow: /
Disallow: /admin/
Disallow: /api/
Disallow: /config/
Disallow: /includes/</pre>
            </div>
            <div class="col-md-6">
                <pre class="schema-preview">User-agent: Googlebot
Allow: /

User-agent: Bingbot
Allow: /

Sitemap: <?= SITE_URL ?>/sitemap.xml</pre>
            </div>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- Redirects Tab -->
<?php if ($tab === 'redirects'): ?>
<div class="row">
    <div class="col-md-4 mb-4">
        <div class="card">
            <div class="card-header"><h3 class="card-title"><i class="fas fa-plus"></i> Add Redirect</h3></div>
            <div class="card-body">
                <form method="POST">
                    <input type="hidden" name="action" value="add_redirect">
                    <div class="form-group mb-3">
                        <label class="form-label">From URL</label>
                        <input type="text" name="from_url" class="form-control" required placeholder="/old-page">
                    </div>
                    <div class="form-group mb-3">
                        <label class="form-label">To URL</label>
                        <input type="text" name="to_url" class="form-control" required placeholder="/new-page">
                    </div>
                    <div class="form-group mb-3">
                        <label class="form-label">Redirect Type</label>
                        <select name="redirect_type" class="form-control">
                            <option value="301">301 - Permanent</option>
                            <option value="302">302 - Temporary</option>
                            <option value="307">307 - Temporary (Strict)</option>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-primary btn-block">Add Redirect</button>
                </form>
            </div>
        </div>
    </div>
    <div class="col-md-8">
        <div class="card">
            <div class="card-header"><h3 class="card-title">Active Redirects (<?= count($redirects) ?>)</h3></div>
            <div class="card-body">
                <?php foreach ($redirects as $r): ?>
                <div class="redirect-item">
                    <div class="redirect-from"><?= htmlspecialchars($r['from_url']) ?></div>
                    <div class="redirect-arrow"><i class="fas fa-arrow-right"></i></div>
                    <div class="redirect-to"><?= htmlspecialchars($r['to_url']) ?></div>
                    <div class="redirect-type"><?= $r['redirect_type'] ?></div>
                    <form method="POST" onsubmit="return confirm('Delete?')">
                        <input type="hidden" name="action" value="delete_redirect">
                        <input type="hidden" name="redirect_id" value="<?= $r['id'] ?>">
                        <button type="submit" class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></button>
                    </form>
                </div>
                <?php endforeach; ?>
                
                <?php if (empty($redirects)): ?>
                <p class="text-center text-muted py-4">No redirects configured</p>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- Analytics Tab -->
<?php if ($tab === 'analytics'): ?>
<div class="card">
    <div class="card-header"><h3 class="card-title"><i class="fas fa-chart-line"></i> SEO Analytics</h3></div>
    <div class="card-body">
        <div class="alert alert-info">
            <i class="fas fa-info-circle"></i> Connect Google Search Console and Google Analytics to view detailed SEO analytics.
        </div>
        
        <div class="row">
            <div class="col-md-4 mb-4">
                <div class="card" style="background: var(--bg-tertiary);">
                    <div class="card-body text-center">
                        <i class="fab fa-google fa-3x mb-3" style="color: #4285f4;"></i>
                        <h5>Google Search Console</h5>
                        <p class="text-muted">Monitor search performance</p>
                        <a href="https://search.google.com/search-console" target="_blank" class="btn btn-primary btn-sm">Open Console</a>
                    </div>
                </div>
            </div>
            <div class="col-md-4 mb-4">
                <div class="card" style="background: var(--bg-tertiary);">
                    <div class="card-body text-center">
                        <i class="fas fa-chart-bar fa-3x mb-3" style="color: #f9ab00;"></i>
                        <h5>Google Analytics</h5>
                        <p class="text-muted">Track website traffic</p>
                        <a href="https://analytics.google.com" target="_blank" class="btn btn-primary btn-sm">Open Analytics</a>
                    </div>
                </div>
            </div>
            <div class="col-md-4 mb-4">
                <div class="card" style="background: var(--bg-tertiary);">
                    <div class="card-body text-center">
                        <i class="fas fa-tachometer-alt fa-3x mb-3" style="color: #00d09c;"></i>
                        <h5>PageSpeed Insights</h5>
                        <p class="text-muted">Check page speed</p>
                        <a href="https://pagespeed.web.dev/?url=<?= urlencode(SITE_URL) ?>" target="_blank" class="btn btn-primary btn-sm">Check Speed</a>
                    </div>
                </div>
            </div>
        </div>
        
        <h5 class="mt-4 mb-3">Keyword Performance</h5>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>Keyword</th>
                        <th>Target Page</th>
                        <th>Volume</th>
                        <th>Difficulty</th>
                        <th>Priority</th>
                    </tr>
                </thead>
                <tbody>
                    <?php 
                    $topKw = dbFetchAll("SELECT * FROM seo_keywords WHERE status = 'active' ORDER BY priority DESC, search_volume DESC LIMIT 10");
                    foreach ($topKw as $kw): 
                    ?>
                    <tr>
                        <td><?= htmlspecialchars($kw['keyword']) ?></td>
                        <td><code><?= htmlspecialchars($kw['target_page'] ?: '-') ?></code></td>
                        <td><?= number_format($kw['search_volume']) ?></td>
                        <td>
                            <div class="difficulty-bar" style="display:inline-block;vertical-align:middle;">
                                <div class="difficulty-fill <?= $kw['difficulty'] < 40 ? 'difficulty-easy' : ($kw['difficulty'] < 70 ? 'difficulty-medium' : 'difficulty-hard') ?>" style="width: <?= $kw['difficulty'] ?>%"></div>
                            </div>
                            <?= $kw['difficulty'] ?>%
                        </td>
                        <td><span class="priority-<?= $kw['priority'] ?>"><?= ucfirst($kw['priority']) ?></span></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php endif; ?>

<?php require_once 'includes/footer.php'; ?>
