/* Agent Box shell — sidebar app in the Substation/agent-q mold. */

:root {
  --bg: #0f1115;
  --bg-panel: #14171d;
  --bg-card: #191d25;
  --line: #262b35;
  --text: #e6e9ef;
  --text-dim: #98a1b2;
  --accent: #6ea8fe;
  --accent-dim: #24344f;
  /* Borders are for edges of boxes; this is for lines drawn across one. */
  --flow-line: #4a5364;
  --radius: 10px;
  --sidebar-w: 232px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-panel: #ffffff;
    --bg-card: #ffffff;
    --line: #dfe4ec;
    --text: #1b202a;
    --text-dim: #5d6779;
    --accent: #2c6bd8;
    --accent-dim: #e4edfd;
    --flow-line: #a8b2c2;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; text-decoration: none; }

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---- sidebar ---- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 12px;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
}

.brand-mark {
  font-size: 20px;
  color: var(--accent);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text small { color: var(--text-dim); font-size: 12px; }

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
}

.nav-item:hover { background: var(--accent-dim); color: var(--text); }

.nav-item.is-active {
  background: var(--accent-dim);
  color: var(--text);
  font-weight: 600;
}

.nav-icon { width: 18px; text-align: center; opacity: .9; }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.env {
  align-self: flex-start;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: 10px;
}

.env-test { color: var(--accent); border-color: var(--accent); }

.build {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.panel {
  padding: 32px clamp(20px, 4vw, 48px) 56px;
  max-width: 980px;
}

.panel.htmx-request { opacity: .5; transition: opacity .12s ease-in; }

.page-head h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.01em; }
.lede { margin: 0 0 24px; color: var(--text-dim); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
}

.card h2 { margin: 0 0 8px; font-size: 16px; }
.card p { margin: 0; color: var(--text-dim); }

.empty { text-align: center; padding: 44px 22px; }
.empty-mark { font-size: 34px; margin: 0 0 10px; color: var(--accent); opacity: .8; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.tile:hover { border-color: var(--accent); }
.tile-icon { font-size: 18px; color: var(--accent); }
.tile-blurb { color: var(--text-dim); font-size: 13px; }

.meta dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: 13px;
}

.meta dt { color: var(--text-dim); }
.meta dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---- duties: search plus a list of rows ---- */

.search {
  position: relative;
  margin-bottom: 18px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 16px;
}

