/* ==========================================
   COMPTON VPN — CSS Design System
   Premium Dark Glassmorphism Theme
   ========================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* === CSS Variables === */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(20, 20, 35, 0.7);
  --bg-card-hover: rgba(30, 30, 50, 0.8);
  --bg-input: rgba(15, 15, 25, 0.8);
  --bg-glass: rgba(255, 255, 255, 0.03);
  
  --border-primary: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --border-accent: rgba(139, 92, 246, 0.3);
  
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --text-accent: #a78bfa;
  
  --accent-purple: #8b5cf6;
  --accent-purple-dim: rgba(139, 92, 246, 0.15);
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-green-dim: rgba(16, 185, 129, 0.15);
  --accent-red: #ef4444;
  --accent-red-dim: rgba(239, 68, 68, 0.15);
  --accent-orange: #f59e0b;
  --accent-orange-dim: rgba(245, 158, 11, 0.15);
  --accent-cyan: #06b6d4;
  
  --gradient-purple: linear-gradient(135deg, #8b5cf6, #6d28d9);
  --gradient-blue: linear-gradient(135deg, #3b82f6, #1d4ed8);
  --gradient-green: linear-gradient(135deg, #10b981, #059669);
  --gradient-red: linear-gradient(135deg, #ef4444, #dc2626);
  --gradient-hero: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 50%, #06b6d4 100%);
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow-purple: 0 0 20px rgba(139, 92, 246, 0.2);
  --shadow-glow-green: 0 0 20px rgba(16, 185, 129, 0.2);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s ease;
  
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Animated background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(ellipse 800px 600px at 20% 20%, rgba(139, 92, 246, 0.08), transparent),
    radial-gradient(ellipse 600px 400px at 80% 80%, rgba(59, 130, 246, 0.06), transparent),
    radial-gradient(ellipse 400px 300px at 50% 50%, rgba(6, 182, 212, 0.04), transparent);
  z-index: -1;
  animation: bgPulse 15s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.7; }
}

/* === Login Screen === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-box {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

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

.login-logo h1 {
  font-size: 2rem;
  font-weight: 900;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.login-logo p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 8px;
  letter-spacing: 1px;
}

.login-logo .gun-emoji {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.4));
}

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

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font-main);
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px var(--accent-purple-dim);
}

.form-input::placeholder {
  color: var(--text-muted);
}

textarea.form-input {
  resize: vertical;
  min-height: 100px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), transparent);
  pointer-events: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--gradient-purple);
  color: white;
  box-shadow: var(--shadow-glow-purple);
}

.btn-primary:hover {
  box-shadow: 0 0 30px rgba(139, 92, 246, 0.35);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--gradient-green);
  color: white;
  box-shadow: var(--shadow-glow-green);
}

.btn-success:hover {
  box-shadow: 0 0 30px rgba(16, 185, 129, 0.35);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--gradient-red);
  color: white;
}

.btn-danger:hover {
  box-shadow: 0 0 30px rgba(239, 68, 68, 0.3);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}

.btn-ghost:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--bg-glass);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  padding: 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}

.btn-icon:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--bg-glass);
}

/* === Layout === */
.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-primary);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 8px 12px;
  margin-bottom: 32px;
}

.sidebar-brand h2 {
  font-size: 1.3rem;
  font-weight: 900;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.sidebar-brand .version {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 1px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
  border-color: var(--border-primary);
}

.nav-item.active {
  color: var(--text-accent);
  background: var(--accent-purple-dim);
  border-color: var(--border-accent);
}

.nav-item .nav-icon {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
}

.nav-item .nav-badge {
  margin-left: auto;
  background: var(--accent-purple-dim);
  color: var(--text-accent);
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-primary);
}

.sidebar-footer .nav-item {
  color: var(--text-muted);
}

/* === Main Content === */
.main-content {
  padding: 32px 40px;
  max-width: 1200px;
}

.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* === Cards === */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all var(--transition-normal);
}

.card:hover {
  border-color: var(--border-hover);
}

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

.card-header h3 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header .card-icon {
  font-size: 1.3rem;
}

