/* =====================================================================
   Buku Kas — Design tokens
   Konsep: "ruang kontrol finansial" — bidang datar, garis rambut, satu
   aksen teal yang dipakai secara sengaja, warna status (hijau/kuning/
   merah) murni untuk makna, bukan dekorasi. Angka selalu monospace &
   rata kanan supaya cepat dipindai.
   Tipografi: Space Grotesk (judul/angka besar) + IBM Plex Sans (isi) +
   IBM Plex Mono (angka tabel).
   ===================================================================== */

:root {
  --bg:           #EEF1F5;
  --surface:      #FFFFFF;
  --surface-2:    #F6F8FA;
  --ink:          #0F1B2D;
  --ink-soft:     #52607A;
  --ink-dim:      #8993A8;
  --line:         #DCE2EA;
  --line-soft:    #E9EDF2;

  --teal:         #0E7C7B;
  --teal-soft:    #DFF1EF;
  --teal-ink:     #085856;

  --emerald:      #17915F;
  --emerald-soft: #DEF2E7;
  --amber:        #B9791A;
  --amber-soft:   #F7EAD3;
  --crimson:      #C6403D;
  --crimson-soft: #F9E2E1;

  --font-display: 'Space Grotesk', 'IBM Plex Sans', sans-serif;
  --font-body:    'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;

  --radius: 8px;
  --radius-sm: 5px;
  --shadow-pop: 0 20px 44px -18px rgba(15,27,45,0.35);

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg:           #0B121F;
  --surface:      #121B2C;
  --surface-2:    #17233A;
  --ink:          #EAF0FA;
  --ink-soft:     #9DAAC4;
  --ink-dim:      #6A7690;
  --line:         #253251;
  --line-soft:    #1B273F;

  --teal:         #35C7BE;
  --teal-soft:    #0F2E31;
  --teal-ink:     #6DE0D8;

  --emerald:      #34C486;
  --emerald-soft: #0E2C24;
  --amber:        #E3A63C;
  --amber-soft:   #302410;
  --crimson:      #EA6D68;
  --crimson-soft: #341918;

  --shadow-pop: 0 20px 44px -16px rgba(0,0,0,0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
  overflow-x: hidden; /* jaring pengaman: cegah SELURUH halaman ikut
    scroll horizontal kalau ada elemen yang meleset lebar (lihat juga
    perbaikan min-width:0 pada .layout/.card di bawah). Area yang
    memang sengaja bisa discroll ke samping (.month-tabs, .table-wrap)
    tetap jalan normal karena masing-masing sudah overflow-x:auto sendiri. */
}

/* ---------------------------------------------------------------------
   Kunci scroll body saat modal terbuka.
   overflow:hidden saja TIDAK cukup di iOS Safari (body tetap bisa
   di-scroll lewat sentuhan walau overflow:hidden), dan itu yang bikin
   modal (position:fixed) terasa "hilang, harus scroll dulu baru
   ketemu" kalau modal dibuka saat halaman sedang dalam posisi
   ter-scroll. Makanya body dikunci pakai position:fixed + top negatif
   (lihat initModalScrollLock di app.js) supaya benar-benar beku, lalu
   posisi scroll semula dikembalikan saat modal ditutup. */
body.modal-open {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
}

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

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

/* ---------------------------------------------------------------------
   Masthead
   --------------------------------------------------------------------- */
.masthead { padding: 28px 0 20px; }

.masthead__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 18px;
}

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

.masthead__mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  flex: none;
}

.masthead__title h1 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.2px;
}

.masthead__title p {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.masthead__actions { display: flex; gap: 8px; align-items: center; }

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease, transform .05s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:active { transform: translateY(1px); }

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

.btn--ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { border-color: var(--ink-dim); }

.btn--icon-only {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.btn--icon-only:hover { color: var(--ink); border-color: var(--ink-dim); }
.btn--icon-only svg { width: 16px; height: 16px; }

.btn--add {
  display: flex;
  width: 100%;
  margin-top: 10px;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--ink-soft);
  padding: 9px;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  border-radius: var(--radius-sm);
}
.btn--add:hover { border-color: var(--teal); color: var(--teal-ink); background: var(--teal-soft); }

.btn--icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-dim);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1;
}
.btn--icon:hover { color: var(--crimson); background: var(--crimson-soft); }

