/* ============================================================
   APP BANJAR — THEME: Dark Sidebar + Purple Gradient
   ============================================================ */

:root {
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f4f9;
  --sidebar-from: #1b2a4d;
  --sidebar-to: #0c1426;
  --sidebar-text: #aab2c5;
  --sidebar-text-active: #ffffff;
  --accent-1: #6366f1;
  --accent-2: #8b5cf6;
  --accent-grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --ok: #16a34a;
  --danger: #ef4444;
  --radius: 10px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  background: radial-gradient(circle at top left, #24365f, var(--sidebar-from) 45%, var(--sidebar-to) 100%);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.topbar-brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(99,102,241,0.35);
}
.topbar-brand-name {
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.2px;
  line-height: 1.2;
}
.topbar-brand-sub {
  color: #8a92b0;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
}
.hamburger:hover {
  background: rgba(255,255,255,0.08);
}

/* ============================================================
   ACCOUNT
   ============================================================ */
.account {
  position: relative;
}

.account-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  border-radius: 30px;
}
.account-btn:hover {
  background: rgba(255,255,255,0.08);
}

.account-btn .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.35);
}

.account-btn .caret {
  font-size: 9px;
  color: rgba(255,255,255,0.6);
}

.account-menu {
  display: none;
  position: absolute;
  top: 42px;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  min-width: 190px;
  z-index: 40;
  overflow: hidden;
}
.account-menu.open {
  display: block;
}

.account-menu .info {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.account-menu .info .name {
  font-weight: 700;
  font-size: 13px;
}

.account-menu .info .role-badge {
  display: inline-block;
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(139,92,246,0.12));
  color: var(--accent-1);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  margin-top: 4px;
}

.account-menu .info .online {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ok);
  margin-top: 8px;
  font-weight: 600;
}
.account-menu .info .online .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

.account-menu button.linklike {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 11px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  cursor: pointer;
}
.account-menu button.linklike:hover {
  background: #fef2f2;
}

/* ============================================================
   SIDEBAR — DARK
   ============================================================ */
.app-shell {
  display: flex;
  min-height: calc(100vh - 56px);
}

