:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #66707d;
  --line: #e4e8ee;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --danger: #dc2626;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --amber-line: #fde68a;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(20, 32, 48, 0.08);
  padding: 48px 40px;
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #16a34a, #0e7490);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
}

.brand-mark.small { width: 28px; height: 28px; font-size: 12px; border-radius: 8px; margin: 0; }

.brand { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.tagline { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  transition: box-shadow 0.15s ease, transform 0.05s ease;
}
.btn-google:hover { box-shadow: 0 4px 14px rgba(20, 32, 48, 0.12); }
.btn-google:active { transform: translateY(1px); }

.login-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 18px 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--line);
}
.login-divider span {
  padding: 0 10px;
}
.access-key-section {
  width: 100%;
  text-align: left;
}
.access-key-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
}
.access-key-group {
  display: flex;
  gap: 8px;
}
.access-key-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  min-width: 0;
}
.access-key-input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.login-error { margin: 18px 0 0; color: var(--danger); font-size: 13px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; flex-shrink: 0; }
.topbar-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-name {
  color: var(--muted);
  font-size: 14px;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 20px;
  padding: 22px;
  max-width: 1080px;
  margin: 0 auto;
}

@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  /* Di layar sempit, form catat manual duluan; chat menyusul di bawah. */
  .chat-card { order: 2; min-height: 380px; }
  .side { order: 1; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 2px 10px rgba(20, 32, 48, 0.04);
}

.card-title { margin: 0 0 12px; font-size: 15px; font-weight: 700; }

.chat-card { display: flex; flex-direction: column; min-height: min(70vh, 640px); }

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 14px;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg.assistant {
  align-self: flex-start;
  background: #eef2f6;
  border-bottom-left-radius: 6px;
  white-space: normal;
}

.msg-content p.md-p {
  margin: 0 0 8px;
  line-height: 1.5;
}
.msg-content p.md-p:last-child {
  margin-bottom: 0;
}

.table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.md-table th,
.md-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.md-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11.5px;
  letter-spacing: 0.03em;
}

.md-table tr:last-child td {
  border-bottom: none;
}

.md-list {
  margin: 8px 0;
  padding-left: 20px;
}

.md-list li {
  margin-bottom: 4px;
  line-height: 1.45;
}

.md-code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.inchat-pending {
  margin-top: 12px;
  padding: 12px 14px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.badge-pending {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary-dark);
  margin-bottom: 6px;
}
.badge-pending.badge-update { color: #2563eb; }
.badge-pending.badge-delete { color: var(--danger); }

.inchat-pending-summary {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.4;
}

.inchat-pending-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.inchat-btn {
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 8px;
}

.chat-form { display: flex; gap: 10px; }

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 14px;
  outline: none;
}
.chat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15); }

.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.primary:disabled { background: #9ca3af; cursor: wait; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.ghost:hover { background: #f0f3f6; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }

.hint { margin: 10px 2px 0; color: var(--muted); font-size: 12.5px; }

.manual-card { margin-bottom: 20px; }

.manual-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 12px; font-weight: 600; color: var(--muted); }

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  outline: none;
  min-width: 0;
}
.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

.field:nth-child(5),
.manual-form .wide { grid-column: 1 / -1; }

.btn.wide { width: 100%; margin-top: 2px; }

.admin-card { margin-top: 20px; }
.admin-card .card-title { margin-top: 16px; }
.admin-card .card-title:first-child { margin-top: 0; }

.admin-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-bottom: 8px;
}
.admin-form input,
.admin-form select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
}
#admin-account-form { grid-template-columns: 1fr auto; }

.admin-list { list-style: none; margin: 0 0 8px; padding: 0; max-height: 220px; overflow-y: auto; }

.admin-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.admin-item:last-child { border-bottom: none; }
.admin-item.inactive { color: var(--muted); }
.admin-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-item-type { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }

@media (max-width: 480px) {
  .topbar { padding: 12px 14px; }
  .topbar-user { gap: 8px; }
  .user-name { font-size: 13px; max-width: 38vw; }
  .layout { padding: 14px; }
  .manual-form { grid-template-columns: minmax(0, 1fr); }
  .admin-form { grid-template-columns: minmax(0, 1fr); }
}

.pending-card { border-color: var(--amber-line); background: var(--amber-bg); margin-bottom: 20px; }
.pending-card .card-title { color: var(--amber); }
.pending-summary { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.row { display: flex; gap: 10px; }

.transactions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.tx {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
}
.tx:last-child { border-bottom: none; }
.tx-main { min-width: 0; flex: 1; }
.tx-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tx-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.tx-amount { font-size: 14px; font-weight: 700; white-space: nowrap; }
.tx-amount.expense { color: var(--danger); }
.tx-amount.income { color: var(--primary); }
.tx-actions { display: flex; gap: 4px; }
.tx-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
}
.tx-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}
.tx-btn.delete:hover {
  background: #fef2f2;
  border-color: #fecaca;
}

.empty { color: var(--muted); font-size: 13.5px; margin: 4px 0 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #1c2430;
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
  z-index: 2000;
}
.toast.error { background: var(--danger); }

/* Modal Overlay & Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--line);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover {
  color: var(--text);
}
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
