/*
  Componentes da área logada e da autenticação. Usa somente os tokens de tokens.css.
  A CSP do servidor bloqueia atributos style="": tudo que varia com os dados (largura de barra, posição de
  dica, nome de transição) é aplicado pelo script via CSSOM, e aqui ficam só os estados e as transições.
*/

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-sm)/var(--lh-body) var(--font-body);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1, h2, h3 { font-family: var(--font-display); line-height: var(--lh-tight); text-wrap: balance; }
h1 { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -0.035em; }
h2 { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: var(--fs-md); font-weight: 700; letter-spacing: -0.01em; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.icon { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip { position: fixed; top: -80px; left: var(--s-5); z-index: 200; padding: var(--s-3) var(--s-4); border-radius: var(--r-sm); background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.skip:focus { top: var(--s-3); }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
@media (pointer: coarse), (max-width: 860px) { :root { --hit: 44px; } }

/* ---------- Estrutura ---------- */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; z-index: 5; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s-2);
  padding: var(--s-6) var(--s-3) var(--s-4);
  background: var(--side-bg); color: var(--side-text-2);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font: 800 1.75rem/1 var(--font-display); letter-spacing: -0.07em; color: var(--side-text); }
.brand small { align-self: flex-start; margin-top: 2px; padding: 3px 5px; border-radius: 5px; box-shadow: inset 0 0 0 1px var(--side-border); font: 600 var(--fs-xs)/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--side-muted); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); rotate: -5deg; }
.brand-mark .icon { width: 22px; height: 22px; stroke-width: 2.5; }
.sidebar .brand { padding: 0 var(--s-3) var(--s-6); }
.nav { display: grid; gap: var(--s-1); }
.nav-label { padding: 0 var(--s-3); margin-bottom: var(--s-1); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--side-muted); }
.nav-link {
  position: relative; display: flex; align-items: center; gap: var(--s-3);
  min-height: 44px; padding: 0 var(--s-3); border-radius: var(--r-sm);
  font-weight: 500; color: var(--side-text-2);
  transition: background-color var(--dur-2), color var(--dur-2);
}
.nav-link:hover { background: var(--side-raised); color: var(--side-text); }
.nav-link[aria-current='page'] { background: var(--side-raised); color: var(--side-text); box-shadow: inset 3px 0 var(--accent); }
.nav-link .icon { color: var(--side-muted); transition: color var(--dur-2); }
.nav-link[aria-current='page'] .icon, .nav-link:hover .icon { color: var(--accent); }
.nav-count { margin-left: auto; min-width: 22px; padding: 1px 6px; border-radius: 6px; background: oklch(0.84 0.15 88 / 0.16); color: oklch(0.87 0.13 90); font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums; text-align: center; }
.sidebar-foot { margin-top: auto; display: grid; gap: var(--s-2); }
.quick-trigger {
  display: flex; align-items: center; gap: var(--s-2); width: 100%; min-height: 44px; padding: 0 var(--s-3);
  border-radius: var(--r-sm); box-shadow: inset 0 0 0 1px var(--side-border); color: var(--side-text-2); font-weight: 500; text-align: start;
  transition: background-color var(--dur-2), color var(--dur-2), scale var(--dur-1) ease-out;
}
.quick-trigger:hover { background: var(--side-raised); color: var(--side-text); }
.quick-trigger:active { scale: 0.96; }
.quick-trigger .icon { width: 18px; height: 18px; color: var(--accent); }
kbd { margin-left: auto; padding: 2px 6px; border-radius: 5px; box-shadow: inset 0 0 0 1px var(--side-border); font: 500 var(--fs-xs)/1.4 var(--font-body); color: var(--side-muted); }
.account-link { display: flex; align-items: center; gap: var(--s-3); min-height: 52px; padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); transition: background-color var(--dur-2); }
.account-link:hover, .account-link[aria-current='page'] { background: var(--side-raised); }
.account-text { min-width: 0; display: grid; }
.account-text b { font-weight: 600; color: var(--side-text); }
.account-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-xs); color: var(--side-muted); }
.avatar { display: grid; place-items: center; flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font: 800 var(--fs-sm)/1 var(--font-display); text-transform: uppercase; }
.avatar.sm { width: 26px; height: 26px; font-size: var(--fs-xs); }
.avatar.alt { background: var(--info-soft); color: var(--info-ink); }

