/*
 * НейроОфис: карточка уточняющих вопросов (ask_user_question, LibreChat v0.8.8).
 * Подключается из index.html при сборке образа (docker/brand.mjs).
 *
 * Все правила привязаны к структуре компонента AskUserQuestions:
 *   корень   — div, у которого прямой потомок-контейнер содержит fieldset[tabindex="-1"][aria-labelledby]
 *              (такой fieldset в клиенте один — шаг пакета вопросов);
 *   панель   — .popover над полем ввода, внутри которой этот корень;
 *   итог     — свёрнутая карточка заданных вопросов в чате ([data-testid="ask-user-question-call"]).
 * Темы высокой контрастности (html.high-contrast) не затрагиваются.
 */

/* ------------------------------------------------------------------ токены */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]),
html:not(.high-contrast) .popover:has(> div > div > fieldset[tabindex="-1"][aria-labelledby]),
html:not(.high-contrast) .popover.\[view-transition-name\:ask-question\] {
  --nq-accent: #2f55ff;
  --nq-accent-hover: #2446e6;
  --nq-accent-ink: #2f55ff;
  --nq-accent-tint: rgba(47, 85, 255, 0.06);
  --nq-accent-tint-hover: rgba(47, 85, 255, 0.1);
  --nq-accent-line: rgba(47, 85, 255, 0.55);
  --nq-ring: rgba(47, 85, 255, 0.3);
  --nq-on-accent: #ffffff;
  --nq-surface: #ffffff;
  --nq-fg: #15171c;
  --nq-muted: #676c76;
  --nq-subtle: #8b909a;
  --nq-line: rgba(17, 24, 39, 0.1);
  --nq-line-strong: rgba(17, 24, 39, 0.2);
  --nq-hover: rgba(17, 24, 39, 0.035);
  --nq-disabled: rgba(17, 24, 39, 0.07);
  --nq-step: rgba(17, 24, 39, 0.14);
  --nq-step-done: rgba(47, 85, 255, 0.4);
  --nq-shadow: 0 1px 2px rgba(17, 24, 39, 0.05), 0 12px 32px -12px rgba(17, 24, 39, 0.18);
}
html.dark:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]),
html.dark:not(.high-contrast) .popover:has(> div > div > fieldset[tabindex="-1"][aria-labelledby]),
html.dark:not(.high-contrast) .popover.\[view-transition-name\:ask-question\] {
  --nq-accent: #2f55ff;
  --nq-accent-hover: #4466ff;
  --nq-accent-ink: #8099ff;
  --nq-accent-tint: rgba(47, 85, 255, 0.11);
  --nq-accent-tint-hover: rgba(47, 85, 255, 0.16);
  --nq-accent-line: rgba(110, 137, 255, 0.75);
  --nq-ring: rgba(96, 126, 255, 0.38);
  --nq-surface: #1c1c1e;
  --nq-fg: #ececf1;
  --nq-muted: #a1a3ab;
  --nq-subtle: #7d8089;
  --nq-line: rgba(255, 255, 255, 0.09);
  --nq-line-strong: rgba(255, 255, 255, 0.18);
  --nq-hover: rgba(255, 255, 255, 0.05);
  --nq-disabled: rgba(255, 255, 255, 0.08);
  --nq-step: rgba(255, 255, 255, 0.16);
  --nq-step-done: rgba(128, 153, 255, 0.5);
  --nq-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px -16px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------------ поверхность */
/* Панель над полем ввода: заголовок «Уточняющие вопросы» + шаги пакета. */
html:not(.high-contrast) .popover:has(> div > div > fieldset[tabindex="-1"][aria-labelledby]) {
  background: var(--nq-surface);
  border: 1px solid var(--nq-line);
  border-radius: 16px;
  box-shadow: var(--nq-shadow);
  color: var(--nq-fg);
  overflow: hidden;
}
html:not(.high-contrast) .popover:has(> div > div > fieldset[tabindex="-1"][aria-labelledby]) > div:first-child {
  border-bottom: 0;
  padding: 14px 12px 0 20px;
  gap: 12px;
}
html:not(.high-contrast) .popover:has(> div > div > fieldset[tabindex="-1"][aria-labelledby]) > div:first-child > p {
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  color: var(--nq-fg);
}
html:not(.high-contrast) .popover:has(> div > div > fieldset[tabindex="-1"][aria-labelledby]) > div:first-child button,
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.justify-end > button {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  color: var(--nq-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
html:not(.high-contrast) .popover:has(> div > div > fieldset[tabindex="-1"][aria-labelledby]) > div:first-child button:hover,
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.justify-end > button:hover {
  background: var(--nq-hover);
  color: var(--nq-fg);
}

/* Карточка в чате (тот же компонент без панели). */
html:not(.high-contrast) div.rounded-lg:has(> div > fieldset[tabindex="-1"][aria-labelledby]) {
  background: var(--nq-surface);
  border: 1px solid var(--nq-line);
  border-radius: 16px;
  color: var(--nq-fg);
  overflow: hidden;
}
/* Строка «развернуть / закрыть» над карточкой в чате: кнопки в правом верхнем углу, без отдельной полосы. */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) {
  position: relative;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.justify-end:first-child {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  border-bottom: 0;
  padding: 0;
  gap: 2px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.justify-end:first-child + div:has(> [role="group"]) {
  padding-top: 14px;
  padding-right: 48px;
}
/* без шагов (один вопрос) — освобождаем место под кнопки справа от заголовка */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.justify-end:first-child + div.overflow-y-auto > fieldset > :is(legend, p[id]) {
  padding-right: 40px;
}

/* ------------------------------------------------------------------ шаги */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div:has(> [role="group"]) {
  border-bottom: 1px solid var(--nq-line);
  padding: 4px 14px 12px 20px;
  min-height: 0;
}
html:not(.high-contrast) div.rounded-lg:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div:first-child:has(> [role="group"]) {
  padding-top: 14px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div:has(> [role="group"]) > p {
  font-size: 13px;
  line-height: 20px;
  font-weight: 400;
  color: var(--nq-muted);
  font-variant-numeric: tabular-nums;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > [role="group"] {
  gap: 2px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > [role="group"] > button {
  height: 20px;
  padding: 0 3px;
  border-radius: 6px;
  outline: none;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > [role="group"] > button:focus-visible {
  box-shadow: 0 0 0 2px var(--nq-ring);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > [role="group"] > button > span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--nq-step);
  transition: width 160ms ease, background-color 160ms ease;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > [role="group"] > button > span.bg-surface-submit {
  background: var(--nq-step-done);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > [role="group"] > button[aria-current="step"] > span {
  width: 18px;
  background: var(--nq-accent);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > [role="group"] > button:not([aria-current="step"]):not(:disabled):hover > span {
  background: var(--nq-line-strong);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > [role="group"] > button:not([aria-current="step"]):not(:disabled):hover > span.bg-surface-submit {
  background: var(--nq-accent-line);
}

/* ------------------------------------------------------------------ вопрос */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.overflow-y-auto {
  padding: 0 20px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset[tabindex="-1"] {
  padding: 18px 0 20px;
  min-height: 0;
}
/* legend по умолчанию ложится на верхнюю рамку fieldset и игнорирует его отступ — делаем обычным блоком */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > legend {
  float: left;
  width: 100%;
  padding: 0;
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 18px;
  font-weight: 400;
  color: var(--nq-muted);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > legend + * {
  clear: both;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > p[id] {
  font-size: 16px;
  line-height: 24px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--nq-fg);
  text-wrap: pretty;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > p:not([id]) {
  margin-top: 4px;
  font-size: 14px;
  line-height: 21px;
  color: var(--nq-muted);
  text-wrap: pretty;
}

/* ------------------------------------------------------------------ варианты */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 8px;
  margin-top: 16px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  max-width: none;
  min-height: 46px;
  height: auto;
  margin: 0;
  padding: 12px 16px 12px 14px;
  border: 1px solid var(--nq-line-strong);
  border-radius: 12px;
  background: transparent;
  color: var(--nq-fg);
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
  text-align: left;
  white-space: normal;
  opacity: 1;
  box-shadow: none;
  outline: none;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
/* индикатор выбора: круг (один ответ) или квадрат (несколько) */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button::before {
  content: "";
  flex: none;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 1.5px solid var(--nq-line-strong);
  border-radius: 999px;
  background: transparent;
  transition: border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button[role="checkbox"]::before {
  border-radius: 5px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button > svg {
  display: none;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button:hover:not(:disabled) {
  background: var(--nq-hover);
  border-color: var(--nq-subtle);
  color: var(--nq-fg);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button:hover:not(:disabled)::before {
  border-color: var(--nq-subtle);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button:focus-visible {
  border-color: var(--nq-accent);
  box-shadow: 0 0 0 3px var(--nq-ring);
}
/* выбранный вариант */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button:is([aria-pressed="true"], [aria-checked="true"]),
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button:is([aria-pressed="true"], [aria-checked="true"]):hover:not(:disabled) {
  background: var(--nq-accent-tint);
  border-color: var(--nq-accent-line);
  color: var(--nq-fg);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button:is([aria-pressed="true"], [aria-checked="true"]):hover:not(:disabled) {
  background: var(--nq-accent-tint-hover);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button[aria-pressed="true"]::before {
  border: 5px solid var(--nq-accent);
  background: var(--nq-on-accent, #fff);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button[aria-checked="true"]::before {
  border-color: var(--nq-accent);
  background: var(--nq-accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.4l2.6 2.6L12 5.4' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px 14px no-repeat;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] > button:disabled {
  opacity: 0.55;
}

/* ------------------------------------------------------------------ свой ответ */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > textarea {
  display: block;
  width: 100%;
  margin-top: 8px;
  min-height: 46px;
  padding: 12px 16px;
  border: 1px solid var(--nq-line-strong);
  border-radius: 12px;
  background: transparent;
  color: var(--nq-fg);
  font-size: 14px;
  line-height: 20px;
  box-shadow: none;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] + textarea {
  border-style: dashed;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > textarea::placeholder {
  color: var(--nq-subtle);
  opacity: 1;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > textarea:hover:not(:disabled):not(:focus) {
  border-color: var(--nq-subtle);
  background: var(--nq-hover);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] + textarea:focus,
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > div[role="group"] + textarea:not(:placeholder-shown) {
  border-style: solid;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div > fieldset > textarea:focus {
  border-color: var(--nq-accent);
  box-shadow: 0 0 0 3px var(--nq-ring);
}

/* ------------------------------------------------------------------ сообщения */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.text-text-warning {
  padding: 0 20px 12px;
  font-size: 13px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > button {
  align-self: flex-start;
  margin: 0 20px 12px;
  padding: 0;
  font-size: 13px;
  color: var(--nq-accent-ink);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > button:hover {
  color: var(--nq-accent-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ------------------------------------------------------------------ кнопки */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child {
  border-top: 1px solid var(--nq-line);
  padding: 12px 16px 12px 8px;
  gap: 8px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child button {
  height: 36px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: none;
  outline: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child button:focus-visible {
  box-shadow: 0 0 0 3px var(--nq-ring);
}
/* «Пропустить» — тихая текстовая кнопка */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child > button {
  border: 0;
  background: transparent;
  color: var(--nq-muted);
  padding: 0 12px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child > button:hover {
  background: var(--nq-hover);
  color: var(--nq-fg);
}
/* «Назад» — вторичная */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child > div > button:not(:last-child) {
  border: 1px solid var(--nq-line-strong);
  background: transparent;
  color: var(--nq-fg);
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child > div > button:not(:last-child):hover {
  background: var(--nq-hover);
  border-color: var(--nq-subtle);
}
/* на первом шаге «Назад» недоступна — не показываем */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child > div > button:not(:last-child):disabled {
  display: none;
}
/* «Далее» / «Отправить» — основная */
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child > div > button:last-child {
  border: 1px solid transparent;
  background: var(--nq-accent);
  color: #ffffff;
  min-width: 96px;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child > div > button:last-child:hover {
  background: var(--nq-accent-hover);
  color: #ffffff;
}
html:not(.high-contrast) div:has(> div > fieldset[tabindex="-1"][aria-labelledby]) > div.border-t:last-child > div > button:last-child:disabled {
  background: var(--nq-disabled);
  color: var(--nq-subtle);
  opacity: 1;
}

/* ------------------------------------------------------------------ один вопрос над полем ввода */
/* Тот же язык: акцент для отмеченных вариантов и «Отправить», без зелёного. */
html:not(.high-contrast) .popover.\[view-transition-name\:ask-question\] button[role="checkbox"][aria-checked="true"] > span:first-child {
  background: var(--nq-accent);
  color: #ffffff;
}
html:not(.high-contrast) .popover.\[view-transition-name\:ask-question\] > div:last-child button.bg-surface-submit {
  background: var(--nq-accent);
  color: #ffffff;
}
html:not(.high-contrast) .popover.\[view-transition-name\:ask-question\] > div:last-child button.bg-surface-submit:hover {
  background: var(--nq-accent-hover);
}

/* ------------------------------------------------------------------ итог в чате */
/* «Ваш ответ» — спокойная плашка вместо полосы слева. */
html:not(.high-contrast) [data-testid="ask-user-question-call"] ~ div > .overflow-hidden > div :is(.min-w-0 > div.border-l-2) {
  margin-top: 10px;
  padding: 10px 12px;
  border-left: 0;
  border-radius: 10px;
  background: rgba(17, 24, 39, 0.04);
}
html.dark:not(.high-contrast) [data-testid="ask-user-question-call"] ~ div > .overflow-hidden > div :is(.min-w-0 > div.border-l-2) {
  background: rgba(255, 255, 255, 0.05);
}
/* подписи «Тип приказа» и «Ваш ответ:» — спокойным текстом, без мелкого полужирного */
html:not(.high-contrast) [data-testid="ask-user-question-call"] ~ div > .overflow-hidden > div > div > p.mb-1.text-xs,
html:not(.high-contrast) [data-testid="ask-user-question-call"] ~ div > .overflow-hidden > div :is(.min-w-0 > div.border-l-2) > p:first-child {
  font-size: 13px;
  line-height: 18px;
  font-weight: 400;
}