.btn--terima { color: var(--emerald); margin-right: 2px; }
.btn--terima:hover { color: var(--emerald); background: var(--emerald-soft); }

.hint-text {
  margin: 8px 2px 0;
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.4;
}

/* ---------------------------------------------------------------------
   Month switcher — pill segmented row + jump dropdown
   --------------------------------------------------------------------- */
.month-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.month-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  flex: 1 1 auto;
  min-width: 0;
}

.month-tab {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: transparent;
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}

.month-tab:hover { color: var(--ink); }

.month-tab.is-active {
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

.month-tab__del {
  opacity: 0;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0 2px;
}
.month-tab:hover .month-tab__del { opacity: .55; }
.month-tab__del:hover { opacity: 1 !important; color: var(--crimson); }

.month-jump {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--ink-soft);
  flex: none;
}
.month-jump:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

/* ---------------------------------------------------------------------
   KPI strip
   --------------------------------------------------------------------- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.kpi__label { font-size: 11.5px; color: var(--ink-soft); font-weight: 500; }

.kpi__row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }

.kpi__value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi__delta {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
  flex: none;
}
.kpi__delta--up { background: var(--emerald-soft); color: var(--emerald); }
.kpi__delta--down { background: var(--crimson-soft); color: var(--crimson); }
.kpi__delta--flat { background: var(--surface-2); color: var(--ink-dim); }

.kpi__spark { width: 100%; height: 22px; display: block; }
.kpi__spark path { fill: none; stroke-width: 1.6; }

.kpi--income .kpi__value { color: var(--emerald); }
.kpi--paid .kpi__value { color: var(--emerald); }
.kpi--due .kpi__value { color: var(--crimson); }
.kpi--balance { background: var(--ink); border-color: var(--ink); }
.kpi--balance .kpi__label { color: #AEB9D2; }
.kpi--balance .kpi__value { color: var(--bg); }
.kpi__value.is-negative { color: var(--crimson) !important; }

/* ---------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: 1fr 336px; gap: 20px; align-items: start; min-width: 0; }
/* min-width:0 di bawah ini WAJIB: tanpa ini, item grid/flex punya
   min-width:auto bawaan browser, artinya tabel lebar (ledger-table)
   yang tak bisa menyusut akan "mendorong" lebar minimum ini naik ke
   .card -> .layout__main/.layout__side -> .layout -> .page -> body,
   sehingga SELURUH HALAMAN melebar & butuh scroll horizontal/zoom-out
   di HP — bukan cuma tabelnya (yang sebenarnya sudah dibungkus
   .table-wrap { overflow-x:auto } dan seharusnya scroll sendiri secara
   lokal). Ini akar penyebab tampilan kurang optimal di layar sempit. */
.layout__main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.layout__side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; min-width: 0; }

/* Cards */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  background: var(--surface);
  min-width: 0;
}
.card--accent-teal { border-left: 3px solid var(--teal); }
.card--accent-emerald { border-left: 3px solid var(--emerald); }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.card__head h2 {
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 700;
  margin: 0;
}

.card__tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.search {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12.5px;
  background: var(--surface-2);
  min-width: 150px;
}
.search:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

.chip-group { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.chip {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.chip:hover { color: var(--ink); }
.chip.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(15,27,45,0.12); }

/* Tables */
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 220px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.table-wrap--tall { max-height: 320px; }

.ledger-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.ledger-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  font-weight: 500;
  color: var(--ink-dim);
  font-size: 11px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th.is-sortable { cursor: pointer; user-select: none; }
th.is-sortable:hover { color: var(--ink); }
th.is-sortable .sort-arrow { display: inline-block; width: 10px; opacity: .5; font-size: 9px; }
th.is-sortable.is-sorted .sort-arrow { opacity: 1; color: var(--teal); }

.ledger-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  position: relative;
}

