:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #d9e1ea;
  --text: #17202a;
  --muted: #657282;
  --blue: #2563eb;
  --green: #138a4b;
  --amber: #a16207;
  --red: #c24136;
  --violet: #6d4aff;
  --shadow: 0 8px 22px rgba(28, 39, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  min-height: 34px;
  padding: 6px 10px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: #9fb0c5;
  background: #f8fafc;
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

button.danger {
  color: var(--red);
  border-color: #f0b8b2;
}

svg.icon {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  flex: 0 0 auto;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 34px;
  padding: 6px 9px;
  background: #fff;
  color: var(--text);
  min-width: 0;
}

textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 280px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: #17202a;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 16px;
}

h3 {
  font-size: 14px;
}

p {
  margin: 0;
}

.muted,
#status-line {
  color: var(--muted);
  font-size: 13px;
}

.create-run {
  display: grid;
  grid-template-columns: minmax(220px, 420px) minmax(160px, 260px) auto;
  gap: 8px;
  flex: 1;
  justify-content: end;
}

.create-run-advanced {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 8px 10px 10px;
}

.create-run-advanced summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.create-run-advanced .check-row.compact {
  margin: 8px 0 6px;
}

.create-run-advanced-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 8px;
}

.create-run-advanced-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.page-switch {
  display: inline-flex;
  gap: 6px;
  flex: 0 0 auto;
}

.app-shell {
  max-width: 1680px;
  margin: 0 auto;
  padding: 16px;
}

.shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
}

.sidebar,
.content {
  min-width: 0;
}

.side-section,
.run-detail,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.side-section {
  padding: 12px;
  margin-bottom: 14px;
}

.section-head,
.run-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.icon-button {
  width: 34px;
  padding: 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  margin: 10px 0;
  font-size: 13px;
}

.runs-list,
.accounts-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 260px);
  overflow: auto;
}

.accounts-page .accounts-list {
  max-height: none;
  overflow: visible;
}

.run-row,
.account-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #fff;
  width: 100%;
  text-align: left;
  display: block;
  min-height: 0;
  cursor: pointer;
}

.run-row.active {
  border-color: var(--blue);
  box-shadow: inset 3px 0 0 var(--blue);
}

.row-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 5px;
}

.run-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.row-title {
  font-weight: 700;
  font-size: 13px;
  min-width: 0;
}

.row-loading-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--blue);
  border-radius: 999px;
  flex: 0 0 auto;
  animation: run-row-spin 0.8s linear infinite;
}

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

.row-sub {
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}

.truncate-copy {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: copy;
}

.run-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 6px 0;
}

.run-stats span {
  border: 1px solid #dfe7ef;
  border-radius: 999px;
  background: #f8fafc;
  color: #465468;
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1.4;
}

