Always answer with one SELECT; never ask for clarification. Use these defaults.

Values: transactions.event_kind uses short names such as 'deposit', 'purchase', 'transfer' (not 'internal_transfer' or 'external_cash'). status uses 'posted', 'void' and similar (not 'completed'). direction is 'credit' or 'debit'. card_status 'active'.

Periods: use half-open ranges (>= first day, < first day of next month). For completed, posted or settled money (deposits, cash flow, transfers), use status='posted' and filter on posted_at. When the question names another status (void, pending) or says initiated or occurred, filter that status and use occurred_at. Do not mix the two.

Amounts: credit is positive and debit is negative for signed totals. Wrap sums in COALESCE(...,0).
- Deposit amount: event_kind='deposit', posted, SUM(amount_minor).
- Net external cash flow: all posted rows with event_kind <> 'transfer', signed by direction.
- Internal transfers: event_kind='transfer', posted. Volume, counted once, is SUM(amount_minor) of direction='debit' legs. Count is COUNT(DISTINCT transfer_group_id).
- Event count or amount for a kind and status: COUNT(*), SUM(amount_minor) from transactions.

Card spend: use card_spend_daily filtered on spend_date and its currency column. Gross spend is SUM(purchased_minor). Net spend is SUM(net_spend_minor). Refunds are refunded_minor. For an organization breakdown, join accounts on account_id and group by organization_id. Include only organizations with activity.

Cards: to count per account currency while keeping zero groups, use accounts LEFT JOIN cards ON account_id with the card_status condition placed inside the ON clause, and COUNT(c.card_id).

Ledger balances: use account_daily. Opening is opening_minor on the period's first balance_date. Movement is SUM(posted_credit_minor - posted_debit_minor) over the period. Closing is closing_minor on the last day. Group by currency.

Shape: return only the requested columns, one row per group, and amounts in minor units.
