:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-alt: #f8fafc;
  --ink: #142333;
  --muted: #6a7a89;
  --line: #d6e0ea;
  --blue: #153f63;
  --blue-2: #245d8f;
  --green: #1f6d4c;
  --amber: #976100;
  --red: #a43c3c;
  --soft-blue: #edf5fc;
  --soft-green: #eef8f2;
  --soft-amber: #fff6e8;
  --soft-red: #fff3f3;
  --shadow: 0 16px 32px rgba(20, 35, 51, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: linear-gradient(180deg, #f6f9fc 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: hidden;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 13px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  border-color: #a9bfd4;
  background: #fbfdff;
}

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

button.primary:hover {
  background: #10314d;
  border-color: #10314d;
}

button.ghost {
  background: var(--soft-blue);
  color: var(--blue);
  border-color: #cbdeef;
}

button.danger {
  background: var(--soft-red);
  color: var(--red);
  border-color: #ebc9c9;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  gap: 4px;
}

.segmented button {
  border: none;
  background: transparent;
  padding-inline: 14px;
}

.segmented button.is-active {
  background: var(--blue);
  color: #fff;
}

.hidden {
  display: none !important;
}

.mode-view {
  min-height: 0;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1,
.summary-head h2,
.start-card h2 {
  margin: 0;
  letter-spacing: -0.03em;
}

.subtle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.app-shell {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  height: calc(100vh - 77px);
  padding: 12px 16px 16px;
  display: grid;
  gap: 16px;
  overflow: hidden;
}

body:has(#editorView:not(.hidden)) .app-shell {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 0;
}

.panel {
  min-height: 0;
  height: 100%;
}

#editorView {
  min-height: 0;
  height: 100%;
}

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

.banner {
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--soft-amber);
  border: 1px solid #ecd5a9;
  color: #6e4c04;
  font-weight: 600;
}

.call-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--soft-blue);
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.progress {
  height: 9px;
  background: #e8eef5;
  border-radius: 999px;
  overflow: hidden;
}

.progress div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--blue-2));
  transition: width 0.16s ease;
}

.step-counter {
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
}

.start-screen {
  height: calc(100% - 54px);
  display: grid;
  place-items: center;
}

.start-card {
  width: min(520px, 100%);
  padding: 20px;
  display: grid;
  gap: 12px;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 11px 12px;
  color: var(--ink);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.call-screen {
  display: grid;
  grid-template-columns: minmax(320px, 1.05fr) minmax(360px, 1fr);
  gap: 14px;
  align-items: start;
  height: calc(100% - 54px);
  min-height: 0;
  overflow: hidden;
}

.question-panel,
.data-panel,
.flow-panel,
.report-section,
.graph-panel,
.inspector-panel,
.validation-panel {
  padding: 14px;
}

.question-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  min-height: 0;
  height: 100%;
}

.script-wrap {
  display: grid;
  align-items: center;
}

.script {
  margin: 0;
  white-space: pre-line;
  font-size: clamp(24px, 2.8vw, 40px);
  line-height: 1.12;
  letter-spacing: -0.04em;
  font-weight: 850;
}

.hint {
  margin: 0;
  padding: 11px 13px;
  border-radius: 14px;
  background: var(--soft-green);
  border: 1px solid #c8e6d4;
  color: #22553d;
  font-weight: 700;
  font-size: 14px;
}

.data-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  min-height: 0;
  height: 100%;
  overflow: auto;
}

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

.fields,
.answers,
.form-grid,
.summary-grid,
.editor-shell {
  display: grid;
  gap: 12px;
}

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

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

.checks {
  display: grid;
  gap: 8px;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}

.check input {
  width: auto;
}

.answers {
  margin-top: 8px;
}

.answer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
}

.answer-num,
.graph-node-badge {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-weight: 900;
  background: var(--soft-blue);
  color: var(--blue);
}

.flow-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.graph-frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.8), transparent 28%),
    linear-gradient(180deg, #f8fbff 0%, #edf3f9 100%);
  min-height: 0;
  height: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.graph-help {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(640px, calc(100% - 24px));
  pointer-events: none;
}

.graph-help span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(203, 222, 239, 0.95);
  background: rgba(255, 255, 255, 0.88);
  color: #153f63;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(20, 35, 51, 0.08);
}

.graph-frame.compact {
  min-height: 0;
}

.graph-svg {
  width: 100%;
  height: 100%;
  min-height: 100%;
  display: block;
  user-select: none;
  -webkit-user-select: none;
}

.graph-node {
  cursor: pointer;
}

.graph-surface {
  cursor: grab;
}

.graph-surface.is-panning {
  cursor: grabbing;
}

.graph-node rect {
  fill: #fff;
  stroke: #bfd1e1;
  stroke-width: 2;
  rx: 18;
  filter: drop-shadow(0 10px 18px rgba(20, 35, 51, 0.08));
}

