:root {
  --font: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  --display: "Sora", var(--font);
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 8px;
  --space: 16px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --brand-accent: #5ce1b5;
  --bg: #0b0f14;
  --bg-elevated: #10161e;
  --surface: #151c26;
  --surface-hover: #1b2430;
  --surface-strong: #1b2430;
  --border: #273140;
  --text: #e8eef5;
  --muted: #8b98a8;
  --faint: #5d6b7c;
  --accent: #6aa8d8;
  --accent-strong: #8bbde6;
  --accent-soft: rgba(106, 168, 216, 0.12);
  --positive: #5dcaa5;
  --warning: #d6b15a;
  --negative: #e07a7a;
  --danger: #e07a7a;
  --pass: #5dcaa5;
  --fail: #e07a7a;
  --kind-suite-bg: rgba(93, 202, 165, 0.12);
  --kind-suite-fg: #5dcaa5;
  --kind-suite-border: rgba(93, 202, 165, 0.28);
  --kind-step-bg: rgba(106, 168, 216, 0.12);
  --kind-step-fg: #8bbde6;
  --kind-step-border: rgba(106, 168, 216, 0.28);
  --input-bg: #0b0f14;
  --console-bg: #0b0f14;
  --console-fg: #d7e3ef;
  --dialog-scrim: rgba(0, 0, 0, 0.55);
  --btn-on-accent: #0b0f14;
  --shadow: none;
}

html[data-theme="light"] {
  color-scheme: light;
  --brand-accent: #0b9e74;
  --bg: #eef1f5;
  --bg-elevated: #f7f9fb;
  --surface: #ffffff;
  --surface-hover: #f3f6f9;
  --surface-strong: #f3f6f9;
  --border: #d5dde6;
  --text: #17202a;
  --muted: #5c6b7a;
  --faint: #8493a3;
  --accent: #1f6fb2;
  --accent-strong: #1f6fb2;
  --accent-soft: rgba(31, 111, 178, 0.08);
  --positive: #1f8a66;
  --warning: #9a7400;
  --negative: #c24747;
  --danger: #c24747;
  --pass: #1f8a66;
  --fail: #c24747;
  --kind-suite-bg: rgba(31, 138, 102, 0.1);
  --kind-suite-fg: #1f8a66;
  --kind-suite-border: rgba(31, 138, 102, 0.24);
  --kind-step-bg: rgba(31, 111, 178, 0.08);
  --kind-step-fg: #1f6fb2;
  --kind-step-border: rgba(31, 111, 178, 0.22);
  --input-bg: #eef1f5;
  --console-bg: #10161e;
  --console-fg: #d7e3ef;
  --dialog-scrim: rgba(0, 0, 0, 0.45);
  --btn-on-accent: #ffffff;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
}

/* Corner release ribbon (image tag from RELEASE / Docker --build-arg). */
body::after {
  position: fixed;
  width: 120px;
  height: 28px;
  top: 15px;
  right: -30px;
  z-index: 9999;
  pointer-events: none;
  text-align: center;
  font-size: 12px;
  font-family: var(--display);
  text-transform: uppercase;
  font-weight: 700;
  color: #fff;
  line-height: 28px;
  transform: rotate(45deg);
  background: #c62828;
  content: attr(data-release);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 1.15rem; }
h2 { font-size: 14px; }
h3 { font-size: 13px; }
h4 { font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); margin: 0 0 12px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.brand-mark {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.15rem;
  line-height: 1.1;
}

.brand-mark span {
  color: var(--brand-accent);
}

.brand-sub {
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace {
  padding: 20px 24px 40px;
  max-width: 1440px;
  margin: 0 auto;
}

.inspect-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 72px;
  height: calc(100vh - 92px);
  min-height: 0;
}

.workspace-main {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.panel,
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  min-width: 0;
  box-shadow: var(--shadow);
}

.panel-head,
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head h2,
.section-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-explorer {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  flex: 1 1 auto;
}

.editor-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.kind-pill,
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid var(--border);
}

.kind-pill.kind-suite {
  background: var(--kind-suite-bg);
  color: var(--kind-suite-fg);
  border-color: var(--kind-suite-border);
}

.editor-crumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 0 0 14px;
  font-size: 13px;
}

.editor-crumb .crumb {
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
  min-width: 0;
  color: var(--accent);
  border-radius: 0;
}

