<!DOCTYPE html>
<html lang="id">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard Admin - PCR Health</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght=400;600;700;800&display=swap');
        body { font-family: 'Plus Jakarta Sans', sans-serif; }
        .line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    </style>
</head>

<body class="bg-slate-50 text-slate-800 antialiased">

    <nav class="bg-white/80 backdrop-blur-md shadow-sm border-b border-slate-200 sticky top-0 z-50">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16 items-center">
                <div class="flex items-center gap-3">
                    <div class="bg-blue-600 p-2 rounded-xl text-white shadow-lg shadow-blue-200">
                        <i class="fas fa-user-shield text-sm md:text-base"></i>
                    </div>
                    <div>
                        <h1 class="text-base md:text-xl font-extrabold tracking-tight">
                            PCR<span class="text-blue-600">Admin</span>
                        </h1>
                        <p class="hidden sm:block text-[10px] text-slate-400 font-bold uppercase tracking-widest">
                            Management Dashboard
                        </p>
                    </div>
                </div>

                <div class="flex items-center gap-2 md:gap-4">
                    <div class="hidden sm:flex flex-col text-right">
                        <span class="text-xs font-bold text-slate-700 leading-none">Administrator</span>
                        <span class="text-[10px] text-green-500 font-bold uppercase tracking-tighter mt-0.5">Online</span>
                    </div>
                    <form action="{{ route('logout') }}" method="POST">
                        @csrf
                        <button type="submit" class="bg-red-50 text-red-600 p-2 md:px-4 md:py-2 rounded-xl text-xs font-bold hover:bg-red-600 hover:text-white transition-all flex items-center gap-2">
                            <i class="fas fa-sign-out-alt"></i>
                            <span class="hidden md:inline">Keluar</span>
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </nav>

    <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6 md:py-10">

        <div class="mb-8 text-center md:text-left">
            <h2 class="text-2xl md:text-4xl font-extrabold text-slate-900 tracking-tight">
                Ringkasan Data <span class="text-blue-600 italic">PCR Health</span>
            </h2>
            <p class="text-sm md:text-base text-slate-500 mt-1">
                Pantau statistik keteraturan makan mahasiswa secara real-time.
            </p>
        </div>

        <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 md:gap-6 mb-8">
            <div class="bg-white rounded-3xl p-5 shadow-sm border border-slate-100 flex items-center gap-4">
                <div class="bg-blue-500 text-white p-4 rounded-2xl shadow-lg shadow-blue-100">
                    <i class="fas fa-users text-xl"></i>
                </div>
                <div>
                    <p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest">Total Data</p>
                    <h3 class="text-2xl font-black text-slate-800 leading-none">{{ $total }}</h3>
                </div>
            </div>

            <div class="bg-white rounded-3xl p-5 shadow-sm border border-slate-100 flex items-center gap-4">
                <div class="bg-green-500 text-white p-4 rounded-2xl shadow-lg shadow-green-100">
                    <i class="fas fa-check text-xl"></i>
                </div>
                <div>
                    <p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest text-green-600">Teratur</p>
                    <h3 class="text-2xl font-black text-slate-800 leading-none">{{ $teratur }}</h3>
                </div>
            </div>

            <div class="bg-white rounded-3xl p-5 shadow-sm border border-slate-100 flex items-center gap-4">
                <div class="bg-yellow-500 text-white p-4 rounded-2xl shadow-lg shadow-yellow-100">
                    <i class="fas fa-clock text-xl"></i>
                </div>
                <div>
                    <p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest text-yellow-600">Terlewat</p>
                    <h3 class="text-2xl font-black text-slate-800 leading-none">{{ $terlewat }}</h3>
                </div>
            </div>

            <div class="bg-white rounded-3xl p-5 shadow-sm border border-slate-100 flex items-center gap-4">
                <div class="bg-red-500 text-white p-4 rounded-2xl shadow-lg shadow-red-100">
                    <i class="fas fa-times text-xl"></i>
                </div>
                <div>
                    <p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest text-red-600">Berantakan</p>
                    <h3 class="text-2xl font-black text-slate-800 leading-none">{{ $berantakan }}</h3>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-3xl p-5 md:p-6 shadow-sm border border-slate-100 mb-8">
            <form method="GET" class="flex flex-col md:flex-row gap-4">
                <div class="flex-1 relative">
                    <i class="fas fa-search absolute left-4 top-1/2 -translate-y-1/2 text-slate-400"></i>
                    <input type="text" name="search" value="{{ request('search') }}" placeholder="Cari Nama atau NIM..."
                        class="w-full pl-11 pr-4 py-3 rounded-2xl bg-slate-50 border-none focus:ring-2 focus:ring-blue-500 outline-none transition text-sm">
                </div>
                <select name="hasil" class="md:w-48 px-4 py-3 rounded-2xl bg-slate-50 border-none focus:ring-2 focus:ring-blue-500 outline-none text-sm font-semibold">
                    <option value="">Semua Kategori</option>
                    <option value="Teratur" {{ request('hasil') == 'Teratur' ? 'selected' : '' }}>Teratur</option>
                    <option value="Sering Terlewat" {{ request('hasil') == 'Sering Terlewat' ? 'selected' : '' }}>Sering Terlewat</option>
                    <option value="Berantakan" {{ request('hasil') == 'Berantakan' ? 'selected' : '' }}>Berantakan</option>
                </select>
                <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-8 py-3 rounded-2xl font-bold transition shadow-xl shadow-blue-100">
                    Filter Data
                </button>
            </form>
        </div>

        <div class="hidden lg:block bg-white rounded-3xl shadow-sm border border-slate-100 overflow-hidden">
            <table class="w-full text-left border-collapse">
                <thead>
                    <tr class="bg-slate-50/50 border-b border-slate-100 text-[10px] font-black uppercase text-slate-400 tracking-widest">
                        <th class="px-6 py-4">Nama Mahasiswa</th>
                        <th class="px-6 py-4 text-center">Indikator</th>
                        <th class="px-6 py-4">AI Recommendation</th>
                        <th class="px-6 py-4 text-center">Status</th>
                        <th class="px-6 py-4 text-right">Tanggal</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    @forelse($data as $item)
                    <tr class="hover:bg-blue-50/30 transition-all">
                        <td class="px-6 py-4">
                            <div>
                                <p class="font-bold text-slate-800 text-sm leading-none mb-1.5">{{ $item->nama }}</p>
                                <p class="text-[10px] text-slate-400 font-mono italic">{{ $item->nim }}</p>
                            </div>
                        </td>
                        <td class="px-6 py-4">
                            <div class="flex flex-col gap-1 items-center">
                                <span class="bg-blue-50 text-blue-700 px-2 py-0.5 rounded-lg text-[9px] font-black italic">Rutin: {{ $item->skor_rutinitas }}/5</span>
                                <span class="bg-slate-50 text-slate-500 px-2 py-0.5 rounded-lg text-[9px] font-black italic">Skip: {{ $item->frekuensi_skip }}</span>
                            </div>
                        </td>
                        <td class="px-6 py-4">
                            <div class="max-w-xs">
                                <p class="text-[11px] text-slate-600 italic line-clamp-2 leading-relaxed">
                                    "{{ $item->rekomendasi ?? 'Data input pola makan sudah terekam di sistem.' }}"
                                </p>
                            </div>
                        </td>
                        <td class="px-6 py-4 text-center">
                            <span class="px-3 py-1 rounded-full text-[10px] font-black uppercase tracking-tighter
                                {{ $item->label_hasil == 'Teratur' ? 'bg-green-100 text-green-700' : ($item->label_hasil == 'Berantakan' ? 'bg-red-100 text-red-700' : 'bg-yellow-100 text-yellow-700') }}">
                                {{ $item->label_hasil }}
                            </span>
                        </td>
                        <td class="px-6 py-4 text-right">
                            <p class="text-[10px] font-bold text-slate-800 leading-none">{{ $item->created_at->format('d M Y') }}</p>
                            <p class="text-[9px] text-slate-400 mt-1 font-mono uppercase tracking-tighter">{{ $item->created_at->format('H:i') }} WIB</p>
                        </td>
                    </tr>
                    @empty
                    <tr><td colspan="5" class="py-20 text-center text-slate-400 font-bold italic">No records found.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <div class="lg:hidden grid grid-cols-1 sm:grid-cols-2 gap-4">
            @forelse($data as $item)
            <div class="bg-white p-5 rounded-3xl shadow-sm border border-slate-100 relative overflow-hidden">
                <div class="flex justify-between items-start mb-4">
                    <div>
                        <h4 class="font-bold text-slate-800 leading-none mb-1.5">{{ $item->nama }}</h4>
                        <span class="text-[10px] text-slate-400 font-mono italic">{{ $item->nim }}</span>
                    </div>
                    <span class="px-2 py-1 rounded-lg text-[9px] font-black uppercase tracking-tighter
                        {{ $item->label_hasil == 'Teratur' ? 'bg-green-100 text-green-700' : ($item->label_hasil == 'Berantakan' ? 'bg-red-100 text-red-700' : 'bg-yellow-100 text-yellow-700') }}">
                        {{ $item->label_hasil }}
                    </span>
                </div>
                
                <div class="bg-slate-50 p-3 rounded-2xl mb-3">
                    <p class="text-[10px] font-black text-blue-600 uppercase mb-1">
                        <i class="fas fa-magic mr-1"></i> Rekomendasi AI
                    </p>
                    <p class="text-[11px] text-slate-600 italic leading-snug">
                        "{{ $item->rekomendasi ?? 'Input data tercatat.' }}"
                    </p>
                </div>

                <div class="flex justify-between items-center pt-3 border-t border-dashed border-slate-100">
                    <div class="flex gap-2">
                        <span class="text-[9px] font-bold text-slate-400">R: {{ $item->skor_rutinitas }}/5</span>
                        <span class="text-[9px] font-bold text-slate-400">S: {{ $item->frekuensi_skip }}</span>
                    </div>
                    <span class="text-[9px] text-slate-400 font-bold italic uppercase tracking-tighter">
                        {{ $item->created_at->format('d/m/y H:i') }}
                    </span>
                </div>
            </div>
            @empty
            <div class="col-span-full py-10 text-center opacity-40">
                <i class="fas fa-folder-open text-3xl mb-2"></i>
                <p class="text-xs font-bold uppercase italic">Data Kosong</p>
            </div>
            @endforelse
        </div>

    </main>

</body>

</html>