/* App chrome + page layouts. Tokens and components live in fin.css (from the design handoff);
   this file only arranges them. Breakpoint: phone < 720px (bottom tab bar), wide >= 720px (top header). */

:root { --tabbar-h: 67px; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.error { color: var(--danger); }

/* ---------- Header (wide) + page head ---------- */
.appbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.appbar-in { max-width: 1200px; margin: 0 auto; padding: 14px 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text) !important; }
.brand span:last-child { font: 600 17px var(--font-display); letter-spacing: -0.01em; }
.appbar .topnav { flex: 1; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 28px 20px 12px; }
.wrap { margin: 0 auto; padding: 4px 16px 32px; display: flex; flex-direction: column; gap: 16px; }
.wrap-narrow { max-width: 560px; }
.dash-head { max-width: 1200px; margin: 0 auto; }
@media (min-width: 720px) { .dash-head { padding-left: 24px; padding-right: 24px; } }
.page-head.narrow { max-width: 560px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

/* ---------- Tab bar (phone) ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
@media (max-width: 719.98px) {
  /* Scrolling (focus, scrollIntoView) keeps things clear of the fixed tab bar. */
  html { scroll-padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }
  .appbar { display: none; }
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .wide-only { display: none !important; }
}
@media (min-width: 720px) {
  .tabbar, .phone-only { display: none !important; }
  .page-head { padding-top: 32px; }
}

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--on-ink); padding: 12px 18px; border-radius: var(--r-md); font: 600 14px var(--font-ui); box-shadow: var(--sh-3); max-width: calc(100vw - 32px); }
@media (max-width: 719.98px) {
  .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
}

/* ---------- Buttons: label swap + loading spinner ---------- */
.btn.is-loading::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--on-ink); border-right-color: transparent; animation: spin .7s linear infinite; }
.btn-secondary.is-loading::after { border-color: var(--text); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- PIN gate ---------- */
.gate { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; justify-content: center; align-items: center; padding: 0 28px 80px; overflow: auto; }
.gate form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 28px; }
.gate .gate-top { display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
.gate .mark { width: 56px; height: 56px; border-radius: 16px; }
.gate .mark svg { width: 26px; height: 26px; }
.gate .pin { min-height: 64px; text-align: center; font-size: 28px; letter-spacing: .4em; border-radius: 16px; }
.gate .field-error { justify-content: center; }

/* ---------- Mic + recording status ---------- */
.capture { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 12px 0 4px; }
.capture .hint { text-align: center; max-width: 280px; }
.rec-row { display: flex; align-items: center; gap: 12px; }
.capture .rec-row { margin-top: 10px; }

/* ---------- Quick Log ---------- */
.form-card { display: flex; flex-direction: column; gap: 18px; }
.grid-amt { display: grid; grid-template-columns: 1.25fr 1fr; gap: 12px; }
.grid-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.date-tall { min-height: 60px; padding: 0 8px 0 12px; }
.row-amt { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

/* ---------- Review ---------- */
.charges-box { position: relative; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.charges-box ul { list-style: none; margin: 0; padding: 0 14px; max-height: 268px; overflow-y: auto; }
.charges-box li { border-top: 1px solid var(--border); margin-top: -1px; }
.charges-box li:first-child { border-top: 0; margin-top: 0; }
.charges-box label { display: flex; align-items: center; gap: 12px; min-height: 56px; cursor: pointer; padding: 6px 0; }
.charges-box input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--ink); cursor: pointer; }
.charges-box .fade { position: absolute; left: 0; right: 0; bottom: 0; height: 40px; background: linear-gradient(to bottom, transparent, var(--surface)); pointer-events: none; }
.say { display: flex; gap: 12px; align-items: flex-start; }
.say .textarea { min-height: 76px; flex: 1; }
/* ---------- Quick Log summary ---------- */
.summary { display: flex; flex-direction: column; gap: 16px; }
.sum-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sum-merchant { font: 600 19px/1.3 var(--font-display); letter-spacing: -0.01em; }
.sum-list { margin: 0; display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.sum-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.sum-list dt { color: var(--text-2); font-size: var(--fs-sm); }
.sum-list dd { margin: 0; font-weight: 600; text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Review: Claude's guesses ---------- */
.ai-status { display: flex; align-items: center; gap: 10px; color: var(--text-2); }
.ai-status.is-error { color: var(--danger); }
.spinner { width: 16px; height: 16px; flex: none; border-radius: 50%; border: 2px solid var(--border-input); border-right-color: transparent; animation: spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) { .spinner, .btn.is-loading::after { animation-duration: 2.4s; } }
.gcards { display: flex; flex-direction: column; gap: 12px; }
.gcard { display: flex; flex-direction: column; gap: 12px; }
.gcard.is-changed { box-shadow: 0 0 0 2px var(--warn-border); }
.gc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.gc-top > .num, .mini-list .num, .row-amt .num { white-space: nowrap; }
.gc-top h3 { font: 600 18px/1.3 var(--font-display); letter-spacing: -0.01em; margin: 0; }
.reason { color: var(--text-2); }
.tag-new { align-self: flex-start; background: var(--warn-bg); color: var(--warn-text); }
.tag-sure { background: var(--positive-bg); color: var(--positive); vertical-align: 1px; }
/* Choices are real radio buttons: selecting doesn't save, the card's Save button does. */
.choices { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 14px; border-radius: var(--r-md); border: 1px solid var(--border-input); background: var(--surface); cursor: pointer; }
.choice:hover { background: var(--surface-2); }
.choice.is-on { border: 2px solid var(--ink); padding: 9px 13px; }
.choice input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--ink); cursor: pointer; }
.choice-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-weight: 600; font-size: 15px; line-height: 1.3; }
.choice-txt .ent-label { white-space: normal; }
.other { display: flex; flex-direction: column; gap: 14px; padding: 14px; border-radius: 14px; background: var(--surface-2); }
.other .textarea { min-height: 64px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { appearance: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--border-input); background: var(--surface); color: var(--text); font: 600 14px var(--font-ui); cursor: pointer; }
.chip[aria-pressed="true"] { border: 2px solid var(--ink); padding: 0 13px; }
.mini-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; }
.mini-row { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.mini-row input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }
details summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.bank-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

