<?php
if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}

if(isset($_SESSION['usuario'])) {
    header('Location: dashboard.php');
    exit();
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <title>Login Admin - Mercadinho Pajeú</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Corona Dark Bootstrap Admin Template CSS -->
    <link rel="stylesheet" href="https://themewagon.github.io/corona-free-dark-bootstrap-admin-template/assets/vendors/mdi/css/materialdesignicons.min.css">
    <link rel="stylesheet" href="https://themewagon.github.io/corona-free-dark-bootstrap-admin-template/assets/vendors/css/vendor.bundle.base.css">
    <link rel="stylesheet" href="https://themewagon.github.io/corona-free-dark-bootstrap-admin-template/assets/css/style.css">
    <link rel="shortcut icon" href="logo.png"/>
    <style>
        html, body, .container-scroller, .page-body-wrapper, .main-panel, .content-wrapper {
            background: #1a2332 !important;
        }
        body {
            background-image: url('logo1.png');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            position: relative;
        }
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(26, 35, 50, 0.5);
            z-index: -1;
        }
        .login-container {
            background: linear-gradient(135deg, #A20000 0%, #8B0000 100%);
            max-width: 370px;
            margin: 70px auto 0 auto;
            border-radius: 14px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
            padding: 40px 34px 26px 34px;
            text-align: center;
        }
        .logo {
            width: 100px;
            margin-bottom: 16px;
            border-radius: 8px;
            background: #fff;
            box-shadow: 0 1.5px 8px rgba(0,0,0,0.2);
        }
        .store-title {
            font-size: 1.5em;
            color: #ffc107;
            margin-bottom: 8px;
            font-weight: bold;
            letter-spacing: 1px;
        }
        h2 {
            color: #ffffff;
            margin-bottom: 32px;
            font-size: 1.15em;
            font-weight: 400;
        }
        label {
            display: block;
            margin: 12px 0 6px 0;
            color: #ffc107;
            text-align: left;
            font-size: 1em;
        }
        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #ffc107;
            border-radius: 6px;
            font-size: 1em;
            margin-bottom: 10px;
            background: #A20000;
            color: #fff;
        }
        input[type="submit"] {
            width: 100%;
            background: #ffc107;
            color: #212529;
            border: none;
            padding: 12px 0;
            border-radius: 6px;
            cursor: pointer;
            font-size: 1.1em;
            font-weight: bold;
            margin-top: 10px;
            transition: background 0.2s;
        }
        input[type="submit"]:hover {
            background: #ffcd39;
        }
        .error {
            background: #fff8e1;
            color: #c0392b;
            border: 1px solid #fbc02d;
            margin-top: 18px;
            font-size: 1em;
            border-radius: 6px;
            padding: 8px 0;
        }
        @media (max-width: 500px) {
            .login-container { max-width: 96vw; padding: 18px 2vw; }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <img src="logo.png" alt="Logo Mercadinho Pajeú" class="logo">
        <div class="store-title">Mercadinho Pajeú</div>
        <h2>Painel Administrativo</h2>
        <form action="valida_login.php" method="post" autocomplete="off">
            <label for="usuario">Usuário:</label>
            <input type="text" name="usuario" id="usuario" placeholder="Digite seu usuário" required>

            <label for="senha">Senha:</label>
            <input type="password" name="senha" id="senha" placeholder="Digite sua senha" required>

            <input type="submit" value="Entrar">
        </form>
        <?php
        if(isset($_GET['erro'])) {
            echo "<div class='error'>Usuário ou senha inválidos!</div>";
        }
        ?>
    </div>
</body>
</html>