:root {
  --bg-void: #0a0d12;
  --bg-surface: #11161f;
  --bg-elevated: #18202c;
  --bg-hover: #1f2938;
  --border: #242e3f;
  --border-strong: #324056;
  --ink-primary: #edf2f7;
  --ink-secondary: #a4b1c3;
  --ink-muted: #6e7d92;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --signal: #10b981;
  --signal-dim: rgba(16, 185, 129, 0.14);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.14);
  --radius: 8px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg-void);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }
.muted { color: var(--ink-muted); }
.mono-sm { font-family: var(--font-mono); font-size: 11px; color: var(--ink-secondary); }

/* Login Gate */
.login-shell {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(59, 130, 246, 0.08), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(16, 185, 129, 0.06), transparent 45%),
    var(--bg-void);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-dim);
  flex-shrink: 0;
}

.login-brand h1 {
  font-size: 18px;
  letter-spacing: 0.14em;
  font-weight: 700;
}

.subtitle {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
}

.login-hint {
  margin-top: 16px;
  font-size: 11px;
  color: var(--ink-muted);
  line-height: 1.5;
}

.login-hint code {
  font-family: var(--font-mono);
  color: var(--ink-secondary);
  background: var(--bg-elevated);
  padding: 1px 4px;
  border-radius: 4px;
}

/* Workbench Layout */
.workbench {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.16s ease;
}

.sidebar.collapsed {
  margin-left: -300px;
}

.sidebar-header {
  height: 46px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.brand-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 13px;
}

.badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--ink-secondary);
}

.badge-mono { font-family: var(--font-mono); }

.header-actions {
  display: flex;
  gap: 4px;
}

.sidebar-tools {
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.search-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-void);
  border: 1px solid var(--border);
  color: var(--ink-primary);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12px;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.profile-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 8px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.profile-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.profile-card.active {
  border-color: var(--accent);
  box-shadow: inset 2px 0 0 var(--accent);
}

.profile-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.profile-title-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.profile-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-chip {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.14);
  color: #93c5fd;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-idle { background: #475569; }
.dot-ok { background: var(--signal); box-shadow: 0 0 0 3px var(--signal-dim); }
.dot-warn { background: var(--warn); }

.profile-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.profile-proxy-line {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.warn-tag {
  font-family: var(--font-sans);
  font-size: 10px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--warn-dim);
  color: var(--warn);
}

.profile-actions {
  display: flex;
  gap: 5px;
}

.sidebar-footer {
  height: 34px;
  padding: 0 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Main Stage */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-void);
}

.session-bar {
  height: 46px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  overflow: visible;
}

.session-bar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
}

.session-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.session-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--ink-secondary);
  cursor: pointer;
  white-space: nowrap;
  font-size: 12px;
}

.session-tab.active {
  background: var(--bg-void);
  border-color: var(--accent);
  color: var(--ink-primary);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.telemetry-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-secondary);
  background: var(--bg-void);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  white-space: nowrap;
}

.url-input {
  width: 210px;
  background: var(--bg-void);
  border: 1px solid var(--border);
  color: var(--ink-primary);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.url-input:focus {
  outline: none;
  border-color: var(--accent);
}

.select-sm {
  background: var(--bg-void);
  border: 1px solid var(--border);
  color: var(--ink-primary);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 12px;
}

/* Dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 240px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-menu button {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--ink-primary);
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}

.dropdown-menu button:hover {
  background: var(--bg-hover);
}

/* Clipboard Drawer */
.clipboard-drawer {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-strong);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clipboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.clipboard-drawer textarea {
  width: 100%;
  background: var(--bg-void);
  border: 1px solid var(--border);
  color: var(--ink-primary);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  resize: vertical;
}

.clipboard-drawer textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.clipboard-actions {
  display: flex;
  gap: 8px;
}

/* Viewport */
.viewport-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #06080b;
  overflow: hidden;
}

.vnc-mount {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vnc-mount > div {
  width: 100% !important;
  height: 100% !important;
}

.vnc-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 18, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.overlay-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--signal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Empty Welcome Stage */
.empty-stage {
  padding: 24px;
  width: 100%;
  max-width: 700px;
}

.empty-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}

.empty-card h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.empty-lead {
  color: var(--ink-secondary);
  margin-bottom: 22px;
}

.checklist {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.check-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.check-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--signal);
  background: var(--signal-dim);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.check-item strong {
  display: block;
  margin-bottom: 3px;
}

.check-item p {
  color: var(--ink-secondary);
  font-size: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full { width: 100%; padding: 9px 14px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-accent {
  background: var(--signal-dim);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
}
.btn-accent:hover:not(:disabled) { background: rgba(16, 185, 129, 0.22); }

.btn-ghost {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--ink-primary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); }

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-dim); }

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.icon-btn:hover { background: var(--bg-hover); color: var(--ink-primary); }
.icon-danger { color: #f87171; border-color: rgba(239, 68, 68, 0.35); }
.icon-danger:hover { background: var(--danger-dim); color: #fca5a5; }

/* Modals & Forms */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-panel {
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.65);
}

.modal-sm { max-width: 400px; }

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

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.section-label:first-of-type { border-top: none; padding-top: 0; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.span-2 { grid-column: span 2; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field > span {
  font-size: 11px;
  color: var(--ink-secondary);
}

.field input,
.field select {
  background: var(--bg-void);
  border: 1px solid var(--border);
  color: var(--ink-primary);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12px;
  width: 100%;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.input-with-btn {
  display: flex;
  gap: 6px;
}

.quick-parse-row {
  display: flex;
  gap: 8px;
}
.quick-parse-row input {
  flex: 1;
  background: var(--bg-void);
  border: 1px dashed var(--border-strong);
  color: var(--ink-primary);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
}

.proxy-check-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.proxy-result {
  font-family: var(--font-mono);
  font-size: 11px;
  flex: 1;
  min-width: 220px;
}

.advanced-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.advanced-box summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-secondary);
}

.advanced-inner {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--ink-secondary);
}

.checkbox-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.inline-error {
  background: var(--danger-dim);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
}

/* Toasts */
.toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--ink-primary);
  padding: 9px 14px;
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  font-size: 12px;
}

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

@media (max-width: 960px) {
  .sidebar { width: 250px; min-width: 250px; }
  .sidebar.collapsed { margin-left: -250px; }
  .telemetry-pill, .url-input { display: none; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
