*,*::before,*::after{box-sizing:border-box;margin:0;padding:0;-webkit-tap-highlight-color:transparent}
:root{
  --bg:#f8f7f5;--surface:#fff;--surface-2:#f2f1ef;--surface-3:#eae8e4;
  --border:#e5e3df;--border-md:#cbc9c4;
  --text:#1a1917;--text-2:#6b6966;--text-3:#a09d99;
  --accent:#2563eb;--accent-bg:#eff4ff;--accent-bdr:#bfcffe;--accent-text:#1d4ed8;
  --success:#16a34a;--success-bg:#f0fdf4;--success-bdr:#86efac;
  --warn:#d97706;--warn-bg:#fffbeb;--warn-bdr:#fde68a;
  --danger:#dc2626;--danger-bg:#fef2f2;--danger-bdr:#fca5a5;
  --brand:#1a1917;
  --radius:10px;--radius-lg:16px;--radius-xl:20px;
  --safe-top:env(safe-area-inset-top,0px);
  --safe-bottom:env(safe-area-inset-bottom,0px);
}
@media(prefers-color-scheme:dark){
  :root{
    --bg:#111110;--surface:#1c1b19;--surface-2:#242321;--surface-3:#2e2c28;
    --border:#2e2c29;--border-md:#3d3b37;
    --text:#f5f4f0;--text-2:#9b9893;--text-3:#5a5854;
    --accent:#60a5fa;--accent-bg:#1e2d47;--accent-bdr:#2a4070;--accent-text:#93c5fd;
    --success:#4ade80;--success-bg:#0f2d1a;--success-bdr:#166534;
    --warn:#fbbf24;--warn-bg:#2d220a;--warn-bdr:#854d0e;
    --danger:#f87171;--danger-bg:#2d1010;--danger-bdr:#991b1b;
    --brand:#f5f4f0;
  }
}
html{background:var(--bg);-webkit-font-smoothing:antialiased}
body{font-family:'Inter',system-ui,-apple-system,sans-serif;font-size:15px;color:var(--text);background:var(--bg);min-height:100vh;min-height:100vh;height:100dvh}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit}
input,select,textarea{font-family:inherit;color:var(--text)}
input[type=number]::-webkit-inner-spin-button{opacity:1}
::-webkit-scrollbar{width:0}
a{color:var(--accent);text-decoration:none}

/* ── Shell ── */
#app{max-width:430px;margin:0 auto;min-height:100vh;min-height:100vh;height:100dvh;display:flex;flex-direction:column}

/* ════════════════════════════════════════════
   WELCOME / AUTH SCREENS
════════════════════════════════════════════ */

/* Welcome screen */
.welcome-screen{
  min-height:100vh;min-height:100vh;height:100dvh;
  display:flex;flex-direction:column;
  background:var(--surface);
  padding-top:var(--safe-top);
}
.welcome-hero{
  flex:1;
  display:flex;flex-direction:column;
  align-items:center;justify-content:center;
  padding:48px 32px 32px;
  text-align:center;
}
.welcome-logo{
  width:72px;height:72px;
  border-radius:20px;
  background:var(--brand);
  display:flex;align-items:center;justify-content:center;
  margin-bottom:24px;
}
.welcome-logo svg{width:40px;height:40px}
.welcome-title{
  font-size:32px;font-weight:700;
  letter-spacing:-1px;line-height:1.15;
  margin-bottom:12px;
}
.welcome-tagline{
  font-size:15px;color:var(--text-2);
  line-height:1.6;max-width:280px;
  margin-bottom:40px;
}
.welcome-inspiration{
  display:flex;align-items:center;gap:10px;
  background:var(--bg);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  padding:12px 16px;
  text-align:left;
  max-width:320px;
  width:100%;
  margin-bottom:0;
}
.wi-icon{font-size:22px;flex-shrink:0}
.wi-text{flex:1}
.wi-label{font-size:10px;font-weight:600;color:var(--text-3);text-transform:uppercase;letter-spacing:.06em;margin-bottom:2px}
.wi-quote{font-size:13px;color:var(--text-2);line-height:1.45;font-style:italic}
.wi-names{font-size:12px;font-weight:600;color:var(--text);margin-top:4px}

.welcome-actions{
  padding:24px 24px calc(24px + var(--safe-bottom));
  display:flex;flex-direction:column;gap:10px;
  border-top:1px solid var(--border);
  background:var(--surface);
}

