/* ============================================================
   Markdownie — Notion-подобный редактор постов для Telegram
   Токены: semantic, парные для light/dark.
   ============================================================ */

:root {
  /* surfaces */
  --bg:            #ffffff;
  --bg-sunken:     #f7f7f5;
  --surface:       #ffffff;
  --surface-hover: rgba(55, 53, 47, 0.06);
  --surface-active:rgba(55, 53, 47, 0.10);

  /* text */
  --text:          #37352f;
  --text-muted:    #787774;
  --text-faint:    #b3b1ab;

  /* lines */
  --border:        rgba(55, 53, 47, 0.10);
  --border-strong: rgba(55, 53, 47, 0.18);

  /* brand */
  --accent:        #2f6fed;
  --accent-hover:  #245bd0;
  --accent-soft:   rgba(47, 111, 237, 0.10);
  --on-accent:     #ffffff;

  /* semantic */
  --danger:        #d44c47;
  --success:       #2e7d51;
  --warn:          #cb7b1a;

  /* code */
  --code-bg:       rgba(135, 131, 120, 0.15);
  --code-fg:       #c0392b;
  --codeblock-bg:  #f7f6f3;

  /* telegram */
  --tg-chat-bg:    #ccd8e3;
  --tg-chat-bg-2:  #dfe6ec;
  --tg-bubble:     #ffffff;
  --tg-bubble-fg:  #10161c;
  --tg-link:       #168acd;
  --tg-quote-bar:  #3a8fd8;
  --tg-meta:       #7c98ab;
  --tg-panel:      #ffffff;

  /* geometry */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --shadow-1: 0 1px 2px rgba(15, 15, 15, 0.06), 0 2px 6px rgba(15, 15, 15, 0.06);
  --shadow-2: 0 4px 12px rgba(15, 15, 15, 0.10), 0 12px 32px rgba(15, 15, 15, 0.10);

  --topbar-h: 52px;
  --dur: 160ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --preview-w: 420px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg:            #191919;
  --bg-sunken:     #151515;
  --surface:       #202020;
  --surface-hover: rgba(255, 255, 255, 0.055);
  --surface-active:rgba(255, 255, 255, 0.10);

  --text:          #e4e2df;
  --text-muted:    #9b9a97;
  --text-faint:    #6b6a67;

  --border:        rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);

  --accent:        #5b8dff;
  --accent-hover:  #7ba3ff;
  --accent-soft:   rgba(91, 141, 255, 0.16);
  --on-accent:     #0d1220;

  --danger:        #ff7369;
  --success:       #4dab7a;
  --warn:          #e0a355;

  --code-bg:       rgba(255, 255, 255, 0.10);
  --code-fg:       #ff8b7e;
  --codeblock-bg:  #1b1b1b;

  --tg-chat-bg:    #0e1621;
  --tg-chat-bg-2:  #17212b;
  --tg-bubble:     #182533;
  --tg-bubble-fg:  #f0f2f4;
  --tg-link:       #62b0e8;
  --tg-quote-bar:  #62b0e8;
  --tg-meta:       #6d8199;
  --tg-panel:      #17212b;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 6px 20px rgba(0, 0, 0, 0.5), 0 16px 48px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* ── reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
/* .fmtbar/.linkpop задают display, поэтому штатное [hidden] их не прячет */
[hidden] { display: none !important; }
button { cursor: pointer; background: none; border: 0; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--accent); color: var(--on-accent);
  padding: 8px 14px; border-radius: var(--r-md); text-decoration: none;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 8px; }

/* ── buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  border-radius: var(--r-md);
  font-size: 14px; font-weight: 500;
  color: var(--text);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.97); }
.btn-icon { width: 32px; padding: 0; justify-content: center; color: var(--text-muted); }
.btn-icon:hover { color: var(--text); }
.btn-primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm { height: 28px; font-size: 13px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ── topbar ──────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  width: 28px; height: 28px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--accent); color: var(--on-accent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }
.brand-text span { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.doc-title-wrap { flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center; min-width: 0; }
.doc-title {
  max-width: 340px; width: 100%;
  background: none; border: 1px solid transparent; border-radius: var(--r-md);
  padding: 5px 10px; font-size: 14px; font-weight: 500; text-align: center;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  text-overflow: ellipsis;
}
.doc-title:hover { background: var(--surface-hover); }
.doc-title:focus { background: var(--surface); border-color: var(--border-strong); outline: none; text-align: left; }
.save-state { font-size: 11px; color: var(--text-faint); white-space: nowrap; }

.topbar-actions { display: flex; align-items: center; gap: 4px; }
[data-theme="light"] .i-moon, [data-theme="dark"] .i-sun { display: none; }

/* ── workspace ───────────────────────────────────────── */
.workspace {
  display: flex;
  height: calc(100dvh - var(--topbar-h));
  min-height: 0;
}
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-write { flex: 1; }
.pane-preview {
  width: var(--preview-w); flex: none;
  background: var(--bg-sunken);
  border-left: 1px solid var(--border);
}
.splitter {
  width: 5px; flex: none; cursor: col-resize;
  background: transparent; margin: 0 -2px; position: relative; z-index: 5;
}
.splitter:hover::after, .splitter:focus-visible::after {
  content: ''; position: absolute; inset: 0 2px; background: var(--accent); opacity: 0.5;
}

/* ── editor ──────────────────────────────────────────── */
.editor-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.editor-shell {
  position: relative;
  max-width: 760px;
  margin: 0 auto;
  padding: 56px 64px 40vh;
}
.editor { outline: none; font-size: 16px; caret-color: var(--accent); }

