@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600;9..40,700&display=swap');

/* ─── Tokens ─────────────────────────────────────────────────── */
:root {
  --purple:        #6B21C8;
  --purple-dark:   #581c87;
  --purple-mid:    #7e22ce;
  --purple-light:  #f3eaff;
  --purple-border: #e0ccff;
  --green:         #4a7c4e;
  --black:         #111111;
  --grey:          #555555;
  --grey-light:    #f7f7f7;
  --grey-border:   #e8e8e8;
  --white:         #ffffff;
  --danger:        #c0392b;
  --success:       #3a7d44;
  --amber:         #b45309;

  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;

  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 4px 24px rgba(107,33,200,0.08);
  --shadow-lg: 0 12px 36px rgba(107,33,200,0.12);
  --transition: 180ms cubic-bezier(0.4,0,0.2,1);
  --max: 1100px;
}

/* ─── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--grey-light);
  color: var(--black);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }

/* ─── Login Page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grey-light);
  position: relative;
  overflow: hidden;
}
.login-page::before {
  content: '';
  position: absolute;
  width: 700px; height: 700px;
  background: radial-gradient(circle, rgba(107,33,200,0.07) 0%, transparent 65%);
  top: -200px; right: -200px;
  pointer-events: none;
}
.login-card {
  background: var(--white);
  border: 1px solid var(--grey-border);
  border-radius: 16px;
  padding: 52px 48px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.45s ease both;
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.login-logo-text {
  font-size: 1.15rem;
  font-weight: 300;
  color: var(--black);
  letter-spacing: -0.01em;
  line-height: 1;
}
.login-logo-text strong { font-weight: 700; }
.login-sub {
  color: var(--grey);
  font-size: 0.875rem;
  margin-bottom: 36px;
}
.login-card h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  margin-bottom: 28px;
  font-weight: 400;
  color: var(--black);
}

/* ─── Fields ─────────────────────────────────────────────────── */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--grey);
  margin-bottom: 7px;
  font-weight: 600;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--white);
  border: 1.5px solid var(--grey-border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--black);
  font-size: 0.95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(107,33,200,0.1);
}

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition);
  cursor: pointer;
  border: none;
}
.btn-primary { background: var(--purple); color: var(--white); }
.btn-primary:hover { opacity: 0.87; transform: translateY(-1px); }
.btn-secondary { background: transparent; color: var(--purple); border: 1.5px solid var(--purple); }
.btn-secondary:hover { background: var(--purple-light); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { opacity: 0.87; }
.btn-ghost { color: var(--grey); padding: 8px 14px; font-weight: 500; }
.btn-ghost:hover { color: var(--purple); }
.btn-sm { padding: 8px 16px; font-size: 0.82rem; }
.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 12px; text-align: center; }

/* ─── App Shell ───────────────────────────────────────────────── */
.app { display: none; flex-direction: column; min-height: 100vh; }
.app.active { display: flex; }

.topnav {
  height: 70px;
  background: rgba(255,255,255,0.97);
  border-bottom: 1px solid #ebebeb;
  display: flex;
  align-items: flex-end;
  padding: 0 28px 10px;
  gap: 4px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}
.topnav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  text-decoration: none;
}
.topnav-logo-text {
  font-size: 1rem;
  font-weight: 300;
  color: var(--black);
  letter-spacing: -0.01em;
  line-height: 1;
}
.topnav-logo-text strong { font-weight: 700; }
.topnav-link {
  font-size: 0.85rem;
  color: var(--grey);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-weight: 500;
  cursor: pointer;
}
.topnav-link:hover { color: var(--purple); }
.topnav-link.active { color: var(--purple); background: var(--purple-light); }
.topnav-avatar {
  width: 32px; height: 32px;
  background: var(--purple);
  color: var(--white);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
  cursor: pointer; margin-left: 8px;
}

.main { flex: 1; padding: 36px 28px; max-width: var(--max); margin: 0 auto; width: 100%; }

/* ─── Pages ──────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; animation: fadeUp 0.3s ease both; }
.page-title { font-family: var(--font-display); font-size: 2rem; font-weight: 400; margin-bottom: 4px; letter-spacing: -0.02em; color: var(--black); }
.page-sub { color: var(--grey); font-size: 0.875rem; margin-bottom: 32px; }

/* ─── Cards ───────────────────────────────────────────────────── */
.card { background: var(--white); border: 1px solid var(--grey-border); border-radius: var(--radius); padding: 24px; }
.card-title { font-size: 0.72rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--grey); margin-bottom: 16px; font-weight: 600; }

