/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #2E5395;
  --primary-light: #D9E2F3;
  --success:       #2E7D32;
  --success-light: #E2F0D9;
  --danger:        #C00000;
  --danger-light:  #FCE4E4;
  --warning:       #BF8F00;
  --warning-light: #FFF2CC;
  --bg:            #F5F6FA;
  --surface:       #FFFFFF;
  --surface2:      #F0F2F8;
  --text:          #1A1A2E;
  --text-sec:      #6B7280;
  --text-muted:    #9CA3AF;
  --border:        #E5E7EB;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── App Shell ────────────────────────────────────────────────────── */
#app {
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 70px;
  -webkit-overflow-scrolling: touch;
}

/* ── Bottom Navigation ────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: 62px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  border: none;
  background: none;
  padding: 8px 0;
}

.nav-btn .nav-ico { font-size: 22px; }
.nav-btn .nav-lbl { font-size: 10px; font-weight: 500; }
.nav-btn.active .nav-ico,
.nav-btn.active .nav-lbl { color: var(--primary); }
.nav-btn:not(.active) .nav-ico,
.nav-btn:not(.active) .nav-lbl { color: var(--text-muted); }

/* ── Pages ────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── Demo Banner ──────────────────────────────────────────────────── */
.demo-banner {
  background: var(--warning-light);
  border-bottom: 1px solid #F5D262;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.demo-banner.hidden { display: none; }
.demo-txt { font-size: 11px; color: var(--warning); font-weight: 600; }
.demo-limit { font-size: 10px; color: var(--warning); }
.upgrade-link { font-size: 11px; color: var(--primary); font-weight: 600; cursor: pointer; white-space: nowrap; }

/* ── Header ───────────────────────────────────────────────────────── */
.hdr {
  padding: 14px 16px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hdr-title { font-size: 20px; font-weight: 700; color: var(--text); }
.pro-tag {
  font-size: 10px; font-weight: 600;
  background: var(--warning-light); color: var(--warning);
  border-radius: 10px; padding: 2px 7px; margin-left: 6px;
}
.add-btn {
  background: var(--primary); color: #fff;
  border: none; border-radius: 20px;
  padding: 8px 16px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
}
.add-btn:active { opacity: .8; }
.add-btn:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }

/* ── Month Nav ────────────────────────────────────────────────────── */
.month-nav {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 2px 16px 12px;
}
.mn-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 50%; width: 30px; height: 30px;
  cursor: pointer; font-size: 16px; color: var(--text-sec);
  display: flex; align-items: center; justify-content: center;
}
.mn-label {
  font-size: 15px; font-weight: 600; color: var(--text);
  min-width: 140px; text-align: center;
}

