/* Building the territory model: add a node, write its logic, accounts route in */

/* ---------- Tree ---------- */

.bbi-mb-tree__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 0;
}

.bbi-mb-tree__head b { display: block; font-size: 15px; font-weight: 800; color: var(--bbi-ink); }
.bbi-mb-tree__head small { display: block; margin-top: 1px; font-size: 12px; font-weight: 700; color: var(--bbi-muted); }

.bbi-mb-tree__foot {
  position: absolute;
  left: 18px;
  right: 14px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 700;
  color: var(--bbi-muted);
}

.bbi-mb-tree__foot svg { width: 15px; height: 15px; flex: none; color: var(--bbi-indigo); }

.bbi-mb-row {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 8px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #e6eaf3;
  box-shadow: var(--bbi-shadow-sm);
  transition: top 0.45s var(--bbi-ease), opacity 0.35s ease, transform 0.45s var(--bbi-spring),
    border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
}

.bbi-mb-row.is-hidden { opacity: 0; transform: translateY(-10px) scale(0.94); }

.bbi-mb-row.is-selected {
  background: #f0f2fb;
  border-color: rgba(94, 114, 228, 0.55);
  box-shadow: 0 0 0 3px rgba(94, 114, 228, 0.12);
}

.bbi-mb-row.is-routed {
  border-color: #8fdcb5;
  box-shadow: 0 0 0 3px rgba(26, 174, 111, 0.14), var(--bbi-shadow-sm);
}

