:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f8fafc;
  --card: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
button { cursor: pointer; font-family: inherit; }
input, select, textarea {
  font-family: inherit; font-size: 14px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: #0f172a; color: #cbd5e1;
  padding: 20px 0; flex-shrink: 0;
}
.sidebar .brand { padding: 0 20px 20px; font-weight: 700; font-size: 18px; color: #fff; border-bottom: 1px solid #1e293b; min-height: 56px; display: flex; align-items: center; justify-content: center; text-align: center; }
.sidebar .empresa-sel { padding: 12px 16px; border-bottom: 1px solid #1e293b; }
.sidebar .empresa-sel select { background: #1e293b; color: #fff; border-color: #334155; }
.sidebar nav { padding: 12px 0; }
.sidebar nav button {
  display: flex; align-items: center; width: 100%; text-align: left; padding: 10px 20px;
  background: none; border: none; color: #cbd5e1; font-size: 14px;
}
.sidebar nav button[disabled] { opacity: .4; cursor: not-allowed; }
.sidebar nav button:hover { background: #1e293b; color: #fff; }
.sidebar nav button.active { background: var(--primary); color: #fff; }
.sidebar .user-box { padding: 12px 20px; border-top: 1px solid #1e293b; margin-top: auto; font-size: 12px; }
.sidebar .user-box button { background: none; border: none; color: #94a3b8; padding: 4px 0; font-size: 12px; }

.main { flex: 1; padding: 24px 32px; overflow-x: auto; }
.main h1 { margin: 0 0 16px; font-size: 22px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi .value.danger { color: var(--danger); }
.kpi .value.success { color: var(--success); }

.btn { padding: 8px 14px; border: none; border-radius: 6px; font-size: 14px; font-weight: 500; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; background: #fff; }
th { text-align: left; padding: 10px 12px; background: #f1f5f9; font-size: 12px; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: #f8fafc; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 500; text-transform: capitalize; }
.badge.aberto    { background: #dbeafe; color: #1e40af; }
.badge.pago, .badge.recebido { background: #dcfce7; color: #166534; }
.badge.vencido   { background: #fee2e2; color: #991b1b; }
.badge.cancelado { background: #f1f5f9; color: #475569; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 8px; padding: 24px; width: 90%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.modal-tabs button { background: none; border: none; padding: 10px 16px; color: var(--muted); font-size: 14px; border-bottom: 2px solid transparent; }
.modal-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.modal-tabs button[disabled] { opacity: .4; cursor: not-allowed; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.login-card { background: #fff; padding: 32px; border-radius: 12px; width: 100%; max-width: 380px; box-shadow: 0 10px 25px rgba(0,0,0,.2); }
.login-card h1 { margin: 0 0 8px; text-align: center; font-size: 24px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 13px; }
.login-card label { display: block; margin-bottom: 12px; font-size: 13px; }
.login-card label span { display: block; margin-bottom: 4px; color: var(--muted); }
.login-card .btn { width: 100%; margin-top: 12px; }
.login-card .err { color: var(--danger); margin-top: 8px; font-size: 13px; text-align: center; }

.empty { text-align: center; padding: 40px; color: var(--muted); }

@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar .brand, .sidebar .empresa-sel, .sidebar nav button span, .sidebar .user-box { display: none; }
  .main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
