@extends('admin.layouts.app')

@section('content')

<style>
    .page-container { padding: 40px 20px; background: #f4f7fb; min-height: calc(100vh - 70px); font-family: 'Outfit', 'Segoe UI', sans-serif; display: flex; flex-direction: column; align-items: center; }
    .form-card { background: #fff; border-radius: 24px; box-shadow: 0 10px 40px rgba(0,0,0,0.03); width: 100%; max-width: 600px; padding: 35px 40px; box-sizing: border-box; }
    .date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 35px; }
    .page-title { font-size: 28px; font-weight: 800; color: #0f172a; margin: 0 0 8px; letter-spacing: -0.5px; }
    
    @media (max-width: 768px) {
        .page-container { padding: 20px 15px !important; }
        .form-card { padding: 25px 20px !important; border-radius: 16px !important; }
        .date-grid { grid-template-columns: 1fr !important; gap: 15px !important; margin-bottom: 25px !important; }
        .page-title { font-size: 24px !important; }
    }
</style>

<div class="page-container">

    {{-- HEADER --}}
    <div style="text-align:center; margin-bottom:30px;">
        <h1 class="page-title">Buat Penugasan Baru</h1>
        <p style="margin:0; color:#64748b; font-size:15px; font-weight:500;">Berikan instruksi tugas kepada pegawai lapangan</p>
    </div>

    @if(session('error'))
        <div style="width:100%; max-width:600px; margin-bottom:20px; padding:14px 18px; background:#fff1f2; border:1px solid #fecdd3; border-radius:12px; color:#be123c; font-size:14px; font-weight:600; display:flex; align-items:center; gap:8px;">
            <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>
            {{ session('error') }}
        </div>
    @endif

    {{-- FORM CARD --}}
    <div class="form-card">
        <form action="{{ route('admin.superadmin.kegiatan.store') }}" method="POST">
            @csrf

            @if ($errors->any())
                <div style="margin-bottom:20px; padding:14px 18px; background:#fff1f2; border:1px solid #fecdd3; border-radius:12px;">
                    <p style="font-weight:700; color:#be123c; margin:0 0 8px; font-size:13px;">Terdapat kesalahan input:</p>
                    <ul style="margin:0; padding-left:18px; color:#be123c; font-size:13px;">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <div style="margin-bottom:24px;">
                <label style="display:block; font-size:11px; font-weight:800; color:#94a3b8; letter-spacing:1.5px; margin-bottom:8px; text-transform:uppercase;">
                    Nomor Surat
                </label>
                <input type="text" name="nomor_surat" value="{{ old('nomor_surat') }}"
                       style="width:100%; padding:14px 16px; background:#f8fafc; border:2px solid transparent; border-radius:12px; font-size:15px; color:#0f172a; outline:none; box-sizing:border-box; transition:all 0.2s; font-family:inherit; font-weight:500;"
                       onfocus="this.style.borderColor='#e0e7ff'; this.style.background='#fff'" onblur="this.style.borderColor='transparent'; this.style.background='#f8fafc'"
                       placeholder="Contoh: 001/ST/V/2026" required>
            </div>

            <div style="margin-bottom:24px;">
                <label style="display:block; font-size:11px; font-weight:800; color:#94a3b8; letter-spacing:1.5px; margin-bottom:8px; text-transform:uppercase;">
                    Nama Kegiatan
                </label>
                <input type="text" name="kegiatan" value="{{ old('kegiatan') }}"
                       style="width:100%; padding:14px 16px; background:#f8fafc; border:2px solid transparent; border-radius:12px; font-size:15px; color:#0f172a; outline:none; box-sizing:border-box; transition:all 0.2s; font-family:inherit; font-weight:500;"
                       onfocus="this.style.borderColor='#e0e7ff'; this.style.background='#fff'" onblur="this.style.borderColor='transparent'; this.style.background='#f8fafc'"
                       placeholder="Contoh: Monitoring Jaringan Dishub" required>
            </div>

            <div style="margin-bottom:24px;">
                <label style="display:block; font-size:11px; font-weight:800; color:#94a3b8; letter-spacing:1.5px; margin-bottom:8px; text-transform:uppercase;">
                    Pilih Petugas (Multiple)
                </label>
                <select name="pegawai_ids[]" multiple required
                        style="width:100%; padding:14px 16px; background:#f8fafc; border:2px solid transparent; border-radius:12px; font-size:14px; color:#334155; outline:none; box-sizing:border-box; transition:all 0.2s; font-family:inherit; font-weight:500; height:140px; line-height:1.5;"
                        onfocus="this.style.borderColor='#e0e7ff'; this.style.background='#fff'" onblur="this.style.borderColor='transparent'; this.style.background='#f8fafc'">
                    @foreach($users as $user)
                        <option value="{{ $user['id'] }}" style="padding:6px 0; border-bottom:1px solid #f1f5f9;">
                            {{ $user['name'] }} - {{ $user['jabatan'] ?? 'Pegawai' }}
                        </option>
                    @endforeach
                </select>
                <p style="font-size:11px; color:#94a3b8; margin-top:8px; font-weight:500;">* Tahan Ctrl/Cmd untuk memilih lebih dari 1 orang</p>
            </div>

            <div class="date-grid">
                <div>
                    <label style="display:block; font-size:11px; font-weight:800; color:#94a3b8; letter-spacing:1.5px; margin-bottom:8px; text-transform:uppercase;">
                        Tanggal Mulai
                    </label>
                    <input type="date" name="tanggal_mulai" value="{{ old('tanggal_mulai') }}"
                           style="width:100%; padding:14px 16px; background:#f8fafc; border:2px solid transparent; border-radius:12px; font-size:14px; color:#334155; outline:none; box-sizing:border-box; transition:all 0.2s; font-family:inherit; font-weight:500; color-scheme:light;"
                           onfocus="this.style.borderColor='#e0e7ff'; this.style.background='#fff'" onblur="this.style.borderColor='transparent'; this.style.background='#f8fafc'" required>
                </div>
                <div>
                    <label style="display:block; font-size:11px; font-weight:800; color:#94a3b8; letter-spacing:1.5px; margin-bottom:8px; text-transform:uppercase;">
                        Tanggal Selesai
                    </label>
                    <input type="date" name="tanggal_selesai" value="{{ old('tanggal_selesai') }}"
                           style="width:100%; padding:14px 16px; background:#f8fafc; border:2px solid transparent; border-radius:12px; font-size:14px; color:#334155; outline:none; box-sizing:border-box; transition:all 0.2s; font-family:inherit; font-weight:500; color-scheme:light;"
                           onfocus="this.style.borderColor='#e0e7ff'; this.style.background='#fff'" onblur="this.style.borderColor='transparent'; this.style.background='#f8fafc'">
                </div>
            </div>

            <button type="submit"
                    style="width:100%; padding:16px; background:#0D215C; color:#fff; border:none; border-radius:12px; font-size:15px; font-weight:800; cursor:pointer; font-family:inherit; transition:all 0.2s;"
                    onmouseover="this.style.transform='translateY(-2px)'; this.style.boxShadow='0 8px 20px rgba(13,33,92,0.2)'" 
                    onmouseout="this.style.transform='translateY(0)'; this.style.boxShadow='none'">
                Konfirmasi & Kirim Tugas
            </button>
        </form>
    </div>

    {{-- KEMBALI LINK --}}
    <div style="margin-top:30px;">
        <a href="{{ route('admin.superadmin.dashboard') }}"
           style="font-size:13px; font-weight:700; color:#64748b; letter-spacing:1px; text-decoration:none; text-transform:uppercase; transition:color 0.2s;"
           onmouseover="this.style.color='#0D215C'" onmouseout="this.style.color='#64748b'">
            Kembali Ke Dashboard
        </a>
    </div>

</div>

@endsection
