/* ══════════════════════════════════════════════
   TOKENS
══════════════════════════════════════════════ */
:root {
  --bg:      #07080f;
  --surf:    #0c0e18;
  --card:    #111422;
  --card2:   #161a2c;
  --border:  #1c2038;
  --border2: #252a45;

  --teal:   #00d4aa;
  --amber:  #f0a040;
  --coral:  #ff6b72;
  --violet: #a78bfa;
  --sky:    #38bdf8;

  --text:   #dde3f5;
  --muted:  #3d4566;
  --muted2: #7a83a8;

  --r: 16px; --r-sm: 10px;
  --font-ui:   'Outfit', sans-serif;
  --font-num:  'JetBrains Mono', monospace;
  --font-disp: 'DM Serif Display', serif;

  --path-a: #00d4aa;
  --path-b: #a78bfa;
  --path-c: #f0a040;
}

/* ══════════════════════════════════════
   RESET & BASE
══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  min-height: 100vh;
  padding-bottom: 116px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
}

/* ══════════════════════════════════════
   LAYOUT
══════════════════════════════════════ */
.container { max-width: 540px; margin: 0 auto; padding: 20px 16px; }

/* ══════════════════════════════════════
   APP HEADER
══════════════════════════════════════ */
.app-header {
  position: sticky; top: 0; z-index: 90;
  background: rgba(7,8,15,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 100%;
}
.app-header-title { font-family: var(--font-disp); font-size: 18px; color: var(--teal); }
.graph-banner {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(0,212,170,.08); border-bottom: 1px solid rgba(0,212,170,.2);
  padding: 9px 16px; cursor: pointer; user-select: none;
  font-size: 12px; font-weight: 600; color: var(--teal);
  transition: background .15s;
}
.graph-banner:hover { background: rgba(0,212,170,.14); }
.graph-banner-close {
  background: none; border: none; color: var(--teal); font-size: 16px;
  line-height: 1; cursor: pointer; padding: 0 0 0 12px; opacity: .7;
}
.graph-banner-close:hover { opacity: 1; }
.save-btn {
  padding: 7px 16px; border-radius: 8px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border2); background: transparent; color: var(--muted2);
  cursor: pointer; font-family: var(--font-ui); transition: .15s;
}
.save-btn.dirty { border-color: var(--amber); color: var(--amber); }
.save-btn.dirty:hover { background: rgba(240,160,64,.08); }

/* ══════════════════════════════════════
   CARDS
══════════════════════════════════════ */
.card {
  background: var(--card);
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.018) 0%, transparent 60%);
  pointer-events: none;
}
.card-alt { background: var(--card2); }
.card-sm  { padding: 14px 16px; }

/* ══════════════════════════════════════
   TYPOGRAPHY
══════════════════════════════════════ */
h1 { font-family: var(--font-disp); font-size: 32px; font-weight: 400; line-height: 1.1; }
h2 { font-family: var(--font-disp); font-size: 22px; font-weight: 400; margin-bottom: 4px; }
h3 { font-family: var(--font-ui); font-size: 14px; font-weight: 700; margin-bottom: 12px; letter-spacing: .02em; }
.micro { font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted2); }
.num   { font-family: var(--font-num); }

/* ══════════════════════════════════════
   INPUTS
══════════════════════════════════════ */
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 10px 13px;
  background: #090b14; border: 1px solid var(--border);
  color: var(--text); border-radius: var(--r-sm);
  font-size: 13px; font-family: var(--font-ui); outline: none;
  transition: border-color .18s, box-shadow .18s;
}
input:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,212,170,.08); }
select option { background: #111422; }
input[type=range] {
  width: 100%; accent-color: var(--teal);
  cursor: pointer; margin: 5px 0 2px;
}
.field { margin-bottom: 12px; }
.field > label { display: block; margin-bottom: 5px; }
.field-row  { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

/* ══════════════════════════════════════
   BUTTONS
══════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 13px; cursor: pointer;
  border: none; width: 100%; transition: .15s; font-family: var(--font-ui);
}
.btn-primary { background: var(--teal); color: #07080f; }
.btn-primary:hover { background: #00bfa0; transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0,212,170,.22); }
.btn-ghost { background: transparent; border: 1px solid var(--border2); color: var(--muted2); }
.btn-ghost:hover { border-color: var(--teal); color: var(--teal); }
.btn-sm   { padding: 8px 14px; font-size: 12px; border-radius: 8px; }
.btn-icon { width: auto; padding: 8px 12px; }
.btn-row  { display: flex; gap: 8px; flex-wrap: wrap; }

/* ══════════════════════════════════════
   TOGGLE
══════════════════════════════════════ */
.toggle-wrap { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted2); cursor: pointer; }
.toggle { position: relative; width: 38px; height: 21px; background: var(--border2); border-radius: 21px; transition: .2s; flex-shrink: 0; }
.toggle.on { background: var(--teal); }
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 15px; height: 15px; background: #fff; border-radius: 50%; transition: .2s;
}
.toggle.on::after { left: 20px; }

