/* Cofrito web — CSS próprio, sem framework.
   Paleta da marca: laranja #F2A330. Claro e escuro pelo esquema do sistema. */

:root {
  --brand: #f2a330;
  --brand-ink: #7a4d05;

  --positive: #339e5c;
  --warning: #eab334;
  --negative: #dc453d;

  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --line: #dedee4;
  --text: #16161a;
  --text-2: #6b6b76;
  --text-3: #a0a0ab;

  --radius: 12px;

  /* Densidade da planilha, calibrada pela referência.
     A conta que definiu os números: lá a tabela de um mês ocupa ~69% da
     largura da janela e aparece só ~1,3 mês por vez. Vale a pena: dá pra ler
     de relance em vez de apertar os olhos. Quem quer ver muitos meses de uma
     vez usa o Horizonte, que é a tela feita pra isso. */
  --row-h: 48px;
  --visible-rows: 15;

  --col-day: 64px;
  --col-type: 200px;
  --col-balance: 212px;

  /* Cores dos cinco tipos de movimentação, iguais ao `MovementType.color` do
     app. Ficam como variável porque a mesma cor pinta o ponto da planilha, a
     pílula do tipo, o botão de salvar e a fatia do donut. */
  --type-entrada: #2e9e6b;
  --type-saida: #c7404d;
  --type-diario: #e69e33;
  --type-economia: #1a73c7;
  --type-cartao: #734dc7;
}

/* Tema escuro. Vale por preferência do sistema **ou** por escolha explícita na
   conta (`Ajustes → Aparência`, a mesma configuração que o app sincroniza). O
   `data-theme` no elemento raiz é quem decide quando o usuário escolheu. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131316;
    --surface: #1c1c21;
    --surface-2: #232329;
    --line: #33333c;
    --text: #f2f2f5;
    --text-2: #a1a1ad;
    --text-3: #6e6e7a;
  }
}

:root[data-theme="dark"] {
  --bg: #131316;
  --surface: #1c1c21;
  --surface-2: #232329;
  --line: #33333c;
  --text: #f2f2f5;
  --text-2: #a1a1ad;
  --text-3: #6e6e7a;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font: 14px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ---------- Entrada ---------- */

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(60rem 40rem at 15% 10%, rgba(255, 255, 255, .35), transparent 60%),
    radial-gradient(50rem 40rem at 85% 90%, rgba(217, 76, 89, .35), transparent 60%),
    linear-gradient(135deg, #fcd28d 0%, var(--brand) 45%, #d16c24 100%);
}

.auth-card {
  width: min(380px, 100%);
  background: var(--surface);
  border-radius: 22px;
  padding: 32px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .22);
}

/* Mascote com o pisca do splash do app: as duas artes empilhadas, alternando
   a opacidade. Mesmo ritmo do `MascotBlinker` em SwiftUI. */
.mascot {
  position: relative;
  width: 118px;
  height: 118px;
  margin: 0 auto 10px;
}

.mascot img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.mascot-open { animation: blink-open 5s infinite; }
.mascot-blink { animation: blink-closed 5s infinite; }

@keyframes blink-open {
  0%, 5%, 12%, 100% { opacity: 1; }
  7%, 10% { opacity: 0; }
}

@keyframes blink-closed {
  0%, 5%, 12%, 100% { opacity: 0; }
  7%, 10% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .mascot-open, .mascot-blink { animation: none; }
  .mascot-blink { opacity: 0; }
}

.wordmark {
  display: block;
  width: 168px;
  margin: 0 auto;
}

.auth-subtitle {
  margin: 6px 0 24px;
  text-align: center;
  color: var(--text-2);
}

.field { display: block; margin-bottom: 14px; }

.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

/* Campo da tela de entrada. Dentro da folha os campos são estilizados por
   `.form-row`, então esta regra fica só com o `.field` — antes ela também pegava
   `.sheet input` e desenhava uma caixa com borda em volta do campo de valor,
   que é justamente o que ele não pode ter. */
