<?php
session_start();

$masterPassword = '#Tz1309'; // Altere esta senha mestra!

if (isset($_POST['password'])) {
    if ($_POST['password'] === $masterPassword) {
        $_SESSION['authenticated'] = true;
        header('Location: resetsenha.php');
        exit();
    } else {
        $error = 'Senha mestra incorreta!';
    }
}

if (isset($_GET['logout'])) {
    session_destroy();
    header('Location: index.php');
    exit();
}

// Se já autenticado, redireciona para resetsenha.php
if (isset($_SESSION['authenticated']) && $_SESSION['authenticated'] === true) {
    header('Location: resetsenha.php');
    exit();
}
?>
<!DOCTYPE html>
<html lang="pt">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Acesso Restrito</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #1a1a1a;
            color: #f0f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }
        .container {
            background-color: #2a2a2a;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
            text-align: center;
            width: 100%;
            max-width: 400px;
        }
        h1 {
            color: #e0e0e0;
            margin-bottom: 20px;
        }
        input[type="password"] {
            width: calc(100% - 20px);
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #555;
            border-radius: 4px;
            background-color: #3a3a3a;
            color: #f0f0f0;
            font-size: 16px;
        }
        input[type="password"]::placeholder {
            color: #bbb;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }
        button:hover {
            background-color: #0056b3;
        }
        .error {
            color: #ff6b6b;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Acesso Restrito</h1>
        <form method="POST">
            <input type="password" name="password" placeholder="Senha Mestra" required>
            <button type="submit">Entrar</button>
        </form>
        <?php if (isset($error)): ?>
            <p class="error"><?php echo $error; ?></p>
        <?php endif; ?>
    </div>
</body>
</html>
