:root {
  --bg: #f0f2f5;
  --bg-soft: #e8ebf0;
  --card: #ffffff;
  --text: #1a1d26;
  --text-muted: #6b7280;
  --text-soft: #9ca3af;
  --border: #e5e7eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --shadow-hover: 0 2px 8px rgba(16, 24, 40, 0.08), 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --green: #16a34a;
  --green-bg: #ecfdf3;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
  --orange: #ea580c;
  --orange-bg: #fff7ed;
  --nav-h: 64px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* —— Top nav —— */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 32px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: grid; place-items: center;
  color: #fff; font-size: 0.85rem; font-weight: 800;
}
.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}
.nav-links a {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-links a:hover { background: var(--bg-soft); color: var(--text); }
.nav-links a.active {
  background: var(--blue-bg);
  color: var(--blue);
  font-weight: 600;
}
.nav-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}
.nav-meta .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #22c55e, #2563eb);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.75rem;
}

/* —— Layout —— */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header h1 {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.page-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}
.chips-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 500;
  box-shadow: var(--shadow);
}
.chip .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}
.chip.purple .dot { background: var(--purple); }
.chip.orange .dot { background: var(--orange); }
.chip.green .dot { background: var(--green); }
.chip .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.chip .hint { color: var(--text-soft); font-weight: 400; }

/* —— Cards —— */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(0,0,0,0.03);
  padding: 20px 22px;
}
.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  letter-spacing: 0.01em;
}
.card-title .badge {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.badge-hold { background: var(--orange-bg); color: var(--orange); }
.badge-ok { background: var(--green-bg); color: var(--green); }

/* —— KPI grid —— */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.kpi {
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 1.7rem;
  font-weight: 740;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}
.kpi-value.pos { color: var(--green); }
.kpi-value.neg { color: var(--red); }
.kpi-value.neutral { color: var(--text); }
.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-bottom: 12px;
}
.spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 28px;
}
.spark span {
  flex: 1;
  border-radius: 3px 3px 1px 1px;
  background: linear-gradient(180deg, #93c5fd, #2563eb);
  opacity: 0.75;
  min-width: 4px;
}
.kpi:nth-child(1) .spark span { background: linear-gradient(180deg, #86efac, #16a34a); }
.kpi:nth-child(2) .spark span { background: linear-gradient(180deg, #93c5fd, #2563eb); }
.kpi:nth-child(3) .spark span { background: linear-gradient(180deg, #fca5a5, #dc2626); }
.kpi:nth-child(4) .spark span { background: linear-gradient(180deg, #c4b5fd, #7c3aed); }

.buffer-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--green-bg);
  color: var(--green);
  font-weight: 600;
}
.buffer-pill.warn { background: var(--orange-bg); color: var(--orange); }

/* —— Middle grid —— */
.mid-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.95fr 1.1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* Debt cards */
.debt-list { display: flex; flex-direction: column; gap: 10px; }
.debt-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid transparent;
  transition: border-color .15s, background .15s;
}
.debt-item:hover { border-color: var(--border); background: #fafbfc; }
.debt-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid; place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  flex-shrink: 0;
}
.debt-info { flex: 1; min-width: 0; }
.debt-info .name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.debt-info .meta {
  font-size: 0.72rem;
  color: var(--text-soft);
  margin-top: 2px;
}
.debt-bal {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}
.debt-bal .tag {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--purple);
  margin-top: 2px;
}

/* Rings */
.rings-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.rings-canvas-wrap {
  position: relative;
  width: 220px;
  height: 220px;
}
.rings-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.rings-center .total {
  font-size: 1.25rem;
  font-weight: 740;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.rings-center .lbl {
  font-size: 0.7rem;
  color: var(--text-soft);
  font-weight: 500;
}
.ring-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ring-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}
.ring-legend-row .swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.ring-legend-row .name { flex: 1; color: var(--text-muted); }
.ring-legend-row .pct {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ring-legend-row .remain {
  color: var(--text-soft);
  font-size: 0.72rem;
  min-width: 72px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Chart */
.chart-wrap { position: relative; height: 220px; }

/* Apple attack banner */
.attack-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #1d1d1f, #3a3a3c);
  color: #fff;
  margin-top: 14px;
}
.attack-banner .icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: rgba(255,255,255,0.12);
  display: grid; place-items: center;
  font-size: 1.1rem;
}
.attack-banner .body { flex: 1; }
.attack-banner .body strong { display: block; font-size: 0.88rem; }
.attack-banner .body span { font-size: 0.72rem; opacity: 0.7; }
.attack-banner .actions { display: flex; gap: 8px; align-items: center; }
.btn {
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-hold {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
}
.btn-propose {
  background: #fff;
  color: #1d1d1f;
}

/* —— Bottom grid —— */
.bot-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr 0.9fr;
  gap: 16px;
}

/* Budget bars */
.budget-list { display: flex; flex-direction: column; gap: 14px; }
.budget-row .top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.8rem;
}
.budget-row .top .name { font-weight: 600; }
.budget-row .top .nums {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
}
.bar-track {
  height: 8px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .4s ease;
}
.bar-fill.over { opacity: 0.95; }

/* Transactions */
.tx-list { display: flex; flex-direction: column; }
.tx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.tx-row:last-child { border-bottom: none; }
.tx-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}
.tx-icon.in { background: var(--green-bg); color: var(--green); }
.tx-icon.out { background: var(--red-bg); color: var(--red); }
.tx-info { flex: 1; min-width: 0; }
.tx-info .name {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-info .meta {
  font-size: 0.7rem;
  color: var(--text-soft);
  margin-top: 1px;
}
.tx-amt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}
.tx-amt.pos { color: var(--green); }
.tx-amt.neg { color: var(--text); }
.pending-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--orange);
  margin-left: 4px;
  vertical-align: middle;
}

/* Bills */
.bills-section { margin-bottom: 14px; }
.bills-section:last-child { margin-bottom: 0; }
.bills-section h4 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  font-weight: 700;
  margin-bottom: 8px;
}
.bill-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.bill-row:last-child { border-bottom: none; }
.bill-date {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--blue-bg);
  color: var(--blue);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1.1;
}
.bill-date .day { font-weight: 740; font-size: 0.95rem; }
.bill-date .mon { font-size: 0.6rem; font-weight: 600; text-transform: uppercase; }
.bill-info { flex: 1; min-width: 0; }
.bill-info .name { font-weight: 600; font-size: 0.85rem; }
.bill-info .due { font-size: 0.7rem; color: var(--text-soft); }
.bill-amt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

/* Stub pages */
.stub {
  display: none;
  text-align: center;
  padding: 80px 24px;
}
.stub.visible { display: block; }
.stub .icon {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: var(--blue-bg);
  color: var(--blue);
  display: grid; place-items: center;
  font-size: 1.6rem;
}
.stub h2 { font-size: 1.4rem; margin-bottom: 8px; letter-spacing: -0.02em; }
.stub p { color: var(--text-muted); max-width: 360px; margin: 0 auto; }

#dashboard-view.hidden { display: none; }

.footer-note {
  margin-top: 28px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-soft);
}

/* Responsive */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .mid-grid, .bot-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topnav { padding: 0 14px; gap: 12px; }
  .page { padding: 18px 14px 48px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.45rem; }
  .nav-meta .who { display: none; }
}
