<?php
// Log the access attempt before any output
if (!file_exists('logs')) {
    mkdir('logs', 0755, true);
}
$logMessage = sprintf(
    "[%s] 403 Access Denied - IP: %s - URI: %s - Agent: %s%s",
    date('Y-m-d H:i:s'),
    $_SERVER['REMOTE_ADDR'] ?? 'unknown',
    $_SERVER['REQUEST_URI'] ?? '/',
    $_SERVER['HTTP_USER_AGENT'] ?? 'unknown',
    PHP_EOL
);
file_put_contents('logs/access_denied.log', $logMessage, FILE_APPEND);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="robots" content="noindex, nofollow">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Access Denied | 403 Forbidden - Creative Web Solutions</title>
    <style>
        :root {
            --primary: #4361ee;
            --primary-dark: #3a0ca3;
            --secondary: #4cc9f0;
            --dark: #212529;
            --light: #f8f9fa;
            --danger: #ef233c;
            --danger-dark: #d90429;
            --gray: #6c757d;
            --card-bg: #ffffff;
            --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
            color: var(--dark);
            line-height: 1.6;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 1rem;
        }
        
        .container {
            width: 100%;
            max-width: 640px;
            padding: 3rem 2rem;
            background-color: var(--card-bg);
            border-radius: 16px;
            box-shadow: var(--shadow);
            text-align: center;
            position: relative;
            overflow: hidden;
        }
        
        .container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 6px;
            background: linear-gradient(90deg, var(--danger) 0%, var(--primary) 100%);
        }
        
        .error-content {
            animation: fadeIn 0.6s cubic-bezier(0.39, 0.575, 0.565, 1) both;
        }
        
        .error-code {
            font-size: 7rem;
            font-weight: 900;
            color: var(--danger);
            margin-bottom: 0.5rem;
            line-height: 1;
            text-shadow: 2px 2px 0 rgba(239, 35, 60, 0.1);
        }
        
        h1 {
            font-size: 2.25rem;
            margin-bottom: 1rem;
            color: var(--dark);
            font-weight: 700;
        }
        
        p {
            font-size: 1.125rem;
            margin-bottom: 2rem;
            opacity: 0.85;
            max-width: 80%;
            margin-left: auto;
            margin-right: auto;
        }
        
        .ip-info {
            background: rgba(233, 236, 239, 0.7);
            padding: 1rem;
            border-radius: 8px;
            margin: 1.5rem 0;
            font-size: 0.95rem;
        }
        
        .ip-address {
            font-family: 'SF Mono', 'Roboto Mono', monospace;
            font-weight: 600;
            color: var(--danger-dark);
            word-break: break-all;
        }
        
        .actions {
            display: flex;
            gap: 1rem;
            justify-content: center;
            flex-wrap: wrap;
            margin-top: 2rem;
        }
        
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0.875rem 2rem;
            border-radius: 50px;
            text-decoration: none;
            font-weight: 600;
            font-size: 1rem;
            transition: all 0.3s ease;
            box-shadow: var(--shadow);
            border: none;
            cursor: pointer;
            gap: 0.5rem;
        }
        
        .btn-primary {
            background-color: var(--primary);
            color: white;
        }
        
        .btn-primary:hover {
            background-color: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: var(--shadow-hover);
        }
        
        .btn-outline {
            border: 2px solid var(--primary);
            color: var(--primary);
            background: transparent;
        }
        
        .btn-outline:hover {
            background-color: var(--primary);
            color: white;
        }
        
        .illustration {
            max-width: 220px;
            margin: 1.5rem auto;
        }
        
        .illustration svg {
            width: 100%;
            height: auto;
            opacity: 0.9;
        }
        
        footer {
            text-align: center;
            margin-top: 2.5rem;
            font-size: 0.875rem;
            color: var(--gray);
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(30px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        @media (max-width: 768px) {
            .container {
                padding: 2rem 1.5rem;
            }
            
            .error-code {
                font-size: 5.5rem;
            }
            
            h1 {
                font-size: 1.75rem;
            }
            
            p {
                max-width: 100%;
                font-size: 1rem;
            }
            
            .btn {
                padding: 0.75rem 1.5rem;
                width: 100%;
            }
            
            .actions {
                flex-direction: column;
                gap: 0.75rem;
            }
            
            .illustration {
                max-width: 180px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="error-content">
            <div class="error-code">403</div>
            <h1>Access Restricted</h1>
            <p>
                Authorization required to access this resource. If you believe this is an error, please contact support.
            </p>
            
            <?php if(!empty($_SERVER['REMOTE_ADDR'])): ?>
            <div class="ip-info">
                <div>Your IP address has been recorded</div>
                <div class="ip-address"><?php echo htmlspecialchars($_SERVER['REMOTE_ADDR']); ?></div>
            </div>
            <?php endif; ?>
            
            <div class="illustration">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
                    <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path>
                    <circle cx="12" cy="9" r="1"></circle>
                    <line x1="12" y1="13" x2="12" y2="16"></line>
                </svg>
            </div>
            
            <div class="actions">
                <a href="/" class="btn btn-primary">
                    <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
                        <polyline points="9 22 9 12 15 12 15 22"></polyline>
                    </svg>
                    Return to Homepage
                </a>
                <a href="mailto:info@creativewebsolutions.co.ke?subject=Access%20Request%20for%20<?php echo urlencode($_SERVER['REQUEST_URI'] ?? ''); ?>&body=IP:%20<?php echo urlencode($_SERVER['REMOTE_ADDR'] ?? ''); ?>%0ARequested%20URL:%20<?php echo urlencode($_SERVER['REQUEST_URI'] ?? ''); ?>" class="btn btn-outline">
                    <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path>
                        <polyline points="22,6 12,13 2,6"></polyline>
                    </svg>
                    Request Access
                </a>
            </div>
        </div>
        
        <footer>
            <p>&copy; <?php echo date('Y'); ?> Creative Web Solutions. All rights reserved.</p>
        </footer>
    </div>
</body>
</html>