/* === Theme Variables === */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --bg-hover: #1f2937;
  --border: #30363d;
  --border-light: #3d444d;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;

  --accent: #2dd4bf;
  --accent-dim: rgba(45, 212, 191, 0.15);
  --accent-glow: rgba(45, 212, 191, 0.4);

  --blue: #58a6ff;
  --blue-dim: rgba(88, 166, 255, 0.15);
  --blue-glow: rgba(88, 166, 255, 0.3);
  --green: #3fb950;
  --green-dim: rgba(63, 185, 80, 0.15);
  --green-glow: rgba(63, 185, 80, 0.4);
  --orange: #d29922;
  --orange-dim: rgba(210, 153, 34, 0.15);
  --orange-glow: rgba(210, 153, 34, 0.3);
  --red: #f85149;
  --red-dim: rgba(248, 81, 73, 0.15);
  --purple: #bc8cff;
  --purple-dim: rgba(188, 140, 255, 0.2);
  --cyan: #56d4dd;
  --cyan-dim: rgba(86, 212, 221, 0.15);
  --cyan-glow: rgba(86, 212, 221, 0.3);

  --radius: 6px;
  --font-mono: 'SF Mono', 'Menlo', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.header-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-sep { color: var(--text-muted); margin: 0 0.15em; }

.conn-badge {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.15em 0.5em;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.conn-badge--connected { background: var(--green-dim); color: var(--green); }
.conn-badge--connecting { background: var(--orange-dim); color: var(--orange); }
.conn-badge--disconnected { background: var(--red-dim); color: var(--red); }

/* === Notification Stack === */
.notification-stack {
  position: fixed;
  top: 3.3rem;
  right: 0.9rem;
  z-index: 65;
  display: grid;
  gap: 0.55rem;
  width: min(24rem, calc(100vw - 1.8rem));
  pointer-events: none;
}

.notification-card {
  pointer-events: auto;
  display: grid;
  gap: 0.45rem;
  padding: 0.72rem 0.78rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.94);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
}

.notification-card--info {
  border-color: rgba(88, 166, 255, 0.3);
}

.notification-card--warn {
  border-color: rgba(210, 153, 34, 0.42);
}

.notification-card--error {
  border-color: rgba(248, 81, 73, 0.46);
}

.notification-card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}

.notification-card__eyebrow {
  color: var(--text-secondary);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.notification-card__age {
  color: var(--text-muted);
  font-size: 0.68rem;
}

.notification-card__title {
  margin: 0;
  color: var(--text-primary);
  font-size: 0.88rem;
  line-height: 1.3;
}

.notification-card__body {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.76rem;
  line-height: 1.5;
}

.notification-card__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.notification-card__action,
.notification-card__dismiss {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-family: var(--font-sans);
  cursor: pointer;
}

.notification-card__action {
  padding: 0.24rem 0.62rem;
}

.notification-card__dismiss {
  width: 1.8rem;
  height: 1.8rem;
}

.notification-card__action:hover,
.notification-card__dismiss:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* === Main Layout === */
.main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* === Resize Handles === */
.resize-handle {
  flex-shrink: 0;
  background: var(--border);
  transition: background 0.15s;
  z-index: 10;
}

.resize-handle:hover,
.resize-handle--active {
  background: var(--accent);
}

.resize-handle--v {
  width: 4px;
  cursor: col-resize;
}

.resize-handle--h {
  height: 4px;
  cursor: row-resize;
}

body.resize-col { cursor: col-resize; }
body.resize-row { cursor: row-resize; }
body.resize-col *, body.resize-row * { cursor: inherit; user-select: none; }

/* === Canvas (left) === */
.canvas-panel {
  flex: 1;
  position: relative;
  background: var(--bg-primary);
  min-width: 200px;
}

.canvas-panel svg {
  display: block;
  cursor: grab;
}

.canvas-panel svg:active {
  cursor: grabbing;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.empty-state[hidden] { display: none; }

/* === Detail Panel (right) === */
.detail-panel {
  width: clamp(18rem, 31vw, 38rem);
  flex-shrink: 0;
  max-width: min(56rem, 62vw);
  background: var(--bg-secondary);
  overflow-y: auto;
  min-width: 16rem;
  container-type: inline-size;
  container-name: inspector;
  scrollbar-gutter: stable;
}

.detail-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.detail-placeholder[hidden] { display: none; }

.detail-content {
  padding: clamp(0.65rem, 1.6vw, 0.95rem);
  min-width: 0;
  overflow: hidden;
}

/* === ID Chips === */
.detail-ids {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.5rem;
  margin-bottom: 0.5rem;
  min-width: 0;
}

.id-row {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.65rem;
  min-width: 0;
}

.id-label {
  color: var(--text-muted);
  flex-shrink: 0;
}

.id-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  max-width: 100%;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1em 0.4em;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.id-chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
  max-width: 100%;
}

.id-chip--responsive {
  flex: 0 1 auto;
}

.id-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.id-chip::after {
  content: '\2398';
  font-size: 0.75em;
  opacity: 0.4;
}

.id-chip:hover::after { opacity: 0.8; }

.id-chip--copied {
  background: var(--green-dim);
  color: var(--green);
  border-color: var(--green);
}

.id-chip--copied::after {
  content: '\2713';
  opacity: 1;
}

.id-convs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  align-items: center;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.id-convs .id-chip {
  flex: 0 1 auto;
  max-width: 100%;
}

.id-chip--muted {
  opacity: 0.5;
  cursor: default;
}

.id-chip--muted::after {
  content: '';
}

/* Header card — groups name, state, IDs, and capabilities */
.detail-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: clamp(0.55rem, 1.25vw, 0.85rem);
  margin-bottom: 0.75rem;
  min-width: 0;
}

.detail-entity {
  display: grid;
  gap: clamp(0.55rem, 1.2vw, 0.85rem);
}

.detail-entity .detail-card {
  margin-bottom: 0;
}

.schema-card__header {
  position: relative;
  display: block;
  min-height: 1.5rem;
  padding-right: 2.25rem;
  margin-bottom: 0.38rem;
}

.schema-card__heading {
  min-width: 0;
  display: grid;
  gap: 0.16rem;
}

.schema-card__title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  text-wrap: balance;
}

.inspector-utility-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem 0.7rem;
  align-items: flex-start;
  margin-top: 0.62rem;
}

.inspector-utility {
  min-width: 0;
  display: grid;
  gap: 0.16rem;
}

.inspector-utility__label {
  color: var(--text-muted);
  font-size: 0.63rem;
  font-family: var(--font-mono);
  text-transform: lowercase;
}

.inspector-utility__value {
  color: var(--text-primary);
  font-size: 0.74rem;
}

.schema-card__meta {
  color: var(--text-muted);
  font-size: 0.68rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.schema-card__summary {
  color: var(--text-muted);
  font-size: 0.67rem;
  line-height: 1.15;
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.schema-card__controls {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-flex;
}

.schema-card__control {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(13, 17, 23, 0.68);
  color: var(--text-secondary);
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  min-height: 1.6rem;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.schema-card__control:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.schema-card__control:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.schema-card__control-icon {
  width: 0.92rem;
  height: 0.92rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.schema-card__title-shell,
.schema-card__widget-shell {
  display: none;
  min-height: 0;
}

.schema-card__title-shell {
  gap: 0.3rem;
}

.schema-card__widget-shell {
  gap: 0.5rem;
}

.schema-card__facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}

.schema-card__fact {
  display: inline-flex;
  align-items: center;
  min-height: 1.1rem;
  padding: 0.05rem 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(110, 118, 129, 0.22);
  background: rgba(255, 255, 255, 0.025);
  color: var(--text-secondary);
  font-size: 0.61rem;
  line-height: 1;
  white-space: nowrap;
}

.schema-widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.7rem, 1fr));
  gap: 0.38rem;
}

