:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --good: #006300;
  --bad: #d03b3b;
  --series-blue: #2a78d6;
  --series-green: #008300;
  --series-magenta: #e87ba4;
  --series-yellow: #eda100;
  --series-aqua: #1baf7a;
  --series-orange: #eb6834;
  --series-violet: #4a3aa7;
  --series-red: #e34948;
  --seq-100: #cde2fb;
  --seq-400: #3987e5;
  --seq-500: #256abf;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255,255,255,0.10);
    --good: #0ca30c;
    --bad: #e66767;
    --series-blue: #3987e5;
    --series-green: #008300;
    --series-magenta: #d55181;
    --series-yellow: #c98500;
    --series-aqua: #199e70;
    --series-orange: #d95926;
    --series-violet: #9085e9;
    --series-red: #e66767;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  min-height: 100vh;
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-screen[hidden] { display: none; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.login-card h1 { font-size: 20px; margin: 0; }
.login-sub { color: var(--text-secondary); font-size: 14px; margin: 0 0 4px; }
.login-card input {
  font-size: 16px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--baseline);
  background: var(--page);
  color: var(--text-primary);
}
.login-card button {
  font-size: 15px;
  font-weight: 600;
  padding: 11px 12px;
  border-radius: 10px;
  border: none;
  background: var(--series-blue);
  color: #fff;
  cursor: pointer;
}
.login-card button:hover { opacity: 0.92; }
.login-erro { color: var(--bad); font-size: 13px; margin: 0; }

/* ---------- App shell ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h1 { font-size: 18px; margin: 0; white-space: nowrap; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
@media (max-width: 420px) {
  .topbar-actions select { max-width: 140px; }
}
.topbar-actions select, .btn-ghost {
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--page);
  color: var(--text-primary);
}
.btn-ghost { cursor: pointer; background: transparent; }

.grid {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 60px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
}

.tiles {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 720px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tile-label { font-size: 12px; color: var(--text-muted); }
.tile-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tile-value.negativo { color: var(--bad); }
.tile-value.positivo { color: var(--good); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.card-wide { grid-column: 1 / -1; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; flex-wrap: wrap; gap: 4px; }
.card-head h2 { font-size: 15px; margin: 0; }
.card-sub { font-size: 12px; color: var(--text-muted); }

/* ---------- Line chart (saldo diário) ---------- */
.chart-area { width: 100%; }
.chart-area svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-tooltip {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  white-space: nowrap;
  z-index: 10;
}
.chart-wrap { position: relative; }

/* ---------- Bar rows (categoria / forma pagamento) ---------- */
.bars-area { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 70px; align-items: center; gap: 8px; }
.bar-row-label { font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row-track { height: 10px; border-radius: 5px; background: var(--gridline); overflow: hidden; }
.bar-row-fill { display: block; height: 100%; border-radius: 5px; transition: width 0.2s ease; }
.bar-row-value { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.empty-msg { color: var(--text-muted); font-size: 13px; padding: 8px 0; }

/* ---------- Cartões ---------- */
.cartoes-area { display: flex; flex-direction: column; gap: 10px; }
.cartao-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer;
}
.cartao-item:hover { border-color: var(--baseline); background: var(--page); }
.cartao-nome { font-size: 13px; font-weight: 600; }
.cartao-detalhe { font-size: 12px; color: var(--text-muted); }
.cartao-total-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.cartao-total { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Selo previsto / pago ---------- */
.selo {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
}
.selo-previsto { background: rgba(237,161,0,0.16); color: var(--series-yellow); }
.selo-pago { background: rgba(0,131,0,0.14); color: var(--good); }

/* ---------- Faturas do cartão (modal) ---------- */
.faturas-area { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow-y: auto; }
.fatura-item { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.fatura-cabecalho {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 14px; cursor: pointer;
}
.fatura-mes { font-size: 13px; font-weight: 600; }
.fatura-venc { font-size: 12px; color: var(--text-muted); }
.fatura-valor { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.fatura-itens { border-top: 1px solid var(--gridline); padding: 6px 14px; display: none; }
.fatura-itens.aberto { display: block; }
.fatura-item-linha {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--gridline); font-size: 12px;
}
.fatura-item-linha:last-of-type { border-bottom: none; }
.fatura-item-desc { color: var(--text-primary); }
.fatura-item-parcela { color: var(--text-muted); }
.fatura-acoes { padding: 10px 14px 12px; }
.fatura-acoes button {
  width: 100%; font-size: 13px; font-weight: 600; padding: 9px; border-radius: 8px;
  border: 1px solid var(--baseline); background: transparent; color: var(--text-primary); cursor: pointer;
}
.fatura-acoes button.pagar { border-color: var(--good); color: var(--good); }
.fatura-acoes button.reabrir { border-color: var(--text-muted); color: var(--text-muted); }

/* ---------- Legenda do grafico de saldo ---------- */
.chart-legenda { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.chart-legenda-item { display: flex; align-items: center; gap: 6px; }
.chart-legenda-linha { width: 18px; height: 0; border-top: 2px solid var(--series-blue); }
.chart-legenda-linha.previsto { border-top-style: dashed; opacity: 0.8; }

/* ---------- Lancamentos ---------- */
.lancamentos-area { display: flex; flex-direction: column; }
.lanc-row {
  display: grid; grid-template-columns: 90px 1fr 110px 90px; gap: 10px; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--gridline); font-size: 13px;
}
.lanc-row:last-child { border-bottom: none; }
.lanc-data { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.lanc-desc { color: var(--text-primary); }
.lanc-cat { color: var(--text-secondary); font-size: 12px; }
.lanc-valor { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.lanc-valor.despesa { color: var(--bad); }
.lanc-valor.receita { color: var(--good); }

/* ---------- Botao flutuante (novo lancamento) ---------- */
.fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--series-blue);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:hover { opacity: 0.92; }

/* ---------- Modal de lancamento ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }
@media (min-width: 560px) {
  .modal-overlay { align-items: center; padding: 24px; }
}
.modal {
  background: var(--surface);
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 18px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
@media (min-width: 560px) {
  .modal { border-radius: 16px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-tabs { display: flex; gap: 6px; }
.modal-tab {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--baseline);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.modal-tab.active { background: var(--series-blue); border-color: var(--series-blue); color: #fff; }
.btn-fechar { font-size: 22px; line-height: 1; padding: 4px 10px; border-radius: 8px; }

.modal-form { display: flex; flex-direction: column; gap: 12px; }
.modal-form[hidden] { display: none; }
.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}
.modal-form input, .modal-form select {
  font-size: 15px;
  padding: 10px 11px;
  border-radius: 9px;
  border: 1px solid var(--baseline);
  background: var(--page);
  color: var(--text-primary);
  font-family: inherit;
}
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-row[hidden] { display: none; }
.modal-erro { color: var(--bad); font-size: 13px; margin: 0; }
.btn-primario {
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--series-blue);
  color: #fff;
  cursor: pointer;
  margin-top: 4px;
}
.btn-primario:hover { opacity: 0.92; }
.btn-primario:disabled { opacity: 0.6; cursor: default; }

