/* MyWealth design system - mobile-first, responsive (iPhone / iPad / desktop), light + dark. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0ea5a4;
  --accent-ink: #ffffff;
  --in: #16a34a;
  --out: #dc2626;
  --pos: #16a34a;
  --neg: #dc2626;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .05);
  --sidebar-w: 232px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --text: #e5e7eb;
    --muted: #94a3b8; --border: #1f2937; --accent: #2dd4bf; --accent-ink: #04211f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px calc(16px + var(--safe-b)); display: none; flex-direction: column; gap: 6px;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 18px; font-weight: 700; }
.brand--center { justify-content: center; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800;
}
.brand-name { font-size: 1.05rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  padding: 10px 12px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 600;
}
.nav-item.is-active { background: var(--surface-2); color: var(--text); }
.nav-item:hover:not(.disabled) { background: var(--surface-2); color: var(--text); }
.nav-item.disabled { color: var(--muted); opacity: .5; cursor: default; }
.nav-soon { margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-top: 16px; }
.nav-soon .small { padding: 0 12px 4px; }

.main { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-btn { background: none; border: 0; font-size: 1.4rem; color: var(--text); cursor: pointer; padding: 4px 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2);
  border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600;
}
.chip-role { color: var(--muted); font-weight: 500; font-size: .72rem; text-transform: uppercase; }
.content { padding: 16px 16px calc(84px + var(--safe-b)); flex: 1; max-width: 1100px; width: 100%; margin: 0 auto; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.bn-item { flex: 1; text-align: center; padding: 12px 4px; color: var(--muted); font-weight: 600; font-size: .8rem; }
.bn-item.is-active { color: var(--accent); }
.scrim { display: none; }

/* ---------- Cards & grid ---------- */
.grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card-title { font-weight: 700; margin-bottom: 12px; }
.card--wide, .kpi--wide { grid-column: 1 / -1; }
.card--form { max-width: 640px; }

.kpi .kpi-label { color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; margin: 4px 0; }
.kpi-sub { display: flex; gap: 16px; flex-wrap: wrap; font-weight: 600; font-size: .9rem; }
.hint { margin-top: 8px; color: var(--muted); font-size: .8rem; }

