/* The app's look: Forest accent, its page and card colors, corner sizes (Corner.card 16,
   tile 12, small 8), and its tuned red and green for amounts, in light and dark. */
:root {
  --accent: #3f7428;
  --hero-start: #4a8530;
  --hero-end: #2e571f;
  --page: #eef2e7;
  --sidebar: #e6eddd;
  --card: #ffffff;
  --border: #dce5d2;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --fill: rgba(60, 60, 67, 0.07);
  --stripe: rgba(0, 0, 0, 0.03);
  --selected: rgba(63, 116, 40, 0.14);
  --negative: #b4232b;
  --positive: #1b7f3b;
  /* System colors for areas and account types (Feature and AccountGroup colors) */
  --green: #34c759; --orange: #ff9500; --indigo: #5856d6; --brown: #a2845e;
  --teal: #30b0c7; --pink: #ff2d55; --red: #ff3b30;
  --corner-card: 16px; --corner-tile: 12px; --corner-small: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #7cc75c;
    --hero-start: #3e7128;
    --hero-end: #223f17;
    --page: #0e130c;
    --sidebar: #141b11;
    --card: #1a2117;
    --border: #2a3524;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --fill: rgba(235, 235, 245, 0.08);
    --stripe: rgba(255, 255, 255, 0.035);
    --selected: rgba(124, 199, 92, 0.18);
    --negative: #ff7a72;
    --positive: #5bd87a;
    --green: #30d158; --orange: #ff9f0a; --indigo: #5e5ce6; --brown: #ac8e68;
    --teal: #40c8e0; --pink: #ff375f; --red: #ff453a;
  }
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.caption { font-size: 0.8rem; color: var(--muted); }
.error { color: var(--negative); margin: 12px 0; }
.negative { color: var(--negative); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button {
  font: inherit; padding: 8px 16px; border-radius: var(--corner-small); border: none;
  background: var(--accent); color: white; cursor: pointer;
}
button.secondary { background: var(--card); color: var(--accent); border: 1px solid var(--border); }
button.link { background: none; color: var(--accent); padding: 2px 0; font-size: 0.9rem; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.small-button { padding: 4px 12px; font-size: 0.85rem; }

/* Icons */
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.inline { width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; color: var(--muted); }
.badge {
  display: inline-grid; place-items: center; width: var(--size); height: var(--size); flex: none;
  border-radius: calc(var(--size) * 0.28); background: var(--badge); color: white;
}
.badge .icon { width: calc(var(--size) * 0.6); height: calc(var(--size) * 0.6); stroke-width: 2.1; }

/* Sign in */
.sign-in-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.sign-in-card {
  max-width: 420px; text-align: center; background: var(--card); border: 0.5px solid var(--border);
  border-radius: var(--corner-card); padding: 36px 32px; box-shadow: 0 3px 16px rgba(0, 0, 0, 0.06);
  display: flex; flex-direction: column; gap: 14px; align-items: center;
}
.app-mark { width: 64px; height: 64px; border-radius: 15px; background: linear-gradient(135deg, var(--hero-start), var(--hero-end)); }
.sign-in-card h1 { font-size: 1.6rem; }
.ck-button { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.apple-button { background: #000; color: #fff; font-size: 1.05rem; font-weight: 600; padding: 12px 24px; border-radius: var(--corner-tile); min-width: 260px; }
@media (prefers-color-scheme: dark) { .apple-button { background: #fff; color: #000; } }

/* Layout */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar); border-right: 0.5px solid var(--border); padding: 20px 12px 16px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-top { padding: 0 10px 12px; }
.sidebar h1 { font-size: 1.15rem; }
.household { display: flex; flex-direction: column; font-size: 0.85rem; margin-top: 2px; }
#household-name { font-weight: 600; color: var(--accent); font-size: 1rem; }
.view-only { color: var(--muted); }
.nav-list { list-style: none; padding: 0; margin: 0; flex: 1; }
.nav-list button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; background: none; color: var(--text);
  padding: 7px 10px; border-radius: var(--corner-small); font-size: 0.92rem;
}
.nav-list button:hover { background: var(--fill); }
.nav-list button[aria-current="page"] { background: var(--selected); font-weight: 600; }
.nav-icon { display: inline-grid; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-amount { font-size: 0.82rem; font-weight: 400; color: var(--muted); }
.nav-amount.negative { color: var(--negative); }
.nav-list .section { font-size: 0.75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 16px 10px 4px; }
.sidebar-footer { padding: 12px 10px 0; border-top: 0.5px solid var(--border); }
.sidebar-footer button { width: 100%; }
.account-email { margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-close, .menu-button, .sidebar-backdrop { display: none; }

main { padding: 24px 32px 48px; min-width: 0; max-width: 1200px; width: 100%; }
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-header h2 { font-size: 1.7rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-end { display: flex; align-items: center; gap: 10px; }
.sample-banner { background: var(--selected); border-radius: var(--corner-small); padding: 8px 12px; margin-bottom: 12px; font-size: 0.9rem; }
.loading { display: flex; gap: 12px; align-items: center; color: var(--muted); padding: 40px 0; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards (DashboardCard, cardStyle) */
.card {
  position: relative; background: var(--card); border: 0.5px solid var(--border); border-radius: var(--corner-card);
  padding: 16px; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06); display: flex; flex-direction: column; gap: 12px; overflow: hidden;
}
.card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--tint, transparent) 9%, transparent), transparent 50%);
}
.card > * { position: relative; }
.card.empty { align-items: flex-start; color: var(--muted); }
.card.empty h3 { color: var(--text); }
.card.warning { border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.card-header { display: flex; align-items: center; gap: 10px; }
.card-header h3 { font-size: 1.05rem; flex: 1; }
.disclosure { display: flex; align-items: center; gap: 10px; flex: 1; background: none; color: var(--text); padding: 0; text-align: left; }
.chevron { color: var(--muted); transition: transform 0.25s; }
.chevron.open { transform: rotate(180deg); }

/* Dashboard */
.dashboard { display: flex; flex-direction: column; gap: 16px; }
.dashboard-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.dashboard-stack { display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 860px) { .dashboard-columns { grid-template-columns: 1fr; } }

.hero {
  color: white; border-radius: var(--corner-card); padding: 16px;
  background: linear-gradient(135deg, var(--hero-start), var(--hero-end));
  display: flex; flex-direction: column; gap: 8px;
}
.hero-header { display: flex; align-items: center; gap: 10px; }
.hero-header h3 { font-size: 1.05rem; flex: 1; }
.hero-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--corner-small); background: rgba(255, 255, 255, 0.2); }
.hero-icon .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.chip { background: rgba(255, 255, 255, 0.2); border-radius: 999px; padding: 4px 10px; font-size: 0.8rem; font-weight: 600; }
.hero-value { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; font-family: ui-rounded, -apple-system, sans-serif; }
.hero-stats { display: flex; gap: 24px; }
.hero-label { font-size: 0.8rem; opacity: 0.8; }
.hero-number { font-weight: 600; font-variant-numeric: tabular-nums; }
.hero-chart { position: relative; height: 150px; margin-top: 4px; }
.hero-chart svg { display: block; overflow: visible; touch-action: pan-y; }
.hero-chart .grid { stroke: rgba(255, 255, 255, 0.2); stroke-width: 1; }
.hero-chart .axis { fill: rgba(255, 255, 255, 0.8); font-size: 11px; }
.hero-chart .line { fill: none; stroke: white; stroke-width: 2.5; stroke-linejoin: round; }
.hero-chart .crosshair { stroke: rgba(255, 255, 255, 0.6); stroke-width: 1; stroke-dasharray: 3 3; }
.hero-chart .dot { fill: white; stroke: var(--hero-end); stroke-width: 2; }
.chart-tooltip {
  position: absolute; pointer-events: none; background: var(--card); color: var(--text); border-radius: var(--corner-small);
  padding: 6px 10px; font-size: 0.8rem; display: flex; flex-direction: column; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.negative { color: var(--negative); }
.amount.strong { font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--fill); border-radius: var(--corner-tile); padding: 10px 12px; }
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-value { font-size: 1.15rem; font-weight: 600; }
.budget-line { display: flex; align-items: center; gap: 10px; }
.budget-bar { flex: 1; height: 8px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.budget-bar span { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.budget-bar.over span { background: var(--negative); }

.balance-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--fill); border-radius: var(--corner-tile); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.tile-title { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 500; }
.tile-value { font-size: 1.25rem; font-weight: 600; font-family: ui-rounded, -apple-system, sans-serif; }
.tile-splits { display: flex; flex-direction: column; gap: 2px; font-size: 0.8rem; }
.account-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px 24px; }
.group-header { display: flex; justify-content: space-between; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding-bottom: 4px; }
.group-header .amount { color: var(--text); }
.group-header .amount.negative { color: var(--negative); }
.account-row {
  width: 100%; display: flex; align-items: center; gap: 10px; background: none; color: var(--text); text-align: left;
  padding: 7px 4px; border-radius: 0; border-top: 0.5px solid var(--border); font-size: 0.9rem;
}
.account-row:hover { background: var(--fill); }
.account-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.account-name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-amounts { display: flex; flex-direction: column; align-items: flex-end; font-weight: 600; }
.account-amounts .expected { font-size: 0.8rem; font-weight: 400; opacity: 0.75; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.check input { accent-color: var(--accent); }

.item-row { display: flex; align-items: center; gap: 10px; font-size: 0.92rem; width: 100%; }
button.item-row { background: none; color: var(--text); padding: 0; text-align: left; }
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.soon { color: var(--accent); font-weight: 600; }
.countdown { color: var(--muted); font-variant-numeric: tabular-nums; }
.countdown.soon { color: var(--accent); font-weight: 400; }
.event-icon { color: var(--pink); width: 22px; display: grid; place-items: center; }

/* Registers */
.register { display: flex; flex-direction: column; gap: 14px; }
.summary-bar { display: flex; flex-wrap: wrap; gap: 12px 28px; align-items: center; background: var(--card); border: 0.5px solid var(--border); border-radius: var(--corner-card); padding: 14px 16px; }
.summary-title { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.summary-value { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { flex: 1; min-width: 220px; display: flex; align-items: center; gap: 8px; background: var(--card); border: 0.5px solid var(--border); border-radius: var(--corner-small); padding: 0 10px; color: var(--muted); }
.search input { flex: 1; border: none; background: none; font: inherit; color: var(--text); padding: 8px 0; outline: none; }
.segmented { display: inline-flex; background: var(--fill); border-radius: 9px; padding: 2px; }
.segmented button { background: none; color: var(--text); padding: 5px 14px; border-radius: 7px; font-size: 0.88rem; }
.segmented button.selected { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); font-weight: 600; }

.table-card { padding: 4px 8px; gap: 0; }
.register-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.register-table th { text-align: left; font-size: 0.78rem; font-weight: 600; color: var(--muted); padding: 10px 8px 8px; border-bottom: 0.5px solid var(--border); }
.register-table td { padding: 8px; vertical-align: top; }
.register-table tbody tr:nth-child(even) td { background: var(--stripe); }
.register-table tbody tr td:first-child { border-radius: var(--corner-small) 0 0 var(--corner-small); }
.register-table tbody tr td:last-child { border-radius: 0 var(--corner-small) var(--corner-small) 0; }
.register-table .number { text-align: right; }
.register-table .date { white-space: nowrap; color: var(--muted); width: 1%; }
.register-table .status { width: 1%; padding-right: 0; color: var(--muted); }
.register-table .status.cleared { color: var(--positive); }
.register-table .status.pending { color: var(--orange); }
.register-table .category, .register-table .account { color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.register-table .balance { color: var(--muted); }
.register-table tr.future td { font-style: normal; }
.payee-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.verify { font-size: 0.7rem; font-weight: 600; color: var(--orange); border: 1px solid currentColor; border-radius: 999px; padding: 0 6px; }
.narrow-only { display: none; }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Phone and narrow windows: the sidebar becomes a drawer, and registers move details under the name */
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .search { flex-basis: 100%; min-width: 0; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .summary-bar { gap: 10px 20px; }
  .register-table td { padding: 8px 6px; }
  .sidebar {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); height: auto;
    transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
  }
  .menu-open .sidebar { transform: none; }
  .menu-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.3); }
  .sidebar-close { display: block; margin-left: auto; margin-bottom: 4px; }
  .menu-button { display: inline-block; padding: 6px 12px; }
  main { padding: 14px 14px 40px; }
  .page-header { flex-wrap: wrap; }
  .page-header h2 { font-size: 1.4rem; flex-basis: 100%; order: 2; }
  .header-end { margin-left: auto; }
  .hero-value { font-size: 2rem; }
  .register-table .date, .register-table .category, .register-table .account, .register-table .balance { display: none; }
  .narrow-only { display: block; }
}