/* ── Balance Card ─────────────────────────────────────────────────── */
.bal-card {
  background: var(--primary); border-radius: 20px;
  margin: 0 16px 12px; padding: 18px;
  box-shadow: 0 4px 20px rgba(46,83,149,.3);
}
.bal-lbl { font-size: 12px; color: rgba(255,255,255,.75); text-align: center; margin-bottom: 4px; }
.bal-val { font-size: 30px; font-weight: 700; text-align: center; margin-bottom: 14px; }
.bal-divider { height: 1px; background: rgba(255,255,255,.2); margin-bottom: 14px; }
.bal-row { display: flex; justify-content: space-around; }
.bal-col { text-align: center; }
.bal-sub-lbl { font-size: 11px; color: rgba(255,255,255,.75); margin-bottom: 3px; }
.bal-sub-val { font-size: 15px; font-weight: 600; }
.inc-c { color: #6EE7B7; }
.exp-c { color: #FCA5A5; }

/* ── Section Title ────────────────────────────────────────────────── */
.sec-title {
  font-size: 12px; font-weight: 600; color: var(--text-sec);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 16px 8px;
}

/* ── Transaction List ─────────────────────────────────────────────── */
.tx-list { padding: 0 12px; }
.tx {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: 12px;
  padding: 11px 12px; margin-bottom: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06); cursor: pointer;
  transition: transform .1s;
}
.tx:active { transform: scale(.98); }
.tx-ico {
  width: 40px; height: 40px; border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 14px; font-weight: 700;
}
.tx-info { flex: 1; min-width: 0; }
.tx-cat { font-size: 13px; font-weight: 600; color: var(--text); }
.tx-note { font-size: 11px; color: var(--text-sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-date { font-size: 10px; color: var(--text-muted); margin-top: 1px; }
.tx-amt { font-size: 14px; font-weight: 700; white-space: nowrap; }
.tx-pos { color: var(--success); }
.tx-neg { color: var(--danger); }
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 14px; line-height: 1.7; }

/* ── Add Form ─────────────────────────────────────────────────────── */
.form-wrap { padding: 16px; }
.form-title { font-size: 20px; font-weight: 700; color: var(--text); text-align: center; margin-bottom: 18px; }
.type-row { display: flex; gap: 8px; margin-bottom: 16px; }
.type-btn {
  flex: 1; padding: 11px; border-radius: 12px;
  border: 1.5px solid var(--border); background: var(--surface2);
  font-size: 14px; font-weight: 600; color: var(--text-sec); cursor: pointer; text-align: center;
}
.type-btn.act-exp { background: var(--danger-light); color: var(--danger); border-color: #F5A5A5; }
.type-btn.act-inc { background: var(--success-light); color: var(--success); border-color: #A5D6A7; }
.f-label { font-size: 12px; font-weight: 600; color: var(--text-sec); margin-bottom: 6px; }
.f-input {
  width: 100%; padding: 11px 13px;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 15px; margin-bottom: 14px; outline: none;
}
.f-input:focus { border-color: var(--primary); }
.cat-grid { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.cat-chip {
  padding: 7px 12px; border-radius: 20px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 12px; font-weight: 500; color: var(--text); cursor: pointer;
}
.cat-chip.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.cat-chip.locked { opacity: .45; cursor: not-allowed; }
.pro-badge {
  font-size: 9px; background: var(--warning-light); color: var(--warning);
  border-radius: 4px; padding: 1px 4px; margin-left: 4px;
}
.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.cancel-btn {
  flex: 1; padding: 13px; border-radius: 13px;
  border: 1.5px solid var(--border); background: var(--surface2);
  font-size: 15px; font-weight: 600; color: var(--text-sec); cursor: pointer;
}
.save-btn {
  flex: 2; padding: 13px; border-radius: 13px;
  border: none; background: var(--primary);
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}

/* ── Stats ────────────────────────────────────────────────────────── */
.stats-wrap { padding: 0 12px 16px; }
.metric-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.metric {
  background: var(--surface); border-radius: 14px;
  padding: 14px; text-align: center; border: 1px solid var(--border);
}
.metric-lbl { font-size: 11px; color: var(--text-sec); margin-bottom: 5px; }
.metric-val { font-size: 16px; font-weight: 700; }
.bal-stat {
  background: var(--surface); border-radius: 14px;
  padding: 14px; text-align: center; margin-bottom: 16px;
  border: 1px solid var(--border);
}
.cat-bar {
  background: var(--surface); border-radius: 13px;
  padding: 12px; margin-bottom: 7px; border: 1px solid var(--border);
}
.cat-bar-hdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cat-bar-lbl { font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 7px; }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cat-amt { font-size: 13px; font-weight: 700; color: var(--text); text-align: right; }
.cat-pct { font-size: 11px; color: var(--text-muted); text-align: right; }
.bar-bg { height: 5px; background: var(--border); border-radius: 3px; }
.bar-fill { height: 5px; border-radius: 3px; transition: width .4s ease; }

/* Lock overlay */
.lock-wrap { position: relative; border-radius: 13px; overflow: hidden; margin-bottom: 7px; }
.lock-overlay {
  position: absolute; inset: 0;
  background: rgba(245,246,250,.88);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  backdrop-filter: blur(2px);
}
.lock-ico { font-size: 26px; color: var(--text-muted); }
.lock-txt { font-size: 12px; font-weight: 600; color: var(--text-sec); }
.lock-link { font-size: 11px; color: var(--primary); font-weight: 600; cursor: pointer; }

/* ── Activate Page ────────────────────────────────────────────────── */
.act-wrap { padding: 20px 16px 32px; }
.act-logo { text-align: center; margin-bottom: 16px; font-size: 52px; }
.act-title { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.act-sub { font-size: 13px; color: var(--text-sec); text-align: center; margin-bottom: 20px; line-height: 1.6; }
.plan-card {
  border-radius: 16px; border: 2px solid var(--primary);
  padding: 16px; margin-bottom: 16px; background: var(--surface);
}
.plan-hdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.plan-name { font-size: 15px; font-weight: 700; color: var(--text); }
.plan-price { font-size: 16px; font-weight: 700; color: var(--primary); }
.plan-feature { font-size: 13px; color: var(--text-sec); padding: 4px 0; display: flex; align-items: center; gap: 8px; }
.plan-feature::before { content: '✓'; color: var(--success); font-weight: 700; }
.act-divider { text-align: center; font-size: 12px; color: var(--text-muted); margin: 16px 0; }
.act-input {
  width: 100%; padding: 14px; border: 2px solid var(--border);
  border-radius: 13px; background: var(--surface); color: var(--text);
  font-size: 18px; text-align: center; letter-spacing: .15em;
  font-weight: 600; outline: none; margin-bottom: 10px;
}
.act-input:focus { border-color: var(--primary); }
.act-btn {
  width: 100%; padding: 15px; border-radius: 14px;
  border: none; background: var(--primary); color: #fff;
  font-size: 16px; font-weight: 700; cursor: pointer; margin-bottom: 10px;
}
.act-err { font-size: 13px; color: var(--danger); text-align: center; margin-bottom: 8px; display: none; }
.act-hint { font-size: 12px; color: var(--text-muted); text-align: center; line-height: 1.6; }
.act-hint b { color: var(--primary); }
.act-success {
  background: var(--success-light); border-radius: 14px;
  padding: 20px; text-align: center; display: none; margin-bottom: 12px;
}
.act-success-ico { font-size: 40px; display: block; margin-bottom: 8px; }
.act-success-txt { font-size: 16px; font-weight: 700; color: var(--success); }
.act-success-sub { font-size: 13px; color: var(--text-sec); margin-top: 4px; }

/* ── Install Banner ───────────────────────────────────────────────── */
.install-banner {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 398px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12); z-index: 200;
}
.install-banner.hidden { display: none; }
.install-txt { flex: 1; font-size: 13px; color: var(--text); font-weight: 500; }
.install-txt span { font-size: 11px; color: var(--text-sec); display: block; }
.install-btn {
  background: var(--primary); color: #fff;
  border: none; border-radius: 10px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.install-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; padding: 0 2px;
}