/* блоки */
.blk {
  position: relative;
  margin: 2px 0;
  padding: 3px 2px;
  min-height: 1.5em;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.blk[data-empty="1"]::after {
  content: attr(data-placeholder);
  position: absolute; left: 2px; top: 3px;
  color: var(--text-faint); pointer-events: none;
  white-space: nowrap; overflow: hidden; max-width: 100%;
}
.blk[data-type="paragraph"][data-empty="1"]::after { content: ''; }
.blk.is-focused[data-type="paragraph"][data-empty="1"]::after {
  content: attr(data-placeholder);
}
/* подсказка начинается там же, где текст блока, — иначе наезжает на маркер */
.blk[data-type="bulleted"][data-empty="1"]::after,
.blk[data-type="numbered"][data-empty="1"]::after { left: 28px; }
.blk[data-type="quote"][data-empty="1"]::after { left: 16px; }
.blk[data-type="code"][data-empty="1"]::after { left: 14px; top: 12px; }

.blk[data-type="h1"] { font-size: 30px; font-weight: 700; line-height: 1.25; letter-spacing: -0.02em; margin: 26px 0 2px; }
.blk[data-type="h2"] { font-size: 23px; font-weight: 650; line-height: 1.3; letter-spacing: -0.015em; margin: 20px 0 1px; }
.blk[data-type="h3"] { font-size: 18px; font-weight: 650; line-height: 1.35; margin: 16px 0 1px; }
.blk[data-type="h1"]:first-child, .blk[data-type="h2"]:first-child, .blk[data-type="h3"]:first-child { margin-top: 0; }

.blk[data-type="bulleted"], .blk[data-type="numbered"] { padding-left: 28px; }
.blk[data-type="bulleted"]::before {
  content: '•'; position: absolute; left: 8px; top: 3px;
  color: var(--text-muted); font-size: 18px; line-height: 1.4;
}
.blk[data-type="numbered"]::before {
  content: attr(data-num) '.'; position: absolute; left: 2px; top: 3px; width: 20px;
  text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 15px;
}
.blk[data-type="quote"] {
  padding-left: 16px; margin: 8px 0;
  border-left: 3px solid var(--text); color: var(--text);
}
.blk[data-type="code"] {
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.6;
  background: var(--codeblock-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px 12px 14px;
  white-space: pre-wrap; tab-size: 2;
  margin: 10px 0;
}
.blk[data-type="code"]::before {
  content: attr(data-lang);
  position: absolute; right: 10px; top: 6px;
  font-size: 11px; color: var(--text-faint); font-family: var(--font);
  letter-spacing: 0.02em; text-transform: lowercase; pointer-events: none;
}
.blk[data-type="divider"] {
  height: 1px; min-height: 0; padding: 0; margin: 20px 0;
  display: flex; align-items: center;
}
.blk[data-type="divider"]::before {
  content: ''; position: absolute; left: 0; right: 0; top: 50%;
  border-top: 1px solid var(--border-strong);
}
.blk[data-type="divider"] br { display: none; }

/* инлайновые метки */
.editor code, .code-inline {
  font-family: var(--font-mono); font-size: 0.88em;
  background: var(--code-bg); color: var(--code-fg);
  padding: 0.15em 0.35em; border-radius: var(--r-sm);
}
.blk[data-type="code"] code { background: none; color: inherit; padding: 0; }
.editor a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; cursor: text; }
.spoiler {
  background: var(--text-faint); color: transparent;
  border-radius: 3px; box-decoration-break: clone;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.editor .spoiler:hover { background: var(--surface-active); color: var(--text); }

/* ── медиа в редакторе ───────────────────────────────── */
.blk[data-type="image"], .blk[data-type="video"] {
  padding: 0; margin: 14px 0; min-height: 0;
  user-select: none;
}
.media {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-sunken);
  overflow: hidden;
}
.media-frame {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 80px; max-height: 360px;
  background: var(--surface-active);
}
.media-view { display: block; max-width: 100%; max-height: 360px; object-fit: contain; }
.media-stub { padding: 32px; color: var(--text-faint); font-size: 13px; }
.media-play {
  position: absolute; width: 48px; height: 48px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.media-play::after {
  content: ''; position: absolute; left: 19px; top: 15px;
  border: 9px solid transparent; border-left: 15px solid #fff; border-right: 0;
}
.media-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  font-size: 12px; color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.media-name {
  font-weight: 500; color: var(--text);
  max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.media-facts { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-warn { color: var(--danger); font-weight: 500; }
.media-acts { margin-left: auto; display: flex; gap: 2px; flex: none; }
.media-acts button {
  padding: 3px 8px; border-radius: var(--r-sm);
  font-size: 12px; color: var(--text-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.media-acts button:hover { background: var(--surface-hover); color: var(--text); }
.editor.is-dropping {
  outline: 2px dashed var(--accent); outline-offset: 10px; border-radius: var(--r-lg);
}

/* гуттер */
.gutter {
  position: absolute; display: none; gap: 1px;
  transform: translateY(-1px);
  z-index: 6;
}
.gutter.is-on { display: flex; }
.gutter-btn {
  width: 22px; height: 24px; display: grid; place-items: center;
  border-radius: var(--r-sm); color: var(--text-faint);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.gutter-btn:hover { background: var(--surface-hover); color: var(--text-muted); }
.gutter-btn[draggable="true"] { cursor: grab; }
.gutter-btn[draggable="true"]:active { cursor: grabbing; }

/* перетаскивание блоков */
.drop-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: var(--accent); border-radius: 2px;
  display: none; pointer-events: none; z-index: 8;
}
.drop-line.is-on { display: block; }
.drop-line::before {
  content: ''; position: absolute; left: -4px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.blk.is-dragging { opacity: 0.35; }

/* ── статусбар ───────────────────────────────────────── */
.statusbar {
  height: 38px; flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
  background: var(--bg);
}
.stat-spacer { flex: 1; }
.dot { color: var(--text-faint); }
.limit {
  width: 84px; height: 4px; border-radius: 999px;
  background: var(--surface-active); overflow: hidden;
}
.limit-fill {
  display: block; height: 100%; width: 0%;
  background: var(--accent); border-radius: 999px;
  transition: width var(--dur) var(--ease), background var(--dur) var(--ease);
}
.limit-fill.is-warn { background: var(--warn); }
.limit-fill.is-over { background: var(--danger); }
.stat.is-over { color: var(--danger); font-weight: 600; }

/* ── preview ─────────────────────────────────────────── */
.preview-head {
  flex: none; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; }
.tab {
  height: 28px; padding: 0 10px; border-radius: var(--r-md);
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover { background: var(--surface-hover); color: var(--text); }
.tab.is-active { background: var(--surface-active); color: var(--text); }
.preview-body { flex: 1; min-height: 0; display: flex; }
.tabpanel { display: none; flex: 1; min-height: 0; }
.tabpanel.is-active { display: flex; }

.code-out {
  flex: 1; margin: 0; padding: 14px 16px;
  overflow: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.65;
  white-space: pre-wrap; word-break: break-word; color: var(--text);
  tab-size: 2;
}

/* Telegram-подобный чат */
.tg-chat {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  background: linear-gradient(160deg, var(--tg-chat-bg-2), var(--tg-chat-bg));
}
.tg-channel {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--tg-panel);
  border-bottom: 1px solid var(--border);
}
.tg-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(140deg, #4facfe, #2f6fed);
  color: #fff; font-weight: 600; font-size: 15px;
}
.tg-channel-meta { display: flex; flex-direction: column; line-height: 1.25; }
.tg-channel-meta strong { font-size: 14px; font-weight: 600; }
.tg-channel-meta span { font-size: 11.5px; color: var(--text-muted); }

.tg-scroll { flex: 1; overflow-y: auto; padding: 14px 12px 20px; }
.tg-msg {
  max-width: 92%;
  background: var(--tg-bubble); color: var(--tg-bubble-fg);
  border-radius: 12px 12px 12px 4px;
  padding: 7px 10px 6px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  font-size: 15px; line-height: 1.42;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
  animation: bubble-in 220ms var(--ease) both;
}
@keyframes bubble-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } }
.tg-msg + .tg-msg { border-radius: 12px 12px 12px 4px; }
.tg-msg .tg-time {
  float: right; font-size: 11px; color: var(--tg-meta);
  margin: 6px -2px -2px 8px; user-select: none;
}
.tg-msg b { font-weight: 600; }
.tg-msg a { color: var(--tg-link); text-decoration: none; }
.tg-msg a:hover { text-decoration: underline; }
.tg-msg code {
  font-family: var(--font-mono); font-size: 0.87em;
  background: rgba(128, 128, 128, 0.18); border-radius: 4px; padding: 0.1em 0.3em;
}
.tg-msg pre {
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
  background: rgba(128, 128, 128, 0.16);
  border-radius: 6px; padding: 8px 10px; margin: 4px 0;
  overflow-x: auto; white-space: pre;
}
.tg-msg blockquote {
  margin: 3px 0; padding: 1px 0 1px 10px;
  border-left: 3px solid var(--tg-quote-bar); border-radius: 2px;
}
.tg-msg .tg-spoiler {
  background: currentColor; color: inherit; border-radius: 3px;
  opacity: 0.28; cursor: pointer; transition: opacity var(--dur) var(--ease);
  box-decoration-break: clone;
}
.tg-msg .tg-spoiler > span { visibility: hidden; }
.tg-msg .tg-spoiler.is-open { opacity: 1; background: none; }
.tg-msg .tg-spoiler.is-open > span { visibility: visible; }
/* медиа в пузыре */
.tg-media {
  display: grid; gap: 2px;
  border-radius: 8px; overflow: hidden;
  margin: -2px -5px 6px;
}
.tg-media[data-count="1"] { grid-template-columns: 1fr; }
.tg-media[data-count="2"] { grid-template-columns: 1fr 1fr; }
.tg-media[data-count="3"], .tg-media[data-count="4"] { grid-template-columns: 1fr 1fr; }
.tg-media-item {
  position: relative; margin: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: rgba(128, 128, 128, 0.2);
}
.tg-media[data-count="1"] .tg-media-item { max-height: 300px; }
.tg-media:not([data-count="1"]) .tg-media-item { aspect-ratio: 1 / 1; }
.tg-media-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tg-media[data-count="1"] img { max-height: 300px; object-fit: contain; }
.tg-media-stub { padding: 28px; font-size: 12px; color: var(--tg-meta); }
.tg-media-play {
  position: absolute; width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
}
.tg-media-play::after {
  content: ''; position: absolute; left: 16px; top: 12px;
  border: 8px solid transparent; border-left: 13px solid #fff; border-right: 0;
}
.tg-media-dur {
  position: absolute; left: 6px; top: 6px;
  padding: 1px 6px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.45); color: #fff; font-size: 11px;
}
.tg-media-warn {
  position: absolute; right: 6px; top: 6px;
  width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700;
}
.tg-copy {
  margin-left: auto;
  padding: 1px 7px; border-radius: var(--r-sm);
  font-size: 11px; color: var(--tg-link);
  transition: background var(--dur) var(--ease);
}
.tg-copy:hover { background: var(--surface-hover); }
.tg-msg-idx .is-over { color: var(--danger); font-weight: 600; }

/* Rich Message: заголовки и списки остаются собой */
.tg-msg.is-rich { white-space: normal; }
.rich-h { font-weight: 600; line-height: 1.3; margin: 10px 0 4px; }
.rich-h:first-child { margin-top: 0; }
.rich-h[data-size="1"] { font-size: 20px; }
.rich-h[data-size="2"] { font-size: 17px; }
.rich-h[data-size="3"] { font-size: 15.5px; }
.rich-p { margin: 0 0 8px; white-space: pre-wrap; }
.rich-p:last-child { margin-bottom: 0; }
.rich-list { margin: 0 0 8px; padding-left: 22px; }
.rich-list li { margin: 2px 0; }
.rich-list li .rich-p { margin: 0; }
.rich-quote {
  margin: 8px 0; padding: 2px 0 2px 10px;
  border-left: 3px solid var(--tg-quote-bar); border-radius: 2px;
}
.rich-pre {
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
  background: rgba(128, 128, 128, 0.16);
  border-radius: 6px; padding: 8px 10px; margin: 6px 0;
  overflow-x: auto; white-space: pre;
}
.rich-hr { height: 1px; background: currentColor; opacity: 0.2; margin: 12px 0; }
.rich-media {
  position: relative; margin: 8px 0; border-radius: 8px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: rgba(128, 128, 128, 0.2);
}
.rich-media img { width: 100%; max-height: 260px; object-fit: cover; display: block; }
.rich-media-acts {
  position: absolute; right: 6px; top: 6px;
  display: flex; gap: 4px;
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.rich-media:hover .rich-media-acts, .rich-media:focus-within .rich-media-acts { opacity: 1; }
.rich-media-acts button {
  padding: 3px 8px; border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.6); color: #fff;
  font-size: 11px; backdrop-filter: blur(3px);
}
.rich-media-acts button:hover { background: var(--accent); }
.tg-tip {
  margin: 8px 2px 0; padding: 9px 11px;
  border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12px; line-height: 1.5; color: var(--text-muted);
}
.tg-tip code { font-family: var(--font-mono); font-size: 11px; }
.tg-warn {
  margin: 8px 2px 0; padding: 8px 10px;
  border-radius: var(--r-md); background: var(--danger); color: #fff;
  font-size: 12px; line-height: 1.4;
}
.check.is-muted, .field.is-muted { opacity: 0.45; }
.hint-top {
  margin: -4px 0 12px; padding: 0 0 10px;
  border-top: 0; border-bottom: 1px solid var(--border);
}

.tg-empty {
  margin: 40px auto; max-width: 240px; text-align: center;
  color: var(--text-muted); font-size: 13px; line-height: 1.5;
}
.tg-msg-idx {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--tg-meta); margin: 0 0 5px 2px;
  letter-spacing: 0.02em;
}

.preview-foot {
  flex: none; display: flex; gap: 8px; padding: 10px;
  border-top: 1px solid var(--border); background: var(--bg);
}
.preview-foot .btn { height: 36px; flex: 1; justify-content: center; }

/* ── всплывашки ──────────────────────────────────────── */
.popover {
  position: fixed; z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  animation: pop-in 120ms var(--ease) both;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(4px) scale(0.98); } }

.fmtbar {
  position: fixed; z-index: 70;
  display: flex; align-items: center; gap: 1px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  animation: pop-in 120ms var(--ease) both;
}
.fb {
  min-width: 30px; height: 28px; padding: 0 7px;
  display: inline-flex; align-items: center; gap: 3px; justify-content: center;
  border-radius: var(--r-sm); font-size: 14px; color: var(--text);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.fb:hover { background: var(--surface-hover); }
.fb.is-on { color: var(--accent); background: var(--accent-soft); }
.fb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 3px; }

.linkpop { display: flex; gap: 6px; padding: 6px; align-items: center; }
.linkpop input {
  width: 260px; height: 28px; padding: 0 8px;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 13px; outline: none;
}
.linkpop input:focus { border-color: var(--accent); }

.menu { width: 268px; max-height: 340px; overflow-y: auto; padding: 6px; }
.menu-group { font-size: 11px; color: var(--text-faint); padding: 6px 8px 4px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 8px; border-radius: var(--r-md); text-align: left;
  transition: background var(--dur) var(--ease);
}
.menu-item:hover, .menu-item.is-active { background: var(--surface-hover); }
.menu-ico {
  width: 30px; height: 30px; flex: none; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text-muted); background: var(--bg);
}
.menu-txt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.menu-txt strong { font-size: 13.5px; font-weight: 500; }
.menu-txt span { font-size: 11.5px; color: var(--text-muted); }
.menu-key { margin-left: auto; font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); }

