/* Дизайн в духе artlebedev.ru: белое, чёрное, красное; прямые углы,
   без градиентов и почти без теней. Светлая тема — основная. */
:root, [data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface2: #f2f2f2;
  --surface3: #e8e8e8;
  --border: #d9d9d9;
  --border-strong: #000000;
  --text: #000000;
  --text-dim: #666666;
  --text-mute: #999999;
  --accent: #e00000;
  --accent-hover: #b80000;
  --accent2: #000000;
  --accent3: #666666;
  --danger: #e00000;
  --warn: #b36b00;
  --node-bg: #ffffff;
  --node-border: #000000;
  --node-root-bg: #e00000;
  --shadow-md: 0 2px 10px rgba(0,0,0,0.10);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.16);
  --grid-dot: rgba(0,0,0,0.10);
}
[data-theme="dark"] {
  --bg: #111111;
  --surface: #111111;
  --surface2: #1e1e1e;
  --surface3: #2a2a2a;
  --border: #333333;
  --border-strong: #ffffff;
  --text: #ffffff;
  --text-dim: #999999;
  --text-mute: #666666;
  --accent: #ff2b2b;
  --accent-hover: #ff5252;
  --accent2: #ffffff;
  --accent3: #999999;
  --danger: #ff2b2b;
  --warn: #e0a030;
  --node-bg: #111111;
  --node-border: #ffffff;
  --node-root-bg: #ff2b2b;
  --shadow-md: 0 2px 10px rgba(0,0,0,0.6);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.7);
  --grid-dot: rgba(255,255,255,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; width: 100%; overflow: hidden; }

body {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

button { font-family: inherit; }

.tb-icon { width: 16px; height: 16px; flex-shrink: 0; }

/* TOOLBAR */
.toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 6px;
  z-index: 1000;
}
.toolbar .logo {
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  letter-spacing: -0.3px;
  margin-right: 10px;
  white-space: nowrap;
}
/* фирменная красная точка после названия */
.toolbar .logo::after, .auth-logo::after { content: '.'; color: var(--accent); }
.toolbar .logo span { color: var(--text-dim); font-weight: 400; }
.tb-sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
.tb-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.tb-btn:hover { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
.tb-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tb-btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.tb-btn.icon-only { padding: 6px; width: 32px; justify-content: center; }
.tb-btn.save { background: var(--accent2); border-color: var(--accent2); color: var(--bg); }
.tb-btn.save:hover { opacity: 0.85; color: var(--bg); }
.tb-btn:disabled { opacity: 0.4; cursor: default; }
.tb-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tb-btn.active:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.tb-btn:disabled:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.tb-spacer { flex: 1; }

.map-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 0;
  min-width: 160px;
  max-width: 280px;
  outline: none;
}
.map-title-input:hover { background: var(--surface); border-color: var(--border); }
.map-title-input:focus { background: var(--surface); border-color: var(--accent); }

/* SIDEBAR (maps list) */
.sidebar {
  position: fixed;
  top: 52px; left: 0; bottom: 0;
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 800;
  transition: transform .25s ease;
}
.sidebar.collapsed { transform: translateX(-100%); }
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 600;
}
.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.sidebar-list::-webkit-scrollbar { width: 6px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 0; }
.map-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background .12s;
  position: relative;
}
.map-item:hover { background: var(--surface2); }
.map-item.active { background: var(--surface2); color: var(--accent); }
.map-item .map-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-item .map-name[contenteditable="true"] {
  background: var(--bg);
  padding: 2px 4px;
  border-radius: 0;
  outline: 1px solid var(--accent);
}
.map-item .map-actions {
  display: none;
  gap: 2px;
}
.map-item:hover .map-actions { display: flex; }
.map-action {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.map-action:hover { background: var(--surface3); color: var(--text); }
.map-action.del:hover { color: var(--danger); }
.map-action svg { width: 13px; height: 13px; }
.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sb-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .12s;
}
.sb-btn:hover { background: var(--surface2); }
.sb-btn svg { width: 14px; height: 14px; }

/* CANVAS AREA */
.canvas-area {
  position: absolute;
  top: 52px;
  left: 240px;
  right: 0; bottom: 0;
  overflow: hidden;
  cursor: grab;
  background: var(--bg);
  transition: left .25s ease, right .25s ease;
}
.sidebar.collapsed ~ .canvas-area { left: 0; }
.canvas-area.panning { cursor: grabbing; }
.canvas-area.linking { cursor: crosshair; }
.canvas-area.rubber { cursor: crosshair; }

