<?php
/**
 * kelola_pesanan.php - Halaman Kelola Pesanan untuk Supir
 * DIPERBAIKI - Menghapus tombol selesai dari supir, diganti dengan indikator
 */
$activeMenu = 'kelolaPesanan';
$pageTitle = 'Kelola Pesanan - Supir';
include __DIR__ . '/../layouts/header.php';

$pesananList = $pesananList ?? [];
$unreadCount = $unreadCount ?? 0;

// Filter status
$filterStatus = isset($_GET['status']) ? $_GET['status'] : 'all';
?>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">

<div class="dashboard-wrapper">
    <?php include __DIR__ . '/../layouts/sidebar_supir.php'; ?>

    <main class="main-content">
        <div class="content-header">
            <div>
                <h2><i class="fas fa-clipboard-list" style="color:#2b6cb0;"></i> Kelola Pesanan</h2>
                <p>Daftar semua pesanan kapal Anda. Perjalanan akan diselesaikan oleh wisatawan.</p>
            </div>
            <div class="header-info">
                <span class="info-badge">
                    <i class="fas fa-info-circle"></i> 
                    Wisatawan dapat menyelesaikan perjalanan setelah selesai
                </span>
            </div>
        </div>

        <?php if(isset($_SESSION['flash_success'])): ?>
            <div class="alert alert-success">
                <i class="fas fa-check-circle"></i>
                <?= htmlspecialchars($_SESSION['flash_success']) ?>
                <button class="alert-close" onclick="this.parentElement.remove()">&times;</button>
                <?php unset($_SESSION['flash_success']); ?>
            </div>
        <?php endif; ?>

        <?php if(isset($_SESSION['flash_error'])): ?>
            <div class="alert alert-danger">
                <i class="fas fa-exclamation-circle"></i>
                <?= htmlspecialchars($_SESSION['flash_error']) ?>
                <button class="alert-close" onclick="this.parentElement.remove()">&times;</button>
                <?php unset($_SESSION['flash_error']); ?>
            </div>
        <?php endif; ?>

        <!-- Filter Tabs -->
        <div class="filter-tabs">
            <a href="?page=supir&action=kelolaPesanan&status=all" class="tab <?= $filterStatus == 'all' ? 'active' : '' ?>">
                Semua (<?= count($pesananList) ?>)
            </a>
            <?php
            $statusCount = [
                'pending' => 0,
                'confirmed' => 0,
                'completed' => 0,
                'cancelled' => 0,
                'menunggu_reschedule' => 0
            ];
            foreach ($pesananList as $p) {
                if ($p['reschedule_status'] == 'menunggu') {
                    $statusCount['menunggu_reschedule']++;
                } elseif (isset($statusCount[$p['status_pesanan']])) {
                    $statusCount[$p['status_pesanan']]++;
                }
            }
            ?>
            <a href="?page=supir&action=kelolaPesanan&status=pending" class="tab <?= $filterStatus == 'pending' ? 'active' : '' ?>">
                Menunggu (<?= $statusCount['pending'] ?>)
            </a>
            <a href="?page=supir&action=kelolaPesanan&status=confirmed" class="tab <?= $filterStatus == 'confirmed' ? 'active' : '' ?>">
                Dikonfirmasi (<?= $statusCount['confirmed'] ?>)
            </a>
            <a href="?page=supir&action=kelolaPesanan&status=completed" class="tab <?= $filterStatus == 'completed' ? 'active' : '' ?>">
                Selesai (<?= $statusCount['completed'] ?>)
            </a>
            <a href="?page=supir&action=kelolaPesanan&status=menunggu_reschedule" class="tab <?= $filterStatus == 'menunggu_reschedule' ? 'active' : '' ?>" style="background: #fef3c7; color: #92400e;">
                <i class="fas fa-calendar-alt"></i> Reschedule (<?= $statusCount['menunggu_reschedule'] ?>)
            </a>
        </div>

        <?php if(empty($pesananList)): ?>
            <div class="empty-state">
                <div class="empty-icon">📭</div>
                <h3>Belum Ada Pesanan</h3>
                <p>Belum ada pesanan untuk kapal Anda.</p>
            </div>
        <?php else: ?>
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Kode</th>
                            <th>Wisatawan</th>
                            <th>Kapal</th>
                            <th>Tanggal</th>
                            <th>Total</th>
                            <th>Status</th>
                            <th>Reschedule</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach($pesananList as $p): 
                            // Cek apakah ada permintaan reschedule
                            $isReschedulePending = ($p['reschedule_status'] == 'menunggu');
                            $isRescheduleApproved = ($p['reschedule_status'] == 'disetujui');
                            
                            // Status pesanan
                            $statusMap = [
                                'pending' => ['badge-warning', 'Menunggu', 'fa-clock'],
                                'confirmed' => ['badge-success', 'Dikonfirmasi', 'fa-check-circle'],
                                'completed' => ['badge-info', 'Selesai', 'fa-flag-checkered'],
                                'cancelled' => ['badge-danger', 'Dibatalkan', 'fa-times-circle'],
                            ];
                            $statusInfo = $statusMap[$p['status_pesanan']] ?? ['badge-secondary', ucfirst($p['status_pesanan']), 'fa-circle'];
                            
                            // Status pembayaran
                            $paymentMap = [
                                'belum_bayar' => ['badge-warning', 'Belum Bayar', 'fa-clock'],
                                'menunggu_konfirmasi' => ['badge-warning', 'Menunggu Konfirmasi', 'fa-hourglass-half'],
                                'lunas' => ['badge-success', 'Lunas', 'fa-check-circle'],
                                'gagal' => ['badge-danger', 'Gagal', 'fa-times-circle'],
                            ];
                            $paymentInfo = $paymentMap[$p['status_pembayaran']] ?? ['badge-secondary', ucfirst($p['status_pembayaran']), 'fa-circle'];
                            
                            // Status pencairan
                            $cairMap = [
                                'belum' => ['badge-secondary', 'Belum Cair', 'fa-clock'],
                                'proses' => ['badge-warning', 'Proses', 'fa-hourglass-half'],
                                'cair' => ['badge-success', 'Sudah Cair', 'fa-check-circle'],
                            ];
                            $cairInfo = $cairMap[$p['status_pencairan'] ?? 'belum'] ?? ['badge-secondary', 'Belum', 'fa-circle'];
                        ?>
                            <tr class="<?= $isReschedulePending ? 'reschedule-pending' : '' ?>">
                                <td>
                                    <span class="kode-badge"><?= htmlspecialchars($p['kode_pesanan']) ?></span>
                                </td>
                                <td>
                                    <div class="wisatawan-cell">
                                        <strong><?= htmlspecialchars($p['wisatawan_nama'] ?? '-') ?></strong>
                                        <small><?= htmlspecialchars($p['wisatawan_hp'] ?? '-') ?></small>
                                    </div>
                                </td>
                                <td><?= htmlspecialchars($p['nama_kapal'] ?? '-') ?></td>
                                <td><?= isset($p['tanggal_berangkat']) ? date('d/m/Y', strtotime($p['tanggal_berangkat'])) : '-' ?></td>
                                <td class="harga">Rp <?= number_format($p['total_harga'] ?? 0, 0, ',', '.') ?></td>
                                <td>
                                    <span class="badge <?= $statusInfo[0] ?>">
                                        <i class="fas <?= $statusInfo[2] ?>"></i>
                                        <?= $statusInfo[1] ?>
                                    </span>
                                    <br>
                                    <span class="badge <?= $paymentInfo[0] ?>" style="margin-top:2px;">
                                        <i class="fas <?= $paymentInfo[2] ?>"></i>
                                        <?= $paymentInfo[1] ?>
                                    </span>
                                    <?php if($p['status_pencairan'] == 'cair'): ?>
                                        <br>
                                        <span class="badge badge-success" style="margin-top:2px; background:#d1fae5; color:#065f46;">
                                            <i class="fas fa-money-bill-wave"></i> Dana Cair
                                        </span>
                                    <?php elseif($p['status_pencairan'] == 'proses'): ?>
                                        <br>
                                        <span class="badge badge-warning" style="margin-top:2px;">
                                            <i class="fas fa-hourglass-half"></i> Dana Proses
                                        </span>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <?php if($isReschedulePending): ?>
                                        <span class="badge badge-warning" style="background:#fef3c7; color:#92400e; display:block; text-align:center;">
                                            <i class="fas fa-clock"></i> Menunggu
                                        </span>
                                        <small style="font-size:0.65rem; color:#92400e; display:block;">
                                            <?= date('d/m/Y', strtotime($p['reschedule_tanggal_baru'])) ?>
                                            <br>
                                            <?= htmlspecialchars(substr($p['reschedule_rute_baru'] ?? '', 0, 15)) ?>...
                                        </small>
                                    <?php elseif($isRescheduleApproved): ?>
                                        <span class="badge badge-success">
                                            <i class="fas fa-check"></i> Disetujui
                                        </span>
                                    <?php elseif($p['reschedule_status'] == 'ditolak'): ?>
                                        <span class="badge badge-danger">
                                            <i class="fas fa-times"></i> Ditolak
                                        </span>
                                    <?php else: ?>
                                        <span class="badge badge-secondary">-</span>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <div class="action-buttons">
                                        <!-- ========================================== -->
                                        <!-- RESCHEDULE - SETUJUI / TOLAK -->
                                        <!-- ========================================== -->
                                        <?php if($isReschedulePending): ?>
                                            <button class="btn btn-sm btn-success btn-reschedule" 
                                                    onclick="openRescheduleModal(<?= $p['id'] ?>, '<?= htmlspecialchars($p['kode_pesanan']) ?>', 'setuju')">
                                                <i class="fas fa-check"></i> Setuju
                                            </button>
                                            <button class="btn btn-sm btn-danger btn-reschedule" 
                                                    onclick="openRescheduleModal(<?= $p['id'] ?>, '<?= htmlspecialchars($p['kode_pesanan']) ?>', 'tolak')">
                                                <i class="fas fa-times"></i> Tolak
                                            </button>
                                        <?php endif; ?>

                                        <!-- ========================================== -->
                                        <!-- UPDATE STATUS PESANAN (TANPA SELESAI) -->
                                        <!-- ========================================== -->
                                        <?php if($p['status_pesanan'] == 'pending'): ?>
                                            <form method="POST" action="?page=supir&action=updateStatusPesanan" style="display:inline;">
                                                <input type="hidden" name="pesanan_id" value="<?= $p['id'] ?>">
                                                <input type="hidden" name="status" value="confirmed">
                                                <button type="submit" class="btn btn-sm btn-success" onclick="return confirm('Verifikasi pesanan ini?')">
                                                    <i class="fas fa-check"></i> Verifikasi
                                                </button>
                                            </form>
                                            <form method="POST" action="?page=supir&action=updateStatusPesanan" style="display:inline;">
                                                <input type="hidden" name="pesanan_id" value="<?= $p['id'] ?>">
                                                <input type="hidden" name="status" value="cancelled">
                                                <button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Batalkan pesanan ini?')">
                                                    <i class="fas fa-times"></i> Batal
                                                </button>
                                            </form>
                                        <?php endif; ?>

                                        <!-- ========================================== -->
                                        <!-- 🔥 HAPUS TOMBOL "SELESAI" - SUDAH DIHAPUS -->
                                        <!-- ========================================== -->
                                        <?php if($p['status_pesanan'] == 'confirmed' && $p['status_pembayaran'] == 'lunas'): ?>
                                            <!-- 🔥 GANTI DENGAN INDIKATOR MENUNGGU WISATAWAN -->
                                            <div class="info-status">
                                                <span class="badge badge-info" style="background:#dbeafe; color:#1e40af; display:block; text-align:center; padding:0.3rem 0.5rem;">
                                                    <i class="fas fa-hourglass-half"></i> Menunggu Wisatawan
                                                </span>
                                                <small style="font-size:0.6rem; color:#718096; display:block; text-align:center; margin-top:2px;">
                                                    Wisatawan akan menyelesaikan perjalanan
                                                </small>
                                            </div>
                                        <?php endif; ?>

                                        <!-- ========================================== -->
                                        <!-- TOMBOL DETAIL -->
                                        <!-- ========================================== -->
                                        <a href="?page=supir&action=detailPesanan&id=<?= $p['id'] ?>" class="btn btn-sm btn-primary">
                                            <i class="fas fa-eye"></i> Detail
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php endif; ?>

        <!-- ========================================== -->
        <!-- INFO FOOTER -->
        <!-- ========================================== -->
        <div class="info-footer">
            <div class="info-item">
                <i class="fas fa-info-circle" style="color:#2b6cb0;"></i>
                <span><strong>Catatan:</strong> Perjalanan akan diselesaikan oleh wisatawan setelah selesai. Supir tidak perlu menekan tombol selesai.</span>
            </div>
            <div class="info-item">
                <i class="fas fa-money-bill-wave" style="color:#22c55e;"></i>
                <span><strong>Pencairan Dana:</strong> Dana akan otomatis cair setelah wisatawan menyelesaikan perjalanan.</span>
            </div>
            <div class="info-item">
                <i class="fas fa-exclamation-triangle" style="color:#f59e0b;"></i>
                <span><strong>Claim:</strong> Jika wisatawan mengajukan claim, dana tidak akan cair sampai claim diproses admin.</span>
            </div>
        </div>
    </main>
