/* ============================================================
   DataVault — Desain tabel modern (dipakai SEMUA tabel)
   ------------------------------------------------------------
   Berlaku untuk table.admin-table, table.table, table.trash-table
   di halaman pengguna & admin. Pasangannya: assets/js/tables.js,
   yang memberi label tiap sel & mengelompokkan tombol aksi.

   Diawali "html body" supaya menang atas <style> milik halaman.
   Desktop  : tabel bersih, header lengket, baris disorot saat hover.
   Kartu    : bila kolom tidak muat (ponsel/tablet/laptop kecil), tiap
              baris menjadi kartu (label kiri, nilai kanan).
   ============================================================ */

/* ---------- Wadah tabel ---------- */
html body :is(.admin-table-card, .table-wrapper, .trash-table-card) {
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  /* Bila kolom tidak muat, tabel digeser menyamping DI DALAM kotak ini —
     isi tidak pernah dipotong atau dipatah paksa */
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
html body .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Tabel ---------- */
html body table.tbl-modern {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  color: var(--text-body);
  font-variant-numeric: tabular-nums;
}
html body table.tbl-modern thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-section);
  color: var(--text-muted);
  font-size: 12.5px; font-weight: 700; letter-spacing: .02em;
  text-transform: none; white-space: normal; line-height: 1.35;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
}
html body table.tbl-modern tbody td {
  /* Boleh dilipat HANYA di spasi (tanggal-waktu jadi 2 baris rapi), tidak pernah
     di tengah kata. Nilai tanpa spasi (invoice, nominal) dikunci satu baris lewat
     .tbl-nowrap dari tables.js. */
  white-space: normal; overflow-wrap: normal; word-break: keep-all;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  background: transparent;
  transition: background-color .15s ease;
}
html body table.tbl-modern tbody tr:last-child td { border-bottom: 0; }
html body table.tbl-modern tbody tr:hover td {
  background: color-mix(in srgb, var(--gold-pale) 65%, transparent);
}
/* Kolom pertama sedikit ditekankan */
html body table.tbl-modern tbody td.tbl-first { color: var(--text-dark); font-weight: 600; }
/* Tampilan tabel: hanya patah bila benar-benar tidak muat (tidak memperkecil kolom).
   Pemotongan "di mana saja" khusus tampilan kartu — lihat blok .tbl-cards di bawah. */
html body table.tbl-modern .tbl-val { min-width: 0; overflow-wrap: break-word; }
/* Hanya sel berteks panjang (ditandai tables.js) yang boleh dilipat */
html body table.tbl-modern tbody td.tbl-nowrap { white-space: nowrap; }
html body table.tbl-modern tbody td.tbl-wrap { white-space: normal; min-width: 220px; max-width: 380px; line-height: 1.5; }

/* ---------- Badge status: bentuk pil dengan titik ---------- */
html body table.tbl-modern .badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
html body table.tbl-modern .badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .85; flex-shrink: 0;
}

/* ---------- Tombol aksi ---------- */
/* Kolom aksi selebar isinya saja, tombol tidak pernah bertumpuk di desktop */
html body table.tbl-modern td.tbl-actions-cell { white-space: nowrap; width: 1%; }
html body table.tbl-modern .tbl-actions {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: nowrap;
}
/* Tombol ikon saja (👁 🗑 ✏️ …) -> kotak bundar seragam */
html body table.tbl-modern .tbl-actions > .tbl-ico {
  width: 36px; height: 36px; padding: 0;
  display: inline-grid; place-items: center;
  border-radius: 11px;
  border: 1px solid var(--border-light);
  background: var(--bg-section);
  color: var(--text-body);
  font-size: 16px; line-height: 1; cursor: pointer;
  transition: transform .2s ease, background-color .2s ease, border-color .2s ease, box-shadow .2s ease;
}
html body table.tbl-modern .tbl-actions > .tbl-ico:hover {
  background: var(--gold-pale);
  border-color: color-mix(in srgb, var(--gold-main) 45%, var(--border-light));
  box-shadow: 0 6px 14px -8px rgba(204, 145, 7, .55);
  transform: translateY(-1px);
}
html body table.tbl-modern .tbl-actions > .tbl-ico.tbl-danger:hover {
  background: var(--error-bg);
  border-color: color-mix(in srgb, var(--error) 45%, var(--border-light));
  box-shadow: 0 6px 14px -8px rgba(239, 68, 68, .55);
}
html body table.tbl-modern .tbl-actions > .tbl-ico:active { transform: scale(.92); }
html body table.tbl-modern .tbl-actions > .tbl-ico:disabled { opacity: .35; cursor: not-allowed; transform: none; box-shadow: none; }