.ledger-table tbody tr:hover { background: var(--surface-2); }
.ledger-table tbody tr.row-flash { animation: rowFlash 900ms ease; }
@keyframes rowFlash { from { background: var(--teal-soft); } to { background: transparent; } }

.col-num { text-align: right; font-family: var(--font-mono); white-space: nowrap; }
.col-action { width: 30px; text-align: center; }
.col-status { width: 100px; }
.col-rekening { min-width: 112px; }

.cell-select {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 4px;
  padding: 4px 6px;
  width: 100%;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
}
.cell-select:hover { border-color: var(--line); }
.cell-select:focus { border-color: var(--teal); background: var(--surface-2); outline: none; color: var(--ink); }
.cell-select option { color: var(--ink); }
.col-drag { width: 22px; padding: 7px 0 !important; text-align: center; }

/* Drag handle — geser baris untuk mengubah urutan */
.drag-handle {
  background: none;
  border: none;
  padding: 4px;
  border-radius: 4px;
  color: var(--ink-dim);
  cursor: grab;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.drag-handle:hover { color: var(--ink); background: var(--surface-2); }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 14px; height: 14px; pointer-events: none; }

/* Dinonaktifkan sementara saat tabel sedang diurutkan/difilter — urutan
   manual hanya berarti pada urutan asli (tanpa sort kolom / pencarian). */
.is-order-locked .drag-handle { color: var(--ink-dim); opacity: .35; cursor: not-allowed; }

.ledger-table tbody tr.is-dragging {
  background: var(--teal-soft);
  box-shadow: inset 0 0 0 1px var(--teal);
  position: relative;
  z-index: 2;
}
.ledger-table tbody tr.is-dragging .cell-input,
.ledger-table tbody tr.is-dragging .btn--icon { pointer-events: none; }

body.is-row-dragging { cursor: grabbing !important; }
body.is-row-dragging * { user-select: none !important; }

.ledger-table__total td {
  border-bottom: none;
  border-top: 2px solid var(--ink);
  font-weight: 700;
  padding-top: 9px;
}

.cell-input {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 4px;
  padding: 4px 6px;
  width: 100%;
  font-family: inherit;
}
.cell-input:hover { border-color: var(--line); }
.cell-input:focus { border-color: var(--teal); background: var(--surface-2); outline: none; }

input.cell-input.col-num-input { text-align: right; font-family: var(--font-mono); }

/* Kolom nominal yang cuma bisa diubah lewat kalkulator ± (Terbayar &
   Biaya Admin di Pengeluaran, Jumlah di Pendapatan) — tampil beda dari
   kolom yang bisa diketik langsung supaya jelas bukan field kosong biasa,
   dan kursor "pointer" menandakan area itu bisa diklik untuk buka
   kalkulatornya. */
.cell-input.is-calc-only {
  background: var(--surface-2);
  color: var(--ink-soft);
  cursor: pointer;
}
.cell-input.is-calc-only:hover { border-color: var(--teal); }
.cell-input.is-calc-only:focus { background: var(--surface-2); }

/* Wrapper kolom nominal: input + tombol kalkulator tambah/kurang */
.col-num-wrap { display: flex; align-items: center; gap: 2px; }
.col-num-wrap .cell-input { flex: 1 1 auto; min-width: 0; }
.btn--calc {
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-dim);
  border-radius: 4px;
  width: 22px;
  height: 22px;
  line-height: 1;
  font-size: 13px;
  font-family: var(--font-mono);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.btn--calc:hover { color: var(--teal-ink); background: var(--teal-soft); border-color: var(--teal); }
.is-readonly .btn--calc,
.is-readonly #btnRefreshAiRec { display: none !important; }
.is-readonly .cell-input.is-calc-only { cursor: default; }