.content { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); min-height: 64px; padding: 0 var(--s-8); }
.topbar .brand { display: none; color: var(--text); font-size: 1.5rem; }
.breadcrumb { display: flex; gap: var(--s-2); color: var(--text-muted); }
.breadcrumb strong { font-weight: 500; color: var(--text-2); }
.top-actions { display: flex; align-items: center; gap: var(--s-2); }
.today { margin-right: var(--s-2); color: var(--text-muted); }
.topbar .avatar-link { display: none; }
.main { width: 100%; max-width: 1240px; margin: 0 auto; padding: var(--s-4) var(--s-8) var(--s-12); }
.main:focus { outline: none; }
.tabbar { display: none; }

/* ---------- Cabeçalho de página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-5); margin-bottom: var(--s-6); }
.eyebrow { margin-bottom: var(--s-2); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fam-ink, var(--text-muted)); }
.page-sub { margin-top: var(--s-2); max-width: 60ch; color: var(--text-2); text-wrap: pretty; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.back-link { display: inline-flex; align-items: center; gap: var(--s-1); min-height: var(--hit); margin-bottom: var(--s-2); color: var(--text-muted); font-weight: 500; }
.back-link:hover { color: var(--text); }
.back-link .icon { width: 16px; height: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); margin: var(--s-8) 0 var(--s-4); }
.section-head h2 { display: flex; align-items: center; gap: var(--s-2); }
.count { padding: 2px 8px; border-radius: 6px; background: var(--sunken); color: var(--text-muted); font: 600 var(--fs-xs)/1.5 var(--font-body); letter-spacing: 0; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--hit); padding: 0 var(--s-4); border-radius: var(--r-sm);
  font-weight: 600; white-space: nowrap; user-select: none;
  transition: background-color var(--dur-2), box-shadow var(--dur-2), color var(--dur-2), scale var(--dur-1) ease-out;
}
.btn:active:not(:disabled) { scale: 0.96; }
.btn .icon { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: inset 0 0 0 1px oklch(0.45 0.125 136 / 0.22); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.btn-secondary:hover { background: var(--surface-2); box-shadow: var(--shadow-2); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--sunken); color: var(--text); }
.btn-danger { color: var(--gasto-ink); }
.btn-danger:hover { background: var(--gasto-soft); }
.btn-danger.solid { background: var(--gasto-ink); color: var(--surface); }
.btn-sm { min-height: 36px; padding: 0 var(--s-3); font-size: var(--fs-xs); }
.btn-block { width: 100%; }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: var(--hit); height: var(--hit); border-radius: var(--r-sm); color: var(--text-2);
  transition: background-color var(--dur-2), color var(--dur-2), scale var(--dur-1) ease-out;
}
.icon-btn:hover { background: var(--sunken); color: var(--text); }
.icon-btn:active { scale: 0.96; }
.icon-btn.bordered { box-shadow: var(--shadow-1); background: var(--surface); }
/* Troca de ícone contextual: os dois ficam no DOM e cruzam com escala, opacidade e desfoque. */
.swap { position: relative; display: grid; place-items: center; }
.swap > * { grid-area: 1 / 1; transition: opacity 300ms var(--ease-swap), scale 300ms var(--ease-swap), filter 300ms var(--ease-swap); }
.swap > .swap-off, .swap.on > .swap-on { opacity: 1; scale: 1; filter: blur(0); }
.swap > .swap-on, .swap.on > .swap-off { opacity: 0; scale: 0.25; filter: blur(4px); }

.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 11px; background: var(--sunken); }
.segmented button { min-height: calc(var(--hit) - 6px); padding: 0 var(--s-3); white-space: nowrap; border-radius: var(--r-sm); color: var(--text-muted); font-weight: 600; transition: background-color var(--dur-2), color var(--dur-2), box-shadow var(--dur-2); }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

.switch { position: relative; flex-shrink: 0; width: 46px; height: 28px; border-radius: var(--r-full); background: var(--border-strong); transition: background-color var(--dur-2); }
.switch::before { content: ''; position: absolute; inset: -8px; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--n-0); box-shadow: 0 1px 3px oklch(0 0 0 / 0.25); transition: translate var(--dur-2) var(--ease-out); }
.switch[aria-checked='true'] { background: var(--meta-solid); }
.switch[aria-checked='true']::after { translate: 18px 0; }

