:root {
  --bg: #f4f4f7; --canvas: #fafafb; --dot: #c9cad3; --panel: #ffffff; --line: #e3e3ea; --ink: #1d1d24; --muted: #7a7b88;
  --accent: #7048e8; --accent-soft: #ece6ff; --sel: #7048e8; --shadow: 0 6px 24px rgba(20, 20, 40, .12), 0 1px 3px rgba(20, 20, 40, .08);
  --edge: #5c5f6b;
}
:root[data-theme="dark"] {
  --bg: #15161b; --canvas: #1b1c22; --dot: #363846; --panel: #23242c; --line: #33343f; --ink: #ececf1; --muted: #9a9bab;
  --accent: #9775fa; --accent-soft: #2f2747; --sel: #9775fa; --shadow: 0 6px 24px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
  --edge: #a3a6b4;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.35 "Segoe UI", system-ui, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
#app { position: fixed; inset: 0; display: grid; grid-template-rows: 48px 1fr; grid-template-columns: auto 1fr; }

#top { grid-column: 1 / 3; display: flex; align-items: center; gap: 6px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5; }
#top .sp { flex: 1; }
#top .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
#boardName { border: 1px solid transparent; background: transparent; color: var(--ink); font: 600 15px "Segoe UI", sans-serif; padding: 5px 8px; border-radius: 6px; width: 320px; }
#boardName:hover { border-color: var(--line); }
#boardName:focus { outline: none; border-color: var(--accent); }
.save { color: var(--muted); font-size: 12px; white-space: nowrap; }
.save.bad { color: #e03131; font-weight: 600; }
.ib { width: 32px; height: 32px; border: 0; background: transparent; border-radius: 7px; font-size: 17px; display: inline-grid; place-items: center; }
.ib:hover, .tb:hover, .zoomv:hover { background: var(--accent-soft); }
.tb { height: 32px; border: 0; background: transparent; border-radius: 7px; padding: 0 10px; }
.tb.wide { width: 100%; background: var(--accent); color: #fff; font-weight: 600; }
.tb.wide:hover { filter: brightness(1.08); background: var(--accent); }
.zoomv { border: 0; background: transparent; min-width: 52px; height: 32px; border-radius: 7px; font-variant-numeric: tabular-nums; }
.menu { position: relative; }
.drop { position: absolute; right: 0; top: 38px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; display: none; min-width: 230px; z-index: 20; }
.drop.open { display: block; }
.drop button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; }
.drop button:hover { background: var(--accent-soft); }
.drop hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }

#side { grid-row: 2; width: 260px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 4; }
#side.hide { display: none; }
.side-h { padding: 10px; display: grid; gap: 8px; }
#boardFilter { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 7px; padding: 7px 9px; font: inherit; }
#boardList { flex: 1; overflow: auto; padding: 0 6px; }
.bi { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 6px; align-items: center; }
.bi:hover { background: var(--bg); }
.bi.on { background: var(--accent-soft); }
.bi b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bi small { color: var(--muted); grid-column: 1; font-size: 11.5px; }
.bi .acts { grid-row: 1 / 3; grid-column: 2; display: none; gap: 2px; }
.bi:hover .acts { display: flex; }
.bi .acts button { border: 0; background: transparent; border-radius: 5px; padding: 3px 5px; color: var(--muted); }
.bi .acts button:hover { background: var(--panel); color: var(--ink); }
.side-f { padding: 10px 12px; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--line); }

#tools { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; display: flex; flex-direction: column; gap: 2px; z-index: 4; }
#app.side-on #tools { left: 272px; }
#tools button { width: 38px; height: 38px; border: 0; background: transparent; border-radius: 8px; display: grid; place-items: center; }
#tools button:hover { background: var(--accent-soft); }
#tools button.on { background: var(--accent); }
#tools button.on svg { stroke: #fff; }
#tools svg { width: 21px; height: 21px; fill: none; stroke: var(--ink); stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
#tools i { height: 1px; background: var(--line); margin: 3px 4px; }