/* ---------------------------------------------------------------------
   Modal — transfer saldo antar rekening
   --------------------------------------------------------------------- */
.transfer-preview {
  margin: -4px 0 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--teal-ink);
}
.transfer-preview.is-error { color: var(--crimson); }

/* Kolom "Biaya Admin" (Pengeluaran) — sama seperti kolom nominal
   lain (Tagihan/Terbayar), cuma sedikit lebih lebar untuk header
   "Biaya Admin" yang lebih panjang. */
.col-admin { min-width: 108px; }

/* ---------------------------------------------------------------------
   Modal — Riwayat / History transaksi
   --------------------------------------------------------------------- */
.riwayat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -4px 0 12px;
  flex-wrap: wrap;
}
.riwayat-toolbar__scope { margin: 0; }
.riwayat-toolbar .btn--ghost { font-size: 12.5px; padding: 6px 10px; }

.riwayat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 55vh;
  overflow-y: auto;
  margin: 0 -4px 4px;
  padding: 0 4px;
}

.riwayat-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.riwayat-item__badge {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-mono);
  background: var(--surface-2);
  color: var(--ink-dim);
}
.riwayat-item.is-tambah .riwayat-item__badge { background: var(--teal-soft); color: var(--teal-ink); }
.riwayat-item.is-terima .riwayat-item__badge { background: var(--teal-soft); color: var(--teal-ink); }
.riwayat-item.is-hapus .riwayat-item__badge { background: var(--crimson-soft, #fde2e1); color: var(--crimson); }
.riwayat-item.is-ubah .riwayat-item__badge { background: var(--amber-soft, #fdf1d8); color: var(--amber, #b3790b); }
.riwayat-item.is-transfer .riwayat-item__badge { background: var(--surface-2); color: var(--ink-soft); }

.riwayat-item__body { flex: 1 1 auto; min-width: 0; }
.riwayat-item__head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.riwayat-item__tipe { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-dim); }
.riwayat-item__waktu { font-size: 11px; color: var(--ink-dim); }
.riwayat-item__judul { font-size: 13.5px; font-weight: 600; color: var(--ink); margin-top: 2px; word-break: break-word; }
.riwayat-item__detail { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; word-break: break-word; }
.riwayat-item__nominal {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------
   Modal — kalkulator tambah/kurang nominal bertahap
   --------------------------------------------------------------------- */
.amount-calc__subtitle { margin: 0 0 14px; font-size: 12.5px; color: var(--ink-soft); }
.amount-calc__total {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  padding: 14px 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
  margin-bottom: 12px;
}
.amount-calc__steps { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-height: 160px; overflow-y: auto; }
.amount-calc__step {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--emerald-soft);
  color: var(--emerald);
}
.amount-calc__step-main { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.amount-calc__step-rek { font-family: var(--font-sans, inherit); font-size: 11.5px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amount-calc__step.is-minus { background: var(--crimson-soft); color: var(--crimson); }
.amount-calc__step .btn--icon { padding: 2px 6px; font-size: 11px; flex: 0 0 auto; }
.amount-calc__entry { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.amount-calc__entry input { flex: 1 1 160px; min-width: 0; }
.amount-calc__entry .cell-select { flex: 1 1 150px; min-width: 0; }
.amount-calc__entry .btn { flex: 0 0 auto; white-space: nowrap; }

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.status-pill--lunas { background: var(--emerald-soft); color: var(--emerald); }
.status-pill--belum { background: var(--crimson-soft); color: var(--crimson); }

.row-negative { color: var(--crimson); }

/* Inline progress bar under name cell for pengeluaran rows */
.progress-track {
  position: absolute;
  left: 6px; right: 6px; bottom: 1px;
  height: 2px;
  background: var(--line-soft);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--teal); border-radius: 2px; transition: width .2s ease; }
.progress-fill.is-over { background: var(--emerald); }

/* Chart cards */
.chart-box { position: relative; min-height: 210px; }
.empty-note { font-size: 12px; color: var(--ink-dim); text-align: center; padding: 36px 0; }

/* Empty state (no month yet) */
.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 56px 20px;
  font-size: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  margin-top: 12px;
  background: var(--surface);
}

.page-foot { text-align: center; color: var(--ink-dim); font-size: 11.5px; padding-top: 24px; }
.page-foot kbd {
  font-family: var(--font-mono);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10.5px;
}

/* ---------------------------------------------------------------------
   Modal
   --------------------------------------------------------------------- */
.modal {
  /* !important + longhand top/right/bottom/left (bukan cuma shorthand
     "inset") sengaja dipasang supaya posisi overlay-penuh-layar ini
     TIDAK BISA ketiban aturan lain / mesin render lama yang kurang
     mendukung "inset", dan tidak pernah jatuh balik jadi kotak biasa
     yang ikut mengalir ke bawah halaman. */
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  inset: 0;
  background: rgba(11,18,31,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 20px;
}
.modal:not([hidden]) { display: flex; }

.modal__panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 380px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-pop);
  animation: modalPop 160ms ease;
}
@keyframes modalPop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

.modal__panel h3 { font-family: var(--font-display); font-size: 17px; margin: 0 0 16px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-size: 12.5px; color: var(--ink-soft); }

.field select, .field input[type="number"], .field input[type="text"], .field input[type="password"] {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface-2);
  color: var(--ink);
}
.field select:focus, .field input:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

.field--checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field--checkbox input { width: 15px; height: 15px; }

.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------------------------------------------------------------------
   Layar kunci (Login: username + password + captcha)
   --------------------------------------------------------------------- */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.lock-screen__panel {
  width: 100%;
  max-width: 320px;
  text-align: center;
  color: var(--ink);
}
.lock-screen__mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: 12px;
  background: var(--teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
}
.lock-screen__panel h2 { font-family: var(--font-display); font-size: 19px; margin: 0 0 6px; color: var(--ink); }
.lock-screen__panel p { margin: 0 0 18px; font-size: 13px; color: var(--ink-dim); }
.lock-screen form .field { text-align: left; }
/* Kotak captcha: gambar SVG dari server (lihat generate_captcha_svg() di
   api.php) ditaruh di sini lewat innerHTML, plus tombol ganti kode. */
.lock-screen__captcha { display: flex; align-items: stretch; gap: 8px; margin-bottom: 14px; }
.lock-screen__captcha-img {
  flex: 1 1 auto;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-screen__captcha-img svg { display: block; width: 100%; height: 56px; }
.lock-screen__captcha-refresh {
  flex: 0 0 auto;
  width: 44px;
  font-size: 17px;
  justify-content: center;
  padding: 0;
}
.lock-screen #formUnlock .btn--primary { width: 100%; justify-content: center; padding: 12px; font-size: 14px; margin-top: 4px; }
.lock-screen__error {
  color: var(--crimson);
  background: var(--crimson-soft);
  border: 1px solid var(--crimson);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 0;
  text-align: center;
}

/* ---------------------------------------------------------------------
   Modal Pengaturan (Login & link lihat-saja)
   --------------------------------------------------------------------- */
.settings-block { padding: 14px 0; border-top: 1px solid var(--line-soft); }
.settings-block:first-of-type { border-top: none; padding-top: 0; }
.settings-block h4 { margin: 0 0 4px; font-family: var(--font-display); font-size: 13.5px; }
.settings-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.settings-row .btn { flex: 1 1 auto; justify-content: center; white-space: nowrap; }
.share-link-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 12px;
  margin-bottom: 4px;
}

/* ---------------------------------------------------------------------
   Kalkulator split / patungan
   --------------------------------------------------------------------- */
.modal__panel--wide { max-width: 460px; }

.split-people { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 6px; }
.split-person { display: flex; align-items: center; gap: 6px; }
.split-person__name { flex: 1 1 auto; min-width: 0; }
.split-person__amount { flex: 0 0 96px; text-align: right; font-family: var(--font-mono); }
.split-person input.cell-input {
  border-color: var(--line);
  background: var(--surface-2);
  padding: 8px 9px;
}

.chip-group#splitMode { margin: 4px 0 4px; }

.split-result {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.split-result__row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.split-result__amount { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }
.split-result__diff { border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 2px; color: var(--ink-soft); font-size: 12px; }
.split-result__diff.is-off .split-result__amount { color: var(--crimson); }

/* ---------------------------------------------------------------------
   Proyeksi Sisa Uang
   --------------------------------------------------------------------- */
.projection-list { display: flex; flex-direction: column; gap: 2px; }
.projection-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line-soft);
}
.projection-row:last-of-type { border-bottom: none; }
.projection-row__label { font-size: 12.5px; color: var(--ink-soft); }
.projection-row__value { font-family: var(--font-mono); font-weight: 700; font-size: 14px; white-space: nowrap; }
.projection-row__value.is-negative { color: var(--crimson); }
.projection-row--now .projection-row__label { color: var(--ink); font-weight: 600; }
.projection-row--now .projection-row__value { color: var(--teal-ink); font-size: 15.5px; }
.projection-note { margin: 8px 2px 0; font-size: 11.5px; color: var(--ink-dim); line-height: 1.4; }

/* ---------------------------------------------------------------------
   Tombol "rutin" (transaksi berulang otomatis)
   --------------------------------------------------------------------- */
.btn--rutin { opacity: .38; filter: grayscale(1); }
.btn--rutin:hover { opacity: .8; filter: none; background: var(--teal-soft); }
.btn--rutin.is-active { opacity: 1; filter: none; }
.btn--rutin.is-active:hover { background: var(--teal-soft); }

/* ---------------------------------------------------------------------
   Mode lihat-saja (read-only / link share)
   --------------------------------------------------------------------- */
.is-readonly .btn--add,
.is-readonly .drag-handle,
.is-readonly .month-tab__del,
.is-readonly .btn--icon:not(.btn--rutin) { display: none !important; }
.is-readonly .btn--rutin { pointer-events: none; }
.is-readonly .col-drag { width: 0; padding: 0 !important; }
.is-readonly .cell-input:disabled,
.is-readonly .cell-select:disabled {
  color: var(--ink);
  opacity: 1;
  cursor: default;
  -webkit-text-fill-color: var(--ink);
}
.readonly-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--amber-soft);
  color: var(--amber);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 700;
}
.is-readonly .readonly-badge { display: inline-flex; }
.readonly-badge { display: none; }