/* ---------- Superfícies ---------- */
.panel { min-width: 0; padding: var(--s-6); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
.panel-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s-3) var(--s-4); margin-bottom: var(--s-5); }
.panel-head > div:first-child { flex: 1 1 200px; min-width: 0; }
.panel-head p { margin-top: var(--s-1); color: var(--text-muted); }
.card { position: relative; min-width: 0; padding: var(--s-5); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); transition: box-shadow var(--dur-2), translate var(--dur-2) var(--ease-out); }
.card.link:hover { box-shadow: var(--shadow-2); translate: 0 -2px; }
/* O título é o link; o pseudo-elemento estende a área de clique ao cartão inteiro sem aninhar botões dentro de <a>. */
.card.link h3 a::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
.card.link .card-actions { position: relative; z-index: 1; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); margin-bottom: var(--s-5); }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { padding: var(--s-5); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
.stat-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); color: var(--text-2); }
.stat-value { display: block; margin: var(--s-3) 0 var(--s-1); font: 800 var(--fs-xl)/1.15 var(--font-display); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-note { font-size: var(--fs-xs); color: var(--text-muted); }
.chip-icon { display: grid; place-items: center; flex-shrink: 0; width: 34px; height: 34px; border-radius: 10px; background: var(--fam-soft, var(--sunken)); color: var(--fam-ink, var(--text-2)); }
.chip-icon .icon { width: 18px; height: 18px; }
.tag { display: inline-flex; align-items: center; gap: var(--s-1); padding: 3px 8px; border-radius: 6px; background: var(--fam-soft, var(--sunken)); color: var(--fam-ink, var(--text-2)); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.tag .icon { width: 13px; height: 13px; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--fam-ink, var(--text)); }

/* ---------- Barras e anéis de progresso ---------- */
.bar { height: 8px; border-radius: var(--r-full); background: var(--sunken); overflow: hidden; }
.bar i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--fam-solid, var(--meta-solid)); transition: width 700ms var(--ease-out); }
/* Recuperação: a trilha é o que falta voltar (coral) e o preenchimento é o que já voltou (lime). */
.bar.recovery { background: var(--gasto-track); }
.bar.recovery i { background: var(--meta-solid); }
.bar-labels { display: flex; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-2); font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.ring { position: relative; display: grid; place-items: center; flex-shrink: 0; }
.ring svg { display: block; rotate: -90deg; }
.ring-track { fill: none; stroke: var(--sunken); }
.ring-value { fill: none; stroke: var(--meta-solid); stroke-linecap: round; transition: stroke-dashoffset 900ms var(--ease-out); }
.ring.done .ring-value { stroke: var(--accent); }
.ring-mark { stroke: var(--surface); stroke-width: 2; }
.ring-label { position: absolute; font: 800 var(--fs-sm)/1 var(--font-display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.ring.lg .ring-label { font-size: var(--fs-2xl); }
.ring-label small { display: block; margin-top: 4px; font: 500 var(--fs-xs)/1 var(--font-body); letter-spacing: 0; color: var(--text-muted); text-align: center; }

/* ---------- Período ---------- */
.period { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); margin-bottom: var(--s-5); }
.period-nav { display: flex; align-items: center; gap: var(--s-1); }
.period-label { margin-left: auto; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.field-inline { min-height: var(--hit); padding: 0 var(--s-3); border: 0; border-radius: var(--r-sm); background: var(--surface); box-shadow: var(--shadow-1); color: var(--text); }

/* ---------- Dashboard ---------- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: var(--s-5); margin-bottom: var(--s-5); }
.spaced { margin-top: var(--s-5); }
.grid-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5); }
.stack { display: grid; gap: var(--s-3); align-content: start; }
.chart-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-4); font-size: var(--fs-xs); color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 3px; background: var(--fam-solid); }
/* O script desenha o SVG na largura do contêiner; a altura mínima reserva o espaço antes disso. */
.chart { position: relative; min-height: 250px; }
.chart svg { display: block; max-width: 100%; overflow: visible; touch-action: pan-y; }
.chart-grid { stroke: var(--border); stroke-dasharray: 3 4; }
.chart-axis { fill: var(--text-muted); font: 500 12px var(--font-body); font-variant-numeric: tabular-nums; }
.chart-bar, .chart-area, .chart-line, .chart-dot { transition: opacity var(--dur-2); }
.chart-bar.gasto, .chart-dot.gasto, .chart-point.gasto { fill: var(--gasto-solid); }
.chart-bar.rec, .chart-dot.rec, .chart-point.rec { fill: var(--rec-solid); }
.chart-bar.meta, .chart-dot.meta, .chart-point.meta { fill: var(--meta-solid); }
.chart-point { stroke: var(--surface); stroke-width: 2; }
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-line.gasto { stroke: var(--gasto-solid); }
.chart-line.rec { stroke: var(--rec-solid); }
.chart-line.meta { stroke: var(--meta-solid); }
.chart-line.ideal { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 5 5; }
.chart-area.gasto { fill: var(--gasto-solid); opacity: 0.14; }
.chart-area.rec { fill: var(--rec-solid); opacity: 0.2; }
.chart-area.meta { fill: var(--meta-solid); opacity: 0.18; }
.chart-gap { fill: var(--gasto-solid); opacity: 0.1; }
.chart-cross { stroke: var(--text-muted); stroke-width: 1; opacity: 0; transition: opacity var(--dur-1); }
.chart-dot { stroke: var(--surface); stroke-width: 2; opacity: 0; }
.chart.hover .chart-cross, .chart.hover .chart-dot { opacity: 1; }
.chart-hit { fill: transparent; }
.chart-tip {
  position: absolute; top: 0; left: 0; z-index: 2; min-width: 168px; padding: var(--s-3); border-radius: var(--r-md);
  background: var(--side-bg); color: var(--side-text); box-shadow: var(--shadow-3); font-size: var(--fs-xs); pointer-events: none;
  opacity: 0; translate: 0 4px; transition: opacity var(--dur-1), translate var(--dur-1);
}
.chart.hover .chart-tip { opacity: 1; translate: 0 0; }
.chart-tip b { display: block; margin-bottom: var(--s-1); font-size: var(--fs-sm); }
.chart-tip div { display: flex; justify-content: space-between; gap: var(--s-4); color: var(--side-text-2); font-variant-numeric: tabular-nums; }
.chart-tip div span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.chart-tip i { width: 7px; height: 7px; border-radius: 2px; background: var(--fam-solid); }
.chart-empty { display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-10) var(--s-4); border-radius: var(--r-md); background: var(--surface-2); color: var(--text-muted); text-align: center; }
.chart-empty strong { color: var(--text-2); font-weight: 600; }
.chart-foot { display: flex; justify-content: space-between; gap: var(--s-4); margin-top: var(--s-4); padding-top: var(--s-3); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-muted); }

