@extends('layouts.master')

@section('title', 'Trust Account Balance - ' . $trust_account->account_number)

@section('content')
<style>
:root{
    --sky:#0ea5e9;
    --sky-deep:#0369a1;
    --sky-light:#38bdf8;
    --sky-ghost:rgba(14,165,233,.07);
    --sky-border:rgba(14,165,233,.2);
    --ink:#0f172a;
    --ink-mid:#475569;
    --ink-soft:#94a3b8;
    --white:#fff;
    --off:#f7fbff;
    --surface:#eef6fd;
    --border:#daeaf8;
    --amber:#f59e0b;
    --success:#10b981;
    --danger:#ef4444;
    --fd:'Cormorant Garamond',Georgia,serif;
    --fb:'DM Sans',system-ui,sans-serif;
    --fm:'DM Mono',monospace
}
.main-content{background:var(--off);font-family:var(--fb)}
.mt-page{max-width:1200px;margin:0 auto;padding:40px 24px 64px}
.mt-hero{background:linear-gradient(135deg,var(--sky-deep),var(--sky));border-radius:22px;padding:28px 34px;color:#fff;box-shadow:0 10px 28px rgba(14,165,233,.2);margin-bottom:24px}
.mt-hero h1{margin:0;font-family:var(--fd);font-size:36px}
.mt-hero p{margin:6px 0 0;font-size:13px;color:rgba(255,255,255,.85)}
.mt-badge{display:inline-flex;flex-direction:column;align-items:center;background:rgba(255,255,255,.18);border:1px solid rgba(255,255,255,.35);border-radius:16px;padding:20px 24px;gap:4px;text-align:center;min-width:140px}
.mt-badge .val{font-family:var(--fd);font-size:32px;font-weight:700;line-height:1}
.mt-badge .lab{font-size:11px;text-transform:uppercase;letter-spacing:.08em}
.mt-badge.balance-positive .val{color:var(--success)}
.mt-badge.balance-negative .val{color:var(--danger)}
.mt-badge.balance-zero .val{color:var(--ink-soft)}
.mt-toolbar{display:flex;align-items:center;gap:12px;margin:20px 0;flex-wrap:wrap}
.mt-btn{display:inline-flex;align-items:center;gap:7px;padding:10px 18px;border-radius:10px;border:1px solid var(--sky-border);text-decoration:none;font-size:13px;font-weight:600;background:#fff;color:var(--sky-deep)}
.mt-btn.primary{background:linear-gradient(135deg,var(--sky-deep),var(--sky));color:#fff;border-color:var(--sky-deep)}
.mt-table{margin-top:18px;background:#fff;border:1px solid var(--border);border-radius:18px;overflow:hidden;box-shadow:0 6px 20px rgba(14,165,233,.08)}
.mt-head,.mt-row{display:grid;grid-template-columns:1.5fr 1fr 1fr 1fr 1fr 2fr;gap:12px;align-items:center;padding:14px 18px}
.mt-head{background:var(--surface);font-size:10px;font-weight:700;color:var(--ink-soft);text-transform:uppercase;letter-spacing:.1em}
.mt-row{border-top:1px solid var(--border);font-size:13px;color:var(--ink-mid)}
.mt-row:hover{background:var(--sky-ghost)}
.mt-title{font-weight:700;color:var(--ink)}
@media (max-width: 1024px){.mt-head,.mt-row{grid-template-columns:1fr 1fr 1fr 1fr}.mt-head div:nth-child(n+5),.mt-row div:nth-child(n+5){display:none}}
@media (max-width: 768px){.mt-page{padding:24px 14px 40px}.mt-hero{flex-direction:column;align-items:flex-start}}
</style>

<div class="mt-page">
    <nav style="font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--ink-soft);margin-bottom:14px;">
        <a href="{{ route('modules.edit.chart-of-accounts') }}" style="color:var(--ink-soft);text-decoration:none;">Chart of Accounts</a>
        <span>›</span>
        <a href="{{ route('trust-accounts.index') }}" style="color:var(--ink-soft);text-decoration:none;">Trust Accounts</a>
        <span>›</span>
        <span style="color:var(--sky-deep);">{{ $trust_account->account_number }} Balance</span>
    </nav>

    <div class="mt-hero">
        <div>
            <h1>{{ $trust_account->account_number }}</h1>
            <p>Current balance for {{ $trust_account->client?->full_name ?? 'Client' }} trust ledger</p>
        </div>
        <div class="mt-badge {{ $balance > 0 ? 'balance-positive' : ($balance < 0 ? 'balance-negative' : 'balance-zero') }}">
            <div class="val">{{ number_format($balance, 2) }}</div>
            <div class="lab">{{ strtoupper($trust_account->currency ?? 'USD') }}</div>
        </div>
    </div>

    <div class="mt-toolbar">
        <a href="{{ route('trust-accounts.index') }}" class="mt-btn">← Back to Trust Accounts</a>
        <a href="{{ route('trust-accounts.show', $trust_account) }}" class="mt-btn">Full Details</a>
    </div>

    @if($recentEntries->isNotEmpty())
    <div class="mt-table">
        <div class="mt-head">
            <div>Date</div>
            <div>Type</div>
            <div>Description</div>
            <div>Debit</div>
            <div>Credit</div>
            <div>Running Balance</div>
        </div>
        @foreach($recentEntries as $entry)
        <div class="mt-row">
            <div>{{ \Carbon\Carbon::parse($entry->created_at)->format('d M Y') }}</div>
            <div>{{ ucfirst($entry->type ?? 'entry') }}</div>
            <div class="mt-title">{{ $entry->description ?? 'N/A' }}</div>
            <div>{{ number_format((float)($entry->debit ?? 0), 2) }}</div>
            <div>{{ number_format((float)($entry->credit ?? 0), 2) }}</div>
            <div>{{ number_format((float)($entry->running_balance ?? 0), 2) }}</div>
        </div>
        @endforeach
    </div>
    @else
    <div style="background:#fff;border:1px solid var(--border);border-radius:18px;padding:40px;text-align:center;color:var(--ink-soft)">
        No ledger entries found for this trust account.
    </div>
    @endif
</div>
@endsection