/* Baris kosong / pesan ("Belum ada data", "Memuat…") */
html body table.tbl-modern td.tbl-empty {
  text-align: center; color: var(--text-muted); padding: 36px 18px; font-weight: 500;
}

/* ============================================================
   TAMPILAN KARTU: baris -> kartu (label kiri, nilai kanan)
   ------------------------------------------------------------
   Dipasang tables.js lewat kelas .tbl-cards, BUKAN hanya berdasarkan
   lebar layar: setiap kali kolom tabel tidak muat di kotaknya
   (ponsel, tablet, laptop kecil, sidebar terbuka), tabel otomatis
   menjadi kartu — tidak pernah terpotong atau harus digeser.
   ============================================================ */
html body .tbl-cards-wrap {
  background: transparent; border: 0; box-shadow: none; border-radius: 0; overflow: visible;
}
html body .tbl-cards-wrap .table-scroll { overflow: visible; }

html body table.tbl-modern.tbl-cards { min-width: 0 !important; font-size: 14px; }
html body table.tbl-modern.tbl-cards thead { display: none; }
html body table.tbl-modern.tbl-cards,
html body table.tbl-modern.tbl-cards tr { display: block; width: 100%; }
/* Kartu disusun dalam grid: 1 kolom di ponsel, 2-3 kolom di layar lebar */
html body table.tbl-modern.tbl-cards tbody {
  display: grid; width: 100%;
  grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr));
  gap: 14px; align-items: start;
}
html body table.tbl-modern.tbl-cards tbody tr:has(> td.tbl-empty) { grid-column: 1 / -1; }

html body table.tbl-modern.tbl-cards tbody tr {
  margin-bottom: 0;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
html body table.tbl-modern.tbl-cards tbody tr:hover td { background: transparent; }

/* Satu sel = label kiri + nilai kanan (selalu tepat 2 bagian) */
html body table.tbl-modern.tbl-cards tbody td {
  display: grid;
  grid-template-columns: minmax(92px, 36%) minmax(0, 1fr);
  align-items: center; gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px dashed var(--border-light);
  text-align: right !important;
}
html body table.tbl-modern.tbl-cards tbody td::before {
  content: attr(data-label);
  text-align: left;
  font-size: 12px; font-weight: 600; letter-spacing: .01em;
  color: var(--text-muted);
}
html body table.tbl-modern.tbl-cards tbody td:last-child { border-bottom: 0; }

/* Sel pertama = kepala kartu */
html body table.tbl-modern.tbl-cards tbody td.tbl-first {
  background: var(--bg-section);
  padding-top: 13px; padding-bottom: 13px;
  border-bottom: 1px solid var(--border-light);
}

/* Nilai selalu rata kanan, termasuk elemen blok di dalamnya (mis. bilah kuota) */
html body table.tbl-modern.tbl-cards tbody td > .tbl-val {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px; min-width: 0;
}
/* Isi tidak boleh lebih lebar dari kolom nilai — teks panjang dipatah, tidak
   meluber ke kiri menimpa label (mis. nama berkas panjang tanpa spasi) */
html body table.tbl-modern.tbl-cards tbody td > .tbl-val > * { max-width: 100%; min-width: 0; }
html body table.tbl-modern.tbl-cards tbody td > .tbl-val :is(div, span, strong, a, p):not(.badge) {
  min-width: 0; overflow-wrap: anywhere;
}
html body table.tbl-modern.tbl-cards tbody td > .tbl-val .truncate { white-space: normal; }

/* Baris aksi = kaki kartu: selebar kartu, tanpa label, tombol berjajar di kanan */
html body table.tbl-modern.tbl-cards tbody td.tbl-actions-cell {
  display: flex; justify-content: flex-end; align-items: center;
  white-space: normal; width: auto;
  background: var(--bg-section);
  border-top: 1px solid var(--border-light); border-bottom: 0;
}
html body table.tbl-modern.tbl-cards tbody td.tbl-actions-cell::before { content: none; }
html body table.tbl-modern.tbl-cards tbody td.tbl-actions-cell .tbl-actions { justify-content: flex-end; flex-wrap: wrap; }

/* Baris kosong tetap satu blok di tengah, tanpa label */
html body table.tbl-modern.tbl-cards tbody tr:has(> td.tbl-empty) { box-shadow: none; }
html body table.tbl-modern.tbl-cards tbody td.tbl-empty { display: block; text-align: center !important; }
html body table.tbl-modern.tbl-cards tbody td.tbl-empty::before { content: none; }

@media (prefers-reduced-motion: reduce) {
  html body table.tbl-modern .tbl-actions > .tbl-ico { transition: none; }
}

/* ============================================================
   TOMBOL AKSI — Manajemen Pengguna (admin/pengguna.html)
   Edit Kuota / Suspend / Hapus Akun dibuat seragam & sejajar.
   ============================================================ */
/* Tampilan tabel (desktop): satu baris, tinggi & gaya seragam */
html body table.tbl-modern .tbl-actions.aksi-pengguna {
  display: flex; flex-wrap: nowrap; justify-content: flex-end; align-items: center; gap: 8px;
}
html body table.tbl-modern .tbl-actions.aksi-pengguna > .btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; min-height: 34px; padding: 0 14px;
  font-size: 12.5px; line-height: 1; white-space: nowrap;
}
/* Tampilan kartu (ponsel/tablet): 2 tombol di baris atas, Hapus Akun selebar kartu */
html body table.tbl-modern.tbl-cards tbody td.tbl-actions-cell .tbl-actions.aksi-pengguna {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%;
}
html body table.tbl-modern.tbl-cards tbody td.tbl-actions-cell .tbl-actions.aksi-pengguna > .btn {
  width: 100%; height: 40px; min-height: 40px;
}
html body table.tbl-modern.tbl-cards tbody td.tbl-actions-cell .tbl-actions.aksi-pengguna > .btn:last-child {
  grid-column: 1 / -1;
}

