:root {
  --bg: #f4f4f4;
  --panel: #ffffff;
  --ink: #161616;
  --muted: #525252;
  --line: #e0e0e0;
  --blue: #0f62fe;
  --green: #198038;
  --red: #da1e28;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(180deg, #e8e8e8 0%, var(--bg) 40%);
}

.top {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  min-height: 3rem;
  background: #161616;
  color: #f4f4f4;
}

.brand {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}

.pill {
  margin-left: auto;
  font-size: 0.75rem;
  color: #c6c6c6;
  font-family: var(--mono);
  padding: 0.2rem 0.55rem;
  border: 1px solid #393939;
}

.pill.ok {
  color: #a7f0ba;
  border-color: #198038;
  background: #071d0e;
}

.pill.warn {
  color: #ffd7d9;
  border-color: #da1e28;
  background: #2d0709;
}

.layout {
  width: min(88rem, calc(100% - 2rem));
  margin: 1rem auto 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(16rem, 1fr) minmax(0, 2fr);
  gap: 1rem;
  align-items: start;
}

.side-rail {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
}

.side-rail > .panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.side-placeholder {
  padding: 1.25rem;
}

.side-placeholder .empty {
  margin: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
}

.panel-h {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  align-items: flex-start;
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.panel-h h1 {
  margin: 0.15rem 0;
  font-size: 1.25rem;
  line-height: 1.2;
  font-weight: 600;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.controls-body {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 1rem;
  padding: 1.25rem;
  align-items: stretch;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
  min-height: 7.5rem;
  padding: 1rem 1.1rem;
  border: 1px dashed #a8a8a8;
  background: #fafafa;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--blue);
  background: #edf5ff;
}

.upload-zone strong {
  font-size: 0.9rem;
}

.upload-zone span {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.controls-side {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  justify-content: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.field select {
  height: 2.5rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-bottom: 1px solid #8d8d8d;
  background: #fff;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
}

.field select:focus {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.primary,
.ghost {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  border: 1px solid transparent;
}

.primary {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}

.primary:hover { background: #0353e9; }
.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.ghost:hover { background: #f4f4f4; }

.success-outline {
  background: #fff;
  border: 1px solid var(--green);
  color: var(--green);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.65rem 1rem;
  cursor: default;
}

.success-outline:disabled {
  opacity: 1;
  cursor: default;
}

.steps {
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.step {
  border: 1px solid var(--line);
  background: #fafafa;
  padding: 0.9rem 1rem;
  border-left: 3px solid #a8a8a8;
}

.step.running {
  border-left-color: var(--blue);
  background: #edf5ff;
}

.step.done {
  border-left-color: var(--green);
  background: #defbe6;
}

.step.warning {
  border-left-color: #f1c21b;
  background: #fcf4d6;
}

.step.error {
  border-left-color: var(--red);
  background: #fff1f1;
}

.step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.step-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.step-index {
  color: var(--muted);
  font-weight: 500;
  margin-right: 0.3rem;
}

.step-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}

.tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.45rem;
  background: #e8e8e8;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-family: var(--sans);
}

.tag.running { background: #d0e2ff; color: var(--blue); }
.tag.done { background: #a7f0ba; color: var(--green); }
.tag.warning { background: #fddc69; color: #8e6a00; }
.tag.error { background: #ffd7d9; color: var(--red); }

.step-desc {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.step-body {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  line-height: 1.5;
}

.step-body.empty { display: none; }

.step-body.md-rendered > :first-child { margin-top: 0; }
.step-body.md-rendered > :last-child { margin-bottom: 0; }
.step-body.md-rendered h1,
.step-body.md-rendered h2,
.step-body.md-rendered h3 {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.9rem;
  line-height: 1.3;
}
.step-body.md-rendered p,
.step-body.md-rendered ul,
.step-body.md-rendered ol {
  margin: 0.35rem 0;
}
.step-body.md-rendered ul,
.step-body.md-rendered ol {
  padding-left: 1.25rem;
}
.step-body.md-rendered code {
  font-family: var(--mono);
  font-size: 0.8em;
  background: rgba(22, 22, 22, 0.06);
  padding: 0.05rem 0.25rem;
}
.step-body.md-rendered hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0.75rem 0;
}

.md-table-wrap {
  overflow-x: auto;
  margin: 0.5rem 0 0.65rem;
  border: 1px solid rgba(22, 22, 22, 0.12);
  background: rgba(255, 255, 255, 0.55);
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  line-height: 1.45;
}

.md-table th,
.md-table td {
  padding: 0.45rem 0.55rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid rgba(22, 22, 22, 0.08);
}

.md-table th {
  background: rgba(22, 22, 22, 0.05);
  font-weight: 600;
}

.md-table tr:last-child td {
  border-bottom: 0;
}

#xml-panel[hidden],
#side-placeholder[hidden] { display: none !important; }

.xml-actions {
  padding: 0 1.25rem 1rem;
}

.xml-summary {
  padding: 0 1.25rem 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.xml-summary strong {
  color: var(--ink);
  font-weight: 600;
}

.xml-preview {
  margin: 0;
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--line);
  background: #161616;
  color: #a7f0ba;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
  overflow: auto;
  max-height: calc(100vh - 16rem);
  white-space: pre;
}

.xml-preview[hidden] {
  display: none !important;
}

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

  .side-rail {
    position: static;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .controls-body {
    grid-template-columns: 1fr;
  }

  .step-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
