:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --border: #e0ddd4;
  --text: #1f1d1a;
  --text-muted: #6a655d;
  --accent: #2c5282;
  --accent-soft: #e2e8f0;
  --green: #2f855a;
  --green-soft: #d6f0e0;
  --yellow: #b59800;
  --yellow-soft: #fbf2c4;
  --red: #c53030;
  --best-effort: #b06f00;
  --best-effort-soft: #ffe0b3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: white;
}

header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

header .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.status-pill {
  margin-left: auto;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 500;
}

.status-pill.connected {
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.disconnected {
  background: #fbe5e3;
  color: var(--red);
}

main {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 360px;
  gap: 1rem;
  padding: 1rem;
  height: calc(100vh - 60px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel h2 {
  margin: 0 0 0.6rem 0;
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.panel .hint {
  margin: 0 0 0.6rem 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* --- Controls --- */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.8rem;
  margin-bottom: 1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px dashed var(--border);
}

.status-grid > div {
  display: flex;
  flex-direction: column;
}

.status-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.status-value {
  font-size: 0.95rem;
  font-weight: 500;
  word-break: break-all;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
  flex-wrap: wrap;
}

.action-row label {
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-basis: 100%;
}

.btn {
  padding: 0.45rem 0.95rem;
  font-size: 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #f1efe9;
}

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

.btn-warn {
  border-color: var(--best-effort);
  color: var(--best-effort);
}

.btn-warn:hover:not(:disabled) {
  background: var(--best-effort-soft);
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
}

select {
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.85rem;
  flex: 1;
}

.failure-explanations {
  margin: 0 0 0.6rem 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfaf6;
  padding: 0.65rem 0.75rem;
  font-size: 0.78rem;
  line-height: 1.45;
  max-height: 22rem;
  overflow-y: auto;
}

.failure-explanation {
  display: none;
}

.failure-explanation[hidden] {
  display: none !important;
}

.failure-explanation.active {
  display: block;
}

.failure-explanation h3 {
  margin: 0 0 0.4rem 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.failure-explanation p {
  margin: 0 0 0.45rem 0;
}

.failure-explanation p:last-child {
  margin-bottom: 0;
}

.failure-explanation code {
  background: var(--accent-soft);
  color: var(--text);
  padding: 0 4px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.75rem;
}

.footer-links {
  margin-top: auto;
  padding-top: 0.7rem;
  border-top: 1px dashed var(--border);
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.footer-links a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
}

.footer-links a:hover {
  text-decoration: underline;
}

/* --- Architecture SVG --- */
.svg-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
}

#graphSvg {
  width: 100%;
  height: 100%;
  max-height: 70vh;
}

.node rect,
.node circle {
  fill: var(--panel);
  stroke: #b8b3a8;
  stroke-width: 1.5;
  transition: all 0.25s ease;
}

.node rect.fix {
  stroke: var(--green);
}

.node rect.best-effort {
  stroke: var(--best-effort);
}

.node text {
  font-size: 12px;
  fill: var(--text);
  pointer-events: none;
}

.node text.node-sub {
  font-size: 9px;
  fill: var(--text-muted);
}

.node.active rect,
.node.active circle {
  stroke: var(--accent);
  stroke-width: 3;
  filter: drop-shadow(0 0 6px rgba(44, 82, 130, 0.45));
  animation: pulse 1s ease-in-out infinite;
}

.node.visited rect,
.node.visited circle {
  fill: var(--green-soft);
  stroke: var(--green);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.04);
  }
}

.edge line,
.edge path {
  fill: none;
  stroke: #c8c3b8;
  stroke-width: 1.5;
  marker-end: url(#arrow);
  transition: all 0.3s ease;
}

.edge.active line,
.edge.active path {
  stroke: var(--green);
  stroke-width: 2.5;
  marker-end: url(#arrow-active);
}

/* --- ReAct stream --- */
#streamList {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    sans-serif;
  font-size: 0.82rem;
}

#streamList li {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

#streamList li .ts {
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-right: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

#streamList li code {
  background: var(--accent-soft);
  color: var(--text);
  padding: 0 4px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.78rem;
}

#streamList li a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px dotted var(--accent);
}

#streamList li a:hover {
  border-bottom-style: solid;
}

#streamList li strong {
  font-weight: 600;
}

#streamList li .stream-sub {
  margin-top: 0.3rem;
  margin-left: 0.2rem;
  padding-left: 0.5rem;
  border-left: 2px solid var(--border);
  color: var(--text-muted);
  font-size: 0.74rem;
  white-space: pre-wrap;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    sans-serif;
}

#streamList li .kind {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.7rem;
  margin-right: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

#streamList li .kind.classify {
  background: var(--yellow-soft);
  color: var(--yellow);
}

#streamList li .kind.fix {
  background: var(--green-soft);
  color: var(--green);
}

#streamList li .kind.error {
  background: #fbe5e3;
  color: var(--red);
}

#streamList li .kind.run {
  background: var(--accent-soft);
  color: var(--accent);
}

.stream-controls {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