.sidebar {
  width: 220px;
  background: radial-gradient(circle at top left, #24365f, var(--sidebar-from) 35%, var(--sidebar-to) 100%);
  padding: 18px 10px 56px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar::-webkit-scrollbar {
  width: 3px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.15s;
}

.sidebar-link:hover {
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-text-active);
}

.sidebar-link.active {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.sidebar-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 8px 12px;
}

.sidebar-version {
  position: absolute;
  left: 18px;
  bottom: 14px;
  font-size: 10.5px;
  font-weight: 600;
  color: rgba(255,255,255,0.35);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
main.container {
  flex: 1;
  padding: 24px 28px;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
}

/* ============================================================
   TYPOGRAPHY
   ============================================================ */
h1 {
  font-size: 21px;
  font-weight: 800;
  margin: 0 0 2px 0;
  color: var(--ink);
  letter-spacing: -0.3px;
}

h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--ink);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: #ffffff;
  border-radius: var(--radius);
  padding: 18px 20px;
  border: 1px solid var(--line);
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

/* ============================================================
   STAT CARDS — PURPLE GRADIENT (DASHBOARD)
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin: 14px 0 22px;
}

.stat-card {
  background: var(--accent-grad);
  border-radius: 14px;
  padding: 20px 18px;
  border: none;
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.25);
}
.stat-card::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 110px;
  height: 110px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
  color: #fff;
}

.stat-card .stat-label {
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  margin-top: 4px;
  font-weight: 600;
}

.stat-card .stat-detail {
  font-size: 11px;
  color: rgba(255,255,255,0.72);
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.18);
}

/* Variant accents so individual stat cards can still read distinctly,
   while staying within the purple-gradient family. */
.stat-card.c-indigo { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.stat-card.c-red    { background: linear-gradient(135deg, #fb7185, #ef4444); box-shadow: 0 10px 24px rgba(239,68,68,0.25); }
.stat-card.c-orange { background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: 0 10px 24px rgba(245,158,11,0.25); }
.stat-card.c-teal   { background: linear-gradient(135deg, #2dd4bf, #0d9488); box-shadow: 0 10px 24px rgba(13,148,136,0.25); }

/* ============================================================
   MENU GRID
   ============================================================ */
.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.nav-card {
  background: #ffffff;
  border-radius: var(--radius);
  padding: 16px 14px;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--line);
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-card:hover {
  border-color: var(--accent-1);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.12);
  transform: translateY(-2px);
}

.nav-card .icon {
  font-size: 20px;
}
.nav-card .title {
  font-weight: 700;
  font-size: 13px;
}
.nav-card .desc {
  font-size: 11px;
  color: var(--muted);
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

th {
  background: #161d2f;
  color: #c3c9da;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }

tr:hover td {
  background: #f8f7ff;
}

/* Tables are injected dynamically into containers with varying ids
   across pages (#tableWrap, #tablePemasukan, #tableMeninggal,
   #tableUsers, etc). On narrow screens these tables are wider than
   the viewport (nama, alamat, wilayah, status badges, aksi...), so
   every such container scrolls horizontally on its own, with a
   subtle edge fade hinting that more columns are available. */
@media (max-width: 900px) {
  #tableWrap, #tablePemasukan, #tablePengeluaran,
  #tableMeninggal, #tableSurat, #tableUsers {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    background:
      linear-gradient(to right, #fff 30%, rgba(255,255,255,0)),
      linear-gradient(to right, rgba(255,255,255,0), #fff 70%) 100% 0,
      linear-gradient(to right, rgba(15,23,42,0.08), rgba(15,23,42,0)),
      linear-gradient(to left, rgba(15,23,42,0.08), rgba(15,23,42,0)) 100% 0;
    background-repeat: no-repeat;
    background-size: 24px 100%, 24px 100%, 8px 100%, 8px 100%;
    background-attachment: local, local, scroll, scroll;
  }
  #tableWrap table, #tablePemasukan table, #tablePengeluaran table,
  #tableMeninggal table, #tableSurat table, #tableUsers table {
    min-width: 600px;
  }
  td, th {
    white-space: nowrap;
  }
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
}
.badge.ok {
  background: #dcfce7;
  color: #16a34a;
}
.badge.danger {
  background: #fee2e2;
  color: #dc2626;
}
.badge.warning {
  background: #fef3c7;
  color: #d97706;
}
.badge.primary {
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(139,92,246,0.12));
  color: var(--accent-1);
}

/* ============================================================
   FORMS
   ============================================================ */
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  background: #fff;
  transition: all 0.15s;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}
input[readonly] {
  background: #f8fafc;
  color: var(--muted);
}

label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.field {
  margin-bottom: 12px;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.row > .field {
  flex: 1;
  min-width: 130px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}
.btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}
.btn:active {
  transform: scale(0.97);
}

.btn.secondary {
  background: #eef0f7;
  color: var(--ink);
  box-shadow: none;
}
.btn.secondary:hover {
  background: #e2e6f3;
  transform: none;
}

.btn.danger {
  background: linear-gradient(135deg, #fb7185, #ef4444);
  box-shadow: 0 4px 12px rgba(239,68,68,0.25);
}
.btn.danger:hover {
  filter: brightness(1.05);
}

.btn.small {
  padding: 5px 11px;
  font-size: 11px;
}

/* ============================================================
   TOOLBAR
   ============================================================ */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 12px;
}

/* A group of filter fields that should wrap together as a unit,
   separate from action buttons (e.g. Reset Filter, + Tambah).
   This keeps buttons from getting visually orphaned mid-row when
   the filter fields wrap to a new line on narrower desktop widths. */
.toolbar-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
  flex: 1 1 auto;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1b2236;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(15,23,42,0.25);
  z-index: 100;
  opacity: 0;
  transform: translateY(12px);
  transition: all 0.25s;
  max-width: 360px;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.error {
  background: linear-gradient(135deg, #fb7185, #ef4444);
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-backdrop.show {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 14px;
  padding: 26px;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,0.18);
}

.modal h3 {
  font-size: 16px;
  font-weight: 800;
  margin-top: 0;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top left, #232c47, #11162a 60%);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 34px 30px;
  width: 100%;
  max-width: 350px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
  border: 1px solid var(--line);
}

.login-card .logo {
  text-align: center;
  margin-bottom: 16px;
}
.login-card .logo .circ {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--accent-grad);
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
  box-shadow: 0 10px 24px rgba(99,102,241,0.35);
}

.login-card h1 {
  text-align: center;
  font-size: 21px;
  margin-bottom: 2px;
}

.login-card .sub {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 22px;
}

.error-box {
  background: #fee2e2;
  color: #dc2626;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
  display: none;
}

/* ============================================================
   SKELETON
   ============================================================ */
.skeleton {
  background: linear-gradient(90deg, #f1f4f9, #f8fafc, #f1f4f9);
  background-size: 200% 100%;
  animation: skeleton 1.2s infinite;
  border-radius: 6px;
  height: 12px;
  margin: 4px 0;
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 30px 16px;
  font-size: 12px;
}

/* ============================================================
   BOTTOM NAV (Mobile)
   ============================================================ */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: radial-gradient(circle at top left, #24365f, var(--sidebar-from) 45%, var(--sidebar-to) 100%);
  border-top: 1px solid rgba(255,255,255,0.08);
  z-index: 20;
  padding: 4px 0;
  overflow-x: auto;
  white-space: nowrap;
  justify-content: center;
}
.bottom-nav::-webkit-scrollbar {
  display: none;
}

.bottom-link {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  text-decoration: none;
  color: #8a92a8;
  font-size: 9px;
  font-weight: 600;
  padding: 6px 14px;
  flex: 0 0 auto;
  min-width: 52px;
}
.bottom-icon {
  font-size: 16px;
}
.bottom-link.active {
  color: #fff;
}

/* Scroll-hint arrows for .bottom-nav, shown only when its content
   overflows the viewport and there's more to reveal in that
   direction. These are independent fixed-position elements (siblings
   of .bottom-nav, injected by JS in api.js) rather than nested inside
   it, so they don't interfere with .bottom-nav's own fixed layout —
   their left/right edges are kept in sync with .bottom-nav's box via
   JS on resize. */
.bottom-nav-arrow {
  display: none;
  position: fixed;
  bottom: 0;
  width: 26px;
  height: 38px;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  z-index: 21;
  pointer-events: none;
}
.bottom-nav-arrow.left {
  left: 0;
  background: linear-gradient(to right, var(--sidebar-to), rgba(12,20,38,0));
}
.bottom-nav-arrow.right {
  right: 0;
  background: linear-gradient(to left, var(--sidebar-to), rgba(12,20,38,0));
}
.bottom-nav-arrow.show {
  display: flex;
}

/* ============================================================
   SIDEBAR BACKDROP
   ============================================================ */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 19;
  display: none;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  main.container {
    padding: 18px 20px;
  }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 20;
    width: 230px;
    transform: translateX(-100%);
    transition: transform 0.2s;
    padding-top: 64px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .hamburger {
    display: block;
  }

  .bottom-nav {
    display: flex;
  }

  main.container {
    padding: 12px;
    padding-bottom: 68px;
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }
  .nav-grid {
    grid-template-columns: 1fr 1fr;
  }

  .row {
    flex-direction: column;
  }
  .row > .field {
    min-width: 100%;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 0 10px;
    height: 50px;
  }
  .topbar .brand .brand-name {
    font-size: 13px;
  }
  .topbar .page-title {
    font-size: 12px;
  }
  .account-btn span:not(.avatar) {
    display: none;
  }

  h1 {
    font-size: 18px;
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .stat-card {
    padding: 14px;
  }
  .stat-card .stat-value {
    font-size: 19px;
  }

  .nav-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .nav-card {
    padding: 12px 10px;
  }
  .nav-card .icon {
    font-size: 18px;
  }

  .card {
    padding: 12px;
  }

  .login-card {
    padding: 26px 18px;
    margin: 10px;
  }

  .toast {
    bottom: 64px;
    right: 10px;
    left: 10px;
    max-width: 100%;
  }
}