:root {
  color-scheme: light;
  --bg: #f5f7f7;
  --panel: #ffffff;
  --line: #d9e1df;
  --text: #1e2726;
  --muted: #64706d;
  --soft: #eef3f2;
  --teal: #167b78;
  --teal-dark: #0d5553;
  --amber: #a76712;
  --red: #b83a35;
  --shadow: 0 14px 34px rgba(22, 35, 34, 0.08);
}

* {
  box-sizing: border-box;
}

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

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
  opacity: 0;
  padding: 10px 12px;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.busy {
  border-color: rgba(22, 123, 120, 0.4);
}

.toast.success {
  border-color: rgba(34, 160, 107, 0.42);
}

.toast.error {
  border-color: rgba(184, 58, 53, 0.46);
  color: var(--red);
}

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

button {
  cursor: pointer;
}

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

.operation-pending .job-board,
.operation-pending .project-rail,
.operation-pending .inspector {
  cursor: wait;
}

.shell {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
  padding: 22px 16px;
}

.brand,
.runtime {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 6px;
  background: var(--text);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.brand strong,
.runtime strong {
  display: block;
  font-size: 14px;
}

.brand span,
.runtime span,
header p,
.board-head span,
.rail-head span {
  color: var(--muted);
  font-size: 12px;
}

nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
}

.nav-item.active {
  background: var(--soft);
  color: var(--text);
  font-weight: 700;
}

.runtime {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: var(--panel);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22a06b;
}

main {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.18;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 13px;
}

.top-actions,
.form-actions,
.board-head,
.rail-head,
.inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.primary,
.secondary,
.icon-button {
  min-height: 34px;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

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

.primary:hover {
  background: var(--teal-dark);
}

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

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(560px, 1fr) 370px;
  gap: 16px;
  padding: 18px;
}