.schema-widget-metric {
  min-width: 0;
  padding: 0.42rem 0.5rem 0.38rem;
  border-radius: 0.72rem;
  border: 1px solid rgba(110, 118, 129, 0.18);
  background: rgba(255, 255, 255, 0.02);
}

.schema-widget-metric__value {
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.1;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.schema-widget-metric__label {
  margin-top: 0.18rem;
  color: var(--text-muted);
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.schema-card__body-shell {
  position: relative;
  min-height: 0;
}

.schema-card__body {
  display: grid;
  gap: 0.45rem;
  min-height: 0;
}

.schema-card__fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1.6rem;
  background: linear-gradient(180deg, rgba(22, 27, 34, 0), rgba(22, 27, 34, 0.96));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.schema-card--resizable {
  overflow: hidden;
  transition: height 0.2s ease, border-color 0.2s ease;
}

body.resize-col .schema-card--resizable,
body.resize-col .schema-card__body-shell,
body.resize-col .schema-card__body,
body.resize-col .schema-card__fade {
  transition: none !important;
}

.detail-panel--instant .schema-card--resizable,
.detail-panel--instant .schema-card__body-shell,
.detail-panel--instant .schema-card__body,
.detail-panel--instant .schema-card__fade {
  transition: none !important;
}

.schema-card--resizable.schema-card--clipped .schema-card__fade {
  opacity: 1;
}

.schema-card--title .schema-card__header {
  min-height: 1.1rem;
  margin-bottom: 0.18rem;
}

.schema-card--title .schema-card__meta {
  display: none;
}

.schema-card--title {
  padding-top: 0.42rem;
  padding-bottom: 0.34rem;
}

.schema-card--title .schema-card__heading {
  gap: 0;
}

.schema-card--title .schema-card__title {
  line-height: 1.05;
}

.schema-card--title .schema-card__title-shell {
  display: grid;
}

.schema-card--title .schema-card__control {
  min-height: 1.2rem;
}

.schema-card--title .schema-card__summary {
  font-size: 0.65rem;
  line-height: 1.08;
}

.schema-card--widget .schema-card__widget-shell {
  display: grid;
}

.schema-card--widget .schema-card__summary {
  font-size: 0.66rem;
  line-height: 1.18;
}

.schema-card--hero {
  background: linear-gradient(180deg, rgba(28, 33, 40, 0.9), rgba(22, 27, 34, 0.98));
}

.schema-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.schema-hero__copy {
  min-width: 0;
}

.schema-kind {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.2rem;
}

.schema-subtitle {
  margin-top: 0.22rem;
  color: var(--text-secondary);
  font-size: 0.76rem;
  line-height: 1.45;
  text-wrap: pretty;
}

.schema-subtitle strong {
  color: var(--text-primary);
}

.schema-badge-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.3rem;
}

.schema-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.18rem 0.52rem;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 600;
}

.schema-row {
  display: grid;
  grid-template-columns: minmax(5.5rem, 8rem) minmax(0, 1fr);
  gap: 0.6rem;
  align-items: start;
}

.schema-row--multiline {
  align-items: start;
}

.schema-row__label {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-family: var(--font-mono);
}

.schema-row__value {
  min-width: 0;
  color: var(--text-primary);
  font-size: 0.78rem;
  line-height: 1.45;
  word-break: break-word;
}

.schema-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  align-items: center;
  max-width: 100%;
}

.schema-chip-list--ids {
  align-items: flex-start;
}

.schema-chip-list--ids .id-chip {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.conversation-summary-list {
  display: grid;
  gap: 0.5rem;
}

.conversation-summary {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(22, 27, 34, 0.72);
  overflow: clip;
}

.conversation-summary--current {
  border-color: rgba(45, 212, 191, 0.25);
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.08);
}

.conversation-summary > summary {
  list-style: none;
}

.conversation-summary > summary::-webkit-details-marker {
  display: none;
}

.conversation-summary__summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: start;
  padding: 0.62rem 0.72rem;
  cursor: pointer;
}

.conversation-summary__summary:hover {
  background: rgba(31, 41, 55, 0.38);
}

.conversation-summary__copy {
  min-width: 0;
  display: grid;
  gap: 0.14rem;
}

.conversation-summary__title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.conversation-summary__title {
  min-width: 0;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  text-wrap: balance;
}

.conversation-summary__badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  padding: 0.08rem 0.42rem;
  color: var(--text-secondary);
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.conversation-summary__badge--current {
  border-color: rgba(45, 212, 191, 0.32);
  color: var(--accent);
}

.conversation-summary__badge--active {
  border-color: rgba(63, 185, 80, 0.32);
  color: var(--green);
}

.conversation-summary__meta {
  color: var(--text-secondary);
  font-size: 0.72rem;
  line-height: 1.45;
}

.conversation-summary__chevron {
  color: var(--text-muted);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  align-self: center;
}

.conversation-summary[open] .conversation-summary__chevron {
  color: var(--text-secondary);
}

.conversation-summary__body {
  display: grid;
  gap: 0.58rem;
  padding: 0 0.72rem 0.72rem;
  border-top: 1px solid rgba(48, 54, 61, 0.6);
}

.conversation-summary__description {
  margin: 0;
  color: var(--text-primary);
  font-size: 0.74rem;
  line-height: 1.5;
  text-wrap: pretty;
}

.conversation-summary__facts {
  display: grid;
  gap: 0.34rem;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}

.conversation-summary__fact {
  display: grid;
  gap: 0.08rem;
}

.conversation-summary__fact-label {
  color: var(--text-muted);
  font-size: 0.64rem;
  font-family: var(--font-mono);
  text-transform: lowercase;
}

.conversation-summary__fact-value {
  color: var(--text-primary);
  font-size: 0.72rem;
  line-height: 1.45;
  word-break: break-word;
}

.conversation-summary__ids {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: flex-start;
}

.conversation-summary__id-block {
  min-width: 0;
  display: grid;
  gap: 0.18rem;
}

.conversation-summary__id-label {
  color: var(--text-muted);
  font-size: 0.64rem;
  font-family: var(--font-mono);
}

.schema-map {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}

