/* ============ RESET & BASE ============ */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,.15);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.2);
  /* dark defaults */
  --bg: #0b0b1a;
  --bg-card: #13132a;
  --bg-elevated: #1a1a3a;
  --bg-input: #1a1a35;
  --text: #e8e8f0;
  --text-secondary: #9898b8;
  --text-muted: #6b6b8a;
  --border: #25254a;
  --border-focus: #6c63ff;
  --primary: #6c63ff;
  --primary-hover: #5a52e0;
  --primary-soft: rgba(108, 99, 255, .12);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, .12);
  --error: #ef4444;
  --error-soft: rgba(239, 68, 68, .12);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, .12);
  --income: #22c55e;
  --expense: #ef4444;
  --nav-bg: #0b0b1a;
  --sidebar-w: 240px;
  --topbar-h: 60px;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-card: #ffffff;
  --bg-elevated: #f0f2f6;
  --bg-input: #f0f2f6;
  --text: #1a1a2e;
  --text-secondary: #5a5a7a;
  --text-muted: #8a8aaa;
  --border: #e2e4ea;
  --border-focus: #6c63ff;
  --primary-soft: rgba(108, 99, 255, .08);
  --success-soft: rgba(34, 197, 94, .08);
  --error-soft: rgba(239, 68, 68, .08);
  --warning-soft: rgba(245, 158, 11, .08);
  --nav-bg: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.1);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

.page { display: none; }
.page.active { display: flex; }

/* ============ TOAST ============ */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
}

.toast {
  pointer-events: auto;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-lg);
  animation: slideIn .3s ease;
  backdrop-filter: blur(12px);
  border: 1px solid;
}

.toast-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.toast-error { background: var(--error-soft); color: var(--error); border-color: color-mix(in srgb, var(--error) 30%, transparent); }
.toast-info { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }

.toast svg { flex-shrink: 0; }
.toast-close { margin-left: auto; background: none; border: none; color: inherit; opacity: .5; cursor: pointer; padding: 2px; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============ LOGIN ============ */
#login-page {
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  background: radial-gradient(ellipse at 30% 20%, rgba(108,99,255,.08) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(34,197,94,.06) 0%, transparent 60%),
              var(--bg);
}

.login-wrapper {
  width: 100%;
  max-width: 400px;
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand-icon {
  display: inline-flex;
  padding: 14px;
  background: var(--primary-soft);
  border-radius: var(--radius-lg);
  color: var(--primary);
  margin-bottom: 16px;
}

.login-brand h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.5px;
}

.brand-sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.login-switch {
  display: flex;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 24px;
}

.switch-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.switch-btn.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

/* ============ FORM ELEMENTS ============ */
.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}

.input-wrap input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.input-wrap input::placeholder { color: var(--text-muted); }

.pw-toggle {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  transition: color var(--transition), background var(--transition);
}

.pw-toggle:hover { color: var(--text); background: var(--bg-elevated); }

/* ============ BUTTONS ============ */
button { font-family: var(--font); cursor: pointer; }

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(108,99,255,.3); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: var(--text-muted); background: var(--bg-input); }
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }

.btn-block { width: 100%; }

.btn-icon-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  font-family: var(--font);
}
.btn-icon-text:hover { border-color: var(--text-muted); color: var(--text); }

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.icon-btn:hover { background: var(--bg-elevated); border-color: var(--border); color: var(--text); }

.logout-btn:hover { color: var(--error); border-color: color-mix(in srgb, var(--error) 30%, transparent); background: var(--error-soft); }

.btn-loader { display: flex; align-items: center; }

/* ============ TOPBAR ============ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 500;
  transition: background var(--transition);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

#mobile-menu-btn { display: none; }

.topbar-left h2 {
  font-size: 16px;
  font-weight: 700;
}

.topbar-right { display: flex; align-items: center; gap: 6px; }

/* theme icons */
.theme-sun, .theme-moon { transition: opacity var(--transition); }
[data-theme="dark"] .theme-sun { display: block; }
[data-theme="dark"] .theme-moon { display: none; }
[data-theme="light"] .theme-sun { display: none; }
[data-theme="light"] .theme-moon { display: block; }

/* ============ SIDEBAR ============ */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 400;
  transition: transform var(--transition), background var(--transition);
}

.sidebar-brand {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 20px;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
}

.sidebar-link:hover { background: var(--bg-elevated); color: var(--text); }
.sidebar-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 350;
  display: none;
  backdrop-filter: blur(2px);
}

.logout-link:hover { color: var(--error) !important; background: var(--error-soft) !important; }

/* ============ MAIN CONTENT ============ */
.dashboard-layout {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 8px 24px 24px;
  max-width: 900px;
  transition: margin var(--transition);
}

