<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Login — WebGIS Pemetaan Sosial</title>
    <meta name="description" content="Masuk ke platform WebGIS Pemetaan Sosial untuk mengelola data kemiskinan dan distribusi bantuan.">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <style>
        /* ─── TOKENS ─── */
        :root {
            --blue:    #2563EB;
            --blue-d:  #1D4ED8;
            --blue-l:  #EFF6FF;
            --blue-m:  rgba(37,99,235,.10);
            --navy:    #0F172A;
            --green:   #10B981;
            --red:     #EF4444;
            --red-l:   #FEF2F2;
            --bg:      #EBF0F7;
            --surface: #FFFFFF;
            --border:  #E2E8F0;
            --border-l:#F1F5F9;
            --text-2:  #475569;
            --text-3:  #94A3B8;
            --sh:      0 4px 24px rgba(15,23,42,.10);
            --sh-lg:   0 20px 60px rgba(15,23,42,.18);
            --r:       16px;
            --r2:      12px;
            --r3:       8px;
        }

        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

        html, body {
            height: 100%;
            font-family: 'Plus Jakarta Sans', sans-serif;
            background: var(--bg);
            overflow: hidden;
        }

        /* ─── ANIMATED BACKGROUND ─── */
        .bg-scene {
            position: fixed; inset: 0;
            background: linear-gradient(135deg, #0F172A 0%, #1E3A5F 40%, #1D4ED8 80%, #2563EB 100%);
            z-index: 0;
            overflow: hidden;
        }

        /* Grid map lines */
        .bg-grid {
            position: absolute; inset: 0;
            background-image:
                linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
                linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
            background-size: 48px 48px;
            animation: gridPan 25s linear infinite;
        }
        @keyframes gridPan {
            0%   { transform: translate(0, 0); }
            100% { transform: translate(48px, 48px); }
        }

        /* Floating blobs */
        .blob {
            position: absolute;
            border-radius: 50%;
            filter: blur(72px);
            opacity: 0.22;
            animation: blobFloat 12s ease-in-out infinite;
        }
        .blob-1 {
            width: 520px; height: 520px;
            background: #3B82F6;
            top: -180px; left: -140px;
            animation-delay: 0s;
        }
        .blob-2 {
            width: 380px; height: 380px;
            background: #10B981;
            bottom: -100px; right: -80px;
            animation-delay: -5s;
        }
        .blob-3 {
            width: 280px; height: 280px;
            background: #6366F1;
            top: 40%; left: 55%;
            animation-delay: -9s;
        }
        @keyframes blobFloat {
            0%, 100% { transform: translate(0, 0) scale(1); }
            33%       { transform: translate(18px, -22px) scale(1.04); }
            66%       { transform: translate(-12px, 14px) scale(0.97); }
        }

        /* Floating map pin particles */
        .particle {
            position: absolute;
            width: 8px; height: 8px;
            border-radius: 50%;
            background: rgba(255,255,255,0.18);
            animation: particleDrift linear infinite;
        }
        @keyframes particleDrift {
            0%   { transform: translateY(100vh) scale(0); opacity: 0; }
            10%  { opacity: 1; }
            90%  { opacity: 1; }
            100% { transform: translateY(-80px) scale(1.2); opacity: 0; }
        }

        /* ─── LAYOUT ─── */
        .page {
            position: relative; z-index: 10;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 24px;
        }

        /* ─── CARD ─── */
        .card {
            width: 100%;
            max-width: 420px;
            background: rgba(255,255,255,0.97);
            border-radius: 24px;
            box-shadow: var(--sh-lg), 0 0 0 1px rgba(255,255,255,0.12);
            overflow: hidden;
            animation: cardIn 0.55s cubic-bezier(0.34,1.4,0.64,1) both;
        }
        @keyframes cardIn {
            from { opacity: 0; transform: translateY(32px) scale(0.94); }
            to   { opacity: 1; transform: translateY(0)   scale(1); }
        }

        /* Card header / hero */
        .card-hero {
            background: linear-gradient(135deg, #1D4ED8 0%, #2563EB 60%, #3B82F6 100%);
            padding: 32px 32px 28px;
            position: relative;
            overflow: hidden;
        }
        .card-hero::after {
            content: '';
            position: absolute;
            bottom: -30px; right: -30px;
            width: 160px; height: 160px;
            border-radius: 50%;
            background: rgba(255,255,255,0.06);
        }
        .card-hero::before {
            content: '';
            position: absolute;
            top: -50px; left: -50px;
            width: 200px; height: 200px;
            border-radius: 50%;
            background: rgba(255,255,255,0.04);
        }

        .hero-logo {
            width: 52px; height: 52px;
            border-radius: 14px;
            background: rgba(255,255,255,0.18);
            border: 1.5px solid rgba(255,255,255,0.28);
            display: flex; align-items: center; justify-content: center;
            margin-bottom: 16px;
            backdrop-filter: blur(8px);
            position: relative; z-index: 1;
        }
        .hero-logo svg { display: block; }

        .hero-title {
            font-size: 22px; font-weight: 800;
            color: #ffffff;
            letter-spacing: -0.5px;
            line-height: 1.2;
            position: relative; z-index: 1;
        }
        .hero-title span {
            color: rgba(255,255,255,0.65);
            font-weight: 500;
            font-size: 13px;
            display: block;
            margin-top: 4px;
            letter-spacing: 0;
        }

        /* Dot grid decoration */
        .hero-dots {
            position: absolute;
            top: 16px; right: 20px;
            display: grid;
            grid-template-columns: repeat(5, 6px);
            gap: 5px;
            z-index: 1;
        }
        .hero-dots span {
            width: 6px; height: 6px;
            border-radius: 50%;
            background: rgba(255,255,255,0.2);
            display: block;
        }

        /* ─── CARD BODY ─── */
        .card-body {
            padding: 28px 32px 24px;
        }

        /* Error alert */
        .alert-error {
            display: flex; align-items: flex-start; gap: 10px;
            background: var(--red-l);
            border: 1.5px solid rgba(239,68,68,0.25);
            border-radius: var(--r3);
            padding: 10px 13px;
            margin-bottom: 20px;
            animation: shakeIn 0.4s cubic-bezier(0.36,0.07,0.19,0.97);
        }
        @keyframes shakeIn {
            0%, 100% { transform: translateX(0); }
            20%       { transform: translateX(-6px); }
            40%       { transform: translateX(6px); }
            60%       { transform: translateX(-4px); }
            80%       { transform: translateX(4px); }
        }
        .alert-error svg { flex-shrink: 0; color: var(--red); margin-top: 1px; }
        .alert-error p  { font-size: 12px; font-weight: 600; color: #B91C1C; line-height: 1.4; }

        /* Section label */
        .form-label {
            font-size: 11px; font-weight: 700;
            color: var(--text-3);
            text-transform: uppercase;
            letter-spacing: 0.07em;
            display: block;
            margin-bottom: 5px;
        }

        /* Input group */
        .input-group {
            position: relative;
            margin-bottom: 14px;
        }
        .input-icon {
            position: absolute;
            left: 12px; top: 50%;
            transform: translateY(-50%);
            color: var(--text-3);
            display: flex;
            pointer-events: none;
            transition: color 0.18s;
        }
        .input-group:focus-within .input-icon {
            color: var(--blue);
        }
        .input-group input {
            width: 100%;
            padding: 11px 12px 11px 38px;
            font-size: 13px; font-family: inherit;
            border: 1.5px solid var(--border);
            border-radius: var(--r3);
            background: var(--border-l);
            color: var(--navy);
            transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
            outline: none;
        }
        .input-group input:focus {
            border-color: var(--blue);
            background: white;
            box-shadow: 0 0 0 3px var(--blue-m);
        }
        .input-group input::placeholder {
            color: var(--text-3);
        }

        /* Password toggle */
        .pw-toggle {
            position: absolute;
            right: 11px; top: 50%;
            transform: translateY(-50%);
            background: none; border: none;
            cursor: pointer;
            color: var(--text-3);
            display: flex;
            padding: 3px;
            border-radius: 5px;
            transition: color 0.15s, background 0.15s;
        }
        .pw-toggle:hover {
            color: var(--blue);
            background: var(--blue-m);
        }
        .pw-toggle svg { display: block; }

        /* Submit button */
        .btn-login {
            width: 100%;
            padding: 12px;
            margin-top: 4px;
            border-radius: var(--r3);
            border: none;
            background: linear-gradient(135deg, var(--blue) 0%, var(--blue-d) 100%);
            color: white;
            font-family: inherit;
            font-size: 13.5px;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.2s;
            display: flex; align-items: center; justify-content: center; gap: 8px;
            box-shadow: 0 4px 14px rgba(37,99,235,0.35);
            position: relative;
            overflow: hidden;
        }
        .btn-login::before {
            content: '';
            position: absolute; inset: 0;
            background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 60%);
            pointer-events: none;
        }
        .btn-login:hover {
            transform: translateY(-1px);
            box-shadow: 0 6px 20px rgba(37,99,235,0.45);
        }
        .btn-login:active {
            transform: translateY(0) scale(0.98);
        }
        .btn-login svg { display: block; flex-shrink: 0; }

        /* Divider */
        .divider {
            display: flex; align-items: center; gap: 10px;
            margin: 20px 0 16px;
        }
        .divider::before, .divider::after {
            content: ''; flex: 1; height: 1px; background: var(--border);
        }
        .divider span {
            font-size: 11px; font-weight: 600;
            color: var(--text-3);
            white-space: nowrap;
        }

        /* Info badges */
        .info-row {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 7px;
        }
        .info-badge {
            background: var(--border-l);
            border: 1px solid var(--border);
            border-radius: var(--r3);
            padding: 8px 10px;
            display: flex; align-items: center; gap: 7px;
        }
        .ib-icon {
            width: 26px; height: 26px;
            border-radius: 7px;
            display: flex; align-items: center; justify-content: center;
            flex-shrink: 0;
        }
        .ib-icon svg { display: block; }
        .ib-text { font-size: 10px; font-weight: 600; color: var(--text-2); line-height: 1.3; }
        .ib-text b { display: block; color: var(--navy); font-size: 11px; }

        /* Footer note */
        .card-footer {
            padding: 10px 32px 20px;
            border-top: 1px solid var(--border-l);
            text-align: center;
            background: var(--border-l);
        }
        .card-footer p {
            font-size: 11px; color: var(--text-3); font-weight: 500;
            display: flex; align-items: center; justify-content: center; gap: 5px;
        }
        .card-footer p svg { color: var(--blue); flex-shrink: 0; }
    </style>
</head>
<body>

<!-- Animated Background -->
<div class="bg-scene">
    <div class="bg-grid"></div>
    <div class="blob blob-1"></div>
    <div class="blob blob-2"></div>
    <div class="blob blob-3"></div>

    <!-- Floating particles -->
    <div class="particle" style="left:12%;animation-duration:9s;animation-delay:0s;width:5px;height:5px;"></div>
    <div class="particle" style="left:25%;animation-duration:13s;animation-delay:-3s;width:8px;height:8px;"></div>
    <div class="particle" style="left:38%;animation-duration:8s;animation-delay:-6s;width:4px;height:4px;"></div>
    <div class="particle" style="left:52%;animation-duration:11s;animation-delay:-1s;width:6px;height:6px;"></div>
    <div class="particle" style="left:67%;animation-duration:14s;animation-delay:-8s;width:5px;height:5px;"></div>
    <div class="particle" style="left:80%;animation-duration:10s;animation-delay:-4s;width:9px;height:9px;"></div>
    <div class="particle" style="left:91%;animation-duration:7s;animation-delay:-2s;width:4px;height:4px;"></div>
</div>

<div class="page">
    <div class="card">

        <!-- Hero Header -->
        <div class="card-hero">
            <div class="hero-dots">
                <?php for($i=0;$i<15;$i++) echo '<span></span>'; ?>
            </div>
            <div class="hero-logo">
                <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0118 0z"/>
                    <circle cx="12" cy="10" r="3"/>
                </svg>
            </div>
            <div class="hero-title">
                WebGIS Pemetaan Sosial
                <span>Platform Manajemen Data Kemiskinan &amp; Distribusi Bantuan</span>
            </div>
        </div>

        <!-- Form Body -->
        <div class="card-body">

            <?php if (!empty($_GET['error'])): ?>
            <div class="alert-error">
                <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                    <circle cx="12" cy="12" r="10"/>
                    <line x1="12" y1="8" x2="12" y2="12"/>
                    <line x1="12" y1="16" x2="12.01" y2="16"/>
                </svg>
                <p>
                    <?php
                    $err = htmlspecialchars($_GET['error']);
                    if ($err === 'invalid') echo 'Username atau password salah. Silakan coba lagi.';
                    elseif ($err === 'empty') echo 'Username dan password tidak boleh kosong.';
                    else echo $err;
                    ?>
                </p>
            </div>
            <?php endif; ?>

            <form action="auth_proses.php" method="POST" id="login-form" onsubmit="handleSubmit(this)">

                <!-- Username -->
                <label class="form-label" for="username">Username</label>
                <div class="input-group">
                    <span class="input-icon">
                        <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2"/>
                            <circle cx="12" cy="7" r="4"/>
                        </svg>
                    </span>
                    <input
                        type="text"
                        id="username"
                        name="username"
                        placeholder="Masukkan username"
                        autocomplete="username"
                        autofocus
                        required
                    >
                </div>

                <!-- Password -->
                <label class="form-label" for="password">Password</label>
                <div class="input-group" style="margin-bottom:20px">
                    <span class="input-icon">
                        <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
                            <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
                            <path d="M7 11V7a5 5 0 0110 0v4"/>
                        </svg>
                    </span>
                    <input
                        type="password"
                        id="password"
                        name="password"
                        placeholder="Masukkan password"
                        autocomplete="current-password"
                        required
                    >
                    <button type="button" class="pw-toggle" id="pw-toggle" onclick="togglePw()" title="Tampilkan password">
                        <svg id="eye-icon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
                            <circle cx="12" cy="12" r="3"/>
                        </svg>
                    </button>
                </div>

                <!-- Submit -->
                <button type="submit" class="btn-login" id="btn-submit">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M15 3h4a2 2 0 012 2v14a2 2 0 01-2 2h-4"/>
                        <polyline points="10 17 15 12 10 7"/>
                        <line x1="15" y1="12" x2="3" y2="12"/>
                    </svg>
                    <span id="btn-text">Masuk ke Sistem</span>
                </button>

            </form>

            <div class="divider"><span>Akses Tersedia</span></div>

            <!-- Role info -->
            <div class="info-row">
                <div class="info-badge">
                    <div class="ib-icon" style="background:#EFF6FF">
                        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#2563EB" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
                        </svg>
                    </div>
                    <div class="ib-text"><b>Admin</b>Kelola semua data</div>
                </div>
                <div class="info-badge">
                    <div class="ib-icon" style="background:#FFFBEB">
                        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#D97706" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <circle cx="12" cy="8" r="5"/>
                            <path d="M3 21h18a9 9 0 00-18 0z"/>
                        </svg>
                    </div>
                    <div class="ib-text"><b>Walikota</b>Pantau &amp; analisis</div>
                </div>
                <div class="info-badge">
                    <div class="ib-icon" style="background:#ECFDF5">
                        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#10B981" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/>
                            <circle cx="9" cy="7" r="4"/>
                            <path d="M23 21v-2a4 4 0 00-3-3.87"/>
                            <path d="M16 3.13a4 4 0 010 7.75"/>
                        </svg>
                    </div>
                    <div class="ib-text"><b>Warga</b>Laporan &amp; peta</div>
                </div>
                <div class="info-badge">
                    <div class="ib-icon" style="background:#F3E8FF">
                        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#9333EA" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M3 21h18"/>
                            <path d="M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"/>
                            <path d="M9 21v-4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v4"/>
                        </svg>
                    </div>
                    <div class="ib-text"><b>Pengurus Masjid</b>Kelola bantuan</div>
                </div>
            </div>
        </div>

        <!-- Footer -->
        <div class="card-footer">
            <p>
                <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                    <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
                    <path d="M7 11V7a5 5 0 0110 0v4"/>
                </svg>
                Sistem dilindungi enkripsi &mdash; WebGIS Pemetaan Sosial &copy; <?= date('Y') ?>
            </p>
        </div>

    </div>
</div>

<script>
    /* ─── Toggle Password Visibility ─── */
    function togglePw() {
        const inp = document.getElementById('password');
        const icon = document.getElementById('eye-icon');
        const isHidden = inp.type === 'password';
        inp.type = isHidden ? 'text' : 'password';
        icon.innerHTML = isHidden
            ? /* eye-off */`<path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/>`
            : /* eye */`<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/>`;
    }

    /* ─── Loading state on submit ─── */
    function handleSubmit(form) {
        const btn  = document.getElementById('btn-submit');
        const text = document.getElementById('btn-text');
        btn.disabled = true;
        btn.style.opacity = '0.8';
        text.textContent = 'Memproses...';

        // Spinner icon
        btn.querySelector('svg').innerHTML = `<circle cx="12" cy="12" r="9" stroke="rgba(255,255,255,.3)" stroke-width="2.5" fill="none"/><path d="M12 3a9 9 0 019 9" stroke="white" stroke-width="2.5" stroke-linecap="round" fill="none" style="transform-origin:center;animation:spin .8s linear infinite"/>`;

        // Re-enable if PHP redirects back (error)
        setTimeout(() => {
            btn.disabled = false;
            btn.style.opacity = '1';
            text.textContent = 'Masuk ke Sistem';
        }, 5000);
    }

    /* ─── Spin keyframe ─── */
    const style = document.createElement('style');
    style.textContent = '@keyframes spin { to { transform: rotate(360deg); } }';
    document.head.appendChild(style);

    /* ─── Enter key focus flow ─── */
    document.getElementById('username').addEventListener('keydown', e => {
        if (e.key === 'Enter') {
            e.preventDefault();
            document.getElementById('password').focus();
        }
    });
</script>

</body>
</html>