/* One dark theme, monospace throughout. This is a terminal that happens to be
   in a browser: the audience is watching code and output, so nothing here
   competes with them for attention. */

:root {
  color-scheme: dark;
  --bg: #101216;
  --panel: #16191f;
  --edge: #262b34;
  --fg: #dfe3e8;
  --dim: #8b929e;
  --accent: #7aa2f7;
  --ok: #7bd88f;
  --blocked: #e0af68;
  --invalid: #e0af68;
  --failed: #f7768e;
  --token: #b4c8f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* -- header ------------------------------------------------------------- */

header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--edge);
  background: var(--panel);
}

.brand {
  font-weight: 600;
  letter-spacing: 0.04em;
}

.grow {
  flex: 1;
}

.meta {
  color: var(--dim);
  font-size: 12px;
}

select,
button {
  font: inherit;
  color: var(--fg);
  background: #1d222a;
  border: 1px solid var(--edge);
  border-radius: 3px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  color: #5a616c;
  cursor: default;
}

button.primary {
  color: #0f1115;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* -- view tabs ---------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 0.25rem;
}

.tab {
  color: var(--dim);
  background: transparent;
  border-color: transparent;
}

.tab[aria-selected="true"] {
  color: var(--fg);
  background: #1c212a;
  border-color: var(--edge);
}

/* -- layout ------------------------------------------------------------- */

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* The two-column grid lives on the VIEW, not on main, because main now holds
   both views and only one is on screen. */
.view {
  flex: 1;
  display: grid;
  grid-template-columns: 20rem 1fr;
  min-height: 0;
}

/* Required, not belt-and-braces. `hidden` is display:none in the UA stylesheet
   only, so the explicit `display: grid` above beats it on specificity and the
   hidden view renders on top of the visible one. Same class of bug as the
   grid-row comment further down. */
.view[hidden] {
  display: none;
}

aside {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.9rem;
  border-right: 1px solid var(--edge);
  background: var(--panel);
  overflow-y: auto;
}

.summary {
  margin: 0;
  color: var(--dim);
  font-size: 12px;
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}

.step {
  padding: 0.4rem 0.5rem;
  border-radius: 3px;
  border-left: 2px solid transparent;
  color: var(--dim);
  white-space: pre-wrap;
  cursor: pointer;
}

.step:hover {
  background: #1c212a;
}

.step.current {
  color: var(--fg);
  background: #1c212a;
  border-left-color: var(--accent);
}

.step.edited::after {
  content: " ·edited";
  color: var(--accent);
  font-size: 11px;
}

/* The scratchpad sits below the nine real steps, separated so it reads as a
   different kind of thing rather than a tenth Act. */
.step.scratch {
  margin-top: 0.5rem;
  border-top: 1px solid var(--edge);
  padding-top: 0.5rem;
  border-radius: 0;
}

.step.status-ok {
  color: var(--ok);
}
.step.status-blocked,
.step.status-invalid {
  color: var(--blocked);
}
.step.status-failed {
  color: var(--failed);
}

.wide {
  width: 100%;
}

/* -- work pane ---------------------------------------------------------- */

.work {
  display: grid;
  /* head · notice · editor · controls · splitter · terminal.
     --editor-height is set in px by the splitter drag; until then the editor and
     the terminal split what is left evenly. */
  grid-template-rows: auto auto var(--editor-height, 1fr) auto auto 1fr;
  min-height: 0;
  padding: 0.9rem 1rem;
  gap: 0.7rem;
}

/* Every child names its row. Implicit placement looks equivalent and is not:
   #notice is `hidden` (display: none) almost always, so it occupies no cell, and
   every row after it shifts up one. That silently gave the CONTROLS row the `1fr`
   and left the terminal at its content height. */
.step-head {
  grid-row: 1;
}
.notice {
  grid-row: 2;
}
.editor {
  grid-row: 3;
}
.controls {
  grid-row: 4;
}
.splitter {
  grid-row: 5;
}
.terminal {
  grid-row: 6;
}

/* -- the resize handle -------------------------------------------------- */

.splitter {
  height: 7px;
  margin: -0.35rem 0;
  border-radius: 4px;
  cursor: row-resize;
  background: var(--edge);
  /* Three dots, so it reads as a grip rather than a border. */
  background-image: radial-gradient(circle, var(--dim) 1px, transparent 1px);
  background-size: 7px 7px;
  background-position: center;
  background-repeat: repeat-x;
  opacity: 0.5;
  transition: opacity 0.12s ease;
}

.splitter:hover,
.splitter:focus-visible,
body.dragging .splitter {
  opacity: 1;
  background-color: var(--accent);
  outline: none;
}

/* While dragging, the pointer is over the textarea half the time -- without
   this, the drag selects code instead of resizing. */
body.dragging {
  cursor: row-resize;
  user-select: none;
}

.step-head h1 {
  margin: 0;
  font-size: 14px;
}

/* No measure cap. A step's narrative is the presenter's script and is read off a
   projector from several metres away, so wrapping it at 70ch left two thirds of
   a wide screen empty and pushed a five-line narrative down onto eight. It fills
   the head, which is the full width of the pane. */
