/* Layout: mobile-first PWA — fixed header, scrollable main, fixed bottom nav */
:root {
  --bg:       #F8FAFC;
  --surface:  #FFFFFF;
  --bg-nav:   rgba(255,255,255,0.93);
  --border:   #E2E8F0;
  --fg:       #0F172A;
  --muted:    #64748B;
  --subtle:   #94A3B8;
  --accent:   #0D9488;
  --accent-t: #F0FDFA;
  --danger:   #E11D48;
  --danger-t: #FFF1F2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:       #0F172A;
    --surface:  #1E293B;
    --bg-nav:   rgba(15,23,42,0.93);
    --border:   #334155;
    --fg:       #F1F5F9;
    --muted:    #94A3B8;
    --subtle:   #64748B;
    --accent:   #14B8A6;
    --accent-t: #0C2626;
    --danger:   #FB7185;
    --danger-t: #2D0A14;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:       #0F172A;
  --surface:  #1E293B;
  --bg-nav:   rgba(15,23,42,0.93);
  --border:   #334155;
  --fg:       #F1F5F9;
  --muted:    #94A3B8;
  --subtle:   #64748B;
  --accent:   #14B8A6;
  --accent-t: #0C2626;
  --danger:   #FB7185;
  --danger-t: #2D0A14;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Safe-area top band (iOS notch) */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  background: var(--surface);
  z-index: 200;
}

/* ── App shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── Header ── */
#header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-left, 0px));
  height: 56px;
  flex-shrink: 0;
}

.logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -.5px;
}
.logo em { color: var(--accent); font-style: normal; }
.logo-sub { display: block; font-size: 10px; font-weight: 500; letter-spacing: .3px; color: var(--muted); line-height: 1; margin-top: 1px; }

.header-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 36px; height: 36px;
  border: none; background: transparent;
  color: var(--muted); border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--border); color: var(--fg); }

/* ── Main content area ── */
#main {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px
           max(16px, env(safe-area-inset-right, 0px))
           calc(80px + env(safe-area-inset-bottom, 0px))
           max(16px, env(safe-area-inset-left, 0px));
}

.view { display: none; }
.view.active { display: block; }

/* ── Shared components ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.section-label {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 20px 0 8px;
}

/* Month navigator */
.month-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; margin-bottom: 16px;
}
.month-nav-btn {
  width: 32px; height: 32px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); border-radius: 9px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.month-nav-btn:hover { background: var(--border); }
.month-label {
  font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 16px;
}

/* ── Donut chart ── */
.donut-wrap {
  padding: 24px 16px 20px;
  display: flex; flex-direction: column; align-items: center;
}
.cat-legend {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px 12px; width: 100%; margin-top: 16px;
}
.leg-item { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.leg-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.leg-name {
  flex: 1; color: var(--muted); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.leg-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Transaction items ── */
.day-group { margin-bottom: 4px; }
.day-header {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--muted); font-weight: 500;
  padding: 10px 2px 6px; text-transform: capitalize;
}
.day-total { font-variant-numeric: tabular-nums; font-weight: 600; }

.tx {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); cursor: pointer;
  transition: background .1s; border-bottom: 1px solid var(--border);
}
.tx:last-child { border-bottom: none; }
.tx:hover { background: var(--bg); }