/* === Stat Cards Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 24px;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-normal);
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
}

.stat-card.purple::before { background: var(--gradient-purple); }
.stat-card.blue::before { background: var(--gradient-blue); }
.stat-card.green::before { background: var(--gradient-green); }
.stat-card.orange::before { 
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.stat-card .stat-icon {
  font-size: 2rem;
  margin-bottom: 12px;
}

.stat-card .stat-value {
  font-size: 2.2rem;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 8px;
  font-family: var(--font-mono);
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* === Tables === */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
}

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

th {
  padding: 14px 16px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  text-align: left;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border-primary);
}

td {
  padding: 14px 16px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-primary);
  vertical-align: middle;
}

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

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* === Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.badge-success {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.badge-error {
  background: var(--accent-red-dim);
  color: var(--accent-red);
}

.badge-warning {
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
}

.badge-info {
  background: var(--accent-purple-dim);
  color: var(--accent-purple);
}

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* === Modals === */
.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: 1000;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: 32px;
  width: 100%;
  max-width: 520px;
  transform: translateY(20px) scale(0.95);
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
}

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

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color var(--transition-fast);
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* === Toasts / Notifications === */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease forwards;
  min-width: 280px;
  max-width: 400px;
}

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.warning { border-left: 3px solid var(--accent-orange); }

.toast.removing {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* === Copy Button === */
.copy-field {
  display: flex;
  gap: 8px;
  align-items: center;
}

.copy-field input {
  flex: 1;
}

.copy-btn {
  flex-shrink: 0;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.85rem;
  max-width: 300px;
  margin: 0 auto 20px;
}

/* === Loading Spinner === */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-secondary);
}

/* === Actions Bar === */
.actions-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.actions-bar .spacer {
  flex: 1;
}

/* === Section Tabs === */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px;
  border-radius: var(--radius-md);
  width: fit-content;
}

.tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  background: var(--accent-purple-dim);
  color: var(--text-accent);
}

/* === Sub Link Display === */
.sub-link-display {
  background: var(--bg-input);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent-cyan);
  word-break: break-all;
  position: relative;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* === Selection === */
::selection {
  background: rgba(139, 92, 246, 0.3);
  color: white;
}

/* === Mobile Menu Button === */
/* На десктопе скрыт, в media (max-width: 768px) превращается в inline-flex.
   min-w/h 44px — touch-target гайдлайны Apple/Material. */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 101;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 1.2rem;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

/* === Sidebar Backdrop (mobile only) ===
   Полупрозрачный фон поверх .main-content когда сайдбар открыт. Кликом
   закрывает sidebar. На десктопе всегда невидим (видимость управляется
   только классом .show, который JS ставит лишь при открытии sidebar — а
   sidebar открывается только на мобилке через .mobile-menu-btn). */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.sidebar-backdrop.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* === Responsive: Mobile (≤768px) === */
