:root {
  --bg: #f5f7fb;
  --panel: rgba(255,255,255,.86);
  --panel-solid: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #eef2ff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(17, 24, 39, .10);
  --shadow-soft: 0 10px 24px rgba(17, 24, 39, .08);
  --radius: 20px;
  --topbar-h: 68px;
  --left-w: 318px;
  --right-w: 332px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37,99,235,.14), transparent 34%),
    radial-gradient(circle at 80% 0%, rgba(14,165,233,.12), transparent 28%),
    var(--bg);
  overflow: hidden;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }

.app-shell { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(229,231,235,.8);
  background: rgba(255,255,255,.74);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 230px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #111827, #2563eb);
  color: #fff; font-weight: 800; letter-spacing: -.04em;
  box-shadow: var(--shadow-soft);
}
.brand-title { font-size: 18px; font-weight: 800; letter-spacing: -.03em; }
.brand-subtitle { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar-status {
  flex: 1;
  min-width: 0;
  color: #374151;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.theme-icon-btn {
  width: 44px;
  min-width: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.theme-icon-btn svg {
  width: 20px;
  height: 20px;
  display: block;
  flex: 0 0 auto;
  overflow: visible;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.admin-open-btn {
  min-width: 78px;
  white-space: nowrap;
}
.admin-open-btn[aria-expanded="true"] {
  border-color: rgba(37,99,235,.35);
  box-shadow: var(--shadow-soft);
  background: #fff;
}

.layout {
  height: calc(100vh - var(--topbar-h));
  display: grid;
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
  gap: 12px;
  padding: 12px;
}
.left-panel, .right-panel {
  min-height: 0;
  overflow: auto;
  padding: 2px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}
.panel-card {
  background: var(--panel);
  border: 1px solid rgba(229,231,235,.78);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 16px;
  backdrop-filter: blur(14px);
}
.intro-card { background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(255,255,255,.76)); }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
h1, h2, p { margin: 0; }
h1 { margin-top: 6px; font-size: 22px; line-height: 1.12; letter-spacing: -.04em; }
h2 { font-size: 15px; letter-spacing: -.02em; }
.panel-card p { color: var(--muted); font-size: 13px; line-height: 1.45; margin-top: 8px; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.pill {
  border-radius: 999px;
  background: #f3f4f6;
  color: #4b5563;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.pill.good { color: #047857; background: #ecfdf5; }
.pill.warn { color: #b45309; background: #fffbeb; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-label { color: #4b5563; font-size: 12px; font-weight: 700; display: flex; flex-direction: column; gap: 6px; }
.input, .textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255,255,255,.9);
  color: var(--text);
  outline: none;
  padding: 11px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 94px; }
.input:focus, .textarea:focus { border-color: rgba(37,99,235,.6); box-shadow: 0 0 0 4px rgba(37,99,235,.10); }

.btn, .tool-btn, .template-btn, .icon-btn {
  border: 0;
  border-radius: 14px;
  min-height: 40px;
  transition: transform .12s, box-shadow .12s, background .12s, border-color .12s;
}
.btn:active, .tool-btn:active, .template-btn:active, .icon-btn:active { transform: translateY(1px); }
.btn { padding: 10px 14px; font-weight: 750; font-size: 13px; }
.btn.full { width: 100%; }
.btn.compact { min-height: 36px; padding: 8px 11px; }
.btn-dark { background: #111827; color: #fff; box-shadow: 0 10px 24px rgba(17,24,39,.18); }
.btn-dark:hover { background: #020617; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 12px 22px rgba(37,99,235,.22); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: rgba(255,255,255,.76); color: #111827; border: 1px solid var(--line); }
.btn-ghost:hover { background: #fff; box-shadow: var(--shadow-soft); }
.btn-danger-soft { color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; }
.btn-danger-soft:hover { background: #fee2e2; }
.file-label { display: flex; align-items: center; justify-content: center; }
.file-label input { display: none; }
.tool-btn {
  background: #fff;
  border: 1px solid var(--line);
  color: #111827;
  font-weight: 750;
  padding: 10px 8px;
}
.tool-btn:hover { border-color: rgba(37,99,235,.35); box-shadow: var(--shadow-soft); }
.template-list { display: flex; flex-direction: column; gap: 8px; }
.template-btn {
  text-align: left;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  color: #111827;
}
.template-btn b { display: block; font-size: 13px; }
.template-btn span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.template-btn:hover { border-color: rgba(37,99,235,.35); box-shadow: var(--shadow-soft); }

.workspace {
  min-width: 0;
  min-height: 0;
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  background: rgba(255,255,255,.52);
  border: 1px solid rgba(229,231,235,.8);
  box-shadow: var(--shadow);
}
.canvas-toolbar {
  position: absolute;
  z-index: 12;
  top: 12px; left: 12px; right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.canvas-toolbar > * { pointer-events: auto; }
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.88);
  color: #111827;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  font-weight: 850;
}
.icon-btn:hover { background: #fff; }
.zoom-value {
  height: 38px;
  min-width: 62px;
  display: grid; place-items: center;
  padding: 0 10px;
  border-radius: 14px;
  background: rgba(255,255,255,.88);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  font-size: 12px;
  font-weight: 800;
}
.autosave {
  margin-left: auto;
  height: 38px;
  display: grid; place-items: center;
  padding: 0 12px;
  border-radius: 14px;
  background: rgba(17,24,39,.84);
  color: #fff;
  box-shadow: var(--shadow-soft);
  font-size: 12px;
}
.canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  background-image:
    linear-gradient(rgba(148,163,184,.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148,163,184,.16) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: 0 0;
}
.board-world {
  position: absolute;
  left: 0; top: 0;
  width: 8000px; height: 6000px;
  transform-origin: 0 0;
}
.edge-layer {
  position: absolute;
  left: 0; top: 0;
  width: 8000px; height: 6000px;
  overflow: visible;
  pointer-events: none;
}
.node-layer { position: absolute; left: 0; top: 0; width: 8000px; height: 6000px; }
.empty-state {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 48px));
  text-align: center;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,.76);
  box-shadow: var(--shadow-soft);
  pointer-events: none;
}
.empty-icon {
  width: 52px; height: 52px; margin: 0 auto 10px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: #111827;
  color: #fff;
  font-weight: 900;
}
.empty-state h2 { font-size: 20px; }
.empty-state p { color: var(--muted); line-height: 1.45; font-size: 13px; margin-top: 8px; }

.node {
  position: absolute;
  border-radius: 20px;
  background: #fff;
  border: 1px solid rgba(229,231,235,.95);
  box-shadow: 0 12px 34px rgba(17,24,39,.10);
  padding: 14px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  transition: box-shadow .15s, border-color .15s, transform .15s, opacity .15s;
}
.node:hover { box-shadow: 0 18px 42px rgba(17,24,39,.15); }
.node.selected { border-color: rgba(37,99,235,.8); box-shadow: 0 0 0 4px rgba(37,99,235,.12), 0 18px 42px rgba(17,24,39,.16); }
.node.group {
  background: rgba(255,255,255,.42);
  border: 1.5px dashed rgba(100,116,139,.58);
  box-shadow: none;
  z-index: 0;
}
.node.card, .node.text { z-index: 2; }
.node.dragging { opacity: .92; }
.node-header { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.node-title { font-weight: 850; letter-spacing: -.025em; line-height: 1.15; white-space: pre-wrap; overflow-wrap: anywhere; }
.node-body { color: #4b5563; font-size: 13px; line-height: 1.38; margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.node.text .node-title { font-size: 14px; color: #1f2937; }
.node.text .node-body { font-size: 14px; color: #111827; }
.node.group .node-title { font-size: 13px; color: #475569; }
.node-actions { display: flex; gap: 5px; flex-shrink: 0; opacity: .86; }
.node-mini {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid rgba(229,231,235,.9);
  background: rgba(255,255,255,.78);
  color: #111827;
  font-size: 12px;
  font-weight: 900;
}
.node-mini:hover { background: #fff; }
.node-blue { background: #eef4ff; border-color: #93c5fd; }
.node-green { background: #ecfdf5; border-color: #86efac; }
.node-amber { background: #fff7ed; border-color: #fcd34d; }
.node-rose { background: #fff1f2; border-color: #fda4af; }
.node-purple { background: #f5f3ff; border-color: #c4b5fd; }
.node-gray { background: #f8fafc; border-color: #cbd5e1; }
.edge-path { fill: none; stroke: rgba(71,85,105,.72); stroke-width: 2.4; }
.edge-arrow { fill: rgba(71,85,105,.72); }
.edge-label { font-size: 12px; fill: #475569; paint-order: stroke; stroke: #fff; stroke-width: 5; }

.color-row { display: flex; flex-wrap: wrap; gap: 8px; }
.color-dot {
  width: 30px; height: 30px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,.92);
  box-shadow: 0 0 0 1px rgba(148,163,184,.6);
}
.color-dot.active { box-shadow: 0 0 0 3px rgba(37,99,235,.22), 0 0 0 1px rgba(37,99,235,.8); }
.color-dot[data-color="blue"] { background: #dbeafe; }
.color-dot[data-color="green"] { background: #d1fae5; }
.color-dot[data-color="amber"] { background: #fef3c7; }
.color-dot[data-color="rose"] { background: #ffe4e6; }
.color-dot[data-color="purple"] { background: #ede9fe; }
.color-dot[data-color="gray"] { background: #e5e7eb; }
.muted-box {
  background: #f8fafc;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.45;
}
.hint-list p { font-size: 12px; margin-top: 7px; }
.board-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow: auto; padding-right: 2px; }
.board-item {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 10px;
}
.board-item b { display: block; font-size: 13px; }
.board-item span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.board-item-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.board-item-actions .btn { min-height: 34px; padding: 7px 8px; font-size: 12px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  max-width: min(360px, calc(100vw - 36px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  background: rgba(17,24,39,.94);
  color: #fff;
  padding: 12px 14px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.35;
  transition: opacity .18s, transform .18s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15,23,42,.42);
  backdrop-filter: blur(8px);
}
.modal-card {
  width: min(420px, 100%);
  border-radius: 24px;
  background: #fff;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,.5);
  padding: 20px;
}
.modal-card h2 { font-size: 18px; }
.modal-card p { color: var(--muted); margin-top: 8px; line-height: 1.45; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

body.readonly .tool-btn,
body.readonly .template-btn,
body.readonly #selectionForm input,
body.readonly #selectionForm textarea,
body.readonly #selectionForm button:not(#collapseNodeBtn),
body.readonly #saveBtn,
body.readonly #clearBoardBtn,
body.readonly #importJsonInput,
body.readonly .file-label { opacity: .55; pointer-events: none; }
body.readonly #editState { color: #b45309; background: #fffbeb; }
body.readonly .node { cursor: default; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 286px minmax(0, 1fr); }
  .right-panel {
    position: fixed;
    right: 12px;
    bottom: 12px;
    top: auto;
    z-index: 30;
    width: min(380px, calc(100vw - 24px));
    max-height: min(58vh, 520px);
  }
}

@media (max-width: 820px) {
  body { overflow: hidden; }
  .topbar { padding: 10px 12px; gap: 10px; }
  .brand { min-width: 0; flex: 1; }
  .brand-mark { width: 38px; height: 38px; border-radius: 13px; }
  .brand-title { font-size: 16px; }
  .brand-subtitle { display: none; }
  .topbar-status { display: none; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 8px 10px; min-height: 36px; }
  .layout { display: block; height: calc(100vh - var(--topbar-h)); padding: 8px; }
  .workspace { height: 100%; border-radius: 20px; }
  .left-panel {
    position: fixed;
    left: 8px;
    top: calc(var(--topbar-h) + 8px);
    bottom: 8px;
    z-index: 35;
    width: min(330px, calc(100vw - 16px));
    transform: translateX(calc(-100% - 18px));
    transition: transform .2s;
  }
  body.left-open .left-panel { transform: translateX(0); }
  .right-panel {
    right: 8px;
    bottom: 8px;
    width: min(360px, calc(100vw - 16px));
    max-height: 48vh;
  }
  .canvas-toolbar { top: 10px; left: 10px; right: 10px; flex-wrap: wrap; }
  .autosave { display: none; }
  .empty-state { top: 54%; }
}

@media (max-width: 540px) {
  .right-panel { display: none; }
  .canvas-toolbar .btn.compact { display: none; }
  .node { border-radius: 18px; padding: 12px; }
  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

/* v1.1 fixes and additions */
[hidden] { display: none !important; }

.small-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 10px;
}
.local-board-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}
.local-board-item {
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 6px;
  align-items: stretch;
}
.local-board-item > button[data-open] {
  min-width: 0;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.82);
  color: var(--text);
  padding: 10px;
}
.local-board-item > button[data-open] b {
  display: block;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.local-board-item > button[data-open] span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}
.local-board-item.active > button[data-open] {
  border-color: rgba(37,99,235,.65);
  box-shadow: 0 0 0 4px rgba(37,99,235,.10);
}
.mini-danger {
  border: 1px solid #fecaca;
  border-radius: 14px;
  background: #fef2f2;
  color: #b91c1c;
  font-weight: 900;
}

html[data-theme="dark"] {
  --bg: #060914;
  --panel: rgba(15,23,42,.82);
  --panel-solid: #0f172a;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --line: rgba(71,85,105,.78);
  --soft: rgba(30,41,59,.9);
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --danger: #fb7185;
  --shadow: 0 18px 50px rgba(0,0,0,.34);
  --shadow-soft: 0 10px 24px rgba(0,0,0,.24);
}
html[data-theme="dark"] body {
  background:
    radial-gradient(circle at top left, rgba(37,99,235,.20), transparent 34%),
    radial-gradient(circle at 80% 0%, rgba(14,165,233,.13), transparent 28%),
    var(--bg);
}
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .workspace,
html[data-theme="dark"] .panel-card,
html[data-theme="dark"] .intro-card,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .modal-card {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}
html[data-theme="dark"] .topbar-status,
html[data-theme="dark"] .field-label,
html[data-theme="dark"] .node-title,
html[data-theme="dark"] .node.text .node-title,
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .tool-btn,
html[data-theme="dark"] .template-btn,
html[data-theme="dark"] .icon-btn,
html[data-theme="dark"] .zoom-value,
html[data-theme="dark"] .input,
html[data-theme="dark"] .textarea,
html[data-theme="dark"] .local-board-item > button[data-open],
html[data-theme="dark"] .board-item,
html[data-theme="dark"] .node-mini {
  color: var(--text);
}
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .tool-btn,
html[data-theme="dark"] .template-btn,
html[data-theme="dark"] .icon-btn,
html[data-theme="dark"] .zoom-value,
html[data-theme="dark"] .input,
html[data-theme="dark"] .textarea,
html[data-theme="dark"] .local-board-item > button[data-open],
html[data-theme="dark"] .board-item,
html[data-theme="dark"] .node-mini,
html[data-theme="dark"] .muted-box {
  background: rgba(15,23,42,.88);
  border-color: var(--line);
}
html[data-theme="dark"] .btn-ghost:hover,
html[data-theme="dark"] .tool-btn:hover,
html[data-theme="dark"] .template-btn:hover,
html[data-theme="dark"] .icon-btn:hover,
html[data-theme="dark"] .node-mini:hover {
  background: rgba(30,41,59,.95);
}
html[data-theme="dark"] .pill {
  background: rgba(30,41,59,.95);
  color: #cbd5e1;
}
html[data-theme="dark"] .canvas {
  background-image:
    linear-gradient(rgba(148,163,184,.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148,163,184,.13) 1px, transparent 1px);
}
html[data-theme="dark"] .node {
  background: rgba(15,23,42,.92);
  border-color: var(--line);
  color: var(--text);
}
html[data-theme="dark"] .node-body,
html[data-theme="dark"] .node.text .node-body,
html[data-theme="dark"] .template-btn span,
html[data-theme="dark"] .local-board-item > button[data-open] span,
html[data-theme="dark"] .board-item span,
html[data-theme="dark"] .modal-card p,
html[data-theme="dark"] .panel-card p {
  color: var(--muted);
}
html[data-theme="dark"] .node-blue { background: #172554; border-color: #3b82f6; }
html[data-theme="dark"] .node-green { background: #052e2b; border-color: #10b981; }
html[data-theme="dark"] .node-amber { background: #3b2f0b; border-color: #f59e0b; }
html[data-theme="dark"] .node-rose { background: #3f1620; border-color: #fb7185; }
html[data-theme="dark"] .node-purple { background: #2e1065; border-color: #8b5cf6; }
html[data-theme="dark"] .node-gray { background: #1f2937; border-color: #94a3b8; }
html[data-theme="dark"] .edge-path { stroke: rgba(148,163,184,.78); }
html[data-theme="dark"] .edge-arrow { fill: rgba(148,163,184,.78); }
html[data-theme="dark"] .edge-label { fill: #cbd5e1; stroke: #0f172a; }
html[data-theme="dark"] .mini-danger,
html[data-theme="dark"] .btn-danger-soft {
  background: rgba(127,29,29,.25);
  border-color: rgba(248,113,113,.38);
  color: #fecaca;
}

@media (max-width: 820px) {
  .local-board-list { max-height: 180px; }
}
@media (max-width: 540px) {
  .topbar-actions .btn { font-size: 12px; padding-left: 8px; padding-right: 8px; }
  #themeToggleBtn { display: none; }
}

/* v1.3 interface */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.66);
}
.mode-tab {
  border: 0;
  border-radius: 12px;
  min-height: 38px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.mode-tab.active {
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow-soft);
}
.file-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.file-grid .btn,
.file-grid .file-label {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  font-size: 12px;
  justify-content: center;
}
.file-grid > [hidden] { display: none !important; }
.clear-compact { margin-top: 8px; min-height: 36px; }
.ghost-hidden { display: none !important; }

.local-board-item {
  grid-template-columns: 1fr 34px;
}
.local-board-share {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: -2px;
}
.mini-action {
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 32px;
  background: rgba(255,255,255,.86);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}
.mini-action.primary {
  grid-column: 1 / -1;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.mini-action.danger {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

.node { cursor: grab; }
.node.dragging { cursor: grabbing; }
.node-title[contenteditable="true"],
.node-body[contenteditable="true"] {
  cursor: text;
  user-select: text;
  outline: none;
  border-radius: 8px;
  padding: 2px 3px;
  margin-left: -3px;
}
.node-title[contenteditable="true"]:focus,
.node-body[contenteditable="true"]:focus {
  background: rgba(255,255,255,.72);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.node-handle {
  position: absolute;
  z-index: 6;
  width: 13px;
  height: 13px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid #fff;
  background: var(--primary);
  box-shadow: 0 4px 10px rgba(37,99,235,.32);
  opacity: 0;
  transform: scale(.86);
  transition: opacity .12s, transform .12s;
}
.node:hover .node-handle,
.node.selected .node-handle,
.node-handle.active {
  opacity: 1;
  transform: scale(1);
}
.handle-top { left: 50%; top: -7px; transform: translateX(-50%) scale(.86); }
.handle-right { right: -7px; top: 50%; transform: translateY(-50%) scale(.86); }
.handle-bottom { left: 50%; bottom: -7px; transform: translateX(-50%) scale(.86); }
.handle-left { left: -7px; top: 50%; transform: translateY(-50%) scale(.86); }
.node:hover .handle-top, .node.selected .handle-top, .handle-top.active { transform: translateX(-50%) scale(1); }
.node:hover .handle-right, .node.selected .handle-right, .handle-right.active { transform: translateY(-50%) scale(1); }
.node:hover .handle-bottom, .node.selected .handle-bottom, .handle-bottom.active { transform: translateX(-50%) scale(1); }
.node:hover .handle-left, .node.selected .handle-left, .handle-left.active { transform: translateY(-50%) scale(1); }
.node-handle:hover { filter: brightness(.95); }
body.readonly .node-handle { display: none; }

.text-board {
  position: absolute;
  inset: 0;
  background: #020202;
  color: #f8fafc;
  overflow: auto;
  padding: clamp(22px, 4vw, 56px);
}
.text-board-editor {
  width: min(1180px, 100%);
  min-height: calc(100% - 20px);
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: clamp(26px, 4vw, 58px);
  line-height: 1.18;
  letter-spacing: -.045em;
  font-weight: 750;
  caret-color: #fff;
}
.text-board-editor:empty::before {
  content: attr(data-placeholder);
  color: rgba(248,250,252,.36);
}
body.text-mode .canvas {
  background-image: none;
  background: #020202;
}
body.text-mode .canvas-toolbar .icon-btn:not(#undoBtn):not(#redoBtn),
body.text-mode .canvas-toolbar .zoom-value,
body.text-mode .canvas-toolbar #fitBtn {
  display: none;
}
body.text-mode .canvas-toolbar #undoBtn,
body.text-mode .canvas-toolbar #redoBtn {
  display: grid;
}
body.text-mode .empty-state { display: none; }
body.text-mode #addPanel,
body.text-mode .selected-card {
  display: none;
}

html[data-theme="dark"] .mode-tabs {
  background: rgba(15,23,42,.88);
}
html[data-theme="dark"] .mode-tab.active {
  background: #e5e7eb;
  color: #111827;
}
html[data-theme="dark"] .mini-action {
  background: rgba(15,23,42,.88);
  border-color: var(--line);
  color: var(--text);
}
html[data-theme="dark"] .mini-action.primary {
  background: var(--primary-dark);
  color: #fff;
}
html[data-theme="dark"] .mini-action.danger {
  background: rgba(127,29,29,.25);
  border-color: rgba(248,113,113,.38);
  color: #fecaca;
}
html[data-theme="dark"] .node-title[contenteditable="true"]:focus,
html[data-theme="dark"] .node-body[contenteditable="true"]:focus {
  background: rgba(15,23,42,.78);
}

@media (max-width: 820px) {
  .file-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .text-board { padding: 26px 18px; }
  .text-board-editor { font-size: clamp(24px, 9vw, 42px); }
}
.drag-grip {
  position: absolute;
  left: 8px;
  top: 8px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  color: rgba(100,116,139,.65);
  font-size: 13px;
  line-height: 1;
  cursor: grab;
  user-select: none;
}
.node .node-header { padding-left: 12px; }
.node.dragging .drag-grip { cursor: grabbing; }

/* v1.3 refinements */
.compact-card { padding: 13px; }
.image-tools { display: grid; grid-template-columns: 1fr 82px; gap: 8px; }
.image-tools .file-label.full { width: 100%; }
.node-image {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: cover;
  border-radius: 14px;
  margin: 10px 0 4px;
  border: 1px solid rgba(148,163,184,.26);
  pointer-events: none;
}
.node-title,
.node-body { cursor: inherit; }
.node-title.editing,
.node-body.editing,
.node-title[contenteditable="true"],
.node-body[contenteditable="true"] {
  cursor: text;
  user-select: text;
  outline: none;
  border-radius: 8px;
  padding: 2px 3px;
  margin-left: -3px;
  background: rgba(255,255,255,.75);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.edge-path.temp-edge {
  stroke-dasharray: 9 7;
  stroke-width: 2.8;
  opacity: .9;
}
.text-board {
  padding: clamp(20px, 3vw, 46px);
}
.text-board-editor {
  width: min(1140px, 100%);
  font-size: 32px;
  line-height: 1.26;
  letter-spacing: -.035em;
  font-weight: 500;
}
.text-board-editor b,
.text-board-editor strong { font-weight: 850; }
.text-tools-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
body.text-focus-mode .topbar,
body.text-focus-mode .left-panel,
body.text-focus-mode .right-panel,
body.text-focus-mode .canvas-toolbar .icon-btn:not(#undoBtn):not(#redoBtn),
body.text-focus-mode .canvas-toolbar .zoom-value,
body.text-focus-mode .canvas-toolbar #fitBtn,
body.text-focus-mode .canvas-toolbar #copyPublicBtn,
body.text-focus-mode .canvas-toolbar .autosave {
  display: none !important;
}
body.text-focus-mode .canvas-toolbar #undoBtn,
body.text-focus-mode .canvas-toolbar #redoBtn {
  display: grid !important;
}
body.text-focus-mode .layout {
  height: 100vh;
  padding: 0;
  display: block;
}
body.text-focus-mode .workspace {
  height: 100vh;
  border-radius: 0;
  border: 0;
}
body.text-focus-mode .canvas-toolbar {
  top: 12px;
  right: 12px;
  left: auto;
}
body.text-focus-mode #textFocusBtn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}
body.text-focus-mode .text-board {
  padding: clamp(24px, 5vw, 78px);
}
.legal-links {
  padding: 4px 6px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}
.legal-links button,
.legal-links a {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  cursor: pointer;
}
.legal-links button:hover,
.legal-links a:hover { color: var(--primary); }
.legal-modal-card {
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
}
.legal-text {
  min-height: 0;
  margin-top: 10px;
  padding-right: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.legal-modal-card .modal-actions { flex: 0 0 auto; }
.legal-text p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin: 0 0 10px;
}
.legal-text .legal-updated {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}
.legal-text h3 {
  margin: 18px 0 8px;
  color: var(--text);
  font-size: 15px;
}
.legal-text ul {
  margin: 0 0 12px;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}
.legal-text li + li { margin-top: 7px; }
.legal-text a { color: var(--primary); }
.legal-text code {
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(148,163,184,.16);
  color: var(--text);
  font-size: 12px;
}
.local-board-item > button[data-open] span { line-height: 1.35; }

@media (max-width: 820px) {
  :root { --topbar-h: 60px; }
  .intro-card p,
  .mode-card .small-note,
  #addPanel .small-note,
  .file-card .panel-title-row { display: none; }
  .panel-card { padding: 12px; border-radius: 18px; }
  h1 { font-size: 18px; }
  .template-list { gap: 6px; }
  .template-btn { padding: 10px; }
  .canvas-toolbar {
    gap: 6px;
    max-width: calc(100vw - 20px);
  }
  .icon-btn,
  .zoom-value { height: 34px; min-width: 34px; }
  .zoom-value { min-width: 54px; }
  .node { min-width: 190px; }
  .node-handle { width: 18px; height: 18px; opacity: 1; }
  .text-board-editor { font-size: 28px; line-height: 1.3; }
}

@media (max-width: 540px) {
  .brand-title { font-size: 15px; }
  #saveBtn { display: none; }
  .topbar-actions { flex-shrink: 0; }
  .canvas-toolbar #zoomOutBtn,
  .canvas-toolbar #zoomInBtn,
  .canvas-toolbar .zoom-value { display: none; }
  .left-panel { width: min(300px, calc(100vw - 16px)); }
  .local-board-list { max-height: 150px; }
  .file-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .text-board { padding: 24px 16px; }
  .text-board-editor { font-size: 26px !important; }
  .node { padding: 12px; }
  .node-title { font-size: 14px; }
  .node-body { font-size: 12px; }
}
body.text-mode .canvas-toolbar #toggleLeftBtn { display: grid; }
body.text-focus-mode .canvas-toolbar #toggleLeftBtn { display: none !important; }

/* v1.4 fixes and UX polish */
.panel-close {
  display: none;
  position: sticky;
  top: 0;
  margin-left: auto;
  z-index: 3;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  color: var(--text);
  font-size: 20px;
  font-weight: 900;
  box-shadow: var(--shadow-soft);
}
.admin-popover {
  position: fixed;
  top: calc(var(--topbar-h) + 10px);
  right: 18px;
  left: auto;
  z-index: 120;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - var(--topbar-h) - 24px);
  overflow: auto;
  box-shadow: 0 22px 70px rgba(17,24,39,.22);
}
.admin-popover[hidden] { display: none !important; }
.local-board-main {
  min-width: 0;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.82);
  color: var(--text);
  padding: 10px;
  cursor: pointer;
}
.local-board-main:hover { border-color: rgba(37,99,235,.35); box-shadow: var(--shadow-soft); }
.local-board-item.active .local-board-main {
  border: 2px solid rgba(37,99,235,.95);
  background: linear-gradient(180deg, rgba(239,246,255,.98), rgba(255,255,255,.96));
  box-shadow: 0 0 0 5px rgba(37,99,235,.14), 0 14px 30px rgba(37,99,235,.12);
}
.local-board-item.active .board-title-line b { color: #1d4ed8; }

.board-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.board-title-line b {
  display: block;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.local-board-main span,
.local-board-main small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
  line-height: 1.35;
}
.board-type-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  min-height: 22px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.board-type-chip.type-schema { color: #1d4ed8; background: #dbeafe; }
.board-type-chip.type-text { color: #047857; background: #d1fae5; }
.all-boards-inline {
  border: 1px dashed rgba(37,99,235,.35);
  border-radius: 14px;
  min-height: 36px;
  background: rgba(255,255,255,.58);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}
.boards-modal-card {
  width: min(820px, 100%);
  max-height: min(82vh, 760px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-head-row p,
.modal-hint { color: var(--muted); font-size: 13px; line-height: 1.45; margin-top: 6px; }
.boards-modal-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  overflow: auto;
  padding: 2px 4px 2px 0;
}
.modal-board-item {
  padding: 2px;
}
.prompt-modal-card { width: min(440px, 100%); }
.prompt-modal-card .input { margin-top: 12px; }
.mode-tabs {
  padding: 5px;
  background: linear-gradient(135deg, rgba(37,99,235,.10), rgba(15,23,42,.05));
}
.mode-tab {
  min-height: 42px;
  font-size: 14px;
  border: 1px solid transparent;
}
.mode-tab.active {
  background: linear-gradient(135deg, #111827, #1d4ed8);
  color: #fff;
  border-color: rgba(255,255,255,.24);
}
.tool-btn.full { width: 100%; }
.node { cursor: default; }
.node-title,
.node-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.node-title[contenteditable="true"],
.node-body[contenteditable="true"] {
  background: transparent;
  box-shadow: none;
  cursor: text;
  user-select: text;
}
.node-title[contenteditable="true"]:focus,
.node-body[contenteditable="true"]:focus {
  background: rgba(255,255,255,.74);
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}
.drag-grip {
  left: 7px;
  top: 7px;
  width: 24px;
  height: 24px;
  border-radius: 10px;
  background: rgba(15,23,42,.08);
  color: rgba(15,23,42,.72);
  cursor: grab;
  z-index: 7;
}
.drag-grip:hover { background: rgba(37,99,235,.14); color: var(--primary-dark); }
.node.dragging .drag-grip { cursor: grabbing; }
.node .node-header { padding-left: 20px; }
html[data-theme="dark"] .local-board-main,
html[data-theme="dark"] .all-boards-inline {
  background: rgba(15,23,42,.72);
  border-color: var(--line);
  color: var(--text);
}
html[data-theme="dark"] .board-type-chip.type-schema { color: #bfdbfe; background: rgba(37,99,235,.28); }
html[data-theme="dark"] .board-type-chip.type-text { color: #bbf7d0; background: rgba(5,150,105,.24); }
html[data-theme="dark"] .drag-grip { background: rgba(255,255,255,.10); color: rgba(226,232,240,.80); }
html[data-theme="dark"] .node-title[contenteditable="true"]:focus,
html[data-theme="dark"] .node-body[contenteditable="true"]:focus {
  background: rgba(15,23,42,.80);
}
@media (max-width: 820px) {
  .panel-close { display: grid; place-items: center; }
  .admin-popover {
    left: 12px !important;
    right: 12px !important;
    top: calc(var(--topbar-h) + 10px) !important;
    width: auto !important;
  }
  .boards-modal-list { grid-template-columns: 1fr; }
  .boards-modal-card { max-height: 86vh; }
  .local-board-list { max-height: 220px; }
}
@media (max-width: 540px) {
  .admin-popover { top: calc(var(--topbar-h) + 8px); }
  .boards-modal-card, .prompt-modal-card { border-radius: 18px; }
  .board-type-chip { min-width: 48px; }
}

/* v1.5 UX fixes */
#toggleLeftBtn { display: none; }
.local-board-list { max-height: 300px; }
.board-type-chip.type-schema { color: #1d4ed8; background: #dbeafe; box-shadow: inset 0 0 0 1px rgba(37,99,235,.18); }
.board-type-chip.type-text { color: #065f46; background: #d1fae5; box-shadow: inset 0 0 0 1px rgba(5,150,105,.18); }
#templatePanel[hidden], #addPanel[hidden] { display: none !important; }
.text-image-label { grid-column: 1 / -1; }
.text-board-editor ul,
.text-board-editor ol { margin: .45em 0 .45em 1.2em; padding-left: .6em; }
.text-board-editor li { margin: .14em 0; }
.text-board-editor img {
  display: block;
  max-width: min(100%, 720px);
  max-height: 520px;
  object-fit: contain;
  border-radius: 18px;
  margin: 22px 0;
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 16px 44px rgba(0,0,0,.32);
}
.node { cursor: grab; }
.node.dragging { cursor: grabbing; }
.drag-grip {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 9px;
  background: rgba(15,23,42,.09);
  color: rgba(15,23,42,.72);
  cursor: grab;
  z-index: 9;
}
.drag-grip:hover { background: rgba(37,99,235,.16); color: var(--primary-dark); }
.node-title,
.node-body { cursor: inherit; }
.node-title[contenteditable="true"],
.node-body[contenteditable="true"] {
  cursor: text;
  user-select: text;
  background: rgba(255,255,255,.78);
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}
.node-branch-toggle {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 8;
  width: 24px;
  height: 24px;
  border-radius: 9px;
  border: 1px solid rgba(229,231,235,.9);
  background: rgba(255,255,255,.9);
  color: #111827;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 6px 16px rgba(17,24,39,.10);
}
.node-branch-toggle:hover { background: #fff; }
.resize-handle {
  position: absolute;
  z-index: 9;
  border: 0;
  background: transparent;
  padding: 0;
  opacity: 0;
}
.node:hover .resize-handle,
.node.selected .resize-handle { opacity: 1; }
.resize-e {
  right: -4px;
  top: 28px;
  bottom: 28px;
  width: 10px;
  cursor: ew-resize;
}
.resize-s {
  left: 36px;
  right: 36px;
  bottom: -4px;
  height: 10px;
  cursor: ns-resize;
}
.resize-se {
  right: -5px;
  bottom: -5px;
  width: 18px;
  height: 18px;
  border-radius: 7px;
  background: var(--primary);
  box-shadow: 0 3px 10px rgba(37,99,235,.30);
  cursor: nwse-resize;
}
.handle-right { right: -7px; top: 50%; }
html[data-theme="dark"] .node-branch-toggle { background: rgba(15,23,42,.92); color: var(--text); border-color: var(--line); }
html[data-theme="dark"] .drag-grip { background: rgba(255,255,255,.10); color: rgba(226,232,240,.82); }

@media (max-width: 820px) {
  #toggleLeftBtn { display: grid; }
  .left-panel {
    background: rgba(245,247,251,.97);
    border: 1px solid rgba(229,231,235,.95);
    border-radius: 22px;
    box-shadow: 0 22px 70px rgba(17,24,39,.22);
    padding: 8px;
    backdrop-filter: blur(18px);
  }
  html[data-theme="dark"] .left-panel {
    background: rgba(6,9,20,.96);
    border-color: var(--line);
  }
  .local-board-list { max-height: 260px; }
  .text-tools-grid { grid-template-columns: 1fr 1fr; }
}
body.text-mode .canvas-toolbar #toggleLeftBtn { display: none; }
@media (max-width: 820px) {
  body.text-mode .canvas-toolbar #toggleLeftBtn { display: grid; }
}
body.text-focus-mode .canvas-toolbar #toggleLeftBtn { display: none !important; }
/* v1.5 extended resize handles */
.resize-n { left: 36px; right: 36px; top: -4px; height: 10px; cursor: ns-resize; }
.resize-w { left: -4px; top: 28px; bottom: 28px; width: 10px; cursor: ew-resize; }
.resize-nw,
.resize-ne,
.resize-sw {
  width: 18px;
  height: 18px;
  border-radius: 7px;
  background: var(--primary);
  box-shadow: 0 3px 10px rgba(37,99,235,.30);
}
.resize-nw { left: -5px; top: -5px; cursor: nwse-resize; }
.resize-ne { right: -5px; top: -5px; cursor: nesw-resize; }
.resize-sw { left: -5px; bottom: -5px; cursor: nesw-resize; }

/* v1.6 UX and layout fixes */
#confirmModal { z-index: 110; }
#promptModal { z-index: 105; }
#boardsModal { z-index: 80; }
.save-panel { order: -10; }
.save-panel .btn { min-height: 46px; font-size: 14px; }
.save-panel .small-note { margin-top: 9px; }
body.left-collapsed .layout { grid-template-columns: 0 minmax(0, 1fr) var(--right-w); }
body.left-collapsed .left-panel { display: none; }
body.right-collapsed .layout { grid-template-columns: var(--left-w) minmax(0, 1fr) 0; }
body.right-collapsed .right-panel { display: none; }
body.left-collapsed.right-collapsed .layout { grid-template-columns: 0 minmax(0, 1fr) 0; }
.panel-toggle { font-size: 12px; min-width: 108px; }
#toggleLeftBtn { display: none !important; }
.node-handle {
  width: 16px;
  height: 16px;
  border-width: 3px;
  z-index: 14;
}
.node-handle::before {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 999px;
}
.handle-top { top: -8px; }
.handle-right { right: -8px; }
.handle-bottom { bottom: -8px; }
.handle-left { left: -8px; }
.node-branch-toggle { right: 22px; }
.resize-handle { z-index: 15; pointer-events: auto; opacity: .55; }
.node:hover .resize-handle, .node.selected .resize-handle { opacity: 1; }
.resize-n { top: -8px !important; height: 18px !important; left: 46px !important; right: 46px !important; }
.resize-s { bottom: -8px !important; height: 18px !important; left: 46px !important; right: 46px !important; }
.resize-e { right: -8px !important; width: 18px !important; top: 42px !important; bottom: 42px !important; }
.resize-w { left: -8px !important; width: 18px !important; top: 42px !important; bottom: 42px !important; }
.resize-se, .resize-nw, .resize-ne, .resize-sw {
  width: 24px !important;
  height: 24px !important;
  border-radius: 9px !important;
  box-shadow: 0 5px 14px rgba(37,99,235,.34) !important;
}
.resize-se { right: -9px !important; bottom: -9px !important; }
.resize-nw { left: -9px !important; top: -9px !important; }
.resize-ne { right: -9px !important; top: -9px !important; }
.resize-sw { left: -9px !important; bottom: -9px !important; }
.node-title, .node-body { cursor: text; }
.drag-grip { cursor: grab; }
.node.dragging .drag-grip { cursor: grabbing; }
.text-board-editor img { max-width: min(100%, 760px); }

@media (max-width: 1180px) {
  body.right-collapsed .right-panel { display: none !important; }
  .panel-toggle-right { display: inline-flex; align-items: center; justify-content: center; }
}
@media (max-width: 820px) {
  #toggleLeftBtn { display: grid !important; }
  .panel-toggle { display: none !important; }
  body.left-collapsed .left-panel { display: flex; }
  body.left-collapsed .layout,
  body.right-collapsed .layout,
  body.left-collapsed.right-collapsed .layout { display: block; }
  body.right-collapsed .right-panel { display: none !important; }
  .left-panel { background: rgba(245,247,251,.98) !important; }
}
@media (max-width: 540px) {
  .save-panel { display: none; }
}

/* v1.7 interface cleanup and interaction fixes */
.left-panel .mode-card .panel-title-row .pill,
.left-panel #addPanel .panel-title-row .pill,
.left-panel #localBoardsPanel .panel-title-row .pill,
.left-panel #templatePanel .panel-title-row .pill,
.left-panel .file-card .panel-title-row .pill { display: none; }
.mode-card, #addPanel, #localBoardsPanel { padding-bottom: 16px; }
.left-panel .small-note { margin-top: 8px; }
.panel-toggle { display: none !important; }
#textFocusBtn { display: inline-flex !important; align-items: center; justify-content: center; }
body.text-mode #textFocusBtn { display: inline-flex !important; }
body.text-mode .canvas-toolbar .icon-btn,
body.text-mode .canvas-toolbar .zoom-value,
body.text-mode .canvas-toolbar #fitBtn { display: none !important; }
.node-handle {
  z-index: 40 !important;
  cursor: crosshair !important;
  pointer-events: auto !important;
}
.node-handle::before {
  inset: -16px !important;
  cursor: crosshair !important;
}
.resize-handle { z-index: 12 !important; }
.resize-e { top: 56px !important; bottom: 56px !important; }
.resize-w { top: 56px !important; bottom: 56px !important; }
.resize-n { left: 56px !important; right: 56px !important; }
.resize-s { left: 56px !important; right: 56px !important; }
.resize-se, .resize-nw, .resize-ne, .resize-sw { z-index: 13 !important; }
body.resizing-node, body.resizing-node * { user-select: none !important; }
.node-title, .node-body { cursor: text !important; }
.node-title[contenteditable="true"], .node-body[contenteditable="true"] { cursor: text !important; }
body.text-focus-mode #textFocusBtn { display: inline-flex !important; }
body.text-focus-mode .canvas-toolbar {
  top: 14px;
  right: 14px;
  left: auto;
  width: auto;
}
body.text-focus-mode .canvas { border-radius: 0; }
@media (max-width: 820px) {
  #textFocusBtn { display: inline-flex !important; }
  body.text-mode #textFocusBtn { display: inline-flex !important; }
  .canvas-toolbar { gap: 7px; }
}

/* v1.8 cleanup, shapes and edge controls */
#templatePanel { display: none !important; }
.primary-add {
  min-height: 54px !important;
  border: 0 !important;
  background: linear-gradient(135deg, #2563eb, #111827) !important;
  color: #fff !important;
  font-size: 15px !important;
  font-weight: 900 !important;
  box-shadow: 0 16px 30px rgba(37,99,235,.25) !important;
}
.primary-add:hover { transform: translateY(-1px); box-shadow: 0 20px 38px rgba(37,99,235,.30) !important; }
.shape-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}
.shape-btn {
  min-height: 36px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.86);
  color: var(--text);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 850;
}
.shape-btn.active { border-color: rgba(37,99,235,.72); box-shadow: 0 0 0 3px rgba(37,99,235,.12); color: var(--primary-dark); }
.shape-preview-rect { border-radius: 8px; }
.shape-preview-round { border-radius: 14px; }
.shape-preview-circle { border-radius: 999px; }
.shape-preview-diamond { clip-path: polygon(50% 3%, 97% 50%, 50% 97%, 3% 50%); border-radius: 0; }
.node.shape-rect { border-radius: 12px; }
.node.shape-round { border-radius: 20px; }
.node.shape-circle { border-radius: 999px; padding: 22px; }
.node.shape-circle .node-header { padding-left: 10px; justify-content: center; text-align: center; }
.node.shape-circle .node-body { text-align: center; }
.node.shape-diamond {
  border-radius: 18px;
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  padding: 28px 34px;
}
.node.shape-diamond .drag-grip { left: 50%; top: 7px; transform: translateX(-50%); }
.node.shape-diamond .node-header { padding-left: 0; justify-content: center; text-align: center; }
.node.shape-diamond .node-body { text-align: center; }
.edge-layer { pointer-events: auto; }
.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 20px;
  pointer-events: stroke;
  cursor: pointer;
}
.edge-hit:hover + .edge-path,
.edge-path.selected {
  stroke: #2563eb;
  stroke-width: 3.6px;
}
.edge-path.selected { filter: drop-shadow(0 4px 8px rgba(37,99,235,.22)); }
#edgeSelectionForm .btn { min-height: 42px; }
.local-board-list { gap: 6px; max-height: 340px; }
.local-board-item {
  grid-template-columns: minmax(0, 1fr) 30px !important;
  gap: 6px;
}
.local-board-main {
  padding: 9px 10px !important;
  border-radius: 13px !important;
}
.board-title-line { gap: 6px; }
.board-title-line b { font-size: 12.5px; }
.local-board-main span.board-meta-line,
.local-board-main span.board-link-line {
  font-size: 10.5px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.local-board-share {
  display: flex !important;
  gap: 5px;
  margin-top: 7px !important;
}
.local-board-share[hidden] { display: none !important; }
.mini-action {
  flex: 1;
  min-height: 27px !important;
  padding: 4px 7px;
  border-radius: 10px !important;
  font-size: 10.5px !important;
}
.mini-action.primary { min-width: 100%; }
.mini-danger {
  min-height: auto;
  border-radius: 12px !important;
  font-size: 14px;
}
.boards-modal-list .local-board-item { padding: 0; }
.node-handle {
  width: 34px !important;
  height: 34px !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  display: grid;
  place-items: center;
  opacity: 0;
}
.node-handle::before { display: none !important; }
.node-handle::after {
  content: "";
  width: 15px;
  height: 15px;
  border-radius: 999px;
  border: 3px solid #fff;
  background: var(--primary);
  box-shadow: 0 4px 10px rgba(37,99,235,.32);
}
.node:hover .node-handle,
.node.selected .node-handle,
.node-handle.active,
body.connecting-edge .node-handle { opacity: 1 !important; }
.handle-top { left: 50% !important; top: -17px !important; transform: translateX(-50%) !important; }
.handle-right { right: -17px !important; top: 50% !important; transform: translateY(-50%) !important; }
.handle-bottom { left: 50% !important; bottom: -17px !important; transform: translateX(-50%) !important; }
.handle-left { left: -17px !important; top: 50% !important; transform: translateY(-50%) !important; }
.resize-handle {
  background: transparent !important;
  opacity: 0 !important;
  z-index: 10 !important;
}
.node:hover .resize-handle,
.node.selected .resize-handle { opacity: .8 !important; }
.resize-e { right: 0 !important; top: 66px !important; bottom: 66px !important; width: 12px !important; }
.resize-w { left: 0 !important; top: 66px !important; bottom: 66px !important; width: 12px !important; }
.resize-n { top: 0 !important; left: 66px !important; right: 66px !important; height: 12px !important; }
.resize-s { bottom: 0 !important; left: 66px !important; right: 66px !important; height: 12px !important; }
.resize-se, .resize-nw, .resize-ne, .resize-sw {
  width: 24px !important;
  height: 24px !important;
  border-radius: 8px !important;
  background: rgba(37,99,235,.9) !important;
  z-index: 11 !important;
}
.resize-se { right: 3px !important; bottom: 3px !important; }
.resize-nw { left: 3px !important; top: 3px !important; }
.resize-ne { right: 3px !important; top: 3px !important; }
.resize-sw { left: 3px !important; bottom: 3px !important; }
.node-title, .node-body { cursor: text !important; }
.drag-grip { cursor: grab !important; }
html[data-theme="dark"] .shape-btn { background: rgba(15,23,42,.88); border-color: var(--line); color: var(--text); }
html[data-theme="dark"] .shape-btn.active { color: #bfdbfe; border-color: rgba(96,165,250,.72); }
html[data-theme="dark"] .edge-hit:hover + .edge-path,
html[data-theme="dark"] .edge-path.selected { stroke: #60a5fa; }
@media (max-width: 820px) {
  .primary-add { min-height: 48px !important; }
  .node-handle { width: 40px !important; height: 40px !important; opacity: 1 !important; }
  .handle-top { top: -20px !important; }
  .handle-right { right: -20px !important; }
  .handle-bottom { bottom: -20px !important; }
  .handle-left { left: -20px !important; }
}


/* v1.9 refinements */
.node-layer { pointer-events: none; }
.node { pointer-events: auto; }
.edge-layer { pointer-events: auto !important; }
.edge-path { pointer-events: none; }
.edge-hit { pointer-events: stroke; stroke-width: 28px; cursor: pointer; }
.edge-path.selected { stroke: #2563eb !important; stroke-width: 4px !important; }

.primary-add {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.primary-add::after {
  content: "";
  position: absolute;
  top: -40%;
  bottom: -40%;
  left: -45%;
  width: 34%;
  transform: skewX(-22deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
  opacity: 0;
  pointer-events: none;
}
.primary-add:hover::after { animation: tb-shine .9s ease; opacity: 1; }
@keyframes tb-shine { from { left: -45%; } to { left: 120%; } }

.shape-row { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
.shape-preview-diamond {
  clip-path: none !important;
  border: 1px solid var(--line) !important;
  border-radius: 12px !important;
  position: relative;
}
.shape-preview-diamond::before {
  content: "◇";
  margin-right: 3px;
  font-size: 13px;
}
.shape-preview-circle::before {
  content: "○";
  margin-right: 3px;
  font-size: 13px;
}
.shape-preview-round::before {
  content: "▭";
  margin-right: 3px;
  font-size: 13px;
}

.node.shape-circle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
}
.node.shape-circle .node-header,
.node.shape-circle .node-body {
  max-width: 76%;
}
.node.shape-diamond {
  clip-path: none !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  overflow: visible !important;
  padding: 26px 36px !important;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.node.shape-diamond::before {
  content: "";
  position: absolute;
  inset: 9%;
  z-index: -1;
  transform: rotate(45deg);
  border-radius: 18px;
  background: var(--diamond-bg, #fff);
  border: 1px solid var(--diamond-border, rgba(229,231,235,.95));
  box-shadow: 0 12px 34px rgba(17,24,39,.10);
}
.node.shape-diamond.selected::before {
  border-color: rgba(37,99,235,.8);
  box-shadow: 0 0 0 4px rgba(37,99,235,.12), 0 18px 42px rgba(17,24,39,.16);
}
.node-blue { --diamond-bg: linear-gradient(180deg, #eff6ff, #fff); --diamond-border: #bfdbfe; }
.node-green { --diamond-bg: linear-gradient(180deg, #ecfdf5, #fff); --diamond-border: #a7f3d0; }
.node-amber { --diamond-bg: linear-gradient(180deg, #fffbeb, #fff); --diamond-border: #fde68a; }
.node-rose { --diamond-bg: linear-gradient(180deg, #fff1f2, #fff); --diamond-border: #fecdd3; }
.node-purple { --diamond-bg: linear-gradient(180deg, #f5f3ff, #fff); --diamond-border: #ddd6fe; }
.node-gray { --diamond-bg: linear-gradient(180deg, #f8fafc, #fff); --diamond-border: #cbd5e1; }
.node.shape-diamond .node-header,
.node.shape-diamond .node-body {
  width: min(72%, 360px);
  max-width: 72%;
}
.node.shape-diamond .drag-grip { left: 50% !important; top: 18px !important; transform: translateX(-50%) !important; }
.node.shape-diamond .handle-top { top: -1px !important; }
.node.shape-diamond .handle-right { right: -1px !important; }
.node.shape-diamond .handle-bottom { bottom: -1px !important; }
.node.shape-diamond .handle-left { left: -1px !important; }

.local-board-item { grid-template-columns: minmax(0, 1fr) !important; }
.local-board-main { position: relative; }
.board-title-line .mini-danger.inline {
  width: 25px;
  height: 25px;
  min-height: 25px;
  border-radius: 9px !important;
  padding: 0;
  flex: 0 0 25px;
  font-size: 14px;
}
.local-board-share { display: flex !important; gap: 5px; margin-top: 6px !important; }
.local-board-share .mini-action { min-height: 25px !important; font-size: 10px !important; padding: 3px 6px; }
.local-board-share .mini-action.primary { min-width: 0 !important; flex: 1; }
.local-board-main span.board-meta-line,
.local-board-main span.board-link-line { font-size: 10px !important; }

html[data-theme="dark"] .node.shape-diamond::before { box-shadow: 0 12px 34px rgba(0,0,0,.26); }

/* v1.10 refinements */
.node-title { font-size: 15px !important; line-height: 1.18 !important; }
.node-body { font-size: 14px !important; line-height: 1.42 !important; }
.node.text .node-title { font-size: 15px !important; }
.node.text .node-body { font-size: 14px !important; }

/* Не конфликтуем: левый верхний угол отдан под перенос блока, resize — через остальные грани/углы. */
.resize-nw { display: none !important; }
.drag-grip {
  left: 10px !important;
  top: 10px !important;
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  min-height: 20px !important;
  z-index: 26 !important;
  border-radius: 8px !important;
  opacity: .92 !important;
}
.node-header { padding-left: 28px !important; }
.node.shape-circle .node-header,
.node.shape-diamond .node-header { padding-left: 0 !important; }
.node.shape-diamond .drag-grip { left: 50% !important; top: 12px !important; width: 20px !important; height: 20px !important; }

.edge-hit {
  pointer-events: stroke !important;
  stroke: rgba(37,99,235,.001) !important;
  stroke-width: 34px !important;
  fill: none !important;
  cursor: pointer !important;
}
.edge-hit:hover + .edge-path,
.edge-path.selected { stroke: #2563eb !important; stroke-width: 4px !important; }

.shape-btn {
  border: 1px solid var(--line) !important;
  background: #fff !important;
  white-space: nowrap !important;
}
.shape-btn.active { border-color: rgba(37,99,235,.85) !important; }
.shape-preview-diamond::before { content: "◇" !important; }
.node.shape-circle,
.node.shape-diamond { overflow: visible !important; }
.node.shape-circle .node-title,
.node.shape-circle .node-body,
.node.shape-diamond .node-title,
.node.shape-diamond .node-body {
  max-width: 76% !important;
  margin-left: auto !important;
  margin-right: auto !important;
  text-align: center !important;
}

/* v1.11 refinements */
.empty-state {
  pointer-events: auto !important;
}
.empty-state h2 {
  font-size: 21px !important;
}
.empty-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}
.empty-actions .btn {
  min-height: 42px;
  justify-content: center;
}
.empty-actions .btn-primary {
  background: linear-gradient(135deg, #2563eb, #111827) !important;
  color: #fff !important;
  box-shadow: 0 14px 34px rgba(37,99,235,.22);
}
.node-title { font-size: 17px !important; line-height: 1.20 !important; }
.node-body { font-size: 16px !important; line-height: 1.44 !important; }
.node.text .node-title { font-size: 17px !important; }
.node.text .node-body { font-size: 16px !important; }
.node.shape-circle .node-title,
.node.shape-circle .node-body,
.node.shape-diamond .node-title,
.node.shape-diamond .node-body {
  max-width: 80% !important;
}
.node.shape-manual .node-title,
.node.shape-manual .node-body {
  max-width: none !important;
}
@media (max-width: 820px) {
  .empty-actions { grid-template-columns: 1fr; }
  .node-title { font-size: 15px !important; }
  .node-body { font-size: 14px !important; }
}

/* v1.12 SEO and storage notes */
.seo-intro {
  margin-top: 8px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}
.storage-note {
  flex-basis: 100%;
  margin: 6px 0 0;
  padding-top: 8px;
  border-top: 1px solid rgba(148,163,184,.22);
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}
.file-note {
  margin-top: 8px;
  font-size: 11.5px;
  line-height: 1.4;
}
.node-title { font-size: 16px !important; }
.node-body { font-size: 15px !important; line-height: 1.42 !important; }
.node.text .node-title { font-size: 16px !important; }
.node.text .node-body { font-size: 15px !important; }
.node.group .node-title { font-size: 15px !important; }
@media (max-width: 820px) {
  .seo-intro,
  .storage-note,
  .file-note { display: none; }
  .node-title { font-size: 15px !important; }
  .node-body { font-size: 13.5px !important; }
}

.legal-divider {
  width: 100%;
  height: 1px;
  background: var(--line);
  margin: 10px 0 8px;
}


/* v1.22: кнопка сворачивания не перекрывает текст блока */
.node-title,
.node-body {
  padding-right: 38px;
}
.node-branch-toggle {
  right: 6px;
}

/* v1.22: история изменений */
.icon-btn.undo-redo {
  font-size: 18px;
  font-weight: 900;
}
.icon-btn:disabled,
.btn:disabled {
  opacity: .42;
  cursor: not-allowed;
  box-shadow: none;
}


body.text-focus-mode .canvas-toolbar {
  width: auto;
  gap: 8px;
}
body.text-focus-mode .canvas-toolbar #textFocusBtn {
  order: 10;
}
body.text-focus-mode .canvas-toolbar #undoBtn {
  order: 8;
}
body.text-focus-mode .canvas-toolbar #redoBtn {
  order: 9;
}
body.text-mode .canvas-toolbar #textFocusBtn,
body.text-focus-mode #textFocusBtn {
  display: inline-flex !important;
}


/* v1.24: undo/redo должны быть видны в текстовом режиме и полном окне */
body.text-mode .canvas-toolbar #undoBtn,
body.text-mode .canvas-toolbar #redoBtn,
body.text-focus-mode .canvas-toolbar #undoBtn,
body.text-focus-mode .canvas-toolbar #redoBtn {
  display: grid !important;
  background: rgba(17,24,39,.92) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,.14) !important;
  box-shadow: 0 10px 28px rgba(0,0,0,.22) !important;
}

body.text-mode .canvas-toolbar #undoBtn:not(:disabled):hover,
body.text-mode .canvas-toolbar #redoBtn:not(:disabled):hover,
body.text-focus-mode .canvas-toolbar #undoBtn:not(:disabled):hover,
body.text-focus-mode .canvas-toolbar #redoBtn:not(:disabled):hover {
  background: rgba(55,65,81,.96) !important;
}

body.text-mode .canvas-toolbar #undoBtn:disabled,
body.text-mode .canvas-toolbar #redoBtn:disabled,
body.text-focus-mode .canvas-toolbar #undoBtn:disabled,
body.text-focus-mode .canvas-toolbar #redoBtn:disabled {
  background: rgba(17,24,39,.55) !important;
  color: rgba(255,255,255,.45) !important;
  opacity: 1 !important;
}

body.text-mode .canvas-toolbar #textFocusBtn,
body.text-focus-mode .canvas-toolbar #textFocusBtn {
  background: rgba(17,24,39,.92) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,.14) !important;
}

body.text-focus-mode .canvas-toolbar {
  display: flex !important;
  justify-content: flex-end;
}


/* v1.25: панель управления и статус сохранения */
.workspace > .autosave {
  position: absolute;
  z-index: 14;
  right: 14px;
  bottom: 14px;
  margin-left: 0;
  height: 34px;
  padding: 0 11px;
  border-radius: 13px;
  background: rgba(255,255,255,.58);
  color: rgba(71,85,105,.68);
  border: 1px solid rgba(148,163,184,.24);
  box-shadow: 0 8px 22px rgba(15,23,42,.08);
  font-size: 12px;
  backdrop-filter: blur(10px);
}

.canvas-toolbar #undoBtn {
  margin-left: auto;
}
.canvas-toolbar #undoBtn,
.canvas-toolbar #redoBtn,
.canvas-toolbar #textFocusBtn {
  order: 20;
}

body.text-mode .canvas-toolbar #undoBtn,
body.text-mode .canvas-toolbar #redoBtn,
body.text-focus-mode .canvas-toolbar #undoBtn,
body.text-focus-mode .canvas-toolbar #redoBtn,
body.text-mode .canvas-toolbar #textFocusBtn,
body.text-focus-mode .canvas-toolbar #textFocusBtn {
  background: rgba(17,24,39,.88) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,.13) !important;
  box-shadow: 0 10px 28px rgba(0,0,0,.20) !important;
}

body.text-mode .canvas-toolbar #undoBtn:not(:disabled):hover,
body.text-mode .canvas-toolbar #redoBtn:not(:disabled):hover,
body.text-focus-mode .canvas-toolbar #undoBtn:not(:disabled):hover,
body.text-focus-mode .canvas-toolbar #redoBtn:not(:disabled):hover,
body.text-mode .canvas-toolbar #textFocusBtn:hover,
body.text-focus-mode .canvas-toolbar #textFocusBtn:hover {
  background: rgba(55,65,81,.96) !important;
}

body.text-mode .canvas-toolbar #undoBtn:disabled,
body.text-mode .canvas-toolbar #redoBtn:disabled,
body.text-focus-mode .canvas-toolbar #undoBtn:disabled,
body.text-focus-mode .canvas-toolbar #redoBtn:disabled {
  background: rgba(17,24,39,.42) !important;
  color: rgba(255,255,255,.34) !important;
  opacity: 1 !important;
}

body.text-mode .workspace > .autosave,
body.text-focus-mode .workspace > .autosave {
  background: rgba(2,6,23,.18);
  color: rgba(148,163,184,.58);
  border-color: rgba(255,255,255,.08);
  box-shadow: none;
}

html[data-theme="dark"] .workspace > .autosave {
  background: rgba(15,23,42,.42);
  color: rgba(148,163,184,.72);
  border-color: rgba(148,163,184,.18);
}

body.text-focus-mode .canvas-toolbar {
  top: 12px;
  right: 12px;
  left: auto;
  width: auto;
  gap: 8px;
  justify-content: flex-end;
}

.text-board-editor a {
  color: #93c5fd;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
}
.text-board-editor a:visited {
  color: #c4b5fd;
}


/* v1.26: порядок верхних кнопок и публичный текст */
.canvas-toolbar #copyPublicBtn {
  order: 20;
}
.canvas-toolbar #undoBtn {
  order: 21;
  margin-left: auto;
}
.canvas-toolbar #redoBtn {
  order: 22;
}
.canvas-toolbar #textFocusBtn {
  order: 23;
}
.canvas-toolbar #copyPublicBtn:not([hidden]) {
  margin-left: auto;
}
.canvas-toolbar #copyPublicBtn:not([hidden]) ~ #undoBtn {
  margin-left: 0;
}

body.text-mode .canvas-toolbar #copyPublicBtn,
body.text-focus-mode .canvas-toolbar #copyPublicBtn,
body.readonly.text-mode .canvas-toolbar #copyPublicBtn,
body.readonly.text-focus-mode .canvas-toolbar #copyPublicBtn {
  display: inline-flex !important;
}

body.text-mode .canvas-toolbar #copyPublicBtn,
body.text-focus-mode .canvas-toolbar #copyPublicBtn,
body.text-mode .canvas-toolbar #undoBtn,
body.text-mode .canvas-toolbar #redoBtn,
body.text-focus-mode .canvas-toolbar #undoBtn,
body.text-focus-mode .canvas-toolbar #redoBtn,
body.text-mode .canvas-toolbar #textFocusBtn,
body.text-focus-mode .canvas-toolbar #textFocusBtn {
  background: rgba(17,24,39,.88) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,.13) !important;
  box-shadow: 0 10px 28px rgba(0,0,0,.20) !important;
}

body.text-mode .canvas-toolbar #copyPublicBtn:hover,
body.text-focus-mode .canvas-toolbar #copyPublicBtn:hover,
body.text-mode .canvas-toolbar #undoBtn:not(:disabled):hover,
body.text-mode .canvas-toolbar #redoBtn:not(:disabled):hover,
body.text-focus-mode .canvas-toolbar #undoBtn:not(:disabled):hover,
body.text-focus-mode .canvas-toolbar #redoBtn:not(:disabled):hover,
body.text-mode .canvas-toolbar #textFocusBtn:hover,
body.text-focus-mode .canvas-toolbar #textFocusBtn:hover {
  background: rgba(55,65,81,.96) !important;
}

body.readonly .text-settings-card .btn,
body.readonly .text-settings-card .file-label {
  opacity: .44;
  cursor: not-allowed;
  pointer-events: none;
}

body.readonly .text-settings-card {
  filter: grayscale(.08);
}

.text-board-editor a {
  color: #93c5fd !important;
  text-decoration: underline !important;
  text-decoration-thickness: 1.6px;
  text-underline-offset: 4px;
  cursor: pointer;
  pointer-events: auto;
}
.text-board-editor a:hover {
  color: #bfdbfe !important;
}


/* v1.27: «Скопировать себе» видно только публичному посетителю, порядок в полном окне сохраняется */
body.text-mode .canvas-toolbar #copyPublicBtn[hidden],
body.text-focus-mode .canvas-toolbar #copyPublicBtn[hidden],
body.readonly.text-mode .canvas-toolbar #copyPublicBtn[hidden],
body.readonly.text-focus-mode .canvas-toolbar #copyPublicBtn[hidden] {
  display: none !important;
}

body.text-mode .canvas-toolbar #copyPublicBtn:not([hidden]),
body.text-focus-mode .canvas-toolbar #copyPublicBtn:not([hidden]),
body.readonly.text-mode .canvas-toolbar #copyPublicBtn:not([hidden]),
body.readonly.text-focus-mode .canvas-toolbar #copyPublicBtn:not([hidden]) {
  display: inline-flex !important;
}

.canvas-toolbar #copyPublicBtn {
  order: 20 !important;
}
.canvas-toolbar #undoBtn {
  order: 21 !important;
}
.canvas-toolbar #redoBtn {
  order: 22 !important;
}
.canvas-toolbar #textFocusBtn {
  order: 23 !important;
}

body.text-focus-mode .canvas-toolbar #copyPublicBtn:not([hidden]) {
  margin-left: 0;
}

body.text-focus-mode .canvas-toolbar {
  display: flex !important;
  justify-content: flex-end !important;
  gap: 8px !important;
}

/* v1.27: ссылки в публичном текстовом режиме явно видны */
.text-board-editor a,
body.readonly .text-board-editor a {
  color: #93c5fd !important;
  text-decoration: underline !important;
  text-decoration-thickness: 1.6px !important;
  text-underline-offset: 4px !important;
  cursor: pointer !important;
  pointer-events: auto !important;
}
.text-board-editor a:hover,
body.readonly .text-board-editor a:hover {
  color: #bfdbfe !important;
}


/* v1.29: верхняя кнопка добавления блока и статус в полном окне */
.canvas-toolbar #toolbarAddBlockBtn {
  order: 20 !important;
  margin-left: auto;
}
.canvas-toolbar #toolbarAddBlockBtn + #textFocusBtn,
.canvas-toolbar #toolbarAddBlockBtn ~ #undoBtn {
  margin-left: 0;
}
body.text-mode .canvas-toolbar #toolbarAddBlockBtn,
body.readonly .canvas-toolbar #toolbarAddBlockBtn {
  display: none !important;
}
body.text-focus-mode .canvas-toolbar #toolbarAddBlockBtn {
  display: inline-flex !important;
}
body.text-focus-mode.text-mode .canvas-toolbar #toolbarAddBlockBtn,
body.readonly.text-focus-mode .canvas-toolbar #toolbarAddBlockBtn {
  display: none !important;
}
.canvas-toolbar #toolbarAddBlockBtn {
  background: rgba(17,24,39,.92) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,.13) !important;
}
.canvas-toolbar #toolbarAddBlockBtn:hover {
  background: rgba(55,65,81,.96) !important;
}

/* Порядок в правой верхней группе: добавить блок -> назад -> вперёд -> полный/обычный вид */
.canvas-toolbar #toolbarAddBlockBtn {
  order: 20 !important;
}
.canvas-toolbar #copyPublicBtn {
  order: 20 !important;
}
.canvas-toolbar #undoBtn {
  order: 21 !important;
  margin-left: 0 !important;
}
.canvas-toolbar #redoBtn {
  order: 22 !important;
}
.canvas-toolbar #textFocusBtn {
  order: 23 !important;
}
.canvas-toolbar #fitBtn + #toolbarAddBlockBtn {
  margin-left: auto;
}

/* В полном окне статус должен читаться, но не перетягивать внимание */
body.text-focus-mode .workspace > .autosave {
  display: grid !important;
  right: 14px !important;
  bottom: 14px !important;
  background: rgba(255,255,255,.74) !important;
  color: rgba(71,85,105,.72) !important;
  border-color: rgba(148,163,184,.24) !important;
  box-shadow: 0 8px 22px rgba(15,23,42,.08) !important;
}
body.text-focus-mode.text-mode .workspace > .autosave {
  background: rgba(255,255,255,.72) !important;
  color: rgba(71,85,105,.70) !important;
}
html[data-theme="dark"] body.text-focus-mode .workspace > .autosave {
  background: rgba(15,23,42,.58) !important;
  color: rgba(203,213,225,.70) !important;
  border-color: rgba(148,163,184,.20) !important;
}


/* v1.30: финальная доводка панели управления и тёмной темы */

/* Режим «Текст»: верхние кнопки справа в обычном виде */
body.text-mode:not(.text-focus-mode) .canvas-toolbar {
  left: auto !important;
  right: 14px !important;
  width: auto !important;
  justify-content: flex-end !important;
  gap: 8px !important;
}
body.text-mode:not(.text-focus-mode) .canvas-toolbar #undoBtn {
  margin-left: 0 !important;
}

/* Светлая тема, режим «Схема»: «Полное окно» и стрелки светлые, «Добавить блок» акцентный */
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #undoBtn,
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #redoBtn,
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #textFocusBtn {
  background: rgba(255,255,255,.92) !important;
  color: #111827 !important;
  border-color: rgba(226,232,240,.98) !important;
  box-shadow: 0 10px 28px rgba(15,23,42,.10) !important;
}
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #undoBtn:not(:disabled):hover,
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #redoBtn:not(:disabled):hover,
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #textFocusBtn:hover {
  background: #fff !important;
}
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #undoBtn:disabled,
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #redoBtn:disabled {
  background: rgba(255,255,255,.58) !important;
  color: rgba(15,23,42,.30) !important;
  opacity: 1 !important;
}
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #toolbarAddBlockBtn {
  background: linear-gradient(135deg, #3b5bdb 0%, #1e3a8a 45%, #111827 100%) !important;
  color: #fff !important;
  border-color: rgba(30,58,138,.36) !important;
  box-shadow: 0 12px 30px rgba(30,64,175,.24) !important;
}
html:not([data-theme="dark"]) body:not(.text-mode) .canvas-toolbar #toolbarAddBlockBtn:hover {
  background: linear-gradient(135deg, #4f6df0 0%, #2447a8 45%, #111827 100%) !important;
}

/* Тёмная тема: выбранная доска должна быть читаемой */
html[data-theme="dark"] .local-board-item.active {
  background: linear-gradient(180deg, rgba(37,99,235,.26), rgba(30,64,175,.16)) !important;
  border-color: rgba(96,165,250,.82) !important;
  box-shadow: 0 0 0 1px rgba(96,165,250,.28), 0 14px 32px rgba(2,6,23,.34) !important;
}
html[data-theme="dark"] .local-board-item.active .board-title-line b {
  color: #dbeafe !important;
}
html[data-theme="dark"] .local-board-item.active .board-meta-line,
html[data-theme="dark"] .local-board-item.active .board-link-line {
  color: rgba(219,234,254,.72) !important;
}
html[data-theme="dark"] .local-board-item.active .board-type-chip {
  background: rgba(147,197,253,.20) !important;
  color: #bfdbfe !important;
  border: 1px solid rgba(147,197,253,.28) !important;
}
html[data-theme="dark"] .local-board-item.active .mini-danger.inline {
  background: rgba(127,29,29,.62) !important;
  color: #fecaca !important;
  border: 1px solid rgba(248,113,113,.35) !important;
}

/* Статус сохранения в полном окне текста — как в обычном текстовом режиме: тихий и не отвлекает */
body.text-focus-mode.text-mode .workspace > .autosave {
  background: rgba(2,6,23,.18) !important;
  color: rgba(148,163,184,.58) !important;
  border-color: rgba(255,255,255,.08) !important;
  box-shadow: none !important;
}
html[data-theme="dark"] body.text-focus-mode.text-mode .workspace > .autosave {
  background: rgba(15,23,42,.42) !important;
  color: rgba(148,163,184,.62) !important;
  border-color: rgba(148,163,184,.16) !important;
  box-shadow: none !important;
}


/* v1.31: финальное выделение активной доски в тёмной теме */
html[data-theme="dark"] .local-board-item.active .local-board-main {
  background: linear-gradient(180deg, rgba(59,130,246,.34), rgba(30,64,175,.24)) !important;
  border: 2px solid rgba(147,197,253,.92) !important;
  color: #eff6ff !important;
  box-shadow:
    0 0 0 4px rgba(96,165,250,.18),
    inset 0 1px 0 rgba(255,255,255,.08),
    0 16px 36px rgba(2,6,23,.42) !important;
}

html[data-theme="dark"] .local-board-item.active .local-board-main:hover {
  background: linear-gradient(180deg, rgba(59,130,246,.40), rgba(30,64,175,.28)) !important;
  border-color: rgba(191,219,254,.96) !important;
}

html[data-theme="dark"] .local-board-item.active .board-title-line b {
  color: #ffffff !important;
}

html[data-theme="dark"] .local-board-item.active .local-board-main span,
html[data-theme="dark"] .local-board-item.active .local-board-main small,
html[data-theme="dark"] .local-board-item.active .board-meta-line,
html[data-theme="dark"] .local-board-item.active .board-link-line {
  color: rgba(219,234,254,.82) !important;
}

html[data-theme="dark"] .local-board-item.active .board-type-chip.type-schema {
  background: rgba(191,219,254,.18) !important;
  color: #dbeafe !important;
  border: 1px solid rgba(191,219,254,.34) !important;
}

html[data-theme="dark"] .local-board-item.active .board-type-chip.type-text {
  background: rgba(134,239,172,.16) !important;
  color: #bbf7d0 !important;
  border: 1px solid rgba(134,239,172,.30) !important;
}

html[data-theme="dark"] .local-board-item.active .mini-danger,
html[data-theme="dark"] .local-board-item.active .mini-danger.inline {
  background: rgba(127,29,29,.88) !important;
  color: #fecaca !important;
  border: 1px solid rgba(248,113,113,.42) !important;
  opacity: 1 !important;
}



/* Для ромба делаем текстовый блок уже, чтобы он визуально оставался в центре фигуры */
.node.shape-diamond .node-title,
.node.shape-diamond .node-body {
  max-width: 78% !important;
}

/* В режиме редактирования центр не должен «прыгать» */
.node.shape-circle .node-title[contenteditable="true"],
.node.shape-circle .node-body[contenteditable="true"],
.node.shape-diamond .node-title[contenteditable="true"],
.node.shape-diamond .node-body[contenteditable="true"] {
  margin-left: 0 !important;
  text-align: center !important;
  padding-left: 38px !important;
  padding-right: 38px !important;
}

/* Скруглённая форма при ручном выборе тоже получает более спокойное центрирование */
.node.shape-round:not(.shape-manual) .node-title,
.node.shape-round:not(.shape-manual) .node-body {
  text-align: center;
}
.node.shape-round:not(.shape-manual) .node-header {
  justify-content: center;
  text-align: center;
}


/* v1.33: аккуратное центрирование текста в фигурах без смещения в режиме редактирования */

/* Фигуры сами выравнивают содержимое по центру */
.node.shape-circle,
.node.shape-diamond {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
}

/* Убираем старый сдвиг, который был нужен для обычных прямоугольников */
.node.shape-circle .node-header,
.node.shape-diamond .node-header,
.node.shape-round:not(.shape-manual) .node-header {
  width: 100% !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  justify-content: center !important;
  align-items: center !important;
  text-align: center !important;
}

/* Текстовые элементы центрируются как отдельный компактный блок */
.node.shape-circle .node-title,
.node.shape-circle .node-body,
.node.shape-diamond .node-title,
.node.shape-diamond .node-body,
.node.shape-round:not(.shape-manual) .node-title,
.node.shape-round:not(.shape-manual) .node-body {
  box-sizing: border-box !important;
  display: block !important;
  margin-left: auto !important;
  margin-right: auto !important;
  text-align: center !important;
  padding-left: 6px !important;
  padding-right: 6px !important;
}

/* Круг: текст шире, но остаётся по центру */
.node.shape-circle .node-title,
.node.shape-circle .node-body {
  width: min(72%, calc(100% - 72px)) !important;
  max-width: min(72%, calc(100% - 72px)) !important;
}

/* Ромб: текст чуть уже, чтобы не залезал в острые края */
.node.shape-diamond .node-title,
.node.shape-diamond .node-body {
  width: min(58%, calc(100% - 96px)) !important;
  max-width: min(58%, calc(100% - 96px)) !important;
}

/* Скруглённая форма: центрируем текст без искусственного левого отступа */
.node.shape-round:not(.shape-manual) .node-title,
.node.shape-round:not(.shape-manual) .node-body {
  width: min(78%, calc(100% - 72px)) !important;
  max-width: min(78%, calc(100% - 72px)) !important;
}

/* В режиме редактирования размер и позиция блока не меняются */
.node.shape-circle .node-title[contenteditable="true"],
.node.shape-circle .node-body[contenteditable="true"],
.node.shape-diamond .node-title[contenteditable="true"],
.node.shape-diamond .node-body[contenteditable="true"],
.node.shape-round:not(.shape-manual) .node-title[contenteditable="true"],
.node.shape-round:not(.shape-manual) .node-body[contenteditable="true"] {
  margin-left: auto !important;
  margin-right: auto !important;
  text-align: center !important;
  padding-left: 6px !important;
  padding-right: 6px !important;
}

/* Фокус редактирования остаётся по центру и не растягивается на всю фигуру */
.node.shape-circle .node-title[contenteditable="true"]:focus,
.node.shape-circle .node-body[contenteditable="true"]:focus,
.node.shape-diamond .node-title[contenteditable="true"]:focus,
.node.shape-diamond .node-body[contenteditable="true"]:focus,
.node.shape-round:not(.shape-manual) .node-title[contenteditable="true"]:focus,
.node.shape-round:not(.shape-manual) .node-body[contenteditable="true"]:focus {
  background: rgba(255,255,255,.62);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}


/* v1.34: расширение текстовой зоны в круге и ромбе */
.node.shape-circle .node-title,
.node.shape-circle .node-body {
  width: min(84%, calc(100% - 44px)) !important;
  max-width: min(84%, calc(100% - 44px)) !important;
}

.node.shape-diamond .node-title,
.node.shape-diamond .node-body {
  width: min(70%, calc(100% - 58px)) !important;
  max-width: min(70%, calc(100% - 58px)) !important;
}

.node.shape-diamond .node-title[contenteditable="true"],
.node.shape-diamond .node-body[contenteditable="true"] {
  width: min(70%, calc(100% - 58px)) !important;
  max-width: min(70%, calc(100% - 58px)) !important;
}

.node.shape-circle .node-title[contenteditable="true"],
.node.shape-circle .node-body[contenteditable="true"] {
  width: min(84%, calc(100% - 44px)) !important;
  max-width: min(84%, calc(100% - 44px)) !important;
}

/* Для небольших ромбов оставляем безопасные края, но поле всё равно шире прежнего */
.node.shape-diamond[style*="width: 2"] .node-title,
.node.shape-diamond[style*="width: 2"] .node-body {
  width: min(66%, calc(100% - 52px)) !important;
  max-width: min(66%, calc(100% - 52px)) !important;
}


/* v1.35: скруглённая карточка снова с левым выравниванием текста */
.node.shape-round:not(.shape-manual) {
  text-align: left !important;
}

.node.shape-round:not(.shape-manual) .node-header {
  width: auto !important;
  justify-content: flex-start !important;
  align-items: center !important;
  text-align: left !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.node.shape-round:not(.shape-manual) .node-title,
.node.shape-round:not(.shape-manual) .node-body {
  width: auto !important;
  max-width: none !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  text-align: left !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.node.shape-round:not(.shape-manual) .node-title[contenteditable="true"],
.node.shape-round:not(.shape-manual) .node-body[contenteditable="true"] {
  width: auto !important;
  max-width: none !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  text-align: left !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}


/* v1.36: заголовок обычной скруглённой карточки не заходит на маркер перетаскивания */
.node.shape-round:not(.shape-manual) .node-header {
  padding-left: 36px !important;
  padding-right: 34px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  justify-content: flex-start !important;
  align-items: flex-start !important;
  text-align: left !important;
}

.node.shape-round:not(.shape-manual) .node-title {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  text-align: left !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.node.shape-round:not(.shape-manual) .node-title[contenteditable="true"] {
  width: 100% !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  text-align: left !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/* Описание остаётся слева, но не привязывается к маркеру переноса */
.node.shape-round:not(.shape-manual) .node-body {
  width: auto !important;
  max-width: none !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  text-align: left !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}


/* v1.37: у ромба кнопка сворачивания не конфликтует с правой точкой связи */
.node.shape-diamond .node-branch-toggle {
  right: 42px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  z-index: 42 !important;
  pointer-events: auto !important;
}

/* Правая точка связи остаётся доступной, но не перекрывает кнопку сворачивания */
.node.shape-diamond .handle-right {
  right: -1px !important;
  z-index: 28 !important;
}

/* При выделении ромба кнопка сворачивания остаётся поверх служебных маркеров */
.node.shape-diamond.selected .node-branch-toggle,
.node.shape-diamond:hover .node-branch-toggle {
  opacity: 1 !important;
}


/* v1.38: подпись на связи и удобное подтверждение удаления */
.edge-label {
  pointer-events: none !important;
  font-size: 13px !important;
  font-weight: 800 !important;
  dominant-baseline: middle;
}

#edgeSelectionForm .field-label {
  margin-top: 4px;
}

#edgeLabelInput {
  min-height: 44px;
}

.confirm-modal-active #confirmOk,
#confirmOk:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(37,99,235,.16), 0 16px 32px rgba(15,23,42,.18);
}


/* v1.39: подпись связи обычным шрифтом и редактирование по двойному клику */
.edge-label {
  pointer-events: auto !important;
  cursor: text !important;
  font-weight: 400 !important;
  font-size: 13px !important;
}

.edge-label-editor {
  position: absolute;
  z-index: 80;
  transform: translate(-50%, -50%);
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 10px;
  border: 1px solid rgba(99,102,241,.45);
  background: rgba(255,255,255,.96);
  color: #111827;
  font-size: 13px;
  font-weight: 400;
  text-align: center;
  box-shadow: 0 14px 30px rgba(15,23,42,.16);
  outline: none;
}

html[data-theme="dark"] .edge-label-editor {
  background: rgba(15,23,42,.96);
  color: #e5e7eb;
  border-color: rgba(147,197,253,.45);
  box-shadow: 0 14px 30px rgba(0,0,0,.28);
}


/* v1.40: подпись связи легче выбирать и редактировать */
.edge-label {
  pointer-events: all !important;
  cursor: text !important;
  user-select: none;
}

.edge-label:hover {
  fill: #1d4ed8;
}
html[data-theme="dark"] .edge-label:hover {
  fill: #93c5fd;
}


/* v1.41: мобильная оптимизация без изменения логики доски */
@media (pointer: coarse), (max-width: 820px), (prefers-reduced-motion: reduce) {
  .topbar,
  .panel-card,
  .modal-card,
  .canvas-toolbar,
  .toast,
  .node,
  .right-panel,
  .left-panel {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .node,
  .panel-card,
  .right-panel,
  .left-panel {
    box-shadow: 0 10px 26px rgba(15, 23, 42, .10) !important;
  }

  .node,
  .edge-path,
  .btn,
  .tool-btn,
  .service-card,
  .panel-card {
    transition-duration: .08s !important;
  }

  * {
    scroll-behavior: auto !important;
  }
}

/* Нижние/служебные части интерфейса можно рендерить лениво, где браузер поддерживает content-visibility. */
.panel-card,
.right-panel,
.left-panel {
  content-visibility: auto;
  contain-intrinsic-size: 1px 180px;
}

html[data-theme="dark"] .admin-open-btn[aria-expanded="true"] {
  background: rgba(15,23,42,.92);
  border-color: rgba(96,165,250,.42);
}


/* v1.52: mobile board usability — safe overrides only for small screens */
@media (max-width: 820px) {
  .workspace {
    min-height: 0;
  }
  .canvas-toolbar {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    max-width: none;
  }
  .canvas-toolbar #zoomOutBtn,
  .canvas-toolbar #zoomInBtn,
  .canvas-toolbar .zoom-value,
  .canvas-toolbar #fitBtn {
    display: grid !important;
  }
  .canvas-toolbar #fitBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
  .canvas-toolbar #toolbarAddBlockBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }
  body.readonly .canvas-toolbar #toolbarAddBlockBtn,
  body.text-mode .canvas-toolbar #toolbarAddBlockBtn,
  body.text-focus-mode .canvas-toolbar #toolbarAddBlockBtn {
    display: none !important;
  }
}

@media (max-width: 540px) {
  .canvas-toolbar {
    top: 8px;
    left: 8px;
    right: 8px;
    justify-content: center;
  }
  .canvas-toolbar .btn.compact {
    display: inline-flex;
  }
  .canvas-toolbar #toggleLeftBtn {
    order: 1;
  }
  .canvas-toolbar #zoomOutBtn {
    order: 2;
  }
  .canvas-toolbar .zoom-value {
    order: 3;
    min-width: 58px;
  }
  .canvas-toolbar #zoomInBtn {
    order: 4;
  }
  .canvas-toolbar #fitBtn {
    order: 5;
    min-width: 92px;
  }
  .canvas-toolbar #toolbarAddBlockBtn {
    order: 6;
    min-height: 38px;
    padding: 9px 14px;
    flex: 1 1 100%;
    max-width: 220px;
    margin: 2px auto 0;
    border-radius: 14px;
  }
  .canvas-toolbar #copyPublicBtn,
  .canvas-toolbar #undoBtn,
  .canvas-toolbar #redoBtn,
  .canvas-toolbar #textFocusBtn {
    display: none !important;
  }
  body.readonly .canvas-toolbar {
    justify-content: center;
  }
  body.readonly .canvas-toolbar #toggleLeftBtn,
  body.readonly .canvas-toolbar #zoomOutBtn,
  body.readonly .canvas-toolbar .zoom-value,
  body.readonly .canvas-toolbar #zoomInBtn,
  body.readonly .canvas-toolbar #fitBtn {
    display: grid !important;
  }
  body.readonly .canvas-toolbar #fitBtn {
    display: inline-flex !important;
  }
  .empty-state {
    top: 56%;
    width: min(330px, calc(100% - 28px));
  }
  .empty-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .empty-actions .btn {
    width: 100%;
  }
}

