<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Dashboard</title>
    <style>
        :root {
    --bg-dark: #1a1a2e;
    --primary-color: #4ecdc4;
    --secondary-color: #45aaf2;
    --gradient: linear-gradient(135deg, #4ecdc4 0%, #45aaf2 100%);
    --danger-color: #ff6b6b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-dark);
    color: #ffffff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(45deg, #16213e, #0f3460);
}

.container {
    width: 100%;
    max-width: 900px;
    padding: 20px;
}

.login-card, .dashboard {
    background: rgba(29, 36, 56, 0.8);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    backdrop-filter: blur(10px);
}

.login-title, .dashboard-title {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 30px;
}

.login-form input {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 8px;
    color: #ffffff;
    transition: all 0.3s ease;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(78, 205, 196, 0.3);
}

.login-form button {
    width: 100%;
    padding: 12px;
    background: var(--gradient);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.login-form button:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 14px rgba(0,0,0,0.2);
}

.error-message {
    color: #ff6b6b;
    text-align: center;
    margin-bottom: 20px;
}

.dashboard {
    max-height: 600px;
    overflow-y: auto;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.visitors-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 10px;
}

.visitors-table th, 
.visitors-table td {
    background: rgba(255,255,255,0.1);
    padding: 15px;
    text-align: left;
    border-radius: 1px;
    color: #ffffff;
}

.visitors-table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--primary-color);
}

.logout-btn, .clear-logs-btn {
    display: block;
    width: 100%;
    background: rgba(255,255,255,0.1);
    color: #ffffff;
    border: none;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 20px;
    transition: all 0.3s ease;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.2);
}

.clear-logs-btn {
    background: rgba(255, 107, 107, 0.1);
    color: var(--danger-color);
}

.clear-logs-btn:hover {
    background: rgba(255, 107, 107, 0.2);
}

.hidden {
    display: none !important;
}
    </style>
</head>
<body>
    <div class="container">
        <div id="loginPage" class="login-card">
            <h1 class="login-title">Admin Dashboard</h1>
            <form id="loginForm" class="login-form">
                <div id="loginError" class="error-message hidden"></div>
                <input type="text" id="hwidInput" placeholder="!.!" required>
                <button type="submit">Login</button>
            </form>
        </div>

        <div id="dashboardPage" class="dashboard hidden">
            <div class="dashboard-header">
                <div class="dashboard-title">Visitor Logs</div>
                <button id="clearLogsBtn" class="clear-logs-btn">Clear Logs</button>
            </div>

            <table class="visitors-table">
                <thead>
                    <tr>
                        <th>IP Address</th>
                        <th>Timestamp</th>
                        <th>User Agent</th>
                    </tr>
                </thead>
                <tbody id="visitorsTableBody">
                </tbody>
            </table>

            <button id="logoutBtn" class="logout-btn">Logout</button>
        </div>
    </div>

    <script>
        const CORRECT_HWID = '0n!=$_-s7d)9)5#1s5w+92e%ac!lh(*b%71j6+x6r4+ew$gv=5';

        class AuthManager {
            static isAuthenticated() {
                return localStorage.getItem('hwid') === CORRECT_HWID;
            }

            static login(hwid) {
                if (hwid === CORRECT_HWID) {
                    localStorage.setItem('hwid', hwid);
                    return true;
                }
                return false;
            }

            static logout() {
                localStorage.removeItem('hwid');
                window.location.reload();
            }
        }

        class VisitorLogger {
    static async logVisitor(type = 'page') {
        if (window.location.pathname !== '/index.html' && 
            window.location.pathname !== '/') {
            return;
        }

        try {
            const response = await fetch('https://api.ipify.org?format=json');
            const data = await response.json();
            
            const visitors = JSON.parse(localStorage.getItem('siteVisitors') || '[]');
            const newVisitor = {
                ip: data.ip,
                timestamp: new Date().toISOString(),
                userAgent: navigator.userAgent,
                type: type
            };
            
            visitors.push(newVisitor);
            
            if (visitors.length > 50) {
                visitors.shift();
            }
            
            localStorage.setItem('siteVisitors', JSON.stringify(visitors));
        } catch (error) {
            console.error('Failed to fetch IP:', error);
        }
    }

    static clearLogs() {
        localStorage.removeItem('siteVisitors');
        displayVisitors(); 
        }
    }   
        const loginPage = document.getElementById('loginPage');
        const dashboardPage = document.getElementById('dashboardPage');
        const loginForm = document.getElementById('loginForm');
        const loginError = document.getElementById('loginError');
        const hwidInput = document.getElementById('hwidInput');
        const logoutBtn = document.getElementById('logoutBtn');
        const clearLogsBtn = document.getElementById('clearLogsBtn');
        const visitorsTableBody = document.getElementById('visitorsTableBody');

        loginForm.addEventListener('submit', async (e) => {
            e.preventDefault();
            const enteredHwid = hwidInput.value.trim();

            if (AuthManager.login(enteredHwid)) {
                await VisitorLogger.logVisitor('login');
                showDashboard();
            } else {
                loginError.textContent = 'Invalid HWID';
                loginError.classList.remove('hidden');
            }
        });

        logoutBtn.addEventListener('click', () => {
            AuthManager.logout();
        });

        clearLogsBtn.addEventListener('click', () => {
            VisitorLogger.clearLogs();
        });

        function showDashboard() {
            loginPage.classList.add('hidden');
            dashboardPage.classList.remove('hidden');
            displayVisitors();
        }

        function displayVisitors() {
            const visitors = JSON.parse(localStorage.getItem('siteVisitors') || '[]');
            visitorsTableBody.innerHTML = '';

            if (visitors.length === 0) {
                const noVisitorsRow = document.createElement('tr');
                noVisitorsRow.innerHTML = `
                    <td colspan="3" style="text-align: center; color: #4ecdc4; padding: 20px;">
                        No visitor logs available
                    </td>
                `;
                visitorsTableBody.appendChild(noVisitorsRow);
                return;
            }

            visitors.reverse().forEach(visitor => {
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td>${visitor.ip}</td>
                    <td>${new Date(visitor.timestamp).toLocaleString()}</td>
                    <td>${visitor.userAgent} (${visitor.type || 'unknown'})</td>
                `;
                visitorsTableBody.appendChild(row);
            });
        }

        document.addEventListener('DOMContentLoaded', async () => {
            await VisitorLogger.logVisitor('page_load');
            
            if (AuthManager.isAuthenticated()) {
                showDashboard();
            }
        });
    </script>
</body>
</html>