* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --primary-light: #a78bfa;
  --bg: #0f0f17;
  --bg-2: #1a1a26;
  --bg-3: #252535;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --border: #2e2e3e;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,0.3);
}
html, body {
  font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.6;
}
body {
  background: radial-gradient(ellipse at top, #1a1638 0%, #0f0f17 50%);
  min-height: 100vh;
}
a { color: var(--primary-light); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

.loading { padding: 80px 20px; text-align: center; color: var(--text-muted); }

/* ====== Auth Pages ====== */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.auth-card h1 {
  font-size: 32px;
  text-align: center;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  font-weight: 900;
}
.auth-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 14px;
}
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-3);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
}
.tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 8px;
  transition: all .18s cubic-bezier(0.23, 1, 0.32, 1);
  font-weight: 500;
}
.tab.active { background: var(--primary); color: #fff; }

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  transition: border-color .15s ease-out;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.field textarea { resize: vertical; min-height: 80px; }
.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  transition: transform .16s cubic-bezier(0.23, 1, 0.32, 1), background .15s ease-out;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-2); }
.btn-danger { background: var(--error); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid transparent;
}
.alert-error { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.3); color: #fca5a5; }
.alert-success { background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.3); color: #6ee7b7; }
.alert-info { background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.3); color: #93c5fd; }
.alert-warning { background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.3); color: #fcd34d; }

/* ====== Layout ====== */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  font-size: 22px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}
.sidebar .role-badge {
  display: inline-block;
  font-size: 11px;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 8px;
  margin-bottom: 22px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
  transition: background .15s ease-out, color .15s ease-out;
  cursor: pointer;
  user-select: none;
}
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .icon { width: 20px; text-align: center; }

.main { padding: 24px 28px; max-width: 100%; overflow-x: hidden; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title { font-size: 24px; font-weight: 800; }
.page-subtitle { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

/* Cards / Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-card .label { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 800; }
.stat-card.primary .value { color: var(--primary-light); }
.stat-card.success .value { color: var(--success); }
.stat-card.warning .value { color: var(--warning); }

.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.card-title { font-size: 17px; font-weight: 700; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td {
  padding: 12px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
th { color: var(--text-muted); font-weight: 600; background: var(--bg-3); }
tr:hover { background: rgba(124, 58, 237, 0.03); }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}
.badge-pending { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-active { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-suspended, .badge-error, .badge-banned { background: rgba(239, 68, 68, 0.15); color: var(--error); }
.badge-expired { background: rgba(161, 161, 170, 0.15); color: var(--text-muted); }
.badge-running, .badge-online { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-stopped, .badge-idle { background: rgba(161, 161, 170, 0.15); color: var(--text-muted); }
.badge-starting, .badge-connecting { background: rgba(59, 130, 246, 0.15); color: var(--info); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; font-size: 19px; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

/* Bot type select */
.bot-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.bot-type-card {
  background: var(--bg-3);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all .18s cubic-bezier(0.23, 1, 0.32, 1);
}
.bot-type-card:hover { border-color: var(--primary-light); transform: translateY(-2px); }
.bot-type-card.selected { border-color: var(--primary); background: rgba(124, 58, 237, 0.1); }
.bot-type-card .emoji { font-size: 32px; margin-bottom: 6px; }
.bot-type-card .title { font-weight: 700; }
.bot-type-card .desc { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.list-add {
  display: flex; gap: 6px; margin-bottom: 8px;
}
.list-item-row {
  display: flex; gap: 6px; margin-bottom: 6px; align-items: center;
}
.list-item-row input { flex: 1; }

/* WhatsApp FAB */
.whatsapp-fab {
  position: fixed; bottom: 18px; left: 18px;
  width: 56px; height: 56px;
  background: #25d366; color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(37, 211, 102, 0.4);
  z-index: 50; position: relative;
  transition: transform .18s cubic-bezier(0.23, 1, 0.32, 1);
}
.whatsapp-fab:hover { transform: scale(1.08); }
.whatsapp-fab:active { transform: scale(0.95); }

/* Toast */
.toast-container {
  position: fixed; top: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: toastIn .25s cubic-bezier(0.23, 1, 0.32, 1);
}
.toast-success { border-color: var(--success); color: #6ee7b7; }
.toast-error { border-color: var(--error); color: #fca5a5; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* Mobile */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; right: 0;
    width: 84%; max-width: 280px;
    height: 100%;
    z-index: 100;
    transform: translateX(100%);
    transition: transform .25s cubic-bezier(0.23, 1, 0.32, 1);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    display: none;
  }
  .sidebar-overlay.show { display: block; }
  .menu-btn {
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 16px;
  }
  .main { padding: 16px; }
  .page-title { font-size: 20px; }
  .stat-card .value { font-size: 22px; }
  .auth-card { padding: 28px 22px; }
  .auth-card h1 { font-size: 26px; }
}
@media (min-width: 769px) {
  .menu-btn { display: none; }
}