/* ---------- My rules ---------- */
.rule-list { display: flex; flex-direction: column; }
.rule { display: flex; flex-direction: column; gap: 6px; padding: 14px 0; border-top: 1px solid var(--border); }
.rule:first-child { border-top: 0; padding-top: 0; }
.rule-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.rule-top h3 { margin: 0; font: 600 16px/1.3 var(--font-display); }
.rule-lines { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; color: var(--text-2); font-size: var(--fs-sm); }
.rule .example { padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2); }
.understood { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.banner-danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

/* ---------- Dashboard ---------- */
.dash { max-width: 1200px; margin: 0 auto; padding: 4px 24px 48px; display: flex; flex-direction: column; gap: 24px; }
.dash-filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.dash-filters .period { width: 220px; }
.dash-filters .period .select { min-height: 44px; font-weight: 600; font-size: 15px; }
.scroll-x { max-width: 100%; overflow-x: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 16px; }
.kpi { display: flex; flex-direction: column; gap: 10px; }
.kpi-inc { order: 1; } .kpi-exp { order: 2; } .kpi-net { order: 3; } .kpi-review { order: 4; }
.kpi-review { color: var(--text) !important; text-decoration: none; }
.kpi-review .go { font: 600 var(--fs-xs) var(--font-ui); display: inline-flex; align-items: center; gap: 4px; text-decoration: underline; text-underline-offset: 3px; }
.kpi-review .go-btn { display: none; }
.money .cents.inherit { color: inherit; opacity: .8; }
.due-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 12px; }
.due-tile { border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.due-tile.is-open { outline: 2px solid var(--ink); outline-offset: -2px; }
.due-tile .why { min-height: 34px; }
.due-toggle { align-self: flex-start; padding: 0 !important; display: inline-flex !important; align-items: center; gap: 4px; text-decoration: none !important; }
.due-detail { margin-top: 16px; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.due-detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 14px 16px; background: var(--surface-2); }
.due-detail .table-wrap { border-radius: 0; }
.charts-row { display: flex; flex-wrap: wrap; gap: 24px; }
.charts-row > .card { min-width: 0; }
.chart-month { flex: 2 1 560px; }
.chart-clients { flex: 1 1 320px; }
.chart-box { position: relative; height: 260px; }
.chart-tip { position: absolute; z-index: 5; padding: 10px 12px !important; box-shadow: var(--sh-3) !important; display: flex; flex-direction: column; gap: 4px; min-width: 168px; pointer-events: none; transition: opacity .1s; }
.chart-tip .tip-row { display: flex; justify-content: space-between; gap: 12px; }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.chart-tip .tip-net { border-top: 1px solid var(--border); padding-top: 4px; }
.hbars { display: flex; flex-direction: column; gap: 18px; }
.cat-bars { display: flex; flex-direction: column; gap: 12px; }
.cat-row { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr) 96px; gap: 16px; align-items: center; }
.cat-row .hbar-track { grid-column: auto; height: 14px; border-radius: 4px; }
.cat-row .hbar-track > span { border-radius: 4px; }
.cat-row .v { text-align: right; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.toolbar .search { flex: 1 1 280px; }
.toolbar .search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.toolbar .search .input { padding-left: 40px; min-height: 44px; font-size: 15px; }
.toolbar .select-wrap { flex: 0 1 280px; }
.toolbar .select-wrap.src { flex-basis: 180px; }
.toolbar .select { min-height: 44px; font-size: 15px; }
.table th.amt { text-align: right; }
.table td.date { white-space: nowrap; }
.tbl-scroll { max-height: 640px; overflow: auto; }
.tbl-scroll .table thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.export { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; justify-content: space-between; }
.export .copy { display: flex; flex-direction: column; gap: 6px; flex: 1 1 360px; }
.export .btns { display: flex; flex-wrap: wrap; gap: 8px; }

@media (max-width: 719.98px) {
  .dash { padding: 4px 16px 32px; gap: 16px; }
  .dash-filters { flex-direction: column; align-items: stretch; gap: 10px; }
  .dash-filters .period { width: auto; }
  .dash-filters .scroll-x { margin: 0 -16px; padding: 0 16px; }
  /* KPIs: Net is the hero; Income + Expenses share one card under it; review becomes a link row. */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
  .kpis .card { box-shadow: none; }
  .kpi-net { order: 1; grid-column: 1 / -1; border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0; padding-bottom: 16px; gap: 8px; }
  .kpi-net .money { font-size: 40px; }
  .kpi-inc { order: 2; border-radius: 0 0 0 var(--r-lg); border-right: 0; padding-top: 16px; gap: 4px; }
  .kpi-exp { order: 3; border-radius: 0 0 var(--r-lg) 0; border-left: 0; padding-top: 16px; gap: 4px; }
  .kpi-inc, .kpi-exp { position: relative; }
  .kpi-inc::before, .kpi-exp::before { content: ""; position: absolute; top: 0; height: 1px; background: var(--border); left: 24px; right: 0; }
  .kpi-exp::before { left: 0; right: 24px; }
  .kpi-inc .money, .kpi-exp .money { font-size: var(--fs-money-md); }
  .kpis .kpi-review { order: 4; grid-column: 1 / -1; margin-top: 16px; flex-direction: row; align-items: center; gap: 14px; min-height: 72px; padding: 20px; box-shadow: var(--sh-1); }
  .kpi-review .money { font-size: var(--fs-money-md); }
  .kpi-review .go { display: none; }
  .kpi-review .go-btn { display: inline-flex; pointer-events: none; }
  .kpi-review .txt { flex: 1; display: flex; flex-direction: column; }
  .kpi-review .label { order: 0; }
  .due-card { background: none; border: 0; box-shadow: none; padding: 0; }
  .due-card .card-head { padding: 8px 4px 0; margin-bottom: 10px !important; }
  .due-card .card-head .xs { display: none; }
  .due-grid { gap: 10px; }
  .due-tile { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--sh-1); border-radius: var(--r-lg); padding: 20px; }
  .due-tile .money { font-size: var(--fs-money-md); }
  .due-tile .why { min-height: 0; }
  .due-tile .due-detail { margin-top: 4px; border: 0; border-radius: 0; }
  .chart-box { height: 168px; }
  .cat-row { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; }
  .cat-row .hbar-track { grid-column: 1 / -1; grid-row: 2; height: 10px; border-radius: var(--r-pill); }
  .cat-bars { gap: 14px; }
  .hbars { gap: 14px; }
  .toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar .search { grid-column: 1 / -1; }
  .export .btns { flex-direction: column; width: 100%; }
  .export .btns .btn { width: 100%; }
  .due-tile .due-detail-head { display: none; }
}

