<?php
ob_start();
session_start();

// 登录处理
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['login'])) {
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    
    // 简单验证（实际项目需加密）
    if ($username == 'admin' && $password == '123456') {
        $_SESSION['user_info'] = [
            'id' => 1,
            'username' => 'admin',
            'realname' => '系统管理员'
        ];
        header('Location: index.php');
        exit;
    } else {
        $errorMsg = '用户名或密码错误！';
    }
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 发票管理系统</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; font-family: "Microsoft YaHei", sans-serif; }
        body {
            background-color: #f5f7fa;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
        }
        .login-box {
            background-color: #fff;
            width: 400px;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.1);
        }
        .login-box h2 {
            text-align: center;
            margin-bottom: 30px;
            color: #2c3e50;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
        }
        .form-control {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid #e6e9ed;
            border-radius: 4px;
            font-size: 14px;
        }
        .btn {
            width: 100%;
            padding: 12px;
            background-color: #3498db;
            color: #fff;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            margin-top: 10px;
        }
        .error-msg {
            color: #e74c3c;
            text-align: center;
            margin-bottom: 20px;
            padding: 10px;
            background-color: #f2dede;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <div class="login-box">
        <h2>发票管理系统</h2>
        <?php if (isset($errorMsg)): ?>
            <div class="error-msg"><?= $errorMsg ?></div>
        <?php endif; ?>
        <form method="post">
            <input type="hidden" name="login" value="1">
            <div class="form-group">
                <label>用户名</label>
                <input type="text" name="username" class="form-control" required placeholder="请输入用户名">
            </div>
            <div class="form-group">
                <label>密码</label>
                <input type="password" name="password" class="form-control" required placeholder="请输入密码">
            </div>
            <button type="submit" class="btn">登录</button>
        </form>
    </div>
</body>
</html>
<?php ob_end_flush(); ?>