/* Relay — dark tool chrome. Amber is signal only (see DESIGN.md):
   it appears where signal is moving or has landed, nowhere else.
   Green only for "done". The page around the tool lives in present.css. */

:root {
  --bg: #101012;
  --panel: #151517;
  --panel-2: #1a1a1d;
  --node: #1c1c20;
  --node-border: #2e2e35;
  --line: #26262c;
  --text: #ece9e2;
  --muted: #9b978c;
  --faint: #6d6a61;
  --amber: #edb54f;
  --amber-deep: #c08c2a;
  --green: #57b981;
  --green-dim: #2c5c42;
  --red: #cf6a5e;
  --paper: #f5f1e8;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Archivo", -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- top bar ---------- */

.topbar {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--text); display: inline-flex; }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -0.02em; font-stretch: 125%; }

.workflow-name {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
}
.workflow-name input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  padding: 5px 9px;
  width: 210px;
  text-align: center;
}
.workflow-name input:hover { border-color: var(--line); }
.workflow-name input:focus { outline: none; border-color: #3d3d46; background: var(--panel-2); }
.saved-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  opacity: 0;
  transition: opacity .3s;
}
.saved-dot.show { opacity: 1; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.runs-count { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-right: 4px; white-space: nowrap; }

.btn {
  border: 1px solid var(--node-border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 7px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  transition: transform .16s var(--ease-out), background-color .16s var(--ease-out), border-color .16s var(--ease-out), color .16s var(--ease-out);
}
.btn:hover { border-color: #3d3d46; }
.btn:active { transform: scale(0.97); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-run {
  background: var(--amber);
  border-color: var(--amber);
  color: #1d1607;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 16px;
}
.btn-run:hover { background: #f2c169; border-color: #f2c169; }
.btn-run:disabled { opacity: .55; cursor: wait; }
.btn-small { padding: 4px 10px; font-size: 12px; }

/* ---------- layout ---------- */

.layout {
  display: flex;
  min-height: 0;
}

/* ---------- palette ---------- */

.palette {
  width: 218px;
  flex: 0 0 218px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.palette-scroll { padding: 14px 12px 6px; overflow-y: auto; }
.palette-group-label {
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 14px 4px 7px;
  font-weight: 600;
}
.palette-group-label:first-child { margin-top: 0; }

.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 8px;
  margin-bottom: 2px;
  color: var(--text);
  font-size: 13px;
}
.palette-item:hover { background: var(--panel-2); border-color: var(--line); }
.palette-item:active { cursor: grabbing; }
.palette-item .p-icon {
  width: 28px; height: 28px;
  flex: 0 0 28px;
  border-radius: 7px;
  background: #222228;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.palette-item .p-sub { display: block; color: var(--faint); font-size: 11px; margin-top: 1px; }

.palette-foot {
  margin-top: auto;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
}
.what-is { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 0 0 8px; }
.palette-hint { color: var(--faint); font-size: 11.5px; line-height: 1.5; margin: 0; }

/* ---------- canvas ---------- */

.canvas-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  background: var(--bg);
  overflow-x: auto;
  overflow-y: hidden;
}
.canvas {
  position: absolute;
  inset: 0;
  min-width: 1060px;
  overflow: hidden;
  background-image: radial-gradient(circle, #26262b 1px, transparent 1px);
  background-size: 22px 22px;
}
.edges { position: absolute; inset: 0; width: 100%; height: 100%; }
.nodes { position: absolute; inset: 0; pointer-events: none; }

.edge-path {
  fill: none;
  stroke: #4a4a52;
  stroke-width: 1.6;
}
.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  cursor: pointer;
  pointer-events: stroke;
}
.edge-group.is-selected .edge-path { stroke: #8e8e99; }
.edge-group.is-flowing .edge-path {
  stroke: var(--amber);
  stroke-dasharray: 6 6;
  animation: dashmove 0.7s linear infinite;
}
.edge-group.is-done .edge-path { stroke: var(--green-dim); }
.edge-temp {
  fill: none;
  stroke: var(--amber);
  stroke-width: 1.6;
  stroke-dasharray: 5 5;
  pointer-events: none;
}
@keyframes dashmove {
  to { stroke-dashoffset: -12; }
}
.edge-x {
  cursor: pointer;
  pointer-events: all;
}
.edge-x circle { fill: #26262c; stroke: #4a4a52; }
.edge-x text { fill: #d8d4c9; font-size: 11px; text-anchor: middle; pointer-events: none; }

/* ---------- nodes ---------- */

.node {
  position: absolute;
  pointer-events: auto;
  width: 228px;
  background: var(--node);
  border: 1px solid var(--node-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
  user-select: none;
  transition: border-color .2s, box-shadow .2s;
}
.node[data-kind="agent"] { width: 264px; }
.node.is-selected { border-color: #55555f; }
.node.is-running {
  border-color: var(--amber);
  animation: nodepulse 1.1s ease-in-out infinite;
}
.node.is-done { border-color: var(--green-dim); }
@keyframes nodepulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(237,181,79,.35), 0 6px 18px rgba(0,0,0,.35); }
  50% { box-shadow: 0 0 0 7px rgba(237,181,79,0), 0 6px 18px rgba(0,0,0,.35); }
}

.node-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  cursor: grab;
}
.node-head:active { cursor: grabbing; }
.node-icon {
  width: 32px; height: 32px;
  flex: 0 0 32px;
  border-radius: 8px;
  background: #26262c;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.node-title { font-weight: 600; font-size: 13.5px; line-height: 1.25; }
.node-sub { color: var(--faint); font-size: 11.5px; margin-top: 1px; line-height: 1.35; }
.node-status {
  margin-left: auto;
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--faint);
}
.node-status.ok { color: var(--green); }
.node-del {
  position: absolute;
  top: -8px; right: -8px;
  width: 19px; height: 19px;
  border-radius: 50%;
  border: 1px solid var(--node-border);
  background: #26262c;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 3;
}
.node:hover .node-del, .node.is-selected .node-del { display: inline-flex; }
.node-del:hover { color: #fff; border-color: var(--red); background: #3a2320; }

.port {
  position: absolute;
  top: 26px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid #4a4a52;
  z-index: 2;
}
.port-in { left: -7px; }
.port-out { right: -7px; cursor: crosshair; }
.port:hover { border-color: var(--amber); background: var(--amber); }
.port.is-target { border-color: var(--amber); background: var(--amber); transform: scale(1.25); }

/* node bodies */
.node-body { border-top: 1px solid var(--line); padding: 10px 12px 12px; }
.node-body:empty { display: none; }

.field-label { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin: 0 0 5px; font-weight: 600; }
.node select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--node-border);
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 12.5px;
  font-family: inherit;
  margin-bottom: 10px;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  border: 1px solid var(--node-border);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 20px;
  padding: 3px 9px;
  font-size: 11.5px;
}
button.chip { cursor: pointer; transition: transform .16s var(--ease-out), color .16s var(--ease-out), background-color .16s var(--ease-out), border-color .16s var(--ease-out); }
button.chip:hover { color: var(--text); }
button.chip:active { transform: scale(0.97); }
button.chip.is-on { color: #cdeeda; border-color: var(--green-dim); background: #1d2a22; }
.chip.static { cursor: default; }
.chip b { color: var(--text); font-weight: 600; }

/* lead card inside trigger while running */
.lead-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 12px;
  animation: slideDown .2s var(--ease-out);
}
.lead-card .lead-name { font-weight: 600; font-size: 12.5px; }
.lead-card .lead-meta { color: var(--faint); font-family: var(--mono); font-size: 10.5px; margin: 2px 0 5px; }
.lead-card .lead-msg { color: var(--muted); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* agent analysis */
.agent-thinking { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.think-dots span {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--amber);
  margin-right: 3px;
  animation: blink 1s infinite;
}
.think-dots span:nth-child(2) { animation-delay: .18s; }
.think-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.analysis { animation: slideDown .2s var(--ease-out); }
.analysis-top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 7px; }
.score {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 500;
  color: var(--amber);
}
.score small { font-size: 10.5px; color: var(--faint); }
.intent { font-size: 12.5px; color: var(--text); font-weight: 500; }
.analysis .chips { margin-top: 2px; }

/* ---------- right panel ---------- */

.panel {
  width: 348px;
  flex: 0 0 348px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-tabs {
  display: flex;
  gap: 2px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--line);
}
.panel-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 10px 9px;
  position: relative;
  transition: color .18s var(--ease-out), border-color .18s var(--ease-out);
}
.panel-tab:hover { color: var(--text); }
.panel-tab.is-active { color: var(--text); border-bottom-color: var(--text); }
.tab-badge {
  position: absolute;
  top: 5px; right: 2px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--amber);
}
.panel-page { display: none; flex: 1; overflow-y: auto; min-height: 0; }
.panel-page.is-active { display: block; }

/* log */
.log { padding: 14px 16px; }
.log-empty p { color: var(--muted); margin: 0 0 6px; }
.log-empty-sub { font-size: 12.5px; line-height: 1.55; color: var(--faint) !important; }
.log-empty-sub strong { color: var(--text); font-weight: 600; }
.log-entry {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed #202025;
  animation: slideDown .2s var(--ease-out);
  font-size: 12.5px;
  line-height: 1.5;
}
.log-entry:last-child { border-bottom: none; }
.log-time { font-family: var(--mono); font-size: 11px; color: var(--faint); flex: 0 0 62px; padding-top: 2px; }
.log-text { color: #cfccc2; }
.log-text b { color: var(--text); }
.log-entry.is-head { border-bottom: 1px solid var(--line); padding-bottom: 9px; }
.log-entry.is-head .log-text { font-weight: 600; color: var(--text); }
.log-entry.is-done .log-text { color: var(--green); }
.log-summary-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid #3a3a42;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0 4px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #cfccc2;
  animation: slideDown .2s var(--ease-out);
}
.log-summary-card .sc-head { font-family: var(--mono); font-size: 10.5px; color: var(--faint); margin-bottom: 5px; }

/* email draft */
.email-view { padding: 16px; }
.panel-empty p { color: var(--muted); margin: 0 0 6px; }
.panel-empty-sub { font-size: 12.5px; line-height: 1.55; color: var(--faint) !important; }
.draft {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px;
  animation: slideDown .2s var(--ease-out);
}
.draft-row { display: flex; gap: 10px; padding: 4px 0; font-size: 13px; }
.draft-label { color: var(--faint); flex: 0 0 52px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; padding-top: 2px; font-weight: 600; }
.draft-to { font-family: var(--mono); font-size: 12px; }
.draft-subject { font-weight: 600; }
.draft-body {
  border-top: 1px solid var(--line);
  margin-top: 9px;
  padding-top: 12px;
  font-size: 13px;
  line-height: 1.65;
  color: #ddd9cf;
  white-space: pre-wrap;
}
.draft-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 11px;
}
.draft-status { color: var(--faint); font-size: 11.5px; }
.draft-status.sent { color: var(--green); }

/* crm */
.crm-view { padding: 16px; }
.crm-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.crm-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.crm-count { color: var(--faint); font-size: 11.5px; font-family: var(--mono); }
.crm-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.crm-table th {
  text-align: left;
  color: var(--faint);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 600;
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
}
.crm-table td { padding: 8px 6px; border-bottom: 1px solid #202025; vertical-align: top; }
.crm-table .c-name { font-weight: 500; }
.crm-table .c-score { font-family: var(--mono); color: var(--amber); }
.crm-table .c-status { color: var(--muted); font-size: 11.5px; }
.crm-table tr.is-new td { background: #1e2a21; animation: slideDown .2s var(--ease-out); }
.panel-note { color: var(--faint); font-size: 11.5px; line-height: 1.55; margin: 12px 0 0; }

/* calendar */
.cal-view { padding: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cal-day {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 7px 9px;
  min-height: 118px;
}
.cal-day-name { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); font-weight: 600; margin-bottom: 7px; }
.cal-block {
  background: #26262c;
  border-radius: 5px;
  padding: 5px 6px;
  font-size: 10.5px;
  line-height: 1.35;
  margin-bottom: 5px;
  color: #cfccc2;
}
.cal-block .cb-time { font-family: var(--mono); color: var(--muted); display: block; font-size: 10px; }
.cal-block.is-new {
  background: #3a2d13;
  border: 1px solid var(--amber-deep);
  color: #f3e3bd;
  animation: slideDown .2s var(--ease-out);
}
.cal-block.is-new .cb-time { color: var(--amber); }
.cal-block.tentative { border-style: dashed; }

/* toast */
.canvas-toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #232329;
  border: 1px solid var(--node-border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  z-index: 20;
  animation: slideDown .18s var(--ease-out);
}

/* drag ghost from palette */
.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: var(--node);
  border: 1px solid #55555f;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  opacity: .92;
  box-shadow: 0 10px 26px rgba(0,0,0,.5);
}

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c2c33; border-radius: 6px; border: 2px solid var(--panel); }
::-webkit-scrollbar-track { background: transparent; }

/* keyboard focus — visible, neutral */
:focus-visible { outline: 2px solid #55555f; outline-offset: 2px; }

/* ---------- small screens: the tool stacks ---------- */

@media (max-width: 920px) {
  .tool-shell { height: auto; max-height: none; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; row-gap: 6px; }
  .workflow-name { order: 3; margin: 0; width: 100%; }
  .workflow-name input { width: 100%; text-align: left; }
  .layout { flex-direction: column; }
  .palette {
    width: auto;
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .palette-scroll { max-height: 172px; }
  .palette-foot { display: none; }
  .canvas-wrap { flex: none; height: 470px; }
  .canvas { min-width: 900px; }
  .panel {
    width: auto;
    flex: none;
    border-left: none;
    border-top: 1px solid var(--line);
  }
  .panel-page { max-height: 400px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01s !important; transition-duration: .01s !important; }
}