.canvas-grid {
  position: absolute;
  inset: -50%;
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
  will-change: transform, background-size;
}

.canvas-inner {
  position: absolute;
  width: 1px; height: 1px;
  overflow: visible;
  transform-origin: 0 0;
  will-change: transform;
}

.connections-svg {
  position: absolute;
  left: 0; top: 0;
  width: 1px; height: 1px;
  pointer-events: none;
  overflow: visible;
}

.rubber-band {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  pointer-events: none;
  z-index: 5;
  border-radius: 0;
}

/* NODES */
.mind-node {
  position: absolute;
  min-width: 140px;
  max-width: 420px;
  width: -webkit-max-content;
  width: -moz-max-content;
  width: max-content;
  background: var(--node-bg);
  border: 1.5px solid var(--node-border);
  border-radius: 0;
  padding: 12px 14px;
  cursor: move;
  transition: box-shadow .2s, border-color .2s, transform .12s;
  z-index: 10;
  touch-action: none;
}
.mind-node:hover {
  border-color: var(--accent);
  box-shadow: 0 0 20px color-mix(in srgb, var(--accent) 18%, transparent);
  z-index: 20;
}
.mind-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent), 0 0 24px color-mix(in srgb, var(--accent) 18%, transparent);
  z-index: 30;
}
.mind-node.search-hit {
  box-shadow: 0 0 0 3px var(--warn), 0 0 24px color-mix(in srgb, var(--warn) 30%, transparent);
}
.mind-node.dim { opacity: 0.35; }
.mind-node.link-target-hover {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent2) 30%, transparent);
}
.mind-node.root {
  background: var(--node-root-bg);
  border-color: transparent;
  min-width: 180px;
  text-align: center;
}
.mind-node.root .node-text { font-weight: 700; font-size: 16px; color: #fff; }

.node-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  outline: none;
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
  min-height: 20px;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}
.node-text:empty::before {
  content: 'Введите текст...';
  color: var(--text-mute);
}
.node-text a { color: var(--accent2); text-decoration: underline; }

.node-media {
  margin-top: 8px;
  border-radius: 0;
  overflow: hidden;
  position: relative;
}
.node-media img, .node-media video {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  background: var(--surface2);
  border-radius: 0;
  display: block;
}
.node-media .media-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.node-media:hover .media-remove { display: flex; }
.node-media .media-remove svg { width: 12px; height: 12px; }

.node-link {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 10px;
  background: color-mix(in srgb, var(--accent2) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent2) 25%, transparent);
  border-radius: 0;
  font-size: 12px;
  color: var(--accent2);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
}
.node-link:hover { background: color-mix(in srgb, var(--accent2) 18%, transparent); }
.node-link .link-remove {
  display: none;
  margin-left: auto;
  width: 18px; height: 18px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--accent2);
  cursor: pointer;
  flex-shrink: 0;
}
.node-link:hover .link-remove { display: flex; }
.node-link .link-remove svg { width: 11px; height: 11px; }

.node-notes-indicator {
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent3);
}

.node-collapse-toggle {
  position: absolute;
  width: 22px; height: 22px;
  border: 1.5px solid var(--node-border);
  background: var(--surface);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  user-select: none;
  z-index: 25;
  transition: background .12s, color .12s, border-color .12s;
}
.node-collapse-toggle:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.node-actions {
  display: none;
  position: absolute;
  top: -36px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px;
  gap: 2px;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  z-index: 100;
}
.mind-node.selected .node-actions { display: flex; }
.na-btn {
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.na-btn:hover { background: var(--surface2); color: var(--text); }
.na-btn.del:hover { color: var(--danger); }
.na-btn svg { width: 14px; height: 14px; }

/* CONTEXT MENU */
.ctx-menu {
  display: none;
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 6px;
  min-width: 200px;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
}
.ctx-menu.open { display: block; }
.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background .12s;
}
.ctx-item:hover { background: var(--surface2); }
.ctx-item svg { width: 15px; height: 15px; color: var(--text-dim); flex-shrink: 0; }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger svg { color: var(--danger); }
.ctx-item .ctx-shortcut {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-mute);
}
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }
.ctx-color-row {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
}
.ctx-color {
  width: 20px; height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .12s;
}
.ctx-color:hover { transform: scale(1.15); }
.ctx-color.clear {
  background: var(--surface2);
  border: 2px dashed var(--border-strong);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* MODAL */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 22px 22px 18px;
  width: 420px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  user-select: text;
  -webkit-user-select: text;
}
.modal h3, .modal h4, .modal p, .modal td, .modal div, .modal pre, .modal code, .modal span:not(.kbd) {
  user-select: text;
  -webkit-user-select: text;
}
.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
}
.modal h4 { font-size: 13px; color: var(--text-dim); margin: 12px 0 6px; font-weight: 500; }
.modal input[type="text"], .modal input[type="url"], .modal textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  margin-bottom: 10px;
  resize: vertical;
}
.modal textarea { min-height: 80px; }
.modal input:focus, .modal textarea:focus { border-color: var(--accent); }
.modal-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}
.modal-btn {
  padding: 8px 18px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.modal-btn:hover { background: var(--surface3); }
.modal-btn.ok { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-btn.ok:hover { background: var(--accent-hover); }
.modal-btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.kbd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.kbd-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.kbd-table td:first-child {
  width: 40%;
  white-space: nowrap;
}
.kbd-table td:last-child { color: var(--text-dim); }
kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text);
  margin: 0 1px;
}