.schema-map__item {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.16rem 0.48rem;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.schema-subsection {
  display: grid;
  gap: 0.45rem;
}

.schema-subsection__title {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.loop-turn-request {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
  align-items: center;
  min-width: 0;
}

.loop-turn-request .id-chip {
  max-width: 100%;
}

.loop-turn-alert {
  padding: 0.6rem 0.72rem;
  border-radius: 10px;
  border: 1px solid rgba(110, 118, 129, 0.22);
  background: rgba(255, 255, 255, 0.025);
  color: var(--text-secondary);
  font-size: 0.74rem;
  line-height: 1.45;
  text-wrap: pretty;
}

.loop-turn-alert--warn {
  border-color: rgba(210, 153, 34, 0.28);
  background: rgba(210, 153, 34, 0.08);
  color: var(--orange);
}

.loop-turn-alert--error {
  border-color: rgba(248, 81, 73, 0.28);
  background: rgba(248, 81, 73, 0.08);
  color: var(--red);
}

.loop-turn-empty {
  padding: 0.72rem 0.78rem;
  border-radius: 10px;
  border: 1px dashed rgba(110, 118, 129, 0.22);
  color: var(--text-secondary);
  font-size: 0.74rem;
  line-height: 1.5;
  background: rgba(255, 255, 255, 0.018);
  text-wrap: pretty;
}

.loop-turn-brief {
  padding: 0.72rem 0.82rem;
  border-radius: 12px;
  border: 1px solid rgba(110, 118, 129, 0.18);
  background: rgba(255, 255, 255, 0.02);
  display: grid;
  gap: 0.55rem;
}

.loop-turn-brief__summary {
  color: var(--text-secondary);
  font-size: 0.76rem;
  line-height: 1.48;
  text-wrap: pretty;
}

.loop-turn-brief__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 0.42rem;
}

.loop-turn-brief__metric {
  min-width: 0;
  padding: 0.48rem 0.56rem 0.44rem;
  border-radius: 10px;
  border: 1px solid rgba(110, 118, 129, 0.14);
  background: rgba(255, 255, 255, 0.02);
}

.loop-turn-brief__metric-value {
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.loop-turn-brief__metric-label {
  margin-top: 0.18rem;
  color: var(--text-muted);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.schema-request-chip {
  border-color: rgba(45, 212, 191, 0.35);
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.detail-header .state-badge { margin-left: auto; }

.detail-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  text-wrap: balance;
}

.state-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.28rem 0.5rem 0.24rem;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.state-badge--sleeping    { background: var(--blue-dim);   color: var(--blue);   }
.state-badge--waiting     { background: var(--cyan-dim);   color: var(--cyan);   }
.state-badge--processing  { background: var(--green-dim);  color: var(--green);  }
.state-badge--error       { background: var(--orange-dim); color: var(--orange); }
.state-badge--stopped     { background: var(--red-dim);    color: var(--red);    }
.state-badge--pending     { background: var(--purple-dim); color: var(--purple); }
.state-badge--supervisor  { background: var(--purple-dim); color: var(--purple); }
.state-badge--completed  { background: var(--green-dim);  color: var(--green);  }

/* === Context Utilization Meter === */
.context-meter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}
.context-meter[hidden] { display: none; }

.context-meter__label {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  flex-shrink: 0;
}

.context-meter__track {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.context-meter__fill {
  height: 100%;
  border-radius: 3px;
  background: var(--blue);
  transition: width 0.4s ease, background-color 0.4s ease;
  width: 0;
}

.context-meter__fill--warn  { background: var(--orange); }
.context-meter__fill--crit  { background: var(--red); }

.context-meter__pct {
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-family: var(--font-mono);
  flex-shrink: 0;
  min-width: 3.5ch;
  text-align: right;
}

/* === Metrics === */
.detail-metrics {
  display: grid;
  grid-template-columns: minmax(5rem, auto) minmax(0, 1fr);
  gap: 0.25rem 0.75rem;
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

.detail-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.5rem 0 0.75rem;
}

.detail-divider[hidden] { display: none; }
.detail-metrics[hidden] { display: none; }
.detail-metrics dt[hidden],
.detail-metrics dd[hidden] { display: none; }

#detail-last-iter[hidden] { display: none; }

/* === Aggregate Stats Bar === */
.detail-aggregates {
  display: grid;
  gap: 0.55rem;
  font-size: 0.7rem;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-radius: 10px;
  padding: 0.65rem 0.72rem;
  margin-bottom: 0.5rem;
}
.agg-summary {
  color: var(--text-secondary);
  font-size: 0.76rem;
  line-height: 1.45;
  text-wrap: pretty;
}
.agg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7.4rem, 1fr));
  gap: 0.42rem;
}
.agg-stat {
  min-width: 0;
  padding: 0.45rem 0.55rem 0.42rem;
  border-radius: 9px;
  border: 1px solid rgba(110, 118, 129, 0.18);
  background: rgba(255, 255, 255, 0.02);
}
.agg-stat--emphasis {
  border-color: rgba(45, 212, 191, 0.28);
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.06);
}
.agg-stat__value {
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.15;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.agg-stat__label {
  margin-top: 0.16rem;
  color: var(--text-muted);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.agg-error {
  color: var(--orange);
  font-size: 0.72rem;
  line-height: 1.45;
  text-wrap: pretty;
}

/* === Iteration Timeline === */
.iter-timeline {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.5rem;
}

/* --- Cards (base) --- */
.iter-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.5rem;
  background: var(--bg-tertiary);
  font-size: 0.75rem;
}

/* Live card */
.iter-card--live {
  border-color: var(--green);
  background: var(--green-dim);
}

/* Past card */
.iter-card--past {
  opacity: 0.85;
}
.iter-card--past .iter-card__header {
  cursor: pointer;
}
.iter-card--past .iter-card__header:hover {
  background: var(--bg-hover);
  border-radius: var(--radius);
  margin: -0.15rem -0.25rem;
  padding: 0.15rem 0.25rem;
}
.iter-card--expanded { opacity: 1; }

/* Supervisor accent — inset left stripe so it layers with live/error borders */
.iter-card--supervisor {
  box-shadow: inset 3px 0 0 var(--purple);
}
.iter-card--supervisor .iter-card__live-label {
  color: var(--purple);
}

/* Error card */
.iter-card--error {
  border-color: var(--orange);
  background: var(--orange-dim);
}

/* --- Card Header --- */
.iter-card__header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
}
.iter-card__live-label {
  font-weight: 700;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--green);
  flex-shrink: 0;
}
.iter-card--live .iter-card__live-label { color: var(--green); }

.iter-card__iter-num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.iter-card__elapsed {
  font-variant-numeric: tabular-nums;
  color: var(--green);
  font-weight: 600;
  font-size: 0.8rem;
}
.iter-card__status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.5rem;
  padding: 0.22rem 0.46rem 0.18rem;
  border-radius: 999px;
  border: 1px solid rgba(63, 185, 80, 0.28);
  background: rgba(63, 185, 80, 0.12);
  color: var(--green);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.iter-card__status-pill--ok {
  border-color: rgba(63, 185, 80, 0.28);
  background: rgba(63, 185, 80, 0.12);
  color: var(--green);
}
.iter-card__status-pill--error {
  border-color: rgba(210, 153, 34, 0.35);
  background: rgba(210, 153, 34, 0.14);
  color: var(--orange);
}
.iter-card__status-pill--supervisor {
  border-color: rgba(188, 140, 255, 0.32);
  background: rgba(188, 140, 255, 0.14);
  color: var(--purple);
}
.iter-card__model {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}
.iter-card__title {
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 14rem;
  font-weight: 500;
}
.iter-card__spacer { flex: 1; }
.iter-card__time {
  color: var(--text-muted);
  font-size: 0.6rem;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  margin-right: 0.3rem;
}
.iter-card__duration {
  color: var(--text-secondary);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.iter-card__chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 0.6rem;
  transition: transform 0.15s;
}
.iter-card--expanded .iter-card__chevron {
  transform: rotate(0deg);
}

