:root {
  --bg: #0f1117;
  --bg-card: #161b22;
  --bg-input: #0d1117;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --primary: #2f81f7;
  --primary-hover: #388bfd;
  --success: #3fb950;
  --warning: #d29922;
  --error: #f85149;
  --terminal-bg: #010409;
  --radius: 8px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Login */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, #1a2332 0%, var(--bg) 70%);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.logo { text-align: center; margin-bottom: 2rem; }

.logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), #8957e5);
  border-radius: 12px;
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.logo h1 { font-size: 1.5rem; font-weight: 700; }
.subtitle { color: var(--text-muted); font-size: 0.875rem; margin-top: 0.25rem; }

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo-small {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), #8957e5);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
}

.header-title { font-weight: 600; }
.user-label { color: var(--text-muted); font-size: 0.875rem; margin-right: 0.75rem; }
.header-right { display: flex; align-items: center; }

/* Main */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.card-wide { grid-column: 1 / -1; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.card-header h2 { font-size: 0.9375rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.card-actions { display: flex; gap: 0.5rem; }

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--border);
  color: var(--text-muted);
}

.badge-idle { background: #21262d; }
.badge-running { background: #1f3a5f; color: var(--primary); }
.badge-success { background: #1a3a2a; color: var(--success); }
.badge-error { background: #3d1f20; color: var(--error); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47,129,247,.15);
}

.form-row { display: flex; gap: 1rem; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.btn-row { display: flex; gap: 0.5rem; margin-top: 0.25rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; }

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

.btn-secondary {
  background: var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: #3d444d; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--border); color: var(--text); }

.error-msg {
  color: var(--error);
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem;
  background: rgba(248,81,73,.1);
  border-radius: 4px;
}

.test-result {
  margin-top: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-family: var(--mono);
}
.test-result.ok { background: rgba(63,185,80,.1); color: var(--success); border: 1px solid rgba(63,185,80,.3); }
.test-result.fail { background: rgba(248,81,73,.1); color: var(--error); border: 1px solid rgba(248,81,73,.3); }

/* Steps */
.steps-list { list-style: none; }

.step-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(48,54,61,.5);
  font-size: 0.875rem;
}
.step-item:last-child { border-bottom: none; }

.step-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  flex-shrink: 0;
  background: #21262d;
  color: var(--text-muted);
}

.step-item.pending .step-icon { background: #21262d; }
.step-item.running .step-icon { background: #1f3a5f; color: var(--primary); animation: pulse 1.5s infinite; }
.step-item.done .step-icon { background: #1a3a2a; color: var(--success); }
.step-item.error .step-icon { background: #3d1f20; color: var(--error); }

.step-label { flex: 1; }
.step-detail { font-size: 0.75rem; color: var(--text-muted); font-family: var(--mono); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Config editor */
.config-editor {
  width: 100%;
  min-height: 280px;
  padding: 1rem;
  background: var(--terminal-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #c9d1d9;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  resize: vertical;
  tab-size: 4;
}

/* Terminal */
.terminal-body { padding: 0; }
.terminal {
  background: var(--terminal-bg);
  min-height: 200px;
  max-height: 320px;
  overflow-y: auto;
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
}

.terminal-line { margin-bottom: 0.125rem; word-break: break-all; }
.terminal-line.cmd { color: #79c0ff; }
.terminal-line.output { color: #8b949e; }
.terminal-line.info { color: var(--text-muted); }
.terminal-line.success { color: var(--success); }
.terminal-line.error { color: var(--error); }
.terminal-line.warning { color: var(--warning); }

/* Template bar */
.template-bar {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.template-select-group { min-width: 200px; }
.template-select { cursor: pointer; }
.template-select option { background: var(--bg-card); }

.template-actions {
  display: flex;
  gap: 0.5rem;
  padding-bottom: 1rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.6);
}

.modal-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
}

.modal-card h3 {
  font-size: 1.125rem;
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Action bar */
.action-bar {
  display: flex;
  justify-content: center;
  padding: 1.5rem 0 0.5rem;
}

@media (max-width: 768px) {
  .grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; gap: 0; }
  .login-card { margin: 1rem; padding: 1.5rem; }
}
