:root {
  --bg: #0d0f14;
  --panel: #151922;
  --panel-2: #1c212c;
  --line: #262c38;
  --text: #e8ebf2;
  --muted: #8b93a5;
  --accent: #4f8cff;
  --accent-2: #6ea8ff;
  --ok: #35c07a;
  --warn: #e0a83a;
  --err: #e05a5a;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--line);
}
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  flex-shrink: 0;
}
.brand strong { display: block; font-size: 14px; }
.brand small { color: var(--muted); font-size: 11px; }

nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-item span { width: 16px; text-align: center; opacity: .8; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: rgba(79,140,255,.14); color: var(--accent-2); }

.sidebar-foot { padding: 14px 18px; border-top: 1px solid var(--line); }
.pill {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}
.pill.ok { color: var(--ok); border-color: #24503a; }
.pill.err { color: var(--err); border-color: #5a2a2a; }

/* ---------- Main ---------- */
main { flex: 1; padding: 28px 34px; max-width: 1180px; }

.section { display: none; }
.section.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

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

.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 16px; }
.muted { color: var(--muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat.err .num { color: var(--err); }
.stat.warn .num { color: var(--warn); }
.stat.ok .num { color: var(--ok); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

/* ---------- Forms ---------- */
label {
  display: block;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: var(--muted);
}

input, select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.field-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.field-row label { flex: 1; margin-bottom: 0; }
.field-row .btn { margin-bottom: 0; white-space: nowrap; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 0;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.switch {
  appearance: none;
  width: 44px;
  height: 24px;
  margin: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background .18s;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .18s, background .18s;
}
.switch:checked { background: rgba(79,140,255,.3); border-color: var(--accent); }
.switch:checked::after { transform: translateX(20px); background: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }

.actions { margin-top: 4px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

.del {
  background: none;
  border: none;
  color: var(--err);
  cursor: pointer;
  font-size: 12.5px;
  padding: 0;
}
.del:hover { text-decoration: underline; }

/* ---------- Misc ---------- */
.out {
  margin-top: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  color: var(--muted);
  min-height: 20px;
  white-space: pre-wrap;
  overflow-x: auto;
  font-family: "Cascadia Code", Consolas, monospace;
}

.test-out { margin-top: 10px; font-size: 12.5px; min-height: 18px; }
.test-out.ok { color: var(--ok); }
.test-out.err { color: var(--err); }

.lvl-info { color: var(--ok); }
.lvl-warn { color: var(--warn); }
.lvl-error { color: var(--err); }

.scenario-list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Выбор стадий ---------- */
.stages-box {
  margin-top: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 13.5px;
  margin: 0;
}
.stage-item:hover { background: rgba(79,140,255,.08); }
.stage-item input { width: auto; margin: 0; accent-color: var(--accent); }
.stage-item .sid { color: var(--muted); font-size: 11.5px; margin-left: auto; font-family: monospace; }
.stage-item.checked { background: rgba(79,140,255,.12); }

label.full { grid-column: 1 / -1; }
.scenario {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--panel-2);
  border-radius: 8px;
  font-size: 13.5px;
}
.badge {
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.badge.on { background: rgba(53,192,122,.15); color: var(--ok); }
.badge.off { background: rgba(139,147,165,.15); color: var(--muted); }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13.5px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  max-width: 360px;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }

@media (max-width: 900px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  nav { flex-direction: row; flex-wrap: wrap; }
  main { padding: 20px; }
  .grid-2 { grid-template-columns: 1fr; }
}
