/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ══ LIGHT MODE — high-specificity element overrides ══════════════ */
html[data-theme="light"] body {
  background-image:
    radial-gradient(ellipse 80% 50% at 5% 0%,   rgba(99,102,241,.07) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 95% 100%, rgba(139,92,246,.05) 0%, transparent 50%);
}

/* Sidebar */
html[data-theme="light"] .sidebar         { background: linear-gradient(180deg,#f4f5ff 0%,#eceffe 100%); border-right-color: rgba(99,102,241,.14); }
html[data-theme="light"] .sidebar-logo    { border-bottom-color: rgba(99,102,241,.1); }
html[data-theme="light"] .sidebar-footer  { background: rgba(99,102,241,.05); border-top-color: rgba(99,102,241,.1); }
html[data-theme="light"] .logo-text       { background: linear-gradient(135deg,#1e1b4b 20%,#6366f1 100%); -webkit-background-clip:text; background-clip:text; }
html[data-theme="light"] .nav-item        { color: #475569; }
html[data-theme="light"] .nav-item:hover  { background: rgba(99,102,241,.08); color: #1e1b4b; }
html[data-theme="light"] .nav-item.active { background: rgba(99,102,241,.14); border-color: rgba(99,102,241,.28); color: #4338ca; }
html[data-theme="light"] .user-name       { color: #0f172a; }

/* Topbar */
html[data-theme="light"] .topbar          { background: rgba(248,249,255,.94); border-bottom-color: rgba(99,102,241,.1); }
html[data-theme="light"] .conn-status     { background: #fff; border-color: rgba(99,102,241,.16); box-shadow: 0 1px 8px rgba(99,102,241,.1); }
html[data-theme="light"] .theme-btn       { background: #fff; border-color: rgba(99,102,241,.18); }

/* Demo banner */
html[data-theme="light"] .demo-banner { background: linear-gradient(90deg,rgba(251,191,36,.07),transparent); border-bottom-color: rgba(251,191,36,.22); }

/* KPI stat cards */
html[data-theme="light"] .card--blue   { background: linear-gradient(150deg,#eef2ff 0%,#dde5ff 100%); border-color: rgba(99,102,241,.32); }
html[data-theme="light"] .card--green  { background: linear-gradient(150deg,#ecfdf5 0%,#cffae8 100%); border-color: rgba(16,185,129,.32); }
html[data-theme="light"] .card--red    { background: linear-gradient(150deg,#fff1f2 0%,#ffdde2 100%); border-color: rgba(244,63,94,.32); }
html[data-theme="light"] .card--purple { background: linear-gradient(150deg,#faf5ff 0%,#ecdffe 100%); border-color: rgba(139,92,246,.32); }
html[data-theme="light"] .card--blue   .card-value { color: #3730a3; }
html[data-theme="light"] .card--green  .card-value { color: #047857; }
html[data-theme="light"] .card--red    .card-value { color: #be123c; }
html[data-theme="light"] .card--purple .card-value { color: #5b21b6; }
html[data-theme="light"] .card--blue   .card-label,
html[data-theme="light"] .card--green  .card-label,
html[data-theme="light"] .card--red    .card-label,
html[data-theme="light"] .card--purple .card-label { color: #475569; }
html[data-theme="light"] .card::before { opacity: .5; }
html[data-theme="light"] .card:hover   { box-shadow: 0 12px 40px rgba(99,102,241,.15) !important; }

/* Chart cards */
html[data-theme="light"] .chart-card       { background: #fff; border-color: rgba(99,102,241,.1); box-shadow: 0 2px 16px rgba(99,102,241,.08),0 1px 3px rgba(0,0,0,.04); }
html[data-theme="light"] .chart-card:hover { border-color: rgba(99,102,241,.22); box-shadow: 0 6px 28px rgba(99,102,241,.12),0 2px 4px rgba(0,0,0,.04); }
html[data-theme="light"] .chart-title      { color: #1e1b4b; }

/* Transactions */
html[data-theme="light"] .txn-row:hover    { background: rgba(99,102,241,.05); }
html[data-theme="light"] .txn-cat-icon     { background: #eef1fb; border-color: rgba(99,102,241,.12); }
html[data-theme="light"] .txn-bank         { background: #eef1fb; border-color: rgba(99,102,241,.12); color: #4338ca; }
html[data-theme="light"] .table-wrap       { border-color: rgba(99,102,241,.1); box-shadow: 0 2px 16px rgba(99,102,241,.07); }
html[data-theme="light"] .txn-table th     { background: #f4f5ff; border-bottom-color: rgba(99,102,241,.12); color: #4338ca; }
html[data-theme="light"] .txn-table td     { border-bottom-color: rgba(99,102,241,.05); }
html[data-theme="light"] .txn-table tbody tr:hover td { background: rgba(99,102,241,.03); }
html[data-theme="light"] .sort-col:hover   { color: #4338ca; }
html[data-theme="light"] .badge-success    { background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.25); }
html[data-theme="light"] .badge-pending    { background: rgba(251,191,36,.1); border-color: rgba(251,191,36,.25); }
html[data-theme="light"] .page-btn         { background: #fff; border-color: rgba(99,102,241,.14); }
html[data-theme="light"] .page-btn:hover:not(.active) { background: #f4f5ff; }

/* Filters + drill bar */
html[data-theme="light"] .drill-bar        { background: #fff; border-color: rgba(99,102,241,.1); box-shadow: 0 2px 12px rgba(99,102,241,.07); }
html[data-theme="light"] .filter-card      { background: #fff; border-color: rgba(99,102,241,.1); box-shadow: 0 2px 12px rgba(99,102,241,.07); }
html[data-theme="light"] .filter-inline select { background: #fff; border-color: rgba(99,102,241,.14); }

/* Analytics */
html[data-theme="light"] .kpi-chip         { background: #fff; border-color: rgba(99,102,241,.1); box-shadow: 0 2px 12px rgba(99,102,241,.07); }
html[data-theme="light"] .kpi-val          { color: #4338ca; }
html[data-theme="light"] .merchant-row:hover { background: rgba(99,102,241,.05); }
html[data-theme="light"] .cat-bar-track    { background: #eef1fb; }

/* Accounts */
html[data-theme="light"] .bank-group-card  { background: #fff; border-color: rgba(99,102,241,.1); box-shadow: 0 2px 12px rgba(99,102,241,.07); }
html[data-theme="light"] .bank-account-row { background: #f4f5ff; border-color: rgba(99,102,241,.1); }
html[data-theme="light"] .no-banks-msg     { background: linear-gradient(135deg,rgba(99,102,241,.05),rgba(139,92,246,.03)); border-color: rgba(99,102,241,.18); }
html[data-theme="light"] .sandbox-hint     { background: rgba(99,102,241,.06); border-color: rgba(99,102,241,.15); }

/* Scrollbar */
html[data-theme="light"] ::-webkit-scrollbar-thumb       { background: #c7d2ef; }
html[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #a5b4d8; }

/* Setup modal */
html[data-theme="light"] .setup-modal-box { background: #fff; border-color: rgba(99,102,241,.2); }
html[data-theme="light"] .setup-step      { background: #f4f5ff; border-color: rgba(99,102,241,.12); }
html[data-theme="light"] .setup-step code { color: #4338ca; }

/* ── Design tokens (dark — default) ───────────────────────────── */
:root {
  --bg:          #05080f;
  --bg-raised:   #090d18;
  --bg-card:     #0d1220;
  --bg-hover:    #121929;
  --bg-input:    #080c16;

  --border:      rgba(255,255,255,.06);
  --border-mid:  rgba(255,255,255,.10);
  --border-hi:   rgba(255,255,255,.16);

  --text:        #eef2ff;
  --text-mid:    #b4c0d9;     /* brighter — was #8896b3 */
  --text-dim:    #8693ae;     /* much brighter — was #3d4d6a (unreadable) */
  --muted:       #b4c0d9;     /* alias — some code uses var(--muted) */

  --blue:        #6366f1;
  --blue-l:      #818cf8;
  --blue-d:      #4338ca;
  --green:       #10b981;
  --green-l:     #34d399;
  --red:         #f43f5e;
  --red-l:       #fb7185;
  --purple:      #8b5cf6;
  --purple-l:    #c4b5fd;
  --amber:       #fbbf24;

  --g-blue:      linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
  --g-green:     linear-gradient(135deg, #10b981 0%, #059669 100%);
  --g-red:       linear-gradient(135deg, #f43f5e 0%, #be123c 100%);
  --g-purple:    linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  --g-sidebar:   linear-gradient(180deg, #0d1220 0%, #090d18 100%);

  --r:    16px;
  --r-sm: 10px;
  --r-xs: 7px;
  --sw:   260px;
  --ease: .2s cubic-bezier(.4,0,.2,1);
}

/* ── Light mode CSS variables ─────────────────────────────────── */
[data-theme="light"] {
  --bg:          #f0f2fb;
  --bg-raised:   #e6eaf8;
  --bg-card:     #ffffff;
  --bg-hover:    #f4f6fd;
  --bg-input:    #f8f9ff;
  --border:      rgba(99,102,241,.1);
  --border-mid:  rgba(99,102,241,.18);
  --border-hi:   rgba(99,102,241,.3);
  --text:        #0f172a;
  --text-mid:    #334155;      /* darker — was #475569 */
  --text-dim:    #64748b;      /* darker — was #94a3b8 (too grey) */
  --muted:       #334155;
  --g-sidebar:   linear-gradient(180deg, #f4f5ff 0%, #eceffe 100%);
}

/* ── Base ──────────────────────────────────────────────────────── */
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

html, body { height: 100vh; max-height: 100vh; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* subtle ambient glow */
  background-image:
    radial-gradient(ellipse 90% 55% at 5% 0%,   rgba(99,102,241,.07) 0%, transparent 55%),
    radial-gradient(ellipse 70% 45% at 95% 100%, rgba(139,92,246,.05) 0%, transparent 50%);
}

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1e2a40; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #2a3a56; }

/* ══════════════════════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sw);
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  background: var(--g-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform var(--ease);
}

/* Logo area */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--border);
}
.logo-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--g-blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 4px 16px rgba(99,102,241,.45), inset 0 1px 0 rgba(255,255,255,.15);
  flex-shrink: 0;
}
.logo-text {
  font-size: 1.28rem;
  font-weight: 800;
  letter-spacing: -.4px;
  background: linear-gradient(135deg, #fff 30%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  text-decoration: none;
  color: var(--text-mid);
  font-size: .98rem;
  font-weight: 600;
  transition: background var(--ease), color var(--ease);
  position: relative;
  border: 1px solid transparent;
}
.nav-item:hover {
  background: rgba(255,255,255,.04);
  color: var(--text);
}
.nav-item.active {
  background: linear-gradient(135deg, rgba(99,102,241,.18) 0%, rgba(99,102,241,.06) 100%);
  color: var(--blue-l);
  border-color: rgba(99,102,241,.22);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -1px; top: 18%; bottom: 18%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--g-blue);
  box-shadow: 0 0 8px var(--blue);
}
.nav-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  transition: all var(--ease);
}
.nav-icon svg {
  width: 18px; height: 18px;
  stroke-width: 2;
}
.nav-item:hover .nav-icon {
  background: rgba(99,102,241,.15);
  color: var(--blue-l);
}
.nav-item.active .nav-icon {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 4px 12px rgba(99,102,241,.45);
}
.nav-label { line-height: 1.2; letter-spacing: -.1px; }

html[data-theme="light"] .nav-icon { background: rgba(99,102,241,.06); }
html[data-theme="light"] .nav-item:hover .nav-icon { background: rgba(99,102,241,.12); }

/* Sidebar plan card — sits just above the user footer. Clickable → pricing. */
.sidebar-plan {
  margin: 10px 14px 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(139,92,246,0.14), rgba(99,102,241,0.14));
  border: 1px solid rgba(139,92,246,0.35);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.sidebar-plan:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(139,92,246,0.18); }
.sidebar-plan .sp-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 4px;
}
.sidebar-plan .sp-badge {
  font-size: 0.68rem; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
  color: white;
}
.sidebar-plan .sp-badge-max   { background: linear-gradient(135deg, #8b5cf6, #ec4899); }
.sidebar-plan .sp-badge-pro   { background: linear-gradient(135deg, #6366f1, #3b82f6); }
.sidebar-plan .sp-badge-trial { background: linear-gradient(135deg, #10b981, #34d399); }
.sidebar-plan .sp-badge-admin { background: linear-gradient(135deg, #f59e0b, #f43f5e); }
.sidebar-plan .sp-days {
  font-size: 0.72rem; color: #cbd5e1; font-weight: 600;
}
[data-theme="light"] .sidebar-plan .sp-days { color: #475569; }
.sidebar-plan .sp-meta {
  font-size: 0.72rem; color: #94a3b8; margin-bottom: 8px;
}
[data-theme="light"] .sidebar-plan .sp-meta { color: #64748b; }
.sidebar-plan .sp-cta {
  width: 100%; padding: 7px 10px;
  border: none; border-radius: 8px;
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: white; font-weight: 600; font-size: 0.76rem;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.sidebar-plan .sp-cta:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(139,92,246,0.4); }
.sidebar-plan.sp-urgent {
  background: linear-gradient(135deg, rgba(251,146,60,0.18), rgba(239,68,68,0.14));
  border-color: rgba(251,146,60,0.55);
}
.sidebar-plan.sp-urgent .sp-days { color: #fdba74; }
.sidebar-plan.sp-expired {
  background: rgba(239,68,68,0.14);
  border-color: rgba(239,68,68,0.45);
}
.sidebar-plan.sp-expired .sp-days { color: #fca5a5; }

/* Footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,.12);
}
.user-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--g-blue);
  display: flex; align-items: center; justify-content: center;
  font-size: .92rem; font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(99,102,241,.4);
}
.user-info { flex: 1; min-width: 0; overflow: hidden; }
.user-name { font-size: .94rem; font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-acct { font-size: .78rem; color: var(--text-mid); margin-top: 3px; font-weight: 500; }

/* ══════════════════════════════════════════════════════════════════
   MAIN SHELL
══════════════════════════════════════════════════════════════════ */
.main {
  margin-left: var(--sw);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 28px;
  height: 58px;
  background: rgba(9,13,24,.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.menu-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--ease);
}
.menu-btn svg { width: 20px; height: 20px; }
.menu-btn:hover {
  background: var(--bg-hover);
  border-color: var(--blue);
  color: var(--blue);
  transform: scale(1.05);
}

.topbar-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.3px;
  flex: 1;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-date { font-size: .98rem; color: var(--text-mid); white-space: nowrap; font-weight: 500; }

/* Status pill */
.conn-status {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: .73rem; font-weight: 500; color: var(--text-mid);
  white-space: nowrap;
}
.conn-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--amber);
  flex-shrink: 0;
}

/* Refresh button (rate-limited) */
.btn-refresh {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border-mid);
  padding: 7px 12px;
  border-radius: var(--r-sm);
  font-size: .78rem; font-weight: 600; font-family: inherit;
  cursor: pointer;
  transition: all var(--ease);
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-refresh svg { width: 15px; height: 15px; transition: transform .4s ease; }
.btn-refresh:hover:not(:disabled) {
  border-color: var(--blue);
  color: var(--blue-l);
  background: var(--bg-hover);
}
.btn-refresh:hover:not(:disabled) svg { transform: rotate(-90deg); }
.btn-refresh:disabled {
  opacity: .55;
  cursor: not-allowed;
}
.btn-refresh.spinning svg {
  animation: refreshSpin 1s linear infinite;
}
@keyframes refreshSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.refresh-meta {
  font-size: .68rem;
  color: var(--text-dim);
  margin-left: 4px;
  font-weight: 500;
  white-space: nowrap;
}
@media (max-width: 720px) {
  .btn-refresh .refresh-label { display: none; }
  .refresh-meta { display: none; }
}
html[data-theme="light"] .btn-refresh { background: #fff; border-color: rgba(99,102,241,.18); }

/* Theme toggle button */
.theme-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-mid);
  background: var(--bg-card);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--ease);
  flex-shrink: 0;
}
.theme-btn:hover { transform: rotate(15deg) scale(1.1); border-color: var(--border-hi); }

/* Logout button in sidebar */
.logout-btn {
  margin-left: auto;
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  width: 28px; height: 28px;
  border-radius: var(--r-xs);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--ease);
}
.logout-btn svg { width: 15px; height: 15px; }
.logout-btn:hover { color: var(--red-l); border-color: rgba(244,63,94,.25); background: rgba(244,63,94,.08); }

/* Logo gem */
.logo-gem {
  font-size: 1.5rem;
  filter: drop-shadow(0 2px 10px rgba(99,102,241,.55));
  animation: gemFloat 5s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes gemFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* Donut chart wrapper */
.donut-wrap {
  position: relative;
  width: 100%;
  height: 220px;
  display: flex; align-items: center; justify-content: center;
}
.donut-wrap canvas { max-height: 300px !important; }

/* Top connect button */
.btn-connect-top {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--g-blue);
  color: #fff; border: none;
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-size: .78rem; font-weight: 600; font-family: inherit;
  cursor: pointer;
  transition: all var(--ease);
  box-shadow: 0 3px 12px rgba(99,102,241,.35);
  white-space: nowrap;
}
.btn-connect-top:hover {
  box-shadow: 0 6px 22px rgba(99,102,241,.55);
  transform: translateY(-1px);
}

/* ── Demo Banner ───────────────────────────────────────────────── */
.demo-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 28px;
  background: linear-gradient(90deg, rgba(251,191,36,.08), rgba(251,191,36,.02));
  border-bottom: 1px solid rgba(251,191,36,.14);
  font-size: .78rem;
}
.demo-banner span:first-child { font-weight: 700; color: var(--amber); }
.demo-banner span:last-of-type { flex: 1; color: var(--text-mid); }
.banner-btn {
  background: rgba(251,191,36,.14);
  color: var(--amber);
  border: 1px solid rgba(251,191,36,.28);
  padding: 5px 13px; border-radius: 6px;
  font-size: .75rem; font-weight: 600; font-family: inherit;
  cursor: pointer; white-space: nowrap;
  transition: background var(--ease);
}
.banner-btn:hover { background: rgba(251,191,36,.24); }
.banner-close {
  background: none; border: none;
  color: var(--text-dim); cursor: pointer; font-size: .85rem;
  padding: 2px; transition: color var(--ease);
}
.banner-close:hover { color: var(--text-mid); }

/* ── Loading ───────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(5,8,15,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
}
.loading-overlay.active { display: flex; }
.spinner {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 2.5px solid rgba(99,102,241,.15);
  border-top-color: var(--blue);
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: .82rem; color: var(--text-mid); font-weight: 500; }

/* ══════════════════════════════════════════════════════════════════
   PAGES
══════════════════════════════════════════════════════════════════ */
.page { display: none; padding: 16px 22px; flex: 1; min-height: 0; overflow-y: auto; }
.page.active { display: flex; flex-direction: column; animation: fadeUp .3s cubic-bezier(.4,0,.2,1); }
/* Dashboard + Analytics prefer to fit viewport (inner cards flex to equal
   heights), but scroll gracefully on short screens instead of clipping. */
#page-analytics.active,
#page-dashboard.active { overflow-y: auto; }

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-header h2 {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -.4px;
}

/* ── Drill-down bar ────────────────────────────────────────────── */
.drill-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 18px;
  margin-bottom: 20px;
}
.drill-group { display: flex; flex-direction: column; gap: 5px; }
.drill-group label {
  font-size: .65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .8px;
  font-weight: 700;
}
.drill-group select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 30px 8px 11px;
  border-radius: var(--r-sm);
  font-size: .8rem; font-family: inherit;
  outline: none; cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='5' viewBox='0 0 9 5'%3E%3Cpath d='M1 1l3.5 3L8 1' stroke='%234a5568' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 128px;
  transition: border-color var(--ease);
}
.drill-group select:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

/* ══════════════════════════════════════════════════════════════════
   STAT CARDS
══════════════════════════════════════════════════════════════════ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  position: relative;
  padding: 22px 22px 20px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: transform var(--ease), box-shadow var(--ease), border-color var(--ease);
  cursor: default;
}
.card:hover { transform: translateY(-4px); }

/* decorative blob */
.card::before {
  content: '';
  position: absolute;
  width: 130px; height: 130px;
  border-radius: 50%;
  top: -55px; right: -45px;
  filter: blur(50px);
  pointer-events: none;
  transition: opacity var(--ease);
}
.card:hover::before { opacity: 1.4; }

/* — Balance card — */
.card--blue {
  background: linear-gradient(150deg, #0f1630 0%, #0d1423 100%);
  border-color: rgba(99,102,241,.22);
}
.card--blue::before { background: rgba(99,102,241,.5); }
.card--blue:hover   { box-shadow: 0 20px 48px rgba(99,102,241,.18); border-color: rgba(99,102,241,.4); }
.card--blue .card-value  { color: var(--blue-l); }
.card--blue .card-icon   { color: var(--blue); }

/* — Income card — */
.card--green {
  background: linear-gradient(150deg, #0a1e18 0%, #091713 100%);
  border-color: rgba(16,185,129,.2);
}
.card--green::before { background: rgba(16,185,129,.5); }
.card--green:hover   { box-shadow: 0 20px 48px rgba(16,185,129,.14); border-color: rgba(16,185,129,.38); }
.card--green .card-value { color: var(--green-l); }
.card--green .card-icon  { color: var(--green); }

/* — Expenses card — */
.card--red {
  background: linear-gradient(150deg, #1e0d14 0%, #160a10 100%);
  border-color: rgba(244,63,94,.2);
}
.card--red::before { background: rgba(244,63,94,.5); }
.card--red:hover   { box-shadow: 0 20px 48px rgba(244,63,94,.14); border-color: rgba(244,63,94,.38); }
.card--red .card-value  { color: var(--red-l); }
.card--red .card-icon   { color: var(--red); }

/* — Savings card — */
.card--purple {
  background: linear-gradient(150deg, #14102a 0%, #0f0c1e 100%);
  border-color: rgba(139,92,246,.2);
}
.card--purple::before { background: rgba(139,92,246,.5); }
.card--purple:hover   { box-shadow: 0 20px 48px rgba(139,92,246,.14); border-color: rgba(139,92,246,.38); }
.card--purple .card-value { color: var(--purple-l); }
.card--purple .card-icon  { color: var(--purple); }

/* Card typography */
.card-label {
  font-size: .95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-mid);
  margin-bottom: 10px;
}
.card-value {
  font-size: 2.35rem;
  font-weight: 800;
  letter-spacing: -.6px;
  line-height: 1;
  margin-bottom: 10px;
}
.card-sub {
  font-size: 1rem;
  color: var(--text-mid);
  font-weight: 600;
}
.card-icon {
  position: absolute;
  right: 18px; top: 18px;
  font-size: 1.9rem;
  opacity: .18;
  pointer-events: none;
}

/* ══════════════════════════════════════════════════════════════════
   CHART CARDS
══════════════════════════════════════════════════════════════════ */
.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 24px 26px;
  transition: border-color var(--ease);
}
.chart-card:hover { border-color: var(--border-mid); }

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.chart-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -.2px;
  color: var(--text);
  margin-bottom: 14px;
}
.chart-header .chart-title { margin-bottom: 0; }

canvas { max-height: 340px; cursor: pointer; }

/* Chart drill-down hint */
.chart-hint {
  font-size: .78rem;
  color: var(--text-mid);
  font-weight: 500;
  letter-spacing: .2px;
  margin-left: 8px;
  opacity: .9;
}
.chart-hint::before { content: "💡 "; }

/* Live badge */
.live-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .76rem; font-weight: 700;
  color: var(--green);
  background: rgba(16,185,129,.1);
  border: 1px solid rgba(16,185,129,.2);
  padding: 3px 9px; border-radius: 20px;
  letter-spacing: .2px;
}
.live-dot {
  width: 6px; height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); box-shadow: 0 0 0 0 rgba(16,185,129,.5); }
  50%       { opacity: .6; transform: scale(.7); }
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 12px;
  margin-top: 12px;
}
.legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: .7rem; color: var(--text-mid);
  font-weight: 500;
}
.legend-dot { width: 8px; height: 8px; border-radius: 3px; flex-shrink: 0; }

/* ══════════════════════════════════════════════════════════════════
   TRANSACTION LIST (Dashboard)
══════════════════════════════════════════════════════════════════ */
.txn-list { display: flex; flex-direction: column; }

.txn-row {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 8px;
  border-radius: var(--r-sm);
  transition: background var(--ease);
  cursor: pointer;
}
.txn-row:hover { background: var(--bg-hover); }

.txn-cat-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: .95rem;
  flex-shrink: 0;
}

/* Transaction merchant logo — clean, no white box wrapper.
   Real brand logos sit on the dark/light app background directly;
   only the letter fallback uses a colored circle. */
.txn-logo {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  background: transparent;
  border: none;
}
.txn-logo img,
.txn-logo .merchant-logo-img { width: 28px; height: 28px; object-fit: contain; display: block; background: transparent; }
.txn-logo .merchant-fallback { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: .9rem; }

/* Small logo inside the Transactions table row */
.txn-cell-merchant { display: flex; align-items: center; gap: 10px; font-size: .98rem; font-weight: 600; }
.txn-logo-sm {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  background: transparent;
  border: none;
}
.txn-logo-sm img,
.txn-logo-sm .merchant-logo-img { width: 22px; height: 22px; object-fit: contain; display: block; background: transparent; }
.txn-logo-sm .merchant-fallback { width: 26px; height: 26px; border-radius: 7px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: .76rem; }

.txn-bank-cell { font-size: .9rem; color: var(--text-mid); font-weight: 500; }

.txn-info { flex: 1; min-width: 0; }
.txn-merchant {
  font-size: .94rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.txn-date {
  font-size: .84rem; color: var(--text-mid);
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px;
  font-weight: 500;
}
.txn-bank {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 5px;
  font-size: .76rem; color: var(--text);
  font-weight: 500;
}

.txn-amount { font-size: .96rem; font-weight: 700; white-space: nowrap; }
.txn-amount.credit { color: var(--green-l); }
.txn-amount.debit  { color: var(--red-l); }

.view-all {
  font-size: .84rem; color: var(--blue-l);
  text-decoration: none; font-weight: 600;
  transition: color var(--ease);
}
.view-all:hover { color: #fff; }

/* ══════════════════════════════════════════════════════════════════
   TRANSACTIONS PAGE
══════════════════════════════════════════════════════════════════ */
.filter-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.filter-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 108px; }
.filter-group label {
  font-size: .76rem; font-weight: 700;
  color: var(--text-mid); text-transform: uppercase; letter-spacing: .8px;
}
.filter-group select,
.filter-group input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--r-sm);
  font-size: .92rem; font-family: inherit;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.filter-group select {
  appearance: none; cursor: pointer; padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='5' viewBox='0 0 9 5'%3E%3Cpath d='M1 1l3.5 3L8 1' stroke='%234a5568' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
.filter-group select:focus,
.filter-group input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.filter-group input::placeholder { color: var(--text-dim); }
.search-input { min-width: 150px; }
.filter-actions { display: flex; align-items: center; gap: 8px; }
.filter-count { font-size: .74rem; color: var(--text-dim); margin-left: 6px; font-weight: 500; }

/* Buttons */
.btn-primary {
  background: var(--g-blue); color: #fff; border: none;
  padding: 8px 18px; border-radius: var(--r-sm);
  font-size: .8rem; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: all var(--ease);
  box-shadow: 0 2px 10px rgba(99,102,241,.3);
}
.btn-primary:hover { box-shadow: 0 5px 18px rgba(99,102,241,.5); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent; color: var(--text-mid);
  border: 1px solid var(--border);
  padding: 8px 14px; border-radius: var(--r-sm);
  font-size: .8rem; font-family: inherit; cursor: pointer;
  transition: all var(--ease);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-mid); }

/* Table */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: auto;
}
.txn-table { width: 100%; border-collapse: collapse; font-size: .98rem; }
.txn-table thead { position: sticky; top: 0; }
.txn-table th {
  text-align: left; padding: 13px 16px;
  color: var(--text-dim);
  font-weight: 700; font-size: .82rem;
  text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-raised);
}
.sort-col { cursor: pointer; user-select: none; }
.sort-col:hover { color: var(--blue-l); }
.txn-table td { padding: 11px 16px; border-bottom: 1px solid rgba(255,255,255,.03); vertical-align: middle; }
.txn-table tbody tr:last-child td { border-bottom: none; }
.txn-table tbody tr:hover td { background: rgba(255,255,255,.025); }

.badge {
  display: inline-flex; align-items: center;
  padding: 4px 11px; border-radius: 20px;
  font-size: .8rem; font-weight: 700; white-space: nowrap;
}
.badge-success { background: rgba(16,185,129,.1); color: var(--green-l); border: 1px solid rgba(16,185,129,.2); }
.badge-pending { background: rgba(251,191,36,.1); color: var(--amber); border: 1px solid rgba(251,191,36,.2); }

/* Pagination */
.pagination { display: flex; justify-content: center; gap: 5px; padding: 16px 0 4px; }
.page-btn {
  width: 30px; height: 30px; border-radius: var(--r-xs);
  border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-mid);
  font-size: .78rem; font-family: inherit; cursor: pointer;
  transition: all var(--ease);
}
.page-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); box-shadow: 0 2px 10px rgba(99,102,241,.4); }
.page-btn:hover:not(.active) { background: var(--bg-hover); color: var(--text); border-color: var(--border-mid); }

/* ══════════════════════════════════════════════════════════════════
   ANALYTICS PAGE
══════════════════════════════════════════════════════════════════ */
.filter-inline { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-inline select {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 7px 28px 7px 10px; border-radius: var(--r-sm);
  font-size: .8rem; font-family: inherit; outline: none; cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='5' viewBox='0 0 9 5'%3E%3Cpath d='M1 1l3.5 3L8 1' stroke='%234a5568' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
  transition: border-color var(--ease);
}
.filter-inline select:focus { border-color: var(--blue); outline: none; }

/* KPI chips */
.kpi-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.kpi-chip {
  flex: 1; min-width: 130px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 5px;
  transition: border-color var(--ease), transform var(--ease);
}
.kpi-chip:hover { border-color: rgba(99,102,241,.3); transform: translateY(-2px); }
.kpi-val { font-size: 1.75rem; font-weight: 800; color: var(--blue-l); letter-spacing: -.5px; line-height: 1; }
.kpi-lbl { font-size: .82rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .7px; font-weight: 700; }

/* KPI color variants */
.kpi-chip.kpi-income {
  background: linear-gradient(135deg, rgba(16,185,129,.18), rgba(16,185,129,.06));
  border-color: rgba(16,185,129,.35);
}
.kpi-chip.kpi-income .kpi-val { color: #34d399; }
.kpi-chip.kpi-income:hover { border-color: rgba(16,185,129,.55); box-shadow: 0 6px 22px rgba(16,185,129,.18); }

.kpi-chip.kpi-expense {
  background: linear-gradient(135deg, rgba(239,68,68,.18), rgba(239,68,68,.06));
  border-color: rgba(239,68,68,.35);
}
.kpi-chip.kpi-expense .kpi-val { color: #f87171; }
.kpi-chip.kpi-expense:hover { border-color: rgba(239,68,68,.55); box-shadow: 0 6px 22px rgba(239,68,68,.18); }

.kpi-chip.kpi-neutral {
  background: linear-gradient(135deg, rgba(99,102,241,.18), rgba(99,102,241,.06));
  border-color: rgba(99,102,241,.35);
}
.kpi-chip.kpi-neutral .kpi-val { color: #818cf8; }
.kpi-chip.kpi-neutral:hover { border-color: rgba(99,102,241,.55); box-shadow: 0 6px 22px rgba(99,102,241,.2); }

/* Light theme tweaks */
html[data-theme="light"] .kpi-chip.kpi-income  .kpi-val { color: #047857; }
html[data-theme="light"] .kpi-chip.kpi-expense .kpi-val { color: #be123c; }
html[data-theme="light"] .kpi-chip.kpi-neutral .kpi-val { color: #4338ca; }

.analytics-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
/* Keep charts compact inside analytics so the whole page fits one viewport */
.analytics-grid .chart-card { padding: 16px 18px; }
.analytics-grid .chart-title { font-size: 1.05rem; margin-bottom: 10px; }
/* Charts fill their grid cell; absolute-positioned canvases handle sizing */
.analytics-grid .chart-body,
.analytics-grid .donut-wrap { flex: 1 1 auto; min-height: 0; position: relative; }
.analytics-grid .chart-body > canvas,
.analytics-grid .donut-wrap > canvas {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
}
#page-analytics .kpi-row { margin-bottom: 14px; gap: 12px; }
#page-analytics .kpi-chip { padding: 12px 14px; }
#page-analytics .page-header { margin-bottom: 12px; }
#page-analytics .merchant-row { padding: 6px 10px; }
#page-analytics .merchant-logo { width: 28px; height: 28px; }
#page-analytics .category-bars { gap: 16px; }
#page-analytics .cat-bar-header { font-size: 1.05rem; margin-bottom: 8px; font-weight: 700; }
#page-analytics .cat-bar-header > span:last-child { font-size: 1rem; font-weight: 700; }
#page-analytics .cat-bar-track { height: 14px; }
.analytics-grid .wide { grid-column: 1 / -1; }

/* Top merchants */
.merchant-list { display: flex; flex-direction: column; gap: 6px; }
.merchant-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-sm);
  transition: background var(--ease);
}
.merchant-row:hover { background: var(--bg-hover); }
.merchant-rank { display: none; }
.merchant-logo {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex: 0 0 auto;
  background: transparent;
  border: none;
}
.merchant-logo img,
.merchant-logo .merchant-logo-img { width: 24px; height: 24px; object-fit: contain; display: block; background: transparent; }
.merchant-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .95rem;
}
.merchant-name { flex: 1; font-size: .94rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.merchant-amt  { font-size: .94rem; font-weight: 700; color: var(--red-l); white-space: nowrap; }

/* Category progress bars */
.category-bars { display: flex; flex-direction: column; gap: 16px; }
.cat-bar-header { display: flex; justify-content: space-between; font-size: .9rem; color: var(--text); margin-bottom: 7px; font-weight: 600; }
.cat-bar-track { height: 8px; background: var(--bg-hover); border-radius: 99px; overflow: hidden; }
.cat-bar-fill {
  height: 100%; border-radius: 99px;
  transition: width 1.2s cubic-bezier(.4,0,.2,1);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 1px 3px rgba(0,0,0,.15);
}

/* ══════════════════════════════════════════════════════════════════
   ACCOUNTS PAGE
══════════════════════════════════════════════════════════════════ */
.btn-connect {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--g-blue);
  color: #fff; border: none;
  padding: 10px 20px; border-radius: var(--r-sm);
  font-size: .85rem; font-weight: 700; font-family: inherit;
  cursor: pointer; transition: all var(--ease);
  box-shadow: 0 4px 16px rgba(99,102,241,.3);
}
.btn-connect:hover { box-shadow: 0 8px 28px rgba(99,102,241,.55); transform: translateY(-2px); }
.btn-connect.large { padding: 13px 26px; font-size: .95rem; margin-top: 20px; }

.section-label {
  font-size: .82rem; font-weight: 800;
  color: var(--text-mid);
  text-transform: uppercase; letter-spacing: .9px;
  margin-bottom: 14px;
}

/* Connected banks grid */
.connected-banks { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.bank-group-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
  transition: border-color var(--ease), transform var(--ease);
}
.bank-group-card:hover { border-color: rgba(99,102,241,.28); transform: translateY(-2px); }

.bank-group-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.bank-group-name { font-size: .95rem; font-weight: 800; }
.bank-group-sub { font-size: .7rem; color: var(--text-mid); margin-top: 3px; }

.btn-remove {
  background: rgba(244,63,94,.08);
  color: var(--red-l);
  border: 1px solid rgba(244,63,94,.15);
  padding: 4px 12px; border-radius: var(--r-xs);
  font-size: .72rem; font-family: inherit; font-weight: 600;
  cursor: pointer; transition: all var(--ease);
}
.btn-remove:hover { background: rgba(244,63,94,.18); border-color: rgba(244,63,94,.3); }

.bank-accounts-list { display: flex; flex-direction: column; gap: 8px; }
.bank-account-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 13px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: border-color var(--ease);
}
.bank-account-row:hover { border-color: rgba(16,185,129,.25); }
.ba-name { font-size: .83rem; font-weight: 700; }
.ba-type { font-size: .68rem; color: var(--text-mid); text-transform: capitalize; margin-top: 2px; }
.ba-current { font-size: .95rem; font-weight: 800; color: var(--green-l); text-align: right; }
.ba-avail { font-size: .74rem; color: var(--text-mid); text-align: right; margin-top: 3px; font-weight: 500; }

/* Empty state */
.no-banks-msg {
  flex-direction: column; align-items: center; text-align: center;
  padding: 60px 28px;
  background: linear-gradient(135deg, rgba(99,102,241,.04) 0%, rgba(139,92,246,.03) 100%);
  border: 1px dashed rgba(99,102,241,.2);
  border-radius: var(--r);
}
.no-banks-icon { font-size: 3.8rem; margin-bottom: 16px; filter: drop-shadow(0 4px 12px rgba(99,102,241,.4)); }
.no-banks-msg h3 { font-size: 1.1rem; font-weight: 800; margin-bottom: 10px; }
.no-banks-msg p { color: var(--text-mid); font-size: .85rem; line-height: 1.7; max-width: 400px; }

.sandbox-hint {
  margin-top: 22px; padding: 14px 20px;
  background: rgba(99,102,241,.08);
  border: 1px solid rgba(99,102,241,.18);
  border-radius: 10px;
  font-size: .78rem; color: var(--text-mid); line-height: 1.75;
  text-align: left;
}
.sandbox-hint strong { color: var(--text); }
.sandbox-hint code { color: var(--blue-l); font-family: 'Consolas', monospace; font-size: .82rem; }

/* ══════════════════════════════════════════════════════════════════
   ANIMATIONS & MICRO-INTERACTIONS
══════════════════════════════════════════════════════════════════ */
@keyframes newTxn {
  0%   { background: rgba(99,102,241,.16); }
  100% { background: transparent; }
}
.txn-row.new { animation: newTxn 2.5s ease forwards; }

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════════════ */
@media (max-width: 1200px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .charts-row      { grid-template-columns: 1fr; }
  .analytics-grid  { grid-template-columns: 1fr; }
  .analytics-grid .wide { grid-column: 1; }
}

@media (max-width: 1100px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet (iPad) + mobile — sidebar collapses to hamburger. Laptops keep sidebar. */
@media (max-width: 960px) {
  .sidebar         { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open    { transform: translateX(0); box-shadow: 8px 0 40px rgba(0,0,0,.6); }
  .main            { margin-left: 0; }
  .menu-btn        { display: inline-flex; }
  /* Backdrop when sidebar is open */
  .sidebar.open::after {
    content: "";
    position: fixed; inset: 0; left: var(--sw);
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: -1;
    animation: fadeIn .2s ease;
  }
}

@media (max-width: 860px) {
  .page            { padding: 14px 14px 32px; }
  .topbar          { padding: 0 14px; gap: 8px; }
  .demo-banner     { padding: 8px 14px; font-size: .73rem; }
  .topbar-date     { display: none; }
  .charts-row      { grid-template-columns: 1fr; }
  .analytics-grid  { grid-template-columns: 1fr; }
  .analytics-grid .wide { grid-column: 1; }
  .filter-row      { gap: 10px; }
}

@media (max-width: 640px) {
  .cards-grid      { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card            { padding: 16px 14px 14px; }
  .card-value      { font-size: 1.45rem; }
  .kpi-row         { display: grid; grid-template-columns: 1fr 1fr; }
  .drill-bar       { gap: 8px; padding: 12px 14px; }
  .drill-group select { min-width: 110px; }
  /* Transaction filters — stack on mobile */
  .filter-row      { flex-direction: column; gap: 10px; }
  .filter-group    { width: 100%; }
  .filter-group select,
  .filter-group input { width: 100%; }
  .search-input    { width: 100%; }
  /* Transaction table — hide lower-priority columns */
  .txn-table th:nth-child(4),
  .txn-table td:nth-child(4),
  .txn-table th:nth-child(5),
  .txn-table td:nth-child(5) { display: none; }
  .txn-table th, .txn-table td { padding: 9px 10px; }
  /* Hide conn status text */
  #connLabel       { display: none; }
  /* Analytics */
  .kpi-chip        { min-width: 0; }
  .chart-card      { padding: 14px 12px; }
}

@media (max-width: 420px) {
  .cards-grid      { grid-template-columns: 1fr; gap: 10px; }
  .kpi-row         { grid-template-columns: 1fr; }
  .topbar-title    { font-size: .85rem; }
  .page-header h2  { font-size: 1rem; }
  .drill-bar       { flex-direction: column; align-items: stretch; }
  .drill-group select { min-width: unset; width: 100%; }
}

/* ══ SETUP MODAL ═══════════════════════════════════════════════════ */
.setup-modal {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(5,8,15,.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.setup-modal.open { display: flex; animation: fadeUp .25s ease; }

.setup-modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-hi);
  border-radius: 20px;
  padding: 30px 28px;
  max-width: 480px; width: 100%;
  box-shadow: 0 32px 80px rgba(0,0,0,.5);
  position: relative;
}
.setup-modal-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none;
  color: var(--text-dim); font-size: 1.1rem;
  cursor: pointer; padding: 4px 8px;
  border-radius: 6px; transition: all var(--ease);
}
.setup-modal-close:hover { color: var(--text); background: var(--bg-hover); }
.setup-modal-title {
  font-size: 1.05rem; font-weight: 800;
  margin-bottom: 6px; letter-spacing: -.3px;
}
.setup-modal-sub {
  font-size: .8rem; color: var(--text-mid);
  margin-bottom: 20px; line-height: 1.6;
}
.setup-steps { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.setup-step {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.setup-step-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--g-blue);
  font-size: .7rem; font-weight: 800; color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}
.setup-step-text { font-size: .8rem; color: var(--text-mid); line-height: 1.6; }
.setup-step-text strong { color: var(--text); }
.setup-step code {
  color: var(--blue-l); font-family: 'Consolas', monospace;
  font-size: .78rem; background: rgba(99,102,241,.1);
  padding: 1px 5px; border-radius: 4px;
}
.setup-modal-btns { display: flex; gap: 10px; }
.setup-modal-btns a {
  flex: 1; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 0;
  background: var(--g-blue); color: #fff;
  border-radius: 10px; text-decoration: none;
  font-size: .83rem; font-weight: 700;
  box-shadow: 0 4px 16px rgba(99,102,241,.35);
  transition: all var(--ease);
}
.setup-modal-btns a:hover { box-shadow: 0 8px 24px rgba(99,102,241,.55); transform: translateY(-1px); }
.setup-modal-btns a.ghost {
  background: transparent; color: var(--text-mid);
  border: 1px solid var(--border-mid);
  box-shadow: none;
}
.setup-modal-btns a.ghost:hover { background: var(--bg-hover); color: var(--text); transform: none; }

/* ══════════════════════════════════════════════════════════════════
   FOOTER
══════════════════════════════════════════════════════════════════ */
.app-footer {
  margin-top: 0;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: .76rem;
  color: var(--text-dim);
  text-align: center;
  flex: 0 0 auto;
}
.app-footer strong { color: var(--text-mid); }
.footer-sep { opacity: .5; }
@media (max-width: 600px) {
  .app-footer { font-size: .7rem; padding: 14px 8px 20px; }
  .footer-sep { display: none; }
}

/* ══════════════════════════════════════════════════════════════════
   WELCOME MODAL (+ generic app-modal)
══════════════════════════════════════════════════════════════════ */
.app-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 9999;
  padding: 20px;
  animation: fadeIn .2s ease;
}
.app-modal.open { display: flex; }
html[data-theme="light"] .app-modal { background: rgba(15,23,42,.45); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.app-modal-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--border-mid);
  border-radius: 22px;
  padding: 36px 32px 28px;
  text-align: center;
  box-shadow: 0 32px 80px rgba(0,0,0,.5);
  animation: popIn .3s cubic-bezier(.16,1,.3,1);
}
html[data-theme="light"] .app-modal-card { box-shadow: 0 24px 64px rgba(15,23,42,.18); }
@keyframes popIn { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }

.app-modal-x {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-mid);
  font-size: 1rem; cursor: pointer;
  transition: all var(--ease);
}
.app-modal-x:hover { background: var(--bg-input); color: var(--text); transform: rotate(90deg); }

.welcome-gem {
  font-size: 3.2rem;
  filter: drop-shadow(0 6px 20px rgba(99,102,241,.6));
  animation: gemFloat 4s ease-in-out infinite;
  margin-bottom: 8px;
}
.welcome-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -.4px;
}
.welcome-title span {
  background: linear-gradient(135deg, var(--blue), var(--purple));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.welcome-sub {
  font-size: .92rem;
  color: var(--text-mid);
  margin-bottom: 24px;
  line-height: 1.5;
}
.welcome-feats {
  display: flex; flex-direction: column; gap: 10px;
  text-align: left;
  margin-bottom: 24px;
}
.welcome-feat {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.welcome-feat > span { font-size: 1.5rem; flex-shrink: 0; }
.welcome-feat b { font-size: .88rem; display: block; color: var(--text); }
.welcome-feat small { font-size: .75rem; color: var(--text-mid); display: block; margin-top: 2px; }
.sandbox-tip {
  background: linear-gradient(135deg, rgba(99,102,241,.12), rgba(139,92,246,.08));
  border: 1px dashed rgba(99,102,241,.45);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 20px;
  font-size: .78rem;
  color: var(--text-mid);
  text-align: left;
}
.sandbox-tip > b { color: var(--blue-l, #818cf8); display: block; margin-bottom: 8px; font-size: .78rem; }
.sandbox-creds { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: .75rem; }
.sandbox-creds code {
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 5px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
  font-size: .78rem;
  font-weight: 600;
}
.welcome-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.welcome-actions button { padding: 10px 20px; font-size: .88rem; }

/* ══════════════════════════════════════════════════════════════════
   AI CHAT WIDGET
══════════════════════════════════════════════════════════════════ */
/* HARD GATE: AI-only UI (chat bubble, chat panel, AI filter banner) is
   NEVER visible outside the AI Insights tab, no matter what inline styles
   or other scripts try to do. */
body:not(.on-ai-page) .chat-bubble,
body:not(.on-ai-page) .chat-panel,
body:not(.on-ai-page) .ai-filter-banner {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
.chat-bubble {
  position: fixed;
  bottom: 22px; right: 22px;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 28px rgba(99,102,241,.5), 0 0 0 6px rgba(99,102,241,.1);
  z-index: 9998;
  transition: transform var(--ease), box-shadow var(--ease);
  animation: chatPulse 2.5s ease-in-out infinite;
}
.chat-bubble:hover { transform: scale(1.08) rotate(-6deg); }
.chat-bubble svg { width: 26px; height: 26px; }
.chat-bubble-dot {
  position: absolute; top: 10px; right: 10px;
  width: 10px; height: 10px;
  background: #10b981;
  border: 2px solid var(--bg-card);
  border-radius: 50%;
}
@keyframes chatPulse {
  0%, 100% { box-shadow: 0 10px 28px rgba(99,102,241,.5), 0 0 0 0 rgba(99,102,241,.4); }
  50%      { box-shadow: 0 10px 28px rgba(99,102,241,.5), 0 0 0 14px rgba(99,102,241,0); }
}

.chat-panel {
  position: fixed;
  bottom: 22px; right: 22px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 500px;
  max-height: calc(100vh - 100px);
  background: var(--bg-card);
  border: 1px solid var(--border-mid);
  border-radius: 18px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  z-index: 9998;
  transform-origin: bottom right;
  animation: chatOpen .25s cubic-bezier(.16,1,.3,1);
}
.chat-panel.open { display: flex; }
html[data-theme="light"] .chat-panel { box-shadow: 0 16px 50px rgba(15,23,42,.2); }
@keyframes chatOpen { from { opacity: 0; transform: translateY(12px) scale(.95); } to { opacity: 1; transform: none; } }

.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
}
.chat-head-info { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.chat-title { font-weight: 700; font-size: .92rem; }
.chat-status { font-size: .7rem; opacity: .88; display: flex; align-items: center; gap: 5px; margin-top: 1px; }
.chat-dot { width: 7px; height: 7px; background: #10b981; border-radius: 50%; animation: chatLive 1.6s ease-in-out infinite; }
@keyframes chatLive { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.chat-close {
  width: 30px; height: 30px; border: none;
  background: rgba(255,255,255,.15); color: #fff;
  border-radius: 50%; cursor: pointer;
  font-size: .9rem;
  transition: background var(--ease);
}
.chat-close:hover { background: rgba(255,255,255,.3); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg);
}
.chat-msg {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: .85rem;
  line-height: 1.45;
  animation: msgIn .2s ease;
  word-wrap: break-word;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chat-msg--bot {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-top-left-radius: 4px;
  align-self: flex-start;
}
.chat-msg--user {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-top-right-radius: 4px;
  align-self: flex-end;
}
.chat-msg code { background: rgba(99,102,241,.15); padding: 1px 6px; border-radius: 4px; font-size: .8rem; }
.chat-msg--user code { background: rgba(255,255,255,.2); color: #fff; }

.chat-input-row {
  display: flex; gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.chat-input-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: .85rem;
  outline: none;
  transition: border-color var(--ease);
}
.chat-input-row input:focus { border-color: var(--blue); }
.chat-input-row button {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--ease);
}
.chat-input-row button:hover { transform: translateX(2px); }
.chat-input-row button svg { width: 16px; height: 16px; }

@media (max-width: 600px) {
  .chat-bubble { bottom: 16px; right: 16px; width: 52px; height: 52px; }
  .chat-panel { bottom: 16px; right: 16px; left: 16px; width: auto; height: calc(100vh - 80px); }
}

/* ── Security page ──────────────────────────────────────────────── */
.sec-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.sec-card-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.sec-icon-box {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.sec-card-title-wrap { flex: 1; }
.sec-card-title { font-size: 1.15rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.sec-card-sub   { font-size: .88rem; color: var(--text-mid); font-weight: 500; }
.sec-status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  border-radius: 99px;
  font-size: .8rem;
  font-weight: 700;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-mid);
}
.sec-status .sec-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #94a3b8;
}
.sec-status.on  { background: rgba(16, 185, 129, 0.18); color: #10b981; }
.sec-status.on  .sec-status-dot { background: #10b981; box-shadow: 0 0 6px #10b981; }
.sec-status.off { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.sec-status.off .sec-status-dot { background: #ef4444; }

.sec-desc { color: var(--text-mid); font-size: .92rem; line-height: 1.55; margin-bottom: 16px; }
.sec-desc strong { color: var(--text); }

.sec-benefits { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.sec-benefit {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px;
  background: var(--bg-hover);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.sec-benefit > span:first-child { font-size: 20px; flex-shrink: 0; }
.sec-benefit b { display: block; color: var(--text); font-size: .92rem; margin-bottom: 2px; }
.sec-benefit small { color: var(--text-mid); font-size: .82rem; line-height: 1.4; }

.sec-enabled-banner {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(16, 185, 129, 0.04));
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 12px;
  margin-bottom: 16px;
}
.sec-enabled-banner .sec-check {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #10b981;
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 18px;
  flex-shrink: 0;
}
.sec-enabled-banner b { display: block; color: var(--text); font-size: .95rem; margin-bottom: 2px; }
.sec-enabled-banner small { color: var(--text-mid); font-size: .82rem; }

.sec-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  gap: 12px;
  border-top: 1px solid var(--border);
}
.sec-row b { display: block; color: var(--text); font-size: .92rem; margin-bottom: 2px; }
.sec-row small { color: var(--text-mid); font-size: .82rem; }

.sec-list {
  list-style: none;
  padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 10px;
}
.sec-list li {
  color: var(--text-mid);
  font-size: .9rem;
  line-height: 1.5;
  padding-left: 4px;
}
.sec-list strong { color: var(--text); }

.btn-danger {
  padding: 9px 18px;
  border-radius: 9px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  transition: all var(--ease);
}
.btn-danger:hover { background: #ef4444; color: white; }

/* ── MFA Enrollment Modal ───────────────────────────────────────── */
.mfa-modal {
  position: fixed; inset: 0;
  background: rgba(10, 15, 28, 0.75);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 9999;
  padding: 20px;
}
.mfa-modal.open { display: flex; }
.mfa-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  max-width: 440px;
  width: 100%;
  padding: 28px;
  position: relative;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
  max-height: 92vh;
  overflow-y: auto;
}
.mfa-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text-mid);
  cursor: pointer;
  font-size: 14px;
}
.mfa-close:hover { background: var(--border); color: var(--text); }
.mfa-step h3 { font-size: 1.3rem; margin: 4px 0 8px; color: var(--text); }
.mfa-step-num {
  font-size: .72rem;
  font-weight: 700;
  color: #8b5cf6;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 4px;
}
.mfa-sub { color: var(--text-mid); font-size: .9rem; line-height: 1.55; margin-bottom: 18px; }
.mfa-qr-wrap {
  background: white;
  padding: 16px;
  border-radius: 14px;
  display: flex; justify-content: center;
  margin-bottom: 16px;
}
.mfa-qr-wrap canvas {
  display: block !important;
  width: 220px !important;
  height: 220px !important;
  max-width: 220px !important;
  max-height: 220px !important;
  cursor: default !important;
  position: static !important;
}
#mfaQrCanvas {
  width: 220px !important;
  height: 220px !important;
}
.mfa-secret-box {
  background: var(--bg-hover);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 20px;
  text-align: center;
}
.mfa-secret-label { font-size: .78rem; color: var(--text-mid); margin-bottom: 6px; }
.mfa-secret-text {
  font-family: 'SF Mono', Consolas, monospace;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .05em;
  word-break: break-all;
}
.mfa-code-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: .4em;
  font-weight: 600;
  font-family: 'SF Mono', Consolas, monospace;
  background: var(--bg-hover);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  outline: none;
}
.mfa-code-input:focus { border-color: #8b5cf6; }
.mfa-actions {
  display: flex; gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}
.mfa-backup-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.mfa-backup-code {
  font-family: 'SF Mono', Consolas, monospace;
  font-size: .92rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  padding: 6px 4px;
  background: var(--bg-card);
  border-radius: 6px;
  user-select: all;
}

/* ── Post-signup MFA prompt modal ──────────────────────────────── */
.mfa-prompt-card { text-align: center; max-width: 480px; }
.mfa-prompt-icon {
  width: 72px; height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  box-shadow: 0 10px 30px rgba(99, 102, 241, .4);
  animation: mfaIconPulse 2.4s ease-in-out infinite;
}
@keyframes mfaIconPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 10px 30px rgba(99, 102, 241, .4); }
  50%      { transform: scale(1.06); box-shadow: 0 14px 40px rgba(99, 102, 241, .6); }
}
.mfa-prompt-card .welcome-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}
.mfa-prompt-hint {
  margin-top: 16px;
  font-size: .8rem;
  color: var(--text-dim);
}
.mfa-prompt-hint b { color: var(--text-mid); }

/* ── Login page MFA step ────────────────────────────────────────── */
.mfa-login-step { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: translateY(0);} }

/* ══════════════════════════════════════════════════════════════════
   NO-SCROLL VIEWPORT LAYOUT
   Every page fits inside the viewport; no scrollbars anywhere.
══════════════════════════════════════════════════════════════════ */
@media (min-width: 961px) {

  /* Thin indigo scrollbars on scrollable areas */
  .page::-webkit-scrollbar { width: 8px; }
  .page::-webkit-scrollbar-track { background: rgba(255,255,255,.03); }
  .page::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #6366f1, #8b5cf6);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
  }
  .page { scrollbar-width: thin; scrollbar-color: rgba(99,102,241,.6) rgba(255,255,255,.04); }

  /* Compact global spacing for dense layouts */
  .page { padding: 14px 20px 14px 20px; gap: 10px; }
  .cards-grid { margin-bottom: 0; gap: 12px; }
  .charts-row { margin-bottom: 0; gap: 12px; }
  .drill-bar  { margin-bottom: 0; padding: 10px 14px; }
  .demo-banner { padding: 8px 14px; }
  .page-header { margin-bottom: 8px; }

  /* Smaller card padding to fit 2 chart rows + KPI row on one screen */
  .card        { padding: 16px 18px 14px; }
  .card-value  { font-size: 2rem; margin-bottom: 5px; }
  .card-label  { margin-bottom: 5px; font-size: .95rem; }
  .card-sub    { font-size: .95rem; }
  .card-icon   { font-size: 1.6rem; right: 16px; top: 16px; }

  .chart-card  { padding: 14px 18px; display: flex; flex-direction: column; min-height: 0; }
  .chart-title { font-size: 1.1rem; margin-bottom: 8px; }
  .chart-header{ margin-bottom: 8px; }

  /* Transactions + Recent list fonts */
  .txn-merchant { font-size: 1rem; }
  .txn-date     { font-size: .88rem; }
  .txn-amount   { font-size: 1.02rem; }

  /* KPI chips (analytics) */
  .kpi-val { font-size: 1.5rem; }
  .kpi-lbl { font-size: .82rem; }

  /* ───── Dashboard: two equal-height chart rows, fit viewport ──── */
  #page-dashboard.active {
    gap: 10px;
    overflow-y: auto;
  }
  #page-dashboard .drill-bar  { flex: 0 0 auto; }
  #page-dashboard .cards-grid { flex: 0 0 auto; }
  /* Both charts-rows split the remaining viewport evenly */
  #page-dashboard .charts-row {
    flex: 1 1 0;
    min-height: 0;
    margin-bottom: 0;
  }
  #page-dashboard .charts-row .chart-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  /* Canvas wrapper fills remaining card space; canvas absolute-positioned
     inside a relative wrapper gives Chart.js an integer-pixel box
     (crisp rendering, no subpixel blur). */
  .chart-body,
  #page-dashboard .donut-wrap {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
  }
  .chart-body > canvas,
  #page-dashboard .donut-wrap > canvas {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }
  /* Recent Transactions list in row 2 scrolls inside its card */
  #page-dashboard .txn-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 6px;
  }
  /* Category legend under donut — no scroll, just a single row */
  #page-dashboard .legend {
    flex: 0 0 auto;
    max-height: 48px;
    overflow: hidden;
  }

  /* Analytics: donut and line chart fill their card */
  #page-analytics .donut-wrap,
  #page-analytics .chart-body {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
  }
  #page-analytics .donut-wrap > canvas,
  #page-analytics .chart-body > canvas {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }

  /* Recent Transactions: internal scroll inside the card */
  #page-dashboard .txn-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(99,102,241,.6) rgba(255,255,255,.04);
  }
  #page-dashboard .txn-list::-webkit-scrollbar { width: 8px; }
  #page-dashboard .txn-list::-webkit-scrollbar-track { background: rgba(255,255,255,.03); border-radius: 8px; }
  #page-dashboard .txn-list::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #6366f1, #8b5cf6);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
  }

  /* Category legend under donut: cap height so the pie still has room */
  #page-dashboard .legend { flex: 0 0 auto; max-height: 60px; overflow-y: auto; }

  /* ───── Analytics ─────────────────────────────────────────────── */
  #page-analytics.active { gap: 10px; }
  #page-analytics .kpi-row { flex: 0 0 auto; margin-bottom: 0; }
  #page-analytics .analytics-grid {
    flex: 1 1 0;
    min-height: 0;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;   /* fill viewport evenly */
    gap: 10px;
  }
  #page-analytics .analytics-grid .chart-card {
    overflow: hidden; min-height: 0;
    display: flex; flex-direction: column;
  }
  #page-analytics .merchant-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    padding-right: 10px;
    scrollbar-width: thin !important;
    scrollbar-color: rgba(99,102,241,.6) rgba(255,255,255,.06) !important;
  }
  #page-analytics .merchant-list::-webkit-scrollbar {
    display: block !important;
    width: 10px !important;
  }
  #page-analytics .merchant-list::-webkit-scrollbar-track {
    background: rgba(255,255,255,.04) !important;
    border-radius: 8px;
  }
  #page-analytics .merchant-list::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #6366f1, #8b5cf6) !important;
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box !important;
  }
  /* Category Spend Breakdown: allow internal scroll, show all categories */
  #page-analytics .category-bars {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    padding-right: 10px;
    scrollbar-width: thin !important;
    scrollbar-color: rgba(99,102,241,.6) rgba(255,255,255,.06) !important;
  }
  #page-analytics .category-bars::-webkit-scrollbar {
    display: block !important;
    width: 10px !important;
  }
  #page-analytics .category-bars::-webkit-scrollbar-track {
    background: rgba(255,255,255,.04) !important;
    border-radius: 8px;
  }
  #page-analytics .category-bars::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #6366f1, #8b5cf6) !important;
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box !important;
  }
  #page-analytics .category-bars::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #4f46e5, #7c3aed) !important;
  }

  /* ───── Transactions ──────────────────────────────────────────── */
  #page-transactions.active { gap: 10px; }
  #page-transactions .filter-card { flex: 0 0 auto; padding: 12px 14px; }
  #page-transactions .table-wrap { flex: 1 1 0; min-height: 0; overflow: hidden; }
  #page-transactions .txn-table tbody tr { height: auto; }
  #page-transactions .pagination { flex: 0 0 auto; }

  /* ───── Accounts ──────────────────────────────────────────────── */
  #page-accounts.active { gap: 12px; }
  #page-accounts #wealthSection .charts-row { min-height: 320px; }
  #page-accounts #wealthSection canvas { max-height: 280px !important; }

  /* ───── Security ──────────────────────────────────────────────── */
  #page-security.active { gap: 10px; }
}


/* ═════════════════════════════════════════════════════════════════
   RESPONSIVE — Phone + Tablet layout fixes (≤ 900px / ≤ 640px)
   Added so FinVista works on all devices, not just desktop.
   ═════════════════════════════════════════════════════════════════ */

/* ── Tablet (≤ 960px) ─────────────────────────────────────────── */
@media (max-width: 960px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 1000; width: 260px;
    box-shadow: 2px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; width: 100% !important; }
  .topbar-burger { display: inline-flex !important; }
  #page-dashboard.active,
  #page-analytics.active { overflow: auto; }
  .charts-row, .analytics-grid {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto !important;
  }
  .chart-body, .donut-wrap { height: 280px !important; min-height: 280px !important; }
  .kpi-row { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
}

/* ── Phone (≤ 640px) ──────────────────────────────────────────── */
@media (max-width: 640px) {
  html { font-size: 14px; }
  body { overflow-x: hidden; }

  .topbar { padding: 10px 12px; height: auto; flex-wrap: wrap; gap: 8px; }
  .topbar-title { font-size: 1.1rem; }
  .topbar-date, .topbar-search { display: none; }
  .topbar-actions { gap: 6px; }
  .topbar-actions button { padding: 6px 10px; font-size: .82rem; }

  .main-content, .page { padding: 12px !important; }
  .page-header h2 { font-size: 1.4rem; }

  .kpi-row { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .kpi-card, .kpi-chip { padding: 10px !important; }
  .kpi-val { font-size: 1.2rem !important; }
  .kpi-label { font-size: .72rem !important; }

  .chart-card { padding: 12px !important; }
  .chart-title { font-size: 1rem !important; }
  .chart-body, .donut-wrap { height: 240px !important; min-height: 240px !important; }

  /* Tables → horizontal scroll on phone */
  .txn-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .txn-table { min-width: 560px; font-size: .82rem; }
  .txn-table th, .txn-table td { padding: 8px 10px; }

  /* Modals fill screen on phone */
  .app-modal .modal-card,
  .fp-modal  .fp-card,
  .mfa-modal .modal-card {
    width: 94vw !important; max-width: 94vw !important;
    max-height: 92vh !important; overflow-y: auto;
    margin: 0 auto;
  }
  .mfa-qr-wrap canvas,
  .mfa-qr-wrap img { width: 180px !important; height: 180px !important; max-width: 180px !important; max-height: 180px !important; }

  /* Accounts page cards stack */
  .connected-banks { grid-template-columns: 1fr !important; }
  .bank-card { padding: 14px !important; }

  /* Security page: cards become full-width */
  .security-grid, .security-cards { grid-template-columns: 1fr !important; gap: 12px !important; }
  .security-card { padding: 14px !important; }

  /* Merchant / category rows: tighter */
  .merchant-row { padding: 8px 10px !important; font-size: .88rem; }
  .merchant-logo { width: 26px !important; height: 26px !important; }
  .cat-bar-header { font-size: .95rem !important; }

  /* Welcome modal fits narrow */
  .welcome-card { padding: 22px 18px !important; }
  .welcome-title { font-size: 1.35rem !important; }
  .welcome-feats { gap: 8px; }
  .welcome-feat { padding: 10px 12px !important; }

  /* Chat bubble stays visible but smaller */
  .chat-bubble { width: 48px !important; height: 48px !important; bottom: 14px !important; right: 14px !important; }

  /* Buttons easier to tap */
  .btn-primary, .btn-submit, .btn-connect, .btn-ghost, button { min-height: 42px; }
}

/* ── Very small phones (≤ 380px) ─────────────────────────────── */
@media (max-width: 380px) {
  .kpi-row { grid-template-columns: 1fr !important; }
  .chart-body, .donut-wrap { height: 200px !important; min-height: 200px !important; }
  .mfa-qr-wrap canvas,
  .mfa-qr-wrap img { width: 160px !important; height: 160px !important; }
}

/* ============ AI INSIGHTS PAGE ============ */
#page-ai .page-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 16px;
}
#page-ai .page-sub { color: #6b7280; font-size: 13px; margin-top: 4px; }
.ai-pill {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white; font-size: 11px; padding: 3px 10px; border-radius: 999px;
  font-weight: 600; vertical-align: middle; margin-left: 6px;
}
.nav-badge {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white; font-size: 10px; padding: 2px 7px; border-radius: 999px;
  font-weight: 700; margin-left: auto;
}
.ai-refresh-btn { display: inline-flex; align-items: center; gap: 6px; }

.ai-hero {
  display: flex; align-items: center; gap: 20px;
  padding: 24px;
  background: linear-gradient(135deg, #667eea15, #764ba215);
  border: 1px solid #667eea30;
  border-radius: 16px;
  margin-bottom: 24px;
}
.ai-hero-icon { font-size: 42px; }
.ai-hero-body { flex: 1; min-width: 0; }
.ai-hero-title { font-size: 18px; font-weight: 600; color: #111827; }
.ai-hero-sub { font-size: 13px; color: #6b7280; margin-top: 4px; }
.ai-hero-score { text-align: center; }
.ai-score-ring {
  width: 72px; height: 72px; border-radius: 50%;
  background: conic-gradient(#667eea var(--score, 0%), #e5e7eb 0);
  display: grid; place-items: center; position: relative;
  margin: 0 auto;
}
.ai-score-ring::before {
  content: ""; position: absolute; inset: 6px;
  border-radius: 50%; background: white;
}
.ai-score-ring span {
  position: relative; font-weight: 700; font-size: 20px; color: #111827;
}
.ai-score-label { font-size: 11px; color: #6b7280; margin-top: 6px; text-transform: uppercase; letter-spacing: 0.5px; }

.ai-section { margin-bottom: 28px; }
.ai-section-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.ai-section-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-size: 18px; flex-shrink: 0;
}
.ai-section-title { font-size: 16px; font-weight: 600; color: #111827; }
.ai-section-sub { font-size: 12px; color: #6b7280; margin-top: 2px; }
.ai-section-total {
  margin-left: auto; font-weight: 700; color: #ff9500;
  font-size: 18px;
}

.ai-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.ai-card {
  background: white; border: 1px solid #e5e7eb; border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.ai-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.06); }
.ai-card-top { display: flex; align-items: center; gap: 10px; }
.ai-card-logo {
  width: 36px; height: 36px; border-radius: 8px;
  background: #f3f4f6; display: grid; place-items: center;
  font-weight: 700; color: #374151; font-size: 14px; flex-shrink: 0;
}
.ai-card-name { font-weight: 600; color: #111827; font-size: 14px; }
.ai-card-meta { font-size: 11px; color: #6b7280; margin-top: 2px; }
.ai-card-amount { margin-left: auto; font-weight: 700; color: #111827; }
.ai-card-body { font-size: 13px; color: #4b5563; line-height: 1.5; }
.ai-card-tag {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; margin-right: 6px;
}
.ai-tag-high { background: #fef2f2; color: #dc2626; }
.ai-tag-med  { background: #fff7ed; color: #ea580c; }
.ai-tag-low  { background: #eff6ff; color: #2563eb; }
.ai-tag-good { background: #ecfdf5; color: #059669; }

.ai-card-actions { display: flex; gap: 8px; margin-top: 4px; }
.ai-btn-sm {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: 1px solid #e5e7eb; background: white; color: #374151;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.ai-btn-sm:hover { background: #f9fafb; }
.ai-btn-sm.primary {
  background: #111827; color: white; border-color: #111827;
}
.ai-btn-sm.primary:hover { background: #374151; }

.ai-empty {
  padding: 20px; text-align: center; color: #6b7280;
  font-size: 13px; background: #f9fafb; border-radius: 12px;
  border: 1px dashed #d1d5db;
}

.ai-disclaimer {
  margin-top: 24px; padding: 12px 16px;
  background: #f9fafb; border: 1px solid #e5e7eb;
  border-radius: 10px; font-size: 12px; color: #6b7280;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .ai-hero { flex-direction: column; text-align: center; }
  .ai-section-total { width: 100%; margin-left: 0; margin-top: 4px; }
  .ai-cards { grid-template-columns: 1fr; }
}

/* ========== AI INSIGHTS — DARK MODE OVERRIDES ========== */
[data-theme="dark"] #page-ai .page-header h1,
[data-theme="dark"] #page-ai .page-header > div > *:first-child { color: #f3f4f6; }
[data-theme="dark"] #page-ai .page-sub { color: #9ca3af; }

[data-theme="dark"] .ai-hero {
  background: linear-gradient(135deg, rgba(102,126,234,0.14), rgba(118,75,162,0.14));
  border: 1px solid rgba(139,92,246,0.35);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
[data-theme="dark"] .ai-hero-title { color: #f9fafb; }
[data-theme="dark"] .ai-hero-sub   { color: #cbd5e1; }
[data-theme="dark"] .ai-score-ring::before { background: #151a2e; }
[data-theme="dark"] .ai-score-ring { background: conic-gradient(#a78bfa var(--score, 0%), rgba(255,255,255,0.08) 0); }
[data-theme="dark"] .ai-score-ring span { color: #f9fafb; }
[data-theme="dark"] .ai-score-label { color: #94a3b8; }

[data-theme="dark"] .ai-section-title { color: #f3f4f6; }
[data-theme="dark"] .ai-section-sub   { color: #94a3b8; }
[data-theme="dark"] .ai-section-icon  { background: rgba(139,92,246,0.15); }
[data-theme="dark"] .ai-section-total { color: #fbbf24; }

[data-theme="dark"] .ai-card {
  background: #1a1f3a;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
[data-theme="dark"] .ai-card:hover {
  box-shadow: 0 10px 28px rgba(0,0,0,0.4);
  border-color: rgba(139,92,246,0.4);
}
[data-theme="dark"] .ai-card-logo {
  background: rgba(255,255,255,0.06);
  color: #e6e8f0;
}
[data-theme="dark"] .ai-card-name   { color: #f3f4f6; }
[data-theme="dark"] .ai-card-meta   { color: #94a3b8; }
[data-theme="dark"] .ai-card-amount { color: #f3f4f6; }
[data-theme="dark"] .ai-card-body   { color: #cbd5e1; }

[data-theme="dark"] .ai-tag-high { background: rgba(220,38,38,0.15); color: #fca5a5; }
[data-theme="dark"] .ai-tag-med  { background: rgba(234,88,12,0.15); color: #fdba74; }
[data-theme="dark"] .ai-tag-low  { background: rgba(37,99,235,0.15); color: #93c5fd; }
[data-theme="dark"] .ai-tag-good { background: rgba(5,150,105,0.15); color: #6ee7b7; }

[data-theme="dark"] .ai-btn-sm {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  color: #e6e8f0;
}
[data-theme="dark"] .ai-btn-sm:hover { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .ai-btn-sm.primary {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff; border-color: transparent;
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}
[data-theme="dark"] .ai-btn-sm.primary:hover { transform: translateY(-1px); }

[data-theme="dark"] .ai-empty {
  background: rgba(255,255,255,0.02);
  border: 1px dashed rgba(255,255,255,0.15);
  color: #94a3b8;
}
[data-theme="dark"] .ai-disclaimer {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.08);
  color: #94a3b8;
}

/* AI Powered badge + loading state */
.ai-powered-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  color: #fff; font-size: 10px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.5px;
  vertical-align: middle; margin-left: 8px;
  box-shadow: 0 2px 8px rgba(99,102,241,0.4);
}
.ai-powered-badge::before {
  content: "✨"; font-size: 10px;
}
.ai-loading {
  display: flex; align-items: center; gap: 10px;
  padding: 20px; background: rgba(99,102,241,0.06);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 12px; color: #a78bfa; font-size: 13px;
}
.ai-loading::before {
  content: ""; width: 16px; height: 16px;
  border: 2px solid rgba(167,139,250,0.3);
  border-top-color: #a78bfa;
  border-radius: 50%;
  animation: aiSpin 0.8s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

/* ========== AI INSIGHTS — PREMIUM REDESIGN ========== */

/* Hero card — simple, bulletproof layout */
.ai-hero {
  position: relative !important;
  overflow: hidden;
  background: linear-gradient(155deg, #1a1f3a, #0f1330) !important;
  border: 1px solid rgba(139,92,246,0.35) !important;
  border-radius: 20px !important;
  padding: 0 !important;
  margin-bottom: 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3), 0 0 0 1px rgba(139,92,246,0.1) inset;
}
[data-theme="light"] .ai-hero {
  background: linear-gradient(155deg, #ffffff, #f8fafc) !important;
  border: 1px solid rgba(99,102,241,0.25) !important;
  box-shadow: 0 8px 24px rgba(15,23,42,0.06);
}

/* Rotating rainbow border — rendered behind the inner card */
.ai-hero::before {
  content: "";
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: conic-gradient(from 0deg,
    transparent 0deg,
    #6366f1 30deg, #a855f7 60deg, #ec4899 90deg,
    transparent 180deg, transparent 360deg);
  animation: aiBorderSpin 5s linear infinite;
  opacity: 0.55;
  z-index: 0;
  pointer-events: none;
}
.ai-hero::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 18px;
  background: linear-gradient(155deg, #1a1f3a, #0f1330);
  z-index: 1;
  pointer-events: none;
}
[data-theme="light"] .ai-hero::after {
  background: linear-gradient(155deg, #ffffff, #f8fafc);
}
@keyframes aiBorderSpin { to { transform: rotate(360deg); } }

.ai-hero-inner {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 26px 28px;
}
.ai-hero-inner::after {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(139,92,246,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139,92,246,0.05) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}
.ai-hero-inner > * { position: relative; z-index: 1; }

.ai-hero-icon {
  font-size: 38px !important;
  width: 70px; height: 70px;
  flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #a855f7, #ec4899);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(139,92,246,0.45), 0 0 0 1px rgba(255,255,255,0.1) inset;
  position: relative;
  animation: aiIconPulse 3s ease-in-out infinite;
}
.ai-hero-body { flex: 1 !important; min-width: 0 !important; }
.ai-hero-score { flex-shrink: 0; text-align: center; }
@keyframes aiIconPulse {
  0%, 100% { box-shadow: 0 10px 30px rgba(139,92,246,0.45), 0 0 0 1px rgba(255,255,255,0.1) inset, 0 0 0 0 rgba(139,92,246,0.5); }
  50%      { box-shadow: 0 10px 36px rgba(139,92,246,0.65), 0 0 0 1px rgba(255,255,255,0.12) inset, 0 0 0 14px rgba(139,92,246,0); }
}

.ai-hero-title {
  font-size: 22px !important;
  font-weight: 700 !important;
  color: #fff;
  background: linear-gradient(135deg, #fff, #c7d2fe);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.3px;
  line-height: 1.3;
}
[data-theme="light"] .ai-hero-title {
  color: #0f172a;
  background: linear-gradient(135deg, #0f172a, #6366f1);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.ai-hero-sub { font-size: 14px !important; color: #b4bad6 !important; margin-top: 6px !important; }

/* Score ring → gradient stroke + glow */
.ai-score-ring {
  width: 90px !important; height: 90px !important;
  background: conic-gradient(
    from 0deg,
    #6366f1 0%, #a855f7 calc(var(--score, 0%) * 0.5), #ec4899 var(--score, 0%),
    rgba(255,255,255,0.06) var(--score, 0%)
  ) !important;
  position: relative;
  filter: drop-shadow(0 0 12px rgba(139,92,246,0.35));
}
.ai-score-ring::before {
  inset: 7px !important;
  background: linear-gradient(155deg, #1a1f3a, #0f1330) !important;
}
.ai-score-ring span {
  font-size: 26px !important;
  background: linear-gradient(135deg, #fff, #c7d2fe);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800 !important;
}
.ai-score-label {
  color: #a78bfa !important;
  font-weight: 700 !important;
  font-size: 10px !important;
}

/* ===== AI Chat-style narrative ===== */
.ai-narrative {
  display: flex; gap: 14px; align-items: flex-start;
  background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(236,72,153,0.08));
  border: 1px solid rgba(139,92,246,0.3);
  border-radius: 18px;
  padding: 18px 20px;
  margin-bottom: 24px;
  position: relative;
  backdrop-filter: blur(10px);
  animation: aiNarrSlide .45s cubic-bezier(.2,.8,.2,1);
}
@keyframes aiNarrSlide {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}
.ai-narrative-avatar {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  display: grid; place-items: center;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(99,102,241,0.35);
}
.ai-narrative-body { flex: 1; color: #e6e8f0; line-height: 1.6; font-size: 14px; }
.ai-narrative-body .ai-narr-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10px; font-weight: 800; letter-spacing: 0.8px;
  color: #a78bfa; text-transform: uppercase; margin-bottom: 6px;
}
.ai-narrative-body .ai-narr-label::after {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: #10b981; box-shadow: 0 0 8px #10b981;
  animation: aiDot 1.4s ease-in-out infinite;
}
@keyframes aiDot { 0%,100% { opacity:1; } 50% { opacity: 0.35; } }

[data-theme="light"] .ai-narrative { color: #1f2937; }
[data-theme="light"] .ai-narrative-body { color: #1f2937; }

/* ===== Loading state ===== */
.ai-loading {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 22px;
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(236,72,153,0.06));
  border: 1px solid rgba(139,92,246,0.3);
  border-radius: 18px;
  color: #c7d2fe; font-size: 14px;
  margin-bottom: 24px;
  position: relative; overflow: hidden;
}
.ai-loading::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(139,92,246,0.15), transparent);
  animation: aiShimmer 1.6s linear infinite;
}
@keyframes aiShimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ===== Sections with gradient accent bars ===== */
.ai-section-head {
  position: relative;
  padding-left: 14px !important;
}
.ai-section-head::before {
  content: "";
  position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: linear-gradient(180deg, #6366f1, #ec4899);
  border-radius: 3px;
}
.ai-section-icon {
  width: 42px !important; height: 42px !important;
  border-radius: 12px !important;
  font-size: 20px !important;
  box-shadow: 0 6px 18px rgba(0,0,0,0.2);
  position: relative;
}
[data-theme="dark"] .ai-section-icon {
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(236,72,153,0.15)) !important;
  border: 1px solid rgba(139,92,246,0.3);
}
.ai-section-title {
  font-size: 18px !important;
  font-weight: 700 !important;
  letter-spacing: -0.2px;
}
.ai-section-total {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 22px !important;
  font-weight: 800 !important;
  text-shadow: 0 0 20px rgba(245,158,11,0.3);
}

/* ===== Redesigned cards ===== */
.ai-cards { gap: 16px !important; }

.ai-card {
  position: relative;
  border-radius: 16px !important;
  padding: 18px !important;
  overflow: hidden;
  isolation: isolate;
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s;
}
/* Gradient-on-hover border trick */
.ai-card::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 16px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(139,92,246,0.0), rgba(236,72,153,0.0));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  transition: background .3s;
  pointer-events: none;
  z-index: 1;
}
.ai-card:hover {
  transform: translateY(-4px) !important;
  box-shadow: 0 16px 40px rgba(99,102,241,0.25) !important;
}
.ai-card:hover::before {
  background: linear-gradient(135deg, rgba(139,92,246,0.7), rgba(236,72,153,0.7));
}
.ai-card > * { position: relative; z-index: 2; }

/* Subtle glow blob behind each card */
.ai-card::after {
  content: "";
  position: absolute;
  top: -40px; right: -40px;
  width: 140px; height: 140px;
  background: radial-gradient(circle, rgba(139,92,246,0.25), transparent 70%);
  opacity: 0;
  transition: opacity .3s;
  z-index: 0;
  pointer-events: none;
}
.ai-card:hover::after { opacity: 1; }

.ai-card-logo {
  width: 42px !important; height: 42px !important;
  border-radius: 11px !important;
  font-size: 15px !important;
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(236,72,153,0.15)) !important;
  color: #fff !important;
  border: 1px solid rgba(139,92,246,0.25);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
[data-theme="light"] .ai-card-logo {
  background: linear-gradient(135deg, #eef2ff, #fce7f3) !important;
  color: #6366f1 !important;
  border-color: rgba(99,102,241,0.2);
}
.ai-card-name   { font-size: 15px !important; font-weight: 700 !important; }
.ai-card-amount {
  font-size: 18px !important;
  background: linear-gradient(135deg, #fff, #c7d2fe);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800 !important;
}
[data-theme="light"] .ai-card-amount {
  background: linear-gradient(135deg, #0f172a, #6366f1);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Tag pills — upgraded */
.ai-card-tag {
  font-size: 10px !important;
  padding: 4px 10px !important;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  backdrop-filter: blur(10px);
}

/* Action buttons — sleeker */
.ai-btn-sm {
  border-radius: 10px !important;
  padding: 9px 14px !important;
  font-size: 12px !important;
  letter-spacing: 0.2px;
  transition: transform .15s, box-shadow .15s, background .15s !important;
}
.ai-btn-sm.primary {
  background: linear-gradient(135deg, #6366f1, #a855f7) !important;
  border: none !important;
  color: #fff !important;
  box-shadow: 0 6px 18px rgba(99,102,241,0.4) !important;
}
.ai-btn-sm.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(99,102,241,0.55) !important;
}

/* ===== Floating sparkles decoration ===== */
.ai-sparkle {
  position: absolute;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #a78bfa;
  box-shadow: 0 0 8px #a78bfa;
  pointer-events: none;
  animation: aiFloat 4s ease-in-out infinite;
}
@keyframes aiFloat {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.6; }
  50%      { transform: translateY(-14px) scale(1.3); opacity: 1; }
}

/* ===== Re-analyze button upgrade ===== */
.ai-refresh-btn {
  background: linear-gradient(135deg, #6366f1, #a855f7) !important;
  border: none !important;
  padding: 10px 20px !important;
  border-radius: 12px !important;
  font-weight: 700 !important;
  box-shadow: 0 8px 24px rgba(99,102,241,0.4) !important;
  transition: transform .15s, box-shadow .15s !important;
  position: relative;
  overflow: hidden;
}
.ai-refresh-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(99,102,241,0.55) !important;
}
.ai-refresh-btn::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transform: translateX(-100%);
  animation: aiBtnShine 3s ease-in-out infinite;
}
@keyframes aiBtnShine {
  0%, 100% { transform: translateX(-100%); }
  50%      { transform: translateX(100%); }
}

/* Powered badge — animated glow */
.ai-powered-badge {
  animation: aiBadgeGlow 2.5s ease-in-out infinite;
}
@keyframes aiBadgeGlow {
  0%, 100% { box-shadow: 0 2px 8px rgba(99,102,241,0.4); }
  50%      { box-shadow: 0 2px 16px rgba(236,72,153,0.6), 0 0 20px rgba(99,102,241,0.3); }
}

/* Page title in AI page */
#page-ai .page-header h2 {
  font-size: 28px !important;
  background: linear-gradient(135deg, #fff, #a78bfa 50%, #ec4899);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800 !important;
  letter-spacing: -0.5px;
}
[data-theme="light"] #page-ai .page-header h2 {
  background: linear-gradient(135deg, #0f172a, #6366f1 50%, #ec4899);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Responsive */
@media (max-width: 700px) {
  .ai-hero-inner { flex-direction: column; text-align: center; padding: 22px; }
  .ai-score-ring { margin: 0 auto; }
}

/* ========== AI BUBBLE CHART (Spending Universe) ========== */
.ai-bubble-wrap {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 18px;
  align-items: stretch;
}
@media (max-width: 900px) {
  .ai-bubble-wrap { grid-template-columns: 1fr; }
}

.ai-bubble-canvas-holder {
  position: relative;
  background: linear-gradient(155deg, rgba(26,31,58,0.85), rgba(15,19,48,0.85));
  border: 1px solid rgba(139,92,246,0.25);
  border-radius: 18px;
  padding: 18px;
  height: 420px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.ai-bubble-canvas-holder::before {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(450px circle at 15% 20%, rgba(99,102,241,0.18), transparent 55%),
    radial-gradient(350px circle at 85% 80%, rgba(236,72,153,0.14), transparent 55%);
  pointer-events: none;
  border-radius: 18px;
}
.ai-bubble-canvas-holder::after {
  content: "";
  position: absolute; inset: 18px;
  background-image:
    linear-gradient(rgba(139,92,246,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139,92,246,0.05) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
  border-radius: 10px;
}
.ai-bubble-canvas-holder canvas { position: relative; z-index: 2; }

[data-theme="light"] .ai-bubble-canvas-holder {
  background: linear-gradient(155deg, #ffffff, #f8fafc);
  border: 1px solid rgba(17,24,39,0.08);
  box-shadow: 0 8px 24px rgba(15,23,42,0.08);
}
[data-theme="light"] .ai-bubble-canvas-holder::before {
  background:
    radial-gradient(450px circle at 15% 20%, rgba(99,102,241,0.08), transparent 55%),
    radial-gradient(350px circle at 85% 80%, rgba(236,72,153,0.06), transparent 55%);
}
[data-theme="light"] .ai-bubble-canvas-holder::after {
  background-image:
    linear-gradient(rgba(99,102,241,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99,102,241,0.05) 1px, transparent 1px);
}

.ai-bubble-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  color: #94a3b8; text-align: center; padding: 24px;
  z-index: 3;
}
.ai-bubble-empty span { font-size: 42px; }
.ai-bubble-empty p    { font-size: 13px; margin: 0; }

/* Legend chips */
.ai-bubble-legend {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 420px; overflow-y: auto;
  padding-right: 4px;
}
.ai-bubble-legend::-webkit-scrollbar { width: 6px; }
.ai-bubble-legend::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.3); border-radius: 3px; }

.ai-bubble-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  color: #e6e8f0;
  cursor: pointer;
  text-align: left;
  transition: transform .15s, background .15s, border-color .15s;
  font: inherit;
  position: relative;
}
.ai-bubble-chip:hover {
  transform: translateX(4px);
  background: rgba(139,92,246,0.1);
  border-color: var(--chip-col, #6366f1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 0 0 1px var(--chip-col) inset;
}
.ai-bubble-chip-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--chip-col, #6366f1);
  box-shadow: 0 0 10px var(--chip-col, #6366f1);
  flex-shrink: 0;
}
.ai-bubble-chip-icon { font-size: 16px; }
.ai-bubble-chip-name { flex: 1; font-size: 13px; font-weight: 600; }
.ai-bubble-chip-amt {
  font-size: 13px; font-weight: 700;
  color: var(--chip-col, #a78bfa);
}
[data-theme="light"] .ai-bubble-chip {
  background: #fff;
  border: 1px solid rgba(17,24,39,0.08);
  color: #1f2937;
  box-shadow: 0 2px 8px rgba(15,23,42,0.04);
}
[data-theme="light"] .ai-bubble-chip:hover {
  background: rgba(99,102,241,0.06);
}

/* ========== TIPS STRIP (replaces tip cards) ========== */
.ai-tips-strip {
  display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(155deg, rgba(26,31,58,0.6), rgba(15,19,48,0.6));
  border: 1px solid rgba(139,92,246,0.2);
  border-radius: 16px;
  padding: 8px;
}
[data-theme="light"] .ai-tips-strip {
  background: #fff;
  border: 1px solid rgba(17,24,39,0.08);
  box-shadow: 0 2px 10px rgba(15,23,42,0.04);
}
.ai-tip-row {
  display: flex; align-items: stretch; gap: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  transition: background .15s, transform .15s;
  position: relative;
}
.ai-tip-row:hover {
  background: rgba(139,92,246,0.08);
  transform: translateX(4px);
}
[data-theme="light"] .ai-tip-row:hover { background: rgba(99,102,241,0.05); }

.ai-tip-num {
  font-size: 11px; font-weight: 800; letter-spacing: 1px;
  color: #a78bfa;
  min-width: 26px;
  align-self: flex-start;
  padding-top: 2px;
}
[data-theme="light"] .ai-tip-num { color: #6366f1; }

.ai-tip-bar {
  width: 3px; border-radius: 3px;
  background: linear-gradient(180deg, #6366f1, #ec4899);
  flex-shrink: 0;
}
.ai-tip-high  .ai-tip-bar { background: linear-gradient(180deg, #ef4444, #f59e0b); }
.ai-tip-med   .ai-tip-bar { background: linear-gradient(180deg, #f59e0b, #fbbf24); }
.ai-tip-good  .ai-tip-bar { background: linear-gradient(180deg, #10b981, #34d399); }

.ai-tip-content { flex: 1; min-width: 0; }
.ai-tip-title {
  font-size: 14px; font-weight: 700;
  color: #fff;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
[data-theme="light"] .ai-tip-title { color: #0f172a; }
.ai-tip-flag {
  font-size: 9px; font-weight: 800; letter-spacing: 0.5px;
  padding: 2px 7px; border-radius: 999px;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  color: #fff;
  text-transform: uppercase;
}
.ai-tip-body {
  font-size: 13px; color: #b4bad6; line-height: 1.5;
  margin-top: 4px;
}
[data-theme="light"] .ai-tip-body { color: #475569; }

/* ===================== AI PAGE v2 — ONE-SCREEN LAYOUT ===================== */
/* IMPORTANT: scope to .active so we don't override `.page { display:none }`
   and render the AI page on every tab. */
.ai-page-v2 { display: none; }
.ai-page-v2.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 100px);      /* page chrome allowance */
  min-height: 560px;
  padding: 14px 18px 18px;
  gap: 12px;
  overflow: hidden;
  position: relative;
  box-sizing: border-box;
}

/* ---------- Topbar ---------- */
.ai-topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: linear-gradient(155deg, #1a1f3a, #0f1330);
  border: 1px solid rgba(139,92,246,0.3);
  border-radius: 14px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
[data-theme="light"] .ai-topbar {
  background: linear-gradient(155deg, #ffffff, #f8fafc);
  border: 1px solid rgba(99,102,241,0.25);
  box-shadow: 0 4px 14px rgba(15,23,42,0.06);
}
.ai-topbar-left  { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.ai-topbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.ai-topbar-text  { min-width: 0; }

.ai-hero-icon-sm {
  width: 46px !important; height: 46px !important;
  font-size: 22px !important;
  border-radius: 13px !important;
  animation: aiIconPulse 3s ease-in-out infinite;
}

.ai-topbar-title {
  margin: 0 !important;
  font-size: 18px !important;
  font-weight: 800 !important;
  color: #fff;
  background: linear-gradient(135deg, #fff, #a78bfa 60%, #ec4899);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  line-height: 1.2;
}
[data-theme="light"] .ai-topbar-title {
  background: linear-gradient(135deg, #0f172a, #6366f1, #ec4899);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.ai-topbar .ai-hero-sub { font-size: 12px !important; margin-top: 2px !important; }

.ai-score-inline { display: flex; align-items: center; gap: 8px; }
.ai-score-inline .ai-score-ring {
  width: 48px !important; height: 48px !important;
  filter: drop-shadow(0 0 8px rgba(139,92,246,0.4));
}
.ai-score-inline .ai-score-ring::before { inset: 4px !important; }
.ai-score-inline .ai-score-ring span { font-size: 14px !important; }
.ai-score-inline .ai-score-label {
  font-size: 10px !important;
  color: #a78bfa !important;
  font-weight: 800 !important;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.ai-topbar .ai-refresh-btn {
  padding: 9px 16px !important;
  font-size: 13px !important;
}

/* ---------- Narrative bar ---------- */
.ai-narrative-bar {
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(236,72,153,0.08));
  border: 1px solid rgba(139,92,246,0.3);
  border-radius: 12px;
  flex-shrink: 0;
  max-height: 70px;
  overflow: hidden;
}
[data-theme="light"] .ai-narrative-bar {
  background: linear-gradient(135deg, rgba(99,102,241,0.06), rgba(236,72,153,0.04));
  border: 1px solid rgba(99,102,241,0.2);
}
.ai-narrative-title {
  font-size: 14px; font-weight: 700; color: #fff;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis;
}
[data-theme="light"] .ai-narrative-title { color: #0f172a; }
.ai-narrative-slot { margin-top: 2px; }
.ai-narrative-slot .ai-narrative {
  margin: 0 !important; padding: 0 !important;
  background: transparent !important; border: none !important;
  font-size: 12px;
}
.ai-narrative-slot .ai-narrative-avatar { display: none; }
.ai-narrative-slot .ai-narr-label { font-size: 9px !important; margin-bottom: 2px !important; }
.ai-narrative-slot .ai-narrative-body {
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
  overflow: hidden; font-size: 12px;
}

/* ---------- 3-column grid, fills remaining space ---------- */
.ai-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1.1fr 1.6fr 1fr;
  gap: 12px;
  min-height: 0;    /* CRITICAL for nested flex/grid scrolling */
  overflow: hidden;
}
@media (max-width: 1100px) {
  .ai-grid { grid-template-columns: 1fr 1fr; }
  .ai-panel-chart { grid-column: 1 / -1; order: -1; max-height: 45vh; }
}
@media (max-width: 720px) {
  .ai-page-v2.active { height: auto; overflow: visible; }
  .ai-grid { grid-template-columns: 1fr; overflow: visible; }
  .ai-panel { max-height: none !important; }
  .ai-panel-scroll { max-height: 50vh; }
}

.ai-panel {
  display: flex; flex-direction: column;
  background: linear-gradient(155deg, #1a1f3a, #0f1330);
  border: 1px solid rgba(139,92,246,0.25);
  border-radius: 14px;
  overflow: hidden;
  min-height: 0;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
[data-theme="light"] .ai-panel {
  background: linear-gradient(155deg, #ffffff, #f8fafc);
  border: 1px solid rgba(17,24,39,0.08);
  box-shadow: 0 4px 14px rgba(15,23,42,0.05);
}

.ai-panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
[data-theme="light"] .ai-panel-head {
  border-bottom: 1px solid rgba(17,24,39,0.06);
}
.ai-panel-head .ai-section-icon {
  width: 34px !important; height: 34px !important;
  font-size: 16px !important;
  border-radius: 10px !important;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.2);
}
.ai-panel-head .ai-section-icon svg { width: 18px; height: 18px; stroke-width: 2; }
.ai-ic-subs  { background: linear-gradient(135deg, #ff8a3d, #ef4444); }
.ai-ic-chart { background: linear-gradient(135deg, #38bdf8, #6366f1); }
.ai-ic-tips  { background: linear-gradient(135deg, #34d399, #10b981); }

/* Topbar gem icon */
.ai-topbar-left .ai-icon-gem {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  box-shadow: 0 6px 18px rgba(139,92,246,0.45), inset 0 1px 0 rgba(255,255,255,0.25);
  font-size: 0;
  flex-shrink: 0;
}
.ai-topbar-left .ai-icon-gem svg { width: 22px; height: 22px; stroke-width: 2; }

/* ══════════════════════════════════════════════════════════════════
   AI panel: Ask Your Money (Claude chat over user's transactions)
══════════════════════════════════════════════════════════════════ */
.ai-panel-ask { display: flex; flex-direction: column; min-height: 0; }
.ai-ic-ask { background: linear-gradient(135deg, #8b5cf6, #ec4899); }

.ai-live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16,185,129,0.25);
  animation: aiLiveDot 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes aiLiveDot {
  0%,100% { box-shadow: 0 0 0 3px rgba(16,185,129,0.25); }
  50%     { box-shadow: 0 0 0 7px rgba(16,185,129,0.00); }
}

/* Anomaly strip (AI-detected unusual charges) */
.ai-anoms {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  background: rgba(239,68,68,0.04);
}
[data-theme="light"] .ai-anoms { background: rgba(239,68,68,0.03); border-bottom-color: rgba(15,23,42,0.06); }
.ai-anom-title {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700;
  color: #fca5a5;
  text-transform: uppercase; letter-spacing: 0.4px;
  margin-bottom: 6px;
}
[data-theme="light"] .ai-anom-title { color: #b91c1c; }
.ai-anom-list { display: flex; flex-direction: column; gap: 4px; }
.ai-anom-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  font-size: 12px;
  transition: background .15s ease;
}
.ai-anom-item:hover { background: rgba(139,92,246,0.12); }
[data-theme="light"] .ai-anom-item { background: rgba(15,23,42,0.03); }
[data-theme="light"] .ai-anom-item:hover { background: rgba(99,102,241,0.08); }
.ai-anom-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.ai-anom-dot.out { background: #f59e0b; }
.ai-anom-dot.dup { background: #3b82f6; }
.ai-anom-name {
  flex: 1; min-width: 0;
  color: #e6e8f0; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
[data-theme="light"] .ai-anom-name { color: #0f172a; }
.ai-anom-amt { color: #fff; font-weight: 800; font-variant-numeric: tabular-nums; }
[data-theme="light"] .ai-anom-amt { color: #0f172a; }
.ai-anom-tag {
  font-size: 9.5px; font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(245,158,11,0.15);
  color: #fbbf24;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.ai-anom-item .ai-anom-dot.dup + .ai-anom-name ~ .ai-anom-tag,
.ai-anom-tag:has(+ *) { }
.ai-anom-item .ai-anom-dot.dup ~ .ai-anom-tag { background: rgba(59,130,246,0.15); color: #60a5fa; }
.ai-anom-ok {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600;
  color: #10b981;
}

/* Chat body */
.ai-chat-body {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.ai-chat-body::-webkit-scrollbar { width: 6px; }
.ai-chat-body::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.35); border-radius: 3px; }
.ai-chat-body::-webkit-scrollbar-track { background: transparent; }

.ai-chat-msg { display: flex; gap: 8px; align-items: flex-start; }
.ai-chat-msg--user { justify-content: flex-end; }
.ai-chat-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(139,92,246,0.5);
}
.ai-chat-bubble {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 12.5px; line-height: 1.5;
  color: #e6e8f0;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.07);
  word-wrap: break-word;
  white-space: pre-wrap;
}
[data-theme="light"] .ai-chat-bubble {
  background: rgba(15,23,42,0.04);
  border-color: rgba(15,23,42,0.07);
  color: #0f172a;
}
.ai-chat-msg--user .ai-chat-bubble {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-color: transparent;
}
.ai-chat-msg--bot  .ai-chat-bubble em {
  color: #9aa4c7; font-style: normal; font-size: 11.5px;
}

/* Typing dots */
.ai-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.ai-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #a78bfa;
  animation: aiTyping 1.2s infinite ease-in-out;
}
.ai-typing i:nth-child(2) { animation-delay: .15s; }
.ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes aiTyping {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1;  transform: translateY(-3px); }
}

/* Suggested prompt chips */
.ai-chat-suggest {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
[data-theme="light"] .ai-chat-suggest { border-top-color: rgba(15,23,42,0.06); }
.ai-chip {
  appearance: none; border: none; cursor: pointer;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  color: #c7d2fe;
  background: rgba(139,92,246,0.12);
  border: 1px solid rgba(139,92,246,0.3);
  transition: background .15s, transform .1s;
}
.ai-chip:hover { background: rgba(139,92,246,0.22); transform: translateY(-1px); }
[data-theme="light"] .ai-chip {
  background: rgba(99,102,241,0.08);
  color: #4338ca;
  border-color: rgba(99,102,241,0.3);
}

/* Input row */
.ai-chat-input-row {
  display: flex; gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
[data-theme="light"] .ai-chat-input-row { border-top-color: rgba(15,23,42,0.06); }
.ai-chat-input-row input {
  flex: 1; min-width: 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(139,92,246,0.3);
  background: rgba(255,255,255,0.04);
  color: #fff;
  font-size: 12.5px;
  outline: none;
  transition: border-color .15s;
}
.ai-chat-input-row input:focus { border-color: #a78bfa; }
[data-theme="light"] .ai-chat-input-row input {
  background: #fff; color: #0f172a;
  border-color: rgba(99,102,241,0.3);
}
.ai-chat-send {
  appearance: none; border: none; cursor: pointer;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(99,102,241,0.4);
  transition: transform .1s;
}
.ai-chat-send:hover { transform: translateY(-1px); }
.ai-chat-send:active { transform: translateY(0); }

/* Treemap SVG tiles (legacy) */
.ai-treemap-svg { display: block; }
.ai-treemap-cell rect { transition: fill-opacity .15s ease, stroke .15s ease; }

/* ── Ranked Bar list ("Spending Breakdown") ─────────────────────── */
.ai-bars-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 6px 10px 6px 4px;
  box-sizing: border-box;
}
.ai-bars-list::-webkit-scrollbar { width: 6px; }
.ai-bars-list::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.35); border-radius: 3px; }
.ai-bars-list::-webkit-scrollbar-track { background: transparent; }

.ai-bar-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  transition: background .15s ease, transform .15s ease, border-color .15s ease;
}
.ai-bar-row:hover {
  background: rgba(139,92,246,0.10);
  border-color: rgba(139,92,246,0.35);
  transform: translateX(2px);
}
[data-theme="light"] .ai-bar-row {
  background: rgba(15,23,42,0.03);
  border: 1px solid rgba(15,23,42,0.06);
}
[data-theme="light"] .ai-bar-row:hover {
  background: rgba(99,102,241,0.08);
  border-color: rgba(99,102,241,0.3);
}

.ai-bar-rank {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: #fff;
  font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(99,102,241,0.4);
}
.ai-bar-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ai-bar-top {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
}
.ai-bar-swatch {
  width: 10px; height: 10px; border-radius: 3px;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.08);
}
.ai-bar-name {
  flex: 1; min-width: 0;
  color: #e6e8f0; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
[data-theme="light"] .ai-bar-name { color: #0f172a; }
.ai-bar-amt {
  font-weight: 800; color: #fff; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
[data-theme="light"] .ai-bar-amt { color: #0f172a; }

.ai-bar-track {
  width: 100%; height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  overflow: hidden;
}
[data-theme="light"] .ai-bar-track { background: rgba(15,23,42,0.07); }
.ai-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .8s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 0 10px rgba(139,92,246,0.35);
}
.ai-bar-meta {
  display: flex; justify-content: space-between;
  font-size: 10.5px;
  color: #9aa4c7;
  font-weight: 500;
}
[data-theme="light"] .ai-bar-meta { color: #64748b; }
.ai-panel-text { flex: 1; min-width: 0; }
.ai-panel-title {
  font-size: 14px; font-weight: 700; color: #fff;
  white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
}
[data-theme="light"] .ai-panel-title { color: #0f172a; }
.ai-panel-sub {
  font-size: 11px; color: #9aa4c7; margin-top: 1px;
  white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
}
[data-theme="light"] .ai-panel-sub { color: #64748b; }
.ai-panel-head .ai-section-total { font-size: 16px !important; }

/* Internal scroll region for each panel */
.ai-panel-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  min-height: 0;
}
.ai-panel-scroll::-webkit-scrollbar { width: 6px; }
.ai-panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(139,92,246,0.35); border-radius: 3px;
}
.ai-panel-scroll::-webkit-scrollbar-thumb:hover { background: rgba(139,92,246,0.55); }
.ai-panel-scroll::-webkit-scrollbar-track { background: transparent; }

/* Stack subscription cards vertically in the narrow column */
.ai-cards-stack {
  grid-template-columns: 1fr !important;
  gap: 10px !important;
}
.ai-cards-stack .ai-card { padding: 12px !important; gap: 8px !important; }
.ai-cards-stack .ai-card-logo {
  width: 34px !important; height: 34px !important; font-size: 13px !important;
}
.ai-cards-stack .ai-card-name { font-size: 13px !important; }
.ai-cards-stack .ai-card-body { font-size: 12px; line-height: 1.45; }
.ai-cards-stack .ai-btn-sm {
  padding: 6px 10px !important; font-size: 11px !important;
}

/* Bubble chart panel fills its column */
.ai-panel-chart .ai-bubble-wrap-v2 {
  flex: 1;
  display: flex;
  padding: 10px;
  min-height: 0;
  overflow: hidden;
}
.ai-panel-chart .ai-bubble-canvas-holder {
  flex: 1;
  height: auto !important;
  min-height: 220px;
  padding: 8px !important;
  border-radius: 12px !important;
  box-shadow: none !important;
  display: flex; align-items: center; justify-content: center;
}
.ai-panel-chart .ai-bubble-legend { display: none !important; }

/* SVG packed bubbles */
.ai-packed-svg { display: block; max-width: 100%; max-height: 100%; }
.ai-packed-group circle {
  transition: filter 0.15s, fill-opacity 0.15s;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.25));
}
.ai-packed-group:hover circle {
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.4));
}

/* Tips inside panel — tighter spacing */
.ai-panel .ai-tips-strip {
  background: transparent;
  border: none;
  padding: 0;
  gap: 4px;
}
.ai-panel .ai-tip-row { padding: 10px 12px; gap: 10px; }
.ai-panel .ai-tip-num { font-size: 10px; min-width: 22px; }
.ai-panel .ai-tip-title { font-size: 13px; }
.ai-panel .ai-tip-body  { font-size: 12px; line-height: 1.4; }

/* AI → Transactions filter banner (shown when a merchant review tab is opened) */
.ai-filter-banner {
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(236,72,153,0.1));
  border: 1px solid rgba(139,92,246,0.35);
  border-radius: 14px;
  padding: 12px 16px;
  margin: 0 0 16px;
  animation: aiFbSlide .35s cubic-bezier(.2,.8,.2,1);
}
@keyframes aiFbSlide { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.ai-fb-icon {
  font-size: 18px; width: 34px; height: 34px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  border-radius: 10px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}
.ai-fb-text { flex: 1; color: #e6e8f0; font-size: 14px; line-height: 1.4; }
.ai-fb-text b { color: #fff; }
[data-theme="light"] .ai-fb-text   { color: #1f2937; }
[data-theme="light"] .ai-fb-text b { color: #0f172a; }
.ai-fb-clear {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #e6e8f0;
  padding: 7px 14px; border-radius: 9px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.ai-fb-clear:hover { background: rgba(255,255,255,0.15); }
[data-theme="light"] .ai-fb-clear {
  background: rgba(17,24,39,0.06); border: 1px solid rgba(17,24,39,0.1); color: #1f2937;
}
[data-theme="light"] .ai-fb-clear:hover { background: rgba(17,24,39,0.1); }

/* ============ ONBOARDING FLOW ============ */
#fxCanvas {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  pointer-events: none; z-index: 99999;
  display: none;
}
#fxCanvas.active { display: block; }

.onboard-modal {
  position: fixed; inset: 0;
  background: rgba(10, 14, 30, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 9998;
  padding: 20px;
}
.onboard-modal.open { display: flex; animation: fadeIn 0.3s ease; }

.onboard-card {
  background: linear-gradient(145deg, #1a1f3a, #151930);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 22px;
  padding: 48px 44px 38px;
  max-width: 640px; width: 100%;
  max-height: 92vh; overflow-y: auto;
  box-shadow: 0 24px 80px rgba(99, 102, 241, 0.25),
              0 0 40px rgba(139, 92, 246, 0.15);
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
  position: relative;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.onboard-progress {
  display: flex; justify-content: center; gap: 8px;
  margin-bottom: 22px;
}
.onboard-dot {
  width: 30px; height: 5px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  transition: all 0.4s;
}
.onboard-dot.active {
  background: linear-gradient(90deg, #6366f1, #a855f7);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}
.onboard-dot.done {
  background: #34c759;
}

.onboard-step { display: none; animation: fadeIn 0.4s ease; }
.onboard-step.active { display: block; }

.onboard-hero {
  font-size: 64px;
  margin: 0 0 8px;
  display: inline-block;
  animation: bounce 1s ease;
}
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-20px); }
  60% { transform: translateY(-10px); }
}

.onboard-title {
  font-size: 26px; font-weight: 700;
  color: #fff; margin: 0 0 10px;
  letter-spacing: -0.3px;
}
.onboard-name {
  background: linear-gradient(90deg, #a855f7, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.onboard-sub {
  color: #a1a7c4;
  font-size: 14.5px;
  line-height: 1.5;
  margin: 0 0 22px;
}
.onboard-feats {
  display: flex; flex-direction: column; gap: 10px;
  margin: 0 0 24px; text-align: left;
}
.onboard-feat {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: 12px;
  transition: transform 0.2s, border-color 0.2s;
}
.onboard-feat:hover {
  transform: translateX(3px);
  border-color: rgba(139, 92, 246, 0.4);
}
.onboard-feat > span:first-child {
  font-size: 24px; flex-shrink: 0;
}
.onboard-feat b {
  color: #fff; font-size: 14px; display: block; margin-bottom: 2px;
}
.onboard-feat small {
  color: #8a90ad; font-size: 12px;
}
.onboard-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 16px;
}
.onboard-actions button {
  flex: 1; min-width: 120px;
  padding: 12px 20px;
  font-size: 14px; font-weight: 600;
  border-radius: 10px; cursor: pointer;
  border: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.onboard-actions .btn-primary {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: white;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.4);
}
.onboard-actions .btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
}
.onboard-actions .btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: #a1a7c4;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.onboard-actions .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.onboard-hint {
  font-size: 12px;
  color: #6b7085;
  margin: 14px 0 0;
  font-style: italic;
}

@media (max-width: 480px) {
  .onboard-card { padding: 24px 20px; }
  .onboard-hero { font-size: 52px; }
  .onboard-title { font-size: 22px; }
  .onboard-actions { flex-direction: column-reverse; }
  .onboard-actions button { width: 100%; }
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE FIXES — comprehensive breakpoint pass
   1440 . 1366 . 1024 (iPad landscape) . 820 (tablet) . 640 . 430 . 360
   Appended last so these rules win against earlier overrides.
══════════════════════════════════════════════════════════════════ */

html, body { overflow-x: hidden; max-width: 100vw; }
*, *::before, *::after { box-sizing: border-box; }

/* iPad landscape / small laptop: collapse sidebar */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 40px rgba(0,0,0,.6); }
  .main { margin-left: 0 !important; width: 100% !important; }
  .menu-btn { display: inline-flex !important; }
  .topbar-date { display: none; }
  .ai-grid { grid-template-columns: 1fr 1fr !important; }
  .ai-panel-chart { grid-column: 1 / -1; order: -1; max-height: 46vh; }
  .ai-page-v2.active { height: auto; min-height: calc(100vh - 80px); overflow: visible; }
}

/* Tablet portrait */
@media (max-width: 820px) {
  .page { padding: 14px 16px; }
  .page-header h2 { font-size: 1.4rem; }
  .cards-grid { grid-template-columns: 1fr 1fr !important; gap: 10px; }
  .charts-row { grid-template-columns: 1fr !important; gap: 10px; }
  .analytics-grid { grid-template-columns: 1fr !important; }
  .topbar { padding: 0 14px; }
  .ai-topbar { padding: 10px 12px; flex-wrap: wrap; gap: 10px; }
  .ai-topbar-left  { flex: 1 1 60%; min-width: 0; }
  .ai-topbar-right { flex: 0 0 auto; gap: 8px; }
  .ai-topbar-title { font-size: 16px !important; }
  .ai-topbar-left .ai-icon-gem { width: 36px; height: 36px; }
  .ai-topbar-left .ai-icon-gem svg { width: 18px; height: 18px; }
  .ai-refresh-btn span { display: none; }
  .ai-refresh-btn { padding: 8px !important; }
}

/* Mobile: single column, large touch targets */
@media (max-width: 640px) {
  .page { padding: 12px; }
  .page-header { gap: 8px; margin-bottom: 12px; }
  .page-header h2 { font-size: 1.25rem; }
  .cards-grid { grid-template-columns: 1fr !important; }
  .card-value { font-size: 1.35rem; }
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="password"], input[type="number"], input[type="date"],
  select, textarea {
    min-height: 42px;
    font-size: 16px !important;
  }
  .txn-table { font-size: .85rem; }
  .txn-table td, .txn-table th { padding: 8px 6px !important; }
  .setup-modal-box, .app-modal-card, .onboard-card, .welcome-card,
  .mfa-modal .modal-card, .mfa-card, .modal-card, .verify-card {
    max-width: calc(100vw - 24px) !important;
    width: calc(100vw - 24px) !important;
    margin: 12px auto !important;
    padding: 20px !important;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
  }
  .ai-chat-suggest { padding: 6px 10px; gap: 5px; }
  .ai-chip { padding: 6px 10px; font-size: 12px; }
  .ai-chat-input-row { padding: 8px 10px; gap: 6px; }
  .ai-chat-input-row input { font-size: 16px; min-height: 38px; }
  .ai-chat-send { width: 38px; height: 38px; flex-shrink: 0; }
  .chat-panel {
    bottom: 12px; right: 12px; left: 12px;
    width: auto;
    height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 80px);
    max-height: calc(100vh - 100px);
  }
  .sidebar { width: min(80vw, 280px); }
}

/* Small phones */
@media (max-width: 430px) {
  .page { padding: 10px; }
  .page-header h2 { font-size: 1.1rem; }
  .card-value { font-size: 1.2rem; }
  .card-label { font-size: .72rem; }
  .topbar { height: 54px; padding: 0 10px; }
  .topbar-logo { font-size: 0.95rem; }
  .demo-mode-pill { display: none; }
  .ai-topbar { padding: 10px; }
  .ai-topbar-left { flex: 1 1 100%; }
  .ai-topbar-right { flex: 1 1 100%; justify-content: space-between; }
  .ai-topbar-title { font-size: 15px !important; }
  .ai-hero-sub { font-size: 11px !important; }
  .ai-panel-head { padding: 10px; gap: 8px; }
  .ai-panel-head .ai-section-icon { width: 30px !important; height: 30px !important; }
  .ai-panel-head .ai-section-icon svg { width: 14px; height: 14px; }
  .ai-panel-title { font-size: 14.5px; }
  .ai-panel-sub { font-size: 11.5px; }
  .ai-chat-bubble { max-width: 92%; font-size: 13.5px; padding: 10px 12px; }
  .ai-chat-avatar { width: 22px; height: 22px; }
  .ai-anom-item { flex-wrap: wrap; padding: 6px 8px; gap: 6px; }
  .ai-anom-name { flex: 1 1 50%; font-size: 11.5px; }
  .ai-anom-amt { font-size: 12px; }
  .ai-anom-tag { font-size: 9px; padding: 2px 5px; }
  .ai-cards-stack .ai-card { padding: 10px !important; }
  .ai-cards-stack .ai-card-name { font-size: 12px !important; }
  .ai-cards-stack .ai-card-body { font-size: 11.5px !important; line-height: 1.4; }
  .ai-cards-stack .ai-btn-sm { font-size: 10.5px !important; padding: 5px 8px !important; }
  .drill-group { width: 100%; }
  .drill-group select,
  .filter-group select,
  .filter-group input { width: 100%; min-height: 42px; font-size: 15px; }
  .txn-table th:nth-child(3),
  .txn-table td:nth-child(3),
  .txn-table th:nth-child(4),
  .txn-table td:nth-child(4),
  .txn-table th:nth-child(5),
  .txn-table td:nth-child(5) { display: none; }
  .txn-table th:nth-child(6),
  .txn-table td:nth-child(6) { text-align: right; }
  .page-btn { min-width: 32px; height: 32px; padding: 0 8px; font-size: 0.8rem; }
  .verify-card, .mfa-card { padding: 18px !important; }
  .app-footer { padding: 10px 12px; font-size: 11px; flex-wrap: wrap; gap: 6px; }
}

/* Ultra-small phones */
@media (max-width: 360px) {
  .page { padding: 8px; }
  .page-header h2 { font-size: 1rem; }
  .card-value { font-size: 1.1rem; }
  .topbar { padding: 0 8px; }
  .topbar-logo { font-size: 0.85rem; }
  .ai-topbar { gap: 8px; }
  .ai-topbar-title { font-size: 14px !important; }
  .ai-score-inline .ai-score-ring { width: 40px !important; height: 40px !important; }
  .ai-score-inline .ai-score-ring span { font-size: 12px !important; }
  .ai-chip { font-size: 11.5px; padding: 6px 9px; }
  .ai-anom-title { font-size: 10px; }
  .ai-anom-list { gap: 3px; }
}

/* Landscape phones (short viewport) */
@media (max-height: 480px) and (orientation: landscape) {
  .ai-page-v2.active { height: auto; min-height: auto; overflow: visible; }
  .ai-narrative-bar { max-height: none; }
  .onboard-card, .welcome-card, .verify-card, .mfa-card {
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }
}

/* ── Large monitors (≥1600px: 27" QHD etc.) — modest scale-up only ── */
@media (min-width: 1600px) {
  .page { padding: 18px 26px; }
  .ai-grid { gap: 14px; }
  .cards-grid, .charts-row, .analytics-grid { gap: 14px; }
}

/* ── 27" QHD (≥1920px): a little more padding, no font bump ── */
@media (min-width: 1920px) {
  .page { padding: 22px 36px; }
}

/* ── 4K / 32" and up (≥2400px) ── */
@media (min-width: 2400px) {
  .page { padding: 28px 52px; }
  .cards-grid, .charts-row, .analytics-grid { gap: 18px; }
  .ai-grid { gap: 18px; }
}

/* ══════════════════════════════════════════════════════════════════
   GLOBAL FONT-SIZE REDUCTION — pulls down body-level type ~1 step
   so the whole app feels tighter without rewriting individual rules.
══════════════════════════════════════════════════════════════════ */
html { font-size: 15px; }
body { font-size: 13.5px; }
.page-header h2 { font-size: 1.5rem; }
.card-value  { font-size: 1.4rem; }
.card-label  { font-size: .74rem; }
/* ── Plan-based visibility ──────────────────────────────────────
   Users on the Pro plan don't get AI features. We hide the sidebar
   AI Insights link + the Ask Your Money card on the dashboard.
   Users on the Max plan see everything. */
body[data-plan="pro"] .nav-item[data-page="ai"] { display: none !important; }
body[data-plan="pro"] #page-ai                  { display: none !important; }
body[data-plan="pro"] .ai-dashboard-card        { display: none !important; }

/* Trial banner shown in topbar while the free trial is active */
.trial-banner {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: linear-gradient(135deg, rgba(139,92,246,0.18), rgba(99,102,241,0.18));
  border: 1px solid rgba(139,92,246,0.35);
  font-size: 0.78rem; font-weight: 600;
  color: #c4b5fd;
  cursor: pointer;
  white-space: nowrap;
}
.trial-banner:hover { background: linear-gradient(135deg, rgba(139,92,246,0.28), rgba(99,102,241,0.28)); }
.trial-banner.expired { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.4); color: #fca5a5; }
.trial-banner.urgent  { background: rgba(251,146,60,0.18); border-color: rgba(251,146,60,0.5); color: #fdba74;
                        animation: trialPulse 2s ease-in-out infinite; }
@keyframes trialPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(251,146,60,0.45); } 50% { box-shadow: 0 0 0 6px rgba(251,146,60,0); } }

/* Login-time trial reminder popup */
.trial-popup-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: trialPopupFade .2s ease;
}
@keyframes trialPopupFade { from { opacity: 0; } to { opacity: 1; } }
.trial-popup {
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 18px;
  padding: 28px 28px 24px;
  max-width: 400px; width: 100%;
  text-align: center;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
  animation: trialPopupPop .25s cubic-bezier(.2,.9,.3,1.3);
}
@keyframes trialPopupPop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
[data-theme="light"] .trial-popup { background: #ffffff; border-color: rgba(15,23,42,0.08); }
.trial-popup-icon { font-size: 2.4rem; margin-bottom: 8px; }
.trial-popup-title {
  font-size: 1.15rem; font-weight: 700; margin: 0 0 8px;
  color: #f1f5f9;
}
[data-theme="light"] .trial-popup-title { color: #0f172a; }
.trial-popup-body {
  font-size: 0.92rem; color: #94a3b8; margin: 0 0 20px; line-height: 1.5;
}
[data-theme="light"] .trial-popup-body { color: #475569; }
.trial-popup-actions { display: flex; gap: 10px; }
.trial-popup-actions button {
  flex: 1; padding: 11px 14px; border-radius: 10px;
  font-size: 0.92rem; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; font-family: inherit;
}
.trial-popup-dismiss {
  background: rgba(148, 163, 184, 0.12);
  color: #e2e8f0;
  border-color: rgba(148, 163, 184, 0.22);
}
.trial-popup-dismiss:hover { background: rgba(148, 163, 184, 0.2); }
[data-theme="light"] .trial-popup-dismiss { background: rgba(15,23,42,0.04); color: #0f172a; border-color: rgba(15,23,42,0.1); }
.trial-popup-cta.primary {
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: white;
  box-shadow: 0 6px 18px rgba(139, 92, 246, 0.35);
}
.trial-popup-cta.primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(139, 92, 246, 0.5); }
[data-theme="light"] .trial-banner { color: #6d28d9; }

.ai-topbar-title { font-size: 18px !important; }
.ai-hero-sub     { font-size: 13px !important; }
.ai-panel-title  { font-size: 15px; }
.ai-panel-sub    { font-size: 12px; }
.ai-narrative-title { font-size: 15px; }
.ai-chat-bubble  { font-size: 14px; line-height: 1.5; }
.ai-chip         { font-size: 12.5px; padding: 7px 11px; }
.ai-bar-name     { font-size: 13px; }
.ai-bar-amt      { font-size: 13.5px; }
.ai-chat-input-row input { font-size: 14px; }
.ai-panel .ai-tip-title { font-size: 14px; }
.ai-panel .ai-tip-body  { font-size: 13px; }

/* ── Fix blank donut chart & cramped demo banner on mobile ──
   Dashboard/Analytics donuts rely on flex parent height — on narrow
   screens that collapses to 0. Pin a sensible min-height and let
   Chart.js resize. */
@media (max-width: 820px) {
  .donut-wrap,
  #page-dashboard .donut-wrap,
  #page-analytics .donut-wrap,
  .chart-body {
    min-height: 260px !important;
    height: 260px !important;
  }
  .donut-wrap canvas,
  .chart-body canvas {
    max-height: 260px !important;
  }
  .chart-card { min-height: 320px; }
  /* Demo banner: stack content cleanly on phones */
  .demo-banner {
    padding: 8px 12px !important;
    gap: 6px !important;
    font-size: 12px !important;
  }
  .demo-banner span:last-of-type {
    flex: 1 1 100%;
    font-size: 11.5px;
    line-height: 1.35;
  }
  .demo-banner .banner-btn { padding: 6px 10px; font-size: 11px; }
}

/* ── Minimum supported viewport: 375×667 (iPhone SE / iPhone 8) ──
   All content must fit comfortably at this size. */
@media (max-width: 375px) {
  .page { padding: 10px; }
  .page-header h2 { font-size: 1.05rem; }
  .card-value { font-size: 1.15rem; }
  .ai-topbar-title { font-size: 14px !important; }
  .ai-hero-sub { font-size: 10.5px !important; }
  .ai-panel-title { font-size: 13.5px; }
  .ai-panel-sub { font-size: 11px; }
  .ai-chat-bubble { font-size: 13px; }
  .ai-chip { font-size: 11.5px; padding: 6px 9px; }
  .ai-bar-name, .ai-bar-amt { font-size: 11.5px; }
  .topbar { height: 52px; padding: 0 10px; }
  .topbar-logo { font-size: 0.88rem; }
}