.balance { display: flex; flex-direction: column; padding: var(--s-6); border-radius: var(--r-lg); background: var(--side-bg); color: var(--side-text-2); box-shadow: var(--shadow-2); }
.balance h2 { color: var(--side-text); }
.balance .panel-head p { color: var(--side-muted); }
.balance-amount { margin: var(--s-2) 0 var(--s-1); font: 800 var(--fs-2xl)/1.15 var(--font-display); letter-spacing: -0.045em; font-variant-numeric: tabular-nums; color: var(--side-text); overflow-wrap: anywhere; }
.balance .bar { height: 10px; margin-top: var(--s-5); background: oklch(0.68 0.17 25 / 0.3); }
.balance .bar i { background: var(--accent); }
.balance .bar-labels { color: var(--side-muted); }
.balance .btn { margin-top: var(--s-5); }
.balance-next { margin-top: var(--s-5); padding-top: var(--s-4); border-top: 1px solid var(--side-border); display: grid; gap: var(--s-2); }
.balance-next h3 { font: 600 var(--fs-xs)/1.4 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--side-muted); }
.due-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); width: 100%; min-height: 44px; padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); background: var(--side-raised); text-align: start; transition: scale var(--dur-1) ease-out; }
.due-row:active { scale: 0.98; }
.due-row b { display: block; color: var(--side-text); font-weight: 600; overflow-wrap: anywhere; }
.due-row small { font-size: var(--fs-xs); color: var(--side-muted); }
.due-row.late small { color: oklch(0.82 0.1 25); }
.due-row .amount { color: var(--accent); }

