<?php $__env->startPush('styles'); ?>
    <style>
        /* ── MANAGEMENT PAGE ── */

        /* Role tabs */
        .mgmt-tabs {
            display: flex; gap: 4px; margin-bottom: 20px;
            background: var(--gray-100); border-radius: 12px; padding: 4px;
            width: fit-content;
        }
        .mgmt-tab {
            padding: 7px 20px; font-size: 13px; font-weight: 600;
            border: none; background: none; border-radius: 9px;
            cursor: pointer; color: var(--gray-500); font-family: 'Sora', sans-serif;
            transition: all 0.15s; white-space: nowrap;
            display: flex; align-items: center; gap: 7px;
        }
        .mgmt-tab.active {
            background: var(--white); color: var(--gray-900);
            box-shadow: 0 1px 4px rgba(0,0,0,0.08);
        }
        .mgmt-tab-dot {
            width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
        }
        .dot-fa   { background: #185FA5; }
        .dot-agro { background: #3B6D11; }
        .dot-mm   { background: #854F0B; }

        /* Role view */
        .mgmt-view { display: none; }
        .mgmt-view.active { display: block; }

        /* Info banner - reset info */
        .mgmt-info-banner {
            background: #FFF8F0; border: 1px solid #FAC775;
            border-radius: 12px; padding: 12px 18px;
            display: flex; align-items: center; gap: 10px;
            margin-bottom: 16px; font-size: 13px; color: #854F0B;
            font-family: 'DM Sans', sans-serif;
        }
        .mgmt-info-banner.success {
            background: #EAF3DE; border-color: #C0DD97; color: #3B6D11;
        }
        .mgmt-info-banner.error {
            background: var(--red-pale); border-color: var(--red-light); color: var(--red-800);
        }
        .mgmt-info-banner svg { flex-shrink: 0; }

        /* Stats row */
        .mgmt-stats-row {
            display: grid; grid-template-columns: repeat(3, 1fr);
            gap: 12px; margin-bottom: 16px;
        }
        @media (max-width: 700px) { .mgmt-stats-row { grid-template-columns: 1fr; } }
        .mgmt-stat-card {
            background: var(--white); border-radius: 14px;
            border: 1px solid var(--gray-200); padding: 16px 20px;
        }
        .mgmt-stat-label {
            font-size: 11px; font-weight: 600; color: var(--gray-500);
            font-family: 'Sora', sans-serif; text-transform: uppercase;
            letter-spacing: 0.05em; margin-bottom: 8px;
        }
        .mgmt-stat-val {
            font-size: 28px; font-weight: 700; color: var(--gray-900);
            font-family: 'Sora', sans-serif; line-height: 1; margin-bottom: 4px;
        }
        .mgmt-stat-sub { font-size: 11px; color: var(--gray-400); font-family: 'DM Sans', sans-serif; }

        /* Card */
        .mgmt-card {
            background: var(--white); border-radius: 14px;
            border: 1px solid var(--gray-200); overflow: hidden;
            margin-bottom: 16px;
        }
        .mgmt-card-header {
            padding: 16px 22px;
            display: flex; align-items: center; justify-content: space-between;
            border-bottom: 1px solid var(--gray-200);
            flex-wrap: wrap; gap: 10px;
        }
        .mgmt-card-header-left { display: flex; align-items: center; gap: 10px; }
        .mgmt-card-title {
            font-family: 'Sora', sans-serif;
            font-size: 15px; font-weight: 600; color: var(--gray-900);
        }
        .mgmt-badge-count {
            font-size: 11px; font-weight: 600; padding: 3px 9px;
            background: var(--red-pale); color: var(--red-800);
            border-radius: 20px; border: 1px solid var(--red-light);
        }

        /* Filter Form */
        .mgmt-filter-form {
            padding: 20px 22px;
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 16px;
        }
        .mgmt-filter-field {
            display: flex; flex-direction: column; gap: 6px;
        }
        .mgmt-filter-label {
            font-size: 12px; font-weight: 500; color: var(--gray-600);
            font-family: 'Sora', sans-serif;
        }
        .mgmt-filter-input, .mgmt-filter-select {
            padding: 9px 12px; font-size: 13px;
            border: 1.5px solid var(--gray-200);
            border-radius: 10px; background: var(--white);
            color: var(--gray-900); outline: none;
            transition: border-color 0.15s;
            font-family: 'DM Sans', sans-serif; width: 100%;
        }
        .mgmt-filter-input:focus, .mgmt-filter-select:focus { border-color: var(--red-main); }
        .mgmt-filter-actions {
            grid-column: 1 / -1;
            display: flex; gap: 10px; justify-content: flex-end; padding-top: 10px;
        }
        .btn-mgmt-apply {
            padding: 9px 20px; font-size: 13px; font-weight: 600;
            background: var(--red-main); color: white; border: none;
            border-radius: 10px; cursor: pointer;
            font-family: 'Sora', sans-serif; transition: background 0.15s;
        }
        .btn-mgmt-apply:hover { background: var(--red-800); }
        .btn-mgmt-reset {
            padding: 9px 20px; font-size: 13px; font-weight: 600;
            background: var(--gray-100); color: var(--gray-700); border: none;
            border-radius: 10px; cursor: pointer;
            font-family: 'Sora', sans-serif; transition: background 0.15s;
        }
        .btn-mgmt-reset:hover { background: var(--gray-200); }


        /* Input Form (FA / Agronomi submit visit) */
        .mgmt-input-form {
            padding: 20px 22px;
            display: flex; flex-direction: column; gap: 16px;
            border-bottom: 1px solid var(--gray-200);
        }
        .mgmt-form-row { display: flex; gap: 12px; flex-wrap: wrap; }
        .mgmt-form-field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 160px; min-width: 140px; }
        .mgmt-form-label {
            font-size: 12px; font-weight: 500; color: var(--gray-600);
            font-family: 'Sora', sans-serif;
        }
        .mgmt-form-label .required { color: var(--red-main); }
        .mgmt-form-input {
            padding: 9px 12px; font-size: 13px;
            border: 1.5px solid var(--gray-200);
            border-radius: 10px; background: var(--gray-50);
            color: var(--gray-900); outline: none;
            transition: border-color 0.15s;
            font-family: 'DM Sans', sans-serif; width: 100%;
        }
        .mgmt-form-input:focus { border-color: var(--red-main); background: var(--white); }
        .mgmt-form-input:disabled {
            background: var(--gray-100); color: var(--gray-400); cursor: not-allowed;
        }
        .mgmt-form-footer {
            padding: 14px 22px; display: flex; align-items: center;
            justify-content: space-between; gap: 10px; flex-wrap: wrap;
        }
        .mgmt-locked-note {
            font-size: 12px; color: var(--gray-400); font-family: 'DM Sans', sans-serif;
            display: flex; align-items: center; gap: 6px;
        }
        .btn-mgmt-submit {
            padding: 9px 22px; font-size: 13px; font-weight: 600;
            background: var(--red-main); color: white; border: none;
            border-radius: 10px; cursor: pointer;
            font-family: 'Sora', sans-serif; transition: background 0.15s;
            box-shadow: 0 3px 10px rgba(163,45,45,0.22);
        }
        .btn-mgmt-submit:hover { background: var(--red-800); }
        .btn-mgmt-submit:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

        /* Table */
        .mgmt-table-scroll { overflow-x: auto; position: relative;}
        .mgmt-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 700px; }
        .mgmt-table thead th {
            padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 600;
            color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.05em;
            background: var(--gray-50); border-bottom: 1px solid var(--gray-200);
            white-space: nowrap; font-family: 'Sora', sans-serif;
        }
        .mgmt-table tbody tr {
            border-bottom: 1px solid var(--gray-100); transition: background 0.12s;
        }
        .mgmt-table tbody tr:last-child { border-bottom: none; }
        .mgmt-table tbody tr:hover { background: var(--gray-50); }
        .mgmt-table tbody td { padding: 12px 16px; vertical-align: middle; }
        .td-no-m { color: var(--gray-400); font-size: 12px; }

        /* Status badges */
        .status-badge {
            display: inline-block; font-size: 11px; font-weight: 600;
            padding: 3px 10px; border-radius: 20px; font-family: 'Sora', sans-serif;
        }
        .s-waiting  { background: #FAEEDA; color: #854F0B; border: 1px solid #FAC775; }
        .s-approved { background: #EAF3DE; color: #3B6D11; border: 1px solid #C0DD97; }
        .s-rejected { background: var(--red-pale); color: var(--red-800); border: 1px solid var(--red-light); }
        .s-draft    { background: var(--gray-100); color: var(--gray-600); border: 1px solid var(--gray-200); }

        /* Action buttons */
        .action-btn-m {
            background: none; border: 1px solid var(--gray-200);
            border-radius: 8px; padding: 4px 10px;
            cursor: pointer; color: var(--gray-600); font-size: 11px; font-weight: 500;
            transition: all 0.12s; margin-right: 4px; font-family: 'DM Sans', sans-serif;
            text-decoration: none; /* Added for link styling */
        }
        .action-btn-m:hover { background: var(--gray-100); color: var(--gray-900); }
        .action-approve { color: #3B6D11; border-color: #C0DD97; }
        .action-approve:hover { background: #EAF3DE; }
        .action-reject  { color: var(--red-main); border-color: var(--red-light); }
        .action-reject:hover { background: var(--red-pale); color: var(--red-800); }
        .action-btn-m:disabled { opacity: 0.35; cursor: not-allowed; }

        /* Empty */
        .mgmt-empty {
            padding: 40px 20px; text-align: center;
            color: var(--gray-400); font-size: 13px;
        }

        /* Pagination */
        .mgmt-table-footer {
            padding: 14px 22px;
            display: flex; align-items: center; justify-content: space-between;
            border-top: 1px solid var(--gray-200);
            flex-wrap: wrap; gap: 10px;
        }
        .pag-info-m { font-size: 12px; color: var(--gray-400); }
        .pag-btns-m { display: flex; align-items: center; gap: 4px; }
        .pag-btn-m {
            min-width: 32px; height: 32px;
            display: flex; align-items: center; justify-content: center;
            border: 1.5px solid var(--gray-200); border-radius: 8px;
            background: var(--white); color: var(--gray-900);
            font-size: 12px; font-weight: 600;
            cursor: pointer; transition: all 0.12s; padding: 0 8px;
            font-family: 'Sora', sans-serif;
        }
        .pag-btn-m:hover:not(:disabled) { background: var(--gray-100); }
        .pag-btn-m.active { background: var(--red-main); color: white; border-color: var(--red-main); }
        .pag-btn-m:disabled { opacity: 0.3; cursor: not-allowed; }

        /* Confirm modal */
        .confirm-backdrop {
            display: none; position: fixed; inset: 0;
            background: rgba(0,0,0,0.42); z-index: 600;
            align-items: center; justify-content: center;
        }
        .confirm-backdrop.open { display: flex; }
        .confirm-box {
            background: var(--white); border-radius: 14px;
            border: 1px solid var(--gray-200);
            padding: 24px 24px 20px;
            width: 100%; max-width: 380px; margin: 20px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.18);
        }
        .confirm-title {
            font-family: 'Sora', sans-serif;
            font-size: 15px; font-weight: 600; margin-bottom: 8px; color: var(--gray-900);
        }
        .confirm-text { font-size: 13px; color: var(--gray-600); margin-bottom: 8px; line-height: 1.5; }
        .confirm-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
        .btn-modal-cancel {
            padding: 9px 18px; font-size: 13px; font-weight: 500;
            background: var(--white); color: var(--gray-600);
            border: 1.5px solid var(--gray-200);
            border-radius: 10px; cursor: pointer;
            font-family: 'DM Sans', sans-serif; transition: all 0.15s;
        }
        .btn-modal-cancel:hover { background: var(--gray-100); }
        .btn-modal-save {
            padding: 9px 22px; font-size: 13px; font-weight: 600;
            background: var(--red-main); color: white; border: none;
            border-radius: 10px; cursor: pointer;
            font-family: 'Sora', sans-serif; transition: background 0.15s;
            box-shadow: 0 3px 10px rgba(163,45,45,0.22);
        }
        .btn-modal-save:hover { background: var(--red-800); }
        .btn-modal-approve {
            padding: 9px 22px; font-size: 13px; font-weight: 600;
            background: #2d6a4f; color: white; border: none;
            border-radius: 10px; cursor: pointer;
            font-family: 'Sora', sans-serif; transition: background 0.15s;
        }
        .btn-modal-approve:hover { background: #1b4332; }

        /* Reject reason textarea */
        .reject-textarea {
            width: 100%; padding: 9px 12px; font-size: 13px;
            border: 1.5px solid var(--gray-200); border-radius: 10px;
            background: var(--gray-50); color: var(--gray-900);
            outline: none; resize: vertical; min-height: 80px;
            transition: border-color 0.15s; font-family: 'DM Sans', sans-serif;
            margin-top: 10px;
        }
        .reject-textarea:focus { border-color: var(--red-main); }

        /* Toast */
        .toast {
            position: fixed; bottom: 24px; right: 24px;
            background: var(--gray-900); color: white;
            padding: 10px 18px; border-radius: 10px;
            font-size: 13px; font-weight: 500;
            z-index: 999; opacity: 0;
            transition: opacity 0.25s, transform 0.25s;
            transform: translateY(10px); pointer-events: none;
        }
        .toast.show { opacity: 1; transform: translateY(0); }
        .toast.success { background: #2d6a4f; }
        .toast.error   { background: var(--red-800); }

        /* Loading Overlay */
        .table-loading-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(2px);
            z-index: 10;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .loading-content {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 12px;
            color: var(--gray-600);
            font-size: 14px;
            text-align: center;
        }
        .loading-spinner {
            width: 32px;
            height: 32px;
            border: 3px solid var(--gray-200);
            border-top: 3px solid var(--red-main);
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
    </style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <div class="page-view active">
        <div class="mgmt-view active" id="view-fa">

            <?php if(session('success')): ?>
                <div class="mgmt-info-banner success">
                    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M8 14A6 6 0 1 0 8 2a6 6 0 0 0 0 12z"/><path d="m6.5 8.5 1 1 3-3"/></svg>
                    <?php echo e(session('success')); ?>

                </div>
            <?php endif; ?>
            <?php if(session('error')): ?>
                <div class="mgmt-info-banner error">
                    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="8" cy="8" r="6"/><path d="M8 7v4M8 5.5v.5"/></svg>
                    <?php echo e(session('error')); ?>

                </div>
            <?php endif; ?>
            <?php if($errors->any()): ?>
                <div class="mgmt-info-banner error">
                    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="8" cy="8" r="6"/><path d="M8 7v4M8 5.5v.5"/></svg>
                    Terdapat kesalahan pada input:
                    <ul style="list-style-type: disc; margin-left: 20px;">
                        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <li><?php echo e($error); ?></li>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </ul>
                </div>
            <?php endif; ?>

            <div class="mgmt-info-banner">
                <svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="8" cy="8" r="6"/><path d="M8 7v4M8 5.5v.5"/></svg>
                <?php echo e($submission_message); ?>

            </div>

            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->any(['isFA', 'isAgronomist'])): ?>
            <!-- Input Card -->
            <form action="<?php echo e(route('management-single.store')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="mgmt-card">
                    <div class="mgmt-card-header">
                        <div class="mgmt-card-header-left">
                            <span class="mgmt-card-title">Input Jumlah Visit Minggu Ini</span>
                        </div>
                    </div>
                    <div class="mgmt-input-form" id="fa-form">
                        <div class="mgmt-form-row">
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('isFA')): ?>
                            <div class="mgmt-form-field">
                                <div class="mgmt-form-label">Jumlah Visit ke Retailer <span class="required">*</span></div>
                                <input class="mgmt-form-input" type="number" min="0" id="fa-inp-retailer" name="visit_retailer" placeholder="0" <?php echo e(!$can_submit ? 'disabled' : ''); ?> />
                            </div>
                            <div class="mgmt-form-field">
                                <div class="mgmt-form-label">Jumlah Visit ke Farmer <span class="required">*</span></div>
                                <input class="mgmt-form-input" type="number" min="0" id="fa-inp-farmer" name="visit_farmer" placeholder="0" <?php echo e(!$can_submit ? 'disabled' : ''); ?> />
                            </div>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('isAgronomist')): ?>
                            <div class="mgmt-form-field">
                                <div class="mgmt-form-label">Jumlah Visit ke Dealer <span class="required">*</span></div>
                                <input class="mgmt-form-input" type="number" min="0" id="agro-inp-dealer" name="visit_dealer" placeholder="0" <?php echo e(!$can_submit ? 'disabled' : ''); ?> />
                            </div>
                            <div class="mgmt-form-field">
                                <div class="mgmt-form-label">Jumlah Visit ke Retailer <span class="required">*</span></div>
                                <input class="mgmt-form-input" type="number" min="0" id="agro-inp-retailer" name="visit_retailer" placeholder="0" <?php echo e(!$can_submit ? 'disabled' : ''); ?> />
                            </div>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="mgmt-form-footer">
                        <?php if(!$can_submit): ?>
                        <div class="mgmt-locked-note">
                            <svg width="13" height="13" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8"><rect x="4" y="7" width="8" height="6" rx="1"/><path d="M6 7V5a2 2 0 0 1 4 0v2"/></svg>
                            Data terkunci hingga hari Sabtu.
                        </div>
                        <?php endif; ?>
                        <div></div>
                        <button type="submit" class="btn-mgmt-submit" id="fa-submit-btn" <?php echo e(!$can_submit ? 'disabled' : ''); ?>>
                            Submit untuk Approval
                        </button>
                    </div>
                </div>
            </form>
            <?php endif; ?>


            <!-- Filters -->
            <div class="mgmt-card">
                <div class="mgmt-card-header">
                    <span class="mgmt-card-title">Filter Data</span>
                </div>
                <div class="mgmt-filter-form">
                    <div class="mgmt-filter-field">
                        <label class="mgmt-filter-label">Date Range</label>
                        <input type="text" class="mgmt-filter-input" id="date-range" />
                    </div>
                    <div class="mgmt-filter-field">
                        <label class="mgmt-filter-label">Status</label>
                        <select class="mgmt-filter-select" id="status-filter">
                            <option value="">Semua Status</option>
                            <option value="Waiting for Approval">Waiting for Approval</option>
                            <option value="Approved">Approved</option>
                            <option value="Rejected">Rejected</option>
                        </select>
                    </div>
                    <div class="mgmt-filter-field">
                        <label class="mgmt-filter-label">Sort</label>
                        <select class="mgmt-filter-select" id="sort-dir">
                            <option value="desc">Terbaru</option>
                            <option value="asc">Terlama</option>
                        </select>
                    </div>
                    <div class="mgmt-filter-actions">
                        <button class="btn-mgmt-apply" onclick="applyMgmtFilter()">Apply</button>
                        <button class="btn-mgmt-reset" onclick="resetMgmtFilter()">Reset</button>
                    </div>
                </div>
            </div>

            <!-- History -->
            <div class="mgmt-card">
                <div class="mgmt-card-header">
                    <div class="mgmt-card-header-left">
                        <span class="mgmt-card-title">Riwayat Pengajuan</span>
                        <span class="mgmt-badge-count" id="fa-hist-count">0 data</span>
                    </div>
                </div>
                <div class="mgmt-table-scroll">
                    <div id="table-loading" class="table-loading-overlay" style="display: none;">
                        <div class="loading-content">
                            <div class="loading-spinner"></div>
                            <span>Memuat data...</span>
                        </div>
                    </div>
                    <table id="faHistTable" class="mgmt-table">
                        <thead><tr>
                            <th style="width:44px">No.</th>
                            <th>Nama</th>
                            <th>Role</th>
                            <th>Total Visit</th>
                            <th>Visit Retailer</th>
                            <th>Visit Petani</th>
                            <th>Visit Dealer</th>
                            <th>Status</th>
                            <th>Tgl. Submit</th>
                            <th>Action</th> 
                        </tr></thead>
                        <tbody></tbody>
                    </table>
                </div>
                <div id="fa-hist-empty" class="mgmt-empty" style="display:none">Belum ada riwayat pengajuan.</div>
                <div class="mgmt-table-footer">
                    <div class="pag-info-m" id="faPagInfo"></div>
                    <div class="pag-btns-m" id="faPagBtns"></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Toast -->
    <div class="toast" id="toast-mgmt"></div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>
        /* ── HELPERS ── */
        function statusBadgeM(s) {
            const cls = s === 'Waiting for Approval' ? 's-waiting'
                : s === 'Approved' ? 's-approved'
                    : s === 'Rejected' ? 's-rejected' : 's-draft';
            return `<span class="status-badge ${cls}">${s}</span>`;
        }

        // Helper functions for loading indicator
        function showTableLoading() {
            document.getElementById('table-loading').style.display = 'flex';
        }

        function hideTableLoading() {
            document.getElementById('table-loading').style.display = 'none';
        }
    </script>
    <script>
        window.Laravel = {
            userRole: '<?php echo e(auth()->user()->role->type_role->value); ?>',
            routes: {
                query: '<?php echo e(route("management-single.query")); ?>',
                store: '<?php echo e(route("management-single.store")); ?>',
                detail: '<?php echo e(route("management.detail", ["id" => ":id"])); ?>', // Added detail route
            }
        };
    </script>
    <?php echo app('Illuminate\Foundation\Vite')(['resources/js/management-single.js']); ?>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH E:\PhpStormProject\sumans_laravel\resources\views/management/management-single.blade.php ENDPATH**/ ?>