:root {
  --navy-900: #0b1b33;
  --navy-800: #12294a;
  --navy-700: #1b3a63;
  --ink: #0f172a;
  --ink-muted: #475569;
  --ink-subtle: #64748b;
  --line: #e2e8f0;
  --surface: #ffffff;
  --canvas: #f4f6fa;
  --brand: #1d4ed8;
  --brand-dark: #1e40af;
  --brand-soft: #e8effd;
  --brand-light: #93b4f5;
  /* The interactive accent follows the brand; green is reserved for credits. */
  --accent: #1d4ed8;
  --accent-soft: #e8effd;
  --positive: #047857;
  --negative: #b91c1c;
  --danger-soft: #fef2f2;
  --success-soft: #ecfdf5;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, .08);
  --z-header: 20;
}

* { box-sizing: border-box; }

/* Flex/grid display values otherwise win over the UA's [hidden] rule. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.015em; }
p { margin: 0; }
a { color: var(--accent); }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--navy-900);
  color: #fff;
  padding: .75rem 1rem;
  z-index: 50;
}
.skip-link:focus { left: 1rem; top: 1rem; }

:where(a, button, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--navy-900);
  color: #fff;
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: .85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  color: #fff;
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -.02em;
  text-decoration: none;
}
.brand-mark { width: 24px; height: 24px; color: #93b4f5; }

.nav { display: flex; gap: .35rem; margin-right: auto; }
.nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: .5rem .85rem;
  border-radius: var(--radius-sm);
  font-size: .94rem;
  font-weight: 500;
  transition: background-color .2s ease, color .2s ease;
}
.nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav a.is-active { background: rgba(147, 180, 245, .18); color: #93b4f5; }

.topbar-user { display: flex; align-items: center; gap: .7rem; }
.topbar-name { font-size: .92rem; color: #e2e8f0; }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .9rem;
}

/* ---------- Page shell ---------- */

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}
.page-auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.page-head { margin-bottom: 1.5rem; }
.page-head h1 { font-size: 1.6rem; }
.page-head p { color: var(--ink-muted); margin-top: .3rem; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .85rem;
}
.section-head h2 { font-size: 1.08rem; }
.section-head a { font-size: .9rem; font-weight: 500; text-decoration: none; }
.section-head a:hover { text-decoration: underline; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.25rem; }