.settings { width: 320px; padding: 14px; }
.settings h2 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 13px; font-weight: 500; }
.field select {
  height: 32px; padding: 0 8px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--bg); font-size: 13.5px;
}
.field select:focus { border-color: var(--accent); outline: none; }
.check { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 10px; font-size: 13.5px; line-height: 1.4; cursor: pointer; }
.check input { margin: 2px 0 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.hint { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ── toast ───────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 90; padding: 9px 16px;
  background: var(--text); color: var(--bg);
  border-radius: 999px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-2);
  animation: toast-in 220ms var(--ease) both;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ── мобильный переключатель ─────────────────────────── */
.mobile-switch { display: none; }

@media (max-width: 900px) {
  body { overflow: auto; }
  .mobile-switch {
    display: flex; gap: 2px; padding: 6px 10px;
    border-bottom: 1px solid var(--border); background: var(--bg);
    position: sticky; top: 0; z-index: 15;
  }
  .ms-btn {
    flex: 1; height: 34px; border-radius: var(--r-md);
    font-size: 14px; font-weight: 500; color: var(--text-muted);
  }
  .ms-btn.is-active { background: var(--surface-active); color: var(--text); }
  .workspace { height: calc(100dvh - var(--topbar-h) - 47px); }
  .pane { display: none; flex: 1; width: 100% !important; }
  .pane.is-active { display: flex; }
  .pane-preview { border-left: 0; }
  .splitter { display: none; }
  .editor-shell { padding: 28px 20px 45vh; }
  .brand-text span { display: none; }
  .btn-label { display: none; }
  .doc-title { max-width: none; }
  .save-state { display: none; }
}

@media (max-width: 560px) {
  .editor-shell { padding: 20px 14px 45vh; }
  .preview-foot { padding: 8px; gap: 6px; }
  .preview-foot .btn { font-size: 13px; padding: 0 8px; }
  .statusbar { gap: 6px; padding: 0 12px; white-space: nowrap; }
  .statusbar .dot, #statMsgs { display: none; }
  .limit { width: 56px; }
  .gutter { display: none !important; }
  .blk[data-type="h1"] { font-size: 26px; }
  .blk[data-type="h2"] { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── публикация ботом ────────────────────────────────── */
.publish { width: 340px; padding: 14px; }
.publish .field small {
  font-size: 11.5px; color: var(--text-muted); line-height: 1.4;
}
.publish .field small a { color: var(--accent); }
.publish input[type="password"], .publish input[type="text"] {
  width: 100%; height: 32px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg); font-size: 13.5px;
}
.publish input:focus { border-color: var(--accent); outline: none; }
.field-row { display: flex; gap: 6px; align-items: center; }
.field-row input { flex: 1; min-width: 0; }
.publish code {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--code-bg); border-radius: 3px; padding: 0.1em 0.3em;
}
.publish-actions { display: flex; gap: 8px; margin: 4px 0 0; }
.publish-actions .btn { flex: 1; height: 34px; justify-content: center; }
.pub-status {
  margin: 10px 0 0; font-size: 12.5px; line-height: 1.45;
  color: var(--text-muted); min-height: 1em;
}
.pub-status.is-good { color: var(--success); }
.pub-status.is-bad { color: var(--danger); }
