/* =========================================================
   SIMDA — RESPONSIVE LAYOUT
   Desktop: sidebar tetap terlihat (perilaku lama, tidak berubah)
   Tablet/HP (<= 880px): sidebar jadi drawer (laci) + bottom nav
   ========================================================= */

/* ── Bottom nav & tombol tutup drawer: hanya untuk mobile ── */
#bottom-nav { display: none; }
#sidebar-close { display: none; }

/* ── Hamburger: sembunyikan di desktop, tampil di mobile ── */
#hamburger-btn { display: none; }

/* ── Overlay gelap di belakang drawer sidebar (mobile) ── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199; /* di bawah sidebar (200), di atas konten */
}
#sidebar-overlay.show { display: block; animation: fadein .15s ease; }

/* =========================================================
   BREAKPOINT 1 — Tablet & HP (≤ 880px): sidebar jadi drawer
   + bottom nav + tabel jadi kartu + target sentuh lebih besar
   ========================================================= */
@media (max-width: 880px) {

  #hamburger-btn { display: flex; }

  #sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
    width: 78vw;
    max-width: 300px;
  }
  #sidebar.mobile-open { transform: translateX(0); }

  /* Tombol X untuk menutup drawer, ditempel di pojok kanan atas logo sidebar */
  #sidebar-close {
    display: flex;
    position: absolute;
    top: 14px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    background: var(--bg3);
    border: 1px solid var(--bdr);
    color: var(--txt2);
    font-size: 14px;
    z-index: 2;
  }

  /* Nav item lebih tinggi & mudah disentuh (min. ~46px) */
  .nav-item { padding: 13px 20px; font-size: 14px; gap: 13px; }
  .nav-icon { font-size: 14px; width: 18px; }
  .nav-sect { padding: 16px 20px 6px; font-size: 10px; }
  .sb-user  { padding: 15px 20px; }
  .avatar   { width: 36px; height: 36px; font-size: 12px; }

  /* Konten utama full-width, tidak lagi digeser oleh sidebar */
  #main { margin-left: 0; }

  .topbar { padding: 0 12px; gap: 8px; height: 56px; }
  .topbar-title { font-size: 14px; }
  .topbar-bread { display: none; } /* hemat ruang di layar sempit */
  .topbar-sep   { display: none; }
  .topbar-clock { display: none; } /* info sekunder, sembunyikan di HP */
  .topbar-right { gap: 6px; }
  #conn-indicator { display: none; } /* status koneksi cukup dilihat lewat aksi, hemat ruang */

  /* Tombol ikon topbar (menu, tema, logout) — target sentuh nyaman */
  .icon-btn { width: 40px; height: 40px; font-size: 15px; }
  .theme-toggle-wrap { transform: scale(1.05); }

  /* Beri ruang bawah supaya konten tidak tertutup bottom-nav */
  #main { padding-bottom: 66px; }
  .page { padding: 14px 14px 24px; }
  .pg-header { flex-wrap: wrap; gap: 10px; }
  .pg-title { font-size: 18px; }
  .pg-actions { width: 100%; }
  .pg-actions .btn { flex: 1; justify-content: center; }

  .section-hdr { flex-wrap: wrap; gap: 10px; }
  .section-title { font-size: 14px; }

  /* Form 2 kolom → 1 kolom agar mudah diisi lewat HP */
  .form-grid-2 { grid-template-columns: 1fr; }

  /* Input & tombol form lebih besar → nyaman disentuh, tidak zoom otomatis di iOS (>=16px) */
  .form-input { padding: 11px 12px; font-size: 16px; }
  .form-label { font-size: 11px; }
  .btn { padding: 10px 16px; font-size: 13px; min-height: 40px; }
  .btn-sm { padding: 9px 12px; font-size: 12px; min-height: 36px; }

  /* Filter bar: input jadi full width bertumpuk rapi */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .form-input,
  .filter-bar .search-inp { width: 100%; max-width: none; }

  /* Tab sub-navigasi (Absensi: Sesi/Rekap, KAS: Qurban/Kas, Database: per-entitas) —
     tetap 1 baris scrollable di HP agar tidak memakan tinggi layar */
  .tabs-sub { gap:2px; margin-bottom:12px; }
  .tab-sub  { padding:9px 12px;font-size:12px;min-height:38px; }

  /* Grup tombol di section-hdr (mis. halaman KAS punya beberapa tombol) —
     biarkan wrap dan tetap nyaman disentuh jari */
  .section-hdr > div { display:flex;flex-wrap:wrap;gap:6px;width:100%; }
  .section-hdr .btn-sm { flex:1;min-width:0;justify-content:center;padding:9px 10px;min-height:36px; }

  /* Kartu statistik dashboard: minimal 2 kolom di HP, teks tidak overflow */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 13px 14px; }
  .stat-val  { font-size: 21px; }
  .stat-label { font-size: 10px; }
  /* Kartu statistik teks lebih kecil pada modul KAS/Rekap (nilai rupiah panjang) agar tidak overflow di HP */
  .stat-val[style*="font-size:20px"], .stat-val[style*="font-size:21px"], .stat-val[style*="font-size:22px"] { font-size:16px !important; }

  /* Modal: tampil sebagai bottom-sheet — pola umum di aplikasi mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box {
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    max-width: 100%;
    width: 100%;
    margin-top: 0;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    animation: slideUpModal .2s ease;
  }
  .modal-box.modal-lg { max-width: 100%; }
  .modal-title { font-size: 16px; }

  /* Tombol aksi modal full width, mudah ditekan jari */
  .btn-row { flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg2); padding-top: 10px; margin-top: 16px; }
  .btn-row .btn { flex: 1; min-width: 100px; justify-content: center; }

  /* ── TABEL → KARTU: lebih ramah dibaca di layar sempit daripada scroll horizontal ── */
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr { display: block; width: 100%; }
  .tbl { border: none; }
  .tbl tbody tr {
    display: block;
    background: var(--bg2);
    border: 1px solid var(--bdr);
    border-radius: 12px;
    padding: 4px 14px;
    margin-bottom: 10px;
  }
  .tbl tbody tr:hover td { background: transparent; }
  .tbl td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    text-align: right;
    padding: 9px 0;
    border-bottom: 1px dashed var(--bdr);
    white-space: normal;
    word-break: break-word;
  }
  .tbl td:last-child { border-bottom: none; }
  .tbl td[data-label]::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    color: var(--txt4);
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: .4px;
    text-align: left;
    flex: 0 0 auto;
    margin-right: auto;
  }
  /* Kolom aksi (tombol edit/hapus): sejajarkan ke kanan, tanpa label ganda */
  .tbl td[data-label="Aksi"] { justify-content: flex-end; }
  .tbl .act { gap: 8px; }
  .tbl .act .btn { min-height: 34px; }

  /* Empty state tetap rapi walau tabel jadi kartu */
  .tbl tr:has(.empty-state) { background: transparent; border: none; padding: 0; }
  .tbl tr:has(.empty-state) td { display: block; text-align: center; border: none; }
  .tbl tr:has(.empty-state) td::before { content: none; }
}

