<?php if (isset($component)) { $__componentOriginale0f1cdd055772eb1d4a99981c240763e = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginale0f1cdd055772eb1d4a99981c240763e = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.admin-layout','data' => ['title' => 'Financeiro — OPCON']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('admin-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Financeiro — OPCON']); ?>

<div x-data="financeiroApp()" x-init="init()">

    
    <div style="display:flex; align-items:flex-start; justify-content:space-between; gap:1rem; margin-bottom:1.5rem; flex-wrap:wrap;">
        <div>
            <h1 style="font-size:1.375rem; font-weight:700; color:#1e3a5f; margin:0;">Financeiro</h1>
            <p style="font-size:0.8125rem; color:#64748b; margin:0.25rem 0 0;">Controle de cobranças mensais e honorários</p>
        </div>
        <div style="display:flex; gap:0.5rem; flex-wrap:wrap;">
            <button @click="openGerar()"
                    style="display:inline-flex; align-items:center; gap:0.5rem; padding:0.5rem 1rem; border:1px solid #e2e8f0; background:#fff; color:#1e3a5f; border-radius:9px; font-size:0.875rem; font-weight:600; cursor:pointer; font-family:inherit; transition:all 0.15s;"
                    onmouseover="this.style.background='#f8fafc'" onmouseout="this.style.background='#fff'">
                <svg style="width:15px;height:15px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
                Gerar cobranças do mês
            </button>
            <button @click="openCreate()"
                    style="display:inline-flex; align-items:center; gap:0.5rem; padding:0.5rem 1.125rem; background:#1e3a5f; color:#fff; border:none; border-radius:9px; font-size:0.875rem; font-weight:600; cursor:pointer; font-family:inherit; transition:background 0.15s;"
                    onmouseover="this.style.background='#162d4a'" onmouseout="this.style.background='#1e3a5f'">
                <svg style="width:15px;height:15px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
                Nova cobrança
            </button>
        </div>
    </div>

    
    <div style="display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:1rem; margin-bottom:1.5rem;">
        <?php
            $kpis = [
                ['label' => 'Faturado este mês', 'value' => 'R$ '.number_format($stats['total_mes'],2,',','.'),  'bg' => '#f0fdf4', 'color' => '#25b87e', 'icon' => 'M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z'],
                ['label' => 'Recebido este mês', 'value' => 'R$ '.number_format($stats['recebido_mes'],2,',','.'), 'bg' => '#eff6ff', 'color' => '#2563eb', 'icon' => 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z'],
                ['label' => 'A receber',          'value' => 'R$ '.number_format($stats['a_receber'],2,',','.'),   'bg' => '#fffbeb', 'color' => '#d97706', 'icon' => 'M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z'],
                ['label' => 'Vencidas',            'value' => $stats['vencidas'] . ' cobranças',                   'bg' => $stats['vencidas'] > 0 ? '#fef2f2' : '#f8fafc', 'color' => $stats['vencidas'] > 0 ? '#dc2626' : '#94a3b8', 'icon' => 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z'],
            ];
        ?>
        <?php $__currentLoopData = $kpis; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kpi): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.125rem;">
            <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:0.625rem;">
                <span style="font-size:0.6875rem; font-weight:700; color:#64748b; text-transform:uppercase; letter-spacing:0.05em;"><?php echo e($kpi['label']); ?></span>
                <div style="width:32px; height:32px; border-radius:9px; background:<?php echo e($kpi['bg']); ?>; display:flex; align-items:center; justify-content:center;">
                    <svg style="width:15px;height:15px;color:<?php echo e($kpi['color']); ?>;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.75" d="<?php echo e($kpi['icon']); ?>"/>
                    </svg>
                </div>
            </div>
            <p style="font-size:1.25rem; font-weight:800; color:#1e3a5f; margin:0;"><?php echo e($kpi['value']); ?></p>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    
    <form method="GET" action="<?php echo e(route('admin.financeiro.index')); ?>"
          style="background:#fff; border-radius:14px; border:1px solid #e2e8f0; padding:0.875rem 1.25rem; margin-bottom:1.25rem; display:flex; flex-wrap:wrap; gap:0.75rem; align-items:flex-end;">
        <div style="flex:1; min-width:130px;">
            <label style="display:block; font-size:0.75rem; font-weight:600; color:#374151; margin-bottom:0.25rem;">Mês</label>
            <input type="month" name="mes" value="<?php echo e(request('mes')); ?>"
                   style="width:100%; padding:0.5rem 0.75rem; border:1px solid #e2e8f0; border-radius:8px; font-size:0.875rem; font-family:inherit; outline:none; box-sizing:border-box;">
        </div>
        <div style="flex:2; min-width:160px;">
            <label style="display:block; font-size:0.75rem; font-weight:600; color:#374151; margin-bottom:0.25rem;">Contrato</label>
            <select name="contrato_id" style="width:100%; padding:0.5rem 0.75rem; border:1px solid #e2e8f0; border-radius:8px; font-size:0.875rem; font-family:inherit; outline:none; background:#fff;">
                <option value="">Todos</option>
                <?php $__currentLoopData = $contratos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($c->id); ?>" <?php echo e(request('contrato_id') == $c->id ? 'selected' : ''); ?>><?php echo e($c->razao_social); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
        <div style="flex:1; min-width:130px;">
            <label style="display:block; font-size:0.75rem; font-weight:600; color:#374151; margin-bottom:0.25rem;">Status</label>
            <select name="status" style="width:100%; padding:0.5rem 0.75rem; border:1px solid #e2e8f0; border-radius:8px; font-size:0.875rem; font-family:inherit; outline:none; background:#fff;">
                <option value="">Todos</option>
                <option value="pendente" <?php echo e(request('status') === 'pendente' ? 'selected' : ''); ?>>Pendente</option>
                <option value="pago"     <?php echo e(request('status') === 'pago'     ? 'selected' : ''); ?>>Pago</option>
                <option value="vencido"  <?php echo e(request('status') === 'vencido'  ? 'selected' : ''); ?>>Vencido</option>
            </select>
        </div>
        <div style="display:flex; gap:0.5rem;">
            <button type="submit" style="padding:0.5rem 1rem; background:#1e3a5f; color:#fff; border:none; border-radius:8px; font-size:0.875rem; font-weight:600; cursor:pointer; font-family:inherit; white-space:nowrap;">Filtrar</button>
            <?php if(request()->hasAny(['mes','contrato_id','status'])): ?>
                <a href="<?php echo e(route('admin.financeiro.index')); ?>" style="padding:0.5rem 0.875rem; border:1px solid #e2e8f0; border-radius:8px; font-size:0.875rem; color:#64748b; text-decoration:none; background:#fff;">Limpar</a>
            <?php endif; ?>
        </div>
    </form>

    
    <div style="background:#fff; border-radius:16px; border:1px solid #e2e8f0; overflow:hidden;">
        <?php if($cobrancas->isEmpty()): ?>
            <div style="padding:3rem; text-align:center;">
                <div style="font-size:2.5rem; margin-bottom:0.75rem;">💰</div>
                <p style="font-size:0.9375rem; font-weight:600; color:#1e3a5f; margin:0 0 0.5rem;">Nenhuma cobrança encontrada</p>
                <p style="font-size:0.8125rem; color:#94a3b8; margin:0;">Clique em "Gerar cobranças do mês" para criar automaticamente.</p>
            </div>
        <?php else: ?>
        <div style="overflow-x:auto;">
            <table style="width:100%; border-collapse:collapse; font-size:0.8125rem;">
                <thead>
                    <tr style="background:#f8fafc; border-bottom:1px solid #e2e8f0;">
                        <th style="padding:0.75rem 1.25rem; text-align:left; font-size:0.6875rem; font-weight:700; text-transform:uppercase; letter-spacing:0.05em; color:#94a3b8; white-space:nowrap;">Contrato</th>
                        <th style="padding:0.75rem 1rem; text-align:left; font-size:0.6875rem; font-weight:700; text-transform:uppercase; letter-spacing:0.05em; color:#94a3b8;">Referência</th>
                        <th style="padding:0.75rem 1rem; text-align:right; font-size:0.6875rem; font-weight:700; text-transform:uppercase; letter-spacing:0.05em; color:#94a3b8;">Valor</th>
                        <th style="padding:0.75rem 1rem; text-align:left; font-size:0.6875rem; font-weight:700; text-transform:uppercase; letter-spacing:0.05em; color:#94a3b8;">Status</th>
                        <th style="padding:0.75rem 1rem; text-align:left; font-size:0.6875rem; font-weight:700; text-transform:uppercase; letter-spacing:0.05em; color:#94a3b8; white-space:nowrap;">Pago em</th>
                        <th style="padding:0.75rem 1rem; width:80px;"></th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $cobrancas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cob): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $sc = ['pendente' => ['bg'=>'#fffbeb','color'=>'#d97706'], 'pago' => ['bg'=>'#f0fdf4','color'=>'#16a34a'], 'vencido' => ['bg'=>'#fef2f2','color'=>'#dc2626']][$cob->status];
                    ?>
                    <tr style="border-bottom:1px solid #f8fafc;" onmouseover="this.style.background='#fafbfc'" onmouseout="this.style.background='transparent'">
                        <td style="padding:0.75rem 1.25rem;">
                            <p style="font-size:0.875rem; font-weight:600; color:#1e3a5f; margin:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:200px;">
                                <?php echo e($cob->contrato?->razao_social ?? '—'); ?>

                            </p>
                            <?php if($cob->contrato?->cnpj): ?>
                                <p style="font-size:0.6875rem; color:#94a3b8; margin:0;"><?php echo e($cob->contrato->cnpj); ?></p>
                            <?php endif; ?>
                        </td>
                        <td style="padding:0.75rem 1rem; color:#374151; white-space:nowrap;"><?php echo e($cob->mes_referencia->format('m/Y')); ?></td>
                        <td style="padding:0.75rem 1rem; text-align:right; font-weight:700; color:#1e3a5f; white-space:nowrap;">R$ <?php echo e(number_format($cob->valor, 2, ',', '.')); ?></td>
                        <td style="padding:0.75rem 1rem;">
                            <span style="display:inline-block; padding:0.2rem 0.625rem; border-radius:100px; font-size:0.75rem; font-weight:700; background:<?php echo e($sc['bg']); ?>; color:<?php echo e($sc['color']); ?>; text-transform:capitalize;">
                                <?php echo e($cob->status); ?>

                            </span>
                        </td>
                        <td style="padding:0.75rem 1rem; color:#64748b; white-space:nowrap; font-size:0.8125rem;">
                            <?php echo e($cob->pago_em ? $cob->pago_em->format('d/m/Y') : '—'); ?>

                        </td>
                        <td style="padding:0.75rem 1rem; text-align:right;">
                            <div style="display:flex; gap:0.375rem; justify-content:flex-end;">
                                <?php if($cob->status !== 'pago'): ?>
                                <button @click="marcarPago(<?php echo e($cob->id); ?>, $el)"
                                        style="padding:0.3rem 0.625rem; background:#f0fdf4; color:#16a34a; border:1px solid #bbf7d0; border-radius:7px; font-size:0.75rem; font-weight:600; cursor:pointer; font-family:inherit; transition:all 0.15s; white-space:nowrap;">
                                    Marcar pago
                                </button>
                                <?php endif; ?>
                                <button @click="deletar(<?php echo e($cob->id); ?>, $el)"
                                        style="padding:0.3rem 0.5rem; background:#fff; color:#94a3b8; border:1px solid #e2e8f0; border-radius:7px; font-size:0.75rem; cursor:pointer; font-family:inherit; transition:all 0.15s;"
                                        onmouseover="this.style.color='#ef4444'; this.style.borderColor='#fecaca'"
                                        onmouseout="this.style.color='#94a3b8'; this.style.borderColor='#e2e8f0'">
                                    <svg style="width:12px;height:12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
                                </button>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>
        <?php if($cobrancas->hasPages()): ?>
            <div style="padding:0.875rem 1.25rem; border-top:1px solid #f1f5f9; display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:0.5rem;">
                <p style="font-size:0.8125rem; color:#94a3b8; margin:0;"><?php echo e($cobrancas->firstItem()); ?>–<?php echo e($cobrancas->lastItem()); ?> de <?php echo e($cobrancas->total()); ?></p>
                <div style="display:flex; gap:0.25rem;">
                    <?php if(!$cobrancas->onFirstPage()): ?>
                        <a href="<?php echo e($cobrancas->previousPageUrl()); ?>" style="padding:0.375rem 0.75rem; border:1px solid #e2e8f0; border-radius:7px; font-size:0.8125rem; color:#64748b; text-decoration:none;">← Anterior</a>
                    <?php endif; ?>
                    <?php if($cobrancas->hasMorePages()): ?>
                        <a href="<?php echo e($cobrancas->nextPageUrl()); ?>" style="padding:0.375rem 0.75rem; border:1px solid #e2e8f0; border-radius:7px; font-size:0.8125rem; color:#64748b; text-decoration:none;">Próximo →</a>
                    <?php endif; ?>
                </div>
            </div>
        <?php endif; ?>
        <?php endif; ?>
    </div>

    
    <div x-show="modal"
         x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100"
         x-transition:leave="transition ease-in duration-150"  x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0"
         @keydown.escape.window="modal=false"
         style="position:fixed; inset:0; z-index:200; background:rgba(15,23,42,0.5); backdrop-filter:blur(3px);">
        <div style="display:flex; align-items:center; justify-content:center; min-height:100%; width:100%; padding:1rem;">
        <div @click.stop
             x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0 scale-95" x-transition:enter-end="opacity-100 scale-100"
             style="background:#fff; border-radius:20px; width:100%; max-width:440px; overflow:hidden; box-shadow:0 32px 80px rgba(0,0,0,0.22); display:flex; flex-direction:column;">
            <div style="background:linear-gradient(135deg,#1e3a5f 0%,#162e4a 100%); padding:1.25rem 1.375rem; display:flex; align-items:center; justify-content:space-between;">
                <div>
                    <h3 style="font-size:1.0625rem; font-weight:700; color:#fff; margin:0 0 2px;">Nova cobrança</h3>
                    <p style="font-size:0.75rem; color:rgba(255,255,255,0.45); margin:0;">Preencha os dados da cobrança</p>
                </div>
                <button @click="modal=false" style="width:30px;height:30px;border-radius:7px;border:1px solid rgba(255,255,255,0.15);background:rgba(255,255,255,0.08);color:rgba(255,255,255,0.6);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.15s;"
                        onmouseover="this.style.background='rgba(255,255,255,0.15)'" onmouseout="this.style.background='rgba(255,255,255,0.08)'">
                    <svg style="width:13px;height:13px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                </button>
            </div>
            <form @submit.prevent="saveCobranca()" style="padding:1.375rem; background:#f8fafc; flex:1; display:flex; flex-direction:column; gap:1rem;">
                <div>
                    <label class="mlabel">Contrato *</label>
                    <select x-model="form.contrato_id" required class="minput" style="background:#fff;">
                        <option value="">Selecionar contrato...</option>
                        <?php $__currentLoopData = $contratos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($c->id); ?>"><?php echo e($c->razao_social); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div style="display:grid; grid-template-columns:1fr 1fr; gap:0.875rem;">
                    <div>
                        <label class="mlabel">Mês de referência *</label>
                        <input x-model="form.mes_referencia" type="month" required class="minput">
                    </div>
                    <div>
                        <label class="mlabel">Valor (R$) *</label>
                        <input x-model="form.valor" type="number" min="0" step="0.01" required class="minput" placeholder="0,00">
                    </div>
                </div>
                <div>
                    <label class="mlabel">Observações</label>
                    <textarea x-model="form.observacoes" rows="2" class="minput" style="resize:vertical;"></textarea>
                </div>
                <div x-show="errMsg" x-text="errMsg" style="font-size:0.8125rem;color:#dc2626;padding:0.625rem 0.875rem;background:#fef2f2;border-radius:10px;border:1.5px solid #fecaca;"></div>
                <div style="display:flex; gap:0.625rem; justify-content:flex-end; padding-top:0.375rem; border-top:1.5px solid #eef2f7;">
                    <button type="button" @click="modal=false"
                            style="padding:0.625rem 1rem;border:1.5px solid #e2e8f0;border-radius:10px;font-size:0.875rem;color:#64748b;background:#fff;cursor:pointer;font-family:inherit;transition:all 0.15s;"
                            onmouseover="this.style.background='#f8fafc'; this.style.borderColor='#cbd5e1'" onmouseout="this.style.background='#fff'; this.style.borderColor='#e2e8f0'">Cancelar</button>
                    <button type="submit" :disabled="saving"
                            style="padding:0.625rem 1.375rem;background:#1e3a5f;color:#fff;border:none;border-radius:10px;font-size:0.875rem;font-weight:600;cursor:pointer;font-family:inherit;transition:background 0.15s;"
                            onmouseover="if(!this.disabled)this.style.background='#162d4a'" onmouseout="if(!this.disabled)this.style.background='#1e3a5f'">
                        <span x-text="saving ? 'Salvando...' : 'Criar cobrança'"></span>
                    </button>
                </div>
            </form>
        </div>
        </div>
    </div>

    
    <div x-show="modalGerar"
         x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100"
         x-transition:leave="transition ease-in duration-150"  x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0"
         @keydown.escape.window="modalGerar=false"
         style="position:fixed; inset:0; z-index:200; background:rgba(15,23,42,0.5); backdrop-filter:blur(3px);">
        <div style="display:flex; align-items:center; justify-content:center; min-height:100%; width:100%; padding:1rem;">
        <div @click.stop
             x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0 scale-95" x-transition:enter-end="opacity-100 scale-100"
             style="background:#fff; border-radius:20px; width:100%; max-width:400px; overflow:hidden; box-shadow:0 32px 80px rgba(0,0,0,0.22); display:flex; flex-direction:column;">
            <div style="background:linear-gradient(135deg,#1e3a5f 0%,#162e4a 100%); padding:1.25rem 1.375rem; display:flex; align-items:center; justify-content:space-between;">
                <div>
                    <h3 style="font-size:1.0625rem; font-weight:700; color:#fff; margin:0 0 2px;">Gerar cobranças automáticas</h3>
                    <p style="font-size:0.75rem; color:rgba(255,255,255,0.45); margin:0;">Para todos os contratos ativos</p>
                </div>
                <button @click="modalGerar=false" style="width:32px;height:32px;border-radius:8px;border:1px solid rgba(255,255,255,0.15);background:rgba(255,255,255,0.08);color:rgba(255,255,255,0.6);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.15s;"
                        onmouseover="this.style.background='rgba(255,255,255,0.15)'" onmouseout="this.style.background='rgba(255,255,255,0.08)'">
                    <svg style="width:13px;height:13px;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                </button>
            </div>
            <div style="padding:1.375rem; background:#f8fafc; flex:1; display:flex; flex-direction:column; gap:1rem;">
                <p style="font-size:0.875rem; color:#64748b; margin:0; line-height:1.55;">Gera cobranças para todos os contratos <strong style="color:#1e3a5f;">Ativos</strong> com honorário definido. Cobranças existentes não são duplicadas.</p>
                <div>
                    <label class="mlabel">Mês de referência</label>
                    <input x-model="mesgerar" type="month" class="minput">
                </div>
                <div x-show="gerarMsg" x-text="gerarMsg" style="font-size:0.8125rem;padding:0.625rem 0.875rem;background:#f0fdf4;color:#16a34a;border-radius:10px;border:1.5px solid #bbf7d0;"></div>
                <div style="display:flex; gap:0.625rem; justify-content:flex-end; padding-top:0.375rem; border-top:1.5px solid #eef2f7;">
                    <button type="button" @click="modalGerar=false"
                            style="padding:0.625rem 1rem;border:1.5px solid #e2e8f0;border-radius:10px;font-size:0.875rem;color:#64748b;background:#fff;cursor:pointer;font-family:inherit;transition:all 0.15s;"
                            onmouseover="this.style.background='#f8fafc'; this.style.borderColor='#cbd5e1'" onmouseout="this.style.background='#fff'; this.style.borderColor='#e2e8f0'">Cancelar</button>
                    <button @click="gerarMes()" :disabled="gerandoMes"
                            style="padding:0.625rem 1.375rem;background:#25b87e;color:#fff;border:none;border-radius:10px;font-size:0.875rem;font-weight:600;cursor:pointer;font-family:inherit;transition:background 0.15s;box-shadow:0 2px 8px rgba(37,184,126,0.3);"
                            :style="gerandoMes ? 'opacity:0.7;' : ''"
                            onmouseover="if(!this.disabled)this.style.background='#1fa96e'" onmouseout="if(!this.disabled)this.style.background='#25b87e'">
                        <span x-text="gerandoMes ? 'Gerando...' : 'Gerar cobranças'"></span>
                    </button>
                </div>
            </div>
        </div>
        </div>
    </div>
</div>

<script>
function financeiroApp() {
    return {
        modal: false, modalGerar: false,
        saving: false, gerandoMes: false,
        errMsg: '', gerarMsg: '',
        mesgerar: '<?php echo e(now()->format("Y-m")); ?>',
        form: { contrato_id: '', mes_referencia: '<?php echo e(now()->format("Y-m")); ?>', valor: '', observacoes: '' },

        init() {},
        openCreate() { this.form = { contrato_id: '', mes_referencia: '<?php echo e(now()->format("Y-m")); ?>', valor: '', observacoes: '' }; this.errMsg = ''; this.modal = true; },
        openGerar()  { this.gerarMsg = ''; this.modalGerar = true; },

        async saveCobranca() {
            this.saving = true; this.errMsg = '';
            try {
                const res  = await fetch('/admin/financeiro', {
                    method: 'POST',
                    headers: { 'Content-Type':'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content, 'Accept':'application/json' },
                    body: JSON.stringify(this.form)
                });
                const data = await res.json();
                if (data.ok) { this.modal = false; window.location.reload(); }
                else { this.errMsg = data.errors ? Object.values(data.errors).flat().join(' ') : 'Erro ao salvar.'; }
            } catch(e) { this.errMsg = 'Erro de conexão.'; }
            finally { this.saving = false; }
        },

        async marcarPago(id) {
            if (!confirm('Marcar esta cobrança como paga?')) return;
            await fetch(`/admin/financeiro/${id}/pago`, {
                method: 'PATCH',
                headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content, 'Accept': 'application/json' }
            });
            window.location.reload();
        },

        async deletar(id) {
            if (!confirm('Excluir esta cobrança?')) return;
            await fetch(`/admin/financeiro/${id}`, {
                method: 'DELETE',
                headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content, 'Accept': 'application/json' }
            });
            window.location.reload();
        },

        async gerarMes() {
            this.gerandoMes = true; this.gerarMsg = '';
            try {
                const res  = await fetch('/admin/financeiro/gerar', {
                    method: 'POST',
                    headers: { 'Content-Type':'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content, 'Accept':'application/json' },
                    body: JSON.stringify({ mes: this.mesgerar })
                });
                const data = await res.json();
                this.gerarMsg = `${data.criadas} cobranças criadas!`;
                setTimeout(() => { this.modalGerar = false; window.location.reload(); }, 1200);
            } catch(e) {}
            finally { this.gerandoMes = false; }
        },
    };
}
</script>

<style>
.mlabel { display:block; font-size:0.75rem; font-weight:600; color:#475569; margin-bottom:0.375rem; letter-spacing:0.01em; }
.minput { width:100%; padding:0.675rem 0.875rem; border:1.5px solid #e2e8f0; border-radius:10px; font-size:0.875rem; font-family:inherit; color:#1e3a5f; outline:none; box-sizing:border-box; background:#fff; transition:border-color 0.15s, box-shadow 0.15s; }
.minput:focus { border-color:#25b87e; box-shadow:0 0 0 3px rgba(37,184,126,0.12); }
.minput::placeholder { color:#c8d3de; }
</style>

 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginale0f1cdd055772eb1d4a99981c240763e)): ?>
<?php $attributes = $__attributesOriginale0f1cdd055772eb1d4a99981c240763e; ?>
<?php unset($__attributesOriginale0f1cdd055772eb1d4a99981c240763e); ?>
<?php endif; ?>
<?php if (isset($__componentOriginale0f1cdd055772eb1d4a99981c240763e)): ?>
<?php $component = $__componentOriginale0f1cdd055772eb1d4a99981c240763e; ?>
<?php unset($__componentOriginale0f1cdd055772eb1d4a99981c240763e); ?>
<?php endif; ?>
<?php /**PATH C:\ProjetosWeb\OPCON\resources\views\pages\admin\financeiro.blade.php ENDPATH**/ ?>