@extends('layouts.app')

@section('title', 'Dashboard Admin')

@push('styles')
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
    :root {
        --primary: #6366f1;
        --primary-hover: #4f46e5;
        --secondary: #8b5cf6;
        --success: #10b981;
        --info: #3b82f6;
        --warning: #f59e0b;
        --danger: #ef4444;
        --light: #f8f9fa;
        --dark: #0f172a;
        --text-secondary: #64748b;
        --bg-light: #f8fafc;
        --border-color: #e2e8f0;
    }

    * {
        font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    }

    body {
        background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
        color: var(--dark);
        min-height: 100vh;
    }

    .container {
        padding: 2rem 1rem;
    }

    .breadcrumb {
        background: transparent;
        padding: 0;
        margin-top: 0.5rem;
    }

    .breadcrumb-item a {
        color: var(--primary);
        text-decoration: none;
        transition: all 0.3s ease;
        font-weight: 500;
    }

    .breadcrumb-item a:hover {
        color: var(--secondary);
    }

    .breadcrumb-item.active {
        color: var(--text-secondary);
    }

    .user-profile-header {
        background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);
        position: relative;
        overflow: hidden;
        border-radius: 20px;
    }

    .user-profile-header::before {
        content: '';
        position: absolute;
        width: 200px;
        height: 200px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 50%;
        top: -50px;
        right: -50px;
        animation: float 6s ease-in-out infinite;
    }

    .user-profile-header::after {
        content: '';
        position: absolute;
        width: 150px;
        height: 150px;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 50%;
        bottom: -30px;
        left: 20px;
        animation: float 8s ease-in-out infinite reverse;
    }

    @keyframes float {
        0%, 100% { transform: translateY(0px); }
        50% { transform: translateY(-20px); }
    }

    .profile-content {
        position: relative;
        z-index: 1;
        color: white;
    }

    .user-avatar {
        width: 120px;
        height: 120px;
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(10px);
        color: white;
        font-size: 2.5rem;
        font-weight: 700;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        border: 3px solid rgba(255, 255, 255, 0.4);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
        margin-bottom: 1rem;
    }

    .user-profile-header h2 {
        font-size: 2rem;
        font-weight: 700;
        margin: 1rem 0 0.5rem 0;
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .badge-container {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
        margin-top: 1rem;
    }

    .badge {
        font-weight: 600;
        padding: 0.5em 1em;
        border-radius: 50px;
        font-size: 0.8rem;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        backdrop-filter: blur(10px);
        background: rgba(255, 255, 255, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.3);
    }

    .badge.bg-white {
        background: rgba(255, 255, 255, 0.95);
        color: var(--primary);
    }

    .badge.bg-white.text-success {
        color: var(--success);
    }

    .btn-edit {
        background: rgba(255, 255, 255, 0.95);
        color: var(--primary);
        border: none;
        font-weight: 600;
        transition: all 0.3s ease;
        border-radius: 10px;
    }

    .btn-edit:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
        background: white;
    }

    .btn-back {
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        color: white;
        border: none;
        font-weight: 600;
        border-radius: 10px;
        transition: all 0.3s ease;
    }

    .btn-back:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
    }

    .card {
        border: none;
        border-radius: 16px;
        box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
        overflow: hidden;
        background: white;
        margin-bottom: 2rem;
        transition: all 0.3s ease;
    }

    .card:hover {
        box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    }

    .stat-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1.5rem;
        margin-bottom: 2rem;
    }

    .stat-card {
        background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 1.5rem;
        text-align: center;
        transition: all 0.3s ease;
        position: relative;
        overflow: hidden;
    }

    .stat-card::before {
        content: '';
        position: absolute;
        width: 100px;
        height: 100px;
        background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
        border-radius: 50%;
        top: -50px;
        right: -50px;
    }

    .stat-card:hover {
        transform: translateY(-8px);
        border-color: var(--primary);
        box-shadow: 0 12px 24px rgba(99, 102, 241, 0.15);
    }

    .stat-value {
        font-size: 2.5rem;
        font-weight: 700;
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        margin-bottom: 0.5rem;
        position: relative;
        z-index: 1;
    }

    .stat-label {
        color: var(--text-secondary);
        font-size: 0.9rem;
        font-weight: 500;
        position: relative;
        z-index: 1;
    }

    .info-card {
        background: white;
        border-radius: 12px;
        border: 1px solid var(--border-color);
        transition: all 0.3s ease;
        height: 100%;
    }

    .info-card:hover {
        border-color: var(--primary);
        box-shadow: 0 8px 20px rgba(99, 102, 241, 0.1);
    }

    .info-card .card-header {
        background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
        border-bottom: 2px solid var(--border-color);
        padding: 1.5rem;
        font-weight: 700;
        color: var(--dark);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .info-card .card-body {
        padding: 1.5rem;
    }

    .info-row {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding-bottom: 1.25rem;
        border-bottom: 1px solid var(--border-color);
    }

    .info-row:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .info-label {
        color: var(--text-secondary);
        font-size: 0.85rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        margin-bottom: 0.35rem;
    }

    .info-value {
        color: var(--dark);
        font-weight: 500;
        font-size: 0.95rem;
    }

    .table {
        margin-bottom: 0;
    }

    .table thead {
        background: linear-gradient(90deg, #f8fafc 0%, #f1f5f9 100%);
    }

    .table th {
        font-weight: 700;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--text-secondary);
        border: none;
        padding: 1.25rem;
    }

    .table tbody tr {
        border-bottom: 1px solid var(--border-color);
        transition: all 0.3s ease;
    }

    .table tbody tr:hover {
        background: #f8fafc;
    }

    .table td {
        padding: 1.25rem;
        vertical-align: middle;
    }

    .status-badge {
        font-size: 0.75rem;
        font-weight: 700;
        padding: 0.5em 1em;
        border-radius: 50px;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        display: inline-block;
    }

    .status-success {
        background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.1));
        color: #059669;
        border: 1px solid rgba(16, 185, 129, 0.3);
    }

    .status-warning {
        background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(217, 119, 6, 0.1));
        color: #b45309;
        border: 1px solid rgba(245, 158, 11, 0.3);
    }

    .status-danger {
        background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(185, 28, 28, 0.1));
        color: #b91c1c;
        border: 1px solid rgba(239, 68, 68, 0.3);
    }

    .btn-outline-primary {
        color: var(--primary);
        border: 1.5px solid var(--primary);
        border-radius: 8px;
        font-weight: 600;
        transition: all 0.3s ease;
    }

    .btn-outline-primary:hover {
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        color: white;
        border-color: transparent;
        transform: translateY(-2px);
        box-shadow: 0 8px 12px rgba(99, 102, 241, 0.3);
    }

    .btn-sm {
        font-weight: 600;
        border-radius: 8px;
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }

    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }

    ::-webkit-scrollbar-track {
        background: #f1f5f9;
    }

    ::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        border-radius: 10px;
    }

    @media (max-width: 768px) {
        .user-profile-header h2 {
            font-size: 1.5rem;
        }

        .user-avatar {
            width: 80px;
            height: 80px;
            font-size: 1.8rem;
        }

        .stat-grid {
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 1rem;
        }

        .stat-value {
            font-size: 1.8rem;
        }

        .info-row {
            flex-direction: column;
        }
    }
