/* ═══════════════════════════════════════════════════════════════════
   Financeiro da Casa — camada de tema sobre o Tabler
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --brand:        #6d5efc;
  --brand-2:      #22d3ee;
  --brand-rgb:    109, 94, 252;
  --tblr-primary: #6d5efc;
  --tblr-primary-rgb: 109, 94, 252;
  --tblr-font-sans-serif: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                          'Helvetica Neue', Arial, sans-serif;
  --money-font: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --c-in:   var(--tblr-green);
  --c-out:  var(--tblr-red);
  --c-inv:  var(--tblr-purple);
  --c-warn: var(--tblr-orange);
}

html { scroll-behavior: smooth; }
body { -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }

/* números sempre alinhados */
.money, .num { font-family: var(--money-font); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

.text-in   { color: var(--c-in)   !important; }
.text-out  { color: var(--c-out)  !important; }
.text-inv  { color: var(--c-inv)  !important; }
.text-warn { color: var(--c-warn) !important; }

/* ─────────────────────────── Boot / splash ─────────────────────────── */
.boot-screen {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  background: var(--tblr-body-bg);
}
.boot-screen.hide { display: none; }
.boot-logo {
  width: 60px; height: 60px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 30px;
  box-shadow: 0 10px 30px -8px rgba(var(--brand-rgb), .6);
}

/* ─────────────────────────── Marca ─────────────────────────── */
.navbar-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 4px 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 36px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 19px;
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 700; font-size: 15px; color: var(--tblr-body-color); }
.brand-sub  { font-size: 10.5px; color: var(--tblr-secondary); font-weight: 500; }

/* ─────────────────────────── Sidebar ─────────────────────────── */
/* A largura fica por conta do Tabler (240px). Fixá-la aqui só cria
   divergência com a margem que ele aplica no .page-wrapper. */
.navbar-vertical .nav-link { border-radius: 8px; margin: 1px 0; font-weight: 500; }
.navbar-vertical .nav-link.active {
  background: linear-gradient(135deg, rgba(var(--brand-rgb), .16), rgba(34, 211, 238, .12));
  color: var(--brand); font-weight: 600;
}
.navbar-vertical .nav-link.active .nav-link-icon { color: var(--brand); }
.nav-section {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  color: var(--tblr-secondary); padding: 16px 10px 5px; opacity: .75;
}
.nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 700; padding: 1px 7px;
  border-radius: 20px; background: var(--tblr-red); color: #fff;
}
.side-foot { border-top: 1px solid var(--tblr-border-color); padding: 10px 8px 0; }
.side-foot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-foot-row .text-secondary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─────────────────────────── Topbar ─────────────────────────── */
.app-topbar {
  position: sticky; top: 0; z-index: 1020;
  background: var(--tblr-bg-surface);
  border-bottom: 1px solid var(--tblr-border-color);
  padding-top: env(safe-area-inset-top);
  min-height: 60px;
}
/* NÃO recuar aqui pela barra lateral: o Tabler já aplica margin-left de 240px
   no .page-wrapper. Somar um padding próprio empurrava o conteúdo para 503px
   num viewport de 1440 e deixava ~260px de faixa morta ao lado do menu.
   O .app-topbar é irmão do .page-wrapper e herda o mesmo recuo. */
.page-title { font-size: 1.05rem; font-weight: 700; }

.month-switch {
  display: inline-flex; align-items: center;
  background: var(--tblr-bg-surface-secondary);
  border: 1px solid var(--tblr-border-color); border-radius: 9px; padding: 2px;
}
.month-switch .btn { border: 0; background: transparent; box-shadow: none; }
.month-switch .month-label {
  min-width: 88px; font-weight: 700; font-size: 13px; text-transform: capitalize;
}
.month-switch.d-none { display: none !important; }

