/* ============================================================
   Financeiro — mobile-first
   Tinta spruce + verde/vermelho para sinal do dinheiro.
   Ouro (--gold) toca APENAS elementos de cartao de credito.
   Todo valor monetario: IBM Plex Mono, tabular, alinhado a direita.
   ============================================================ */

:root {
  color-scheme: light dark;

  --bg:        #eef1ef;
  --bg-2:      #e4e9e5;
  --surface:   #ffffff;
  --line:      #d3dad4;
  --line-soft: #e2e7e3;
  --ink:       #16241e;
  --ink-2:     #47554e;
  --muted:     #75837b;

  --positive:  #1f7a4d;
  --positive-bg: #e5f1ea;
  --negative:  #c2452f;
  --negative-bg: #f7e7e3;
  --gold:      #9a6b12;
  --gold-bg:   #f6ecd6;

  --radius:   14px;
  --radius-s: 9px;
  --shadow:   0 1px 2px rgba(22, 36, 30, .06), 0 8px 24px rgba(22, 36, 30, .06);

  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --nav-h: 60px;
  --maxw: 480px;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1f1a;
    --bg-2:      #142a23;
    --surface:   #16281f;
    --line:      #24382f;
    --line-soft: #1e3128;
    --ink:       #e8efe9;
    --ink-2:     #a9b8af;
    --muted:     #7d8f84;

    --positive:  #4cc98a;
    --positive-bg: #133026;
    --negative:  #f08a72;
    --negative-bg: #3a1e18;
    --gold:      #e4b23c;
    --gold-bg:   #2f2712;

    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
}

/* ---------- tipografia base ---------- */

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
small { font-size: .8rem; }

.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.02em;
}
.pos { color: var(--positive); }
.neg { color: var(--negative); }

.label {
  font-size: .74rem;
  color: var(--muted);
  font-weight: 500;
}

/* ============================================================
   Layout de tela com nav inferior
   ============================================================ */

.screen {
  padding: calc(var(--safe-top) + 14px) 16px calc(var(--nav-h) + var(--safe-bottom) + 24px);
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
}
.topbar .month {
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--ink-2);
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 5px 12px;
}

/* faixa de meses (extrato) */
.month-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px 20px;
  padding: 2px 16px 12px;
  scrollbar-width: none;
}
.month-strip::-webkit-scrollbar { display: none; }
.mchip {
  flex: 0 0 auto;
  scroll-snap-align: center;
  border: 1px solid var(--line-soft);
  background: var(--bg-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .8rem;
  letter-spacing: -0.01em;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.mchip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

/* ---------- nav inferior ---------- */

.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--maxw);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 50;
}
.nav button {
  border: 0;
  background: none;
  color: var(--muted);
  font-family: var(--font);
  font-size: .7rem;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.nav button.active { color: var(--ink); }
.nav button.active svg { stroke: var(--positive); }

/* ============================================================
   Herói: saldo como total de extrato
   ============================================================ */

.balance {
  padding: 8px 2px 20px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 22px;
}
.balance .label { display: block; margin-bottom: 6px; }
.balance .value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 2.6rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
}
.balance .sub {
  margin-top: 8px;
  font-size: .8rem;
  color: var(--muted);
}

/* ---------- par entrada / saida do mes ---------- */

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 22px;
}
.pair > div {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-s);
  padding: 12px 12px 14px;
}
.pair .label { display: flex; align-items: center; gap: 6px; }
.pair .dot { width: 7px; height: 7px; border-radius: 999px; display: inline-block; }
.pair .dot.in { background: var(--positive); }
.pair .dot.out { background: var(--negative); }
.pair .amount { margin-top: 6px; font-size: 1.1rem; font-weight: 600; }

/* ---------- faixa fatura dos cartoes ---------- */

.invoice-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--gold-bg);
  border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent);
  border-radius: var(--radius-s);
  padding: 12px 14px;
  margin-bottom: 26px;
}
.invoice-strip .label { color: color-mix(in srgb, var(--gold) 78%, var(--ink)); }
.invoice-strip .amount { font-size: 1.05rem; font-weight: 600; color: var(--gold); }
.invoice-strip:disabled { opacity: .55; }

