<?= $this->extend('layouts/app') ?>

<?= $this->section('content') ?>

<style>
    /* ===== MODERN SAAS DESIGN SYSTEM TOKENS ===== */
    :root {
        --bg-body: #f8fafc;
        --bg-card: #ffffff;
        --bg-accent: #f1f5f9;
        --bg-input: #ffffff;
        --border-color: #e2e8f0;
        --border-hover: #cbd5e1;
        --text-main: #0f172a;
        --text-sub: #64748b;
        --primary: #4f46e5;
        --primary-hover: #4338ca;
        --primary-light: rgba(79, 70, 229, 0.08);
        --success: #10b981;
        --success-hover: #059669;
        --danger: #ef4444;
        --danger-hover: #dc2626;
        --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
        --radius-lg: 16px;
        --radius-md: 12px;
        --radius-sm: 8px;
        --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }

    @media (prefers-color-scheme: dark) {
        :root {
            --bg-body: #0b0f19;
            --bg-card: #151e2e;
            --bg-accent: #1e293b;
            --bg-input: #0f172a;
            --border-color: #243044;
            --border-hover: #334155;
            --text-main: #f8fafc;
            --text-sub: #94a3b8;
            --primary-light: rgba(79, 70, 229, 0.18);
            --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
            --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
        }
    }

    [data-bs-theme="dark"] {
        --bg-body: #0b0f19;
        --bg-card: #151e2e;
        --bg-accent: #1e293b;
        --bg-input: #0f172a;
        --border-color: #243044;
        --border-hover: #334155;
        --text-main: #f8fafc;
        --text-sub: #94a3b8;
        --primary-light: rgba(79, 70, 229, 0.18);
        --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    }

    body, .content-wrapper, .main-content, .content, .page-content, main, .password-workspace {
        background-color: var(--bg-body) !important;
        color: var(--text-main) !important;
        transition: var(--transition);
    }

    .password-card-container {
        max-width: 680px;
        margin: 0 auto;
    }

    /* Card Premium Styling */
    .card-modern {
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
        padding: 2rem;
        box-shadow: var(--shadow-sm);
        transition: var(--transition);
    }

    /* Form Controls */
    .form-label-modern {
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text-main);
        margin-bottom: 0.5rem;
        display: flex;
        align-items: center;
        gap: 0.35rem;
    }

    .form-control-modern {
        background-color: var(--bg-input);
        border: 1px solid var(--border-color);
        color: var(--text-main);
        border-radius: var(--radius-sm);
        padding: 0.65rem 0.9rem;
        font-size: 0.9rem;
        transition: var(--transition);
    }

    .form-control-modern:focus {
        background-color: var(--bg-input);
        color: var(--text-main);
        border-color: var(--primary);
        box-shadow: 0 0 0 3px var(--primary-light);
        outline: none;
    }

    /* Input Group & Password Toggle Button */
    .input-group-modern {
        position: relative;
    }

    .input-group-modern .form-control-modern {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
    }

    .btn-password-toggle {
        background-color: var(--bg-accent);
        border: 1px solid var(--border-color);
        border-left: none;
        color: var(--text-sub);
        border-top-right-radius: var(--radius-sm);
        border-bottom-right-radius: var(--radius-sm);
        padding: 0.65rem 0.9rem;
        transition: var(--transition);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .btn-password-toggle:hover {
        color: var(--text-main);
        background-color: var(--border-color);
    }

    /* Action Buttons */
    .btn-success-modern {
        background-color: var(--success);
        color: #ffffff;
        border: 1px solid var(--success);
        border-radius: var(--radius-sm);
        padding: 0.6rem 1.4rem;
        font-weight: 600;
        font-size: 0.875rem;
        transition: var(--transition);
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
    }

    .btn-success-modern:hover {
        background-color: var(--success-hover);
        border-color: var(--success-hover);
        color: #ffffff;
        box-shadow: var(--shadow-sm);
    }

    .btn-secondary-modern {
        background-color: transparent;
        color: var(--text-sub);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        padding: 0.6rem 1.4rem;
        font-weight: 600;
        font-size: 0.875rem;
        transition: var(--transition);
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
    }

    .btn-secondary-modern:hover {
        background-color: var(--bg-accent);
        color: var(--text-main);
        border-color: var(--border-hover);
    }

    /* Guideline Card */
    .security-hint-box {
        background-color: var(--bg-accent);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        padding: 1rem 1.25rem;
    }
</style>

<div class="container-fluid py-4 password-workspace">
    
    <div class="password-card-container">
        
        <!-- PAGE HEADER -->
        <div class="d-flex flex-column flex-sm-row justify-content-between align-items-sm-center mb-4 gap-3">
            <div>
                <h3 class="fw-bold mb-0 text-main">Ganti Password</h3>
                <p class="text-sub small mb-0 mt-0.5">Perbarui kata sandi Anda secara berkala untuk menjaga keamanan akun.</p>
            </div>
            <div>
                <a href="<?= base_url('superadmin/profile') ?>" class="btn btn-secondary-modern fs-7">
                    <i class="bi bi-arrow-left"></i> Kembali ke Profil
                </a>
            </div>
        </div>

        <!-- FLASH ERROR / VALIDATION ALERT -->
        <?php if (session()->getFlashdata('error')) : ?>
            <div class="alert alert-danger alert-dismissible fade show rounded-3 shadow-sm border-0 mb-4" role="alert">
                <div class="d-flex align-items-center gap-2">
                    <i class="bi bi-exclamation-triangle-fill fs-5 text-danger"></i>
                    <div><?= session()->getFlashdata('error') ?></div>
                </div>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        <?php endif; ?>

        <?php if (session()->getFlashdata('errors')) : ?>
            <div class="alert alert-danger alert-dismissible fade show rounded-3 shadow-sm border-0 mb-4" role="alert">
                <div class="d-flex align-items-start gap-2">
                    <i class="bi bi-exclamation-triangle-fill fs-5 text-danger mt-0.5"></i>
                    <div>
                        <strong class="d-block mb-1">Terjadi kesalahan validasi:</strong>
                        <ul class="mb-0 ps-3 small">
                            <?php foreach (session()->getFlashdata('errors') as $error) : ?>
                                <li><?= esc($error) ?></li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        <?php endif; ?>

        <!-- MAIN FORM CARD -->
        <div class="card-modern">
            
            <form method="post" action="<?= base_url('superadmin/profile/changePassword') ?>">
                
                <?= csrf_field() ?>

                <!-- PASSWORD LAMA -->
                <div class="mb-4">
                    <label for="old_password" class="form-label-modern">
                        <i class="bi bi-shield-lock text-primary"></i> Password Lama
                    </label>
                    <div class="input-group input-group-modern">
                        <input type="password" 
                               id="old_password" 
                               name="old_password" 
                               class="form-control form-control-modern" 
                               placeholder="Masukkan password saat ini" 
                               required>
                        <button type="button" 
                                class="btn btn-password-toggle" 
                                onclick="togglePasswordVisibility('old_password', this)"
                                title="Tampilkan/Sembunyikan Password">
                            <i class="bi bi-eye"></i>
                        </button>
                    </div>
                </div>

                <!-- PASSWORD BARU -->
                <div class="mb-4">
                    <label for="new_password" class="form-label-modern">
                        <i class="bi bi-key text-primary"></i> Password Baru
                    </label>
                    <div class="input-group input-group-modern">
                        <input type="password" 
                               id="new_password" 
                               name="new_password" 
                               class="form-control form-control-modern" 
                               placeholder="Masukkan password baru" 
                               required>
                        <button type="button" 
                                class="btn btn-password-toggle" 
                                onclick="togglePasswordVisibility('new_password', this)"
                                title="Tampilkan/Sembunyikan Password">
                            <i class="bi bi-eye"></i>
                        </button>
                    </div>
                </div>

                <!-- KONFIRMASI PASSWORD -->
                <div class="mb-4">
                    <label for="confirm_password" class="form-label-modern">
                        <i class="bi bi-check2-circle text-primary"></i> Konfirmasi Password Baru
                    </label>
                    <div class="input-group input-group-modern">
                        <input type="password" 
                               id="confirm_password" 
                               name="confirm_password" 
                               class="form-control form-control-modern" 
                               placeholder="Ulangi password baru" 
                               required>
                        <button type="button" 
                                class="btn btn-password-toggle" 
                                onclick="togglePasswordVisibility('confirm_password', this)"
                                title="Tampilkan/Sembunyikan Password">
                            <i class="bi bi-eye"></i>
                        </button>
                    </div>
                </div>

                <!-- SECURITY GUIDELINES BOX -->
                <div class="security-hint-box mb-4">
                    <div class="d-flex gap-2.5">
                        <i class="bi bi-info-circle text-primary fs-5 mt-0.5"></i>
                        <div>
                            <span class="fw-bold text-main fs-7 d-block mb-1">Anjuran Keamanan Kata Sandi:</span>
                            <ul class="text-sub small mb-0 ps-3">
                                <li>Gunakan minimal 8 karakter.</li>
                                <li>Kombinasikan huruf besar, huruf kecil, angka, dan simbol unik.</li>
                                <li>Hindari menggunakan kata sandi yang mudah ditebak atau pernah digunakan sebelumnya.</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- ACTION BUTTONS -->
                <div class="d-flex align-items-center justify-content-end gap-2 pt-3 border-top border-color">
                    <a href="<?= base_url('superadmin/profile') ?>" class="btn btn-secondary-modern">
                        Batal
                    </a>
                    <button type="submit" class="btn btn-success-modern shadow-sm">
                        <i class="bi bi-shield-check fs-6"></i> Ganti Password
                    </button>
                </div>

            </form>

        </div>

    </div>

</div>

<!-- SCRIPT SHOW/HIDE PASSWORD -->
<script>
    function togglePasswordVisibility(inputId, btn) {
        const input = document.getElementById(inputId);
        const icon = btn.querySelector('i');
        
        if (input.type === 'password') {
            input.type = 'text';
            icon.classList.replace('bi-eye', 'bi-eye-slash');
        } else {
            input.type = 'password';
            icon.classList.replace('bi-eye-slash', 'bi-eye');
        }
    }
</script>

<?= $this->endSection() ?>