:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #242528;
  --muted: #686e73;
  --line: #d3d8d5;
  --accent: #0f766e;
  --accent-2: #8a4b2a;
  --danger: #b42318;
  --good: #177245;
  --warn: #9a6400;
  --code: #1e2528;
}

* {
  box-sizing: border-box;
}

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

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

h1 {
  font-size: 24px;
  font-weight: 720;
}

h2 {
  font-size: 16px;
  font-weight: 720;
}

h3 {
  margin-top: 18px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
}

#statusLine {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.tabbar {
  display: flex;
  gap: 8px;
  padding: 12px 24px 0;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
  overflow-x: auto;
}

.tab-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
}

.tab-button:hover,
.tab-button.active {
  border-color: var(--line);
  background: var(--bg);
  color: var(--ink);
}

.tab-shell {
  padding: 16px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.overview-grid,
.runs-layout {
  display: grid;
  gap: 16px;
  align-items: start;
}

.overview-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.runs-layout {
  grid-template-columns: minmax(360px, 0.9fr) minmax(460px, 1.1fr);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  min-width: 0;
}

.train-panel,
.query-panel,
.builder-panel {
  max-width: 1120px;
  margin: 0 auto;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

form,
.query-panel {
  display: grid;
  gap: 12px;
}

.panel-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.explain-block {
  display: grid;
  gap: 10px;
  color: #3c4344;
  font-size: 14px;
  line-height: 1.5;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.label-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.help-btn {
  display: inline-grid;
  place-items: center;
  width: 19px;
  min-width: 19px;
  height: 19px;
  min-height: 19px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #eef3f1;
  color: var(--accent);
  padding: 0;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.help-btn:hover,
.help-btn:focus {
  border-color: var(--accent);
  background: #e0efec;
  color: var(--accent);
}

.form-section {
  display: grid;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.form-section h3:first-child {
  margin-top: 0;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.4;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.14);
}

button {
  min-height: 36px;
  border: 1px solid #0b5f59;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: #0b5f59;
}

button:disabled {
  border-color: var(--line);
  background: #e3e7e5;
  color: #757d78;
  cursor: not-allowed;
}

#cancelBtn,
#logoutBtn {
  border-color: #88411f;
  background: var(--accent-2);
}

#cancelBtn:hover,
#logoutBtn:hover {
  background: #713719;
}

.grid-2,
.grid-4 {
  display: grid;
  gap: 10px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.builder-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.builder-layout .form-section {
  min-width: 0;
}

.full-span {
  grid-column: 1 / -1;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.action-row button {
  width: auto;
}

.compact-table {
  max-height: 244px;
  overflow: auto;
}

tr.spec-row {
  cursor: pointer;
}

tr.spec-row:hover,
tr.spec-row.selected {
  background: #eef3f1;
}

.output-card {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfc;
}

.validation-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.validation-list li.pass {
  color: var(--good);
}

.validation-list li.fail {
  color: var(--danger);
}

.validation-list li.manual {
  color: var(--warn);
}

.flow-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 22px;
}

.flow-list li {
  padding-left: 4px;
}

.flow-list span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

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

.default-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.default-grid strong,
.default-grid span {
  display: block;
}

.default-grid strong {
  font-size: 12px;
}

.default-grid span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.terms {
  display: grid;
  grid-template-columns: minmax(100px, 0.3fr) minmax(0, 1fr);
  gap: 9px 12px;
  margin: 0;
  font-size: 13px;
}

.terms dt {
  font-weight: 800;
}

.terms dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
}

tr.run-row {
  cursor: pointer;
}

tr.run-row:hover,
tr.run-row.selected {
  background: #eef3f1;
}

.status {
  display: inline-block;
  min-width: 78px;
  border-radius: 6px;
  padding: 3px 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.status.completed {
  background: #e8f5ee;
  color: var(--good);
}

.status.running,
.status.queued {
  background: #e7f4f3;
  color: var(--accent);
}

.status.failed,
.status.cancelled,
.status.interrupted {
  background: #fff0ed;
  color: var(--danger);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  font-size: 12px;
}

.meta-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  overflow-wrap: anywhere;
}

.checkpoint-list {
  display: grid;
  gap: 8px;
}

.checkpoint {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
}

.checkpoint code {
  overflow-wrap: anywhere;
  color: var(--accent);
}

.checkpoint button {
  justify-self: start;
  min-height: 30px;
  padding: 5px 9px;
}

.log-box,
.query-output {
  min-height: 160px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--code);
  color: #edf1ef;
  padding: 10px;
  white-space: pre-wrap;
  font-size: 12px;
}

.query-output {
  min-height: 220px;
}

.error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-check input {
  width: 16px;
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(25, 31, 31, 0.38);
  padding: 18px;
}

.help-overlay[hidden] {
  display: none;
}

.help-popover {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  box-shadow: 0 18px 60px rgba(20, 30, 30, 0.22);
}

.help-popover p {
  color: #374143;
  font-size: 14px;
  line-height: 1.5;
}

.auth-shell {
  display: grid;
  min-height: calc(100vh - 74px);
  place-items: center;
  padding: 16px;
}

.auth-panel {
  width: min(360px, 100%);
}

@media (max-width: 1040px) {
  .overview-grid,
  .runs-layout,
  .builder-layout {
    grid-template-columns: 1fr;
  }

  .full-span {
    grid-column: auto;
  }
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .tabbar {
    padding-inline: 10px;
  }

  .tab-shell {
    padding: 10px;
  }

  .grid-2,
  .grid-4,
  .meta-grid,
  .default-grid,
  .terms {
    grid-template-columns: 1fr;
  }
}
