.map-node.is-tree-selected {
  outline: 3px solid rgba(49, 94, 223, .28);
  outline-offset: 3px;
  box-shadow: 0 4px 13px rgba(34, 72, 157, .15);
}
.outline-row.is-tree-selected {
  border-radius: 8px;
  background: #edf3ff;
  box-shadow: inset 3px 0 0 var(--blue, #315edf);
}
.map-node { overflow: visible; }
.ws-tree-handle {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  padding: 0;
  border: 1px solid #b9c9e4;
  border-radius: 50%;
  color: #315edf;
  background: #fff;
  box-shadow: 0 2px 6px rgba(35, 58, 98, .14);
  cursor: crosshair;
  touch-action: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity .14s ease, background .14s ease, border-color .14s ease;
}
.map-node:hover .ws-tree-handle,
.map-node:focus-within .ws-tree-handle,
.map-node.is-tree-selected .ws-tree-handle,
.map-viewport.is-tree-linking .ws-tree-handle {
  opacity: 1;
  pointer-events: auto;
}
.ws-tree-handle:hover, .ws-tree-handle:focus-visible {
  border-color: #315edf;
  color: #fff;
  background: #315edf;
}
.ws-tree-handle.top { top: -13px; left: 50%; transform: translateX(-50%); }
.ws-tree-handle.right { top: 50%; right: -13px; transform: translateY(-50%); }
.ws-tree-handle.bottom { bottom: -13px; left: 50%; transform: translateX(-50%); }
.ws-tree-handle.left { top: 50%; left: -13px; transform: translateY(-50%); }
.map-viewport { position: relative; overflow-anchor: none; }
.map-stage { cursor: grab; user-select: none; }
.map-viewport.is-panning, .map-viewport.is-panning * { cursor: grabbing !important; user-select: none; }
.tree-junction {position:relative; flex:0 0 0; height:0; z-index:2}
.tree-junction.is-folded {flex-basis:calc(var(--arm) + 12px)}
.tree-junction.is-folded::before {content:""; position:absolute; left:0; top:0; width:var(--arm); height:var(--line-w); background:var(--wire)}
.junction-toggle {position:absolute; left:var(--arm); top:0; transform:translate(-50%,-50%); display:grid; place-items:center; width:20px; height:20px; padding:0; border:1.5px solid #a6b6c9; border-radius:50%; background:#fff; color:#52647b; cursor:pointer}
.junction-sign {position:relative; display:grid; place-items:center; width:100%; height:100%}
.junction-sign::before {content:""; width:10px; height:2px; background:currentColor}
.is-folded .junction-sign::before {width:14px}
.is-folded .junction-sign::after {content:""; position:absolute; width:2px; height:14px; background:currentColor}
.junction-toggle::after {content:"";position:absolute;inset:-3px}
.junction-toggle:hover,.junction-toggle:focus-visible,.is-folded>.junction-toggle {color:#673d71;border-color:#9973a4;background:#faf4fc}
@media(min-width:641px){.home-view .map-tree{--arm:clamp(26px,2vw,36px)}}
@media(max-width:640px){
  .tree-junction:not(.is-folded) {flex:none;width:0;height:20px;margin-left:24px}
  .tree-junction:not(.is-folded)::before {content:"";position:absolute;left:0;top:0;width:var(--line-w);height:100%;background:var(--wire)}
  .tree-junction:not(.is-folded)>.junction-toggle {left:0;top:11px}
  .map-row.branch-folded {--arm:26px;flex-direction:row;align-items:center}
}
.map-viewport.is-tree-linking { cursor: crosshair; }
.ws-tree-preview {
  position: absolute;
  z-index: 3;
  inset: 0 auto auto 0;
  overflow: visible;
  pointer-events: none;
}
.ws-tree-preview path {
  fill: none;
  stroke: #315edf;
  stroke-width: 2;
  stroke-dasharray: 6 5;
  stroke-linecap: round;
}
.ws-tree-menu {
  position: fixed;
  z-index: 80;
  display: grid;
  gap: 5px;
  width: 232px;
  padding: 10px;
  border: 1px solid #d9e2f0;
  border-radius: 14px;
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 14px 40px rgba(29, 47, 83, .18);
  backdrop-filter: blur(10px);
}
.ws-tree-menu-title {
  overflow: hidden;
  padding: 4px 7px 8px;
  color: var(--muted, #74809a);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-tree-action {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 39px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #40506b;
  background: transparent;
  text-align: left;
  font: inherit;
  font-size: 13px;
  font-weight: 630;
  cursor: pointer;
}
.ws-tree-action:hover:not(:disabled) { color: #244cb7; background: #f0f4ff; }
.ws-tree-action.is-primary {
  border-color: var(--blue, #315edf);
  color: #fff;
  background: var(--blue, #315edf);
}
.ws-tree-action.is-primary:hover:not(:disabled) { color: #fff; background: #244fc7; }
.ws-tree-action:disabled { opacity: .55; cursor: wait; }
.ws-tree-action:focus-visible, .ws-tree-handle:focus-visible, .ws-tree-editor input:focus-visible {
  outline: 3px solid rgba(49, 94, 223, .3);
  outline-offset: 2px;
}
.ws-tree-editor {
  position: fixed;
  z-index: 85;
  display: grid;
  gap: 10px;
  width: min(276px, calc(100vw - 24px));
  padding: 13px;
  border: 1px solid #d9e2f0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 14px 40px rgba(29, 47, 83, .2);
}
.ws-tree-editor label { display: grid; gap: 6px; color: #41506a; font-size: 12px; font-weight: 700; }
.ws-tree-editor input {
  box-sizing: border-box;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #d8e1ee;
  border-radius: 8px;
  color: var(--ink, #17243d);
  background: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 450;
}
.ws-tree-editor-actions { display: flex; justify-content: flex-end; gap: 7px; }
.ws-tree-editor-actions .ws-tree-action { justify-content: center; width: auto; min-height: 34px; padding: 6px 9px; border: 1px solid #dfe6f1; }
.ws-tree-editor-actions .ws-tree-action.is-primary { border-color: var(--blue, #315edf); }
.ws-tree-editor-error { margin: 0; color: #b33231; font-size: 12px; line-height: 1.45; }
.leaf-node, .outline-row[data-case-id] { position: relative; }
.leaf-node > .leaf-title { padding-right: 28px; }
.ws-case-move-button {
  display: inline-grid;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  place-items: center;
  padding: 0;
  border: 1px solid #d9e2f0;
  border-radius: 7px;
  color: #687a99;
  background: #fff;
  cursor: grab;
  opacity: 0;
  pointer-events: none;
  transition: opacity .13s ease, color .13s ease, background .13s ease;
}
.leaf-node > .ws-case-move-button { position: absolute; top: 4px; right: 5px; }
.leaf-node:hover > .ws-case-move-button,
.leaf-node:focus-within > .ws-case-move-button,
.outline-row[data-case-id]:hover > .ws-case-move-button,
.outline-row[data-case-id]:focus-within > .ws-case-move-button {
  opacity: 1;
  pointer-events: auto;
}
.ws-case-move-button:hover, .ws-case-move-button:focus-visible {
  color: #315edf;
  background: #eef3ff;
}
.ws-case-move-button:focus-visible {
  outline: 2px solid rgba(49, 94, 223, .35);
  outline-offset: 2px;
}
.outline-row[data-case-id] > .ws-case-move-button { min-height: 28px; }
.leaf-node.is-case-drag-source { opacity: .58; outline: 2px dashed #315edf; outline-offset: 2px; }
.is-case-moving { user-select: none; cursor: grabbing; }
.map-node.ws-case-drop-child,
.leaf-node.ws-case-drop-child,
.outline-row.ws-case-drop-child {
  outline: 3px solid rgba(49, 94, 223, .42);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(49, 94, 223, .09);
}
.leaf-node.ws-case-drop-after::after,
.outline-row.ws-case-drop-after::after {
  position: absolute;
  z-index: 5;
  right: -2px;
  bottom: -5px;
  left: -2px;
  height: 4px;
  border-radius: 4px;
  background: #315edf;
  box-shadow: 0 0 0 3px rgba(49, 94, 223, .14);
  content: "";
  pointer-events: none;
}
.map-node.ws-case-drop-invalid,
.leaf-node.ws-case-drop-invalid,
.outline-row.ws-case-drop-invalid {
  outline: 3px solid rgba(195, 65, 63, .55);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(195, 65, 63, .08);
}
.ws-case-drop-hint {
  position: fixed;
  z-index: 95;
  max-width: min(310px, calc(100vw - 24px));
  padding: 8px 11px;
  border: 1px solid #b9caef;
  border-radius: 9px;
  color: #2349a9;
  background: #f4f7ff;
  box-shadow: 0 5px 18px rgba(30, 54, 99, .18);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  pointer-events: none;
}
.ws-case-drop-hint[data-valid="false"] {
  border-color: #efc3c0;
  color: #a43634;
  background: #fff6f5;
}
.ws-case-move-dialog {
  width: min(430px, calc(100vw - 28px));
  max-width: none;
  max-height: min(90dvh, 680px);
  padding: 0;
  border: 1px solid #d9e2f0;
  border-radius: 16px;
  color: var(--ink, #17243d);
  background: #fff;
  box-shadow: 0 20px 64px rgba(24, 43, 78, .24);
  overflow: auto;
}
.ws-case-move-dialog::backdrop { background: rgba(22, 35, 59, .48); backdrop-filter: blur(3px); }
.ws-case-move-panel { padding: 22px; }
.ws-case-move-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.ws-case-move-head h2 { margin: 0; font-size: 19px; }
.ws-case-move-head p { margin: 5px 0 0; overflow-wrap: anywhere; color: var(--muted, #74809a); font-size: 13px; }
.ws-case-move-close { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border: 0; border-radius: 9px; color: #74809a; background: #f2f5fa; cursor: pointer; }
.ws-case-move-form { display: grid; gap: 15px; }
.ws-case-move-form label { display: grid; gap: 7px; color: #40506b; font-size: 13px; font-weight: 680; }
.ws-case-move-form select { box-sizing: border-box; width: 100%; min-height: 43px; padding: 8px 11px; border: 1px solid #d9e2f0; border-radius: 9px; color: var(--ink, #17243d); background: #fff; font: inherit; font-size: 14px; }
.ws-case-move-help { margin: -3px 0 0; color: #8793a8; font-size: 12px; line-height: 1.45; }
.ws-case-move-error { margin: 0; color: #ac3936; font-size: 13px; }
.ws-case-move-form footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
.ws-case-move-form footer .ws-tree-action { width: auto; min-width: 74px; justify-content: center; border: 1px solid #dfe6f1; }
.ws-case-move-form footer .ws-tree-action.is-primary { border-color: var(--blue, #315edf); }
.ws-case-move-form select:focus-visible, .ws-case-move-close:focus-visible { outline: 3px solid rgba(49, 94, 223, .28); outline-offset: 2px; }
@media (max-width: 700px) {
  .ws-tree-menu {
    left: 12px !important;
    right: 12px !important;
    top: auto !important;
    bottom: max(12px, env(safe-area-inset-bottom)) !important;
    width: auto;
    max-height: min(45dvh, 280px);
    overflow: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .ws-tree-menu-title { grid-column: 1 / -1; }
  .ws-tree-action { justify-content: center; min-height: 43px; padding-inline: 7px; }
  .ws-tree-action span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ws-tree-editor { z-index: 86; }
  .ws-tree-handle { width: 28px; height: 28px; }
  .ws-case-move-button { opacity: 1; pointer-events: auto; }
  .ws-case-move-dialog { width: 100vw; margin: auto 0 0; border-radius: 17px 17px 0 0; }
  .ws-case-move-panel { padding: 20px 17px max(20px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .ws-tree-menu, .ws-tree-editor, .ws-tree-handle, .ws-case-move-button { scroll-behavior: auto; transition: none; }
}
