<div class="container-fluid" id="container-wrapper">
  <!-- Page Header -->
  <div class="mutasi-pagehead d-flex flex-wrap align-items-center justify-content-between mb-3">
    <div class="mb-2 mb-md-0">
      <h1 class="h3 mb-0 text-gray-800">Mutasi</h1>
      <div class="text-muted small">Timeline perpindahan saldo antar kas/rekening.</div>
    </div>
  </div>

  <div class="row justify-content-center">
    <div class="col-12">
      <div class="card mutasi-card shadow-sm">
        <div class="card-body">
          <div class="card-block">
            <div class="mutasi-toolbar card-header d-flex flex-wrap align-items-center justify-content-between">
              <h5 class="card-title mb-0">Timeline Mutasi</h5>

              <!-- Toolbar (tetap pakai class & id lama agar mutasi.js aman) -->
              <div class="btn-group cetak_laporan mutasi-actions" role="group" aria-label="Mutasi actions">
                <button type="button" data-info="mutasi" class="btn btn-success btn-sm add_mutasi" data-id="0">
                  <i class="fa fa-plus"></i> Buat Mutasi
                </button>

                <div class="btn-group" role="group" aria-label="Date range">
                  <div id="reportrange" class="mutasi-daterange">
                    <i class="fa fa-calendar"></i>&nbsp;
                    <span></span> <i class="fa fa-caret-down"></i>
                  </div>
                </div>
              </div>
            </div>

            <!-- Timeline container (id tetap: dataMutasi) -->
            <div class="vertical-timeline vertical-timeline--animate vertical-timeline--one-column" id="dataMutasi"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- Modal (struktur & id tetap agar JS aman) -->
<div id="ModalMutasi" class="modal left fade" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content flat">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalScrollableTitle">Mutasi Kas</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

      <div class="modal-body">
        <form id="myForm" enctype="multipart/form-data"> <!-- [FIX] wajib ada spasi sebelum enctype -->
          <input type="hidden" name="id_mutasi" id="id_mutasi" value="0">
          <input type="hidden" name="type" id="type">

          <div class="row">
            <div class="col-12">

              <div class="form-group mb-2">
                <label for="dari_kas" class="mb-1">Dari Kas</label>
                <select name="dari_kas" id="dari_kas" class="form-control form-control-sm" required></select>
              </div>

              <div class="form-group mb-2 rekening_dari" style="display:none">
                <label for="rekening_dari" class="mb-1">Rekening/Merchant</label>
                <select name="rekening_dari" id="rekening_dari" class="form-control form-control-sm" required></select>
              </div>

              <div class="form-group mb-2">
                <label for="tujuan" class="mb-1">Tujuan Kas</label>
                <select name="tujuan" id="tujuan" class="form-control form-control-sm" required>
                  <option value="">Pilih</option>
                  <option value="1">Ya</option>
                  <option value="0">Tidak</option>
                </select>
              </div>

              <div class="form-group mb-2 rekening" style="display:none">
                <label for="rekening" class="mb-1">Rekening/Merchant</label>
                <select name="rekening" id="rekening" class="form-control form-control-sm" required></select>
              </div>

              <div class="form-group mb-2">
                <label for="saldo" class="mb-1">Total Saldo</label>
                <div class="input-group">
                  <input type="text" name="saldo" id="saldo" value="0" class="form-control form-control-sm" readonly>
                  <div class="input-group-append">
                    <button class="btn btn-outline-info btn-sm cek_saldo" type="button">Cek</button>
                  </div>
                </div>
              </div>

              <div class="form-group mb-2">
                <label for="jumlah" class="mb-1">Jumlah</label>
                <input type="text" name="jumlah" id="jumlah" class="form-control form-control-sm input" onkeyup="formatNumber(this);" required>
              </div>

              <div class="form-group mb-2">
                <label for="catatan" class="mb-1">Catatan</label>
                <input type="text" name="catatan" id="catatan" class="form-control form-control-sm input" required>
              </div>

              <!-- [ADD] Upload Bukti Mutasi (Opsional) -->
              <div class="form-group mb-2">
                <label for="bukti_mutasi" class="mb-1">Lampiran Bukti (Opsional)</label>
                <input type="file" name="bukti_mutasi" id="bukti_mutasi"
                       class="form-control form-control-sm"
                       accept=".jpg,.jpeg,.png,.pdf">
                <small class="text-muted">Format: JPG/JPEG/PNG/PDF. Maks 6MB.</small>
              </div>
              <!-- [END ADD] Upload Bukti Mutasi -->

              <div class="form-group d-flex flex-row"></div>
            </div>
          </div>
        </form>
      </div>

      <div class="modal-footer">
        <button type="button" name="submit" class="btn btn-info save_mutasi">Simpan</button>
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>


<script src="<?= base_url('assets/'); ?>js/mutasi.js?r=<?=asset_version('assets/js/mutasi.js');?>"></script>

