:root {
  /* Палитра берётся из темы Telegram, с запасными значениями (тёмная Telegram-тема) */
  --bg: var(--tg-theme-bg-color, #0e1621);
  --bg-panel: var(--tg-theme-secondary-bg-color, #17212b);
  --bg-elev: #1e2c3a;
  --bg-hover: #242f3d;
  --border: #2b3a4a;
  --input-bg: #17212b;
  --text: var(--tg-theme-text-color, #e9eef4);
  --text-dim: var(--tg-theme-hint-color, #8a9aa9);
  --accent: var(--tg-theme-button-color, #2aabee);
  --accent-dark: #229ed9;
  --on-accent: var(--tg-theme-button-text-color, #fff);
  --danger: #e05c5c;
  --ok: #57c27a;
  --radius: 10px;
  --mono: "Cascadia Code", Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}


/* ── верхняя панель ───────────────────────── */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  padding-top: max(9px, env(safe-area-inset-top));
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

/* переключатель вида Editor / HTML — по центру топбара */
.view-toggle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-50% + env(safe-area-inset-top) / 2));
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.vt-btn {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 12px;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s;
}
.vt-btn.active { background: var(--accent); color: var(--on-accent, #fff); }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .3px;
  user-select: none;
}

.app-version {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-dim);
  opacity: .6;
  letter-spacing: 0;
  align-self: flex-end;
  padding-bottom: 1px;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-left { display: flex; align-items: center; gap: 4px; }

/* ── кнопки отмены / повтора ─────────────────── */
.hist-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.hist-btn:active { background: var(--bg-hover); }
@media (hover: hover) { .hist-btn:hover:not([disabled]) { background: var(--bg-hover); } }
.hist-btn[disabled] { opacity: .3; pointer-events: none; cursor: default; }

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: var(--on-accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: .15s;
  box-shadow: 0 2px 10px rgba(42, 171, 238, .25);
}
.send-btn:active { transform: scale(.96); }
.send-btn:disabled { opacity: .5; pointer-events: none; }

/* ── тулбар: аккордеон из категорий (Формат/Типы/Списки/Блоки) ───── */
.toolbar {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  max-height: 220px;
  overflow: hidden;
  transition: max-height .22s ease, opacity .22s ease;
}

/* полноэкранный режим редактора (двойной тап по верхней панели): прячем тулбар */
body.editor-full .toolbar {
  max-height: 0;
  opacity: 0;
  border-bottom-color: transparent;
}
body.editor-full .topbar { cursor: zoom-out; }

/* строка категорий-иконок — всегда одна линия, раскрытие горизонтальное (инлайн,
   в той же строке); если не влезает — горизонтальный скролл. */
.tb-cats {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 2px;
  padding: 4px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tb-cats::-webkit-scrollbar { display: none; }

.tb-cat-block {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

/* Кнопка категории — «вкладка» с рамкой и стрелкой раскрытия: визуально
   отличается от плоских кнопок-действий внутри раскрытой группы. */
.tb-cat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 36px;
  padding: 0 7px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  flex: 0 0 auto;
  transition: background .12s, color .12s, border-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.tb-cat:active { background: var(--bg-hover); transform: scale(.94); }
.tb-cat.active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* стрелка-индикатор «раскрывается»; в открытом состоянии переворачивается */
.tb-cat-caret { width: 8px; height: 5px; flex: 0 0 auto; opacity: .55; transition: transform .15s ease; }
.tb-cat.active .tb-cat-caret { transform: rotate(180deg); opacity: .9; }

@media (hover: hover) {
  .tb-cat:hover:not(.active) { background: var(--bg-hover); }
}

/* Раскрытие действий категории — аккордеон вправо, в той же строке.
   Кнопки лежат на «лотке»-подложке, примыкающем к активной вкладке, —
   так они читаются как содержимое категории, а не самостоятельные иконки. */
.tb-cat-actions {
  display: flex;
  align-items: center;
  gap: 1px;
  max-width: 0;
  margin-left: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width .2s ease, margin-left .2s ease, padding .2s ease,
              background .2s ease, border-color .2s ease;
}
.tb-cat-actions.open {
  max-width: 320px;
  margin-left: 3px;
  padding: 0 3px;
  background: rgba(42, 171, 238, .10);
  border-color: var(--border);
}
/* кнопки внутри лотка — чуть компактнее основного размера */
.tb-cat-actions .tb { height: 32px; min-width: 32px; border-radius: 7px; }

.tb {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background .12s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.tb:active { background: var(--bg-elev); transform: scale(.91); }
.tb.mono { font-family: var(--mono); font-size: 12.5px; }
.tb-chevron { width: 8px; height: 5px; margin-left: 2px; flex-shrink: 0; opacity: 0.6; }

@media (hover: hover) {
  .tb:hover { background: var(--bg-hover); }
  .send-btn:hover { filter: brightness(1.1); }
}

.tb.active {
  background: rgba(42, 171, 238, .18);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(42, 171, 238, .4);
}


/* ── медиа-блоки в тексте ───────────────────────── */
.editor .media-block {
  position: relative;   /* контекст для оверлея прогресса скачивания (.mb-dl-overlay) */
  margin: 10px 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px 10px;
  user-select: none;
}

.mb-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}
.mb-label {
  font-size: 11px;
  color: var(--accent);
  background: rgba(42, 171, 238, .1);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.mb-label-click { cursor: pointer; }
.mb-label-click:active { background: rgba(42, 171, 238, .22); }

/* интерактивные элементы карточки — над оверлеем выбора (z-index 4) */
.mb-ctl { position: relative; z-index: 6; }

/* тег типа со шевроном (клик — меню смены типа) */
.mb-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}
.mb-tag:active { background: rgba(42, 171, 238, .22); }
.mb-tag .mb-chev { opacity: .85; }

/* «+ Добавить медиа» */
.mb-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  color: var(--accent);
  background: rgba(42, 171, 238, .1);
  border-radius: 999px;
  padding: 2px 10px 2px 8px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.mb-add-btn:active { background: rgba(42, 171, 238, .22); }

/* На узких экранах кнопки-действия медиа-блока сжимаются до иконок (без подписи),
   чтобы не вылезать за пределы блока. На широких — с текстом. */
@media (max-width: 600px) {
  .mb-add-btn .mb-btn-label { display: none; }
  .mb-add-btn { gap: 0; padding: 3px 8px; }
}

/* «Заменить» и «Изменить» у одиночного медиа — видны только когда блок выбран */
.editor .media-block .mb-replace-btn,
.editor .media-block .mb-edit-btn { display: none; }
.editor .media-block.block-selected .mb-replace-btn,
.editor .media-block.block-selected .mb-edit-btn { display: inline-flex; }

/* корзина — удалить блок */
.mb-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  flex: 0 0 auto;
  transition: background .12s, color .12s;
}
.mb-del:active { background: var(--danger); color: #fff; }

/* выпадающее меню смены типа контейнера */
.mb-dropdown {
  position: absolute;
  z-index: 20;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
.mb-dropdown-item {
  text-align: left;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  border-radius: 7px;
  cursor: pointer;
}
.mb-dropdown-item:active { background: var(--bg-hover); }
.mb-dropdown-item.active { color: var(--accent); font-weight: 600; }

/* выпадающее меню выбора уровня заголовка (кнопка H на тулбаре) */
.heading-menu { min-width: 180px; max-height: 64vh; overflow-y: auto; }
.heading-menu .mb-dropdown-item { padding: 6px 12px; }
.heading-menu .hm-sample { margin: 0; line-height: 1.2; font-weight: 600; }
.heading-menu h1.hm-sample { font-size: 20px; }
.heading-menu h2.hm-sample { font-size: 18px; }
.heading-menu h3.hm-sample { font-size: 16.5px; }
.heading-menu h4.hm-sample { font-size: 15px; }
.heading-menu h5.hm-sample { font-size: 13.5px; }
.heading-menu h6.hm-sample { font-size: 12.5px; opacity: .82; }

/* мини-инпут подписи прямо в блоке */
.mb-caption-input {
  width: 100%;
  margin-top: 7px;
  padding: 6px 9px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  outline: none;
  box-sizing: border-box;
}

/* граничная строка перед первым нередактируемым блоком — невидима, только для позиционирования курсора */
.editor > .edge-guard {
  height: 0;
  min-height: 0;
  line-height: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
}

/* индикатор места вставки при перетаскивании блока */
.block-drop-indicator {
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  margin: 2px 0;
  pointer-events: none;
}

/* предупреждение о превышении лимита медиа в блоке */
.mb-warn {
  background: transparent;
  border: none;
  color: #e8b54a;
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex: 0 0 auto;
}
.mb-warn:active { opacity: .7; }

.mb-rm {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
.mb-rm:active { background: var(--danger); color: #fff; }

.mb-row { display: flex; gap: 8px; overflow-x: auto; }

/* превью во время загрузки: полупрозрачное → 100% когда файл загрузился */
.mb-uploading { opacity: .5; transition: opacity .3s ease; }

/* во время загрузки поднимаем ряд над оверлеем выбора, чтобы работал горизонтальный скролл */
.media-block[data-state="uploading"] .mb-row {
  position: relative;
  z-index: 5;
  touch-action: pan-x;
}

/* коллаж — мозаика как в посте Telegram */
.mb-grid {
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 110px;
  border-radius: 8px;
  overflow: hidden;
}
.mb-grid-1 { grid-template-columns: 1fr; grid-auto-rows: 200px; }
.mb-grid-2 { grid-template-columns: 1fr 1fr; }
.mb-grid-3 { grid-template-columns: 2fr 1fr; }
.mb-grid-3 .mb-item:first-child { grid-row: span 2; }
.mb-grid-4 { grid-template-columns: 1fr 1fr; }
.mb-grid .mb-item { width: 100%; height: 100%; }
.mb-grid .mb-thumb,
.mb-grid .mb-tile {
  width: 100%;
  height: 100%;
  max-width: none;
  min-width: 0;
  border-radius: 0;
}

.mb-item {
  position: relative;
  flex: 0 0 auto;
  /* подавляем нативное меню вебвью по лонг-тапу (сохранить изображение и т.п.) */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.mb-item .mb-thumb,
.mb-item .mb-tile {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none; /* клики/лонг-тап ловит обёртка .mb-item, а не сама картинка */
}
.mb-item.mb-drag-source { opacity: .3; }

/* «парящий» клон, едущий за пальцем */
.mb-drag-clone {
  position: fixed;
  margin: 0;
  z-index: 1000;
  pointer-events: none;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
  transform: scale(1.06);
  opacity: .96;
}
.mb-drag-clone .mb-item-rm { display: none; }
.mb-drag-clone .mb-thumb,
.mb-drag-clone .mb-tile {
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  object-fit: cover;
}

.mb-item-rm {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.mb-item-rm:active { background: var(--danger); }

.mb-thumb {
  height: 96px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  flex: 0 0 auto;
  max-width: 220px;
}
.mb-tile {
  height: 96px;
  min-width: 120px;
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 26px;
  flex: 0 0 auto;
  padding: 0 12px;
}
.mb-tile span {
  font-size: 10.5px;
  color: var(--text-dim);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── превью видео: первый кадр + значок play ── */
.mb-vwrap { position: relative; flex: 0 0 auto; display: inline-flex; }
.mb-vwrap .mb-thumb { display: block; }
.mb-grid .mb-vwrap { width: 100%; height: 100%; }
.mb-item .mb-vwrap { pointer-events: none; }
.mb-play-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.mb-play-badge svg { margin-left: 2px; }

/* кнопка «редактировать» на элементе коллажа/слайдшоу — под ✕ */
.mb-item-edit { top: 30px; font-size: 11px; }
.mb-item-edit:active { background: var(--accent); }

/* спойлер: размытое превью + активная кнопка-глазик */
.mb-spoiled, .mb-spoiled .mb-thumb { filter: blur(10px) saturate(.75); }
.mb-vwrap.mb-spoiled .mb-play-badge { display: none; }
.mb-item-eye:active { background: var(--accent); }
.mb-item-eye.mb-eye-on { background: var(--accent); }
.mb-eye-btn.mb-eye-on { background: var(--accent); color: var(--on-accent, #fff); }
.editor .media-block .mb-eye-btn { display: none; }
.editor .media-block.block-selected .mb-eye-btn { display: inline-flex; }

/* обрезка превью, чтобы блюр спойлера не выходил за скругления */
.mb-vwrap.mb-spoiled, .mb-item .mb-spoiled { overflow: hidden; border-radius: 8px; }
img.mb-spoiled { border-radius: 8px; }

/* ── редактор медиа (кроп / поворот / обрезка) ── */
.media-edit {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .5);
  animation: slideUp .2s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
/* контент не должен сжиматься при переполнении (иначе превью с фиксированной
   высотой вылезает поверх соседних строк) — вместо сжатия модалка скроллится */
.media-edit > * { flex: 0 0 auto; }
.me-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 15px;
}
.me-ttl-note {
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text-dim);
  background: rgba(42, 171, 238, .10);
  border: 1px solid rgba(42, 171, 238, .28);
  border-radius: 8px;
  padding: 7px 10px;
}
.me-close {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.me-close:active { background: var(--bg-hover); }
.me-stage { position: relative; display: flex; justify-content: center; min-height: 60px; }
.me-media-box {
  position: relative;
  border-radius: 10px;
  background: var(--bg);
  touch-action: none;
}
.me-media {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  object-fit: fill;
  border-radius: 10px;
  user-select: none;
  -webkit-user-drag: none;
}
/* индикатор загрузки превью */
.me-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  pointer-events: none;
}
.me-spin {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: me-spin .8s linear infinite;
}
@keyframes me-spin { to { transform: rotate(360deg); } }
/* затемнение вокруг кроп-рамки (4 прямоугольника вместо box-shadow) */
.me-dim {
  position: absolute;
  background: rgba(0, 0, 0, .55);
  pointer-events: none;
}
.me-crop {
  position: absolute;
  border: 2px solid var(--accent);
  cursor: move;
  box-sizing: border-box;
}
.me-grid-l { position: absolute; background: rgba(255, 255, 255, .35); pointer-events: none; }
.me-grid-v { top: 0; bottom: 0; width: 1px; }
.me-grid-h { left: 0; right: 0; height: 1px; }
.me-h {
  position: absolute;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
  box-sizing: border-box;
  transform: scale(.72);
}
.me-h-nw { left: -11px; top: -11px; cursor: nwse-resize; }
.me-h-ne { right: -11px; top: -11px; cursor: nesw-resize; }
.me-h-sw { left: -11px; bottom: -11px; cursor: nesw-resize; }
.me-h-se { right: -11px; bottom: -11px; cursor: nwse-resize; }
.me-controls { display: flex; flex-direction: column; gap: 10px; }
.me-row { display: flex; gap: 8px; }
.me-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  background: rgba(42, 171, 238, .12);
  color: var(--accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.me-btn:active { background: rgba(42, 171, 238, .25); }
.me-btn-ghost { background: var(--bg-hover); color: var(--text-dim); }
.me-btn-primary { background: var(--accent); color: var(--on-accent, #fff); }
.me-btn-primary:active { background: var(--accent-dark); }
.me-btn:disabled { opacity: .6; cursor: default; }
/* play-кнопка + таймкод */
.me-playrow { display: flex; align-items: center; gap: 12px; }
.me-play {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--on-accent, #fff);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
}
.me-play:active { background: var(--accent-dark); }
.me-play svg { margin-left: 1px; }
.me-time {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
}
.me-time b { color: var(--text); font-weight: 700; }
.me-time span { color: var(--text-dim); }

/* вкладки */
.me-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.me-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  background: none;
  border: none;
  border-radius: 9px;
  padding: 9px 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.me-tab.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}
.me-p { display: flex; flex-direction: column; gap: 10px; }
.me-p.hidden { display: none; }
.me-row-wrap { flex-wrap: wrap; }
.me-hint { font-size: 12px; color: var(--text-dim); }

/* чипы (аспекты, углы, флипы) */
.me-chip {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border: none;
  border-radius: 9px;
  background: var(--bg-hover);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.me-chip.active { background: var(--accent); color: var(--on-accent, #fff); }
.me-btn-on { box-shadow: inset 0 0 0 1.5px var(--accent); }
.me-sq {
  width: 36px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

/* филмстрип обрезки */
.met-strip {
  position: relative;
  height: 60px;
  margin-top: 26px;   /* место под пузырёк плейхеда */
  touch-action: none;
  user-select: none;
  cursor: pointer;
}
.met-tiles {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 10px;   /* шкала времени — внутри скобок окна обрезки */
  right: 10px;
  display: flex;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg);
}
.met-tile { flex: 1 1 0; width: 0; height: 100%; display: block; }
.met-shade {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(5, 10, 16, .68);
  pointer-events: none;
}
.met-shade-l { left: 0; width: 0; }
.met-shade-r { left: 100%; right: 0; }
.met-win {
  position: absolute;
  top: 0;
  bottom: 0;
  border: 2px solid var(--accent);
  border-left-width: 10px;
  border-right-width: 10px;
  border-radius: 10px;
  box-sizing: border-box;
  pointer-events: none;
}
.met-h {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: ew-resize;
}
.met-h::after {
  content: '';
  width: 3px;
  height: 18px;
  border-radius: 2px;
  background: var(--on-accent, #fff);
}
.met-h-l { left: -12px; }
.met-h-r { right: -12px; }
.met-ph {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  transform: translateX(-1px);
  pointer-events: none;
}
.met-ph-bub {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--on-accent, #fff);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 7px;
  white-space: nowrap;
}
.met-stats { display: flex; gap: 8px; }
.met-stat {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
.met-stat span {
  display: block;
  font-size: 10px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.met-stat b { font-size: 14px; font-variant-numeric: tabular-nums; }

/* звук */
.mes-volrow { display: flex; align-items: center; gap: 12px; }
.mes-vol { flex: 1; accent-color: var(--accent); }
.mes-vol:disabled { opacity: .35; }
.me-btn:disabled { opacity: .45; cursor: default; }
.mes-noaudio { flex: 1; font-size: 12.5px; color: var(--text-dim); text-align: center; }
/* звуковая волна аудио на полосе обрезки */
.met-wave { flex: 1 1 0; width: 0; height: 100%; display: block; }
.mes-vol-label {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  width: 44px;
  text-align: right;
  flex: 0 0 auto;
}
.me-size-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--bg);
  overflow: hidden;
}
.me-size-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .2s ease; }
.me-size-over .me-size-fill { background: var(--danger); }
.me-size-label { font-size: 12px; color: var(--text-dim); margin-top: 5px; }
.me-size-over .me-size-label { color: var(--danger); }
.me-actions { display: flex; justify-content: flex-end; gap: 8px; }

.mb-row.mb-clickable { cursor: pointer; }

/* ── пустой медиа-блок (плейсхолдер-дропзона) ── */
.editor .media-block.mb-empty { border-style: dashed; }
.mb-empty-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 22px 14px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-dim);
  text-align: center;
}
.mb-empty-ic { color: var(--accent); opacity: .85; }
.mb-empty-title { font-size: 13px; color: var(--text); font-weight: 500; }
.mb-empty-hint { font-size: 11px; color: var(--text-dim); }
.mb-empty-actions { display: flex; gap: 8px; margin-top: 4px; }
.mb-empty-btn {
  font-size: 12px;
  color: var(--accent);
  background: rgba(42, 171, 238, .1);
  border: 1px solid rgba(42, 171, 238, .35);
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer;
}
.mb-empty-btn:active { background: rgba(42, 171, 238, .22); }

/* прогресс загрузки */
.mb-progress {
  margin-top: 9px;
  height: 5px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}
.mb-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  transition: width .15s linear;
}
.mb-progress-text { font-size: 11.5px; color: var(--text-dim); margin-top: 5px; }

/* оверлей прогресса скачивания видео по ссылке (yt-dlp) — поверх медиа-блока */
.mb-dl-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border-radius: inherit;
  background: color-mix(in srgb, var(--bg-panel) 82%, transparent);
  backdrop-filter: blur(2px);
}
.mb-dl-card { width: 100%; max-width: 320px; }
.mb-dl-label { font-size: 12.5px; color: var(--text); margin-bottom: 8px; text-align: center; }
.mb-dl-card .mb-progress { margin-top: 0; }

.mb-caption { font-size: 12px; color: var(--text-dim); margin-top: 7px; font-style: italic; cursor: pointer; }
.mb-caption:active { color: var(--text); }

/* подсказка «добавить подпись» */
.mb-caption-add {
  font-size: 12px;
  color: var(--accent);
  margin-top: 7px;
  cursor: pointer;
  user-select: none;
}
.mb-caption-add:active { opacity: .7; }

/* Шторка-меню (openSheet) должна перекрывать и полноэкранные экраны
   (Настройки/Профиль, .screen z-index:90) — иначе, например, окно выбора
   тарифа подписки открывалось ПОЗАДИ настроек и было не видно. */
.overlay.media-menu-ov { z-index: 150; }

/* ── окно предложения Premium подписки (3 тарифа колонками) ── */
.overlay.sub-offer-ov { z-index: 150; place-items: center; }
.sub-offer-modal {
  width: min(92vw, 400px);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
}
.sub-offer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.sub-offer-title { font-size: 17px; font-weight: 700; }
.sub-offer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-dim);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sub-offer-close:active { background: var(--border); color: var(--text); }
.sub-offer-hint { font-size: 13.5px; color: var(--text-dim); line-height: 1.45; }
.sub-offer-pick { font-size: 13.5px; margin: 10px 0 12px; font-weight: 500; }
.sub-offer-plans {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.sub-offer-plan {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.sub-offer-plan-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.sub-offer-buy {
  width: 100%;
  padding: 7px 4px;
  font-size: 13.5px;
  white-space: nowrap;
}

/* меню действий медиа-блока */
.media-menu {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .5);
  animation: slideUp .2s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.media-menu-item {
  font: inherit;
  font-size: 15px;
  text-align: center;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.media-menu-item:active { background: var(--bg-hover); }
.media-menu-item.danger { color: var(--danger); }
.media-menu-item.cancel { color: var(--text-dim); font-weight: 600; margin-top: 4px; }
.media-menu-title { font-size: 12.5px; color: var(--text-dim); text-align: center; padding: 10px 12px 6px; line-height: 1.4; }

/* ── пикер эмодзи (компактный поповер под строкой) ───────────── */
.emoji-layer { position: fixed; inset: 0; z-index: 60; }
.emoji-layer.hidden { display: none; }

.emoji-caret {
  position: fixed;
  width: 2px;
  min-height: 18px;
  background: var(--accent);
  border-radius: 1px;
  pointer-events: none;
  z-index: 59;
  animation: emoji-caret-blink .9s step-end infinite;
  transform: translateX(-1px);
}
.emoji-caret.hidden { display: none; }
@keyframes emoji-caret-blink { 0%,100%{opacity:1} 50%{opacity:0} }
.emoji-grid.hidden, .emoji-custom.hidden { display: none; }
.emoji-pop {
  position: fixed;
  width: min(300px, calc(100vw - 16px));
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.emoji-drag-handle {
  display: flex; justify-content: center; align-items: center;
  padding: 5px 0 7px; cursor: grab; touch-action: none; user-select: none;
}
.emoji-drag-handle:active { cursor: grabbing; }
.emoji-drag-pill {
  width: 32px; height: 4px; border-radius: 2px;
  background: var(--border);
}
.emoji-pop-body { padding: 8px; }
.emoji-search-wrap {
  position: relative;
  margin-bottom: 6px;
}
.emoji-search-wrap.hidden { display: none; }
.emoji-search-icon {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-dim); pointer-events: none;
}
.emoji-search {
  display: block; width: 100%; box-sizing: border-box;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font: inherit; font-size: 14px;
  padding: 7px 10px 7px 30px;
  outline: none;
}
.emoji-search:focus { border-color: var(--accent); }
.emoji-no-results {
  text-align: center; padding: 16px 8px 8px;
  font-size: 13px; color: var(--text-dim);
}
.emoji-no-results.hidden { display: none; }

.emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  max-height: 168px;
  overflow-y: auto;
}
.emoji-cell {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.emoji-cell:active { background: var(--bg-hover); }
.emoji-cell img, .emoji-cell video { width: 26px; height: 26px; object-fit: contain; display: block; margin: auto; }

.emoji-custom-saved {
  display: flex; flex-wrap: wrap; gap: 1px;
  max-height: 168px; overflow-y: auto;
}
.emoji-custom-saved.hidden { display: none; }
.emoji-cell-wrap { position: relative; display: inline-flex; }
.emoji-cell.pressing {
  transform: scale(0.75);
  background: rgba(220, 53, 69, .18);
  transition: transform .6s ease-in, background .3s;
}
.emoji-custom-form.hidden { display: none; }
.emoji-custom .hint { margin-bottom: 8px; font-size: 12px; }
.emoji-custom-row { display: flex; gap: 6px; margin-bottom: 8px; overflow: hidden; }
.emoji-custom-row input {
  flex: 1;
  min-width: 0;
  margin: 0;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 9px 11px;
  outline: none;
}
.emoji-custom-row input:focus { border-color: var(--accent); }
#emojiCustomFallback { flex: 0 0 52px; text-align: center; }
#emojiCustomInsert { width: 100%; }

.emoji-tabs {
  display: flex; align-items: center;
  border-top: 1px solid var(--border);
}
.emoji-tab {
  flex: 1;
  padding: 11px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.emoji-tab.active { color: var(--accent); font-weight: 600; }
.emoji-nav-del {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: 0 0 auto;
  border: none; background: transparent;
  color: var(--danger, #e53935);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.emoji-nav-del:active { opacity: .6; }

/* ── текстовые элементы rich messages ───────────────────────── */
.editor h1 { font-size: 1.55em; margin: 10px 0 6px; line-height: 1.3; }
.editor h2 { font-size: 1.32em; margin: 9px 0 5px; line-height: 1.3; }
.editor h3 { font-size: 1.15em; margin: 8px 0 4px; line-height: 1.3; }
.editor h4 { font-size: 1.08em; margin: 7px 0 4px; line-height: 1.3; }
.editor h5 { font-size: 1.0em;  margin: 7px 0 4px; line-height: 1.3; }
.editor h6 { font-size: 0.92em; margin: 7px 0 4px; line-height: 1.3; opacity: .82; }

.editor > p,
.editor > div:not([contenteditable]) { margin: 0 0 10px; }
.editor > p:last-child,
.editor > div:not([contenteditable]):last-child { margin-bottom: 0; }
.editor ul, .editor ol { padding-left: 26px; margin: 8px 0; }
.editor li { margin: 2px 0; }

/* Чекбокс в МАРКИРОВАННОМ списке заменяет буллет: убираем маркер, чекбокс
   ставим слева «висячим отступом» (padding-left + отрицательный text-indent),
   а не position:absolute — так чекбокс в потоке (каретка встаёт после него),
   а перенос строки выравнивается по левому краю. 22px = чекбокс(16)+отступ(6).
   В НУМЕРОВАННОМ списке номер сохраняем — чекбокс идёт после цифры/буквы. */
.editor ul > li[data-checked] { list-style: none; padding-left: 22px; text-indent: -22px; }
/* Маркированный чекбокс-список: маркера нет, поэтому убираем зарезервированный
   под него отступ <ul> — чекбоксы прижимаются к левому краю (список у нас
   однородный: если в <ul> есть чекбокс-пункт, то все пункты чекбоксы). */
.editor ul:has(> li[data-checked]) { padding-left: 3px; }
.editor ol > li[data-checked] { text-indent: 0; }
.editor ol > li[data-checked] .tg-checkbox { margin-left: 2px; }
.editor li[data-checked] .tg-checkbox {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid var(--text-dim);
  margin-right: 6px; vertical-align: -2px; cursor: pointer; flex-shrink: 0; text-indent: 0;
  background: transparent; box-sizing: border-box; transition: background .15s, border-color .15s;
}
.editor li[data-checked="true"] .tg-checkbox {
  background: var(--accent, #2aabee); border-color: var(--accent, #2aabee);
}
.editor li[data-checked="true"] .tg-checkbox::after {
  content: ''; display: block;
  width: 4px; height: 7px; border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(40deg) translate(-1px, -1px);
}
.editor li[data-checked="true"] { opacity: .6; }

.editor hr { border: none; height: 17px; margin: 10px 0; background: linear-gradient(transparent calc(50% - 0.5px), var(--border) calc(50% - 0.5px), var(--border) calc(50% + 0.5px), transparent calc(50% + 0.5px)); }

.editor footer {
  font-size: .86em;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 6px;
  margin-top: 10px;
  margin-bottom: 10px;
}

.editor mark {
  background: rgba(255, 214, 79, .35);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.editor .tg-math {
  display: inline-block;
  vertical-align: middle;
  background: rgba(120, 200, 120, .12);
  border-radius: 4px;
  padding: 0 3px;
  color: #9fdfa8;
  /* Атом не участвует в текстовом выделении — иначе мобильный каретка-драг
     цепляет его и роняет фокус редактора. Каретка скользит по ZWSP вокруг. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
  cursor: default;
}

.editor .tg-time {
  background: rgba(42, 171, 238, .12);
  border-radius: 4px;
  padding: 0 4px;
  color: #6ec5f2;
  border-bottom: 1px dashed rgba(42, 171, 238, .5);
  /* см. .tg-math — дата тоже неделимый атом, не выделяется как текст */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
  cursor: default;
}

.mark-ic {
  background: rgba(255, 214, 79, .35);
  border-radius: 3px;
  padding: 0 4px;
  font-weight: 600;
}

/* ── таблицы ───────────────────────── */
.editor table { border-collapse: collapse; margin: 0; font-size: .92em; width: 100%; }
.editor th, .editor td { border: 1px solid var(--border); padding: 6px 12px; min-width: 60px; }
.editor th { background: var(--bg-panel); font-weight: 600; text-align: left; }
/* границы вкл/выкл по data-bordered (по умолчанию есть — базовое правило выше) */
.editor table[data-bordered="false"] th, .editor table[data-bordered="false"] td { border: none; }
/* полосатость строк по data-striped */
.editor table[data-striped="true"] tr:nth-child(even) td { background: rgba(255, 255, 255, .07); }
/* выравнивание содержимого ячеек — атрибут align на самой ячейке (по ячейкам) */
.editor th[align="center"], .editor td[align="center"] { text-align: center; }
.editor th[align="right"], .editor td[align="right"] { text-align: right; }
/* подсветка текущей (с кареткой) ячейки */
.editor th.cell-active, .editor td.cell-active { outline: 2px solid var(--accent); outline-offset: -2px; background: rgba(42, 171, 238, .10); }
/* блок-выделение нескольких ячеек (как в Excel): drag / Ctrl+click / лонг-тап */
.editor th.cell-sel, .editor td.cell-sel { background: rgba(42, 171, 238, .28); }
.editor th.cell-sel.cell-active, .editor td.cell-sel.cell-active { background: rgba(42, 171, 238, .28); }
/* во время блок-выделения гасим нативную подсветку текста и нативный скролл внутри ячеек */
.editor table.cells-selecting { -webkit-user-select: none; user-select: none; touch-action: none; }
/* при удержании (до срабатывания лонг-тапа) запрещаем системное выделение текста и callout,
   иначе ОС начинает своё выделение и перехватывает палец, не давая войти в режим выбора ячеек */
.editor table.cells-armed { touch-action: none; }
.editor table.cells-armed,
.editor table.cells-armed th,
.editor table.cells-armed td { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* блок-обёртка таблицы с контролами */
.tbl-block { position: relative; margin: 20px 0; padding-top: 22px; padding-right: 30px; padding-bottom: 30px; }
.tbl-block .tbl-scroll { overflow-x: auto; }
.tbl-ctl {
  position: absolute;
  z-index: 5; /* выше overlay выбора блока (z-index: 4) */
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .12s, color .12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  /* none — иначе браузер на мобиле трактует движение пальца как скролл и шлёт
     pointercancel ДО срабатывания лонг-пресса (380мс), и перетаскивание слетает */
  touch-action: none;
}
.tbl-ctl:active { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (hover: hover) { .tbl-ctl:hover { background: var(--bg-hover); color: var(--text); } }
.tbl-add-col { top: 22px; right: 0; width: 24px; bottom: 30px; border-radius: 8px; font-size: 18px; }
.tbl-add-row { left: 0; bottom: 0; right: 30px; height: 24px; border-radius: 8px; font-size: 18px; }
.tbl-menu { right: 0; bottom: 0; width: 24px; height: 24px; border-radius: 8px; font-size: 15px; }
.tbl-ctl.tbl-dragging { background: var(--accent); color: #fff; border-color: var(--accent); font-size: 14px; letter-spacing: 1px; touch-action: none; }

/* dropdown настроек таблицы (⋮) */
.tbl-dropdown {
  position: fixed;
  background: var(--panel, var(--bg-elev));
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
  padding: 4px 0;
  z-index: 200;
  min-width: 170px;
}
.tbl-dd-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  user-select: none;
}
.tbl-dd-row:active { background: var(--bg-hover); }
@media (hover: hover) { .tbl-dd-row:hover { background: var(--bg-hover); } }
.tbl-dd-row input[type="checkbox"] { cursor: pointer; width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--accent); }

/* Заголовок таблицы (сверху) — по цветам как метка языка блока кода. Редактируется
   инлайн. position:absolute над зарезервированным padding-top; z-index:5 — кликать
   поверх overlay блока (z-index:4). */
.tbl-title,
.tbl-title-input {
  position: absolute;
  left: 2px;
  z-index: 5;
  box-sizing: border-box;
  max-width: calc(100% - 34px);
}
.tbl-title {
  top: 4px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tbl-title.tbl-title-empty { opacity: .55; }
.tbl-title-input {
  top: 1px;
  width: 240px;
  font-size: 11px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 6px;
  outline: none;
}

/* заблокированные кнопки тулбара внутри ячейки таблицы */
.tb.tb-cell-blocked,
.add-action.tb-cell-blocked { opacity: 0.35; pointer-events: none; }

/* пикер размера таблицы */
.tbl-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  max-width: 240px;     /* компактные ячейки ~44px, иначе при 5 столбцах они огромные */
  margin: 0 auto 10px;
  touch-action: none;
}
.tbl-grid-cell {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-panel);
  transition: background .08s, border-color .08s;
}
.tbl-grid-cell.on { background: var(--accent); border-color: var(--accent); }
.tbl-modal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.tbl-modal-head h2 { margin-bottom: 8px; }
.tbl-size-label { text-align: center; font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.tbl-modal-head .tbl-size-label { margin-bottom: 0; }
.tbl-size-inputs { display: flex; align-items: flex-end; justify-content: center; gap: 12px; margin-bottom: 14px; }
.tbl-size-field { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.tbl-size-fieldlabel { font-size: 11.5px; color: var(--text-dim); }
.tbl-size-inputs input {
  width: 72px; text-align: center; padding: 8px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font: inherit; font-size: 14px; outline: none;
}
.tbl-size-inputs input:focus { border-color: var(--accent); }
.tbl-size-x { color: var(--text-dim); font-size: 14px; padding-bottom: 10px; }
.tbl-opt-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.tbl-stripe-row { justify-content: flex-start; cursor: pointer; }
.tbl-opt-label { font-size: 13.5px; color: var(--text); }
.tbl-seg { display: flex; gap: 4px; flex-wrap: wrap; }
.tbl-seg button {
  padding: 6px 9px; background: var(--bg); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 7px; font: inherit; font-size: 12px; cursor: pointer;
  transition: border-color .12s, color .12s;
}
.tbl-seg button.active { border-color: var(--accent); color: var(--accent); }
/* специфичность выше, чем у .modal input { width:100% } — иначе чекбокс растягивается */
.modal input.tbl-switch { width: 20px; height: 20px; min-width: 0; accent-color: var(--accent); cursor: pointer; flex: 0 0 auto; margin: 0; padding: 0; }

/* плавающее меню выравнивания ячейки */
.cell-align-bar {
  position: fixed;
  z-index: 30;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
.cell-align-bar.hidden { display: none; }
.cell-align-bar button {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 6px;
  color: var(--text-dim); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cell-align-bar button.active { background: rgba(42, 171, 238, .18); color: var(--accent); }
.cell-align-bar button:active { background: var(--bg-hover); }
.cell-align-bar .cab-div { width: 1px; align-self: stretch; margin: 2px 3px; background: var(--border); }
.cell-align-bar button.cab-off { display: none; }

/* плавающее меню типа нумерации (нумерованный список) */
.list-type-bar {
  position: fixed;
  z-index: 30;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
.list-type-bar.hidden { display: none; }
.list-type-bar button {
  min-width: 30px; height: 30px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 6px;
  color: var(--text-dim); cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.list-type-bar button.active { background: rgba(42, 171, 238, .18); color: var(--accent); }
.list-type-bar button:active { background: var(--bg-hover); }

/* ── плавающий тулбар при выделении текста ─── */
.sel-fmt-bar {
  position: fixed;
  z-index: 200;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1px;
  padding: 3px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .5);
  pointer-events: auto;
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.sel-fmt-bar::-webkit-scrollbar { display: none; }
.sel-fmt-bar.hidden { display: none; }

/* ── Кастомное контекстное меню (правый клик в редакторе) ── */
.ctx-menu {
  position: fixed;
  z-index: 300;
  min-width: 168px;
  padding: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .55);
  display: flex;
  flex-direction: column;
}
.ctx-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.ctx-menu-item:hover { background: var(--bg-hover); }
.ctx-menu-item:disabled { opacity: .35; cursor: default; }
.ctx-menu-item:disabled:hover { background: none; }
.ctx-menu-key { color: var(--text-dim); font-size: 12px; }
.ctx-menu-div { height: 1px; background: var(--border); margin: 4px 2px; }

/* ── Авто-ссылки: @mention #hashtag $cashtag /command ── */
.editor .tg-auto-link {
  color: #c08bff;          /* отличается от обычных ссылок (синие) */
  cursor: pointer;
}
/* «снятое» (экранированное) — выглядит как обычный текст, но кликабельно для возврата */
.editor .tg-no-autolink { cursor: pointer; }

.al-popup {
  position: fixed;
  z-index: 300;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .55);
  padding: 3px;
}
.al-popup-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.al-popup-btn:hover { background: var(--bg-hover); }
.al-popup-btn svg { flex: 0 0 auto; }
.sfb {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 7px;
  color: var(--text); cursor: pointer; font: inherit; font-size: 14px;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.sfb.mono { font-family: var(--mono); font-size: 11px; }
.sfb b { font-weight: 800; font-size: 15px; }
.sfb i { font-style: italic; }
.sfb u { text-decoration: underline; }
.sfb s { text-decoration: line-through; }
.sfb:active, .sfb.active { background: rgba(42, 171, 238, .18); color: var(--accent); }
.sfb-sep {
  width: 1px; height: 20px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

/* ── пул-цитата ───────────────────────── */
.editor aside {
  position: relative;
  border: none;
  background: #21374A;
  border-radius: 10px;
  padding: 12px 42px;   /* поля под кавычки слева/справа */
  margin: 10px 0;
  font-style: italic;
  font-size: 1.05em;
  text-align: center;
}
/* декоративные кавычки: слева-сверху и справа-снизу */
.editor aside::before,
.editor aside::after {
  position: absolute;
  color: #65BDF3;
  font-size: 1.5em;
  font-style: normal;
  line-height: 1;
  pointer-events: none;
}
.editor aside::before { content: "\275D"; top: 10px; left: 14px; }
.editor aside::after  { content: "\275E"; bottom: 10px; right: 14px; }
.editor aside > footer.aside-author {
  display: block;
  font-size: .78em;
  font-style: normal;
  color: #65BDF3;
  border-top: none;   /* переопределяем общий .editor footer — тут не настоящий футер поста */
  padding-top: 0;
  margin-top: 6px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
/* мини-инпут автора цитаты прямо в блоке (как подпись у медиа) */
.aside-author-input {
  width: 100%;
  padding: 4px 8px;
  font: inherit;
  font-size: .78em;
  font-style: normal;
  text-align: center;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 7px;
  outline: none;
}

/* ── якорь, сноска, формула-блок, карта ───────────────────────── */
.editor .anchor-block {
  display: flex;
  align-items: center;
  padding: 1px 0;
  margin: 8px 0;
  line-height: 1;
}
.editor .tg-anchor {
  font-size: .78em;
  color: var(--text-dim);
  background: var(--bg-panel);
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  user-select: none;
}

.editor .tg-reference {
  font-size: .85em;
  color: var(--text-dim);
  border-top: 1px dashed var(--border);
  padding-top: 5px;
  margin-top: 8px;
}
.editor .tg-reference::before {
  content: "[" attr(data-name) "] ";
  color: var(--accent);
  font-family: var(--mono);
  font-size: .9em;
}

.editor .tg-math-block {
  position: relative;
  background: rgba(120, 200, 120, .07);
  border: 1px solid rgba(120, 200, 120, .25);
  border-radius: var(--radius);
  padding: 14px;
  margin: 10px 0;
  text-align: center;
  user-select: none;
}
.editor .tg-math-block .math-body {
  color: #9fdfa8;
  overflow: visible;
}
.editor .tg-math-block .math-body .katex-display { margin: 0; }
.editor .tg-math-block .math-rm { position: absolute; top: 6px; right: 6px; }

.editor .tg-map-block {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px 10px;
  margin: 10px 0;
  user-select: none;
}
.editor .tg-map-block .map-body {
  height: 160px;
  border-radius: 8px;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
.map-preview-grid {
  position: absolute;
}
.map-preview-grid img {
  position: absolute;
  width: 256px; height: 256px;
  display: block; pointer-events: none;
  user-select: none; -webkit-user-drag: none;
}
.map-preview-pin {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -100%);
  pointer-events: none;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,.55));
  z-index: 1;
}
[data-scheme="dark"] .map-preview-grid img {
  filter: brightness(.85) invert(1) hue-rotate(180deg) saturate(1.1);
}
.map-osm-attr {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: 9px;
  line-height: 1.3;
  background: rgba(255,255,255,.78);
  padding: 1px 4px;
  border-radius: 2px;
  z-index: 2;
  pointer-events: none;
  color: #333;
}
.map-osm-attr a { color: #0078a8; pointer-events: none; text-decoration: none; }
[data-scheme="dark"] .map-osm-attr {
  background: rgba(0,0,0,.55);
  color: var(--text-dim);
}
[data-scheme="dark"] .map-osm-attr a { color: var(--accent); }

/* ── редактор ───────────────────────── */
.editor-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;      /* редактор стоит вертикально и растёт по содержимому */
  justify-content: flex-start;
  padding: 18px 16px;
  -webkit-overflow-scrolling: touch;
  position: relative;
  scroll-padding-bottom: 64px;
}
.editor-wrap.drag-over::after {
  content: '';
  position: fixed; inset: 0; z-index: 999; pointer-events: none;
  background: rgba(42, 171, 238, .08);
  border: 2.5px dashed rgba(42, 171, 238, .6);
  border-radius: var(--radius);
  margin: 4px;
}
.editor-drop-label {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  z-index: 1000; pointer-events: none;
  background: rgba(42,171,238,.92); color: #fff;
  padding: 8px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  white-space: nowrap;
  opacity: 0; transition: opacity .15s;
}
.editor-wrap.drag-over .editor-drop-label { opacity: 1; }
/* Когда курсор над конкретным медиа-блоком — общую подсветку «новый блок» гасим,
   подсвечивается сам блок (см. .mb-drop-target). */
.editor-wrap.drag-over.drag-into-block::after { opacity: 0; }
.editor-wrap.drag-over.drag-into-block .editor-drop-label { opacity: 0; }

/* подсветка медиа-блока как цели для drop «добавить сюда» */
.editor .media-block.mb-drop-target {
  outline: 2.5px dashed var(--accent);
  outline-offset: 2px;
  background: rgba(42, 171, 238, .12);
}

.block-handle {
  position: fixed;
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 28px;
  transform: translateY(-50%);
  cursor: grab;
  color: var(--text-dim);
  opacity: .4;
  touch-action: none;
  z-index: 10;
  border-radius: 4px;
  transition: opacity .15s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.block-handle:hover, .block-handle.active { opacity: .9; color: var(--accent); }
.block-handle.dragging { cursor: grabbing; opacity: 0; }

/* быстрое удаление выделенного блока (справа) */
.block-delete {
  position: fixed;
  display: none;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  transform: translateY(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  cursor: pointer;
  z-index: 10;
  transition: background .12s, color .12s;
  -webkit-tap-highlight-color: transparent;
}
.block-delete:active { background: var(--danger); color: #fff; border-color: var(--danger); }
@media (hover: hover) { .block-delete:hover { color: var(--danger); border-color: var(--danger); } }

/* ── HTML-режим: textarea + overlay подсветки синтаксиса ── */
.html-editor-wrap {
  flex: 1;
  align-self: stretch;
  position: relative;
  min-height: 240px;
  min-width: 0;
}
.html-editor-wrap.hidden { display: none; }

/* Общий шрифт/метрики для обоих слоёв — ДОЛЖНЫ совпадать точно */
.html-highlight,
.html-source {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: break-word;
  -webkit-text-size-adjust: 100%;
  letter-spacing: 0;
}

/* Нижний слой: подсвеченный HTML */
.html-highlight {
  z-index: 0;
  overflow: hidden;           /* прокрутка управляется textarea */
  scrollbar-width: none;
  pointer-events: none;
  border: none;
  outline: none;
  color: var(--text);
  background: transparent;
}
.html-highlight::-webkit-scrollbar { display: none; }

/* Верхний слой: textarea для редактирования */
.html-source {
  z-index: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: transparent;           /* текст скрыт — виден только курсор */
  caret-color: var(--text);
  -webkit-text-fill-color: transparent;
}
.html-source::placeholder {
  color: var(--text-dim);
  -webkit-text-fill-color: var(--text-dim);
}

/* Токены подсветки */
.hl-comment { color: #6a8a96; font-style: italic; }
.hl-tn      { color: #e07b8a; }   /* tag name        */
.hl-an      { color: #d4a96a; }   /* attribute name  */
.hl-av      { color: #89c882; }   /* attribute value */
.hl-p       { color: #7a90a0; }   /* punctuation < > = / */

.editor.hidden { display: none; }
.editor-overlay.hidden { display: none; }

/* ── оверлей выбора блоков ── */
.editor-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  /* height задаётся через JS (ResizeObserver по editor), чтобы покрыть весь прокручиваемый контент */
  min-height: 100%;
  z-index: 4;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ── выделенный блок ── */
.block-selected {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px rgba(42, 171, 238, 0.38);
  border-radius: 3px;
}

.editor {
  width: 100%;
  max-width: none;
  /* растём по содержимому (в flex-колонке .editor-wrap), но заполняем всю высоту,
     когда текста мало — чтобы вся область оставалась кликабельной. Без flex:1 0 auto
     редактор растягивался до высоты контейнера, а контент вылезал за его рамку —
     из-за чего padding-bottom не давал места под последней строкой. */
  flex: 1 0 auto;
  padding-left: 26px;
  padding-right: 38px; /* место под корзину справа: зазор до кнопки 8px */
  min-height: 240px;
  outline: none;
  font-size: 16.5px;
  line-height: 1.25;
  caret-color: var(--accent);
  word-break: break-word;
  /* нижняя сейф-зона: высота клавиатуры (--kb-inset) + большой запас, чтобы
     последнюю строку можно было прокрутить заметно выше нижней панели/клавиатуры
     (пустая прокручиваемая область под текстом) */
  padding-bottom: calc(var(--kb-inset, 0px) + max(220px, 45vh));
}

.editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  pointer-events: none;
}

.editor a {
  color: var(--accent);
  text-underline-offset: 3px;
  -webkit-touch-callout: none;
  -webkit-user-select: text;
  user-select: text;
  cursor: text;
  -webkit-user-drag: none;
}
/* Единая подсветка выделения во всём редакторе: ссылки выделяются так же,
   как обычный текст (иначе синяя ссылка выглядела отдельным блоком). */
.editor ::selection {
  background: var(--accent);
  color: #fff;
}
.editor ::-moz-selection {
  background: var(--accent);
  color: #fff;
}

.editor code {
  font-family: var(--mono);
  font-size: .88em;
  background: rgba(42, 171, 238, .12);
  color: #6ec5f2;
  padding: 1.5px 6px;
  border-radius: 5px;
}

.editor pre {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  padding-top: 28px;   /* всегда резервируем место под метку языка */
  margin: 10px 0;
  white-space: pre-wrap;
  position: relative;
}
/* Метка языка (клик — правка инлайн). Показываем всегда: имя языка или плейсхолдер. */
.editor pre::after {
  content: attr(data-language);
  position: absolute;
  top: 7px;
  right: 10px;
  font-size: 10.5px;
  color: var(--text-dim);
  cursor: pointer;
  text-transform: lowercase;
}
.editor pre:not([data-language])::after,
.editor pre[data-language=""]::after {
  content: "язык ▾";
  opacity: .55;
}
/* Пока открыто поле ввода языка — прячем метку/плейсхолдер под ней (иначе
   генерируемый ::after контент рисуется поверх реального дочернего <input>). */
.editor pre:has(.pre-lang-input)::after {
  display: none;
}
/* Инлайн-инпут смены языка */
.editor pre .pre-lang-input {
  position: absolute;
  top: 4px;
  right: 8px;
  width: 120px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  text-align: right;
  text-transform: lowercase;
  z-index: 3;
  outline: none;
}
/* Выпадающий список языков поверх блока кода. !important — потому что общий
   сброс «.editor pre *» (ниже) обнуляет фон/рамку/шрифт всех потомков pre как код. */
.editor pre .pre-lang-dd {
  position: absolute !important;
  top: 26px;
  right: 8px;
  width: 170px !important;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-elev) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  z-index: 6;
  padding: 3px !important;
  margin: 0 !important;
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif !important;
  font-size: 12.5px !important;
  color: var(--text) !important;
  text-align: left;
  white-space: normal;
}
.editor pre .pre-lang-dd.hidden { display: none; }
.editor pre .pre-lang-opt {
  padding: 4px 8px !important;
  border-radius: 4px !important;
  margin: 0 !important;
  color: var(--text) !important;
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif !important;
  font-size: 12.5px !important;
  cursor: pointer;
}
.editor pre .pre-lang-opt.active,
.editor pre .pre-lang-opt:hover { background: var(--accent) !important; color: var(--on-accent, #fff) !important; }

.editor pre code { background: none; padding: 0; color: #9ad1f0; }

/* Внутри кода форматирование не отображается — всё рендерится как обычный код. */
.editor code *, .editor pre * {
  font-weight: inherit !important;
  font-style: inherit !important;
  text-decoration: none !important;
  font-family: inherit !important;
  font-size: inherit !important;
  color: inherit !important;
  background: none !important;
  filter: none !important;        /* снимаем размытие спойлера */
  border: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  vertical-align: baseline !important;  /* sub/sup в одну линию */
}

/* Подсветка синтаксиса (highlight.js), тема ~ atom-one-dark. !important — чтобы
   перебить сброс «.editor pre *», который обнуляет цвет всех потомков блока кода. */
.editor pre .hljs-comment, .editor pre .hljs-quote { color: #7d8799 !important; font-style: italic !important; }
.editor pre .hljs-keyword, .editor pre .hljs-selector-tag, .editor pre .hljs-literal,
.editor pre .hljs-doctag, .editor pre .hljs-formula { color: #c678dd !important; }
.editor pre .hljs-section, .editor pre .hljs-name, .editor pre .hljs-selector-id,
.editor pre .hljs-selector-class, .editor pre .hljs-tag, .editor pre .hljs-deletion,
.editor pre .hljs-variable, .editor pre .hljs-template-variable { color: #e06c75 !important; }
.editor pre .hljs-string, .editor pre .hljs-regexp, .editor pre .hljs-addition,
.editor pre .hljs-attribute, .editor pre .hljs-meta .hljs-string { color: #98c379 !important; }
.editor pre .hljs-number, .editor pre .hljs-symbol, .editor pre .hljs-bullet,
.editor pre .hljs-link, .editor pre .hljs-meta, .editor pre .hljs-selector-attr,
.editor pre .hljs-selector-pseudo { color: #d19a66 !important; }
.editor pre .hljs-title, .editor pre .hljs-class .hljs-title, .editor pre .hljs-title.class_,
.editor pre .hljs-attr, .editor pre .hljs-property { color: #e5c07b !important; }
.editor pre .hljs-title.function_, .editor pre .hljs-function .hljs-title,
.editor pre .hljs-built_in, .editor pre .hljs-builtin-name { color: #61afef !important; }
.editor pre .hljs-type, .editor pre .hljs-params { color: #56b6c2 !important; }
.editor pre .hljs-emphasis { font-style: italic !important; }
.editor pre .hljs-strong { font-weight: 700 !important; }

.editor blockquote {
  border-left: 3px solid var(--accent);
  background: rgba(42, 171, 238, .07);
  border-radius: 4px 8px 8px 4px;
  padding: 8px 12px;
  margin: 10px 0;
  color: #cfdce8;
}
.editor blockquote.expandable { border-left-color: #b08fef; background: rgba(176, 143, 239, .08); }
.editor blockquote.expandable::after {
  content: "▾ разворачиваемая";
  display: block;
  font-size: 11px;
  color: #b08fef;
  margin-top: 4px;
}

/* ── раскрывающийся блок (details/summary) ── */
.editor .exp-block {
  position: relative;
  margin: 12px 0;
  border: 1px solid var(--border);
  border-left: 3px solid #b08fef;
  border-radius: 8px;
  background: rgba(176, 143, 239, .06);
  overflow: hidden;
}
.editor .exp-summary {
  position: relative;
  font-weight: 600;
  padding: 9px 12px 9px 30px;
  outline: none;
  cursor: text;
  min-height: 1.2em;
}
/* Стрелка — кликабельная кнопка сворачивания/разворачивания */
.editor .exp-toggle {
  position: absolute;
  left: 5px;
  top: 7px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: none;
  color: #b08fef;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.editor .exp-toggle::before {
  content: "▾";
  transition: transform .15s ease;
}
.editor .exp-block[data-open="false"] .exp-toggle::before {
  transform: rotate(-90deg);
}
.editor .exp-block[data-open="false"] .exp-body {
  display: none;
}
.editor .exp-summary:empty::after {
  content: attr(data-ph);
  color: var(--text-dim);
  opacity: .55;
  font-weight: 400;
  pointer-events: none;
}
.editor .exp-body {
  padding: 4px 12px 8px;
  border-top: 1px solid var(--border);
}
/* Вложенный раскрывающийся блок — небольшой отступ по бокам, чтобы видеть иерархию.
   .exp-body даёт 12px паддинга с каждой стороны — гасим его отрицательным margin,
   оставляя видимый шаг 4px слева (3px рамки + 1px добавка), 1px справа. */
.editor .exp-body .exp-block {
  margin-left: -11px;
  margin-right: -12px;
}
.editor .exp-body > *:first-child { margin-top: 0; }
.editor .exp-body > *:last-child  { margin-bottom: 0; }
.editor .exp-body > * + * { margin-top: 8px; }
[data-scheme="light"] .editor .exp-block { background: rgba(124, 92, 191, .06); border-left-color: #7c5cbf; }
[data-scheme="light"] .editor .exp-summary::before { color: #7c5cbf; }

.editor .tg-spoiler {
  background: repeating-linear-gradient(45deg, #3a4a5c 0 4px, #2f3d4d 4px 8px);
  color: rgba(255, 255, 255, 0.45);
  border-radius: 4px;
  padding: 0 3px;
  transition: .2s;
  cursor: pointer;
}
.editor .tg-spoiler:hover, .editor .tg-spoiler:focus-within { color: var(--text); }
[data-scheme="light"] .editor .tg-spoiler { color: rgba(0, 0, 0, 0.4); }

.editor .tg-emoji {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}
.editor .tg-emoji img,
.editor .tg-emoji video { width: 1.3em; height: 1.3em; object-fit: contain; display: block; }

/* ── статусбар ───────────────────────── */
.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  flex: 0 0 auto;
  overflow: visible;
}
#sendBtn { margin-left: auto; }

/* ── круговой индикатор статистики поста (топбар) ───────────────────────── */
.stats-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  background: none;
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex: 0 0 auto;
}
.stats-ring:active { background: var(--bg-hover); }
/* жёлтый восклицательный знак в треугольнике — внутри кольца при warn */
.stats-warn-ic {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: none;
  color: #e8b54a;
  pointer-events: none;
}
.stats-ring.warn .stats-warn-ic { display: flex; }
.stats-ring-svg { transform: rotate(-90deg); overflow: visible; }
.stats-ring-bg { fill: none; stroke: var(--border); stroke-width: 3; }
.stats-ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset .25s ease, stroke .25s ease;
}
.stats-ring.warn .stats-ring-fg { stroke: #e8b54a; }
.stats-ring.over .stats-ring-fg { stroke: var(--danger); }

.stats-pop-scrim { position: fixed; inset: 0; z-index: 55; background: transparent; }
.stats-pop-scrim.hidden { display: none; }

.stats-pop {
  position: fixed;
  z-index: 56;
  width: 240px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  animation: fade .15s ease;
}
.stats-pop.hidden { display: none; }
.stats-block { padding: 8px 0; }
.stats-block + .stats-block { border-top: 1px solid var(--border); }
.stats-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.stats-label { color: var(--text-dim); }
.stats-value { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats-value.stats-warn { color: #e8b54a; }
.stats-value.stats-over { color: var(--danger); }
.stats-note { font-size: 11.5px; color: #e8b54a; line-height: 1.4; margin-top: 4px; }
.stats-note.hidden { display: none; }

/* ── «+» с раскрывающимися действиями ───────────────────────── */
.add-menu { position: relative; display: inline-flex; align-items: center; }
.add-menu.open { z-index: 40; }
/* все действия закреплены на панели → меню «+» пустое, прячем сам «+» */
.add-menu.hidden { display: none; }
.add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, transform .1s;
}
.add-btn:active { background: var(--accent-dark); transform: scale(.92); }
.add-plus { transition: transform .2s ease; }
.add-menu.open .add-plus { transform: rotate(45deg); }

.add-actions {
  position: absolute;
  bottom: calc(100% + 14px);
  /* Кнопка «+» стоит у левого края футера — центрирование (left:50% +
     translateX(-50%)) утаскивало поповер за левую границу экрана. Вместо
     этого выравниваем по левому краю кнопки и растим вправо. */
  left: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  /* .add-menu (родитель для позиционирования) шириной всего ~34px (по кнопке
     «+»), поэтому shrink-to-fit для абсолютно спозиционированного блока без
     собственной ширины считается непредсказуемо (в одну колонку либо шире
     экрана). Задаём ширину явно, отвязанную от контейнера, — так flex-wrap
     всегда переносит кнопки в аккуратную сетку без горизонтального скролла. */
  width: max-content;
  max-width: min(280px, calc(100vw - 24px));
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  max-height: calc(var(--vv-height, 100vh) - 72px);
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  transform: translateY(8px) scale(.96);
  transform-origin: bottom left;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.add-menu.open .add-actions {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.add-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s, transform .1s;
}
.add-action:active { background: var(--accent); color: #fff; border-color: var(--accent); transform: scale(.92); }
.add-math { font-size: 14px; font-weight: 600; line-height: 1; }
.emoji-footer-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: 0 0 auto;
  border: none; border-radius: 50%;
  background: var(--accent); color: #fff;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background .15s, transform .1s;
}
.emoji-footer-btn:active { background: var(--accent-dark); transform: scale(.92); }
.emoji-footer-btn.active { background: rgba(42,171,238,.35); }

/* закреплённая на нижней панели кнопка скрыта из меню «+» */
.add-actions .add-action.hidden { display: none; }

/* закреплённые кнопки на нижней панели — после «+» и эмодзи, до «Отправить».
   Горизонтальный скролл, если не влезают. */
.bar-pinned {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.bar-pinned::-webkit-scrollbar { display: none; }
.bar-pinned:empty { flex: 0 0 auto; }
.bar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s, transform .1s;
}
.bar-btn:active { background: var(--accent); color: #fff; border-color: var(--accent); transform: scale(.92); }
.bar-btn .add-math { font-size: 14px; font-weight: 600; line-height: 1; }
.bar-btn.tb-cell-blocked { opacity: 0.35; pointer-events: none; }

/* ── модалки ───────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 16, .65);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: end center;
  z-index: 50;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.overlay.hidden { display: none; }

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 20px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .5);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } }

@media (min-width: 600px) {
  .overlay { place-items: center; }
  .modal { border-radius: 16px; max-width: 460px; animation: pop .18s ease; }
  @keyframes pop { from { transform: scale(.96); opacity: 0; } }
}

.modal.small { max-width: 420px; }
.modal h2 { font-size: 16.5px; margin-bottom: 8px; }
.hint { font-size: 12.5px; color: var(--text-dim); margin-bottom: 14px; line-height: 1.5; }

.modal input {
  display: block;
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 11px 13px;
  outline: none;
  transition: border-color .15s;
}
.modal input:focus { border-color: var(--accent); }

.prompt-choice { display: flex; gap: 16px; margin: 12px 0 4px; font-size: 13px; color: var(--text); }
.prompt-choice.hidden { display: none; }
.prompt-choice label { display: flex; align-items: center; gap: 6px; margin-bottom: 0; cursor: pointer; user-select: none; color: var(--text); }
.prompt-choice input { display: inline-block; width: auto; margin: 0; accent-color: var(--accent); }

.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .spacer { flex: 1; }
.modal-close-btn { position: absolute; top: 12px; right: 12px; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: none; border: none; border-radius: 6px; color: var(--text-dim); cursor: pointer; transition: background .12s, color .12s; }
.modal-close-btn:hover { background: var(--bg-hover); color: var(--text); }
.modal-close-btn:active { background: var(--bg-elev); }

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 9px;
  border: none;
  cursor: pointer;
  transition: .15s;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:active { background: var(--accent-dark); }
.btn.ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn.ghost:active { color: var(--text); background: var(--bg-hover); }
.btn.ghost.danger { color: #e05c5c; border-color: #e05c5c44; }
.btn.ghost.danger:active { background: rgba(224, 92, 92, .12); }

/* ── список каналов ───────────────────────── */
.channel-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.ch-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: .12s;
}
.ch-item:active { border-color: var(--accent); background: var(--bg-hover); }
.ch-preview { margin-bottom: 6px; }
.ch-sel { border-color: var(--accent) !important; background: rgba(42, 171, 238, .08) !important; }
.ch-sel .ch-title { color: var(--accent); }
.ch-title { font-size: 15px; font-weight: 600; }
.ch-un { font-size: 12.5px; color: var(--text-dim); }
.ch-loading, .ch-empty { font-size: 13.5px; color: var(--text-dim); padding: 14px 4px; line-height: 1.5; }

/* ── блок планирования в меню отправки ── */
.ch-schedule { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.ch-schedule-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--text); }
.ch-schedule-body { margin-top: 10px; }
.ch-schedule-body.hidden { display: none; }
.ch-schedule-input {
  width: 100%; box-sizing: border-box; padding: 9px 11px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font: inherit; font-size: 14px; outline: none;
}
.ch-schedule-input:focus { border-color: var(--accent); }
.ch-schedule-hint { font-size: 11.5px; color: var(--text-dim); margin-top: 6px; line-height: 1.4; }
.sched-err { color: var(--danger); font-size: 11px; margin-top: 2px; }
.ch-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 6px;
}
.ch-section-label { font-size: 12px; color: var(--text-dim); }
.ch-refresh-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--text-dim);
  cursor: pointer;
  transition: .15s;
  flex: 0 0 auto;
}
.ch-refresh-btn:active { color: var(--accent); border-color: var(--accent); }
.ch-refresh-btn.spinning svg { animation: ch-spin .7s linear infinite; }
@keyframes ch-spin { to { transform: rotate(360deg); } }

/* ── тост ───────────────────────── */
.toast {
  position: fixed;
  bottom: calc(46px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
  z-index: 100;
  animation: fade .2s ease;
  max-width: 86vw;
  text-align: center;
}
.toast.ok { border-color: rgba(87, 194, 122, .5); }
.toast.err { border-color: rgba(224, 92, 92, .55); }
.toast.hidden { display: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }

/* ── / Slash Command Palette ──────────────────── */
.slash-palette {
  position: fixed;
  z-index: 200;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, .5);
  width: 300px;
  max-height: 300px;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: slashFadeUp .12s ease;
}
.slash-palette.hidden { display: none; }
@keyframes slashFadeUp {
  from { opacity: 0; transform: translateY(6px); }
}

.slash-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 9px 13px;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.slash-item:hover { background: var(--bg-hover); }
.slash-item.active { background: color-mix(in srgb, var(--accent) 18%, var(--bg-elev)); }

.slash-item-label {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
}
.slash-item-desc {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 1px;
  line-height: 1.3;
}

/* highlight matching chars */
.slash-item-label mark,
.slash-item-desc mark {
  background: none;
  color: var(--accent);
  font-weight: 700;
}

/* ── светлая тема ───────────────────────── */
[data-scheme="light"] {
  --bg-elev:  var(--tg-theme-bg-color, #fff);
  --bg-hover: rgba(0, 0, 0, .07);
  --border:   rgba(0, 0, 0, .13);
  --accent-dark: var(--tg-theme-link-color, #1a8fc7);
  --input-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
}

/* ── модалка ссылки ── */
.modal .link-text-input {
  display: block; width: 100%; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--input-bg); color: var(--text);
  font: inherit; font-size: 14px; padding: 9px 11px;
  outline: none; box-sizing: border-box;
}
.modal .link-text-input:focus { border-color: var(--accent); }
.link-type-row { display: flex; gap: 4px; margin-bottom: 12px; }
.link-type-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  flex: 1; padding: 7px 4px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text-dim);
  font: inherit; font-size: 10px; cursor: pointer; transition: border-color .15s, color .15s;
}
.link-type-btn.active { border-color: var(--accent); color: var(--accent); }
.link-type-btn:active { background: var(--bg-hover); }
.link-input-row { display: flex; }
.modal .link-prefix-input {
  flex: 0 0 90px; width: 90px; border-radius: 8px 0 0 8px;
  border: 1px solid var(--border); border-right: none;
  background: var(--bg-elev); color: var(--text-dim);
  font: inherit; font-size: 13px; padding: 9px 8px; outline: none; box-sizing: border-box;
}
.modal .link-prefix-input:focus { border-color: var(--accent); z-index: 1; position: relative; }
.link-suffix-wrap { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; }
.modal .link-suffix-input {
  flex: 1; min-width: 0; width: auto; border-radius: 0 8px 8px 0;
  border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text);
  font: inherit; font-size: 14px; padding: 9px 34px 9px 11px; outline: none; box-sizing: border-box;
}
.modal .link-suffix-input:focus { border-color: var(--accent); }
.link-anchor-pick {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; background: none; border: none;
  color: var(--text-dim); cursor: pointer; border-radius: 4px; padding: 0;
  transition: color .12s, background .12s;
}
.link-anchor-pick:hover { color: var(--text); background: var(--bg-hover); }
.link-anchor-pick.hidden { display: none; }
.link-anchor-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 8px; overflow-y: auto; max-height: 160px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.link-anchor-dropdown.hidden { display: none; }
.link-anchor-option {
  padding: 9px 12px; cursor: pointer; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.link-anchor-option:last-child { border-bottom: none; }
.link-anchor-option:hover { background: var(--bg-hover); }

/* ── модалка карты ── */
.map-modal { max-width: 500px; max-height: 90dvh; overflow-y: auto; }
.map-search-row { display: flex; gap: 6px; margin-bottom: 10px; }
.map-search-row input { flex: 1; min-width: 0; }
.map-search-btn { padding: 0 12px; flex-shrink: 0; }
.map-container {
  width: 100%; height: 280px; border-radius: 10px; overflow: hidden;
  margin-bottom: 6px; border: 1px solid var(--border);
}
.map-hint {
  font-size: 11.5px; color: var(--text-dim); text-align: center;
  margin: 0 0 10px; line-height: 1.4;
}
.map-caption-wrap { position: relative; margin-bottom: 14px; }
.map-caption-wrap input { padding-right: 36px; margin-bottom: 0 !important; }
.map-caption-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg-hover); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); padding: 0; flex-shrink: 0;
  transition: opacity .15s;
}
.map-caption-clear.hidden { display: none; }
.map-geo-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--accent); cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.3);
  transition: background .15s;
}
.map-geo-btn:hover { background: var(--bg-hover); }
.map-geo-btn.loading { opacity: .5; pointer-events: none; }
/* Leaflet dark-mode overrides */
[data-scheme="dark"] .leaflet-tile { filter: brightness(.85) invert(1) hue-rotate(180deg) saturate(1.1); }
[data-scheme="dark"] .leaflet-control-zoom a { background: var(--bg-elev); color: var(--text); border-color: var(--border); }
[data-scheme="dark"] .leaflet-control-attribution { background: rgba(0,0,0,.5); color: var(--text-dim); }
[data-scheme="dark"] .leaflet-control-attribution a { color: var(--accent); }
.leaflet-control-attribution { font-size: 10px !important; }

/* ── модалка дата/время ── */
.time-picker-row { display: flex; gap: 8px; margin-bottom: 12px; }
/* Обёртка поля даты с кнопкой-календарём */
.time-date-wrap { position: relative; flex: 1.5; min-width: 0; display: flex; }
.time-date-wrap .time-date-input { flex: 1; padding-right: 32px; }
.time-cal-btn {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 3px; display: flex; align-items: center; line-height: 0;
}
.time-cal-btn:hover { color: var(--text); }
#timeDateHidden { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; top: 0; left: 0; }
.modal .time-date-input,
.modal .time-time-input {
  flex: 1; min-width: 0; width: 100%; border: 1px solid var(--border); border-radius: 8px;
  background: var(--input-bg); color: var(--text);
  font: inherit; font-size: 14px; padding: 9px 10px; outline: none; box-sizing: border-box;
  color-scheme: inherit;
}
.modal .time-date-input:focus,
.modal .time-time-input:focus { border-color: var(--accent); }
/* Чипы выбора формата + кнопка «Относительное» */
.time-fmt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
/* чипы формата — в одну строку (если не влезают, горизонтальная прокрутка без полосы) */
.time-chip-group { display: flex; flex-wrap: nowrap; gap: 5px; flex: 1; min-width: 0; overflow-x: auto; transition: opacity .15s; scrollbar-width: none; -ms-overflow-style: none; }
.time-chip-group::-webkit-scrollbar { display: none; }
.time-chip-group.time-dim { opacity: .4; }   /* приглушены в относительном режиме */
/* «Относительное» — отдельной второй строкой */
.time-rel-row { display: flex; margin-bottom: 12px; }
.time-chip {
  flex: 0 0 auto;
  padding: 4px 11px; border: none; border-radius: 20px;
  background: var(--bg-panel); font: inherit; font-size: 12.5px;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s, opacity .15s;
}
.time-chip[data-state="off"] { color: var(--text-dim); opacity: 0.45; }
.time-chip[data-state]:not([data-state="off"]) { color: var(--accent); background: rgba(42,171,238,.13); }
.time-chip:active { opacity: .7; }
/* Кнопка «Относительное» (без data-state): серая, синяя когда активна */
.time-rel-btn { flex: 0 0 auto; color: var(--text-dim); }
.time-rel-btn.active { color: var(--accent); background: rgba(42,171,238,.13); }
/* Редактируемое поле итогового текста */
.time-preview-input {
  width: 100%; box-sizing: border-box; margin-bottom: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px; padding: 9px 10px; outline: none;
}
.time-preview-input:focus { border-color: var(--accent); }

/* ───────── редактор формул (на весь экран) ───────── */
.overlay .fe-modal {
  width: 100vw; max-width: 100vw;
  height: 100dvh; max-height: 100dvh;
  border: none; border-radius: 0;
  padding: 12px 14px;
  /* содержимое держим над клавиатурой: её высота приходит в --kb-inset */
  padding-bottom: calc(12px + var(--kb-inset, 0px));
  display: flex; flex-direction: column; gap: 10px;
  animation: none;
}
/* верхняя панель: Font / Size / Space + закрыть */
.fe-top { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.fe-top .spacer { flex: 1 1 auto; }
.fe-topbtn {
  flex: 0 0 auto; height: 40px; padding: 0 12px;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-panel); color: var(--text); font: inherit; font-size: 13px;
  cursor: pointer; transition: background .12s, border-color .12s, color .12s;
}
.fe-topbtn svg { flex: 0 0 auto; }
.fe-topbtn:hover { background: var(--bg-hover); }
.fe-topbtn.active { border-color: var(--accent); color: var(--accent); background: rgba(42,171,238,.13); }
/* стрелка «назад» — первой кнопкой слева */
.fe-back {
  flex: 0 0 auto; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 9px; background: none; color: var(--text); cursor: pointer;
  transition: background .12s;
}
.fe-back:hover { background: var(--bg-hover); }
/* плавающий дроп-даун (Font/Size/Space) */
.fe-drop {
  position: fixed; z-index: 60; min-width: 180px; max-width: 92vw; max-height: 60vh;
  overflow-y: auto; padding: 5px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.fe-drop.hidden { display: none; }
.fe-drop-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 8px 10px; border: none; border-radius: 7px; background: none;
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer; text-align: left;
}
.fe-drop-item:hover { background: var(--bg-hover); }
.fe-drop-name { flex: 1 1 auto; white-space: nowrap; }
.fe-drop-prev { flex: 0 0 auto; color: var(--text); }
/* панель категорий — внизу, переносится в несколько строк */
.fe-toolbar {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; gap: 5px;
}
.fe-cat {
  flex: 1 1 auto; padding: 7px 8px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-panel); color: var(--text);
  font: inherit; font-size: 12px; white-space: nowrap; cursor: pointer; text-align: center;
  transition: background .12s, border-color .12s, color .12s;
}
.fe-cat:hover { background: var(--bg-hover); }
.fe-cat.active { border-color: var(--accent); color: var(--accent); background: rgba(42,171,238,.13); }
/* панель символов — открывается снизу «вместо клавиатуры», высотой с клавиатуру */
.fe-panel {
  flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  padding: 8px; height: 42vh; overflow-y: auto;
}
.fe-panel.hidden { display: none; }
.fe-group + .fe-group { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.fe-group-title { font-size: 11px; color: var(--text-dim); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.fe-items { display: flex; flex-wrap: wrap; gap: 4px; }
.fe-item {
  min-width: 34px; min-height: 32px; padding: 3px 7px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-panel); color: var(--text); cursor: pointer;
  transition: background .1s, border-color .1s;
}
.fe-item:hover { background: var(--bg-hover); border-color: var(--accent); }
.fe-item .katex { font-size: 1em; }
/* ввод и превью — равные резиновые блоки: всегда одинаковой высоты, сжимаются вместе */
.fe-input {
  flex: 1 1 0; min-height: 56px;
  width: 100%; box-sizing: border-box; resize: none;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--input-bg); color: var(--text);
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px;
  padding: 9px 10px; outline: none; line-height: 1.4;
}
.fe-input:focus { border-color: var(--accent); }
.fe-preview-wrap { flex: 1 1 0; min-height: 56px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-panel); padding: 8px 10px; }
.fe-preview-label { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.fe-preview { min-height: 34px; overflow-x: auto; color: var(--text); }
.fe-preview.fe-err { color: #e2566b; font-family: ui-monospace, monospace; font-size: 12.5px; white-space: pre-wrap; }
/* две кнопки вставки внизу */
.fe-actions { flex: 0 0 auto; display: flex; gap: 8px; }
.fe-insert-btn { flex: 1 1 0; }

/* кнопка «Расширенный редактор» — в правом верхнем углу диалога формулы */
#promptOverlay .modal { position: relative; }
.prompt-extra { position: absolute; top: 19px; right: 16px; padding: 5px 10px; font-size: 12.5px; }
.prompt-extra[hidden] { display: none; }

/* модалки */
[data-scheme="light"] .overlay { background: rgba(0, 0, 0, .35); }
[data-scheme="light"] .modal   { box-shadow: 0 -4px 24px rgba(0, 0, 0, .12); }

/* тост */
[data-scheme="light"] .toast { box-shadow: 0 4px 20px rgba(0, 0, 0, .12); }

/* инлайн код */
[data-scheme="light"] .editor code {
  background: rgba(42, 171, 238, .1);
  color: #0e6fa3;
}
[data-scheme="light"] .editor pre code { color: #0e6fa3; }

/* цитата */
[data-scheme="light"] .editor blockquote { color: var(--text); }
[data-scheme="light"] .editor blockquote.expandable {
  border-left-color: #7c5cbf;
  background: rgba(124, 92, 191, .08);
}
[data-scheme="light"] .editor blockquote.expandable::after { color: #7c5cbf; }

/* спойлер */
[data-scheme="light"] .editor .tg-spoiler {
  background: repeating-linear-gradient(45deg, #c8d0d8 0 4px, #b8c0c8 4px 8px);
}

/* формулы */
[data-scheme="light"] .editor .tg-math {
  background: rgba(40, 140, 60, .1);
  color: #1e7a34;
}
[data-scheme="light"] .editor .tg-math-block {
  background: rgba(40, 140, 60, .07);
  border-color: rgba(40, 140, 60, .2);
}
[data-scheme="light"] .editor .tg-math-block .math-body,
[data-scheme="light"] .editor .tg-math { color: #1e7a34; }

/* временная метка */
[data-scheme="light"] .editor .tg-time {
  background: rgba(42, 171, 238, .1);
  color: #0e6fa3;
  border-bottom-color: rgba(42, 171, 238, .4);
}

/* метка языка кода */
[data-scheme="light"] .tb.active {
  background: rgba(42, 171, 238, .14);
  box-shadow: inset 0 0 0 1px rgba(42, 171, 238, .35);
}

/* ── гамбургер-кнопка ───────────────────────── */
.menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  margin: -6px 0 -6px -6px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: background .15s;
}
.menu-btn:active { background: var(--bg-hover); }

/* ── боковое меню (drawer) ──────────────────── */
.drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 95;
  opacity: 1;
  transition: opacity .22s ease;
}
.drawer-scrim.hidden { display: none; }
.drawer-scrim.closing { opacity: 0; }

.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(80vw, 300px);
  z-index: 96;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: max(18px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom));
  box-shadow: 2px 0 20px rgba(0, 0, 0, .35);
  transform: translateX(0);
  transition: transform .24s cubic-bezier(.4, 0, .2, 1);
  overflow-y: auto;
}
.drawer.hidden { display: none; }
.drawer.closing { transform: translateX(-100%); }

.drawer-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 18px 0;
  font-weight: 600;
  font-size: 19px;
  letter-spacing: .3px;
  user-select: none;
}

.drawer-version-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 18px 16px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.drawer-version {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.drawer-nav {
  display: flex;
  flex-direction: column;
  padding: 4px 8px;
  gap: 2px;
}
.drawer-item {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  transition: background .15s;
}
.drawer-item svg { color: var(--text-dim); flex: 0 0 auto; }
.drawer-item:active svg { color: var(--accent); }
.drawer-item.current { background: var(--bg-elev); color: var(--accent); font-weight: 600; }
.drawer-item.current svg { color: var(--accent); }
.drawer-item-new-post { color: var(--accent); font-weight: 600; }
.drawer-item-new-post svg { color: var(--accent); }
.drawer-div { height: 1px; background: var(--border); margin: 6px 0; }
.new-post-sub-hint { display: flex; align-items: flex-start; font-size: 12px; color: var(--text-dim); margin-top: 10px; line-height: 1.4; }
.new-post-sub-hint.hidden { display: none; }

/* рипл-эффект на пунктах меню */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(42, 171, 238, .35);
  transform: scale(0);
  animation: ripple-grow .55s ease-out;
  pointer-events: none;
}
@keyframes ripple-grow {
  to { transform: scale(2.4); opacity: 0; }
}

/* ── полноэкранная страница ─────────────────── */
.screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  opacity: 1;
  transition: opacity .18s ease;
}
.screen.hidden { display: none; }
/* открытие/закрытие — фейд */
.screen.entering, .screen.closing { opacity: 0; }

/* горизонтальный слайд содержимого при навигации внутри (профиль ↔ эмодзи) */
@keyframes screen-slide-right { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes screen-slide-left  { from { transform: translateX(-40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.screen-body.anim-right { animation: screen-slide-right .2s cubic-bezier(.4, 0, .2, 1); }
.screen-body.anim-left  { animation: screen-slide-left .2s cubic-bezier(.4, 0, .2, 1); }

.screen-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  padding-top: max(9px, env(safe-area-inset-top));
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.screen-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: background .15s;
}
.screen-back:active { background: var(--bg-hover); }
.screen-title {
  font-size: 17px;
  font-weight: 600;
}
.screen-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 18px max(18px, env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

/* ── профиль ─────────────────────────────────── */
.profile-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0 18px;
}
.profile-avatar {
  width: 84px; height: 84px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
  overflow: hidden;
}
.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.profile-name {
  font-size: 20px;
  font-weight: 700;
}
.profile-username {
  font-size: 14px;
  color: var(--text-dim);
}
.profile-status {
  margin-top: 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .3px;
  background: linear-gradient(90deg, #f7a4ff, #a18bff 45%, #5ec6ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.profile-status--free {
  background: none;
  -webkit-background-clip: unset;
  background-clip: unset;
  -webkit-text-fill-color: unset;
  color: var(--text-dim);
}
.profile-sub-card {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 4px;
}
.profile-sub-info {
  font-size: 14px;
  line-height: 1.4;
}
.profile-sub-hint {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}
.profile-sub-btn {
  width: 100%;
  padding: 10px 16px;
}

.profile-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s;
}
.profile-btn:active { background: var(--bg-hover); }
.profile-btn .pb-count {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.profile-btn .pb-arrow { color: var(--text-dim); display: inline-flex; }

/* ── менеджер кастомных эмодзи ────────────────── */
.em-hint {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.45;
  margin-bottom: 16px;
}
.em-hint code {
  font-family: var(--mono);
  background: var(--bg-panel);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--accent);
}
.em-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
.em-link:active { opacity: .7; }
.em-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.em-item {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 30px;
}
.em-item img, .em-item video, .em-item tg-emoji {
  width: 34px; height: 34px;
  object-fit: contain;
}
.em-del {
  position: absolute;
  top: -7px; right: -7px;
  width: 22px; height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--bg);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: transform .1s;
}
.em-del:active { transform: scale(.85); }
.em-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 28px 0;
  white-space: nowrap;
}
.em-premium-notice {
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  padding: 32px 16px;
  line-height: 1.5;
}
.em-donate-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.em-donate-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.em-donate-goal {
  font-size: 12px;
  color: var(--text-dim);
}
.em-donate-addr {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-dim);
  overflow: hidden;
}
.em-donate-addr span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.em-donate-copy {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  color: var(--accent);
  font-size: 12px;
  font: inherit;
}
.em-donate-btn {
  width: 100%;
  padding: 9px 16px;
}
.btn-danger-outline {
  display: block;
  width: 100%;
  padding: 12px;
  background: none;
  border: 1px solid var(--danger);
  border-radius: 12px;
  color: var(--danger);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger-outline:active { background: rgba(224, 92, 92, .12); }

/* ── заглушка «скоро» ────────────────────────── */
.screen-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
  color: var(--text-dim);
  text-align: center;
}
.screen-soon .ss-emoji { font-size: 40px; }

/* ── экран настроек ──────────────────────────── */
.settings-section { margin-bottom: 24px; }
.settings-section-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 0 4px;
  margin-bottom: 8px;
}
.settings-section-desc {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.45;
  padding: 0 4px;
  margin-bottom: 10px;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}
.settings-row + .settings-row { margin-top: 8px; }
.settings-row + .settings-expandable,
.settings-expandable + .settings-row,
.settings-expandable + .settings-expandable { margin-top: 16px; }
.settings-row-text { flex: 1; min-width: 0; }
.settings-row-title {
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.settings-row-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 3px;
  line-height: 1.4;
}
.badge-exp {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(42,171,238,.14);
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
}
/* Недоступная настройка: заголовок и тумблер приглушены, описание остаётся
   читаемым — в нём объясняется, почему выключено. */
.settings-row-disabled { cursor: default; }
.settings-row-disabled .settings-row-title,
.settings-row-disabled .tgl { opacity: .45; }
.settings-row-disabled .badge-exp {
  color: var(--text-dim);
  background: rgba(127,127,127,.16);
}

/* кастомизация нижней панели — всё одним блоком: подсказка + строки
   (⠿ + иконка + название + тумблер), строки перетаскиваются за ⠿ */
.bar-cfg {
  position: relative;   /* контекст для линии-индикатора вставки */
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.bar-cfg-hint {
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
  border-bottom: 1px solid var(--border);
}
.bar-cfg-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 8px 8px;
  background: var(--bg-panel);
}
.bar-cfg-item + .bar-cfg-item { border-top: 1px solid var(--border); }
/* «поднятая» строка: следует за пальцем (transform из JS), с тенью поверх остальных */
.bar-cfg-item.bar-cfg-dragging {
  position: relative;
  z-index: 4;
  background: var(--bg-elev);
  border-radius: 8px;
  border-top-color: transparent;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .45);
  cursor: grabbing;
}
/* подсвеченная линия — место, куда встанет строка */
.bar-cfg-drop {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(42, 171, 238, .8);
  pointer-events: none;
  z-index: 5;
}
.bar-cfg-grip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 30px;
  color: var(--text-dim);
  cursor: grab;
  opacity: .55;
  touch-action: none;   /* тач-драг за ручку не должен скроллить страницу */
  -webkit-tap-highlight-color: transparent;
}
.bar-cfg-grip:active { cursor: grabbing; }
.bar-cfg-row {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.bar-cfg-ic {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}
.bar-cfg-ic svg { width: 20px; height: 20px; }
.bar-cfg-ic .add-math { font-size: 14px; font-weight: 600; line-height: 1; }
.bar-cfg-label { flex: 1; min-width: 0; font-size: 15px; font-weight: 500; }

/* раскрывающийся блок хранилища (тогл + поле ввода в одном блоке) */
.settings-expandable {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.settings-expandable .settings-row {
  background: none;
  border: none;
  border-radius: 0;
}
.storage-off-hint {
  padding: 2px 16px 12px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}
.storage-off-hint.hidden { display: none; }
.storage-expand {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
}
.storage-expand.hidden { display: none; }
.storage-status { font-size: 13.5px; margin-bottom: 10px; line-height: 1.4; word-break: break-word; }
.storage-status-dim { color: var(--text-dim); }
.storage-input-row { display: flex; gap: 8px; }
.storage-input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 14px;
  padding: 9px 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
}
.storage-input:focus { border-color: var(--accent); }
.storage-apply { flex-shrink: 0; padding: 9px 16px; }
.storage-hint { font-size: 12px; color: var(--text-dim); margin-top: 8px; line-height: 1.4; }

/* toggle switch */
.tgl { position: relative; width: 44px; height: 26px; flex-shrink: 0; display: inline-block; }
.tgl input { position: absolute; opacity: 0; width: 0; height: 0; }
.tgl-track {
  position: absolute; inset: 0;
  border-radius: 13px;
  background: var(--border);
  transition: background .2s;
}
.tgl input:checked + .tgl-track { background: var(--accent); }
.tgl input:disabled + .tgl-track { opacity: .5; }
.tgl-thumb {
  position: absolute; pointer-events: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  top: 3px; left: 3px;
  transition: transform .2s;
}
.tgl input:checked ~ .tgl-thumb { transform: translateX(18px); }

/* вложенная панель под тоглом (напр. список скобок) */
.settings-sub-panel { border-top: 1px solid var(--border); padding: 6px 12px 10px; }
.settings-sub-panel.hidden { display: none; }
.settings-sub-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 4px; cursor: pointer;
}
.settings-sub-row + .settings-sub-row { border-top: 1px solid var(--border); }
.settings-sub-row-label { flex: 1; font-size: 14px; }

/* ── баннер режима редактирования ───────────────── */
.edit-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: rgba(42, 171, 238, .07);
  border-bottom: 1px solid rgba(42, 171, 238, .22);
  flex: 0 0 auto;
  min-height: 38px;
}
.edit-banner.hidden { display: none; }
.edit-banner-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  color: var(--accent);
}
.edit-action-btn {
  padding: 4px 11px;
  border: 1px solid rgba(42, 171, 238, .5);
  border-radius: 12px;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.edit-action-btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.edit-action-btn:active { opacity: .75; }
.edit-action-btn.hidden { display: none; }
.edit-exit-btn {
  padding: 4px 6px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
.edit-exit-btn:active { color: var(--text); }

/* ── список черновиков / опубликованных ─────────── */
.post-list { display: flex; flex-direction: column; }
.post-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
  position: relative;
}
.post-item:active { background: var(--bg-hover); }
.post-item-time { font-size: 11px; color: var(--text-dim); }
.post-item-snippet {
  font-size: 13px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-item-del {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  opacity: .5;
}
.post-item-del:active { color: var(--danger); opacity: 1; }
.post-tab-row {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  scrollbar-width: none;
}
.post-tab-row::-webkit-scrollbar { display: none; }
.post-tab {
  padding: 10px 15px;
  font-size: 13px;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.post-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.post-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
}
.sched-promo-btn { display: block; margin: 4px auto 0; }

/* ── In-page confirm dialog (не закрывает клавиатуру) ── */
.ipc-ov {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.55);
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 20px;
}
.ipc-box {
  background: var(--bg-panel, #17212b);
  border-radius: 12px;
  padding: 20px 20px 10px;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  font-family: inherit;
}
.ipc-msg {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text, #e9eef4);
  margin: 0 0 18px;
  word-break: break-word;
}
.ipc-row {
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: flex-end;
  justify-content: flex-end;
  gap: 2px;
  margin: 0 -6px;
}
.ipc-btn {
  background: transparent;
  border: none;
  outline: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--accent, #2aabee);
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
  line-height: 1;
  display: block;
}
.ipc-btn:active { opacity: 0.6; }
.ipc-btn-ok { font-weight: 700; }