.graph-node.is-selected rect {
  stroke: var(--blue);
  fill: #f9fcff;
  stroke-width: 2.6;
  filter: drop-shadow(0 18px 26px rgba(21, 63, 99, 0.18));
}

.graph-node.is-linked rect {
  stroke: #245d8f;
  fill: #f5faff;
  stroke-width: 2.35;
  filter: drop-shadow(0 14px 22px rgba(36, 93, 143, 0.14));
}

.graph-node.is-current rect {
  stroke: var(--green);
}

.graph-node.is-history rect {
  fill: #f6fbf7;
}

.graph-node.is-invalid rect {
  stroke: var(--red);
}

.graph-node text {
  fill: var(--ink);
  font-size: 12.5px;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.graph-edge {
  fill: none;
  stroke: #a2b7c8;
  stroke-width: 2.2;
  cursor: pointer;
  opacity: 0.94;
}

.graph-edge.is-history {
  stroke: var(--green);
  stroke-width: 2.8;
}

.graph-edge.is-current {
  stroke: var(--blue);
  stroke-width: 2.8;
}

.graph-edge.is-selected {
  stroke: var(--red);
  stroke-width: 3.4;
}

.graph-edge.is-incoming {
  stroke: #2d6f55;
  stroke-width: 3;
}

.graph-edge.is-outgoing {
  stroke: #245d8f;
  stroke-width: 3;
}

.graph-edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  cursor: pointer;
}

.summary-screen {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  height: calc(100% - 54px);
  min-height: 0;
}

.summary-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  border-radius: 999px;
  padding: 8px 11px;
  background: #eff4f8;
  font-size: 12px;
  font-weight: 800;
}

.chip.high {
  background: #edf8f1;
  color: var(--green);
}

.chip.mid {
  background: #fff5e7;
  color: var(--amber);
}

.chip.low {
  background: #f7f1f1;
  color: var(--red);
}

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

.kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px 12px;
}

.k {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.v {
  white-space: pre-wrap;
}

.history-box {
  display: grid;
  gap: 10px;
  max-height: 100%;
  overflow: auto;
}

.history-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-alt);
  border: 1px solid #e2eaf2;
}

.graph-panel {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.editor-shell {
  position: relative;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  height: 100%;
  grid-template-columns: minmax(0, 1fr);
}

#editorView .editor-shell {
  min-height: 0;
}

#editorView .graph-panel {
  height: 100%;
  border-radius: 0;
  border-left: none;
  border-right: none;
  box-shadow: none;
}

#editorView .graph-frame {
  min-height: 0;
  height: 100%;
}

.editor-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: min(460px, 42vw);
  height: 100%;
  display: grid;
  align-content: start;
  gap: 12px;
  z-index: 3;
  transition: transform .18s ease, opacity .18s ease;
  max-width: calc(100vw - 24px);
}

#editorView .editor-sidebar {
  height: 100%;
}

.editor-sidebar.is-collapsed {
  transform: translateX(calc(100% + 18px));
  opacity: 0;
  pointer-events: none;
}

.inspector-panel,
.validation-panel {
  max-height: 100%;
  overflow: auto;
}

.empty-state {
  color: var(--muted);
  font-weight: 600;
}

#edgeInspector {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.section-separator {
  height: 1px;
  margin: 14px 0;
  background: var(--line);
}

.mini-grid {
  display: grid;
  gap: 10px;
}

.array-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px auto;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid #e1e8ef;
  border-radius: 12px;
  background: var(--panel-alt);
}

.field-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #e1e8ef;
  border-radius: 12px;
  background: var(--panel-alt);
}

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

.field-row-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

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

.checkbox-inline input {
  width: auto;
}

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

.validation-item {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #e4ebf2;
  background: var(--panel-alt);
}

.validation-item.error {
  border-color: #e7baba;
  background: #fff4f4;
}

.validation-item.warning {
  border-color: #ecd39a;
  background: #fff9ee;
}

.validation-item.ok {
  border-color: #c8e2d2;
  background: #f3fbf6;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #17314b;
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 1280px) {
  .call-screen,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .call-screen,
  .summary-screen {
    overflow: auto;
  }

  .graph-frame {
    min-height: 420px;
  }

  .editor-sidebar {
    width: min(520px, calc(100vw - 40px));
  }
}

@media (max-width: 760px) {
  .app-header,
  .panel-head,
  .summary-head {
    flex-direction: column;
  }

  .app-shell {
    height: calc(100vh - 109px);
  }

  .fields,
  .field-row-grid,
  .kv,
  .array-row {
    grid-template-columns: 1fr;
  }

  .script {
    font-size: clamp(22px, 7vw, 34px);
  }
}
