

<?php $__env->startSection('title', $account->account_number); ?>
<?php $__env->startSection('page-title', $account->account_number); ?>
<?php $__env->startSection('page-subtitle', $account->customer?->fullName()); ?>

<?php $__env->startSection('content'); ?>
<?php
    $currency = auth()->user()->tenant->settings['currency'] ?? 'NGN';
    $money = fn ($amount) => $currency.' '.number_format((float) $amount, 2);
    $goalLabel = (float) $account->target_amount > 0 ? 'Target amount' : 'Planned savings';
    $hasGoal = (float) $progress['goal'] > 0;
    $canApproveSavings = auth()->user()->hasPermission('savings.approve');
    $accountStatusClasses = [
        'pending' => 'text-bg-warning',
        'active' => 'text-bg-success',
        'rejected' => 'text-bg-danger',
        'closed' => 'text-bg-secondary',
        'inactive' => 'text-bg-secondary',
    ];
    $statusLabels = [
        'saved' => 'Saved',
        'partial' => 'Partial',
        'missed' => 'Missed',
        'due_today' => 'Due today',
        'upcoming' => 'Upcoming',
    ];
    $statusClasses = [
        'saved' => 'text-bg-success',
        'partial' => 'text-bg-info',
        'missed' => 'text-bg-danger',
        'due_today' => 'text-bg-warning',
        'upcoming' => 'text-bg-light text-dark',
    ];
    $transactionStatusClasses = [
        'posted' => 'text-bg-success',
        'pending' => 'text-bg-warning',
        'rejected' => 'text-bg-danger',
        'canceled' => 'text-bg-secondary',
    ];
    $withdrawnAmount = (float) ($progress['withdrawn'] ?? 0);
    $processingFeeAlreadyDeducted = (float) $account->transactions
        ->where('status', 'posted')
        ->sum('processing_fee_amount');
    $withdrawalProcessingFeeDue = $account->withdrawalProcessingFeeDue($processingFeeAlreadyDeducted);
    $depositProcessingFeeDue = $account->depositProcessingFeeDue($processingFeeAlreadyDeducted);
    $withdrawalAvailableOn = $account->locked_until ?: $account->maturity_date ?: $account->target_date;
    $withdrawalPolicy = $account->product?->withdrawal_policy ?? 'flexible';
    $completionAmount = $account->completionAmount();
    $completedByBalance = $completionAmount > 0 && (float) $account->balance >= $completionAmount;
    $withdrawalReady = (float) $account->balance > 0 && match (true) {
        $account->status === 'closed' => true,
        $withdrawalPolicy !== 'locked_until_maturity' => true,
        $withdrawalAvailableOn && $withdrawalAvailableOn->lte(today()) => true,
        default => $completedByBalance,
    };
    $canPostDeposit = $account->status === 'active';
    $canPostWithdrawal = in_array($account->status, ['active', 'closed'], true) && $withdrawalReady;
    $accountRuleSections = [
        'Account setup' => [
            ['label' => 'Account', 'value' => $account->account_number, 'icon' => 'bi-credit-card-2-front'],
            ['label' => 'Product', 'value' => $account->product_name, 'icon' => 'bi-wallet2'],
            ['label' => 'Status', 'value' => ucfirst(str_replace('_', ' ', $account->status)), 'icon' => 'bi-circle-fill'],
        ],
        'Plan rules' => collect([
            (float) $account->target_amount > 0 ? ['label' => 'Target amount', 'value' => $money($account->target_amount), 'icon' => 'bi-bullseye'] : null,
            $account->target_date ? ['label' => 'Target date', 'value' => app_date($account->target_date), 'icon' => 'bi-calendar-event'] : null,
            (float) $account->contribution_amount > 0 ? ['label' => 'Contribution', 'value' => $money($account->contribution_amount), 'icon' => 'bi-cash-coin'] : null,
            $account->contribution_frequency ? ['label' => 'Frequency', 'value' => ucfirst(str_replace('_', ' ', $account->contribution_frequency)), 'icon' => 'bi-arrow-repeat'] : null,
            $account->contribution_periods ? ['label' => 'Contributions', 'value' => number_format($account->contribution_periods), 'icon' => 'bi-list-ol'] : null,
            (float) $account->planned_total_amount > 0 ? ['label' => 'Total amount to save', 'value' => $money($account->planned_total_amount), 'icon' => 'bi-piggy-bank'] : null,
            $account->maturity_date ? ['label' => 'Maturity date', 'value' => app_date($account->maturity_date), 'icon' => 'bi-calendar2-check'] : null,
            filled($account->cooperative_group_name) ? ['label' => 'Group', 'value' => $account->cooperative_group_name, 'icon' => 'bi-people'] : null,
        ])->filter()->values()->all(),
        'Fees and access' => collect([
            ['label' => 'Withdrawal rule', 'value' => $account->product?->withdrawalPolicyLabel() ?? 'Flexible withdrawals', 'icon' => 'bi-unlock'],
            (float) $account->processing_fee_amount > 0 ? ['label' => 'Processing fee', 'value' => $money($account->processing_fee_amount), 'icon' => 'bi-receipt'] : null,
            (float) $account->processing_fee_amount > 0 ? ['label' => 'Fee timing', 'value' => $account->processingFeeTimingLabel(), 'icon' => 'bi-clock-history'] : null,
            (float) $account->processing_fee_amount > 0 ? ['label' => 'Fee method', 'value' => $account->processingFeeTypeLabel(), 'icon' => 'bi-sliders'] : null,
            $withdrawnAmount > 0 ? ['label' => 'Withdrawn', 'value' => $money($withdrawnAmount), 'icon' => 'bi-arrow-up-circle'] : null,
        ])->filter()->values()->all(),
    ];