.narrative {
  margin: 0.35rem 0 0;
  color: var(--dim);
}

.notice {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--blocked);
  border-radius: 3px;
  color: var(--blocked);
}

.editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--edge);
  border-radius: 3px;
  overflow: hidden;
}

/* `.editor-bar`, not `.bar`. The config panel's cap meter further down also
   called itself `.bar`, and being later in the file it WON: this strip was
   rendering as that meter's `display: inline-block; width: 5rem; height: 5px`,
   which is why the code/prompt tabs would have been a 5px sliver. Two unrelated
   things sharing a class name in one stylesheet is the bug; renaming the one
   whose markup this feature rewrites fixes it without touching the meter. */
.editor-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.6rem;
  background: #1a1e25;
  border-bottom: 1px solid var(--edge);
  color: var(--dim);
  font-size: 12px;
}

/* Tabs over the one pane, so switching to the prompt costs no vertical space --
   the editor and the terminal are already splitting a fixed height. */
.pane-tabs {
  display: flex;
  gap: 0.15rem;
}

.pane-tab {
  padding: 0.05rem 0.45rem;
  color: var(--dim);
  background: transparent;
  border-color: transparent;
  font-size: 12px;
}

.pane-tab[aria-selected="true"] {
  color: var(--fg);
  background: #22272f;
  border-color: var(--edge);
}

/* The resolved prompt, read-only. Sits in the same box as the textarea and only
   one of the two is ever visible. */
.prompt-view {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding: 0.7rem;
  background: #12151a;
}

.prompt-view[hidden] {
  display: none;
}

.prompt-name {
  color: var(--accent);
  margin-bottom: 0.4rem;
}

/* Not the first: every prompt after the first needs air above it. */
.prompt-block + .prompt-block {
  margin-top: 1rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--edge);
}

.prompt-role {
  margin: 0.5rem 0 0.15rem;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.prompt-text {
  margin: 0;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
}

.dirty {
  color: var(--accent);
}

.hint {
  color: #5a616c;
  font-size: 12px;
}

textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: none;
  padding: 0.7rem;
  background: #12151a;
  color: var(--fg);
  font: inherit;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* -- config pane -------------------------------------------------------- */
/* Two rows only -- a fixed head and a scrolling body -- so a long agent list
   scrolls inside the pane instead of pushing the page. */

.panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  padding: 0.9rem 1rem;
  gap: 0.7rem;
}

.config-body {
  min-height: 0;
  overflow-y: auto;
}

/* Scaffolding for a panel whose renderer has not landed yet. Says which feature
   builds it, so an empty pane reads as "not written" rather than "broken". */
.pending {
  padding: 0.9rem;
  border: 1px dashed var(--edge);
  border-radius: 3px;
  color: var(--dim);
  max-width: 70ch;
}

/* -- config: the agent table -------------------------------------------- */

table.grid {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.2rem;
}

table.grid th {
  text-align: left;
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid var(--edge);
  color: var(--dim);
  font-size: 12px;
  font-weight: 400;
}

table.grid td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid #1c2028;
  vertical-align: middle;
}

table.grid tbody tr {
  cursor: pointer;
}

table.grid tbody tr:hover {
  background: #1a1f27;
}

table.grid tbody tr.current {
  background: #1c212a;
  box-shadow: inset 2px 0 0 var(--accent);
}

td.id {
  color: var(--fg);
}

td.dim {
  color: var(--dim);
}

td.spend {
  white-space: nowrap;
  color: var(--dim);
  font-size: 12px;
}

/* A cap bar, not a percentage to read: the point is whether this agent is near
   its ceiling, which a length answers faster than a number. */
.bar {
  display: inline-block;
  width: 5rem;
  height: 5px;
  margin-left: 0.5rem;
  border-radius: 3px;
  background: #23282f;
  overflow: hidden;
  vertical-align: middle;
}

.bar .fill {
  display: block;
  height: 100%;
  background: var(--ok);
}

.bar .fill.warn {
  background: var(--blocked);
}

.bar .fill.over {
  background: var(--failed);
}

/* -- config: the models panel ------------------------------------------- */

/* Eight columns do not fit a projector. The table scrolls inside its own box so
   the pane never scrolls sideways as a whole. */
.scroll-x {
  overflow-x: auto;
  margin-bottom: 1.2rem;
}

.scroll-x table.grid {
  margin-bottom: 0;
}

/* Rows here select nothing, so they must not offer a pointer or a hover. */
table.grid tbody tr.static {
  cursor: default;
}

table.grid tbody tr.static:hover {
  background: transparent;
}

.readonly {
  margin-bottom: 1rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--edge);
  border-left: 2px solid var(--blocked);
  border-radius: 3px;
  color: var(--dim);
  max-width: 82ch;
}

.readonly strong {
  color: var(--blocked);
  font-weight: 600;
}

td.caps {
  white-space: nowrap;
}

.tag {
  display: inline-block;
  margin-right: 0.25rem;
  padding: 0 0.3rem;
  border-radius: 2px;
  font-size: 11px;
}

