:root {
  --text: #1c2b1e;
  --paper: #f0f4ef;
  --ink: #243528;
  --sage: #5a8a5e;
  --line: #c8d9c4;
  --muted: rgba(28, 43, 30, 0.62);
  --card: #f7faf6;
  --failed: #8f4d45;
  --pending: #8a7340;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  color: var(--text);
  background:
    linear-gradient(rgba(200, 217, 196, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200, 217, 196, 0.35) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px, 28px 28px, auto;
  font-family: Inter, -apple-system, "system-ui", "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

/* —— Auth gate —— */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(380px, 100%);
  padding: 28px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
}
.gate-card .mark { display: block; margin-bottom: 14px; }
.gate-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.gate-note {
  margin: 6px 0 18px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}
.gate label {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.gate input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.gate button[type="submit"] {
  width: 100%;
  margin-top: 4px;
  padding: 10px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.gate button[type="submit"]:disabled {
  opacity: 0.55;
  cursor: default;
}
.dev-code {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(90, 138, 94, 0.16);
  color: var(--sage);
  font-size: 13px;
  font-weight: 600;
}
.error {
  margin: 12px 0 0;
  color: var(--failed);
  font-size: 13px;
  font-weight: 500;
}
.error.banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid #e38b84;
  border-radius: 12px;
  background: rgba(143, 77, 69, 0.1);
}

/* —— Shell —— */
.shell {
  display: grid;
  grid-template-columns: 72px 300px 1fr;
  gap: 14px;
  height: 100vh;
  padding: 14px;
  overflow: hidden;
}

.rail,
.drawer,
.rest {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
}

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 16px 0;
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
  position: relative;
  z-index: 4;
  height: 100%;
  overflow: visible;
}
.drawer, .rest { height: 100%; overflow: auto; }
.drawer { padding: 18px 14px 14px; }
.drawer-pane[hidden],
.view[hidden] { display: none !important; }

.mark {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--sage);
}

.rail nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rail-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: rgba(240, 244, 239, 0.62);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.rail-btn svg { width: 20px; height: 20px; }
.rail-btn.on { background: rgba(90, 138, 94, 0.28); color: var(--paper); }

.profile-menu { margin-top: auto; position: relative; }
.profile-menu summary { list-style: none; cursor: pointer; }
.profile-menu summary::-webkit-details-marker { display: none; }
.menu {
  position: absolute;
  left: calc(100% + 10px);
  bottom: 0;
  min-width: 180px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(28, 43, 30, 0.08);
  z-index: 3;
}
.menu button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.menu button:hover:not(:disabled) { background: rgba(90, 138, 94, 0.12); }
.menu button:disabled { color: var(--muted); cursor: default; }
.menu em { font-style: normal; font-weight: 500; font-size: 11px; color: var(--muted); }