/* Auth screen (login / signup) */
.auth-screen{
  min-height:100vh;min-height:100vh;height:100dvh;
  display:flex;flex-direction:column;
  padding-top:var(--safe-top);
  background:var(--surface);
}
.auth-topbar{
  display:flex;align-items:center;
  padding:14px 16px;
  gap:12px;
}
.auth-back{
  width:36px;height:36px;border-radius:50%;
  border:1px solid var(--border);background:var(--surface-2);
  display:flex;align-items:center;justify-content:center;
  font-size:18px;color:var(--text-2);flex-shrink:0;
}
.auth-back:active{background:var(--border)}
.auth-screen-title{font-size:17px;font-weight:600}

.auth-body{
  flex:1;
  padding:8px 24px 0;
  overflow-y:auto;
}
.auth-headline{font-size:26px;font-weight:700;letter-spacing:-.5px;margin-bottom:6px;margin-top:8px}
.auth-sub{font-size:14px;color:var(--text-2);margin-bottom:28px;line-height:1.5}

.auth-footer{
  padding:16px 24px calc(20px + var(--safe-bottom));
  text-align:center;
  font-size:14px;color:var(--text-2);
}
.auth-footer a{font-weight:600;color:var(--accent)}

/* ════════════════════════════════════════════
   APP CHROME
════════════════════════════════════════════ */
.topbar{
  position:sticky;top:0;z-index:50;
  background:var(--surface);border-bottom:1px solid var(--border);
  padding:10px 16px;
  padding-top:calc(10px + var(--safe-top));
  display:flex;align-items:center;justify-content:space-between;gap:8px;
}
.topbar-left{display:flex;flex-direction:column;gap:1px;min-width:0}
.topbar-eyebrow{font-size:10px;color:var(--text-3);font-weight:600;letter-spacing:.08em;text-transform:uppercase}
.event-switcher{display:flex;align-items:center;gap:5px;cursor:pointer;min-width:0}
.ev-name{font-size:18px;font-weight:600;line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ev-chevron{font-size:13px;color:var(--text-3);flex-shrink:0}
.topbar-actions{display:flex;gap:6px;flex-shrink:0}
.icon-btn{width:36px;height:36px;border-radius:50%;border:1px solid var(--border);background:var(--surface-2);display:flex;align-items:center;justify-content:center;font-size:16px;color:var(--text-2);flex-shrink:0}
.icon-btn:active{background:var(--border)}

/* Hero */
.hero{background:var(--surface);border-bottom:1px solid var(--border);padding:18px 16px 14px}
.hero-amount-row{display:flex;align-items:baseline;gap:6px;margin-bottom:2px}
.hero-amount{font-size:36px;font-weight:700;letter-spacing:-1.5px;line-height:1}
.hero-currency{font-size:16px;font-weight:500;color:var(--text-2)}
.hero-label{font-size:13px;color:var(--text-2);margin-bottom:12px}
.budget-bar-wrap{margin-bottom:12px}
.budget-bar-track{height:5px;background:var(--surface-2);border-radius:3px;overflow:hidden;margin-bottom:5px}
.budget-bar-fill{height:100%;border-radius:3px;transition:width .4s}
.budget-bar-meta{display:flex;justify-content:space-between;font-size:12px;color:var(--text-3)}
.hero-stats{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px}
.hstat{background:var(--bg);border-radius:var(--radius);padding:9px 10px}
.hstat-label{font-size:10px;color:var(--text-3);font-weight:600;margin-bottom:3px;text-transform:uppercase;letter-spacing:.05em}
.hstat-value{font-size:15px;font-weight:600}
.hstat-value.ok{color:var(--success)}
.hstat-value.warn{color:var(--warn)}
.hstat-value.danger{color:var(--danger)}

/* View toggle */
.view-toggle-wrap{background:var(--surface);border-bottom:1px solid var(--border);padding:10px 16px}
.view-toggle{display:flex;background:var(--bg);border-radius:var(--radius);padding:3px;gap:2px}
.vt-btn{flex:1;padding:7px 6px;border-radius:8px;font-size:13px;font-weight:500;color:var(--text-2);white-space:nowrap;transition:all .15s}
.vt-btn.active{background:var(--surface);color:var(--text);box-shadow:0 1px 3px rgba(0,0,0,.08)}

/* Content */
.content{flex:1;overflow-y:auto;padding-bottom:76px;padding-bottom:calc(76px + var(--safe-bottom))}

/* Section headers */
.section-header{display:flex;align-items:center;justify-content:space-between;padding:14px 16px 8px}
.section-title{font-size:11px;font-weight:600;color:var(--text-3);text-transform:uppercase;letter-spacing:.06em}
.section-value{font-size:14px;font-weight:600}

/* Month nav */
.month-nav{display:flex;align-items:center;justify-content:space-between;padding:10px 16px;background:var(--surface);border-bottom:1px solid var(--border)}
.month-nav-btn{width:34px;height:34px;border-radius:8px;border:1px solid var(--border);background:var(--surface-2);display:flex;align-items:center;justify-content:center;font-size:20px;color:var(--text-2)}
.month-nav-btn:active{background:var(--border)}
.month-nav-title{font-size:16px;font-weight:600}

/* Category cards */
.cat-list{padding:8px 16px 0;display:flex;flex-direction:column;gap:6px}
.cat-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);padding:12px 14px;display:flex;align-items:center;gap:12px;cursor:pointer}
.cat-card:active{background:var(--surface-2)}
.cat-emoji{font-size:22px;width:34px;text-align:center;flex-shrink:0}
.cat-body{flex:1;min-width:0}
.cat-name{font-size:14px;font-weight:500;margin-bottom:5px}
.cat-prog-track{height:4px;background:var(--bg);border-radius:2px;overflow:hidden}
.cat-prog-fill{height:100%;border-radius:2px}
.cat-right{text-align:right;flex-shrink:0}
.cat-spent{font-size:15px;font-weight:600}
.cat-of-budget{font-size:11px;color:var(--text-3);margin-top:2px}

