:root {
  --bg: #05070A;
  --panel: #0C1017;
  --panel-border: #1B2430;
  --text: #E7EEF5;
  --muted: #6B7A8C;
  --accent: #38BDF8;
  --accent-dim: #1D7FA8;
  --accent-glow: rgba(56, 189, 248, 0.35);
  --online: #34E7B4;
  --warn: #FBBF24;
  --danger: #FB6B5B;
  --radius: 10px;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Space Grotesk', sans-serif;
  --dur: 0.2s;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.grid-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(56,189,248,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56,189,248,0.05) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black 30%, transparent 75%);
  animation: gridDrift 40s linear infinite;
}
@keyframes gridDrift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 42px 42px, 42px 42px; }
}

.screen { position: relative; z-index: 1; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.14em;
  font-size: 15px;
}
.brand span::after {
  content: '_';
  color: var(--accent);
  animation: blinkCursor 1.1s steps(1) infinite;
}
@keyframes blinkCursor {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.brand-ring {
  --size: 22px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  position: relative;
  background: conic-gradient(from 0deg, var(--accent), transparent 60%, var(--accent));
  animation: spin 3s linear infinite;
}
.brand-ring.small { --size: 18px; }
.brand-ring::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--bg);
}
.brand-core {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px 2px var(--accent-glow);
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 360px;
  padding: 36px 32px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
  box-shadow: 0 0 0 1px rgba(56,189,248,0.04), 0 20px 60px -20px rgba(0,0,0,0.6);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-sub {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
  margin: 12px 0 24px;
  letter-spacing: 0.02em;
}
#login-form label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--mono);
}
#login-form input {
  width: 100%;
  padding: 11px 12px;
  background: #080B10;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 16px;
  font-family: var(--sans);
  transition: border-color var(--dur), box-shadow var(--dur);
}
#login-form input:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.12);
}

button, .primary-btn {
  cursor: pointer;
  font-family: var(--sans);
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}

#login-form button, .add-panel button, .primary-btn {
  position: relative;
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #04141C;
  overflow: hidden;
  transition: background var(--dur), transform 0.12s;
}
#login-form button::before, .add-panel button::before {
  content: '';
  position: absolute;
  top: 0; left: -60%;
  width: 40%; height: 100%;
  background: linear-gradient(120deg, transparent, rgba(255,255,255,0.5), transparent);
  transform: skewX(-20deg);
  transition: left 0.5s ease;
}
#login-form button:hover::before, .add-panel button:hover::before { left: 130%; }
#login-form button:hover, .add-panel button:hover, .primary-btn:hover { background: #64D3FA; }
#login-form button:active, .add-panel button:active { transform: scale(0.98); }

.btn-spinner {
  display: none;
  width: 14px; height: 14px;
  border: 2px solid rgba(4,20,28,0.3);
  border-top-color: #04141C;
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.6s linear infinite;
}
button.loading .btn-label { display: none; }
button.loading .btn-spinner { display: block; }
button.loading { pointer-events: none; opacity: 0.85; }

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 10px 0 0;
  animation: shake 0.35s;
}
.error-text:empty { animation: none; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--panel-border);
  animation: rise 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.server-key {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ghost-btn {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  transition: color var(--dur), border-color var(--dur);
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent-dim); }

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  position: relative;
  z-index: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  animation: rise 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(var(--delay, 0) * 80ms);
}

.add-panel form { display: flex; gap: 10px; }
.add-panel input {
  flex: 1;
  padding: 11px 12px;
  background: #080B10;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--sans);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.add-panel input:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.12);
}
.add-panel button { padding: 11px 18px; white-space: nowrap; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-head h2 {
  font-size: 13px;
  margin: 0;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: var(--mono);
  color: var(--muted);
}
.muted { color: var(--muted); font-size: 13px; }

.empty-state { text-align: center; padding: 40px 0; color: var(--muted); }
.empty-state p:first-child { color: var(--text); font-size: 15px; margin-bottom: 6px; }

.skeleton-row {
  height: 52px;
  border-radius: 8px;
  margin-bottom: 10px;
  background: linear-gradient(100deg, #0E131B 30%, #161D28 50%, #0E131B 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -20% 0; }
}

.client-row {
  display: grid;
  grid-template-columns: 12px 1fr auto auto auto;
  align-items: center;
  gap: 16px;
  padding: 14px 8px;
  border-bottom: 1px solid var(--panel-border);
  animation: rise 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
  transition: background var(--dur);
}
.client-row:hover { background: rgba(56,189,248,0.03); }
.client-row:last-child { border-bottom: none; }
.client-row.removing {
  animation: dissolve 0.3s ease forwards;
}
@keyframes dissolve {
  to { opacity: 0; transform: scale(0.97) translateX(-6px); }
}

.status-dot { position: relative; width: 8px; height: 8px; border-radius: 50%; background: #33404F; }
.status-dot.online { background: var(--online); }
.status-dot.online::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid var(--online);
  animation: ping 1.8s cubic-bezier(0, 0, 0.2, 1) infinite;
}
@keyframes ping {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(2.2); opacity: 0; }
}

.client-info .name { font-weight: 600; font-size: 14px; }
.client-info .meta { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 2px; }

.client-actions { display: flex; gap: 8px; }
.icon-btn {
  background: #080B10;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--sans);
  transition: border-color var(--dur), color var(--dur), transform 0.1s;
}
.icon-btn:hover { border-color: var(--accent-dim); color: var(--accent); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.handshake { font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: right; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 8, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 28px;
  width: 340px;
  text-align: center;
  position: relative;
  animation: popIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-card h3 { margin: 0 0 16px; font-size: 15px; font-family: var(--mono); }
.modal-card img {
  width: 240px;
  height: 240px;
  background: white;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  transition: color var(--dur);
}
.modal-close:hover { color: var(--text); }
.modal-actions { margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }
  .grid-bg { animation: none; }
  .status-dot.online::after { display: none; }
}

@media (max-width: 560px) {
  .client-row {
    grid-template-columns: 12px 1fr;
    grid-template-areas: "dot info" ". actions" ". hs";
    row-gap: 8px;
  }
  .client-actions { grid-area: actions; }
  .handshake { grid-area: hs; text-align: left; }
}
