:root {
  --bg: #0d0f14;
  --surface: #13161d;
  --surface-hover: #1a1e27;
  --border: #1e2330;
  --accent: #6c63ff;
  --accent-hover: #5a52d9;
  --accent2: #a78bfa;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.1);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.1);
  --yellow: #eab308;
  --text: #e2e8f0;
  --muted: #64748b;
  --sidebar-w: 240px;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
}
.sidebar-logo {
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.nav-links {
  list-style: none;
  padding: 16px 12px;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
  transition: .2s;
  font-weight: 500;
  margin-bottom: 4px;
}
.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.nav-link.active {
  background: rgba(108, 99, 255, 0.1);
  color: var(--accent);
}
.sidebar-footer {
  padding: 20px;
  border-top: 1px solid var(--border);
}
.user-badge {
  background: var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.logout-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: .2s;
}
.logout-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

/* --- Main Content --- */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 40px;
  max-width: 1200px;
}

.page { display: none; animation: fadeIn .3s; }
.page:not(.hidden) { display: block; }
@keyframes fadeIn { from{opacity:0; transform:translateY(10px)} to{opacity:1; transform:translateY(0)} }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}
.page-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 30px;
}
.page-header .page-title { margin-bottom: 0; }

.mt { margin-top: 30px; }

/* --- Cards & Grids --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.card h2 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top:0; left:0; width:4px; height:100%;
  background: var(--border);
}
.stat-card.accent::before { background: var(--accent); }
.stat-card.green::before { background: var(--green); }
.stat-card.purple::before { background: var(--accent2); }

.stat-value { font-size: 32px; font-weight: 700; margin-bottom: 4px; }
.stat-label { font-size: 13px; color: var(--muted); }

/* --- Tables --- */
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: none; }

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.active { background: var(--green-bg); color: var(--green); }
.badge.inactive { background: var(--red-bg); color: var(--red); }
.badge.protocol { background: var(--border); color: var(--text); }

/* --- Forms & Buttons --- */
.field { margin-bottom: 16px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-family: inherit;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.btn-row { display: flex; gap: 12px; }
.btn-primary, .btn-outline, .btn-danger, .btn-sm {
  border-radius: 8px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: .2s;
  outline: none;
}
.btn-primary {
  background: var(--accent); border: none; color: #fff; padding: 10px 20px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--text); padding: 10px 20px;
}
.btn-outline:hover { border-color: var(--muted); }
.btn-danger {
  background: transparent; border: 1px solid var(--red); color: var(--red); padding: 10px 20px;
}
.btn-danger:hover { background: var(--red-bg); }

.btn-sm { padding: 6px 12px; font-size: 12px; }

/* --- Modals --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn .2s;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 40px rgba(0,0,0,.5);
}
.modal h2 { margin-bottom: 24px; font-size: 18px; }

/* --- Toasts --- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface);
  border-left: 4px solid var(--accent);
  padding: 16px 24px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  z-index: 2000;
  transition: transform .3s, opacity .3s;
}
.toast.hidden { transform: translateX(120%); opacity: 0; }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }

/* --- Protocols Grid --- */
.protocols-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px;
}
.proto-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.proto-head { display: flex; justify-content: space-between; align-items: center; }
.proto-name { font-weight: 600; font-size: 15px; }
.proto-status { width: 10px; height: 10px; border-radius: 50%; background: var(--red); }
.proto-status.active { background: var(--green); box-shadow: 0 0 10px var(--green); }
.proto-info { font-size: 12px; color: var(--muted); }

/* --- Bots Grid --- */
.bots-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.bot-status {
  display: inline-block; padding: 4px 10px; border-radius: 20px;
  background: var(--border); font-size: 12px; margin-bottom: 20px;
}

/* --- Online Indicator --- */
.status-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--muted);
  margin-right: 8px;
  vertical-align: middle;
  opacity: 0.5;
  transition: all .3s;
}
.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  opacity: 1;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 4px var(--green); }
  50% { box-shadow: 0 0 12px var(--green); }
}

/* --- Config Modal --- */
.config-list {
  display: flex; flex-direction: column; gap: 12px;
  max-height: 60vh; overflow-y: auto;
}
.config-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.config-item .config-proto {
  font-weight: 600; font-size: 13px;
  color: var(--accent); margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: .5px;
}
.config-item .config-link {
  word-break: break-all;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
  background: rgba(0,0,0,.3);
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: .2s;
}
.config-item .config-link:hover {
  color: var(--text); background: rgba(0,0,0,.5);
}
.config-item .config-details {
  font-size: 12px; color: var(--muted);
  line-height: 1.8;
}
.config-item .config-details strong { color: var(--text); }
.btn-copy {
  background: var(--accent);
  border: none; color: #fff;
  padding: 4px 10px; border-radius: 4px;
  font-size: 11px; cursor: pointer;
  margin-top: 8px;
  transition: .2s;
}
.btn-copy:hover { background: var(--accent-hover); }

/* --- Bandwidth Bar --- */
.bw-bar {
  height: 4px; background: var(--border);
  border-radius: 2px; margin-top: 4px;
  overflow: hidden;
}
.bw-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width .5s ease;
}
.bw-text {
  font-size: 11px; color: var(--muted); margin-top: 2px;
}

/* --- Checkbox Custom --- */
.checkbox-field {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; cursor: pointer;
}
.checkbox-field input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.checkbox-field label {
  margin-bottom: 0; cursor: pointer; font-size: 13px;
}

/* --- Modal wider for configs --- */
.modal.modal-wide { max-width: 560px; }

/* --- Mobile & Responsive --- */
.mobile-header {
  display: none; /* Caché par défaut sur PC */
  position: fixed; top: 0; left: 0; right: 0;
  height: 60px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 150;
  padding: 0 20px;
  align-items: center; justify-content: space-between;
}
.header-left { display: flex; align-items: center; gap: 15px; }
.menu-toggle {
  background: transparent; border: none;
  color: var(--text); font-size: 24px; cursor: pointer;
}
.mobile-logo { font-weight: 700; font-size: 18px; color: var(--accent); }
.user-badge-top {
  font-size: 11px; background: var(--border);
  padding: 4px 8px; border-radius: 4px;
  text-transform: uppercase; color: var(--muted);
}
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 190; display: none; backdrop-filter: blur(2px);
}

/* Regles Globales Admin-Only */
body.reseller-mode .admin-only { display: none !important; }

/* --- Dropdown Menu --- */
.dropdown {
  position: relative;
  display: inline-block;
}
.dropdown-btn {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: .2s;
}
.dropdown-btn:hover {
  background: var(--border);
}
.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  min-width: 160px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  border-radius: 10px;
  z-index: 50;
  margin-top: 8px;
  overflow: hidden;
  animation: fadeIn .2s;
}
.dropdown-content.show {
  display: block;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  transition: .2s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.dropdown-item:hover {
  background: var(--surface-hover);
}
.dropdown-item.danger {
  color: var(--red);
}
.dropdown-item.danger:hover {
  background: var(--red-bg);
}
.dropdown-item i {
  font-size: 14px;
  width: 16px;
  text-align: center;
}

@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .3s ease;
    z-index: 200;
  }
  .sidebar.active { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main { margin-left: 0; padding: 80px 20px 20px 20px; }
  .mobile-header { display: flex; }
  
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 16px; }
  .table-container { overflow-x: auto; width: 100%; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 16px; }
  .modal { padding: 20px; margin: 10px; width: 95%; }
}