/* Transactions */
.tx-group{padding:0 16px}
.tx-date-row{display:flex;align-items:center;justify-content:space-between;padding:14px 0 6px}
.tx-date-label{font-size:12px;font-weight:600;color:var(--text-3)}
.tx-date-total{font-size:13px;font-weight:600;color:var(--text-2)}
.tx-item{display:flex;align-items:center;gap:12px;padding:10px 0;border-bottom:1px solid var(--border);cursor:pointer}
.tx-item:last-child{border-bottom:none}
.tx-item:active{opacity:.7}
.tx-icon-wrap{width:38px;height:38px;border-radius:11px;background:var(--surface-2);display:flex;align-items:center;justify-content:center;font-size:20px;flex-shrink:0}
.tx-body{flex:1;min-width:0}
.tx-desc{font-size:14px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tx-meta{font-size:12px;color:var(--text-3);margin-top:2px;display:flex;align-items:center;gap:5px;flex-wrap:wrap}
.tx-tag{font-size:10px;font-weight:600;padding:1px 6px;border-radius:20px}
.tx-tag.ins{background:var(--success-bg);color:var(--success)}
.tx-tag.rec{background:var(--warn-bg);color:var(--warn)}
.tx-tag.rei{background:var(--accent-bg);color:var(--accent-text)}
.tx-right{text-align:right;flex-shrink:0}
.tx-amount{font-size:15px;font-weight:600}
.tx-paid-by{font-size:11px;color:var(--text-3);margin-top:1px}

/* Lifetime grid */
.lifetime-grid{padding:8px 16px 0;display:grid;grid-template-columns:1fr 1fr;gap:10px}
.lt-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);padding:14px 12px;cursor:pointer}
.lt-card:active{background:var(--surface-2)}
.lt-emoji{font-size:20px;margin-bottom:6px}
.lt-name{font-size:12px;color:var(--text-2);margin-bottom:4px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.lt-amount{font-size:18px;font-weight:700}
.lt-sub{font-size:11px;color:var(--text-3);margin-top:2px}
.lt-prog-track{height:3px;background:var(--bg);border-radius:2px;margin-top:10px;overflow:hidden}
.lt-prog-fill{height:100%;border-radius:2px}

/* Monthly bars */
.monthly-bars{padding:4px 16px 0;display:flex;flex-direction:column;gap:8px}
.mbar-row{display:flex;align-items:center;gap:10px}
.mbar-label{width:52px;font-size:12px;color:var(--text-3);text-align:right;font-weight:500;flex-shrink:0}
.mbar-track{flex:1;height:22px;background:var(--surface-2);border-radius:5px;overflow:hidden;cursor:pointer}
.mbar-fill{height:100%;border-radius:5px;display:flex;align-items:center;padding:0 8px;min-width:4px;background:var(--accent)}
.mbar-fill-lbl{font-size:11px;font-weight:600;color:#fff;white-space:nowrap}
.mbar-fill.light .mbar-fill-lbl{color:var(--text)}
.mbar-val{width:68px;font-size:12px;font-weight:600;color:var(--text-2);text-align:right;flex-shrink:0}

/* Insights */
.insight-card{margin:4px 16px 0;border-radius:var(--radius-lg);padding:11px 14px;display:flex;align-items:flex-start;gap:10px;font-size:13px;line-height:1.45;background:var(--accent-bg);border:1px solid var(--accent-bdr)}
.insight-card.warn-card{background:var(--warn-bg);border-color:var(--warn-bdr)}
.insight-card.danger-card{background:var(--danger-bg);border-color:var(--danger-bdr)}
.insight-card.ok-card{background:var(--success-bg);border-color:var(--success-bdr)}
.insight-icon{font-size:16px;flex-shrink:0;margin-top:1px}

/* Summary stats */
.summary-stats{display:grid;grid-template-columns:1fr 1fr;gap:8px;padding:8px 16px 4px}
.sum-stat{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);padding:12px 14px}
.sum-stat-label{font-size:11px;color:var(--text-3);font-weight:600;text-transform:uppercase;letter-spacing:.05em;margin-bottom:4px}
.sum-stat-value{font-size:18px;font-weight:700}
.sum-stat-sub{font-size:11px;color:var(--text-3);margin-top:2px}

/* Search */
.search-bar-wrap{padding:10px 16px 4px}
.search-row{display:flex;gap:8px}
.search-input{flex:1;border:1px solid var(--border);border-radius:var(--radius);padding:9px 12px;font-size:14px;background:var(--surface);color:var(--text);outline:none}
.search-input:focus{border-color:var(--accent)}
.cat-filter{border:1px solid var(--border);border-radius:var(--radius);padding:9px 8px;font-size:13px;background:var(--surface);color:var(--text-2);outline:none;max-width:120px}

/* FAB */
.fab-wrap{position:sticky;bottom:0;padding:12px 16px calc(12px + var(--safe-bottom));background:linear-gradient(to top,var(--bg) 50%,transparent);display:flex;justify-content:flex-end;pointer-events:none}
.fab{width:56px;height:56px;border-radius:28px;background:var(--brand);color:var(--surface);font-size:28px;display:flex;align-items:center;justify-content:center;pointer-events:all;box-shadow:0 4px 16px rgba(0,0,0,.2)}
.fab:active{opacity:.85;transform:scale(.93)}

/* Sheet */
.sheet-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:100;align-items:flex-end}
.sheet-overlay.open{display:flex}
.sheet{background:var(--surface);border-radius:var(--radius-xl) var(--radius-xl) 0 0;padding:0 20px calc(24px + var(--safe-bottom));width:100%;max-height:92vh;max-height:92dvh;overflow-y:auto;animation:slideUp .22s ease}
@keyframes slideUp{from{transform:translateY(100%)}to{transform:translateY(0)}}
.sheet-handle{width:40px;height:4px;background:var(--border-md);border-radius:2px;margin:14px auto 18px}
.sheet-title{font-size:18px;font-weight:600;margin-bottom:4px}
.sheet-sub{font-size:13px;color:var(--text-2);margin-bottom:16px}

