:root {
  --page: #eef3f7;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --line: #dce4ea;
  --line-soft: #edf2f5;
  --text: #333b43;
  --muted: #828b95;
  --muted-2: #a8b1bb;
  --blue: #2fc6f6;
  --blue-dark: #1aa7d8;
  --green: #bbed21;
  --green-dark: #a6d51c;
  --danger: #ff5752;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: #eef3f7;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.35;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell.sidebar-collapsed {
  grid-template-columns: 58px minmax(0, 1fr);
}

.sidebar {
  position: relative;
  background: #f7f9fa;
  border-right: 1px solid var(--line);
  padding: 18px 14px;
}

.brand {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 14px;
  color: #2b3a43;
  font-size: 16px;
  font-weight: 700;
}

.sidebar-toggle {
  margin-left: auto;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: #e6eef2;
  color: #65727c;
  font-size: 20px;
  line-height: 1;
}

.app-shell.sidebar-collapsed .brand {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .nav-item span:not(.nav-dot) {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  position: absolute;
  left: 45px;
  transform: rotate(180deg);
}

.app-shell.sidebar-collapsed .sidebar {
  padding-left: 9px;
  padding-right: 9px;
}

.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(180deg, #3fd3ff, #1aafe8);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.sidebar nav {
  display: grid;
  gap: 2px;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: #535f69;
  text-align: left;
  padding: 0 10px;
}

.nav-item:hover {
  background: #edf3f6;
}

.nav-item.active {
  background: #e1eef4;
  color: #1f303a;
  font-weight: 700;
}

.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b7c4cc;
}

.nav-item.active .nav-dot {
  background: var(--blue);
}

.workspace {
  min-width: 0;
  padding: 18px 20px 30px;
  background: linear-gradient(180deg, #f7fafc 0, #eef3f7 120px, #eef3f7 100%);
}

.topbar {
  min-height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 14px;
}

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

h1 {
  color: #2d3b45;
  font-size: 26px;
  font-weight: 400;
  line-height: 1.2;
}

h2 {
  color: #525c67;
  font-size: 14px;
  font-weight: 700;
}

h3 {
  color: #5d6771;
  font-size: 13px;
  font-weight: 700;
}

.topbar p {
  color: var(--muted);
  margin-top: 6px;
}

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

.btn {
  min-height: 39px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 2px;
  padding: 0 17px;
  background: #dfe6ea;
  color: #535c64;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.btn.primary {
  background: var(--green);
  color: #535c00;
}

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

.btn.secondary {
  background: #e9eff2;
  color: #5d6870;
}

.btn.secondary:hover {
  background: #dfe8ed;
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.compact {
  min-height: 31px;
  padding: 0 12px;
  background: var(--green);
  color: #535c00;
  font-size: 11px;
}

.mode-tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-bottom: 13px;
}

.mode-tab {
  min-height: 38px;
  border: 0;
  border-radius: 2px 2px 0 0;
  background: #dce6eb;
  color: #626f78;
  padding: 0 18px;
  font-size: 13px;
  font-weight: 700;
}

.mode-tab.active {
  background: var(--panel);
  color: #2d3b45;
  box-shadow: var(--shadow);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.split {
  display: grid;
  grid-template-columns: minmax(250px, 292px) minmax(0, 1fr);
  gap: 14px;
}

.top-rules-list {
  margin-bottom: 14px;
}

.designer-panel {
  display: none;
}

#rulesView.show-designer .top-rules-list {
  display: none;
}

#rulesView.show-designer .designer-panel {
  display: block;
}

#rulesView.show-list .preview {
  display: none;
}

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

.panel-header {
  min-height: 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}

.list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

.rule-item {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line-soft);
  border-left: 3px solid transparent;
  border-radius: 2px;
  background: #fff;
  text-align: left;
  padding: 10px 11px;
}

.rule-item:hover {
  background: #fbfdfe;
}

.rule-item.active {
  border-left-color: var(--blue);
  background: #f5fbfe;
}

.rule-item strong {
  display: block;
  margin-bottom: 4px;
  color: #333b43;
  font-size: 13px;
  font-weight: 700;
}

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

.form-grid {
  display: grid;
  gap: 11px;
}

label {
  display: grid;
  gap: 5px;
  color: #808b95;
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cdd8df;
  border-radius: 2px;
  background: #fff;
  color: #333b43;
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px rgba(47, 198, 246, 0.2);
}

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

.editor {
  min-width: 0;
}

.bp-layout {
  min-height: 640px;
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 282px;
  background: #eef3f7;
  border: 1px solid #c8d3da;
  box-shadow: 0 1px 3px rgba(88, 110, 124, 0.25);
}

.bp-inspector-head {
  color: #6d7882;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.bp-canvas-panel {
  min-width: 0;
  background: #edf3f7;
}

.bp-canvas-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #fff, #f8fbfc);
  border-bottom: 1px solid #cfdbe2;
}

.bp-canvas-head p {
  color: #8a949e;
  font-size: 12px;
  margin-top: 3px;
}

.bp-canvas {
  min-height: 580px;
  padding: 26px 22px 32px;
  position: relative;
  overflow: auto;
  background-color: #edf3f7;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(151, 169, 180, 0.42) 1px, transparent 0);
  background-size: 18px 18px;
}

