:root {
  --bg-main: #0b0f19;
  --bg-card: rgba(20, 26, 43, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --primary-accent: #00f2fe;
  --secondary-accent: #4facfe;
  --purple-accent: #7f00ff;
  --success: #00e676;
  --danger: #ff5252;
  --warning: #ffab00;
  --text-main: #f0f4fc;
  --text-muted: #8e9bb0;
  --radius-lg: 16px;
  --radius-md: 10px;
  --shadow-glow: 0 8px 32px 0 rgba(0, 242, 254, 0.15);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(127, 0, 255, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(0, 242, 254, 0.15) 0%, transparent 40%);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, h4, .brand {
  font-family: 'Outfit', sans-serif;
}

.hidden {
  display: none !important;
}

/* GLASS CARD */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.glass-card:hover {
  border-color: rgba(0, 242, 254, 0.25);
}

/* LOGIN OVERLAY */
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 25, 0.9);
  backdrop-filter: blur(16px);
  z-index: 1000;
}

.login-card {
  width: 100%;
  max-width: 420px;
  border-top: 3px solid var(--primary-accent);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.logo-icon {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--primary-accent), var(--purple-accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  margin: 0 auto 16px;
  box-shadow: 0 0 20px rgba(0, 242, 254, 0.4);
}

.login-header h2 {
  font-size: 24px;
  font-weight: 700;
}

.login-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}

.input-group input, .input-group select {
  width: 100%;
  padding: 12px 16px;
  background: rgba(10, 14, 23, 0.8);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.input-group input:focus, .input-group select:focus {
  border-color: var(--primary-accent);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
}

/* LINE COPY WRAPPERS */
.line-box label {
  display: block;
  font-size: 13px;
  color: var(--primary-accent);
  font-weight: 600;
  margin-bottom: 6px;
}

.line-input-wrap {
  display: flex;
  gap: 10px;
}

.line-input-wrap input {
  flex: 1;
  background: #080c16;
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: #00f2fe;
  font-family: monospace;
  font-size: 13px;
}

/* PERMISSIONS CHECKBOX GRID */
.permissions-group {
  margin-bottom: 20px;
  background: rgba(10, 14, 23, 0.5);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
}

.perm-title {
  display: block;
  font-size: 13px;
  color: var(--primary-accent);
  margin-bottom: 12px;
  font-weight: 600;
}

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

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
}

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

/* BUTTONS */
.btn {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--secondary-accent), var(--purple-accent));
  color: #fff;
  box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79, 172, 254, 0.5);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--primary-accent);
}

.btn-danger {
  background: linear-gradient(135deg, #ff5252, #ff1744);
  color: #fff;
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 82, 82, 0.4);
}

.btn-block {
  width: 100%;
  justify-content: center;
}

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

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

.sidebar {
  width: 260px;
  background: rgba(14, 19, 32, 0.95);
  border-right: 1px solid var(--bg-card-border);
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
}

.brand-icon {
  color: var(--primary-accent);
  font-size: 26px;
}

.brand small {
  font-size: 10px;
  background: var(--purple-accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}

.sidebar-nav {
  margin-top: 36px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
  color: var(--primary-accent);
  background: rgba(0, 242, 254, 0.1);
  border-left: 3px solid var(--primary-accent);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 20px;
  border-top: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-size: 13px;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}

.btn-icon:hover {
  color: var(--danger);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-title h1 {
  font-size: 26px;
  font-weight: 700;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
  background: rgba(255, 255, 255, 0.05);
}

.status-badge.active {
  color: var(--success);
  background: rgba(0, 230, 118, 0.1);
}

.status-badge.active i {
  animation: pulse 2s infinite;
}

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

.topbar-actions {
  display: flex;
  gap: 12px;
}

#activeServerSelect {
  min-width: 205px;
  background: transparent;
  color: var(--text-main);
  color-scheme: dark;
}

#activeServerSelect option {
  background-color: #111626;
  color: #f0f4fc;
}

#activeServerSelect option:checked {
  background-color: #28345a;
  color: #ffffff;
}

.mobile-menu-btn,
.mobile-sidebar-backdrop {
  display: none;
}

/* TAB CONTENT */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 20px;
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
}