/* ---------- Metas ---------- */
.goal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s-4); }
.goal-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-4); align-items: center; }
.goal-card h3 { overflow-wrap: anywhere; }
.card-kicker { display: flex; flex-wrap: wrap; gap: var(--s-1); margin-bottom: var(--s-2); }
.money-line { margin-top: var(--s-1); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.money-line b { font: 700 var(--fs-md)/1.3 var(--font-display); letter-spacing: -0.02em; color: var(--text); }
.hint { margin-top: var(--s-2); font-size: var(--fs-xs); color: var(--text-2); text-wrap: pretty; }
.hint.late { color: var(--gasto-ink); }
.hint.good { color: var(--meta-ink); }
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.goal-card .card-actions { grid-column: 1 / -1; justify-content: space-between; padding-top: var(--s-3); border-top: 1px solid var(--border); }
.members { display: flex; }
.members .avatar { margin-left: -6px; box-shadow: 0 0 0 2px var(--surface); }
.members .avatar:first-child { margin-left: 0; }

/* ---------- Gastos e recuperações ---------- */
.record-list { display: grid; gap: var(--s-3); }
.expense-card { display: grid; grid-template-columns: auto minmax(0, 1.1fr) minmax(0, 1.2fr) auto; gap: var(--s-5); align-items: center; }
.expense-card h3 { overflow-wrap: anywhere; }
.meta-line { margin-top: var(--s-1); font-size: var(--fs-xs); color: var(--text-muted); }
.meta-line.late { color: var(--gasto-ink); font-weight: 600; }
.expense-card .card-actions { flex-direction: column; align-items: stretch; }
.cat-bars { display: grid; gap: var(--s-3); }
.cat-row { display: grid; grid-template-columns: minmax(110px, 0.6fr) minmax(0, 1.6fr) auto; gap: var(--s-3); align-items: center; }
.cat-row span:first-child { display: flex; align-items: center; gap: var(--s-2); color: var(--text-2); }
.cat-row .icon { width: 16px; height: 16px; color: var(--text-muted); }

.activity { display: grid; }
.activity li + li { border-top: 1px solid var(--border); }
.activity-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s-3); align-items: center; width: 100%; min-height: 56px; padding: var(--s-2) var(--s-2); margin: 0 calc(var(--s-2) * -1); border-radius: var(--r-sm); text-align: start; transition: background-color var(--dur-2); }
.activity-row:hover { background: var(--surface-2); }
.activity-main { min-width: 0; display: grid; }
.activity-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-main small { font-size: var(--fs-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.no-rows { padding: var(--s-8) var(--s-4); border-radius: var(--r-md); background: var(--surface-2); color: var(--text-muted); text-align: center; }

.schedule { display: grid; gap: var(--s-2); }
.schedule li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s-3); align-items: center; min-height: 48px; padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); background: var(--surface-2); }
.schedule .step { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--sunken); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 700; }
.schedule li.paid .step { background: var(--meta-soft); color: var(--meta-ink); }
.schedule li.late { box-shadow: inset 3px 0 var(--gasto-solid); }
.schedule li.next { box-shadow: inset 3px 0 var(--rec-solid); }
.schedule small { display: block; font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- Detalhe ---------- */
.detail-hero { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-8); align-items: center; padding: var(--s-8); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); margin-bottom: var(--s-5); }
.detail-hero.flat { grid-template-columns: minmax(0, 1fr); }
.hero-value { font: 800 var(--fs-3xl)/1.05 var(--font-display); letter-spacing: -0.05em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-value small { font: 500 var(--fs-md)/1.4 var(--font-body); letter-spacing: 0; color: var(--text-muted); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s-4); margin-top: var(--s-5); }
.fact small { display: block; font-size: var(--fs-xs); color: var(--text-muted); }
.fact b { font: 700 var(--fs-md)/1.4 var(--font-display); font-variant-numeric: tabular-nums; }
.detail-hero .bar { height: 12px; margin-top: var(--s-5); }

/* ---------- Formulários e diálogos ---------- */
.field { display: grid; gap: 6px; margin-bottom: var(--s-4); }
.field label, .field-label { font-weight: 600; color: var(--text-2); }
.field input, .field select, .field textarea, .input {
  width: 100%; min-height: 46px; padding: 0 var(--s-3); border: 0; border-radius: var(--r-sm);
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text);
  transition: box-shadow var(--dur-2);
}
.field textarea { padding: var(--s-3); min-height: 132px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--fs-xs); line-height: 1.6; }
.field input::placeholder, .field textarea::placeholder { color: var(--text-muted); opacity: 0.8; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .input:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--focus), 0 0 0 4px oklch(0.76 0.19 132 / 0.22); }
.field small { font-size: var(--fs-xs); color: var(--text-muted); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 48px; }
.password-field .icon-btn { position: absolute; top: 50%; right: 3px; translate: 0 -50%; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 var(--s-3); border-radius: var(--r-full); box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; transition: background-color var(--dur-2), color var(--dur-2), box-shadow var(--dur-2), scale var(--dur-1) ease-out; }
.chip:active { scale: 0.96; }
.chip .icon { width: 15px; height: 15px; }
.chip[aria-pressed='true'] { background: var(--text); color: var(--bg); box-shadow: none; }
.form-error { padding: var(--s-3); border-radius: var(--r-sm); background: var(--gasto-soft); color: var(--gasto-ink); font-weight: 500; }
.form-error.ok { background: var(--meta-soft); color: var(--meta-ink); }