.codex-setup-form {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.codex-setup-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.codex-setup-form .check-row {
  display: flex;
  margin: 0;
  color: var(--text);
}

.setup-head,
.codex-setup-form button[type="submit"] {
  grid-column: 1 / -1;
}

.setup-jobs {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.setup-job {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcfe;
  min-width: 0;
  overflow: hidden;
}

.log-tail {
  max-height: 180px;
  margin: 6px 0 0;
  white-space: pre-wrap;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

.empty-state {
  min-height: calc(100vh - 110px);
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  padding: 24px;
}

.run-detail {
  padding: 16px;
}

.hidden {
  display: none !important;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  background: #f8fafc;
}

.badge.completed,
.badge.verified,
.badge.available,
.badge.passed {
  color: var(--green);
  border-color: #b8dfc8;
  background: #f0fbf5;
}

.badge.failed,
.badge.diverged,
.badge.cancelled,
.badge.missing,
.badge.disabled,
.badge.invalid,
.badge.critical,
.badge.high {
  color: var(--red);
  border-color: #f1b8b2;
  background: #fff5f4;
}

.badge.running,
.badge.running_lanes,
.badge.integrating_features,
.badge.integrating_run,
.badge.final_summary,
.badge.configured {
  color: var(--blue);
  border-color: #b9cffb;
  background: #f2f6ff;
}

.badge.blocked,
.badge.paused,
.badge.cooldown,
.badge.skipped,
.badge.not-configured,
.badge.not_configured,
.badge.medium {
  color: var(--amber);
  border-color: #e7ce9c;
  background: #fff8e8;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0 10px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  min-height: 64px;
  background: #fbfcfe;
}

.metric span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.metric strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.metric.wide {
  grid-column: span 6;
}

.progress-track {
  height: 10px;
  background: #e8edf4;
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 14px;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.control-panel,
.forms-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.compact-controls {
  gap: 5px;
}

.compact-controls button {
  min-height: 30px;
  padding: 4px 7px;
  font-size: 12px;
}

.forms-row form {
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(120px, 160px) minmax(220px, 1fr) auto;
  flex: 1 1 360px;
}

#rerun-form {
  grid-template-columns: minmax(160px, 1fr) auto;
  flex: 0 1 300px;
}

#model-form {
  grid-template-columns: minmax(120px, 160px) minmax(140px, 1fr) auto;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-top: 14px;
}

.tab {
  border: 0;
  border-radius: 6px 6px 0 0;
  background: transparent;
  min-height: 38px;
  border-bottom: 3px solid transparent;
}

.tab.active {
  border-bottom-color: var(--blue);
  color: var(--blue);
  background: #f5f8ff;
}

.tab-panel {
  padding-top: 14px;
  min-height: 420px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f7f9fc;
  color: #344255;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table-sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-align: left;
  cursor: pointer;
}

.table-sort-button.active {
  color: #16283d;
}

.sort-indicator {
  font-size: 11px;
  line-height: 1;
}

td {
  overflow: hidden;
  max-width: 280px;
}

pre,
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre {
  background: #101923;
  color: #dbe7f3;
  padding: 12px;
  border-radius: 6px;
  overflow: auto;
  max-height: 520px;
  font-size: 12px;
}

.workflow {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

.node {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 10px;
  background: #fff;
  cursor: pointer;
  min-height: 76px;
  display: block;
  text-align: left;
  width: 100%;
}

.node.completed,
.node.accepted,
.node.ready,
.node.succeeded {
  border-left-color: var(--green);
}

.node.running,
.node.queued {
  border-left-color: var(--blue);
}

.node.blocked,
.node.paused,
.node.pending {
  border-left-color: var(--amber);
}

.node.failed,
.node.cancelled {
  border-left-color: var(--red);
}

.node.selected {
  outline: 2px solid #80a8f8;
  outline-offset: 1px;
}

.node-kind {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.edge-list {
  margin-top: 14px;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 12px;
}

.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
  min-width: 0;
  overflow: auto;
}

.artifact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  align-content: start;
}

.artifact-card {
  min-height: 154px;
  align-items: stretch;
  justify-content: start;
  display: grid;
  gap: 7px;
  text-align: left;
  white-space: normal;
}

.artifact-card.selected {
  border-color: var(--blue);
  box-shadow: inset 3px 0 0 var(--blue);
}

.inline-list {
  margin: 0;
  padding-left: 18px;
}

.timeline {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.timeline-item {
  border-left: 3px solid #9fb0c5;
  padding-left: 8px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(140px, 220px) minmax(180px, 1fr) minmax(160px, 220px) auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.settings-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.settings-grid input,
.settings-grid select {
  color: var(--text);
  font-size: 13px;
}

.accounts-page {
  display: grid;
  gap: 14px;
}

.accounts-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.account-page-summary {
  margin-bottom: 8px;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 12px;
}

.account-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px;
  min-width: 0;
  overflow: hidden;
}

.provider-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.provider-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 10px;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field-row {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.field-row input {
  width: 100%;
}

.checkbox-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.checkbox-row input {
  width: auto;
}

.account-global-toggle {
  margin-top: 12px;
}

.other-accounts {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #17202a;
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  max-width: 420px;
  z-index: 20;
}

@media (max-width: 980px) {
  .topbar,
  .topbar-tools,
  .shell,
  .accounts-layout,
  .create-run,
  .summary-grid,
  .split,
  .settings-grid {
    display: block;
  }

  .topbar {
    height: auto;
  }

  .create-run {
    margin-top: 10px;
  }

  .create-run-advanced-grid {
    display: block;
  }

  .create-run > *,
  .forms-row form,
  .codex-setup-form {
    width: 100%;
    margin-top: 6px;
  }

  .sidebar {
    margin-bottom: 14px;
  }

  .metric,
  .metric.wide {
    margin-bottom: 8px;
  }

  .artifact-grid,
  .workflow,
  .account-grid,
  .provider-grid {
    grid-template-columns: 1fr;
  }
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 10px;
  min-width: 0;
  display: grid;
  gap: 4px;
}

.mini-card span {
  color: var(--muted);
  font-size: 12px;
}

.mini-card strong {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.mini-card.completed,
.mini-card.passed {
  border-color: #b8dfc8;
  background: #f0fbf5;
}

.mini-card.failed,
.mini-card.critical,
.mini-card.high {
  border-color: #f1b8b2;
  background: #fff5f4;
}

.mini-card.blocked,
.mini-card.missing,
.mini-card.paused {
  border-color: #e7ce9c;
  background: #fff8e8;
}

.stack-gap {
  margin-top: 12px;
}

@media (max-width: 980px) {
  .overview-grid {
    grid-template-columns: 1fr;
  }
}

.job-cell-head {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
}

.codex-spacer {
  display: inline-block;
  width: 34px;
}

.jobs-table td {
  max-width: none;
}

.codex-conversation-row td {
  background: #fbfcfe;
  padding: 10px 32px;
}

.codex-conversation-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.codex-conversation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.codex-conversation-log {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  max-height: 340px;
  min-height: 120px;
  overflow: auto;
  margin: 0;
  padding: 12px;
}

.codex-agent-thread {
  display: grid;
  gap: 10px;
}

.codex-agent-message {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 10px 12px;
}

.codex-agent-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.codex-agent-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.5;
}

.codex-agent-empty {
  white-space: pre-wrap;
}

.live-duration {
  white-space: nowrap;
}

.danger-text {
  color: var(--red);
}
