:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --border: #e6e8ef;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #2c5cdc;
  --primary-soft: #e7eefc;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --accent: #8b5cf6;
  --accent-soft: #ede9fe;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar__brand {
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.sidebar__brand h1 {
  font-size: 16px;
  margin: 0 0 4px;
  color: var(--primary);
}
.sidebar__brand p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  cursor: pointer;
  border-left: 3px solid transparent;
  color: var(--text);
  font-weight: 500;
  user-select: none;
  font-size: 13px;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active {
  background: var(--primary-soft);
  border-left-color: var(--primary);
  color: var(--primary);
}
.nav-item__icon { font-size: 16px; width: 18px; text-align: center; }

.main {
  padding: 24px 32px 48px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.header h2 { font-size: 22px; margin: 0; }
.header__actions { display: flex; gap: 8px; align-items: center; }

select, input, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
}
button:hover { background: var(--bg); }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover { background: #244cb8; }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.sm { padding: 4px 10px; font-size: 12px; }

/* KPI Cards (top of dashboard) */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 1024px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.kpi {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.kpi__icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}
.kpi--primary .kpi__icon { background: var(--primary-soft); color: var(--primary); }
.kpi--success .kpi__icon { background: var(--success-soft); color: var(--success); }
.kpi--danger .kpi__icon { background: var(--danger-soft); color: var(--danger); }
.kpi--accent .kpi__icon { background: var(--accent-soft); color: var(--accent); }
.kpi__label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.kpi__value { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* Cards in general */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card__header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card__title { font-size: 14px; font-weight: 600; margin: 0; color: var(--text); }
.card__action { font-size: 12px; color: var(--primary); cursor: pointer; }

/* Dashboard charts row */
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 900px) { .row-2 { grid-template-columns: 1fr; } }

.donut-card {
  text-align: center;
}
.donut-card .chart-wrapper { position: relative; height: 240px; }
.donut-card__center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.donut-card__center .v { font-size: 18px; font-weight: 700; }
.donut-card__center .l { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }

.legend { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; max-height: 160px; overflow-y: auto; }
.legend__item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend__dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend__label { flex: 1; color: var(--text-muted); }
.legend__value { font-weight: 600; }

.chart-card { height: 320px; position: relative; }
.chart-card .chart-wrapper { height: 260px; position: relative; }

/* Cards row (faturas) */
.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.fatura-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.fatura-card__head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--text-muted); }
.fatura-card__valor { font-size: 16px; font-weight: 700; }
.fatura-card__venc { font-size: 11px; color: var(--text-muted); }

/* Wizard (atualização mensal) */
.wizard {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.wizard__steps { display: flex; gap: 8px; margin-bottom: 24px; flex-wrap: wrap; }
.wizard__step {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.wizard__step.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.wizard__step.done { background: var(--success-soft); color: var(--success); border-color: var(--success-soft); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 20px;
  margin-bottom: 20px;
}
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.form-grid input, .form-grid select { font-size: 14px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  margin-bottom: 16px;
  transition: all .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone p { margin: 8px 0; color: var(--text-muted); }
.dropzone strong { color: var(--primary); }

/* Tables */
.table-wrapper { overflow-x: auto; margin-top: 12px; }
table.tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.tx-table th, table.tx-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.tx-table th { font-weight: 600; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
table.tx-table tr:hover td { background: var(--bg); }
table.tx-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tx-table .neg { color: var(--danger); }
table.tx-table .pos { color: var(--success); }
table.tx-table select, table.tx-table input { padding: 4px 6px; font-size: 12px; }

/* Goals */
.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
}
.goal-card__nome { font-weight: 600; }
.goal-card__sub { font-size: 12px; color: var(--text-muted); }
.goal-card__val { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.goal-card__mes { font-size: 13px; color: var(--text-muted); }

.budget-row {
  display: flex; align-items: center; gap: 16px; margin-bottom: 14px;
  background: var(--surface); padding: 16px 20px; border-radius: var(--radius);
  border: 1px solid var(--border);
}
.budget-row label { font-size: 12px; color: var(--text-muted); }
.budget-row input[type=number] { width: 140px; }

/* Balanço */
.balanco-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) { .balanco-grid { grid-template-columns: 1fr; } }

.balanco-card { padding: 0; overflow: hidden; }
.balanco-card__head {
  padding: 14px 20px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.balanco-card__head--ativos { color: var(--success); }
.balanco-card__head--passivos { color: var(--danger); }
.balanco-card table { padding: 0 8px; }
.balanco-card .total {
  padding: 14px 20px;
  background: var(--bg);
  font-weight: 700;
  display: flex; justify-content: space-between;
  border-top: 1px solid var(--border);
}
.pl-total {
  margin-top: 16px;
  background: var(--primary);
  color: #fff;
  padding: 18px 24px;
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pl-total .l { font-size: 12px; opacity: .85; text-transform: uppercase; letter-spacing: .05em; }
.pl-total .v { font-size: 22px; font-weight: 700; }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: grid; place-items: center; z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 92%; max-width: 480px;
  box-shadow: var(--shadow-md);
}
.modal h3 { margin: 0 0 16px; }
.modal__actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Empty states */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty h3 { margin: 0 0 8px; color: var(--text); font-size: 16px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: slidein .2s;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slidein { from { transform: translateY(20px); opacity: 0; } }

/* Hide for print/export */
@media print {
  .sidebar, .header__actions, .nav-print-hidden { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .main { padding: 12px; max-width: 100%; }
}

/* Utility */
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.right { text-align: right; }
.center { text-align: center; }
.tnum { font-variant-numeric: tabular-nums; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-gap-8 { display: flex; gap: 8px; }
.space-between { display: flex; justify-content: space-between; align-items: center; }