.field input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(242, 163, 48, .25);
}

button.primary {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

button.primary:disabled { opacity: .45; cursor: not-allowed; }
button.primary:not(:disabled):hover { filter: brightness(1.05); }

button.link {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 6px;
  font: inherit;
  color: var(--text-2);
  background: none;
  border: 0;
  cursor: pointer;
}

button.link.small { font-size: 12px; margin: 0; text-align: left; width: auto; }
button.link:hover { color: var(--text); }

.message {
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
}

.message.error { color: var(--negative); background: rgba(220, 69, 61, .12); }
.message.info { color: var(--positive); background: rgba(51, 158, 92, .12); }

/* ---------- Moldura ---------- */

.shell {
  display: grid;
  grid-template-columns: 208px 1fr;
  height: 100%;
  /* Trava a moldura no tamanho da janela. Quem rola é a área de conteúdo, por
     dentro — a lateral fica parada. */
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  /* Se a própria lateral não couber (notebook baixo), ela rola por dentro em
     vez de empurrar a página. */
  overflow-y: auto;
}

.sidebar-brand { padding: 2px 10px 18px; }
.sidebar-brand img { display: block; width: 116px; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-actions {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  font: inherit;
  color: var(--text-2);
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item.is-active {
  color: var(--brand);
  background: rgba(242, 163, 48, .12);
  font-weight: 600;
}

.nav-icon { width: 18px; text-align: center; opacity: .9; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-3);
}

.who {
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* `min-height: 0` não é detalhe: item de grid nasce com `min-height: auto`, que
   o proíbe de encolher abaixo do próprio conteúdo. Sem isso, uma tela longa
   (Ajustes, Faturas) estica o `.main` além da linha do grid, a página inteira
   passa a rolar e leva a barra lateral junto — e o `overflow: auto` do
   `.content` nunca chega a valer, porque ele nunca fica menor que o conteúdo. */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-title { margin: 0; font-size: 19px; }

.topbar-right {
  justify-self: end;
  font-size: 12px;
  color: var(--text-3);
}

.period { display: flex; align-items: center; gap: 4px; }

.period-label {
  min-width: 176px;
  padding: 5px 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  border-radius: 999px;
}

.step {
  width: 26px;
  height: 26px;
  font: inherit;
  color: var(--text-2);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.step:hover { background: var(--surface-2); color: var(--text); }

.content { flex: 1; overflow: auto; padding: 20px; }

.loading, .empty {
  padding: 40px;
  text-align: center;
  color: var(--text-3);
}

/* ---------- Planilha ---------- */

.months { display: flex; align-items: flex-start; gap: 28px; }

.month { flex: none; }

.month-title {
  margin: 0 0 8px 2px;
  font-size: 15px;
  font-weight: 700;
}

/* O mês é uma janela de altura fixa que rola por dentro, com cabeçalho e
   rodapé presos. É o que permite a linha ser alta sem a página virar um rolo
   de 12 meses × 31 dias. */
.sheet-table {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .06);
}

/* Altura fixa, sem `flex: 1`. Com flex-grow num contêiner de altura automática
   a área cresceria junto com o conteúdo e a rolagem interna nunca aconteceria
   — que foi exatamente o que deu errado na primeira tentativa.
   `--visible-rows` é recalculado em JS conforme a altura da janela (ver
   `fitRows` em grid.js): a altura tem que ser múltiplo exato da linha, senão
   sobra meia linha cortada na borda. */
.rows {
  flex: none;
  height: calc(var(--row-h) * var(--visible-rows));
  overflow-y: auto;
  scrollbar-width: thin;
}

.row { display: flex; align-items: stretch; height: var(--row-h); flex: none; }

.row.head {
  height: 42px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  border-bottom: 1px solid var(--line);
}

.row.foot {
  height: 52px;
  font-size: 14px;
  font-weight: 700;
  border-top: 2px solid var(--line);
  background: var(--surface);
}

.row.day { border-bottom: 1px solid var(--line); }
.row.day:last-child { border-bottom: 0; }
.row.day:hover { background: var(--surface-2); cursor: pointer; }

.cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 16px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  border-right: 1px solid var(--line);
}

/* O ícone do tipo fica à esquerda e o valor à direita, como na referência —
   dá uma âncora visual pra varrer a coluna sem reler o cabeçalho. */
.cell .dot { margin-right: auto; }

.cell.day-num {
  width: var(--col-day);
  justify-content: center;
  padding: 0;
  font-size: 15px;
  color: var(--text-2);
  font-weight: 600;
}

.cell.type { width: var(--col-type); }

.cell.balance {
  width: var(--col-balance);
  font-weight: 700;
  border-right: 0;
}

.cell.zero { color: var(--text-3); }
.cell.zero .dot { opacity: .35; filter: grayscale(1); }

.day-num.weekend { background: rgba(92, 125, 199, .12); }

.day-num.today {
  background: var(--text);
  color: var(--surface);
  font-weight: 800;
}

/* A coluna de saldo é a leitura de relance da planilha. Dia projetado entra
   mais lavado que dia já realizado. */
.balance.pos { background: rgba(51, 158, 92, .30); }
.balance.warn { background: rgba(234, 179, 52, .30); }
.balance.neg { background: rgba(220, 69, 61, .30); }
.balance.projected.pos { background: rgba(51, 158, 92, .15); }
.balance.projected.warn { background: rgba(234, 179, 52, .15); }
.balance.projected.neg { background: rgba(220, 69, 61, .15); }

.dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 5px;
  border-radius: 50%;
  vertical-align: -1px;
  flex: none;
}

.dot.entrada { background: var(--type-entrada); }
.dot.saida { background: var(--type-saida); }
.dot.diario { background: var(--type-diario); }
.dot.economia { background: var(--type-economia); }
.dot.cartao { background: var(--type-cartao); }

/* ---------- Totais ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  max-width: 980px;
}

.card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.card .value {
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.card .hint { margin-top: 6px; font-size: 12px; color: var(--text-3); }

.section-title {
  margin: 26px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.list {
  max-width: 980px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.list-row:last-child { border-bottom: 0; }
.list-row .amount { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Horizonte ---------- */

.horizon-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  max-width: 1400px;
}