@media (max-width: 768px) {
  /* === Layout === */
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: -280px;
    width: 260px;
    z-index: 100;
    transition: left var(--transition-normal);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    left: 0;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  /* На странице подписчиков ранее снимали max-width у main-content, чтобы
     9-колоночная таблица не задыхалась. На мобилке таблица превращается в
     карточки → max-width не нужен в принципе. */
  .main-content,
  .main-content:has(#page-users:not(.hidden)) {
    padding: 68px 14px 24px;
    max-width: 100%;
  }

  /* === Page header === */
  .page-header {
    margin-bottom: 20px;
  }
  .page-header h1 {
    font-size: 1.35rem;
  }
  .page-header p {
    font-size: 0.85rem;
  }

  /* === Stats === */
  .stats-grid,
  .stats-grid.stats-grid-wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 20px;
  }
  .stat-card {
    padding: 16px 14px;
  }
  .stat-card .stat-icon {
    font-size: 1.6rem;
    margin-bottom: 8px;
  }
  .stat-card .stat-value {
    font-size: 1.7rem;
  }
  .stat-card .stat-label {
    font-size: 0.7rem;
    letter-spacing: 0.5px;
  }

  /* === Cards === */
  .card {
    padding: 18px 16px;
  }
  .card-header {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
  }
  .card-header h3 {
    font-size: 0.95rem;
  }
  .content-grid {
    gap: 14px;
  }
  .dashboard-meta-grid,
  .quick-actions-grid {
    grid-template-columns: 1fr;
  }

  /* === Actions bar === */
  .actions-bar {
    gap: 8px;
  }
  .actions-bar .spacer {
    display: none;
  }
  .actions-bar > .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }

  /* === Forms === */
  .form-group {
    margin-bottom: 14px;
  }
  .form-group label {
    font-size: 0.72rem;
  }
  /* font-size: 16px на input/select предотвращает auto-zoom на iOS Safari
     при фокусе. min-height: 44px — touch-target гайдлайн. */
  .form-input,
  select.form-input {
    font-size: 16px;
    min-height: 44px;
    padding: 12px 14px;
  }
  textarea.form-input {
    font-size: 14px;
    min-height: 110px;
  }
  .form-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* === Buttons === */
  .btn {
    min-height: 44px;
  }
  .btn.btn-sm {
    min-height: 36px;
    font-size: 0.78rem;
  }
  .btn.btn-icon {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
    font-size: 1.05rem;
  }
  .btn.btn-mini {
    min-width: 32px;
    min-height: 32px;
  }

  /* === Tabs === */
  .tabs,
  .keys-tabs {
    width: 100%;
    flex-wrap: wrap;
  }
  .tab,
  .keys-tab {
    flex: 1 1 0;
    text-align: center;
    justify-content: center;
    padding: 10px 14px;
  }

  /* ==================================================================
     Tables → Cards (Mobile-first)
     ==================================================================
     Таблицы на мобилке превращаются в вертикальные карточки:
       - thead скрываем целиком
       - tr становится отдельной карточкой (border, padding, glassmorphism)
       - td → flex column с подписью через ::before { content: attr(data-label) }
       - td.td-actions → footer карточки с grid-сеткой кнопок
     На вход требуется: <td data-label="Заголовок">…</td>
     Ячейка действий должна иметь class="td-actions" и НЕ иметь data-label. */
  .table-wrapper {
    border: none;
    border-radius: 0;
    overflow-x: visible;
    background: transparent;
  }

  /* Перебиваем table-layout: fixed и фиксированные width:X% колонок,
     которые задаются для users-таблицы на десктопе (см. блок #usersTableContainer
     ниже в файле, lines 2230-2282). */
  .table-wrapper table,
  #usersTableContainer table {
    table-layout: auto;
    width: 100%;
  }
  .table-wrapper thead,
  #usersTableContainer thead {
    display: none;
  }
  .table-wrapper tbody,
  .table-wrapper tr,
  .table-wrapper td,
  #usersTableContainer tbody,
  #usersTableContainer tr,
  #usersTableContainer td {
    display: block;
    width: auto !important;
  }

  .table-wrapper tr {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    padding: 14px 14px 0;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition-fast);
  }
  .table-wrapper tr:hover {
    border-color: var(--border-hover);
  }
  .table-wrapper tr:hover td,
  .table-wrapper tr td {
    background: transparent;
  }

  .table-wrapper td {
    padding: 10px 0;
    border-bottom: 1px dashed var(--border-primary);
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.88rem;
    overflow-wrap: anywhere;
    word-break: break-word;
    vertical-align: top;
  }
  .table-wrapper td::before {
    content: attr(data-label);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 700;
    color: var(--text-muted);
    line-height: 1.4;
  }
  /* td без data-label (например td.td-actions) — без подписи */
  .table-wrapper td:not([data-label])::before {
    content: '';
    display: none;
  }
  .table-wrapper td:last-child {
    border-bottom: none;
  }

  /* Footer-блок карточки — кнопки действий растягиваются в grid-сетку */
  .table-wrapper td.td-actions {
    margin: 8px -14px 0;
    padding: 12px 14px;
    border-top: 1px solid var(--border-primary);
    border-bottom: none;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }
  .table-wrapper td.td-actions .table-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
    gap: 8px;
  }
  .table-wrapper td.td-actions .table-actions .btn-icon {
    width: 100%;
    min-height: 44px;
  }

  /* Доноры: URL-ячейка теперь без эллипсиса, переносится по словам */
  .donor-url {
    max-width: none;
    white-space: normal;
    word-break: break-all;
    font-size: 0.78rem;
  }

  /* Users: traffic-cell сбрасываем фиксированную ширину (она нужна
     только в табличном layout на десктопе) */
  #usersTableContainer .traffic-cell,
  .traffic-cell {
    min-width: 0;
    max-width: none;
  }

  /* ==================================================================
     Modals → Bottom Sheet
     ================================================================== */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  /* На мобилке модалка прилипает снизу: full-width, скруглённые верхние
     углы, max-height 92dvh (с fallback на 92vh для старых iOS).
     dvh — dynamic viewport units, корректно учитывают address bar Safari. */
  .modal,
  .modal.modal-lg,
  .modal.modal-xl {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 0 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
  }
  .modal-overlay.active .modal {
    transform: translateY(0);
  }

  /* form внутри modal становится flex column на всю свободную высоту,
     чтобы margin-top:auto на .modal-actions прижимал кнопки к низу даже
     в коротких формах. */
  .modal > form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  /* Sticky header с drag-handle сверху для bottom-sheet feel */
  .modal-header {
    position: sticky;
    top: 0;
    z-index: 5;
    margin: 0 -16px 14px;
    padding: 18px 16px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
  }
  .modal-header::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.18);
  }
  .modal-header h2 {
    font-size: 1.05rem;
    padding-right: 44px;
  }
  .modal-close {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.6rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
  }

  /* Sticky-footer с кнопками. margin-top: auto тянет к низу form,
     env(safe-area-inset-bottom) — учёт home-indicator на iOS.
     column-reverse: основная кнопка (Создать/Сохранить) сверху, отмена внизу
     — соответствует мобильным гайдлайнам (главное действие у большого пальца). */
  .modal-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: auto -16px 0;
    padding: 14px 16px max(14px, env(safe-area-inset-bottom));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    flex-direction: column-reverse;
    gap: 10px;
  }
  .modal-actions .btn {
    width: 100%;
  }

  /* === Devices modal: устройства в столбик === */
  .device-card {
    flex-direction: column;
    gap: 10px;
  }
  .device-card > div {
    width: 100%;
    min-width: 0;
  }
  .device-card .btn-icon {
    align-self: flex-end;
  }

  /* === Sub-link display: ссылка переносится === */
  .sub-link-display {
    font-size: 0.78rem;
    padding: 14px 12px;
  }

  /* === Acc-key-row (keys по донорам) — переносим элементы === */
  .acc-key-row {
    flex-wrap: wrap;
    padding: 12px 14px 12px 38px;
    gap: 8px;
  }
  .acc-key-name {
    flex: 1 1 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .acc-key-host {
    display: inline;
  }
  .acc-donor-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .acc-donor-name {
    flex: 1 1 60%;
  }

  /* === Sub-order-row (моя подписка) === */
  .sub-order-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .sub-order-name {
    flex: 1 1 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .sub-order-brand {
    display: inline;
  }

  /* === Toasts === */
  .toast-container {
    bottom: 16px;
    right: 12px;
    left: 12px;
  }
  .toast {
    min-width: 0;
    max-width: 100%;
  }

  /* === Quick-actions grid сразу 1 колонка на мобилке === */
  .quick-actions-grid {
    grid-template-columns: 1fr;
  }
}

/* === Responsive: Narrow phones (≤480px) === */
@media (max-width: 480px) {
  .actions-bar > .btn {
    flex: 1 1 100%;
  }
  /* На очень узких — не более 4 кнопок-икон в ряд, но min 56px остаётся */
  .table-wrapper td.td-actions .table-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .modal-header h2 {
    font-size: 1rem;
  }
}

/* === Responsive: Tiny phones (≤400px) === */
@media (max-width: 400px) {
  .stats-grid,
  .stats-grid.stats-grid-wide {
    grid-template-columns: 1fr;
  }
  .main-content,
  .main-content:has(#page-users:not(.hidden)) {
    padding: 64px 12px 20px;
  }
  .stat-card .stat-value {
    font-size: 1.55rem;
  }
  .page-header h1 {
    font-size: 1.25rem;
  }
}

/* === Donor Card Inline === */
.donor-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.donor-url {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-count {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
}

/* === Toggle Switch === */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  transition: all var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent-purple);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* === Animations for page transitions === */
.page-section {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Action buttons in tables */
.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Grid for content sections */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

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

/* Quick info block */
.info-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
}

.info-block .info-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
}

