:root {
  --bg: #f2f5fb;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #475569;
  --stroke: #cbd5e1;
  --primary: #0f4c81;
  --primary-2: #1d4ed8;
  --success: #166534;
  --danger: #b91c1c;
  --warning: #b45309;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(circle at top left, #dbeafe, transparent 44%),
    radial-gradient(circle at top right, #cffafe, transparent 40%), var(--bg);
  color: var(--ink);
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
}

.page-shell {
  min-height: 100vh;
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
}

.hero {
  border: 1px solid #bfdbfe;
  border-radius: 18px;
  padding: 1.25rem 1.4rem;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 45%, #ffffff 100%);
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2rem);
}

.eyebrow {
  margin: 0 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #1e40af;
  font-size: 0.72rem;
}

.subtitle {
  margin: 0.45rem 0 0;
  color: var(--muted);
  max-width: 60ch;
}

.hero-status {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pill {
  font-size: 0.74rem;
  border-radius: 999px;
  padding: 0.35rem 0.62rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.status-idle {
  background: #e2e8f0;
}
.status-running {
  background: #fef3c7;
  color: #92400e;
}
.status-completed {
  background: #dcfce7;
  color: var(--success);
}
.status-failed,
.status-error {
  background: #fee2e2;
  color: var(--danger);
}
.socket-online {
  background: #dcfce7;
  color: var(--success);
}
.socket-offline {
  background: #e2e8f0;
  color: #334155;
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.05);
}

.control-panel {
  padding: 1rem;
  display: grid;
  gap: 1rem;
  align-content: start;
  max-height: calc(100vh - 160px);
  overflow: auto;
}

.control-panel h2 {
  font-size: 0.95rem;
  margin: 0 0 0.5rem;
}

textarea,
input[type="number"],
input[type="text"],
select {
  width: 100%;
  border: 1px solid var(--stroke);
  border-radius: 11px;
  background: #f8fafc;
  color: var(--ink);
  padding: 0.65rem 0.75rem;
  font: inherit;
}

#task-input {
  min-height: 130px;
  resize: vertical;
}

.field-row {
  margin-top: 0.55rem;
  display: grid;
  gap: 0.35rem;
}

.field-row label {
  font-size: 0.78rem;
  color: var(--muted);
}

.button-row {
  margin-top: 0.7rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.button-row.compact {
  margin-top: 0;
}

.btn {
  border: 1px solid var(--stroke);
  background: white;
  color: #1e293b;
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
}

.btn:hover {
  background: #f8fafc;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-primary {
  border-color: #0ea5e9;
  color: white;
  background: linear-gradient(120deg, var(--primary) 0%, var(--primary-2) 100%);
}

.btn-primary:hover {
  filter: brightness(1.04);
}

.btn-ghost {
  background: #f8fafc;
}

.meta-list {
  display: grid;
  gap: 0.45rem;
}

.meta-list div {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 9px;
  padding: 0.45rem 0.55rem;
  font-size: 0.82rem;
}

.meta-list span {
  color: #64748b;
}

.meta-list strong {
  color: #0f172a;
}

.hint {
  margin: 0;
  font-size: 0.74rem;
  color: #64748b;
}

.config-form {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.45rem;
  max-height: 50vh;
  overflow: auto;
  overflow-x: hidden;
  padding-right: 0.2rem;
}

.cfg-section {
  border: 1px solid #dbeafe;
  border-radius: 12px;
  padding: 0.55rem;
  background: linear-gradient(180deg, #f8fbff, #ffffff);
  display: grid;
  gap: 0.45rem;
}

.cfg-warning {
  border: 1px solid #fca5a5;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  font-size: 0.74rem;
  line-height: 1.35;
  word-break: break-word;
}

.cfg-section h3 {
  margin: 0;
  font-size: 0.82rem;
}

.cfg-section-head,
.cfg-subhead,
.cfg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}

.cfg-add-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  min-width: 0;
  width: 100%;
}

.cfg-add-row input {
  width: 100%;
  min-width: 0;
  max-width: 170px;
  font-size: 0.75rem;
  padding: 0.38rem 0.5rem;
}

.cfg-stack {
  display: grid;
  gap: 0.45rem;
}

.cfg-card {
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 0.45rem;
  background: #ffffff;
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

.cfg-card strong {
  font-size: 0.78rem;
}

.cfg-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
  min-width: 0;
}

.cfg-grid label,
.cfg-step label {
  display: grid;
  gap: 0.22rem;
  font-size: 0.72rem;
  color: #475569;
}

