/* ==========================================================================
   mobile.css — lapisan tampilan mobile untuk Dashboard Mapan
   --------------------------------------------------------------------------
   Semua aturan di file ini hanya aktif di layar < 992px.
   Tampilan desktop tidak berubah sama sekali.
   Dipasang SETELAH bootstrap.min.css dan style.css.
   ========================================================================== */

:root {
  --mnav-h: 58px;          /* tinggi tab bar bawah */
  --mtap: 44px;            /* ukuran minimum area sentuh */
}

/* ==========================================================================
   1. DASAR — hanya layar kecil
   ========================================================================== */
@media (max-width: 991.98px) {

  html {
    -webkit-text-size-adjust: 100%;   /* teks tidak membesar sendiri saat layar diputar */
  }

  body {
    overflow-x: hidden;               /* cegah halaman bisa digeser ke samping */
  }

  /* Background per halaman dari style.css: di HP dibuat menempel supaya
     tidak ikut memanjang saat halaman panjang. */
  body::before {
    background-attachment: scroll;
  }

  .container,
  .container-fluid {
    padding-left: 14px;
    padding-right: 14px;
  }

  /* Ruang di bawah supaya konten terakhir tidak tertutup tab bar */
  body.has-mnav {
    padding-bottom: calc(var(--mnav-h) + env(safe-area-inset-bottom) + 8px);
  }

  /* Judul halaman jangan terlalu besar di layar sempit */
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.15rem; }
  h4 { font-size: 1.05rem; }

  .card {
    border-radius: 12px;
  }

  .card-body,
  .card.p-3 {
    padding: 14px !important;
  }

  /* Jarak antar kolom saat menumpuk */
  .row > [class*="col-"] {
    margin-bottom: 12px;
  }
  .row.g-0 > [class*="col-"],
  .row.gx-0 > [class*="col-"] {
    margin-bottom: 0;
  }

  /* ---- Area sentuh & input ---- */
  .btn,
  .nav-link,
  .page-link {
    min-height: var(--mtap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn-sm {
    min-height: 38px;
  }

  .form-control,
  .form-select {
    min-height: var(--mtap);
    font-size: 16px;        /* 16px mencegah iOS melakukan zoom otomatis saat mengetik */
  }

  .form-control-sm,
  .form-select-sm {
    min-height: 38px;
    font-size: 16px;
  }

  .form-check-input {
    width: 1.25em;
    height: 1.25em;
    margin-top: .15em;
  }

  /* Tombol di dalam form dibuat selebar layar, kecuali tombol aksi di tabel
     dan tombol yang memang dikelompokkan. */
  .card form .btn:not(.btn-sm):not(.btn-close) {
    width: 100%;
  }
  .card form .btn + .btn {
    margin-top: 8px;
  }
  .btn-group .btn,
  .btn-group-sm .btn,
  .table .btn,
  td .btn,
  .input-group .btn {
    width: auto !important;
    margin-top: 0 !important;
  }

  /* Tombol aksi berderet di dalam tabel */
  td .btn + .btn,
  td .btn + form {
    margin-left: 4px;
  }
}

/* ==========================================================================
   2. NAVBAR
   ========================================================================== */
@media (max-width: 991.98px) {

  .navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    padding-top: .35rem;
    padding-bottom: .35rem;
  }

  .navbar-brand {
    font-size: 1.05rem;
    max-width: 62vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .navbar-toggler {
    min-height: var(--mtap);
    min-width: var(--mtap);
    padding: .25rem .5rem;
  }
  .navbar-toggler:focus {
    box-shadow: none;
  }

  /* Menu yang terbuka bisa digulir sendiri kalau isinya banyak */
  .navbar-collapse {
    max-height: 72vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: .5rem;
  }

  .navbar-nav .nav-item + .nav-item {
    border-top: 1px solid rgba(128, 128, 128, .18);
  }

  .navbar-nav .nav-link {
    justify-content: flex-start;
    padding: .7rem .25rem;
    font-size: 1rem;
  }

  /* Halaman yang sedang dibuka ditandai */
  .navbar-nav .nav-link.mnav-active {
    font-weight: 600;
    box-shadow: inset 3px 0 0 #0d6efd;
    padding-left: .75rem;
  }
  .navbar-dark .nav-link.mnav-active {
    box-shadow: inset 3px 0 0 #6ea8fe;
  }

  /* Blok "Hi, user (role)" + Logout di header.php */
  .navbar .d-flex.align-items-center.gap-3 {
    flex-direction: column;
    align-items: stretch !important;
    gap: .5rem !important;
    padding: .75rem .25rem calc(.5rem + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(128, 128, 128, .18);
  }
  .navbar .d-flex.align-items-center.gap-3 .btn {
    width: 100%;
  }
}

/* ==========================================================================
   3. TAB BAR BAWAH (dibuat otomatis oleh mobile.js)
   ========================================================================== */
.mnav {
  display: none;
}

@media (max-width: 991.98px) {
  .mnav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1040;
    background: #ffffff;
    border-top: 1px solid #dee2e6;
    box-shadow: 0 -2px 14px rgba(0, 0, 0, .06);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mnav a {
    flex: 1 1 0;
    min-width: 0;
    height: var(--mnav-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: #6c757d;
    font-size: 11px;
    line-height: 1;
    background: none;
    border: 0;
    padding: 0 2px;
  }

  .mnav a span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mnav a svg {
    width: 21px;
    height: 21px;
    flex: none;
  }

  .mnav a.mnav-on {
    color: #0d6efd;
    font-weight: 600;
  }

  .mnav a:active {
    background: #f1f3f5;
  }
}

/* ==========================================================================
   4. TABEL
   ========================================================================== */
@media (max-width: 991.98px) {

  /* Mode geser: tabel lebar tetap utuh, digulir mendatar */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }

  .mscroll-hint {
    display: block;
    font-size: 12px;
    color: #6c757d;
    margin: 0 0 6px;
  }

  .table > :not(caption) > * > * {
    padding: .5rem .5rem;
  }

  /* Lebar kolom yang dipatok di HTML diabaikan di layar kecil */
  .table th[style*="width"],
  .table td[style*="width"] {
    width: auto !important;
  }

  /* Matriks hak akses: kolom pertama tetap terlihat saat digeser */
  .table-perm th.sticky,
  .table-perm td.sticky {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
  }

  /* Panel tabel voucher_check yang sengaja melebar di desktop */
  .panel-tabel {
    width: 100% !important;
    margin-left: 0 !important;
  }

  .gulir {
    max-height: 60vh;
  }
}

/* ---- Mode kartu: tiap baris tabel jadi satu kartu (hanya HP) ---- */
@media (max-width: 575.98px) {

  table.mobile-cards {
    border: 0 !important;
    background: transparent;
  }

  table.mobile-cards thead {
    display: none;
  }

  table.mobile-cards,
  table.mobile-cards tbody,
  table.mobile-cards tr,
  table.mobile-cards td {
    display: block;
    width: 100%;
  }

  table.mobile-cards tr {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 6px 10px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
  }

  table.mobile-cards td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border: 0 !important;
    border-bottom: 1px solid #f1f3f5 !important;
    padding: 8px 0 !important;
    text-align: left !important;
    white-space: normal !important;
    min-width: 0;
  }

  table.mobile-cards tr td:last-child {
    border-bottom: 0 !important;
  }

  table.mobile-cards td::before {
    content: attr(data-label);
    flex: 0 0 38%;
    max-width: 38%;
    font-size: 12px;
    font-weight: 600;
    color: #6c757d;
    line-height: 1.35;
  }

  /* Sel isian panjang (kode voucher, JSON log) boleh memotong kata */
  table.mobile-cards td > * {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  /* Baris "Belum ada data" yang memakai colspan */
  table.mobile-cards td[colspan]::before {
    content: none;
  }
  table.mobile-cards td[colspan] {
    justify-content: center;
    text-align: center !important;
  }

  /* Baris aksi ditaruh penuh di bawah kartu */
  table.mobile-cards td.mcard-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  table.mobile-cards td.mcard-actions::before {
    flex-basis: 100%;
    max-width: 100%;
    margin-bottom: 2px;
  }

  /* Tabel logs yang bertema gelap */
  table.log-table.mobile-cards tr {
    background: rgba(20, 20, 26, .92);
    border-color: #333;
  }
  table.log-table.mobile-cards td {
    border-bottom-color: #2a2a2a !important;
    color: #e9ecef;
  }
  table.log-table.mobile-cards td::before {
    color: #9ca3af;
  }
  table.log-table.mobile-cards td:first-child {
    min-width: 0 !important;
    text-align: left !important;
  }
}

/* ==========================================================================
   5. HALAMAN INDEX — kartu statistik & Quick Actions
   ========================================================================== */
@media (max-width: 991.98px) {

  /* Susunan asli: 5 tombol berjajar + widget 280px di kanan.
     Di HP diubah jadi dua baris yang menumpuk. */
  .quick-actions-wrapper {
    flex-direction: column;
    gap: 12px;
  }

  .quick-actions-left {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .quick-action-item {
    min-height: 76px;
    font-size: .9rem;
    padding: 12px 8px;
  }

  /* Tombol terakhir (jumlah ganjil) memakai lebar penuh */
  .quick-actions-left > .quick-action-item:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    min-height: 58px;
  }

  .quick-actions-right {
    width: 100%;
  }

  /* Di layar sentuh tidak ada hover, jadi warnanya dibuat solid langsung */
  .quick-action-item.qa-primary   { background: #0d6efd; color: #fff; border-color: #0d6efd; }
  .quick-action-item.qa-secondary { background: #6c757d; color: #fff; border-color: #6c757d; }
  .quick-action-item.qa-success   { background: #198754; color: #fff; border-color: #198754; }
  .quick-action-item.qa-dark      { background: #212529; color: #fff; border-color: #212529; }
  .quick-action-item.disabled     { background: #e9ecef; color: #adb5bd; border-color: #dee2e6; }

  /* Kartu statistik: tiga angka jadi tiga baris ringkas */
  .card .stat,
  .card-body h3 {
    font-size: 1.5rem;
    margin-bottom: 0;
  }
  .card-body h5 {
    font-size: .95rem;
  }
}

@media (max-width: 575.98px) {
  .quick-actions-left {
    grid-template-columns: 1fr 1fr;
  }
}

/* ==========================================================================
   6. PANEL & MODAL
   ========================================================================== */
@media (max-width: 991.98px) {

  /* Panel detail log (aslinya lebar 380px menempel di kanan) */
  .detail-panel {
    width: 100% !important;
    max-width: 100% !important;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .detail-panel .btn-close,
  .detail-panel .close {
    min-width: var(--mtap);
    min-height: var(--mtap);
  }

  /* Modal dibuat hampir sepenuh layar */
  .modal-dialog {
    margin: .5rem;
    max-width: calc(100% - 1rem);
  }
  .modal-body {
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-footer .btn {
    flex: 1 1 auto;
  }

  /* Pagination */
  .pagination {
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
  }
  .pagination a,
  .page-link {
    min-width: var(--mtap);
    min-height: var(--mtap);
  }

  /* Select kecil yang dipatok lebarnya */
  select[style*="max-width"] {
    max-width: 100% !important;
  }
  .preset-select {
    width: 100% !important;
  }

  /* Ringkasan angka di voucher_check */
  .ringkasan {
    grid-template-columns: repeat(2, 1fr);
  }
  .ringkasan .nilai {
    font-size: .95rem;
  }
}

@media (max-width: 400px) {
  .ringkasan {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   7. AKSESIBILITAS
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .detail-panel,
  .quick-action-item {
    transition: none !important;
  }
}

:focus-visible {
  outline: 3px solid rgba(13, 110, 253, .55);
  outline-offset: 2px;
}
