<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

<style>
/* ─── DESIGN TOKENS ──────────────────────────────────────── */
:root {
  --teal-900: #0d3d38;
  --teal-800: #0b5a52;
  --teal-700: #0b7a6e;
  --teal-600: #0d9488;
  --teal-500: #14b8a6;
  --teal-400: #2dd4bf;
  --teal-100: #ccfbf1;
  --teal-50:  #f0fdfa;
  --green-500: #10b981;
  --green-600: #059669;
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --amber-50:  #fffbeb;
  --amber-100: #fef3c7;
  --red-400:  #f87171;
  --red-500:  #ef4444;
  --red-600:  #dc2626;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --slate-50: #f8fafc;
  --slate-100:#f1f5f9;
  --slate-200:#e2e8f0;
  --slate-400:#94a3b8;
  --slate-500:#64748b;
  --slate-700:#334155;
  --slate-900:#0f172a;
  --card-shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 20px rgba(0,0,0,.06);
  --primary:       var(--teal-700);
  --primary-dark:  var(--teal-800);
  --primary-light: var(--teal-50);
  --primary-mid:   var(--teal-500);
  --radius:        14px;
  --radius-sm:     9px;
  --radius-xs:     6px;
  --shadow:        0 4px 24px rgba(13,148,136,0.10), 0 1px 4px rgba(0,0,0,0.05);
  --shadow-sm:     var(--card-shadow);
}

/* ─── WRAPPER ─────────────────────────────────────────────── */
/* ─── WRAPPER ─────────────────────────────────────────────── */
/* JADI: */
.ar-wrapper {
  width: 100%;
}
/* ─── PAGE HEADER ─────────────────────────────────────────── */
.ar-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 14px;
}
.ar-header-left h4 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--teal-800);
  margin: 0 0 5px;
  display: flex;
  align-items: center;
  gap: 11px;
  letter-spacing: -.3px;
}
.ar-header-left h4 .hi {
  width: 40px; height: 40px;
  border-radius: 11px;
  
  background: linear-gradient(135deg, var(--teal-600), var(--teal-500));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.05rem;
  box-shadow: 0 4px 12px rgba(13,148,136,0.32);
  flex-shrink: 0;
}
.ar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.77rem;
  color: var(--slate-400);
  padding-left: 51px;
}
.ar-breadcrumb a { color: var(--teal-600); text-decoration: none; font-weight: 600; }
.ar-breadcrumb a:hover { text-decoration: underline; }
.ar-breadcrumb .sep { color: var(--slate-200); }

.btn-tambah {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 24px;
  border-radius: 50px;
  border: none;
  background: #0d9488;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 3px 12px rgba(13,148,136,0.28);
  transition: all .2s;
  white-space: nowrap;
}
.btn-tambah:hover {
  background: #0b7a6e;
  box-shadow: 0 5px 16px rgba(13,148,136,0.38);
  transform: translateY(-1px);
  color: #fff;
}

/* ─── FLASH ALERTS ────────────────────────────────────────── */
.flash-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  margin-bottom: 20px;
  font-size: 0.85rem;
  position: relative;
}
.flash-alert.success { background: var(--teal-50); border-left: 4px solid var(--teal-600); color: var(--teal-800); }
.flash-alert.error   { background: #fef2f2; border-left: 4px solid var(--red-500); color: #7f1d1d; }
.flash-alert .fa-close {
  margin-left: auto; cursor: pointer; font-size: 1rem; opacity: .55;
  background: none; border: none; color: inherit; padding: 0; line-height: 1;
}
.flash-alert .fa-close:hover { opacity: 1; }

/* ─── STAT CARDS (gradient solid, seperti dashboard pinjaman) ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 26px;
}
.stat-card {
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 118px;
  position: relative;
  overflow: hidden;
  border: none;
  transition: transform .22s, box-shadow .22s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card.s1 { background: linear-gradient(135deg, #0d5c55, #0fb8a9); box-shadow: 0 4px 24px rgba(13,148,136,0.35); }
.stat-card.s2 { background: linear-gradient(135deg, #047857, #34d399); box-shadow: 0 4px 20px rgba(16,185,129,0.32); }
.stat-card.s3 { background: linear-gradient(135deg, #c07200, #fbbf24); box-shadow: 0 4px 20px rgba(251,191,36,0.32); }

.stat-card .sc-bg-icon {
  position: absolute;
  right: 16px; top: 50%;
  transform: translateY(-50%);
  font-size: 58px;
  opacity: 0.16;
  color: #fff;
  line-height: 1;
  pointer-events: none;
}
.stat-info .si-label {
  font-size: 0.70rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .65px;
  color: rgba(255,255,255,0.78);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.stat-info .si-label i { font-size: 0.80rem; }
.stat-info .si-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}
.stat-info .si-sub {
  font-size: 0.73rem;
  color: rgba(255,255,255,0.62);
  margin-top: 5px;
}

/* ─── MAIN CARD ───────────────────────────────────────────── */
.ar-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1.5px solid var(--slate-100);
}
.ar-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1.5px solid var(--slate-100);
  background: var(--slate-50);
  flex-wrap: wrap;
  gap: 10px;
}
.ar-card-header h5 {
  font-size: 0.92rem; font-weight: 700; color: var(--teal-800);
  margin: 0; display: flex; align-items: center; gap: 8px;
}
.ar-card-header h5 i { color: var(--teal-500); }

