/* Our Money — design system. Calm, pastel, native-app feel. */

:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-alt: #f3efe9;
  --ink: #2b2a28;
  --ink-muted: #716c64;
  --ink-faint: #a29c92;
  --border: rgba(43, 42, 40, 0.09);
  --border-strong: rgba(43, 42, 40, 0.16);

  --sage: #9fbba6;
  --sage-deep: #6f8f78;
  --sage-tint: #e7f0e8;
  --dusty-blue: #8ba3c2;
  --dusty-blue-tint: #e9eef6;
  --lavender: #ab9fc9;
  --lavender-tint: #efebf7;
  --blush: #d9a596;
  --blush-tint: #f7e9e4;
  --mint: #8fcdb3;
  --mint-tint: #e5f5ee;
  --gold: #cf9f4f;
  --gold-tint: #f6ecd9;

  --positive: #6f8f78;
  --warning: #cf9f4f;
  --danger: #bb6a58;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(30, 28, 25, 0.04), 0 8px 24px rgba(30, 28, 25, 0.05);
  --shadow-float: 0 8px 28px rgba(30, 28, 25, 0.16);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 64px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181715;
    --surface: #221f1c;
    --surface-alt: #2a2622;
    --ink: #f1ede6;
    --ink-muted: #b6afa4;
    --ink-faint: #857e73;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --sage-tint: #223228;
    --dusty-blue-tint: #202632;
    --lavender-tint: #262233;
    --blush-tint: #33241e;
    --mint-tint: #1d2e27;
    --gold-tint: #332a16;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #181715;
  --surface: #221f1c;
  --surface-alt: #2a2622;
  --ink: #f1ede6;
  --ink-muted: #b6afa4;
  --ink-faint: #857e73;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --sage-tint: #223228;
  --dusty-blue-tint: #202632;
  --lavender-tint: #262233;
  --blush-tint: #33241e;
  --mint-tint: #1d2e27;
  --gold-tint: #332a16;
  color-scheme: dark;
}

@view-transition { navigation: auto; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
a { color: inherit; }
button { font-family: inherit; }
h1, h2, h3, h4, p { margin: 0; }

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 24px);
  position: relative;
}
@media (min-width: 900px) {
  .app-shell { max-width: 720px; }
}
@media (min-width: 1200px) {
  .app-shell { max-width: 960px; }
}

.page-header {
  padding: calc(var(--safe-top) + 18px) 20px 4px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.sync-freshness {
  font-size: 0.78rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.content { padding: 8px 16px 0; display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
}
.card + .card { margin-top: 0; }
.card-tight { padding: 14px 16px; }
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-hero { text-align: center; padding: 22px 18px; }
.stat-hero .month-label { color: var(--ink-muted); font-size: 0.85rem; font-weight: 600; }
.stat-hero .amount { font-size: 2.6rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.stat-hero .subtitle { color: var(--ink-muted); font-size: 0.92rem; margin-top: 6px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--radius-pill);
  font-size: 0.78rem; font-weight: 600;
}
.pill-positive { background: var(--sage-tint); color: var(--sage-deep); }
.pill-warning { background: var(--gold-tint); color: #8a6a2c; }
.pill-neutral { background: var(--surface-alt); color: var(--ink-muted); }

.segmented {
  display: flex; background: var(--surface-alt); border-radius: var(--radius-pill);
  padding: 3px; gap: 2px;
}
.segmented button {
  flex: 1; border: none; background: transparent; padding: 9px 12px;
  border-radius: var(--radius-pill); font-size: 0.85rem; font-weight: 600;
  color: var(--ink-muted); cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card); }

.balance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.balance-card { padding: 16px; }
.balance-card .label { font-size: 0.78rem; color: var(--ink-muted); font-weight: 600; }
.balance-card .value { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
.balance-card .meta { font-size: 0.75rem; color: var(--ink-faint); margin-top: 4px; }

.bar-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.bar-row .bar-label { flex: 0 0 128px; font-size: 0.85rem; color: var(--ink-muted); }
.bar-track { flex: 1; height: 9px; border-radius: 5px; background: var(--surface-alt); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; }
.bar-row .bar-value { flex: 0 0 auto; font-size: 0.85rem; font-weight: 600; min-width: 64px; text-align: right; }

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
}
.list-item:last-child { border-bottom: none; }
.list-item .avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.95rem;
}
.list-item .lines { flex: 1; min-width: 0; }
.list-item .merchant { font-weight: 600; font-size: 0.95rem; }
.list-item .meta { font-size: 0.78rem; color: var(--ink-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .amount { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.list-item .amount.negative { color: var(--ink); }
.list-item .amount.positive { color: var(--sage-deep); }
.list-item .badge { font-size: 0.68rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; margin-left: 6px; }

.section-link { display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; font-weight: 600; color: var(--sage-deep); padding-top: 2px; text-decoration: none; }

.insight-line { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: 0.92rem; line-height: 1.4; }
.insight-line .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dusty-blue); margin-top: 7px; flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-md); border: none; padding: 13px 20px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer; min-height: 48px;
}
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-secondary { background: var(--surface-alt); color: var(--ink); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--ink-muted); }
.btn:disabled { opacity: 0.5; }

