:root {
  --nf-primary: #005a6e;
  --nf-secondary: #2E8EAD;
  --nf-accent: #007c93;
  --nf-white: #ffffff;

  --bg: #f5f9fa;
  --surface: #ffffff;
  --text: #17262a;
  --text-muted: #6b7d81;
  --border: #e3edef;

  --success: #2e9e5b;
  --success-bg: #e7f6ee;
  --warning: #e0a015;
  --warning-bg: #fdf3df;
  --danger: #d5473f;
  --danger-bg: #fbeae9;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow: 0 2px 10px rgba(0, 60, 72, 0.07);
  --shadow-lift: 0 8px 24px rgba(0, 60, 72, 0.14);

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  padding-bottom: 88px;
}

/* ===== Top bar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 0) 16px 0;
  background: var(--nf-primary);
  color: var(--nf-white);
  height: calc(56px + env(safe-area-inset-top, 0px));
}

.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-mark {
  background: var(--nf-white);
  color: var(--nf-primary);
  font-size: 13px;
  font-weight: 800;
  border-radius: 8px;
  padding: 4px 6px;
  letter-spacing: 0.5px;
}
.brand-name { font-size: 16px; }

.icon-btn {
  background: rgba(255,255,255,0.14);
  border: none;
  color: var(--nf-white);
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chevron { font-size: 10px; opacity: 0.85; }

/* ===== Layout ===== */
main#main-content { padding: 16px; }
.screen { display: none; animation: fadein 0.15s ease; }
.screen.visible { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: translateY(0);} }

.screen-title { font-size: 20px; font-weight: 800; margin: 4px 0 16px; color: var(--nf-primary); }
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 22px 4px 10px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 4px;
}

/* ===== Dashboard summary ===== */
.summary-card {
  background: linear-gradient(135deg, var(--nf-primary), var(--nf-accent));
  border-radius: var(--radius-lg);
  padding: 20px;
  color: var(--nf-white);
  box-shadow: var(--shadow-lift);
}
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 10px;
}
.summary-item { display: flex; flex-direction: column; gap: 3px; }
.summary-label { font-size: 12px; opacity: 0.82; font-weight: 500; }
.summary-value { font-size: 19px; font-weight: 800; }
.summary-item.highlight .summary-value { color: #ffffff; }
.health-badge {
  margin-top: 16px;
  background: rgba(255,255,255,0.16);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

/* ===== Breakdown / progress bars ===== */
.breakdown-list { display: flex; flex-direction: column; gap: 16px; }
.breakdown-item .breakdown-top {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  margin-bottom: 6px;
}
.breakdown-item .cat-name { font-weight: 700; }
.breakdown-item .cat-amounts { color: var(--text-muted); }
.progress-track {
  height: 9px;
  background: var(--border);
  border-radius: 20px;
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 20px; background: var(--nf-secondary); transition: width 0.3s ease; }
.progress-fill.warn { background: var(--warning); }
.progress-fill.over { background: var(--danger); }
.breakdown-status { font-size: 12px; margin-top: 5px; font-weight: 600; }
.breakdown-status.ok { color: var(--success); }
.breakdown-status.warn { color: var(--warning); }
.breakdown-status.over { color: var(--danger); }

.empty-state { color: var(--text-muted); font-size: 13.5px; text-align: center; padding: 10px 4px; }

/* ===== Upcoming ===== */
.upcoming-list { display: flex; flex-direction: column; gap: 12px; }
.upcoming-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.upcoming-item:last-child { border-bottom: none; padding-bottom: 0; }
.upcoming-name { font-weight: 700; font-size: 14px; }
.upcoming-due { font-size: 12px; color: var(--text-muted); }
.upcoming-amount { font-weight: 700; color: var(--nf-primary); }
.upcoming-item.soon .upcoming-due { color: var(--danger); font-weight: 600; }

/* ===== Cash flow ===== */
.cashflow-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 14.5px; border-bottom: 1px solid var(--border); }
.cashflow-row:last-child { border-bottom: none; }
.cashflow-row.positive span:last-child { color: var(--success); font-weight: 700; }
.cashflow-row.negative span:last-child { color: var(--danger); font-weight: 700; }
.cashflow-row.total { font-weight: 800; font-size: 16px; padding-top: 12px; }

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
}
.nav-btn {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 8px;
  flex: 1;
}
.nav-btn.active { color: var(--nf-primary); }
.nav-icon { font-size: 20px; }
.nav-add { flex: 0 0 64px; margin-top: -28px; }
.nav-add-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--nf-accent);
  color: var(--nf-white);
  font-size: 30px;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(0, 124, 147, 0.45);
}