/* ─── EMPTY STATE ─────────────────────────────────────────── */
.empty-state { text-align: center; padding: 64px 24px; }
.empty-state-icon {
  width: 76px; height: 76px; border-radius: 50%;
  background: var(--teal-50);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px; font-size: 2.1rem;
}
.empty-state h6 { font-weight: 700; color: var(--slate-700); margin-bottom: 6px; }
.empty-state p  { font-size: 0.84rem; color: var(--slate-400); margin: 0; }

/* ─── TABLE ───────────────────────────────────────────────── */
.ar-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ar-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.ar-table thead tr { background: var(--slate-50); border-bottom: 2px solid var(--slate-200); }
.ar-table thead th {
  padding: 13px 18px; font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .65px; color: var(--slate-400); white-space: nowrap;
}
.ar-table thead th.center { text-align: center; }
.ar-table tbody tr { border-bottom: 1px solid var(--slate-100); transition: background .15s; }
.ar-table tbody tr:hover { background: var(--teal-50); }
.ar-table tbody tr:last-child { border-bottom: none; }
.ar-table tbody td { padding: 15px 18px; font-size: 0.87rem; color: var(--slate-700); vertical-align: middle; }
.ar-table tbody td.center { text-align: center; }

/* ─── TABLE CELL PARTS ────────────────────────────────────── */
.no-cell { color: var(--slate-400); font-size: 0.79rem; font-weight: 600; }
.arisan-name { font-weight: 700; color: var(--teal-800); font-size: 0.91rem; }
.arisan-desc { font-size: 0.75rem; color: var(--slate-400); margin-top: 2px; }
.nominal-cell { font-weight: 700; color: var(--slate-900); font-size: 0.93rem; }
.periode-pill { display: inline-block; border-radius: 50px; padding: 3px 12px; font-size: 0.72rem; font-weight: 700; }
.periode-pill.bulanan    { background: var(--teal-50);  color: var(--teal-700); border: 1px solid var(--teal-100); }
.periode-pill.mingguan   { background: var(--amber-50); color: var(--amber-600); border: 1px solid var(--amber-100); }
.periode-pill.dua-minggu { background: #f5f3ff; color: #6d28d9; border: 1px solid #ede9fe; }
.date-cell { font-size: 0.82rem; color: var(--slate-500); white-space: nowrap; }
.peserta-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--slate-100); border-radius: 50px; padding: 4px 13px;
  font-size: 0.76rem; font-weight: 700; color: var(--slate-700);
}
.status-pill {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 50px; padding: 4px 13px; font-size: 0.73rem; font-weight: 700; white-space: nowrap;
}
.status-pill.aktif    { background: var(--teal-50);  color: var(--teal-700);  border: 1px solid var(--teal-100); }
.status-pill.selesai  { background: #eff6ff; color: var(--blue-600);  border: 1px solid #bfdbfe; }
.status-pill.nonaktif { background: var(--slate-100); color: var(--slate-500); border: 1px solid var(--slate-200); }

/* ─── ACTION BUTTONS ──────────────────────────────────────── */
.action-group { display: flex; align-items: center; justify-content: center; gap: 5px; flex-wrap: wrap; }
.act-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 33px; height: 33px; border-radius: var(--radius-xs);
  border: 1.5px solid transparent; font-size: 0.84rem; text-decoration: none;
  cursor: pointer; transition: all .18s; background: none; padding: 0;
}
.act-btn.people { border-color: var(--teal-100); color: var(--teal-600);  background: var(--teal-50); }
.act-btn.people:hover  { background: var(--teal-100); border-color: var(--teal-400); }
.act-btn.cal    { border-color: #bbf7d0; color: var(--green-600); background: #f0fdf4; }
.act-btn.cal:hover     { background: #bbf7d0; border-color: var(--green-500); }
.act-btn.trophy { border-color: var(--amber-100); color: var(--amber-600); background: var(--amber-50); }
.act-btn.trophy:hover  { background: var(--amber-100); border-color: var(--amber-400); }
.act-btn.edit   { border-color: var(--slate-200); color: var(--slate-500); background: var(--slate-50); }
.act-btn.edit:hover    { background: var(--slate-200); border-color: var(--slate-400); color: var(--slate-700); }

/* ─── MOBILE ──────────────────────────────────────────────── */
@media (max-width: 767px) {
  .ar-table-wrap { display: none; }
  .mobile-list { display: flex; flex-direction: column; gap: 13px; padding: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-grid .stat-card:last-child { grid-column: 1 / -1; }
  .ar-page-header { flex-direction: column; align-items: flex-start; }
  /* .ar-wrapper { padding: 0 12px 48px; } */
  .stat-card { min-height: 100px; padding: 18px 16px 16px; }
  .stat-info .si-value { font-size: 1.8rem; }
  .stat-card .sc-bg-icon { font-size: 44px; }
}
@media (min-width: 768px) {
  .mobile-list { display: none; }
}

.mobile-arisan-card {
  border: 1.5px solid var(--slate-200); border-radius: var(--radius-sm);
  padding: 15px; background: #fff; transition: box-shadow .2s;
}
.mobile-arisan-card:hover { box-shadow: var(--shadow-sm); border-color: var(--teal-100); }
.mac-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 9px; }
.mac-name    { font-weight: 700; color: var(--teal-800); font-size: 0.92rem; }
.mac-nominal { font-size: 0.97rem; font-weight: 800; color: var(--teal-600); }
.mac-meta    { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 13px; }
.mac-actions { display: flex; gap: 8px; }
.mac-actions .act-btn { flex: 1; border-radius: var(--radius-xs); width: auto; height: 36px; padding: 0 10px; gap: 5px; font-size: 0.78rem; }
.mac-actions .act-btn span { font-size: 0.74rem; font-weight: 600; }

/* ─── DATATABLES ─────────────────────────────────────────── */
.ar-dt-top { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px 10px; flex-wrap: wrap; gap: 10px; }
.ar-dt-bot { display: flex; justify-content: space-between; align-items: center; padding: 10px 24px 16px; flex-wrap: wrap; gap: 10px; }
.dataTables_filter label { font-size: 0.83rem; color: var(--slate-500); }
.dataTables_length label { font-size: 0.83rem; color: var(--slate-500); }
.dataTables_info          { font-size: 0.8rem;  color: var(--slate-400); }
.paginate_button { border-radius: var(--radius-xs) !important; font-size: 0.82rem !important; }
.paginate_button.current { background: var(--teal-600) !important; border-color: var(--teal-600) !important; color: #fff !important; }
</style>
<!-- Harus ada di header.php, SEBELUM konten view -->
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>
<div class="ar-wrapper">

  <!-- ── Page Header ── -->
  <div class="ar-page-header">
    <div class="ar-header-left">
      <h4>
        <span class="hi"><i class="bi bi-gift"></i></span>
        Manajemen Arisan RT
      </h4>
      <div class="ar-breadcrumb">
        <a href="<?php echo base_url('dashboard'); ?>">Dashboard</a>
        <span class="sep">/</span>
        <span>Arisan</span>
      </div>
    </div>
    <?php if(is_admin()): ?>
    <a href="<?php echo base_url('arisan/tambah'); ?>" class="btn-tambah">
      <i class="bi bi-plus-circle"></i> Buat Arisan Baru
    </a>
    <?php endif; ?>
  </div>

  <!-- ── Flash Alerts ── -->
  <?php if($this->session->flashdata('success')): ?>
  <div class="flash-alert success" id="flashSuccess">
    <i class="bi bi-check-circle-fill"></i>
    <span><?php echo $this->session->flashdata('success'); ?></span>
    <button class="fa-close" onclick="this.parentElement.remove()">✕</button>
  </div>
  <?php endif; ?>
  <?php if($this->session->flashdata('error')): ?>
  <div class="flash-alert error" id="flashError">
    <i class="bi bi-exclamation-triangle-fill"></i>
    <span><?php echo $this->session->flashdata('error'); ?></span>
    <button class="fa-close" onclick="this.parentElement.remove()">✕</button>
  </div>
  <?php endif; ?>

  <!-- ── Stat Cards ── -->
  <?php
  $total_peserta_all = 0;
  foreach($arisan_list as $a) {
    $total_peserta_all += $this->Arisan_model->count_peserta_by_arisan($a->id);
  }
  ?>
  <div class="stat-grid">
    <div class="stat-card s1">
      <div class="sc-bg-icon"><i class="bi bi-gift-fill"></i></div>
      <div class="stat-info">
        <div class="si-label"><i class="bi bi-gift-fill"></i> Total Arisan</div>
        <div class="si-value"><?php echo count($arisan_list); ?></div>
        <div class="si-sub">Seluruh arisan terdaftar</div>
      </div>
    </div>
    <div class="stat-card s2">
      <div class="sc-bg-icon"><i class="bi bi-activity"></i></div>
      <div class="stat-info">
        <div class="si-label"><i class="bi bi-activity"></i> Arisan Aktif</div>
        <div class="si-value"><?php echo $total_arisan_aktif; ?></div>
        <div class="si-sub">Sedang berjalan</div>
      </div>
    </div>
    <div class="stat-card s3">
      <div class="sc-bg-icon"><i class="bi bi-people-fill"></i></div>
      <div class="stat-info">
        <div class="si-label"><i class="bi bi-people-fill"></i> Total Peserta</div>
        <div class="si-value"><?php echo $total_peserta_all; ?></div>
        <div class="si-sub">Dari semua arisan</div>
      </div>
    </div>
  </div>

  <!-- ── Main Card ── -->
  <div class="ar-card">
    <div class="ar-card-header">
      <h5><i class="bi bi-list-ul"></i> Daftar Arisan</h5>
    </div>

    <?php if(empty($arisan_list)): ?>
      <div class="empty-state">
        <div class="empty-state-icon">🎁</div>
        <h6>Belum Ada Arisan</h6>
        <p>Buat arisan baru untuk memulai.</p>
      </div>

    <?php else: ?>

      <!-- Desktop Table -->
      <div class="ar-table-wrap">
        <table class="ar-table" id="tableArisan">
          <thead>
            <tr>
              <th style="width:48px">No</th>
              <th>Nama Arisan</th>
              <th>Nominal Iuran</th>
              <th>Periode</th>
              <th>Tgl Mulai</th>
              <th class="center">Peserta</th>
              <th>Status</th>
              <th class="center" style="width:180px">Aksi</th>
            </tr>
          </thead>
          <tbody>
            <?php $no = 1; foreach($arisan_list as $a):
              $tp = $this->Arisan_model->count_peserta_by_arisan($a->id);
              $periode_class = 'bulanan';
              if($a->periode == 'mingguan')       $periode_class = 'mingguan';
              elseif($a->periode == 'dua_minggu') $periode_class = 'dua-minggu';
            ?>
            <tr>
              <td class="no-cell"><?php echo $no++; ?></td>
              <td>
                <div class="arisan-name"><?php echo $a->nama_arisan; ?></div>
                <?php if(!empty($a->keterangan)): ?>
                  <div class="arisan-desc"><?php echo $a->keterangan; ?></div>
                <?php endif; ?>
              </td>
              <td><span class="nominal-cell">Rp <?php echo number_format($a->nominal_iuran, 0, ',', '.'); ?></span></td>
              <td>
                <span class="periode-pill <?php echo $periode_class; ?>">
                  <?php echo ucfirst(str_replace('_', ' ', $a->periode)); ?>
                </span>
              </td>
              <td class="date-cell"><?php echo date('d M Y', strtotime($a->tanggal_mulai)); ?></td>
              <td class="center">
                <span class="peserta-pill"><i class="bi bi-people"></i> <?php echo $tp; ?></span>
              </td>
              <td>
                <?php if($a->status == 'aktif'): ?>
                  <span class="status-pill aktif"><i class="bi bi-circle-fill" style="font-size:.42rem"></i> Aktif</span>
                <?php elseif($a->status == 'selesai'): ?>
                  <span class="status-pill selesai"><i class="bi bi-flag-fill" style="font-size:.58rem"></i> Selesai</span>
                <?php else: ?>
                  <span class="status-pill nonaktif"><i class="bi bi-circle" style="font-size:.42rem"></i> Nonaktif</span>
                <?php endif; ?>
              </td>
              <td class="center">
                <div class="action-group">
                  <a href="<?php echo base_url('arisan/peserta/'.$a->id); ?>" class="act-btn people" title="Kelola Peserta"><i class="bi bi-people"></i></a>
                  <a href="<?php echo base_url('arisan/pertemuan/'.$a->id); ?>" class="act-btn cal" title="Pertemuan"><i class="bi bi-calendar-event"></i></a>
                  <a href="<?php echo base_url('arisan/riwayat/'.$a->id); ?>" class="act-btn trophy" title="Riwayat Pemenang"><i class="bi bi-trophy"></i></a>
                  <?php if(is_admin()): ?>
                  <a href="<?php echo base_url('arisan/edit/'.$a->id); ?>" class="act-btn edit" title="Edit"><i class="bi bi-pencil"></i></a>
                  <?php endif; ?>
                </div>
              </td>
            </tr>
            <?php endforeach; ?>
          </tbody>
        </table>
      </div>

      <!-- Mobile Cards -->
      <div class="mobile-list">
        <?php foreach($arisan_list as $a):
          $tp = $this->Arisan_model->count_peserta_by_arisan($a->id);
          $periode_class = 'bulanan';
          if($a->periode == 'mingguan')       $periode_class = 'mingguan';
          elseif($a->periode == 'dua_minggu') $periode_class = 'dua-minggu';
        ?>
        <div class="mobile-arisan-card">
          <div class="mac-top">
            <div>
              <div class="mac-name"><?php echo $a->nama_arisan; ?></div>
              <?php if(!empty($a->keterangan)): ?>
                <div style="font-size:.75rem;color:var(--slate-400);margin-top:2px"><?php echo $a->keterangan; ?></div>
              <?php endif; ?>
            </div>
            <div class="mac-nominal">Rp <?php echo number_format($a->nominal_iuran, 0, ',', '.'); ?></div>
          </div>
          <div class="mac-meta">
            <span class="periode-pill <?php echo $periode_class; ?>"><?php echo ucfirst(str_replace('_', ' ', $a->periode)); ?></span>
            <span class="peserta-pill"><i class="bi bi-people"></i> <?php echo $tp; ?> peserta</span>
            <?php if($a->status == 'aktif'): ?>
              <span class="status-pill aktif"><i class="bi bi-circle-fill" style="font-size:.42rem"></i> Aktif</span>
            <?php elseif($a->status == 'selesai'): ?>
              <span class="status-pill selesai"><i class="bi bi-flag-fill" style="font-size:.58rem"></i> Selesai</span>
            <?php else: ?>
              <span class="status-pill nonaktif"><i class="bi bi-circle" style="font-size:.42rem"></i> Nonaktif</span>
            <?php endif; ?>
            <span style="font-size:.73rem;color:var(--slate-400)">
              <i class="bi bi-calendar3 me-1"></i><?php echo date('d M Y', strtotime($a->tanggal_mulai)); ?>
            </span>
          </div>
          <div class="mac-actions">
            <a href="<?php echo base_url('arisan/peserta/'.$a->id); ?>" class="act-btn people"><i class="bi bi-people"></i><span>Peserta</span></a>
            <a href="<?php echo base_url('arisan/pertemuan/'.$a->id); ?>" class="act-btn cal"><i class="bi bi-calendar-event"></i><span>Pertemuan</span></a>
            <a href="<?php echo base_url('arisan/riwayat/'.$a->id); ?>" class="act-btn trophy"><i class="bi bi-trophy"></i><span>Riwayat</span></a>
            <?php if(is_admin()): ?>
            <a href="<?php echo base_url('arisan/edit/'.$a->id); ?>" class="act-btn edit"><i class="bi bi-pencil"></i><span>Edit</span></a>
            <?php endif; ?>
          </div>
        </div>
        <?php endforeach; ?>
      </div>

    <?php endif; ?>
  </div>
</div>

<script>
$(document).ready(function() {
  $('#tableArisan').DataTable({
    language: { url: '<?php echo base_url("assets/json/id.json"); ?>' },
    order: [[4, 'desc']],
    pageLength: 25,
    responsive: true,
    dom: '<"ar-dt-top"lf>rt<"ar-dt-bot"ip>',
    initComplete: function() {
      $('.dataTables_filter input').css({
        'border': '1.5px solid #e2e8f0', 'border-radius': '8px',
        'padding': '7px 13px', 'font-size': '0.84rem', 'outline': 'none'
      }).on('focus', function() {
        $(this).css({'border-color': '#0d9488', 'box-shadow': '0 0 0 3px rgba(13,148,136,0.12)'});
      }).on('blur', function() {
        $(this).css({'border-color': '#e2e8f0', 'box-shadow': 'none'});
      });
    }
  });

  setTimeout(function() {
    ['flashSuccess','flashError'].forEach(function(id) {
      var el = document.getElementById(id);
      if (el) {
        el.style.transition = 'opacity .4s';
        el.style.opacity = '0';
        setTimeout(function(){ el.remove(); }, 420);
      }
    });
  }, 4500);
});
</script>