:root {
  --bg: #0b1120;
  --panel: #111a2e;
  --panel-2: #16213a;
  --line: #263250;
  --text: #e6ecf6;
  --muted: #93a1bd;
  --accent: #3b82f6;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.logo {
  color: var(--accent);
  font-size: 18px;
}

.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tabs a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 550;
}

.tabs a:hover {
  background: var(--panel-2);
  color: var(--text);
}

.tabs a.active {
  background: var(--panel-2);
  color: var(--text);
}



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

/*
 * Full width on purpose. The step editor carries selector candidates and
 * bindings side by side, and the runs table now has a trace column — a centred
 * column forced both into horizontal scrolling on screens with room to spare.
 */
main {
  padding: 22px 26px 48px;
  max-width: none;
  margin: 0;
}

h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

h2 {
  font-size: 15px;
  margin: 26px 0 10px;
  color: var(--text);
}

.sub {
  color: var(--muted);
  margin: 0 0 18px;
  font-size: 13px;
  /* Long lines of explanatory text are hard to scan at full window width. */
  max-width: 90ch;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 190px;
  flex: 1;
}

.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

input,
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 9px;
  font: inherit;
  width: 100%;
}

textarea {
  font-family: var(--mono);
  font-size: 12px;
  min-height: 110px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(59, 130, 246, 0.5);
  outline-offset: -1px;
}

button {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 7px 13px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}

button:hover:not(:disabled) {
  filter: brightness(1.12);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.ghost {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}

button.danger {
  background: transparent;
  border-color: var(--bad);
  color: var(--bad);
}

button.tiny {
  padding: 3px 7px;
  font-size: 11px;
}

/* ------------------------------------------------------------------ tables */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(38, 50, 80, 0.6);
  vertical-align: top;
}

tr.clickable:hover td {
  background: var(--panel-2);
  cursor: pointer;
}

.table-scroll {
  overflow-x: auto;
}

/* ------------------------------------------------------------------- chips */

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.chip.published,
.chip.SUCCEEDED,
.chip.PUBLISHED {
  color: var(--good);
  border-color: rgba(52, 211, 153, 0.45);
}

.chip.draft,
.chip.DRAFT,
.chip.AWAITING_REVIEW {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.45);
}