/* ---------------------------------------------------------------------
   Toast
   --------------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 12px 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 60;
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast--error { background: var(--crimson); color: #fff; }
.toast--success { background: var(--emerald); color: #fff; }
.toast__undo {
  border: 1px solid rgba(255,255,255,0.4);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.toast__undo:hover { background: rgba(255,255,255,0.15); }

/* ---------------------------------------------------------------------
   Responsive
   ---------------------------------------------------------------------
   Prinsip: di layar sempit, semua elemen yang bisa diketik WAJIB
   font-size >= 16px (iOS Safari otomatis zoom-in saat fokus ke input
   dengan font < 16px — ini penyebab utama "harus zoom" di HP). Padding
   dikompensasi supaya kontrol tetap terlihat ringkas, bukan besar.
   --------------------------------------------------------------------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

  .page { padding: 0 10px 32px; }
  .masthead { padding: 16px 0 14px; }
  .masthead__top { gap: 10px; padding-bottom: 12px; }
  .masthead__mark { width: 32px; height: 32px; font-size: 14px; border-radius: 8px; }
  .masthead__title { gap: 9px; flex-wrap: wrap; }
  .masthead__title h1 { font-size: 17px; }
  .masthead__title p { font-size: 11px; }
  .masthead__actions { flex-wrap: wrap; justify-content: flex-end; gap: 6px; row-gap: 8px; }
  .masthead__actions .btn--ghost,
  .masthead__actions .btn--primary { padding: 8px 11px; font-size: 12px; }
  .btn--icon-only { width: 38px; height: 38px; } /* target sentuh min. ~38-40px */

  .month-row { gap: 6px; }
  .month-jump { display: none; }
  .month-tab { padding: 8px 12px; font-size: 12.5px; }

  .kpi-strip { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
  .kpi { padding: 10px 12px; gap: 5px; }
  .kpi__value { font-size: 15.5px; }
  .kpi__label { font-size: 10.5px; }

  .layout { gap: 12px; }
  .layout__main, .layout__side { gap: 12px; }
  .pair { grid-template-columns: 1fr; gap: 12px; }

  .card { padding: 12px 12px 14px; border-radius: 10px; }
  .card__head { flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 8px; }
  .card__head h2 { font-size: 14px; }
  .card__tools { gap: 6px; }
  .search { width: 100%; min-width: 0; font-size: 16px; padding: 8px 10px; } /* 16px = anti auto-zoom */

  .table-wrap { max-height: 200px; margin: 0 -12px; width: calc(100% + 24px); }
  .table-wrap--tall { max-height: 260px; }
  .ledger-table { font-size: 12.5px; }
  .ledger-table thead th:first-child, .ledger-table td:first-child { padding-left: 12px; }
  .ledger-table thead th:last-child, .ledger-table td:last-child { padding-right: 12px; }
  .ledger-table thead th { padding: 7px 6px; font-size: 10.5px; }
  .ledger-table td { padding: 8px 6px; }

  /* Input sel tabel: font 16px saat FOKUS saja (anti-zoom), tapi tampil
     ringkas (13px) saat tidak diketik — trik scale supaya tetap rapi. */
  .cell-input, .cell-select { font-size: 13px; }
  .cell-input:focus, .cell-select:focus { font-size: 16px; }

  .btn--icon { padding: 6px 7px; font-size: 15px; } /* target sentuh lebih besar utk hapus/terima/rutin */
  .col-action { width: 34px; }
  .col-rekening { min-width: 92px; }
  .col-admin { min-width: 84px; }
  .riwayat-list { max-height: 60vh; }
  .riwayat-toolbar { flex-direction: column; align-items: stretch; }
  .riwayat-toolbar .btn--ghost { width: 100%; }

  .modal { padding: 12px; align-items: flex-end; }
  .modal__panel, .modal__panel--wide { max-width: 100%; max-height: 85vh; padding: 18px 16px 16px; border-radius: 14px 14px 0 0; animation: modalSlideUp 180ms ease; }
  @keyframes modalSlideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
  .field select, .field input[type="number"], .field input[type="text"], .field input[type="password"],
  .share-link-input, #splitTotal, .split-person__name, .split-person__amount,
  #amountCalcInput, #transferAmount, #transferFeeAmount {
    font-size: 16px; /* anti auto-zoom iOS di semua form modal */
  }
  .amount-calc__entry { flex-wrap: wrap; }
  .amount-calc__entry input { flex-basis: 100%; }
  .amount-calc__entry .cell-select { flex-basis: 100%; }
  .amount-calc__entry .btn { flex: 1 1 45%; justify-content: center; }
  .modal__actions { flex-wrap: wrap; }
  .modal__actions .btn { flex: 1 1 auto; justify-content: center; }
  .settings-row .btn { flex: 1 1 45%; }

  .split-person__amount { flex-basis: 84px; }

  .projection-row__value { font-size: 13px; }
  .projection-row--now .projection-row__value { font-size: 14.5px; }

  .toast { left: 10px; right: 10px; bottom: 14px; transform: none; max-width: none; }

  .page-foot { font-size: 10.5px; padding-top: 16px; }
}

@media (max-width: 380px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .masthead__title p { display: none; } /* hemat ruang di layar sangat sempit (<380px) */
  .col-rekening { min-width: 76px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Focus visibility */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
