/* Moneyflow — dark fintech design system.
   Palette: trust blue + profit green on dark (ui-ux-pro-max "Personal Finance Tracker"). */

:root {
  --primary: #1E40AF;
  --primary-light: #3B82F6;
  --accent: #059669;      /* income / positive */
  --destructive: #DC2626; /* expense / negative */
  --warning: #D97706;

  --bg: #0F172A;
  --fg: #FFFFFF;
  --card: #192134;
  --card-fg: #FFFFFF;
  --muted-fg: #94A3B8;
  --border: rgba(255, 255, 255, 0.08);

  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

.page { display: none; }
.page.active { display: block; }

/* ── Header ─────────────────────────────────────────── */

.header {
  padding: calc(16px + env(safe-area-inset-top, 0px)) 20px 14px;
  background: linear-gradient(180deg, rgba(30, 64, 175, 0.35), transparent);
}

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

.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 20px; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }

.header-sub { margin-top: 4px; font-size: 13px; color: var(--muted-fg); }

.me-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
}

.me-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.me-name { font-size: 13px; font-weight: 600; }

/* ── Content ────────────────────────────────────────── */

.content { padding: 4px 16px 24px; }

.loading { display: flex; justify-content: center; padding: 60px 0; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--muted-fg); padding: 60px 20px; font-size: 14px; }

.not-onboarded {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  color: var(--muted-fg);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

/* ── Balance cards ──────────────────────────────────── */

.cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.balance-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  position: relative;
  overflow: hidden;
}

.balance-card.is-me {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary-light) inset, 0 8px 20px -12px rgba(59, 130, 246, 0.6);
}

.balance-card .card-icon { font-size: 18px; margin-bottom: 6px; display: block; }
.balance-card .card-label {
  font-size: 12px;
  color: var(--muted-fg);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.balance-card .card-me-tag {
  font-size: 10px;
  color: var(--primary-light);
  font-weight: 700;
  margin-left: 4px;
}
.balance-card .card-amount {
  margin-top: 6px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.balance-card .card-amount.negative { color: var(--destructive); }

/* ── Lifestyle card ("Питание и быт") ──────────────────── */

.lifestyle-card {
  margin-bottom: 16px;
}

.lifestyle-card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.lifestyle-card-top .card-icon { margin-bottom: 0; }
.lifestyle-card-top .card-label { flex: 1; }

/* Small "факт" tag reinforcing that the big number above is real money, not
   a projection — mirrors the "ПРОГНОЗ" badge on the plan row below. */
.lifestyle-real-tag {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--accent);
  border: 1px solid rgba(5, 150, 105, 0.4);
  background: rgba(5, 150, 105, 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  text-transform: uppercase;
}

.lifestyle-amount-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.lifestyle-balance-btn {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--muted-fg);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 999px;
  cursor: pointer;
}
.lifestyle-balance-btn:hover { color: var(--fg); border-color: var(--primary-light); }

/* Forecast row — visually boxed off with a dashed border + muted colours so
   it never reads like part of the real balance above it. */
.lifestyle-forecast-box {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.lifestyle-forecast-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-fg);
}

.forecast-badge {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--muted-fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.lifestyle-plan-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--primary-light);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}
.lifestyle-plan-btn:hover { text-decoration: underline; }

.lifestyle-rate-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.lifestyle-rate-label { font-size: 12px; color: var(--muted-fg); }

.lifestyle-rate-input {
  width: 76px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 6px 8px;
  text-align: right;
  outline: none;
}
.lifestyle-rate-input:focus { border-color: var(--primary-light); }

/* ── Essential subcategories panel ─────────────────────── */

.essential-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.essential-summary {
  padding: 0 16px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--warning);
}
.essential-summary.all-closed { color: var(--accent); }
.essential-summary:empty { display: none; }

.essential-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  padding: 14px 16px;
  cursor: pointer;
}

.chevron { color: var(--muted-fg); transition: transform 0.2s ease; }
.chevron.open { transform: rotate(180deg); }

.essential-month { color: var(--muted-fg); font-weight: 400; text-transform: capitalize; }

.essential-header-row { display: flex; align-items: center; }
.essential-header-row .essential-toggle { flex: 1; }
.essential-gear-btn {
  background: none;
  border: none;
  color: var(--muted-fg);
  font-size: 16px;
  padding: 14px 16px 14px 4px;
  cursor: pointer;
}
.essential-gear-btn:hover { color: var(--fg); }

.essential-list { display: none; padding: 0 16px 14px; }
.essential-list.open { display: block; }

.category-row { padding: 10px 0; border-top: 1px solid var(--border); }
.category-row:first-child { border-top: none; }
.category-row.closed .category-figures { color: var(--accent); }