.summary {
  background: linear-gradient(135deg, var(--navy-800), var(--navy-700));
  color: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
}
.summary-label { font-size: .85rem; color: #a5c0dd; letter-spacing: .02em; }
.summary-value { font-size: 2.3rem; font-weight: 680; letter-spacing: -.03em; margin-top: .2rem; }
.summary-meta { font-size: .88rem; color: #a5c0dd; margin-top: .4rem; }

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.account-card {
  display: block;
  padding: 1.15rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.account-card:hover { border-color: #94a3b8; box-shadow: var(--shadow-md); }

.account-top { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.account-name { font-weight: 600; font-size: .98rem; }
.account-number { color: var(--ink-subtle); font-size: .85rem; margin-top: .1rem; }
.account-balance { font-size: 1.55rem; font-weight: 660; letter-spacing: -.02em; margin-top: .85rem; }
.account-balance.is-negative { color: var(--negative); }

.tag {
  font-size: .72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .22rem .5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #1e40af;
  white-space: nowrap;
}
.tag-credit { background: #ede9fe; color: #5b21b6; }
.tag-savings { background: #dbeafe; color: #1d4ed8; }

/* ---------- Layout columns ---------- */

.columns {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

/* ---------- Transactions ---------- */

.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-item {
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--line);
}
.tx-item:first-child { border-top: 0; }

.tx-icon {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #f1f5f9;
  color: var(--ink-muted);
  display: grid;
  place-items: center;
}
.tx-icon svg { width: 19px; height: 19px; }
.tx-icon.is-income { background: var(--success-soft); color: var(--positive); }

.tx-main { min-width: 0; flex: 1; }
.tx-desc {
  font-weight: 550;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-meta { font-size: .84rem; color: var(--ink-subtle); margin-top: .1rem; }

.tx-amounts { text-align: right; flex: none; }
.tx-amount { font-weight: 620; font-variant-numeric: tabular-nums; }
.tx-amount.is-positive { color: var(--positive); }
.tx-balance { font-size: .82rem; color: var(--ink-subtle); font-variant-numeric: tabular-nums; margin-top: .1rem; }

.empty { padding: 2.5rem 1.25rem; text-align: center; color: var(--ink-subtle); }

/* ---------- Spending breakdown ---------- */

.spend-row { display: flex; align-items: center; gap: .75rem; padding: .55rem 0; }
.spend-label { font-size: .9rem; text-transform: capitalize; width: 6.5rem; flex: none; }
.spend-bar { flex: 1; height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.spend-fill { display: block; height: 100%; min-width: 3px; background: var(--accent); border-radius: 999px; }
.spend-value { font-size: .88rem; font-variant-numeric: tabular-nums; color: var(--ink-muted); flex: none; }

/* ---------- Forms ---------- */

.field { margin-bottom: 1.05rem; }
.field label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: .35rem; }
.field-hint { font-size: .82rem; color: var(--ink-subtle); margin-top: .35rem; }

.input, .select {
  width: 100%;
  padding: .7rem .85rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.input:hover, .select:hover { border-color: #94a3b8; }
.input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, .16);
}
.select { cursor: pointer; appearance: none; background-image:
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; background-size: 18px; padding-right: 2.4rem;
}

.input-money { position: relative; }
.input-money span {
  position: absolute;
  left: .85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-subtle);
  pointer-events: none;
}
.input-money .input { padding-left: 1.85rem; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 44px;
  padding: .65rem 1.2rem;
  font-size: .96rem;
  font-family: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1e40af; }
.btn-secondary { background: #fff; color: var(--ink); border-color: #cbd5e1; }
.btn-secondary:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-ghost { background: rgba(255, 255, 255, .1); color: #fff; }
.btn-ghost:hover { background: rgba(255, 255, 255, .2); }
.btn-sm { min-height: 36px; padding: .4rem .8rem; font-size: .88rem; }
.btn-block { width: 100%; }

.form-actions { display: flex; gap: .7rem; flex-wrap: wrap; margin-top: 1.35rem; }

/* ---------- Alerts ---------- */

.alert {
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  margin-bottom: 1.25rem;
  border: 1px solid transparent;
}
.alert-error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.alert-success { background: var(--success-soft); border-color: #a7f3d0; color: #065f46; }

/* ---------- Auth pages ---------- */

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}
.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  font-size: 1.15rem;
  font-weight: 680;
  letter-spacing: -.02em;
  color: var(--navy-900);
  margin-bottom: 1.5rem;
}
.auth-brand svg { width: 26px; height: 26px; color: var(--accent); }
.auth-card h1 { font-size: 1.35rem; text-align: center; }
.auth-sub { text-align: center; color: var(--ink-muted); font-size: .93rem; margin: .4rem 0 1.5rem; }
.auth-alt { text-align: center; font-size: .92rem; color: var(--ink-muted); margin-top: 1.25rem; }

.demo-note {
  margin-top: 1.5rem;
  padding: .85rem 1rem;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  font-size: .87rem;
  color: var(--ink-muted);
}
.demo-note strong { color: var(--ink); }
.demo-note code {
  background: #eef2f7;
  padding: .1rem .35rem;
  border-radius: 4px;
  font-size: .87em;
}

/* ---------- Footer ---------- */

.footer {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem;
  color: var(--ink-subtle);
  font-size: .85rem;
  text-align: center;
}

/* ---------- Detail page ---------- */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .9rem;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 1rem;
}
.back-link:hover { text-decoration: underline; }
.back-link svg { width: 16px; height: 16px; }

.detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .columns { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: .75rem 1rem; padding: .75rem 1rem; }
  .nav { order: 3; width: 100%; margin-right: 0; }
  .nav a { flex: 1; text-align: center; }
  .topbar-name { display: none; }
  .page { padding: 1.25rem 1rem 2rem; }
  .summary-value { font-size: 1.9rem; }
  .tx-item { padding: .8rem 1rem; }
  .tx-icon { width: 34px; height: 34px; }
  .auth-card { padding: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
