:root {
  color-scheme: light;
  --page: #f6f4ee; --surface: #fffdf9; --surface-2: #efece4; --ink: #1c1b18; --ink-2: #5b5952; --muted: #8c8a82;
  --grid: #e6e2d8; --axis: #cfcbc0; --border: rgba(28,27,24,0.09); --border-strong: rgba(28,27,24,0.16);
  --s1: #2a78d6; --s1-track: #cde2fb; --s1-deep: #1c5cab; --s3: #1baf7a;
  --good: #0ca30c; --good-text: #006300; --warning: #fab219; --critical: #d03b3b;
  --accent-wash: rgba(42,120,214,0.10); --thumb: #fffdf9;
  --shadow-card: 0 1px 2px rgba(28,27,24,0.04), 0 10px 30px rgba(28,27,24,0.06);
  --shadow-thumb: 0 1px 2px rgba(28,27,24,0.12), 0 2px 6px rgba(28,27,24,0.08);
  --radius: 18px; --gap: 16px;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #1b1a17; --surface: #262522; --surface-2: #2f2e2a; --ink: #f3f1ea; --ink-2: #c6c3b8; --muted: #8c8a82;
  --grid: #35332e; --axis: #45433d; --border: rgba(255,255,255,0.09); --border-strong: rgba(255,255,255,0.18);
  --s1: #3987e5; --s1-track: #184f95; --s1-deep: #86b6ef; --s3: #199e70;
  --good-text: #0ca30c; --accent-wash: rgba(57,135,229,0.16); --thumb: #3a3934;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.4), 0 10px 30px rgba(0,0,0,0.35);
  --shadow-thumb: 0 1px 2px rgba(0,0,0,0.5);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-text-size-adjust: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--s1); text-decoration: none; }
.app { max-width: 680px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: 64px; }

/* header */
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: calc(env(safe-area-inset-top) + 14px) var(--gap) 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-size: 18px; letter-spacing: 0.01em; color: var(--ink); }
.mark { width: 24px; height: 24px; border-radius: 8px; background: var(--ink); color: var(--page); display: grid; place-items: center; font: 600 13px/1 system-ui, sans-serif; }
.who { text-align: right; color: var(--muted); font-size: 13px; }
.month-nav { display: flex; align-items: center; gap: 2px; }
.month-title { font-weight: 600; min-width: 136px; text-align: center; font-size: 15px; }
.icon-btn { background: none; border: 0; width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); }

/* greeting + composer */
.greet { padding: 36px var(--gap) 8px; }
.greeting { font-family: var(--serif); font-weight: 400; font-size: 34px; line-height: 1.1; letter-spacing: -0.01em; margin: 0 0 24px; text-align: center; color: var(--ink); }
.composer { background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-card); padding: 18px 16px 12px; transition: box-shadow .2s, border-color .2s; }
.composer:focus-within { border-color: var(--border-strong); box-shadow: var(--shadow-card), 0 0 0 4px var(--accent-wash); }
.composer textarea { display: block; width: 100%; border: 0; background: transparent; resize: none; outline: none; font-size: 17px; line-height: 1.4; padding: 2px 4px 14px; min-height: 30px; max-height: 140px; }
.composer textarea::placeholder { color: var(--muted); font-size: 15px; }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 12px; }
.send { width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--ink); color: var(--page); font-size: 18px; font-weight: 700; display: grid; place-items: center; transition: transform .1s, opacity .2s; }
.send:active { transform: scale(0.95); }
.composer textarea:placeholder-shown ~ .composer-bar .send { opacity: .35; }

