/* A largura do cartão determina a composição das suas linhas. */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}
.panel-stack { display: grid; min-width: 0; gap: 16px; align-content: start; }
.panel { min-width: 0; container-type: inline-size; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 8px 12px; }
.panel-head > div:first-child { flex: 1 1 12rem; min-width: 0; }
.panel-head .pill { flex: 0 0 auto; max-width: 100%; white-space: normal; }
.panel h2 { line-height: 1.35; }
.hint { line-height: 1.55; }
.benefit-person h3, .benefit-shared h3 { line-height: 1.4; }

/* Uma só grade para itens padrão e itens adicionais. */
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 10px 12px;
  min-width: 0;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.45;
}
.row:last-child { border-bottom: 0; }
.row > * { min-width: 0; }
.row.editable-row, .row.custom-row {
  grid-template-columns: minmax(0, 1fr) 44px 44px;
  grid-template-rows: auto auto;
}
.base-label-wrap, .custom-name-wrap { grid-column: 1 / -1; grid-row: 1; position: relative; display: block; min-width: 0; }
.base-label-input, .custom-name-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 10px 30px 10px 10px;
  border: 1px dashed var(--accent-ring);
  border-radius: 8px;
  background: rgba(255, 138, 42, .045);
  color: var(--ink);
  font: inherit;
  line-height: 1.45;
  text-align: left;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
  resize: none;
  overflow: hidden;
}
.base-label-wrap::after, .custom-name-wrap::after {
  content: "✎";
  position: absolute;
  top: 12px;
  right: 9px;
  color: var(--accent-2);
  font-size: 13px;
  line-height: 20px;
  pointer-events: none;
}
.custom-name-wrap small { display: block; margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.custom-owner-input {
  display: block;
  width: auto;
  max-width: 100%;
  min-width: 0;
  min-height: 44px;
  margin-top: 6px;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, .18);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
}
.row .currency-edit-wrap {
  grid-column: 1;
  grid-row: 2;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 5px;
  width: min(100%, 11rem);
  min-width: 0;
  min-height: 44px;
  padding: 0 9px;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, .25);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.currency-edit-wrap > span { flex: 0 0 auto; }
.currency-edit-wrap .row-currency-input {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 8px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.currency-edit-wrap .row-currency-input:focus-visible { outline: none; }
.currency-edit-wrap:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.row .check-cell {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  place-items: center;
  width: 44px;
  min-height: 44px;
  margin: 0;
  cursor: pointer;
}
.item-remove, .delete {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  color: var(--muted);
  cursor: pointer;
  transition: background .16s, color .16s;
}
.row .item-remove { grid-column: 3; grid-row: 2; justify-self: center; }
.item-remove:hover, .delete:hover { background: rgba(255, 107, 94, .14); color: var(--danger); }
.row:has(.base-check:checked), .row:has(.custom-check:checked) { opacity: .88; }
.check-cell input, .tx-check {
  --check-size: 22px;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: block;
  box-sizing: border-box;
  flex: 0 0 var(--check-size);
  width: var(--check-size);
  min-width: var(--check-size);
  height: var(--check-size);
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, .42);
  border-radius: 50%;
  background: rgba(0, 0, 0, .15);
  cursor: pointer;
}
.check-cell input[data-tone="income"]:checked, .tx-check[data-tone="income"]:checked { border-color: #58d68d; background: #2eaf61; box-shadow: 0 0 12px rgba(46, 175, 97, .4); }
.check-cell input[data-tone="expense"]:checked, .tx-check[data-tone="expense"]:checked { border-color: var(--danger); background: var(--danger); box-shadow: 0 0 12px rgba(255, 107, 94, .4); }
.check-cell input:checked::after, .tx-check:checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 47%;
  width: 5px;
  height: 9px;
  border-right: 2px solid #1a0f05;
  border-bottom: 2px solid #1a0f05;
  transform: translate(-50%, -58%) rotate(45deg);
  box-sizing: content-box;
}
.base-label-input:focus-visible, .custom-name-input:focus-visible, .custom-owner-input:focus-visible, .tx-edit:focus-visible, .check-cell input:focus-visible, .tx-check:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.inline-total { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; color: var(--accent-2); }
.total-row { font-weight: 650; color: var(--ink); border-top: 1px solid var(--line); margin-top: 5px; padding-top: 14px; }
/* Preserva os centavos em cartões aninhados nas menores telas. */
@container (max-width: 18rem) {
  .row.editable-row, .row.custom-row, .transaction { column-gap: 8px; }
}

