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

:root {
  /* Brand */
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.14);
  --indigo: #6366f1;

  /* Neutrals */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Semantic surfaces (themeable) */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active-bg: rgba(37, 99, 235, 0.18);
  --sidebar-active-text: #ffffff;

  /* Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);

  --transition: 0.18s ease;
  --sidebar-w: 240px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #0f172a;
  --border: #1f2937;
  --text: #e5e7eb;
  --text-muted: #94a3b8;
  --gray-50: #0f172a;
  --gray-100: #1e293b;
  --gray-200: #1f2937;
  --gray-700: #cbd5e1;
  --sidebar-bg: #060b16;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.page {
  min-height: 100vh;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition),
    box-shadow var(--transition), transform var(--transition);
}

button:active {
  transform: translateY(1px);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.6rem 1.1rem;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-block {
  width: 100%;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.5rem 0.9rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-cancel {
  padding: 0.6rem 1.1rem;
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-cancel:hover {
  background: var(--gray-200);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Forms */
.form-group {
  margin-bottom: var(--space-4);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 500;
  color: var(--text);
  font-size: 0.9rem;
}

input,
select {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input::placeholder {
  color: var(--gray-400);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

input:user-invalid {
  border-color: var(--danger);
}

input:user-invalid:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.field-hint {
  display: block;
  margin-top: var(--space-1);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.error {
  color: var(--danger);
  margin-top: var(--space-3);
  font-size: 0.875rem;
  min-height: 1.2em;
}

/* ===== Login Page ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(37, 99, 235, 0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(99, 102, 241, 0.16), transparent 55%),
    var(--bg);
}

.login-container {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
}

.login-brand h1 {
  font-size: 1.5rem;
  color: var(--text);
  line-height: 1.1;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== Dashboard Shell ===== */
.dashboard-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: var(--space-4) var(--space-3);
  z-index: 50;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3) var(--space-5);
  color: #fff;
}

.sidebar-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
}

.sidebar-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.7rem 0.9rem;
  background: transparent;
  color: var(--sidebar-text);
  border-radius: var(--radius-sm);
  text-align: left;
  font-weight: 500;
  width: 100%;
}

.tab-btn .nav-icon {
  flex-shrink: 0;
  opacity: 0.85;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.tab-btn.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.tab-btn.active .nav-icon {
  opacity: 1;
  color: #60a5fa;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 40;
}

.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
}

#sidebar-toggle {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.3rem 0.6rem 0.3rem 0.3rem;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
}

.icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: inline; }

/* Content */
.content {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

.stat-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.stat-icon-blue { background: var(--primary-soft); color: var(--primary); }
.stat-icon-indigo { background: rgba(99, 102, 241, 0.14); color: var(--indigo); }
.stat-icon-green { background: var(--success-soft); color: var(--success); }
.stat-icon-red { background: var(--danger-soft); color: var(--danger); }

.stat-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.toolbar h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-box input {
  border: none;
  padding: 0.55rem 0;
  background: transparent;
  width: 220px;
  max-width: 100%;
}

.search-box input:focus {
  outline: none;
  box-shadow: none;
}

/* Filter */
.filter-group {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  align-items: center;
  flex-wrap: wrap;
}

.filter-group label {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.filter-group select {
  width: auto;
  min-width: 170px;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  min-width: 560px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  z-index: 1;
}

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

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td {
  font-size: 0.9rem;
  color: var(--text);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:nth-child(even) {
  background: var(--surface-2);
}

tbody tr:hover {
  background: var(--primary-soft);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.6;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-aktif {
  background: var(--success-soft);
  color: var(--success);
}

.status-nonaktif {
  background: var(--danger-soft);
  color: var(--danger);
}

.jenis-setor {
  background: var(--success-soft);
  color: var(--success);
}

.jenis-tarik {
  background: var(--danger-soft);
  color: var(--danger);
}

.action-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  margin-right: var(--space-1);
  color: #fff;
}

.action-btn.edit {
  background: var(--warning);
}

.action-btn.edit:hover {
  background: #b45309;
}

.action-btn.delete {
  background: var(--danger);
}

.action-btn.delete:hover {
  background: #b91c1c;
}

/* Empty & loading states */
.state-cell {
  text-align: center;
  padding: var(--space-6) var(--space-4) !important;
  color: var(--text-muted);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
}

.empty-state svg {
  opacity: 0.5;
}

.empty-state strong {
  color: var(--text);
  font-weight: 600;
}

.skeleton-bar {
  height: 12px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 37%, var(--gray-100) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* Saldo */
.saldo-form {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.saldo-form-field {
  flex: 1;
  min-width: 220px;
}

.saldo-form-field label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 500;
  font-size: 0.9rem;
}

.saldo-form button {
  white-space: nowrap;
}

.saldo-card {
  background: linear-gradient(135deg, var(--primary), var(--indigo));
  color: #fff;
  padding: var(--space-5);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.saldo-card h3 {
  font-size: 1.3rem;
  margin-bottom: var(--space-1);
}

.saldo-id {
  opacity: 0.85;
  margin-bottom: var(--space-5);
  font-size: 0.9rem;
}

.saldo-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}

.saldo-item {
  padding: var(--space-4);
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-sm);
  text-align: center;
  backdrop-filter: blur(2px);
}

.saldo-item span {
  display: block;
  font-size: 0.82rem;
  opacity: 0.9;
  margin-bottom: var(--space-2);
}

.saldo-item strong {
  font-size: 1.25rem;
}

.saldo-utama {
  background: rgba(255, 255, 255, 0.95);
  color: var(--primary-dark);
  border-color: transparent;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--space-4);
  animation: overlay-in var(--transition);
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  padding: var(--space-5);
  animation: modal-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}

.modal-header h2 {
  font-size: 1.2rem;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-5);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
  }

  .dashboard-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .dashboard-shell.sidebar-open .sidebar-overlay {
    display: block;
  }

  #sidebar-toggle {
    display: inline-flex;
  }

  .content {
    padding: var(--space-4);
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-actions {
    width: 100%;
  }

  .search-box {
    flex: 1;
  }

  .search-box input {
    width: 100%;
  }

  .saldo-details {
    grid-template-columns: 1fr;
  }

  .saldo-form {
    flex-direction: column;
    align-items: stretch;
  }

  .saldo-form button {
    width: 100%;
  }

  .user-chip span:not(.user-avatar) {
    display: none;
  }

  .btn-ghost span {
    display: none;
  }
}