.horizon-month {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.horizon-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.horizon-head h3 { margin: 0; font-size: 15px; }

.trend {
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
}

.trend.crescendo { color: var(--positive); background: rgba(51, 158, 92, .14); }
.trend.emQueda { color: var(--negative); background: rgba(220, 69, 61, .14); }
.trend.recuperando { color: var(--brand); background: rgba(242, 163, 48, .16); }

.horizon-balances {
  display: flex;
  gap: 22px;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.horizon-balances div { display: flex; flex-direction: column; gap: 2px; }
.horizon-balances b { font-size: 17px; }

.muted { color: var(--text-3); font-size: 12px; font-weight: 400; }

.tone-pos { color: var(--positive); }
.tone-warn { color: var(--warning); }
.tone-neg { color: var(--negative); }

.alert {
  margin-top: 10px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--negative);
  background: rgba(220, 69, 61, .12);
  border-radius: 8px;
}

/* ---------- Folha ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, .45);
  z-index: 20;
}

.sheet {
  width: min(460px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 24px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .35);
}

/* Folha larga pras que listam (fatura, detalhe da tag, detalhamento anual):
   com 460px a linha "descrição … valor" ficava quebrando em duas. */
.sheet-wide { width: min(720px, 100%); }

.sheet h3 { margin: 0 0 16px; font-size: 18px; }

.sheet-message {
  margin: -6px 0 16px;
  font-size: 13px;
  color: var(--text-2);
}

.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }

.sheet-actions button {
  flex: 1;
  padding: 11px;
  font: inherit;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

/* O botão de ação herda a cor do tipo, como no app, onde o `PrimaryActionButton`
   recebe `type.color`. Sem tipo definido, cai na cor da marca. */
.sheet-actions button.primary {
  margin: 0;
  color: #fff;
  background: var(--type-color, var(--brand));
  border-color: transparent;
}

.sheet-actions button.danger {
  margin: 0;
  color: #fff;
  background: var(--negative);
  border-color: transparent;
}

.sheet-actions button:not(:disabled):hover { filter: brightness(1.06); }
.sheet-actions button:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Campo de valor ---------- */

.amount-field {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--line);
}

.amount-field:focus-within { border-bottom-color: var(--type-color, var(--brand)); }

.amount-currency {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-2);
}

.amount-input {
  width: auto;
  min-width: 0;
  flex: 0 1 auto;
  padding: 0;
  font: inherit;
  font-size: 40px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: left;
  color: var(--type-color, var(--text));
  background: none;
  border: 0;
  field-sizing: content;
}

.amount-input:focus { outline: none; }
.amount-input::placeholder { color: var(--text-3); }

/* `field-sizing` ainda não é universal; sem ele o campo usa a largura padrão do
   input, que é larga demais e joga o "R$" pra longe do número. */
@supports not (field-sizing: content) {
  .amount-input { width: 7ch; text-align: center; }
}

.inline-amount { display: inline-flex; align-items: baseline; gap: 6px; }
.inline-amount .amount-currency { font-size: 13px; }

.inline-amount input {
  width: 9ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Seletor de tipo ---------- */

.type-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

.type-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.type-pill:hover { color: var(--text); }

.type-pill.is-active {
  color: #fff;
  background: var(--type-color);
  border-color: transparent;
  font-weight: 600;
}

.type-pill .dot { margin: 0; }
.type-pill.is-active .dot { background: rgba(255, 255, 255, .85); }

/* ---------- Formulário ---------- */

.form-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.content .form-card { max-width: 720px; }

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.form-row:last-child { border-bottom: 0; }
.form-row.is-clickable { cursor: pointer; }
.form-row.is-clickable:hover { background: var(--surface-2); }

.form-label { color: var(--text-2); flex: none; }

.form-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  justify-content: flex-end;
}

/* Dentro do formulário o campo não ocupa a linha inteira: o rótulo fica à
   esquerda e o controle à direita, como nas linhas do app. */
.form-row input[type="text"],
.form-row input[type="search"],
.form-row input[type="date"],
.form-row input[type="number"],
.form-row select {
  width: auto;
  min-width: 150px;
  padding: 7px 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-row input[type="number"] { min-width: 84px; text-align: right; }

.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(242, 163, 48, .25);
}

.form-hint,
.form-note {
  margin: 0;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-3);
  border-bottom: 1px solid var(--line);
}

.form-card > .form-hint:last-child { border-bottom: 0; }

.form-note {
  margin-top: 12px;
  border: 0;
  padding: 0;
  color: var(--text-2);
}

.form-section {
  padding: 14px 14px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.form-section-title {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-2);
}

.form-section p { margin: 0; font-size: 12px; color: var(--text-2); }

.frozen { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Controles ---------- */

.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented button {
  padding: 5px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--text-2);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.segmented button.is-active {
  color: var(--text);
  background: var(--surface);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch span {
  position: absolute;
  inset: 0;
  background: var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s;
}

.switch span::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s;
}

.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(18px); }

.swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  max-width: 360px;
}

.swatch {
  height: 36px;
  font: inherit;
  font-weight: 800;
  color: #fff;
  background: var(--tag-color);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.swatch.is-active { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--tag-color); }

