/* =========================================================
   CATATKU — COMPONENTS.CSS
   Komponen UI yang dapat dipakai ulang di seluruh halaman.
   ========================================================= */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  transition: background var(--transition-fast), border-color var(--transition-fast), opacity var(--transition-fast);
}

.btn svg {
  width: 16px;
  height: 16px;
}

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

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color-strong);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

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

.btn-danger:hover {
  opacity: 0.9;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Card umum ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

/* ---------- Welcome / placeholder card (Tahap 1) ---------- */
.welcome-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-sm);
  max-width: 640px;
}

.welcome-card h2 {
  font-size: 22px;
  margin-bottom: 10px;
}

.welcome-card p {
  color: var(--text-secondary);
  font-size: 14.5px;
  line-height: 1.6;
  margin-bottom: 20px;
}

.welcome-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.db-status {
  font-size: 13px;
  color: var(--text-muted);
}

.db-status.is-success {
  color: var(--color-primary-dark);
  font-weight: 600;
}

.db-status.is-error {
  color: var(--color-expense);
  font-weight: 600;
}

.placeholder-card {
  background: var(--bg-card);
  border: 1px dashed var(--border-color-strong);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
  max-width: 480px;
  margin: 40px auto 0;
}

.placeholder-card svg {
  width: 34px;
  height: 34px;
  margin: 0 auto 14px;
  color: var(--color-primary);
}

.placeholder-card h2 {
  font-size: 17px;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.placeholder-card p {
  font-size: 13.5px;
  line-height: 1.6;
}

/* ---------- Empty state (dipakai pada tahap-tahap berikutnya) ---------- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 40px;
  height: 40px;
  color: var(--text-muted);
  margin: 0 auto 12px;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13.5px;
  margin-bottom: 18px;
}

/* ---------- Switch (toggle) ---------- */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  transition: background var(--transition-fast);
}

.switch-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition-fast);
}

.switch input:checked + .switch-slider {
  background: var(--color-primary);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}

/* ---------- Toast notification ---------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  color: var(--text-primary);
  min-width: 240px;
  max-width: 340px;
  animation: toast-in 200ms ease;
}

.toast.toast-error {
  border-left-color: var(--color-expense);
}

.toast.toast-warning {
  border-left-color: var(--color-warning);
}

.toast.toast-info {
  border-left-color: var(--color-info);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Modal ---------- */
.modal-root:empty {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 21, 32, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 900;
  animation: modal-fade 150ms ease;
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  padding: 24px;
}

.modal-box h3 {
  font-size: 17px;
  margin-bottom: 10px;
}

.modal-box p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* =========================================================
   DASHBOARD — kartu statistik, grafik, transaksi terakhir, anggaran
   ========================================================= */

/* ---------- Grid umum ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* ---------- Stat card ---------- */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

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

.stat-icon svg {
  width: 20px;
  height: 20px;
}

.stat-icon-balance { background: var(--color-primary-light); color: var(--color-primary-dark); }
.stat-icon-income { background: var(--color-income-bg); color: var(--color-income); }
.stat-icon-expense { background: var(--color-expense-bg); color: var(--color-expense); }
.stat-icon-count { background: var(--color-warning-bg); color: var(--color-warning); }

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

.stat-label {
  font-size: 12.5px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.stat-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------- Card header (dipakai di dalam .card) ---------- */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}

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

.card-header-note {
  font-size: 12px;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--color-primary-dark);
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px;
}

.link-btn:hover {
  text-decoration: underline;
}

/* ---------- Chart card ---------- */
.chart-wrap {
  position: relative;
  width: 100%;
}

.chart-wrap-line {
  height: 260px;
}

.chart-wrap-doughnut {
  height: 180px;
  max-width: 220px;
  margin: 0 auto;
}

/* ---------- Legend kategori (doughnut) ---------- */
.legend-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name {
  flex: 1;
  color: var(--text-primary);
}

.legend-percent {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12.5px;
}

.legend-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  list-style: none;
}

/* ---------- Transaksi terakhir ---------- */
.transaction-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.transaction-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.transaction-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.transaction-icon svg {
  width: 16px;
  height: 16px;
}

.transaction-icon.is-income { background: var(--color-income-bg); color: var(--color-income); }
.transaction-icon.is-expense { background: var(--color-expense-bg); color: var(--color-expense); }