</div>

<!-- ========================================== -->
<!-- MODAL RESCHEDULE -->
<!-- ========================================== -->
<div class="modal-overlay" id="rescheduleModal">
    <div class="modal">
        <div class="modal-header">
            <h3><i class="fas fa-calendar-alt" style="color:#f59e0b;"></i> <span id="rescheduleModalTitle">Konfirmasi Perubahan Jadwal</span></h3>
            <button class="modal-close" onclick="closeRescheduleModal()">&times;</button>
        </div>
        <form method="POST" action="?page=supir&action=konfirmasiReschedule" id="rescheduleForm">
            <input type="hidden" name="pesanan_id" id="reschedulePesananId">
            <input type="hidden" name="keputusan" id="rescheduleKeputusan">

            <div class="modal-body">
                <div class="info-box">
                    <i class="fas fa-info-circle"></i>
                    <div>
                        <strong>Permintaan Perubahan Jadwal</strong>
                        <p id="rescheduleInfo">Memproses...</p>
                    </div>
                </div>

                <div class="form-group" id="rescheduleAlasanGroup" style="display:none;">
                    <label>Alasan Penolakan <span class="required">*</span></label>
                    <textarea name="alasan" id="rescheduleAlasan" class="form-control" rows="3" 
                              placeholder="Berikan alasan mengapa Anda menolak perubahan jadwal..."></textarea>
                    <small class="form-hint">Alasan akan dikirim ke wisatawan.</small>
                </div>
            </div>

            <div class="form-actions">
                <button type="button" class="btn btn-secondary" onclick="closeRescheduleModal()">Batal</button>
                <button type="submit" class="btn btn-primary" id="rescheduleSubmitBtn">
                    <i class="fas fa-paper-plane"></i> Konfirmasi
                </button>
            </div>
        </form>
    </div>