.search input {
  width: 100%;
  padding: 11px 14px 11px 34px;
  font: inherit;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.search input:focus {
  outline: none;
  border-color: var(--accent);
}

.search input::placeholder { color: var(--text-dim); }

.result-count {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.duty-rows.htmx-request { opacity: .5; transition: opacity .12s ease-in; }

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

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

.row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.row-desc {
  color: var(--text-dim);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-side { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.badge {
  padding: 2px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.badge-cron, .badge-button, .badge-hook, .badge-node {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.badge-on { color: var(--text); }
.badge-off { opacity: .7; text-decoration: line-through; }

.crumb { margin: 0 0 8px; font-size: 13px; color: var(--text-dim); }
.crumb a:hover { color: var(--accent); }

.node-list { margin: 12px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.node-list .badge { margin-right: 6px; }

.node-next { color: var(--text-dim); font-size: 13px; }

/* ---- the flow graph: a duty's steps, left to right ---- */

/* One colour per step type, used by the node, its icon and the legend, so the
   same thing always reads the same way. */
.flow-code     { --node: #6ea8fe; }
.flow-llm      { --node: #b98cf0; }
.flow-decision { --node: #e0b154; }
.flow-notify   { --node: #5fbf90; }
.flow-noop     { --node: var(--text-dim); }
.flow-unknown  { --node: #d97b6c; }

.flow-card p { margin-bottom: 4px; }

/* A wide duty scrolls sideways inside its card rather than stretching the
   page — the sidebar layout has no room to give. */
.flow-scroll {
  overflow-x: auto;
  margin: 14px -6px 0;
  padding: 0 6px 6px;
}

/* The inline style carries the natural width and the floor it may shrink to;
   `height: auto` lets the viewBox keep the aspect ratio while it does. */
.flow { display: block; max-width: 100%; height: auto; }

.flow-node-box {
  fill: var(--bg-panel);
  stroke: var(--node);
  stroke-width: 1.5;
}

.flow-noop .flow-node-box { stroke-dasharray: 5 4; }

.flow-node-icon {
  fill: var(--node);
  font: 600 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.flow-node-label { fill: var(--text); font: 600 13px ui-sans-serif, system-ui, sans-serif; }

.flow-node-sub {
  fill: var(--text-dim);
  font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Arrows sit on the card, not on the page, so they need to be a step
   stronger than `--line` to be followed across a gap. */
.flow-edge {
  fill: none;
  stroke: var(--flow-line);
  stroke-width: 1.8;
}

/* A loop back to an earlier step, drawn under the graph — dashed so it is not
   mistaken for the forward path. */
.flow-edge.is-back { stroke-dasharray: 6 5; }

.flow-arrow-head { fill: var(--flow-line); }

.flow-edge-label rect { fill: var(--bg-card); stroke: var(--line); }

.flow-edge-label text {
  fill: var(--text-dim);
  text-anchor: middle;
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.flow-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 12px 0 0;
  padding: 0;
  font-size: 12px;
  color: var(--text-dim);
}

.flow-legend li { display: flex; align-items: baseline; gap: 6px; }

.flow-legend-mark {
  color: var(--node);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.flow-legend-blurb { opacity: .8; }

.flow-none { margin-top: 12px; }
.flow-warn { margin-top: 12px; color: #d97b6c; font-size: 13px; }

.flow-list { margin-top: 14px; font-size: 13px; }
.flow-list summary { color: var(--text-dim); cursor: pointer; }
.flow-list summary:hover { color: var(--accent); }
.flow-list .node-list { font-size: 13px; }

/* ---- buttons ---- */

.btn {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }

.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.page-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.empty-action { margin: 16px 0 0; }

/* ---- the duty-building chat ---- */

.chat-log {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 12px 14px;
  max-width: 44em;
}

.msg-who {
  display: block;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}

/* The agent writes prose with its own line breaks — keep them. */
.msg-text { margin: 0; white-space: pre-wrap; }

.msg-you { margin-left: auto; border-color: var(--accent-dim); background: var(--accent-dim); }
.msg-you .msg-who { color: var(--accent); }

/* The box speaking for itself: errors, and "saved". Never the agent's voice. */
.msg-box { border-style: dashed; }
.msg-box .msg-text { color: var(--text-dim); }

.proposal { border-color: var(--accent); }
.proposal h3 { margin: 18px 0 0; font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; }
.proposal-desc { margin: 0; color: var(--text-dim); }

.proposal-meta {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 4px 12px;
  margin: 14px 0 0;
  font-size: 14px;
}

.proposal-meta dt { color: var(--text-dim); }
.proposal-meta dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.verdict { margin-top: 16px; font-size: 14px; border-left: 3px solid var(--line); padding-left: 12px; }
.verdict ul { margin: 6px 0 0; padding-left: 18px; }
.verdict-bad { border-left-color: #d97b6c; }
.verdict-bad p { margin: 8px 0 0; }
.verdict-note { border-left-color: var(--accent); color: var(--text-dim); }

.proposal-actions { display: flex; gap: 10px; margin-top: 18px; }

.chat-say { display: flex; flex-direction: column; gap: 8px; max-width: 44em; }

.chat-say textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.chat-say textarea:focus { outline: none; border-color: var(--accent); }
.chat-say-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hint { color: var(--text-dim); font-size: 12px; }

.thinking { margin: 0; color: var(--accent); font-size: 13px; }
.htmx-indicator { display: none; }
.htmx-request .thinking, .htmx-request.thinking { display: block; }

/* ---- runs: what a duty actually did ---- */

/* One colour per outcome, used by the history badge and by the step marks, so
   a failed run reads the same everywhere. `held` is deliberately not green:
   it ran, but nothing left the box. */
.run-succeeded, .badge-run-succeeded { --run: #5fbf90; }
.run-partial,   .badge-run-partial   { --run: #e0b154; }
.run-failed,    .badge-run-failed    { --run: #d97b6c; }
.run-running,   .badge-run-running   { --run: var(--accent); }

.badge-run {
  color: var(--run, var(--text-dim));
  border-color: var(--run, var(--line));
  font-weight: 600;
}

.runs-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.runs-head h2 { margin-bottom: 4px; }
.runs-head form { margin: 0; }

.run-rows .row-desc { -webkit-line-clamp: 2; }
.runs-none { margin-top: 4px; }

.run-summary h2 { margin-bottom: 12px; }
.run-error {
  margin-top: 14px;
  padding-left: 12px;
  border-left: 3px solid var(--run, var(--line));
  color: var(--text);
  font-size: 14px;
}

.run-steps {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.run-step {
  border: 1px solid var(--line);
  border-left: 3px solid var(--step, var(--line));
  border-radius: var(--radius);
  padding: 12px 14px;
}

/* A step that didn't run is visibly quieter than one that did — but it is
   still on the page, because a skipped step is news too. */
.run-step-ok        { --step: #5fbf90; }
.run-step-held      { --step: #e0b154; }
.run-step-failed    { --step: #d97b6c; }
.run-step-skipped   { --step: var(--line); opacity: .72; }
.run-step-unreached { --step: var(--line); opacity: .55; }

.run-step-head { display: flex; align-items: baseline; gap: 10px; }
.run-step-mark { color: var(--step, var(--text-dim)); font-weight: 700; }
.run-step-name { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; min-width: 0; }
.run-step-status { margin-left: auto; color: var(--text-dim); font-size: 12px; white-space: nowrap; }

.run-step-detail { margin: 6px 0 0 26px; color: var(--text-dim); font-size: 13px; }

.run-step-output {
  margin: 10px 0 0 26px;
  padding: 10px 12px;
  max-height: 18em;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- integrations: one row per door, each carrying its own state ---- */

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .92em;
  padding: 1px 5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  word-break: break-word;
}


.door {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.door-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1 1 320px; }
.door-name { display: flex; flex-direction: column; gap: 2px; }
.door-name:hover strong { color: var(--accent); }
.door-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.door-note { margin: 0 0 10px; }
.door-note:last-child { margin-bottom: 0; }

/* The state block: the same markup in the list and on the door's own page, so
   a check swaps identically from either. */
.health { display: flex; flex-direction: column; gap: 6px; flex: 1 1 300px; }
.health-detail, .health-used { margin: 0; color: var(--text-dim); font-size: 13px; }
.health-when { opacity: .8; }
.health-check { margin-top: 4px; }

.badge-health { border-color: var(--health, var(--line)); color: var(--health, var(--text-dim)); }
.badge-health-ok { --health: #5fbf90; }
/* Not red: a door with no credential yet is unfinished, not broken. */
.badge-health-no-credential { --health: #e0b154; }
.badge-health-broken { --health: #d97b6c; }
.badge-health-unknown { --health: var(--line); }

@media (max-width: 720px) {

  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .row { flex-wrap: wrap; }
  .page-head-row { flex-direction: column; }
  .msg { max-width: none; }
  .runs-head { flex-direction: column; }
  .door { flex-direction: column; }
}
