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

:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100vh;
}

/* ---- Login ---- */
#login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.login-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 2.5rem; width: 100%; max-width: 400px;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: .25rem; }
.login-card p { color: var(--gray-500); margin-bottom: 1.5rem; font-size: .875rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .375rem; color: var(--gray-700); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: .5rem .75rem; border: 1px solid var(--gray-300);
  border-radius: var(--radius); font-size: .875rem; outline: none;
  transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.login-error { color: var(--danger); font-size: .875rem; margin-bottom: 1rem; }
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .5rem 1rem; border-radius: var(--radius); font-size: .875rem;
  font-weight: 500; cursor: pointer; border: none; transition: background .15s;
  text-decoration: none; gap: .375rem;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: .375rem .625rem; font-size: .8125rem; }
.btn-block { width: 100%; }

/* ---- Layout ---- */
#app-layout { display: flex; min-height: 100vh; }
#sidebar {
  width: 240px; background: var(--gray-900); color: #fff;
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
  height: 100vh; overflow-y: auto;
}
#sidebar .brand { padding: 1rem 1.25rem; font-size: 1.125rem; font-weight: 700; border-bottom: 1px solid var(--gray-700); }
#sidebar nav { flex: 1; padding: .5rem 0; }
#sidebar nav a {
  display: flex; align-items: center; gap: .5rem;
  padding: .625rem 1.25rem; color: var(--gray-400); text-decoration: none;
  font-size: .875rem; transition: all .15s;
}
#sidebar nav a:hover, #sidebar nav a.active { background: var(--gray-800); color: #fff; }
#sidebar nav a.active { border-left: 3px solid var(--primary); }
#sidebar .sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--gray-700); }
#sidebar .sidebar-footer .user-info { font-size: .8125rem; color: var(--gray-400); margin-bottom: .5rem; }
#sidebar .sidebar-footer a { color: var(--gray-400); text-decoration: none; font-size: .8125rem; }
#sidebar .sidebar-footer a:hover { color: #fff; }
#main-content { margin-left: 240px; flex: 1; padding: 1.5rem; min-height: 100vh; }

/* ---- Page header ---- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-header h2 { font-size: 1.25rem; font-weight: 600; }

/* ---- Table ---- */
.table-wrapper { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-toolbar { display: flex; align-items: center; gap: .75rem; padding: 1rem; border-bottom: 1px solid var(--gray-200); }
.table-toolbar input, .table-toolbar select { padding: .375rem .625rem; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: .8125rem; outline: none; }
.table-toolbar input:focus, .table-toolbar select:focus { border-color: var(--primary); }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--gray-50); }
th { text-align: left; padding: .75rem 1rem; font-size: .75rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--gray-200); }
td { padding: .75rem 1rem; font-size: .875rem; border-bottom: 1px solid var(--gray-100); }
tr:hover td { background: var(--gray-50); }
.actions { display: flex; gap: .375rem; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--gray-400); }

/* ---- Pagination ---- */
.pagination { display: flex; align-items: center; justify-content: center; gap: .375rem; padding: 1rem; }
.pagination button { padding: .375rem .75rem; border: 1px solid var(--gray-300); border-radius: var(--radius); background: #fff; cursor: pointer; font-size: .8125rem; color: var(--gray-700); }
.pagination button:hover:not(:disabled) { background: var(--gray-100); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .info { font-size: .8125rem; color: var(--gray-500); margin-left: .5rem; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; border-bottom: 1px solid var(--gray-200); }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-header button { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--gray-400); padding: .25rem; }
.modal-body { padding: 1.5rem; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; padding: 1rem 1.5rem; border-top: 1px solid var(--gray-200); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-error { color: var(--danger); font-size: .8125rem; margin-top: .75rem; }
.form-success { color: var(--success); font-size: .8125rem; margin-top: .75rem; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: .125rem .5rem; border-radius: 9999px; font-size: .75rem; font-weight: 500; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ---- Loading ---- */
.loading { display: flex; align-items: center; justify-content: center; padding: 3rem; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Dashboard ---- */
.dash-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.dash-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; display: flex; flex-direction: column; gap: .25rem; position: relative; overflow: hidden; }
.dash-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.dash-card--blue::before { background: #3b82f6; }
.dash-card--green::before { background: #22c55e; }
.dash-card--amber::before { background: #f59e0b; }
.dash-card--purple::before { background: #8b5cf6; }
.dash-card--cyan::before { background: #06b6d4; }
.dash-card--rose::before { background: #f43f5e; }
.dash-card-icon { width: 20px; height: 20px; }
.dash-card--blue .dash-card-icon { color: #3b82f6; }
.dash-card--green .dash-card-icon { color: #22c55e; }
.dash-card--amber .dash-card-icon { color: #f59e0b; }
.dash-card--purple .dash-card-icon { color: #8b5cf6; }
.dash-card--cyan .dash-card-icon { color: #06b6d4; }
.dash-card--rose .dash-card-icon { color: #f43f5e; }
.dash-card-label { font-size: .75rem; text-transform: uppercase; color: var(--gray-500); font-weight: 600; letter-spacing: .05em; text-align: center; }
.dash-card-value { font-size: 2rem; font-weight: 700; text-align: right; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  #sidebar { width: 100%; height: auto; position: relative; }
  #main-content { margin-left: 0; }
  #app-layout { flex-direction: column; }
  .form-row { grid-template-columns: 1fr; }
}