/* DROPDOWN */
.dropdown-wrap { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 6px;
  min-width: 180px;
  box-shadow: var(--shadow-lg);
  z-index: 1001;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background .12s;
}
.dropdown-item:hover { background: var(--surface2); }
.dropdown-item svg { width: 16px; height: 16px; color: var(--text-dim); }
.dropdown-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ZOOM */
.zoom-ctrl {
  position: fixed;
  bottom: 16px; right: 16px;
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px;
  z-index: 500;
  box-shadow: var(--shadow-md);
}
.zoom-btn {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  transition: background .12s, color .12s;
}
.zoom-btn:hover { background: var(--surface2); color: var(--text); }
.zoom-btn svg { width: 14px; height: 14px; }
.zoom-label {
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-dim);
  min-width: 44px;
  justify-content: center;
}

/* MINIMAP */
.minimap {
  position: fixed;
  bottom: 60px; right: 16px;
  width: 200px; height: 140px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 0;
  z-index: 480;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  cursor: pointer;
}
.minimap.hidden { display: none; }
.minimap canvas { display: block; width: 100%; height: 100%; }
.minimap-viewport {
  position: absolute;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  pointer-events: none;
  border-radius: 0;
}

/* HINTS */
.help-hint {
  position: fixed;
  bottom: 16px; left: 16px;
  font-size: 12px;
  color: var(--text-dim);
  z-index: 500;
  line-height: 1.6;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: 6px 10px;
  border-radius: 0;
  border: 1px solid var(--border);
  transition: opacity .25s, transform .25s;
}
.help-hint.hidden { opacity: 0; transform: translateY(20px); pointer-events: none; }
.sidebar.collapsed ~ .help-hint { left: 16px; }
.sidebar:not(.collapsed) ~ .help-hint { left: 256px; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 0;
  font-size: 13px;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 4000;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.danger { border-color: var(--danger); }

/* EXPORT OVERLAY */
.export-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 5000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}
.export-overlay.show { display: flex; }
.export-overlay .spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.export-overlay p { color: #ddd; font-size: 14px; }

/* SEARCH BAR */
.search-bar {
  display: none;
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 6px;
  width: 380px;
  max-width: 92vw;
  box-shadow: var(--shadow-lg);
  z-index: 1500;
  align-items: center;
  gap: 4px;
}
.search-bar.open { display: flex; }
.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 6px 10px;
  outline: none;
}
.search-bar .search-info {
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-dim);
  padding: 0 8px;
}
.search-bar button {
  width: 28px; height: 28px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.search-bar button:hover { background: var(--surface2); color: var(--text); }
.search-bar button svg { width: 14px; height: 14px; }

/* SIDE PANEL (notes) */
.side-panel {
  position: fixed;
  top: 52px; right: 0; bottom: 0;
  width: 340px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 700;
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
}
.side-panel.open { transform: translateX(0); }
.side-panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.side-panel-header h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 600;
}
.side-panel-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.side-panel-content textarea {
  flex: 1;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  padding: 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  outline: none;
}
.side-panel-content textarea:focus { border-color: var(--accent); }
.side-panel-content .node-label {
  font-size: 12px;
  color: var(--text-mute);
  margin-bottom: 8px;
}
.side-panel-content .node-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
  word-break: break-word;
}