/* --- Card Body (expandable) --- */
.iter-card__body {
  padding-top: 0.35rem;
  margin-top: 0.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  display: grid;
  gap: 0.38rem;
}
.iter-card__body[hidden] { display: none; }
.iter-card__preview {
  margin-top: 0.25rem;
  color: var(--text-secondary);
  font-size: 0.72rem;
  line-height: 1.4;
  text-wrap: pretty;
}
.iter-card__summary-line {
  color: var(--text-secondary);
  font-size: 0.72rem;
  line-height: 1.45;
  text-wrap: pretty;
}
.iter-card__facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.34rem;
}
.iter-card__fact {
  min-width: 0;
  padding: 0.38rem 0.46rem 0.34rem;
  border-radius: 9px;
  border: 1px solid rgba(110, 118, 129, 0.18);
  background: rgba(255, 255, 255, 0.02);
}
.iter-card__fact-value {
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.15;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.iter-card__fact-label {
  margin-top: 0.15rem;
  color: var(--text-muted);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.iter-card__tokens {
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.iter-card__tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
}
.iter-card__scope {
  display: grid;
  gap: 0.42rem;
}
.iter-card__scope-group {
  display: grid;
  gap: 0.22rem;
}
.iter-card__scope-label {
  color: var(--text-muted);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.iter-card__scope-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.24rem;
}
.iter-card__tool-item {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05em 0.35em;
}
.iter-card__tool-item--scope {
  background: rgba(30, 41, 59, 0.72);
  color: var(--text-primary);
  border-color: rgba(96, 165, 250, 0.26);
}
.iter-card__error {
  color: var(--orange);
  word-break: break-word;
}
.iter-card__sup-badge {
  display: inline-block;
  font-size: 0.6rem;
  color: var(--purple);
}
.iter-card__timestamp {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.6rem;
}

/* Handler summary stats */
.iter-card__summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-secondary);
}
.iter-card__summary-item { white-space: nowrap; }

/* LLM call context (live card enrichment) */
.iter-card__llm-context {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-muted);
  margin: 0.2rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Connector Lines --- */
.iter-connector {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.25rem 0 0.25rem 1.2rem;
}
.iter-connector__line {
  width: 2px;
  height: 12px;
  background: var(--border);
  margin-left: 0.3rem;
  margin-bottom: 0.15rem;
}
.iter-connector__label {
  font-size: 0.6rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.iter-connector__sup {
  font-size: 0.6rem;
  font-family: var(--font-mono);
  color: var(--purple);
  opacity: 0.8;
}

/* --- Live tools (reused inside live cards) --- */
.live-tools {
  list-style: none;
  padding: 0;
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  font-family: var(--font-mono);
}
.live-tool {
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
}
.live-tool--running::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: live-spin 0.8s linear infinite;
  flex-shrink: 0;
}
.live-tool--done::before {
  content: '\2713';
  color: var(--green);
  width: 10px;
  text-align: center;
  flex-shrink: 0;
  font-size: 0.75rem;
}
.live-tool--error::before {
  content: '\2717';
  color: var(--red);
  width: 10px;
  text-align: center;
  flex-shrink: 0;
  font-size: 0.75rem;
}
@keyframes live-spin { to { transform: rotate(360deg); } }