/* ============================================================
   Extrato (lista de movimentos) — linhas hairline, sem cards
   ============================================================ */

.section-title {
  font-size: .78rem;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 4px;
}

/* alerta de limite estourado (dashboard) */
.limit-alert {
  width: 100%;
  text-align: left;
  border: 1px solid color-mix(in srgb, var(--negative) 45%, transparent);
  background: var(--negative-bg);
  color: var(--ink);
  border-radius: var(--radius-s);
  padding: 12px 14px;
  margin-bottom: 22px;
  cursor: pointer;
  font: inherit;
}
.limit-alert-h { font-weight: 600; font-size: .86rem; color: var(--negative); margin-bottom: 6px; }
.limit-alert-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: .8rem;
  padding: 2px 0;
}
.limit-alert-row .num { font-family: var(--mono); }

/* limites por categoria (Ajustes) */
.lim {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.lim-name { font-size: .92rem; font-weight: 500; }
.lim-meta { font-size: .74rem; color: var(--muted); }
.lim-meta .num { font-family: var(--mono); }
.lim.over .lim-name { color: var(--negative); }
.lim.over .lim-meta { color: var(--negative); }
.lim.near .lim-meta { color: var(--gold); }
.lim-edit { display: flex; gap: 6px; align-items: center; }
.lim-input {
  width: 110px;
  font-family: var(--mono);
  text-align: right;
  padding: 8px 10px;
}

.ledger-search {
  position: relative;
  margin-bottom: 6px;
}
.ledger-search input {
  padding-right: 38px;
}
.ledger-search button {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.ledger { list-style: none; }
.ledger li {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.ledger .day {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.1;
}
.ledger .day b { display: block; font-size: .95rem; color: var(--ink-2); font-weight: 600; }
.ledger .desc { min-width: 0; }
.ledger .desc .name {
  font-size: .92rem;
  font-weight: 500;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ledger .desc .meta {
  font-size: .72rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  align-items: center;
  margin-top: 2px;
}
.ledger .tag-card {
  color: var(--gold);
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  border-radius: 999px;
  padding: 0 6px;
  font-size: .68rem;
}
.ledger .amount {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: .95rem;
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}
.ledger li.expanded { background: var(--bg-2); border-radius: var(--radius-s); padding-left: 10px; padding-right: 10px; }
.ledger .row-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  padding-top: 6px;
}

/* ============================================================
   Cartoes
   ============================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  display: block;
  color: inherit;
  font: inherit;
}
.card .card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.card .card-name { font-size: 1rem; font-weight: 600; }
.card .card-flag { font-size: .74rem; color: var(--muted); }
.card .fatura {
  margin-top: 14px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: -0.03em;
}
.card .fatura-label { font-size: .72rem; color: var(--muted); }
.card .limit {
  margin-top: 12px;
  height: 5px;
  background: var(--bg-2);
  border-radius: 999px;
  overflow: hidden;
}
.card .limit > i { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.card .limit-meta { margin-top: 5px; font-size: .7rem; color: var(--muted); }

/* detalhe do cartao */
.detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.detail-head .back {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--ink);
}
.detail-head .back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

.detail-total {
  background: var(--gold-bg);
  border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.detail-total .big {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: -0.03em;
}

.purchase {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.purchase .p-name { font-size: .92rem; font-weight: 500; }
.purchase .p-meta { font-size: .72rem; color: var(--muted); }
.purchase .p-amount { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; font-weight: 500; }
.purchase .p-actions { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 6px; }
.purchase.paid .p-name { text-decoration: line-through; color: var(--muted); }

/* ============================================================
   Formularios
   ============================================================ */

.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: .78rem;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
}
input, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 12px 13px;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus {
  outline: 2px solid var(--positive);
  outline-offset: 1px;
  border-color: transparent;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2375837b' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}
.input-money {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 600;
  text-align: right;
  letter-spacing: -0.02em;
}

/* campo de categoria com busca */
.catfield { position: relative; }
.catfield-panel {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
}
.catfield-opt,
.catfield-add {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink);
  text-align: left;
  padding: 11px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.catfield-opt:hover,
.catfield-add:hover { background: var(--bg-2); }
.catfield-opt.sel { color: var(--positive); font-weight: 600; }
.catfield-add { color: var(--gold); font-weight: 600; }
.catfield-add::before { content: "+ "; }
.catfield-empty { padding: 11px 10px; color: var(--muted); font-size: .85rem; }

/* checkbox */
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 2px;
  font-size: .9rem;
  cursor: pointer;
}
.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--positive);
  flex: 0 0 auto;
}
.check #repetirDia { color: var(--muted); }

/* tag "fixo" no extrato */
.tag-fixo {
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 6px;
  font-size: .68rem;
}

/* lista de lancamentos fixos (Ajustes) */
.rec {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.rec.off { opacity: .5; }
.rec-name { font-size: .92rem; font-weight: 500; }
.rec-meta { font-size: .72rem; color: var(--muted); }
.rec-val { font-weight: 600; text-align: right; white-space: nowrap; }
.rec-actions { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 6px; }

/* toggle entrada/saida */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-s);
  padding: 3px;
  margin-bottom: 18px;
}
.seg button {
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  padding: 9px;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); }
.seg button.in[aria-pressed="true"] { color: var(--positive); }
.seg button.out[aria-pressed="true"] { color: var(--negative); }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* botoes */
.btn {
  width: 100%;
  border: 0;
  border-radius: var(--radius-s);
  padding: 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--ink);
  color: var(--bg);
}
.btn:active { transform: translateY(1px); }
.btn.gold { background: var(--gold); color: #1a1206; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.tiny { width: auto; padding: 7px 12px; font-size: .8rem; }
.btn.danger { background: none; color: var(--negative); border: 1px solid color-mix(in srgb, var(--negative) 40%, transparent); }

.btn.loading {
  pointer-events: none;
  opacity: .9;
}
.btn.loading::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 9px;
  vertical-align: -2px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  animation: spin .65s linear infinite;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.loading:disabled { opacity: .9; }

.btn-fixed {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  width: calc(min(100vw, var(--maxw)) - 32px);
  z-index: 40;
  box-shadow: var(--shadow);
}
/* mantem a centralizacao horizontal ao pressionar (bug: pulava pra esquerda) */
.btn-fixed:active { transform: translateX(-50%) translateY(1px); }

/* spinner de carregamento de tela */
@keyframes spin { to { transform: rotate(360deg); } }
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 64px 20px;
  color: var(--muted);
  font-size: .86rem;
}
.loader::before {
  content: "";
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--line);
  border-top-color: var(--positive);
  border-radius: 999px;
  animation: spin .65s linear infinite;
}

