<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>@yield('title', 'Internet Banking') — {{ platform_name() }}</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Source+Sans+3:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>body { margin: 0; font-family: "Source Sans 3", system-ui, sans-serif; }</style>
    <link rel="icon" href="{{ platform_logo('favicon') }}" type="image/svg+xml">
    <link rel="stylesheet" href="{{ asset('css/fundi.css') }}">
</head>
<body>
@php
    $portalCustomer = \App\Models\Customer::find(session('portal_customer_id'));
    $currentRoute = request()->route()?->getName() ?? '';
    $navItems = \App\Models\NavigationMenu::forLocation('portal');
@endphp
<div class="fundi-portal">
    <header class="fundi-portal-header">
        <div class="fundi-portal-header__inner">
            <div class="fundi-portal-brand">
                <x-brand-logo variant="light" size="sm" taglineText="Internet Banking" />
            </div>
            <nav>
                <ul class="fundi-portal-nav">
                    @foreach($navItems as $item)
                        <li>
                            <a href="{{ $item->href() }}" class="{{ $item->isActive($currentRoute) ? 'active' : '' }}"
                               @if($item->open_in_new_tab) target="_blank" rel="noopener" @endif>
                                {{ $item->label }}
                            </a>
                        </li>
                    @endforeach
                    <li>
                        <form method="POST" action="{{ route('portal.logout') }}" style="display:inline;">
                            @csrf
                            <button type="submit" class="fundi-btn fundi-btn--ghost fundi-btn--sm">Logout</button>
                        </form>
                    </li>
                </ul>
            </nav>
        </div>
    </header>

    <div class="fundi-portal-body">
        @if($portalCustomer)
            <p class="text-muted mb-0" style="margin-bottom:1rem;font-size:0.875rem;">
                Welcome, <strong>{{ $portalCustomer->display_name }}</strong>
                · {{ $portalCustomer->customer_no }}
            </p>
        @endif

        @if(session('success'))
            <div class="fundi-alert fundi-alert--success">{{ session('success') }}</div>
        @endif
        @if($errors->any())
            <div class="fundi-alert fundi-alert--error">
                <ul>
                    @foreach($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        @yield('content')
    </div>
</div>
@stack('scripts')
</body>
</html>