@keyframes slideUpModal { from { transform: translateY(24px); opacity:.6; } to { transform: translateY(0); opacity:1; } }

/* =========================================================
   BOTTOM NAV — hanya tampil di mobile (≤ 880px)
   ========================================================= */
@media (max-width: 880px) {
  #bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 60px;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg1);
    border-top: 1px solid var(--bdr);
    z-index: 150;
    box-shadow: 0 -4px 16px rgba(0,0,0,.15);
  }
  .bn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--txt3);
    font-size: 9.5px;
    font-family: var(--mono);
    cursor: pointer;
    user-select: none;
    transition: color .15s;
  }
  .bn-item i { font-size: 17px; }
  .bn-item.active { color: var(--accent); }
  .bn-item:active { opacity: .6; }
}

/* =========================================================
   BREAKPOINT 2 — HP kecil (≤ 480px)
   ========================================================= */
@media (max-width: 480px) {
  #sidebar { width: 84vw; max-width: 300px; }

  .login-box { width: 100%; padding: 30px 20px; border-radius: 14px; }
  #login-wrap { padding: 16px; }
  .login-logo { font-size: 22px; }

  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .pg-title  { font-size: 16px; }

  /* Kartu ringkasan/metric turun jadi 1 kolom bila terlalu sempit */
  .form-row label.form-label { font-size: 10px; }

  .bn-item span { display: block; }
  .bn-item i { font-size: 16px; }

  .modal-title { font-size: 15px; }

  /* Grafik kehadiran: lebih pendek & padat di HP kecil */
  .chart-canvas-box { height: 180px; }
}

/* =========================================================
   Tablet lanskap besar / laptop kecil (881px–1100px):
   sidebar tetap terlihat tapi sedikit lebih ramping
   ========================================================= */
@media (min-width: 881px) and (max-width: 1100px) {
  :root { --sw: 210px; }
  .page { padding: 16px 18px; }
}