.tx-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.tx-info { flex: 1; min-width: 0; }
.tx-desc {
  font-size: 15px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tx-cat { font-size: 13px; color: var(--muted); margin-top: 1px; }
.tx-amt {
  font-family: 'Space Grotesk', sans-serif; font-weight: 600;
  font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ── Empty states ── */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-icon { font-size: 44px; margin-bottom: 14px; opacity: .5; }
.empty h3 { font-size: 16px; font-weight: 600; color: var(--fg); margin-bottom: 6px; }
.empty p { font-size: 14px; line-height: 1.6; }

/* ── Statistics bar charts ── */
.bar-chart-inner { padding: 18px 16px; }
.bar-row {
  display: grid; grid-template-columns: 110px 1fr 72px;
  align-items: center; gap: 10px; margin-bottom: 10px;
}
.bar-row:last-child { margin-bottom: 0; }
.bar-label {
  font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 5px;
  overflow: hidden; white-space: nowrap;
}
.bar-track { height: 7px; background: var(--border); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; transition: width .5s cubic-bezier(.34,1.56,.64,1); }
.bar-val {
  font-size: 13px; font-weight: 600;
  font-variant-numeric: tabular-nums; text-align: right; color: var(--fg);
}

/* ── Floating action button ── */
#fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: calc(68px + env(safe-area-inset-bottom, 0px) + 14px);
  width: 54px; height: 54px; border-radius: 17px;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px color-mix(in srgb, var(--accent) 50%, transparent);
  z-index: 90; transition: transform .15s;
}
#fab:hover { transform: scale(1.06); }
#fab:active { transform: scale(.95); }

/* ── Bottom navigation ── */
#bnav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(60px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-nav);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: flex-start; padding-top: 6px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  z-index: 100;
}
.nb {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: none; background: transparent; color: var(--subtle);
  cursor: pointer; padding: 4px 0; font-size: 10px; font-weight: 500;
  letter-spacing: .02em; transition: color .15s; font-family: inherit;
}
.nb.active { color: var(--accent); }
.nb svg { transition: transform .15s; }
.nb.active svg { transform: scale(1.12); }

/* ── Modal bottom sheet ── */
#moverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  z-index: 300; display: flex; align-items: flex-end;
}
#msheet {
  background: var(--surface); border-radius: 24px 24px 0 0; width: 100%;
  max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0
           max(20px, env(safe-area-inset-left, 0px))
           calc(24px + env(safe-area-inset-bottom, 0px));
}
.mhandle {
  width: 36px; height: 4px; background: var(--border);
  border-radius: 99px; margin: 12px auto 20px;
}
.mtitle {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700;
  font-size: 20px; margin-bottom: 22px;
}

/* Amount input */
.amt-wrap {
  display: flex; align-items: center; gap: 4px;
  border: 2px solid var(--accent); border-radius: 16px;
  padding: 12px 16px; margin-bottom: 20px; background: var(--accent-t);
}
.amt-sign {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700;
  font-size: 30px; color: var(--accent); line-height: 1;
}
#amt-in {
  flex: 1; border: none; background: transparent;
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 30px;
  color: var(--fg); outline: none; font-variant-numeric: tabular-nums; min-width: 0;
}
#amt-in::placeholder { color: var(--subtle); }

/* Category grid */
.field-lbl {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); margin-bottom: 9px;
}
.cat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; margin-bottom: 20px;
}
.cat-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border: 2px solid var(--border); background: var(--bg);
  border-radius: 14px; cursor: pointer; font-size: 11px; color: var(--muted);
  font-weight: 500; font-family: inherit;
  transition: border-color .15s, background .15s, color .15s;
}
.cat-btn .emo { font-size: 22px; }
.cat-btn.sel { border-color: var(--accent); background: var(--accent-t); color: var(--accent); }

/* Form fields */
.field { margin-bottom: 14px; }
.form-in {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--fg);
  font-family: 'Inter', sans-serif; font-size: 15px; outline: none;
  transition: border-color .15s;
}
.form-in:focus { border-color: var(--accent); }

/* Buttons */
.btn-primary {
  width: 100%; padding: 15px; background: var(--accent); color: #fff;
  border: none; border-radius: 16px;
  font-family: 'Inter', sans-serif; font-size: 16px; font-weight: 600;
  cursor: pointer; margin-top: 6px; transition: opacity .15s, transform .1s;
}
.btn-primary:hover { opacity: .9; }
.btn-primary:active { transform: scale(.98); }

.btn-danger {
  width: 100%; padding: 13px; background: var(--danger-t); color: var(--danger);
  border: none; border-radius: 14px; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 10px; font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  transition: opacity .15s;
}
.btn-danger:hover { opacity: .8; }

.btn-ghost {
  width: 100%; padding: 13px; background: var(--bg); color: var(--muted);
  border: 1.5px solid var(--border); border-radius: 14px;
  font-size: 15px; font-weight: 500; cursor: pointer;
  margin-top: 8px; font-family: inherit; transition: background .15s;
}
.btn-ghost:hover { background: var(--border); }

