/* Finanças da Família — Dark Theme */
:root {
  --bg: #0f1923;
  --card: #1a2733;
  --border: #2c3e4c;
  --accent: #2dd4a7;
  --accent-dim: #1a9d7c;
  --text: #e8eef2;
  --text-muted: #7a909e;
  --danger: #e05c5c;
  --warn: #e09a2c;
  --ok: #2dd4a7;
  --radius: 12px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

/* ── Layout ──────────────────────────────────────────────────────────── */

#app { max-width: 560px; margin: 0 auto; padding-bottom: 80px; }

header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

header h1 { font-size: 16px; font-weight: 600; flex: 1; }

#mes-selector {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 14px;
  cursor: pointer;
}

#btn-config {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

/* ── Bottom Nav ──────────────────────────────────────────────────────── */

nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

nav button {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 8px;
  transition: color .15s, background .15s;
}

nav button .icon { font-size: 22px; }
nav button.active { color: var(--accent); }
nav button:hover { background: rgba(45,212,167,.08); }

/* ── Tabs / Screens ──────────────────────────────────────────────────── */

.screen { display: none; padding: 16px; }
.screen.active { display: block; }

/* ── Cards ──────────────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.big-number {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.metric-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.metric-value { font-size: 20px; font-weight: 700; }
.metric-value.ok     { color: var(--ok); }
.metric-value.danger { color: var(--danger); }
.metric-value.warn   { color: var(--warn); }

/* ── Lançar Despesa ─────────────────────────────────────────────────── */

#valor-display {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--accent);
  text-align: center;
  min-height: 64px;
  padding: 8px 0;
}

#valor-display.has-value { color: var(--text); }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.cat-btn {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--text);
}

.cat-btn .emoji { font-size: 22px; }
.cat-btn .label { font-size: 10px; text-align: center; line-height: 1.2; color: var(--text-muted); }
.cat-btn.selected { border-color: var(--accent); background: rgba(45,212,167,.1); }
.cat-btn.selected .label { color: var(--accent); }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.5); }

#campo-valor {
  font-size: 32px;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  border-color: var(--accent);
  height: 70px;
  inputmode: decimal;
}

/* ── Botões ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 12px 20px;
  transition: opacity .15s, transform .1s;
  width: 100%;
}

.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--accent); color: var(--bg); }
.btn-secondary { background: var(--card); border: 1.5px solid var(--border); color: var(--text); }
.btn-danger    { background: rgba(224,92,92,.15); border: 1.5px solid var(--danger); color: var(--danger); }
.btn-sm { padding: 7px 14px; font-size: 13px; width: auto; border-radius: 8px; }
.btn-icon { background: none; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 4px 8px; }

/* ── Listas ──────────────────────────────────────────────────────────── */

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: none; }

.item-info { flex: 1; min-width: 0; }
.item-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.item-valor { font-size: 15px; font-weight: 700; flex-shrink: 0; }
.item-cat { font-size: 18px; flex-shrink: 0; }

/* ── Contas Fixas ────────────────────────────────────────────────────── */

.conta-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.conta-item:last-child { border-bottom: none; }
.conta-item input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.conta-nome { flex: 1; font-size: 14px; }
.conta-nome.pago { text-decoration: line-through; color: var(--text-muted); }
.conta-valor { font-size: 15px; font-weight: 600; flex-shrink: 0; }
.conta-valor.pago { color: var(--ok); }

/* ── Insights ────────────────────────────────────────────────────────── */

.insight-card {
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--border);
}

.insight-card.positivo { border-color: var(--ok); background: rgba(45,212,167,.06); }
.insight-card.alerta   { border-color: var(--warn); background: rgba(224,154,44,.06); }
.insight-card.critico  { border-color: var(--danger); background: rgba(224,92,92,.06); }
.insight-card.info     { border-color: var(--border); background: var(--card); }

.insight-emoji { font-size: 24px; flex-shrink: 0; }
.insight-titulo { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.insight-texto  { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* ── Investimentos ───────────────────────────────────────────────────── */

.ativo-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.ativo-item:last-child { border-bottom: none; }
.ativo-header { display: flex; justify-content: space-between; align-items: center; }
.ativo-nome { font-size: 14px; font-weight: 600; }
.ativo-ticker { font-size: 12px; color: var(--text-muted); }
.ativo-tipo-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--border);
  color: var(--text-muted);
}
.ativo-valores { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); }
.ativo-resultado { font-size: 13px; font-weight: 600; }
.resultado-pos { color: var(--ok); }
.resultado-neg { color: var(--danger); }

/* ── Modal ───────────────────────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  width: 100%;
  max-width: 560px;
  max-height: 85dvh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title { font-size: 17px; font-weight: 700; }

/* ── Login ───────────────────────────────────────────────────────────── */

#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 32px 20px;
  gap: 12px;
}

#login-screen h1 { font-size: 26px; font-weight: 800; color: var(--accent); }
#login-screen p { color: var(--text-muted); font-size: 14px; }
#login-form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

/* ── Toast ───────────────────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  white-space: nowrap;
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.ok    { border-color: var(--ok); color: var(--ok); }
#toast.error { border-color: var(--danger); color: var(--danger); }

/* ── Seção título ────────────────────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0 10px;
}

.section-title { font-size: 14px; font-weight: 700; }
.section-total { font-size: 13px; color: var(--text-muted); }

/* ── Canvas dos gráficos ─────────────────────────────────────────────── */

.chart-wrap { position: relative; height: 180px; margin: 8px 0; }

/* ── Divider ─────────────────────────────────────────────────────────── */

.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Utilitários ─────────────────────────────────────────────────────── */

.hidden  { display: none !important; }
.mt-8   { margin-top: 8px; }
.mt-12  { margin-top: 12px; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.text-center { text-align: center; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); font-size: 14px; }
