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

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(17, 24, 39, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(99, 132, 255, 0.4);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  --accent-blue: #6366f1;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --accent-cyan: #06b6d4;
  --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);
  --gradient-success: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  background-image: 
    linear-gradient(rgba(99, 102, 241, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99, 102, 241, 0.03) 1px, transparent 1px);
  background-size: 50px 50px;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 400px;
  background: radial-gradient(ellipse at 50% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.screen {
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.hidden {
  display: none !important;
}

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-card);
}

.login-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--gradient-primary);
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.logo-icon svg {
  width: 20px;
  height: 20px;
}

.logo-icon.small {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
}

.logo-icon.small svg {
  width: 16px;
  height: 16px;
}

.field {
  margin-bottom: 1.25rem;
}

.field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.field input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: 0.9375rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.error-msg {
  color: var(--accent-red);
  font-size: 0.8125rem;
  margin-top: 1rem;
  text-align: center;
  padding: 0.5rem;
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius-xs);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius-xs);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--gradient-primary);
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
}

.btn-success {
  background: var(--gradient-success);
  color: #fff;
}

.btn-success:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

.btn-success:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
  box-shadow: none;
}

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

.btn-secondary:hover {
  background: rgba(99, 102, 241, 0.1);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
  box-shadow: none;
}

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

.btn-ghost:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.btn-full {
  width: 100%;
  padding: 0.75rem;
}

.btn-lg {
  padding: 0.85rem 1.75rem;
  font-size: 1rem;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

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

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Dashboard */
.dashboard {
  padding: 1.5rem 2rem 3rem;
  max-width: 1100px;
  margin: 0 auto;
}

/* Cards */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-card);
  transition: border-color 0.2s;
}

.card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3), 0 0 20px rgba(99, 102, 241, 0.1);
}

.card h2 {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* Config */
.config-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.config-row label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 500;
}

.config-row input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: border-color 0.2s;
}

.config-row input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Actions */
.actions-card {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Messages */
.msg {
  font-size: 0.8125rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-xs);
}

.msg.success {
  color: var(--accent-green);
  background: rgba(34, 197, 94, 0.1);
}

.msg.error {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.1);
}

/* Running indicator */
.running-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-color: var(--border-active);
  box-shadow: var(--shadow-glow);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--border-color);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

.running-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.running-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.running-step {
  font-size: 0.9375rem;
  color: var(--text-primary);
  font-weight: 500;
}

/* Status section */
.status-section {
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-left: 0.25rem;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.status-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  transition: border-color 0.2s, transform 0.2s;
}

.status-card:hover {
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.status-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.status-card-header h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.panel-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel-icon svg {
  width: 18px;
  height: 18px;
}

.novavps-icon {
  color: var(--accent-cyan);
  filter: drop-shadow(0 0 6px rgba(6, 182, 212, 0.6));
}

.xray-icon {
  color: var(--accent-amber);
  filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.6));
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.status-badge.idle {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
}

.status-badge.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
}

.status-badge.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

.status-detail {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.status-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Data sections */
.data-section {
  padding: 0;
  overflow: hidden;
}

.data-section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.data-section-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.data-section-header h2 {
  margin: 0;
  flex: 1;
}

.data-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.collapse-arrow {
  font-size: 0.625rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.collapse-arrow.collapsed {
  transform: rotate(-90deg);
}

.data-content {
  max-height: 1000px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.data-content.collapsed {
  max-height: 0;
}

.table-wrapper {
  overflow-x: auto;
  border-top: 1px solid var(--border-color);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table thead th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  white-space: nowrap;
}

.data-table tbody tr {
  transition: background 0.15s;
}

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

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.synced-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
}

.synced-badge.yes {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.2);
}

.synced-badge.no {
  color: var(--text-muted);
}

.synced-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.synced-badge.yes::before {
  background: var(--accent-green);
}

.synced-badge.no::before {
  background: var(--text-muted);
}

/* Latency */
.latency-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.latency-good {
  color: var(--accent-green);
}

.latency-fair {
  color: var(--accent-amber);
}

.latency-poor {
  color: var(--accent-red);
}

.latency-error {
  color: var(--text-muted);
}

/* Last run */
.last-run-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0;
  font-size: 0.8125rem;
}

.last-run-label {
  color: var(--text-muted);
}

.last-run-value {
  color: var(--text-secondary);
  font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
  .dashboard {
    padding: 1rem;
  }

  .topbar {
    padding: 0.75rem 1rem;
  }

  .config-row {
    flex-direction: column;
    align-items: stretch;
  }

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

  .data-table {
    font-size: 0.75rem;
  }

  .data-table thead th,
  .data-table tbody td {
    padding: 0.5rem 0.6rem;
  }
}
