/**
 * Univer Calc — переиспользуемый компонент табличного редактора
 * Neuronis
 */

.univer-calc-container {
  min-height: 320px;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Переключатель версий Univer Calc ──────────────────────────────────── */
.univer-version-switcher {
  flex-shrink: 0;
  position: relative;
  margin-left: 8px;
}

.univer-version-switcher__btn {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 18px;
  padding: 0 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  color: #aaa;
  font-size: 11px;
  font-family: Liberation Sans, Arial, sans-serif;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.univer-version-switcher__btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #e0e0e0;
}

.univer-version-switcher__chevron {
  font-size: 9px;
  line-height: 1;
  opacity: 0.7;
}

.univer-version-switcher__menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 9999;
  min-width: 140px;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.univer-version-switcher__item {
  display: block;
  padding: 5px 12px;
  color: #ccc;
  font-size: 12px;
  font-family: Liberation Sans, Arial, sans-serif;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.1s;
}

.univer-version-switcher__item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.univer-version-switcher__item--active {
  color: #fff;
  font-weight: 600;
}

/* Шапка в стиле LibreOffice Calc: верхняя чёрная полоса */
.univer-libre-title-bar {
  flex-shrink: 0;
  height: 22px;
  padding: 0 4px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #000;
  color: #e0e0e0;
  font-size: 12px;
  font-family: Liberation Sans, Arial, sans-serif;
  line-height: 1;
}

.univer-libre-title-bar__text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Кнопка Восстановить / Развернуть */
.univer-libre-title-bar__winbtn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  padding: 0;
  margin-left: 6px;
  background: transparent;
  border: none;
  border-radius: 2px;
  color: #c0c0c0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.univer-libre-title-bar__winbtn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.univer-winbtn-icon {
  width: 12px;
  height: 12px;
  display: block;
}

/* По умолчанию (развёрнуто) — показываем иконку «Восстановить» (два квадрата) */
.univer-winbtn-icon--maximize { display: none; }
.univer-winbtn-icon--restore  { display: block; }

/* В восстановленном состоянии — показываем иконку «Развернуть» (один квадрат) */
.univer-calc-container.univer-calc--restored .univer-winbtn-icon--maximize { display: block; }
.univer-calc-container.univer-calc--restored .univer-winbtn-icon--restore  { display: none; }

/* Переход ширины только в режиме «восстановить» — не на всём контейнере:
   иначе любой пересчёт max-width (flex, скроллбар, субпиксели) даёт дёрганье правого края листа. */
.univer-calc-container.univer-calc--restored {
  width: 60vw;
  max-width: 60vw;
  min-width: 420px;
  align-self: flex-start;
  transition: width 0.2s ease, max-width 0.2s ease;
}

/* Нижняя полоса с вкладками меню (тёмно-серый фон) */
.univer-libre-menu-bar {
  flex-shrink: 0;
  height: 26px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 2px;
  background: #3c3c3c;
  color: #e0e0e0;
  font-size: 12px;
  font-family: Liberation Sans, Arial, sans-serif;
  line-height: 1;
}

.univer-libre-menu-bar span {
  padding: 4px 8px;
  cursor: default;
  border-radius: 2px;
}

.univer-libre-menu-bar span:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Декоративная полоса тулбара в стиле LibreOffice (рисунок) */
.univer-libre-toolbar {
  flex-shrink: 0;
  overflow: hidden;
  display: block;
  line-height: 0;
  background: #3c3c3c;
  position: relative;
}

.univer-libre-toolbar.univer-libre-toolbar--buttons {
  overflow: visible !important;
}

/* Режим с отдельными кнопками (calc trainer) */
.univer-libre-toolbar--buttons {
  display: flex;
  flex-direction: row;
  min-height: 38px;
  overflow: visible;
  z-index: 3;
}

.univer-libre-toolbar-buttons {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  overflow: visible;
  position: relative;
}

.univer-libre-toolbar-buttons .univer-libre-toolbar-btn--icon {
  flex: none;
  width: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s;
}

.univer-libre-toolbar-buttons .univer-libre-toolbar-btn--icon:hover {
  background: rgba(255, 255, 255, 0.08);
}

.univer-libre-toolbar-buttons .univer-libre-toolbar-btn--icon:focus-visible {
  outline: 1px solid rgba(255, 255, 255, 0.4);
  outline-offset: -1px;
}

