#mapWrap {
  position: fixed; inset: 0; z-index: 57; visibility: hidden; opacity: 0;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px);
  transition: opacity .3s, visibility .3s;
}
#mapWrap.open { visibility: visible; opacity: 1; }
#mapBox {
  position: absolute; inset: 24px; display: flex; flex-direction: column;
  background: var(--glass-strong); border: 1px solid var(--stroke);
  border-radius: var(--r-lg); backdrop-filter: blur(50px) saturate(1.7);
  -webkit-backdrop-filter: blur(50px) saturate(1.7);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .6);
  transform: scale(.97); transition: transform .35s cubic-bezier(.2, .9, .3, 1.1);
  overflow: hidden;
}
#mapWrap.open #mapBox { transform: none; }
#mapBox .shead { display: flex; align-items: center; gap: 10px; padding: 16px 18px 10px; }
#mapBox .shead .t { font-size: 17px; font-weight: 650; }
#mapBox .mapinfo { flex: 1; font-size: 11.5px; color: var(--txt3); }
/* поле вопроса: базис мелкий, иначе распирает шапку и кнопки уезжают */
#mapBox .map-find {
  flex: 0 1 300px; min-width: 0; box-sizing: border-box;
  padding: 8px 12px; font-size: 12.5px;
}
#mapBox .map-find.busy { opacity: .6; }
.map-stage { position: relative; flex: 1; min-height: 0; display: flex; }
.map-view { position: relative; flex: 1; min-width: 0; }

/* дерево полок слева: вложенность слотов как есть, без перекладывания в
   полосу сверху — полок под два десятка, и в строку они не ложатся */
.map-tree {
  width: 236px; flex-shrink: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 2px 8px 14px 12px; border-right: 1px solid var(--stroke-soft);
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .14) transparent;
}
.map-tree::-webkit-scrollbar { width: 6px; }
.map-tree::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 3px; }
.map-tree .row {
  display: flex; align-items: center; gap: 4px; padding: 5px 8px 5px 0;
  border-radius: 8px; cursor: pointer; font-size: 12.5px; color: var(--txt2);
  transition: background .16s, color .16s; user-select: none;
}
.map-tree .row:hover { background: rgba(255, 255, 255, .07); color: var(--txt); }
.map-tree .row.on { background: rgba(255, 255, 255, .13); color: var(--txt); font-weight: 600; }
.map-tree .row.root { margin-bottom: 2px; }
.map-tree .tw {
  width: 15px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  opacity: .5; transition: transform .18s;
}
/* уголок — тонкий SVG, а не символ-треугольник (задача #348) */
.map-tree .tw .ico { width: 10px; height: 10px; stroke-width: 2.4; }
.map-tree .tw.open { transform: rotate(90deg); }
.map-tree .tw.leaf { opacity: 0; }
.map-tree .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-tree .n { flex-shrink: 0; font-size: 10.5px; opacity: .45; font-variant-numeric: tabular-nums; }
.map-tree .row.on .n { opacity: .6; }
#mapCanvas, .map-gl { display: block; width: 100%; height: 100%; }
.map-gl { position: absolute; inset: 0; }
.map-view { cursor: grab; }
.map-view.dragging { cursor: grabbing; }
.map-view.panning { cursor: move; }
.map-empty {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  text-align: center; padding: 40px; font-size: 13.5px; color: var(--txt3); line-height: 1.6;
}
.map-empty.on { display: flex; }
.map-legend {
  position: absolute; left: 16px; bottom: 14px; display: flex; align-items: center;
  gap: 14px; font-size: 11.5px; color: var(--txt2); pointer-events: none; flex-wrap: wrap;
}
.map-legend span { display: flex; align-items: center; gap: 6px; }
.map-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.map-legend .map-hint { color: var(--txt3); opacity: .75; }
.map-card {
  position: absolute; right: 16px; top: 16px; width: min(320px, 42%);
  /* текст записи бывает в тысячи знаков — карточка должна скроллиться, а не
     уезжать за пределы сцены */
  max-height: calc(100% - 32px); overflow-y: auto; overscroll-behavior: contain;
  padding: 13px 15px; border-radius: var(--r-md); display: none;
  background: rgba(20, 20, 24, .82); border: 1px solid var(--stroke);
  backdrop-filter: blur(20px); box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  font-size: 13px; line-height: 1.45; color: var(--txt);
  animation: popIn .2s cubic-bezier(.2, .9, .3, 1.3);
}
.map-card.on { display: block; }
.map-card::-webkit-scrollbar { width: 8px; }
.map-card::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .18); border-radius: 4px; }
.map-card .mc-text { word-break: break-word; white-space: pre-wrap; }
.map-card .mc-kind {
  font-size: 9.5px; font-weight: 700; padding: 3px 7px; border-radius: 7px;
  text-transform: uppercase; display: inline-block; margin-bottom: 7px;
}
.map-card .mc-meta { margin-top: 8px; font-size: 10.5px; color: var(--txt3); }
.map-card .mc-near { margin-top: 9px; font-size: 11.5px; color: var(--txt2); }
.map-card .mc-near b { color: var(--txt3); font-weight: 600; display: block; margin-bottom: 3px; }

