/* =========================================================================
   Poupa Money - Design System
   ========================================================================= */

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #0ea5e9;

  --bg: #f4f5fb;
  --bg-elevated: #ffffff;
  --bg-soft: #eef0fb;
  --border: #e4e6f1;
  --text: #1e2130;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;

  --sidebar-bg: #14162b;
  --sidebar-text: #b8bad3;
  --sidebar-active: #6366f1;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 43, 0.06);
  --shadow-md: 0 6px 20px rgba(20, 22, 43, 0.08);
  --shadow-lg: 0 16px 40px rgba(20, 22, 43, 0.14);
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-width: 260px;
  --sidebar-width-collapsed: 76px;
  --topbar-height: 72px;
  --topbar-height-mobile: 64px;
}

:root[data-theme='dark'] {
  --bg: #0f1120;
  --bg-elevated: #171a2e;
  --bg-soft: #1d2038;
  --border: #2a2d47;
  --text: #eef0fb;
  --text-muted: #a2a5c4;
  --text-faint: #6f7295;

  --sidebar-bg: #0b0c1a;
  --sidebar-text: #9698bd;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1120;
    --bg-elevated: #171a2e;
    --bg-soft: #1d2038;
    --border: #2a2d47;
    --text: #eef0fb;
    --text-muted: #a2a5c4;
    --text-faint: #6f7295;
    --sidebar-bg: #0b0c1a;
    --sidebar-text: #9698bd;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; touch-action: manipulation; }
input, select, textarea { font-family: inherit; }
a, button, .btn, .btn-icon, .icon-btn { touch-action: manipulation; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* =========================================================================
   Layout
   ========================================================================= */
.app-layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  transition: width var(--transition);
  z-index: 40;
}

.sidebar.collapsed { width: var(--sidebar-width-collapsed); }

.sidebar.collapsed .label { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar.collapsed .sidebar-nav a { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar.collapsed .sidebar-toggle { display: flex; align-items: center; justify-content: center; gap: 0; }
.sidebar.collapsed .sidebar-toggle .icon { font-size: 1.1rem; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 24px;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-brand .logo-dot {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-nav { flex: 1; overflow-y: auto; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
}

.sidebar-nav a .icon { font-size: 1.15rem; width: 22px; text-align: center; flex-shrink: 0; }

.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

.sidebar-nav a.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 14px;
  margin-top: 10px;
}

.sidebar-toggle {
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: var(--sidebar-text);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-toggle:hover { background: rgba(255, 255, 255, 0.12); }

.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 30;
  gap: 16px;
}

.topbar-search {
  flex: 1;
  max-width: 420px;
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-search-bar {
  position: relative;
  flex: 1;
  min-width: 0;
}

.topbar-search input {
  width: 100%;
  padding: 10px 38px 10px 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.9rem;
}

.topbar-search .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
}

.mobile-search-close {
  display: none;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  color: var(--text);
  cursor: pointer;
}

/* Toggle de escopo (Este mes / Todos os meses): no desktop fica ao lado do
   campo de busca (nao empilhado embaixo), e so aparece enquanto a busca
   esta em uso - fora disso ficava sempre visivel empurrando a altura da
   topbar (o botao "comia" a linha debaixo dela). */
.search-scope-toggle { display: none; gap: 4px; flex-shrink: 0; }
.search-scope-toggle.show { display: flex; }
.search-scope-toggle button {
  padding: 7px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}
.search-scope-toggle button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.topbar-search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 340px;
  overflow-y: auto;
  display: none;
}

.topbar-search-results.show { display: block; }

.topbar-search-results .result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
  cursor: default;
}
/* Titulo do resultado (1o span): sem min-width:0 + overflow-wrap, uma
   palavra unica muito comprida no titulo nao encolhia e sobrepunha o
   valor a direita. */
.topbar-search-results .result-item > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.topbar-search-results .result-item:last-child { border-bottom: none; }
.topbar-search-results .result-item[data-id]:hover,
.topbar-search-results .result-item[data-id]:active { background: var(--bg-soft); }

.topbar-actions { display: flex; align-items: center; gap: 14px; }

.topbar-brand {
  display: none;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

.topbar-brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.05rem;
  transition: background var(--transition), transform var(--transition);
}

.icon-btn:hover { background: var(--border); }
.icon-btn:active { transform: scale(0.94); }

#mobile-menu-btn { display: none; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  overflow: hidden;
  flex-shrink: 0;
}

.user-avatar.is-pig { background: none; }
.user-avatar svg { width: 100%; height: 100%; }

.user-chip .user-name { font-size: 0.85rem; font-weight: 600; }

.avatar-editor-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0 4px;
}
.avatar-editor-preview svg { width: 108px; height: 108px; }

