:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --border: #e2e4e9;
  --text-primary: #1a1d23;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #15803d;
  --green-bg: #ecf9ef;
  --amber: #b45309;
  --amber-bg: #fef6e6;
  --red: #b91c1c;
  --red-bg: #fdecec;
  --gray-bg: #f1f2f4;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }

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

.sidebar {
  width: 220px;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  flex-shrink: 0;
}

.sidebar .brand {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 4px;
}

.sidebar nav a:hover { background: var(--gray-bg); }
.sidebar nav a.active { background: #e8f0fe; color: var(--primary-dark); font-weight: 500; }

.main {
  flex: 1;
  padding: 2rem 2.5rem;
  max-width: 1200px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.topbar h1 { font-size: 20px; font-weight: 600; }

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}

.btn:hover { background: var(--gray-bg); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { color: var(--red); border-color: #f3c9c9; }
.btn-danger:hover { background: var(--red-bg); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---------- Cards / metrics ---------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 1.75rem;
}

.metric {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
}

.metric .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.metric .value { font-size: 22px; font-weight: 600; }
.metric .sub { font-size: 11px; margin-top: 4px; color: var(--text-muted); }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 1rem;
}

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
td { padding: 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gray { background: var(--gray-bg); color: var(--text-secondary); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-field label { font-size: 12px; color: var(--text-secondary); }
.form-field input, .form-field select, .form-field textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text-primary);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* ---------- Progress bars ---------- */
.progress-bar { height: 6px; background: var(--gray-bg); border-radius: 3px; overflow: hidden; min-width: 70px; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--green); }
.progress-fill.over { background: var(--red); }
.progress-fill.warn { background: var(--amber); }

/* ---------- Alerts ---------- */
.alert-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 10px;
}
.alert-overdue { background: var(--red-bg); color: var(--red); }
.alert-budget { background: var(--amber-bg); color: var(--amber); }

/* ---------- Login page ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 360px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
}
.login-card h1 { font-size: 18px; margin-bottom: 1.5rem; text-align: center; }
.error-msg { color: var(--red); font-size: 13px; margin-top: 10px; text-align: center; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 420px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal h2 { font-size: 16px; margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 1rem; }

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mb-0 { margin-bottom: 0 !important; }

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .main { padding: 1.25rem; }
  .form-grid { grid-template-columns: 1fr; }
}
