

<?php $__env->startSection('title', 'Savings'); ?>
<?php $__env->startSection('page-title', 'Savings Products'); ?>
<?php $__env->startSection('page-subtitle', 'Regular, target, thrift / Isusu, and cooperative savings'); ?>

<?php $__env->startSection('content'); ?>
<?php
    $canManageSavings = auth()->user()->hasPermission('savings.manage');
    $canApproveSavings = auth()->user()->hasPermission('savings.approve');
    $currency = auth()->user()->tenant->settings['currency'] ?? 'NGN';
    $compactNumber = function ($amount) {
        $amount = (float) $amount;
        $absolute = abs($amount);
        $format = fn ($value, $suffix) => rtrim(rtrim(number_format($value, 1), '0'), '.').$suffix;

        if ($absolute >= 1000000000) {
            return $format($amount / 1000000000, 'b');
        }

        if ($absolute >= 1000000) {
            return $format($amount / 1000000, 'm');
        }

        if ($absolute >= 1000) {
            return $format($amount / 1000, 'k');
        }

        return number_format($amount, 2);
    };
    $money = fn ($amount) => $currency.' '.number_format((float) $amount, 2);
    $compactMoney = fn ($amount) => $currency.' '.$compactNumber($amount);
    $dueSavingsAccounts = (int) ($savingsStats['due_savings_accounts'] ?? 0);
    $savingsMetricCards = [
        ['Deposited today', $compactMoney($savingsStats['today_deposits'] ?? 0), 'Approved deposits today', 'bi-arrow-down-circle', 'teal'],
        ['Due savings', $compactMoney($savingsStats['due_savings_amount'] ?? 0), $compactNumber($dueSavingsAccounts).' '.str('account')->plural($dueSavingsAccounts).' due', 'bi-calendar2-week', 'amber'],
        ['Active accounts', $compactNumber($savingsStats['active_accounts'] ?? 0), 'Currently running plans', 'bi-check2-circle', 'green'],
        ['Savings balance', $compactMoney($savingsStats['balance'] ?? 0), 'Total balance held', 'bi-cash-stack', 'blue'],
    ];
    $activeSavingsFilters = filled($search) || filled($productId) || filled($typeFilter) || filled($statusFilter);
    $savingsStatusOptions = ['active' => 'Active', 'inactive' => 'Inactive', 'closed' => 'Closed'];
    $productPayload = $products->map(fn ($product) => [
        'id' => $product->id,
        'name' => $product->name,
        'type' => $product->type,
        'type_label' => $product->typeLabel(),
        'description' => $product->description,
        'account_number_prefix' => $product->account_number_prefix,
        'interest_rate' => $product->interest_rate,
        'minimum_opening_balance' => $product->minimum_opening_balance,
        'minimum_balance' => $product->minimum_balance,
        'processing_fee_type' => $product->processing_fee_type ?? 'fixed',
        'processing_fee_value' => $product->processing_fee_value ?? 0,
        'processing_fee_timing' => $product->processing_fee_timing ?? 'manual',
        'processing_fee_timing_label' => $product->processingFeeTimingLabel(),
        'contribution_frequency' => $product->contribution_frequency,
        'duration_days' => $product->duration_days,
        'withdrawal_policy' => $product->withdrawal_policy,
        'allow_member_create' => $product->allow_member_create ? '1' : '0',
        'show_on_member_portal' => $product->show_on_member_portal ? '1' : '0',
        'show_on_public_website' => $product->show_on_public_website ? '1' : '0',
        'is_active' => $product->is_active ? '1' : '0',
        'update_route' => route('tenant.savings-products.update', $product),
        'delete_route' => route('tenant.savings-products.destroy', $product),
    ])->values();
?>

<?php if($errors->any()): ?>
    <div class="alert alert-warning border-0"><?php echo e($errors->first()); ?></div>
<?php endif; ?>

<section class="finance-hero finance-hero-savings mb-4">
    <div class="finance-hero-copy">
        <span>Savings center</span>
        <h2>Build flexible savings products for every member group.</h2>
        <p>Open regular savings, target plans, thrift / Isusu, and cooperative accounts with clear rules, maturity dates, and contribution schedules.</p>
    </div>
    <div class="finance-metric-grid">
        <?php $__currentLoopData = $savingsMetricCards; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $value, $hint, $icon, $tone]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="finance-metric-card <?php echo e($tone); ?>">
                <i class="bi <?php echo e($icon); ?>"></i>
                <span><?php echo e($label); ?></span>
                <strong><?php echo e($value); ?></strong>
                <small><?php echo e($hint); ?></small>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
</section>