/* ─── Dashboard ───────────────────────────────────────────────── */
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 20px; }
.account-card { background: var(--white); border: 1px solid var(--grey-border); border-radius: var(--radius); padding: 24px; transition: all var(--transition); }
.account-card:hover { border-color: var(--purple-border); box-shadow: var(--shadow); transform: translateY(-2px); }
.account-name { font-size: 0.72rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--grey); margin-bottom: 10px; font-weight: 600; }
.account-balance { font-family: var(--font-display); font-size: 2.2rem; letter-spacing: -0.02em; margin-bottom: 14px; line-height: 1; color: var(--black); }
.account-meta { font-size: 0.8rem; color: var(--grey); margin-bottom: 16px; line-height: 1.6; }
.account-meta span { color: var(--black); font-weight: 500; }
.account-update-btn { font-size: 0.82rem; color: var(--purple); background: var(--purple-light); border: none; border-radius: var(--radius-sm); padding: 7px 14px; font-weight: 600; transition: all var(--transition); cursor: pointer; }
.account-update-btn:hover { background: var(--purple-border); }

.summary-bar { background: var(--purple); border-radius: var(--radius); padding: 28px 36px; display: flex; align-items: center; gap: 40px; margin-bottom: 20px; flex-wrap: wrap; }
.summary-item { text-align: center; }
.summary-label { font-size: 0.72rem; letter-spacing: 0.09em; text-transform: uppercase; color: rgba(255,255,255,0.65); margin-bottom: 6px; font-weight: 600; }
.summary-value { font-family: var(--font-display); font-size: 1.9rem; letter-spacing: -0.02em; line-height: 1; color: var(--white); }
.summary-value.positive { color: #86efac; }
.summary-value.negative { color: #fca5a5; }
.summary-divider { width: 1px; background: rgba(255,255,255,0.2); align-self: stretch; }

.category-bars { display: flex; flex-direction: column; gap: 16px; margin-top: 4px; }
.cat-bar-row { display: flex; align-items: center; gap: 14px; }
.cat-bar-label { font-size: 0.82rem; color: var(--grey); width: 80px; flex-shrink: 0; font-weight: 500; }
.cat-bar-track { flex: 1; height: 8px; background: var(--grey-light); border-radius: 99px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 99px; transition: width 0.7s cubic-bezier(0.4,0,0.2,1); }
.cat-bar-fill.essential { background: var(--purple); }
.cat-bar-fill.savings   { background: var(--green); }
.cat-bar-fill.fun       { background: #9333ea; }
.cat-bar-pct { font-size: 0.82rem; color: var(--grey); width: 36px; text-align: right; font-weight: 500; }

/* ─── Payments ───────────────────────────────────────────────── */
.payments-controls { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.payments-controls select { background: var(--white); border: 1.5px solid var(--grey-border); border-radius: var(--radius-sm); padding: 8px 14px; color: var(--black); font-size: 0.85rem; outline: none; transition: border-color var(--transition); font-weight: 500; cursor: pointer; }
.payments-controls select:focus { border-color: var(--purple); }

.payments-table { width: 100%; border-collapse: collapse; }
.payments-table th { text-align: left; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--grey); padding: 12px 18px; font-weight: 600; border-bottom: 1px solid var(--grey-border); background: var(--grey-light); }
.payments-table th:first-child { border-radius: 12px 0 0 0; }
.payments-table th:last-child  { border-radius: 0 12px 0 0; }
.payments-table td { padding: 14px 18px; font-size: 0.9rem; border-bottom: 1px solid var(--grey-border); vertical-align: middle; color: var(--black); }
.payments-table tr:last-child td { border-bottom: none; }
.payments-table tbody tr { transition: background var(--transition); }
.payments-table tbody tr:hover td { background: var(--purple-light); }

.payment-row.passed .payment-name { color: var(--success); font-weight: 500; }
.payment-row.passed .payment-date { color: var(--success); }
.payment-row.passed td { color: var(--grey); }
.payment-row.upcoming .payment-name { color: var(--black); font-weight: 500; }
.payment-row.upcoming .payment-date { color: var(--amber); font-weight: 600; }

.payment-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: 0.72rem; font-weight: 600; }
.badge-essential { background: var(--purple-light); color: var(--purple); }
.badge-savings   { background: #dcfce7; color: var(--green); }
.badge-fun       { background: #f3e8ff; color: #7e22ce; }
.badge-oneoff    { background: #fee2e2; color: var(--danger); }

.payment-actions { display: flex; gap: 6px; opacity: 0; transition: opacity var(--transition); }
.payments-table tbody tr:hover .payment-actions { opacity: 1; }
.icon-btn { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 6px; color: var(--grey); transition: all var(--transition); background: none; border: none; cursor: pointer; font-size: 0.9rem; }
.icon-btn:hover { color: var(--purple); background: var(--purple-light); }
.icon-btn.danger:hover { color: var(--danger); background: #fee2e2; }

/* ─── Modal ───────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 20px; backdrop-filter: blur(4px); }
.modal-overlay.open { display: flex; }
.modal { background: var(--white); border: 1px solid var(--grey-border); border-radius: 16px; padding: 36px; width: 100%; max-width: 480px; box-shadow: var(--shadow-lg); animation: fadeUp 0.22s ease both; }
.modal-title { font-family: var(--font-display); font-size: 1.5rem; margin-bottom: 24px; font-weight: 400; color: var(--black); }
.modal-row { display: flex; gap: 12px; }
.modal-row .field { flex: 1; }
.modal-actions { display: flex; gap: 10px; margin-top: 24px; justify-content: flex-end; }

.toggle-field { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--grey-border); margin-top: 4px; }
.toggle-label { font-size: 0.9rem; color: var(--black); font-weight: 500; }
.toggle-sub { font-size: 0.78rem; color: var(--grey); margin-top: 2px; }
.toggle { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider { position: absolute; inset: 0; background: var(--grey-border); border-radius: 99px; cursor: pointer; transition: background var(--transition); }
.toggle-slider::before { content: ''; position: absolute; width: 18px; height: 18px; background: var(--white); border-radius: 50%; left: 3px; top: 3px; transition: all var(--transition); box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle input:checked + .toggle-slider { background: var(--purple); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ─── Onboarding ──────────────────────────────────────────────── */
.onboarding { max-width: 540px; margin: 60px auto 0; text-align: center; }
.onboarding-icon { font-size: 3rem; margin-bottom: 20px; }
.onboarding h2 { font-family: var(--font-display); font-size: 2rem; margin-bottom: 12px; font-weight: 400; color: var(--black); }
.onboarding p { color: var(--grey); margin-bottom: 36px; }
.onboarding-form { text-align: left; }
.accounts-setup { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.account-setup-row { display: flex; align-items: center; gap: 12px; background: var(--white); border: 1.5px solid var(--grey-border); border-radius: var(--radius-sm); padding: 13px 16px; transition: border-color var(--transition); }
.account-setup-row:focus-within { border-color: var(--purple); }
.account-setup-num { width: 26px; height: 26px; background: var(--purple-light); color: var(--purple); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.78rem; font-weight: 700; flex-shrink: 0; }
.account-setup-row input { flex: 1; background: none; border: none; outline: none; color: var(--black); font-size: 0.95rem; }

/* ─── Profile ─────────────────────────────────────────────────── */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.audit-list { display: flex; flex-direction: column; }
.audit-item { display: flex; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--grey-border); font-size: 0.85rem; }
.audit-item:last-child { border-bottom: none; }
.audit-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--purple); flex-shrink: 0; margin-top: 5px; }
.audit-action { color: var(--black); font-weight: 500; }
.audit-meta { color: var(--grey); font-size: 0.78rem; margin-top: 2px; }

/* ─── Upload ──────────────────────────────────────────────────── */
.upload-zone { border: 2px dashed var(--grey-border); border-radius: var(--radius); padding: 52px 36px; text-align: center; transition: all var(--transition); cursor: pointer; background: var(--white); }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--purple); background: var(--purple-light); }
.upload-icon { font-size: 2.5rem; margin-bottom: 14px; }
.upload-text { color: var(--grey); font-size: 0.9rem; }
.upload-text strong { color: var(--purple); }

/* ─── Utilities ───────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mb-8   { margin-bottom: 8px; }
.mb-16  { margin-bottom: 16px; }
.mb-24  { margin-bottom: 24px; }
.text-muted  { color: var(--grey); }
.text-sm     { font-size: 0.85rem; }
.text-purple { color: var(--purple); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ─── Animations ──────────────────────────────────────────────── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.4); border-top-color: var(--white); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }

/* ─── Toast ───────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast { background: var(--white); border: 1px solid var(--grey-border); border-radius: var(--radius-sm); padding: 12px 18px; font-size: 0.85rem; box-shadow: var(--shadow-lg); animation: fadeUp 0.25s ease both; max-width: 300px; border-left: 3px solid var(--purple); color: var(--black); font-weight: 500; }
.toast.error   { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  .topnav { padding: 0 16px 8px; height: 60px; }
  .topnav-link span { display: none; }
  .main { padding: 20px 16px; }
  .summary-bar { gap: 20px; padding: 20px 24px; }
  .summary-value { font-size: 1.5rem; }
  .profile-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .login-card { padding: 36px 24px; }
  .modal { padding: 24px; }
  .accounts-grid { grid-template-columns: 1fr; }
  .payments-table th:nth-child(3), .payments-table td:nth-child(3) { display: none; }
  .payment-actions { opacity: 1; }
}
