:root {
  --navy: #0e1a3d;
  --navy-2: #172852;
  --navy-3: #1e3266;
  --gold: #d4af37;
  --gold-light: #f2d97a;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1b2340;
  --muted: #6b7280;
  --border: #e6e8f0;
  --green: #1fa855;
  --green-bg: #e7f7ee;
  --red: #e34850;
  --red-bg: #fdeceb;
  --blue: #3b6fe0;
  --blue-bg: #eaf0fe;
  --yellow: #e8a93b;
  --yellow-bg: #fdf3e2;
  --radius: 14px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; overflow-x: hidden; }
.hidden { display: none !important; }
button { font-family: inherit; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; }
p { margin: 0; }
::placeholder { color: #9aa1b5; }

/* ---------------- PIN screen ---------------- */
.pin-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, #0a132c 100%);
  padding: 20px;
}
.pin-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 40px 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.pin-logo {
  width: 64px; height: 64px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--gold-light), var(--gold));
  border-radius: 16px;
  font-size: 30px; font-weight: 800; color: var(--navy);
}
.pin-card h1 { font-size: 22px; color: var(--navy); margin-bottom: 4px; }
.pin-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.pin-card input {
  width: 100%;
  font-size: 26px;
  text-align: center;
  letter-spacing: 10px;
  padding: 14px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
}
.pin-error { color: var(--red); font-size: 14px; min-height: 18px; margin-bottom: 8px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { background: var(--gold-light); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); color: var(--text); cursor: pointer; }
.link-btn { background: none; border: none; color: var(--blue); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; }
.icon-action { background: none; border: none; cursor: pointer; color: var(--muted); padding: 4px; font-size: 15px; }
.icon-action:hover { color: var(--text); }
.icon-action.danger:hover { color: var(--red); }

/* ---------------- App shell ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  color: #cfd6ea;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px 18px; }
.brand-shield {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(160deg, var(--gold-light), var(--gold));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--navy); font-size: 19px;
  flex-shrink: 0;
}
.brand-text { line-height: 1.25; }
.brand-text .l1 { font-size: 14px; font-weight: 800; color: #fff; letter-spacing: 0.06em; }
.brand-text .l2 { font-size: 10.5px; font-weight: 700; color: var(--gold-light); letter-spacing: 0.14em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #b7c0dd;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item .ic { width: 18px; text-align: center; font-size: 15px; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(212,175,55,0.16); color: var(--gold-light); }

.sidebar-goals { padding: 10px 16px; display: flex; flex-direction: column; gap: 10px; }
.mini-goal { background: rgba(255,255,255,0.05); border-radius: 12px; padding: 12px; }
.mini-goal .row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 8px; }
.mini-goal .name { color: #fff; font-weight: 700; }
.mini-goal .amt { color: #9aa5c7; }
.mini-bar { height: 6px; border-radius: 4px; background: rgba(255,255,255,0.12); overflow: hidden; }
.mini-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-light)); border-radius: 4px; }

.sidebar-footer { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.avatar-circle { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(160deg, var(--gold-light), var(--gold)); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--navy); font-size: 13px; flex-shrink: 0; }
.sidebar-footer .who { line-height: 1.3; flex: 1; min-width: 0; }
.sidebar-footer .who .n { color: #fff; font-weight: 700; font-size: 13px; }
.sidebar-footer .who .r { color: #8f9ac0; font-size: 11.5px; }
.logout-btn { background: none; border: none; color: #8f9ac0; cursor: pointer; font-size: 15px; }
.logout-btn:hover { color: #fff; }

/* ---------------- Main content ---------------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 22px 28px 60px;
}
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 22px; flex-wrap: wrap;
}
.topbar h1 { font-size: 24px; font-weight: 800; color: var(--navy); }
.topbar .greet-wave { display: inline-block; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.topbar-right { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }
.month-picker { display: flex; align-items: center; gap: 8px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; }
.month-picker button { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 14px; padding: 2px 4px; }
.month-picker button:hover { color: var(--navy); }
.month-picker .lbl { font-weight: 700; color: var(--text); font-size: 13px; min-width: 88px; text-align: center; }

.mobile-topbar { display: none; }

.view { display: block; }
.view.hidden { display: none; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.view-header h2 { font-size: 21px; font-weight: 800; color: var(--navy); }
.view-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------------- Cards / grid ---------------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px 18px;
}
.card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.card-title h3 { font-size: 15px; font-weight: 800; color: var(--navy); }
.card-title .icon-tag { font-size: 15px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .lbl { font-size: 11.5px; font-weight: 800; letter-spacing: 0.04em; color: var(--blue); text-transform: uppercase; margin-bottom: 10px; }
.stat-card.expenses .lbl { color: var(--red); }
.stat-card.net .lbl { color: var(--green); }
.stat-card.avail .lbl { color: var(--navy); }
.stat-card .val { font-size: 25px; font-weight: 800; color: var(--text); margin-bottom: 8px; }
.stat-card .delta { font-size: 12.5px; font-weight: 700; }
.stat-card .delta.up { color: var(--green); }
.stat-card .delta.down { color: var(--red); }
.stat-card .delta .prev { color: var(--muted); font-weight: 500; }
.stat-card .refresh { font-size: 12px; color: var(--muted); }

.grid-3 { display: grid; grid-template-columns: 1.1fr 1.1fr 1fr; gap: 16px; margin-bottom: 16px; align-items: stretch; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-a { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 16px; margin-bottom: 16px; }

/* Donut */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { position: relative; width: 132px; height: 132px; border-radius: 50%; flex-shrink: 0; }
.donut::after { content: ''; position: absolute; inset: 16px; border-radius: 50%; background: var(--card-bg); }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1; }
.donut-center .pct { font-size: 22px; font-weight: 800; color: var(--text); }
.donut-center .lbl2 { font-size: 10.5px; color: var(--muted); text-align: center; line-height: 1.2; }
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.legend-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.legend-row .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.legend-row .k { color: var(--muted); display: flex; align-items: center; }
.legend-row .v { font-weight: 700; color: var(--text); }
.card-footer-link { margin-top: 12px; display: block; font-size: 13px; font-weight: 700; }