.project-rail,
.job-board,
.inspector {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.project-rail,
.inspector {
  padding: 14px;
}

.project-list {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.project {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 10px;
  text-align: left;
}

.project.active {
  border-color: rgba(22, 123, 120, 0.34);
  background: #edf8f7;
}

.project strong {
  display: block;
  font-size: 13px;
}

.project span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-board {
  overflow: hidden;
}

.board-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.table-wrap {
  overflow: auto;
}

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

th:nth-child(1),
td:nth-child(1) {
  width: 24%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 18%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 20%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 14%;
}

th:nth-child(5),
td:nth-child(5) {
  width: 16%;
}

th:nth-child(6),
td:nth-child(6) {
  width: 42px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  background: #fbfcfc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

tr.selected {
  background: #edf8f7;
}

td:first-child strong,
td:first-child span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.pill.good {
  background: #e4f5ee;
  color: #11613f;
}

.pill.warn {
  background: #fff1db;
  color: var(--amber);
}

.pill.bad {
  background: #fde8e7;
  color: var(--red);
}

.inspector {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}

#jobForm {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  font-size: 13px;
}

textarea {
  min-height: 178px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(88px, 0.55fr) minmax(136px, 0.9fr);
  gap: 10px;
}

.schedule-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(96px, 0.8fr) minmax(112px, 0.8fr);
  gap: 10px;
}

.hidden {
  display: none;
}

.check {
  align-content: end;
  display: flex;
  flex-direction: row;
  gap: 8px;
  min-height: 58px;
}

.check input {
  width: 16px;
}

.status-block,
.log-block {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.output-console {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  padding: 14px;
}

.output-console > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.output-actions {
  display: flex;
  gap: 6px;
}

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

dl {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 6px 10px;
  margin: 0;
  font-size: 12px;
}

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

dd {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

code,
pre,
.codex-transcript {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101817;
  color: #d9f2ee;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

code {
  display: block;
  overflow: auto;
  padding: 8px;
}

pre {
  min-height: 128px;
  max-height: 260px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.codex-transcript {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: clamp(520px, 76vh, 980px);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: scroll;
  overscroll-behavior: contain;
  padding: 14px;
  scrollbar-color: #577571 #101817;
  scrollbar-gutter: stable;
}

.codex-transcript > * {
  flex: 0 0 auto;
}

.log-source {
  border: 1px solid rgba(217, 242, 238, 0.12);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: #9ed9d3;
  font-size: 11px;
  padding: 9px 10px;
}

.job-run {
  border: 1px solid rgba(217, 242, 238, 0.2);
  border-radius: 6px;
  background: rgba(7, 14, 13, 0.76);
  overflow: visible;
}

.job-run.latest {
  border-color: rgba(75, 199, 155, 0.5);
}

.job-run-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(217, 242, 238, 0.16);
  background: #17211f;
  padding: 11px 12px;
}

.job-run-head h3 {
  color: #eefbf8;
  font-size: 13px;
  line-height: 1.3;
}

.job-run-head p {
  margin-top: 3px;
  color: #9ab9b4;
  font-size: 11px;
}

.run-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 70%;
}

.run-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  border: 1px solid rgba(217, 242, 238, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: #cde7e3;
  font-size: 11px;
  padding: 0 8px;
  white-space: nowrap;
}

.run-chip strong {
  color: #82b9b2;
  font-size: 10px;
  text-transform: uppercase;
}

.run-chip.good {
  border-color: rgba(75, 199, 155, 0.38);
  color: #a8e9cd;
}

.run-chip.warn {
  border-color: rgba(255, 203, 111, 0.38);
  color: #ffd58a;
}

.run-chip.bad {
  border-color: rgba(255, 126, 120, 0.38);
  color: #ffb5b1;
}

.run-transcript {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.run-summary-note {
  border: 1px solid rgba(75, 199, 155, 0.22);
  border-radius: 6px;
  background: rgba(75, 199, 155, 0.08);
  color: #a8e9cd;
  font-size: 11px;
  padding: 8px 10px;
}

.tool-detail-group {
  border: 1px solid rgba(217, 242, 238, 0.14);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
}

.tool-detail-group > summary {
  cursor: pointer;
  color: #9ed9d3;
  font-size: 11px;
  font-weight: 800;
  padding: 9px 10px;
  text-transform: uppercase;
}

.tool-detail-body {
  display: grid;
  gap: 10px;
  border-top: 1px solid rgba(217, 242, 238, 0.12);
  padding: 10px;
}

.transcript-block {
  border: 1px solid rgba(217, 242, 238, 0.16);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.035);
  overflow: hidden;
}

.transcript-heading {
  border-bottom: 1px solid rgba(217, 242, 238, 0.14);
  background: rgba(255, 255, 255, 0.055);
  color: #9ed9d3;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  padding: 8px 10px;
  text-transform: uppercase;
}

summary.transcript-heading {
  cursor: pointer;
  list-style-position: inside;
}

.transcript-body {
  min-height: 0;
  max-height: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #d9f2ee;
  font-size: 12px;
  line-height: 1.5;
  padding: 12px;
}

.transcript-user {
  border-color: rgba(113, 181, 255, 0.3);
}

.transcript-user .transcript-heading {
  color: #b9d8ff;
}

.transcript-assistant {
  border-color: rgba(75, 199, 155, 0.3);
}

.transcript-assistant .transcript-heading {
  color: #a8e9cd;
}

.transcript-exec {
  border-color: rgba(255, 203, 111, 0.3);
}

.transcript-exec .transcript-heading {
  color: #ffd58a;
}

.transcript-diff {
  border-color: rgba(205, 180, 255, 0.3);
}

.transcript-diff .transcript-heading {
  color: #d8c9ff;
}

.transcript-diff .transcript-body {
  max-height: 420px;
  overflow: auto;
}

.transcript-journal,
.transcript-runtime {
  opacity: 0.86;
}

.transcript-runtime .transcript-body {
  max-height: 220px;
  overflow: auto;
}

.transcript-journal .transcript-body {
  max-height: 280px;
  overflow: auto;
}

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

  .sidebar {
    display: none;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .codex-transcript {
    height: 70vh;
  }

  .job-run-head {
    display: grid;
    top: 0;
  }

  .run-meta {
    justify-content: flex-start;
    max-width: none;
  }

  .inspector {
    max-height: none;
  }
}

[hidden] { display: none !important; }
#backup-workspace { padding: 1.5rem; max-width: 1500px; }
.backup-heading, .backup-policy-fields { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.backup-heading { justify-content: space-between; }
.backup-policy-fields label { display: grid; gap: .4rem; min-width: 180px; flex: 1; }
#backup-blockers { color: #b45309; line-height: 1.6; }
#backup-policy-form { margin-top: 1.5rem; }
#backup-policy-form button { margin-top: 1rem; }
#backup-plan { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 28rem; overflow: auto; padding: 1rem; }

[hidden] { display: none !important; }
#signInPanel { max-width: 36rem; margin: 15vh auto; padding: 2rem; }