.info-block .info-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-primary);
  word-break: break-all;
}

.compact-info {
  padding: 14px 16px;
  min-height: 52px;
  justify-content: center;
}

.compact-info .info-value {
  font-family: var(--font-main);
  font-size: 0.88rem;
  line-height: 1.5;
}

.node-advanced-toolbar {
  display: flex;
  justify-content: flex-start;
  margin: 4px 0 14px;
}

/* Hide class */
.hidden {
  display: none !important;
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, 
    rgba(255,255,255,0.03) 25%, 
    rgba(255,255,255,0.08) 50%, 
    rgba(255,255,255,0.03) 75%
  );
  background-size: 200% 100%;
  animation: skeleton 1.5s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   KEYS PAGE — Remnawave-inspired Futuristic Design
   ============================================================ */

/* === Keys Statistics Panel === */
.keys-stats-panel {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.keys-stat-item {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 16px 24px;
  min-width: 100px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-normal);
}

.keys-stat-item:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.keys-stat-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}

.keys-stat-total::before {
  background: var(--gradient-hero);
}

.keys-stat-donors::before {
  background: var(--gradient-green);
}

.keys-stat-proto::before {
  background: var(--gradient-purple);
}

.keys-stat-number {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 6px;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.keys-stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* === Protocol Badges === */
.proto-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.proto-vless {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border-color: rgba(139, 92, 246, 0.25);
  text-shadow: 0 0 10px rgba(139, 92, 246, 0.3);
}

.route-mode-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: 106px;
  flex-shrink: 0;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.18);
}

