/* ====== Tokens & reset ====== */
/* Tema "Buku Kas Digital": hijau pinus (untung), kertas hangat, aksen emas koin.
   UI: Plus Jakarta Sans · Angka uang: Spline Sans Mono */
:root {
  color-scheme: light;
  --bg: #f6f5f0;
  --surface: #ffffff;
  --text: #1c2420;
  --muted: #67736b;
  --border: #e6e4da;
  --border-strong: #c9c6b8;
  --hover-bg: #f3f2ec;
  --accent: #0e7a55;
  --accent-strong: #0a5c40;
  --accent-solid: #0e7a55;
  --accent-solid-hover: #0a5c40;
  --accent-soft: #e7f4ee;
  --accent-soft-hover: #d9ede4;
  --accent-soft-border: #cde9dc;
  --accent-softer: #f2faf6;
  --gold: #d99a06;
  --success: #0e7a55;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(28, 36, 32, 0.06);
  --shadow-md: 0 10px 28px rgba(28, 36, 32, 0.14);
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  --font-money: 'Spline Sans Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
}

/* Tema gelap: diaktifkan lewat data-theme di <html> (lihat js/theme.js).
   Default mengikuti prefers-color-scheme sampai pengguna memilih manual. */
[data-theme='dark'] {
  color-scheme: dark;
  --bg: #141816;
  --surface: #1d2320;
  --text: #e9edeb;
  --muted: #9fa9a3;
  --border: #2e3632;
  --border-strong: #4a554f;
  --hover-bg: #272e2a;
  --accent: #3cba8a;
  --accent-strong: #82dfba;
  --accent-solid: #168663;
  --accent-solid-hover: #1da377;
  --accent-soft: #20362c;
  --accent-soft-hover: #294738;
  --accent-soft-border: #31544a;
  --accent-softer: #1a2520;
  --gold: #e6b83c;
  --success: #3cba8a;
  --danger: #ff8a7a;
  --danger-soft: #402521;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.5);
}

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

[hidden] {
  display: none !important;
}

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

body {
  font-family: var(--font);
  /* Tekstur kertas halus di atas warna latar (tema "Buku Kas Digital") */
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* Transisi mulus saat pergantian tema (kelas dipasang sementara oleh theme.js) */
html.theme-anim,
html.theme-anim *,
html.theme-anim *::before,
html.theme-anim *::after {
  transition: background-color 0.35s ease, border-color 0.35s ease, color 0.35s ease !important;
}

/* Scrollbar tipis senada tema */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--muted);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

::selection {
  background: var(--accent);
  color: #fff;
}

[data-theme='dark'] ::selection {
  background: var(--accent);
  color: #0b1310;
}

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

svg {
  flex: none;
}

/* ====== Sidebar (desktop) ====== */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 18px;
  font-weight: 800;
  font-size: 15.5px;
  letter-spacing: -0.02em;
}

.brand-dot {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent) 20%, var(--gold) 110%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
  flex: none;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.side-nav a:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.side-nav a.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.side-nav svg {
  width: 20px;
  height: 20px;
}

.side-foot {
  margin-top: auto;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

/* ====== Main layout ====== */
.main {
  margin-left: 250px;
  max-width: 1100px;
  padding: 30px 32px 56px;
}

/* Kartu & header muncul bertahap saat halaman dibuka.
   Longhand (bukan shorthand animation) agar animation-delay di bawah
   tidak ikut tereset oleh rule dasar. */
.page-head,
.main > *:not(.stats-grid):not(.skeleton-grid),
.settings-stack > .card {
  animation-name: rise;
  animation-duration: 0.5s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
  animation-fill-mode: backwards;
}

.main > *:nth-child(2) { animation-delay: 0.05s; }
.main > *:nth-child(3) { animation-delay: 0.1s; }
.main > *:nth-child(4) { animation-delay: 0.15s; }
.main > *:nth-child(5) { animation-delay: 0.2s; }
.main > *:nth-child(6) { animation-delay: 0.25s; }
.main > *:nth-child(7) { animation-delay: 0.3s; }
.main > *:nth-child(8) { animation-delay: 0.35s; }
.main > *:nth-child(9) { animation-delay: 0.4s; }
.main > *:nth-child(10) { animation-delay: 0.45s; }

.settings-stack > .card:nth-child(2) { animation-delay: 0.06s; }
.settings-stack > .card:nth-child(3) { animation-delay: 0.12s; }

/* Transisi lembut antar halaman pada kerangka aplikasi */
.sidebar,
.bottom-nav {
  animation: pageFade 0.45s ease backwards;
}

@keyframes pageFade {
  from {
    opacity: 0;
  }
}

/* Sapaan dinamis di atas judul halaman */
.greeting {
  margin-bottom: 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-strong);
}

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