.drawer-pane[data-pane="home"] {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.tool-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tool-options button,
.work {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tool-options button {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 10px;
  text-align: left;
}
.tool-options button .tool-copy { min-width: 0; flex: 1; }
.tool-options button em {
  display: block;
  margin-top: 2px;
  font-style: normal;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}
.tool-mark {
  width: 22px;
  height: 22px;
  flex: none;
  display: block;
}
.tool-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.works {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
  min-height: 0;
}
.works h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
#works-list { display: flex; flex-direction: column; gap: 8px; }
.work { padding: 12px; text-align: left; width: 100%; }
.work.on,
.work:hover { background: rgba(90, 138, 94, 0.12); border-color: var(--sage); }

/* Agent work pane (not Iris .bubble.agent — class name collision). */
.rest > .agent,
section.agent {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 70vh;
}
.rest > .agent[hidden],
section.agent[hidden] { display: none !important; }
.rest.is-agent .home-page,
.rest.is-agent .nodes-page,
.rest.is-agent .iris-page,
.rest.is-agent .tools-page { display: none !important; }

.tool-grid {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.tool-grid li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-weight: 600;
}
.tool-grid .tool-label { font-weight: 600; font-size: 14px; }
.tool-grid .tool-mark { width: 24px; height: 24px; }
.tool-grid .tool-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tool-grid em {
  font-style: normal;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
}
.tool-grid .connect {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.tool-grid .connect:hover { border-color: var(--sage); background: rgba(90, 138, 94, 0.12); }
.drawer-pane[data-pane="tools"] .tool-options { flex-direction: column; }
.drawer-pane[data-pane="nodes"] { display: flex; flex-direction: column; gap: 8px; }

.agent-bar { display: flex; align-items: center; gap: 12px; }
.agent-bar h2 { margin: 0; font-size: 18px; font-weight: 700; }
.agent-role { color: var(--muted); font-size: 12px; font-weight: 600; }
.back {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
}
.chat { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 460px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.bubble span { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--sage); }
.bubble p { margin: 4px 0 0; font-size: 14px; }
.bubble.agent { margin-left: 28px; background: var(--paper); }
.bubble.tool { margin-left: 28px; border-style: dashed; }
.bubble .dots { height: 8px; }

.drawer-head h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.drawer-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.drawer-list,
.feed {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.drawer-list { display: flex; flex-direction: column; gap: 6px; }

.thread { margin-top: 16px; }
.thread h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.d-item {
  position: relative;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 10px 10px 16px;
  border-radius: 14px;
}
.d-item:first-child { background: rgba(90, 138, 94, 0.12); }

.face {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: visible;
  flex: none;
  background: var(--ink);
  color: var(--paper);
}
.face.sm { width: 32px; height: 32px; border-radius: 8px; }
.face img,
.initials {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: cover;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
}
.initials { display: grid; }
.badge {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 16px;
  height: 16px;
  padding: 1px;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}

.d-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.d-name { font-size: 13px; font-weight: 600; }
.d-line {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.d-item > time {
  color: var(--muted);
  font-size: 11px;
  padding-top: 2px;
}

.rest { padding: 16px 18px 28px; }

.node-area {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  min-height: 56px;
}
.node-area:empty::before,
.empty-hint {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.node-area:empty::before {
  content: "No nodes yet";
  align-self: center;
}

.node {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
.node strong { display: block; font-size: 14px; }
.node span,
.node em { color: var(--muted); font-style: normal; font-size: 12px; font-weight: 500; }

.node.live {
  border-color: var(--sage);
  background: rgba(90, 138, 94, 0.1);
  animation: live-blink 1.4s ease-in-out infinite;
}
.node.live span { color: var(--sage); }

.node.down {
  border-color: #e38b84;
  background: rgba(143, 77, 69, 0.1);
  box-shadow: 0 0 0 3px rgba(227, 139, 132, 0.28);
}
.node.down span { color: var(--failed); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e38b84;
}
.node.live .dot { background: var(--sage); }

.disconnected-block {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  padding: 0;
}
.disconnected-block[hidden] { display: none !important; }
.disconnected-block > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: -0.01em;
}
.disconnected-block > summary::-webkit-details-marker { display: none; }
.disconnected-block > summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  margin-right: 6px;
  color: var(--sage);
}
.disconnected-block[open] > summary::before { content: "▾"; }
.disconnected-list {
  margin: 0 12px 12px;
  border-style: dashed;
  min-height: 0;
}
.disconnected-list:empty::before { content: none; }

.node-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-left: auto;
}
.node .rename {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  cursor: pointer;
  white-space: nowrap;
}
.node .rename:hover { border-color: var(--sage); background: rgba(90, 138, 94, 0.12); }

.iris-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: calc(100vh - 48px);
  min-height: 0;
  overflow: hidden;
}
.iris-layout {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}
.iris-views {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}
@media (max-width: 900px) {
  .iris-views { grid-template-columns: 1fr; }
}
.iris-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 8px;
  overflow: hidden;
}
.iris-col-title {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  flex: 0 0 auto;
  color: var(--muted);
}
/* Transcript scrolls; bubbles never stretch to fill the pane. */
.iris-chat {
  list-style: none;
  margin: 0;
  padding: 0 4px 8px 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}
.iris-chat .bubble {
  flex: 0 0 auto;
  height: auto;
  max-height: none;
  align-self: stretch;
}
.iris-chat .bubble.you {
  align-self: flex-end;
  max-width: 92%;
}
.iris-chat .bubble.agent,
.iris-chat .bubble.fail {
  align-self: stretch;
  max-width: 92%;
}
.iris-chat:empty::before {
  content: "No messages yet.";
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  flex: 0 0 auto;
  align-self: flex-start;
  padding: 4px 0;
}
.iris-agent-chat:empty::before {
  content: "Agent pipe is empty until the brain passes a batch.";
}
.iris-events {
  flex: 0 0 auto;
  max-height: 28vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  overflow: hidden;
}
.iris-event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}
.iris-event-list li {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}
.iris-event-list .ev-name {
  color: var(--ink);
  font-weight: 600;
}
.iris-event-list .ev-tx {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  opacity: 0.75;
}
.iris-event-list:empty::before {
  content: "No events yet.";
  color: var(--muted);
}
.bubble.you {
  background: rgba(90, 138, 94, 0.12);
  border-color: var(--sage);
}
.bubble.you span { color: var(--ink); }
.bubble.fail {
  border-color: #e38b84;
  background: rgba(143, 77, 69, 0.1);
}
.bubble.fail span { color: var(--failed); }
.bubble .state {
  margin-left: 6px;
  font-size: 10px;
  font-weight: 600;
  opacity: 0.65;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.receipt-ticks {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  margin-left: 6px;
  vertical-align: middle;
}
.receipt-ticks .tick {
  display: inline-block;
  width: 9px;
  height: 9px;
  position: relative;
}
.receipt-ticks .tick::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 0;
  width: 4px;
  height: 7px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.receipt-ticks .tick-grey { color: #8aa08a; }
.receipt-ticks .tick-blue { color: #5a8a5e; }
.iris-compose {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex: 0 0 auto;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}
.iris-compose textarea {
  flex: 1;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  min-height: 44px;
  max-height: 120px;
}
.iris-compose button {
  padding: 10px 16px;
  border: 1px solid var(--sage);
  border-radius: 14px;
  background: var(--sage);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.iris-compose button:disabled {
  opacity: 0.55;
  cursor: wait;
}
.iris-refresh {
  align-self: flex-start;
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes live-blink {
  0%, 100% { box-shadow: 0 0 0 0 rgba(90, 138, 94, 0.15); }
  50% { box-shadow: 0 0 0 4px rgba(90, 138, 94, 0.45); }
}

.split {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.split::before,
.split::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.feed { display: flex; flex-direction: column; gap: 8px; }

.row {
  position: relative;
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-areas:
    "time who"
    "time text";
  gap: 2px 12px;
  padding: 12px 14px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
}
.row time { grid-area: time; color: var(--muted); font-size: 12px; padding-top: 6px; }
.who { grid-area: who; display: flex; align-items: center; gap: 8px; }
.name { font-weight: 600; font-size: 14px; }
.row p { grid-area: text; margin: 0; font-size: 14px; }

.react {
  position: absolute;
  right: 10px;
  bottom: -10px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--sage);
}
.react svg { width: 14px; height: 14px; }
.pending .react { color: var(--pending); }
.failed .react { color: var(--failed); }
.ignored .react,
.ignored .d-line,
.ignored p { color: var(--muted); }

.dots { display: flex; align-items: flex-end; gap: 2px; height: 10px; }
.dots i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  animation: wave 0.9s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes wave {
  0%, 70%, 100% { transform: translateY(0); }
  35% { transform: translateY(-4px); }
}

.tip {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  padding: 3px 7px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.react:hover .tip,
.react:focus .tip { opacity: 1; }

.empty-block {
  margin-top: 16px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

/* —— 3h demo lists —— */
.demo-works, .demo-updates, .demo-audits { margin: 0 0 18px; padding: 0 4px; }
.demo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.demo-row {
  display: grid; gap: 2px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  cursor: default;
}
.demo-row.unread { border-color: var(--sage); box-shadow: inset 3px 0 0 var(--sage); }
.demo-meta { font-size: 12px; color: var(--muted); }
.demo-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.demo-table th, .demo-table td {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.demo-table th { color: var(--muted); font-weight: 500; }