/* Transaction detail */
.detail-hero {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; background: var(--bg); border-radius: 16px; margin-bottom: 18px;
}
.detail-icon {
  width: 52px; height: 52px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; flex-shrink: 0;
}
.detail-amt {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700;
  font-size: 30px; font-variant-numeric: tabular-nums;
}
.detail-cat { font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.detail-row {
  font-size: 14px; padding: 11px 0;
  border-bottom: 1px solid var(--border); color: var(--muted);
}
.detail-row:last-of-type { border-bottom: none; }
.detail-row strong { color: var(--fg); }

/* Settings info row */
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.settings-row:last-of-type { border-bottom: none; }
.settings-row span:first-child { color: var(--muted); }
.settings-row span:last-child { font-weight: 600; }

/* Update status feedback */
.update-feedback {
  margin-top: 12px; padding: 12px; border-radius: 12px;
  font-size: 14px; text-align: center;
}
.update-feedback.ok { background: var(--accent-t); color: var(--accent); }
.update-feedback.err { background: var(--danger-t); color: var(--danger); }

/* ── Goals ── */
.goal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px; margin-bottom: 10px;
}
.goal-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 10px;
}
.goal-label { font-size: 14px; font-weight: 600; color: var(--fg); }
.goal-amounts { font-size: 13px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.goal-track { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.goal-fill { height: 100%; border-radius: 99px; transition: width .6s cubic-bezier(.34,1.56,.64,1); }
.goal-fill.ok   { background: #22C55E; }
.goal-fill.warn { background: #F59E0B; }
.goal-fill.over { background: var(--danger); }

/* ── Income / transfer tx amounts ── */
.tx-amt.income       { color: #22C55E; }
.tx-amt.transfer-amt { color: #6366F1; }
.detail-amt.income   { color: #22C55E; }

/* ── Type toggle (add form) ── */
.type-toggle {
  display: flex; background: var(--bg);
  border: 1.5px solid var(--border); border-radius: 12px;
  overflow: hidden; margin-bottom: 20px;
}
.type-toggle button {
  flex: 1; padding: 10px 4px; border: none; background: transparent;
  font-size: 13px; font-weight: 600; color: var(--muted);
  cursor: pointer; font-family: inherit; transition: background .15s, color .15s;
}
.type-toggle button.active { background: var(--accent); color: #fff; }
#tt-income.active  { background: #22C55E !important; }
#tt-transfer.active { background: #6366F1 !important; }

/* ── Date range filter ── */
.date-filter {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; margin-bottom: 16px; overflow: hidden;
}
.date-filter-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; cursor: pointer;
  font-size: 14px; color: var(--muted); font-weight: 500;
  transition: color .15s;
}
.date-filter-toggle.active { color: var(--accent); }
.date-filter-fields {
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 8px; padding: 0 14px 10px;
}
.date-filter-sep { color: var(--muted); font-size: 13px; text-align: center; }

/* ── Split rows ── */
.split-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.split-row .form-in { margin: 0; }

/* ── Tags ── */
.tx-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.tx-tag {
  font-size: 11px; padding: 1px 7px; border-radius: 20px;
  background: var(--accent)22; color: var(--accent); font-weight: 500;
}

/* ── Search bar ── */
.search-wrap {
  position: relative; margin-bottom: 16px;
}
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.search-in {
  width: 100%; box-sizing: border-box;
  padding: 10px 14px 10px 36px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; font-size: 14px; color: var(--fg);
  outline: none; transition: border-color .15s;
  -webkit-appearance: none;
}
.search-in::placeholder { color: var(--muted); }
.search-in:focus { border-color: var(--accent); }
/* hide the native ✕ in Chrome/Safari */
.search-in::-webkit-search-cancel-button { display: none; }

/* ── Settings section links ── */
.settings-link {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  margin-bottom: 10px; cursor: pointer; color: var(--fg);
  transition: background .15s;
}
.settings-link:hover { background: var(--bg); }
.settings-link svg   { color: var(--subtle); flex-shrink: 0; }

/* ── Settings sub-page items ── */
.settings-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px;
}
.settings-item-label { font-size: 14px; font-weight: 500; }
.settings-item-sub   { font-size: 13px; color: var(--muted); margin-top: 2px; }

.icon-btn-sm {
  width: 32px; height: 32px; border: 1.5px solid var(--border);
  background: var(--bg); color: var(--muted); border-radius: 9px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 15px; flex-shrink: 0; transition: background .15s;
}
.icon-btn-sm:hover { background: var(--border); }

/* ── Category color picker ── */
.color-grid {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px;
}
.color-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid transparent; cursor: pointer;
  transition: transform .15s;
}
.color-swatch.sel { border-color: var(--fg); transform: scale(1.15); }

/* select reuses .form-in styles */
select.form-in { cursor: pointer; }

/* ── Bank view ─────────────────────────────────────────────────────────── */
.bank-login {
  display: flex; flex-direction: column; align-items: center;
  padding: 48px 24px 24px; gap: 12px;
}
.bank-login-icon { margin-bottom: 8px; }
.bank-login-title { font-family: 'Space Grotesk', sans-serif; font-size: 1.3rem; font-weight: 600; }
.bank-login-sub { color: var(--muted); font-size: .875rem; margin-bottom: 4px; }
.bank-login-btn { width: 100%; margin-top: 4px; }
.bank-login-err { color: var(--danger); font-size: .85rem; }
.bank-login .form-in { width: 100%; }
.pw-wrap { position: relative; width: 100%; }
.pw-wrap .form-in { width: 100%; padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--muted); padding: 4px;
  display: flex; align-items: center;
}
.pw-toggle:hover { color: var(--fg); }

.bank-header { padding: 12px 14px 0; }
.bank-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bank-action-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; justify-content: center; font-size: .85rem; padding: 8px 12px; }
.bank-logout-btn {
  display: flex; align-items: center; padding: 8px; color: var(--muted);
  background: none; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.bank-logout-btn:hover { color: var(--danger); border-color: var(--danger); }
.bank-status { font-size: .8rem; color: var(--muted); padding: 6px 2px 0; min-height: 20px; }
.bank-status-err { color: var(--danger); }

.bank-filter { padding: 10px 14px 2px; }
.bank-filter .search-in { width: 100%; }

.bank-tx-row { cursor: pointer; }
.bank-tx-row:hover { background: var(--accent-t); }
.bank-cat-label {
  font-size: .78rem; color: var(--accent); cursor: pointer; margin-top: 2px;
  display: block;
}
.bank-cat-label em { color: var(--subtle); font-style: normal; }
.bank-amt-credit { color: #16a34a; }
.bank-amt-debit  { color: var(--fg); }
.bank-empty { padding: 32px 14px; color: var(--muted); text-align: center; font-size: .9rem; }

.bank-cat-grid { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 8px; }
.bank-cat-chip {
  padding: 6px 12px; border-radius: 20px; font-size: .82rem;
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 12%, transparent);
  color: var(--chip-color, var(--accent));
  border: 1px solid color-mix(in srgb, var(--chip-color, var(--accent)) 40%, transparent);
  cursor: pointer;
}
.bank-cat-chip:hover, .bank-cat-chip.selected {
  background: var(--chip-color, var(--accent)); color: #fff;
}
.bank-cat-custom { display: flex; gap: 8px; margin: 4px 0 8px; }
.bank-cat-custom .form-in { flex: 1; }
.bank-cat-custom .btn-primary { white-space: nowrap; padding: 0 14px; }

.bank-cat-filter {
  display: flex; gap: 6px; overflow-x: auto; padding: 6px 14px 2px;
  scrollbar-width: none;
}
.bank-cat-filter::-webkit-scrollbar { display: none; }
.bank-filter-chip {
  flex-shrink: 0; padding: 4px 10px; border-radius: 20px; font-size: .78rem;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); cursor: pointer; white-space: nowrap;
}
.bank-filter-chip.active {
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 12%, transparent);
  color: var(--chip-color, var(--accent));
  border-color: color-mix(in srgb, var(--chip-color, var(--accent)) 40%, transparent);
}

.bank-cat-badge {
  display: inline-block; font-size: .75rem; font-weight: 500;
  color: var(--chip-color, var(--accent));
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 10%, transparent);
  border-radius: 10px; padding: 1px 7px; margin-top: 3px; cursor: pointer;
}
.bank-cat-empty { color: var(--subtle); font-size: .78rem; cursor: pointer; display: block; margin-top: 2px; }
.bank-cat-empty em { font-style: normal; }

.bank-more-btn { width: calc(100% - 28px); margin: 8px 14px; }