.editor-crumb .crumb:disabled,
.editor-crumb .crumb-current {
  color: var(--text);
  font-weight: 600;
  cursor: default;
}

.editor-crumb .crumb-sep {
  color: var(--faint);
}

.scenario-lane,
.scenario-detail,
.json-preview-wrap,
.output-log-wrap {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px;
}

.suite-description {
  margin: 0 0 12px;
}

.suite-members {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
}

.suite-member {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
}

.suite-member:hover {
  background: var(--surface-hover);
  filter: none;
}

.suite-member.is-current {
  border-color: var(--kind-suite-border);
  background: var(--kind-suite-bg);
}

.session-env-wrap #session-env-empty {
  margin: 0;
}

.tree-kind {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-strong);
  border-radius: 4px;
  padding: 2px 6px;
}

.tree-row.kind-suite .tree-kind {
  color: var(--kind-suite-fg);
  background: var(--kind-suite-bg);
}

.tree-row.kind-scenario .tree-kind {
  color: var(--accent-strong);
}

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
#scenario-name {
  width: 220px;
  flex: 0 1 220px;
}

input, textarea, button, select {
  font: inherit;
  color: inherit;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  background: var(--input-bg);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

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

button,
.icon-btn {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-shadow: none;
  font-weight: 500;
}

button:hover,
.icon-btn:hover {
  background: var(--surface-hover);
  filter: none;
}

button.ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

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

button.primary:hover {
  filter: brightness(1.05);
}

button.danger-subtle {
  background: var(--surface);
  color: var(--negative);
  border-color: var(--border);
}

button:disabled { cursor: default; opacity: 0.5; filter: none; }

html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="light"] .icon-moon { display: none; }

.theme-toggle {
  width: 34px;
  height: 32px;
  padding: 0;
}

.explorer-actions {
  gap: 6px;
}
.explorer-actions button {
  padding: 5px 8px;
  font-size: 12px;
}

.file-explorer {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.file-explorer-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 10px 6px;
}

.tree-row.kind-suite .tree-icon {
  color: var(--kind-suite-fg);
}

.tree-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 6px 8px;
  box-shadow: none;
  font-size: 13px;
  min-height: 32px;
}
.tree-row:hover { background: var(--surface-hover); filter: none; }
.tree-row.selected {
  background: var(--accent-soft);
  border-color: var(--border);
}
.tree-row.folder-selected:not(.selected) {
  background: var(--surface-hover);
}
.tree-chevron,
.tree-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.tree-chevron {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  min-width: 16px;
  border-radius: 4px;
}
.tree-chevron:hover { color: var(--text); filter: none; }
button.tree-row,
button.tree-chevron,
button.crumb,
button.step-card-body {
  box-shadow: none;
}
.tree-chevron svg,
.tree-icon svg {
  width: 14px;
  height: 14px;
  display: block;
}
.tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.tree-meta {
  margin-left: auto;
  color: var(--faint);
  font-size: 11px;
  flex: 0 0 auto;
  font-family: var(--mono);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }

.scenario-grid-top {
  margin-bottom: 16px;
  align-items: start;
}

.scenario-grid-bottom {
  margin-top: 12px;
  align-items: start;
}

.json-field-actions {
  align-items: stretch;
}

.json-field-btn {
  width: 100%;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  min-height: 38px;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface);
}

.json-field-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface-hover);
}

.json-field-btn.is-set {
  color: var(--text);
  border-color: var(--kind-suite-border);
}

.json-field-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.json-field-flag {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--kind-suite-fg);
  background: var(--kind-suite-bg);
  border: 1px solid var(--kind-suite-border);
  border-radius: 4px;
  padding: 2px 6px 2px 5px;
}

.json-field-flag::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--kind-suite-fg);
}

.json-field-flag[hidden] {
  display: none;
}

.json-edit-row {
  display: flex;
  align-items: center;
}

.scenario-builder {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 12px;
}

.lane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.lane-head #test-sequence {
  margin-left: auto;
}

.step-sequence {
  display: grid;
  gap: 8px;
}

.step-card {
  display: grid;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 120ms ease, background 120ms ease;
}

.step-card.dragging {
  opacity: 0.55;
}

.step-card.drag-over {
  border-color: var(--accent);
}

