:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #f7f9fd;
  --border: #e1e6f0;
  --text: #14213d;
  --text-muted: #5c6580;
  --primary: #004aad;
  --primary-dark: #00337a;
  --primary-light: #e7eefb;
  --accent: #ffbf00;
  --accent-dark: #cc9900;
  --accent-light: #fff6de;
  --success: #1a8a5f;
  --success-bg: #e6f6ee;
  --warning: #b8862f;
  --warning-bg: #fbf2e0;
  --danger: #b23b3b;
  --danger-bg: #fbe9e9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 30, 80, 0.06), 0 4px 16px rgba(0, 30, 80, 0.07);
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 4px 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--primary); }
button { font-family: inherit; }

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #0058c9 0%, #00347e 55%, #001d47 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  padding: 36px 32px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 28px;
  text-align: center;
}

.login-brand .badge {
  width: 96px; height: auto;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.login-brand .badge img { width: 100%; height: auto; display: block; }

.login-brand h1 { font-size: 18px; }
.login-brand span { font-size: 12.5px; color: var(--text-muted); }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface-alt);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .12s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #eef2f1; }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #f7d9d9; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

#login-error {
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  display: none;
}

/* ---------- App shell ---------- */
#app-shell { display: none; min-height: 100vh; }
#app-shell.active { display: flex; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #00265e 0%, #004aad 100%);
  color: #eaf1fd;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 6px 8px 22px; }
.sidebar-brand .badge {
  width: 128px; height: auto;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-brand .badge img { width: 100%; height: auto; display: block; }
.sidebar-brand .title { font-size: 13.5px; font-weight: 700; line-height: 1.25; }
.sidebar-brand .subtitle { font-size: 10.5px; opacity: .75; letter-spacing: .03em; text-transform: uppercase; }

.nav-group { margin-top: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: rgba(234,250,244,0.82);
  cursor: pointer;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.16); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-item .icon { width: 18px; text-align: center; font-size: 14px; }

.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.14); }
.sidebar-user { font-size: 12px; opacity: .85; margin-bottom: 8px; word-break: break-all; }

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 32px 60px;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap; gap: 12px;
}
.topbar h2 { font-size: 20px; }
.topbar .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
@media (max-width: 1080px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card { padding: 16px 18px; }
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat-card .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 1080px) { .grid-2 { grid-template-columns: 1fr; } }

.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title h3 { font-size: 15px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-alt); }
tbody tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.mono { font-variant-numeric: tabular-nums; }

.badge-status {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.badge-status.lunas { background: var(--success-bg); color: var(--success); }
.badge-status.belum { background: #eef1f0; color: var(--text-muted); }
.badge-status.nunggak { background: var(--danger-bg); color: var(--danger); }
.badge-status.aktif { background: var(--success-bg); color: var(--success); }
.badge-status.nonaktif { background: #eef1f0; color: var(--text-muted); }
.badge-status.dibayar { background: var(--success-bg); color: var(--success); }

.pill-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 11.5px;
  font-weight: 600;
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters select, .filters input { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; background: var(--surface); }

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

/* ---------- Modal ---------- */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(10, 20, 17, 0.45);
  align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%; max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  padding: 24px;
}
.modal.modal-wide { max-width: 720px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { font-size: 16px; }
.modal-close { cursor: pointer; color: var(--text-muted); font-size: 18px; line-height: 1; background: none; border: none; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.tag-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 13px; box-shadow: var(--shadow);
  z-index: 200; opacity: 0; transform: translateY(8px);
  transition: all .18s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

.loading-inline { font-size: 13px; color: var(--text-muted); padding: 16px 0; }

.action-icons { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-btn {
  width: 28px; height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 12.5px;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

@media print {
  #app-shell, #login-screen { display: none !important; }
}
