:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dbe3ef;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-2: #4f46e5;
  --queued: #64748b;
  --running: #2563eb;
  --completed: #16a34a;
  --failed: #dc2626;
  --blocked: #d97706;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: linear-gradient(180deg, #eef2ff 0%, var(--bg) 28%, #f8fafc 100%);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  text-decoration: none;
}

.topbar-brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.topbar-brand-text strong {
  font-size: 1rem;
  line-height: 1.2;
}

.topbar-brand-text small {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-dropdown {
  position: relative;
}

.nav-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.nav-dropdown.is-open .nav-dropdown-toggle,
.nav-dropdown-toggle:hover {
  border-color: rgba(37, 99, 235, 0.35);
  color: var(--accent);
}

.nav-dropdown-caret {
  font-size: 0.75rem;
  line-height: 1;
}

.nav-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  min-width: 168px;
  display: none;
  flex-direction: column;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
  z-index: 30;
}

.nav-dropdown.is-open .nav-dropdown-menu {
  display: flex;
}

.nav-dropdown-menu a,
.nav-dropdown-action {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  background: transparent;
  cursor: pointer;
}

.nav-dropdown-menu a:hover,
.nav-dropdown-action:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
}

.nav-dropdown-form {
  margin: 0;
}

.auth-page {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 64px);
  padding: 2rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.brand-icon { font-size: 2rem; }
.auth-brand h1 { margin: 0.5rem 0 0.25rem; font-size: 1.5rem; }
.auth-brand p { margin: 0; color: var(--muted); }

.auth-form label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.auth-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  margin-bottom: 1rem;
}

.auto-refresh {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.summary-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  padding: 1.25rem 1.5rem;
}

.summary-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.summary-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
}

.summary-value-sm { font-size: 0.9rem; color: var(--muted); }
.summary-label { color: var(--muted); font-size: 0.8rem; }
.summary-active { color: var(--running); }
.summary-failed { color: var(--failed); }
.summary-updated { display: flex; flex-direction: column; gap: 0.25rem; }

.jobs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.25rem;
  padding: 0 1.5rem 2rem;
}

.job-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.job-card.status-running { border-color: rgba(37, 99, 235, 0.45); }
.job-card.status-failed,
.job-card.interrupted { border-color: rgba(220, 38, 38, 0.4); }
.job-card.status-completed { border-color: rgba(22, 163, 74, 0.4); }
.job-card.status-blocked { border-color: rgba(217, 119, 6, 0.45); }

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

.card-title h2 { margin: 0; font-size: 1.35rem; }
.job-id {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
}

.status-badge {
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.status-queued { background: #e2e8f0; color: #475569; }
.status-badge.status-running { background: #dbeafe; color: #1d4ed8; }
.status-badge.status-completed { background: #dcfce7; color: #15803d; }
.status-badge.status-failed { background: #fee2e2; color: #b91c1c; }
.status-badge.status-blocked { background: #ffedd5; color: #c2410c; }

.card-phase .label,
.signals-box .label,
.agents-row .label,
.error-box .label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.phase-current strong { font-size: 1rem; }
.progress-pill {
  margin-left: 0.5rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
}

.phase-stepper {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.step {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}

.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 0.35rem;
  flex-shrink: 0;
  background: var(--border);
}

.step-done .step-dot { background: var(--completed); }
.step-active .step-dot {
  background: var(--running);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}
.step-pending .step-label { color: var(--muted); }

.step-label { font-size: 0.875rem; font-weight: 500; }

.signal-list {
  margin: 0.35rem 0 0;
  padding-left: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.signals-box,
.result-box,
.error-box,
.agents-row {
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.error-box p {
  margin: 0;
  color: #b91c1c;
  font-size: 0.875rem;
  white-space: pre-wrap;
}

.agent-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.agent-links a,
.result-box a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
}

.agent-chip,
.meta-chip {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 0.75rem;
  border: 1px solid #dbeafe;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.card-footer time {
  font-size: 0.75rem;
  color: var(--muted);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.875rem;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
}

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

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

.btn-resume {
  background: #ecfdf5;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

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

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 0.75rem;
  border-radius: 10px;
  margin-bottom: 1rem;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.empty-state h2 { color: var(--text); margin-bottom: 0.5rem; }

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .jobs-grid { grid-template-columns: 1fr; }
}