.route-mode-btn {
  min-width: 0;
  border: none;
  border-radius: 4px;
  padding: 5px 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 800;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.route-mode-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.route-mode-btn.active.lte {
  background: rgba(255, 176, 32, 0.18);
  color: var(--accent-orange);
}

.route-mode-btn.active.wifi {
  background: rgba(0, 212, 255, 0.16);
  color: var(--accent-cyan);
}

.route-badge {
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  white-space: nowrap;
}

.route-badge-lte {
  color: var(--accent-orange);
  background: rgba(255, 176, 32, 0.12);
}

.route-badge-wifi {
  color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.12);
}

/* === V2 Additions === */
.stat-card.cyan::before {
  background: linear-gradient(135deg, #06b6d4, #0891b2);
}

/* Capacity-подсветка для Proton Slots: warning при близости к лимиту,
   danger при переполнении (LRU-вытеснение начнётся на следующем VIP). */
.stat-card.warning::before {
  background: linear-gradient(135deg, var(--accent-orange), #d97706);
}
.stat-card.warning .stat-value {
  color: var(--accent-orange);
}
.stat-card.danger::before {
  background: linear-gradient(135deg, var(--accent-red), #b91c1c);
}
.stat-card.danger .stat-value {
  color: var(--accent-red);
}

/* Amnezia-строка под именем юзера в таблице. Очень мелкий шрифт, муто-цвет,
   моноширинный exit_ip — чтобы IP не «прыгал» в табличной вёрстке. */
.user-amnezia-line {
  margin-top: 2px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.user-amnezia-line .user-amnezia-iface,
.user-amnezia-line .user-amnezia-ip {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  overflow-wrap: anywhere;
  word-break: break-all;
}
.user-amnezia-line.user-amnezia-pending {
  color: #94a3b8;
  font-style: italic;
}
.user-amnezia-line.user-amnezia-down {
  color: var(--accent-orange);
}

/* Идёт хендшейк недавно, RX/TX капают — VIP реально использует туннель.
   Зелёный, чтобы админ visually filter'ил и не трогал. */
.user-amnezia-line.user-amnezia-active {
  color: var(--accent-green, #22c55e);
}

/* Хендшейк давно / нет вообще / трафик нулевой — кандидат на release.
   Жёлто-янтарный, в одном тоне с `.user-amnezia-down` чтобы не делать
   радугу из четырёх состояний, но чуть приглушеннее и курсивом для
   визуального отличия от «туннель опущен». */
.user-amnezia-line.user-amnezia-idle {
  color: var(--accent-warning, #d97706);
  font-style: italic;
}

.badge-muted {
  background: rgba(148, 163, 184, 0.12);
  color: #94a3b8;
}

.stats-grid-wide {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.dashboard-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.quick-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
  background: rgba(0, 0, 0, 0.15);
}

.mode-row strong {
  font-family: var(--font-mono);
  font-size: 1rem;
}

.muted-copy {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.7;
}

.modal-lg {
  max-width: 760px;
}

.modal-xl {
  max-width: 980px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

.form-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.form-hint {
  margin-top: 4px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
  background: rgba(0, 0, 0, 0.16);
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.6;
}

.table-primary {
  font-weight: 600;
  color: var(--text-primary);
}

.table-secondary {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

.user-tg-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent-cyan, #29b6f6);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

.user-tg-link:hover,
.user-tg-link:focus-visible {
  color: var(--accent-cyan-hover, #4fc3f7);
  border-bottom-color: currentColor;
}

.user-tg-link-id {
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: 0.02em;
  opacity: 0.85;
}

.traffic-cell {
  min-width: 168px;
  max-width: 220px;
}

.traffic-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  line-height: 1.1;
}

.traffic-percent {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-primary);
}

.traffic-label {
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.traffic-remaining {
  margin-top: 4px;
  color: #cffafe;
  font-size: 0.84rem;
  font-weight: 700;
}

.traffic-detail {
  margin-top: 6px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.45;
}

.traffic-bar {
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
}

.traffic-bar-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-green));
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.28);
  transition: width var(--transition-normal);
}

.traffic-bar-muted .traffic-bar-fill {
  background: rgba(255, 255, 255, 0.18);
  box-shadow: none;
}

.traffic-cell-unlimited .traffic-percent {
  color: #c4b5fd;
}

.traffic-cell-pending .traffic-remaining,
.traffic-cell-unlimited .traffic-remaining {
  color: var(--text-primary);
}

.mono {
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.muted-small {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.info-banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(6, 182, 212, 0.18);
  background: rgba(6, 182, 212, 0.08);
  color: #67e8f9;
  font-size: 0.85rem;
}

.devices-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.device-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
  background: rgba(0, 0, 0, 0.15);
}

.keys-stat-of {
  margin-left: 4px;
  font-size: 1rem;
  opacity: 0.8;
}

select.form-input {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

@media (max-width: 900px) {
  .dashboard-meta-grid,
  .quick-actions-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.proto-unknown {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border-color: rgba(255, 255, 255, 0.08);
}

/* === Keys Tabs === */
.keys-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: rgba(0, 0, 0, 0.25);
  padding: 4px;
  border-radius: var(--radius-md);
  width: fit-content;
}

.keys-tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 8px;
}

.keys-tab:hover {
  color: var(--text-primary);
}

.keys-tab.active {
  background: var(--accent-purple-dim);
  color: var(--text-accent);
}

.keys-tab-badge {
  background: var(--accent-purple);
  color: white;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.keys-stat-of {
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.5;
}

/* === Donor Accordion === */
.acc-donor {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color var(--transition-normal);
}

.acc-donor:hover {
  border-color: var(--border-hover);
}

.acc-donor-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}

.acc-donor-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.acc-arrow {
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.acc-donor.open .acc-arrow {
  transform: rotate(90deg);
}

.acc-donor-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acc-donor-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-purple);
  background: var(--accent-purple-dim);
  padding: 3px 10px;
  border-radius: 99px;
  flex-shrink: 0;
}

.acc-donor-actions {
  flex-shrink: 0;
}

.acc-donor-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.acc-donor.open .acc-donor-body {
  max-height: 9999px;
}

/* === Accordion Key Row === */
.acc-key-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px 8px 42px;
  border-top: 1px solid rgba(255, 255, 255, 0.03);
  transition: background var(--transition-fast);
  min-height: 40px;
}

.acc-key-row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.acc-key-selected {
  background: rgba(139, 92, 246, 0.04);
}

.acc-key-selected:hover {
  background: rgba(139, 92, 246, 0.07);
}

/* Custom checkbox */
.acc-key-check {
  position: relative;
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.acc-key-check input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.acc-checkmark {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-hover);
  border-radius: 4px;
  background: transparent;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.acc-checkmark::after {
  content: '✓';
  font-size: 0.65rem;
  color: white;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.acc-key-check input:checked + .acc-checkmark {
  background: var(--accent-purple);
  border-color: var(--accent-purple);
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.3);
}

.acc-key-check input:checked + .acc-checkmark::after {
  opacity: 1;
}

.acc-key-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acc-key-host {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.08);
  padding: 1px 6px;
  border-radius: 3px;
  flex-shrink: 0;
  display: none;
}

@media (min-width: 900px) {
  .acc-key-host {
    display: inline;
  }
}

.acc-key-branded {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-purple);
  flex-shrink: 0;
}

/* === Subscription Order List === */
.sub-order-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sub-order-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.sub-order-row:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
}