/* --- история изменений памяти: колонка справа от облака (задача #149) ---
   Складывается кнопкой в шапке: главное здесь облако, и панель не должна
   отъедать у него ширину, когда она не нужна. */
#mapBox .map-log { display: none; }
#mapBox.logon .map-log { display: flex; }     /* нажатую кнопку красит общий .iconbtn.on */
.map-log {
  width: 300px; flex-shrink: 0; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--stroke-soft);
}
.mlog-head {
  display: flex; align-items: baseline; gap: 8px; padding: 4px 14px 8px;
  border-bottom: 1px solid var(--stroke-soft);
}
.mlog-head .mlog-t { font-size: 12.5px; font-weight: 650; color: var(--txt2); }
.mlog-head .mlog-n { font-size: 10.5px; color: var(--txt3); }
.mlog-list {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 6px 8px 14px; scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .14) transparent;
}
.mlog-list::-webkit-scrollbar { width: 6px; }
.mlog-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 3px; }
.mlog-empty { padding: 18px 8px; font-size: 12px; color: var(--txt3); text-align: center; }
.mlog-row {
  display: flex; gap: 9px; padding: 7px 8px; border-radius: 9px; cursor: pointer;
  transition: background .16s;
}
.mlog-row:hover { background: rgba(255, 255, 255, .06); }
.mlog-row.on { background: rgba(255, 255, 255, .12); }
.mlog-row + .mlog-row { margin-top: 1px; }
.mlog-row .mi { flex-shrink: 0; width: 16px; height: 16px; margin-top: 1px; opacity: .9; }
.mlog-row .mi svg { width: 16px; height: 16px; display: block; }
.mlog-row .mb { flex: 1; min-width: 0; }
.mlog-row .mh { display: flex; align-items: baseline; gap: 6px; }
.mlog-row .mh b { font-size: 11.5px; font-weight: 650; color: var(--txt); }
.mlog-row .mx {
  font-size: 9.5px; font-weight: 700; padding: 1px 5px; border-radius: 6px;
  background: rgba(255, 255, 255, .12); color: var(--txt2); font-variant-numeric: tabular-nums;
}
.mlog-row .mw {
  margin-left: auto; flex-shrink: 0; font-size: 10.5px; color: var(--txt3);
  font-variant-numeric: tabular-nums;
}
/* текст записи — тремя строками: строка истории это опознавательный кусок,
   а не сама запись (её открывает клик по строке) */
.mlog-row .mt {
  margin-top: 2px; font-size: 11.5px; line-height: 1.35; color: var(--txt2);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.mlog-row .ms {
  margin-top: 3px; font-size: 10px; color: var(--txt3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* вкладки полки/облако/история — только на узком экране */
.map-tabs { display: none; }
.map-tabs .tab, .task-tabs .tab {
  flex: 1; min-width: 0; padding: 8px 6px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--stroke-soft); background: transparent; color: var(--txt2);
  font: inherit; font-size: 12.5px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; transition: background .16s, color .16s;
}
.map-tabs .tab.on, .task-tabs .tab.on {
  background: rgba(255, 255, 255, .13); color: var(--txt); font-weight: 600;
}

/* Телефон: три колонки в 390 пикселей не ложатся никак, поэтому они становятся
   вкладками — история открывается ВМЕСТО облака, а не поверх него. */
@media (max-width: 900px) {
  #mapBox { inset: 8px; }
  #mapBox .shead { flex-wrap: wrap; gap: 8px; padding: 12px 12px 6px; }
  /* заголовок распирает первую строку, иначе ↻ и ✕ липнут к нему, а справа
     остаётся пустое место */
  #mapBox .shead .t { font-size: 15.5px; flex: 1 1 auto; }
  #mapBox .map-find { flex: 1 1 100%; order: 5; }        /* поле вопроса — своей строкой */
  #mapBox .mapinfo { flex: 1 1 100%; order: 6; }
  #mapLogBtn { display: none; }                          /* его заменяют вкладки */
  .map-tabs { display: flex; gap: 6px; padding: 6px 12px 2px; }

  /* видна ровно одна панель — та, что выбрана вкладкой */
  #mapStage .map-tree, #mapStage .map-view { display: none; }
  #mapBox.logon .map-log { display: none; }
  #mapStage.pane-tree .map-tree {
    display: block; width: auto; flex: 1 1 auto; border-right: none;
  }
  #mapStage.pane-view .map-view { display: block; }
  #mapStage.pane-log .map-log {
    display: flex; width: auto; flex: 1 1 auto; border-left: none;
  }

  .map-legend { gap: 10px; font-size: 10.5px; bottom: 10px; left: 10px; }
  .map-legend .map-hint { display: none; }                /* мышиных жестов тут нет */
  .map-card { left: 10px; right: 10px; top: 10px; width: auto; max-height: 52%; }
}
#mapMatches button,#mapPages button,#mapCard button { display:block; margin:4px; padding:5px 8px; color:var(--blue); background:transparent; border:1px solid var(--stroke); border-radius:7px; cursor:pointer; }