/* ══════════════════════════════════════
   SCENARIO CHIPS
══════════════════════════════════════ */
.scenario-chips {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 14px 16px 4px; max-width: 540px; margin: 0 auto;
}
.scenario-chip {
  padding: 5px 14px; border-radius: 20px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  border: 1px solid var(--border2); color: var(--muted2);
  cursor: pointer; transition: .15s; background: transparent;
}
.scenario-chip:hover { border-color: var(--muted); color: var(--text); }
.scenario-chip.active { font-weight: 700; }
.scenario-chip-add { color: var(--teal); border-color: rgba(0,212,170,.3); }
.scenario-chip-add:hover { background: rgba(0,212,170,.07); border-color: var(--teal); }

/* ══════════════════════════════════════
   PATH TAGS
══════════════════════════════════════ */
.path-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 20px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}

/* ══════════════════════════════════════
   NAV
══════════════════════════════════════ */
.app-footer {
  position: fixed; bottom: 67px; left: 0; right: 0;
  text-align: center; padding: 6px;
  font-size: 12px;
  background: rgba(7,8,15,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  color: var(--muted2);
  z-index: 99;
}
.app-footer a { color: var(--teal); text-decoration: none; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(11,13,22,.95); backdrop-filter: blur(16px);
  display: flex; justify-content: space-around;
  padding: 10px 0 20px; border-top: 1px solid var(--border);
  z-index: 100;
}
.nav-item {
  cursor: pointer; color: var(--muted); font-weight: 600;
  font-size: 10px; text-align: center; line-height: 1.7;
  padding: 6px 10px; border-radius: 10px; transition: .15s;
  letter-spacing: .04em;
}
.nav-item .nav-icon { font-size: 18px; display: block; margin-bottom: 2px; }
.nav-item.active { color: var(--teal); background: rgba(0,212,170,.07); }

/* ══════════════════════════════════════
   AUTH
══════════════════════════════════════ */
.auth-tab-btn {
  flex: 1; padding: 8px; background: transparent; border: none;
  color: var(--muted2); font-size: 13px; font-weight: 600;
  cursor: pointer; border-radius: 8px; transition: .15s;
  font-family: var(--font-ui);
}
.auth-tab-btn.active { background: var(--card); color: var(--text); }
.auth-error {
  background: rgba(255,107,114,.08); border: 1px solid rgba(255,107,114,.2);
  color: var(--coral); border-radius: 8px; padding: 8px 12px;
  font-size: 12px; margin-bottom: 12px;
}

/* ══════════════════════════════════════
   AVATAR GRID
══════════════════════════════════════ */
.avatar-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 14px 0; }
.avatar-item {
  background: var(--surf); padding: 12px 0; border-radius: 12px;
  text-align: center; cursor: pointer; border: 2px solid transparent;
  font-size: 24px; transition: .15s;
}
.avatar-item.sel { border-color: var(--teal); background: rgba(0,212,170,.07); }
.avatar-item:hover { transform: scale(1.06); }

/* ══════════════════════════════════════
   STATS
══════════════════════════════════════ */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stat-box {
  background: var(--surf); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 10px; text-align: center;
}
.stat-val { font-family: var(--font-num); font-size: 14px; font-weight: 600; }
.stat-sub { font-size: 9px; color: var(--muted2); margin-top: 3px; text-transform: uppercase; letter-spacing: .06em; }

