<?= $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;
        --danger: #ef4444;
        --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, .profile-edit-workspace {
        background-color: var(--bg-body) !important;
        color: var(--text-main) !important;
        transition: var(--transition);
    }

    .profile-card-container {
        max-width: 768px;
        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-text-modern {
        background-color: var(--bg-accent);
        border: 1px solid var(--border-color);
        color: var(--text-sub);
        border-radius: var(--radius-sm) 0 0 var(--radius-sm);
        padding: 0.65rem 0.9rem;
        font-size: 0.9rem;
        font-weight: 600;
    }

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

    .form-text-modern {
        font-size: 0.78rem;
        color: var(--text-sub);
        margin-top: 0.35rem;
    }

    /* Action Buttons */
    .btn-primary-modern {
        background-color: var(--primary);
        color: #ffffff;
        border: 1px solid var(--primary);
        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-primary-modern:hover {
        background-color: var(--primary-hover);
        border-color: var(--primary-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);
    }
</style>

<div class="container-fluid py-4 profile-edit-workspace">
    
    <div class="profile-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">Edit Profil</h3>
                <p class="text-sub small mb-0 mt-0.5">Perbarui informasi kredensial personal dan data kontak akun Anda.</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/update') ?>">
                
                <?= csrf_field() ?>

                <!-- USERNAME FIELD -->
                <div class="mb-4">
                    <label for="username" class="form-label-modern">
                        <i class="bi bi-person-badge text-primary"></i> Username
                    </label>
                    <div class="input-group input-group-modern">
                        <span class="input-group-text input-group-text-modern">@</span>
                        <input type="text" 
                               id="username" 
                               name="username" 
                               class="form-control form-control-modern font-monospace" 
                               value="<?= esc($user['username'] ?? '') ?>" 
                               placeholder="Masukkan username"
                               required>
                    </div>
                    <div class="form-text-modern">
                        Username unik yang digunakan untuk login dan identifikasi sistem.
                    </div>
                </div>

                <!-- NAMA LENGKAP FIELD -->
                <div class="mb-4">
                    <label for="nama_lengkap" class="form-label-modern">
                        <i class="bi bi-card-heading text-primary"></i> Nama Lengkap
                    </label>
                    <input type="text" 
                           id="nama_lengkap" 
                           name="nama_lengkap" 
                           class="form-control form-control-modern" 
                           value="<?= esc($user['nama_lengkap'] ?? '') ?>" 
                           placeholder="Masukkan nama lengkap"
                           required>
                    <div class="form-text-modern">
                        Nama lengkap sesuai dengan identitas resmi Anda.
                    </div>
                </div>

                <!-- EMAIL FIELD -->
                <div class="mb-4">
                    <label for="email" class="form-label-modern">
                        <i class="bi bi-envelope text-primary"></i> Alamat Email
                    </label>
                    <input type="email" 
                           id="email" 
                           name="email" 
                           class="form-control form-control-modern" 
                           value="<?= esc($user['email'] ?? '') ?>" 
                           placeholder="nama@domain.com"
                           required>
                    <div class="form-text-modern">
                        Email aktif untuk notifikasi sistem dan pemulihan akun.
                    </div>
                </div>

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

            </form>
        </div>

    </div>

</div>

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