:root {
  --bg-primary: #0a0e17;
  --bg-surface: #111827;
  --bg-surface-elevated: #1a2333;
  --bg-surface-hover: #222e44;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.2);
  --accent-amber: #f59e0b;
  --accent-amber-glow: rgba(245, 158, 11, 0.2);
  --accent-rose: #ef4444;
  --accent-rose-glow: rgba(239, 68, 68, 0.2);
  --accent-indigo: #6366f1;
  --accent-indigo-hover: #4f46e5;
  --accent-indigo-glow: rgba(99, 102, 241, 0.25);
  --accent-cyan: #06b6d4;

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

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* App Header */
.app-header {
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.logo-badge {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 0 16px var(--accent-emerald-glow);
}

.logo-badge svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
  transition: background var(--transition-fast);
}

.pulse-dot.ready {
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulse 2s infinite;
}

.pulse-dot.needs_qr {
  background: var(--accent-amber);
  box-shadow: 0 0 8px var(--accent-amber);
  animation: pulse 1.5s infinite;
}

.pulse-dot.loading {
  background: var(--accent-indigo);
  box-shadow: 0 0 8px var(--accent-indigo);
  animation: pulse 1s infinite;
}

.pulse-dot.error {
  background: var(--accent-rose);
  box-shadow: 0 0 8px var(--accent-rose);
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Primary Button */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: var(--accent-indigo);
  color: white;
  box-shadow: 0 2px 10px var(--accent-indigo-glow);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-indigo-hover);
  transform: translateY(-1px);
}

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

.btn-outline:hover:not(:disabled) {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8125rem;
}

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

/* Nav Tabs */
.tabs-nav-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
}

.tabs-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  overflow-x: auto;
  padding: 0 1.5rem;
  gap: 0.5rem;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 0.85rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-btn.active {
  color: var(--accent-indigo);
  border-bottom-color: var(--accent-indigo);
}

/* Main Layout */
.main-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

.tab-panel {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Stats Row */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.stat-icon.emerald { background: var(--accent-emerald-glow); color: var(--accent-emerald); }
.stat-icon.amber { background: var(--accent-amber-glow); color: var(--accent-amber); }
.stat-icon.rose { background: var(--accent-rose-glow); color: var(--accent-rose); }
.stat-icon.indigo { background: var(--accent-indigo-glow); color: var(--accent-indigo); }

.stat-details h3 {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

/* Dashboard Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Monitors Grid */
.monitors-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.monitor-item {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  transition: all var(--transition-fast);
}

.monitor-item:hover {
  background: var(--bg-surface-hover);
  border-color: rgba(255, 255, 255, 0.12);
}

.monitor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.monitor-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.monitor-url {
  font-size: 0.775rem;
  color: var(--text-muted);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.status-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.status-tag.up { background: var(--accent-emerald-glow); color: var(--accent-emerald); }
.status-tag.down { background: var(--accent-rose-glow); color: var(--accent-rose); }
.status-tag.warning { background: var(--accent-amber-glow); color: var(--accent-amber); }
.status-tag.paused { background: rgba(255, 255, 255, 0.08); color: var(--text-muted); }

.monitor-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  padding-top: 0.5rem;
}

/* VNC Container */
.vnc-wrapper {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.vnc-toolbar {
  background: var(--bg-surface-elevated);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.vnc-title {
  font-size: 0.875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.vnc-controls {
  display: flex;
  gap: 0.5rem;
}

.vnc-screen-container {
  width: 100%;
  height: 750px;
  background: #000;
  position: relative;
}

.vnc-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #000;
}

.vnc-info-box {
  background: rgba(99, 102, 241, 0.08);
  border-left: 4px solid var(--accent-indigo);
  padding: 1rem 1.25rem;
  margin-top: 1rem;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 0.875rem;
}

.vnc-info-box ol {
  margin-top: 0.5rem;
  padding-left: 1.25rem;
  color: var(--text-secondary);
}

.vnc-info-box li {
  margin-bottom: 0.25rem;
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  color: var(--text-primary);
  font-family: inherit;
  transition: all var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px var(--accent-indigo-glow);
}

textarea.form-control {
  min-height: 110px;
  resize: vertical;
}

.templates-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.template-chip {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.template-chip:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border-color: var(--accent-indigo);
}

.chat-picker-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.chat-chip {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat-chip:hover {
  background: var(--accent-emerald-glow);
  color: var(--accent-emerald);
  border-color: var(--accent-emerald);
}

/* Logs and Events */
.events-stream {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 380px;
  overflow-y: auto;
}

.event-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  border-left: 3px solid var(--text-muted);
}

.event-row.success { border-left-color: var(--accent-emerald); }
.event-row.warning { border-left-color: var(--accent-amber); }
.event-row.error { border-left-color: var(--accent-rose); }
.event-row.info { border-left-color: var(--accent-indigo); }

.event-time {
  color: var(--text-muted);
  font-family: monospace;
  font-size: 0.75rem;
  white-space: nowrap;
}

.event-msg {
  flex: 1;
  word-break: break-word;
}

.raw-log-box {
  background: #06090e;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  color: #94a3b8;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Toast Alerts */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toast {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 280px;
  animation: slideIn 0.25s ease-out;
}

.toast.success { border-left: 4px solid var(--accent-emerald); }
.toast.error { border-left: 4px solid var(--accent-rose); }
.toast.info { border-left: 4px solid var(--accent-indigo); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    align-items: stretch;
  }
  .header-actions {
    justify-content: space-between;
  }
  .vnc-screen-container {
    height: 500px;
  }
}
