/* =========================================================
   DESIGN TOKENS
   ========================================================= */
:root {
  --color-primary: #091413;
  --color-secondary: #285A48;
  --color-accent: #408A71;
  --color-bebas: #B8862F;
  /* kantong "bebas pakai" - warna hangat pembeda */
  --color-danger: #A6423A;

  --bg: #F4F6F5;
  --surface: #FFFFFF;
  --border: #DCE3E0;
  --text: #10201D;
  --text-muted: #5B6E68;

  --font-heading: 'Poppins', sans-serif;
  --font-body: 'Inter', sans-serif;

  --radius: 6px;
  --sidebar-w: 252px;
}

:root[data-theme="dark"] {
  --bg: #1C1C1D;
  --surface: #212122;
  --border: #45454A;
  --text: #F4F6F5;
  --text-muted: #A6A6AA;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  transition: background-color 0.25s ease, color 0.25s ease;
}

#pwaInstallWrap .btn-secondary {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

#pwaInstallWrap .btn-secondary:hover {
  background: rgba(64, 138, 113, 0.08);
  border-color: var(--color-accent);
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-heading);
  color: var(--text);
  margin: 0 0 4px;
  font-weight: 600;
  line-height: 1.25;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

p {
  margin: 0 0 8px;
  color: var(--text-muted);
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* =========================================================
   AUTH PAGES (login / register)
   ========================================================= */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.auth-visual {
  background: var(--color-primary);
  color: #fff;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.auth-visual .mark {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-visual .mark img {
  width: 34px;
  height: 34px;
  background: #fff;
  border-radius: var(--radius);
  padding: 4px;
  object-fit: contain;
  flex-shrink: 0;
}

.auth-visual .pitch h1 {
  color: #fff;
  font-size: clamp(28px, 3.4vw, 40px);
  max-width: 9ch;
}

.auth-visual .pitch p {
  color: #C9D6D1;
  max-width: 42ch;
  margin-top: 12px;
}

.auth-visual .split-preview {
  display: flex;
  gap: 8px;
  margin-top: 32px;
}

.split-preview .chip {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.split-preview .chip strong {
  display: block;
  font-family: var(--font-heading);
  font-size: 20px;
}

.split-preview .chip span {
  font-size: 12px;
  color: #A8BAB4;
}

.auth-visual .foot-note {
  color: #7E9690;
  font-size: 13px;
}

.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.auth-form {
  width: 100%;
  max-width: 380px;
}

.auth-form h2 {
  font-size: 24px;
}

.auth-form>p {
  margin-bottom: 28px;
}

/* =========================================================
   FORM ELEMENTS
   ========================================================= */
.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  white-space: nowrap;
}

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

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 72px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--color-accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font-body);
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover {
  background: #37785F;
  text-decoration: none;
}

.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--color-accent);
  text-decoration: none;
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-danger:hover {
  background: #8C362F;
  text-decoration: none;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.auth-switch {
  margin-top: 20px;
  font-size: 14px;
  text-align: center;
}

.form-error {
  background: #FBEAE8;
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 18px;
}

/* =========================================================
   APP SHELL
   ========================================================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  background: #fff;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 4px;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  margin: 0;
}

.brand-sub {
  font-size: 12px;
  color: #8FA69F;
  margin: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: auto;
}

.sidebar-nav a {
  color: #C9D6D1;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border-left: 2px solid transparent;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

.sidebar-nav a.is-active {
  background: rgba(64, 138, 113, 0.18);
  color: #fff;
  border-left-color: var(--color-accent);
}

.sidebar-wallet {
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  padding-top: 16px;
  margin-top: 20px;
}

.wallet-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #7E9690;
  margin-bottom: 10px;
}

.wallet-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  padding: 5px 0;
  color: #C9D6D1;
}

.wallet-row strong {
  font-family: var(--font-heading);
  font-weight: 600;
  color: #fff;
  font-size: 13px;
}

.wallet-row strong.is-negative {
  color: #E3948C;
}

.wallet-total {
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  margin-top: 6px;
  padding-top: 10px;
}

.wallet-total strong {
  color: #fff;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 14px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: transparent;
  color: #C9D6D1;
  font-size: 13px;
  cursor: pointer;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
}

.theme-toggle .icon-moon {
  display: none;
}

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

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

.sidebar-logout {
  margin-top: 18px;
  color: #8FA69F;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: underline;
}

.nav-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 30;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--color-primary);
  border: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: left 0.2s ease;
}

.app-shell:has(.sidebar.is-open) .nav-toggle {
  left: min(calc(78vw + 16px), 296px);
}

.nav-toggle span {
  width: 18px;
  height: 2px;
  background: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.app-shell:has(.sidebar.is-open) .nav-toggle span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.app-shell:has(.sidebar.is-open) .nav-toggle span:nth-child(2) {
  opacity: 0;
}

.app-shell:has(.sidebar.is-open) .nav-toggle span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 56px;
  max-width: none;
  width: calc(100% - var(--sidebar-w));
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 28px;
}

.page-head h1 {
  font-size: 24px;
}

.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 20px;
  border: 1px solid transparent;
}

.flash-success {
  background: #E9F3EE;
  border-color: var(--color-accent);
  color: var(--color-secondary);
}

.flash-error {
  background: #FBEAE8;
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* =========================================================
   CARDS & GRID
   ========================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

.card h2 {
  font-size: 16px;
}

.total-balance-card {
  display: flex;
  align-items: center;
  font-family: 'Poppins';
  gap: 8px;
  background: var(--color-primary);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}

.total-balance-card .stat-label {
  color: #8FA69F;
  margin: 0;
  font-size: 11px;
}

.total-balance-card .stat-value {
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  margin: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-card.bucket-nabung {
  border-left-color: var(--color-secondary);
}

.stat-card.bucket-bebas {
  border-left-color: var(--color-bebas);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: none;
}

.stat-card .stat-value {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin: 4px 0 10px;
}

.progress-track {
  height: 6px;
  border-radius: 3px;
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: var(--color-accent);
}

.bucket-nabung .progress-fill {
  background: var(--color-secondary);
}

.bucket-bebas .progress-fill {
  background: var(--color-bebas);
}

.stat-foot {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.two-col {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
}

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

.section-title a {
  font-size: 13px;
  font-weight: 500;
}

/* =========================================================
   TABLES
   ========================================================= */
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  width: 100%;
  display: block;
}

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

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