.univer-libre-toolbar-buttons .univer-libre-toolbar-btn--icon img {
  width: auto;
  height: 32px;
  max-height: 39px;
  display: block;
}

.univer-border-split {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  z-index: 40;
}

.univer-border-split__toggle {
  width: 18px !important;
  min-width: 18px;
  padding: 0 !important;
  border-left: 1px solid rgba(255, 255, 255, 0.15) !important;
}

.univer-border-split__chevron {
  font-size: 10px;
  line-height: 1;
  color: #cfcfcf;
}

.univer-calc-container[data-theme="light"] .univer-border-split__chevron {
  color: #444;
}

.univer-calc-container[data-theme="light"] .univer-border-split__toggle {
  border-left-color: rgba(0, 0, 0, 0.18) !important;
}

.univer-border-menu {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  min-width: 180px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  border: 1px solid #555;
  background: #2a2a2a;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
}

.univer-border-menu[hidden] {
  display: none !important;
}

.univer-border-menu__item {
  border: none;
  background: transparent;
  color: #f0f0f0;
  text-align: left;
  font-size: 13px;
  line-height: 1.25;
  padding: 6px 10px;
  cursor: pointer;
}

.univer-border-menu__item:hover {
  background: rgba(255, 255, 255, 0.09);
}

.univer-calc-container[data-theme="light"] .univer-border-menu {
  border-color: #c9c9c9;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.univer-calc-container[data-theme="light"] .univer-border-menu__item {
  color: #1a1a1a;
}

.univer-calc-container[data-theme="light"] .univer-border-menu__item:hover {
  background: rgba(0, 0, 0, 0.06);
}

/* Светлая тема: фон меню и кнопок #f2f2f2 */
.univer-calc-container[data-theme="light"] .univer-libre-menu-bar {
  background: #f2f2f2;
  color: #1a1a1a;
}

.univer-calc-container[data-theme="light"] .univer-libre-menu-bar span:hover {
  background: rgba(0, 0, 0, 0.06);
}

.univer-calc-container[data-theme="light"] .univer-libre-toolbar {
  background: #f2f2f2;
}

.univer-calc-container[data-theme="light"] .univer-libre-toolbar-buttons .univer-libre-toolbar-btn--icon:hover {
  background: rgba(0, 0, 0, 0.06);
}

.univer-calc-container[data-theme="light"] .univer-libre-toolbar-buttons .univer-libre-toolbar-btn--icon:focus-visible {
  outline: 1px solid rgba(0, 0, 0, 0.25);
}

/* Кнопки light — на 15% меньше */
.univer-calc-container[data-theme="light"] .univer-libre-toolbar-buttons .univer-libre-toolbar-btn--icon img {
  transform: scale(0.85);
  transform-origin: center center;
}

.univer-libre-toolbar img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 38px;
  object-fit: contain;
  object-position: left top;
  vertical-align: top;
}

/* Активные зоны: сортировка и автофильтр (поверх картинки, верхний ряд иконок) */
.univer-libre-toolbar-actions {
  position: absolute;
  left: auto;
  right: 100px;
  top: 0;
  bottom: auto;
  height: 40%;
  width: 14%;
  min-width: 60px;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  pointer-events: none;
}

.univer-libre-toolbar-actions .univer-libre-toolbar-btn {
  pointer-events: auto;
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  font-size: 0;
  color: transparent;
  outline: none;
}

.univer-libre-toolbar-actions .univer-libre-toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.univer-libre-toolbar-actions .univer-libre-toolbar-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: -2px;
}

/* Цветные индикаторы для сортировки */
.univer-libre-toolbar-actions .univer-libre-toolbar-btn[data-action="sort-asc"] {
  background: rgba(76, 175, 80, 0.25);
}

.univer-libre-toolbar-actions .univer-libre-toolbar-btn[data-action="sort-asc"]:hover {
  background: rgba(76, 175, 80, 0.35);
}

.univer-libre-toolbar-actions .univer-libre-toolbar-btn[data-action="sort-desc"] {
  background: rgba(244, 67, 54, 0.25);
}

.univer-libre-toolbar-actions .univer-libre-toolbar-btn[data-action="sort-desc"]:hover {
  background: rgba(244, 67, 54, 0.35);
}

