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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #ef4444;
  --success: #22c55e;
  --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,0.1), 0 1px 2px rgba(0,0,0,0.06);
}

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

.hidden { display: none !important; }

/* Login */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--gray-500);
  margin-bottom: 24px;
}

/* Layout */
#admin-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--gray-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-700);
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.nav-list {
  list-style: none;
  flex: 1;
  padding: 8px 0;
}

.nav-link {
  display: block;
  padding: 10px 20px;
  color: var(--gray-300);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover, .nav-link.active {
  background: var(--gray-800);
  color: #fff;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-700);
}

.main-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

.page-section h2 {
  font-size: 22px;
  margin-bottom: 20px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 4px;
}

.stat-card .stat-detail {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 2px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--gray-700);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

textarea { resize: vertical; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}

.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 { opacity: 0.9; }

.btn-ghost { background: transparent; color: var(--gray-300); border: 1px solid var(--gray-600); }
.btn-ghost:hover { background: var(--gray-800); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }

/* Tables */
.table-container {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
  font-size: 14px;
}

th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-600);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--gray-50); }

/* Search */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-bar input { max-width: 320px; }

/* Pagination */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}

.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
}

.pagination button:hover { background: var(--gray-100); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination span { color: var(--gray-500); font-size: 14px; }

/* Messages */
.error-message {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 12px;
}

.success-message {
  color: var(--success);
  font-size: 14px;
  margin-bottom: 12px;
}

/* Section header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-header h2 { margin-bottom: 0; }

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 24px;
  cursor: pointer;
  color: var(--gray-400);
}

.modal-close:hover { color: var(--gray-600); }

.modal-content h3 { margin-bottom: 20px; }

/* Dashboard extras */
.dashboard-extras {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.dashboard-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.dashboard-card h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--gray-700);
}

.dashboard-card .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.dashboard-card .stat-row .label { color: var(--gray-500); }
.dashboard-card .stat-row .value { font-weight: 600; }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fce4ec; color: #c62828; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0e7ff; color: #3730a3; }
.badge-free { background: #f3f4f6; color: #6b7280; }
.badge-pro { background: #fef3c7; color: #92400e; font-weight: 600; }
.badge-pro::before { content: '⭐ '; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar input { max-width: 240px; }
.filter-bar select { width: auto; min-width: 140px; }

/* Avatar */
.avatar {
  display: inline-flex;
  width: 32px; height: 32px;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 600;
}

/* Actions cell */
.actions-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* Pro button */
.btn-pro { background: #f59e0b; color: #fff; }
.btn-pro:hover { background: #d97706; }

.btn-warning { background: #f59e0b; color: #fff; }
.btn-warning:hover { background: #d97706; }

/* User detail grid */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.detail-section h4 {
  font-size: 14px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-200);
}
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}
.detail-row span:first-child {
  color: var(--gray-500);
}
.detail-row span:last-child {
  font-weight: 500;
  text-align: right;
}

/* Modal sizes */
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 720px; }

/* Modal actions */
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Links in table */
td a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
td a:hover { text-decoration: underline; }

@media (max-width: 768px) {
  #admin-layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-extras { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
}
