{{-- Calendar, upcoming due dates, quick notes --}}
<div class="space-y-6">
    {{-- Live calendar --}}
    <div class="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-sm transition-shadow hover:shadow-md">
        <div class="mb-4 flex items-center justify-between">
            <h3 class="text-base font-bold text-slate-900">Calendar</h3>
            <div class="flex gap-1">
                <button type="button" id="calendar-prev" class="flex h-9 w-9 items-center justify-center rounded-lg text-slate-500 transition-colors hover:bg-slate-100 hover:text-violet-600" aria-label="Previous month">
                    <span class="material-symbols-outlined">chevron_left</span>
                </button>
                <button type="button" id="calendar-next" class="flex h-9 w-9 items-center justify-center rounded-lg text-slate-500 transition-colors hover:bg-slate-100 hover:text-violet-600" aria-label="Next month">
                    <span class="material-symbols-outlined">chevron_right</span>
                </button>
            </div>
        </div>
        <p id="calendar-month-year" class="mb-4 text-center text-sm font-semibold text-slate-800">{{ now()->format('F Y') }}</p>
        <div class="mb-2 grid grid-cols-7 gap-1 text-center text-[10px] font-semibold uppercase tracking-wide text-slate-400 sm:text-xs">
            <span>S</span><span>M</span><span>T</span><span>W</span><span>T</span><span>F</span><span>S</span>
        </div>
        <div id="calendar-days" class="grid grid-cols-7 gap-1 text-center text-sm">
            @php
                $firstDay = now()->startOfMonth()->startOfWeek();
                $lastDay = now()->endOfMonth()->endOfWeek();
                $currentDay = $firstDay->copy();
                $today = now();
            @endphp
            @while ($currentDay <= $lastDay)
                @if ($currentDay->month != now()->month)
                    <span class="flex min-h-[2.25rem] items-center justify-center rounded-xl text-slate-300">{{ $currentDay->day }}</span>
                @elseif ($currentDay->isSameDay($today))
                    <span class="flex min-h-[2.25rem] items-center justify-center rounded-xl bg-violet-600 text-sm font-semibold text-white shadow-md shadow-violet-500/30">{{ $currentDay->day }}</span>
                @else
                    <span class="flex min-h-[2.25rem] items-center justify-center rounded-xl text-slate-800 transition-colors hover:bg-slate-100">{{ $currentDay->day }}</span>
                @endif
                @php $currentDay->addDay(); @endphp
            @endwhile
        </div>
        @if ($upcomingDueInvoices->isNotEmpty())
            <div class="mt-5 border-t border-slate-100 pt-4">
                <p class="mb-2 text-xs font-semibold uppercase tracking-wide text-slate-500">Upcoming due</p>
                <ul class="space-y-2">
                    @foreach ($upcomingDueInvoices as $inv)
                        <li>
                            <a href="{{ route('admin.invoices.show', $inv) }}" class="flex items-center justify-between gap-2 rounded-lg px-2 py-1.5 text-xs transition-colors hover:bg-violet-50">
                                <span class="truncate font-medium text-slate-800">{{ $inv->invoice_number }}</span>
                                <span class="shrink-0 text-slate-500">{{ $inv->due_date?->format('M j') }}</span>
                            </a>
                        </li>
                    @endforeach
                </ul>
            </div>
        @endif
    </div>

    {{-- Quick notes --}}
    <div class="flex flex-col rounded-2xl border border-slate-200/80 bg-white p-5 shadow-sm transition-shadow hover:shadow-md">
        <div class="mb-4 flex items-center justify-between gap-2">
            <div class="flex items-center gap-2">
                <span class="flex h-9 w-9 items-center justify-center rounded-lg bg-amber-100 text-amber-700">
                    <span class="material-symbols-outlined text-[20px]">sticky_note_2</span>
                </span>
                <h3 class="text-base font-bold text-slate-900">Quick notes</h3>
            </div>
        </div>
        <div id="notes-container" class="max-h-[22rem] space-y-2 overflow-y-auto pr-1">
            @forelse ($notes as $note)
                @php
                    $typeLabel = match ($note->type) {
                        'warning' => 'Payment due',
                        'reminder' => 'Reminder',
                        'task' => 'Client task',
                        default => 'Note',
                    };
                    $typeRing = match ($note->type) {
                        'warning' => 'ring-amber-200/80 bg-amber-50/50',
                        'reminder' => 'ring-sky-200/80 bg-sky-50/50',
                        'task' => 'ring-emerald-200/80 bg-emerald-50/50',
                        default => 'ring-slate-200/80 bg-slate-50/80',
                    };
                @endphp
                <div class="note-item group rounded-xl border border-slate-100 p-3 ring-1 {{ $typeRing }} transition-all hover:shadow-sm" data-note-id="{{ $note->id }}">
                    <div class="flex items-start justify-between gap-2">
                        <div class="min-w-0 flex-1">
                            <div class="mb-1 flex flex-wrap items-center gap-2">
                                <span class="rounded-md bg-white/80 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wide text-slate-600 ring-1 ring-slate-200/80">{{ $typeLabel }}</span>
                                @if ($note->is_pinned)
                                    <span class="material-symbols-outlined text-[16px] text-amber-500" title="Pinned">push_pin</span>
                                @endif
                            </div>
                            <p class="font-semibold text-slate-900">{{ $note->title }}</p>
                            <p class="mt-1 line-clamp-2 text-sm text-slate-600">{{ $note->content }}</p>
                            @if ($note->due_date)
                                <span class="mt-2 inline-flex items-center gap-1 rounded-full bg-white/90 px-2 py-0.5 text-xs font-medium text-violet-700 ring-1 ring-violet-200">
                                    <span class="material-symbols-outlined text-[14px]">event</span>
                                    {{ $note->due_date->format('M j, Y') }}
                                </span>
                            @endif
                        </div>
                        <div class="flex shrink-0 gap-0.5 opacity-70 transition-opacity group-hover:opacity-100">
                            <button type="button" class="edit-note rounded-lg p-1.5 text-slate-400 hover:bg-white hover:text-violet-600" data-note-id="{{ $note->id }}" title="Edit">
                                <span class="material-symbols-outlined text-[18px]">edit</span>
                            </button>
                            <button type="button" class="delete-note rounded-lg p-1.5 text-slate-400 hover:bg-white hover:text-rose-600" data-note-id="{{ $note->id }}" title="Delete">
                                <span class="material-symbols-outlined text-[18px]">delete</span>
                            </button>
                        </div>
                    </div>
                </div>
            @empty
                <div class="rounded-xl border border-dashed border-slate-200 bg-slate-50/50 py-10 text-center">
                    <span class="material-symbols-outlined mb-2 text-4xl text-slate-300">note_add</span>
                    <p class="text-sm text-slate-500">No notes yet</p>
                    <p class="mt-1 text-xs text-slate-400">Capture reminders and follow-ups</p>
                </div>
            @endforelse
        </div>
        <button type="button" id="add-note-btn" class="mt-4 flex w-full items-center justify-center gap-2 rounded-xl border border-dashed border-slate-300 py-2.5 text-sm font-semibold text-slate-600 transition-colors hover:border-violet-400 hover:bg-violet-50/50 hover:text-violet-700">
            <span class="material-symbols-outlined text-[20px]">add</span>
            Add note
        </button>
    </div>
</div>
