:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --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;
  --sidebar-w: 260px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.08);
}

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

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

/* LOGIN ========================================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.login-container { width: 100%; max-width: 420px; }

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 25px 50px rgba(0,0,0,.25);
}

.login-logo {
  text-align: center;
  margin-bottom: 8px;
}

.login-logo .brand-icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 28px;
  margin-bottom: 12px;
}

.login-card h1 { font-size: 22px; font-weight: 700; text-align: center; }
.login-card p { color: var(--gray-500); font-size: 14px; text-align: center; margin-bottom: 28px; }

/* LAYOUT ========================================= */
.admin-container { display: flex; min-height: 100vh; }

/* SIDEBAR ======================================= */
.sidebar {
  width: var(--sidebar-w);
  background: var(--gray-900);
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 200;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand .brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-brand .brand-text { line-height: 1.2; }
.sidebar-brand .brand-text strong { display: block; font-size: 15px; font-weight: 700; }
.sidebar-brand .brand-text small { font-size: 11px; color: var(--gray-400); font-weight: 400; }

.sidebar-nav {
  padding: 12px 10px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav .nav-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gray-500);
  padding: 16px 12px 6px;
  font-weight: 600;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--gray-400);
  text-decoration: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
}

.sidebar-nav a .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.sidebar-nav a.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.sidebar-nav a.logout {
  margin-top: auto;
  color: var(--gray-500);
  border-top: 1px solid rgba(255,255,255,.06);
  padding-top: 14px;
  margin-top: 8px;
}

.sidebar-nav a.logout:hover { color: var(--danger); background: rgba(239,68,68,.1); }

/* MAIN ========================================== */
.admin-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-header {
  background: #fff;
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}

.admin-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-900);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--gray-500);
  font-size: 13px;
}

.header-right .admin-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
}

.admin-content {
  padding: 28px 32px;
  flex: 1;
}

/* MESSAGES ====================================== */
.messages { margin-bottom: 20px; }

.message {
  padding: 12px 16px 12px 44px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  position: relative;
  line-height: 1.4;
}

.message::before {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
}

.message-success {
  background: var(--success-bg);
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.message-success::before { content: '✓'; }

.message-error {
  background: var(--danger-bg);
  color: #991b1b;
  border: 1px solid #fecaca;
}
.message-error::before { content: '✕'; }

.message-info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}
.message-info::before { content: 'ℹ'; }

/* STATS ========================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 16px;
  border: 1px solid var(--gray-100);
  transition: box-shadow .2s;
}

.stat-card:hover { box-shadow: var(--shadow-lg); }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.yellow { background: var(--warning-bg); color: var(--warning); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }

.stat-info { flex: 1; }
.stat-label { font-size: 12px; color: var(--gray-500); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--gray-900); line-height: 1.2; }
.stat-sub { font-size: 12px; color: var(--gray-400); margin-top: 2px; }

/* DASHBOARD GRID ================================= */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

@media (max-width: 1100px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* CARDS ========================================= */
.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--gray-800);
}

.card-header .card-action {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

/* TABLES ======================================== */
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table thead { border-bottom: 2px solid var(--gray-100); }

.table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-500);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}

.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}

.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--gray-50); }

.table td code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--gray-700);
}

/* BADGES ======================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-paid, .badge-active, .badge-valid { background: var(--success-bg); color: #065f46; }
.badge-paid::before, .badge-active::before, .badge-valid::before { background: var(--success); }

.badge-pending { background: var(--warning-bg); color: #92400e; }
.badge-pending::before { background: var(--warning); }

.badge-expired, .badge-used, .badge-inactive { background: var(--danger-bg); color: #991b1b; }
.badge-expired::before, .badge-used::before, .badge-inactive::before { background: var(--danger); }

.badge-disconnected { background: var(--gray-100); color: var(--gray-600); }
.badge-disconnected::before { background: var(--gray-400); }

/* FILTER BAR ===================================== */
.filter-bar {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--gray-100);
  border-radius: 8px;
  margin-bottom: 16px;
}

.filter-bar a {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  text-decoration: none;
  transition: all .15s;
}

.filter-bar a.active {
  background: #fff;
  color: var(--gray-900);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

/* TOOLBAR ======================================== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

/* STATS MINI ===================================== */
.stats-mini {
  display: flex;
  gap: 24px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--gray-500);
}

.stats-mini span strong { color: var(--gray-800); }

/* FORMS ========================================= */
.form { max-width: 720px; }

.form-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
}

.form-card h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-100);
}

.form-group { margin-bottom: 18px; }

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

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="color"],
.form-group input[type="tel"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--gray-800);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.form-group textarea { min-height: 80px; resize: vertical; }

.form-group small {
  display: block;
  color: var(--gray-400);
  font-size: 11px;
  margin-top: 4px;
}

.form-group .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
}

.form-group .checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--gray-100);
}

/* BUTTONS ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
  line-height: 1.4;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(99,102,241,.35); }

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover { background: #059669; }

.btn-danger {
  background: var(--danger-bg);
  color: #991b1b;
}
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { display: flex; width: 100%; justify-content: center; }

/* PAGINATION ===================================== */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 24px;
}

.pagination a, .pagination span {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--gray-600);
  text-decoration: none;
  background: #fff;
  border: 1px solid var(--gray-200);
  transition: all .15s;
}

.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* MODAL ========================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: #fff;
  padding: 32px;
  border-radius: 16px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 25px 50px rgba(0,0,0,.25);
  animation: modal-in .2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-box h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }

/* UTILITIES ====================================== */
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-400); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* RESPONSIVE ===================================== */
@media (max-width: 768px) {
  :root { --sidebar-w: 220px; }
  .admin-content { padding: 20px; }
  .admin-header { padding: 0 20px; }
  .form-row { flex-direction: column; gap: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .sidebar { width: 64px; }
  .sidebar .brand-text { display: none; }
  .sidebar .nav-label { display: none; }
  .sidebar .nav-text { display: none; }
  .sidebar-nav a { justify-content: center; padding: 12px; }
  .sidebar-nav a .nav-icon { margin: 0; }
  .admin-main { margin-left: 64px; }
  .stats-grid { grid-template-columns: 1fr; }
  .admin-content { padding: 16px; }
  .admin-header { padding: 0 16px; }
  .filter-bar { flex-wrap: wrap; }
}