.sub-order-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
  min-width: 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.sub-order-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub-order-brand {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-purple);
  background: var(--accent-purple-dim);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(139, 92, 246, 0.12);
  flex-shrink: 0;
  display: none;
}

@media (min-width: 900px) {
  .sub-order-brand {
    display: inline;
  }
}

.sub-order-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Drag Handle */
.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
  transition: all var(--transition-fast);
  user-select: none;
  flex-shrink: 0;
}

.drag-handle:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.drag-handle:active {
  cursor: grabbing;
}

/* Drag States */
.sub-order-row.dragging {
  opacity: 0.35;
  border-color: var(--accent-purple);
}

.sub-order-row.drag-over-above {
  border-top: 2px solid var(--accent-cyan);
  margin-top: -1px;
}

.sub-order-row.drag-over-below {
  border-bottom: 2px solid var(--accent-cyan);
  margin-bottom: -1px;
}

/* Inline Rename Input */
.brand-edit-input {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-purple);
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid var(--accent-purple);
  border-radius: 4px;
  padding: 3px 8px;
  outline: none;
  min-width: 180px;
  max-width: 260px;
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.2);
}

.brand-edit-input:focus {
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.35);
}

/* Make brand span look editable */
.sub-order-brand {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-purple);
  background: var(--accent-purple-dim);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(139, 92, 246, 0.12);
  flex-shrink: 0;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sub-order-brand:hover {
  border-color: var(--accent-purple);
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.15);
}