.page-content {
  padding: 28px;
  flex: 1;
  animation: fadeIn 240ms ease;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header h1 { font-size: 1.5rem; margin: 0 0 4px; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

/* Sem isso, o botao do cabecalho ficava lado a lado com o titulo ou quebrava
   pra baixo dependendo so do tamanho do texto de cada pagina (titulo/
   subtitulo/rotulo do botao) - Entradas e Saidas, por exemplo, acabavam com
   o botao em posicoes diferentes por puro acaso de quantos caracteres cada
   texto tinha. Empilhar sempre no mobile garante o mesmo layout em toda
   pagina, independente do texto. O Dashboard tem seu proprio layout mobile
   (regra acima, mais especifica) e fica de fora disso. */
@media (max-width: 720px) {
  body:not([data-page="dashboard"]) .page-header {
    flex-direction: column;
    align-items: stretch;
  }
  body:not([data-page="dashboard"]) .page-header > *:last-child {
    width: 100%;
  }
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  box-shadow: var(--shadow-sm);
}
.month-nav .btn-icon { width: 30px; height: 30px; border: none; background: transparent; font-size: 1.1rem; }

@media (max-width: 960px) {
  .grid-dashboard-orcamento { grid-template-columns: 1fr !important; }

  /* Dashboard mobile: titulo "Orcamento" fica na mesma linha do seletor de
     mes, alinhado a direita - no desktop essas duas linhas ficam empilhadas
     a esquerda, sem alteracao. */
  body[data-page="dashboard"] .page-header {
    align-items: center;
    gap: 8px;
  }
  body[data-page="dashboard"] .page-header > div:first-child {
    display: contents;
  }
  body[data-page="dashboard"] .page-header h1 {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1.2rem;
  }
  body[data-page="dashboard"] .month-nav {
    flex-shrink: 0;
  }
  body[data-page="dashboard"] #mes-label {
    min-width: 96px !important;
    font-size: 0.78rem;
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   Botoes
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: var(--shadow-md); }

.btn-secondary { background: var(--bg-soft); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-block { width: 100%; white-space: normal; text-align: center; line-height: 1.35; }
.btn-block-left { text-align: left; justify-content: flex-start; }
/* display:flex proprio: .btn-icon nao herda do .btn (e usado sozinho, sem
   a classe .btn junto), entao nunca teve centralizacao de verdade - um
   emoji de texto ficava centralizado mais por sorte da linha de base do que
   por regra, e um SVG (sem baseline de texto) escancarava isso. */
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border-radius: var(--radius-sm); background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); }
.btn-icon:hover { background: var(--border); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* =========================================================================
   Cards
   ========================================================================= */
.grid {
  display: grid;
  gap: 20px;
}

.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 1200px) { .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .grid-cols-4, .grid-cols-3, .grid-cols-2 { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
  min-width: 0;
}

.card:hover { box-shadow: var(--shadow-md); }

.card canvas { display: block; width: 100%; }

.stat-card { display: flex; flex-direction: column; gap: 10px; }

.stat-card .stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card .stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: #fff;
}

.stat-icon.bg-primary { background: linear-gradient(135deg, var(--primary), #a855f7); }
.stat-icon.bg-success { background: linear-gradient(135deg, #22c55e, #16a34a); }
.stat-icon.bg-danger { background: linear-gradient(135deg, #ef4444, #dc2626); }
.stat-icon.bg-info { background: linear-gradient(135deg, #0ea5e9, #0284c7); }
.stat-icon.bg-warning { background: linear-gradient(135deg, #f59e0b, #d97706); }

.stat-card .stat-label { color: var(--text-muted); font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-card .stat-value.positive { color: var(--success); }
.stat-card .stat-value.negative { color: var(--danger); }

.stat-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.stat-badge.up { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.stat-badge.down { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title-row h3 { margin: 0; font-size: 1.02rem; }
.card-title-row .muted { color: var(--text-muted); font-size: 0.8rem; }

/* =========================================================================
   Lista de opcoes de configuracoes: cada linha abre um modal proprio, em vez
   de empilhar todos os formularios soltos na tela ao mesmo tempo.
   ========================================================================= */
.settings-list { display: flex; flex-direction: column; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 6px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.settings-row:last-child { border-bottom: none; }
.settings-row:hover { background: var(--bg-soft); }

.settings-row-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
  background: var(--bg-soft);
}

.settings-row-body { flex: 1; min-width: 0; }
.settings-row-title { font-weight: 600; font-size: 0.92rem; }
.settings-row-desc { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.settings-row-chevron { color: var(--text-faint); font-size: 1.3rem; flex-shrink: 0; }

.settings-row.danger .settings-row-icon { background: color-mix(in srgb, var(--danger) 15%, transparent); }
.settings-row.danger .settings-row-title { color: var(--danger); }

/* =========================================================================
   Cartao de plano (Assinatura): preco em destaque + lista compacta de
   beneficios com check, em vez de bullets padrao do navegador.
   ========================================================================= */
.price-tag {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 14px 18px;
  margin-bottom: 14px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
}
.price-tag .price-value { font-size: 2rem; font-weight: 800; color: var(--primary); }
.price-tag .price-period { font-size: 0.9rem; color: var(--text-muted); }

.feature-list { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.feature-list li { display: flex; align-items: flex-start; gap: 9px; font-size: 0.85rem; }
.feature-list .check { color: var(--success); flex-shrink: 0; font-weight: 700; }

/* Botao de expandir/ocultar secoes de lista: so aparece no mobile, onde
   a lista comeca recolhida para reduzir a rolagem inicial da pagina. */
.btn-toggle-lista { display: none; }
.lista-colapsavel.oculto { display: none; }
@media (max-width: 720px) {
  .btn-toggle-lista { display: inline-flex; }
}

/* =========================================================================
   Tabelas
   ========================================================================= */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.87rem; background: var(--bg-elevated); }

table.data-table th {
  text-align: left;
  padding: 13px 16px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table th.text-right { text-align: right; }
table.data-table th.text-center { text-align: center; }

table.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data-table tbody tr { transition: background var(--transition); }
table.data-table tbody tr:hover { background: var(--bg-soft); }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tfoot tr td { border-top: 1px solid var(--border); border-bottom: none; }

.text-success { color: var(--success); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-muted { color: var(--text-muted); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Nome de categoria com bolinha de cor: agrupa os dois num unico item para
   a bolinha ficar sempre centralizada com o texto, mesmo dentro de celulas
   de tabela que viram flex/grid no mobile. */
.cat-nome-cell { display: inline-flex; align-items: center; gap: 6px; }

.table-actions { display: flex; gap: 8px; justify-content: flex-end; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .emoji { font-size: 2.6rem; margin-bottom: 12px; }

/* =========================================================================
   Abas (tabs) reutilizaveis
   ========================================================================= */
.tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tabs button {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}
.tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* =========================================================================
   Paleta de cores rapida (categorias, metas)
   ========================================================================= */
.color-swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
}
.color-swatch:active { transform: scale(0.9); }
.color-swatch.selected { box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--text); }

/* =========================================================================
   Filtros / Toolbar
   ========================================================================= */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.toolbar .field { flex: 1; min-width: 160px; }

.field label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }

.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.87rem;
  transition: border var(--transition);
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Codigo "copia e cola" do PIX: mesma casca visual dos inputs do resto do
   site (sem isso, o textarea cai no estilo padrao branco do navegador e
   destoa completamente do card escuro ao redor). */
.pix-code-box {
  width: 100%;
  margin-top: 14px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  height: 80px;
  resize: none;
  transition: border var(--transition);
}
.pix-code-box:focus { outline: none; border-color: var(--primary); }

.phone-field { display: flex; gap: 8px; position: relative; }
.phone-field select { width: auto; flex-shrink: 0; }
.phone-field input { flex: 1; min-width: 0; }

/* Combobox pesquisavel de pais (cadastro): troca o <select> nativo (que so
   mostra sigla/DDI e nao da pra pesquisar) por um botao + dropdown com
   busca, mantendo o mesmo espaco reservado do antigo select. */
.country-select { position: relative; flex-shrink: 0; }
.country-select-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 10px 10px 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.87rem;
  cursor: pointer;
  white-space: nowrap;
}
.country-select-trigger:hover, .country-select-trigger:focus { outline: none; border-color: var(--primary); }
.country-select-caret { font-size: 0.65rem; color: var(--text-muted); margin-left: 2px; }

.country-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  padding: 10px;
}
.country-search {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 8px;
}
.country-search:focus { outline: none; border-color: var(--primary); }
.country-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; }
.country-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.84rem;
  text-align: left;
  cursor: pointer;
}
.country-option:hover, .country-option:focus { background: var(--bg-soft); outline: none; }
.country-option-flag { font-size: 1.1rem; flex-shrink: 0; }
.country-option-nome { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.country-option-ddi { color: var(--text-muted); font-size: 0.78rem; flex-shrink: 0; }
.country-empty { padding: 10px; text-align: center; color: var(--text-muted); font-size: 0.82rem; }

.field textarea { resize: vertical; min-height: 70px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* =========================================================================
   Modais
   ========================================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 20, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  animation: overlayIn 180ms ease forwards;
  padding: 20px;
}

@keyframes overlayIn { to { opacity: 1; } }

.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(14px) scale(0.98);
  opacity: 0;
  animation: modalIn 220ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalIn { to { transform: translateY(0) scale(1); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); line-height: 1; }

.modal-body { padding: 22px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { padding: 16px 24px 22px; display: flex; justify-content: flex-end; gap: 10px; }

.modal-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-form-grid .span-2 { grid-column: span 2; }

@media (max-width: 560px) { .modal-form-grid { grid-template-columns: 1fr; } .modal-form-grid .span-2 { grid-column: span 1; } }

/* =========================================================================
   Toasts
   ========================================================================= */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
}

.toast {
  min-width: 260px;
  max-width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
  font-size: 0.86rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toastIn 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

/* No celular o toast ocupa a largura da tela, abaixo da area do relogio/notch */
@media (max-width: 560px) {
  #toast-container {
    left: 14px;
    right: 14px;
    top: calc(12px + env(safe-area-inset-top));
  }
  .toast { min-width: 0; max-width: none; width: 100%; }
}

@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

/* =========================================================================
   Progresso / Metas
   ========================================================================= */
.progress-bar { width: 100%; height: 10px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--primary-light)); transition: width 400ms ease; }

.meta-card { display: flex; flex-direction: column; gap: 12px; }
.meta-card .meta-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
/* Bloco do titulo (1o filho): sem min-width:0 uma palavra unica muito
   comprida no titulo da meta nao encolhia e sobrepunha os botoes de
   editar/excluir ao lado. */
.meta-card .meta-top > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.meta-card .meta-values { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-muted); }
.meta-card .meta-percent { font-size: 1.3rem; font-weight: 700; }

/* Linha secundaria dos cards de estatistica (ex.: total acumulado de investimentos) */
.stat-card .stat-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.stat-card .stat-sub strong { color: var(--info); font-weight: 700; }

/* Card compacto de metas no dashboard */
.dash-metas-lista { display: flex; flex-direction: column; gap: 18px; max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-right: 4px; }
.dash-metas-lista .empty-state { padding: 10px 0; }
.dash-metas-lista .empty-state .emoji { font-size: 1.8rem; margin-bottom: 6px; }

.dash-meta-item .dash-meta-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-size: 0.85rem; }
.dash-meta-item .dash-meta-head .dash-meta-titulo {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Sem min-width:0 o item flex nao encolhia abaixo do tamanho do texto
     (um titulo comprido furava a caixa e sobrepunha o percentual ao lado)
     - o ellipsis so funciona de fato com isso aqui. */
  min-width: 0;
}
.dash-meta-item .dash-meta-head .dash-meta-percent { font-weight: 700; font-size: 0.8rem; flex-shrink: 0; }
.dash-meta-item .progress-bar { height: 6px; }
.dash-meta-item .dash-meta-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: 0.76rem; color: var(--text-muted); }

.dash-meta-add {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 32px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), transform var(--transition);
}
.dash-meta-add:hover { background: var(--border); }
.dash-meta-add:active { transform: scale(0.96); }

/* =========================================================================
   Login / Registro
   ========================================================================= */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top left, #6366f1 0%, #14162b 55%);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  animation: fadeIn 300ms ease;
}

.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand .logo-dot { width: 44px; height: 44px; border-radius: 12px; object-fit: cover; }
.auth-brand span { font-weight: 700; font-size: 1.25rem; }

.auth-card h2 { margin: 0 0 6px; font-size: 1.4rem; }
.auth-card .subtitle { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 24px; }

.auth-footer { margin-top: 20px; text-align: center; font-size: 0.86rem; color: var(--text-muted); }
.auth-footer a { color: var(--primary); font-weight: 600; }

.form-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  display: none;
}

.form-error.show { display: block; }

/* =========================================================================
   Utilidades
   ========================================================================= */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.w-full { width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--bg-soft) 25%, var(--border) 50%, var(--bg-soft) 75%);
  background-size: 200% 100%;
  animation: skeletonLoad 1.4s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeletonLoad { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 18px; }
.pagination button {
  min-width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* =========================================================================
   Bottom navigation (mobile)
   ========================================================================= */
.bottom-nav { display: none; }

@media (max-width: 960px) {
  .bottom-nav {
    display: flex;
    align-items: stretch;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(20, 22, 43, 0.08);
    z-index: 100;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }

  .bottom-nav a, .bottom-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 7px 2px 6px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 0.66rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
  }

  .bottom-nav .icon {
    font-size: 1.3rem;
    line-height: 1;
    padding: 3px 14px;
    border-radius: 999px;
    transition: background var(--transition);
  }
  .bottom-nav a.active, .bottom-nav button.active { color: var(--primary); }
  .bottom-nav a.active .icon, .bottom-nav button.active .icon {
    background: color-mix(in srgb, var(--primary) 16%, transparent);
  }
  .bottom-nav a:active, .bottom-nav button:active { background: var(--bg-soft); }
}

/* Mobile sidebar (acessivel via botao "Mais" da bottom nav) */
@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;
    width: min(300px, 82vw);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .sidebar.collapsed { width: min(300px, 82vw); }
  .sidebar.collapsed .label { display: inline; }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-footer { display: none; }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 39;
    display: none;
  }
  .sidebar-backdrop.show { display: block; }

  .page-content {
    padding: calc(var(--topbar-height-mobile) + env(safe-area-inset-top) + 16px) 16px calc(88px + env(safe-area-inset-bottom));
  }
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 30;
    padding: env(safe-area-inset-top) 14px 0;
    height: calc(var(--topbar-height-mobile) + env(safe-area-inset-top));
    min-height: 0;
  }
  #mobile-menu-btn { display: none; }
  .topbar-brand { display: flex; }
  .topbar-search { display: none; }

  /* Busca em tela cheia: blur no conteudo atras em vez de cobrir com fundo solido */
  body.mobile-search-active .topbar-search {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
    max-width: none;
  }
  body.mobile-search-active .topbar-search-bar input {
    font-size: 16px;
    padding: 13px 44px;
    background: var(--bg-elevated);
    box-shadow: var(--shadow-lg);
  }
  body.mobile-search-active .mobile-search-close { display: flex; align-items: center; justify-content: center; }
  /* No desktop o toggle fica ao lado do campo, mas na tela cheia do mobile
     ele volta a ficar embaixo (empilhado) e sempre visivel assim que a
     busca abre - o campo ja recebe foco no clique do icone de lupa, mas
     forcamos aqui tambem pra nao depender so do timing do evento de foco. */
  body.mobile-search-active .search-scope-toggle {
    display: flex;
    margin-top: 16px;
  }
  body.mobile-search-active .topbar-search-results {
    position: static;
    display: block;
    margin-top: 16px;
    max-height: none;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    overflow: hidden;
  }
  .mobile-search-btn { display: flex; }

  /* Alvos de toque maiores */
  .btn-icon { width: 42px; height: 42px; }
  .icon-btn { width: 44px; height: 44px; }
  .pagination button { min-width: 40px; height: 40px; }
  .dash-meta-add { min-height: 40px; padding: 8px 16px; font-size: 0.82rem; }

  /* No mobile a pagina inteira rola, entao a lista de metas nao precisa de
     scroll interno (scroll aninhado atrapalha o toque) */
  .dash-metas-lista { max-height: none; overflow-y: visible; padding-right: 0; }

  .user-chip .user-name { display: none; }
  .user-chip { padding: 3px; }
  .topbar-actions { gap: 8px; }

  /* Evita zoom automatico do iOS ao focar campos (fonte < 16px dispara zoom) */
  .field input, .field select, .field textarea,
  .toolbar input, .toolbar select { font-size: 16px; }

  /* Modais viram bottom-sheet */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none;
    width: 100%;
    max-height: 92dvh;
    max-height: 92vh;
    border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(100%);
    animation: modalSheetIn 260ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }
  @keyframes modalSheetIn { to { transform: translateY(0); opacity: 1; } }
  .modal-form-grid { grid-template-columns: 1fr; }
  .modal-form-grid .span-2 { grid-column: span 1; }

  /* Tabs de relatorio rolam na horizontal em vez de quebrar linha */
  .report-tabs, .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .report-tabs button, .tabs button { flex-shrink: 0; }

  .auth-card { padding: 30px 22px; }
  .auth-page { padding: 0; align-items: stretch; }
  .auth-card { border-radius: 0; max-width: none; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; }
}