.chip.FAILED,
.chip.EXPIRED,
.chip.REJECTED,
.chip.archived,
.chip.ARCHIVED {
  color: var(--bad);
  border-color: rgba(248, 113, 113, 0.45);
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

.warn {
  color: var(--warn);
}

.bad {
  color: var(--bad);
}

.good {
  color: var(--good);
}

.spread {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  /* `.card` carries a bottom margin but no top one, so a header row sitting
     directly above one had nothing between them. */
  margin-bottom: 16px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------- step editor */

.step-row td {
  border-bottom: 1px solid rgba(38, 50, 80, 0.8);
}

.step-row.boundary td {
  background: rgba(59, 130, 246, 0.09);
  color: var(--accent);
  font-weight: 600;
}

.step-row.unbound td {
  background: rgba(251, 191, 36, 0.08);
}

.step-row.disabled td {
  opacity: 0.5;
}

.binding {
  display: flex;
  gap: 6px;
  align-items: center;
}

.binding select {
  width: 118px;
  flex: none;
}

.selector-cell {
  max-width: 480px;
}

.selector-cell input {
  font-family: var(--mono);
  font-size: 11.5px;
}

.fallbacks {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  margin-top: 3px;
  word-break: break-all;
}

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

.diff-add {
  color: var(--good);
}

.diff-del {
  color: var(--bad);
}

.diff-same {
  color: var(--muted);
}

pre {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  overflow: auto;
  margin: 0;
}

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 11px 14px;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  z-index: 50;
  white-space: pre-wrap;
}

.toast.bad {
  border-left-color: var(--bad);
}

.toast.good {
  border-left-color: var(--good);
}

.empty {
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
}

/* --------------------------------------------------- live recording view */

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

.addressbar input {
  font-family: var(--mono);
  font-size: 12.5px;
}

.live-layout {
  display: grid;
  /* The stage keeps its aspect ratio, so cap it and let the step list take the
     rest rather than stretching a 1280×800 screencast across a 2560px window. */
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 16px;
  align-items: start;
  max-width: 1900px;
}

@media (max-width: 1100px) {
  .live-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stage-card {
  padding: 10px;
}

/*
 * The stage owns keyboard focus while recording, so the outline is a real
 * affordance: it tells the operator their typing is going to the portal.
 */
.stage {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  outline: none;
  cursor: default;
  min-height: 300px;
  display: flex;
}

.stage:focus-visible,
.stage:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

.screen {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.side {
  position: sticky;
  top: 74px;
}

.live-steps {
  margin: 10px 0;
  max-height: 420px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.live-step {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-step.warn {
  color: var(--warn);
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 7px;
  border-top: 1px solid var(--line);
  padding-top: 11px;
}

/*
 * Dropdown picker, drawn over the stream. It exists because a native <select>
 * popup is an OS widget: it never appears in a screencast, and while open it
 * swallows the keystrokes we forward.
 */
.select-picker {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  min-width: 280px;
  max-width: 80%;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  z-index: 5;
}

.select-picker[hidden] {
  display: none;
}

.picker-head {
  font-size: 12px;
  margin-bottom: 8px;
}

.select-picker select {
  font-size: 13px;
}

.picker-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ------------------------------------------------------- run trace panel */

.trace-row td {
  background: rgba(22, 33, 58, 0.6);
  padding: 14px 12px;
}

.trace-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.trace-section {
  margin-bottom: 12px;
  min-width: 0;
}

.trace-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}

.trace-section pre {
  max-height: 420px;
}

.trace-steps {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--mono);
  font-size: 11.5px;
}

.trace-step {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 3px 6px;
  border-radius: 4px;
  color: var(--muted);
}

.trace-step.bad {
  background: rgba(248, 113, 113, 0.1);
  color: var(--bad);
}

.trace-step-no {
  min-width: 24px;
  text-align: right;
  color: var(--muted);
}

.trace-ms {
  margin-left: auto;
  white-space: nowrap;
}

/* ----------------------------------------------------- review before submit */

.tab-badge {
  display: inline-block;
  margin-left: 6px;
  background: var(--warn);
  color: #1a1400;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
}

.tab-badge[hidden] {
  display: none;
}

.review-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr);
  gap: 16px;
  align-items: start;
}

@media (max-width: 1100px) {
  .review-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.review-shot {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

/* --------------------------------------------------------------- modals */

/*
 * Replaces native confirm()/prompt(). Those can be suppressed by the browser
 * after a few uses, which made destructive actions fail silently.
 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 11, 22, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
  width: min(520px, 100%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.modal-title {
  font-size: 15px;
  font-weight: 650;
  margin-bottom: 10px;
}

.modal-line {
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

button.danger-solid {
  background: var(--bad);
  border-color: var(--bad);
  color: #2a0707;
  font-weight: 650;
}

button.danger-solid:hover:not(:disabled) {
  filter: brightness(1.08);
}

/* ---------------------------------------------------------- empty state */

/*
 * Shown when there is nothing to list. One instruction, centred, rather than a
 * table with no rows — the first thing a new user sees should tell them what
 * this page is for.
 */
.empty-state {
  min-height: calc(100vh - 190px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
}

.empty-glyph {
  font-size: 44px;
  line-height: 1;
  color: var(--accent);
  opacity: 0.85;
  margin-bottom: 18px;
}

.empty-title {
  font-size: 22px;
  margin: 0 0 10px;
}

.empty-text {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  max-width: 52ch;
  margin: 0 0 24px;
}

.empty-cta {
  padding: 11px 22px;
  font-size: 14px;
}

.empty-steps {
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 34px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  width: min(620px, 100%);
}

.empty-step {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
}

.empty-step-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

/* ------------------------------------------------- in-page tabs (workflow) */

.subtabs {
  display: flex;
  gap: 2px;
  margin: 22px 0 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.subtabs a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  color: var(--muted);
  font-weight: 550;
  white-space: nowrap;
  /* Sits on the container's border so the active tab can cover it. */
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.subtabs a:hover {
  color: var(--text);
}

.subtabs a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.subtab-count {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.subtabs a.active .subtab-count {
  color: var(--text);
}

.tabpanel {
  padding-top: 18px;
}

/* The panel opens with its own heading often enough that the stock h2 gap
   would double up on the tab strip. */
.tabpanel > h2:first-child {
  margin-top: 0;
}

/* The banner shown while a published version's steps are unlocked. */
.editing-note {
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.editing-note strong {
  color: var(--text);
}

/* ------------------------------------------------------ identity + banner */

.who {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  font-size: 12.5px;
  color: var(--muted);
}

.who strong {
  color: var(--text);
  font-weight: 600;
}

.who .role {
  font-family: var(--mono, ui-monospace), monospace;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 6px;
  color: var(--muted);
}

/*
 * Deliberately loud and full width: acting as somebody else must never be
 * something an operator forgets they are doing.
 */
.impersonation {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 22px;
  background: var(--warn-soft, #2a2113);
  border-bottom: 1px solid var(--warn, #fbbf24);
  color: var(--warn, #fbbf24);
  font-size: 13px;
}

.impersonation strong {
  color: var(--text);
}

.impersonation button {
  margin-left: auto;
}

/* ------------------------------------------------------------ auth screens */

.auth-shell {
  max-width: 380px;
  margin: 8vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-shell h1 {
  margin: 0;
  font-size: 22px;
}

.auth-shell .sub {
  margin: 0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.auth-form input {
  font-size: 14px;
  padding: 9px 11px;
}

.secret-reveal {
  border: 1px dashed var(--good, #34d399);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.secret-reveal code {
  font-size: 12.5px;
  word-break: break-all;
}

/* Key/value rows on the account and company pages. */
.kv {
  display: flex;
  gap: 12px;
  padding: 5px 0;
  font-size: 13.5px;
}

.kv + .kv {
  border-top: 1px solid var(--line);
}

.kv .k {
  min-width: 140px;
  color: var(--muted);
}

.kv .v {
  color: var(--text);
}

td.right,
th.right {
  text-align: right;
  white-space: nowrap;
}

/*
 * Action cells hold two or three controls. Spacing them with a margin rather
 * than flex + gap keeps the cell a real table cell, so the column still lines
 * up with its header.
 */
td.right > * + * {
  margin-left: 8px;
}

.empty-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 20px;
  text-align: center;
}

.empty-hero h2 {
  margin: 0;
}

.empty-hero p {
  margin: 0;
  color: var(--muted);
}

.auth-form .hint {
  font-size: 11.5px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

/*
 * A class that sets `display` beats the browser's own `[hidden]` rule, so
 * `.tabs`, `.who` and `.impersonation` stayed on screen when hidden was set.
 * This makes the attribute mean what it says, everywhere.
 */
[hidden] {
  display: none !important;
}

/* The rename affordance, beside the name it changes. */
.titled {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-edit {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 6px;
  /* Quiet until wanted: the name is the heading, not the button. */
  opacity: 0.55;
  transition: opacity 120ms ease, color 120ms ease, border-color 120ms ease;
}

.titled:hover .icon-edit,
.icon-edit:focus-visible {
  opacity: 1;
  color: var(--text);
  border-color: var(--line);
}

.icon-edit:hover:not(:disabled) {
  filter: none;
  background: var(--panel-2);
}

/* A value and its copy button, side by side. */
.copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.copy-row input {
  flex: 1;
  min-width: 0;
}