<div class="card border-0 shadow-sm savings-workspace finance-workspace">
    <div class="finance-tabbar">
        <ul class="nav nav-pills finance-tabs" role="tablist">
            <li class="nav-item" role="presentation"><button class="nav-link active" data-bs-toggle="tab" data-bs-target="#savings-accounts" type="button"><i class="bi bi-wallet2 me-1"></i> Accounts</button></li>
            <?php if($canApproveSavings): ?>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-toggle="tab" data-bs-target="#savings-pending-deposits" type="button">
                        <i class="bi bi-hourglass-split me-1"></i> Pending approvals
                        <?php if(($savingsStats['pending_deposits'] ?? 0) > 0): ?>
                            <span class="badge text-bg-warning ms-1"><?php echo e($compactNumber($savingsStats['pending_deposits'])); ?></span>
                        <?php endif; ?>
                    </button>
                </li>
            <?php endif; ?>
            <li class="nav-item" role="presentation">
                <button class="nav-link" data-bs-toggle="tab" data-bs-target="#savings-missed" type="button">
                    <i class="bi bi-calendar-x me-1"></i> Missed savings
                    <?php if(($savingsStats['missed_savings_accounts'] ?? 0) > 0): ?>
                        <span class="badge text-bg-danger ms-1"><?php echo e($compactNumber($savingsStats['missed_savings_accounts'])); ?></span>
                    <?php endif; ?>
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" data-bs-toggle="tab" data-bs-target="#savings-maturing-soon" type="button">
                    <i class="bi bi-calendar2-check me-1"></i> Maturing soon
                    <?php if(($savingsStats['maturing_soon'] ?? 0) > 0): ?>
                        <span class="badge text-bg-info ms-1"><?php echo e($compactNumber($savingsStats['maturing_soon'])); ?></span>
                    <?php endif; ?>
                </button>
            </li>
            <?php if($canManageSavings): ?>
                <li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#open-savings-account" type="button"><i class="bi bi-person-plus me-1"></i> Open account</button></li>
                <li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#savings-products" type="button"><i class="bi bi-sliders me-1"></i> Products</button></li>
            <?php endif; ?>
        </ul>
    </div>

    <div class="tab-content">
        <div class="tab-pane fade show active" id="savings-accounts">
            <div class="finance-pane-title">
                <div>
                    <span>Accounts</span>
                    <h3>Savings account register</h3>
                    <p>Track balances, product type, member ownership, and account progress.</p>
                </div>
                <?php if($canManageSavings): ?>
                    <button class="btn btn-primary btn-sm" type="button" data-bs-toggle="tab" data-bs-target="#open-savings-account"><i class="bi bi-plus-lg me-1"></i> Open account</button>
                <?php endif; ?>
            </div>
            <div class="p-3">
                <form method="GET" class="row g-2 align-items-end finance-filter-panel savings-account-filter" data-auto-savings-filter>
                    <div class="col-lg-4">
                        <label class="form-label">Search accounts</label>
                        <div class="input-group">
                            <span class="input-group-text"><i class="bi bi-search"></i></span>
                            <input name="q" value="<?php echo e($search); ?>" class="form-control" placeholder="Account no, member, phone..." data-savings-search autocomplete="off">
                        </div>
                    </div>
                    <div class="col-sm-6 col-lg-3">
                        <label class="form-label">Product</label>
                        <select name="product_id" class="form-select" data-savings-select>
                            <option value="">All products</option>
                            <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($product->id); ?>" <?php if((string) $productId === (string) $product->id): echo 'selected'; endif; ?>><?php echo e($product->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-sm-6 col-lg-2">
                        <label class="form-label">Type</label>
                        <select name="type" class="form-select" data-savings-select>
                            <option value="">All types</option>
                            <?php $__currentLoopData = $types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($value); ?>" <?php if($typeFilter === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-sm-6 col-lg-2">
                        <label class="form-label">Status</label>
                        <select name="status" class="form-select" data-savings-select>
                            <option value="">All statuses</option>
                            <?php $__currentLoopData = $savingsStatusOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($value); ?>" <?php if($statusFilter === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-sm-6 col-lg-1 d-grid">
                        <?php if($activeSavingsFilters): ?>
                            <a href="<?php echo e(route('tenant.savings.index')); ?>" class="btn btn-outline-secondary">Clear</a>
                        <?php else: ?>
                            <button class="btn btn-outline-primary" type="submit"><i class="bi bi-funnel"></i></button>
                        <?php endif; ?>
                    </div>
                </form>
            </div>
            <div class="table-responsive finance-table-shell">
                <table class="table mb-0 align-middle finance-table">
                    <thead>
                        <tr>
                            <th>Account</th>
                            <th>Member</th>
                            <th>Product</th>
                            <th>Status</th>
                            <th class="text-end">Balance</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><span class="finance-id-pill"><?php echo e($account->account_number); ?></span></td>
                                <td><div class="fw-semibold"><?php echo e($account->customer?->fullName()); ?></div><small class="text-muted"><?php echo e($account->customer?->account_number); ?></small></td>
                                <td><?php echo e($account->product_name); ?></td>
                                <td><span class="finance-soft-badge status-<?php echo e($account->status); ?>"><?php echo e(ucfirst(str_replace('_', ' ', $account->status))); ?></span></td>
                                <td class="text-end fw-semibold"><?php echo e($compactMoney($account->balance)); ?></td>
                                <td><a class="btn btn-sm btn-outline-primary" href="<?php echo e(route('tenant.savings.show', $account)); ?>">Open</a></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr><td colspan="6" class="text-center text-muted py-4">No savings accounts yet.</td></tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            <div class="card-body"><?php echo e($accounts->links()); ?></div>
        </div>

        <?php if($canApproveSavings): ?>
            <div class="tab-pane fade" id="savings-pending-deposits">
                <div class="finance-pane-title">
                    <div>
                        <span>Approvals</span>
                        <h3>Pending savings transactions</h3>
                        <p>Review deposit and withdrawal requests before they affect member savings balances.</p>
                    </div>
                    <div class="finance-pane-count">
                        <strong><?php echo e($compactNumber($savingsStats['pending_deposits'] ?? 0)); ?></strong>
                        <span>waiting</span>
                    </div>
                </div>

                <div class="p-3 p-lg-4">
                    <?php if($pendingSavingsDeposits->isNotEmpty()): ?>
                        <div class="pending-review-card">
                            <div class="pending-review-head">
                                <div>
                                    <span>Pending approvals</span>
                                    <strong><?php echo e($pendingSavingsDeposits->count()); ?> savings transaction<?php echo e($pendingSavingsDeposits->count() === 1 ? '' : 's'); ?> waiting</strong>
                                </div>
                            </div>
                            <form method="POST" id="bulkSavingsDepositForm">
                                <?php echo csrf_field(); ?>
                            </form>
                            <div class="bulk-approval-bar">
                                <div>
                                    <strong>Bulk action</strong>
                                    <span>Select multiple deposits or withdrawals, then approve or reject them together.</span>
                                </div>
                                <div class="bulk-approval-controls">
                                    <input name="rejected_reason" form="bulkSavingsDepositForm" class="form-control form-control-sm" placeholder="Reason for bulk rejection">
                                    <button class="btn btn-sm btn-success" type="submit" form="bulkSavingsDepositForm" formaction="<?php echo e(route('tenant.savings.transactions.bulk-approve')); ?>">
                                        <i class="bi bi-check2-circle me-1"></i> Approve selected
                                    </button>
                                    <button class="btn btn-sm btn-outline-danger" type="submit" form="bulkSavingsDepositForm" formaction="<?php echo e(route('tenant.savings.transactions.bulk-reject')); ?>">
                                        <i class="bi bi-x-circle me-1"></i> Reject selected
                                    </button>
                                </div>
                            </div>
                            <div class="table-responsive">
                                <table class="table mb-0 align-middle">
                                    <thead>
                                        <tr>
                                            <th style="width:44px;"><input class="form-check-input" type="checkbox" data-savings-deposit-select-all aria-label="Select all pending deposits"></th>
                                            <th>Member</th>
                                            <th>Account</th>
                                            <th>Type</th>
                                            <th>Initiated by</th>
                                            <th class="text-end">Amount</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__currentLoopData = $pendingSavingsDeposits; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                                <td><input class="form-check-input" type="checkbox" name="transaction_ids[]" value="<?php echo e($transaction->id); ?>" form="bulkSavingsDepositForm" data-savings-deposit-checkbox aria-label="Select <?php echo e($transaction->reference); ?>"></td>
                                                <td><?php echo e($transaction->customer?->fullName()); ?></td>
                                                <td><?php echo e($transaction->account?->account_number); ?></td>
                                                <td><span class="badge <?php echo e($transaction->type === 'withdrawal' ? 'text-bg-danger' : 'text-bg-success'); ?>"><?php echo e(ucfirst($transaction->type)); ?></span></td>
                                                <td><?php echo e($transaction->creator?->name ?? 'System / member'); ?></td>
                                                <td class="text-end fw-semibold"><?php echo e($money($transaction->amount)); ?></td>
                                                <td class="text-end">
                                                    <div class="dropdown">
                                                        <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Actions</button>
                                                        <ul class="dropdown-menu dropdown-menu-end">
                                                            <li><button class="dropdown-item" type="button" data-bs-toggle="modal" data-bs-target="#savingsPendingDeposit<?php echo e($transaction->id); ?>"><i class="bi bi-eye me-2"></i>View</button></li>
                                                            <li>
                                                                <form method="POST" action="<?php echo e(route('tenant.savings.transactions.approve', $transaction)); ?>">
                                                                    <?php echo csrf_field(); ?>
                                                                    <button class="dropdown-item text-success" type="submit"><i class="bi bi-check2-circle me-2"></i>Approve</button>
                                                                </form>
                                                            </li>
                                                            <li><button class="dropdown-item text-danger" type="button" data-bs-toggle="modal" data-bs-target="#savingsPendingDeposit<?php echo e($transaction->id); ?>"><i class="bi bi-x-circle me-2"></i>Reject</button></li>
                                                        </ul>
                                                    </div>
                                                </td>
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                            </div>
                            <?php $__currentLoopData = $pendingSavingsDeposits; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="modal fade" id="savingsPendingDeposit<?php echo e($transaction->id); ?>" tabindex="-1" aria-labelledby="savingsPendingDeposit<?php echo e($transaction->id); ?>Label" aria-hidden="true">
                                    <div class="modal-dialog modal-dialog-centered modal-lg">
                                        <div class="modal-content border-0 shadow">
                                            <div class="modal-header">
                                                <div>
                                                    <h2 class="modal-title h5" id="savingsPendingDeposit<?php echo e($transaction->id); ?>Label">Savings <?php echo e($transaction->type); ?> details</h2>
                                                    <div class="text-muted small"><?php echo e($transaction->reference); ?></div>
                                                </div>
                                                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                            </div>
                                            <div class="modal-body">
                                                <div class="row g-3">
                                                    <div class="col-md-4"><div class="detail-tile"><span>Member</span><strong><?php echo e($transaction->customer?->fullName()); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Member account</span><strong><?php echo e($transaction->customer?->account_number ?? '-'); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Savings account</span><strong><?php echo e($transaction->account?->account_number ?? '-'); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Amount</span><strong><?php echo e($money($transaction->amount)); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Method</span><strong><?php echo e(ucfirst($transaction->method)); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Type</span><strong><?php echo e(ucfirst($transaction->type)); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Status</span><strong><?php echo e(ucfirst($transaction->status ?? 'pending')); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Initiated by</span><strong><?php echo e($transaction->creator?->name ?? 'System / member'); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Approved by</span><strong><?php echo e($transaction->approver?->name ?? 'Not approved yet'); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Date</span><strong><?php echo e(app_datetime($transaction->transacted_at) ?? '-'); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Balance before</span><strong><?php echo e($money($transaction->balance_before)); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Balance after approval</span><strong><?php echo e($money($transaction->type === 'withdrawal' ? (float) $transaction->balance_before - (float) $transaction->amount : (float) $transaction->balance_before + (float) ($transaction->net_amount ?: $transaction->amount))); ?></strong></div></div>
                                                    <div class="col-md-4"><div class="detail-tile"><span>Reference</span><strong><?php echo e($transaction->reference); ?></strong></div></div>
                                                    <div class="col-12">
                                                        <div class="detail-tile">
                                                            <span>Narration</span>
                                                            <strong><?php echo e($transaction->description ?: 'No narration supplied.'); ?></strong>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Close</button>
                                                <form method="POST" action="<?php echo e(route('tenant.savings.transactions.approve', $transaction)); ?>">
                                                    <?php echo csrf_field(); ?>
                                                    <button class="btn btn-success btn-sm">Approve <?php echo e($transaction->type); ?></button>
                                                </form>
                                                <form method="POST" action="<?php echo e(route('tenant.savings.transactions.reject', $transaction)); ?>" class="pending-modal-reject">
                                                    <?php echo csrf_field(); ?>
                                                    <input name="rejected_reason" class="form-control form-control-sm" placeholder="Reason for rejection" required>
                                                    <button class="btn btn-outline-danger btn-sm">Reject</button>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    <?php else: ?>
                        <div class="pending-empty-state">
                            <i class="bi bi-check2-circle"></i>
                            <strong>No pending savings transactions</strong>
                            <span>Approved deposits and withdrawals will remain visible in each member savings account.</span>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        <?php endif; ?>

        <div class="tab-pane fade" id="savings-missed">
            <div class="finance-pane-title">
                <div>
                    <span>Missed contributions</span>
                    <h3>Missed savings</h3>
                    <p>Accounts with past contribution dates that have not been fully covered by posted deposits.</p>
                </div>
                <div class="finance-pane-count danger">
                    <strong><?php echo e($compactNumber($savingsStats['missed_savings_accounts'] ?? 0)); ?></strong>
                    <span><?php echo e($compactMoney($savingsStats['missed_savings_amount'] ?? 0)); ?></span>
                </div>
            </div>

            <div class="p-3 p-lg-4">
                <?php if($missedSavingsAccounts->isNotEmpty()): ?>
                    <div class="table-responsive finance-table-shell">
                        <table class="table mb-0 align-middle finance-table">
                            <thead>
                                <tr>
                                    <th>Account</th>
                                    <th>Member</th>
                                    <th>Oldest missed</th>
                                    <th>Missed periods</th>
                                    <th class="text-end">Missed amount</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $missedSavingsAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td>
                                            <span class="finance-id-pill"><?php echo e($account->account_number); ?></span>
                                            <div class="small text-muted mt-1"><?php echo e($account->product_name); ?></div>
                                        </td>
                                        <td>
                                            <div class="fw-semibold"><?php echo e($account->customer?->fullName()); ?></div>
                                            <small class="text-muted"><?php echo e($account->customer?->account_number); ?></small>
                                        </td>
                                        <td><?php echo e(app_date($account->oldest_missed_due_date) ?? '-'); ?></td>
                                        <td><span class="finance-soft-badge status-rejected"><?php echo e($compactNumber($account->missed_savings_periods)); ?></span></td>
                                        <td class="text-end fw-semibold text-danger"><?php echo e($compactMoney($account->missed_savings_amount)); ?></td>
                                        <td class="text-end">
                                            <button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="modal" data-bs-target="#missedSavings<?php echo e($account->id); ?>">
                                                View
                                            </button>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                    <?php $__currentLoopData = $missedSavingsAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $goal = (float) ($account->target_amount ?: $account->planned_total_amount ?: 0);
                            $remaining = $goal > 0 ? max(0, $goal - (float) $account->balance) : 0;
                        ?>
                        <div class="modal fade" id="missedSavings<?php echo e($account->id); ?>" tabindex="-1" aria-labelledby="missedSavings<?php echo e($account->id); ?>Label" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-centered modal-lg">
                                <div class="modal-content border-0 shadow">
                                    <div class="modal-header">
                                        <div>
                                            <h2 class="modal-title h5" id="missedSavings<?php echo e($account->id); ?>Label">Missed savings details</h2>
                                            <div class="text-muted small"><?php echo e($account->account_number); ?> - <?php echo e($account->product_name); ?></div>
                                        </div>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <div class="modal-body">
                                        <div class="row g-3">
                                            <div class="col-md-4"><div class="detail-tile"><span>Member</span><strong><?php echo e($account->customer?->fullName()); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Member account</span><strong><?php echo e($account->customer?->account_number ?? '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Savings account</span><strong><?php echo e($account->account_number); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Product</span><strong><?php echo e($account->product_name); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Account officer</span><strong><?php echo e($account->customer?->accountOfficer?->name ?? 'Unassigned'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Status</span><strong><?php echo e(ucfirst(str_replace('_', ' ', $account->status))); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Contribution</span><strong><?php echo e($account->contribution_amount ? $money($account->contribution_amount) : '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Frequency</span><strong><?php echo e($account->contribution_frequency ? ucfirst(str_replace('_', ' ', $account->contribution_frequency)) : '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Missed periods</span><strong><?php echo e($compactNumber($account->missed_savings_periods)); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Oldest missed date</span><strong><?php echo e(app_date($account->oldest_missed_due_date) ?? '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Latest missed date</span><strong><?php echo e(app_date($account->latest_missed_due_date) ?? '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Missed amount</span><strong><?php echo e($money($account->missed_savings_amount)); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Current balance</span><strong><?php echo e($money($account->balance)); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Goal</span><strong><?php echo e($goal > 0 ? $money($goal) : '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Remaining to goal</span><strong><?php echo e($goal > 0 ? $money($remaining) : '-'); ?></strong></div></div>
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Close</button>
                                        <a class="btn btn-primary btn-sm" href="<?php echo e(route('tenant.savings.show', $account)); ?>">Open account</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php else: ?>
                    <div class="pending-empty-state">
                        <i class="bi bi-check2-circle"></i>
                        <strong>No missed savings</strong>
                        <span>Past due contribution schedules with unpaid amounts will appear here automatically.</span>
                    </div>
                <?php endif; ?>
            </div>
        </div>

        <div class="tab-pane fade" id="savings-maturing-soon">
            <div class="finance-pane-title">
                <div>
                    <span>Maturity watch</span>
                    <h3>Savings maturing soon</h3>
                    <p>Track target, thrift, Isusu, and cooperative savings accounts that mature within the next 30 days.</p>
                </div>
                <div class="finance-pane-count info">
                    <strong><?php echo e($compactNumber($savingsStats['maturing_soon'] ?? 0)); ?></strong>
                    <span>next 30 days</span>
                </div>
            </div>

            <div class="p-3 p-lg-4">
                <?php if($maturingSavingsAccounts->isNotEmpty()): ?>
                    <div class="table-responsive finance-table-shell">
                        <table class="table mb-0 align-middle finance-table">
                            <thead>
                                <tr>
                                    <th>Account</th>
                                    <th>Member</th>
                                    <th>Maturity date</th>
                                    <th>Days left</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $maturingSavingsAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        $goal = (float) ($account->target_amount ?: $account->planned_total_amount ?: 0);
                                        $daysLeft = max(0, (int) today()->diffInDays($account->maturity_date, false));
                                    ?>
                                    <tr>
                                        <td><span class="finance-id-pill"><?php echo e($account->account_number); ?></span></td>
                                        <td><div class="fw-semibold"><?php echo e($account->customer?->fullName()); ?></div><small class="text-muted"><?php echo e($account->customer?->account_number); ?></small></td>
                                        <td><?php echo e(app_date($account->maturity_date)); ?></td>
                                        <td><span class="finance-soft-badge"><?php echo e($daysLeft); ?> day<?php echo e($daysLeft === 1 ? '' : 's'); ?></span></td>
                                        <td class="text-end">
                                            <button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="modal" data-bs-target="#maturingSavings<?php echo e($account->id); ?>">
                                                View
                                            </button>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                    <?php $__currentLoopData = $maturingSavingsAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $goal = (float) ($account->target_amount ?: $account->planned_total_amount ?: 0);
                            $daysLeft = max(0, (int) today()->diffInDays($account->maturity_date, false));
                            $remaining = $goal > 0 ? max(0, $goal - (float) $account->balance) : 0;
                        ?>
                        <div class="modal fade" id="maturingSavings<?php echo e($account->id); ?>" tabindex="-1" aria-labelledby="maturingSavings<?php echo e($account->id); ?>Label" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-centered modal-lg">
                                <div class="modal-content border-0 shadow">
                                    <div class="modal-header">
                                        <div>
                                            <h2 class="modal-title h5" id="maturingSavings<?php echo e($account->id); ?>Label">Maturing savings details</h2>
                                            <div class="text-muted small"><?php echo e($account->account_number); ?> - <?php echo e($account->product_name); ?></div>
                                        </div>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <div class="modal-body">
                                        <div class="row g-3">
                                            <div class="col-md-4"><div class="detail-tile"><span>Member</span><strong><?php echo e($account->customer?->fullName()); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Member account</span><strong><?php echo e($account->customer?->account_number ?? '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Savings account</span><strong><?php echo e($account->account_number); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Product</span><strong><?php echo e($account->product_name); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Status</span><strong><?php echo e(ucfirst(str_replace('_', ' ', $account->status))); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Current balance</span><strong><?php echo e($money($account->balance)); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Goal</span><strong><?php echo e($goal > 0 ? $money($goal) : '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Remaining</span><strong><?php echo e($goal > 0 ? $money($remaining) : '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Start date</span><strong><?php echo e(app_date($account->start_date) ?? '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Maturity date</span><strong><?php echo e(app_date($account->maturity_date) ?? '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Days left</span><strong><?php echo e($daysLeft); ?> day<?php echo e($daysLeft === 1 ? '' : 's'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Contribution</span><strong><?php echo e($account->contribution_amount ? $money($account->contribution_amount) : '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>Frequency</span><strong><?php echo e($account->contribution_frequency ? ucfirst(str_replace('_', ' ', $account->contribution_frequency)) : '-'); ?></strong></div></div>
                                            <div class="col-md-4"><div class="detail-tile"><span>No. of contributions</span><strong><?php echo e($account->contribution_periods ?: '-'); ?></strong></div></div>
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Close</button>
                                        <a class="btn btn-primary btn-sm" href="<?php echo e(route('tenant.savings.show', $account)); ?>">Open account</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php else: ?>
                    <div class="pending-empty-state">
                        <i class="bi bi-calendar2-check"></i>
                        <strong>No savings account is maturing soon</strong>
                        <span>Accounts with maturity dates within the next 30 days will appear here.</span>
                    </div>
                <?php endif; ?>
            </div>
        </div>

        <?php if($canManageSavings): ?>
            <div class="tab-pane fade" id="open-savings-account">
                <div class="row g-4 p-3 p-lg-4">
                    <div class="col-lg-7">
                        <div class="savings-section-title finance-section-title">
                            <h2>Open a product account</h2>
                            <p>Select a member and the savings product rules will show the fields needed for that account.</p>
                        </div>
                        <form method="POST" action="<?php echo e(route('tenant.savings.store')); ?>" class="finance-form-panel savings-open-form" data-open-savings-form>
                            <?php echo csrf_field(); ?>
                            <div class="savings-open-section">
                                <div class="savings-open-section-title">
                                    <span><i class="bi bi-person-check"></i></span>
                                    <div>
                                        <strong>Member and product</strong>
                                        <small>Start by choosing who owns the account and the savings structure to apply.</small>
                                    </div>
                                </div>
                                <div class="row g-3">
                                    <div class="col-md-6">
                                        <label class="form-label">Member</label>
                                        <div class="input-group mb-2">
                                            <span class="input-group-text"><i class="bi bi-search"></i></span>
                                            <input type="search" class="form-control" placeholder="Search member by name, phone, or account no." data-open-savings-member-search autocomplete="off">
                                        </div>
                                        <select name="customer_id" class="form-select" required data-open-savings-member-select>
                                            <option value="">Select member</option>
                                            <?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($customer->id); ?>" data-search="<?php echo e(strtolower(trim(($customer->account_number ?? '').' '.$customer->fullName().' '.($customer->phone ?? '').' '.($customer->email ?? '')))); ?>"><?php echo e($customer->account_number); ?> - <?php echo e($customer->fullName()); ?> <?php if($customer->phone): ?> (<?php echo e($customer->phone); ?>) <?php endif; ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                        <div class="form-text" data-open-savings-member-count><?php echo e(number_format($customers->count())); ?> member<?php echo e($customers->count() === 1 ? '' : 's'); ?> available</div>
                                    </div>
                                    <div class="col-md-6">
                                        <label class="form-label">Savings product</label>
                                        <select name="savings_product_id" class="form-select" required data-savings-open-product>
                                            <option value="">Select product</option>
                                            <?php $__currentLoopData = $products->where('is_active', true); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($product->id); ?>"><?php echo e($product->name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="savings-open-summary" data-savings-open-summary>
                                Select a product to see contribution, target, and maturity requirements.
                            </div>

                            <div class="savings-open-section">
                                <div class="savings-open-section-title">
                                    <span><i class="bi bi-calendar2-week"></i></span>
                                    <div>
                                        <strong>Plan details</strong>
                                        <small>Only the fields needed for the selected product will appear here.</small>
                                    </div>
                                </div>
                                <div class="row g-3">
                                    <div class="col-md-4">
                                        <label class="form-label">Start date</label>
                                        <input name="start_date" type="date" value="<?php echo e(now()->toDateString()); ?>" class="form-control" data-savings-start-date>
                                    </div>
                                    <div class="col-md-4 d-none" data-target-field>
                                        <label class="form-label">Target amount</label>
                                        <input name="target_amount" type="number" min="0.01" step="0.01" class="form-control">
                                    </div>
                                    <div class="col-md-4 d-none" data-target-field>
                                        <label class="form-label">Target date</label>
                                        <input name="target_date" type="date" class="form-control">
                                    </div>
                                    <div class="col-md-4 d-none" data-contribution-field>
                                        <label class="form-label">Contribution amount</label>
                                        <input name="contribution_amount" type="number" min="0.01" step="0.01" class="form-control">
                                    </div>
                                    <div class="col-md-4 d-none" data-contribution-field>
                                        <label class="form-label">No. of contributions</label>
                                        <input name="contribution_periods" type="number" min="1" max="10000" class="form-control" data-savings-contribution-periods>
                                    </div>
                                    <div class="col-md-4 d-none" data-contribution-field>
                                        <label class="form-label">Contribution frequency</label>
                                        <select name="contribution_frequency" class="form-select">
                                            <option value="">Use product default</option>
                                            <?php $__currentLoopData = $contributionFrequencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($value); ?>"><?php echo e($label); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                    <div class="col-md-4 d-none" data-cooperative-field>
                                        <label class="form-label">Cooperative / group name</label>
                                        <input name="cooperative_group_name" class="form-control" placeholder="e.g. Ariaria Traders">
                                    </div>
                                </div>
                            </div>

                            <div class="savings-open-section savings-open-preview-section d-none" data-plan-preview-field>
                                <div class="savings-open-section-title">
                                    <span><i class="bi bi-graph-up-arrow"></i></span>
                                    <div>
                                        <strong>Plan preview</strong>
                                        <small>The system estimates maturity and total expected contribution before saving.</small>
                                    </div>
                                </div>
                                <div class="row g-3">
                                    <div class="col-md-6">
                                        <label class="form-label">Maturity date</label>
                                        <input class="form-control bg-light" readonly data-savings-maturity-preview placeholder="Auto calculated">
                                    </div>
                                    <div class="col-md-6">
                                        <label class="form-label">Total amount to save</label>
                                        <input class="form-control bg-light" readonly data-savings-total-preview placeholder="Auto calculated">
                                    </div>
                                </div>
                            </div>

                            <div class="savings-open-section">
                                <div class="savings-open-section-title">
                                    <span><i class="bi bi-arrow-repeat"></i></span>
                                    <div>
                                        <strong>Automatic debit</strong>
                                        <small>Let the member save manually, automatically, or only after missed contributions.</small>
                                    </div>
                                </div>
                                <div class="row g-3">
                                    <div class="col-md-5">
                                        <label class="form-label">Debit option</label>
                                        <select name="auto_debit_mode" class="form-select" data-open-savings-auto-mode>
                                            <?php $__currentLoopData = $autoDebitModes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($value); ?>" <?php if(old('auto_debit_mode', \App\Models\SavingsAccount::AUTO_DEBIT_MANUAL_ONLY) === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                    <div class="col-md-7">
                                        <label class="form-label">Source savings account</label>
                                        <select name="auto_debit_savings_account_id" class="form-select" data-open-savings-auto-source>
                                            <option value="">Select source account</option>
                                            <?php $__currentLoopData = $autoDebitAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($account->id); ?>" data-customer-id="<?php echo e($account->customer_id); ?>" <?php if((string) old('auto_debit_savings_account_id', '') === (string) $account->id): echo 'selected'; endif; ?>><?php echo e($account->customer?->fullName()); ?> - <?php echo e($account->account_number); ?> (<?php echo e($money($account->balance)); ?>)</option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <button class="btn btn-primary btn-lg savings-open-submit">
                                <i class="bi bi-send-check me-1"></i> Open account
                            </button>
                        </form>
                    </div>
                    <div class="col-lg-5">
                        <div class="savings-side-card finance-guide-card">
                            <span>Product guide</span>
                            <h3>Choose the right savings structure</h3>
                            <div class="finance-guide-list">
                                <div><i class="bi bi-wallet2"></i><strong>Regular</strong><p>Flexible deposits and withdrawals for everyday savings.</p></div>
                                <div><i class="bi bi-bullseye"></i><strong>Target</strong><p>Goal-based savings with a target amount and optional target date.</p></div>
                                <div><i class="bi bi-calendar-week"></i><strong>Thrift / Isusu</strong><p>Contribution savings for daily, weekly, or monthly thrift collections.</p></div>
                                <div><i class="bi bi-people"></i><strong>Cooperative</strong><p>Group-based savings for societies, unions, markets, and associations.</p></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="tab-pane fade" id="savings-products">
                <div class="finance-pane-title">
                    <div>
                        <span>Products</span>
                        <h3>Savings product studio</h3>
                        <p>Create or edit savings products, then decide where members can see or use them.</p>
                    </div>
                </div>
                <div class="row g-4 p-3 p-lg-4 savings-product-layout">
                    <div class="col-xl-4">
                        <div class="savings-product-editor finance-editor-card">
                            <div class="d-flex justify-content-between gap-2 align-items-start mb-3">
                                <div>
                                    <div class="small text-primary fw-bold text-uppercase">Product setup</div>
                                    <h2 class="h5 mb-1">Savings products</h2>
                                    <div class="text-muted small">Choose what members can see, create, and use on the public website.</div>
                                </div>
                                <button class="btn btn-sm btn-dark" type="button" data-savings-product-new><i class="bi bi-plus-lg"></i></button>
                            </div>

                            <label class="form-label">Product to manage</label>
                            <select class="form-select mb-3" data-savings-product-selector>
                                <option value="">Create new product</option>
                                <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($product->id); ?>"><?php echo e($product->name); ?> <?php echo e($product->is_active ? '' : '(inactive)'); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>

                            <form method="POST" action="<?php echo e(route('tenant.savings-products.store')); ?>" class="vstack gap-3" data-savings-product-form>
                                <?php echo csrf_field(); ?>
                                <input type="hidden" name="_method" value="PATCH" data-savings-product-method disabled>

                                <div class="savings-product-section finance-product-section">
                                    <div class="savings-product-section-title"><i class="bi bi-pencil-square"></i><span>Basics</span></div>
                                    <label class="form-label">Product name</label>
                                    <input name="name" class="form-control" placeholder="e.g. Market women Isusu" required>
                                    <div class="row g-2 mt-1">
                                        <div class="col-6">
                                            <label class="form-label">Type</label>
                                            <select name="type" class="form-select">
                                                <?php $__currentLoopData = $types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($value); ?>"><?php echo e($label); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                        <div class="col-6">
                                            <label class="form-label">Status</label>
                                            <select name="is_active" class="form-select">
                                                <option value="1">Active</option>
                                                <option value="0">Inactive</option>
                                            </select>
                                        </div>
                                        <div class="col-12">
                                            <label class="form-label">Savings ID prefix</label>
                                            <input name="account_number_prefix" class="form-control text-uppercase" maxlength="20" pattern="[A-Za-z0-9]+" placeholder="SAV">
                                            <div class="form-text">New savings account IDs will start with this prefix.</div>
                                        </div>
                                    </div>
                                    <label class="form-label mt-2">Description</label>
                                    <textarea name="description" class="form-control" rows="2"></textarea>
                                </div>

                                <div class="savings-product-section finance-product-section">
                                    <div class="savings-product-section-title"><i class="bi bi-cash-stack"></i><span>Rules</span></div>
                                    <div class="row g-2">
                                        <div class="col-6">
                                            <label class="form-label">Interest rate (%)</label>
                                            <input name="interest_rate" type="number" step="0.01" min="0" value="0" class="form-control" required>
                                        </div>
                                        <div class="col-6">
                                            <label class="form-label">Opening minimum</label>
                                            <input name="minimum_opening_balance" type="number" step="0.01" min="0" value="0" class="form-control" required>
                                        </div>
                                        <div class="col-6">
                                            <label class="form-label">Minimum balance</label>
                                            <input name="minimum_balance" type="number" step="0.01" min="0" value="0" class="form-control" required>
                                        </div>
                                        <div class="col-6">
                                            <label class="form-label">Processing fee type</label>
                                            <select name="processing_fee_type" class="form-select" data-processing-fee-type>
                                                <?php $__currentLoopData = $processingFeeTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($value); ?>"><?php echo e($label); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                        <div class="col-6" data-processing-fee-value-field>
                                            <label class="form-label">Processing fee value</label>
                                            <input name="processing_fee_value" type="number" step="0.01" min="0" value="0" class="form-control">
                                        </div>
                                        <div class="col-12">
                                            <label class="form-label">When to deduct fee</label>
                                            <select name="processing_fee_timing" class="form-select">
                                                <?php $__currentLoopData = $processingFeeTimings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($value); ?>"><?php echo e($label); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                            <div class="form-text">Use withdrawal for thrift / Isusu, or first deposit when the fee should be removed from the first saved amount.</div>
                                        </div>
                                        <div class="col-6">
                                            <label class="form-label">Duration days</label>
                                            <input name="duration_days" type="number" min="1" class="form-control">
                                        </div>
                                        <div class="col-6">
                                            <label class="form-label">Contribution frequency</label>
                                            <select name="contribution_frequency" class="form-select">
                                                <option value="">Not fixed</option>
                                                <?php $__currentLoopData = $contributionFrequencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($value); ?>"><?php echo e($label); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                        <div class="col-12">
                                            <label class="form-label">Withdrawal policy</label>
                                            <select name="withdrawal_policy" class="form-select">
                                                <?php $__currentLoopData = $withdrawalPolicies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($value); ?>"><?php echo e($label); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="savings-product-section finance-product-section">
                                    <div class="savings-product-section-title"><i class="bi bi-eye"></i><span>Visibility</span></div>
                                    <div class="row g-2">
                                        <div class="col-4">
                                            <label class="form-label">Members create</label>
                                            <select name="allow_member_create" class="form-select">
                                                <option value="1">Allow</option>
                                                <option value="0">Block</option>
                                            </select>
                                        </div>
                                        <div class="col-4">
                                            <label class="form-label">Portal</label>
                                            <select name="show_on_member_portal" class="form-select">
                                                <option value="1">Show</option>
                                                <option value="0">Hide</option>
                                            </select>
                                        </div>
                                        <div class="col-4">
                                            <label class="form-label">Website</label>
                                            <select name="show_on_public_website" class="form-select">
                                                <option value="1">Show</option>
                                                <option value="0">Hide</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="d-flex flex-wrap gap-2">
                                    <button class="btn btn-primary flex-grow-1" data-savings-product-submit>Save product</button>
                                    <button class="btn btn-outline-danger" type="submit" form="deleteSavingsProductForm" data-savings-product-delete disabled>Delete / disable</button>
                                </div>
                            </form>

                            <form method="POST" id="deleteSavingsProductForm" data-savings-product-delete-form>
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                            </form>
                        </div>
                    </div>

                    <div class="col-xl-8">
                        <div class="savings-product-showcase-title">
                            <div>
                                <span>Product library</span>
                                <strong><?php echo e(number_format($products->count())); ?> configured products</strong>
                            </div>
                            <small>Cards show visibility, fee rule, ID prefix, and current status.</small>
                        </div>
                        <div class="row g-3">
                            <?php $__empty_1 = true; $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <div class="col-md-6">
                                    <div class="savings-product-card finance-product-card">
                                        <div class="d-flex justify-content-between gap-2">
                                            <div>
                                                <div class="fw-semibold"><?php echo e($product->name); ?></div>
                                                <div class="small text-muted"><?php echo e($product->typeLabel()); ?></div>
                                            </div>
                                            <span class="badge <?php echo e($product->is_active ? 'text-bg-success' : 'text-bg-secondary'); ?>"><?php echo e($product->is_active ? 'Active' : 'Inactive'); ?></span>
                                        </div>
                                        <p><?php echo e($product->description ?: 'Savings product configured for this tenant.'); ?></p>
                                        <div class="small text-muted"><?php echo e($product->withdrawalPolicyLabel()); ?> <?php if($product->contribution_frequency): ?> | <?php echo e($product->contributionFrequencyLabel()); ?> <?php endif; ?></div>
                                        <div class="small text-muted mt-1">ID starts with: <strong><?php echo e($product->account_number_prefix ?: 'SAV'); ?></strong></div>
                                        <div class="small text-muted mt-1">
                                            Processing fee:
                                            <?php if(($product->processing_fee_type ?? 'fixed') === 'contribution_amount'): ?>
                                                One contribution amount
                                            <?php elseif(($product->processing_fee_type ?? 'fixed') === 'percentage'): ?>
                                                <?php echo e($product->processing_fee_value); ?>%
                                            <?php else: ?>
                                                <?php echo e(number_format((float) $product->processing_fee_value, 2)); ?> fixed
                                            <?php endif; ?>
                                        </div>
                                        <div class="small text-muted mt-1">Fee timing: <strong><?php echo e($product->processingFeeTimingLabel()); ?></strong></div>
                                        <div class="d-flex flex-wrap gap-1 mt-2">
                                            <span class="badge <?php echo e($product->allow_member_create ? 'text-bg-info' : 'text-bg-light text-dark'); ?>">Member <?php echo e($product->allow_member_create ? 'can create' : 'blocked'); ?></span>
                                            <span class="badge <?php echo e($product->show_on_member_portal ? 'text-bg-primary' : 'text-bg-light text-dark'); ?>">Portal <?php echo e($product->show_on_member_portal ? 'shown' : 'hidden'); ?></span>
                                            <span class="badge <?php echo e($product->show_on_public_website ? 'text-bg-dark' : 'text-bg-light text-dark'); ?>">Website <?php echo e($product->show_on_public_website ? 'shown' : 'hidden'); ?></span>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <div class="col-12"><div class="text-muted">No savings products yet.</div></div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', () => {
    const pendingSelectAll = document.querySelector('[data-savings-deposit-select-all]');
    const pendingCheckboxes = Array.from(document.querySelectorAll('[data-savings-deposit-checkbox]'));
    const bulkForm = document.getElementById('bulkSavingsDepositForm');
    const bulkRejectReason = document.querySelector('[name="rejected_reason"][form="bulkSavingsDepositForm"]');

    const syncPendingSelectAll = () => {
        if (!pendingSelectAll) return;

        const checked = pendingCheckboxes.filter((checkbox) => checkbox.checked).length;
        pendingSelectAll.checked = checked > 0 && checked === pendingCheckboxes.length;
        pendingSelectAll.indeterminate = checked > 0 && checked < pendingCheckboxes.length;
    };

    pendingSelectAll?.addEventListener('change', () => {
        pendingCheckboxes.forEach((checkbox) => {
            checkbox.checked = pendingSelectAll.checked;
        });
        syncPendingSelectAll();
    });

    pendingCheckboxes.forEach((checkbox) => checkbox.addEventListener('change', syncPendingSelectAll));
    bulkForm?.addEventListener('submit', (event) => {
        if (!pendingCheckboxes.some((checkbox) => checkbox.checked)) {
            event.preventDefault();
            alert('Select at least one pending savings transaction first.');
            return;
        }

        if ((event.submitter?.getAttribute('formaction') || '').includes('bulk-reject') && !bulkRejectReason?.value.trim()) {
            event.preventDefault();
            bulkRejectReason?.focus();
            alert('Enter a reason for the bulk rejection.');
        }
    });

    document.querySelectorAll('[data-auto-savings-filter]').forEach((filterForm) => {
        const search = filterForm.querySelector('[data-savings-search]');
        const selects = filterForm.querySelectorAll('[data-savings-select]');
        let timer = null;
        const submit = () => filterForm.requestSubmit ? filterForm.requestSubmit() : filterForm.submit();

        search?.addEventListener('input', () => {
            clearTimeout(timer);
            timer = setTimeout(submit, 550);
        });

        selects.forEach((select) => select.addEventListener('change', submit));
    });

    const products = <?php echo json_encode($productPayload, 15, 512) ?>;
    const byId = new Map(products.map((product) => [String(product.id), product]));
    const currency = <?php echo json_encode(auth()->user()->tenant->settings['currency'] ?? 'NGN', 15, 512) ?>;
    const formatMoney = (amount) => `${currency} ${Number(amount || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;

    const setRequired = (selector, required) => {
        document.querySelectorAll(selector).forEach((field) => {
            field.required = required;
        });
    };

    const estimatedProcessingFee = (product) => {
        const contributionInput = document.querySelector('[data-open-savings-form] [name="contribution_amount"]');
        const targetInput = document.querySelector('[data-open-savings-form] [name="target_amount"]');
        const contribution = Number(contributionInput?.value || 0);
        const target = Number(targetInput?.value || 0);
        const base = contribution > 0 ? contribution : (target > 0 ? target : Number(product.minimum_opening_balance || 0));

        if (product.processing_fee_type === 'percentage') {
            return base * (Number(product.processing_fee_value || 0) / 100);
        }

        if (product.processing_fee_type === 'contribution_amount') {
            return contribution;
        }

        return Number(product.processing_fee_value || 0);
    };
    const intervalDays = { daily: 1, weekly: 7, biweekly: 14, monthly: 30, quarterly: 90, yearly: 365 };
    const addContributionPeriods = (startDate, frequency, periods) => {
        const date = new Date(`${startDate}T00:00:00`);

        switch (frequency) {
            case 'daily': date.setDate(date.getDate() + periods); break;
            case 'weekly': date.setDate(date.getDate() + (periods * 7)); break;
            case 'biweekly': date.setDate(date.getDate() + (periods * 14)); break;
            case 'quarterly': date.setMonth(date.getMonth() + (periods * 3)); break;
            case 'yearly': date.setFullYear(date.getFullYear() + periods); break;
            default: date.setMonth(date.getMonth() + periods); break;
        }

        return date.toISOString().slice(0, 10);
    };
    const syncSavingsPlanPreview = (product) => {
        const form = document.querySelector('[data-open-savings-form]');
        const startInput = form?.querySelector('[name="start_date"]');
        const contributionInput = form?.querySelector('[name="contribution_amount"]');
        const frequencyInput = form?.querySelector('[name="contribution_frequency"]');
        const periodsInput = form?.querySelector('[name="contribution_periods"]');
        const maturityPreview = document.querySelector('[data-savings-maturity-preview]');
        const totalPreview = document.querySelector('[data-savings-total-preview]');
        const frequency = frequencyInput?.value || product?.contribution_frequency || 'monthly';

        if (periodsInput && !periodsInput.value && Number(product?.duration_days || 0) > 0) {
            periodsInput.value = Math.max(1, Math.ceil(Number(product.duration_days) / (intervalDays[frequency] || 30)));
        }

        const periods = Number(periodsInput?.value || 0);
        const contribution = Number(contributionInput?.value || 0);

        if (maturityPreview) {
            maturityPreview.value = startInput?.value && periods > 0 ? addContributionPeriods(startInput.value, frequency, periods) : '';
        }

        if (totalPreview) {
            totalPreview.value = contribution > 0 && periods > 0 ? formatMoney(contribution * periods) : '';
        }
    };

    const openSelector = document.querySelector('[data-savings-open-product]');
    const openSummary = document.querySelector('[data-savings-open-summary]');
    const memberSearch = document.querySelector('[data-open-savings-member-search]');
    const memberSelect = document.querySelector('[data-open-savings-member-select]');
    const memberCount = document.querySelector('[data-open-savings-member-count]');
    const memberOptions = memberSelect ? Array.from(memberSelect.options).slice(1) : [];

    const syncMemberSearch = () => {
        if (!memberSelect) return;

        const term = String(memberSearch?.value || '').trim().toLowerCase();
        let matches = 0;

        memberOptions.forEach((option) => {
            const visible = !term || String(option.dataset.search || option.textContent || '').includes(term);
            option.hidden = !visible;
            option.disabled = !visible;
            if (visible) matches++;
        });

        if (memberSelect.selectedOptions[0]?.disabled) {
            memberSelect.value = '';
        }

        if (memberCount) {
            memberCount.textContent = term
                ? `${matches.toLocaleString()} matching member${matches === 1 ? '' : 's'}`
                : `${memberOptions.length.toLocaleString()} member${memberOptions.length === 1 ? '' : 's'} available`;
        }
    };

    memberSearch?.addEventListener('input', syncMemberSearch);
    syncMemberSearch();

    const openAutoMode = document.querySelector('[data-open-savings-auto-mode]');
    const openAutoSource = document.querySelector('[data-open-savings-auto-source]');
    const syncOpenAutoDebit = () => {
        const enabled = openAutoMode && openAutoMode.value !== 'manual_only';
        if (openAutoSource) {
            openAutoSource.classList.toggle('d-none', !enabled);
            openAutoSource.required = Boolean(enabled);
            const customerId = memberSelect?.value || '';
            openAutoSource.querySelectorAll('option[data-customer-id]').forEach((option) => {
                option.hidden = Boolean(customerId) && option.dataset.customerId !== customerId;
            });
        }
    };
    openAutoMode?.addEventListener('change', syncOpenAutoDebit);
    memberSelect?.addEventListener('change', syncOpenAutoDebit);
    syncOpenAutoDebit();

    const syncOpenProduct = () => {
        const product = byId.get(String(openSelector?.value || ''));
        document.querySelectorAll('[data-target-field], [data-contribution-field], [data-plan-preview-field], [data-cooperative-field]').forEach((field) => field.classList.add('d-none'));
        setRequired('[name="target_amount"]', false);
        setRequired('[name="contribution_amount"]', false);
        setRequired('[name="contribution_periods"]', false);
        setRequired('[name="cooperative_group_name"]', false);

        if (!product) {
            if (openSummary) openSummary.textContent = 'Select a product to see contribution, target, and maturity requirements.';
            return;
        }

        const contributionText = product.type === 'regular'
            ? 'Contribution amount is entered when posting deposits'
            : 'Contribution amount is set when opening each member account';
        const feeText = product.processing_fee_type === 'contribution_amount'
            ? `Processing fee: ${formatMoney(estimatedProcessingFee(product))} (one contribution amount)`
            : `Processing fee: ${formatMoney(estimatedProcessingFee(product))}`;
        const feeTimingText = product.processing_fee_timing_label || String(product.processing_fee_timing || 'manual').replaceAll('_', ' ');
        if (openSummary) openSummary.textContent = `${product.name}: ${product.type_label}. ${contributionText}. ${feeText}. Fee timing: ${feeTimingText}. Withdrawal: ${String(product.withdrawal_policy).replaceAll('_', ' ')}.`;

        const needsContributionAmount = ['thrift_isusu', 'cooperative'].includes(product.type) || product.processing_fee_type === 'contribution_amount';

        if (needsContributionAmount) {
            document.querySelectorAll('[data-contribution-field], [data-plan-preview-field]').forEach((field) => field.classList.remove('d-none'));
            setRequired('[name="contribution_amount"]', true);
            setRequired('[name="contribution_periods"]', true);
        }

        if (product.type === 'target') {
            document.querySelectorAll('[data-target-field], [data-contribution-field], [data-plan-preview-field]').forEach((field) => field.classList.remove('d-none'));
            setRequired('[name="target_amount"]', true);
            setRequired('[name="contribution_amount"]', true);
            setRequired('[name="contribution_periods"]', true);
        }

        if (product.type === 'thrift_isusu') {
            document.querySelectorAll('[data-contribution-field], [data-plan-preview-field]').forEach((field) => field.classList.remove('d-none'));
            setRequired('[name="contribution_amount"]', true);
            setRequired('[name="contribution_periods"]', true);
        }

        if (product.type === 'cooperative') {
            document.querySelectorAll('[data-contribution-field], [data-plan-preview-field], [data-cooperative-field]').forEach((field) => field.classList.remove('d-none'));
            setRequired('[name="cooperative_group_name"]', true);
            setRequired('[name="contribution_amount"]', true);
            setRequired('[name="contribution_periods"]', true);
        }

        syncSavingsPlanPreview(product);
    };
    openSelector?.addEventListener('change', syncOpenProduct);
    document.querySelector('[data-open-savings-form] [name="contribution_amount"]')?.addEventListener('input', syncOpenProduct);
    document.querySelector('[data-open-savings-form] [name="target_amount"]')?.addEventListener('input', syncOpenProduct);
    document.querySelector('[data-open-savings-form] [name="contribution_frequency"]')?.addEventListener('change', syncOpenProduct);
    document.querySelector('[data-open-savings-form] [name="contribution_periods"]')?.addEventListener('input', syncOpenProduct);
    document.querySelector('[data-open-savings-form] [name="start_date"]')?.addEventListener('change', syncOpenProduct);
    syncOpenProduct();

    const selector = document.querySelector('[data-savings-product-selector]');
    const form = document.querySelector('[data-savings-product-form]');
    const methodInput = document.querySelector('[data-savings-product-method]');
    const newButton = document.querySelector('[data-savings-product-new]');
    const submitButton = document.querySelector('[data-savings-product-submit]');
    const deleteButton = document.querySelector('[data-savings-product-delete]');
    const deleteForm = document.querySelector('[data-savings-product-delete-form]');
    const storeRoute = <?php echo json_encode(route('tenant.savings-products.store'), 15, 512) ?>;
    const processingFeeType = form?.querySelector('[data-processing-fee-type]');
    const processingFeeValueField = form?.querySelector('[data-processing-fee-value-field]');

    const setField = (name, value) => {
        const field = form?.querySelector(`[name="${name}"]`);
        if (field) field.value = value ?? '';
    };

    const syncProcessingFeeValue = () => {
        const useContribution = processingFeeType?.value === 'contribution_amount';
        processingFeeValueField?.classList.toggle('d-none', useContribution);
        const valueInput = form?.querySelector('[name="processing_fee_value"]');
        if (valueInput) {
            valueInput.required = !useContribution;
            if (useContribution) valueInput.value = '0';
        }
    };

    const resetForm = () => {
        if (!form) return;
        form.reset();
        form.action = storeRoute;
        methodInput.disabled = true;
        submitButton.textContent = 'Save product';
        deleteButton.disabled = true;
        deleteForm.removeAttribute('action');
        setField('type', 'regular');
        setField('account_number_prefix', 'SAV');
        setField('interest_rate', '0');
        setField('minimum_opening_balance', '0');
        setField('minimum_balance', '0');
        setField('processing_fee_type', 'fixed');
        setField('processing_fee_value', '0');
        setField('processing_fee_timing', 'manual');
        setField('withdrawal_policy', 'flexible');
        setField('allow_member_create', '1');
        setField('show_on_member_portal', '1');
        setField('show_on_public_website', '1');
        setField('is_active', '1');
        syncProcessingFeeValue();
    };

    const loadProduct = (id) => {
        const product = byId.get(String(id));
        if (!product) {
            resetForm();
            return;
        }

        form.action = product.update_route;
        methodInput.disabled = false;
        submitButton.textContent = 'Update product';
        deleteButton.disabled = false;
        deleteForm.action = product.delete_route;
        Object.entries(product).forEach(([name, value]) => setField(name, value));
        syncProcessingFeeValue();
    };

    processingFeeType?.addEventListener('change', syncProcessingFeeValue);
    selector?.addEventListener('change', (event) => loadProduct(event.target.value));
    newButton?.addEventListener('click', () => {
        if (selector) selector.value = '';
        resetForm();
    });
    resetForm();
});
</script>

<style>
.savings-workspace .table th {
    color: #475569;
    font-size: .82rem;
    text-transform: uppercase;
}
.savings-section-title h2,
.savings-side-card h3,
.savings-product-editor h2 {
    font-size: 1.05rem;
    margin-bottom: .25rem;
}
.savings-section-title p,
.savings-side-card p,
.savings-product-card p {
    color: #64748b;
    margin-bottom: 0;
}
.savings-side-card,
.savings-product-editor,
.savings-product-card {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    padding: 1rem;
}
.savings-side-card {
    background: #f8fafc;
}
.savings-product-section {
    padding: .95rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
}
.savings-product-section-title {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin-bottom: .75rem;
    color: #0f766e;
    font-weight: 800;
}
.savings-product-section .form-label {
    margin-bottom: .25rem;
    font-size: .82rem;
    color: #475569;
}
.pending-review-card {
    border: 1px solid #fde68a;
    border-radius: 8px;
    overflow: hidden;
    background: #fffbeb;
}
.pending-review-head {
    display: flex;
    justify-content: space-between;
    padding: .85rem 1rem;
    border-bottom: 1px solid #fde68a;
}
.pending-review-head span {
    display: block;
    color: #92400e;
    font-size: .78rem;
    font-weight: 800;
    text-transform: uppercase;
}
.pending-review-head strong {
    color: #451a03;
}
.detail-tile {
    height: 100%;
    padding: .8rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
}
.detail-tile span {
    display: block;
    margin-bottom: .25rem;
    color: #64748b;
    font-size: .76rem;
    font-weight: 800;
    text-transform: uppercase;
}
.detail-tile strong {
    display: block;
    color: #172033;
    font-size: .92rem;
    font-weight: 800;
    overflow-wrap: anywhere;
}
.finance-pane-count {
    display: grid;
    place-items: center;
    min-width: 84px;
    padding: .55rem .85rem;
    border: 1px solid #fde68a;
    border-radius: 8px;
    background: #fffbeb;
}
.finance-pane-count strong {
    color: #92400e;
    font-size: 1.25rem;
    line-height: 1;
}
.finance-pane-count span {
    margin-top: .2rem;
    color: #92400e;
    font-size: .72rem;
    font-weight: 900;
    text-transform: uppercase;
}
.finance-pane-count.info {
    border-color: #bae6fd;
    background: #f0f9ff;
}
.finance-pane-count.info strong,
.finance-pane-count.info span {
    color: #0369a1;
}
.finance-pane-count.danger {
    border-color: #fecaca;
    background: #fef2f2;
}
.finance-pane-count.danger strong,
.finance-pane-count.danger span {
    color: #b91c1c;
}
.bulk-approval-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 1rem;
    border-bottom: 1px solid #fde68a;
    background: #fff7ed;
}
.bulk-approval-bar strong {
    display: block;
    color: #451a03;
}
.bulk-approval-bar span {
    color: #92400e;
    font-size: .82rem;
    font-weight: 700;
}
.bulk-approval-controls {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    gap: .5rem;
    align-items: center;
    min-width: min(100%, 620px);
}
.pending-modal-reject {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: .5rem;
    align-items: center;
    min-width: min(100%, 420px);
}
.pending-empty-state {
    display: grid;
    place-items: center;
    gap: .45rem;
    min-height: 230px;
    padding: 2rem;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    text-align: center;
}
.pending-empty-state i {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    background: #dcfce7;
    color: #15803d;
    font-size: 1.55rem;
}
.pending-empty-state strong {
    color: #172033;
    font-size: 1.05rem;
}
.pending-empty-state span {
    max-width: 420px;
    color: #64748b;
    font-weight: 700;
}
@media (max-width: 767.98px) {
    .bulk-approval-bar,
    .bulk-approval-controls,
    .pending-modal-reject {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .bulk-approval-bar {
        display: grid;
    }
}
</style>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\Polite hp\Documents\Codex\2026-05-08\build-a-complete-production-ready-saas\microfinance-saas\resources\views\tenant\savings\index.blade.php ENDPATH**/ ?>