dialog { padding: 0; border: 0; color: var(--text); background: transparent; max-width: none; max-height: none; }
dialog::backdrop { background: var(--overlay); backdrop-filter: blur(4px); }
.dialog { width: min(480px, calc(100vw - 24px)); max-height: min(88dvh, 760px); margin: auto; overflow: auto; border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-3); }
.dialog.wide { width: min(720px, calc(100vw - 24px)); }
.dialog[open] { animation: dialog-in var(--dur-2) var(--ease-out); }
.dialog[open]::backdrop { animation: fade-in var(--dur-2) ease-out; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); padding: var(--s-6) var(--s-6) 0; }
.dialog-head p { margin-top: var(--s-2); color: var(--text-muted); text-wrap: pretty; }
.dialog-body { padding: var(--s-5) var(--s-6) var(--s-6); }
.dialog-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-5); }
.dialog-foot .btn-danger { margin-right: auto; }

.quick { width: min(600px, calc(100vw - 24px)); margin-top: 12dvh; }
.quick-input { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--border); }
.quick-input .icon { color: var(--text-muted); }
.quick-input input { flex: 1; min-width: 0; min-height: 48px; border: 0; background: none; outline: none; font-size: var(--fs-md); }
.quick-list { max-height: min(52dvh, 420px); overflow: auto; padding: var(--s-2); }
.quick-group { padding: var(--s-3) var(--s-3) var(--s-1); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.quick-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s-3); align-items: center; width: 100%; min-height: 52px; padding: var(--s-2) var(--s-3); border-radius: var(--r-md); text-align: start; }
.quick-item[aria-selected='true'] { background: var(--sunken); }
.quick-item b { display: block; font-weight: 600; overflow-wrap: anywhere; }
.quick-item small { font-size: var(--fs-xs); color: var(--text-muted); }
.quick-item .amount { font-size: var(--fs-md); }
.quick-foot { display: flex; flex-wrap: wrap; gap: var(--s-4); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-muted); }
.quick-foot kbd { margin: 0 4px 0 0; box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text-2); }

.import-table { width: 100%; border-collapse: collapse; font-size: var(--fs-xs); }
.import-table th { padding: var(--s-2); text-align: start; color: var(--text-muted); font-weight: 600; }
.import-table td { padding: var(--s-2); border-top: 1px solid var(--border); vertical-align: middle; }
.import-table td:last-child, .import-table th:last-child { text-align: end; font-variant-numeric: tabular-nums; }
.import-scroll { max-height: 300px; overflow: auto; border-radius: var(--r-md); box-shadow: inset 0 0 0 1px var(--border); }
.check { width: 20px; height: 20px; accent-color: var(--meta-solid); }

/* ---------- Avisos ---------- */
.toasts { position: fixed; left: 50%; bottom: var(--s-6); z-index: 300; display: grid; gap: var(--s-2); translate: -50% 0; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--side-bg); color: var(--side-text); box-shadow: var(--shadow-3); pointer-events: auto; opacity: 0; translate: 0 12px; transition: opacity var(--dur-2), translate var(--dur-2) var(--ease-out); }
.toast.show { opacity: 1; translate: 0 0; }
.toast span { flex: 1; }
.toast button { min-height: 36px; padding: 0 var(--s-3); border-radius: var(--r-sm); color: var(--accent); font-weight: 700; }
.toast button:hover { background: var(--side-raised); }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4); border-radius: var(--r-md); background: var(--fam-soft, var(--sunken)); color: var(--fam-ink, var(--text-2)); }
.banner p { flex: 1; min-width: 200px; }
.banner .btn { background: var(--surface); color: var(--text); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-full); background: var(--rec-soft); color: var(--rec-ink); font-size: var(--fs-xs); font-weight: 600; }
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.empty { display: grid; justify-items: center; gap: var(--s-3); padding: var(--s-12) var(--s-5); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); text-align: center; }
.empty .chip-icon { width: 56px; height: 56px; border-radius: 18px; }
.empty .chip-icon .icon { width: 26px; height: 26px; }
.empty p { max-width: 44ch; color: var(--text-muted); text-wrap: pretty; }
.empty.compact { padding: var(--s-8) var(--s-5); }
.checklist { display: grid; gap: var(--s-2); }
.checklist button { display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: 56px; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--surface-2); text-align: start; transition: background-color var(--dur-2), scale var(--dur-1) ease-out; }
.checklist button:hover { background: var(--sunken); }
.checklist button:active { scale: 0.98; }
.checklist b { display: block; font-weight: 600; }
.checklist small { color: var(--text-muted); font-size: var(--fs-xs); }
.checklist .done b { text-decoration: line-through; color: var(--text-muted); }
.checklist .step { display: grid; place-items: center; flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--border-strong); color: var(--text-muted); font-weight: 700; font-size: var(--fs-xs); }
.checklist .done .step { background: var(--meta-solid); box-shadow: none; color: var(--accent-ink); }