/* ══════════════════════════════════════
   MONTE CARLO
══════════════════════════════════════ */
.prob-bar-wrap { margin: 8px 0; }
.prob-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.prob-bar { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.prob-fill { height: 100%; border-radius: 4px; transition: width .6s ease; }

/* ══════════════════════════════════════
   LIFE EVENTS
══════════════════════════════════════ */
.event-type-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.event-type-chip {
  padding: 5px 12px; border-radius: 20px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border2); color: var(--muted2);
  cursor: pointer; transition: .15s; background: transparent;
}
.event-type-chip.active { border-color: var(--teal); color: var(--teal); background: rgba(0,212,170,.08); }
.event-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surf); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
  animation: slideIn .25s ease;
}
.event-stripe { width: 3px; height: 34px; border-radius: 3px; flex-shrink: 0; }
.event-info { flex: 1; }
.event-name { font-weight: 600; font-size: 13px; }
.event-meta { font-size: 11px; color: var(--muted2); margin-top: 2px; }
.event-del { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 18px; padding: 4px; transition: color .15s; }
.event-del:hover { color: var(--coral); }

/* ══════════════════════════════════════
   ASSETS / DEBTS
══════════════════════════════════════ */
.asset-row { margin-bottom: 10px; }
.balance-total {
  font-family: var(--font-num); font-size: 22px; font-weight: 600;
  color: var(--teal); margin-bottom: 4px;
}

/* ══════════════════════════════════════
   SHARE
══════════════════════════════════════ */
.share-card {
  background: linear-gradient(135deg, #0e1828 0%, #0a1220 100%);
  border: 1px solid var(--border2); border-radius: var(--r);
  padding: 24px; text-align: center;
}
.share-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0,212,170,.1); border: 1px solid rgba(0,212,170,.2);
  color: var(--teal); border-radius: 20px; padding: 6px 14px;
  font-size: 12px; font-weight: 600; margin-bottom: 18px;
}
.share-url-box {
  background: var(--surf); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; text-align: left;
}

/* ══════════════════════════════════════
   COMMENTS
══════════════════════════════════════ */
.comment-item {
  display: flex; gap: 10px; margin-bottom: 10px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.comment-item:last-child { border-bottom: none; margin-bottom: 0; }
.comment-avatar { font-size: 22px; flex-shrink: 0; }
.comment-author { font-weight: 600; font-size: 12px; margin-bottom: 2px; }
.comment-text   { font-size: 13px; color: var(--muted2); line-height: 1.5; }

/* ══════════════════════════════════════
   FRIENDS
══════════════════════════════════════ */
.friend-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.friend-item:last-child { border-bottom: none; }
.friend-info { flex: 1; }
.friend-name { font-weight: 600; font-size: 13px; }

/* ══════════════════════════════════════
   DISCLAIMER
══════════════════════════════════════ */
.disclaimer {
  background: rgba(240,160,64,.05); border: 1px solid rgba(240,160,64,.15);
  border-radius: 10px; padding: 10px 14px;
  font-size: 11px; color: #b0894a; line-height: 1.6;
  margin-bottom: 14px; display: flex; gap: 8px; align-items: flex-start;
}

/* ══════════════════════════════════════
   BREAKEVEN
══════════════════════════════════════ */
.breakeven {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.02); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; font-size: 12px; margin-top: 10px;
}

/* ══════════════════════════════════════
   EMPTY STATES
══════════════════════════════════════ */
.empty { text-align: center; padding: 36px 20px; color: var(--muted2); }
.empty-icon { font-size: 36px; margin-bottom: 10px; }

/* ══════════════════════════════════════
   TOAST
══════════════════════════════════════ */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--border2);
  color: var(--text); padding: 10px 20px; border-radius: 10px;
  font-size: 13px; font-weight: 600; z-index: 200;
  animation: fadeUp .2s ease, fadeOut .3s ease 2.2s forwards;
  white-space: nowrap;
}
.toast.error { border-color: rgba(255,107,114,.4); color: var(--coral); }
@keyframes fadeOut { to { opacity: 0; transform: translateX(-50%) translateY(-6px); } }

/* ══════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════ */
@keyframes fadeUp  { from { opacity:0; transform:translateY(12px);} to { opacity:1; transform:none;} }
@keyframes slideIn { from { opacity:0; transform:translateX(-8px);} to { opacity:1; transform:none;} }
.fade-up { animation: fadeUp .3s ease forwards; }

/* ══════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════ */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ══════════════════════════════════════
   ACCENTS & LEGEND
