/* === CSS Variables === */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --white: #ffffff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Navigation === */
.nav {
  background: var(--gray-900);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 56px;
  box-shadow: var(--shadow);
}
.nav-brand {
  color: var(--white);
  font-weight: 700;
  font-size: 1.15rem;
  margin-right: 2rem;
}
.nav-links { display: flex; gap: 0.25rem; flex: 1; }
.nav-links a {
  color: var(--gray-300);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover, .nav-links a.active {
  background: rgba(255,255,255,0.1);
  color: var(--white);
  text-decoration: none;
}
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.nav-user { color: var(--gray-300); font-size: 0.85rem; }
.nav-right .btn-sm {
  background: transparent;
  color: var(--gray-300);
  border: 1px solid var(--gray-500);
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: var(--radius);
}
.nav-right .btn-sm:hover { background: rgba(255,255,255,0.1); color: var(--white); }

/* === Layout === */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.section { margin-bottom: 2rem; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.section-header h2 { font-size: 1.2rem; font-weight: 600; }

/* === Dashboard Cards === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card-label { font-size: 0.8rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.05em; }
.card-value { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }
.card.alert { border-left: 4px solid var(--danger); }
.card.alert .card-value { color: var(--danger); }

/* === Tables === */
.table-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.75rem 1rem; font-size: 0.9rem; }
th { background: var(--gray-50); color: var(--gray-500); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 2px solid var(--gray-200); }
td { border-bottom: 1px solid var(--gray-100); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }
.empty-row td { text-align: center; color: var(--gray-500); padding: 2rem; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-group { display: flex; gap: 0.5rem; }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--gray-700); margin-bottom: 0.3rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--white);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
}
.login-box h1 { text-align: center; margin-bottom: 0.25rem; }
.login-box p { text-align: center; color: var(--gray-500); margin-bottom: 1.5rem; font-size: 0.9rem; }

/* === Modals === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--gray-500);
  padding: 0.25rem;
}
.modal-close:hover { color: var(--gray-900); }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-draft { background: var(--gray-200); color: var(--gray-700); }
.badge-sent { background: #dbeafe; color: #1e40af; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-user { background: var(--gray-100); color: var(--gray-700); }
.badge-low { background: #fee2e2; color: #991b1b; }

/* === Alerts === */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* === Responsive === */
@media (max-width: 768px) {
  .nav { flex-wrap: wrap; height: auto; padding: 0.75rem; }
  .nav-links { order: 3; width: 100%; margin-top: 0.5rem; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .modal { margin: 1rem; max-width: calc(100% - 2rem); }
}
