/* ================================
   3X-Manager Design System
   Dark Cyberpunk Theme
   Typography: Unified Sans
   ================================ */

/* ---- CSS Variables (Design Tokens) ---- */
:root {
  /* Colors */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(18, 18, 30, 0.85);
  --bg-card-hover: rgba(24, 24, 40, 0.95);
  --bg-input: rgba(10, 10, 20, 0.6);

  --border-color: rgba(100, 120, 255, 0.12);
  --border-hover: rgba(100, 180, 255, 0.3);
  --border-focus: rgba(80, 200, 255, 0.6);

  --text-primary: #e8eaf0;
  --text-secondary: #8b90a0;
  --text-muted: #555a6e;

  --accent-cyan: #50c8ff;
  --accent-blue: #5080ff;
  --accent-gradient: linear-gradient(135deg, #50c8ff 0%, #5080ff 100%);
  --accent-glow: 0 0 20px rgba(80, 200, 255, 0.15);

  --danger: #ff4466;
  --danger-glow: 0 0 15px rgba(255, 68, 102, 0.2);
  --success: #44ff88;
  --warning: #ffaa44;

  /* Typography */
  --font-ui: 'Inter', 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  --font-heading: var(--font-ui);
  --font-body: var(--font-ui);
  --font-size-xs: 0.78rem;
  --font-size-sm: 0.88rem;
  --font-size-md: 0.95rem;
  --font-size-lg: 1.05rem;
  --font-size-xl: 1.6rem;

  /* Spacing */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

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

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

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---- Background Glows ---- */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.08;
  pointer-events: none;
  z-index: 0;
}

.bg-glow-1 {
  width: 600px;
  height: 600px;
  background: var(--accent-cyan);
  top: -200px;
  right: -100px;
}

.bg-glow-2 {
  width: 500px;
  height: 500px;
  background: var(--accent-blue);
  bottom: -150px;
  left: -100px;
}

/* ---- Typography ---- */
h1,
h2,
h3,
h4 {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0;
}

h1 {
  font-size: var(--font-size-xl);
}

h2 {
  font-size: var(--font-size-lg);
}

label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

label svg {
  opacity: 0.6;
}

/* ---- Form Elements ---- */
input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-md);
  outline: none;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(80, 200, 255, 0.08);
}

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

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

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-normal);
  outline: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(80, 200, 255, 0.3);
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  font-weight: 600;
}

.btn-primary:hover {
  box-shadow: var(--accent-glow), 0 4px 12px rgba(80, 200, 255, 0.15);
  filter: brightness(1.1);
}

.btn-primary:active {
  filter: brightness(0.95);
}

.btn-accent {
  background: rgba(80, 200, 255, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(80, 200, 255, 0.25);
}

.btn-accent:hover {
  background: rgba(80, 200, 255, 0.2);
  border-color: rgba(80, 200, 255, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

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

.btn-danger {
  background: rgba(255, 68, 102, 0.15);
  color: var(--danger);
  border: 1px solid rgba(255, 68, 102, 0.3);
}

.btn-danger:hover {
  background: rgba(255, 68, 102, 0.25);
  box-shadow: var(--danger-glow);
}

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

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Spinner ---- */
.spinner {
  animation: spin 0.8s linear infinite;
}

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

/* ---- Badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  background: rgba(80, 200, 255, 0.1);
  color: var(--accent-cyan);
  border: 1px solid rgba(80, 200, 255, 0.2);
  border-radius: 20px;
  font-family: var(--font-body);
  font-size: var(--font-size-xs);
  font-weight: 500;
}

.badge-sm {
  padding: 2px 10px;
  font-size: var(--font-size-xs);
}

/* ================================
   LOGIN
   ================================ */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 40px 32px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4), var(--accent-glow);
  animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: var(--accent-gradient);
  border-radius: var(--radius-lg);
  color: #fff;
  margin-bottom: 16px;
  box-shadow: var(--accent-glow);
}

.login-header h1 {
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* ================================
   DASHBOARD
   ================================ */
.dashboard {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent-cyan);
}

.topbar-title {
  font-family: var(--font-body);
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Main Content */
.main-content {
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.content-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* Panels */
.panel {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition-normal);
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-size: var(--font-size-md);
}

.panel-header h2 svg {
  color: var(--accent-cyan);
  opacity: 0.8;
}

.panel-body {
  padding: 16px 18px;
}

/* Button Groups */
.btn-group-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.confirm-group {
  display: flex;
  gap: 6px;
}

.confirm-group .btn {
  flex: 1;
}

/* ================================
   QR CODES
   ================================ */
.qr-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.qr-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  transition: border-color var(--transition-normal);
}

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

.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

.qr-image {
  max-width: 100%;
  max-height: 310px;
  border-radius: var(--radius-sm);
}

/* ================================
   CLIENTS TABLE
   ================================ */
.table-container {
  position: relative;
  isolation: isolate;
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(80, 200, 255, 0.2) transparent;
}

.table-container::-webkit-scrollbar {
  width: 6px;
}

.table-container::-webkit-scrollbar-track {
  background: transparent;
}

.table-container::-webkit-scrollbar-thumb {
  background: rgba(80, 200, 255, 0.2);
  border-radius: 3px;
}

.table-container::-webkit-scrollbar-thumb:hover {
  background: rgba(80, 200, 255, 0.35);
}

#clients-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

#clients-table thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

#clients-table thead tr {
  background: var(--bg-secondary);
}