/* ---------- Donut & bars ---------- */
.donut-wrap { position: relative; width: 180px; margin: 0 auto; }
.donut { width: 180px; height: 180px; transform: rotate(-90deg); }
.donut-ring { stroke: var(--surface-2); }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.legend { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.legend--row { flex-direction: row; gap: 16px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.legend-val { margin-left: auto; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.bar-stack { flex: 1; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.bar { width: 42%; border-radius: 5px 5px 0 0; min-height: 2px; }
.bar-in { background: var(--in); }
.bar-out { background: var(--out); }
.bar-label { color: var(--muted); font-size: .72rem; }

/* ---------- Lists & tables ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.acc-link { display: flex; flex-direction: column; gap: 4px; }
.acc-name { font-weight: 600; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: .7rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.badge-joint { color: var(--accent); }
.badge-private { color: var(--out); }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 8px; border-bottom: 1px solid var(--border); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }

/* ---------- Page head ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-figure { font-size: 1.6rem; font-weight: 800; margin: 2px 0; }
.page-figure.sm { font-size: 1.25rem; }
.group-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.group-subtotal { font-weight: 700; }
.balances { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.stats { list-style: none; display: flex; gap: 22px; padding: 10px 0; margin: 0; flex-wrap: wrap; }
.stats li { display: flex; flex-direction: column; }
.stat-num { font-size: 1.5rem; font-weight: 800; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form--inline { }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; font-weight: 600; }
.field span { color: var(--muted); }
.field--grow { flex: 1; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 150px; }
input, select { font: inherit; padding: 11px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.fieldset legend { font-weight: 700; padding: 0 6px; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 700; padding: 11px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; min-height: 44px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.inline { display: inline; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .9rem; }
.alert-error { background: color-mix(in srgb, var(--out) 12%, transparent); color: var(--out); border: 1px solid color-mix(in srgb, var(--out) 30%, transparent); }
.alert-warn { background: color-mix(in srgb, #f59e0b 14%, transparent); border: 1px solid color-mix(in srgb, #f59e0b 34%, transparent); }
.empty { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* ---------- Cards wallet ---------- */
.card-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.card-stack { display: flex; flex-direction: column; gap: 12px; }
.cardface {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.cardface.is-sub { margin-left: 18px; border-left: 3px solid var(--accent); }
.cardface-img { width: 100%; aspect-ratio: 1.5857 / 1; object-fit: cover; display: block; }
.cardface-body {
  aspect-ratio: 1.5857 / 1; padding: 16px; color: #fff; display: flex; flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 65%, #000));
}
.cardface-top { display: flex; align-items: center; justify-content: space-between; }
.chip-emv { width: 34px; height: 24px; border-radius: 5px; background: linear-gradient(135deg,#e8d38a,#b8963f); }
.cardface-net { font-weight: 800; letter-spacing: .06em; }
.cardface-num { font-size: 1.2rem; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.cardface-bottom { display: flex; justify-content: space-between; font-size: .85rem; text-transform: uppercase; }
.cardface-meta { padding: 12px 14px; }
.cardface-name { font-weight: 700; }
@media (min-width: 768px) { .card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .card-grid { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Two-column split inside a card ---------- */
.split { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 768px) { .split { grid-template-columns: 1fr 1fr; } }

/* ---------- Passkey status message ---------- */
/* Keep any scrolled-to element clear of the sticky top bar. scroll-padding covers
   anchor/scrollIntoView; scroll-margin covers focus-driven scrolling (and keeps
   browser-extension prompts anchored to a field from landing under the header). */
html { scroll-padding-top: 96px; }
.card, .pk-status, input, select, textarea, summary { scroll-margin-top: 96px; }
.pk-status { margin: 12px 0 0; padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; }
.pk-status:empty { display: none; margin: 0; padding: 0; }
.pk-status.info { background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.pk-status.warn {
  background: color-mix(in srgb, #f59e0b 14%, transparent);
  border: 1px solid color-mix(in srgb, #f59e0b 34%, transparent);
}
.pk-status.error {
  background: color-mix(in srgb, var(--out) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--out) 30%, transparent);
  color: var(--out);
}

/* ---------- Recovery codes ---------- */
.code-list { list-style: none; padding: 8px 0 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.code-list code { font-size: 1rem; }

/* ---------- Budgets & reports ---------- */
.progress { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; border: 1px solid var(--border); }
.progress-bar { height: 100%; background: var(--accent); }
.progress-bar.over { background: var(--out); }
.report-sheet { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.report-sheet h2 { font-size: 1.05rem; margin: 18px 0 8px; }
.report-sheet h2:first-child { margin-top: 0; }

@media print {
  .sidebar, .topbar, .bottom-nav, .no-print { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  .report-sheet { border: none; box-shadow: none; padding: 0; }
  body { background: #fff; }
}

/* ---------- Forecast chart ---------- */
.fc-chart { width: 100%; height: 260px; background: var(--surface-2); border-radius: var(--radius-sm); }
.fc-band { fill: color-mix(in srgb, var(--accent) 16%, transparent); stroke: none; }
.fc-actual { fill: none; stroke: var(--text); stroke-width: 0.7; vector-effect: non-scaling-stroke; }
.fc-expected { fill: none; stroke: var(--accent); stroke-width: 0.9; stroke-dasharray: 2 1.5; vector-effect: non-scaling-stroke; }
.fc-today { stroke: var(--muted); stroke-width: 0.5; stroke-dasharray: 1 1; vector-effect: non-scaling-stroke; }

/* ---------- Bills ---------- */
.bill-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.bill-row:last-child { border-bottom: 0; }
.bill-name { font-weight: 700; }
.bill-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; text-align: right; }
.qr-details { margin-top: 8px; }
.qr-wrap { padding-top: 8px; }
.qr-img { border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 6px; }

/* ---------- Auth pages ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card { padding: 24px; }
.auth-title { margin: 6px 0 16px; font-size: 1.3rem; }
.auth-foot { text-align: center; margin-top: 14px; }
details.card summary { cursor: pointer; }
details.card[open] summary { margin-bottom: 12px; }

/* ---------- Responsive: iPad ---------- */
@media (min-width: 768px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 22px; }
}
/* ---------- Responsive: desktop with sidebar ---------- */
@media (min-width: 1024px) {
  .sidebar { display: flex; }
  .main { margin-left: var(--sidebar-w); }
  .bottom-nav { display: none; }
  .only-mobile { display: none; }
  .content { padding: 26px 30px calc(30px + var(--safe-b)); }
  .grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Mobile drawer (sidebar opened via ☰) ---------- */
@media (max-width: 1023px) {
  body.nav-open .sidebar { display: flex; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
}