#stage { grid-row: 2; grid-column: 2; position: relative; overflow: hidden; background: var(--canvas); }
#svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
#gridDot { fill: var(--dot); }
#stage.pan, #stage.pan * { cursor: grab !important; }
#stage.panning, #stage.panning * { cursor: grabbing !important; }
#stage.crosshair #svg { cursor: crosshair; }

.node { cursor: move; }
.node .sh { stroke-width: 2; }
.node.sticky .sh { filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .18)); }
.node .t { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px 12px; overflow: hidden; }
.node .c { white-space: pre-wrap; word-break: break-word; outline: none; max-width: 100%; min-width: 4px; cursor: inherit; }
.node .c[contenteditable] { cursor: text; user-select: text; }
.node.ellipse .t, .node.diamond .t, .node.hex .t { padding: 12% 16%; }
.node.diamond .t { padding: 22% 24%; }
.node.sticky .t { align-items: flex-start; justify-content: flex-start; text-align: left; padding: 14px 14px; }
.node.text .t { padding: 2px 4px; }
.node.hit .sh { stroke: var(--sel) !important; stroke-width: 3; }
.node.found .sh { stroke: #f59f00 !important; stroke-width: 4; }
.frame .fbody { cursor: default; }
.frame .ftitle { cursor: move; }
.frame .ftitle div { font-weight: 700; font-size: 14px; padding: 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; outline: none; }
.badge { cursor: pointer; }
.badge text { font: 700 11px "Segoe UI", sans-serif; fill: #fff; pointer-events: none; }

.edge .hitp { stroke: transparent; fill: none; cursor: pointer; }
.edge .ln { fill: none; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.edge.sel .ln { filter: drop-shadow(0 0 3px var(--sel)); }
.edge .lab div { display: inline-block; background: var(--canvas); color: var(--ink); padding: 1px 6px; border-radius: 5px; font-size: 13px; white-space: pre; }
.edge .labwrap { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.edge .labwrap div { pointer-events: auto; cursor: pointer; }

.selbox { fill: none; stroke: var(--sel); stroke-width: 1.5; pointer-events: none; }
.handle { fill: #fff; stroke: var(--sel); stroke-width: 1.5; }
.conn { fill: var(--sel); stroke: #fff; stroke-width: 1.5; cursor: crosshair; opacity: .9; }
.conn:hover { opacity: 1; }
.eend { fill: #fff; stroke: var(--sel); stroke-width: 2; cursor: grab; }
.guide { stroke: #f03e3e; stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }
.temp { fill: none; stroke: var(--sel); stroke-width: 2; stroke-dasharray: 6 4; pointer-events: none; }
.band { fill: rgba(112, 72, 232, .08); stroke: var(--sel); stroke-width: 1; stroke-dasharray: 4 3; }

.ctx { position: absolute; z-index: 6; background: var(--panel); border-radius: 11px; box-shadow: var(--shadow); padding: 5px; display: flex; align-items: center; gap: 3px; flex-wrap: wrap; white-space: nowrap; max-width: min(560px, calc(100% - 16px)); }
.ctx .sw { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.ctx .sw.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.ctx .cb { height: 28px; min-width: 28px; border: 0; background: transparent; border-radius: 6px; padding: 0 7px; font-size: 13px; display: inline-grid; place-items: center; }
.ctx .cb:hover { background: var(--accent-soft); }
.ctx .cb.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.ctx .cb svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.ctx .vs { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }
.ctx input[type=color] { width: 24px; height: 24px; border: 0; padding: 0; background: none; cursor: pointer; }

.search { position: absolute; top: 12px; right: 12px; z-index: 7; background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; display: flex; align-items: center; gap: 4px; }
.search input { border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; width: 240px; background: var(--bg); color: var(--ink); font: inherit; }
.search span { color: var(--muted); font-size: 12px; min-width: 44px; text-align: center; }

#mini { position: absolute; right: 12px; bottom: 12px; width: 220px; height: 150px; background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); z-index: 4; cursor: pointer; }
.hint { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--ink); color: var(--canvas); padding: 7px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 8; }
.hint.on { opacity: .92; }
.labeled { position: absolute; z-index: 9; font: 13px "Segoe UI", sans-serif; padding: 4px 8px; border: 2px solid var(--accent); border-radius: 6px; background: var(--panel); color: var(--ink); resize: none; outline: none; min-width: 120px; text-align: center; }

.modal { position: fixed; inset: 0; background: rgba(10, 10, 20, .45); display: grid; place-items: center; z-index: 30; }
.modal .card { background: var(--panel); border-radius: 16px; padding: 22px 26px; width: min(980px, 94vw); max-height: 90vh; overflow: auto; position: relative; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 8px; font-size: 20px; }
.modal h3 { margin: 14px 0 6px; font-size: 14px; color: var(--accent); }
.modal p { margin: 5px 0; }
.modal .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; }
.modal .close { position: absolute; right: 12px; top: 12px; }
.modal .muted { color: var(--muted); margin-top: 14px; }
kbd { display: inline-block; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font: 12px "Segoe UI", sans-serif; background: var(--bg); }

/* комментарии */
.cmt { cursor: pointer; }
.cmt path { fill: #f59f00; stroke: #fff; stroke-width: 1.5; }
.cmt circle { fill: #fff; }
.cmtcard { display: inline-block; transform: translateY(-100%); max-width: 100%; background: rgba(255, 224, 102, .62); border: 1px solid rgba(245, 159, 0, .55); color: var(--ink); border-radius: 8px; padding: 6px 9px; font-size: 13px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; cursor: pointer; transition: background .15s; }
.cmtcard:hover { background: rgba(255, 224, 102, .95); }
:root[data-theme="dark"] .cmtcard { background: rgba(245, 159, 0, .28); }
.cmtpop { position: absolute; z-index: 9; max-width: 300px; background: #fff9db; color: #3b3000; border: 1px solid #f59f00; border-radius: 9px; padding: 8px 11px; font-size: 13px; white-space: pre-wrap; box-shadow: var(--shadow); pointer-events: none; }
.cmted { position: absolute; z-index: 10; width: 300px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 10px; border-top: 4px solid #f59f00; }
.cmth { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.cmth b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmted textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: 14px "Segoe UI", sans-serif; padding: 8px; resize: vertical; outline: none; }
.cmted textarea:focus { border-color: #f59f00; }
.cmtf { display: flex; gap: 6px; margin-top: 8px; }
#btnExport, #btnCmt { white-space: nowrap; }

/* узкий экран: телефон, Telegram */
.narrow-only { display: none; }
@media (max-width: 760px) {
  .narrow-only { display: inline; } .wide-only { display: none; }
  #boardName { flex: 1 1 120px; }
  #top { gap: 2px; padding: 0 4px; }
  #boardName { width: auto; flex: 1; min-width: 0; font-size: 14px; }
  #top .sp, #top .sep, #btnZoomIn, #btnZoomOut, #zoomVal, #btnTheme, #btnHelp { display: none; }
  .save { max-width: 64px; overflow: hidden; text-overflow: ellipsis; font-size: 10.5px; }
  .tb { padding: 0 7px; }
  #side { position: absolute; left: 0; top: 48px; bottom: 0; width: min(300px, 86vw); box-shadow: var(--shadow); z-index: 12; }
  #tools, #app.side-on #tools { left: 50%; top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); transform: translateX(-50%); flex-direction: row; max-width: calc(100% - 16px); overflow-x: auto; }
  #tools i { width: 1px; height: auto; margin: 4px 3px; }
  #tools button { width: 42px; height: 42px; flex: none; }
  #mini { display: none; }
  .ctx { max-width: calc(100% - 16px); overflow-x: auto; flex-wrap: nowrap; }
  .ctx .cb { height: 36px; min-width: 36px; flex: none; }
  .ctx .sw { width: 26px; height: 26px; flex: none; }
  .search { left: 8px; right: 8px; }
  .search input { width: auto; flex: 1; min-width: 0; }
  .modal .cols { grid-template-columns: 1fr; }
  .hint { bottom: 72px; }
}
