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

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

<style>
    /* ===== ENTERPRISE 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);
    }

    /* DARK MODE COLOR VARIABLES */
    @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; /* Putih terang */
            --text-sub: #94a3b8;  /* Abu-abu terang */
            --primary-light: rgba(79, 70, 229, 0.2);
            --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; /* Putih terang */
        --text-sub: #94a3b8;  /* Abu-abu terang */
        --primary-light: rgba(79, 70, 229, 0.2);
        --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    }

    /* GLOBAL WORKSPACE OVERRIDES FOR DARK MODE TEXT */
    body, .content-wrapper, .main-content, .content, .page-content, main, .category-edit-workspace {
        background-color: var(--bg-body) !important;
        color: var(--text-main) !important;
        transition: var(--transition);
    }

    .text-main {
        color: var(--text-main) !important;
    }

    .text-sub {
        color: var(--text-sub) !important;
    }

    /* OVERRIDE BOOTSTRAP DARK TEXT IN DARK MODE */
    @media (prefers-color-scheme: dark) {
        .text-dark, .text-body, h1, h2, h3, h4, h5, h6, p, span, td, th, label, option {
            color: var(--text-main) !important;
        }
        .text-muted {
            color: var(--text-sub) !important;
        }
    }

    [data-bs-theme="dark"] .text-dark,
    [data-bs-theme="dark"] .text-body,
    [data-bs-theme="dark"] h1, [data-bs-theme="dark"] h2, [data-bs-theme="dark"] h3,
    [data-bs-theme="dark"] h4, [data-bs-theme="dark"] h5, [data-bs-theme="dark"] h6,
    [data-bs-theme="dark"] p, [data-bs-theme="dark"] span, [data-bs-theme="dark"] td,
    [data-bs-theme="dark"] th, [data-bs-theme="dark"] label, [data-bs-theme="dark"] option {
        color: var(--text-main) !important;
    }

    [data-bs-theme="dark"] .text-muted {
        color: var(--text-sub) !important;
    }

    /* Layout Card Container */
    .form-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 Labels & Controls */
    .form-label-modern {
        font-size: 0.875rem;
        font-weight: 600;
        color: var(--text-main);
        margin-bottom: 0.5rem;
        display: flex;
        align-items: center;
        gap: 0.4rem;
    }

    .input-group-modern {
        border-radius: var(--radius-sm);
        overflow: hidden;
    }

    .input-group-modern .input-group-text {
        background-color: var(--bg-accent) !important;
        border: 1px solid var(--border-color) !important;
        color: var(--text-sub) !important;
        padding-left: 0.9rem;
        padding-right: 0.9rem;
    }

    .form-control-modern {
        background-color: var(--bg-input) !important;
        border: 1px solid var(--border-color) !important;
        color: var(--text-main) !important;
        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) !important;
        color: var(--text-main) !important;
        border-color: var(--primary) !important;
        box-shadow: 0 0 0 3px var(--primary-light);
        outline: none;
    }

    /* Buttons Styling */
    .btn-primary-modern {
        background-color: var(--primary);
        color: #ffffff !important;
        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 !important;
        box-shadow: var(--shadow-sm);
    }

    .btn-secondary-modern {
        background-color: transparent;
        color: var(--text-sub) !important;
        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) !important;
        border-color: var(--border-hover);
    }

    .btn-outline-modern {
        background-color: transparent;
        color: var(--text-main) !important;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        padding: 0.5rem 1rem;
        transition: var(--transition);
    }

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

    /* Contextual Info Box */
    .info-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 category-edit-workspace">
    
    <div class="form-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 Kategori Barang</h3>
                <p class="text-sub small mb-0 mt-0.5">Perbarui nama dan data kategori dalam sistem inventaris.</p>
            </div>
            <div>
                <a href="<?= base_url('owner/category') ?>" class="btn btn-outline-modern fs-7 fw-semibold">
                    <i class="bi bi-arrow-left"></i> Kembali ke Daftar
                </a>
            </div>
        </div>

        <!-- ERROR VALIDATION ALERT -->
        <?php if (session('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 if (is_array(session('errors'))) : ?>
                                <?php foreach (session('errors') as $error) : ?>
                                    <li><?= esc($error) ?></li>
                                <?php endforeach; ?>
                            <?php else : ?>
                                <li><?= esc(session('errors')) ?></li>
                            <?php endif; ?>
                        </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('owner/category/update/'.$category['id_category']) ?>">
                
                <?= csrf_field() ?>

                <!-- FIELD NAMA KATEGORI -->
                <div class="mb-4">
                    <label for="nama_kategori" class="form-label-modern">
                        <i class="bi bi-tag-fill text-primary"></i> Nama Kategori <span class="text-danger">*</span>
                    </label>
                    <div class="input-group input-group-modern">
                        <span class="input-group-text">
                            <i class="bi bi-folder2-open"></i>
                        </span>
                        <input type="text"
                               id="nama_kategori"
                               name="nama_kategori"
                               value="<?= esc(old('nama_kategori', $category['nama_kategori'])) ?>"
                               class="form-control form-control-modern"
                               placeholder="Contoh: Elektronik & Gadget"
                               maxlength="100"
                               required
                               autofocus>
                    </div>
                    <div class="form-text text-sub small mt-1.5">
                        Gunakan nama kategori yang jelas dan mudah diidentifikasi (Maks. 100 karakter).
                    </div>
                </div>

                <!-- CONTEXTUAL GUIDELINE BOX -->
                <div class="info-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">Catatan Perubahan:</span>
                            <p class="text-sub small mb-0">
                                Memperbarui nama kategori akan otomatis mempengaruhi pengelompokan seluruh produk yang terhubung dengan kategori ini di dalam inventaris.
                            </p>
                        </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('owner/category') ?>" 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() ?>