* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; }
p { margin: 0; }
a { color: inherit; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; top: -48px; left: 8px; background: var(--accent-fill); color: var(--on-accent); padding: .6rem 1rem; border-radius: var(--radius-sm); z-index: 999; }
.skip-link:focus { top: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: var(--bg-elevated); border-right: 1px solid var(--border); display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0; }
.sidebar-brand { height: var(--topbar-h); display: flex; align-items: center; gap: .7rem; padding: 0 1.3rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-brand .mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent-fill)); color: var(--on-accent); display: grid; place-items: center; font-weight: 800; font-family: var(--font-display); }
.sidebar-brand .name { font-weight: 700; font-family: var(--font-display); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem .8rem; }
.sidebar-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 700; padding: .9rem .7rem .4rem; }
.nav-item { display: flex; align-items: center; gap: .8rem; padding: .6rem .7rem; border-radius: var(--radius-sm); color: var(--text-soft); cursor: pointer; margin-bottom: .1rem; font-weight: 500; border: none; background: none; width: 100%; text-align: left; }
.nav-item:hover { background: var(--bg-sunken); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--info-text); }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: 1rem; padding: 0 1.4rem; background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar h2 { font-size: 1.15rem; }
.topbar .sub { font-size: .78rem; color: var(--text-faint); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.icon-btn { width: 40px; height: 40px; border-radius: var(--radius-sm); display: grid; place-items: center; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-soft); cursor: pointer; }
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.avatar { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: .74rem; color: var(--on-accent); flex-shrink: 0; background: var(--accent-fill); }

.content { flex: 1; padding: 1.6rem; max-width: 1300px; width: 100%; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.btn { display: inline-flex; align-items: center; gap: .5rem; border-radius: var(--radius-sm); padding: .6rem 1.1rem; font-weight: 600; font-size: .85rem; cursor: pointer; border: 1px solid transparent; min-height: 40px; }
.btn-primary { background: var(--accent-fill); color: var(--on-accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-outline { background: none; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--info-text); }
.btn-sm { padding: .4rem .8rem; font-size: .78rem; min-height: 36px; }

.grid { display: grid; gap: 1.2rem; }
.grid-2 { grid-template-columns: 1.6fr 1fr; }
.grid-2-rev { grid-template-columns: 1fr 1.4fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) { .grid-2, .grid-2-rev { grid-template-columns: 1fr; } }
@media (max-width: 650px) { .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1.3rem; box-shadow: var(--shadow-sm); }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: .8rem; flex-wrap: wrap; }
.panel-title h3 { font-size: .95rem; }

.stat-card { display: flex; flex-direction: column; gap: .5rem; }
.stat-label { color: var(--text-soft); font-size: .82rem; }
.stat-value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 800; }
.stat-delta { font-size: .75rem; font-weight: 700; display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .5rem; border-radius: 999px; width: fit-content; }
.stat-delta.up { color: var(--success-text); background: var(--success-soft); }
.stat-delta.down { color: var(--danger-text); background: var(--danger-soft); }

