:root {
  --bg: #080d1a;
  --surface: #111827;
  --surface-2: #1a2335;
  --border: rgba(148, 163, 184, 0.16);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.14);
  --blue: #38bdf8;
  --purple: #a78bfa;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  line-height: 1.45;
  min-height: 100%;
}

.num {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* Auth Screen */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-row img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.brand-row h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

/* App Shell */
.app-shell {
  max-width: 820px;
  margin: 0 auto;
  padding: 14px 14px calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-left img {
  width: 30px;
  height: 30px;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.month-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.muted {
  color: var(--muted);
  font-size: 0.82rem;
}

/* Hero Safe-to-Spend */
.hero-card {
  background: linear-gradient(145deg, #111b2e 0%, #0d1525 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 12px;
}

.hero-card.state-green { border-color: rgba(52, 211, 153, 0.35); }
.hero-card.state-amber { border-color: rgba(251, 191, 36, 0.35); }
.hero-card.state-red { border-color: rgba(248, 113, 113, 0.4); }

.mode-switch {
  display: inline-flex;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 3px;
}

.mode-switch button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.mode-switch button.active {
  background: var(--surface-2);
  color: var(--text);
}

.hero-value {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 8px 0 4px;
}

.state-green .hero-value { color: var(--green); }
.state-amber .hero-value { color: var(--amber); }
.state-red .hero-value { color: var(--red); }

.hero-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
}

.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }

.breakdown-list {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
}

/* Grid stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

@media (min-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

.stat-label {
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-val {
  font-size: 1.05rem;
  font-weight: 700;
}

/* Progress bars */
.prog-item {
  margin-bottom: 12px;
}
.prog-item:last-child { margin-bottom: 0; }

.prog-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  margin-bottom: 5px;
}

.prog-track {
  height: 8px;
  background: #0f172a;
  border-radius: 999px;
  overflow: hidden;
}

.prog-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Rows / Lists */
.list-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 12px;
}

.item-main {
  min-width: 0;
  flex: 1;
}

.item-title {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-sub {
  font-size: 0.76rem;
  color: var(--muted);
}

.item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Forms & Buttons */
label.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 12px;
}

input, select {
  width: 100%;
  background: #0b1220;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 0.95rem;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--blue);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 42px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #0ea5e9);
  color: #03151e;
}

.btn-sm {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.78rem;
  border-radius: 8px;
}

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
}

.btn-block {
  width: 100%;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.cat-pill {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.cat-pill.active {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
}

/* Rent Simulator */
.range-wrap {
  margin: 10px 0 14px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--green);
}

.sim-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.sim-box {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
}

/* Floating Action Button & Bottom Nav */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 40;
  border: none;
  border-radius: 999px;
  padding: 13px 18px;
  font-size: 0.92rem;
  font-weight: 700;
  background: linear-gradient(135deg, #34d399, #38bdf8);
  color: #04131c;
  box-shadow: 0 10px 30px rgba(16, 185, 129, 0.35);
  cursor: pointer;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  background: rgba(11, 17, 32, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px 4px;
  font-size: 0.74rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

.nav-btn.active {
  color: var(--green);
}

.nav-icon {
  font-size: 1.15rem;
}

/* Modal / Bottom Sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
}

@media (min-width: 640px) {
  .modal-sheet {
    border-radius: 20px;
    padding: 22px;
  }
}

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

.error-msg {
  color: var(--red);
  font-size: 0.84rem;
  margin: 6px 0;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
