@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg:        #f5f5f3;
  --surface:   #ffffff;
  --surface2:  #efefed;
  --border:    #e0e0dc;
  --border2:   #c8c8c4;
  --text:      #1a1a18;
  --dim:       #6b6b67;
  --muted:     #adadaa;
  --pos:       #1a1a18;
  --pos-bg:    #efefed;
  --neg:       #1a1a18;
  --neg-bg:    #efefed;
  --accent:    #1a1a18;
  --accent-bg: #e8e8e6;
  --r:         6px;
  --r-sm:      4px;
  --header-h:  52px;
  --nav-h:     58px;
}

:root.dark {
  --bg:        #141414;
  --surface:   #1e1e1e;
  --surface2:  #2a2a2a;
  --border:    #333333;
  --border2:   #444444;
  --text:      #eaeaea;
  --dim:       #9e9e9e;
  --muted:     #6b6b6b;
  --pos:       #eaeaea;
  --pos-bg:    #2a2a2a;
  --neg:       #eaeaea;
  --neg-bg:    #2a2a2a;
  --accent:    #eaeaea;
  --accent-bg: #333333;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── HEADER ── */
header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px;
  gap: 12px;
}

.logo-mark {
  width: 28px; height: 28px;
  background: var(--text);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px; font-weight: 700;
  letter-spacing: -.4px; color: var(--text);
}

.header-sub {
  font-size: 11px; color: var(--dim);
  margin-top: 1px;
}

.theme-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ── BOTTOM NAV (mobile) ── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom);
  align-items: center;
  justify-content: space-around;
}

.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; padding: 8px 4px;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-family: 'Inter', sans-serif;
  font-size: 10px; font-weight: 600; letter-spacing: .3px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn.active { color: var(--text); }

.nav-icon {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
}

/* SVG icons */
svg { display: block; }

/* ── MAIN ── */
main {
  padding-top: calc(var(--header-h) + 20px);
  padding-bottom: 32px;
  padding-left: 20px;
  padding-right: 20px;
  max-width: 980px;
  margin: 0 auto;
}

/* ── PAGES ── */
.page { display: none; }
.page.active { display: block; }

/* ── SUMMARY CARDS ── */
.summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px;
}

.card-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .9px;
  color: var(--dim); margin-bottom: 8px;
}

.card-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 20px; font-weight: 500;
  letter-spacing: -.5px; line-height: 1;
}

.card-value.green { color: #2a7a4b; }
.card-value.red   { color: #b83a3a; }

.card-sub {
  font-size: 11px; color: var(--muted);
  margin-top: 6px;
}

/* ── FILTER ── */
.filter-bar {
  display: flex; align-items: center;
  gap: 8px; flex-wrap: wrap;
  margin-bottom: 20px;
}

.pill {
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: none;
  color: var(--dim);
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: border-color .15s, color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}

.pill:hover { color: var(--text); border-color: var(--border2); }

.pill.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--surface);
}

.date-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.mobile-date-icon {
  display: none;
}

.date-pick {
  padding: 6px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--dim);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
}
.date-pick:focus { outline: 1px solid var(--border2); color: var(--text); }

.search-pick {
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  min-width: 140px;
  flex-grow: 1;
}
.search-pick:focus { outline: none; border-color: var(--border2); }
.search-pick::placeholder { color: var(--muted); }

/* ── CHART ── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 16px 12px;
  margin-bottom: 20px;
}

.chart-head {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 12px; font-weight: 700;
  color: var(--text); letter-spacing: -.1px;
}

.legend {
  display: flex; gap: 14px;
}

.legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--dim);
}

.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}

.chart-wrap { height: 100px; }
canvas { width: 100%; height: 100%; }

/* ── TX LIST ── */
.list-head {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.tx-badge {
  font-size: 11px; color: var(--muted);
  background: var(--surface2);
  padding: 3px 9px;
  border-radius: 99px;
  border: 1px solid var(--border);
}

.tx-list { display: flex; flex-direction: column; gap: 6px; }

.group-date {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .9px;
  color: var(--muted);
  padding: 10px 2px 4px;
}

.tx-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
  cursor: default;
  transition: border-color .12s;
}

.tx-item:hover { border-color: var(--border2); }