?>

<div class="savings-detail-shell">
    <section class="savings-progress-hero mb-4">
        <div class="savings-progress-copy">
            <div class="d-flex flex-wrap align-items-center gap-2 mb-2">
                <span class="badge text-bg-light text-dark"><?php echo e($account->typeLabel()); ?></span>
                <span class="badge <?php echo e($accountStatusClasses[$account->status] ?? 'text-bg-secondary'); ?>"><?php echo e(ucfirst(str_replace('_', ' ', $account->status))); ?></span>
            </div>
            <h2><?php echo e($account->product_name); ?></h2>
            <p><?php echo e($account->product?->withdrawalPolicyLabel() ?? 'Flexible withdrawals'); ?> for <?php echo e($account->customer?->fullName()); ?>.</p>
            <div class="savings-plan-strip">
                <div><span>Start</span><strong><?php echo e(app_date($account->start_date) ?? '-'); ?></strong></div>
                <div><span>Maturity</span><strong><?php echo e(app_date($account->maturity_date) ?? '-'); ?></strong></div>
                <div><span>Contribution</span><strong><?php echo e($account->contribution_amount ? $money($account->contribution_amount) : '-'); ?></strong></div>
                <div><span>Frequency</span><strong><?php echo e($account->contribution_frequency ? ucfirst(str_replace('_', ' ', $account->contribution_frequency)) : '-'); ?></strong></div>
            </div>
        </div>

        <div class="savings-progress-visual">
            <div class="savings-progress-ring" style="--progress: <?php echo e($progress['percent']); ?>%;">
                <div>
                    <strong><?php echo e(number_format($progress['percent'], $progress['percent'] == (int) $progress['percent'] ? 0 : 1)); ?>%</strong>
                    <span>saved</span>
                </div>
            </div>
            <div class="savings-progress-bar">
                <div class="d-flex justify-content-between small mb-2">
                    <span><?php echo e($goalLabel); ?></span>
                    <strong><?php echo e($hasGoal ? $money($progress['goal']) : '-'); ?></strong>
                </div>
                <div class="progress">
                    <div class="progress-bar" style="width: <?php echo e($progress['percent']); ?>%"></div>
                </div>
                <div class="d-flex justify-content-between small mt-2 text-muted">
                    <span>Saved <?php echo e($money($progress['saved'])); ?></span>
                    <span>Remaining <?php echo e($hasGoal ? $money($progress['remaining']) : '-'); ?></span>
                </div>
            </div>
        </div>
    </section>

    <div class="row g-3 mb-4">
        <div class="col-md-3"><div class="savings-metric-card"><span>Current balance</span><strong><?php echo e($money($account->balance)); ?></strong></div></div>
        <div class="col-md-3"><div class="savings-metric-card"><span><?php echo e($goalLabel); ?></span><strong><?php echo e($hasGoal ? $money($progress['goal']) : '-'); ?></strong></div></div>
        <div class="col-md-3"><div class="savings-metric-card"><span>Remaining</span><strong><?php echo e($hasGoal ? $money($progress['remaining']) : '-'); ?></strong></div></div>
        <div class="col-md-3"><div class="savings-metric-card"><span>Total deposits</span><strong><?php echo e($money($progress['deposited'])); ?></strong></div></div>
    </div>

    <div class="row g-4">
        <div class="col-lg-4">
            <div class="card border-0 shadow-sm savings-rule-card mb-4">
                <div class="savings-rule-head">
                    <span><i class="bi bi-list-check"></i></span>
                    <div>
                        <strong>Account rules</strong>
                        <small>Only rules that apply to this savings account are shown.</small>
                    </div>
                </div>
                <div class="savings-rule-body">
                    <?php $__currentLoopData = $accountRuleSections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $section => $rules): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="savings-rule-section">
                            <h3><?php echo e($section); ?></h3>
                            <?php if(count($rules)): ?>
                                <div class="savings-rule-grid">
                                    <?php $__currentLoopData = $rules; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rule): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <div class="savings-rule-tile">
                                            <i class="bi <?php echo e($rule['icon']); ?>"></i>
                                            <span><?php echo e($rule['label']); ?></span>
                                            <strong><?php echo e($rule['value']); ?></strong>
                                        </div>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </div>
                            <?php else: ?>
                                <div class="savings-rule-empty">No fixed target, group, or contribution rule was set for this account.</div>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>

            <?php if(auth()->user()->hasPermission('savings.manage')): ?>
                <div class="card border-0 shadow-sm">
                    <div class="card-body">
                        <h2 class="h5">Post transaction</h2>
                        <?php if($canPostDeposit || $canPostWithdrawal): ?>
                            <?php if($account->status === 'closed'): ?>
                                <p class="text-muted small mb-2">This savings plan is completed and closed for new deposits. You can still request withdrawal of the available balance.</p>
                            <?php else: ?>
                                <p class="text-muted small mb-2">Deposits and withdrawals will wait for approval before they update the member balance.</p>
                            <?php endif; ?>
                            <form method="POST" action="<?php echo e(route('tenant.savings.transactions.store', $account)); ?>" class="vstack gap-2">
                                <?php echo csrf_field(); ?>
                                <select name="type" class="form-select">
                                    <?php if($canPostDeposit): ?>
                                        <option value="deposit">Deposit</option>
                                    <?php endif; ?>
                                    <?php if($canPostWithdrawal): ?>
                                        <option value="withdrawal" <?php if(! $canPostDeposit): echo 'selected'; endif; ?>>Withdrawal</option>
                                    <?php endif; ?>
                                </select>
                                <input name="amount" type="number" step="0.01" min="0.01" class="form-control" placeholder="Amount" required>
                                <select name="method" class="form-select"><option value="cash">Cash</option><option value="transfer">Transfer</option><option value="pos">POS</option><option value="cheque">Cheque</option></select>
                                <textarea name="description" class="form-control" placeholder="Narration"></textarea>
                                <?php if($canPostWithdrawal && $withdrawalProcessingFeeDue > 0): ?>
                                    <div class="alert alert-light border small mb-0">
                                        Processing fee of <?php echo e($money($withdrawalProcessingFeeDue)); ?> will be deducted from this withdrawal.
                                    </div>
                                <?php endif; ?>
                                <?php if($canPostDeposit && $depositProcessingFeeDue > 0): ?>
                                    <div class="alert alert-light border small mb-0">
                                        Processing fee of <?php echo e($money($depositProcessingFeeDue)); ?> will be deducted when the first deposit is approved.
                                    </div>
                                <?php endif; ?>
                                <button class="btn btn-primary"><?php echo e($canPostWithdrawal && ! $canPostDeposit ? 'Save withdrawal' : 'Save transaction'); ?></button>
                            </form>
                            <?php if(! $canPostWithdrawal && $account->status === 'active' && (float) $account->balance > 0 && $withdrawalPolicy === 'locked_until_maturity'): ?>
                                <div class="alert alert-light border small mb-0 mt-3">
                                    Withdrawal becomes available <?php echo e($withdrawalAvailableOn ? 'on '.app_date($withdrawalAvailableOn) : 'when this savings plan reaches its maturity or target'); ?>.
                                </div>
                            <?php endif; ?>
                        <?php else: ?>
                            <?php if($account->status === 'closed'): ?>
                                <div class="text-muted small">This savings account is completed and fully paid out.</div>
                            <?php else: ?>
                                <div class="text-muted small">Transactions can be posted when the savings account is active.</div>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endif; ?>
        </div>

        <div class="col-lg-8">
            <div class="card border-0 shadow-sm savings-schedule-card">
                <div class="card-header bg-white border-0">
                    <ul class="nav nav-pills gap-2" role="tablist">
                        <li class="nav-item" role="presentation"><button class="nav-link active" data-bs-toggle="tab" data-bs-target="#savings-schedule-pane" type="button">Savings schedule</button></li>
                        <li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#savings-statement-pane" type="button">Statement</button></li>
                    </ul>
                </div>

                <div class="tab-content">
                    <div class="tab-pane fade show active" id="savings-schedule-pane">
                        <div class="card-body border-top">
                            <div class="d-flex flex-column flex-lg-row justify-content-between gap-3 align-items-lg-center">
                                <div>
                                    <h2 class="h5 mb-1">Contribution schedule</h2>
                                    <div class="text-muted small"><?php echo e(count($savingsSchedule)); ?> contribution<?php echo e(count($savingsSchedule) === 1 ? '' : 's'); ?> generated from this savings plan.</div>
                                </div>
                                <div class="d-flex flex-wrap gap-2">
                                    <button class="btn btn-outline-primary btn-sm schedule-action-btn" type="button" data-savings-schedule-copy>Copy</button>
                                    <button class="btn btn-outline-primary btn-sm schedule-action-btn" type="button" data-savings-schedule-excel>Excel</button>
                                    <button class="btn btn-outline-primary btn-sm schedule-action-btn" type="button" data-savings-schedule-print>Print</button>
                                </div>
                            </div>
                            <div class="d-flex justify-content-end align-items-center gap-2 mt-3">
                                <label class="form-label mb-0">Search</label>
                                <input class="form-control schedule-search" data-savings-schedule-search>
                            </div>
                        </div>

                        <?php if(count($savingsSchedule) === 0): ?>
                            <div class="card-body border-top">
                                <div class="alert alert-light border mb-0">No schedule is available yet. Add contribution amount, start date, frequency, and number of contributions when opening this savings account.</div>
                            </div>
                        <?php else: ?>
                            <div class="table-responsive">
                                <table class="table table-bordered savings-schedule-table mb-0" data-savings-schedule-table data-export-name="<?php echo e($account->account_number); ?>-savings-schedule">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Date</th>
                                            <th class="text-end">Amount to Save</th>
                                            <th class="text-end">Saved Amount</th>
                                            <th class="text-end">Remaining</th>
                                            <th>Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__currentLoopData = $savingsSchedule; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?php
                                                $label = $statusLabels[$row['status']] ?? ucfirst($row['status']);
                                                $class = $statusClasses[$row['status']] ?? 'text-bg-secondary';
                                            ?>
                                            <tr data-searchable="<?php echo e(strtolower(app_date($row['due_date']).' '.$label.' '.$money($row['expected']).' '.$money($row['paid']))); ?>">
                                                <td><?php echo e($row['period']); ?></td>
                                                <td><?php echo e(app_date($row['due_date'])); ?></td>
                                                <td class="text-end"><?php echo e($money($row['expected'])); ?></td>
                                                <td class="text-end text-success"><?php echo e($money($row['paid'])); ?></td>
                                                <td class="text-end"><?php echo e($money($row['remaining'])); ?></td>
                                                <td><span class="badge <?php echo e($class); ?>"><?php echo e($label); ?></span></td>
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                            </div>
                        <?php endif; ?>
                    </div>

                    <div class="tab-pane fade" id="savings-statement-pane">
                        <div class="table-responsive">
                            <table class="table mb-0 align-middle">
                                <thead><tr><th>Date</th><th>Type</th><th>Reference</th><th>Status</th><th>Initiated by</th><th>Approved by</th><th class="text-end">Amount</th><th class="text-end">Balance</th><th></th></tr></thead>
                                <tbody>
                                    <?php $__empty_1 = true; $__currentLoopData = $account->transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                        <?php
                                            $transactionFee = (float) ($transaction->processing_fee_amount ?? 0);
                                            $transactionNet = (float) ($transaction->net_amount ?? 0);
                                            if ($transactionNet <= 0 && $transactionFee < (float) $transaction->amount) {
                                                $transactionNet = (float) $transaction->amount - $transactionFee;
                                            }
                                        ?>
                                        <tr>
                                            <td><?php echo e(app_datetime($transaction->transacted_at) ?? '-'); ?></td>
                                            <td><?php echo e(ucfirst($transaction->type)); ?></td>
                                            <td><?php echo e($transaction->reference); ?></td>
                                            <td><span class="badge <?php echo e($transactionStatusClasses[$transaction->status ?? 'posted'] ?? 'text-bg-secondary'); ?>"><?php echo e(ucfirst($transaction->status ?? 'posted')); ?></span></td>
                                            <td><?php echo e($transaction->creator?->name ?? 'System / member'); ?></td>
                                            <td>
                                                <?php if(($transaction->status ?? 'posted') === 'canceled'): ?>
                                                    <?php echo e($transaction->canceler?->name ?? 'Canceled'); ?>

                                                <?php else: ?>
                                                    <?php echo e($transaction->approver?->name ?? (($transaction->status ?? 'posted') === 'pending' ? 'Not approved yet' : 'Auto-posted')); ?>

                                                <?php endif; ?>
                                            </td>
                                            <td class="text-end">
                                                <strong><?php echo e($money($transaction->amount)); ?></strong>
                                                <?php if($transactionFee > 0): ?>
                                                    <div class="text-muted small">Fee <?php echo e($money($transactionFee)); ?> | <?php echo e($transaction->type === 'withdrawal' ? 'Net payout' : 'Net saved'); ?> <?php echo e($money($transactionNet)); ?></div>
                                                <?php endif; ?>
                                            </td>
                                            <td class="text-end"><?php echo e($money($transaction->balance_after)); ?></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">
                                                        <?php if($canApproveSavings && $transaction->status === 'pending'): ?>
                                                            <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="collapse" data-bs-target="#savingReject<?php echo e($transaction->id); ?>"><i class="bi bi-x-circle me-2"></i>Reject</button></li>
                                                        <?php elseif(($transaction->status ?? 'posted') === 'posted'): ?>
                                                            <li><a class="dropdown-item" href="<?php echo e(route('tenant.savings.transactions.receipt', $transaction)); ?>"><i class="bi bi-receipt me-2"></i>Receipt</a></li>
                                                            <?php if($canApproveSavings): ?>
                                                                <li><button class="dropdown-item text-danger" type="button" data-bs-toggle="modal" data-bs-target="#cancelSavingsTransaction<?php echo e($transaction->id); ?>"><i class="bi bi-slash-circle me-2"></i>Cancel</button></li>
                                                            <?php endif; ?>
                                                        <?php else: ?>
                                                            <li><span class="dropdown-item-text text-muted small">No action</span></li>
                                                        <?php endif; ?>
                                                    </ul>
                                                </div>
                                                <?php if($canApproveSavings && $transaction->status === 'pending'): ?>
                                                    <form method="POST" action="<?php echo e(route('tenant.savings.transactions.reject', $transaction)); ?>" class="collapse mt-2" id="savingReject<?php echo e($transaction->id); ?>">
                                                        <?php echo csrf_field(); ?>
                                                        <div class="d-flex gap-1">
                                                            <input name="rejected_reason" class="form-control form-control-sm" placeholder="Reason" required>
                                                            <button class="btn btn-sm btn-danger">Submit</button>
                                                        </div>
                                                    </form>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                        <tr><td colspan="9" class="text-center text-muted py-4">No savings transactions yet.</td></tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                        <?php if($canApproveSavings): ?>
                            <?php $__currentLoopData = $account->transactions->where('status', 'posted'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="modal fade" id="cancelSavingsTransaction<?php echo e($transaction->id); ?>" tabindex="-1" aria-labelledby="cancelSavingsTransaction<?php echo e($transaction->id); ?>Label" aria-hidden="true">
                                    <div class="modal-dialog modal-dialog-centered">
                                        <div class="modal-content border-0 shadow">
                                            <form method="POST" action="<?php echo e(route('tenant.savings.transactions.cancel', $transaction)); ?>">
                                                <?php echo csrf_field(); ?>
                                                <div class="modal-header">
                                                    <div>
                                                        <h2 class="modal-title h5" id="cancelSavingsTransaction<?php echo e($transaction->id); ?>Label">Cancel transaction</h2>
                                                        <div class="text-muted small"><?php echo e($transaction->reference); ?> | <?php echo e(ucfirst($transaction->type)); ?> | <?php echo e($money($transaction->amount)); ?></div>
                                                    </div>
                                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                </div>
                                                <div class="modal-body">
                                                    <label class="form-label">Cancellation reason</label>
                                                    <textarea name="canceled_reason" class="form-control" rows="3" required placeholder="Why is this posted transaction being canceled?"></textarea>
                                                    <div class="form-text">The balance and accounting entries will be reversed, while the audit record remains.</div>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Close</button>
                                                    <button class="btn btn-danger">Cancel transaction</button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
.savings-progress-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(280px, .9fr);
    gap: 1rem;
    padding: 1.2rem;
    border-radius: 12px;
    color: #fff;
    background: linear-gradient(135deg, #0f766e, #14532d);
    overflow: hidden;
}
.savings-progress-copy h2 {
    margin: 0;
    font-size: clamp(1.4rem, 2vw, 2.1rem);
}
.savings-progress-copy p {
    max-width: 680px;
    color: rgba(255, 255, 255, .82);
}
.savings-plan-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .75rem;
    margin-top: 1rem;
}
.savings-plan-strip div,
.savings-progress-visual {
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(255, 255, 255, .1);
    border-radius: 8px;
    padding: .8rem;
}
.savings-plan-strip span {
    display: block;
    color: rgba(255, 255, 255, .72);
    font-size: .78rem;
}
.savings-plan-strip strong {
    display: block;
    margin-top: .18rem;
}
.savings-progress-visual {
    display: grid;
    align-items: center;
    justify-items: center;
    gap: 1rem;
}
.savings-progress-ring {
    width: 150px;
    aspect-ratio: 1;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: conic-gradient(#facc15 var(--progress), rgba(255, 255, 255, .22) 0);
}
.savings-progress-ring > div {
    width: 108px;
    aspect-ratio: 1;
    border-radius: 50%;
    display: grid;
    place-items: center;
    align-content: center;
    background: #fff;
    color: #14532d;
}
.savings-progress-ring strong {
    font-size: 1.6rem;
}
.savings-progress-ring span {
    font-size: .78rem;
    color: #64748b;
}
.savings-progress-bar {
    width: 100%;
}
.savings-progress-bar .progress {
    height: 12px;
    background: rgba(255, 255, 255, .22);
}
.savings-progress-bar .progress-bar {
    background: #facc15;
}
.savings-metric-card {
    min-height: 96px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    background: #fff;
    box-shadow: 0 .5rem 1rem rgba(15, 23, 42, .04);
}
.savings-metric-card span {
    display: block;
    color: #64748b;
    font-size: .82rem;
}
.savings-metric-card strong {
    display: block;
    margin-top: .35rem;
    font-size: 1.15rem;
}
.savings-rule-card {
    overflow: hidden;
}
.savings-rule-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, #fff, #f8fafc);
}
.savings-rule-head > span {
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: #ecfdf5;
    color: #0f766e;
    font-size: 1.1rem;
}
.savings-rule-head strong,
.savings-rule-head small {
    display: block;
}
.savings-rule-head strong {
    color: #172033;
    font-weight: 900;
}
.savings-rule-head small {
    color: #64748b;
    font-size: .82rem;
}
.savings-rule-body {
    display: grid;
    gap: 1rem;
    padding: 1rem;
}
.savings-rule-section h3 {
    margin: 0 0 .65rem;
    color: #0f766e;
    font-size: .78rem;
    font-weight: 900;
    text-transform: uppercase;
}
.savings-rule-grid {
    display: grid;
    gap: .65rem;
}
.savings-rule-tile {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: .15rem .65rem;
    align-items: center;
    padding: .75rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
}
.savings-rule-tile i {
    grid-row: span 2;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #f0fdfa;
    color: #0f766e;
}
.savings-rule-tile span {
    color: #64748b;
    font-size: .78rem;
    font-weight: 800;
}
.savings-rule-tile strong {
    color: #172033;
    font-size: .92rem;
    font-weight: 900;
    word-break: break-word;
}
.savings-rule-empty {
    padding: .75rem;
    border-radius: 8px;
    background: #f8fafc;
    color: #64748b;
    font-size: .84rem;
    font-weight: 700;
}
.savings-schedule-table th {
    background: #f8fafc;
    color: #343a40;
    font-weight: 700;
    white-space: nowrap;
}
.savings-schedule-table td {
    vertical-align: middle;
    white-space: nowrap;
}
.schedule-search {
    max-width: 320px;
}
@media (max-width: 991.98px) {
    .savings-progress-hero {
        grid-template-columns: 1fr;
    }
    .savings-plan-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 575.98px) {
    .savings-plan-strip {
        grid-template-columns: 1fr;
    }
}
@media print {
    body * {
        visibility: hidden;
    }
    .savings-schedule-card, .savings-schedule-card * {
        visibility: visible;
    }
    .savings-schedule-card {
        position: absolute;
        inset: 0 auto auto 0;
        width: 100%;
        box-shadow: none !important;
    }
    .schedule-action-btn, .schedule-search, .savings-schedule-card label, .savings-schedule-card .nav {
        display: none !important;
    }
}
</style>