/* Fields */
.field{margin-bottom:14px}
.field-label{font-size:11px;font-weight:600;color:var(--text-2);text-transform:uppercase;letter-spacing:.05em;margin-bottom:6px;display:block}
.field-input{width:100%;border:1px solid var(--border);border-radius:var(--radius);padding:11px 13px;font-size:15px;background:var(--surface-2);color:var(--text);outline:none;-webkit-appearance:none;appearance:none}
.field-input:focus{border-color:var(--accent);background:var(--surface)}
.field-row{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.field-hint{font-size:12px;color:var(--text-3);margin-top:4px}

/* Buttons */
.btn-primary{width:100%;padding:14px;border-radius:var(--radius-lg);background:var(--brand);color:var(--surface);font-size:16px;font-weight:600;margin-top:6px;border:none;display:flex;align-items:center;justify-content:center;gap:8px}
.btn-primary:active{opacity:.85}
.btn-primary:disabled{opacity:.5;cursor:not-allowed}
.btn-secondary{width:100%;padding:13px;border-radius:var(--radius-lg);border:1px solid var(--border);background:transparent;color:var(--text-2);font-size:15px;font-weight:500;margin-top:8px}
.btn-secondary:active{background:var(--surface-2)}
.btn-danger{width:100%;padding:13px;border-radius:var(--radius-lg);background:var(--danger-bg);color:var(--danger);font-size:15px;font-weight:600;margin-top:8px;border:1px solid var(--danger-bdr)}
.btn-accent{width:100%;padding:13px;border-radius:var(--radius-lg);background:var(--accent-bg);color:var(--accent-text);font-size:15px;font-weight:600;margin-top:8px;border:1px solid var(--accent-bdr)}

/* Spinner */
.spinner{width:20px;height:20px;border:2px solid rgba(255,255,255,.3);border-top-color:#fff;border-radius:50%;animation:spin .7s linear infinite;flex-shrink:0}
@keyframes spin{to{transform:rotate(360deg)}}

/* Event grid */
.event-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:18px}
.event-option{background:var(--surface-2);border:1.5px solid var(--border);border-radius:var(--radius-lg);padding:14px 12px;cursor:pointer;display:flex;flex-direction:column;gap:4px;position:relative}
.event-option:active{background:var(--accent-bg)}
.event-option.selected{border-color:var(--accent);background:var(--accent-bg)}
.eo-emoji{font-size:24px}
.eo-name{font-size:13px;font-weight:600}
.eo-count{font-size:11px;color:var(--text-3)}
.event-option.selected .eo-count{color:var(--accent-text)}
.eo-del{position:absolute;top:8px;right:8px;width:22px;height:22px;border-radius:50%;background:var(--danger-bg);color:var(--danger);font-size:12px;font-weight:700;display:flex;align-items:center;justify-content:center}

/* Cat budgets */
.cat-budget-row{display:flex;align-items:center;gap:10px;padding:8px 0;border-bottom:1px solid var(--border)}
.cat-budget-row:last-child{border-bottom:none}
.cat-budget-emoji{font-size:18px;width:28px;text-align:center}
.cat-budget-name{flex:1;font-size:14px;font-weight:500}
.cat-budget-input{width:100px;border:1px solid var(--border);border-radius:var(--radius);padding:6px 8px;font-size:14px;background:var(--surface-2);color:var(--text);outline:none;text-align:right}
.cat-budget-input:focus{border-color:var(--accent)}

/* Loading overlay */
.loading-screen{min-height:100vh;min-height:100vh;height:100dvh;display:flex;align-items:center;justify-content:center;flex-direction:column;gap:16px}
.loading-logo{font-size:40px;font-weight:700;letter-spacing:-1px}
.loading-dots{display:flex;gap:6px}
.loading-dot{width:6px;height:6px;border-radius:50%;background:var(--text-3);animation:dotPulse 1.2s infinite}
.loading-dot:nth-child(2){animation-delay:.2s}
.loading-dot:nth-child(3){animation-delay:.4s}
@keyframes dotPulse{0%,80%,100%{opacity:.2}40%{opacity:1}}

/* Empty state */
.empty-state{text-align:center;padding:36px 24px;color:var(--text-3)}
.empty-icon{font-size:38px;margin-bottom:10px;opacity:.5}
.empty-title{font-size:15px;font-weight:600;color:var(--text-2);margin-bottom:6px}
.empty-body{font-size:13px;line-height:1.5}

.divider{height:1px;background:var(--border);margin:4px 0}
.spacer{height:12px}

/* Toast */
#toast-container{position:fixed;bottom:calc(72px + var(--safe-bottom));left:50%;transform:translateX(-50%);z-index:200;display:flex;flex-direction:column;gap:8px;pointer-events:none;width:90%;max-width:380px}
.toast{background:var(--text);color:var(--surface);padding:12px 16px;border-radius:var(--radius-lg);font-size:14px;font-weight:500;text-align:center;animation:toastIn .2s ease;opacity:1;transition:opacity .3s}
.toast.out{opacity:0}
.toast.warn-toast{background:var(--warn)}
.toast.ok-toast{background:var(--success)}
@keyframes toastIn{from{transform:translateY(10px);opacity:0}to{transform:translateY(0);opacity:1}}