.step-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.step-card-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.step-resolved {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  word-break: break-all;
  font-family: var(--mono);
}

.step-index {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-strong);
  color: var(--accent);
  font-weight: 700;
  font-family: var(--mono);
  font-size: 12px;
}

.step-copy {
  display: grid;
  gap: 4px;
}

.step-copy strong {
  font-size: 13px;
}

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

.step-detail-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.toolbar-action {
  width: 100%;
}

.icon-button {
  width: 32px;
  min-width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 4px;
  flex: 0 0 auto;
}

.icon-button span {
  font-size: 1rem;
  line-height: 1;
}

.step-detail-form .actions button,
.toolbar-action,
.tree-row,
.section-head .actions button,
#regression-run,
#test-step,
#test-sequence,
#save-scenario,
#add-step,
#refresh-scenarios,
#new-scenario,
#new-folder {
  min-width: 0;
  max-width: 100%;
}

.step-detail-form {
  display: grid;
  gap: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-direction: row;
}

.toggle-row input {
  width: auto;
}

.run-mode-hint {
  margin: 8px 0 12px;
  font-size: 12px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 20px;
  font-size: 13px;
}

.results-table th,
.results-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.results-table th {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.results-table .row-fail td {
  background: color-mix(in srgb, var(--fail) 10%, transparent);
}

.results-table .row-pass td:nth-child(2) {
  color: var(--pass);
  font-weight: 600;
}

.results-table .row-fail td:nth-child(2) {
  color: var(--fail);
  font-weight: 600;
}

.metric-box.metric-fail strong {
  color: var(--fail);
}

.step-test-actions {
  margin-top: 0;
  justify-content: space-between;
}

.step-test-output {
  margin-top: 10px;
  min-height: 120px;
  max-height: 280px;
}

.step-curl-wrap {
  display: grid;
  gap: 8px;
}

.step-curl-wrap .lane-head {
  margin-bottom: 0;
}

.step-curl {
  margin: 0;
  min-height: 88px;
  max-height: 220px;
  white-space: pre-wrap;
  word-break: break-all;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 20px;
  color: var(--muted);
  background: var(--surface);
}

.hidden {
  display: none;
}

.json-dialog {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.json-dialog.hidden {
  display: none;
}

.json-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: var(--dialog-scrim);
}

.session-env-wrap {
  margin: 12px 0 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.session-env-wrap.is-unsatisfied {
  border-color: var(--warning);
  box-shadow: inset 0 0 0 1px var(--warning);
}

.env-dialog-fields {
  display: grid;
  gap: 12px;
  margin: 10px 0 0;
}

.env-dialog-fields label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

.env-dialog-fields input {
  font-family: var(--mono);
  font-size: 13px;
}

.env-current-value {
  font-size: 11px;
  font-family: var(--mono);
  word-break: break-all;
}

#session-env-run-hint {
  margin: 8px 0 0;
}

.json-dialog-card {
  position: relative;
  margin: 5vh auto;
  width: min(960px, calc(100% - 32px));
  max-height: 90vh;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: none;
  padding: 16px 18px 18px;
}

.modal-head h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

#json-dialog-editor {
  min-height: 460px;
}

.run-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.run-progress-wrap {
  margin-top: 12px;
}

.run-progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

.run-progress-track {
  height: 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  overflow: hidden;
}

.run-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.8s linear;
}

.run-progress-bar--error {
  background: var(--negative);
  width: 100% !important;
}

.json-preview-wrap {
  margin-top: 16px;
}

.json-preview-wrap summary,
.output-log-wrap summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  user-select: none;
}

.json-preview-wrap summary {
  margin-bottom: 10px;
}

.output-log-wrap {
  margin-top: 12px;
}

.output-log-wrap[open] summary {
  margin-bottom: 10px;
}

.output-log-wrap .console {
  margin: 0;
}

.console, .report {
  background: var(--console-bg);
  color: var(--console-fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12.5px;
}

.report {
  white-space: normal;
  line-height: 1.55;
}

.report p {
  margin: 0.45rem 0;
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 6px;
}
.metric-box span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.metric-box strong {
  font-size: 22px;
  letter-spacing: -0.03em;
  font-weight: 600;
}

@media (max-width: 1100px) {
  .inspect-layout,
  .scenario-builder {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .step-detail-toolbar {
    grid-template-columns: 1fr;
  }
}