/* Credit card visual */
.story-strip { display: flex; gap: 1rem; align-items: flex-start; background: var(--accent-soft, var(--bg-sunken)); border: 1px solid var(--accent); border-radius: var(--radius-md); padding: 1rem 1.2rem; margin-bottom: 1.2rem; font-size: .86rem; color: var(--text-soft); }
.story-icon { font-size: 1.4rem; flex-shrink: 0; }
.goal-milestones { display: flex; gap: .4rem; justify-content: center; margin-top: .9rem; }
.milestone-badge { font-size: .68rem; font-weight: 700; padding: .25rem .55rem; border-radius: 999px; background: var(--bg-sunken); color: var(--text-faint); }
.milestone-badge.earned { background: var(--gold-soft, var(--accent-soft)); color: var(--gold-text, var(--accent)); }
.budget-alert { font-size: .78rem; color: var(--text-soft); margin-top: .5rem; background: var(--bg-sunken); border-radius: var(--radius-sm); padding: .5rem .7rem; }
.flip-card { perspective: 1200px; cursor: pointer; min-height: 170px; }
.flip-card-inner { position: relative; width: 100%; height: 100%; min-height: 170px; transition: transform .5s; transform-style: preserve-3d; }
.flip-card.flipped .flip-card-inner { transform: rotateY(180deg); }
.flip-front, .flip-back { position: absolute; inset: 0; backface-visibility: hidden; }
.flip-back { transform: rotateY(180deg); }
.credit-card { border-radius: var(--radius-lg); padding: 1.6rem; color: #fff; position: relative; overflow: hidden; min-height: 170px; display: flex; flex-direction: column; justify-content: space-between; }
.forecast-strip { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; padding: .6rem 0; }
.forecast-point { display: flex; flex-direction: column; gap: .2rem; padding: .7rem .9rem; background: var(--bg-sunken); border-radius: var(--radius-sm); }
.forecast-point.forecast-final { background: var(--accent-soft, var(--bg-sunken)); border: 1px solid var(--accent); }
.forecast-label { font-size: .72rem; color: var(--text-faint); }
.forecast-amt { font-weight: 700; font-family: var(--font-display); }
.forecast-amt.up { color: var(--success-text); }
.forecast-amt.down { color: var(--danger-text); }
.forecast-arrow { color: var(--text-faint); }
body.privacy-on .privacy-target { filter: blur(6px); user-select: none; }
.credit-card.card-1 { background: linear-gradient(135deg,#1f7a5c,#0f4a37); }
.credit-card.card-2 { background: linear-gradient(135deg,#2b2b3a,#12121c); }
.credit-card .chip { width: 34px; height: 26px; border-radius: 6px; background: linear-gradient(135deg,#e0b04a,#b8862e); }
.credit-card .num { font-family: var(--font-display); letter-spacing: .12em; font-size: 1.05rem; }
.credit-card .foot-row { display: flex; justify-content: space-between; font-size: .74rem; opacity: .85; }

.badge { font-size: .7rem; font-weight: 700; padding: .18rem .5rem; border-radius: 999px; display: inline-block; }
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-gold { background: var(--gold-soft); color: var(--gold-text); }
.badge-neutral { background: var(--bg-sunken); color: var(--text-faint); }

/* Transactions */
.txn-toolbar { display: flex; gap: .7rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.txn-toolbar .search-box { max-width: 240px; }
.txn-toolbar select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem .7rem; background: var(--bg-elevated); color: var(--text); min-height: 40px; }
.txn-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.txn-table th { text-align: left; color: var(--text-faint); font-weight: 700; font-size: .7rem; text-transform: uppercase; padding: .6rem .7rem; border-bottom: 1px solid var(--border); }
.txn-table td { padding: .75rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.txn-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.txn-icon svg { width: 16px; height: 16px; }
.txn-name-row { display: flex; align-items: center; gap: .7rem; }
.amt-neg { color: var(--danger-text); font-weight: 700; }
.amt-pos { color: var(--success-text); font-weight: 700; }
.txn-cat-select { border: 1px solid transparent; background: none; color: var(--text); border-radius: var(--radius-sm); padding: .3rem .4rem; font-size: .84rem; }
.txn-cat-select:hover, .txn-cat-select:focus-visible { border-color: var(--border); background: var(--bg-sunken); }
.empty-state { text-align: center; padding: 2.4rem 1rem; color: var(--text-faint); }
.empty-state h4 { color: var(--text); font-size: .95rem; margin-bottom: .3rem; }

/* Budget bars */
.budget-row { margin-bottom: 1.1rem; }
.budget-row:last-child { margin-bottom: 0; }
.budget-head { display: flex; justify-content: space-between; font-size: .84rem; margin-bottom: .4rem; }
.budget-head .cat { font-weight: 700; }
.progress-bar { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.progress-bar .fill { height: 100%; border-radius: 999px; }

/* Goals */
.goal-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: .6rem; position: relative; }
.goal-ring { position: relative; width: 110px; height: 110px; }
.goal-ring svg { transform: rotate(-90deg); }
.goal-ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; }
.goal-title { font-weight: 700; font-size: .88rem; }
.goal-sub { font-size: .76rem; color: var(--text-faint); }

/* Bills */
.bill-row { display: flex; align-items: center; gap: 1rem; padding: .85rem 0; border-bottom: 1px solid var(--border); }
.bill-row:last-child { border-bottom: none; }
.bill-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--bg-sunken); display: grid; place-items: center; flex-shrink: 0; color: var(--text-soft); }
.bill-info { flex: 1; }
.bill-name { font-weight: 700; font-size: .88rem; }
.bill-due { font-size: .76rem; color: var(--text-faint); }
.bill-amt { font-weight: 700; font-family: var(--font-display); }
.bill-actions { display: flex; align-items: center; gap: .6rem; }

/* Cash flow */
.period-switch { display: flex; background: var(--bg-sunken); border-radius: var(--radius-sm); padding: .2rem; }
.period-switch button { background: none; border: none; padding: .5rem .9rem; font-size: .8rem; font-weight: 600; color: var(--text-faint); border-radius: var(--radius-sm); cursor: pointer; min-height: 36px; }
.period-switch button.active { background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow-sm); }
.cashflow-legend { display: flex; gap: 1.2rem; margin-top: .8rem; font-size: .8rem; color: var(--text-soft); }
.cashflow-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Chart tooltip */
.chart-tooltip { position: absolute; background: var(--text); color: var(--bg-elevated); font-size: .72rem; padding: .35rem .6rem; border-radius: 6px; pointer-events: none; opacity: 0; transition: opacity .12s ease; white-space: nowrap; z-index: 10; }
.chart-tooltip.visible { opacity: 1; }
.chart-wrap { position: relative; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,13,19,.55); display: none; align-items: center; justify-content: center; z-index: 200; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--bg-elevated); border-radius: var(--radius-lg); padding: 1.6rem; width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); position: relative; }
.modal-close { position: absolute; top: 1rem; right: 1rem; width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-sunken); color: var(--text-soft); cursor: pointer; }
.modal-box h2 { font-size: 1.05rem; margin-bottom: 1.1rem; padding-right: 2rem; }
.modal-field { margin-bottom: .9rem; }
.modal-field label { display: block; font-size: .78rem; font-weight: 600; color: var(--text-soft); margin-bottom: .35rem; }
.modal-field input, .modal-field select { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .7rem; background: var(--bg); color: var(--text); font-size: .86rem; min-height: 40px; }
.modal-row { display: flex; gap: .7rem; }
.modal-row .modal-field { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }

.mobile-nav-toggle { display: none; }
@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { position: fixed; z-index: 40; height: 100vh; transform: translateX(-100%); transition: transform .2s ease; }
  .app-shell.mobile-nav-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(10,13,19,.5); z-index: 35; }
  .app-shell.mobile-nav-open .sidebar-backdrop { display: block; }
  .mobile-nav-toggle { display: grid !important; }
}

.toast-stack { position: fixed; bottom: 1.3rem; right: 1.3rem; display: flex; flex-direction: column; gap: .6rem; z-index: 100; }
.toast { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem 1rem; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: .6rem; font-size: .82rem; min-width: 220px; }
