:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --green: #22c55e;
  --blue: #8b5cf6;
  --red: #e5484d;
  --amber: #d97706;
  --violet: #5b21b6;
  --purple: #8b5cf6;
  --purple-dark: #5b21b6;
  --deep: #0f172a;
  --radius: 8px;
  --shadow: 0 18px 60px rgba(17, 24, 39, 0.08);
}

body[data-theme="dark"] {
  --bg: #0f172a;
  --surface: rgba(30, 41, 59, 0.86);
  --ink: #f8fafc;
  --muted: #a5b4fc;
  --line: rgba(148, 163, 184, 0.2);
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(139, 92, 246, 0.13), transparent 30%),
    radial-gradient(circle at 86% 6%, rgba(91, 33, 182, 0.16), transparent 30%),
    linear-gradient(180deg, #f8fafc, var(--bg));
  color: var(--ink);
}
body[data-theme="dark"] {
  background:
    radial-gradient(circle at 14% 12%, rgba(139, 92, 246, 0.24), transparent 28%),
    radial-gradient(circle at 88% 4%, rgba(91, 33, 182, 0.28), transparent 32%),
    linear-gradient(180deg, #111827, #0f172a);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
body.auth-mode #appView {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  height: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
body.auth-mode {
  overflow: hidden;
}
body.app-mode #authView {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  height: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.eyebrow { margin: 0 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: 0; font-size: 0.73rem; font-weight: 800; }

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  min-width: 260px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 14px 16px;
  border-radius: var(--radius);
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 24px;
  background:
    radial-gradient(circle at 22% 20%, rgba(139, 92, 246, 0.34), transparent 24%),
    radial-gradient(circle at 82% 12%, rgba(91, 33, 182, 0.35), transparent 28%),
    radial-gradient(circle at 50% 88%, rgba(167, 139, 250, 0.18), transparent 24%),
    linear-gradient(135deg, #080b1c 0%, #0f172a 48%, #1e1b4b 100%);
}
.auth-shell::before {
  content: "";
  position: absolute;
  inset: -80px;
  background-image:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(circle at 50% 38%, black, transparent 72%);
  animation: gridFloat 16s ease-in-out infinite alternate;
}
.auth-shell::after {
  content: "";
  position: absolute;
  width: 520px;
  height: 520px;
  right: 6%;
  top: 10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(34,197,94,0.18), rgba(37,99,235,0.1) 42%, transparent 68%);
  filter: blur(18px);
  animation: pulseGlow 5.5s ease-in-out infinite;
}
.auth-shell .brand-orbit {
  position: absolute;
  width: min(52vw, 640px);
  aspect-ratio: 1;
  left: clamp(24px, 8vw, 130px);
  top: 50%;
  transform: translateY(-50%);
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.08);
  background:
    radial-gradient(circle, rgba(255,255,255,0.06), transparent 42%),
    conic-gradient(from 120deg, transparent, rgba(15,159,110,0.3), transparent, rgba(37,99,235,0.28), transparent);
  filter: blur(0.2px);
  opacity: 0.74;
  animation: slowRotate 20s linear infinite;
  pointer-events: none;
}
.auth-shell .brand-orbit::after {
  content: "";
  position: absolute;
  inset: 18%;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
}
.auth-card {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(22px, 4.6vw, 46px);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.72), rgba(15, 23, 42, 0.52)),
    radial-gradient(circle at 20% 0%, rgba(139, 92, 246, 0.28), transparent 38%);
  box-shadow: 0 32px 90px rgba(0,0,0,0.38), inset 0 1px 0 rgba(255,255,255,0.14);
  backdrop-filter: blur(26px);
  animation: cardIn 0.55s ease both;
}
.auth-logo {
  width: 82px;
  height: 82px;
  margin: 0 auto 16px;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.18);
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.22), transparent 30%),
    linear-gradient(135deg, #5b21b6, #8b5cf6 58%, #a78bfa);
  box-shadow: 0 0 38px rgba(139, 92, 246, 0.36), inset 0 1px 0 rgba(255,255,255,0.3);
  display: grid;
  place-items: center;
  transform: rotate(-4deg);
  animation: logoFloat 4s ease-in-out infinite;
}
.auth-logo span {
  color: white;
  font-size: 1.72rem;
  font-weight: 900;
  text-shadow: 0 0 18px rgba(255,255,255,0.34);
  transform: rotate(4deg);
}
.auth-heading { text-align: center; margin-bottom: 22px; color: white; }
.auth-heading h1 {
  margin: 0;
  font-size: 3rem;
  line-height: 1;
  color: #f8fafc;
  text-shadow: 0 0 34px rgba(139, 92, 246, 0.42);
}
.auth-heading p { margin: 10px 0 0; color: rgba(248,250,252,0.66); font-size: 0.9rem; }
.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 4px;
  border-radius: 14px;
  background: rgba(255,255,255,0.08);
  margin-bottom: 24px;
}
.tab-btn {
  border: 0;
  border-radius: 11px;
  padding: 11px 8px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}