th {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: none;
}

td.amount-in {
  color: var(--color-secondary);
  font-weight: 600;
}

td.amount-out {
  color: var(--color-danger);
  font-weight: 600;
}

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.tag-utama {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.tag-nabung {
  color: var(--color-secondary);
  border-color: var(--color-secondary);
}

.tag-bebas {
  color: var(--color-bebas);
  border-color: var(--color-bebas);
}

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

.transaction-list {
  display: none;
}

.transaction-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface);
}

.transaction-card+.transaction-card {
  margin-top: 10px;
}

.transaction-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.transaction-card-top .amount-in,
.transaction-card-top .amount-out {
  font-weight: 600;
  font-size: 14px;
}

.transaction-card-mid {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.transaction-card-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.transaction-card-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

/* =========================================================
   FORM CARD LAYOUT (add income/expense, category, settings)
   ========================================================= */
.form-grid {
  display: grid;
  grid-template-columns: 480px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bucket-group {
  margin-bottom: 18px;
}

.bucket-group:last-child {
  margin-bottom: 0;
}

.bucket-group-label {
  display: inline-block;
  margin: 0 0 8px;
}

.category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.category-row .cat-meta {
  display: flex;
  align-items: center;
}

.category-row form {
  display: inline;
}

.percent-inputs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.percent-total {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 18px;
}

.percent-total strong {
  color: var(--text);
}

.percent-total.is-invalid strong {
  color: var(--color-danger);
}

/* =========================================================
   FILTER BAR RIWAYAT
   ========================================================= */
.tx-filter-bar {
  margin-bottom: 18px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end; /* Memastikan semua input dan tombol sejajar di bagian bawah */
}

.filter-row .field { 
  margin-bottom: 0; 
  min-width: 140px; 
}

.filter-search { 
  flex: 1 1 200px; 
}

/* Penyesuaian tombol Reset Filter agar berwarna hijau & sejajar presisi */
.filter-reset-btn {
  background: var(--color-accent);
  color: #fff;
  border: 1px solid var(--color-accent);
  height: 41px; /* Menyesuaikan tinggi standar input/select */
  padding: 0 16px;
  white-space: nowrap;
}

.filter-reset-btn:hover {
  background: #37785F;
  border-color: #37785F;
  color: #fff;
}

.riwayat-loading {
  text-align: center;
  padding: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.btn-icon {
  padding: 6px 8px;
  gap: 0;
}

.transaction-card-actions {
  gap: 8px;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-overlay.is-open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

.filter-toggle-btn {
  display: none;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

@media (max-width: 780px) {
  .filter-toggle-btn { 
    display: inline-flex; 
  }

  .filter-row {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 12px; /* Jarak konsisten antar field di mobile */
  }

  /* Reset margin dan flex agar field tidak merenggang berlebihan */
  .filter-row .field { 
    min-width: 0; 
    margin-bottom: 0; 
    flex: none; /* Menghapus aturan flex-basis 200px di mobile */
  }

  .tx-filter-bar.is-open .filter-row { 
    display: flex; 
  }

  .filter-reset-btn {
    width: 100%;
    margin-top: 4px;
  }
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 960px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }

  .auth-visual {
    display: none;
  }

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

  .two-col {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 780px) {
  .nav-toggle {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: min(78vw, 280px);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    padding: 20px 18px;
  }

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

  .main-content {
    padding: 84px 16px 48px;
    max-width: 100%;
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .form-actions {
    width: 100%;
    gap: 8px;
  }

  .form-actions .btn {
    flex: 1;
  }

  .card {
    padding: 16px;
  }

  .stat-grid {
    gap: 12px;
  }

  .category-row {
    flex-wrap: wrap;
    gap: 10px;
  }
}

@media (max-width: 780px) {

  .dashboard-tx-table,
  .list-tx-table {
    display: none;
  }

  .transaction-list {
    display: block;
  }

  .field-hint {
    font-size: 11px;
  }
}

@media (max-width: 520px) {
  .percent-inputs {
    grid-template-columns: 1fr;
  }

  th,
  td {
    white-space: normal;
  }

  .auth-form-wrap {
    padding: 24px 16px;
  }

  table {
    font-size: 13px;
    width: max-content;
    min-width: 100%;
  }

  th,
  td {
    padding: 8px;
  }

  .stat-card .stat-value {
    font-size: 19px;
  }
}

/* =========================================================
   LOADING OVERLAY
   ========================================================= */
#globalLoadingOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(9, 20, 19, 0.4);
}

#globalLoadingOverlay.is-visible {
  display: flex;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: loading-spin 0.7s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }

  .loading-spinner {
    animation-duration: 1.4s;
  }
}