/* Плавающий AI-чат (Qwen) — только страницы hyperformula */
.neuroege-ai-chat {
  --ne-ai-chat-surface: rgba(35, 40, 45, 0.92);
  --ne-ai-chat-border: rgba(255, 255, 255, 0.12);
  position: fixed;
  right: 1rem;
  bottom: 1.25rem;
  z-index: 10060;
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.875rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: min(100vw - 2rem, calc(22rem * 1.3));
  pointer-events: none;
}

/* Ширина: якорь из JS (task9 в окне — .task-solve__right; иначе условие ×1.3) */
.neuroege-ai-chat.neuroege-ai-chat--anchored {
  max-width: none;
}

.neuroege-ai-chat.neuroege-ai-chat--anchored .neuroege-ai-chat__panel {
  width: 100%;
  max-width: none;
}

.neuroege-ai-chat.neuroege-ai-chat--dock-right {
  align-items: stretch;
  gap: 0;
}

.neuroege-ai-chat.neuroege-ai-chat--dock-right .neuroege-ai-chat__panel {
  width: 100%;
  height: 100%;
  max-height: none;
}

.neuroege-ai-chat.neuroege-ai-chat--dock-right .neuroege-ai-chat__resize-handle {
  display: none;
}

.neuroege-ai-chat * {
  pointer-events: auto;
}

/* Панель не должна перехватывать клики вне своих блоков (flex-gap и т.п.) — иначе перекрывает chrome Calc, кнопка «Развернуть». */
.neuroege-ai-chat .neuroege-ai-chat__panel.neuroege-ai-chat__panel--open {
  pointer-events: none;
}

.neuroege-ai-chat .neuroege-ai-chat__panel.neuroege-ai-chat__panel--open > * {
  pointer-events: auto;
}

/* Colibre chrome выше панели чата (10060), чтобы клик доходил без обходного pointerdown в JS где возможно */
#fortune-sheet-calc-container > .univer-libre-title-bar {
  z-index: 10070;
}

#fortune-sheet-calc-container > .fortune-lo-menubar {
  z-index: 10075;
}

#fortune-sheet-calc-container > .univer-libre-toolbar.fortune-lo-toolbar {
  z-index: 10072;
}

