:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;

  --pago: #16a34a;
  --pendente: #d97706;
  --vencido: #dc2626;
  --agendado: #2563eb;
  --cancelado: #6b7280;
  --recebido: #16a34a;
  --a-receber: #d97706;
  --atrasado: #dc2626;
  --parcial: #2563eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 24px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  background: var(--surface);
  color: var(--text);
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.error-msg {
  color: var(--vencido);
  font-size: 13px;
  margin: -8px 0 16px;
}

/* ---- App shell ---- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: #111827;
  color: #d1d5db;
  padding: 20px 12px;
  flex-shrink: 0;
}

.sidebar h2 {
  color: white;
  font-size: 16px;
  margin: 0 0 4px;
  padding: 0 8px;
}
.sidebar .user-info {
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 20px;
  padding: 0 8px;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  color: #d1d5db;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 500;
  margin-bottom: 4px;
}
.nav-item:hover { background: #1f2937; }
.nav-item.active { background: var(--primary); color: white; }

.main {
  flex: 1;
  padding: 24px 32px;
  overflow-x: auto;
}

.main h1 {
  font-size: 22px;
  margin: 0 0 20px;
}

.view { display: none; }
.view.active { display: block; }

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 16px;
  border: 1px solid var(--border);
}
.kpi-card .label { font-size: 12px; color: var(--muted); }
.kpi-card .value { font-size: 22px; font-weight: 700; margin-top: 6px; }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 16px;
  border: 1px solid var(--border);
}
.chart-card h3 { margin: 0 0 12px; font-size: 14px; }

/* Toolbar */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: flex-end;
}
.toolbar .field { min-width: 140px; }
.toolbar label { margin-bottom: 4px; }
.toolbar input, .toolbar select { margin-bottom: 0; }

/* Table */
.table-wrap {
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: white;
}
.status-Pago, .status-Recebido { background: var(--pago); }
.status-Pendente { background: var(--pendente); }
.status-A_receber { background: var(--a-receber); }
.status-Vencido { background: var(--vencido); }
.status-Atrasado { background: var(--atrasado); }
.status-Agendado { background: var(--agendado); }
.status-Parcial { background: var(--parcial); }
.status-Cancelado { background: var(--cancelado); }

.row-actions button { margin-right: 6px; font-size: 12px; padding: 6px 10px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 12px; padding: 24px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.hidden { display: none !important; }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; display: flex; overflow-x: auto; gap: 4px; }
  .sidebar h2, .sidebar .user-info { display: none; }
  .nav-item { white-space: nowrap; }
  .main { padding: 16px; }
}