/* ICON BUTTON */
.icon-btn {
  width: 28px; height: 28px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn svg { width: 14px; height: 14px; }

/* CHAT PANEL */
.chat-panel {
  position: fixed;
  top: 52px; right: 0; bottom: 0;
  width: 380px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 750;
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
}
.chat-panel.open { transform: translateX(0); }
.chat-panel.open ~ .side-panel.open { transform: translateX(-380px); }
.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-header h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 600;
}
.chat-header .chat-actions {
  display: flex;
  gap: 4px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 0; }
.chat-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 0;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-msg.assistant code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.chat-msg.assistant pre {
  background: var(--bg);
  padding: 8px 10px;
  border-radius: 0;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  margin: 6px 0;
}
.chat-msg.assistant strong { font-weight: 600; }
.chat-msg.thinking {
  align-self: flex-start;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  font-style: italic;
}
.chat-msg.thinking::after {
  content: '...';
  display: inline-block;
  animation: dots 1.2s steps(4, end) infinite;
  width: 1.2em;
  text-align: left;
  overflow: hidden;
  vertical-align: bottom;
}
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75%, 100% { content: '...'; }
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
  padding: 0 20px;
  line-height: 1.6;
}
.chat-empty strong { color: var(--text-dim); display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; }
.chat-attachments {
  display: none;
  padding: 8px 10px 0;
  border-top: 1px solid var(--border);
  gap: 6px;
  flex-wrap: wrap;
}
.chat-attachments.has-items { display: flex; }
.chat-att {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 12px;
  color: var(--text);
  max-width: 200px;
}
.chat-att .att-icon {
  width: 26px; height: 26px;
  border-radius: 0;
  background: var(--surface3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.chat-att .att-icon img { width: 100%; height: 100%; object-fit: cover; }
.chat-att .att-icon svg { width: 14px; height: 14px; color: var(--accent3); }
.chat-att .att-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-att .att-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-att .att-size { color: var(--text-mute); font-size: 10px; }
.chat-att .att-remove {
  width: 18px; height: 18px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-att .att-remove:hover { background: var(--surface3); color: var(--danger); }
.chat-att .att-remove svg { width: 12px; height: 12px; }
.chat-att.parsing { opacity: 0.6; }
.chat-att.error { border-color: var(--danger); color: var(--danger); }

.chat-msg-att {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  background: rgba(255,255,255,0.15);
  border-radius: 0;
  font-size: 11px;
  margin: 2px 4px 2px 0;
  vertical-align: middle;
}
.chat-msg-att svg { width: 11px; height: 11px; }
.chat-msg.assistant .chat-msg-att { background: var(--surface3); color: var(--text-dim); }
.chat-msg-img {
  display: block;
  max-width: 100%;
  max-height: 200px;
  border-radius: 0;
  margin-top: 6px;
}

.chat-attach-btn {
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.chat-attach-btn:hover { background: var(--surface3); color: var(--accent); }
.chat-attach-btn svg { width: 18px; height: 18px; }

.chat-input-wrap {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input-wrap textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  min-height: 40px;
  max-height: 140px;
  line-height: 1.4;
}
.chat-input-wrap textarea:focus { border-color: var(--accent); }
.chat-send {
  width: 40px; height: 40px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .12s;
}
.chat-send:hover { background: var(--accent-hover); }
.chat-send:disabled { opacity: 0.4; cursor: default; }
.chat-send svg { width: 18px; height: 18px; }
.chat-context-info {
  font-size: 11px;
  color: var(--text-mute);
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.chat-context-info b { color: var(--text-dim); font-weight: 500; }

/* AI */
.mind-node.ai-loading {
  position: relative;
  pointer-events: none;
}
.mind-node.ai-loading::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 0;
  border: 2px solid var(--accent3);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
  pointer-events: none;
}
.tb-btn.ai {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tb-btn.ai:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.ai-prompt-modal textarea { min-height: 120px; }
.ai-key-status {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.ai-key-status.ok { color: var(--accent2); }
.ai-key-status.bad { color: var(--danger); }
.ai-model-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.ai-model-row select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  cursor: pointer;
}
.ai-model-row select:focus { border-color: var(--accent); }

/* RESPONSIVE */
@media (max-width: 720px) {
  .sidebar { width: 78vw; }
  .canvas-area { left: 0 !important; }
  .toolbar .tb-btn span { display: none; }
  .toolbar .tb-btn { padding: 6px; }
  .toolbar .map-title-input { min-width: 100px; max-width: 140px; font-size: 13px; }
  .help-hint { display: none; }
  .minimap { display: none; }
  .side-panel { width: 92vw; }
}

/* ── Экран входа ─────────────────────────────────────────────── */
/* ── Лендинг (пока пользователь не вошёл) ────────────────────── */
.auth-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: #fff;
  overflow-y: auto;
  scroll-behavior: smooth;
  user-select: text; -webkit-user-select: text;
}
.ld-top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 6vw;
  background: rgba(17,17,17,0.92);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.ld-top-logo { color: #fff; font-weight: 700; font-size: 18px; }
.ld-top-logo::after { content: '.'; color: #ff2b2b; }
.ld-top-btn {
  border: 1px solid #fff; background: transparent; color: #fff;
  padding: 8px 22px; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer;
}
.ld-top-btn:hover { background: #fff; color: #111; }

/* Обложка */
.ld-hero {
  background: #111; color: #fff;
  display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px;
  align-items: center;
  padding: 9vh 6vw 11vh;
  min-height: 78vh;
  margin-top: -57px; /* под липкую шапку */
  padding-top: calc(9vh + 57px);
}
.ld-hero-text h1 {
  font-size: clamp(38px, 4.6vw, 66px);
  font-weight: 700; letter-spacing: -2px; line-height: 1.05;
  margin: 0 0 22px;
  animation: ldUp .7s ease both;
}
.ld-hero-text p {
  font-size: 18px; line-height: 1.55; color: #aaa;
  max-width: 480px; margin: 0 0 30px;
  animation: ldUp .7s ease .15s both;
}
.ld-cta {
  background: #e00000; color: #fff; border: none;
  padding: 16px 36px; font-size: 17px; font-weight: 700;
  font-family: inherit; cursor: pointer;
  animation: ldUp .7s ease .3s both;
  transition: background .15s, transform .15s;
}
.ld-cta:hover { background: #b80000; transform: translateY(-2px); }
.ld-cta-note {
  font-size: 13px; color: #777; margin-top: 12px;
  animation: ldUp .7s ease .45s both;
}

/* Карта рисует себя */
.ld-art { width: 100%; display: block; }
.ld-line {
  stroke-dasharray: 260; stroke-dashoffset: 260;
  animation: ldDraw .9s ease forwards;
}
.ld-line.l1 { animation-delay: .5s; }
.ld-line.l2 { animation-delay: .7s; }
.ld-line.l3 { animation-delay: .9s; }
.ld-line.l4 { animation-delay: 1.3s; }
.ld-line.l5 { animation-delay: 1.5s; }
.ld-line.l6 { animation-delay: 1.9s; }
.ld-node { opacity: 0; animation: ldPop .45s ease forwards; }
.ld-node.n1 { animation-delay: .15s; }
.ld-node.n2 { animation-delay: 1.0s; }
.ld-node.n3 { animation-delay: 1.2s; }
.ld-node.n4 { animation-delay: 1.4s; }
.ld-node.n5 { animation-delay: 1.8s; }
.ld-node.n6 { animation-delay: 2.0s; }
.ld-node.n7 { animation-delay: 2.4s; }
@keyframes ldDraw { to { stroke-dashoffset: 0; } }
@keyframes ldPop { from { opacity: 0; } to { opacity: 1; } }
@keyframes ldUp {
  from { opacity: 0; transform: translateY(26px); }
  to   { opacity: 1; transform: none; }
}

/* Секции */
.ld-section { padding: 90px 6vw; background: #fff; color: #000; }
.ld-section h2 {
  font-size: clamp(28px, 3.2vw, 44px);
  font-weight: 700; letter-spacing: -1px;
  margin: 0 0 40px;
}
.ld-gray { background: #f2f2f2; }
.ld-dark { background: #111; color: #fff; }
.ld-what { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; max-width: 1000px; }
.ld-what p { font-size: 17px; line-height: 1.6; color: #444; margin: 0; }
.ld-steps, .ld-cards {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px;
}
.ld-step-num {
  font-size: 54px; font-weight: 700; color: #e00000;
  line-height: 1; margin-bottom: 14px;
}
.ld-step h3, .ld-card h3 { font-size: 19px; font-weight: 700; margin: 0 0 10px; }
.ld-step p { font-size: 15px; line-height: 1.55; color: #555; margin: 0; }
.ld-card {
  border: 1px solid #333; padding: 26px;
}
.ld-card h3::after { content: '.'; color: #ff2b2b; }
.ld-card p { font-size: 15px; line-height: 1.55; color: #999; margin: 0; }

/* Появление при прокрутке */
.reveal { opacity: 0; transform: translateY(28px); transition: opacity .6s ease, transform .6s ease; }
.reveal.visible { opacity: 1; transform: none; }
.ld-steps .ld-step:nth-child(2), .ld-cards .ld-card:nth-child(2) { transition-delay: .12s; }
.ld-steps .ld-step:nth-child(3), .ld-cards .ld-card:nth-child(3) { transition-delay: .24s; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
  .ld-line { animation: none; stroke-dashoffset: 0; }
  .ld-node { animation: none; opacity: 1; }
  .ld-hero-text h1, .ld-hero-text p, .ld-cta, .ld-cta-note { animation: none; }
}

/* Формы входа и регистрации */
.ld-auth { padding-bottom: 110px; }
.auth-forms {
  display: grid; grid-template-columns: 1fr 1fr; gap: 48px;
  max-width: 860px;
}
.auth-form-block { display: flex; flex-direction: column; gap: 12px; }
.auth-form-block h3 { font-size: 22px; font-weight: 700; margin: 0 0 4px; color: #000; }
.auth-form-block input {
  background: #fff; border: none; border-bottom: 2px solid #000;
  padding: 12px 2px; color: #000;
  font-size: 16px; font-family: inherit; outline: none;
}
.auth-form-block input::placeholder { color: #999; }
.auth-form-block input:focus { border-bottom-color: #e00000; }
.auth-error { color: #e00000; font-size: 13px; min-height: 18px; }
/* Входа нет (класс ставит скрипт в начале body до отрисовки) —
   стартовый экран виден сразу, без мигания рабочей области */
html.need-auth .auth-overlay { display: block !important; }
.auth-hint { font-size: 14px; color: #555; margin: 0; line-height: 1.5; }
.auth-links { display: flex; gap: 18px; font-size: 13px; }
.auth-links a { color: #555; text-decoration: underline; }
.auth-links a:hover { color: #e00000; }
.auth-step { max-width: 380px; }
.auth-substep { display: flex; flex-direction: column; gap: 12px; }
.auth-overlay .auth-btn {
  border: 2px solid #000; background: #fff; color: #000;
  border-radius: 0; padding: 14px;
  font-size: 16px; font-weight: 600; font-family: inherit; cursor: pointer;
}
.auth-overlay .auth-btn:hover { background: #f2f2f2; }
.auth-overlay .auth-btn.primary { background: #e00000; border-color: #e00000; color: #fff; }
.auth-overlay .auth-btn.primary:hover { background: #b80000; border-color: #b80000; }
.auth-overlay .auth-btn:disabled { opacity: 0.6; cursor: default; }

.ld-footer {
  padding: 26px 6vw; background: #111; color: #777; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px;
}
.ld-footer .ld-dot { color: #ff2b2b; }
.ld-footer-link { color: #777; }
.ld-footer-link:hover { color: #fff; }

@media (max-width: 860px) {
  .ld-hero { grid-template-columns: 1fr; min-height: auto; padding-bottom: 60px; }
  .ld-art { max-width: 380px; }
  .ld-what, .ld-steps, .ld-cards, .auth-forms { grid-template-columns: 1fr; }
  .ld-section { padding: 56px 24px; }
}
.auth-btn {
  border: 1px solid var(--border-strong); background: var(--surface2);
  color: var(--text); border-radius: 0; padding: 10px;
  font-size: 14px; font-family: inherit; cursor: pointer;
}
.auth-btn:hover { background: var(--surface3); }
.auth-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.auth-btn.primary:hover { background: var(--accent-hover); }
.auth-btn:disabled { opacity: 0.6; cursor: default; }

/* ── Пользователь в сайдбаре ─────────────────────────────────── */
.sb-user { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.sb-user-email {
  flex: 1; font-size: 12px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-user .sb-btn { width: auto; flex: none; }

/* Индикатор хранилища аккаунта */
.sb-storage { margin-bottom: 6px; }
.sb-storage-bar {
  height: 4px; background: var(--surface3); margin-bottom: 4px;
}
.sb-storage-fill {
  height: 100%; width: 0; background: var(--text);
  transition: width .4s ease;
}
.sb-storage-fill.full { background: var(--accent); }
.sb-storage-label { font-size: 11px; color: var(--text-mute); }