/* ---------- Autenticação ---------- */
.auth-page { display: grid; place-items: center; min-height: 100dvh; padding: var(--s-6) var(--s-4); background: radial-gradient(circle at 18% 8%, oklch(0.91 0.19 128 / 0.28) 0, transparent 34%), var(--bg); }
.auth-card { width: min(100%, 460px); padding: var(--s-10); border-radius: 28px; background: var(--surface); box-shadow: var(--shadow-3); }
.auth-card .brand { color: var(--text); }
.auth-card .brand small { color: var(--text-muted); box-shadow: inset 0 0 0 1px var(--border-strong); }
.auth-copy { margin: var(--s-8) 0 var(--s-6); }
.auth-copy h1 { margin: var(--s-2) 0; }
.auth-copy p:last-child { color: var(--text-2); }
.auth-tabs { display: flex; width: 100%; margin-bottom: var(--s-5); }
.auth-tabs button { flex: 1; }
.auth-form .btn { margin-top: var(--s-2); }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-2); margin-top: var(--s-3); }
.text-link { display: inline-flex; align-items: center; min-height: 36px; color: var(--accent-text); font-weight: 600; text-decoration: underline; text-decoration-thickness: from-font; text-underline-offset: 3px; }
.text-link:hover { color: var(--text); }
.divider { display: flex; align-items: center; gap: var(--s-3); margin: var(--s-5) 0 var(--s-4); font-size: var(--fs-xs); color: var(--text-muted); }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.google-g { font: 800 var(--fs-md)/1 var(--font-display); color: oklch(0.62 0.19 262); }
.auth-hint { margin-top: var(--s-5); font-size: var(--fs-xs); color: var(--text-muted); text-wrap: pretty; }
.auth-hint a { color: var(--text-2); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Conta ---------- */
.settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5); align-items: start; }
.settings .panel.full { grid-column: 1 / -1; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-3) 0; }
.setting + .setting { border-top: 1px solid var(--border); }
.setting b { display: block; font-weight: 600; }
.setting small { color: var(--text-muted); font-size: var(--fs-xs); text-wrap: pretty; }
.setting > div:first-child { min-width: 0; }
.danger-zone { box-shadow: inset 0 0 0 1px var(--gasto-solid); }
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 0 var(--s-3) var(--s-3); text-align: start; font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.table td { padding: var(--s-3); border-top: 1px solid var(--border); }
.people { display: grid; gap: var(--s-2); }
.person { display: flex; align-items: center; gap: var(--s-3); min-height: 44px; }
.person span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.invite-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-2); margin-top: var(--s-4); }

/* ---------- Movimento ---------- */
@keyframes fade-in { from { opacity: 0; } }
@keyframes dialog-in { from { opacity: 0; translate: 0 12px; scale: 0.98; } }
@keyframes enter { from { opacity: 0; translate: 0 12px; filter: blur(4px); } }
/* Entrada em blocos, com 80ms entre eles, só quando a pessoa troca de tela (a classe sai depois da primeira pintura). */
.motion .page > * { animation: enter var(--dur-3) var(--ease-out) both; }
.motion .page > :nth-child(2) { animation-delay: 80ms; }
.motion .page > :nth-child(3) { animation-delay: 160ms; }
.motion .page > :nth-child(4) { animation-delay: 240ms; }
.motion .page > :nth-child(n + 5) { animation-delay: 320ms; }
/* O bloco que participa da transição entre telas (cartão que vira cabeçalho) não entra de novo por conta própria. */
.motion .page > [data-vt] { animation: none; }

/* Números que rolam: cada dígito é uma coluna de 0 a 9 deslocada verticalmente. */
.roll-visual { display: inline-flex; line-height: 1.15; white-space: pre; }
.roll-col { display: inline-block; height: 1.15em; overflow: hidden; }
.roll-strip { display: flex; flex-direction: column; transition: transform 800ms var(--ease-out); }
.roll-strip span { height: 1.15em; }