/* Mini buttons for remove */
.btn-mini {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-main);
  flex-shrink: 0;
}

.btn-mini:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn-mini:disabled {
  opacity: 0.25;
  cursor: default;
}

.btn-mini:active:not(:disabled) {
  transform: scale(0.92);
}

.btn-mini-danger:hover:not(:disabled) {
  background: var(--accent-red-dim);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--accent-red);
}

/* === Nodes Catalog === */
.protocol-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
}

.protocol-summary-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-glass);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
}

.protocol-summary-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.protocol-summary-of {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-left: 4px;
}

.protocol-summary-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  font-weight: 600;
}

.protocol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.protocol-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.protocol-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, transparent, transparent);
  transition: background var(--transition-normal);
}

.protocol-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.protocol-card-active {
  border-color: rgba(16, 185, 129, 0.25);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.04) 0%, var(--bg-card) 100%);
}

.protocol-card-active::before {
  background: var(--gradient-green);
}

.protocol-card-disabled {
  opacity: 0.7;
  border-color: rgba(245, 158, 11, 0.2);
}

.protocol-card-disabled::before {
  background: linear-gradient(90deg, var(--accent-orange), #d97706);
}

.protocol-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.protocol-card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  flex: 1;
}

.protocol-card-description {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.protocol-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--bg-glass);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
}

.protocol-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
}

.protocol-meta-label {
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

.protocol-meta-value {
  color: var(--text-primary);
  font-weight: 600;
}

.protocol-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
  background: rgba(139, 92, 246, 0.05);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
}