.bp-start,
.bp-end {
  width: 154px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  border-radius: 18px;
  border: 1px solid #82b736;
  background: linear-gradient(180deg, #b6e55f, #88c63a);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.35), 0 2px 2px rgba(91, 118, 50, 0.18);
}

.bp-end {
  border-color: #8c9ba4;
  background: linear-gradient(180deg, #b6c2c9, #8f9ea7);
}

.bp-line {
  width: 2px;
  height: 26px;
  margin: 0 auto;
  background: #9fb0ba;
  position: relative;
}

.bp-line::after {
  content: "";
  position: absolute;
  left: -4px;
  bottom: -1px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid #9fb0ba;
}

.branches {
  display: grid;
  gap: 14px;
}

.branch {
  width: min(690px, 100%);
  margin: 0 auto;
  position: relative;
}

.branch.child {
  width: calc(100% - 48px);
  margin: 12px 0 0 42px;
}

.branch.child::before {
  content: "";
  position: absolute;
  top: -16px;
  left: -24px;
  width: 24px;
  height: 40px;
  border-left: 2px solid #9fb0ba;
  border-bottom: 2px solid #9fb0ba;
}

.bp-node {
  width: 100%;
  min-height: 66px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #9eb7c6;
  border-radius: 3px;
  background: linear-gradient(180deg, #ffffff 0, #f8fbfc 100%);
  box-shadow: inset 0 1px rgba(255,255,255,0.9), 0 2px 3px rgba(85, 105, 116, 0.2);
  padding: 0;
  text-align: left;
}

.bp-node:hover {
  border-color: #35aad3;
  box-shadow: inset 0 1px rgba(255,255,255,0.9), 0 0 0 2px rgba(74, 180, 220, 0.22), 0 2px 3px rgba(85, 105, 116, 0.2);
}

.bp-node-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
}

.bp-node-icon {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: 1px solid #33a4c8;
  background: linear-gradient(180deg, #91def5, #36aed4);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.bp-node-title {
  color: #24333d;
  font-size: 15px;
  font-weight: 700;
}

.bp-node-subtitle {
  color: #66747e;
  font-size: 12px;
  margin-top: 3px;
}

.bp-node-result {
  color: #6da720;
  font-size: 12px;
  margin-top: 3px;
}

.bp-node-open {
  min-width: 112px;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid #d8e3e8;
  background: rgba(246, 249, 251, 0.72);
  color: #1d93bf;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.bp-node-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 14px;
}

.bp-add-step,
.bp-delete-step {
  min-height: 27px;
  border: 1px dashed #a5bac6;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  color: #5f6d76;
  padding: 0 12px;
  font-size: 12px;
}

.bp-delete-step {
  border-style: solid;
  color: #a15b5b;
}

.bp-inspector {
  background: #f7f9fa;
  border-left: 1px solid #cfdbe2;
  padding: 12px;
}

.branch-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 9px;
  align-items: end;
}

.show-fields {
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

.bp-section-title {
  min-height: 31px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.show-list {
  display: grid;
  gap: 7px;
  margin-top: 7px;
}

.show-item {
  display: grid;
  grid-template-columns: 1fr 0.8fr 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line-soft);
}

.bp-mini-delete {
  width: 31px;
  min-height: 31px;
  align-self: end;
  border: 0;
  border-radius: 2px;
  background: #edf2f5;
  color: #8b969f;
  font-size: 18px;
}

.block-modal[hidden] {
  display: none;
}

.block-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.block-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(25, 34, 40, 0.35);
}

.block-modal-panel {
  position: absolute;
  top: 52px;
  right: 42px;
  width: min(760px, calc(100vw - 84px));
  max-height: calc(100vh - 104px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #fff;
  border: 1px solid #aebfc9;
  box-shadow: 0 18px 42px rgba(38, 57, 68, 0.34);
}

.block-modal-head {
  min-height: 68px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #d0dce3;
  background: linear-gradient(180deg, #fff, #f5f8fa);
}

.block-modal-head p {
  color: #8a949e;
  margin-top: 4px;
}

.block-modal-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #e8eef2;
  color: #64717b;
  font-size: 24px;
}

.block-modal-body {
  overflow: auto;
  padding: 16px 18px 18px;
}

.modal-editor {
  display: grid;
  gap: 16px;
}

.modal-group {
  border: 1px solid #dce4ea;
  background: #fbfcfd;
  padding: 13px;
}

.modal-group h3 {
  margin-bottom: 10px;
}

.modal-note {
  color: #8a949e;
  font-size: 12px;
}

.preview {
  margin-top: 14px;
}

.preview-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 11px;
}

.field.hidden {
  display: none;
}

.field-value {
  display: block;
}

.events-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.event {
  min-height: 145px;
  display: grid;
  place-items: center;
  gap: 10px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 16px;
  background: #fff;
}

.mark {
  font-size: 44px;
  color: var(--danger);
  line-height: 1;
}

.event.installed .mark {
  color: #8dc63f;
}

.settings-row {
  margin-top: 13px;
}

.settings-row label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 400;
}

.settings-row input {
  width: auto;
  min-height: auto;
}

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

  .sidebar {
    display: flex;
    gap: 14px;
    align-items: center;
    overflow-x: auto;
  }

  .brand {
    margin: 0;
    padding: 0;
    white-space: nowrap;
  }

  .sidebar nav {
    display: flex;
    gap: 4px;
  }

  .nav-item {
    white-space: nowrap;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .bp-layout {
    grid-template-columns: 1fr;
  }

  .bp-inspector {
    border: 0;
    border-bottom: 1px solid #d6e0e6;
  }

  .split,
  .form-grid,
  .branch-row,
  .show-item,
  .preview-form,
  .events-grid {
    grid-template-columns: 1fr;
  }
}
