:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-2: #f8fafb;
  --control: #ffffff;
  --ink: #182127;
  --muted: #64717c;
  --line: #d5dde3;
  --line-strong: #b7c4cc;
  --accent: #c97619;
  --accent-dark: #8b4a0b;
  --accent-soft: #fff2df;
  --ok: #167a44;
  --warn: #a96706;
  --bad: #b82e2e;
  --blue: #2369c9;
  --green: #218656;
  --red: #d13a32;
  --shadow: 0 12px 28px rgba(27, 39, 47, 0.08);
  --radius: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101417;
  --panel: #171d22;
  --panel-2: #11171c;
  --control: #11171c;
  --ink: #e7edf2;
  --muted: #9aa7b1;
  --line: #2d3841;
  --line-strong: #44515c;
  --accent: #d99034;
  --accent-dark: #f1b25c;
  --accent-soft: #302417;
  --ok: #63c98d;
  --warn: #e1a64f;
  --bad: #e06d6d;
  --blue: #75aaff;
  --green: #70d99f;
  --red: #ff7771;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.42;
}

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

button,
.file-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
  padding: 7px 11px;
  cursor: pointer;
}

a.file-button {
  text-decoration: none;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

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

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

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
  padding: 7px 9px;
}

textarea {
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.36;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(201, 118, 25, 0.24);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

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

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

.brand-logo {
  width: 150px;
  height: 40px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.1;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  font-weight: 600;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

.theme-swatch {
  width: 15px;
  height: 15px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: linear-gradient(90deg, var(--ink) 0 50%, var(--bg) 50% 100%);
}

.status-message {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 3px 7px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-message.ok {
  color: var(--ok);
}

.status-message.error {
  color: var(--bad);
}

.workspace {
  display: grid;
  grid-template-columns: 290px minmax(600px, 1fr) 390px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.workflow-panel,
.analysis-panel {
  position: sticky;
  top: 12px;
  align-self: start;
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.work-panel {
  min-width: 0;
  display: grid;
  gap: 12px;
  align-content: start;
}

.step-header,
.step-form,
.visual-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.step-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
}

.step-header h2,
.panel-heading h2,
.panel-heading h3 {
  margin: 0;
}

.step-header h2 {
  font-size: 20px;
  line-height: 1.15;
}

.step-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.kicker {
  display: inline-flex;
  margin-bottom: 5px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

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

.panel-heading h2 {
  font-size: 15px;
}

.panel-heading h3 {
  font-size: 13px;
}

.panel-heading span {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 3px 7px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.workflow-panel {
  padding: 12px;
}

.workflow-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.workflow-list li {
  border-top: 1px solid var(--line);
}

.workflow-list li:first-child {
  border-top: 0;
}

.workflow-list button {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 26px;
  column-gap: 10px;
  align-items: start;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 8px 8px;
  text-align: left;
}

.workflow-list li.active button {
  background: var(--accent-soft);
}

.workflow-list strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
}

.workflow-list .step-copy,
.workflow-list .step-summary {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.workflow-list .step-copy {
  min-width: 0;
}

.workflow-list .step-summary {
  line-height: 1.34;
}

.step-num,
.step-state {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  min-width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  letter-spacing: 0;
}

.step-state {
  justify-self: end;
  font-size: 11px;
}

.workflow-list li.active .step-num {
  background: var(--accent);
  color: #fff;
}

.step-state.ok {
  background: var(--ok);
  color: #fff;
}

.step-state.warn {
  background: var(--warn);
  color: #fff;
}

.step-state.bad {
  background: var(--bad);
  color: #fff;
}

.step-form {
  padding: 16px 18px;
}

.form-group {
  margin-bottom: 22px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
}

.group-index {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.form-group h3 {
  margin: 0;
  font-size: 14px;
}

.field-note {
  max-width: 760px;
  margin: 0 0 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
}

.field-list {
  counter-reset: field-row;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.field-row {
  counter-increment: field-row;
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(150px, 210px) minmax(220px, 320px) 28px;
  align-items: center;
  column-gap: 10px;
  width: fit-content;
  max-width: 100%;
  min-height: 36px;
}

.field-row.wide {
  grid-template-columns: 28px minmax(150px, 210px) minmax(320px, 560px) 28px;
}

.field-row::before {
  content: counter(field-row);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.field-label {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.field-input-cell {
  min-width: 0;
}

.field-input-cell input,
.field-input-cell select,
.field-input-cell textarea {
  width: 100%;
}

.check-cell {
  display: flex;
  align-items: center;
  min-height: 34px;
}

.check-cell input {
  width: 18px;
  height: 18px;
  min-height: 0;
  accent-color: var(--accent);
}

.field-help {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--control);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  cursor: help;
}

.field-help:hover,
.field-help:focus,
.field-help:focus-visible {
  border-color: var(--accent);
  color: var(--accent-dark);
  outline: none;
}

.field-help::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: 300px;
  max-width: min(300px, calc(100vw - 40px));
  padding: 8px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.field-help:hover::after,
.field-help:focus::after,
.field-help:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.visual-section {
  padding: 12px;
}

#visualCanvas {
  display: block;
  width: 100%;
  height: 360px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.analysis-block {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.analysis-block:last-child {
  border-bottom: 0;
}

.metric-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 10px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.metric-list dt {
  color: var(--muted);
  font-weight: 700;
}

.metric-list dd {
  margin: 0;
  text-align: right;
}

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

.check-list li {
  margin-bottom: 7px;
}

.check-list .ok {
  color: var(--ok);
}

.check-list .warn {
  color: var(--warn);
}

.check-list .bad {
  color: var(--bad);
}

.preview-switch {
  display: inline-flex;
  gap: 3px;
  margin: 0 0 9px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.preview-switch button {
  min-height: 26px;
  border: 0;
  padding: 4px 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.preview-switch button.active {
  background: var(--accent);
  color: #fff;
}

#configPreview {
  min-height: 420px;
  max-height: 58vh;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11171c;
  color: #d7e1e8;
  padding: 11px;
  font: 12px/1.48 Consolas, "Courier New", monospace;
  white-space: pre;
}

@media (max-width: 1380px) {
  .workspace {
    grid-template-columns: 270px minmax(0, 1fr);
  }

  .analysis-panel {
    position: static;
    grid-column: 2;
    max-height: none;
  }
}

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

  .topbar-actions {
    justify-content: flex-start;
  }

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

  .workflow-panel {
    position: static;
    max-height: none;
  }

  .analysis-panel {
    grid-column: 1;
  }

  .field-row,
  .field-row.wide {
    grid-template-columns: 28px minmax(140px, 190px) minmax(200px, 320px) 28px;
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 8px;
  }

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

  .field-row,
  .field-row.wide {
    grid-template-columns: 26px minmax(0, 1fr) 28px;
    row-gap: 4px;
    width: 100%;
  }

  .field-label {
    grid-column: 2 / 4;
  }

  .field-input-cell {
    grid-column: 2 / 3;
  }

  .field-help {
    grid-column: 3;
    grid-row: 2;
  }

  .field-help::after {
    right: 0;
    top: calc(100% + 8px);
    transform: translateY(-4px);
  }

  .field-help:hover::after,
  .field-help:focus::after,
  .field-help:focus-visible::after {
    transform: translateY(0);
  }

  .step-actions {
    width: 100%;
  }

  .step-actions button {
    flex: 1;
  }

  #visualCanvas {
    height: 300px;
  }
}