<style>
  /* ====== Modern + Responsive (tanpa ubah logic) ====== */
  :root{
    --mutasi-border: rgba(0,0,0,.08);
    --mutasi-muted: #6b7280;
    --mutasi-bgsoft: #f8fafc;
    --mutasi-line: #e9ecef;
  }

  .mutasi-card{
    border: 1px solid var(--mutasi-border);
    border-radius: 14px;
    overflow: hidden;
  }

  .mutasi-toolbar{
    background: linear-gradient(180deg, #ffffff, #fbfdff);
    border-bottom: 1px solid var(--mutasi-border);
    padding: .85rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    gap: .75rem;
  }

  .mutasi-toolbar .card-title{
    font-weight: 700;
    letter-spacing: .2px;
  }

  .mutasi-actions{
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    justify-content: flex-end;
  }

  /* Override inline style reportrange (tetap pakai id yang sama) */
  #reportrange.mutasi-daterange{
    background: #fff;
    cursor: pointer;
    padding: .45rem .65rem;
    border: 1px solid var(--mutasi-border);
    border-radius: 10px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    white-space: nowrap;
    font-size: .875rem;
  }

  /* ====== Timeline Responsive ====== */
  /*
  .vertical-timeline{
    width: 100%;
    position: relative;
    padding: .75rem 0 1rem;
  }

  .vertical-timeline::before{
    content:'';
    position:absolute;
    top: 0;
    left: 28px;            /* lebih rapih */
    height: 100%;
    width: 4px;
    background: var(--mutasi-line);
    border-radius: 999px;
  }
 /*
  .vertical-timeline-element{
    position: relative;
    margin: 0 0 1rem;
  }

  .vertical-timeline-element-icon{
    position: absolute;
    top: .2rem;
    left: 20px;
    z-index: 2;
  }

  .vertical-timeline-element-icon .badge-dot-xl{
    box-shadow: 0 0 0 6px #fff;
    border-radius: 999px;
  }

  .badge-dot-xl{
    width: 16px;
    height: 16px;
    position: relative;
  }

  .badge-dot-xl::before{
    content:'';
    width: 8px;
    height: 8px;
    border-radius: 999px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin: -4px 0 0 -4px;
    background: #fff;
  }

  .vertical-timeline-element-content{
    position: relative;
    margin-left: 64px; /* menyesuaikan garis kiri */
    background: #fff;
    border: 1px solid var(--mutasi-border);
    border-radius: 14px;
    padding: .85rem .95rem;
    font-size: .9rem;
    box-shadow: 0 1px 0 rgba(0,0,0,.02);
  }
 /*
  .vertical-timeline-element-content .timeline-title{
    font-size: .85rem;
    text-transform: uppercase;
    margin: 0 0 .35rem;
    font-weight: 800;
    letter-spacing: .4px;
  }

  .vertical-timeline-element-content .vertical-timeline-element-date{
    display: inline-flex;
    margin-bottom: .5rem;
    padding: .2rem .55rem;
    border-radius: 999px;
    background: var(--mutasi-bgsoft);
    color: var(--mutasi-muted);
    font-size: .78rem;
    white-space: nowrap;
  }

  .vertical-timeline-element-content:after{
    content:"";
    display: table;
    clear: both;
  }

  /* Animasi bawaan tetap aman */
  .vertical-timeline--animate .vertical-timeline-element-icon.bounce-in{
    visibility: visible;
    animation: cd-bounce-1 .8s;
  }
  */

  /* ====== Modal Left Responsive ====== */
  .modal.left .modal-dialog{
    position: fixed;
    margin: 0;
    width: 420px;
    max-width: 92vw;
    height: 100%;
    left: 0;
    top: 0;
    transform: translate3d(-100%,0,0);
  }

  .modal.left.show .modal-dialog,
  .modal.left.in .modal-dialog{ /* bootstrap 4 compatibility */
    transform: translate3d(0,0,0);
  }

  .modal.left .modal-content{
    height: 100%;
    border: 0;
    border-radius: 0 16px 16px 0;
    overflow: hidden;
  }

  .modal.left .modal-header{
    background: #fff;
    border-bottom: 1px solid var(--mutasi-border);
  }

  .modal.left .modal-title{
    font-weight: 800;
  }

  .modal.left .modal-body{
    background: #fff;
  }

  .modal.left .modal-footer{
    border-top: 1px solid var(--mutasi-border);
    background: #fff;
  }

  /* ====== Small screen tweaks ====== */
  @media (max-width: 576px){
    .mutasi-toolbar{
      padding: .75rem .75rem;
    }
    .mutasi-actions{
      width: 100%;
      justify-content: flex-start;
    }
    #reportrange.mutasi-daterange{
      width: 100%;
      justify-content: space-between;
    }
    .vertical-timeline::before{ left: 22px; }
    .vertical-timeline-element-icon{ left: 14px; }
    .vertical-timeline-element-content{ margin-left: 54px; padding: .75rem .8rem; }
  }
</style>