<script>
document.addEventListener('DOMContentLoaded', () => {
    const table = document.querySelector('[data-savings-schedule-table]');
    const search = document.querySelector('[data-savings-schedule-search]');
    const copyButton = document.querySelector('[data-savings-schedule-copy]');
    const excelButton = document.querySelector('[data-savings-schedule-excel]');
    const printButton = document.querySelector('[data-savings-schedule-print]');

    if (!table) return;

    const visibleRows = () => Array.from(table.querySelectorAll('tbody tr'))
        .filter((row) => row.style.display !== 'none');

    const tableMatrix = () => {
        const headers = Array.from(table.querySelectorAll('thead th')).map((cell) => cell.innerText.trim());
        const rows = visibleRows().map((row) => Array.from(row.children).map((cell) => cell.innerText.trim()));

        return [headers, ...rows];
    };

    search?.addEventListener('input', () => {
        const term = search.value.trim().toLowerCase();

        table.querySelectorAll('tbody tr').forEach((row) => {
            row.style.display = !term || row.dataset.searchable.includes(term) ? '' : 'none';
        });
    });

    copyButton?.addEventListener('click', async () => {
        const text = tableMatrix().map((row) => row.join('\t')).join('\n');

        try {
            await navigator.clipboard.writeText(text);
            copyButton.textContent = 'Copied';
            setTimeout(() => copyButton.textContent = 'Copy', 1200);
        } catch (error) {
            const area = document.createElement('textarea');
            area.value = text;
            document.body.appendChild(area);
            area.select();
            document.execCommand('copy');
            area.remove();
        }
    });

    excelButton?.addEventListener('click', () => {
        const csv = tableMatrix()
            .map((row) => row.map((cell) => `"${cell.replaceAll('"', '""')}"`).join(','))
            .join('\n');
        const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
        const link = document.createElement('a');
        link.href = URL.createObjectURL(blob);
        link.download = `${table.dataset.exportName || 'savings-schedule'}.csv`;
        link.click();
        URL.revokeObjectURL(link.href);
    });

    printButton?.addEventListener('click', () => window.print());
});
</script>
<?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/show.blade.php ENDPATH**/ ?>