.fly-chip { position: fixed; top: 0; left: 0; z-index: 400; padding: 6px 12px; border-radius: var(--r-full); background: var(--accent); color: var(--accent-ink); font: 800 var(--fs-sm)/1.2 var(--font-display); font-variant-numeric: tabular-nums; box-shadow: var(--shadow-3); pointer-events: none; will-change: transform, opacity; }
.pulse { animation: pulse 700ms var(--ease-out); }
@keyframes pulse { 30% { scale: 1.05; } }
.confetti { position: fixed; inset: 0; z-index: 390; width: 100%; height: 100%; pointer-events: none; }
.stamp { animation: stamp 520ms var(--ease-out) both; }
@keyframes stamp { from { opacity: 0; scale: 1.6; rotate: -8deg; filter: blur(4px); } }

::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--dur-2); }
::view-transition-group(*) { animation-duration: 380ms; animation-timing-function: var(--ease-out); }

/* ---------- Telas menores ---------- */
@media (max-width: 1080px) {
  .shell { grid-template-columns: 208px minmax(0, 1fr); }
  .topbar, .main { padding-inline: var(--s-5); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .expense-card { grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); }
  .expense-card .card-actions { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
  .today { display: none; }
}
@media (max-width: 860px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .topbar { position: sticky; top: 0; z-index: 6; min-height: 56px; padding-inline: var(--s-4); background: color-mix(in oklch, var(--bg) 88%, transparent); backdrop-filter: blur(12px); }
  .topbar .brand, .topbar .avatar-link { display: inline-flex; align-items: center; min-height: var(--hit); }
  .topbar .avatar-link { justify-content: center; min-width: var(--hit); }
  .chart { min-height: 210px; }
  .btn-sm { min-height: 40px; }
  .breadcrumb { display: none; }
  .main { padding: var(--s-3) var(--s-4) calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.75rem; }
  .page-head { flex-direction: column; align-items: stretch; gap: var(--s-4); }
  .page-actions .btn { flex: 1; }
  .settings, .grid-even { grid-template-columns: minmax(0, 1fr); }
  .stats, .stats.three { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
  .stats.three > :first-child { grid-column: 1 / -1; }
  .stat, .card, .panel, .balance { padding: var(--s-4); }
  .stat-value { font-size: var(--fs-lg); }
  .period-label { width: 100%; margin: 0; }
  .expense-card { grid-template-columns: auto minmax(0, 1fr); gap: var(--s-3) var(--s-4); }
  .expense-progress { grid-column: 1 / -1; }
  .expense-card .card-actions .btn { flex: 1; }
  .detail-hero { grid-template-columns: minmax(0, 1fr); justify-items: start; gap: var(--s-5); padding: var(--s-5); }
  .hero-value { font-size: var(--fs-2xl); }
  .cat-row { grid-template-columns: minmax(0, 1fr) auto; }
  .cat-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .field-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  /* Campos em 16px evitam o zoom automático do iOS ao focar. */
  .field input, .field select, .input, .quick-input input, .field-inline { font-size: var(--fs-md); }
  .dialog, .dialog.wide, .quick { width: 100vw; max-width: none; max-height: 92dvh; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .dialog[open] { animation-name: sheet-in; }
  .dialog-head { padding: var(--s-5) var(--s-5) 0; }
  .dialog-body { padding: var(--s-4) var(--s-5) calc(var(--s-5) + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(88px + env(safe-area-inset-bottom)); }
  .auth-card { padding: var(--s-6) var(--s-5); border-radius: var(--r-lg); }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
    padding: 6px var(--s-2) calc(6px + env(safe-area-inset-bottom)); background: var(--side-bg); box-shadow: 0 -1px 0 var(--side-border);
  }
  .tabbar a { display: grid; justify-items: center; gap: 2px; min-height: 52px; padding-top: 6px; border-radius: var(--r-sm); color: var(--side-muted); font-size: var(--fs-xs); font-weight: 500; transition: color var(--dur-2); }
  .tabbar a[aria-current='page'] { color: var(--accent); }
  .tabbar a .icon { width: 22px; height: 22px; }
  .tabbar-add { display: grid; place-items: center; justify-self: center; width: 52px; height: 52px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px oklch(0.91 0.19 128 / 0.35); transition: scale var(--dur-1) ease-out; }
  .tabbar-add:active { scale: 0.96; }
  .tabbar-add .icon { width: 24px; height: 24px; stroke-width: 2.4; }
}
@keyframes sheet-in { from { translate: 0 100%; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