/* As quatro colunas só são usadas quando o cartão tem espaço para elas. */
@container (min-width: 32rem) {
  .row.editable-row, .row.custom-row { grid-template-columns: minmax(0, 1fr) 11rem 44px 44px; grid-template-rows: auto; }
  .base-label-wrap, .custom-name-wrap { grid-column: 1; grid-row: 1; }
  .row .currency-edit-wrap { grid-column: 2; grid-row: 1; width: 100%; }
  .row .check-cell { grid-column: 3; grid-row: 1; }
  .row .item-remove { grid-column: 4; grid-row: 1; }
}

/* A mesma prioridade de descrição, valor e ações nas movimentações. */
.transactions { list-style: none; margin: 0; padding: 0; }
.transaction { display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px; gap: 10px 12px; min-width: 0; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.transaction:last-child { border-bottom: 0; }
.transaction.done { opacity: .88; }
.transaction > div:first-child { grid-column: 1 / -1; grid-row: 1; min-width: 0; }
.tx-description-input { display: block; width: 100%; min-width: 0; min-height: 44px; padding: 10px; border: 0; border-radius: 8px; background: rgba(0, 0, 0, .18); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); color: var(--ink); font: inherit; font-weight: 600; line-height: 1.45; resize: none; overflow: hidden; }
.tx-title, .tx-meta, .note, .hint { word-break: normal; overflow-wrap: break-word; }
.tx-title { font-weight: 600; }
.tx-meta { font-size: 12px; color: var(--muted); margin-top: 5px; }
.tx-check-wrap { grid-column: 2; grid-row: 2; display: grid; place-items: center; width: 44px; min-height: 44px; cursor: pointer; }
.tx-value { grid-column: 1; grid-row: 2; justify-self: end; display: flex; align-items: center; gap: 5px; min-width: 0; max-width: 100%; min-height: 44px; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-value.income { color: var(--ink); }
.tx-value.expense { color: var(--muted); }
.tx-amount-input { width: 8rem; min-width: 0; max-width: 100%; min-height: 44px; border: 0; border-radius: 7px; padding: 7px; background: rgba(0, 0, 0, .2); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); color: inherit; font: inherit; font-variant-numeric: tabular-nums; text-align: right; }
.transaction .delete { grid-column: 3; grid-row: 2; }
@container (min-width: 32rem) {
  .transaction { grid-template-columns: minmax(0, 1fr) 11rem 44px 44px; }
  .transaction > div:first-child { grid-column: 1; }
  .tx-value { grid-column: 2; grid-row: 1; }
  .tx-check-wrap { grid-column: 3; grid-row: 1; }
  .transaction .delete { grid-column: 4; grid-row: 1; }
}
.add-item-form, .add-item-form > label { min-width: 0; }
.add-item-form { grid-template-columns: minmax(0, 1fr); }
.add-item-form input, .add-item-form select { min-width: 0; min-height: 44px; }
.add-item summary { min-height: 44px; line-height: 1.45; }
.pluggy-status { min-width: 0; }
.data-actions .secondary { min-width: min(100%, 170px); max-width: 100%; }
.hero-meta > div { min-width: 0; }
@media (max-width: 47.999rem) {
  .hero-meta > div:last-child { flex-wrap: wrap; }
}
/* 2 × 350px de cartão + espaçamento e margens; abaixo disso, uma coluna. */
@media (min-width: 48rem) and (max-width: 71.999rem) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
  .grid > .panel-stack { display: contents; }
  .grid > .panel-stack:nth-child(2) > section.panel:first-child { grid-column: 1 / -1; grid-row: 2; }
  .grid > .panel-stack:nth-child(2) > section.panel:last-child { grid-column: 1; grid-row: 3; }
  .grid > .panel-stack:nth-child(3) > section.panel { grid-column: 2; grid-row: 3; }
}
/* Três grupos cabem com cerca de 350px por cartão a partir de 1152px. */
@media (min-width: 72rem) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Cadastro mensal usa a mesma superfície de vidro e os controles existentes. */
.expense-add { display:flex; align-items:center; gap:8px; min-height:44px; width:100%; padding:8px 0; border:0; background:transparent; color:var(--accent-2); font:inherit; font-weight:650; text-align:left; cursor:pointer; }
.expense-add span { font-size:24px; }
.expense-dialog { position:fixed; inset:0; margin:auto; box-sizing:border-box; width:min(520px,calc(100% - 24px)); max-height:calc(100dvh - 24px); overflow-y:auto; overflow-x:hidden; }
.expense-dialog[open] { display:block; }
.expense-dialog h2 { font-size:22px; }
.expense-form { display:grid; grid-template-columns:minmax(0,1fr); gap:14px; }
.expense-form > label, .expense-form > div > label, .expense-dialog #expense-login label { display:grid; gap:6px; min-width:0; color:var(--muted); font-size:14px; line-height:1.5; }
.expense-form input:not([type=checkbox]):not([type=radio]), .expense-form select { box-sizing:border-box; width:100%; max-width:100%; min-width:0; min-height:44px; padding:10px 12px; border:1px solid var(--line); border-radius:10px; background:#202023; color:var(--ink); font:inherit; }
.expense-form fieldset { min-width:0; margin:0; padding:10px; border:1px solid var(--line); border-radius:12px; }
.expense-form legend { color:var(--muted); font-size:14px; padding:0 4px; }
.expense-form .frequency-choice { display:flex; align-items:center; gap:10px; min-height:44px; padding:8px; border:1px solid transparent; border-radius:8px; cursor:pointer; }
.frequency-choice:has(:checked) { background:rgba(255,138,42,.12); border-color:var(--accent)!important; color:var(--accent-2); }
.expense-form input[type=radio], .expense-form input[type=checkbox] { flex:0 0 20px; width:20px; height:20px; margin:0; accent-color:var(--accent); }
.expense-form .expense-confirm { display:flex; align-items:center; gap:10px; min-height:44px; }
.expense-dialog [hidden] { display:none!important; }
.expense-dialog-actions { display:flex; flex-wrap:wrap; gap:12px; justify-content:center; }
.expense-dialog-actions button { flex:1 1 160px; min-height:44px; max-width:100%; }
.expense-dialog button:disabled { opacity:.5; cursor:wait; }
.expense-dialog :focus-visible, .expense-add:focus-visible, .recurrence-manage:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.expense-form .hint { margin:0; }
#expense-import { margin-top:18px; border-top:1px solid var(--line); padding-top:12px; }
#expense-import summary { min-height:44px; cursor:pointer; color:var(--muted); line-height:1.5; }
.recurrence-manage { display:block; margin-top:6px; min-height:44px; max-width:100%; padding:7px 8px; border:1px solid var(--line); border-radius:8px; background:rgba(255,138,42,.06); color:var(--accent-2); font:inherit; font-size:12px; cursor:pointer; text-align:left; }
.expense-status { margin:0 0 16px; }
.expense-status:empty { display:none; }

.balance-explanation{font-size:12px;color:var(--muted);line-height:1.5;margin:0 0 12px;overflow-wrap:break-word}
.month-closing{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px;margin-bottom:12px;font-size:12px;color:var(--muted)}
.month-closing .secondary{min-height:44px;font-size:12px;padding:8px 12px}
.month-closing button:disabled{opacity:.5;cursor:default}

#sync-badge{white-space:normal;max-width:260px;line-height:1.4}#sync-dialog .add-item-form{grid-template-columns:minmax(0,1fr)}
