:root {
  --bg-deep: #0a0e17;
  --bg-panel: rgba(15, 20, 32, 0.85);
  --bg-card: rgba(22, 28, 45, 0.6);
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 179, 237, 0.5);
  --text: #e8edf5;
  --text-muted: #7a8499;
  --accent: #3b9eff;
  --accent-glow: rgba(59, 158, 255, 0.35);
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --terminal-bg: #0d1117;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Consolas', monospace;
  --sidebar-w: 320px;
  --metrics-w: 300px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-deep);
}

/* Background effects */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 50%, black 20%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
}

.bg-glow--1 {
  width: 500px;
  height: 500px;
  top: -10%;
  right: 10%;
  background: rgba(59, 158, 255, 0.12);
}

.bg-glow--2 {
  width: 400px;
  height: 400px;
  bottom: -5%;
  left: 20%;
  background: rgba(139, 92, 246, 0.08);
}

/* Layout */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
  padding: 16px;
  gap: 16px;
}

/* Workspace */
.workspace {
  flex: 1;
  display: flex;
  gap: 16px;
  min-width: 0;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  min-height: 0;
  overflow: hidden;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.logo {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.logo svg {
  width: 22px;
  height: 22px;
  color: white;
}

.sidebar__brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar__brand p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.connect-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-section--grow {
  flex: 1;
}

.form-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-section:first-child {
  width: 90px;
  flex-shrink: 0;
}

input,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 158, 255, 0.15);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

textarea {
  resize: vertical;
  min-height: 100px;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
}

.input-group {
  position: relative;
}

.input-group input {
  padding-left: 38px;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.input-icon svg {
  width: 16px;
  height: 16px;
}

/* Auth tabs */
.tabs {
  display: flex;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: rgba(59, 158, 255, 0.2);
  color: var(--accent);
}

.auth-panel.hidden {
  display: none;
}

/* Connect button */
.btn-connect {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-connect:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px var(--accent-glow);
}

.btn-connect:active:not(:disabled) {
  transform: translateY(0);
}

.btn-connect:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-loader {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.sidebar__footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition), box-shadow var(--transition);
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.6);
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-dot.error {
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Metrics panel */
.metrics-panel {
  width: var(--metrics-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  overflow-y: auto;
}

.metrics-panel__head h2 {
  font-size: 0.95rem;
  font-weight: 600;
}

.metrics-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
  margin-bottom: 12px;
}

.metric-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.metric-card__label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.metric-card__label strong {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
}

.chart-wrap {
  position: relative;
  height: 72px;
}

.chart-wrap--short {
  height: 64px;
}

.net-legend {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.net-legend__item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dot-legend {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-legend--rx {
  background: #3b9eff;
}

.dot-legend--tx {
  background: #a78bfa;
}

/* Terminal area */
.terminal-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.terminal-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.window-controls {
  display: flex;
  gap: 7px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dot--red { background: #ff5f57; }
.dot--yellow { background: #febc2e; }
.dot--green { background: #28c840; }

.terminal-title {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.terminal-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-btn:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.15);
}

.icon-btn--danger:hover {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.3);
}

.terminal-wrapper {
  flex: 1;
  position: relative;
  background: var(--terminal-bg);
  overflow: hidden;
}

#terminal {
  width: 100%;
  height: 100%;
  padding: 8px 4px;
}

#terminal .xterm {
  height: 100%;
}

#terminal .xterm-viewport {
  overflow-y: auto !important;
}

.terminal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(4px);
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 10;
}

.terminal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
  padding: 32px;
}

.overlay-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 158, 255, 0.1);
  border: 1px solid rgba(59, 158, 255, 0.2);
  border-radius: 16px;
  color: var(--accent);
}

.overlay-icon svg {
  width: 32px;
  height: 32px;
}

.overlay-content h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.overlay-content p {
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 280px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  padding: 12px 18px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: slideIn 0.3s ease;
  backdrop-filter: blur(12px);
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
}

.toast.success {
  border-color: rgba(52, 211, 153, 0.4);
  color: #a7f3d0;
}

.toast.info {
  border-color: rgba(59, 158, 255, 0.4);
  color: #bfdbfe;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 1200px) {
  .workspace {
    flex-direction: column;
  }

  .metrics-panel {
    width: 100%;
    max-height: 280px;
  }

  .metric-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
}

@media (max-width: 900px) {
  .app {
    flex-direction: column;
    padding: 12px;
  }

  .sidebar {
    width: 100%;
    max-height: 42vh;
  }

  .terminal-area {
    min-height: 40vh;
  }

  .metric-cards {
    grid-template-columns: 1fr;
  }
}