/* Тема страницы: data-theme на html, .dark на body */
.univer-calc-container[data-theme="dark"] .univer-libre-title-bar,
.dark .univer-calc-container .univer-libre-title-bar,
[data-theme="dark"] .univer-calc-container .univer-libre-title-bar {
  background: #202020;
  color: #e8e8e8;
}

.univer-calc-container[data-theme="dark"] .univer-libre-menu-bar,
.dark .univer-calc-container .univer-libre-menu-bar,
[data-theme="dark"] .univer-calc-container .univer-libre-menu-bar {
  background: #202020;
  color: #e8e8e8;
}

.univer-calc-container[data-theme="dark"] .univer-libre-toolbar,
.dark .univer-calc-container .univer-libre-toolbar,
[data-theme="dark"] .univer-calc-container .univer-libre-toolbar {
  background: #202020;
}

.univer-calc-container #univer-calc-app {
  flex: 1;
  min-height: 280px;
  width: 100%;
  position: relative;
  /* scrollbar-gutter: stable здесь провоцировал колебания ширины вложенного грида Univer. */
  min-width: 0;
}

/* Меньше отступ сверху у поля ввода формулы (при двойном клике по ячейке и после F4) */
.univer-calc-container #univer-calc-app > div > div:first-child {
  padding-top: 0.25rem !important;
}

/* После F4 Univer перерисовывает и вешает .univer-pt-4 (1rem) на верхний ряд — убираем лишний отступ */
.univer-calc-container #univer-calc-app .univer-pt-4,
.univer-calc-container #univer-calc-app .univer-pt-14 {
  padding-top: 0.25rem !important;
}

/* Первая строка грида (строка формул) — без лишнего отступа сверху */
.univer-calc-container #univer-calc-app [class*="univer-grid-rows"] > *:first-child {
  padding-top: 0.25rem !important;
  margin-top: 0 !important;
}

/* Редактор в ячейке: одна строка; родитель не растягивать на 2 строки (после F4 / лишний абзац в модели) */
.univer-calc-container #univer-calc-app div:has(> [id*="INTERNAL_EDITOR"][id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"])) {
  max-height: 36px !important;
  min-height: 0 !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}
.univer-calc-container #univer-calc-app [id*="INTERNAL_EDITOR"][id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  min-height: 0 !important;
  max-height: 28px !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  align-items: center !important;
  justify-content: flex-start !important;
}
.univer-calc-container #univer-calc-app [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) {
  padding-top: 0 !important;
  min-height: 0;
}
.univer-calc-container #univer-calc-app [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) > div:empty,
.univer-calc-container #univer-calc-app [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) > p:empty {
  display: none !important;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}
.univer-calc-container #univer-calc-app [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) [contenteditable="true"] {
  padding-top: 2px !important;
  padding-bottom: 2px !important;
  margin: 0 !important;
  line-height: 1.35 !important;
  max-height: 2em !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  white-space: pre !important;
  vertical-align: middle;
}