/* the switch: a light track, a white thumb that slides */
.switch { position: relative; display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.switch-thumb { position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); background: var(--thumb); border-radius: 9px; box-shadow: var(--shadow-thumb); transition: transform .22s cubic-bezier(.2,.8,.2,1); }
.switch[data-mode="plan"] .switch-thumb { transform: translateX(100%); }
.switch-opt { position: relative; z-index: 1; border: 0; background: none; padding: 6px 14px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--ink-2); white-space: nowrap; transition: color .2s; }
.switch-opt.is-active { color: var(--ink); font-weight: 600; }
.deep-toggle { display: none; border: 1px solid var(--border-strong); background: transparent; border-radius: 10px; padding: 6px 12px; font-size: 14px; color: var(--ink-2); }
.deep-toggle[aria-pressed="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); }
.composer[data-advisor="true"] .switch { display: none; }
.composer[data-advisor="true"] .deep-toggle { display: inline-block; }

/* tabs + content */
.tabs { display: flex; gap: 2px; padding: 40px var(--gap) 16px; }
.tab { flex: 1; border: 0; background: none; padding: 8px 0; border-radius: 11px; color: var(--muted); font-weight: 600; }
.tab.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--border); }
.content { flex: 1; padding: 0 var(--gap) 32px; display: flex; flex-direction: column; gap: 16px; }
.loading, .empty { color: var(--muted); text-align: center; padding: 32px 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px; }
.card h3 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); letter-spacing: 0.01em; }
.hero .label { color: var(--ink-2); font-size: 13px; }
.hero .value { font-size: 44px; font-weight: 650; line-height: 1.1; letter-spacing: -0.01em; margin: 2px 0 2px; }
.hero .value small { font-size: 20px; font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.hero .sub { color: var(--ink-2); font-size: 13px; }
.meter { position: relative; height: 10px; border-radius: 6px; background: var(--s1-track); margin-top: 12px; display: flex; gap: 2px; overflow: visible; }
.meter .fill { height: 100%; border-radius: 6px; background: var(--s1); transition: width .4s ease; }
.meter .fill.warn { background: var(--warning); }
.meter .fill.over { background: var(--critical); }
.meter .fill.planned { background: var(--warning); }
.planned-note { color: var(--muted); font-size: 11px; margin-left: 4px; }
.planned-dot { background: var(--warning); vertical-align: middle; margin: 0 2px 2px 0; }
.meter .pace { position: absolute; top: -4px; width: 2px; height: 18px; background: var(--ink-2); border-radius: 1px; }
.meter .pace::after { content: attr(data-label); position: absolute; top: 20px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.meter.small { height: 6px; margin-top: 6px; }
.hero-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--grid); }
.kpi { min-width: 0; }
.kpi .label { color: var(--ink-2); font-size: 12px; }
.kpi .value { font-size: 19px; font-weight: 650; margin-top: 2px; white-space: nowrap; }
.kpi .delta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .delta.good { color: var(--good-text); }
.kpi .delta.bad { color: var(--critical); }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; }
.chart-head .toggle { background: none; border: 0; color: var(--s1); font-size: 13px; padding: 0; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--page); font-size: 12px; padding: 6px 8px; border-radius: 8px; transform: translate(-50%, -110%); white-space: nowrap; opacity: 0; transition: opacity .1s; }
.chart .tip strong { font-size: 13px; }
.chart table { width: 100%; font-size: 13px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.chart td { padding: 3px 0; border-bottom: 1px solid var(--grid); }
.chart td:last-child { text-align: right; }
.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--grid); align-items: center; cursor: pointer; }
.row:first-child { border-top: 0; }
.row .name { font-weight: 600; }
.row .nums { color: var(--ink-2); font-size: 13px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row .nums b { color: var(--ink); font-size: 15px; }
.row .bar { grid-column: 1 / -1; }
.row .status { font-size: 12px; color: var(--ink-2); grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.warn { background: var(--warning); } .dot.over { background: var(--critical); } .dot.good { background: var(--good); } .dot.watch { background: var(--s1); } .dot.idea { background: var(--s3); }
.sub-rows { padding-left: 12px; border-left: 2px solid var(--grid); margin: 0 0 8px; }
.sub-rows .row { padding: 7px 0; }
.sub-rows .row .name { font-weight: 500; }
.txn { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--grid); cursor: pointer; }
.txn:first-child { border-top: 0; }
.txn .ava { width: 36px; height: 36px; border-radius: 11px; background: var(--surface-2); color: var(--ink-2); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.txn .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn .meta { color: var(--muted); font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.txn .amt { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.txn .amt.in { color: var(--good-text); }
.txn.muted { opacity: .55; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; }
.chip.unc { background: rgba(250,178,25,0.18); }
.plans { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.plan { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.plan .img { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 26px; }
.plan .img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.plan .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.plan .title { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.plan .price { font-weight: 650; }
.plan .meta { color: var(--muted); font-size: 12px; }
.plan .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; }
.btn { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 10px; padding: 6px 10px; font-size: 13px; font-weight: 600; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--page); }
.btn.ghost { border-color: transparent; color: var(--s1); padding-left: 4px; padding-right: 4px; }
.btn:disabled { opacity: .5; cursor: default; }
.bubble { max-width: 94%; padding: 11px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.bubble.q { align-self: flex-end; background: var(--surface-2); border-color: transparent; font-weight: 500; }
.bubble .model { color: var(--muted); font-size: 11px; margin-top: 6px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 4px 0 8px; padding-left: 20px; }
.thread { display: flex; flex-direction: column; gap: 10px; }
.qa { display: flex; flex-direction: column; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--grid); }
.qa:last-child { border-bottom: 0; }
.insight { display: grid; grid-template-columns: 14px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--grid); }
.insight:first-child { border-top: 0; }
.insight .dot { margin-top: 6px; }
.insight b { display: block; }
.insight span { color: var(--ink-2); font-size: 14px; }
.toast { pointer-events: none; position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translateX(-50%); background: var(--ink); color: var(--page); padding: 10px 14px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 92vw; box-shadow: var(--shadow-card); }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 40; }
.sheet { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 680px; max-height: 80dvh; overflow: auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 14px var(--gap) calc(env(safe-area-inset-bottom) + 16px); z-index: 50; box-shadow: var(--shadow-card); }
.sheet h3 { margin: 0 0 10px; font-size: 16px; }
.sheet .opt { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 6px; border-top: 1px solid var(--grid); font-size: 15px; }
.sheet .opt small { color: var(--muted); margin-left: 6px; }
.sheet .opt.is-selected { font-weight: 700; color: var(--s1-deep); }
.sheet .group { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; margin: 12px 0 2px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 10px 0 -2px; }
.section-head h2 { font-size: 16px; margin: 0; }
@media (min-width: 560px) { .plans { grid-template-columns: repeat(3, 1fr); } .hero .value { font-size: 52px; } .greeting { font-size: 40px; } .greet { padding-top: 48px; } .tabs { padding-top: 48px; } }

/* ---------- hover (pointer devices) */
@media (hover: hover) {
  .row:hover, .txn:hover { background: linear-gradient(to right, transparent, var(--surface-2) 12%, var(--surface-2) 88%, transparent); border-radius: 8px; }
  .tab:not(.is-active):hover { color: var(--ink-2); }
  .btn:hover { border-color: var(--ink-2); }
  .btn.primary:hover { opacity: .9; }
  .plan:hover { box-shadow: var(--shadow-card); transform: translateY(-1px); }
  .plan { transition: transform .15s, box-shadow .15s; }
}

/* ---------- tablet */
@media (min-width: 680px) {
  .app { max-width: 820px; }
  .plans { grid-template-columns: repeat(3, 1fr); }
  .composer textarea { font-size: 18px; }
}

/* ---------- desktop: the greeting and composer stay centred, the dashboard becomes a 12-column grid */
@media (min-width: 960px) {
  .app { max-width: 1180px; padding-bottom: 80px; }
  .top { padding-top: 22px; }
  .brand { font-size: 20px; }
  .greet { max-width: 780px; width: 100%; margin: 0 auto; padding-top: 44px; }
  .greeting { font-size: 44px; margin-bottom: 26px; }
  .composer { padding: 20px 20px 14px; border-radius: 26px; }
  .composer textarea { font-size: 18px; min-height: 36px; }
  .tabs { max-width: 560px; margin: 0 auto; padding-top: 44px; width: 100%; }
  .content { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; align-items: start; }
  .content > * { grid-column: 1 / -1; min-width: 0; }
  .sec-hero { grid-column: 1 / -1; display: grid; grid-template-columns: 1.1fr 1fr; gap: 28px; align-items: center; padding: 20px 26px 16px; }
  .hero .value { font-size: 50px; }
  .hero-main > div:last-child { height: 10px; }
  .hero-kpis { margin: 0; padding: 4px 0 4px 28px; border-top: 0; border-left: 1px solid var(--grid); gap: 20px; }
  .kpi .value { font-size: 24px; }
  .sec-chart { grid-column: span 7; }
  .sec-groups { grid-column: span 5; display: flex; flex-direction: column; max-height: 470px; }
  .sec-groups .cat-list { overflow: auto; flex: 1; min-height: 0; padding-right: 6px; scrollbar-width: thin; }
  .sec-groups .plan-foot { flex-shrink: 0; }
  .sec-unc { grid-column: span 5; }
  .sec-recent { grid-column: span 7; }
  .sec-recent.wide { grid-column: 1 / -1; }
  .sec-recent.wide .rows { columns: 2; column-gap: 32px; }
  .sec-recent.wide .txn { break-inside: avoid; }
  .card { padding: 22px 24px; }
  .card h3 { font-size: 13px; margin-bottom: 14px; }
  .plans { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .sec-full { grid-column: 1 / -1; }
  .sec-insights { grid-column: span 5; position: sticky; top: 16px; align-self: start; }
  .sec-thread { grid-column: span 7; }
  .bubble { max-width: 100%; }
  .sheet { max-width: 720px; border-radius: 22px; bottom: 24px; }
  .toast { top: auto; bottom: 28px; }
}
@media (min-width: 1280px) {
  .sec-hero { grid-template-columns: 1fr 1fr; }
}


/* ---------- plan editing */
.plan-edit { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.plan-edit button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 18px; line-height: 1; color: var(--ink); }
.plan-edit input { width: 96px; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 15px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.plan-edit input:focus { outline: none; border-color: var(--s1); box-shadow: 0 0 0 3px var(--accent-wash); }
.plan-edit .unit { color: var(--muted); font-size: 13px; }
.row.edit { cursor: default; }
.row.edit .nums { font-size: 12px; }
.plan-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 0 4px; border-top: 1px solid var(--grid); margin-top: 6px; font-size: 13px; color: var(--ink-2); }
@media (hover: hover) { .plan-edit button:hover { border-color: var(--ink-2); } }


/* ---------- analytics */
.an-kpis { display: grid; grid-template-columns: 1fr; gap: 12px; }
.kpi-tile .label { color: var(--ink-2); font-size: 13px; }
.kpi-tile .big { font-size: 34px; font-weight: 650; line-height: 1.15; margin: 2px 0; }
.kpi-tile .big small { font-size: 16px; color: var(--ink-2); margin-left: 4px; font-weight: 500; }
.kpi-tile .delta { color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin: -4px 0 8px; }
.legend .key { display: inline-block; vertical-align: middle; margin-right: 6px; }
.legend .key.line { width: 18px; height: 2px; background: var(--s1); border-radius: 1px; }
.legend .key.line.gray { background: var(--axis); }
.legend .key.line.dashed { background: repeating-linear-gradient(to right, var(--s1) 0 4px, transparent 4px 8px); }
.legend .key.rect { width: 12px; height: 12px; background: var(--s1); border-radius: 3px; }
.legend .key.tick { width: 14px; height: 2px; background: var(--ink-2); }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.hbar-head .nums { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.hbar-head .nums b { color: var(--ink); }
.hbar-head small { color: var(--muted); }
.hbar-track { height: 8px; border-radius: 5px; background: var(--s1-track); margin-top: 5px; }
.hbar-fill { height: 100%; border-radius: 5px; background: var(--s1); }
.moves { width: 100%; border-collapse: collapse; font-size: 14px; }
.moves td { padding: 8px 0; border-top: 1px solid var(--grid); vertical-align: middle; }
.moves tr:first-child td { border-top: 0; }
.moves .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; padding-left: 10px; }
.moves .muted { color: var(--muted); }
.mv-name { font-weight: 550; }
.mv-group { font-size: 11px; color: var(--muted); }
.mv-foot { font-size: 11px; color: var(--muted); text-align: right; margin-top: 6px; }
@media (min-width: 680px) { .an-kpis { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) {
  .an-kpis { grid-column: 1 / -1; grid-template-columns: repeat(3, 1fr); gap: 20px; }
  .an-pace { grid-column: span 7; } .an-structure { grid-column: span 5; }
  .an-trend { grid-column: span 7; } .an-moves { grid-column: span 5; }
  .an-owners, .an-weekday, .an-merchants { grid-column: span 4; }
  .tabs { max-width: 640px; }
}


/* ---------- passkeys */
.pk-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--grid); }
.pk-row .meta { color: var(--muted); font-size: 12px; }
.nudge { margin: 12px var(--gap) -2px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.nudge > span:last-child { display: flex; gap: 6px; }
@media (min-width: 960px) { .nudge { max-width: 780px; margin-left: auto; margin-right: auto; } }

.plan-link { color: inherit; display: block; }
.plan-link .ext { color: var(--muted); font-size: 12px; }
@media (hover: hover) { .plan-link:hover .ext { color: var(--s1); } .plan .title .plan-link:hover { text-decoration: underline; text-underline-offset: 2px; } }

/* ---------- category editing */
.cat-more { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 0 6px; line-height: 1; vertical-align: middle; cursor: pointer; }
.cat-more:hover { color: var(--ink); }
.add-cat { margin: 4px 0 8px; font-size: 13px; }
.fld { display: block; margin: 8px 0; font-size: 13px; color: var(--muted); }
.fld input, .fld select { margin-top: 4px; }

.kind-switch .switch-opt { padding: 7px 0; }
.cat-list .row .name .chip { font-size: 11px; margin-left: 6px; vertical-align: middle; }