/* ─────────────────────────── Página ─────────────────────────── */
.page-body { margin-top: 1.25rem; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
@media (min-width: 992px) { .page-body { padding-bottom: 2rem; } }

/* ─────────────────────────── KPI ─────────────────────────── */
.kpi { position: relative; overflow: hidden; height: 100%; }
.kpi .card-body { padding: .85rem 1rem; }
.kpi-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 700; color: var(--tblr-secondary); display: flex; align-items: center; gap: 5px;
}
.kpi-value { font-size: 1.45rem; font-weight: 700; line-height: 1.25; margin-top: 2px; }
.kpi-sub { font-size: 11px; color: var(--tblr-secondary); margin-top: 1px; }
.kpi-accent { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
@media (max-width: 575.98px) { .kpi-value { font-size: 1.2rem; } .kpi .card-body { padding: .7rem .8rem; } }

/* ─────────────────────────── Cartão de crédito ─────────────────────────── */
.credit-card {
  border-radius: 14px; padding: 16px 18px; color: #fff; min-height: 150px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
  box-shadow: 0 8px 24px -10px rgba(0, 0, 0, .5);
}
.credit-card::after {
  content: ''; position: absolute; right: -40px; top: -40px;
  width: 160px; height: 160px; border-radius: 50%; background: rgba(255, 255, 255, .1);
}
.credit-card .cc-name { font-weight: 700; font-size: 15px; }
.credit-card .cc-num  { font-family: var(--money-font); letter-spacing: .18em; opacity: .85; font-size: 13px; }
.credit-card .cc-meta { font-size: 10.5px; opacity: .8; text-transform: uppercase; letter-spacing: .04em; }
.credit-card .cc-value { font-size: 1.35rem; font-weight: 700; }
.cc-bar { height: 5px; border-radius: 4px; background: rgba(255,255,255,.25); overflow: hidden; }
.cc-bar > div { height: 100%; background: #fff; border-radius: 4px; }

/* ─────────────────────────── Listas ─────────────────────────── */
.row-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--tblr-border-color);
}
.row-item:last-child { border-bottom: 0; }
.row-icon {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 11px; color: var(--tblr-secondary); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-amount { font-weight: 700; text-align: right; white-space: nowrap; }

/* barra de categoria */
.cat-bar { height: 6px; border-radius: 4px; background: var(--tblr-bg-surface-secondary); overflow: hidden; }
.cat-bar > div { height: 100%; border-radius: 4px; transition: width .35s ease; }

/* ─────────────────────────── Seletor de tipo ─────────────────────────── */
.kind-picker { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.kind-opt {
  border: 1px solid var(--tblr-border-color); background: var(--tblr-bg-surface);
  border-radius: 9px; padding: 9px 6px; font-size: 12.5px; font-weight: 600;
  color: var(--tblr-secondary); cursor: pointer; transition: .15s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.kind-opt i { font-size: 15px; }
.kind-opt:hover { background: var(--tblr-bg-surface-secondary); }
.kind-opt.on[data-kind="despesa"]      { background: var(--tblr-red);    border-color: var(--tblr-red);    color: #fff; }
.kind-opt.on[data-kind="receita"]      { background: var(--tblr-green);  border-color: var(--tblr-green);  color: #fff; }
.kind-opt.on[data-kind="investimento"] { background: var(--tblr-purple); border-color: var(--tblr-purple); color: #fff; }
@media (max-width: 480px) { .kind-opt { flex-direction: column; gap: 2px; font-size: 11px; padding: 8px 4px; } }

/* ─────────────────────────── Grade de ícones ─────────────────────────── */
.icon-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px;
  max-height: 148px; overflow-y: auto; padding: 6px;
  border: 1px solid var(--tblr-border-color); border-radius: 8px;
}
.icon-opt {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  color: var(--tblr-secondary); background: var(--tblr-bg-surface-secondary);
}
.icon-opt:hover { color: var(--brand); }
.icon-opt.on { background: rgba(var(--brand-rgb), .15); border-color: var(--brand); color: var(--brand); }

/* ─────────────────────────── Alertas ─────────────────────────── */
.alert-purple {
  background: rgba(var(--brand-rgb), .1); border-color: rgba(var(--brand-rgb), .3);
  color: var(--tblr-body-color);
}
.alert-strip { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; font-size: 12.5px; }

/* ─────────────────────────── FAB + bottom nav ─────────────────────────── */
.fab {
  position: fixed; right: 16px; z-index: 1035; border: 0;
  bottom: calc(74px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 17px; font-size: 25px; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 10px 24px -6px rgba(var(--brand-rgb), .7);
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.94); }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  display: flex; background: var(--tblr-bg-surface);
  border-top: 1px solid var(--tblr-border-color);
  padding: 5px 2px calc(5px + env(safe-area-inset-bottom));
  backdrop-filter: saturate(180%) blur(12px);
}
.bn-i {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 1px; border: 0; background: none; border-radius: 9px;
  color: var(--tblr-secondary); font-size: 9.5px; font-weight: 600;
}
.bn-i i { font-size: 20px; }
.bn-i span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.bn-i.on { color: var(--brand); }

/* ─────────────────────────── Tabelas ─────────────────────────── */
.table thead th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em;
  font-weight: 700; color: var(--tblr-secondary); white-space: nowrap;
}
.table td { vertical-align: middle; font-size: 13px; }
.table-hover tbody tr:hover { background: var(--tblr-bg-surface-secondary); }
.tbl-actions { white-space: nowrap; text-align: right; }
.tbl-actions .btn { padding: 2px 6px; }

/* ─────────────────────────── Filtros ─────────────────────────── */
.filter-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.chip-group { display: inline-flex; background: var(--tblr-bg-surface-secondary); border-radius: 9px; padding: 3px; gap: 2px; }
.chip {
  border: 0; background: none; border-radius: 7px; padding: 5px 11px;
  font-size: 12px; font-weight: 600; color: var(--tblr-secondary); white-space: nowrap;
}
.chip.on { background: var(--tblr-bg-surface); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
@media (max-width: 767.98px) {
  .filter-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .filter-scroll::-webkit-scrollbar { display: none; }
  .filter-scroll .filter-bar { flex-wrap: nowrap; }
}

/* ─────────────────────────── Estado vazio ─────────────────────────── */
.empty-mini { text-align: center; padding: 26px 12px; color: var(--tblr-secondary); font-size: 12.5px; }
.empty-mini i { font-size: 28px; display: block; margin-bottom: 8px; opacity: .5; }

/* ─────────────────────────── Gráficos ─────────────────────────── */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { max-width: 100%; }

/* ─────────────────────────── Ajustes mobile ─────────────────────────── */
@media (max-width: 767.98px) {
  .card { border-radius: 12px; }
  .modal-dialog:not(.modal-sm) { margin: 0; align-items: flex-end; min-height: 100%; }
  .modal-dialog:not(.modal-sm) .modal-content { border-radius: 18px 18px 0 0; max-height: 94vh; }
  /* iOS não dá zoom com fonte >= 16px */
  .form-control, .form-select { font-size: 16px; }
  .h1 { font-size: 1.5rem; }
}

/* impressão */
@media print {
  .app-topbar, .navbar-vertical, .bottom-nav, .fab, .btn { display: none !important; }
  .page-wrapper { padding-left: 0 !important; }
}

/* ─────────────────────────── Tabela de lançamentos ─────────────────────────── */
/* Sem table-layout fixo a coluna de descrição assume max-content — medimos
   1527px — e empurra Valor e Situação para fora da tela em qualquer largura.
   As larguras ficam AQUI, e não em style= no HTML: estilo inline vence media
   query, e foi o que impediu a primeira tentativa de corrigir o celular.
   nth-child conta todas as colunas, inclusive as escondidas por breakpoint. */
.tbl-lanc { table-layout: fixed; width: 100%; }
.tbl-lanc td, .tbl-lanc th { overflow: hidden; }
.tbl-lanc thead th:nth-child(1) { width: 72px; }   /* Data */
.tbl-lanc thead th:nth-child(3) { width: 124px; }  /* Categoria */
.tbl-lanc thead th:nth-child(4) { width: 92px; }   /* Quem */
.tbl-lanc thead th:nth-child(5) { width: 124px; }  /* Pagamento */
.tbl-lanc thead th:nth-child(6) { width: 118px; }  /* Valor */
.tbl-lanc thead th:nth-child(7) { width: 112px; }  /* Situação */
.tbl-lanc thead th:nth-child(8) { width: 104px; }  /* ações */
.tbl-lanc .lanc-desc { min-width: 0; }
.tbl-lanc .lanc-desc .lanc-title {
  font-weight: 600; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Celular: 72+118+112+104 = 406px não cabiam num container de ~380px, a
   descrição ia a zero e a tabela voltava a rolar. */
@media (max-width: 767.98px) {
  .tbl-lanc th, .tbl-lanc td { padding-left: .35rem; padding-right: .35rem; }
  .tbl-lanc thead th:nth-child(1) { width: 44px; }
  .tbl-lanc thead th:nth-child(6) { width: 96px; }
  .tbl-lanc thead th:nth-child(7) { width: 74px; }
  .tbl-lanc thead th:nth-child(8) { width: 36px; }
  .tbl-lanc .tbl-actions .btn { padding: 2px 4px; }
  .tbl-lanc td:nth-child(7) .text-secondary { display: none; }
}
/* Faixa intermediária: Categoria devolve espaço para a descrição. */
@media (min-width: 768px) and (max-width: 1023.98px) {
  .tbl-lanc thead th:nth-child(3) { width: 104px; }
}

/* Telas de 375px (iPhone SE e similares): com as larguras acima a descrição
   caía para 92px. Aqui Data, Valor, Situação e ações vão ao mínimo em que o
   conteúdo ainda cabe, devolvendo ~120px à descrição. */
@media (max-width: 420px) {
  .tbl-lanc thead th:nth-child(1) { width: 40px; }
  .tbl-lanc thead th:nth-child(6) { width: 82px; }
  .tbl-lanc thead th:nth-child(7) { width: 68px; }
  .tbl-lanc thead th:nth-child(8) { width: 32px; }
  .tbl-lanc td, .tbl-lanc th { padding-left: .3rem; padding-right: .3rem; }
}

/* Abaixo de 360px (iPhone SE 1ª geração e afins) nem o mínimo cabia: a data
   sai, já que descrição, valor e situação importam mais para decidir. */
@media (max-width: 359.98px) {
  .tbl-lanc thead th:nth-child(1), .tbl-lanc tbody td:nth-child(1) { display: none; }
}