/* v1.58: публичные ссылки в правой колонке */
.public-links-card .link-box {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.72);
  margin-bottom: 10px;
}
.public-links-card .link-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.public-links-card .link-box a {
  color: var(--primary);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
html[data-theme="dark"] .public-links-card .link-box {
  background: rgba(15,23,42,.62);
}


/* v1.69: PWA + финальная мобильная стабилизация TaskBoard */
@media (max-width: 820px) {
  :root { --topbar-h: 62px; }
  .topbar {
    height: var(--topbar-h);
    padding: 9px 10px;
    gap: 8px;
  }
  .brand { min-width: 0; gap: 9px; }
  .brand-mark { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 12px; }
  .brand-title { font-size: 16px; }
  .brand-subtitle { display: block; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
  .topbar-actions { flex: 0 0 auto; }
  .theme-icon-btn { width: 38px; min-width: 38px; min-height: 38px; }
  .admin-open-btn { min-width: 68px; min-height: 38px; padding-inline: 10px !important; }
  .layout {
    height: calc(100vh - var(--topbar-h) - var(--course-promo-h));
    padding: 6px;
  }
  .workspace { border-radius: 17px; }
  .left-panel {
    left: 6px;
    right: 6px;
    bottom: 6px;
    width: auto;
    max-width: 360px;
  }
  .right-panel { right: 6px; bottom: 6px; width: min(360px, calc(100vw - 12px)); }
  .canvas-toolbar {
    top: 7px;
    left: 7px;
    right: 7px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .canvas-toolbar #copyPublicBtn,
  .canvas-toolbar #textFocusBtn { display: none !important; }
  .canvas-toolbar #toolbarAddBlockBtn { margin-left: auto; }
  .empty-state { width: min(380px, calc(100% - 24px)); }
}

@media (min-width: 541px) and (max-width: 680px) {
  .canvas-toolbar #undoBtn,
  .canvas-toolbar #redoBtn { display: none !important; }
  .canvas-toolbar #toolbarAddBlockBtn { flex: 1 1 auto; min-width: 145px; }
}

@media (max-width: 540px) {
  :root { --topbar-h: 58px; }
  .topbar { padding: 8px; }
  .brand-mark { width: 36px; height: 36px; flex-basis: 36px; }
  .brand-title { font-size: 15px; }
  .brand-subtitle { max-width: 38vw; font-size: 9px; }
  .admin-open-btn { min-width: 60px; font-size: 12px; }
  .canvas-toolbar {
    justify-content: center;
    padding: 0;
  }
  .canvas-toolbar #toggleLeftBtn,
  .canvas-toolbar #zoomOutBtn,
  .canvas-toolbar #zoomInBtn { width: 36px; height: 36px; }
  .canvas-toolbar .zoom-value { height: 36px; min-width: 54px; }
  .canvas-toolbar #fitBtn { min-height: 36px; min-width: 86px; padding-inline: 10px; }
  .canvas-toolbar #toolbarAddBlockBtn {
    flex: 1 1 100%;
    max-width: 240px;
    min-height: 38px;
    margin: 2px auto 0;
  }
  .empty-state { top: 55%; width: min(330px, calc(100% - 20px)); padding-inline: 4px; }
  .empty-state h2 { font-size: 18px; }
  .empty-state p { font-size: 12px; }
  .modal-card { width: calc(100vw - 20px); padding: 16px; border-radius: 18px; }
  .cookie-notice { z-index: 160; }
}

@media (max-width: 360px) {
  .brand-subtitle { display: none; }
  .admin-open-btn { min-width: 54px; padding-inline: 8px !important; }
  .canvas-toolbar #fitBtn { min-width: 78px; font-size: 11px; }
}

/* v1.71: свободный текст, безопасное сохранение и обновлённые элементы добавления */
.secondary-add {
  margin-top: 9px;
  min-height: 46px;
  border: 1px solid rgba(37, 99, 235, .22);
  background: rgba(37, 99, 235, .07);
  color: var(--primary-dark);
  font-weight: 850;
}
.secondary-add:hover {
  border-color: rgba(37, 99, 235, .42);
  background: rgba(37, 99, 235, .12);
}
.add-panel-note { margin: 8px 2px 0; }
.toolbar-add-text { min-width: 86px; }

.node.text,
.node.text.shape-round,
.node.text.shape-circle,
.node.text.shape-diamond {
  background: transparent !important;
  border: 1px dashed transparent !important;
  box-shadow: none !important;
  border-radius: 12px !important;
  padding: 14px 12px 10px 34px !important;
  overflow: visible !important;
}
.node.text::before,
.node.text::after { display: none !important; }
.node.text:hover {
  background: rgba(255, 255, 255, .34) !important;
  border-color: rgba(148, 163, 184, .32) !important;
  box-shadow: none !important;
}
.node.text.selected {
  background: rgba(255, 255, 255, .72) !important;
  border-color: rgba(37, 99, 235, .72) !important;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .10) !important;
}
.node.text .free-text-header { display: none !important; }
.node.text .free-text-content,
.node.text.shape-round:not(.shape-manual) .free-text-content,
.node.text.shape-circle .free-text-content,
.node.text.shape-diamond .free-text-content {
  display: block !important;
  width: 100% !important;
  min-height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  font-size: var(--free-text-size, 24px) !important;
  line-height: 1.28 !important;
  font-weight: 700 !important;
  letter-spacing: -.02em !important;
  text-align: left !important;
  color: #111827;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: hidden;
}
.node.text.node-blue .free-text-content { color: #1d4ed8; }
.node.text.node-green .free-text-content { color: #047857; }
.node.text.node-amber .free-text-content { color: #b45309; }
.node.text.node-rose .free-text-content { color: #be123c; }
.node.text.node-purple .free-text-content { color: #6d28d9; }
.node.text.node-gray .free-text-content { color: #111827; }
.node.text .node-branch-toggle,
.node.text .node-image { display: none !important; }
.node.text .drag-grip {
  left: 6px !important;
  top: 9px !important;
  opacity: .64 !important;
}
.node.text.selected .drag-grip,
.node.text:hover .drag-grip { opacity: 1 !important; }

html[data-theme="dark"] .secondary-add {
  background: rgba(96, 165, 250, .10);
  border-color: rgba(96, 165, 250, .28);
  color: #bfdbfe;
}
html[data-theme="dark"] .node.text:hover {
  background: rgba(15, 23, 42, .40) !important;
  border-color: rgba(148, 163, 184, .30) !important;
}
html[data-theme="dark"] .node.text.selected {
  background: rgba(15, 23, 42, .78) !important;
  border-color: rgba(96, 165, 250, .78) !important;
}
html[data-theme="dark"] .node.text.node-blue .free-text-content { color: #93c5fd; }
html[data-theme="dark"] .node.text.node-green .free-text-content { color: #6ee7b7; }
html[data-theme="dark"] .node.text.node-amber .free-text-content { color: #fcd34d; }
html[data-theme="dark"] .node.text.node-rose .free-text-content { color: #fda4af; }
html[data-theme="dark"] .node.text.node-purple .free-text-content { color: #c4b5fd; }
html[data-theme="dark"] .node.text.node-gray .free-text-content { color: #f8fafc; }

.empty-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.empty-actions #emptyTextBoardBtn { grid-column: 1 / -1; }

@media (max-width: 820px) {
  .canvas-toolbar #toolbarAddTextBtn { display: inline-flex; }
  .node.text .free-text-content { font-size: var(--free-text-size, 20px) !important; }
}

@media (max-width: 540px) {
  .canvas-toolbar #toolbarAddTextBtn {
    min-height: 36px;
    min-width: 82px;
  }
  .empty-actions { grid-template-columns: 1fr; }
  .empty-actions #emptyTextBoardBtn { grid-column: auto; }
}


/* v1.72: структурные ветки, быстрый плюс и форматирование свободного текста */
.node-tree-tools {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(37, 99, 235, .16);
  border-radius: 14px;
  background: rgba(37, 99, 235, .055);
}
.tree-shortcuts-note { margin: 0; line-height: 1.45; }

.node.selected:not(.text) { overflow: visible; z-index: 25; }
.node-context-actions {
  position: absolute;
  left: 50%;
  top: -48px;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  padding: 5px;
  border: 1px solid rgba(203, 213, 225, .92);
  border-radius: 13px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 12px 34px rgba(15, 23, 42, .16);
  white-space: nowrap;
  z-index: 40;
}
.node-context-actions button {
  min-height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #334155;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
.node-context-actions button:hover { background: #eef4ff; color: #1d4ed8; }
.node-add-child {
  position: absolute;
  right: -19px;
  top: 50%;
  width: 38px;
  height: 38px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  border: 4px solid rgba(255, 255, 255, .98);
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  box-shadow: 0 9px 22px rgba(37, 99, 235, .30);
  font-size: 23px;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
  z-index: 41;
}
.node-add-child:hover { transform: translateY(-50%) scale(1.08); background: #1d4ed8; }

.edge-path.tree-edge { stroke: rgba(37, 99, 235, .72); stroke-width: 2.7; }
.edge-hit.tree-edge { stroke-width: 18; }
.edge-path.link-edge { stroke-dasharray: 0; }

.node.text .free-text-content b,
.node.text .free-text-content strong { font-weight: 900; }
.node.text .free-text-content ul,
.node.text .free-text-content ol {
  margin: .25em 0 .25em 1.25em;
  padding: 0;
  list-style-position: outside;
}
.node.text .free-text-content li { margin: .12em 0; }
.node.text .free-text-content a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: .08em;
  text-underline-offset: .12em;
}
.node.text .free-text-content img {
  display: block;
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
  margin: .45em 0;
  border-radius: 12px;
}
.node.text .free-text-content p,
.node.text .free-text-content div { margin: 0 0 .18em; }
.node.text .free-text-content p:last-child,
.node.text .free-text-content div:last-child { margin-bottom: 0; }

html[data-theme="dark"] .node-tree-tools {
  background: rgba(96, 165, 250, .08);
  border-color: rgba(96, 165, 250, .20);
}
html[data-theme="dark"] .node-context-actions {
  background: rgba(15, 23, 42, .97);
  border-color: rgba(71, 85, 105, .92);
}
html[data-theme="dark"] .node-context-actions button { color: #cbd5e1; }
html[data-theme="dark"] .node-context-actions button:hover { background: rgba(59, 130, 246, .18); color: #bfdbfe; }
html[data-theme="dark"] .node-add-child { border-color: #0f172a; }

@media (max-width: 820px) {
  .node-context-actions { top: -44px; }
  .node-context-actions button { min-height: 29px; padding: 0 7px; font-size: 10px; }
  .node-add-child { width: 36px; height: 36px; right: -18px; }
}


/* v1.72.1: понятное добавление тем справа и снизу */
.node-add-child,
.node-add-sibling {
  position: absolute;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 4px solid rgba(255, 255, 255, .98);
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  box-shadow: 0 9px 22px rgba(37, 99, 235, .30);
  font-size: 23px;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
  z-index: 41;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease, background .12s ease;
}
.node-add-child {
  right: -47px;
  top: 50%;
  transform: translateY(-50%);
}
.node-add-sibling {
  left: 50%;
  bottom: -47px;
  transform: translateX(-50%);
}
.node.selected > .node-add-child,
.node.selected > .node-add-sibling {
  opacity: 1;
  pointer-events: auto;
}
.node.selected > .node-add-child:hover {
  transform: translateY(-50%) scale(1.08);
  background: #1d4ed8;
}
.node.selected > .node-add-sibling:hover {
  transform: translateX(-50%) scale(1.08);
  background: #1d4ed8;
}
html[data-theme="dark"] .node-add-child,
html[data-theme="dark"] .node-add-sibling { border-color: #0f172a; }

@media (max-width: 820px) {
  .node-add-child,
  .node-add-sibling { width: 36px; height: 36px; }
  .node-add-child { right: -44px; }
  .node-add-sibling { bottom: -44px; }
}


/* v1.72.3: быстрые плюсы по наведению и безопасный интервал веток */
@media (hover: hover) and (pointer: fine) {
  .node:hover > .node-add-child,
  .node:hover > .node-add-sibling {
    opacity: 1;
    pointer-events: auto;
  }
  .node:hover > .node-add-sibling:hover {
    transform: translateX(-50%) scale(1.08);
    background: #1d4ed8;
  }
}

.node.shape-circle { padding: 0; }
.node.shape-diamond { padding: 0 !important; }
.node.shape-diamond .node-content-clip {
  padding: 26px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

/* v1.72.3: быстрые действия без клика и адаптивные связи веток */
.grid-2.single-column { grid-template-columns: 1fr; }

/* Внешние кнопки не обрезаются карточкой, а её содержимое остаётся внутри границ. */
.node {
  padding: 0;
  overflow: visible;
}
.node-content-clip {
  position: absolute;
  inset: 0;
  padding: 14px;
  overflow: hidden;
  border-radius: inherit;
}
.node.shape-circle { padding: 0; }
.node.shape-circle .node-content-clip { padding: 22px; }
.node.shape-diamond { padding: 0 !important; }
.node.shape-diamond .node-content-clip {
  padding: 26px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

/* Кнопки почти соприкасаются с карточкой, поэтому hover не теряется в зазоре. */
.node-add-child { right: -40px; }
.node-add-sibling { bottom: -40px; }

@media (hover: hover) and (pointer: fine) {
  .node:not(.text):hover { z-index: 26; }
  .node:not(.text):hover > .node-add-child,
  .node:not(.text):hover > .node-add-sibling {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 820px) {
  .node-add-child { right: -38px; }
  .node-add-sibling { bottom: -38px; }
}

/* v1.72.4: двусторонняя компоновка веток и разнесение независимых деревьев */


/* v1.72.5: направление плюса и прямые связи интеллект-карты */
.node.branch-left > .node-add-child {
  left: -40px;
  right: auto;
}
.node.branch-right > .node-add-child {
  left: auto;
  right: -40px;
}

/* Структурные связи — тонкие прямые линии без стрелок. Ручные связи
   сохраняют стрелки и прежнюю кривую форму. */
.edge-path.tree-edge {
  stroke: rgba(71, 85, 105, .78) !important;
  stroke-width: 2.15px !important;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.edge-hit.tree-edge { stroke-width: 24px !important; }
html[data-theme="dark"] .edge-path.tree-edge {
  stroke: rgba(203, 213, 225, .68) !important;
}

@media (max-width: 820px) {
  .node.branch-left > .node-add-child { left: -38px; right: auto; }
  .node.branch-right > .node-add-child { left: auto; right: -38px; }
}


/* v1.72.6: динамические верхние/нижние точки структурных связей;
   размеры скруглённых карточек синхронизированы с размерами создания. */

/* v1.72.7: четырёхсторонние ветки сохраняют направление при добавлении
   и автоматическом выравнивании. */
.node.branch-top > .node-add-child {
  left: 50%;
  right: auto;
  top: -40px;
  bottom: auto;
  transform: translateX(-50%);
}
.node.branch-bottom > .node-add-child {
  left: 50%;
  right: auto;
  top: auto;
  bottom: -40px;
  transform: translateX(-50%);
}

/* У вертикальной ветки кнопка темы того же уровня уходит вправо,
   чтобы не накладываться на плюс продолжения ветки сверху/снизу. */
.node.branch-top > .node-add-sibling,
.node.branch-bottom > .node-add-sibling {
  left: auto;
  right: -40px;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}

.node.selected.branch-top > .node-add-child:hover,
.node.selected.branch-bottom > .node-add-child:hover,
.node.branch-top:hover > .node-add-child:hover,
.node.branch-bottom:hover > .node-add-child:hover {
  transform: translateX(-50%) scale(1.08);
}
.node.selected.branch-top > .node-add-sibling:hover,
.node.selected.branch-bottom > .node-add-sibling:hover,
.node.branch-top:hover > .node-add-sibling:hover,
.node.branch-bottom:hover > .node-add-sibling:hover {
  transform: translateY(-50%) scale(1.08);
}

@media (max-width: 820px) {
  .node.branch-top > .node-add-child { top: -38px; }
  .node.branch-bottom > .node-add-child { bottom: -38px; }
  .node.branch-top > .node-add-sibling,
  .node.branch-bottom > .node-add-sibling { right: -38px; }
}

/* v1.72.8: структурные линии используют единую грань для каждой группы направления. */


/* v1.72.9: кнопка сворачивания следует за направлением дочерних связей. */
.node-branch-toggle.collapse-right {
  left: auto !important;
  right: 6px !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translateY(-50%) !important;
}
.node-branch-toggle.collapse-left {
  left: 6px !important;
  right: auto !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translateY(-50%) !important;
}
.node-branch-toggle.collapse-top {
  left: 50% !important;
  right: auto !important;
  top: 6px !important;
  bottom: auto !important;
  transform: translateX(-50%) !important;
}
.node-branch-toggle.collapse-bottom {
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: 6px !important;
  transform: translateX(-50%) !important;
}

/* У ромба кнопка остаётся ближе к соответствующей вершине, но не
   перекрывает саму точку ручного соединения. */
.node.shape-diamond .node-branch-toggle.collapse-right { right: 38px !important; }
.node.shape-diamond .node-branch-toggle.collapse-left { left: 38px !important; }
.node.shape-diamond .node-branch-toggle.collapse-top { top: 24px !important; }
.node.shape-diamond .node-branch-toggle.collapse-bottom { bottom: 24px !important; }


/* v1.72.10: многоточечное сворачивание, индикатор выравнивания
   и защита новых соседних тем от наложения. */

/* Кнопка сворачивания находится снаружи карточки непосредственно на линии.
   Так верхняя кнопка не перекрывает заголовок, а смешанные ветки получают
   одинаковые кнопки на каждой реально используемой грани. */
.node-branch-toggle.collapse-right {
  left: auto !important;
  right: -12px !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translate(50%, -50%) !important;
}
.node-branch-toggle.collapse-left {
  left: -12px !important;
  right: auto !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translate(-50%, -50%) !important;
}
.node-branch-toggle.collapse-top {
  left: 50% !important;
  right: auto !important;
  top: -12px !important;
  bottom: auto !important;
  transform: translate(-50%, -50%) !important;
}
.node-branch-toggle.collapse-bottom {
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: -12px !important;
  transform: translate(-50%, 50%) !important;
}
.node.shape-diamond .node-branch-toggle.collapse-right {
  left: auto !important; right: -12px !important; top: 50% !important;
}
.node.shape-diamond .node-branch-toggle.collapse-left {
  left: -12px !important; right: auto !important; top: 50% !important;
}
.node.shape-diamond .node-branch-toggle.collapse-top {
  left: 50% !important; top: -12px !important;
}
.node.shape-diamond .node-branch-toggle.collapse-bottom {
  left: 50% !important; bottom: -12px !important;
}

/* В правой панели жёлтый цвет означает, что ветка изменялась вручную
   и её можно привести к аккуратной автоматической компоновке. */
#autoLayoutBtn.layout-needed,
#toolbarAutoLayoutBtn {
  background: #facc15 !important;
  color: #422006 !important;
  border-color: #eab308 !important;
  box-shadow: 0 10px 24px rgba(234, 179, 8, .24) !important;
  font-weight: 850;
}
#autoLayoutBtn.layout-needed:hover,
#toolbarAutoLayoutBtn:hover {
  background: #fde047 !important;
  border-color: #ca8a04 !important;
}
#autoLayoutBtn:not(.layout-needed) {
  background: rgba(255,255,255,.92);
}
html[data-theme="dark"] #autoLayoutBtn:not(.layout-needed) {
  background: rgba(15,23,42,.72);
}

/* Контекстная кнопка появляется рядом с «+ Блок», только когда выбранная
   ветка действительно требует выравнивания. */
.canvas-toolbar #toolbarAutoLayoutBtn {
  order: 21 !important;
  margin-left: 0 !important;
  min-height: 38px;
  white-space: nowrap;
}
.canvas-toolbar #undoBtn { order: 22 !important; }
.canvas-toolbar #redoBtn { order: 23 !important; }
.canvas-toolbar #textFocusBtn { order: 24 !important; }
body.text-mode .canvas-toolbar #toolbarAutoLayoutBtn,
body.readonly .canvas-toolbar #toolbarAutoLayoutBtn,
body.text-focus-mode.text-mode .canvas-toolbar #toolbarAutoLayoutBtn {
  display: none !important;
}

@media (max-width: 820px) {
  .canvas-toolbar #toolbarAutoLayoutBtn {
    min-height: 36px;
    padding-inline: 10px;
    font-size: 11px;
  }
}
@media (max-width: 560px) {
  .canvas-toolbar #toolbarAutoLayoutBtn {
    max-width: 112px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* v1.72.11: постоянное глобальное выравнивание и чистая текстовая панель */
body.text-mode #toolbarAddTextBtn { display: none !important; }
.toolbar-auto-layout:not([hidden]) { white-space: nowrap; }


/* v1.72.12: быстрые плюсы вынесены дальше от кнопок сворачивания,
   а ручной перенос проверяет пересечения всей подветки. */
.node.branch-right > .node-add-child { right: -58px !important; left: auto !important; }
.node.branch-left > .node-add-child { left: -58px !important; right: auto !important; }
.node.branch-top > .node-add-child { top: -58px !important; bottom: auto !important; }
.node.branch-bottom > .node-add-child { bottom: -58px !important; top: auto !important; }
.node.branch-top > .node-add-sibling,
.node.branch-bottom > .node-add-sibling { right: -58px !important; }
.node.branch-left > .node-add-sibling,
.node.branch-right > .node-add-sibling { bottom: -58px !important; }

@media (max-width: 820px) {
  .node.branch-right > .node-add-child { right: -54px !important; }
  .node.branch-left > .node-add-child { left: -54px !important; }
  .node.branch-top > .node-add-child { top: -54px !important; }
  .node.branch-bottom > .node-add-child { bottom: -54px !important; }
  .node.branch-top > .node-add-sibling,
  .node.branch-bottom > .node-add-sibling { right: -54px !important; }
  .node.branch-left > .node-add-sibling,
  .node.branch-right > .node-add-sibling { bottom: -54px !important; }
}

/* v1.72.13: доступные быстрые плюсы и внутренние кнопки сворачивания. */
/* Возвращаем кнопки добавления ближе к карточке: между карточкой и кнопкой
   больше нет разрыва, поэтому она не исчезает при переводе курсора. */
.node.branch-right > .node-add-child { right: -40px !important; left: auto !important; }
.node.branch-left > .node-add-child { left: -40px !important; right: auto !important; }
.node.branch-top > .node-add-child { top: -40px !important; bottom: auto !important; }
.node.branch-bottom > .node-add-child { bottom: -40px !important; top: auto !important; }
.node.branch-top > .node-add-sibling,
.node.branch-bottom > .node-add-sibling { right: -40px !important; }
.node.branch-left > .node-add-sibling,
.node.branch-right > .node-add-sibling { bottom: -40px !important; }

/* Кнопки сворачивания снова находятся внутри карточки и не конкурируют
   с быстрыми плюсами. */
.node-branch-toggle.collapse-right {
  left: auto !important;
  right: 6px !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translateY(-50%) !important;
}
.node-branch-toggle.collapse-left {
  left: 6px !important;
  right: auto !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translateY(-50%) !important;
}
.node-branch-toggle.collapse-top {
  left: 50% !important;
  right: auto !important;
  top: 6px !important;
  bottom: auto !important;
  transform: translateX(-50%) !important;
}
.node-branch-toggle.collapse-bottom {
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: 6px !important;
  transform: translateX(-50%) !important;
}

/* Если сверху есть кнопка сворачивания, содержимое карточки опускается ниже,
   чтобы заголовок не попадал под кнопку. */
.node:has(> .node-branch-toggle.collapse-top) > .node-content-clip {
  padding-top: 30px;
}
.node.shape-circle:has(> .node-branch-toggle.collapse-top) > .node-content-clip {
  padding-top: 34px;
}
.node.shape-diamond:has(> .node-branch-toggle.collapse-top) > .node-content-clip {
  padding-top: 38px;
}

/* Для ромбов кнопки остаются внутри визуальной фигуры. */
.node.shape-diamond .node-branch-toggle.collapse-right { right: 38px !important; }
.node.shape-diamond .node-branch-toggle.collapse-left { left: 38px !important; }
.node.shape-diamond .node-branch-toggle.collapse-top { top: 24px !important; }
.node.shape-diamond .node-branch-toggle.collapse-bottom { bottom: 24px !important; }

@media (max-width: 820px) {
  .node.branch-right > .node-add-child { right: -38px !important; }
  .node.branch-left > .node-add-child { left: -38px !important; }
  .node.branch-top > .node-add-child { top: -38px !important; }
  .node.branch-bottom > .node-add-child { bottom: -38px !important; }
  .node.branch-top > .node-add-sibling,
  .node.branch-bottom > .node-add-sibling { right: -38px !important; }
  .node.branch-left > .node-add-sibling,
  .node.branch-right > .node-add-sibling { bottom: -38px !important; }
}


/* TaskBoard 1.73 — режим «Холст» */
.mode-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.drawing-layer {
  position: absolute;
  inset: 0;
  width: 8000px;
  height: 6000px;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
.edge-layer { z-index: 2; }
.node-layer { z-index: 3; }
body.canvas-mode .canvas {
  background-color: #fff;
  background-image: none;
  touch-action: none;
}
html[data-theme="dark"] body.canvas-mode .canvas { background: #f8fafc; }
body.canvas-mode .edge-layer,
body.canvas-mode .node-layer { display: none; }
body.canvas-mode .selected-card,
body.canvas-mode #textSettingsPanel,
body.canvas-mode #addPanel { display: none !important; }
body.canvas-mode .canvas-empty-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  display: grid;
  gap: 8px;
  max-width: 420px;
  padding: 20px 24px;
  border: 1px solid #dbe4f0;
  border-radius: 18px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 18px 44px rgba(15,23,42,.1);
  text-align: center;
  color: #64748b;
  pointer-events: none;
}
body.canvas-mode .canvas-empty-hint b { color: #111827; font-size: 18px; }
.canvas-tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.canvas-tool-btn.active {
  color: #fff;
  border-color: #3555df;
  background: linear-gradient(135deg,#4767ee,#13204d);
  box-shadow: 0 8px 20px rgba(53,85,223,.2);
}
.canvas-color-row { display: flex; flex-wrap: wrap; gap: 9px; margin: 6px 0 14px; }
.canvas-color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px #cbd5e1;
  cursor: pointer;
}
.canvas-color-dot.active { box-shadow: 0 0 0 3px #4f67e8; }
.canvas-width-label { display: flex; justify-content: space-between; align-items: center; }
.canvas-width-input { width: 100%; accent-color: #405de4; }
.canvas-quick-tools { display: flex; gap: 6px; align-items: center; }
.canvas-quick-tools .btn { min-width: auto; }
body.canvas-mode .canvas.tool-pen,
body.canvas-mode .canvas.tool-marker { cursor: crosshair; touch-action: none; }
body.canvas-mode .canvas.tool-eraser { cursor: cell; touch-action: none; }
body.canvas-mode .canvas.tool-hand { cursor: grab; }
body.canvas-mode .canvas.tool-hand:active { cursor: grabbing; }
body.canvas-mode .canvas-toolbar #toolbarAddBlockBtn,
body.canvas-mode .canvas-toolbar #toolbarAddTextBtn,
body.canvas-mode .canvas-toolbar #toolbarAutoLayoutBtn { display: none !important; }
body.canvas-mode .canvas-toolbar #canvasQuickTools:not([hidden]) { display: flex; }
.board-type-chip.type-canvas { color:#92400e; background:#fef3c7; box-shadow:inset 0 0 0 1px rgba(217,119,6,.2); }
html[data-theme="dark"] .board-type-chip.type-canvas { color:#fde68a; background:rgba(217,119,6,.24); }
@media (max-width: 820px) {
  .mode-tab { font-size: 12px; padding-inline: 5px; }
  .canvas-quick-tools { display: none !important; }
  body.canvas-mode .canvas-empty-hint { width: min(78vw, 360px); padding: 16px 18px; }
}


/* TaskBoard 1.73.1 — полировка режима «Холст» */
body:not(.canvas-mode) #drawingLayer { display: none !important; }
body.canvas-mode .canvas-empty-hint[hidden] { display: none !important; }
body.canvas-mode #canvasToolsPanel { display: none !important; }
.canvas-settings-card .canvas-color-row { margin-bottom: 12px; }
.canvas-settings-card .canvas-width-input { margin-bottom: 12px; }
.canvas-settings-card #clearCanvasBtn { margin-top: 4px; }
.local-board-item {
  grid-template-columns: minmax(0, 1fr) !important;
  border-radius: 14px !important;
}
.local-board-main {
  width: 100%;
  min-width: 0;
  border-radius: 14px !important;
  clip-path: none !important;
}
.local-board-item.active .local-board-main {
  border-radius: 14px !important;
}
.board-title-line b {
  padding-left: 0;
  min-width: 48px;
}
.board-type-chip.type-canvas {
  color: #92400e;
  background: #fef3c7;
  border-radius: 999px !important;
}
.local-board-item .mini-danger.inline { flex: 0 0 auto; }
@media (max-width: 1100px) {
  .canvas-settings-card .canvas-tool-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* TaskBoard 1.73.2 — единое отображение карточек «Мои доски» */
.local-board-list .local-board-item,
.boards-modal-list .local-board-item {
  display: block !important;
  width: 100%;
  min-width: 0;
}
.local-board-list .local-board-main,
.boards-modal-list .local-board-main {
  box-sizing: border-box;
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  width: 100% !important;
  min-width: 0;
  min-height: 82px;
  padding: 9px 10px !important;
  overflow: visible !important;
  clip-path: none !important;
}
.local-board-list .board-title-line,
.boards-modal-list .board-title-line {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: 6px;
  width: 100%;
  min-width: 0;
}
.local-board-list .board-title-line b[data-rename],
.boards-modal-list .board-title-line b[data-rename] {
  display: block !important;
  width: 100%;
  min-width: 0 !important;
  max-width: none;
  margin: 0;
  padding: 2px 0;
  overflow: hidden;
  color: var(--text) !important;
  font-size: 12.5px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
  user-select: text;
}
.local-board-list .local-board-item.active .board-title-line b[data-rename],
.boards-modal-list .local-board-item.active .board-title-line b[data-rename] {
  color: #1d4ed8 !important;
}
.local-board-list .board-title-line .board-type-chip,
.boards-modal-list .board-title-line .board-type-chip {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 22px;
  margin: 0 !important;
  padding: 4px 8px;
  line-height: 1;
  white-space: nowrap;
}
.local-board-list .board-title-line .mini-danger.inline,
.boards-modal-list .board-title-line .mini-danger.inline {
  display: inline-grid !important;
  place-items: center;
  margin: 0 !important;
}
.local-board-list .local-board-main .board-meta-line,
.local-board-list .local-board-main .board-link-line,
.boards-modal-list .local-board-main .board-meta-line,
.boards-modal-list .local-board-main .board-link-line {
  position: static !important;
  display: block !important;
  flex: 0 0 auto;
  width: 100%;
  min-height: 13px;
  margin: 3px 0 0 !important;
  overflow: hidden;
  visibility: visible !important;
  opacity: 1 !important;
  color: var(--muted) !important;
  font-size: 10px !important;
  line-height: 1.3 !important;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.local-board-list .local-board-share,
.boards-modal-list .local-board-share {
  width: 100%;
  min-width: 0;
}
.board-title-line b[data-rename]:focus-visible {
  outline: 2px solid rgba(59,130,246,.55);
  outline-offset: 2px;
  border-radius: 5px;
}
html[data-theme="dark"] .local-board-list .local-board-item.active .board-title-line b[data-rename],
html[data-theme="dark"] .boards-modal-list .local-board-item.active .board-title-line b[data-rename] {
  color: #fff !important;
}


/* TaskBoard 1.73.3 — устранение конфликта имени класса холста */
/* Тип доски использует отдельный namespace type-*, чтобы не наследовать .canvas редактора. */
.local-board-list .board-type-chip.type-canvas,
.boards-modal-list .board-type-chip.type-canvas {
  position: static !important;
  inset: auto !important;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
  touch-action: auto !important;
  background-image: none !important;
  background-size: auto !important;
}

/* TaskBoard 1.73.4 — один клик по названию открывает доску, двойной переименовывает */


/* TaskBoard 1.73.6 — финальный экран запуска и выравнивание независимых корней */
.canvas-toolbar #toolbarAddBlockBtn {
  order: 20 !important;
  margin-left: auto !important;
}
.canvas-toolbar #toolbarAddTextBtn {
  order: 21 !important;
  margin-left: 0 !important;
}
.canvas-toolbar #toolbarAutoLayoutBtn { order: 22 !important; }
.canvas-toolbar #undoBtn { order: 23 !important; }
.canvas-toolbar #redoBtn { order: 24 !important; }
.canvas-toolbar #textFocusBtn { order: 25 !important; }


/* TaskBoard 1.73.6 — четыре действия на пустой схеме */
.empty-state {
  width: min(390px, calc(100% - 32px));
}
.empty-actions {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  gap: 10px !important;
}
.empty-actions .btn {
  min-width: 0;
  white-space: nowrap;
  padding-left: 12px;
  padding-right: 12px;
}
#emptyAddTextBtn {
  font-size: 12.5px;
}
@media (max-width: 420px) {
  .empty-state { width: calc(100% - 20px); padding-left: 16px; padding-right: 16px; }
  .empty-actions { gap: 8px !important; }
  .empty-actions .btn { font-size: 12px; padding-left: 8px; padding-right: 8px; }
}


/* TaskBoard 1.73.7 — аккуратная сетка запуска и единый логотип */
.empty-actions {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 10px !important;
  width: 100%;
}
.empty-actions > .btn,
.empty-actions #emptyTextBoardBtn,
.empty-actions #emptyCanvasBtn {
  grid-column: auto !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 44px;
  margin: 0 !important;
  white-space: nowrap;
  justify-content: center;
}
.brand-mark {
  display: block !important;
  object-fit: contain;
  background: transparent !important;
  color: transparent !important;
  padding: 0 !important;
  overflow: visible;
}
@media (max-width: 420px) {
  .empty-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .empty-actions > .btn {
    min-height: 42px;
    font-size: 11.5px;
    padding-left: 6px !important;
    padding-right: 6px !important;
  }
}