/* Тёмная тема: фон контейнера Univer и ячеек */
.univer-calc-container[data-theme="dark"] #univer-calc-app,
[data-theme="dark"] .univer-calc-container #univer-calc-app {
  background: #1a1a1a !important;
}
/* Тёмная тема: вся строка формул (над и под полем A1) — фон #202020 */
.univer-calc-container[data-theme="dark"] #univer-calc-app > div,
.univer-calc-container[data-theme="dark"] #univer-calc-app > div > div:first-child,
.univer-calc-container[data-theme="dark"] #univer-calc-app [class*="univer-grid-rows"] > *:first-child,
.univer-calc-container[data-theme="dark"] #univer-calc-app .univer-pt-4,
.univer-calc-container[data-theme="dark"] #univer-calc-app .univer-pt-14,
.univer-calc-container[data-theme="dark"] #univer-calc-app div:has(> input:not([data-neuroege-rus-value])),
[data-theme="dark"] .univer-calc-container #univer-calc-app > div,
[data-theme="dark"] .univer-calc-container #univer-calc-app > div > div:first-child,
[data-theme="dark"] .univer-calc-container #univer-calc-app [class*="univer-grid-rows"] > *:first-child,
[data-theme="dark"] .univer-calc-container #univer-calc-app .univer-pt-4,
[data-theme="dark"] .univer-calc-container #univer-calc-app .univer-pt-14,
[data-theme="dark"] .univer-calc-container #univer-calc-app div:has(> input:not([data-neuroege-rus-value])) {
  background: #202020 !important;
}
/* Тёмная тема: угол на пересечении заголовков колонок и строк */
.univer-calc-container[data-theme="dark"] #univer-calc-app [class*="corner"],
.univer-calc-container[data-theme="dark"] #univer-calc-app [class*="Corner"],
.univer-calc-container[data-theme="dark"] #univer-calc-app [class*="sheet-corner"],
[data-theme="dark"] .univer-calc-container #univer-calc-app [class*="corner"],
[data-theme="dark"] .univer-calc-container #univer-calc-app [class*="Corner"],
[data-theme="dark"] .univer-calc-container #univer-calc-app [class*="sheet-corner"] {
  background: #202020 !important;
}
/* Тёмная тема: поле имён (A1) — координаты активной ячейки */
.univer-calc-container[data-theme="dark"] #univer-calc-app input:not([data-neuroege-rus-value]),
[data-theme="dark"] .univer-calc-container #univer-calc-app input:not([data-neuroege-rus-value]) {
  background: #202020 !important;
  color: #e8e8e8 !important;
  border-color: #444 !important;
}

/* Поле координаты ячейки (A1): выравнивание по центру */
.univer-calc-container #univer-calc-app input:not([data-neuroege-rus-value]) {
  text-align: center !important;
  text-align-last: center !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

/* Тёмная тема: фон и цвет текста редактора в ячейке (включая портал — двойной клик не должен красить в чёрный) */
.univer-calc-container[data-theme="dark"] #univer-calc-app div:has(> [id*="INTERNAL_EDITOR"][id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"])),
[data-theme="dark"] .univer-calc-container #univer-calc-app div:has(> [id*="INTERNAL_EDITOR"][id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"])),
[data-theme="dark"] div:has(> [id*="INTERNAL_EDITOR"][id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"])),
[data-theme="dark"] .univer-calc-container #univer-calc-app [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]),
[data-theme="dark"] [id*="INTERNAL_EDITOR"][id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]),
[data-theme="dark"] [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) {
  background: #1a1a1a !important;
  color: #e8e8e8 !important;
}

/* Убрать чёрный фон у contenteditable при редактировании ячейки */
[data-theme="dark"] [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) [contenteditable="true"],
[data-theme="dark"] .univer-calc-container [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) [contenteditable="true"] {
  background: #1a1a1a !important;
}

/* Светлая тема: фон Univer и ячейки — светлые (переопределяем Univer) */
.univer-calc-container[data-theme="light"] #univer-calc-app,
.univer-calc-container[data-theme="light"] #univer-calc-app > div,
[data-theme="light"] .univer-calc-container #univer-calc-app,
[data-theme="light"] .univer-calc-container #univer-calc-app > div {
  background: #ffffff !important;
}
.univer-calc-container[data-theme="light"] #univer-calc-app div:has(> [id*="INTERNAL_EDITOR"][id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"])),
.univer-calc-container[data-theme="light"] #univer-calc-app [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]),
[data-theme="light"] .univer-calc-container #univer-calc-app div:has(> [id*="INTERNAL_EDITOR"][id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"])),
[data-theme="light"] .univer-calc-container #univer-calc-app [id*="DOCS_NORMAL"]:not([id*="FORMULA_BAR"]) {
  background: #ffffff !important;
  color: #1a1a1a !important;
}

/* Полоса «Формула (русский вариант)» — всегда видна, над областью строки формул Univer */
.neuroege-formula-rus-strip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  padding: 4px 10px;
  margin-top: -10px;
  margin-left: 80px;
  background: #202020;
  border-bottom: none;
  font-size: 13px;
  font-family: "Liberation Mono", "DejaVu Sans Mono", Consolas, monospace;
  line-height: 1.4;
  color: #0d3d0d;
  box-sizing: border-box;
  position: relative;
  z-index: 2;
}
/* Univer app подтягивается вверх — строка формул оказывается под полосой, названия колонок остаются видимыми */
.neuroege-formula-rus-strip ~ #univer-calc-app {
  margin-top: -32px;
  position: relative;
  z-index: 1;
}
.dark .neuroege-formula-rus-strip,
.univer-calc-container[data-theme="dark"] .neuroege-formula-rus-strip,
[data-theme="dark"] .neuroege-formula-rus-strip {
  background: #202020;
  border-bottom-color: transparent;
  color: inherit;
}