/* entrada suave do conteudo de cada tela */
@keyframes viewIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.screen, .login { animation: viewIn .16s ease-out both; }

/* skeleton */
@keyframes shimmer { to { background-position: -160% 0; } }
.sk {
  border-radius: var(--radius-s);
  background: linear-gradient(100deg, var(--bg-2) 30%, var(--line-soft) 50%, var(--bg-2) 70%);
  background-size: 240% 100%;
  animation: shimmer 1.2s linear infinite;
}

/* ============================================================
   Login
   ============================================================ */

.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 28px calc(40px + var(--safe-bottom));
}
.login .brand {
  font-family: var(--mono);
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: -0.03em;
}
.login .brand + p { color: var(--muted); margin: 4px 0 34px; }
.login .btn { margin-top: 6px; }

/* ============================================================
   Utilidades
   ============================================================ */

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: .9rem;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 76px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 500;
  z-index: 100;
  max-width: calc(100vw - 40px);
  box-shadow: var(--shadow);
}
.toast.err { background: var(--negative); color: #fff; }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 6px 6px 12px;
  font-size: .82rem;
}
.chip button {
  border: 0;
  background: var(--bg-2);
  color: var(--muted);
  width: 20px; height: 20px;
  border-radius: 999px;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
}

hr.div { border: 0; border-top: 1px solid var(--line-soft); margin: 22px 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .btn.loading::before { display: none; }
  .loader::before {
    animation: none !important;
    border-top-color: var(--positive);
    border-right-color: var(--positive);
  }
}

@media (min-width: 481px) {
  body { background: var(--bg-2); }
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