.bbi-mb-chev { display: grid; place-items: center; width: 12px; height: 12px; flex: none; color: #a3aec4; }
.bbi-mb-chev svg { width: 12px; height: 12px; }
.bbi-mb-chev.is-open svg { transform: rotate(90deg); }

.bbi-mb-ico {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 8px;
}

.bbi-mb-ico svg { width: 14px; height: 14px; }
.bbi-mb-ico--root { background: linear-gradient(135deg, #344767, #1e2a4a); color: #fff; }
.bbi-mb-ico--region { background: rgba(94, 114, 228, 0.13); color: var(--bbi-indigo); }
.bbi-mb-ico--segment { background: rgba(130, 94, 228, 0.13); color: var(--bbi-purple); }
.bbi-mb-ico--terr { background: #fff; border: 1.5px solid rgba(94, 114, 228, 0.35); color: var(--bbi-indigo); }
.bbi-mb-row.is-routed .bbi-mb-ico--terr { border-color: transparent; background: var(--bbi-grad-good); color: #fff; }

.bbi-mb-row__name { flex: 1; min-width: 0; line-height: 1.2; }

.bbi-mb-row__name b {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-weight: 800;
  color: var(--bbi-ink);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.bbi-mb-row__name small { display: block; font-size: 11.5px; font-weight: 800; white-space: nowrap; }
.bbi-mb-row__name small:empty { display: none; }
.bbi-mb-row__name small.is-warn { color: #e8590c; }
.bbi-mb-row__name small.is-good { color: var(--bbi-good); }

.bbi-mb-row__count {
  flex: none;
  font-size: 13px;
  font-weight: 800;
  color: var(--bbi-muted);
  font-variant-numeric: tabular-nums;
}

.bbi-mb-row.is-routed .bbi-mb-row__count { color: var(--bbi-good); }

/* Right-click menu */
.bbi-mb-menu {
  position: absolute;
  z-index: 20;
  padding: 6px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid rgba(94, 114, 228, 0.14);
  box-shadow: var(--bbi-shadow-lg);
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  transform-origin: 0 0;
  transition: opacity 0.2s ease, transform 0.25s var(--bbi-ease);
}

.bbi-mb-menu.is-open { opacity: 1; transform: none; }

.bbi-mb-menu__item {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--bbi-ink);
  white-space: nowrap;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.bbi-mb-menu__item svg { width: 15px; height: 15px; flex: none; color: var(--bbi-muted); }
.bbi-mb-menu__item.is-hover { background: rgba(94, 114, 228, 0.12); color: var(--bbi-indigo); }
.bbi-mb-menu__item.is-hover svg { color: var(--bbi-indigo); }

/* Accounts dropping into the new node */
.bbi-mb-drop {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 30;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 4px 8px -2px rgba(30, 42, 74, 0.35);
}

/* ---------- Node Details ---------- */

.bbi-mb-nd__body { padding: 16px 18px; transition: opacity 0.2s ease; }
.bbi-mb-nd__body.is-swap { opacity: 0; }

.bbi-mb-nd__head { display: flex; align-items: center; height: 36px; }
.bbi-mb-nd__title { white-space: nowrap; }
.bbi-mb-nd__title b { font-size: 18px; font-weight: 800; color: var(--bbi-ink); letter-spacing: -0.01em; }
.bbi-mb-nd__title span { margin-left: 6px; font-size: 14px; font-weight: 700; color: var(--bbi-muted); }

.bbi-mb-save {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  margin-left: auto;
  padding: 0 16px;
  border-radius: 9px;
  border: 1.5px solid #e3e7f0;
  background: #fff;
  font-size: 13px;
  font-weight: 800;
  color: #aab3c8;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.bbi-mb-save.is-dirty,
.bbi-mb-save.is-saving {
  border-color: var(--bbi-navy-deep);
  background: var(--bbi-navy-deep);
  color: #fff;
  box-shadow: 0 10px 20px -10px rgba(30, 42, 74, 0.6);
}

.bbi-mb-crumbs { display: flex; align-items: center; gap: 6px; height: 22px; margin-top: 8px; }
.bbi-mb-crumbs i { font-style: normal; font-size: 13px; font-weight: 700; color: #b4bdd0; }

.bbi-mb-crumb {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--bbi-surface-2);
  font-size: 12px;
  font-weight: 700;
  color: var(--bbi-muted);
  white-space: nowrap;
}

.bbi-mb-crumb svg { width: 11px; height: 11px; }
.bbi-mb-crumb.is-current { background: var(--bbi-navy-deep); color: #fff; }

.bbi-mb-fields { display: flex; gap: 10px; margin-top: 16px; }
.bbi-mb-field { flex: 1; min-width: 0; }
.bbi-mb-field--status { flex: none; width: 108px; }
.bbi-mb-label { font-size: 12px; font-weight: 800; color: var(--bbi-muted); }

.bbi-mb-status { justify-content: space-between; color: var(--bbi-ink); }
.bbi-mb-status svg { width: 13px; height: 13px; color: #a3aec4; }

.bbi-mb-input {
  display: flex;
  align-items: center;
  height: 40px;
  margin-top: 6px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1.5px solid #dfe3f1;
  font-size: 14px;
  font-weight: 700;
  color: var(--bbi-ink);
  white-space: nowrap;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.bbi-mb-input.is-focus { border-color: rgba(94, 114, 228, 0.7); box-shadow: 0 0 0 4px rgba(94, 114, 228, 0.12); }
.bbi-mb-input.is-selected .bbi-mb-input__text { background: rgba(94, 114, 228, 0.22); }

.bbi-mb-caret {
  display: none;
  width: 2px;
  height: 17px;
  margin-left: 1px;
  background: var(--bbi-indigo);
  animation: bbi-mb-blink 0.9s steps(2, start) infinite;
}

.bbi-mb-input.is-focus .bbi-mb-caret,
.bbi-mb-dd.is-open .bbi-mb-caret { display: inline-block; }

@keyframes bbi-mb-blink { to { visibility: hidden; } }

/* Logic Builder */
.bbi-mb-lb { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--bbi-line); }

.bbi-mb-lb__head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 26px;
  font-size: 15px;
  font-weight: 800;
  color: var(--bbi-ink);
}

.bbi-mb-lb__bar { display: flex; align-items: center; gap: 8px; height: 30px; margin-top: 12px; }
.bbi-mb-ops { display: inline-flex; gap: 3px; }

.bbi-mb-ops span {
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e4e8f1;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 26px;
  color: #7b88a3;
  transition: background 0.3s ease, color 0.3s ease, opacity 0.3s ease;
}

.bbi-mb-ops .is-on { background: var(--bbi-grad-brand); color: #fff; box-shadow: 0 6px 12px -6px rgba(94, 114, 228, 0.7); }
.bbi-mb-ops.is-single span:not(:first-child) { opacity: 0.45; }
.bbi-mb-ops.is-single .is-on { background: #9aa5bd; box-shadow: none; }

.bbi-mb-add {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid #c9cfdd;
  color: var(--bbi-muted);
}

.bbi-mb-add svg { width: 13px; height: 13px; }

.bbi-mb-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 13px;
  font-weight: 700;
  color: var(--bbi-muted);
  white-space: nowrap;
}

.bbi-mb-count svg { width: 16px; height: 16px; }

.bbi-mb-count__n {
  display: inline-flex;
  align-items: center;
  min-width: 14px;
  font-size: 14px;
  font-weight: 800;
  color: var(--bbi-ink);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}

.bbi-mb-count.is-live .bbi-mb-count__n { color: var(--bbi-indigo); }

.bbi-mb-refresh {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid rgba(94, 114, 228, 0.45);
  background: #fff;
  color: var(--bbi-indigo);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.25s ease, transform 0.35s var(--bbi-spring);
}

.bbi-mb-refresh svg { width: 14px; height: 14px; }
.bbi-mb-refresh.is-on { opacity: 1; transform: none; animation: bbi-mb-bounce 0.6s ease; }

@keyframes bbi-mb-bounce {
  0%, 100% { translate: 0 0; }
  35% { translate: 0 -5px; }
  65% { translate: 0 1px; }
}

.bbi-mb-rules {
  position: relative;
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 8px;
  border-radius: 12px;
  background: var(--bbi-surface-2);
  border: 1px solid var(--bbi-line);
}

.bbi-mb-rule {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 46px;
  padding: 0 7px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e6eaf3;
}

.bbi-mb-sel {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  height: 30px;
  flex: none;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid #dfe3f1;
  font-size: 13px;
  font-weight: 700;
  color: var(--bbi-ink);
  white-space: nowrap;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, width 0.35s var(--bbi-ease);
}

.bbi-mb-sel svg { width: 12px; height: 12px; flex: none; color: #a3aec4; }
.bbi-mb-sel--field { width: 116px; }
.bbi-mb-sel--op { width: 92px; }
.bbi-mb-sel.is-focus { border-color: rgba(94, 114, 228, 0.7); box-shadow: 0 0 0 3px rgba(94, 114, 228, 0.12); }

.bbi-mb-val {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 4px;
  border-radius: 8px;
  border: 1px solid #dfe3f1;
  overflow: hidden;
}

.bbi-mb-rule.is-empty .bbi-mb-sel--field { width: 148px; }
.bbi-mb-rule.is-empty .bbi-mb-sel--op { width: 80px; }
.bbi-mb-rule.is-empty .bbi-mb-sel--field .bbi-mb-sel__t { color: #a3aec4; }
.bbi-mb-rule.is-empty .bbi-mb-sel--op,
.bbi-mb-rule.is-empty .bbi-mb-val { border-style: dashed; opacity: 0.55; }

.bbi-mb-chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 6px;
  border-radius: 6px;
  background: rgba(94, 114, 228, 0.12);
  font-size: 12px;
  font-weight: 800;
  color: var(--bbi-indigo);
  white-space: nowrap;
}

.bbi-mb-chip--more { padding: 0 2px; background: none; color: var(--bbi-muted); }

/* Field search dropdown */
.bbi-mb-dd {
  position: absolute;
  top: 58px;
  left: 8px;
  z-index: 10;
  width: 210px;
  padding: 8px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid rgba(94, 114, 228, 0.16);
  box-shadow: var(--bbi-shadow-lg);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.25s var(--bbi-ease);
}

.bbi-mb-dd.is-open { opacity: 1; transform: none; }

.bbi-mb-dd__search {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1.5px solid rgba(94, 114, 228, 0.55);
  font-size: 13px;
  font-weight: 700;
  color: var(--bbi-ink);
}

.bbi-mb-dd__search svg { width: 14px; height: 14px; flex: none; color: var(--bbi-muted); }
.bbi-mb-dd__search .bbi-mb-caret { margin-left: -6px; height: 15px; }

.bbi-mb-dd__group {
  margin-top: 8px;
  padding: 3px 8px;
  border-left: 3px solid var(--bbi-indigo);
  border-radius: 3px;
  background: var(--bbi-surface-2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bbi-muted);
}

.bbi-mb-dd__opts { margin-top: 4px; }

.bbi-mb-dd__opt {
  display: block;
  height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  line-height: 30px;
  color: var(--bbi-ink);
  transition: background-color 0.2s ease;
}

.bbi-mb-dd__opt b { font-weight: 800; color: var(--bbi-indigo); }
.bbi-mb-dd__opt.is-hover { background: rgba(94, 114, 228, 0.12); }

/* Footer: what Save does, then the result */
.bbi-mb-foot {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 62px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1.5px dashed #dfe3f1;
  background: var(--bbi-surface-2);
  transition: background-color 0.35s ease, border-color 0.35s ease;
}

.bbi-mb-foot__icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  background: #fff;
  color: var(--bbi-indigo);
  box-shadow: var(--bbi-shadow-sm);
}

.bbi-mb-foot__icon svg { width: 17px; height: 17px; }
.bbi-mb-foot__text b { display: block; font-size: 14px; font-weight: 800; color: var(--bbi-ink); }
.bbi-mb-foot__text small { display: block; margin-top: 1px; font-size: 12px; font-weight: 600; color: var(--bbi-muted); }

.bbi-mb-foot.is-busy { border-style: solid; border-color: rgba(94, 114, 228, 0.3); background: #f7f8ff; }

.bbi-mb-foot.is-done { border-style: solid; border-color: var(--bbi-good-edge); background: #effbf5; }
.bbi-mb-foot.is-done .bbi-mb-foot__icon { background: var(--bbi-grad-good); color: #fff; }
.bbi-mb-foot.is-done .bbi-mb-foot__text b { color: #138a58; }

.bbi-mb-spin {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2.5px solid rgba(94, 114, 228, 0.25);
  border-top-color: var(--bbi-indigo);
  animation: bbi-spin 0.7s linear infinite;
}

.bbi-mb-spin--light { border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; }

@media (prefers-reduced-motion: reduce) {
  :root[data-reduced-motion="honor"] .bbi-mb-caret,
  :root[data-reduced-motion="honor"] .bbi-mb-spin,
  :root[data-reduced-motion="honor"] .bbi-mb-refresh.is-on { animation: none; }
}