.univer-calc-container[data-theme="light"] .neuroege-formula-rus-strip {
  background: #f2f2f2;
  color: #1a1a1a;
}

.univer-calc-container[data-theme="light"] .neuroege-formula-rus-strip__sigma,
.univer-calc-container[data-theme="light"] .neuroege-formula-rus-strip__dropdown,
.univer-calc-container[data-theme="light"] .neuroege-formula-rus-strip__equals {
  color: #1a1a1a;
}

.univer-calc-container[data-theme="light"] .neuroege-formula-rus-strip__input {
  background: #f2f2f2;
  color: #1a1a1a;
  border-color: #d0d0d0;
}

.univer-calc-container[data-theme="light"] .neuroege-formula-rus-strip__input:focus {
  background: #f2f2f2;
  outline-color: #999;
}

.univer-calc-container[data-theme="light"] .neuroege-formula-rus-strip__input::placeholder {
  color: rgba(0, 0, 0, 0.4);
}
.neuroege-formula-rus-strip__icons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding-right: 8px;
  visibility: visible;
}
.neuroege-formula-rus-strip__fx {
  font-size: 14px;
  font-style: italic;
  font-weight: 600;
  color: #2563eb;
}
.neuroege-formula-rus-strip__sigma {
  font-size: 18px;
  color: #fff;
  line-height: 1;
}
.neuroege-formula-rus-strip__dropdown {
  font-size: 10px;
  color: #fff;
  line-height: 1;
}
.neuroege-formula-rus-strip__equals {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}
.neuroege-formula-rus-strip__input {
  flex: 1;
  min-width: 0;
  width: 0;
  font-size: 13px;
  line-height: 1.35;
  background: #202020;
  color: #fff;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 8px;
  margin: 0;
  font-family: inherit;
  box-sizing: border-box;
}
.neuroege-formula-rus-strip__input:focus {
  outline: 2px solid #555;
  outline-offset: 1px;
  background: #202020;
}
.dark .neuroege-formula-rus-strip__input,
.univer-calc-container[data-theme="dark"] .neuroege-formula-rus-strip__input {
  background: #202020;
  color: #fff;
  border-color: #444;
}
.dark .neuroege-formula-rus-strip__input:focus,
.univer-calc-container[data-theme="dark"] .neuroege-formula-rus-strip__input:focus {
  background: #202020;
}
.neuroege-formula-rus-strip__input::placeholder {
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
}
.dark .neuroege-formula-rus-strip__input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

/* Зеркало русской формулы поверх строки формул Univer (модель рисует латиницу) */
.neuroege-formula-bar-rus-mirror {
  position: fixed;
  display: none;
  z-index: 2147483645;
  pointer-events: none;
  overflow: hidden;
  white-space: pre;
  box-sizing: border-box;
  margin: 0;
  border: none;
  outline: none;
}
body.neuroege-fb-rus-mirror-on [data-editorid*="FORMULA_BAR"] [contenteditable="true"],
body.neuroege-fb-rus-mirror-on [data-editorid*="FORMULA_BAR"][contenteditable="true"] {
  color: transparent !important;
  -webkit-text-fill-color: transparent !important;
  text-shadow: none !important;
}

/* Зеркало русской формулы поверх плавающего редактора ячейки при range-pick (как строка формул) */
.neuroege-native-cell-inplace-rus-mirror {
  position: fixed;
  display: none;
  z-index: 2147483645;
  pointer-events: none;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-all;
  box-sizing: border-box;
  margin: 0;
  border: none;
  outline: none;
}
body.neuroege-native-cell-rus-mirror-on [contenteditable="true"][data-neuroege-native-rus-mirror="1"] {
  color: transparent !important;
  -webkit-text-fill-color: transparent !important;
  text-shadow: none !important;
}

