<?php
session_start();

$allowed_ips = ['23.248.178.227', '23.248.178.230', '23.248.178.225', '129.227.47.6'];
$admin_credentials = [
    ['id' => 'kodokpuki', 'password' => 'contoh123$$'],
    ['id' => 'admin', 'password' => 'moneycome$$']
];

$error_message = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = $_POST['id'] ?? '';
    $password = $_POST['password'] ?? '';

    $is_authenticated = false;
    foreach ($admin_credentials as $admin) {
        if ($id === $admin['id'] && $password === $admin['password']) {
            $is_authenticated = true;
            break;
        }
    }

    if ($is_authenticated) {
        $_SESSION['admin_logged_in'] = true;
        header("Location: admin.php");
        exit;
    }

    $error_message = 'Username atau password tidak sesuai.';
}
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Login</title>
    <style>
        :root {
            --bg-top: #0f2031;
            --bg-bottom: #08111b;
            --panel: rgba(10, 21, 33, 0.86);
            --panel-border: rgba(255, 255, 255, 0.1);
            --text: #f7fbff;
            --muted: #a9bece;
            --gold-1: #f7df97;
            --gold-2: #db9a37;
            --gold-3: #8b541b;
            --danger-bg: rgba(255, 109, 92, 0.12);
            --danger-border: rgba(255, 109, 92, 0.24);
        }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            min-height: 100vh;
            padding: 20px 14px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: "Trebuchet MS", "Segoe UI", sans-serif;
            color: var(--text);
            background:
                radial-gradient(circle at top, rgba(247, 223, 151, 0.14), transparent 24%),
                radial-gradient(circle at bottom right, rgba(46, 113, 185, 0.14), transparent 26%),
                linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
        }

        .page-shell {
            width: 100%;
            max-width: 980px;
        }

        .navbar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 16px;
            padding: 12px 16px;
            border-radius: 18px;
            border: 1px solid var(--panel-border);
            background: rgba(7, 15, 24, 0.7);
            backdrop-filter: blur(12px);
            box-shadow: 0 16px 30px rgba(0, 0, 0, 0.18);
        }

        .navbar-brand img {
            width: clamp(108px, 18vw, 145px);
            height: auto;
            display: block;
        }

        .navbar-title {
            color: rgba(247, 251, 255, 0.74);
            font-size: 13px;
            font-weight: 800;
            letter-spacing: 0.12em;
            text-transform: uppercase;
        }

        .login-layout {
            display: grid;
            grid-template-columns: minmax(280px, 1fr) minmax(320px, 420px);
            gap: 22px;
            margin-top: 20px;
            align-items: stretch;
        }

        .hero-panel,
        .login-panel {
            border: 1px solid var(--panel-border);
            border-radius: 28px;
            background: var(--panel);
            backdrop-filter: blur(14px);
            box-shadow: 0 28px 50px rgba(0, 0, 0, 0.28);
        }

        .hero-panel {
            padding: 34px 30px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .eyebrow {
            margin: 0 0 10px;
            color: var(--gold-1);
            font-size: 12px;
            font-weight: 800;
            letter-spacing: 0.14em;
            text-transform: uppercase;
        }

        h1 {
            margin: 0;
            font-size: 40px;
            line-height: 1.05;
            color: #fff8ea;
        }

        .hero-text {
            margin: 16px 0 0;
            color: var(--muted);
            font-size: 15px;
            line-height: 1.75;
        }

        .hero-points {
            margin-top: 22px;
            display: grid;
            gap: 12px;
        }

        .hero-point {
            padding: 14px 16px;
            border-radius: 18px;
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.06);
            color: #eef6ff;
            font-size: 14px;
        }

        .login-panel {
            padding: 30px 26px;
        }

        .login-card-logo {
            display: flex;
            justify-content: center;
            margin-bottom: 18px;
        }

        .login-card-logo img {
            width: min(72%, 220px);
            height: auto;
            display: block;
            filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.25));
        }

        .login-title {
            margin: 0;
            font-size: 28px;
            text-align: center;
            color: #fff8ea;
        }

        .login-subtitle {
            margin: 10px 0 0;
            text-align: center;
            font-size: 14px;
            line-height: 1.7;
            color: var(--muted);
        }

        .error-box {
            margin-top: 18px;
            padding: 12px 14px;
            border-radius: 14px;
            border: 1px solid var(--danger-border);
            background: var(--danger-bg);
            color: #ffd7d1;
            font-size: 14px;
        }

        .form-group {
            margin-top: 18px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #eef5fb;
            font-size: 14px;
            font-weight: 700;
        }

        input {
            width: 100%;
            padding: 13px 14px;
            border: 1px solid rgba(255, 255, 255, 0.12);
            border-radius: 14px;
            outline: none;
            background: rgba(255, 255, 255, 0.06);
            color: var(--text);
            font-size: 15px;
            transition: border-color 0.2s ease, box-shadow 0.2s ease;
        }

        input:focus {
            border-color: rgba(247, 223, 151, 0.7);
            box-shadow: 0 0 0 4px rgba(247, 223, 151, 0.14);
        }

        .submit-button {
            width: 100%;
            margin-top: 22px;
            padding: 14px 16px;
            border: none;
            border-radius: 16px;
            cursor: pointer;
            font-size: 15px;
            font-weight: 900;
            letter-spacing: 0.08em;
            color: #261205;
            background: linear-gradient(180deg, var(--gold-1), var(--gold-2));
            box-shadow: 0 18px 28px rgba(0, 0, 0, 0.18);
            transition: transform 0.2s ease, filter 0.2s ease;
        }

        .submit-button:hover {
            transform: translateY(-2px);
            filter: brightness(1.03);
        }

        @media (max-width: 860px) {
            .login-layout {
                grid-template-columns: 1fr;
            }
        }

        @media (max-width: 480px) {
            h1 {
                font-size: 32px;
            }

            .hero-panel,
            .login-panel {
                border-radius: 22px;
            }

            .navbar-title {
                font-size: 11px;
            }
        }
    </style>
</head>
<body>
    <div class="page-shell">

        <section class="login-layout">

            <div class="login-panel">
                <div class="login-card-logo">
                    <img src="logo.png" alt="Logo">
                </div>
                <h2 class="login-title">Admin Login</h2>
                <p class="login-subtitle">Masukkan username dan password admin untuk mengakses panel pengelolaan voucher.</p>

                <?php if ($error_message): ?>
                    <div class="error-box"><?= htmlspecialchars($error_message) ?></div>
                <?php endif; ?>

                <form action="admin_login.php" method="POST">
                    <div class="form-group">
                        <label for="id">Username</label>
                        <input type="text" id="id" name="id" autocomplete="username" required>
                    </div>

                    <div class="form-group">
                        <label for="password">Password</label>
                        <input type="password" id="password" name="password" autocomplete="current-password" required>
                    </div>

                    <button type="submit" class="submit-button">Masuk ke Dashboard</button>
                </form>
            </div>
        </section>
    </div>
</body>
</html>