.tag.on {
  color: var(--ok);
  background: #16261c;
}

/* Present but unsupported, so it is dimmed rather than absent -- "no vision"
   is information, and a missing tag would read as "not stated". */
.tag.off {
  color: #4d545e;
  background: #171a20;
  text-decoration: line-through;
}

td.chain {
  font-size: 12px;
  white-space: nowrap;
}

.ladders {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ladder {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
}

.ladder .tier {
  min-width: 4.5rem;
  color: var(--accent);
}

/* -- config: the agent form --------------------------------------------- */

.form-head h2 {
  margin: 0 0 0.2rem;
  font-size: 13px;
  color: var(--accent);
}

.form-group {
  margin-bottom: 1.1rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--edge);
}

.form-group h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--dim);
}

.group-note {
  margin: 0.25rem 0 0.7rem;
  color: #6f7783;
  font-size: 12px;
  max-width: 78ch;
}

/* Auto-fit rather than a fixed column count, so the form reflows on a projector
   at 1024px instead of scrolling sideways. */
.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.7rem 1.1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.field label {
  color: var(--fg);
  font-size: 12px;
}

.field .help {
  margin: 0;
  color: #6f7783;
  font-size: 11px;
}

/* The two list fields and the prompt need the full width -- a column of
   checkboxes 15rem wide reads as a cramped afterthought. */
.field.kind-aliases,
.field.kind-text {
  grid-column: 1 / -1;
}

.field input[type="number"],
.field select,
.field textarea {
  font: inherit;
  color: var(--fg);
  background: #12151a;
  border: 1px solid var(--edge);
  border-radius: 3px;
  padding: 0.3rem 0.45rem;
  min-width: 0;
}

.field input[type="number"]:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.field input[type="number"]::placeholder,
.field textarea::placeholder {
  color: #5a616c;
}

.field textarea {
  resize: vertical;
  white-space: pre-wrap;
}

.field.kind-bool input[type="checkbox"] {
  align-self: start;
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: #12151a;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--dim);
  font-size: 12px;
  cursor: pointer;
}

.check input {
  accent-color: var(--accent);
}

.check.orphan span,
.check.absent span {
  color: var(--blocked);
}

/* -- config: the key/value row editor ----------------------------------- */

.rows {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-start;
}

.row-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
}

.kv {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.kv input {
  font: inherit;
  color: var(--fg);
  background: #12151a;
  border: 1px solid var(--edge);
  border-radius: 3px;
  padding: 0.25rem 0.4rem;
  min-width: 0;
}

.kv input:focus {
  outline: none;
  border-color: var(--accent);
}

.kv .kv-key {
  flex: 1;
  max-width: 16rem;
}

.kv .kv-value {
  width: 7rem;
}

.kv-remove {
  padding: 0.2rem 0.45rem;
  color: var(--dim);
}

.kv-remove:hover {
  color: var(--failed);
  border-color: var(--failed);
}

.kv-add {
  font-size: 12px;
  color: var(--dim);
}

/* A single-line string field, sized like the number inputs beside it. */
.field input[type="text"] {
  font: inherit;
  color: var(--fg);
  background: #12151a;
  border: 1px solid var(--edge);
  border-radius: 3px;
  padding: 0.3rem 0.45rem;
  min-width: 0;
}

.field input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.field.kind-list,
.field.kind-map {
  grid-column: 1 / -1;
}

/* -- config: the built-in audit denylist (read-only) --------------------- */

.denylist {
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--edge);
}

.denylist .checks {
  border: 0;
  background: transparent;
  padding: 0.2rem 0;
  gap: 0.25rem 0.35rem;
}

.denylist .tag {
  cursor: default;
}

/* -- config: controls and messages -------------------------------------- */

.form-controls,
.form-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-footer {
  margin-top: 1.4rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--edge);
}

/* Hidden until it has something to say, so the form does not carry an empty
   red box around with it. */
.form-error {
  display: none;
  margin-bottom: 0.7rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--failed);
  border-radius: 3px;
  color: var(--failed);
  white-space: pre-wrap;
}

.form-error.shown {
  display: block;
}

.form-error.ok {
  border-color: var(--ok);
  color: var(--ok);
}

/* -- terminal ----------------------------------------------------------- */

.terminal {
  min-height: 0;
  overflow-y: auto;
  padding: 0.7rem;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: #0c0e12;
}

.row {
  white-space: pre-wrap;
  word-break: break-word;
}

.row.cmd {
  margin-top: 0.6rem;
  color: var(--accent);
}
.row.note {
  color: var(--accent);
}
.row.log {
  color: var(--dim);
}
.row.token {
  color: var(--token);
}
.row.result {
  color: var(--fg);
}
.row.footer {
  color: #5a616c;
}
.row.blocked,
.row.warn {
  color: var(--blocked);
}
.row.err {
  color: var(--failed);
}

.row.end {
  margin-bottom: 0.3rem;
}
.row.end.ok {
  color: var(--ok);
}
.row.end.blocked,
.row.end.invalid {
  color: var(--blocked);
}
.row.end.failed {
  color: var(--failed);
}