.cfg-grid input,
.cfg-grid select,
.cfg-step input,
.cfg-step select,
.cfg-map-row input {
  font-size: 0.74rem;
  padding: 0.38rem 0.5rem;
}

.cfg-full {
  grid-column: 1 / -1;
}

.cfg-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  font-size: 0.72rem;
  color: #334155;
}

.cfg-flags label {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
}

.cfg-step {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.4rem;
  display: grid;
  gap: 0.35rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

.cfg-map-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.35rem;
  align-items: center;
}

.main-panel {
  display: grid;
  gap: 0.85rem;
}

.stats-grid {
  padding: 0.8rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.stats-grid article {
  border: 1px solid #dbeafe;
  border-radius: 11px;
  padding: 0.65rem;
  display: grid;
  gap: 0.3rem;
  background: linear-gradient(180deg, #eff6ff, #ffffff);
}

.stats-grid span {
  font-size: 0.72rem;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-grid strong {
  font-size: 0.95rem;
}

.graph-card,
.timeline-card,
.comms-card,
.output-card,
.logs-card {
  padding: 0.85rem 1rem;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
}

.section-title-row h2 {
  margin: 0;
  font-size: 0.95rem;
}

#graph {
  width: 100%;
  min-height: 460px;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  background: radial-gradient(
    circle at center,
    #eff6ff 0%,
    #dbeafe 45%,
    #bfdbfe 100%
  );
}

.timeline {
  max-height: 260px;
  overflow: auto;
  display: grid;
  gap: 0.45rem;
}

.comms {
  max-height: 300px;
  overflow: auto;
  display: grid;
  gap: 0.45rem;
}

.comm-item {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0.5rem 0.58rem;
  background: white;
  display: grid;
  gap: 0.2rem;
}

.comm-item.latest {
  border-color: #0ea5e9;
  box-shadow: 0 0 0 2px #dbeafe inset;
}

.comm-meta {
  font-size: 0.71rem;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.comm-route {
  font-size: 0.79rem;
  font-weight: 700;
  color: #0f172a;
  word-break: break-word;
}

.comm-message {
  font-size: 0.76rem;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-word;
}

.timeline-item {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0.48rem 0.56rem;
  background: white;
  cursor: pointer;
  display: grid;
  gap: 0.22rem;
}

.timeline-item:hover {
  background: #f8fafc;
}

.timeline-item.selected {
  border-color: #1d4ed8;
  box-shadow: 0 0 0 2px #bfdbfe inset;
}

.timeline-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.73rem;
  color: #334155;
}

.timeline-route {
  font-size: 0.78rem;
  font-weight: 700;
}

.timeline-msg {
  font-size: 0.74rem;
  color: #475569;
}

#final-output {
  margin: 0;
  min-height: 130px;
  max-height: 320px;
  overflow: auto;
  border: 1px solid #dbeafe;
  border-radius: 11px;
  padding: 0.8rem;
  font-family: "IBM Plex Mono", "SF Mono", Menlo, monospace;
  font-size: 0.8rem;
  background: #f8fafc;
}

.logs {
  max-height: 220px;
  overflow: auto;
  display: grid;
  gap: 0.33rem;
}

.log-item {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.38rem 0.48rem;
  font-size: 0.76rem;
  display: grid;
  gap: 0.15rem;
}

.log-meta {
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.67rem;
}

.edge {
  fill: none;
  stroke-width: 2.8;
  opacity: 0.78;
}

.edge-latest {
  stroke-dasharray: 8 6;
  animation: dash-move 1.1s linear infinite;
  opacity: 1;
  stroke-width: 3.1;
}

.edge-selected {
  opacity: 1;
  stroke-width: 3.6;
}

.edge-label {
  fill: #0f172a;
  font-size: 10px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #f8fafc;
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.node {
  cursor: pointer;
}

.node text {
  pointer-events: none;
}

.node-label {
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.25);
  stroke-width: 1px;
  stroke-linejoin: round;
}

.node-label-title {
  fill: #ffffff;
}

.node-label-agent {
  fill: #dbeafe;
}

@keyframes dash-move {
  from {
    stroke-dashoffset: 0;
  }
  to {
    stroke-dashoffset: -28;
  }
}

@media (max-width: 1160px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .control-panel {
    max-height: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .page-shell {
    padding: 0.8rem;
  }

  .hero {
    padding: 1rem;
    flex-direction: column;
  }

  .stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .cfg-grid,
  .cfg-step {
    grid-template-columns: minmax(0, 1fr);
  }

  .cfg-map-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .cfg-add-row {
    width: 100%;
  }

  .cfg-add-row input {
    width: 100%;
  }
}
