<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $title ?></title>
    <!-- CSS Dependencies -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,600,700&display=fallback">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
    
    <style>
        html { scroll-behavior: smooth; }
        body { font-family: 'Source Sans Pro', sans-serif; background-color: #f4f7f6; color: #333; }
        .bg-emerald-landing { background: linear-gradient(135deg, #1b4332 0%, #2d6a4f 100%); color: white; }
        .text-emerald { color: #2d6a4f !important; }
        .btn-emerald { background-color: #2d6a4f; color: white; border: none; transition: 0.3s; }
        .btn-emerald:hover { background-color: #1b4332; color: white; transform: translateY(-2px); }
        .card-outline-emerald { border-top: 4px solid #2d6a4f; }
        .search-box { background-color: #e8f5e9; border: 1px solid #c8e6c9; border-radius: 8px; }
        .badge-amber { background-color: #ffc107; color: #000; font-weight: bold; }
        .hero-terlaris-box { background: rgba(255, 255, 255, 0.15); backdrop-filter: blur(5px); border: 1px solid rgba(255,255,255,0.3); border-radius: 12px; }
    </style>
</head>
<body>

<!-- NAVBAR NAVIGASI PORTAL -->
<nav class="navbar navbar-expand-lg navbar-dark bg-emerald-landing sticky-top shadow-sm py-3">
    <div class="container">
        <a class="navbar-brand font-weight-bold" href="<?= base_url('/') ?>">
            <i class="fas fa-seedling text-warning mr-2"></i> SIM SARI RASA
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navPortal">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navPortal">
            <ul class="navbar-nav ml-auto align-items-center">
                <li class="nav-item"><a class="nav-link text-white mr-2" href="#cek-rdkk"><i class="fas fa-search mr-1"></i> Cek Kuota</a></li>
                <li class="nav-item"><a class="nav-link text-white mr-2" href="#tentang-kami"><i class="fas fa-info-circle mr-1"></i> Tentang Kami</a></li>
                <li class="nav-item"><a class="nav-link text-white mr-2" href="#visi-misi"><i class="fas fa-bullseye mr-1"></i> Visi & Misi</a></li>
                <li class="nav-item"><a class="nav-link text-white mr-3" href="#kontak"><i class="fas fa-phone-alt mr-1"></i> Kontak</a></li>
                <li class="nav-item">
                    <a href="<?= base_url('auth') ?>" class="btn btn-warning btn-sm font-weight-bold px-3 text-dark rounded-pill shadow-sm">
                        <i class="fas fa-user-lock mr-1"></i> Login Petugas
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- HERO HEADER BANNER & WIDGET PUPUK TERLARIS -->
<header class="jumbotron jumbotron-fluid bg-emerald-landing text-center mb-5 py-5">
    <div class="container">
        <h1 class="display-4 font-weight-bold mb-2">SIM SARI RASA</h1>
        <p class="lead opacity-90 mb-4">Sistem Informasi Manajemen Kelompok Tani Sari Rasa — Desa Trahean</p>
        
        <!-- REVISI 3: WIDGET PUPUK TERLARIS DITEBUS PETANI -->
        <div class="row justify-content-center">
            <div class="col-md-8 col-lg-6">
                <div class="hero-terlaris-box p-3 text-white text-left d-flex align-items-center shadow-sm">
                    <div class="mr-3 text-center px-3 py-2 bg-warning rounded text-dark">
                        <i class="fas fa-crown fa-2x"></i>
                    </div>
                    <div>
                        <span class="badge badge-amber text-uppercase mb-1"><i class="fas fa-fire mr-1"></i> Pupuk Paling Banyak Ditebus</span>
                        <h4 class="font-weight-bold mb-0 text-white"><?= esc($terlaris['nama_pupuk']) ?></h4>
                        <small class="text-light">Total penebusan petani: <b><?= number_format($terlaris['jumlah'], 0, ',', '.') ?> Kg</b></small>
                    </div>
                </div>
            </div>
        </div>
    </div>
</header>

<div class="container">
    
    <!-- SEKSI 1: CEK KUOTA e-RDKK & LOG PASOKAN MASUK -->
    <section id="cek-rdkk" class="mb-5">
        <div class="row">
            <!-- KOLOM KIRI: CEK MANDIRI NIK -->
            <div class="col-lg-7 mb-4">
                <div class="card shadow-sm border-0 card-outline-emerald h-100">
                    <div class="card-body p-4">
                        <h4 class="font-weight-bold text-emerald mb-2"><i class="fas fa-search-location mr-2"></i> Cek Sisa Kuota e-RDKK Mandiri</h4>
                        <p class="text-muted small mb-3">Masukkan 16 digit NIK Anda untuk memeriksa alokasi dan sisa sisa kuota pupuk bersubsidi.</p>
                        
                        <form action="<?= base_url('/') ?>#cek-rdkk" method="get" class="search-box p-3 mb-4">
                            <div class="input-group">
                                <input type="text" name="nik" value="<?= esc($nik) ?>" maxlength="16" pattern="\d{16}" 
                                       class="form-control form-control-lg border-0 shadow-none bg-white font-weight-bold" 
                                       placeholder="Masukkan 16 Digit NIK..." required>
                                <div class="input-group-append pl-2">
                                    <button type="submit" class="btn btn-emerald btn-lg px-4 rounded-right font-weight-bold">
                                        Periksa
                                    </button>
                                </div>
                            </div>
                        </form>

                        <!-- HASIL PENCARIAN -->
                        <?php if ($nik !== null): ?>
                            <hr>
                            <?php if (!empty($alokasi)): ?>
                                <div class="alert alert-success bg-light text-dark border border-success p-3 mb-3">
                                    <span class="small text-muted">Nama Anggota Poktan:</span>
                                    <h5 class="font-weight-bold mb-0 text-emerald"><?= esc($alokasi[0]['nama_petani']) ?></h5>
                                    <small class="text-secondary">NIK: <b><?= esc($alokasi[0]['nik']) ?></b></small>
                                </div>

                                <div class="table-responsive">
                                    <table class="table table-bordered table-striped mb-0 text-center">
                                        <thead class="bg-emerald-landing text-white">
                                            <tr>
                                                <th>Pupuk</th>
                                                <th>Jatah (Kg)</th>
                                                <th>Terpakai</th>
                                                <th>Sisa Kuota</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($alokasi as $row): 
                                                $sisaKuota = $row['jatah_kg'] - $row['terpakai_kg'];
                                            ?>
                                                <tr>
                                                    <td class="text-left font-weight-bold"><?= esc($row['nama_pupuk']) ?></td>
                                                    <td><?= number_format($row['jatah_kg'], 0, ',', '.') ?></td>
                                                    <td class="text-danger font-weight-bold"><?= number_format($row['terpakai_kg'], 0, ',', '.') ?></td>
                                                    <td>
                                                        <?php if($sisaKuota <= 0): ?>
                                                            <span class="badge badge-danger px-2 py-1">Habis</span>
                                                        <?php else: ?>
                                                            <span class="badge badge-success bg-emerald px-2 py-1"><?= number_format($sisaKuota, 0, ',', '.') ?> Kg</span>
                                                        <?php endif; ?>
                                                    </td>
                                                </tr>
                                            <?php endforeach; ?>
                                        </tbody>
                                    </table>
                                </div>
                            <?php else: ?>
                                <div class="text-center text-muted py-4 shadow-sm rounded border bg-light">
                                    <i class="fas fa-folder-open fa-3x mb-2 text-warning"></i>
                                    <h5 class="font-weight-bold text-dark mb-1">Data Tidak Ditemukan</h5>
                                    <p class="small px-3 mb-0">NIK <b><?= esc($nik) ?></b> tidak terdaftar dalam database alokasi e-RDKK kelompok tani tahun ini.</p>
                                </div>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <!-- KOLOM KANAN: LOG PASOKAN MASUK -->
            <div class="col-lg-5 mb-4">
                <div class="card shadow-sm border-0 card-outline-emerald h-100">
                    <div class="card-body p-4">
                        <h4 class="font-weight-bold text-emerald mb-2"><i class="fas fa-truck-loading mr-2"></i> Kiriman Pasokan Masuk</h4>
                        <p class="text-muted small mb-3">Catatan kedatangan stok pupuk bersubsidi terbaru di gudang kelompok.</p>
                        
                        <div class="list-group list-group-flush">
                            <?php if (!empty($pupuk_masuk)): ?>
                                <?php foreach ($pupuk_masuk as $pm): ?>
                                    <div class="list-group-item px-0 py-3 border-bottom">
                                        <div class="d-flex w-100 justify-content-between align-items-center mb-1">
                                            <h6 class="font-weight-bold text-dark mb-0"><?= esc($pm['nama_pupuk']) ?></h6>
                                            <span class="badge badge-info px-2 py-1">+ <?= number_format($pm['jumlah_masuk'], 0, ',', '.') ?> Kg</span>
                                        </div>
                                        <div class="d-flex justify-content-between text-muted small">
                                            <span>Kode: <b><?= esc($pm['kode_pupuk']) ?></b></span>
                                            <span><i class="far fa-calendar-alt mr-1"></i> <?= date('d M Y', strtotime($pm['tanggal_masuk'])) ?></span>
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <div class="text-center text-muted py-5">
                                    <i class="fas fa-boxes fa-2x mb-2"></i>
                                    <p class="mb-0">Belum ada catatan aktivitas pasokan barang masuk.</p>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- REVISI 1: SEKSI TENTANG KAMI -->
    <section id="tentang-kami" class="mb-5 pt-3">
        <div class="card shadow-sm border-0 card-outline-emerald">
            <div class="card-body p-4 p-md-5">
                <div class="row align-items-center">
                    <div class="col-md-12">
                        <span class="badge badge-success bg-emerald px-3 py-1 mb-2">Profil Kelompok</span>
                        <h3 class="font-weight-bold text-emerald mb-3">Kelompok Tani Sari Rasa</h3>
                        <p class="text-justify leading-relaxed">
                            Kelompok Tani Sari Rasa merupakan kelompok tani yang berada di <b>Desa Trahean, Kecamatan Teweh Selatan, Kabupaten Barito Utara</b>. Kelompok tani ini dibentuk sebagai wadah bagi para petani untuk saling bekerja sama, meningkatkan pengetahuan, serta mengembangkan usaha tani yang produktif dan berkelanjutan.
                        </p>
                        <p class="text-justify leading-relaxed">
                            Seiring perkembangan teknologi, Kelompok Tani Sari Rasa menghadirkan <b>Sistem Informasi Manajemen (SIM) Sari Rasa</b> sebagai media informasi dan pelayanan digital. Sistem ini memudahkan anggota dalam memperoleh informasi mengenai stok pupuk, penyaluran pupuk bersubsidi, kuota e-RDKK, data anggota, serta berbagai informasi lainnya secara cepat, transparan, dan mudah diakses.
                        </p>
                        <p class="text-justify leading-relaxed mb-0">
                            Melalui sistem ini diharapkan pengelolaan administrasi kelompok tani menjadi lebih efektif, meningkatkan transparansi penyaluran pupuk bersubsidi, serta mendukung pelayanan yang lebih baik bagi seluruh anggota Kelompok Tani Sari Rasa.
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- REVISI 1: SEKSI VISI & MISI -->
    <section id="visi-misi" class="mb-5 pt-3">
        <div class="row">
            <div class="col-md-5 mb-4 mb-md-0">
                <div class="card shadow-sm border-0 bg-emerald-landing text-white h-100">
                    <div class="card-body p-4 p-md-5 d-flex flex-column justify-content-center">
                        <i class="fas fa-eye fa-3x text-warning mb-3"></i>
                        <h3 class="font-weight-bold mb-3">Visi Kami</h3>
                        <p class="lead mb-0" style="font-size: 1.1rem; line-height: 1.6;">
                            "Menjadi kelompok tani yang mandiri, maju, dan berdaya saing melalui pengelolaan pertanian yang produktif serta pemanfaatan teknologi informasi."
                        </p>
                    </div>
                </div>
            </div>
            <div class="col-md-7">
                <div class="card shadow-sm border-0 card-outline-emerald h-100">
                    <div class="card-body p-4 p-md-5">
                        <h3 class="font-weight-bold text-emerald mb-4"><i class="fas fa-bullseye mr-2"></i> Misi Kami</h3>
                        <ul class="list-unstyled mb-0">
                            <li class="media mb-3">
                                <span class="bg-emerald text-white rounded-circle p-2 mr-3 font-weight-bold d-flex align-items-center justify-content-center" style="width: 36px; height: 36px;">1</span>
                                <div class="media-body pt-1">
                                    <h6 class="font-weight-bold mb-1">Kesejahteraan Anggota</h6>
                                    <p class="text-muted mb-0">Meningkatkan kesejahteraan anggota kelompok tani.</p>
                                </div>
                            </li>
                            <li class="media mb-3">
                                <span class="bg-emerald text-white rounded-circle p-2 mr-3 font-weight-bold d-flex align-items-center justify-content-center" style="width: 36px; height: 36px;">2</span>
                                <div class="media-body pt-1">
                                    <h6 class="font-weight-bold mb-1">Transparansi Pupuk Bersubsidi</h6>
                                    <p class="text-muted mb-0">Mengelola penyaluran pupuk bersubsidi secara transparan dan tepat sasaran.</p>
                                </div>
                            </li>
                            <li class="media mb-3">
                                <span class="bg-emerald text-white rounded-circle p-2 mr-3 font-weight-bold d-flex align-items-center justify-content-center" style="width: 36px; height: 36px;">3</span>
                                <div class="media-body pt-1">
                                    <h6 class="font-weight-bold mb-1">Pemanfaatan Teknologi Digital</h6>
                                    <p class="text-muted mb-0">Memanfaatkan teknologi informasi untuk meningkatkan pelayanan dan administrasi kelompok tani.</p>
                                </div>
                            </li>
                            <li class="media">
                                <span class="bg-emerald text-white rounded-circle p-2 mr-3 font-weight-bold d-flex align-items-center justify-content-center" style="width: 36px; height: 36px;">4</span>
                                <div class="media-body pt-1">
                                    <h6 class="font-weight-bold mb-1">Kebersamaan & Kebangkitan</h6>
                                    <p class="text-muted mb-0">Meningkatkan kerja sama dan kebersamaan antaranggota.</p>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- REVISI 4: SEKSI CONTACT PERSON KETUA KELOMPOK TANI -->
    <section id="kontak" class="mb-5 pt-3">
        <div class="card shadow-sm border-0 card-outline-emerald">
            <div class="card-body p-4 p-md-5">
                <div class="row align-items-center">
                    <div class="col-md-6 mb-4 mb-md-0">
                        <span class="badge badge-success bg-emerald px-3 py-1 mb-2">Layanan Informasi</span>
                        <h3 class="font-weight-bold text-emerald mb-3">Hubungi Pengurus Kelompok</h3>
                        <p class="text-muted">Jika Anda membutuhkan bantuan terkait keanggotaan, kendala kuota e-RDKK, atau jadwal penebusan pupuk, silakan hubungi Ketua Kelompok Tani Sari Rasa.</p>
                        
                        <div class="d-flex align-items-center mt-4">
                            <div class="bg-emerald text-white rounded-circle p-3 mr-3">
                                <i class="fas fa-id-card-alt fa-2x"></i>
                            </div>
                            <div>
                                <h5 class="font-weight-bold mb-0">Ketua Kelompok Tani</h5>
                                <p class="text-emerald font-weight-bold mb-0">Poktan Sari Rasa — Desa Trahean</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-md-6">
                        <div class="bg-light p-4 rounded border">
                            <div class="media mb-3">
                                <i class="fas fa-map-marker-alt text-emerald fa-1x mr-3 mt-1"></i>
                                <div class="media-body">
                                    <strong class="d-block text-dark">Alamat Sekretariat:</strong>
                                    <span class="text-muted">Desa Trahean, Kecamatan Teweh Selatan, Kabupaten Barito Utara, Kalimantan Tengah</span>
                                </div>
                            </div>
                            <div class="media mb-3">
                                <i class="fas fa-phone-alt text-emerald fa-1x mr-3 mt-1"></i>
                                <div class="media-body">
                                    <strong class="d-block text-dark">Telepon / WhatsApp Ketua:</strong>
                                    <a href="https://wa.me/6281234567890" target="_blank" class="text-emerald font-weight-bold">+62 812-3456-7890</a>
                                </div>
                            </div>
                            <div class="media">
                                <i class="fas fa-clock text-emerald fa-1x mr-3 mt-1"></i>
                                <div class="media-body">
                                    <strong class="d-block text-dark">Jam Pelayanan Penebusan:</strong>
                                    <span class="text-muted">Senin - Sabtu (08.00 - 16.00 WIB)</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

</div>

<!-- REVISI FOOTER -->
<footer class="bg-emerald-landing text-white py-4 mt-5">
    <div class="container text-center">
        <h5 class="font-weight-bold mb-1">SIM Sari Rasa &copy; 2026</h5>
        <p class="mb-1 font-weight-bold text-warning">Kelompok Tani Sari Rasa</p>
        <p class="small opacity-75 mb-0">Desa Trahean, Kecamatan Teweh Selatan, Kabupaten Barito Utara</p>
    </div>
</footer>

<!-- JS Script Dependencies -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>