input, select, textarea {
  width: 100%; padding: 13px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--ink); font-size: 1rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--dusty-blue); outline-offset: 1px;
}
label { font-size: 0.85rem; font-weight: 600; color: var(--ink-muted); display: block; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.field-hint { font-size: 0.78rem; color: var(--ink-faint); margin-top: 5px; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.bottom-nav-inner {
  max-width: 560px; margin: 0 auto; display: flex; height: var(--nav-height);
}
@media (min-width: 900px) { .bottom-nav-inner { max-width: 720px; } }
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: var(--ink-faint); font-size: 0.68rem; font-weight: 600;
  min-height: 48px;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--sage-deep); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--border) 37%, var(--surface-alt) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  * { scroll-behavior: auto !important; }
}

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 18, 16, 0.4); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 22px 22px 0 0; padding: 10px 20px calc(24px + var(--safe-bottom));
  max-height: 86vh; overflow-y: auto;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 8px auto 14px; }
.sheet h2 { font-size: 1.15rem; margin-bottom: 14px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-muted); }
.empty-state .icon { font-size: 2rem; margin-bottom: 10px; }
.empty-state h3 { color: var(--ink); font-size: 1.05rem; margin-bottom: 6px; }
.empty-state p { font-size: 0.88rem; line-height: 1.4; }

.filter-chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.filter-chip-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: none; padding: 8px 14px; border-radius: var(--radius-pill); border: 1px solid var(--border-strong);
  background: var(--surface); font-size: 0.82rem; font-weight: 600; color: var(--ink-muted); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.filter-chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.month-nav { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px; }
.month-nav button { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 50%; width: 38px; height: 38px; font-size: 1.1rem; cursor: pointer; }
.month-nav .current { font-weight: 700; font-size: 1.05rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: var(--radius-pill); font-size: 0.85rem; font-weight: 600;
  box-shadow: var(--shadow-float); z-index: 80; opacity: 0; transition: all 0.25s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.pull-indicator { display: flex; justify-content: center; padding: 6px 0; color: var(--ink-faint); font-size: 0.8rem; height: 0; overflow: hidden; transition: height 0.15s ease; }
.pull-indicator.visible { height: 32px; }

table.plain { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.plain th, table.plain td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--border); }
.table-scroll { overflow-x: auto; }

.center-form { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.center-form .card { width: 100%; max-width: 380px; }
.brand-mark { width: 56px; height: 56px; margin: 0 auto 16px; display: block; }

.error-text { color: var(--danger); font-size: 0.85rem; margin-top: 8px; }
.muted { color: var(--ink-muted); }
.small { font-size: 0.82rem; }
.text-right { text-align: right; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