.stat-icon.cpu { background: linear-gradient(135deg, #ff9900, #ff5500); }
.stat-icon.mem { background: linear-gradient(135deg, #00f2fe, #4facfe); }
.stat-icon.readers { background: linear-gradient(135deg, #7f00ff, #e100ff); }
.stat-icon.users { background: linear-gradient(135deg, #00e676, #1de9b6); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-info h3 {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary-accent);
  transition: width 0.3s ease;
}

/* TABLES */
.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  padding: 16px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--bg-card-border);
}

.data-table td {
  padding: 16px;
  border-bottom: 1px solid var(--bg-card-border);
  font-size: 14px;
}

.data-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.badge-success { background: rgba(0, 230, 118, 0.15); color: var(--success); }
.badge-secondary { background: rgba(142, 155, 176, 0.15); color: var(--text-muted); }
.badge-danger { background: rgba(255, 82, 82, 0.15); color: var(--danger); }
.badge-postgres { background: rgba(79, 172, 254, 0.15); color: var(--secondary-accent); }
.badge-reseller { background: rgba(127, 0, 255, 0.15); color: #e100ff; }

/* ONLINE BADGE GLOW */
.badge-online {
  background: rgba(0, 230, 118, 0.2);
  color: var(--success);
  border: 1px solid rgba(0, 230, 118, 0.4);
  box-shadow: 0 0 10px rgba(0, 230, 118, 0.3);
}

.badge-online i {
  animation: pulse 1.5s infinite;
}

/* TERMINAL LOGS */
.terminal-card {
  background: #060911;
  padding: 0;
  border: 1px solid #1a233b;
}

.terminal-header {
  padding: 12px 16px;
  background: #0e1424;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #1a233b;
}

.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.red { background: #ff5f56; }
.dot.yellow { background: #ffbd2e; }
.dot.green { background: #27c93f; }

.terminal-title {
  margin-left: 12px;
  font-size: 12px;
  font-family: monospace;
  color: var(--text-muted);
}

.terminal-body, .terminal-preview {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  color: #a9b7c6;
  padding: 16px;
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 500px;
}

.terminal-preview {
  max-height: 250px;
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--bg-card-border);
  margin-bottom: 0;
  flex-shrink: 0;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding-top: 16px;
  padding-bottom: 16px;
  max-height: calc(90vh - 140px);
}

.close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--bg-card-border);
  margin-top: 0;
  flex-shrink: 0;
}


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

.max-w-600 { max-width: 600px; }

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

.alert-box {
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 16px;
}

.alert-box.error {
  background: rgba(255, 82, 82, 0.15);
  color: var(--danger);
  border: 1px solid rgba(255, 82, 82, 0.3);
}

.alert-box.success {
  background: rgba(0, 230, 118, 0.15);
  color: var(--success);
  border: 1px solid rgba(0, 230, 118, 0.3);
}

.modal-lg {
  max-width: 1050px !important;
  width: 92vw;
}

.actions-cell {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px !important;
  white-space: nowrap !important;
}

.actions-cell .btn {
  padding: 6px 10px !important;
  font-size: 12px !important;
}

/* RESPONSIVE LAYOUT */
@media (max-width: 900px) {
  body.mobile-menu-open {
    overflow: hidden;
  }

  .app-container {
    display: block;
    min-height: 100dvh;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 300px);
    height: 100dvh;
    z-index: 3000;
    padding: 20px;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 16px 0 40px rgba(0, 0, 0, 0.45);
    overflow-y: auto;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(3, 6, 15, 0.72);
    backdrop-filter: blur(3px);
    z-index: 2990;
  }

  .mobile-sidebar-backdrop.active {
    display: block;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-md);
    background: rgba(14, 19, 32, 0.9);
    color: var(--text-main);
    font-size: 18px;
    cursor: pointer;
  }

  .main-content {
    width: 100%;
    min-width: 0;
    padding: 20px 16px 32px;
    overflow-x: hidden;
  }

  .topbar {
    align-items: flex-start;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
  }

  .page-title {
    flex: 1;
    min-width: 0;
  }

  .page-title h1 {
    font-size: clamp(19px, 5vw, 24px);
    line-height: 1.2;
  }

  .topbar-actions,
  .topbar-actions.superadmin-only {
    width: 100%;
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px !important;
  }

  .topbar-actions > div:first-child {
    grid-column: 1 / -1;
    min-height: 42px;
  }

  .topbar-actions .btn {
    width: 100%;
    min-width: 0;
    padding-inline: 10px;
  }

  .section-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .section-toolbar h2 {
    font-size: 20px;
    line-height: 1.25;
  }

  .section-toolbar > div {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 8px !important;
  }

  .section-toolbar > .btn,
  .section-toolbar > div > .btn {
    width: 100%;
    min-width: 0;
    white-space: normal;
    text-align: center;
    justify-content: center;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
  }

  .stat-card {
    gap: 12px;
    padding: 16px;
  }

  .stat-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
  }

  .stat-info h3 {
    font-size: 19px;
  }

  .grid-2,
  .dashboard-sections.grid-2,
  .max-w-1000.grid-2 {
    grid-template-columns: 1fr !important;
  }

  .glass-card {
    border-radius: 12px;
  }

  .filter-card > div,
  .filter-card > div > div {
    width: 100%;
    align-items: stretch !important;
    flex-direction: column;
  }

  .filter-card .search-wrap,
  .filter-card select,
  .filter-card input {
    width: 100% !important;
    min-width: 0 !important;
  }

  #userCountBadge,
  #modalUserCountBadge {
    width: 100%;
    text-align: left;
    padding-top: 4px;
  }

  .table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .data-table {
    min-width: 760px;
  }

  .data-table th,
  .data-table td {
    padding: 12px;
    white-space: nowrap;
  }

  .actions-cell {
    position: sticky;
    right: 0;
    background: #15172a;
    box-shadow: -8px 0 12px rgba(8, 10, 20, 0.35);
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card,
  .modal-lg {
    width: 100% !important;
    max-width: none !important;
    max-height: 94dvh;
    border-radius: 18px 18px 0 0;
    padding: 18px 16px;
  }

  .modal-body {
    max-height: calc(94dvh - 135px);
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1 1 140px;
    justify-content: center;
  }

  .card-header[style*="justify-content: space-between"] {
    align-items: stretch !important;
    flex-direction: column;
    gap: 12px;
  }

  .card-header[style*="justify-content: space-between"] > div {
    display: grid !important;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .card-header[style*="justify-content: space-between"] .btn {
    width: 100%;
    justify-content: center;
  }

  .login-overlay {
    padding: 14px;
  }

  .login-card {
    padding: 26px 20px;
  }
}

@media (max-width: 520px) {
  .main-content {
    padding: 16px 12px 28px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .section-toolbar > div,
  .topbar-actions,
  .topbar-actions.superadmin-only {
    grid-template-columns: 1fr;
  }

  .topbar-actions > div:first-child {
    grid-column: 1;
  }

  .data-table {
    min-width: 700px;
  }

  .btn {
    min-height: 42px;
  }
}