.neuroege-ai-chat__fab {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  border: 1px solid var(--ne-ai-chat-border);
  background: var(--green, #05b87d);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  line-height: 1;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.neuroege-ai-chat__fab:hover {
  transform: scale(1.04);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.neuroege-ai-chat__fab:focus-visible {
  outline: 2px solid var(--green, #05b87d);
  outline-offset: 2px;
}

.neuroege-ai-chat__fab[aria-expanded="true"] {
  display: none;
}

.neuroege-ai-chat__panel {
  display: none;
  flex-direction: column;
  min-height: 0;
  width: min(100vw - 2rem, calc(22rem * 1.3));
  max-height: min(70vh, 28rem);
  border-radius: 12px;
  border: 1px solid var(--ne-ai-chat-border);
  background: var(--ne-ai-chat-surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.neuroege-ai-chat__panel--open {
  display: flex;
}

.neuroege-ai-chat__resize-handle {
  flex-shrink: 0;
  height: 8px;
  margin: -2px 0 0;
  padding: 2px 0;
  box-sizing: content-box;
  cursor: ns-resize;
  touch-action: none;
  background: transparent;
  position: relative;
}

.neuroege-ai-chat__resize-handle::after {
  content: "";
  position: absolute;
  left: 25%;
  right: 25%;
  top: 50%;
  transform: translateY(-50%);
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
  pointer-events: none;
}

.neuroege-ai-chat__resize-handle:hover::after {
  background: rgba(5, 184, 125, 0.55);
}

[data-theme="light"] .neuroege-ai-chat__resize-handle::after {
  background: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .neuroege-ai-chat__resize-handle:hover::after {
  background: rgba(5, 184, 125, 0.45);
}

[data-theme="light"] .neuroege-ai-chat {
  --ne-ai-chat-surface: rgba(255, 255, 255, 0.95);
  --ne-ai-chat-border: rgba(0, 0, 0, 0.1);
}

.neuroege-ai-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--ne-ai-chat-border);
  color: var(--white, #fff);
  font-weight: 600;
}

[data-theme="light"] .neuroege-ai-chat__head {
  color: var(--white, #1d1d1f);
}

.neuroege-ai-chat__close {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
  opacity: 0.75;
}

.neuroege-ai-chat__close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] .neuroege-ai-chat__close:hover {
  background: rgba(0, 0, 0, 0.06);
}

.neuroege-ai-chat__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--white, #fff);
}

[data-theme="light"] .neuroege-ai-chat__messages {
  color: var(--white, #1d1d1f);
}

.neuroege-ai-chat__msg {
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
}

.neuroege-ai-chat__msg strong {
  font-weight: 700;
}

.neuroege-ai-chat__msg em {
  font-style: italic;
}

.neuroege-ai-chat__msg code {
  font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace;
  font-size: 0.84em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  word-break: break-all;
}

[data-theme="light"] .neuroege-ai-chat__msg code {
  background: rgba(0, 0, 0, 0.08);
}

.neuroege-ai-chat__pre {
  margin: 0.35rem 0;
  padding: 0.5rem 0.55rem;
  max-width: 100%;
  overflow-x: auto;
  border-radius: 6px;
  border: 1px solid var(--ne-ai-chat-border, rgba(255, 255, 255, 0.15));
  background: rgba(0, 0, 0, 0.35);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.neuroege-ai-chat__pre code {
  display: block;
  padding: 0;
  background: transparent;
  white-space: pre-wrap;
  word-break: break-word;
}

[data-theme="light"] .neuroege-ai-chat__pre {
  background: rgba(0, 0, 0, 0.06);
}

.neuroege-ai-chat__msg--user {
  align-self: flex-end;
  background: rgba(5, 184, 125, 0.25);
  max-width: 92%;
}

.neuroege-ai-chat__msg--assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  max-width: 100%;
}

.neuroege-ai-chat__msg--assistant.neuroege-ai-chat__msg--streaming {
  min-height: 2.25rem;
}

.neuroege-ai-chat__stream-tail {
  white-space: pre-wrap;
  word-break: break-word;
}

[data-theme="light"] .neuroege-ai-chat__msg--assistant {
  background: rgba(0, 0, 0, 0.06);
}

.neuroege-ai-chat__thinking {
  align-self: flex-start;
  display: inline-flex;
  align-items: baseline;
  gap: 0.2rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted, rgba(255, 255, 255, 0.55));
  font-size: 0.875rem;
  line-height: 1.4;
}

[data-theme="light"] .neuroege-ai-chat__thinking {
  background: rgba(0, 0, 0, 0.05);
  color: rgba(29, 29, 31, 0.55);
}

.neuroege-ai-chat__thinking-label {
  font-style: italic;
}

.neuroege-ai-chat__thinking-dots span {
  display: inline-block;
  animation: neuroege-ai-thinking-dot 1.05s ease-in-out infinite;
  opacity: 0.25;
}

.neuroege-ai-chat__thinking-dots span:nth-child(1) {
  animation-delay: 0s;
}

.neuroege-ai-chat__thinking-dots span:nth-child(2) {
  animation-delay: 0.18s;
}

.neuroege-ai-chat__thinking-dots span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes neuroege-ai-thinking-dot {
  0%,
  100% {
    opacity: 0.2;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.neuroege-ai-chat__foot {
  padding: 0.5rem 0.6rem 0.65rem;
  border-top: 1px solid var(--ne-ai-chat-border);
  display: flex;
  gap: 0.4rem;
}

.neuroege-ai-chat__input {
  flex: 1;
  line-height: 1.45;
  min-height: calc(2 * 1.45em + 0.9rem);
  max-height: min(38vh, 12rem);
  height: auto;
  resize: none;
  overflow-y: hidden;
  border-radius: 8px;
  border: 1px solid var(--ne-ai-chat-border);
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  padding: 0.45rem 0.55rem;
  font: inherit;
  box-sizing: border-box;
}

[data-theme="light"] .neuroege-ai-chat__input {
  background: rgba(255, 255, 255, 0.9);
}

.neuroege-ai-chat__input:focus {
  outline: 2px solid var(--green, #05b87d);
  outline-offset: 0;
}

.neuroege-ai-chat__send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  padding: 0 0.5rem;
  border-radius: 8px;
  border: none;
  background: var(--green, #05b87d);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.neuroege-ai-chat__send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.neuroege-ai-chat__hint {
  padding: 0 0.75rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted, rgba(255, 255, 255, 0.55));
  line-height: 1.35;
}

/* /python/: открытый чат на всю высоту правой колонки */
body.neuroege-python-playground-page.fortune-page-task9
  .fortune-task9-page.task-solve-page
  > .task-solve__right {
  position: relative;
}
body.neuroege-python-playground-page.fortune-page-task9
  .fortune-task9-page.task-solve-page
  > .task-solve__right
  #neuroege-ai-chat.neuroege-ai-chat--anchored.neuroege-ai-chat--dock-right {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  width: auto;
  max-width: none;
  height: auto;
}

/* /python/: FAB в углу окна, если панель закрыта и сработала привязка к колонке (остаточные стили) */
body.neuroege-python-playground-page.fortune-page-task9
  #neuroege-ai-chat:not(.neuroege-ai-chat--anchored):not(.neuroege-ai-chat--dock-right) {
  position: fixed !important;
  right: 1rem !important;
  bottom: 1.25rem !important;
  top: auto !important;
  left: auto !important;
  width: auto !important;
  max-width: min(100vw - 2rem, calc(22rem * 1.3)) !important;
  height: auto !important;
}

/* HF задание 1: чат в колонке под «Показать ответ» (класс из шаблона ai_chat_hf_task1_inflow).
   Правила здесь, а не только в <head> task1: иначе базовый .neuroege-ai-chat { position:fixed; z-index:10060 }
   из этого же файла визуально перекрывает условие до/вместо выполнения JS. */
body.fortune-page-task1.neuroege-hyperformula-page
  #fortune-task9-statement-wrap
  .neuroege-ai-chat.neuroege-ai-chat--hf-task1-inflow {
  position: relative !important;
  right: auto !important;
  bottom: auto !important;
  top: auto !important;
  left: auto !important;
  width: 100% !important;
  max-width: none !important;
  z-index: 2 !important;
  align-items: stretch !important;
}

body.fortune-page-task1.neuroege-hyperformula-page
  #fortune-task9-statement-wrap
  .neuroege-ai-chat.neuroege-ai-chat--hf-task1-inflow
  .neuroege-ai-chat__panel {
  width: 100% !important;
  max-width: none !important;
}

/* То же без предка #fortune-task9-statement-wrap — на случай смены DOM/кэша шаблона */
body.fortune-page-task1.neuroege-hyperformula-page
  #neuroege-ai-chat.neuroege-ai-chat--hf-task1-inflow {
  position: relative !important;
  right: auto !important;
  bottom: auto !important;
  top: auto !important;
  left: auto !important;
  width: 100% !important;
  max-width: none !important;
  z-index: 2 !important;
  align-items: stretch !important;
}

body.fortune-page-task1.neuroege-hyperformula-page
  #neuroege-ai-chat.neuroege-ai-chat--hf-task1-inflow
  .neuroege-ai-chat__panel {
  width: 100% !important;
  max-width: none !important;
}
