:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1d212a;
  --line: #262b36;
  --text: #e6e8ec;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --ok: #3ecf8e;
  --warn: #f5b74e;
  --danger: #ff6b6b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
.loading { padding: 40px; color: var(--muted); }

/* ── Каркас ── */

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side .brand { font-weight: 600; padding: 4px 10px 14px; letter-spacing: .2px; }
.side .brand small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.side a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.side a:hover { background: var(--panel-2); }
.side a.active { background: var(--accent); color: #fff; }
.side .spacer { flex: 1; }
.side .me { color: var(--muted); font-size: 12px; padding: 10px; border-top: 1px solid var(--line); }
.side .me b { color: var(--text); display: block; font-size: 13px; }

.main { padding: 20px 24px 60px; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head h1 { font-size: 20px; margin: 0; font-weight: 600; }
.head .sub { color: var(--muted); font-size: 13px; }
.head .grow { flex: 1; }

/* ── Элементы ── */

button, .btn {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled), .btn:hover { border-color: #39404f; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.small { padding: 4px 9px; font-size: 12px; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #12151b;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards { display: grid; gap: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: #1f4a39; }
.badge.warn { color: var(--warn); border-color: #4a3d1f; }
.badge.danger { color: var(--danger); border-color: #4a2020; }
.badge.accent { color: var(--accent); border-color: #25365e; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; }
td { padding: 9px 10px; border-top: 1px solid var(--line); }
tbody tr:hover { background: var(--panel-2); cursor: pointer; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ── Метрики ── */

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.metric .value { font-size: 24px; font-weight: 600; }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.chart .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; min-width: 0; }
.chart .bar i { display: block; background: var(--accent); border-radius: 3px 3px 0 0; }
.chart .bar i.paid { background: var(--ok); }
.chart .bar span { color: var(--muted); font-size: 10px; text-align: center; font-style: normal; overflow: hidden; }

/* ── Флоу ── */

.branch { margin-bottom: 26px; }
.branch h2 { font-size: 14px; margin: 0 0 4px; font-weight: 600; }
.branch .about { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.chain { display: flex; align-items: stretch; gap: 0; overflow-x: auto; padding-bottom: 8px; }

.node {
  width: 230px;
  flex: 0 0 230px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
}
.node:hover { border-color: #39404f; }
.node.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.node.off { opacity: .5; }
.node .title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.node .text { color: var(--muted); font-size: 12px; max-height: 54px; overflow: hidden; white-space: pre-wrap; }
.node .chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.node .trigger { position: absolute; top: -9px; left: 10px; font-size: 11px; }

.link { flex: 0 0 90px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; position: relative; }
.link .line { width: 100%; height: 1px; background: var(--line); position: relative; }
.link .line::after {
  content: '';
  position: absolute;
  right: 0;
  top: -3px;
  border: 3.5px solid transparent;
  border-left-color: var(--line);
}
.link .delay { font-size: 11px; color: var(--muted); white-space: nowrap; }
.link .add { opacity: 0; transition: opacity .1s; }
.link:hover .add { opacity: 1; }
.chain .end { flex: 0 0 90px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }

/* ── Боковой редактор ── */

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(520px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 18px 20px 40px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: -20px 0 40px rgba(0,0,0,.35);
}
.drawer h2 { font-size: 16px; margin: 0 0 2px; }
.drawer .close { position: absolute; top: 14px; right: 16px; }
.drawer .foot { display: flex; gap: 8px; position: sticky; bottom: -40px; background: var(--panel); padding: 12px 0; margin-top: 10px; border-top: 1px solid var(--line); }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 19; }

/* ── Предпросмотр сообщения ── */

.preview { background: #0d1017; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.bubble { background: #182533; border-radius: 12px; padding: 10px 12px; max-width: 360px; white-space: pre-wrap; word-break: break-word; }
.bubble img, .bubble video { width: 100%; border-radius: 8px; margin-bottom: 8px; display: block; }
.bubble video.note { width: 180px; height: 180px; border-radius: 50%; object-fit: cover; }
.bubble .kbd { margin-top: 8px; display: grid; gap: 4px; }
.bubble .kbd span { background: #21364d; border-radius: 6px; padding: 6px; text-align: center; font-size: 13px; color: #a8c7ff; }

/* ── Медиа ── */

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.media-item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.media-item .thumb { height: 120px; background: #0d1017; border-radius: 8px; display: grid; place-items: center; overflow: hidden; margin-bottom: 8px; }
.media-item .thumb img, .media-item .thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-item .name { font-weight: 600; font-size: 13px; }

/* ── Мелочи ── */

.progress { height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ok); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.timeline { display: grid; gap: 6px; font-size: 13px; }
.timeline .item { display: flex; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.timeline .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.error { border-color: #4a2020; color: #ffb4b4; }
.toast.ok { border-color: #1f4a39; color: #a9f0d1; }

/* ── Вход ── */

.login { min-height: 100vh; display: grid; place-items: center; }
.login form { width: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login h1 { font-size: 18px; margin: 0 0 16px; }
.login .error { color: var(--danger); font-size: 13px; margin-bottom: 10px; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .brand { padding: 4px 8px; }
  .side .spacer, .side .me { display: none; }
  .main { padding: 16px; }
}