</div>

<script>
function openRescheduleModal(id, kode, keputusan) {
    document.getElementById('reschedulePesananId').value = id;
    document.getElementById('rescheduleKeputusan').value = keputusan;
    
    const title = document.getElementById('rescheduleModalTitle');
    const info = document.getElementById('rescheduleInfo');
    const alasanGroup = document.getElementById('rescheduleAlasanGroup');
    const submitBtn = document.getElementById('rescheduleSubmitBtn');
    
    if (keputusan === 'setuju') {
        title.textContent = '✅ Setujui Perubahan Jadwal';
        info.innerHTML = `
            <strong>Kode Pesanan:</strong> ${kode}<br>
            <strong>Keputusan:</strong> <span style="color:#22c55e;">SETUJU</span><br>
            <small>Wisatawan akan menerima notifikasi bahwa perubahan jadwal disetujui.</small>
        `;
        alasanGroup.style.display = 'none';
        submitBtn.className = 'btn btn-success';
        submitBtn.innerHTML = '<i class="fas fa-check"></i> Setujui';
    } else {
        title.textContent = '❌ Tolak Perubahan Jadwal';
        info.innerHTML = `
            <strong>Kode Pesanan:</strong> ${kode}<br>
            <strong>Keputusan:</strong> <span style="color:#ef4444;">TOLAK</span><br>
            <small>Wisatawan akan menerima notifikasi bahwa perubahan jadwal ditolak.</small>
        `;
        alasanGroup.style.display = 'block';
        submitBtn.className = 'btn btn-danger';
        submitBtn.innerHTML = '<i class="fas fa-times"></i> Tolak';
    }
    
    document.getElementById('rescheduleModal').classList.add('active');
    document.body.style.overflow = 'hidden';
}