.neuroege-formula-fn-hint {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2147483646;
  max-width: 520px;
  padding: 8px 10px;
  background: #faf8e8;
  border: 1px solid #b8b88a;
  border-radius: 3px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  font-family: Liberation Sans, "DejaVu Sans", Arial, sans-serif;
  line-height: 1.35;
  pointer-events: none;
  display: none;
  color: #1a1a1a;
}
.neuroege-formula-fn-hint--visible {
  display: block;
}
.neuroege-formula-fn-hint__names {
  font-weight: 600;
  margin-bottom: 6px;
  word-wrap: break-word;
}
.neuroege-formula-fn-hint__desc {
  color: #333;
  font-weight: normal;
}

/* Univer root needs explicit height */
.calc-widget--univer .univer-calc-container {
  min-height: 360px;
}

.calc-widget--univer .calc-answer {
  flex-shrink: 0;
  padding: 0.75rem;
  border-top: 1px solid var(--border, rgba(255,255,255,0.1));
}

/* Диалог «Сохранить как» в стиле Excel/LibreOffice */
.univer-saveas {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}
.univer-saveas[hidden] {
  display: none !important;
}
.univer-saveas-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.univer-saveas-window {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: #3c3c3c;
  border: 1px solid #555;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  font-family: Liberation Sans, Arial, sans-serif;
}
.univer-saveas-title {
  padding: 10px 14px;
  background: #0078d4;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border-radius: 4px 4px 0 0;
}
.univer-saveas-body {
  padding: 16px 14px;
  color: #e0e0e0;
  font-size: 12px;
}
.univer-saveas-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.univer-saveas-row:last-child {
  margin-bottom: 0;
}
.univer-saveas-row label {
  flex-shrink: 0;
  width: 90px;
  text-align: right;
}
.univer-saveas-input,
.univer-saveas-select {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #666;
  border-radius: 3px;
  font-size: 12px;
  font-family: inherit;
}
.univer-saveas-input:focus,
.univer-saveas-select:focus {
  outline: 2px solid #0078d4;
  outline-offset: 1px;
  border-color: #0078d4;
}
.univer-saveas-select {
  cursor: pointer;
}
.univer-saveas-footer {
  padding: 12px 14px;
  background: #2d2d2d;
  border-top: 1px solid #444;
  border-radius: 0 0 4px 4px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.univer-saveas-btn {
  padding: 6px 16px;
  font-size: 12px;
  font-family: inherit;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.univer-saveas-btn--primary {
  background: #0078d4;
  color: #fff;
  border-color: #006cbd;
}
.univer-saveas-btn--primary:hover {
  background: #1084d8;
}
.univer-saveas-btn--secondary {
  background: #4a4a4a;
  color: #e0e0e0;
  border-color: #555;
}
.univer-saveas-btn--secondary:hover {
  background: #5a5a5a;
}
/* Тёмная тема — подстраиваем под контейнер */
.univer-calc-container[data-theme="dark"] .univer-saveas-window,
[data-theme="dark"] .univer-saveas-window {
  background: #252525;
  border-color: #444;
}
.univer-calc-container[data-theme="dark"] .univer-saveas-footer,
[data-theme="dark"] .univer-saveas-footer {
  background: #1e1e1e;
  border-top-color: #333;
}

/* Диалог «Сортировка» в стиле LibreOffice Calc */
.univer-sort-dialog {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}
.univer-sort-dialog[hidden] {
  display: none !important;
}
.univer-sort-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.univer-sort-window {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: #3c3c3c;
  border: 1px solid #555;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  font-family: Liberation Sans, Arial, sans-serif;
}
.univer-sort-window--calc {
  max-width: 560px;
  display: flex;
  flex-direction: column;
}
.univer-sort-title {
  padding: 10px 14px;
  background: #1a1a1a;
  color: #e8e8e8;
  font-size: 13px;
  font-weight: 600;
  border-radius: 4px 4px 0 0;
  border-bottom: 1px solid #333;
}
.univer-sort-panels {
  display: flex;
  flex: 1;
  min-height: 260px;
}
.univer-sort-sidebar {
  width: 130px;
  flex-shrink: 0;
  background: #2d2d2d;
  border-right: 1px solid #444;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.univer-sort-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: #b0b0b0;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.univer-sort-tab:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.06);
  color: #e0e0e0;
}
.univer-sort-tab:disabled {
  cursor: default;
  opacity: 0.6;
}
.univer-sort-tab--active {
  background: #185abd !important;
  color: #fff !important;
}
.univer-sort-tab-img {
  display: block;
  width: auto;
  height: 56px;
  max-width: 100%;
  object-fit: contain;
}
.univer-sort-tab[data-sort-tab="criteria"] .univer-sort-tab-img--active,
.univer-sort-tab[data-sort-tab="options"] .univer-sort-tab-img--active {
  display: none;
}
.univer-sort-tab--active[data-sort-tab="criteria"] .univer-sort-tab-img--default,
.univer-sort-tab--active[data-sort-tab="options"] .univer-sort-tab-img--default {
  display: none;
}
.univer-sort-tab--active[data-sort-tab="criteria"] .univer-sort-tab-img--active,
.univer-sort-tab--active[data-sort-tab="options"] .univer-sort-tab-img--active {
  display: block;
}
.univer-sort-content {
  flex: 1;
  overflow: auto;
  padding: 16px 18px;
  background: #252525;
  color: #e0e0e0;
  font-size: 12px;
}
.univer-sort-pane {
  display: block;
}
.univer-sort-key {
  margin-bottom: 14px;
}
.univer-sort-key:last-of-type {
  margin-bottom: 16px;
}
.univer-sort-key-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: #e8e8e8;
}
.univer-sort-key-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.univer-sort-key-col {
  display: flex;
  align-items: center;
  gap: 8px;
}
.univer-sort-key-radios {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}
.univer-sort-key-sub {
  color: #a0a0a0;
  font-size: 11px;
  min-width: 52px;
}
.univer-sort-select {
  min-width: 100px;
  padding: 5px 8px;
  background: #3a3a3a;
  color: #e0e0e0;
  border: 1px solid #555;
  border-radius: 3px;
  font-size: 12px;
}
.univer-sort-select:focus {
  outline: 2px solid #185abd;
  outline-offset: 1px;
}
.univer-sort-radio,
.univer-sort-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: normal;
  color: #c8c8c8;
}
.univer-sort-key--disabled .univer-sort-key-label,
.univer-sort-key--disabled .univer-sort-key-sub,
.univer-sort-key--disabled .univer-sort-radio {
  color: #707070;
}
.univer-sort-key--disabled .univer-sort-select {
  opacity: 0.6;
  cursor: not-allowed;
}
.univer-sort-params {
  padding-top: 14px;
  border-top: 1px solid #404040;
}
.univer-sort-params-title {
  font-weight: 600;
  margin-bottom: 10px;
  color: #e0e0e0;
}
.univer-sort-param {
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.univer-sort-param:last-child {
  margin-bottom: 0;
}
.univer-sort-param-label {
  flex-shrink: 0;
  min-width: 70px;
  color: #a0a0a0;
}
.univer-sort-param-radios {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.univer-sort-footer {
  padding: 12px 16px;
  background: #1e1e1e;
  border-top: 1px solid #333;
  border-radius: 0 0 4px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.univer-sort-footer-right {
  display: flex;
  gap: 8px;
}
.univer-sort-btn {
  padding: 6px 16px;
  font-size: 12px;
  font-family: inherit;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.univer-sort-btn--primary {
  background: #185abd;
  color: #fff;
  border-color: #134a9a;
}
.univer-sort-btn--primary:hover {
  background: #1e6ad4;
}
.univer-sort-btn--primary:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}
.univer-sort-btn--secondary {
  background: #3a3a3a;
  color: #e0e0e0;
  border-color: #505050;
}
.univer-sort-btn--secondary:hover {
  background: #454545;
}
.univer-sort-btn--help {
  background: transparent;
  color: #a0a0a0;
  border-color: transparent;
}
.univer-sort-btn--help:hover {
  color: #e0e0e0;
}
.univer-filter-body {
  padding: 16px 18px;
  background: #252525;
  color: #e0e0e0;
  font-size: 12px;
}
.univer-filter-row {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.univer-filter-row:last-of-type {
  margin-bottom: 0;
}
.univer-filter-label {
  color: #a0a0a0;
  flex-shrink: 0;
}
.univer-filter-values {
  max-height: 180px;
  overflow-y: auto;
  padding: 8px;
  background: #1e1e1e;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.univer-filter-values label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #c8c8c8;
}
.univer-filter-values label:hover {
  color: #e0e0e0;
}