button.compact {
  width: auto;
  margin: 12px 0 0;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

button.primary.compact { color: #fff; background: var(--brand); border-color: transparent; }
button.compact:disabled { opacity: .45; cursor: not-allowed; }

.danger-link {
  padding: 6px 10px;
  font: inherit;
  font-weight: 600;
  color: var(--negative);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.danger-link:hover { background: rgba(220, 69, 61, .12); }
.danger-link.wide { display: block; width: 100%; margin-top: 10px; text-align: center; }

.section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  /* Acompanha a largura das listas: sem o teto, o contador e a seta iam parar
     na outra ponta do monitor, longe do título. */
  max-width: 980px;
  padding: 0;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
}

.section-toggle .section-title { margin-right: auto; }
.chevron { color: var(--text-3); font-size: 12px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 980px;
}

.toolbar .section-title { margin-right: auto; }

.toolbar input[type="search"] {
  width: 200px;
  padding: 7px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.toolbar input[type="search"]:focus { outline: none; border-color: var(--brand); }
.toolbar button.compact { margin: 0; }

.count-hint { margin: 10px 0 0; font-size: 12px; color: var(--text-3); }

.hint-box {
  max-width: 980px;
  padding: 14px 16px;
  color: var(--text-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.list-row.is-clickable { cursor: pointer; }
.list-row.is-clickable:hover { background: var(--surface-2); }

/* ---------- Folha do dia ---------- */

.day-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.day-title { flex: 1; text-align: center; }
.day-title h3 { margin: 0 0 2px; font-size: 16px; }
.day-title span { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

.day-item { border-bottom: 1px solid var(--line); }
.day-item:last-child { border-bottom: 0; }
.day-item .list-row { border-bottom: 0; }
.day-item.is-open { background: var(--surface-2); }

.day-item-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.day-item-meta { display: block; font-size: 12px; color: var(--text-3); }

.day-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
}

.day-actions button {
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.day-actions button:hover { border-color: var(--text-3); }
.day-actions .danger-link { border-color: transparent; background: none; color: var(--negative); }
.day-hint { margin: 0 4px 4px; font-size: 12px; color: var(--text-2); }

/* ---------- Tela de sucesso ---------- */

.success { text-align: center; padding: 16px 4px 4px; }

.success-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  font-size: 34px;
  line-height: 64px;
  color: #fff;
  background: var(--type-color, var(--brand));
  border-radius: 50%;
}

.success h3 { margin: 0 0 8px; }
.success p { margin: 0; font-size: 13px; color: var(--text-2); }

/* ---------- Totais ---------- */

.metrics { max-width: 720px; }

.metric-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.metric-row:last-child { border-bottom: 0; }
.metric-row.is-clickable { cursor: pointer; }
.metric-row.is-clickable:hover { background: var(--surface-2); }
.metric-row > div { display: flex; flex-direction: column; gap: 2px; margin-right: auto; }

.metric-value {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.tone-brand { color: var(--brand); }

.distribution {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
  max-width: 720px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.distribution .list { flex: 1; min-width: 260px; border: 0; }

/* Donut sem biblioteca: um `conic-gradient` com um furo no meio. O texto do
   centro é irmão do anel, não filho — a máscara que abre o furo apagaria
   qualquer conteúdo dentro dele. */
.donut { position: relative; width: 190px; height: 190px; flex: none; }

.donut-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--slices));
  -webkit-mask: radial-gradient(circle, transparent 0 60px, #000 60px);
  mask: radial-gradient(circle, transparent 0 60px, #000 60px);
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
}

.donut-center b { font-size: 19px; font-variant-numeric: tabular-nums; }

.year-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 16px;
}

/* ---------- Faturas ---------- */

.invoice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 980px;
}

.invoice-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.invoice-card.is-plain { border: 0; }

.invoice-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
}

.invoice-card.is-plain .invoice-head { display: none; }
.invoice-head:hover { background: var(--surface-2); }
.invoice-head > div:first-child { display: flex; flex-direction: column; gap: 3px; margin-right: auto; }

.invoice-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}

.pill {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
}

.status-aberta { color: var(--brand); background: rgba(242, 163, 48, .16); }
.status-fechada { color: var(--warning); background: rgba(234, 179, 52, .16); }
.status-vencida { color: var(--negative); background: rgba(220, 69, 61, .14); }
.status-paga { color: var(--positive); background: rgba(51, 158, 92, .14); }

.invoice-body { padding: 0 16px 16px; }
.invoice-body .list { margin-bottom: 10px; }
.paid-note { margin: 8px 0 0; font-size: 12px; color: var(--positive); font-weight: 600; }

.invoice-actions { display: flex; gap: 10px; margin-top: 12px; }

.invoice-actions button {
  flex: 1;
  padding: 9px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.invoice-actions button.primary {
  width: auto;
  margin: 0;
  color: #fff;
  background: var(--positive);
  border-color: transparent;
}

/* ---------- Tags ---------- */

.tag-name { display: flex; align-items: center; gap: 10px; }

.tag-bubble {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--tag-color) 18%, transparent);
}

.tag-bubble.big { width: 52px; height: 52px; font-size: 24px; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--tag-color);
  background: color-mix(in srgb, var(--tag-color) 18%, transparent);
  border-radius: 999px;
}