/* Bar chart (cash flow) */
.barchart { display: flex; align-items: flex-end; gap: 14px; height: 150px; padding-top: 6px; }
.barchart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.barchart .bars { display: flex; align-items: flex-end; gap: 3px; height: 100%; }
.barchart .bar { width: 9px; border-radius: 3px 3px 0 0; min-height: 2px; }
.barchart .bar.income { background: var(--green); }
.barchart .bar.expense { background: var(--red); }
.barchart .xlabel { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.chart-legend .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }

/* Lists */
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-ico { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.list-main { flex: 1; min-width: 0; }
.list-main .t { font-weight: 700; font-size: 13.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-main .s { font-size: 12px; color: var(--muted); }
.list-amt { font-weight: 800; font-size: 13.5px; text-align: right; flex-shrink: 0; }
.list-amt.pos { color: var(--green); }
.list-amt.neg { color: var(--red); }
.list-actions { display: flex; gap: 4px; flex-shrink: 0; }
.empty-state { text-align: center; padding: 28px 10px; color: var(--muted); font-size: 13.5px; }
.empty-state .big { font-size: 28px; margin-bottom: 8px; }

/* Surprise fund card */
.fund-amt { font-size: 26px; font-weight: 800; color: var(--text); }
.fund-goal-lbl { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.progress-track { height: 9px; border-radius: 5px; background: var(--border); overflow: hidden; position: relative; }
.progress-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, #8b5cf6, #6366f1); }
.progress-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.progress-pct { font-size: 12.5px; font-weight: 700; color: var(--muted); min-width: 32px; text-align: right; }
.fund-note { font-size: 12px; color: var(--muted); margin: 10px 0 12px; }

/* Tables */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.data-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table .num { text-align: right; font-weight: 700; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 800; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.gray { background: var(--bg); color: var(--muted); }
.mini-progress { width: 90px; height: 6px; border-radius: 4px; background: var(--border); overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
.mini-progress > span { display: block; height: 100%; border-radius: 4px; }
.table-scroll { overflow-x: auto; }

/* Calendar */
.cal-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.cal-day { min-width: 96px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 12px; padding: 10px 10px 12px; background: var(--bg); }
.cal-day.today { background: var(--navy); border-color: var(--navy); }
.cal-day .dow { font-size: 10px; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.cal-day .dom { font-size: 16px; font-weight: 800; color: var(--text); margin: 2px 0 8px; }
.cal-day.today .dow, .cal-day.today .dom { color: var(--gold-light); }
.cal-bill { font-size: 11px; background: var(--card-bg); border-radius: 6px; padding: 4px 6px; margin-bottom: 4px; }
.cal-bill .n { font-weight: 700; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-bill .a { color: var(--muted); }
.cal-day.today .cal-bill { background: rgba(255,255,255,0.1); color: #fff; }
.cal-day.today .cal-bill .a { color: #b7c0dd; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cal-grid .dow-head { text-align: center; font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; padding-bottom: 4px; }
.cal-cell { min-height: 96px; border: 1px solid var(--border); border-radius: 10px; padding: 6px; background: var(--card-bg); }
.cal-cell.other-month { background: var(--bg); opacity: 0.55; }
.cal-cell.is-today { border-color: var(--gold); box-shadow: inset 0 0 0 1.5px var(--gold); }
.cal-cell .cnum { font-size: 12px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.cal-cell .cbill { font-size: 10.5px; background: var(--blue-bg); color: var(--blue); border-radius: 5px; padding: 2px 5px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.cal-cell .cbill.paid { background: var(--green-bg); color: var(--green); text-decoration: line-through; }

/* Forms / modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,15,35,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--card-bg); border-radius: 16px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; font-weight: 800; color: var(--navy); }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; background: var(--bg); color: var(--text); font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: 2px solid var(--gold-light); border-color: var(--gold); }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input { width: auto; }
.form-error { color: var(--red); font-size: 13px; margin-bottom: 10px; min-height: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 13.5px; font-weight: 600; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,0.3); }

/* Mobile bottom nav */
.bottom-nav { display: none; }

/* ------------- Responsive ------------- */
@media (max-width: 980px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { padding: 14px 14px 90px; }
  .topbar { display: none; }
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--navy); color: #fff; padding: 14px 16px; border-radius: 14px; margin-bottom: 16px;
  }
  .mobile-topbar .brand { display: flex; align-items: center; gap: 10px; }
  .mobile-topbar .brand-shield { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
  .mobile-topbar .brand-text .l1 { font-size: 11px; }
  .mobile-topbar .brand-text .l2 { font-size: 8px; }
  .view-header h2 { font-size: 18px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .stat-card { padding: 12px 14px; }
  .stat-card .val { font-size: 19px; }
  .card { padding: 14px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--navy); padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-around; align-items: center;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
  }
  .bottom-nav button { background: none; border: none; color: #8f9ac0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 9.5px; font-weight: 700; cursor: pointer; padding: 4px 6px; }
  .bottom-nav button .ic { font-size: 17px; }
  .bottom-nav button.active { color: var(--gold-light); }
  .bottom-nav button.fab .ic { width: 38px; height: 38px; background: var(--gold); color: var(--navy); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-bottom: 2px; }
  .form-row { grid-template-columns: 1fr; }
  .donut-wrap { flex-direction: column; align-items: flex-start; }
  table.data-table { font-size: 12.5px; }
  .cal-grid .dow-head { font-size: 9px; }
  .cal-cell { min-height: 60px; padding: 4px; }
  .more-sheet-grid { grid-template-columns: repeat(3, 1fr) !important; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

/* More sheet (mobile) */
.more-sheet { position: fixed; inset: 0; background: rgba(10,15,35,0.5); z-index: 90; display: flex; align-items: flex-end; }
.more-sheet .panel { background: var(--card-bg); width: 100%; border-radius: 20px 20px 0 0; padding: 18px; }
.more-sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 12px; }
.more-sheet-grid button { display: flex; flex-direction: column; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px 6px; font-size: 11.5px; font-weight: 700; color: var(--text); cursor: pointer; }
.more-sheet-grid button .ic { font-size: 18px; }