.category-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}
.category-name { font-weight: 500; }
.category-figures { color: var(--muted-fg); }

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 999px; background: var(--primary-light); }
.progress-fill.warn { background: var(--warning); }
.progress-fill.closed { background: var(--accent); }
.progress-fill.over { background: var(--destructive); }

/* ── Action buttons ─────────────────────────────────── */

.actions-row { display: flex; gap: 10px; margin-bottom: 8px; }

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
}
.action-icon { font-size: 16px; }
.action-income { background: var(--accent); }
.action-expense { background: var(--destructive); }

/* ── History ────────────────────────────────────────── */

.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
}

.history-main { flex: 1; min-width: 0; }
.history-title { font-size: 14px; font-weight: 600; }
.history-sub { font-size: 12px; color: var(--muted-fg); margin-top: 2px; }

.history-amount { font-size: 15px; font-weight: 700; white-space: nowrap; }
.history-amount.positive { color: var(--accent); }
.history-amount.negative { color: var(--destructive); }

.status-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.status-badge.pending { background: rgba(217, 119, 6, 0.2); color: var(--warning); }
.status-badge.confirmed { background: rgba(5, 150, 105, 0.2); color: var(--accent); }
.status-badge.rejected { background: rgba(220, 38, 38, 0.2); color: var(--destructive); }

/* ── Bottom nav ─────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--muted-fg);
  font-size: 11px;
  font-weight: 600;
  padding: 4px;
  cursor: pointer;
}
.nav-btn.active { color: var(--primary-light); }
.nav-icon { font-size: 18px; }

/* ── Modals ─────────────────────────────────────────── */

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 50;
  align-items: flex-end;
}
.overlay.open { display: flex; }

.modal {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  animation: slide-up 0.22s ease-out;
}
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 18px 10px;
  font-size: 16px;
  font-weight: 700;
}
.modal-close {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--fg);
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
}

.modal-body { padding: 4px 18px 18px; }

/* Banners at the top of income/forecast/correction modals — the primary fix
   for the real-income-vs-plan mixup: colour + copy make it hard to miss
   which kind of modal you're in before you type a number. */
.modal-banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 4px;
}
.modal-banner.real {
  background: rgba(5, 150, 105, 0.15);
  border: 1px solid rgba(5, 150, 105, 0.45);
  color: #34D399;
}
.modal-banner.forecast {
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed var(--border);
  color: var(--muted-fg);
  font-weight: 500;
}
.modal-banner.info {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: var(--primary-light);
  font-weight: 500;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-fg);
  margin: 14px 0 6px;
}
.field-label:first-child { margin-top: 0; }

.field-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 15px;
  font-family: inherit;
  padding: 12px 14px;
  outline: none;
}
.field-input:focus { border-color: var(--primary-light); }
textarea.field-input { resize: vertical; min-height: 44px; }

.hint { font-size: 12px; color: var(--warning); margin-top: 8px; line-height: 1.4; }
.field-error { color: var(--destructive); font-size: 13px; margin-top: 10px; min-height: 0; }

.submit-btn {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.submit-btn:disabled { opacity: 0.5; cursor: default; }

.direction-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.direction-opt {
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--fg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.direction-opt.selected { border-color: var(--primary-light); background: rgba(59, 130, 246, 0.15); }
.direction-opt.disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Manage categories & percentages ───────────────────── */

.manage-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }

.manage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.manage-name-input {
  flex: 2;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--fg);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  padding: 8px 8px;
  outline: none;
}
.manage-name-input:focus { border-color: var(--primary-light); background: rgba(255, 255, 255, 0.04); }

.manage-amount-input {
  flex: 1;
  min-width: 0;
  width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted-fg);
  font-size: 14px;
  font-family: inherit;
  padding: 8px 8px;
  outline: none;
  text-align: right;
}
.manage-amount-input:focus { border-color: var(--primary-light); background: rgba(255, 255, 255, 0.04); color: var(--fg); }

.manage-delete-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted-fg);
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
}
.manage-delete-btn:hover { color: var(--destructive); background: rgba(220, 38, 38, 0.12); }

.manage-add-row { display: flex; gap: 8px; margin-top: 14px; }
.manage-add-row .field-input { margin: 0; }
#new-cat-name { flex: 2; }
#new-cat-amount { flex: 1; min-width: 0; }

.secondary-btn { background: rgba(255, 255, 255, 0.08); margin-top: 10px; }

.manage-divider { height: 1px; background: var(--border); margin: 20px 0; }

.pct-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.pct-grid .field-label { margin: 0 0 6px; }

/* ── Income result ──────────────────────────────────── */

.split-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.split-row:first-child { border-top: none; }
.split-amount { font-weight: 700; color: var(--accent); }

/* ── Toast ──────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px);
  background: #1E293B;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 100;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