#clients-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  padding: 10px 16px;
  text-align: left;
  font-family: var(--font-body);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 1px 0 var(--border-color);
  z-index: 6;
  line-height: 1.3;
  background-clip: padding-box;
}

#clients-table thead th:nth-child(1) {
  width: 20%;
}

#clients-table thead th:nth-child(2) {
  width: 20%;
}

#clients-table thead th:nth-child(3) {
  width: 20%;
}

#clients-table thead th:nth-child(4) {
  width: 20%;
}

#clients-table thead th:nth-child(5) {
  width: 20%;
}

#clients-table thead th.sortable-header {
  cursor: pointer;
  user-select: none;
}

#clients-table thead th.sortable-header .th-label {
  margin-right: 6px;
}

#clients-table thead th.sortable-header .sort-indicator {
  display: inline-block;
  min-width: 10px;
  opacity: 0.5;
  font-size: 0.72em;
  vertical-align: middle;
}

#clients-table thead th.sortable-header:hover {
  color: var(--text-primary);
  background: rgba(80, 200, 255, 0.08);
}

#clients-table thead th.sorted-asc,
#clients-table thead th.sorted-desc {
  color: var(--accent-cyan);
}

#clients-table thead th.sorted-asc .sort-indicator,
#clients-table thead th.sorted-desc .sort-indicator {
  opacity: 1;
}

#clients-table tbody tr {
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid rgba(100, 120, 255, 0.05);
}

#clients-table tbody tr:hover {
  background: rgba(80, 200, 255, 0.06);
}

#clients-table tbody tr.selected {
  background: rgba(80, 200, 255, 0.1);
  border-left: 3px solid var(--accent-cyan);
}

#clients-table tbody tr.empty-row {
  cursor: default;
}

#clients-table tbody tr.empty-row:hover {
  background: transparent;
}

#clients-table tbody td {
  padding: 10px 16px;
  font-size: var(--font-size-sm);
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text-primary);
  position: relative;
  z-index: 1;
}

#clients-table thead th:nth-child(2),
#clients-table thead th:nth-child(3),
#clients-table thead th:nth-child(4),
#clients-table tbody td.traffic-cell {
  text-align: right;
}

#clients-table thead th:nth-child(5),
#clients-table tbody td:last-child {
  text-align: center;
}

#clients-table tbody td:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#clients-table tbody td.traffic-cell {
  color: var(--text-secondary);
  font-weight: 500;
}

.client-status {
  display: inline-block;
  min-width: 44px;
  text-align: center;
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.status-online {
  color: #0a2a14;
  background: rgba(68, 255, 136, 0.86);
}

.status-offline {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 0;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
}

/* ================================
   TOAST NOTIFICATIONS
   ================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  pointer-events: auto;
  animation: toastIn 0.3s ease;
  max-width: 420px;
}

.toast.toast-success {
  border-left: 3px solid var(--success);
}

.toast.toast-error {
  border-left: 3px solid var(--danger);
}

.toast.toast-info {
  border-left: 3px solid var(--accent-cyan);
}

.toast.toast-out {
  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);
  }
}

/* ================================
   RESPONSIVE
   ================================ */
@media (max-width: 1024px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}

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

  .content-grid {
    gap: 12px;
  }

  .qr-container {
    grid-template-columns: 1fr;
  }

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

  .topbar {
    padding: 10px 14px;
  }
}

@media (max-width: 375px) {
  html {
    font-size: 14px;
  }
}