/* ===== Add Transaction screen ===== */
.quickadd-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 18px; }
.quickadd-chip {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1.5px solid var(--nf-secondary);
  color: var(--nf-primary);
  font-weight: 700;
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 20px;
  white-space: nowrap;
}

.type-toggle { display: flex; background: var(--border); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.type-btn { flex: 1; border: none; background: none; padding: 10px 0; border-radius: 9px; font-weight: 700; font-size: 13.5px; color: var(--text-muted); }
.type-btn.active { background: var(--surface); color: var(--nf-primary); box-shadow: var(--shadow); }

.amount-input-wrap {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  padding: 18px 0;
}
.currency-prefix { font-size: 18px; font-weight: 700; color: var(--text-muted); }
.amount-input {
  border: none;
  background: none;
  font-size: 44px;
  font-weight: 800;
  color: var(--nf-primary);
  width: 200px;
  text-align: center;
}
.amount-input:focus { outline: none; }
.budget-hint { text-align: center; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; min-height: 18px; }
.budget-hint.warn { color: var(--warning); font-weight: 600; }
.budget-hint.over { color: var(--danger); font-weight: 600; }

.field-label { font-size: 13px; font-weight: 700; color: var(--text-muted); margin: 18px 2px 8px; }

.category-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.category-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.category-btn .cat-icon { font-size: 24px; }
.category-btn.active { border-color: var(--nf-accent); background: #eaf6f8; color: var(--nf-primary); }

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.pill.active { background: var(--nf-primary); border-color: var(--nf-primary); color: var(--nf-white); }

.text-input, .select-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
  margin-bottom: 4px;
}
.text-input:focus, .select-input:focus { outline: none; border-color: var(--nf-secondary); }

.btn-primary {
  background: var(--nf-primary);
  color: var(--nf-white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.03em;
  width: 100%;
}
.btn-save { margin-top: 26px; }
.btn-secondary {
  background: #eaf6f8;
  color: var(--nf-primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px;
  font-size: 14.5px;
  font-weight: 700;
}
.btn-block { width: 100%; margin-top: 10px; }

/* ===== Plan screen ===== */
.plan-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }
.plan-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.plan-row-name { font-weight: 600; font-size: 14px; flex: 1; }
.plan-row input {
  width: 110px;
  text-align: right;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.plan-row-remove { background: none; border: none; color: var(--danger); font-size: 18px; padding: 0 4px; }

/* ===== Transactions list ===== */
.search-row, .filter-row { margin-bottom: 10px; }
.filter-row { display: flex; gap: 8px; }
.filter-row .select-input { flex: 1; }

.txn-list { display: flex; flex-direction: column; gap: 8px; }
.txn-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
.txn-icon { font-size: 22px; width: 34px; text-align: center; }
.txn-main { flex: 1; min-width: 0; }
.txn-desc { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-meta { font-size: 12px; color: var(--text-muted); }
.txn-amount { font-weight: 800; font-size: 14.5px; white-space: nowrap; }
.txn-amount.expense { color: var(--danger); }
.txn-amount.income { color: var(--success); }

/* ===== More menu ===== */
.more-menu { display: flex; flex-direction: column; gap: 10px; }
.more-item {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px 16px;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  box-shadow: var(--shadow);
  color: var(--text);
}
.panel { margin-top: 20px; }
.panel h3 { color: var(--nf-primary); font-size: 16px; margin: 4px 4px 10px; }

.yearly-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.yearly-table th, .yearly-table td { text-align: right; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.yearly-table th:first-child, .yearly-table td:first-child { text-align: left; }

.goal-item, .recurring-item, .account-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.goal-item:last-child, .recurring-item:last-child, .account-item:last-child { border-bottom: none; }
.goal-top, .recurring-top, .account-top { display: flex; justify-content: space-between; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.goal-sub, .recurring-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }

.hint-text { font-size: 12px; color: var(--text-muted); margin-top: 10px; line-height: 1.5; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--nf-white);
  padding: 11px 20px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 100;
  box-shadow: var(--shadow-lift);
  max-width: 90%;
  text-align: center;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 35, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}
.modal-backdrop[hidden] { display: none; }
.modal-sheet {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-sheet h3 { margin-top: 0; color: var(--nf-primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn-secondary, .modal-actions .btn-primary { flex: 1; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: none; border-radius: var(--radius-sm); padding: 13px; font-weight: 700; width: 100%; margin-top: 10px; }

@media (min-width: 481px) {
  #app { box-shadow: 0 0 40px rgba(0,0,0,0.08); }
}