.tx-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tx-dot.income { background: #2a7a4b; }
.tx-dot.expense { background: #b83a3a; }

.tx-info { flex: 1; min-width: 0; }

.tx-desc {
  font-size: 13px; font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.tx-cat {
  font-size: 11px; color: var(--muted);
  margin-top: 2px;
}

.tx-amount {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px; font-weight: 500;
  flex-shrink: 0;
}

.tx-amount.income { color: #2a7a4b; }
.tx-amount.expense { color: #b83a3a; }

.tx-del {
  width: 26px; height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .12s, background .12s;
}

.tx-item:hover .tx-del { opacity: 1; }

.tx-del:hover {
  background: var(--surface2);
  border-color: var(--border2);
  color: var(--text);
}

/* mobile: always show delete */
@media (hover: none) {
  .tx-del { opacity: 1; }
}

.empty {
  text-align: center;
  padding: 44px 20px;
}

.empty-title { font-size: 13px; font-weight: 600; color: var(--dim); margin-bottom: 4px; }
.empty-sub { font-size: 12px; color: var(--muted); }

/* ── FORM (Tambah page) ── */
.form-wrap {
  max-width: 480px;
}

.type-toggle {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-bottom: 20px;
}

.type-btn {
  padding: 11px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: none;
  color: var(--dim);
  font-family: 'Inter', sans-serif;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}

.type-btn.income.active { background: var(--surface2); border-color: var(--border2); color: var(--text); }
.type-btn.expense.active { background: var(--surface2); border-color: var(--border2); color: var(--text); }
.type-btn:not(.active):hover { border-color: var(--border2); color: var(--text); }

.field { margin-bottom: 14px; }

.field-label {
  display: block;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--dim); margin-bottom: 6px;
}

.field-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  transition: border-color .15s;
  -webkit-appearance: none;
}

.field-input:focus { outline: none; border-color: var(--border2); }
.field-input::placeholder { color: var(--muted); }

input[type="number"].field-input { font-family: 'JetBrains Mono', monospace; }

select.field-input { cursor: pointer; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.submit-btn {
  width: 100%; padding: 12px;
  margin-top: 4px;
  border-radius: var(--r-sm);
  border: none;
  background: var(--text);
  color: var(--surface);
  font-family: 'Inter', sans-serif;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
}

.submit-btn:hover { opacity: .88; }
.submit-btn:active { opacity: .75; }

/* ── EXPORT PAGE ── */
.export-section { margin-bottom: 24px; }

.export-section-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin-bottom: 10px;
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.exp-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--dim);
  font-family: 'Inter', sans-serif;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

.exp-btn:hover { border-color: var(--border2); color: var(--text); background: var(--surface2); }

.exp-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h, 0px) + 16px);
  left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 99px;
  padding: 9px 18px;
  font-size: 13px; font-weight: 600;
  color: var(--text);
  opacity: 0; pointer-events: none;
  transition: all .25s ease;
  z-index: 500;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok  { border-color: var(--border2); color: var(--text); }
.toast.err { border-color: var(--border2); color: var(--dim); }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  main {
    padding-top: calc(var(--header-h) + 16px);
    padding-bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
    padding-left: 14px;
    padding-right: 14px;
  }

  .bottom-nav { display: flex; }

  .summary-row {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  /* balance card full-width on mobile */
  .card-balance { grid-column: span 2; }

  .card-value { font-size: 17px; }

  .filter-bar { gap: 6px; }
  .pill { padding: 5px 11px; font-size: 11px; }
  
  .date-wrapper {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    display: flex; align-items: center; justify-content: center;
    color: var(--dim);
    flex-shrink: 0;
  }
  .mobile-date-icon {
    display: block;
    pointer-events: none;
  }
  .date-pick {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
    padding: 0;
  }
  .search-pick {
    width: 100%;
    flex-basis: 100%;
    margin-top: 2px;
  }

  .field-row { grid-template-columns: 1fr; gap: 0; }

  .export-grid { grid-template-columns: 1fr; }

  .toast { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); }
}

@media (min-width: 601px) {
  .desktop-sidebar {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    align-items: start;
  }
}

/* hide desktop sidebar pane on mobile */
@media (max-width: 600px) {
  .desktop-only { display: none !important; }
}

/* scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── VAULT UI ── */
#vault-screen {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.vault-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 32px 24px;
  width: 100%; max-width: 340px; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}
.vault-logo {
  width: 48px; height: 48px; margin: 0 auto 16px;
  background: var(--text); color: var(--surface);
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
}
.vault-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.vault-desc { font-size: 13px; color: var(--dim); margin-bottom: 24px; }
.vault-input {
  width: 100%; padding: 12px 16px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 15px; margin-bottom: 16px; text-align: center;
}
.vault-input:focus { outline: none; border-color: var(--text); }
.vault-btn {
  width: 100%; padding: 12px; border-radius: var(--r-sm);
  border: none; background: var(--text); color: var(--surface);
  font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: opacity .15s;
}
.vault-btn:hover { opacity: .88; }
.vault-btn:active { opacity: .75; }