/* Stacked list rows (phone versions of the dashboard tables) */
.stack-rows .table, .stack-rows tbody, .stack-rows tr, .stack-rows td { display: block; width: 100%; }
.stack-rows .table td { padding: 0; border: 0; }
.stack-rows .table tbody tr:hover td { background: none; }
.mrow { display: flex; flex-direction: column; gap: 10px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.mrow-top { display: flex; justify-content: space-between; gap: 12px; }
.mrow-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mrow .select, .mrow .input { min-height: 44px; font-size: 15px; }
.mrow-note { display: flex; gap: 8px; }
.trow { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.stack-rows tr:first-child .trow { border-top: 0; }
.trow .ent { margin-top: 7px; }
.trow .grow { flex: 1; min-width: 0; }
.drow { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.stack-rows tr:first-child .drow { border-top: 1px solid var(--border); }
.stack-rows.tbl-scroll { max-height: none; }

/* ---------- Ask ---------- */
.tabbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ask { display: flex; flex-direction: column; gap: 14px; }
.ask-intro { display: flex; flex-direction: column; gap: 16px; }
.ask-starters { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.ask-starters .chip { min-height: 40px; text-align: left; font-weight: 500; }
.ask-thread { display: flex; flex-direction: column; gap: 12px; }
.ask-thread:empty { display: none; }
.ask-msg { max-width: 100%; overflow-wrap: anywhere; scroll-margin-top: 16px; }
.ask-me { align-self: flex-end; max-width: 85%; background: var(--ink); color: var(--on-ink); padding: 10px 14px; border-radius: var(--r-md) var(--r-md) 4px var(--r-md); font: 500 15px/1.4 var(--font-ui); white-space: pre-wrap; }
.ask-ai { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; font-size: 15px; line-height: 1.5; color: var(--text); }
.ask-ai p { margin: 0 0 8px; }
.ask-ai p:last-child { margin-bottom: 0; }
.ask-ai ul { margin: 0 0 8px; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.ask-ai ul:last-child { margin-bottom: 0; }
.ask-ai .ask-checked { margin-top: 10px; }
.ask-wait { display: flex; align-items: center; gap: 10px; }
.ask-err { border-color: var(--danger); color: var(--danger); }
.ask-composer { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.ask-composer .textarea { min-height: 56px; }
.ask-send-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.due-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-top: 14px; }