.tag-header { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.tag-header h3 { margin: 0; }
.tag-header > div { margin-right: auto; }
.tag-total { font-size: 20px; font-variant-numeric: tabular-nums; }

.emoji-input { text-align: center; min-width: 70px !important; font-size: 18px; }

/* ---------- Saldos no celular (lista de dias) ---------- */

.saldo-atual {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.saldo-atual b {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.daycards { display: flex; flex-direction: column; gap: 8px; }

.daycard {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Barra da cor da marca no dia de hoje, igual ao overlay do DayCard no app. */
.daycard.is-hoje::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 0;
  width: 4px;
  border-radius: 0 2px 2px 0;
  background: var(--brand);
}

.daycard-topo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}

.daycard-data {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 42px;
  flex: none;
  line-height: 1.2;
}

.daycard-data b { font-size: 19px; }
.daycard-data .muted { font-size: 11px; text-transform: capitalize; }

.daycard-meio {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-right: auto;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  font-size: 13px;
}

.daycard-badges { display: flex; gap: 5px; }
.daycard-badges .dot { width: 14px; height: 14px; margin: 0; }

.daycard-ghost { display: flex; align-items: center; gap: 6px; color: var(--text-2); }

/* Ponto "fantasma": contorno em vez de preenchimento, pra dizer que é projeção
   e não lançamento real — o mesmo recado do ghostBadge tracejado do app. */
.dot.is-ghost {
  background: none;
  border: 1.5px dashed var(--type-diario);
}

.daycard-saldo {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  flex: none;
  font-variant-numeric: tabular-nums;
}

.daycard-saldo .muted { font-size: 11px; }
.daycard-saldo b { font-size: 15px; }

.daycard-detalhe {
  padding: 0 14px 12px;
  border-top: 1px solid var(--line);
}

.daycard-linha {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.daycard-nota { margin: 0 0 6px; font-size: 12px; color: var(--text-2); }

.daycard-link {
  padding: 4px 0;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  background: none;
  border: 0;
  cursor: pointer;
  margin-left: auto;
  display: block;
}

/* ---------- Celular ---------- */

/* O corte é 860px: abaixo disso a planilha já não mostra um mês inteiro sem
   rolagem horizontal, que é quando ela deixa de compensar. Quem decide é a
   largura da tela, nunca o user-agent (ver o comentário em `app.js`). */
@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  /* A lateral vira a barra de abas de baixo. É a mesma marcação de sempre —
     só o arranjo muda —, então toda a navegação continua ligada onde estava. */
  .sidebar {
    order: 2;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    gap: 2px;
    padding: 6px 4px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .sidebar-brand,
  .sidebar-foot,
  .nav-item[data-view="tags"],
  .nav-item[data-view="faturas"],
  #action-today {
    display: none;
  }

  /* `display: contents` dissolve os dois contêineres e faz os botões virarem
     filhos diretos da barra. Sem isso o `order` abaixo não teria efeito nenhum:
     ele só reordena irmãos do mesmo flex, e o "+" vivia noutro contêiner — foi
     por isso que ele apareceu encostado na ponta em vez de no meio. */
  .nav,
  .nav-actions {
    display: contents;
  }

  /* Quatro abas com o "+" no meio, na ordem do app. */
  .nav-item[data-view="saldos"] { order: 1; }
  .nav-item[data-view="totais"] { order: 2; }
  #action-add { order: 3; }
  .nav-item[data-view="horizonte"] { order: 4; }
  .nav-item[data-view="ajustes"] { order: 5; }

  .nav-item {
    flex-direction: column;
    gap: 2px;
    flex: 1;
    padding: 6px 2px;
    font-size: 11px;
    text-align: center;
    border-radius: 10px;
  }

  .nav-item.is-active { background: none; }
  .nav-icon { width: auto; font-size: 17px; }

  /* O "+" é ação, não aba — por isso vira botão redondo da cor da marca.
     `flex: none` é obrigatório: sem ele o botão herda o `flex: 1` das abas,
     estica junto com elas e o círculo vira elipse. */
  #action-add {
    flex: none;
    width: 46px;
    height: 46px;
    justify-content: center;
    padding: 0;
    font-size: 0;
    color: #fff;
    background: var(--brand);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(242, 163, 48, .4);
  }

  #action-add:hover { background: var(--brand); color: #fff; }
  #action-add .nav-icon { font-size: 24px; }

  .main { order: 1; min-height: 0; }

  .topbar {
    grid-template-columns: auto 1fr;
    gap: 8px;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  .topbar-title { font-size: 16px; }
  .topbar-right { display: none; }
  .period { justify-self: end; gap: 2px; }
  .period-label { min-width: 92px; padding: 4px 8px; font-size: 13px; }
  /* Janela de 12 meses não existe no celular: Saldos anda de mês em mês. */
  #win-prev, #win-next { display: none; }

  .content { padding: 14px; }

  .cards,
  .horizon-list { grid-template-columns: 1fr; }

  .distribution { flex-direction: column; align-items: stretch; gap: 16px; }
  .donut { align-self: center; }
  .distribution .list { min-width: 0; }

  .metric-row { padding: 12px 14px; }
  .metric-value { font-size: 17px; }

  /* A folha vira folha de verdade: sobe de baixo e ocupa a tela. */
  .overlay { padding: 0; align-items: flex-end; }

  .sheet,
  .sheet-wide {
    width: 100%;
    max-height: 92vh;
    padding: 20px 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
  }

  /* Empilha rótulo e campo: lado a lado, em 390px, o campo fica com 100px. */
  .form-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .form-row .form-control { justify-content: flex-start; }

  .form-row input[type="text"],
  .form-row input[type="search"],
  .form-row input[type="date"],
  .form-row select {
    width: 100%;
    min-width: 0;
  }

  .form-row.is-clickable {
    flex-direction: row;
    align-items: center;
  }

  .segmented { width: 100%; }
  .segmented button { flex: 1; }

  .toolbar input[type="search"] { flex: 1; width: auto; }

  .invoice-head { flex-wrap: wrap; }
  .day-actions button { flex: 1; }

  /* 16px é o piso pra o Safari do iPhone não dar zoom sozinho ao focar. */
  .field input,
  .form-row input,
  .form-row select,
  .toolbar input { font-size: 16px; }
}

/* Linha de ação destrutiva dentro de um form-card (hoje: zerar a conta). */
.destructive-row {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--negative);
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

.destructive-row:hover { background: rgba(220, 69, 61, .08); }
.destructive-row span { display: flex; flex-direction: column; gap: 2px; }

.auth-closed {
  margin: 16px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

/* ---------- Gamificação ---------- */

.topbar-right { display: flex; align-items: center; gap: 12px; }

.streak-pill {
  padding: 3px 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  background: var(--surface-2);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.streak-pill.doneToday { color: var(--positive); background: rgba(51, 158, 92, .14); }
.streak-pill.atRisk { color: var(--brand); background: rgba(242, 163, 48, .16); }
.streak-pill.lastChance { color: var(--warning); background: rgba(234, 179, 52, .18); }

/* Card de check-in, no topo de Saldos. */
.checkin-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 980px;
  margin-bottom: 14px;
  padding: 14px 16px;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.checkin-card:hover { border-color: var(--brand); }
.checkin-card.is-feito { cursor: default; color: var(--text-2); font-size: 13px; }
.checkin-card.is-feito:hover { border-color: var(--line); }
.checkin-card span:nth-child(2) { display: flex; flex-direction: column; gap: 2px; margin-right: auto; }
.checkin-card-icone { font-size: 20px; }

/* Folha do check-in. */
.checkin { text-align: center; }
.checkin h3 { margin-bottom: 12px; }

.checkin-barra {
  height: 5px;
  margin-bottom: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.checkin-progresso {
  height: 100%;
  background: var(--type-color, var(--brand));
  border-radius: 999px;
  transition: width .2s;
}

.checkin-passo { margin: 0 0 16px; font-size: 12px; color: var(--text-2); }

.checkin-selo {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--type-color) 15%, transparent);
}

.checkin-selo .dot { width: 30px; height: 30px; margin: 0; }
.checkin-tipo { margin: 0 0 4px; font-weight: 700; color: var(--type-color); }
.checkin-pergunta { margin: 0 0 18px; font-size: 17px; }
.checkin-ok { margin: -8px 0 14px; font-size: 12px; color: var(--positive); font-weight: 600; }

.checkin-aviso {
  margin: 0 0 14px;
  padding: 12px;
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: 10px;
  text-align: left;
}

.checkin-desc {
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 12px;
  font: inherit;
  text-align: center;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.checkin-desc:focus { outline: none; border-color: var(--brand); }
.checkin-dir { margin-bottom: 12px; }
.checkin .primary { width: 100%; margin: 0; }

.checkin-fim .checkin-festa { font-size: 56px; margin-bottom: 8px; }
.checkin-fim p { margin: 0 0 16px; color: var(--text-2); }

.checkin-sequencia {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 4px;
  font-size: 20px;
  font-weight: 800;
}

.checkin-sequencia .muted { font-size: 12px; font-weight: 500; }

/* Folha da sequência. */
.streak-grande {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 22px;
  margin-bottom: 18px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.streak-chama { font-size: 40px; }
.streak-grande b { font-size: 44px; font-weight: 800; line-height: 1; }
.streak-fase { margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--text-2); }
.streak-grande.doneToday .streak-fase { color: var(--positive); }
.streak-grande.atRisk .streak-fase,
.streak-grande.lastChance .streak-fase { color: var(--brand); }

.perdoes { display: flex; gap: 8px; }
.perdao { font-size: 24px; filter: grayscale(1); opacity: .35; }
.perdao.is-cheio { filter: none; opacity: 1; }

/* Conquistas. */
.conquista {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.conquista:last-child { border-bottom: 0; }
.conquista-icone { font-size: 22px; filter: grayscale(1); opacity: .4; }
.conquista.is-feita .conquista-icone { filter: none; opacity: 1; }
.conquista-texto { display: flex; flex-direction: column; gap: 2px; margin-right: auto; min-width: 0; }
.conquista-texto .muted { font-size: 12px; }

.conquista-barra {
  height: 4px;
  margin-top: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.conquista-barra span { display: block; height: 100%; background: var(--brand); }
.conquista-marca { font-size: 14px; font-weight: 700; color: var(--text-3); }
.conquista.is-feita .conquista-marca { color: var(--positive); }

/* Comemoração. */
.comemoracao { text-align: center; padding: 12px 4px 4px; }
.comemoracao-icone { font-size: 60px; margin-bottom: 10px; }

.comemoracao-tag {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--brand);
}

.comemoracao h3 { margin: 0 0 6px; }
.comemoracao p { margin: 0 0 4px; font-size: 13px; color: var(--text-2); }