══════════════════════════════════════ */
.accent-a { color: var(--path-a); }
.accent-b { color: var(--path-b); }
.accent-c { color: var(--path-c); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted2); }
.legend-dot  { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend-line { width: 18px; height: 2px; border-radius: 2px; flex-shrink: 0; }

.chart-hdr { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.range-btns { display: flex; gap: 4px; }
.range-btn  { background: none; border: 1px solid var(--border2); border-radius: 6px; color: var(--muted2); font-size: 11px; padding: 3px 8px; cursor: pointer; font-family: inherit; transition: .15s; }
.range-btn.active, .range-btn:hover { border-color: var(--teal); color: var(--teal); }

/* ══════════════════════════════════════
   PROJECTION TABLE
══════════════════════════════════════ */
#proj-table { margin-top: 4px; }
.proj-table { width: 100%; border-collapse: collapse; font-size: 12px; font-family: var(--font-num); }
.proj-table th {
  text-align: right; padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--muted2); font-size: 10px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  white-space: nowrap;
}
.proj-table th:first-child { text-align: left; }
.proj-table td { text-align: right; padding: 5px 8px; border-bottom: 1px solid rgba(28,32,56,.5); white-space: nowrap; }
.proj-table td:first-child { text-align: left; }
.proj-table tr:hover td { background: rgba(255,255,255,.025); }
.tbl-age { font-weight: 700; color: var(--muted2); font-size: 11px; }
.tbl-pos { color: var(--teal); }
.tbl-neg { color: var(--coral); }
.tbl-bal { font-weight: 700; }

/* ── Balance sheet table additions ── */
.bs-expandable { cursor: pointer; user-select: none; transition: color .15s; }
.bs-expandable:hover { color: var(--teal) !important; }
.bs-expand-arrow { font-size: 9px; color: var(--muted2); margin-right: 3px; display: inline-block; }
.bs-summary-row td { font-weight: 500; }
.bs-detail-row td {
  background: rgba(255,255,255,.012);
  border-bottom: 1px solid rgba(28,32,56,.3);
  font-size: 11px; padding: 3px 8px; color: var(--muted2);
}
.bs-detail-row td:first-child { color: var(--muted); padding-left: 16px; }
.bs-detail-label { text-align: left; }
.bs-col-clickable { cursor: pointer; user-select: none; }
.bs-col-clickable:hover { color: var(--teal); }

/* ── Cashflow summary table ── */
#proj-cashflow { margin-top: 4px; }
.cf-year-row td { font-weight: 700; border-top: 1px solid var(--border); padding-top: 8px; background: rgba(255,255,255,.018); }
.cf-section-hdr td { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted2); padding: 3px 8px; cursor: pointer; user-select: none; border-bottom: none; }
.cf-section-hdr:hover td { color: var(--teal); }
.cf-reference-row td { font-size: 11px; color: var(--muted2); font-style: italic; border-bottom: none; padding: 2px 8px; }

/* ══════════════════════════════════════
   COLLAPSIBLE SECTIONS
══════════════════════════════════════ */
.sec-hdr {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 0; margin-top: 2px;
  border-top: 1px solid var(--border);
  cursor: pointer; user-select: none;
  transition: color .15s;
}
.sec-hdr:hover { color: var(--teal); }
.sec-hdr:hover .sec-arrow { color: var(--teal); }
.sec-title { font-weight: 600; font-size: 13px; }
.sec-arrow { font-size: 10px; color: var(--muted2); transition: color .15s; }
.sec-body { padding-top: 10px; }
.sec-badge {
  margin-left: auto;
  background: var(--surf); border: 1px solid var(--border2);
  color: var(--muted2); border-radius: 10px;
  padding: 2px 8px; font-size: 10px; font-weight: 700;
}

/* ══════════════════════════════════════
   FALLING MONEY ANIMATION
══════════════════════════════════════ */
.money-rain-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  width: calc((100vw - 540px) / 2);
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.money-rain-panel.left  { left: 0; }
.money-rain-panel.right { right: 0; }
@media (max-width: 540px) {
  .money-rain-panel.left  { width: 50vw; }
  .money-rain-panel.right { width: 50vw; }
}

@keyframes moneyFall {
  0%   { transform: translateY(-60px) rotate(0deg);   opacity: 0; }
  10%  { opacity: .55; }
  90%  { opacity: .45; }
  100% { transform: translateY(110vh) rotate(360deg); opacity: 0; }
}

.money-symbol {
  position: absolute;
  top: 0;
  font-size: 22px;
  animation: moneyFall linear infinite;
  will-change: transform, opacity;
  user-select: none;
}
