:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --brand: #4f46e5;
  --brand-d: #4338ca;
  --line: #e2e8f0;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
a { color: var(--brand); }

/* ---------- halaman publik (login / cek / info) ---------- */
.pub-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.pub-card { width: 100%; max-width: 380px; padding: 28px; }
.pub-card.wide { max-width: 640px; }
.pub-card h1 { margin: 0 0 4px; font-size: 20px; }
.pub-card label { display: block; margin: 14px 0 4px; font-size: 13px; color: var(--muted); }
.pub-card input, .pub-card select { width: 100%; }
.pub-links { display: flex; gap: 8px; margin-top: 14px; }
.pub-links .btn { flex: 1; }

/* ---------- layout aplikasi ---------- */
#app { display: flex; min-height: 100vh; }
#topbar { display: none; }
#backdrop { display: none; }
#sidebar {
  width: 230px;
  background: #1e1b4b;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-size: 18px; font-weight: 700; padding: 6px 10px 18px; }
.brand small { color: #a5b4fc; margin-left: 6px; }
#menu { flex: 1; }
#menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14.5px;
  margin-bottom: 2px;
  min-height: 44px;
}
#menu button:hover { background: #312e81; }
#menu button.active { background: var(--brand); color: #fff; font-weight: 600; }
.side-foot { border-top: 1px solid #312e81; padding-top: 12px; }
#userBox { padding: 4px 12px 8px; }
#btnLogout { width: 100%; }
#main { flex: 1; padding: 24px; min-width: 0; }
#view { max-width: 1000px; margin: 0 auto; }
#view h2 { margin: 0 0 14px; font-size: 20px; }

/* ---------- komponen ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }

.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.danger { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.btn.ok { background: #ecfdf5; border-color: #a7f3d0; color: var(--ok); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14.5px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
textarea { resize: vertical; min-height: 64px; }
label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
label .hint { color: #94a3b8; font-size: 12px; }

.err { color: var(--danger); font-size: 13.5px; margin-top: 10px; }
.err.hidden { display: none; }

/* ---------- tabel ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 2px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: #fafbff; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl .aksi { white-space: nowrap; text-align: right; }
.tbl .aksi .btn { margin-left: 4px; }
.tbl .muted-sm { color: var(--muted); font-size: 12.5px; }

/* ---------- badge ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok { background: #ecfdf5; color: var(--ok); }
.badge.warn { background: #fffbeb; color: var(--warn); }
.badge.info { background: #eff6ff; color: #2563eb; }
.badge.danger { background: #fef2f2; color: var(--danger); }
.badge.mute { background: #f1f5f9; color: var(--muted); }

/* ---------- statistik ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.stat .k { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.stat .v { font-size: 21px; font-weight: 700; }
.stat .s { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat .v.danger { color: var(--danger); }
.stat .v.ok { color: var(--ok); }
.stat .v.warn { color: var(--warn); }

/* ---------- toolbar / form ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar input, .toolbar select { width: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal.hidden { display: none; }
.modal-box { width: 100%; max-width: 460px; background: var(--card); border-radius: 14px; padding: 20px; }
.modal-box.wide { max-width: 560px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 99;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  max-width: 360px;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast.hidden { display: none; }

/* ---------- cek tagihan publik ---------- */
.cek-item { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-top: 14px; }
.cek-item h3 { margin: 0 0 2px; font-size: 16px; }
.cek-item .meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

/* ==========================================================================
   RESPONSIVE — tablet / HP
   ========================================================================== */

/* ---------- ≤ 768px: sidebar jadi drawer + topbar ---------- */
@media (max-width: 768px) {
  #app { display: block; }

  #topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1e1b4b;
    color: #e2e8f0;
    padding: 8px 12px;
    position: sticky;
    top: 0;
    z-index: 40;
  }
  #topbar .brand { font-size: 16px; padding: 4px 6px; }
  #topbar #btnMenu {
    background: transparent;
    border-color: #312e81;
    color: #e2e8f0;
    font-size: 20px;
    line-height: 1;
    padding: 6px 12px;
    min-height: 40px;
    min-width: 44px;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    width: 250px;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 6px 0 28px rgba(0, 0, 0, 0.35);
  }

  #backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
  }
  #backdrop.show { opacity: 1; pointer-events: auto; }

  #main { padding: 14px 12px; }
  #view h2 { font-size: 18px; }
}

/* ---------- ≤ 640px: tabel jadi kartu, toolbar menumpuk ---------- */
@media (max-width: 640px) {
  /* input 16px: mencegah auto-zoom iOS Safari saat fokus */
  input, select, textarea { font-size: 16px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input, .toolbar select { width: 100%; }
  .toolbar .spacer { display: none; }
  .toolbar .btn { width: 100%; text-align: center; }

  /* tabel -> kartu (baris header = tr pertama, tanpa thead) */
  .tbl-wrap { overflow: visible; }
  .tbl tr:first-child { display: none; }
  .tbl tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 6px 12px 10px;
    margin-bottom: 10px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.06);
  }
  .tbl tr:hover td { background: transparent; }
  .tbl td {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 1px 12px;
    border: none;
    padding: 6px 0;
    text-align: left;
    white-space: normal;
  }
  .tbl td::before {
    flex: 0 0 100%;
    content: attr(data-label);
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }
  .tbl td.aksi {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px dashed var(--line);
  }
  .tbl td.aksi::before { display: none; }
  .tbl .aksi .btn { margin-left: 0; }
  .btn.small { padding: 8px 12px; font-size: 13px; min-height: 38px; }

  /* modal & toast menempel layar kecil */
  .modal { padding: 24px 10px; }
  .modal-box { padding: 16px; }
  .modal-foot .btn { min-height: 42px; }
  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; text-align: center; }
}

/* ---------- ≤ 480px: layar HP sempit ---------- */
@media (max-width: 480px) {
  .pub-card { padding: 22px 18px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat { padding: 12px; }
  .stat .v { font-size: 18px; }
}
