:root {
  --bg: #0c0d14;
  --panel: #151726;
  --panel-alt: #1c1f33;
  --border: #2b304d;
  --text: #eef1ff;
  --muted: #9aa3c2;
  --accent: #7c5cff;
  --accent-hover: #6a46ff;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  display: grid; place-items: center; font-weight: 800; font-size: 16px;
}
.brand h1 { margin: 0; font-size: 16px; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; justify-content: space-between; align-items: center;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px;
  padding: 10px 12px; text-align: left; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: 0.15s;
}
.nav-item:hover { background: var(--panel-alt); color: var(--text); }
.nav-item.active { background: rgba(124, 92, 255, 0.18); border-color: var(--accent); color: #fff; }

.sidebar-footer { margin-top: auto; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 14px; }
.status-line { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.dot.online { background: var(--success); }
.mock-box { margin-top: 8px; padding: 8px; background: var(--panel-alt); border-radius: 8px; }
.mock-box a { color: #c4b5fd; }

.main { padding: 24px 28px; overflow-y: auto; max-width: 1280px; width: 100%; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-header h2 { margin: 0 0 4px; font-size: 22px; }
.page-header p { margin: 0; color: var(--muted); font-size: 14px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 16px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; background: #0e101c; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
  font-family: inherit; font-size: 13px;
}
textarea { font-family: ui-monospace, Consolas, monospace; resize: vertical; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
button.btn {
  border: 0; border-radius: 8px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff; transition: 0.15s;
}
button.btn:hover { background: var(--accent-hover); }
button.btn.secondary { background: var(--panel-alt); border: 1px solid var(--border); color: var(--text); }
button.btn.secondary:hover { border-color: var(--accent); }
button.btn.success { background: #15803d; }
button.btn.warn { background: #b45309; }
button.btn.danger { background: #b91c1c; }
button.btn.info { background: #0284c7; }
button.btn.sm { padding: 6px 10px; font-size: 12px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.3px;
  background: var(--panel-alt); color: var(--muted);
}
.badge.AUTHENTICATED, .badge.RUNNING, .badge.SUCCEEDED { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.badge.WAITING_CONFIRMATION, .badge.QUEUED, .badge.NEEDS_LOGIN { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.badge.FAILED, .badge.STOPPED, .badge.CANCELLED { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.badge.UNKNOWN { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }

.pill {
  background: var(--warn); color: #111; border-radius: 999px;
  padding: 1px 7px; font-size: 11px; font-weight: 800;
}

.code-box {
  background: #0a0c15; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  word-break: break-all; white-space: pre-wrap; color: #cbd5e1;
}

.gate-banner {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.16), rgba(124, 92, 255, 0.16));
  border: 2px solid var(--warn);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 20px;
}
.gate-banner h3 { margin: 0 0 6px; color: #fde68a; }
.gate-banner p { margin: 0 0 12px; font-size: 14px; }
.gate-banner img { max-width: 100%; max-height: 260px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 12px; display: block; }

.log-list { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; }
.log-entry {
  background: #0e101c; border-left: 3px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 12px;
}
.log-entry.success { border-left-color: var(--success); }
.log-entry.warn { border-left-color: var(--warn); }
.log-entry.error { border-left-color: var(--danger); }
.log-entry.info { border-left-color: var(--info); }
.log-entry img { margin-top: 8px; max-width: 360px; border-radius: 6px; border: 1px solid var(--border); display: block; }

.meta-row { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin: 6px 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; border: 1px dashed var(--border); border-radius: 10px; }

.hidden { display: none !important; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; width: 100%; max-width: 560px; padding: 18px; max-height: 88vh; overflow-y: auto;
}
.modal-card.modal-wide {
  max-width: 1020px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-header h3 { margin: 0; }
.btn-icon { background: transparent; border: 0; color: var(--muted); font-size: 24px; cursor: pointer; }

.terminal-conn-grid {
  display: grid;
  grid-template-columns: minmax(140px, 1.3fr) 85px minmax(110px, 0.9fr) minmax(170px, 1.3fr) minmax(170px, 1.3fr);
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}
.terminal-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.terminal-viewport {
  background: #090b12;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  height: 430px;
  min-height: 280px;
  overflow: hidden;
}
@media (max-width: 820px) {
  .terminal-conn-grid { grid-template-columns: 1fr 1fr; }
}

.toast-container { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--panel-alt); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
}