/* Delegate call inline display (live card) */
.live-tool__delegate-icon {
  margin-right: 0.25em;
  font-size: 0.65rem;
}
.live-tool__delegate-task {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-tool__delegate-profile {
  font-size: 0.55rem;
  color: var(--purple);
  margin-left: 0.5em;
  flex-shrink: 0;
}

/* Delegate calls in past iteration cards */
.iter-card__delegates {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.25rem;
}
.iter-card__delegate-call {
  display: flex;
  align-items: baseline;
  gap: 0.2em;
  font-size: 0.65rem;
  color: var(--text-secondary);
  padding: 0.15em 0.35em;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 2px solid var(--purple);
  border-radius: 3px;
}
.iter-card__delegate-icon {
  font-size: 0.6rem;
  flex-shrink: 0;
}
.iter-card__delegate-task {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.iter-card__delegate-profile {
  font-size: 0.55rem;
  color: var(--purple);
  flex-shrink: 0;
}
.iter-card__delegate-call--error {
  border-left-color: var(--red);
}

.detail-metrics dt {
  color: var(--text-secondary);
  font-weight: 500;
}

.detail-metrics dd {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: right;
}

.detail-error:not(:empty) {
  color: var(--orange);
  word-break: break-word;
}

/* === Capability Tags === */
.detail-tags { margin-top: 0.35rem; }
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.tag-chip {
  display: inline-block;
  font-size: 0.6rem;
  font-family: var(--font-mono);
  background: transparent;
  color: var(--text-muted);
  border-radius: 9px;
  padding: 0.1em 0.5em;
}
.tag-chip--active {
  background: var(--accent-dim);
  color: var(--accent);
}
.tag-chip--muted {
  opacity: 0.4;
}
.tag-chip--dynamic {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px dashed rgba(45, 212, 191, 0.35);
}

/* === Section Title === */
.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

/* === Log Panel (bottom) === */
.log-panel {
  flex-shrink: 0;
  height: 180px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 80px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.log-toolbar__copy {
  display: grid;
  gap: 0.1rem;
}

.log-toolbar .section-title { margin-bottom: 0; }

.log-toolbar__subtitle {
  color: var(--text-muted);
  font-size: 0.68rem;
}

.log-filters {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.log-select {
  font-size: 0.75rem;
  font-family: var(--font-sans);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2em 0.5em;
}

.btn {
  font-size: 0.75rem;
  font-family: var(--font-sans);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.2em 0.6em;
  cursor: pointer;
}

.btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.log-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.log-empty[hidden] { display: none; }

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  margin-top: auto;
}

.log-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.log-table th {
  text-align: left;
  padding: 0.3rem 0.5rem;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.log-table td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-col-time { width: 75px; white-space: nowrap; }
.log-col-level { width: 55px; white-space: nowrap; }
.log-col-subsystem { width: 80px; white-space: nowrap; }
.log-col-msg { max-width: 300px; }
.log-col-detail { /* grows with content */ }

.log-table tbody {
  overflow-y: auto;
}

.log-table tbody tr:hover { background: var(--bg-hover); }

.log-table td.log-time {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.log-table td.log-subsystem {
  color: var(--text-secondary);
}

.log-table td.log-msg {
  color: var(--text-primary);
}

.log-table td.log-detail {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-attr {
  display: inline;
  white-space: nowrap;
  margin-right: 0.5em;
}

.log-attr-key {
  color: var(--text-muted);
}

.log-attr-val {
  color: var(--text-secondary);
}

.log-attr-val--model { color: var(--purple); }
.log-attr-val--tool { color: var(--accent); }
.log-attr-val--duration { color: var(--blue); }
.log-attr-val--tokens { color: var(--orange); }

/* Log ID chips — copy-clickable, dynamically sized */
.log-id-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2em;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1em 0.4em;
  margin-left: 0.4em;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.log-id-chip:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-color: var(--border-light);
}

.log-id-chip::after {
  content: '\2398';
  font-size: 0.75em;
  opacity: 0.4;
}

.log-id-chip:hover::after { opacity: 0.8; }

.log-id-chip--copied {
  background: var(--green-dim);
  color: var(--green);
  border-color: var(--green);
}

.log-id-chip--copied::after {
  content: '\2713';
  opacity: 1;
}

/* Level badges */
.level-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  text-transform: uppercase;
}

.level-badge--ERROR { background: var(--red-dim); color: var(--red); }
.level-badge--WARN  { background: var(--orange-dim); color: var(--orange); }
.level-badge--INFO  { background: var(--accent-dim); color: var(--accent); }
.level-badge--DEBUG { background: rgba(139,148,158,0.1); color: var(--text-muted); }
.level-badge--TRACE { background: rgba(139,148,158,0.05); color: var(--text-muted); }

/* === Scrollbar Styling === */
.log-scroll,
.detail-content {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.log-scroll::-webkit-scrollbar,
.detail-content::-webkit-scrollbar {
  width: 6px;
}

.log-scroll::-webkit-scrollbar-track,
.detail-content::-webkit-scrollbar-track {
  background: transparent;
}

.log-scroll::-webkit-scrollbar-thumb,
.detail-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.log-scroll::-webkit-scrollbar-thumb:hover,
.detail-content::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* Log panel scroll wrapper */
.log-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.log-scroll[hidden] { display: none; }

/* === Footer === */
.footer {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0.3rem 1rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  flex-shrink: 0;
}

.footer-item { white-space: nowrap; }

.footer-link {
  margin-left: auto;
  color: var(--text-secondary);
  text-decoration: none;
}

.footer-link:hover { color: var(--accent); }

/* === SVG Node Styles === */

/* Base node group */
.loop-node { cursor: pointer; }
.loop-node:hover .node-ring { opacity: 0.92; }

/* Trust zone underglow — diffused coloured halo behind the node */
.trust-glow {
  opacity: 0.45;
  pointer-events: none;
}

/* Selection halo */
.selection-ring {
  opacity: 0;
  stroke: var(--accent);
  stroke-width: 2;
  transition: opacity 0.2s ease;
}

.node-selected .selection-ring {
  opacity: 0.8;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

/* Outer state ring */
.node-ring {
  opacity: 0.72;
  transition: opacity 0.3s ease, stroke 0.4s ease, stroke-width 0.3s ease;
}

.node-occlusion {
  fill: rgba(13, 17, 23, 0.94);
  stroke: none;
  pointer-events: none;
}

/* Main core */
.node-shape {
  stroke: rgba(230, 237, 243, 0.16);
  stroke-width: 1.5;
  transition: fill 0.8s ease, filter 0.8s ease, opacity 0.6s ease;
  will-change: transform, opacity;
}

/* Category fills */
.node-shape--category-generic       { fill: rgba(139, 148, 158, 0.24); }
.node-shape--category-metacognitive { fill: rgba(188, 140, 255, 0.26); }
.node-shape--category-channel       { fill: rgba(86, 212, 221, 0.26); }
.node-shape--category-delegate      { fill: rgba(210, 153, 34, 0.26); }
.node-shape--category-scheduled     { fill: rgba(88, 166, 255, 0.26); }

/* Runtime-state rings */
.node-ring--sleeping    { stroke: var(--blue);   filter: drop-shadow(0 0 6px var(--blue-glow)); }
.node-ring--waiting     { stroke: var(--cyan);   filter: drop-shadow(0 0 6px var(--cyan-glow)); }
.node-ring--processing  { stroke: var(--green);  filter: drop-shadow(0 0 10px var(--green-glow)); }
.node-ring--supervisor  { stroke: var(--purple); filter: drop-shadow(0 0 14px rgba(188, 140, 255, 0.6)); }
.node-ring--error       { stroke: var(--orange); filter: drop-shadow(0 0 8px var(--orange-glow)); }
.node-ring--degraded    { stroke: var(--orange); filter: drop-shadow(0 0 8px var(--orange-glow)); }
.node-ring--stopped     { stroke: var(--text-muted); filter: none; opacity: 0.5; }
.node-ring--pending     { stroke: var(--purple); filter: drop-shadow(0 0 4px var(--purple-dim)); opacity: 0.6; }
.node-ring--completed   { stroke: var(--green); filter: drop-shadow(0 0 6px var(--green-glow)); }

/* Node label */
.node-icon {
  fill: rgba(230, 237, 243, 0.9);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  pointer-events: none;
  user-select: none;
}

.node-icon--delegate {
  font-size: 16px;
}

.node-label {
  fill: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

/* Compact capacity badge on the rim */
.node-rim-badge {
  pointer-events: none;
}

.node-rim-badge__body {
  fill: rgba(13, 17, 23, 0.96);
  stroke: rgba(230, 237, 243, 0.22);
  stroke-width: 1.25;
}

.node-rim-badge__text {
  fill: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.node-rim-badge--context .node-rim-badge__body {
  stroke: rgba(45, 212, 191, 0.45);
}

.node-rim-badge--model .node-rim-badge__body {
  stroke-dasharray: 3 2;
  stroke: rgba(210, 153, 34, 0.5);
}

.node-rim-badge--unknown .node-rim-badge__body {
  stroke-dasharray: 2 2;
  stroke: rgba(139, 148, 158, 0.46);
  opacity: 0.82;
}

/* Supervisor indicator ring */
.supervisor-dot {
  fill: none;
  stroke: var(--purple);
  stroke-width: 2;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.supervisor-dot--active {
  opacity: 1;
  animation: supervisor-pulse 1.5s ease-in-out infinite;
}

.supervisor-dot--faded {
  opacity: 0.25;
  stroke-dasharray: 4 3;
}

@keyframes supervisor-pulse {
  0%, 100% { opacity: 0.7; stroke-width: 2; }
  50% { opacity: 1; stroke-width: 3; }
}

/* === Breathing Animations === */
/* Only animate transform — never opacity or fill.  Colour/glow changes
   are driven by CSS transitions on the .node-shape base rule so that
   state swaps (sleeping↔processing↔waiting) crossfade smoothly à la
   Gource's linear colour interpolation rather than popping when the
   keyframe restarts. */

@keyframes breathe-idle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

@keyframes breathe-active {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.055); }
}

@keyframes breathe-alert {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.node-shape--activity-sleeping {
  animation: breathe-idle 5s cubic-bezier(0.37, 0, 0.63, 1) infinite;
  filter: drop-shadow(0 0 4px rgba(88, 166, 255, 0.18));
}

.node-shape--activity-waiting {
  animation: breathe-idle 7s cubic-bezier(0.37, 0, 0.63, 1) infinite;
  filter: drop-shadow(0 0 4px rgba(86, 212, 221, 0.18));
}

.node-shape--activity-processing {
  animation: breathe-active 2.4s cubic-bezier(0.37, 0, 0.63, 1) infinite;
  filter: drop-shadow(0 0 8px rgba(63, 185, 80, 0.18));
}

.node-shape--activity-supervisor {
  animation: breathe-active 2.4s cubic-bezier(0.37, 0, 0.63, 1) infinite;
  filter: drop-shadow(0 0 10px rgba(188, 140, 255, 0.24));
}

.node-shape--activity-error {
  animation: breathe-alert 3s cubic-bezier(0.37, 0, 0.63, 1) infinite;
  filter: drop-shadow(0 0 6px rgba(210, 153, 34, 0.2));
}

.node-shape--activity-degraded {
  animation: breathe-alert 3s cubic-bezier(0.37, 0, 0.63, 1) infinite;
  filter: drop-shadow(0 0 6px rgba(210, 153, 34, 0.2));
}

/* === System Node === */
.system-node { cursor: pointer; }
.system-node:hover .node-ring { opacity: 0.3; }

.system-rect {
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 2;
  transition: fill 0.6s ease, filter 0.6s ease;
}

.system-rect--healthy {
  fill: var(--green);
  stroke: var(--green);
  filter: drop-shadow(0 0 6px var(--green-glow));
}

.system-rect--degraded {
  fill: var(--orange);
  stroke: var(--orange);
  filter: drop-shadow(0 0 6px var(--orange-glow));
}

/* === System Detail Panel === */
.system-sections {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.system-section {
  margin-bottom: 0;
}

.system-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.system-section-header .section-title {
  margin-bottom: 0;
}

.system-section-meta {
  color: var(--text-muted);
  font-size: 0.65rem;
  font-family: var(--font-mono);
  text-align: right;
}

.system-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 0.5rem;
}

.system-stat {
  min-width: 0;
  padding: 0.45rem 0.55rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.system-stat--emphasis {
  border-color: rgba(45, 212, 191, 0.35);
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.08);
}

.system-stat__label {
  color: var(--text-muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}

.system-stat__value {
  color: var(--text-primary);
  font-size: 0.76rem;
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

.system-services {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.system-svc-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.8rem;
  padding: 0.45rem 0.55rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.system-svc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.system-svc-dot--ok { background: var(--green); }
.system-svc-dot--err { background: var(--orange); }

.system-svc-name {
  color: var(--text-primary);
  font-weight: 500;
}

.system-svc-info {
  min-width: 0;
  flex: 1;
}

.system-svc-meta {
  color: var(--text-muted);
  font-size: 0.68rem;
  margin-top: 0.1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.system-svc-error {
  color: var(--orange);
  font-size: 0.68rem;
  margin-top: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-subsection {
  margin-top: 0.8rem;
}

.system-subtitle {
  color: var(--text-secondary);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.system-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.system-item {
  padding: 0.5rem 0.6rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.system-item__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.system-item__title {
  min-width: 0;
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  word-break: break-word;
}

.system-item__title--mono {
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.system-item__metric {
  color: var(--text-secondary);
  font-size: 0.66rem;
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}

.system-item__subtitle,
.system-item__facts,
.system-item__telemetry,
.system-item__reason {
  margin-top: 0.25rem;
  font-size: 0.68rem;
  line-height: 1.4;
}

.system-item__subtitle,
.system-item__facts,
.system-item__telemetry {
  color: var(--text-secondary);
}

.system-item__subtitle {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.system-item__facts,
.system-item__telemetry,
.system-item__reason {
  font-family: var(--font-mono);
}

.system-item__facts,
.system-item__reason,
.system-item__error {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.system-item__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.system-item__button {
  font-size: 0.68rem;
}

.system-item__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.system-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.system-chip--provider,
.system-chip--resource,
.system-chip--config,
.system-chip--discovered {
  color: var(--blue);
  border-color: rgba(88, 166, 255, 0.3);
  background: var(--blue-dim);
}

.system-chip--ok {
  color: var(--green);
  border-color: rgba(63, 185, 80, 0.3);
  background: var(--green-dim);
}

.system-chip--warn {
  color: var(--orange);
  border-color: rgba(210, 153, 34, 0.3);
  background: var(--orange-dim);
}

.system-chip--error {
  color: var(--red);
  border-color: rgba(248, 81, 73, 0.3);
  background: var(--red-dim);
}

.system-chip--muted {
  color: var(--text-muted);
}

.system-item__error {
  margin-top: 0.3rem;
  color: var(--orange);
  font-size: 0.68rem;
  line-height: 1.4;
  word-break: break-word;
}

.system-empty {
  color: var(--text-muted);
  font-size: 0.74rem;
  padding: 0.4rem 0;
}

.registry-page {
  display: block;
  height: auto;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(circle at top left, rgba(86, 212, 221, 0.05), transparent 28%),
    radial-gradient(circle at top right, rgba(88, 166, 255, 0.05), transparent 24%),
    var(--bg-primary);
}

.request-page {
  display: block;
  height: auto;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  color-scheme: dark;
  background:
    radial-gradient(circle at top right, rgba(45, 212, 191, 0.04), transparent 24%),
    radial-gradient(circle at left center, rgba(88, 166, 255, 0.04), transparent 22%),
    var(--bg-primary);
}

.request-page .request-window {
  min-height: 100vh;
}

.request-page .request-window__sidebar {
  background: linear-gradient(180deg, rgba(22, 27, 34, 0.98), rgba(13, 17, 23, 0.98));
}

.request-page .request-window__main {
  background:
    linear-gradient(180deg, rgba(13, 17, 23, 0.96), rgba(13, 17, 23, 0.99)),
    var(--bg-primary);
}

.request-page .request-window__empty {
  background: rgba(28, 33, 40, 0.42);
}

.registry-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.registry-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.05rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(28, 33, 40, 0.92), rgba(22, 27, 34, 0.98));
}

.registry-hero__copy {
  min-width: 0;
  display: grid;
  gap: 0.25rem;
}

.registry-hero__eyebrow {
  color: var(--text-muted);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.registry-hero__title {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
}

.registry-hero__subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.5;
  max-width: 70ch;
}

.registry-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}

.registry-card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.registry-empty {
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.02);
}

.registry-empty[hidden],
.registry-section[hidden] {
  display: none !important;
}

.request-window__empty[hidden],
.request-content[hidden],
.waterfall[hidden] {
  display: none !important;
}

/* Progress ring for sleep countdown */
.sleep-ring {
  fill: none;
  stroke: var(--blue);
  stroke-width: 8;
  opacity: 0.8;
  stroke-linecap: round;
  transform-origin: 0 0;
  transform: rotate(-90deg);
  /* No transition — tick() updates at 60fps for smooth fill,
     and the reset snap-back is instant between cycles. */
}

/* === Toggle Buttons === */
.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-size: 0.7rem;
  font-family: var(--font-sans);
  font-weight: 500;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.15em 0.6em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.toggle-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }

.toggle-icon {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.4;
  transition: background 0.15s, opacity 0.15s;
}

.toggle-btn--active {
  color: var(--accent);
  border-color: var(--accent);
}

.toggle-btn--active .toggle-icon {
  background: var(--accent);
  opacity: 1;
}

/* Panel hidden states */
.detail-panel[hidden] { display: none; }
.resize-handle[hidden] { display: none; }
.log-panel[hidden] { display: none; }

/* === Legend Overlay === */
.legend-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(1, 4, 9, 0.5);
  backdrop-filter: blur(2px);
  z-index: 70;
}

.legend-backdrop[hidden],
.legend-panel[hidden] {
  display: none;
}

.legend-panel {
  position: fixed;
  top: 3.8rem;
  right: 1rem;
  z-index: 80;
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 6.4rem);
  overflow-y: auto;
  padding: 0.9rem;
  background: rgba(22, 27, 34, 0.96);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
}

.legend-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.legend-panel__title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.legend-panel__subtitle {
  margin-top: 0.2rem;
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.legend-section {
  padding-top: 0.8rem;
  margin-top: 0.8rem;
  border-top: 1px solid rgba(61, 68, 77, 0.75);
}

.legend-section:first-of-type {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}

.legend-anatomy {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 1rem;
  align-items: center;
}

.legend-node-demo {
  position: relative;
  width: 9rem;
  height: 9rem;
  margin: 0 auto;
}

.legend-node-demo__trust,
.legend-node-demo__selection,
.legend-node-demo__supervisor,
.legend-node-demo__ring,
.legend-node-demo__sleep,
.legend-node-demo__core,
.legend-node-demo__badge,
.legend-node-demo__sigil {
  position: absolute;
}

.legend-node-demo__trust {
  inset: 1rem;
  border-radius: 50%;
  background: rgba(105, 240, 174, 0.2);
  box-shadow: 0 0 22px rgba(105, 240, 174, 0.42);
}

.legend-node-demo__selection {
  inset: 0.45rem;
  border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  opacity: 0.7;
}

.legend-node-demo__supervisor {
  inset: 0.95rem;
  border-radius: 50%;
  border: 2px solid var(--purple);
  box-shadow: 0 0 12px rgba(188, 140, 255, 0.35);
}

.legend-node-demo__ring {
  inset: 1.7rem;
  border-radius: 50%;
  border: 3px solid var(--green);
  box-shadow: 0 0 10px rgba(63, 185, 80, 0.35);
}

.legend-node-demo__sleep {
  inset: 1.95rem;
  border-radius: 50%;
  border: 5px solid transparent;
  border-top-color: var(--blue);
  border-right-color: var(--blue);
  opacity: 0.85;
  transform: rotate(-40deg);
}

.legend-node-demo__core {
  inset: 2.35rem;
  border-radius: 50%;
  background: rgba(86, 212, 221, 0.28);
  border: 1.5px solid rgba(230, 237, 243, 0.16);
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.18);
}

.legend-node-demo__badge {
  top: 1.6rem;
  right: 1.3rem;
  min-width: 2rem;
  padding: 0.12rem 0.35rem;
  border-radius: 999px;
  background: rgba(13, 17, 23, 0.96);
  border: 1.25px solid rgba(45, 212, 191, 0.45);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  text-align: center;
}

.legend-node-demo__sigil {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(230, 237, 243, 0.9);
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
}

.legend-list {
  display: grid;
  gap: 0.55rem;
}

.legend-item,
.legend-chip,
.legend-link-item {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
}

.legend-copy {
  min-width: 0;
}

.legend-copy strong {
  display: block;
  font-size: 0.78rem;
  color: var(--text-primary);
}

.legend-copy p {
  margin-top: 0.1rem;
  color: var(--text-secondary);
  font-size: 0.72rem;
  line-height: 1.45;
}

.legend-marker {
  flex: 0 0 auto;
  width: 1.4rem;
  height: 1.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(13, 17, 23, 0.92);
}

.legend-marker--fill {
  background: rgba(86, 212, 221, 0.28);
  border: 1px solid rgba(230, 237, 243, 0.16);
}

.legend-marker--ring {
  border: 2px solid var(--green);
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.24);
}

.legend-marker--sleep {
  border: 3px solid transparent;
  border-top-color: var(--blue);
  border-right-color: var(--blue);
  transform: rotate(-35deg);
}

.legend-marker--halo {
  box-shadow:
    0 0 0 2px var(--accent),
    0 0 0 5px rgba(188, 140, 255, 0.35),
    0 0 12px rgba(105, 240, 174, 0.32);
}

.legend-marker--badge {
  width: auto;
  min-width: 2.2rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(45, 212, 191, 0.45);
}

.legend-chip-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem 0.9rem;
}

.legend-mini-node,
.legend-state-swatch,
.legend-glow-swatch {
  flex: 0 0 auto;
}

.legend-mini-node {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: rgba(230, 237, 243, 0.92);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  border: 1px solid rgba(230, 237, 243, 0.16);
}

.legend-mini-node--generic       { background: rgba(139, 148, 158, 0.24); }
.legend-mini-node--metacognitive { background: rgba(188, 140, 255, 0.26); }
.legend-mini-node--channel       { background: rgba(86, 212, 221, 0.26); }
.legend-mini-node--delegate      { background: rgba(210, 153, 34, 0.26); }
.legend-mini-node--scheduled     { background: rgba(88, 166, 255, 0.26); }

.legend-state-swatch {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: rgba(13, 17, 23, 0.92);
  border: 3px solid var(--text-muted);
}

.legend-state-swatch--sleeping   { border-color: var(--blue); box-shadow: 0 0 6px var(--blue-glow); }
.legend-state-swatch--waiting    { border-color: var(--cyan); box-shadow: 0 0 6px var(--cyan-glow); }
.legend-state-swatch--processing { border-color: var(--green); box-shadow: 0 0 8px var(--green-glow); }
.legend-state-swatch--supervisor { border-color: var(--purple); box-shadow: 0 0 12px rgba(188, 140, 255, 0.5); }
.legend-state-swatch--degraded   { border-color: var(--orange); box-shadow: 0 0 8px var(--orange-glow); }
.legend-state-swatch--stopped    { border-color: var(--text-muted); opacity: 0.65; }

.legend-capacity-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.legend-capacity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  background: rgba(13, 17, 23, 0.92);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  border: 1.25px solid rgba(230, 237, 243, 0.22);
}

.legend-capacity-badge--context {
  border-color: rgba(45, 212, 191, 0.45);
}

.legend-capacity-badge--model {
  border-style: dashed;
  border-color: rgba(210, 153, 34, 0.5);
}

.legend-note {
  margin-top: 0.45rem;
  color: var(--text-secondary);
  font-size: 0.72rem;
}

.legend-glow-swatch {
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: rgba(13, 17, 23, 0.65);
}

.legend-glow-swatch--admin {
  box-shadow: 0 0 12px rgba(38, 166, 154, 0.8);
  border: 2px solid rgba(38, 166, 154, 0.9);
}

.legend-glow-swatch--household {
  box-shadow: 0 0 12px rgba(224, 64, 251, 0.8);
  border: 2px solid rgba(224, 64, 251, 0.9);
}

.legend-glow-swatch--trusted {
  box-shadow: 0 0 12px rgba(105, 240, 174, 0.8);
  border: 2px solid rgba(105, 240, 174, 0.9);
}

.legend-glow-swatch--unknown {
  box-shadow: 0 0 12px rgba(255, 82, 82, 0.8);
  border: 2px solid rgba(255, 82, 82, 0.9);
}

.legend-link-list {
  display: grid;
  gap: 0.6rem;
}

.legend-line-swatch {
  width: 3.4rem;
  height: 0;
  margin-top: 0.72rem;
  border-top: 3px solid var(--text-muted);
  opacity: 0.6;
}

.legend-line-swatch--child {
  border-top-width: 2px;
  border-top-style: dashed;
}

.legend-line-swatch--flash {
  border-top-color: var(--accent);
  border-top-width: 4px;
  opacity: 0.9;
}

/* === Context Menu === */
.context-menu {
  position: fixed;
  z-index: 100;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0;
  min-width: 160px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.context-menu[hidden] { display: none; }

.context-menu li {
  list-style: none;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.1s;
}

.context-menu li:hover { background: var(--bg-hover); }

.context-menu-item--disabled {
  color: var(--text-muted);
  cursor: default;
}

.context-menu-item--disabled:hover {
  background: transparent;
}

.context-menu-sep {
  border-top: 1px solid var(--border);
  margin: 0.2rem 0;
  padding: 0;
  pointer-events: none;
}

@media (pointer: coarse) {
  .context-menu {
    min-width: 220px;
    border-radius: 12px;
    padding: 0.35rem 0;
  }

  .context-menu li {
    min-height: 2.65rem;
    display: flex;
    align-items: center;
    padding: 0.6rem 0.95rem;
    font-size: 0.92rem;
  }
}

/* === Linking Lines === */
.link-line {
  stroke: var(--text-muted);
  stroke-width: 3;
  fill: none;
  opacity: 0.33;
  stroke-linecap: round;
  pointer-events: none;
  transition: stroke 0.3s ease, opacity 0.3s ease;
}

.link-line--error {
  stroke: var(--red);
  opacity: 0.6;
}

.link-line--degraded {
  stroke: var(--orange);
  opacity: 0.5;
}

.link-line--child {
  stroke: var(--text-muted);
  stroke-width: 2.5;
  stroke-dasharray: 6 4;
  opacity: 0.4;
}

.link-line--flash {
  stroke: var(--accent);
  opacity: 0.8;
  stroke-width: 4;
}

/* === Node Enter/Exit Animations === */
/* Applied to inner <g class="node-inner"> so scale is around (0,0) which is the
   node center (children are drawn centered at origin). */
@keyframes node-enter {
  0%   { transform: scale(0.2); opacity: 0; }
  38%  { transform: scale(0.9); opacity: 1; }
  64%  { transform: scale(1.1); opacity: 1; }
  82%  { transform: scale(0.975); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.node-inner--entering {
  animation: node-enter 0.62s cubic-bezier(0.2, 0.9, 0.24, 1.08) forwards;
}

@keyframes node-exit {
  0%   { transform: scale(1); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

.loop-node--exiting .node-inner {
  animation: node-exit 0.3s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

.loop-node--exiting {
  pointer-events: none;
}

@media (max-width: 820px) {
  .schema-hero,
  .schema-row {
    grid-template-columns: 1fr;
  }

  .schema-hero {
    flex-direction: column;
  }

  .schema-badge-list {
    justify-content: flex-start;
  }

  .legend-panel {
    top: 3.4rem;
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    max-height: calc(100vh - 5.25rem);
  }

  .legend-anatomy,
  .legend-chip-grid {
    grid-template-columns: 1fr;
  }
}

@container inspector (max-width: 34rem) {
  .detail-content {
    padding: 0.65rem;
  }

  .detail-card {
    padding: 0.58rem 0.65rem;
  }

  .schema-card__header {
    padding-right: 2.1rem;
  }

  .schema-row {
    grid-template-columns: minmax(4.75rem, 6.25rem) minmax(0, 1fr);
    gap: 0.45rem;
  }

  .system-summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  }

  .conversation-summary__facts {
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  }

  .detail-metrics {
    grid-template-columns: minmax(4.25rem, auto) minmax(0, 1fr);
    gap: 0.2rem 0.55rem;
  }
}

@container inspector (max-width: 29rem) {
  .schema-hero {
    flex-direction: column;
    gap: 0.55rem;
  }

  .schema-badge-list {
    justify-content: flex-start;
  }

  .schema-row {
    grid-template-columns: 1fr;
    gap: 0.18rem;
  }

  .schema-row__label {
    font-size: 0.66rem;
  }

  .schema-card__header {
    padding-right: 2.05rem;
  }

  .conversation-summary__summary {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .conversation-summary__chevron {
    justify-self: flex-start;
  }

  .conversation-summary__facts,
  .system-summary-grid {
    grid-template-columns: 1fr;
  }

  .detail-metrics,
  .request-meta-bar {
    grid-template-columns: 1fr;
  }

  .request-meta-bar {
    display: grid;
    gap: 0.35rem;
  }

  .waterfall__bar,
  .request-content__header {
    flex-wrap: wrap;
  }

  .waterfall__call-id {
    width: 100%;
  }
}

@container inspector (min-width: 44rem) {
  .schema-row {
    grid-template-columns: 8.75rem minmax(0, 1fr);
  }

  .schema-card__body {
    gap: 0.55rem;
  }

  .conversation-summary__facts {
    grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr));
  }

  .system-summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@container inspector (min-width: 54rem) {
  .system-summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Completed delegate: fade to translucent but stay clickable */
.loop-node--fading .node-inner {
  opacity: 0.35;
  transition: opacity 1s ease-out;
}

/* === Iteration Flash === */
@keyframes ring-flash {
  0%   { opacity: 0.7; stroke-width: 3; }
  100% { opacity: 0; stroke-width: 2; }
}

.node-ring--flash {
  opacity: 0.7;
  stroke-width: 3;
  animation: ring-flash 0.4s ease-out forwards;
}

/* Brief green pulse on the node shape when an iteration completes.
   Guarantees visual feedback even for sub-millisecond handler loops
   where the processing state is too brief to render. */
@keyframes shape-iter-pulse {
  0%   { filter: drop-shadow(0 0 14px var(--green-glow)) brightness(1.3); }
  100% { filter: none; }
}

.node-shape--iter-pulse {
  animation: shape-iter-pulse 0.7s ease-out forwards;
}

/* === Error Shake === */
@keyframes node-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-3px); }
  40%      { transform: translateX(3px); }
  60%      { transform: translateX(-2px); }
  80%      { transform: translateX(2px); }
}

.loop-node--shake .node-inner {
  animation: node-shake 0.3s ease-in-out;
}

/* === Request Detail / Waterfall === */

.request-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
}

.request-content__section {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.request-content__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  cursor: pointer;
  user-select: none;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.request-content__header:hover {
  color: var(--text-primary);
}

.request-content__header .copy-btn {
  opacity: 0;
  transition: opacity 0.15s;
}
.request-content__section:hover .copy-btn,
.request-content__section:focus-within .copy-btn {
  opacity: 1;
}

@media (pointer: coarse) {
  .request-content__header .copy-btn {
    opacity: 1;
  }
}

.request-content__body {
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
  max-height: 200px;
  overflow-y: auto;
}

.request-content__body--collapsed {
  display: none;
}

.waterfall {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
}

.waterfall__title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.waterfall__item {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.waterfall__item:hover {
  border-color: var(--accent);
}

.waterfall__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  user-select: none;
}

.waterfall__index {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 18px;
}

.waterfall__name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  flex: 1;
}

.waterfall__call-id {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.waterfall__expand {
  display: none;
  padding: 0 10px 8px;
}

.waterfall__expand--open {
  display: block;
}

.waterfall__sub-section {
  margin-bottom: 6px;
}

.waterfall__sub-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.waterfall__sub-content {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
  max-height: 160px;
  overflow-y: auto;
  background: var(--bg-tertiary);
  border-radius: 4px;
  padding: 6px 8px;
}

.copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.65rem;
  padding: 1px 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.copy-btn--copied {
  color: var(--green);
  border-color: var(--green);
}

.request-meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 6px 0;
  font-size: 0.75rem;
}

.request-meta-bar__item {
  display: flex;
  align-items: center;
  gap: 3px;
}

.request-meta-bar__label {
  color: var(--text-muted);
}

.request-meta-bar__value {
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.request-meta-bar__value--warn {
  color: var(--orange);
}

.log-id-chip--clickable {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.log-id-chip--clickable:hover {
  color: var(--accent);
}

/* === Responsive === */
@media (max-width: 768px) {
  .notification-stack {
    top: 3.6rem;
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
  }

  .main { flex-direction: column; }

  .resize-handle--v {
    width: auto;
    height: 4px;
    cursor: row-resize;
  }

  .canvas-panel {
    min-height: 38svh;
  }

  .detail-panel {
    width: 100% !important;
    min-width: 0;
    max-width: none;
    min-height: 16rem;
    max-height: min(54svh, 34rem);
  }
}