.section { display: none; }
.section.active { display: block; animation: fadeUp .35s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ CARDS ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.card-body { padding: 20px 24px 24px; }
.card-body.p-0 { padding: 0; }

/* ============ BADGE ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-error { background: var(--error-soft); color: var(--error); }
.badge-info { background: var(--primary-soft); color: var(--primary); }

.btn-sm {
  padding: 4px 12px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-sm:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-sm:disabled { opacity: 0.5; cursor: default; background: var(--bg-elevated); color: var(--text-muted); border-color: var(--border); }

.payment-list { margin-top: 16px; }

/* ============ DOCS ============ */
.docs-content { font-size: 0.9rem; line-height: 1.7; }
.docs-content h4 { margin: 16px 0 8px; font-size: 1.1rem; }
.docs-content p { margin-bottom: 8px; color: var(--text-secondary); }
.docs-content code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--primary);
}
.docs-table { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
.docs-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.docs-table td:first-child { width: 140px; font-family: monospace; color: var(--text); }
.docs-endpoint {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 0 4px;
  font-family: monospace;
  font-size: 0.9rem;
}
.endpoint-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 44px;
}
.endpoint-badge.get { background: var(--success-soft); color: var(--success); }
.endpoint-badge.post { background: var(--primary-soft); color: var(--primary); }
.docs-code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 4px 0 12px;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
  line-height: 1.5;
}
.docs-list { padding-left: 20px; color: var(--text-secondary); }
.docs-list li { margin-bottom: 4px; }
.docs-list li code { font-size: 0.8rem; }

/* ============ CONFIRM MODAL ============ */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.2s ease;
}
.confirm-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px 20px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.confirm-icon { margin-bottom: 12px; color: var(--warning); }
.confirm-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.confirm-msg {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.confirm-actions .btn-secondary {
  min-width: 100px;
  padding: 8px 20px;
}
.confirm-actions .btn-primary {
  min-width: 100px;
  padding: 8px 20px;
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* ============ FORM GRID ============ */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ============ DIVIDER ============ */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ============ OTP SECTION ============ */
.otp-section {
  animation: fadeUp .3s ease;
}

/* ============ TOKEN BOX ============ */
.token-box {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--primary-soft);
  animation: fadeUp .3s ease;
}

.token-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 10px;
}

.token-box code {
  display: block;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 13px;
  word-break: break-all;
  color: var(--text);
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

/* ============ STATS ============ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: border-color var(--transition);
}

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

.stat-total .stat-icon { background: var(--primary-soft); color: var(--primary); }
.stat-income .stat-icon { background: var(--success-soft); color: var(--success); }
.stat-expense .stat-icon { background: var(--error-soft); color: var(--expense); }

.stat-info { min-width: 0; }
.stat-label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.stat-value { display: block; font-size: 20px; font-weight: 800; letter-spacing: -.5px; }
.stat-total .stat-value { color: var(--text); }
.stat-income .stat-value { color: var(--income); }
.stat-expense .stat-value { color: var(--expense); }

/* ============ TRANSACTIONS ============ */
.tx-list { max-height: 480px; overflow-y: auto; }

.tx-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  gap: 12px;
}

.tx-empty p { font-size: 14px; }

.tx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  gap: 12px;
}
.tx-item:last-child { border-bottom: none; }
.tx-item:hover { background: var(--bg-elevated); }

.tx-info { min-width: 0; }
.tx-desc { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.tx-amount { font-size: 15px; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
.tx-amount.positive { color: var(--income); }
.tx-amount.negative { color: var(--expense); }

.tx-count {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.refresh-btn { flex-shrink: 0; }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  #mobile-menu-btn { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .sidebar-brand { display: flex; }

  .main-content {
    margin-left: 0;
    padding: 16px;
  }

  .stat-grid { grid-template-columns: 1fr; gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 18px; }

  .form-grid { grid-template-columns: 1fr; gap: 12px; }

  .btn-row { flex-direction: column; }
  .btn-row button { width: 100%; }

  .card-header { padding: 16px 16px 0; flex-wrap: wrap; gap: 8px; }
  .card-body { padding: 16px; }

  .tx-item { padding: 14px 16px; }

  #toast-container {
    left: 16px;
    right: 16px;
    max-width: none;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .main-content { padding: 20px; }
  .stat-grid { gap: 12px; }
  .stat-card { padding: 16px; }
}

@media (min-width: 1200px) {
  .main-content { padding: 32px; }
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }


/* ============ QRIS ============ */
.qris-display {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: 12px;
}

.qris-image-wrap {
  flex-shrink: 0;
  width: 160px;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  padding: 8px;
}

.qris-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qris-info {
  flex: 1;
}

.qris-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.qris-balance-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: block;
}

.qris-balance-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-success);
}

.qris-result {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
  display: none;
}

.qris-result.show {
  display: block;
}

.qris-result.success {
  background: var(--bg-success);
  color: var(--color-success);
  border: 1px solid var(--color-success);
}

.qris-result.error {
  background: var(--bg-error);
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

.qris-tx-list {
  margin-top: 1rem;
}

.qris-tx-items {
  max-height: 300px;
  overflow-y: auto;
}

.qris-tx-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.qris-tx-item:last-child {
  border-bottom: none;
}

.qris-tx-desc {
  font-size: 0.85rem;
  color: var(--text-primary);
}

.qris-tx-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.qris-tx-amount {
  font-weight: 700;
  font-size: 0.9rem;
}

.qris-tx-amount.credit {
  color: var(--color-success);
}

.qris-tx-amount.debit {
  color: var(--color-error);
}

.qris-empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

@media (max-width: 640px) {
  .qris-display {
    flex-direction: column;
    text-align: center;
  }
  .qris-image-wrap {
    width: 140px;
    height: 140px;
  }
}