.tab-btn { color: rgba(255,255,255,0.62); }
.tab-btn.active { background: linear-gradient(135deg, #5b21b6, #8b5cf6); color: white; box-shadow: 0 12px 30px rgba(139,92,246,0.28); }
.auth-form { display: grid; gap: 16px; animation: fade 0.25s ease; }
.auth-form h2 { margin: 0 0 4px; font-size: 1.45rem; color: white; }
.auth-form h2::after {
  content: "";
  display: block;
  width: 64px;
  height: 4px;
  margin-top: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #5b21b6, #a78bfa);
  box-shadow: 0 0 22px rgba(139,92,246,0.34);
}

label { display: grid; gap: 7px; color: var(--ink); font-size: 0.9rem; font-weight: 700; }
.auth-card label { color: rgba(255,255,255,0.76); }
input, select {
  width: 100%;
  border: 1px solid rgba(148,163,184,0.32);
  border-radius: var(--radius);
  padding: 12px 13px;
  outline: none;
  background: rgba(255,255,255,0.84);
  color: var(--ink);
  transition: border 0.2s ease, box-shadow 0.2s ease;
}
.auth-card input { background: rgba(255,255,255,0.1); color: white; border-color: rgba(255,255,255,0.18); }
.auth-card input:focus { border-color: #a78bfa; box-shadow: 0 0 0 4px rgba(139,92,246,0.18); }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(139,92,246,0.14); }

.primary-btn, .secondary-btn, .ghost-btn, .icon-btn {
  border: 0;
  border-radius: var(--radius);
  min-height: 44px;
  padding: 0 16px;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s ease;
}
.primary-btn {
  background: linear-gradient(135deg, #5b21b6, #8b5cf6 58%, #a78bfa);
  color: white;
  box-shadow: 0 14px 34px rgba(139,92,246,0.3);
  position: relative;
  overflow: hidden;
}
.primary-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.26), transparent);
  transform: translateX(-120%);
  transition: transform 0.55s ease;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 18px 34px rgba(139,92,246,0.38); }
.primary-btn:hover::after { transform: translateX(120%); }
.secondary-btn { background: #e9f3ff; color: #1453bf; }
.ghost-btn, .icon-btn { background: #f3f4f6; color: var(--ink); }
.secondary-btn:hover, .ghost-btn:hover, .icon-btn:hover, .mini-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(15,23,42,0.1);
}
body[data-theme="dark"] .ghost-btn,
body[data-theme="dark"] .icon-btn {
  background: rgba(255,255,255,0.08);
  color: #f8fafc;
  border: 1px solid rgba(255,255,255,0.08);
}
.token-box { padding: 12px; border-radius: var(--radius); background: #ecfdf5; color: #047857; font-size: 0.88rem; overflow-wrap: anywhere; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background:
    radial-gradient(circle at 20% 0%, rgba(139,92,246,0.26), transparent 32%),
    linear-gradient(180deg, #1e1b4b, #0f172a);
  color: white;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo span {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #22c55e, #2563eb);
  font-weight: 900;
}
.logo strong, .logo small { display: block; }
.logo small { color: rgba(255,255,255,0.62); margin-top: 3px; }
.profile-summary {
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 10px;
  background: rgba(255,255,255,0.07);
  color: white;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}
.profile-summary:hover {
  background: rgba(255,255,255,0.11);
}
.profile-summary img,
.profile-photo-editor img {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  object-fit: cover;
  flex: 0 0 auto;
  background: rgba(255,255,255,0.12);
}
.profile-summary span,
.profile-summary strong,
.profile-summary small { display: block; min-width: 0; }
.profile-summary strong {
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-summary small {
  color: rgba(255,255,255,0.62);
  font-size: 0.75rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar nav { display: grid; gap: 8px; }
.nav-btn {
  border: 0;
  border-radius: var(--radius);
  padding: 13px 14px;
  background: transparent;
  color: rgba(255,255,255,0.72);
  text-align: left;
  font-weight: 800;
}
.nav-btn.active, .nav-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-btn.active {
  box-shadow: inset 3px 0 0 #a78bfa, 0 10px 30px rgba(139,92,246,0.14);
}
.workspace { min-width: 0; padding: 24px; }
.view-enter {
  animation: viewEnter 0.32s ease both;
}
.workspace::before {
  content: "";
  position: fixed;
  right: -160px;
  top: 110px;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(37,99,235,0.13), transparent 68%);
  pointer-events: none;
  z-index: -1;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
.topbar h2 { margin: 0; font-size: clamp(1.5rem, 3vw, 2.3rem); }
.top-greeting {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.top-greeting img {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  object-fit: cover;
  background: rgba(148,163,184,0.16);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.top-actions input { width: 156px; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}
.metric-card, .chart-panel, .ai-panel, .panel-form, .table-panel, .split-panel, .score-card, .habit-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  animation: panelRise 0.45s ease both;
}
body[data-theme="dark"] .metric-card,
body[data-theme="dark"] .chart-panel,
body[data-theme="dark"] .ai-panel,
body[data-theme="dark"] .panel-form,
body[data-theme="dark"] .table-panel,
body[data-theme="dark"] .split-panel,
body[data-theme="dark"] .score-card,
body[data-theme="dark"] .habit-panel,
body[data-theme="dark"] .help-card {
  background: linear-gradient(180deg, rgba(30,41,59,0.92), rgba(15,23,42,0.86));
  backdrop-filter: blur(18px);
}
.metric-card:hover, .chart-panel:hover, .ai-panel:hover, .panel-form:hover, .table-panel:hover, .split-panel:hover, .score-card:hover, .habit-panel:hover {
  transform: translateY(-2px);
  border-color: rgba(139,92,246,0.24);
  box-shadow: 0 22px 70px rgba(17, 24, 39, 0.11);
}
.metric-card { padding: 18px; display: grid; gap: 8px; min-height: 132px; overflow: hidden; position: relative; }
.metric-card::after {
  content: "";
  position: absolute;
  width: 120px;
  height: 120px;
  right: -54px;
  top: -54px;
  border-radius: 50%;
  background: rgba(139,92,246,0.1);
}
.metric-card span { color: var(--muted); font-weight: 800; font-size: 0.84rem; }
.metric-card strong { font-size: clamp(1.45rem, 2.7vw, 2rem); letter-spacing: 0; overflow-wrap: anywhere; }
.metric-card strong,
.section-title strong {
  animation: softGlowText 3.2s ease-in-out infinite;
}
.metric-card small { color: var(--muted); }
.metric-card.income { border-top: 4px solid var(--green); }
.metric-card.spent { border-top: 4px solid var(--red); }
.metric-card.balance { border-top: 4px solid var(--blue); }
.metric-card.portfolio { border-top: 4px solid #14b8a6; }
.metric-card.health { border-top: 4px solid var(--violet); }

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.score-card {
  padding: 16px;
  display: grid;
  gap: 9px;
}
.score-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}
.score-card strong {
  font-size: 1.35rem;
}
.score-track {
  height: 9px;
  border-radius: 999px;
  background: rgba(148,163,184,0.16);
  overflow: hidden;
}
.score-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  transition: width 0.25s ease;
}
.spending-score .score-track span { background: linear-gradient(90deg, #22c55e, #14b8a6); }
.wealth-score .score-track span { background: linear-gradient(90deg, #14b8a6, #8b5cf6); }
.overall-score .score-track span { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }

.investment-overview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.investment-stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background:
    linear-gradient(135deg, rgba(34,197,94,0.08), transparent 48%),
    var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  gap: 7px;
  overflow: hidden;
  position: relative;
}
.investment-stat::after {
  content: "";
  position: absolute;
  width: 96px;
  height: 96px;
  right: -44px;
  top: -48px;
  border-radius: 50%;
  background: rgba(34,197,94,0.12);
}
.investment-stat span { color: var(--muted); font-weight: 800; font-size: 0.78rem; text-transform: uppercase; }
.investment-stat strong { font-size: 1.35rem; position: relative; z-index: 1; }
.investment-stat small { color: var(--muted); line-height: 1.45; position: relative; z-index: 1; }
.negative-value { color: var(--red); }

.insights-row, .charts-grid, .forms-grid, .planning-grid, .expense-split-grid {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}
.insights-row { grid-template-columns: 1.4fr 0.8fr; }
.expense-split-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.charts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.forms-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.forms-grid.single-form { grid-template-columns: minmax(280px, 620px); }
.planning-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wide { grid-column: 1 / -1; }
.ai-panel, .chart-panel, .panel-form, .table-panel { padding: 18px; }
.split-panel {
  padding: 18px;
  overflow: hidden;
  position: relative;
}
.split-panel::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -78px;
  top: -92px;
  border-radius: 50%;
  opacity: 0.12;
}
.necessary-panel { border-top: 4px solid #22c55e; }
.unnecessary-panel { border-top: 4px solid #e5484d; }
.necessary-panel::after { background: #22c55e; }
.unnecessary-panel::after { background: #e5484d; }
.necessary-panel .section-title strong { color: #16a34a; }
.unnecessary-panel .section-title strong { color: #e5484d; }
.expense-card-list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 2px;
}
.dashboard-expense-card,
.empty-expense-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(248,250,252,0.72);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  animation: listIn 0.35s ease both;
}
.dashboard-expense-card:hover {
  transform: translateX(3px);
  box-shadow: 0 12px 32px rgba(15,23,42,0.08);
}
.dashboard-expense-card strong,
.dashboard-expense-card span { display: block; }
.dashboard-expense-card strong { font-size: 0.95rem; }
.dashboard-expense-card span { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.dashboard-expense-card b { white-space: nowrap; font-size: 0.95rem; }
.dashboard-expense-card.necessary { border-left: 4px solid #22c55e; }
.dashboard-expense-card.unnecessary { border-left: 4px solid #e5484d; }
.dashboard-expense-card.necessary b { color: #16a34a; }
.dashboard-expense-card.unnecessary b { color: #e5484d; }
.empty-expense-card.necessary { color: #16a34a; background: rgba(34,197,94,0.08); }
.empty-expense-card.unnecessary { color: #e5484d; background: rgba(229,72,77,0.08); }
body[data-theme="dark"] .dashboard-expense-card,
body[data-theme="dark"] .empty-expense-card,
body[data-theme="dark"] .habit-card,
body[data-theme="dark"] .empty-habit {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.08);
}
.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.section-title h3, .panel-form h3 { margin: 0; font-size: 1.08rem; }
.ai-list { display: grid; gap: 10px; }
.ai-item {
  padding: 12px;
  border-radius: var(--radius);
  background: #f8fafc;
  border: 1px solid #edf2f7;
  line-height: 1.5;
  animation: listIn 0.35s ease both;
}
body[data-theme="dark"] .ai-item,
body[data-theme="dark"] .stack-card,
body[data-theme="dark"] .chip,
body[data-theme="dark"] .segmented label,
body[data-theme="dark"] .mini-btn {
  background: rgba(255,255,255,0.06);
  color: #f8fafc;
  border-color: rgba(255,255,255,0.09);
}
body[data-theme="dark"] input,
body[data-theme="dark"] select {
  background: rgba(15,23,42,0.78);
  color: #f8fafc;
  border-color: rgba(148,163,184,0.22);
}
body[data-theme="dark"] table th,
body[data-theme="dark"] table td {
  border-color: rgba(148,163,184,0.16);
}
.ai-item.alert { border-left: 4px solid var(--amber); }
.ai-item.tip { border-left: 4px solid var(--green); }
.avoid-card {
  padding: 13px;
  border-radius: var(--radius);
  border: 1px solid rgba(229,72,77,0.2);
  background: rgba(229,72,77,0.08);
  display: grid;
  gap: 10px;
}
.avoid-card strong { font-size: 0.92rem; }
.avoid-card div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.avoid-card span {
  padding: 7px 9px;
  border-radius: 999px;
  background: rgba(229,72,77,0.1);
  color: #e5484d;
  font-size: 0.78rem;
  font-weight: 800;
}
.comparison-card {
  display: grid;
  gap: 14px;
  min-height: 210px;
}
.comparison-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 12px;
}
.comparison-row strong,
.comparison-row span { display: block; }
.comparison-row strong { font-size: 0.86rem; }
.comparison-row span { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }
.comparison-row b { font-size: 0.88rem; color: var(--muted); }
.comparison-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(148,163,184,0.16);
  overflow: hidden;
}
.comparison-track span {
  display: block;
  height: 100%;
  min-width: 4px;
  border-radius: inherit;
}
.comparison-track .necessary { background: linear-gradient(90deg, #16a34a, #22c55e); }
.comparison-track .unnecessary { background: linear-gradient(90deg, #be123c, #e5484d); }
.comparison-impact {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(34,197,94,0.22);
  background: rgba(34,197,94,0.08);
  display: grid;
  gap: 4px;
}
.comparison-impact span,
.comparison-impact small { color: var(--muted); }
.comparison-impact strong { font-size: 1.4rem; color: #16a34a; }
.comparison-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.comparison-breakdown span {
  padding: 9px;
  border-radius: 6px;
  background: rgba(148,163,184,0.1);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}
.habit-panel {
  padding: 18px;
  margin-top: 14px;
}
.habit-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.habit-card,
.empty-habit {
  border: 1px solid rgba(148,163,184,0.16);
  border-radius: var(--radius);
  padding: 13px;
  background: rgba(248,250,252,0.7);
}
.habit-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.habit-head strong,
.habit-head span { display: block; }
.habit-head strong { font-size: 0.94rem; }
.habit-head span { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }
.habit-head b { white-space: nowrap; color: var(--red); }
.habit-months {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
  align-items: end;
  min-height: 64px;
}
.habit-months span {
  display: grid;
  gap: 5px;
  align-items: end;
  justify-items: center;
}
.habit-months i {
  display: block;
  width: 100%;
  max-width: 22px;
  border-radius: 999px 999px 3px 3px;
  background: linear-gradient(180deg, #e5484d, #d97706);
}
.habit-months small {
  color: var(--muted);
  font-size: 0.68rem;
}
.empty-habit {
  grid-column: 1 / -1;
  color: var(--muted);
}
canvas { width: 100%; display: block; }

.panel-form { display: grid; gap: 13px; }
.panel-form h3 {
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(229,231,235,0.8);
}
.two-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.segmented label {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 11px;
  font-size: 0.84rem;
  background: #f9fafb;
}
.segmented input { width: auto; }
.chip-list { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 10px;
  background: #f3f4f6;
  color: #374151;
  font-weight: 700;
  font-size: 0.82rem;
}
.chip button, .text-danger {
  border: 0;
  background: transparent;
  color: var(--red);
  font-weight: 900;
  padding: 0;
}

.table-panel { margin-top: 14px; }
.table-wrap { width: 100%; overflow-x: auto; }
.table-wrap { -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
th { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mini-btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 0.78rem;
  font-weight: 800;
}
.mini-btn.danger { color: var(--red); }
.status { border-radius: 999px; padding: 6px 9px; font-size: 0.76rem; font-weight: 900; }
.status.ok { background: #dcfce7; color: #047857; }
.status.bad { background: #fee2e2; color: #b91c1c; }
.stack-list { display: grid; gap: 10px; }
.stack-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  display: grid;
  gap: 8px;
  background: #fbfdff;
}
.progress {
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--blue)); }
.investment-list {
  display: grid;
  gap: 12px;
}
.investment-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fbfdff;
  display: grid;
  gap: 12px;
  border-left: 4px solid var(--muted);
}
.investment-card.positive { border-left-color: var(--green); }
.investment-card.negative { border-left-color: var(--red); }
.investment-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.investment-card-head strong,
.investment-card-head span { display: block; }
.investment-card-head span { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }
.investment-card-head b { color: var(--green); white-space: nowrap; }
.investment-card.negative .investment-card-head b { color: var(--red); }
.investment-card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.profile-layout {
  max-width: 720px;
}
.profile-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.profile-form {
  display: grid;
  gap: 14px;
}
.toggle-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(148,163,184,0.08);
}
.toggle-line input {
  width: auto;
}
.profile-photo-editor {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(148,163,184,0.08);
}
.profile-photo-editor img {
  width: 96px;
  height: 96px;
}
.profile-photo-editor > div {
  display: grid;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
body[data-theme="dark"] .investment-stat,
body[data-theme="dark"] .investment-card,
body[data-theme="dark"] .profile-panel {
  background:
    linear-gradient(135deg, rgba(34,197,94,0.08), transparent 48%),
    rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.09);
}
body[data-theme="dark"] .profile-photo-editor {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.09);
}

.help-hero {
  padding: clamp(24px, 5vw, 52px);
  border-radius: 18px;
  color: white;
  background:
    radial-gradient(circle at 82% 10%, rgba(167,139,250,0.28), transparent 30%),
    linear-gradient(135deg, #0f172a, #5b21b6 58%, #1e1b4b);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.18);
  overflow: hidden;
  position: relative;
}
.help-hero::after {
  content: "";
  position: absolute;
  width: 220px;
  height: 220px;
  right: -60px;
  bottom: -80px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: 0 0 80px rgba(34,197,94,0.18);
}
.help-hero h3 { margin: 6px 0 8px; font-size: clamp(1.8rem, 4vw, 3rem); }
.help-hero p { max-width: 620px; margin: 0; color: rgba(255,255,255,0.76); line-height: 1.7; }
.help-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.help-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.88);
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
}
.help-card strong { color: var(--muted); text-transform: uppercase; font-size: 0.78rem; }
.help-card span { font-size: 1.08rem; font-weight: 800; overflow-wrap: anywhere; }

@keyframes fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slowRotate {
  to { transform: translateY(-50%) rotate(360deg); }
}
@keyframes pulseGlow {
  0%, 100% { opacity: 0.55; transform: scale(0.96); }
  50% { opacity: 0.95; transform: scale(1.04); }
}
@keyframes gridFloat {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(28px, 22px, 0); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes floatUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes logoFloat {
  0%, 100% { transform: translateY(0) rotate(-4deg); box-shadow: 0 0 34px rgba(139, 92, 246, 0.34), inset 0 1px 0 rgba(255,255,255,0.3); }
  50% { transform: translateY(-5px) rotate(-4deg); box-shadow: 0 0 54px rgba(139, 92, 246, 0.5), inset 0 1px 0 rgba(255,255,255,0.34); }
}
@keyframes panelRise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes listIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes softGlowText {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(139,92,246,0)); }
  50% { filter: drop-shadow(0 0 9px rgba(139,92,246,0.16)); }
}
@keyframes viewEnter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1100px) {
  .summary-grid, .forms-grid, .investment-overview, .score-grid, .habit-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .insights-row, .charts-grid, .expense-split-grid { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .app-shell {
    display: block !important;
    min-height: 100vh;
  }
  .sidebar {
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 10px 12px !important;
    border-radius: 0 0 18px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    z-index: 20;
    box-shadow: 0 14px 44px rgba(0,0,0,0.22);
    backdrop-filter: blur(18px);
  }
  .logo { display: none; }
  .profile-summary { display: none !important; }
  .sidebar nav {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .nav-btn {
    min-width: max-content;
    min-height: 42px;
    padding: 8px 14px;
    text-align: center;
    white-space: nowrap;
    font-size: 0.78rem;
  }
  .nav-btn.active {
    box-shadow: inset 0 -3px 0 #a78bfa, 0 8px 22px rgba(139,92,246,0.18);
  }
  .workspace {
    padding: 16px;
  }
}

@media (max-width: 820px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-shell { min-height: 100vh; padding: 18px; }
  .auth-card { width: 100%; max-width: 430px; padding: 24px; }
  .auth-logo { width: 72px; height: 72px; border-radius: 18px; }
  .auth-logo span { font-size: 1.5rem; }
  .auth-heading h1 { font-size: 2.4rem; }
  .nav-btn {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 0.74rem;
  }
  .workspace { padding: 14px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .summary-grid, .forms-grid, .planning-grid, .two-cols, .investment-overview, .investment-card-grid, .comparison-breakdown, .score-grid, .habit-list { grid-template-columns: 1fr; }
  .comparison-row { grid-template-columns: 1fr; }
  .profile-photo-editor { align-items: flex-start; flex-direction: column; }
  .help-grid { grid-template-columns: 1fr; }
  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }
  .top-actions input { grid-column: 1 / -1; }
  .top-actions input, .top-actions a, .top-actions button { width: 100%; min-width: 0; }
  table { min-width: 620px; }
  .toast {
    top: 10px;
    right: 10px;
    left: 10px;
    min-width: 0;
    max-width: none;
  }
}

@media (max-width: 460px) {
  .sidebar { padding: 8px !important; }
  .nav-btn { min-height: 38px; padding: 7px 10px; font-size: 0.68rem; }
  .summary-grid { gap: 10px; }
  .metric-card, .chart-panel, .ai-panel, .panel-form, .table-panel, .split-panel, .score-card, .habit-panel { padding: 14px; }
  .dashboard-expense-card { align-items: flex-start; flex-direction: column; }
  .dashboard-expense-card b { align-self: flex-end; }
  .auth-card { padding: 20px; border-radius: 20px; }
  .auth-tabs { margin-bottom: 18px; }
  .auth-heading p { font-size: 0.8rem; }
}