@media (max-width: 720px) {
  /* Tabelas de dados viram cartoes empilhados */
  table.data-table thead { display: none; }
  table.data-table, table.data-table tbody, table.data-table tr, table.data-table td {
    display: block;
    width: 100%;
  }
  table.data-table { background: transparent; }
  table.data-table tr {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    padding: 6px 4px;
  }
  table.data-table tr:last-child { margin-bottom: 0; }
  table.data-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    text-align: right;
  }
  table.data-table td:last-child { border-bottom: none; }
  table.data-table td[data-label]::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }
  table.data-table td .table-actions { justify-content: flex-end; width: 100%; }
  .table-wrap { border: none; overflow-x: visible; }

  /* Espaco entre a ultima linha-cartao e o rodape de total (cada um e
     "ultimo filho" do seu proprio pai - tbody/tfoot - entao os dois zeram
     a propria margem e ficam colados sem essa regra). Nao vale para as
     tabelas de lista compacta, que ja usam borda continua sem gaps. */
  table.data-table:not(.tabela-compacta) tfoot tr { margin-top: 10px; }

  /* Filtros de Receitas/Despesas/Investimentos: grid fixo de 2 colunas em
     vez do flex-wrap automatico. O flex-wrap decidia se Categoria/Mes
     cabiam lado a lado com base na largura ja renderizada, e essa largura
     mudava assim que o JS preenchia o valor do mes logo apos o primeiro
     desenho da tela - dava a impressao de o campo "pular" de lugar. */
  body[data-page="receitas"] .toolbar,
  body[data-page="despesas"] .toolbar,
  body[data-page="investimentos"] .toolbar {
    display: grid;
    /* minmax(0, 1fr) e nao só "1fr" (que já equivale a minmax(auto,1fr)):
       "auto" deixaria a coluna nunca menor que o conteúdo do item, e no
       Safari/iOS o controle nativo do <input type="month"> tem uma largura
       mínima de conteúdo maior que no Chrome/Android - por isso o campo Mês
       só "vazava" para fora do cartão no iPhone, nunca no Android, mesmo
       com o mesmo CSS. */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
  }
  body[data-page="receitas"] .toolbar .field,
  body[data-page="despesas"] .toolbar .field,
  body[data-page="investimentos"] .toolbar .field {
    min-width: 0;
  }
  body[data-page="receitas"] .toolbar .field:first-child,
  body[data-page="despesas"] .toolbar .field:first-child,
  body[data-page="investimentos"] .toolbar .field:first-child {
    grid-column: 1 / -1;
  }
  /* Investimentos so tem 2 campos (Pesquisar + Mes): o segundo, sozinho na
     ultima linha, tambem ocupa a largura toda em vez de ficar pela metade. */
  body[data-page="investimentos"] .toolbar .field:nth-child(2):last-child {
    grid-column: 1 / -1;
  }
  /* Reforça o encolhimento do próprio input (não só do .field ao redor):
     no iOS/Safari o controle nativo de month/date pode não respeitar
     width:100% e continuar largo o bastante pra ultrapassar a borda do
     cartão - min-width:0 direto no input evita esse vazamento. */
  .field input[type="month"],
  .field input[type="date"] {
    min-width: 0;
    max-width: 100%;
  }

  /* Lista compacta: 1 linha por lancamento (Receitas, Despesas, Investimentos,
     Orcamento do Dashboard e Lancamentos dos Relatorios), em vez do cartao
     empilhado acima - menos scroll, leitura mais rapida no celular. O grid
     fica no tbody/tfoot (nao em cada tr) para as colunas alinharem entre
     TODAS as linhas - com o grid em cada tr, uma linha com valor de mais
     digitos empurrava a coluna de data para uma posicao diferente das
     demais linhas. A tr vira "display:contents" para suas td's entrarem
     direto no grid do tbody. */
  table.data-table.tabela-compacta {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
  }
  table.data-table.tabela-compacta tbody,
  table.data-table.tabela-compacta tfoot {
    display: grid;
    /* Coluna 1 (Data) e 3/4 (Valor/acoes) tem largura de conteudo (auto);
       a coluna 2 (Titulo/Nome/Investimento) e a flexivel (1fr) - assim o
       texto do titulo fica colado perto da Data (coluna 1) e sobra o
       espaco vazio do lado do Valor, em vez do titulo flutuar pra perto
       do Valor com um vao entre a Data e ele. */
    grid-template-columns: auto 1fr auto auto;
    align-items: stretch;
    /* Sem column-gap de proposito: um "gap" real entre colunas do grid
       corta a border-bottom em pedacos (cada celula desenha so o proprio
       trecho). O espacamento visual vem do padding-left de cada coluna,
       assim a borda passa reta de ponta a ponta. */
    padding: 0 12px;
  }
  table.data-table.tabela-compacta tr { display: contents; }
  table.data-table.tabela-compacta td {
    display: flex;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    text-align: left;
  }
  table.data-table.tabela-compacta tr:last-child td { border-bottom: none; }
  table.data-table.tabela-compacta td[data-label]::before { content: none; }
  table.data-table.tabela-compacta td[data-label="Categoria"],
  table.data-table.tabela-compacta td[data-label="Tipo"] { display: none; }
  table.data-table.tabela-compacta td[colspan] {
    grid-column: 1 / -1;
    padding: 20px 0;
  }
  /* Rodape "Total:": usa colspan por causa do desktop (tabela normal), mas
     no grid mobile precisa ficar so ate a coluna 3 (onde comeca a coluna
     Valor) - "1 / 4" cobriria a propria coluna Valor e sobreporia o rotulo
     em cima do numero. A linha divisoria acima do total vem da mesma regra
     "table.data-table tfoot tr td" usada no desktop (fora do media query) -
     nao repete aqui pra nao duplicar a borda. */
  table.data-table.tabela-compacta td[colspan].rodape-total-label {
    grid-column: 1 / 3;
    padding: 11px 0;
  }
  /* Grid-column aqui precisa acompanhar a ordem real das celulas no HTML
     (Data e a primeira td de cada linha): o auto-placement do grid CSS usa
     um cursor que so anda pra frente, entao uma celula com grid-column
     explicito MENOR que a coluna ja alcancada pelo cursor (ex.: Data com
     coluna 2 chegando ANTES de uma celula de coluna 1) forca essa celula
     pro inicio da PROXIMA linha do grid, quebrando o layout em vez de
     manter tudo numa linha so. Por isso Data = coluna 1 (bate com a ordem
     do HTML) e Titulo/Nome/Investimento = coluna 2. */
  table.data-table.tabela-compacta td[data-label="Data"] {
    grid-column: 1;
    white-space: nowrap;
    font-size: 0.74rem;
    color: var(--text-muted);
    padding-right: 8px;
  }
  table.data-table.tabela-compacta td[data-label="Título"],
  table.data-table.tabela-compacta td[data-label="Titulo"],
  table.data-table.tabela-compacta td[data-label="Nome"],
  table.data-table.tabela-compacta td[data-label="Investimento"] {
    grid-column: 2;
    min-width: 0;
    /* Titulo grande quebra linha (a linha fica mais alta) em vez de cortar
       o texto com reticencias ou de invadir a coluna do Valor. "anywhere" e
       nao "break-word": os dois quebram a palavra do mesmo jeito na tela,
       mas break-word nao conta essa quebra ao calcular o tamanho minimo da
       celula dentro do flex (a td e display:flex) - daí uma palavra unica
       muito comprida (sem espacos) empurrava/ultrapassava a coluna do Valor
       mesmo com min-width:0 na td. "anywhere" conta a quebra nesse calculo
       tambem, entao a celula realmente encolhe e a palavra quebra dentro
       dela em vez de sobrepor o texto no Valor. */
    white-space: normal;
    overflow-wrap: anywhere;
    font-weight: 600;
    font-size: 0.86rem;
    padding-left: 10px;
  }
  table.data-table.tabela-compacta td[data-label="Valor"] {
    grid-column: 3;
    white-space: nowrap;
    font-size: 0.86rem;
    justify-content: flex-end;
    padding-left: 10px;
  }
  table.data-table.tabela-compacta td:last-child:not([data-label]):not([colspan]) {
    grid-column: 4;
    justify-content: flex-end;
    padding-left: 6px;
  }
  table.data-table.tabela-compacta .table-actions { gap: 2px; width: auto; }
  table.data-table.tabela-compacta .btn-icon { width: 30px; height: 30px; font-size: 0.82rem; }

  /* Celula de "lista vazia" (icone + texto): tanto a tabela normal quanto a
     compacta viram flex no td (pra empilhar rotulo/valor no mobile), e um
     td[colspan] com um unico filho fica encostado no inicio do eixo
     principal em vez de centralizado - o text-align:center do .empty-state
     nao ajuda porque quem decide a posicao aqui e o flex do td pai, nao o
     alinhamento de texto. :has() mira so a celula que de fato tem um
     ".empty-state" dentro, sem mexer na celula "Total:" (que tambem usa
     colspan, mas nao deve centralizar). */
  table.data-table td[colspan]:has(.empty-state) {
    justify-content: center;
    text-align: center;
  }

  /* Efeito de destaque temporario ao chegar via busca (Ctrl+F-like). Nas
     tabelas de lista compacta a tr vira "display:contents" (sem caixa
     propria), entao o destaque precisa ir nas td's - a tr sozinha nao
     pinta nada. */
  @keyframes rowHighlightFlash {
    0%, 60% { background: color-mix(in srgb, var(--primary) 30%, transparent); }
    100% { background: transparent; }
  }
  tr.row-highlight, td.row-highlight { animation: rowHighlightFlash 2.2s ease-out; }
}

@media (min-width: 721px) {
  tr.row-highlight, td.row-highlight { animation: rowHighlightFlash 2.2s ease-out; }
  @keyframes rowHighlightFlash {
    0%, 60% { background: color-mix(in srgb, var(--primary) 22%, transparent); }
    100% { background: transparent; }
  }
}