</style>
@endpush

@section('content')
<div class="container">
    <!-- Header Navigation -->
    <div class="d-flex justify-content-between align-items-start mb-4">
        <div>
            <h1 class="h3 mb-2" style="font-weight: 700; color: var(--dark);">
                <i class="fas fa-user-circle me-2" style="background: linear-gradient(135deg, #6366f1, #8b5cf6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;"></i>
                Dashboard Admin
            </h1>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-0">
                    <li class="breadcrumb-item active" aria-current="page">Dashboard</li>
                </ol>
            </nav>
        </div>
    </div>

    <!-- Welcome Card -->
    <div class="card mb-4" style="background: linear-gradient(135deg, #6366f1, #8b5cf6); color: white;">
        <div class="card-body p-4">
            <h5 class="card-title" style="font-weight: 700;">Selamat Datang, {{ auth()->user()->name }}!</h5>
            <p class="card-text" style="margin-bottom: 1.5rem;">Ini adalah dashboard admin. Dari sini, Anda dapat mengelola semua aspek aplikasi.</p>
            <a href="{{ route('admin.absensi.index') }}" class="btn btn-light">
                <i class="fas fa-tachometer-alt me-2"></i>Ke Halaman Utama
            </a>
        </div>
    </div>

    <!-- Quick Actions -->
    <div class="row g-4 mb-4">
        <div class="col-md-4">
            <div class="card text-white" style="background: linear-gradient(135deg, #10b981, #3bbf77);">
                <div class="card-body">
                    <h5 class="card-title">Kehadiran Hari Ini</h5>
                    <div class="d-flex align-items-center justify-content-between">
                        <div>
                            <h2 class="stat-value mb-0">{{ $todayAttendanceCount }}</h2>
                            <div class="stat-label">Total Kehadiran</div>
                        </div>
                        <div class="icon" style="font-size: 2.5rem;">
                            <i class="fas fa-calendar-check" style="color: rgba(255, 255, 255, 0.8);"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card text-white" style="background: linear-gradient(135deg, #ef4444, #f87171);">
                <div class="card-body">
                    <h5 class="card-title">Kehadiran Tidak Valid</h5>
                    <div class="d-flex align-items-center justify-content-between">
                        <div>
                            <h2 class="stat-value mb-0">{{ $invalidAttendanceCount }}</h2>
                            <div class="stat-label">Total Tidak Valid</div>
                        </div>
                        <div class="icon" style="font-size: 2.5rem;">
                            <i class="fas fa-times-circle" style="color: rgba(255, 255, 255, 0.8);"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card text-white" style="background: linear-gradient(135deg, #3b82f6, #60a5fa);">
                <div class="card-body">
                    <h5 class="card-title">Pengguna Terdaftar</h5>
                    <div class="d-flex align-items-center justify-content-between">
                        <div>
                            <h2 class="stat-value mb-0">{{ $userCount }}</h2>
                            <div class="stat-label">Total Pengguna</div>
                        </div>
                        <div class="icon" style="font-size: 2.5rem;">
                            <i class="fas fa-users" style="color: rgba(255, 255, 255, 0.8);"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Registered Users List -->
    <div class="card" style="max-width:700px;margin:auto;margin-top:32px;">
        <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;">
            <h3 style="color:#1e293b;font-size:18px;">Daftar Pengguna Terdaftar</h3>
            <a href="{{ route('admin.users.create') }}" class="btn btn-primary btn-sm" style="padding:8px 18px;border-radius:8px;font-weight:600;">
                + Daftarkan Pengguna Baru
            </a>
        </div>
        <ul style="list-style:none;padding:0;margin:0;">
            @foreach($users as $user)
                <li style="margin-bottom:14px;padding-bottom:10px;border-bottom:1px solid #e5e7eb;">
                    <div style="font-weight:600;color:#2563eb;">{{ $user->name }}</div>
                    <div style="font-size:13px;color:#64748b;">{{ $user->email }}</div>
                    <div style="font-size:12px;color:#0ea5e9;">Role: {{ $user->role ?? '-' }}</div>
                </li>
            @endforeach
        </ul>
    </div>
</div>
@endsection

@push('scripts')
<script>
    document.addEventListener('DOMContentLoaded', function() {
        var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
        var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
            return new bootstrap.Tooltip(tooltipTriggerEl);
        });
    });
</script>
@endpush