:root {
  --bg-base: #0b0e14;
  --bg-surface: #141923;
  --bg-elevated: #1c2331;
  --bg-chip: #232c3d;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text-primary: #f3f6fc;
  --text-secondary: #9ba6ba;
  --text-muted: #687387;
  --accent-green: #10b981;
  --accent-green-bg: rgba(16, 185, 129, 0.14);
  --accent-amber: #f59e0b;
  --accent-amber-bg: rgba(245, 158, 11, 0.15);
  --accent-red: #ef4444;
  --accent-red-bg: rgba(239, 68, 68, 0.16);
  --accent-blue: #3b82f6;
  --accent-blue-bg: rgba(59, 130, 246, 0.16);
  --tbank-yellow: #ffdd2d;
  --sber-green: #21a038;
  --radius-lg: 18px;
  --radius-md: 13px;
  --radius-sm: 9px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(11, 14, 20, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

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

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--accent-blue-bg);
  color: #60a5fa;
  font-weight: 600;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Main Viewport */
.viewport {
  flex: 1;
  padding: 14px 14px calc(84px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.16s ease-out;
}

.tab-pane.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Hero Safe-to-Spend Card */
.hero-card {
  background: linear-gradient(155deg, #162235 0%, #121824 65%, #10151e 100%);
  border: 1px solid rgba(59, 130, 246, 0.24);
  border-radius: var(--radius-lg);
  padding: 18px 16px 16px;
  margin-bottom: 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.hero-card.danger {
  background: linear-gradient(155deg, #2b1519 0%, #16151d 70%);
  border-color: rgba(239, 68, 68, 0.35);
}

.hero-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hero-label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.hero-amount {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 8px 0 12px;
  color: var(--accent-green);
}

.hero-card.danger .hero-amount {
  color: var(--accent-red);
}

.progress-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #10b981, #34d399);
  transition: width 0.25s ease;
}

.progress-fill.warn {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.progress-fill.danger {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

.hero-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.hero-alerts {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alert-pill {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.35;
}

.alert-pill.warn {
  background: var(--accent-amber-bg);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.alert-pill.danger {
  background: var(--accent-red-bg);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-pill.good {
  background: var(--accent-green-bg);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Quick Actions */
.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.qa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.qa-btn:active {
  transform: scale(0.97);
}

.qa-expense { border-color: rgba(239, 68, 68, 0.28); }
.qa-income { border-color: rgba(16, 185, 129, 0.28); }
.qa-work { border-color: rgba(59, 130, 246, 0.28); }

/* Generic Cards & Grids */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px;
  margin-bottom: 12px;
}

.card-tbank {
  border-top: 3px solid var(--tbank-yellow);
}

.card-sber {
  border-top: 3px solid var(--sber-green);
}

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

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.section-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 14px 2px 8px;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 2px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
}

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

.mt-10 { margin-top: 10px; }
.mt-16 { margin-top: 16px; }

.stat-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
}

.stat-tile:active {
  background: var(--bg-elevated);
}

.stat-tile-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-tile-val {
  font-size: 18px;
  font-weight: 700;
}

.stat-tile-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* Formula List */
.formula-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.formula-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}

.formula-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.formula-row.total {
  padding-top: 4px;
  font-weight: 700;
  font-size: 14px;
  color: #93c5fd;
}

.formula-subitems {
  padding-left: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.val-pos { color: var(--accent-green); font-weight: 600; }
.val-neg { color: #fca5a5; font-weight: 600; }
.val-neutral { color: var(--text-primary); font-weight: 600; }

/* Pills & Buttons */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}

.pill-accent { background: var(--accent-blue-bg); color: #93c5fd; }
.pill-green { background: var(--accent-green-bg); color: #6ee7b7; }
.pill-amber { background: var(--accent-amber-bg); color: #fcd34d; }
.pill-red { background: var(--accent-red-bg); color: #fca5a5; }
.pill-muted { background: var(--bg-chip); color: var(--text-secondary); }

.btn-primary, .btn-secondary, .btn-danger, .btn-chip {
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
  padding: 10px 14px;
  font-size: 13px;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 9px 12px;
  font-size: 12.5px;
}

.btn-danger {
  background: var(--accent-red-bg);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 9px 12px;
  font-size: 12.5px;
}

.btn-sm {
  padding: 7px 11px;
  font-size: 12px;
}

.btn-chip {
  background: var(--accent-blue-bg);
  color: #93c5fd;
  padding: 5px 10px;
  font-size: 12px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* Credit Card Details */
.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0;
}

.kv-box {
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.kv-label {
  font-size: 11px;
  color: var(--text-muted);
}

.kv-val {
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
}

.carousel-box {
  background: rgba(255, 221, 45, 0.06);
  border: 1px solid rgba(255, 221, 45, 0.22);
  border-radius: var(--radius-md);
  padding: 11px;
  margin-top: 10px;
}

.tail-warning-box {
  background: var(--accent-red-bg);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-top: 10px;
  color: #fecaca;
  font-size: 12.5px;
}

/* Item Lists (Work Accruals & Transactions) */
.big-stat {
  font-size: 26px;
  font-weight: 800;
  color: #93c5fd;
}

.muted-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.muted-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.item-list {
  display: flex;
  flex-direction: column;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.list-row:last-child {
  border-bottom: none;
}

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

.list-title {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

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

.list-amt {
  font-weight: 700;
  font-size: 13.5px;
  text-align: right;
}

.mini-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filter-pills {
  display: flex;
  gap: 4px;
}

.filter-pill {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 99px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.filter-pill.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

/* Mode Toggle Button on Sinking Funds */
.mode-switch-btn {
  width: 100%;
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(59, 130, 246, 0.32);
  background: rgba(59, 130, 246, 0.1);
  color: #bfdbfe;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(15, 19, 28, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px 4px;
  cursor: pointer;
  font-family: inherit;
}

.nav-item.active {
  color: #60a5fa;
}

.nav-icon {
  font-size: 18px;
}

.nav-label {
  font-size: 11px;
  font-weight: 600;
}

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

.modal-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-strong);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
  font-weight: 500;
}

.form-input, .form-select {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions button {
  flex: 1;
  padding: 12px;
  font-size: 14px;
}

/* Auth Center Screen & Toast */
.center-card {
  margin: 48px 20px;
  padding: 28px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  text-align: center;
}

.center-icon {
  font-size: 38px;
  margin-bottom: 8px;
}

.toast {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid var(--border-strong);
  padding: 9px 16px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  max-width: 90vw;
  text-align: center;
}