function closeRescheduleModal() {
    document.getElementById('rescheduleModal').classList.remove('active');
    document.body.style.overflow = '';
}

document.addEventListener('keydown', function(e) {
    if (e.key === 'Escape') closeRescheduleModal();
});

document.getElementById('rescheduleModal').addEventListener('click', function(e) {
    if (e.target === this) closeRescheduleModal();
});

// Validasi form sebelum submit
document.getElementById('rescheduleForm').addEventListener('submit', function(e) {
    const keputusan = document.getElementById('rescheduleKeputusan').value;
    const alasan = document.getElementById('rescheduleAlasan');
    
    if (keputusan === 'tolak' && alasan.value.trim() === '') {
        e.preventDefault();
        alert('Silakan isi alasan penolakan!');
        alasan.focus();
    }
});
</script>

<style>
.dashboard-wrapper {
    display: flex;
    gap: 24px;
    max-width: 1200px;
    margin: 1.5rem auto 0;
    padding: 0 20px;
    width: 100%;
    flex: 1;
    align-items: flex-start;
}

.main-content {
    flex: 1;
    min-width: 0;
    background: #fff;
    border-radius: 14px;
    padding: 1.8rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    border: 1px solid #e2e8f0;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 10px;
}

.content-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: #1a202c;
    margin: 0;
}