/* ============================================================
   PERBAIKAN TATA LETAK KARTU — Manajemen Pengguna & Log Aktivitas (dan tabel lain)
   ------------------------------------------------------------
   1) Sel di kartu SELALU selebar kartu. Aturan .tbl-wrap (min 220px / max 380px) dibuat
      untuk KOLOM TABEL; di kartu ia ikut menyempitkan sel "Pengguna" & "Detail Aktivitas"
      sehingga teksnya berhenti di tengah, tidak sejajar dengan nilai lain.
   2) <br> di dalam wadah nilai dianggap item tata letak (kena jarak antar-item) sehingga
      nama dan email terpisah jauh; di kartu <br> disembunyikan, susunannya sudah kolom.
   3) Blok "Masa Aktif" rata kanan & berukuran sama dengan nilai lain (sebelumnya rata kiri, 11px).
   4) Jarak antar tombol di baris aksi memakai gap grid, bukan margin lama (.btn + .btn).
   ============================================================ */
html body table.tbl-modern.tbl-cards tbody td.tbl-wrap,
html body table.tbl-modern.tbl-cards tbody td.tbl-nowrap {
  min-width: 0; max-width: none; width: auto;
}
html body table.tbl-modern.tbl-cards tbody td.tbl-wrap { white-space: normal; line-height: 1.5; }

html body table.tbl-modern.tbl-cards tbody td > .tbl-val > br { display: none; }

/* Masa aktif (komponen .plan-period dari app.js) di dalam kartu */
html body table.tbl-modern.tbl-cards tbody td > .tbl-val > .plan-period {
  width: 100%; max-width: 230px; min-width: 0; margin-left: auto;
  align-items: stretch; gap: 5px; text-align: right;
}
html body table.tbl-modern.tbl-cards tbody td > .tbl-val > .plan-period .plan-period__row { gap: 12px; }
html body table.tbl-modern.tbl-cards tbody td > .tbl-val > .plan-period .plan-period__label  { font-size: 12px; text-align: left; }
html body table.tbl-modern.tbl-cards tbody td > .tbl-val > .plan-period .plan-period__value  { font-size: 13px; }
html body table.tbl-modern.tbl-cards tbody td > .tbl-val > .plan-period .plan-period__status { font-size: 13px; text-align: right; }
html body table.tbl-modern.tbl-cards tbody td > .tbl-val > .plan-period .plan-period__bar    { height: 5px; }

/* Tombol aksi: jarak hanya dari gap, tanpa margin tambahan */
html body table.tbl-modern .tbl-actions.aksi-pengguna > .btn { margin: 0; }

/* 5) Lencana (paket, status, dll.) di kartu tidak boleh melebihi kolom nilai: teks panjang
      (mis. "Akun Pro - CLAUDE PRO · 20 Hari") turun baris di dalam lencana, bukan terpotong. */
html body table.tbl-modern.tbl-cards tbody td > .tbl-val .badge {
  max-width: 100%; white-space: normal; text-align: right; line-height: 1.35;
  overflow-wrap: anywhere; word-break: normal;
}

/* 6) Mode tabel: teks Masa Aktif seukuran teks kolom lain (sebelumnya 11px, tampak lebih kecil) */
html body table.tbl-modern:not(.tbl-cards) td .plan-period.is-compact .plan-period__label  { font-size: 12px; }
html body table.tbl-modern:not(.tbl-cards) td .plan-period.is-compact .plan-period__value  { font-size: 12.5px; }
html body table.tbl-modern:not(.tbl-cards) td .plan-period.is-compact .plan-period__status { font-size: 12.5px; }