h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.page-sub {
  margin-top: 2px;
  font-size: 14px;
  color: var(--muted);
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Toggle tema: ikon bulan saat terang, matahari saat gelap (dikendalikan CSS),
   dengan animasi putar saat berganti. */
.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  animation: spinIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme='dark'] .theme-toggle .icon-sun {
  display: block;
  animation: spinIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

@keyframes spinIn {
  from {
    transform: rotate(-120deg) scale(0.4);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* ====== Card & filter bar ====== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.filter-card {
  padding: 14px 16px;
  margin-bottom: 16px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip.active {
  background: var(--accent-solid);
  border-color: var(--accent-solid);
  color: #fff;
}

.custom-range {
  display: none;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.custom-range.show {
  display: flex;
}

.custom-range label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}

/* ====== Statistik dashboard ====== */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px;
}

.skeleton {
  height: 86px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface) 40%, var(--hover-bg) 50%, var(--surface) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

.skeleton.sk-hero {
  grid-column: span 2;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  animation: rise 0.45s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.stat-card:nth-child(2) { animation-delay: 0.04s; }
.stat-card:nth-child(3) { animation-delay: 0.08s; }
.stat-card:nth-child(4) { animation-delay: 0.12s; }
.stat-card:nth-child(5) { animation-delay: 0.16s; }
.stat-card:nth-child(6) { animation-delay: 0.2s; }
.stat-card:nth-child(7) { animation-delay: 0.24s; }

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.stat-label {
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.stat-value {
  font-family: var(--font-money);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* Indikator perbandingan periode sebelumnya (diisi via JS) */
.stat-delta {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.stat-delta.up {
  color: var(--success);
}

.stat-delta.down {
  color: var(--danger);
}

.stat-card.hero .stat-delta.up {
  color: #a9ecd0;
}

.stat-card.hero .stat-delta.down {
  color: #ffd6cf;
}

/* Kartu utama: Pendapatan Bersih, ditata seperti total di struk.
   Gradient memakai warna literal (bukan token) agar sama di tema terang/gelap. */
.stat-card.hero {
  position: relative;
  grid-column: span 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border: 0;
  color: #fff;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 8px),
    linear-gradient(135deg, #128662, #0a5c40);
  box-shadow: 0 10px 24px rgba(10, 92, 64, 0.35);
}

/* Cahaya lembut di sekeliling kartu hero */
.stat-card.hero::after {
  content: '';
  position: absolute;
  inset: -14px;
  z-index: -1;
  border-radius: 28px;
  background: radial-gradient(closest-side, rgba(18, 134, 98, 0.38), transparent);
  pointer-events: none;
}

.stat-card.hero .stat-label {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.4);
  color: #b9e6d3;
}

.stat-card.hero .stat-value {
  font-size: clamp(28px, 5vw, 36px);
  font-weight: 700;
  letter-spacing: 0;
}

@media (max-width: 560px) {
  .stat-card.hero {
    grid-column: 1 / -1;
  }
}

@media (hover: hover) {
  .stat-card:not(.hero):hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    transition: transform 0.15s, box-shadow 0.15s;
  }
}

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

.empty-note {
  margin-top: 14px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

/* ====== Grafik tren profit ====== */
.chart-card {
  padding: 18px 18px 10px;
  margin-top: 16px;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.chart-head h2 {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.chart-sub {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.chart-total {
  font-family: var(--font-money);
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-body {
  position: relative;
}

.chart-body svg {
  display: block;
  width: 100%;
}

/* Bar grafik tumbuh dari garis nol saat dirender */
.chart-body .bar-pos,
.chart-body .bar-neg {
  transform-box: fill-box;
  animation: barGrow 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.chart-body .bar-pos {
  transform-origin: center bottom;
}

.chart-body .bar-neg {
  transform-origin: center top;
}

@keyframes barGrow {
  from {
    transform: scaleY(0);
  }
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  opacity: 0;
  transition: opacity 0.15s;
}

.chart-tooltip.show {
  opacity: 1;
}

.chart-tooltip span {
  display: block;
  color: var(--muted);
}

.chart-tooltip strong {
  font-family: var(--font-money);
  font-variant-numeric: tabular-nums;
}

.chart-empty {
  padding: 26px 0 22px;
  text-align: center;
  font-size: 13.5px;
  color: var(--muted);
}

/* Ilustrasi empty state */
.empty-illust {
  width: 92px;
  height: auto;
  margin-bottom: 14px;
  color: var(--muted);
  opacity: 0.85;
}

.empty-illust.small {
  width: 64px;
  margin-bottom: 8px;
  display: inline-block;
}

.illust-accent {
  color: var(--accent);
}

/* Badge kategori berwarna (tabel & widget) */
.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}

.cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  display: inline-block;
}

/* ====== Breakdown profit per kategori ====== */
.breakdown-body {
  padding: 4px 0 12px;
}

/* ====== Sorotan periode ====== */
.highlights-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 4px 0 12px;
}

.hl-label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.hl-value {
  display: block;
  font-size: 14.5px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.hl-sub {
  display: block;
  margin-top: 2px;
  font-family: var(--font-money);
  font-size: 13px;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  .highlights-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* Sorotan menjadi baris ringkas: label kiri, nilai kanan */
  .hl-item {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px dashed var(--border);
  }

  .hl-item:last-child {
    border-bottom: 0;
    padding-bottom: 2px;
  }

  .hl-label {
    grid-column: 1;
    grid-row: 1;
    margin-bottom: 0;
  }

  .hl-value {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
    font-size: 13.5px;
  }

  .hl-sub {
    grid-column: 2;
    grid-row: 2;
    text-align: right;
  }
}

/* ====== Rekap bulanan ====== */
.recap-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0 12px;
}

.mr-row {
  display: grid;
  grid-template-columns: 92px 1fr auto 52px;
  gap: 12px;
  align-items: center;
  padding: 8px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.mr-row:hover {
  background: var(--hover-bg);
}

.mr-label {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.mr-count {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .mr-row {
    grid-template-columns: 84px 1fr auto;
  }

  .mr-count {
    display: none;
  }
}

.cb-row {
  display: grid;
  grid-template-columns: minmax(90px, 150px) 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 7px 0;
}

.cb-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.cb-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--accent-softer);
  overflow: hidden;
}

.cb-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-solid), var(--gold));
  transform-origin: left center;
  animation: cbGrow 0.6s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

@keyframes cbGrow {
  from {
    transform: scaleX(0);
  }
}

.cb-fill.negative {
  background: var(--danger);
}

.cb-value {
  font-family: var(--font-money);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.cb-value.negative {
  color: var(--danger);
}

@media (max-width: 480px) {
  .cb-row {
    grid-template-columns: 1fr auto;
  }

  .cb-bar {
    grid-column: 1 / -1;
    order: 3;
  }
}

/* ====== Widget transaksi terakhir (dashboard) ====== */
.recent-more {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-strong);
}

.recent-list {
  list-style: none;
  padding: 2px 0 10px;
}

.recent-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px dashed var(--border);
}

.recent-list li:last-child {
  border-bottom: 0;
}

.recent-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.recent-date {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.recent-profit {
  font-family: var(--font-money);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ====== Tombol & input ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

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

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

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

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

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

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

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

/* Merah tetap solid di kedua tema agar teks putih selalu terbaca */
.btn-danger {
  background: #d92d20;
  color: #fff;
}

.btn-danger:hover {
  background: #b42318;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

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

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  /* >=16px agar iOS Safari tidak auto-zoom saat input difokuskan */
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 122, 85, 0.18);
}

.textarea {
  resize: vertical;
  min-height: 60px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr 92px;
  gap: 10px;
}

@media (max-width: 480px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }

  .field-row .field:last-child {
    grid-column: 1 / -1;
  }
}

/* ====== Filter transaksi ====== */
.filters-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: center;
}

.filters-grid > * {
  min-width: 0;
}

.filters-grid .input,
.filters-grid .select {
  height: 42px;
}

@media (max-width: 900px) {
  .filters-grid {
    grid-template-columns: 1fr 1fr;
  }

  .filters-grid #search {
    grid-column: 1 / -1;
  }
}

@media (max-width: 480px) {
  .filters-grid {
    grid-template-columns: 1fr 1fr;
  }

  .filters-grid #search {
    grid-column: 1 / -1;
  }
}

.count-note {
  padding: 13px 16px 0;
  font-size: 12.5px;
  color: var(--muted);
}

/* ====== Tabel transaksi ====== */
.table-wrap {
  overflow-x: auto;
  padding: 6px 8px 10px;
}

table {
  width: 100%;
  min-width: 1010px;
  border-collapse: collapse;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  color: var(--muted);
  white-space: nowrap;
}

/* Kolom yang bisa diklik untuk mengurutkan — ikon indikator berupa SVG
   (mask) agar tidak bergantung pada glyph panah yang tidak ada di font UI. */
th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable::after {
  content: '';
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-left: 5px;
  vertical-align: -1px;
  background-color: currentColor;
  opacity: 0.4;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 9 5-5 5 5'/%3E%3Cpath d='m7 15 5 5 5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 9 5-5 5 5'/%3E%3Cpath d='m7 15 5 5 5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}

th.sort-asc::after {
  opacity: 1;
  color: var(--accent-strong);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5'/%3E%3Cpath d='m5 12 7-7 7 7'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 19V5'/%3E%3Cpath d='m5 12 7-7 7 7'/%3E%3C/svg%3E");
}

th.sort-desc::after {
  opacity: 1;
  color: var(--accent-strong);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14'/%3E%3Cpath d='m19 12-7 7-7-7'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14'/%3E%3Cpath d='m19 12-7 7-7-7'/%3E%3C/svg%3E");
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

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

tbody tr:hover {
  background: var(--accent-softer);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* Baris total hasil filter */
tfoot td {
  padding: 12px;
  border-top: 2px solid var(--border-strong);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.item-name {
  display: block;
  font-weight: 600;
}

.cell-notes {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.fee-pct {
  font-size: 12px;
  color: var(--muted);
}

.positive {
  color: var(--success);
}

.negative {
  color: var(--danger);
}

td.positive,
td.negative,
strong.positive,
strong.negative {
  font-weight: 600;
}

.cell-actions {
  white-space: nowrap;
}

.cell-actions .icon-btn + .icon-btn {
  margin-left: 6px;
}

.empty-state {
  margin: 10px;
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
}

.empty-state p {
  margin-bottom: 16px;
}

/* ====== Paginasi tabel ====== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 0 6px;
}

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

.small-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

  /* Mobile: tabel menjadi kartu ringkas (grid, bukan daftar panjang) */
  @media (max-width: 768px) {
    table {
      min-width: 0;
    }

    thead {
      display: none;
    }

    tbody tr {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      grid-template-areas:
        'item item date'
        'cat cat margin'
        'modal jual fee'
        'net net net'
        'aksi aksi aksi';
      gap: 0 12px;
      margin: 10px 8px;
      padding: 12px 14px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px;
      box-shadow: var(--shadow-sm);
    }

    tbody td {
      display: flex;
      align-items: center;
      min-width: 0;
      padding: 2px 0;
      border-bottom: 0;
      text-align: left;
    }

    tbody td::before {
      content: attr(data-label);
      flex: none;
      margin-right: 6px;
      font-size: 10.5px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--muted);
    }

    tbody td[data-label='Item'] {
      grid-area: item;
      flex-direction: column;
      align-items: flex-start;
    }

    tbody td[data-label='Item']::before {
      content: none;
    }

    tbody td[data-label='Tanggal'] {
      grid-area: date;
      justify-content: flex-end;
      font-size: 12px;
      color: var(--muted);
    }

    tbody td[data-label='Tanggal']::before {
      content: none;
    }

    tbody td[data-label='Kategori'] {
      grid-area: cat;
    }

    tbody td[data-label='Kategori']::before {
      content: none;
    }

    tbody td[data-label='Margin'] {
      grid-area: margin;
      justify-content: flex-end;
      font-size: 12.5px;
    }

    tbody td[data-label='Modal'] {
      grid-area: modal;
    }

    tbody td[data-label='Harga Jual'] {
      grid-area: jual;
    }

    tbody td[data-label='Fee'] {
      grid-area: fee;
    }

    tbody td[data-label='Modal'],
    tbody td[data-label='Harga Jual'],
    tbody td[data-label='Fee'] {
      flex-direction: column;
      align-items: flex-start;
      gap: 0;
      margin-top: 8px;
      padding-top: 8px;
      border-top: 1px dashed var(--border);
    }

    tbody td[data-label='Pendapatan Bersih'] {
      grid-area: net;
      justify-content: space-between;
      margin-top: 8px;
      padding-top: 10px;
      border-top: 1px dashed var(--border);
      font-size: 15px;
    }

    tbody td[data-label='Aksi'] {
      grid-area: aksi;
      justify-content: flex-end;
      gap: 8px;
      margin-top: 6px;
      padding-top: 8px;
      border-top: 1px solid var(--border);
    }

    tbody td[data-label='Aksi']::before {
      content: none;
    }

    .cell-notes {
      margin-top: 2px;
    }

    /* Baris total: kartu ringkas dua kolom */
    tfoot tr {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 0 12px;
      margin: 12px 8px;
      padding: 12px 14px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px;
      box-shadow: var(--shadow-sm);
    }

    tfoot td {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 3px 0;
      border-top: 0;
      border-bottom: 0;
      text-align: right;
    }

    tfoot td::before {
      content: attr(data-label);
      flex: none;
      margin-right: 6px;
      font-size: 10.5px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--muted);
      text-align: left;
    }

    tfoot td[data-label='Total'] {
      grid-column: 1 / -1;
      margin-bottom: 4px;
      padding-bottom: 8px;
      border-bottom: 1px dashed var(--border);
      font-size: 14px;
    }

    tfoot td[data-label='Total']::before {
      content: none;
    }

    tfoot td[data-label='Pendapatan Bersih'] {
      grid-column: 1 / -1;
      margin-top: 6px;
      padding-top: 8px;
      border-top: 1px dashed var(--border);
      font-size: 15px;
    }

    tfoot td[data-label=''] {
      display: none;
    }

    .cell-actions {
      justify-content: flex-end;
    }

    .item-name {
      font-size: 14.5px;
      overflow-wrap: anywhere;
    }
  }

/* ====== Modal transaksi ====== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
}

.modal-sm {
  max-width: 400px;
}

.confirm-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 20px 20px;
}

.confirm-message {
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

#tx-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 20px;
}

.preview-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 13px 15px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: 12px;
}

.preview-box > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 13.5px;
  color: var(--muted);
}

.preview-box strong {
  font-family: var(--font-money);
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.form-error {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

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

@media (max-width: 560px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: none;
    max-height: 94vh;
    max-height: 94dvh;
    border-radius: 18px 18px 0 0;
  }

  .modal-head {
    border-radius: 18px 18px 0 0;
  }

  /* beri ruang aman agar tombol tidak tertutup home indicator */
  #tx-form {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .modal-actions {
    flex-direction: row-reverse;
  }

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

/* ====== Layar kunci PIN ====== */
.lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.lock-box {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.lock-dot {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  margin-bottom: 4px;
}

.lock-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.lock-sub {
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 10px;
}

.lock-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.lock-input {
  text-align: center;
  font-family: var(--font-money);
  font-size: 22px;
  letter-spacing: 10px;
}

.lock-error {
  font-size: 13px;
  color: var(--danger);
}

.lock-keypad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 8px;
  margin-top: 12px;
  justify-content: center;
}

.key-btn {
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

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

.key-btn:active {
  transform: scale(0.96);
}

.lock-box.shake {
  animation: shake 0.4s;
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* ====== Halaman pengaturan ====== */
.settings-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-card {
  padding: 20px;
}

.settings-card h2 {
  margin-bottom: 4px;
  font-size: 16px;
  font-weight: 700;
}

.hint {
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}

.fee-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.pin-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 300px;
}

.pin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 2px;
}

.fee-input {
  width: 110px;
  text-align: right;
}

.pct-sign {
  color: var(--muted);
  font-weight: 600;
}

.save-hint {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--success);
}

.save-hint svg {
  vertical-align: -1px;
}

.stat-delta svg {
  margin-right: 4px;
  vertical-align: -0.5px;
}

.category-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.cat-name {
  font-weight: 500;
  overflow-wrap: anywhere;
}

.cat-badge {
  margin-left: 8px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

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

.small-btn {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.small-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.small-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}

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

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

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

.rename-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
}

.category-add {
  display: flex;
  gap: 10px;
}

.category-add .input {
  flex: 1;
  min-width: 0;
}

.cat-error {
  margin-top: 10px;
  font-size: 13px;
  color: var(--danger);
}

/* ====== Toast notifikasi ====== */
.toast-container {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

@media (max-width: 768px) {
  .toast-container {
    bottom: calc(88px + env(safe-area-inset-bottom));
  }
}

.toast {
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: none;
}

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

/* ====== Ripple & confetti ====== */
.btn,
.small-btn,
.key-btn,
.chip,
.icon-btn {
  position: relative;
  overflow: hidden;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.18;
  pointer-events: none;
  transform: scale(0);
  animation: ripple 0.5s ease-out forwards;
}

@keyframes ripple {
  to {
    transform: scale(1);
    opacity: 0;
  }
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
  overflow: hidden;
  pointer-events: none;
}

.confetti {
  position: absolute;
  top: -14px;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  to {
    transform: translateY(110vh) rotate(var(--rot, 360deg));
    opacity: 0.85;
  }
}

/* ====== Bottom navigation (mobile) ====== */
.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  display: none;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.bottom-nav a.active {
  color: var(--accent-strong);
  font-weight: 600;
}

.bottom-nav svg {
  width: 22px;
  height: 22px;
}

/* ====== FAB tambah cepat (khusus mobile) ====== */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 35;
  display: none;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  background: var(--accent-solid);
  color: #fff;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.fab svg {
  width: 26px;
  height: 26px;
}

.fab:hover {
  background: var(--accent-solid-hover);
}

.fab:active {
  transform: scale(0.94);
}

/* ====== Responsive breakpoint ====== */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .bottom-nav {
    display: flex;
  }

  .fab {
    display: flex;
  }

  .main {
    margin-left: 0;
    padding: 20px 16px calc(96px + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 21px;
  }

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

  .page-head .btn {
    width: 100%;
  }

  /* Perbesar area sentuh (target nyaman ~44px) */
  .icon-btn {
    width: 40px;
    height: 40px;
  }

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

  .chip {
    padding: 9px 16px;
  }

  .small-btn {
    padding: 9px 14px;
  }

  .bottom-nav a {
    padding: 8px 4px;
  }

  .stat-value {
    font-size: 17px;
    overflow-wrap: anywhere;
  }

  .stat-card {
    padding: 12px 14px;
  }

  /* Rekap bulan tanpa transaksi disembunyikan agar tidak buang ruang */
  .recap-list .mr-row.mr-empty {
    display: none;
  }
}