.content-header p {
    color: #718096;
    font-size: 0.95rem;
    margin: 0.2rem 0 0;
}

.header-info .info-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.8rem;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid #93c5fd;
}

.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.8rem 1.2rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    border-left: 4px solid transparent;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border-left-color: #22c55e;
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
    border-left-color: #ef4444;
}

.alert-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    padding: 0 4px;
}

.alert-close:hover {
    opacity: 1;
}

/* Filter Tabs */
.filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filter-tabs .tab {
    padding: 0.4rem 1rem;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #4a5568;
    text-decoration: none;
    transition: all 0.3s ease;
}

.filter-tabs .tab:hover {
    background: #edf2f7;
    text-decoration: none;
}

.filter-tabs .tab.active {
    background: #2b6cb0;
    color: #fff;
    border-color: #2b6cb0;
}

/* Table */
.table-responsive {
    overflow-x: auto;
    margin-top: 0.5rem;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.table thead {
    background: #f7fafc;
}

.table th {
    text-align: left;
    padding: 0.6rem 0.8rem;
    font-weight: 600;
    color: #4a5568;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}

.table td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid #edf2f7;
    vertical-align: middle;
}

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

.table tbody tr.reschedule-pending {
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
}

.table tbody tr.reschedule-pending:hover {
    background: #fef3c7;
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.15rem 0.6rem;
    border-radius: 20px;
    font-size: 0.6rem;
    font-weight: 600;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-secondary {
    background: #e5e7eb;
    color: #4b5563;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

/* Cells */
.kode-badge {
    font-weight: 600;
    color: #2b6cb0;
    font-size: 0.7rem;
    background: #ebf8ff;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
}

.wisatawan-cell {
    display: flex;
    flex-direction: column;
}

.wisatawan-cell small {
    font-size: 0.65rem;
    color: #718096;
}

.harga {
    font-weight: 600;
    color: #2b6cb0;
    white-space: nowrap;
}

.action-buttons {
    display: flex;
    gap: 0.2rem;
    flex-wrap: wrap;
}

.info-status {
    min-width: 120px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.25rem 0.6rem;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.btn-success {
    background: #22c55e;
    color: #fff;
}

.btn-success:hover {
    background: #16a34a;
}

.btn-danger {
    background: #ef4444;
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-primary {
    background: #2b6cb0;
    color: #fff;
}

.btn-primary:hover {
    background: #1a4a7a;
}

.btn-sm {
    padding: 0.2rem 0.5rem;
    font-size: 0.65rem;
}

.btn-reschedule {
    min-width: 60px;
}

/* Info Footer */
.info-footer {
    margin-top: 1.5rem;
    padding: 1rem 1.2rem;
    background: #f7fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.info-footer .info-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.8rem;
    color: #4a5568;
}

.info-footer .info-item i {
    margin-top: 0.1rem;
    flex-shrink: 0;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.8rem 2rem;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        transform: scale(0.95) translateY(-20px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1a202c;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: #a0aec0;
    transition: all 0.3s ease;
    line-height: 1;
}

.modal-close:hover {
    color: #1a202c;
}

.modal-body {
    margin-bottom: 1rem;
}

.info-box {
    display: flex;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    background: #dbeafe;
    border: 1px solid #93c5fd;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.info-box i {
    font-size: 1.5rem;
    color: #2563eb;
}

.info-box strong {
    color: #1e40af;
    font-size: 0.85rem;
}

.info-box p {
    color: #1e40af;
    font-size: 0.8rem;
    margin: 0.1rem 0;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: #4a5568;
    margin-bottom: 0.2rem;
}

.form-group .required {
    color: #ef4444;
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    font-family: inherit;
    resize: vertical;
}

.form-control:focus {
    outline: none;
    border-color: #2b6cb0;
    box-shadow: 0 0 0 3px rgba(43,108,176,0.08);
}

.form-hint {
    font-size: 0.7rem;
    color: #a0aec0;
    margin-top: 0.2rem;
    display: block;
}

.form-actions {
    display: flex;
    gap: 0.8rem;
    justify-content: flex-end;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: #f7fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.empty-icon {
    font-size: 3.5rem;
    display: block;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2d3748;
}

.empty-state p {
    color: #718096;
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    .dashboard-wrapper {
        flex-direction: column;
        padding: 0 12px;
        margin-top: 1rem;
    }
    .main-content {
        padding: 1rem;
    }
    .content-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .filter-tabs {
        flex-wrap: wrap;
    }
    .filter-tabs .tab {
        font-size: 0.7rem;
        padding: 0.3rem 0.7rem;
    }
    .action-buttons {
        flex-direction: column;
    }
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
    .modal {
        padding: 1.2rem;
    }
    .table {
        font-size: 0.7rem;
    }
    .table th,
    .table td {
        padding: 0.3rem 0.4rem;
    }
    .info-footer {
        padding: 0.8rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.8rem;
    }
    .modal {
        padding: 1rem;
    }
    .info-status {
        min-width: unset;
    }
}
</style>

<?php include __DIR__ . '/../layouts/footer.php'; ?>