.transaction-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.transaction-desc {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-category {
  font-size: 12px;
  color: var(--text-muted);
}

.transaction-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.transaction-amount {
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
}

.transaction-amount.is-income { color: var(--color-income); }
.transaction-amount.is-expense { color: var(--color-expense); }

.transaction-date {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------- Anggaran bulan ini ---------- */
.budget-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.budget-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.budget-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.budget-row-name {
  font-size: 13.5px;
  font-weight: 600;
}

.budget-row-percent {
  font-size: 12.5px;
  font-weight: 700;
}

.budget-row-percent.is-safe { color: var(--color-primary-dark); }
.budget-row-percent.is-near { color: var(--color-warning); }
.budget-row-percent.is-over { color: var(--color-expense); }

.budget-row-amounts {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: var(--bg-hover);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  transition: width var(--transition-base);
}

.progress-bar.is-safe { background: var(--color-primary); }
.progress-bar.is-near { background: var(--color-warning); }
.progress-bar.is-over { background: var(--color-expense); }

/* ---------- Empty state: tombol di dalamnya ikut style .btn, sudah ada ---------- */

/* =========================================================
   HALAMAN TRANSAKSI — toolbar, tabel responsif, pagination
   ========================================================= */

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  background: var(--bg-card);
  min-width: 220px;
  flex: 1;
  max-width: 320px;
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  border: none;
  background: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13.5px;
  width: 100%;
}

.filter-select {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13.5px;
}

.table-card {
  padding: 8px 20px 20px;
}

#trxTableWrap {
  overflow-x: auto;
}

.trx-table-header,
.trx-row {
  min-width: 640px;
}
.trx-table-header,
.trx-row {
  display: grid;
  grid-template-columns: 110px 1.6fr 1fr 110px 150px 90px;
  align-items: center;
  gap: 10px;
}

.trx-table-header {
  padding: 14px 8px;
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.trx-sort-btn {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  text-align: left;
  padding: 0;
}

.trx-sort-amount {
  text-align: right;
}

.trx-col-actions {
  text-align: right;
}

.trx-row {
  padding: 14px 8px;
  border-bottom: 1px solid var(--border-color);
  font-size: 13.5px;
}

.trx-row:last-child {
  border-bottom: none;
}

.trx-cell {
  min-width: 0;
}

.trx-cell-desc span:not(.cell-label) {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trx-cell-amount {
  text-align: right;
}

.amount-text {
  font-weight: 700;
}

.amount-text.is-income { color: var(--color-income); }
.amount-text.is-expense { color: var(--color-expense); }

.trx-cell-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.cell-label {
  display: none;
}

.icon-action-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-action-btn svg {
  width: 14px;
  height: 14px;
}

.icon-action-btn:hover {
  background: var(--bg-hover);
}

.icon-action-btn.icon-action-danger:hover {
  background: var(--color-expense-bg);
  color: var(--color-expense);
  border-color: var(--color-expense-bg);
}

/* ---------- Pagination ---------- */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 16px;
}

.pagination-info {
  font-size: 12.5px;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  gap: 8px;
}

/* =========================================================
   FORM MODAL (Tambah/Edit Transaksi, dsb.)
   ========================================================= */
.modal-box-form {
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
}

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

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-optional {
  font-weight: 400;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13.5px;
  background: var(--bg-input);
  color: var(--text-primary);
}

textarea.form-input {
  resize: vertical;
  font-family: inherit;
}

.form-error {
  display: block;
  font-size: 12px;
  color: var(--color-expense);
  margin-top: 4px;
  min-height: 14px;
}

.segmented-control {
  display: flex;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segment-btn {
  flex: 1;
  padding: 9px;
  background: var(--bg-card);
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  border-right: 1px solid var(--border-color-strong);
}

.segment-btn:last-child {
  border-right: none;
}

.segment-btn.is-active {
  background: var(--color-primary);
  color: #fff;
}

/* =========================================================
   HALAMAN KATEGORI — tab tipe, daftar kategori, icon & color picker
   ========================================================= */

.segmented-control-tabs {
  width: auto;
  max-width: 320px;
}

.segment-btn.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.category-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border-color);
}

.category-row:last-child {
  border-bottom: none;
}

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

.category-icon svg {
  width: 18px;
  height: 18px;
}

.category-name {
  flex: 1;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.category-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.category-preview-group {
  background: var(--bg-hover);
  border-radius: var(--radius-md);
  padding: 6px 10px;
}

.category-preview {
  padding: 8px 4px;
  border-bottom: none;
}

.form-hint {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 6px;
}

.icon-picker {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  max-height: 168px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.icon-choice {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-choice svg {
  width: 16px;
  height: 16px;
}

.icon-choice.is-selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.color-picker {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.color-choice {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-choice.is-selected {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--bg-card);
}

/* ---------- Badge (dipakai untuk status kategori/anggaran nanti) ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge-income {
  background: var(--color-income-bg);
  color: var(--color-income);
}

.badge-expense {
  background: var(--color-expense-bg);
  color: var(--color-expense);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}