.protocol-stats-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
}

.protocol-stats-value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.protocol-stats-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.protocol-error {
  padding: 8px 12px;
  background: var(--accent-red-dim);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  color: var(--accent-red);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  line-height: 1.4;
}

.protocol-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 8px;
}

.protocol-create-btn {
  flex: 1;
  min-height: 38px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.protocol-actions .btn {
  flex: 1;
  min-width: 0;
}

@media (max-width: 600px) {
  .protocol-grid {
    grid-template-columns: 1fr;
  }
  .protocol-stats {
    grid-template-columns: 1fr 1fr;
  }
  .protocol-stats-item:last-child {
    grid-column: span 2;
  }
}

/* === Subscribers table layout =================================================
   Цели:
     1. Убрать горизонтальный скроллбар: длинный токен и tg-ссылка не должны
        распирать колонку «Пользователь».
     2. Контент в ячейках переносится по словам (not посимвольно!), бейджи
        и заголовки остаются читаемыми, кнопки действий wrap'аются вниз.
     3. На широких экранах таблица занимает всю доступную ширину справа от
        sidebar, потому что 9 колонок в 1200px max-width задыхаются.
   Селектор привязан к #usersTableContainer, чтобы не задеть таблицы доноров,
   ключей и узлов (у них своя ширина и свои колонки). */

/* На странице подписчиков снимаем max-width у main-content: 9-колоночная
   таблица слишком тесная при 1120px. На остальных страницах (Дашборд,
   Доноры, Узлы, Ключи) max-width: 1200px остаётся. */
.main-content:has(#page-users:not(.hidden)) {
  max-width: none;
}

#usersTableContainer table {
  table-layout: fixed;
  width: 100%;
}

/* Заголовки таблицы — однострочные. Без этого при table-layout:fixed
   узкие колонки разбивали 'Статус' → 'С Т А Т У С' посимвольно. */
#usersTableContainer th {
  white-space: nowrap;
}

/* Бейджи внутри подписчиков переносятся по словам, а не по буквам.
   'Relay Backends Unavailable' рендерится в 3 строки внутри pill'а,
   но 'hybrid' не превращается в 'h y b r i d'. */
#usersTableContainer .badge {
  white-space: normal;
  word-break: keep-all;
  text-align: left;
  line-height: 1.3;
}

#usersTableContainer th:nth-child(1),  /* Статус */
#usersTableContainer td:nth-child(1) { width: 9%; }
#usersTableContainer th:nth-child(2),  /* Пользователь */
#usersTableContainer td:nth-child(2) { width: 24%; }
#usersTableContainer th:nth-child(3),  /* Режим */
#usersTableContainer td:nth-child(3) { width: 6%; }
#usersTableContainer th:nth-child(4),  /* Node */
#usersTableContainer td:nth-child(4) { width: 11%; }
#usersTableContainer th:nth-child(5),  /* Трафик */
#usersTableContainer td:nth-child(5) { width: 13%; }
#usersTableContainer th:nth-child(6),  /* Онлайн */
#usersTableContainer td:nth-child(6) { width: 7%; }
#usersTableContainer th:nth-child(7),  /* Устройства */
#usersTableContainer td:nth-child(7) { width: 7%; }
#usersTableContainer th:nth-child(8),  /* Послед. доступ */
#usersTableContainer td:nth-child(8) { width: 9%; }
#usersTableContainer th:nth-child(9),  /* Действия */
#usersTableContainer td:nth-child(9) { width: 14%; }

/* Сужаем .traffic-cell внутри подписчиков: при table-layout:fixed колонка
   получает 13%, и фиксированный min-width: 168px уже не нужен — иначе он
   снова распирает таблицу на узких десктопах. */
#usersTableContainer .traffic-cell {
  min-width: 0;
  max-width: none;
}

/* Действия: иконки-кнопки умеют wrap (см. .table-actions выше). Чуть
   уменьшаем padding, чтобы 6 иконок поместились в 2 строки в 14% колонке. */
#usersTableContainer .table-actions .btn-icon {
  padding: 7px;
}
