/* =========================================================
   Controle financeiro — estilos
   Para mudar o visual, ajuste primeiro as variáveis abaixo.
   ========================================================= */
:root {
  /* Tipografia */
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 18px;
  --fs-xl: 26px;

  /* Cores (tema claro) */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #121826;
  --text-2: #5b6474;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --accent-soft: #e8eefe;
  --positivo: #0f8a5f;
  --positivo-soft: #e1f5ec;
  --negativo: #d23a3a;
  --negativo-soft: #fdeaea;
  --pendente: #a96a00;
  --pendente-soft: #fff1d6;
  --destaque-bg: #121826;
  --destaque-text: #ffffff;

  /* Gráficos: cores das séries (ordem fixa, testada para daltonismo) */
  --serie-1: #2a78d6;   /* azul — Entradas / 1ª categoria */
  --serie-2: #eb6834;   /* laranja — Saídas / 2ª categoria */
  --serie-3: #1baf7a;
  --serie-4: #eda100;
  --serie-5: #e87ba4;
  --serie-outras: #a3a9b3;
  --grade: #eceef2;

  /* Forma e espaçamento */
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --control-h: 40px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1b212a;
    --border: #2a313c;
    --text: #e8ecf2;
    --text-2: #97a1b1;
    --accent: #6b8cff;
    --accent-text: #0d1117;
    --accent-soft: #1f2a4a;
    --positivo: #4cc79a;
    --positivo-soft: #12332a;
    --negativo: #ff7a7a;
    --negativo-soft: #3a1a1a;
    --pendente: #f0b44c;
    --pendente-soft: #3a2c10;
    --destaque-bg: #232b38;
    --destaque-text: #ffffff;
    --serie-1: #3987e5;
    --serie-2: #d95926;
    --serie-3: #199e70;
    --serie-4: #c98500;
    --serie-5: #d55181;
    --serie-outras: #5b6474;
    --grade: #222932;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--fs-md)/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
h1, h2 { margin: 0; }
.muted { color: var(--text-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Controles ---------- */
input {
  height: var(--control-h); width: 100%; min-width: 0;
  padding: 0 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input::placeholder { color: var(--text-2); opacity: .7; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  height: var(--control-h); padding: 0 16px; font: 600 var(--fs-md)/1 var(--font);
  border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }

.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; padding: 0;
  font-size: 22px; line-height: 1; color: var(--text);
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Topo ---------- */
.topo { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topo-inner {
  max-width: 1040px; margin: 0 auto; padding: 12px var(--gap);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--gap);
}
.topo-inner > .btn { justify-self: end; }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; justify-self: start; }
.seg button {
  height: 34px; padding: 0 14px; font: 600 var(--fs-sm)/1 var(--font); white-space: nowrap;
  color: var(--text-2); background: transparent; border: 0; border-radius: 8px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.mes-nav { display: flex; align-items: center; gap: 8px; }
.mes-nav h1 { font-size: var(--fs-lg); font-weight: 700; min-width: 170px; text-align: center; white-space: nowrap; }

/* ---------- Página ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: var(--gap); display: grid; gap: var(--gap); }

.resumo { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 4px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.card-rotulo { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.card-valor { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.card-nota { font-size: var(--fs-sm); color: var(--text-2); min-height: 1.4em; }
.card-input {
  height: auto; padding: 0; border: 0; background: transparent; border-radius: 0;
  font: 700 var(--fs-xl)/1.2 var(--font); letter-spacing: -.01em; border-bottom: 1px dashed var(--border);
}
.card-input:focus { outline: none; border-bottom: 1px solid var(--accent); }
.card-destaque { background: var(--destaque-bg); color: var(--destaque-text); border-color: transparent; }
.card-destaque .card-rotulo, .card-destaque .card-nota { color: rgba(255,255,255,.72); }
.card-destaque.negativo .card-valor { color: #ff9b9b; }
.card-destaque.positivo .card-valor { color: #7ee2b8; }

.barra { display: flex; justify-content: flex-end; }

/* ---------- Listas ---------- */
.bloco { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.bloco-topo { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.bloco-topo h2 { font-size: var(--fs-lg); font-weight: 700; }
.bloco-total { color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; }

.row {
  display: grid; align-items: center; gap: 12px; padding: 10px 16px;
  grid-template-columns: 116px minmax(0, 1fr) minmax(0, 180px) 130px 76px;
  border-bottom: 1px solid var(--border);
}
.row:hover { background: var(--surface-2); }
.row .nome { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .cat { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .valor { text-align: right; font-weight: 600; white-space: nowrap; }
.row.paga .nome, .row.paga .valor { color: var(--text-2); }
.row .acoes { display: flex; justify-content: flex-end; gap: 4px; }
.row .acoes .icon-btn { width: 32px; height: 32px; font-size: 14px; border-color: transparent; color: var(--text-2); }
.row .acoes .icon-btn:hover { color: var(--text); border-color: var(--border); }
.row .acoes .icon-btn.confirmar { color: var(--negativo); border-color: var(--negativo); width: auto; padding: 0 10px; font-weight: 600; }

.vazio { padding: 20px 16px; color: var(--text-2); font-size: var(--fs-sm); }

.pill {
  height: 30px; padding: 0 12px; font: 600 var(--fs-sm)/1 var(--font); white-space: nowrap;
  border-radius: 999px; border: 0; cursor: pointer;
  color: var(--pendente); background: var(--pendente-soft);
}
.pill[aria-pressed="true"] { color: var(--positivo); background: var(--positivo-soft); }
.pill:hover { filter: brightness(.96); }

.row.edicao { grid-template-columns: minmax(0, 1fr) minmax(0, 180px) 130px auto; }
.row.edicao .status { display: none; }
.row.edicao input { height: 36px; }
.row.edicao .valor { text-align: left; }

/* ---------- Formulário de adicionar ---------- */
.add {
  display: grid; gap: 12px; padding: 12px 16px; background: var(--surface-2);
  grid-template-columns: minmax(0, 1fr) minmax(0, 180px) 130px auto;
}

/* ---------- Gráficos ---------- */
.graficos { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--gap); align-items: start; }
.grafico .bloco-topo { align-items: center; gap: 12px; flex-wrap: wrap; }
.grafico-corpo { padding: 16px; }
.grafico-corpo svg { display: block; width: 100%; overflow: visible; }
.grafico-vazio { padding: 48px 0; text-align: center; color: var(--text-2); font-size: var(--fs-sm); }

.legenda { display: flex; gap: 14px; font-size: var(--fs-sm); color: var(--text-2); }
.leg-item { display: inline-flex; align-items: center; gap: 6px; }
.leg-cor { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.eixo { font-size: 12px; fill: var(--text-2); }
.eixo-mes.atual { fill: var(--text); font-weight: 700; }
.linha-grade { stroke: var(--grade); stroke-width: 1; }
.linha-base { stroke: var(--border); stroke-width: 1; }
.alvo { fill: transparent; cursor: pointer; }
.alvo:hover { fill: var(--surface-2); }

.seg-sm button { height: 28px; padding: 0 10px; }

.grafico { container-type: inline-size; }
.pizza { display: grid; grid-template-columns: 160px minmax(0, 1fr); align-items: center; gap: 20px; }
@container (max-width: 440px) {
  .pizza { grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 16px; }
  .pizza-lista { width: 100%; }
}
.pizza svg { width: 160px; height: 160px; }
.fatia { stroke: var(--surface); stroke-width: 2; transition: opacity .15s; cursor: default; }
.pizza.foco .fatia:not(.ativa) { opacity: .3; }
.pizza-total { font-size: 17px; font-weight: 700; fill: var(--text); }
.pizza-rotulo { font-size: 12px; fill: var(--text-2); }

.pizza-lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: var(--fs-sm); }
.pizza-lista li {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 40px; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-sm); transition: opacity .15s;
}
.pizza-lista li:hover, .pizza-lista li.ativa { background: var(--surface-2); }
.pizza.foco .pizza-lista li:not(.ativa) { opacity: .45; }
.pizza-lista .nome { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pizza-lista .val { font-weight: 600; white-space: nowrap; }
.pizza-lista .pct { color: var(--text-2); text-align: right; }

.dica {
  position: fixed; z-index: 20; pointer-events: none; min-width: 160px; white-space: nowrap;
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: var(--fs-sm);
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.dica strong { display: block; margin-bottom: 4px; }
.dica .linha { display: flex; align-items: center; gap: 6px; }
.dica .linha span:last-child { margin-left: auto; padding-left: 12px; font-weight: 600; }
.dica .sub { color: var(--text-2); margin-top: 4px; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--gap); }
.login-card {
  width: 100%; max-width: 360px; display: grid; gap: 12px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.login-card h1 { font-size: var(--fs-xl); }
.erro { margin: 0; color: var(--negativo); font-size: var(--fs-sm); }

/* ---------- Aviso ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg); font-size: var(--fs-sm); font-weight: 600;
}

/* ---------- Celular ---------- */
@media (max-width: 720px) {
  .topo-inner { grid-template-columns: 1fr auto; }
  .mes-nav { grid-column: 1 / -1; order: 3; justify-content: space-between; }
  .mes-nav h1 { flex: 1; }
  .card-valor, .card-input { font-size: 22px; }

  .row {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "nome nome valor" "cat status acoes";
    row-gap: 6px;
  }
  .row .nome { grid-area: nome; }
  .row .valor { grid-area: valor; }
  .row .cat { grid-area: cat; }
  .row .status { grid-area: status; }
  .row .acoes { grid-area: acoes; }
  .row.edicao {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "nome nome" "cat valor" "acoes acoes";
  }
  .row.edicao .status { display: none; }

  .graficos { grid-template-columns: minmax(0, 1fr); }

  .add { grid-template-columns: 1fr 1fr; }
  .add input[name="nome"] { grid-column: 1 / -1; }
  .add .btn { grid-column: 1 / -1; }
}
