/* AI-панель Bi-cycle: плавающая кнопка + панель запроса к assistant API. */
#bi-assistant-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 9999;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: #1a4a8c;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
#bi-assistant-fab:hover { background: #0d6b9e; }
#bi-assistant-panel {
  position: fixed;
  right: 18px;
  bottom: 82px;
  z-index: 9999;
  width: 420px;
  max-width: calc(100vw - 36px);
  max-height: min(70vh, 640px);
  display: flex;
  flex-direction: column;
  background: #fff;
  color: #222;
  border: 1px solid #d9d9d9;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  font-family: Inter, Helvetica, Arial, sans-serif;
  font-size: 13px;
  overflow: hidden;
}
#bi-assistant-panel[hidden] { display: none; }
.bi-assistant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #1a4a8c;
  color: #fff;
  font-weight: 600;
}
.bi-assistant-head button {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
}
.bi-assistant-body {
  padding: 10px 12px;
  overflow-y: auto;
}
.bi-assistant-row { display: flex; gap: 6px; margin-bottom: 8px; }
.bi-assistant-row input[type="text"],
.bi-assistant-row input:not([type]) {
  flex: 1;
  min-width: 0;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
}
.bi-assistant-row button {
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  background: #1a4a8c;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.bi-assistant-row button:disabled { opacity: 0.5; cursor: default; }
.bi-assistant-result { margin-top: 4px; line-height: 1.45; }
.bi-assistant-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  margin-bottom: 6px;
  background: #e6f4ea;
  color: #137333;
}
.bi-assistant-badge.warn { background: #fef7e0; color: #b06000; }
.bi-assistant-badge.err { background: #fce8e6; color: #a50e0e; }
.bi-assistant-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.bi-assistant-chip {
  background: #f1f3f4;
  border: 1px solid #dadce0;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
}
/* SUGGEST-V1: чипы did-you-mean (кликабельные кнопки под текстом отказа). */
.bi-assistant-suggest { margin-top: 8px; }
.bi-assistant-suggest-group {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 4px 0;
}
.bi-assistant-suggest-label { font-size: 12px; opacity: 0.8; }
button.bi-assistant-suggest-chip { cursor: pointer; font: inherit; }
button.bi-assistant-suggest-chip:hover { border-color: #1a4a8c; }
button.bi-assistant-suggest-chip:focus-visible {
  outline: 2px solid #1a4a8c; outline-offset: 1px;
}
.bi-assistant-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.bi-assistant-actions a,
.bi-assistant-actions button {
  border: 1px solid #1a4a8c;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  background: #fff;
  color: #1a4a8c;
}
.bi-assistant-actions a.primary { background: #1a4a8c; color: #fff; }
.bi-assistant-table { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 12px; }
.bi-assistant-table th, .bi-assistant-table td { border-bottom: 1px solid #e0e0e0; padding: 3px 6px; text-align: left; }
.bi-assistant-table th { color: #5f6368; font-weight: 600; }
.bi-assistant-hint { color: #5f6368; font-size: 11px; margin-top: 6px; }
/* v5: шаги, история, блок ответа над сеткой дашборда */
.bi-assistant-steps { margin-top: 4px; line-height: 1.45; }
.bi-assistant-q { font-weight: 600; margin-bottom: 4px; }
ul.bi-assistant-steplist { list-style: none; margin: 4px 0; padding: 0; }
ul.bi-assistant-steplist li { color: #5f6368; font-size: 12px; padding: 1px 0; }
ul.bi-assistant-steplist li.active::after {
  content: ''; display: inline-block; width: 10px; height: 10px; margin-left: 6px;
  border: 2px solid #1a4a8c; border-top-color: transparent; border-radius: 50%;
  animation: bi-assistant-spin 0.8s linear infinite; vertical-align: -1px;
}
ul.bi-assistant-steplist li.done { color: #137333; }
@keyframes bi-assistant-spin { to { transform: rotate(360deg); } }
.bi-assistant-hist { margin-top: 8px; border-top: 1px solid #e0e0e0; padding-top: 6px; }
.bi-assistant-histitem {
  font-size: 12px; color: #1a4a8c; cursor: pointer; padding: 3px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bi-assistant-histitem:hover { text-decoration: underline; }
#bi-assistant-answer {
  border-radius: 12px;
  padding: 10px 14px; margin: 8px 0 12px; line-height: 1.45;
  font-family: Inter, Helvetica, Arial, sans-serif; font-size: 13px;
  box-shadow: none;
  box-sizing: border-box; width: 100%; max-width: 100%; overflow: hidden;
  grid-column: 1 / -1;  /* если родитель — грид дашборда: блок на всю ширину */
}
#bi-assistant-answer[hidden] { display: none; }
/* v26: две палитры под фактическую тему Superset (класс ставит biApplyTheme).
 * Светлая (дефолт Superset): блок сливается с белыми карточками. */
#bi-assistant-answer.bi-theme-light {
  color-scheme: light;
  background: #ffffff;
  border: 1px solid #d9d9d9;
  color: #1e2a3a;
}
.bi-theme-light .bi-assistant-answer-q { font-weight: 700; font-size: 14px; margin-bottom: 8px; color: #12315e; }
.bi-theme-light .bi-assistant-answer-text { margin: 6px 0; color: #1e2a3a; }
.bi-theme-light .bi-assistant-summaryline {
  font-weight: 700; font-size: 15px; line-height: 1.3; letter-spacing: 0.2px;
  margin: 6px 0 4px; color: #0d2f5e;
  background: #e8eff9; border-radius: 6px; padding: 6px 10px; display: inline-block;
}
.bi-theme-light .bi-assistant-chip { background: #eef3fa; border-color: #b9cbe8; color: #12315e; }
.bi-theme-light .bi-assistant-hint { color: #47617f; }
.bi-theme-light .bi-assistant-badge { background: #d7e6c9; color: #1e5b1e; }
.bi-theme-light .bi-assistant-badge.warn { background: #fdf0c2; color: #8a4d00; }
.bi-theme-light .bi-assistant-badge.err { background: #fbd9d5; color: #8f0d0d; }
.bi-theme-light .bi-assistant-actions button {
  background: #fff; border-color: #1a4a8c; color: #1a4a8c;
}
/* Тёмная (переключатель в настройках пользователя): цвета карточек дашборда. */
#bi-assistant-answer.bi-theme-dark {
  color-scheme: dark;
  background: #1c2126;
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: #e6e9ee;
}
.bi-theme-dark .bi-assistant-answer-q { font-weight: 700; font-size: 14px; margin-bottom: 8px; color: #ffffff; }
.bi-theme-dark .bi-assistant-answer-text { margin: 6px 0; color: #e6e9ee; }
.bi-theme-dark .bi-assistant-summaryline {
  font-weight: 700; font-size: 15px; line-height: 1.3; letter-spacing: 0.2px;
  margin: 6px 0 4px; color: #ffffff;
  background: rgba(255, 255, 255, 0.07); border-radius: 6px; padding: 6px 10px; display: inline-block;
}
.bi-theme-dark .bi-assistant-chip { background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.14); color: #d5dbe2; }
.bi-theme-dark .bi-assistant-hint { color: #9aa4ae; }
.bi-theme-dark .bi-assistant-badge { background: rgba(46, 160, 67, 0.18); color: #7ee2a0; }
.bi-theme-dark .bi-assistant-badge.warn { background: rgba(187, 128, 9, 0.20); color: #f0c35c; }
.bi-theme-dark .bi-assistant-badge.err { background: rgba(248, 81, 73, 0.16); color: #ffa198; }
.bi-theme-dark .bi-assistant-actions button {
  background: transparent; border-color: rgba(255, 255, 255, 0.25); color: #e6e9ee;
}
/* v27: блок ответа читается сверху вниз: цифры -> фильтры -> действия.
 * Ужимаем «шум» (чипы/хинты) и делаем кнопки явными в обеих темах. */
#bi-assistant-answer .bi-assistant-chips { margin: 6px 0 2px; }
#bi-assistant-answer .bi-assistant-answer-text { margin: 4px 0; }
#bi-assistant-answer .bi-assistant-hint { margin-top: 4px; }
.bi-assistant-actions button {
  font-weight: 600; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.bi-assistant-actions button:disabled { opacity: 0.55; cursor: default; }
.bi-theme-light .bi-assistant-actions button:hover { background: #eef3fa; }
.bi-theme-dark .bi-assistant-actions button:hover { background: rgba(255, 255, 255, 0.08); }
.bi-assistant-actions .bi-assistant-hint { align-self: center; margin: 0 2px; }
.bi-assistant-login input { margin-bottom: 6px; width: 100%; box-sizing: border-box; }

/* Постоянная кнопка сброса фильтров AI-ассистента: видна на дашборде, пока
 * применены фильтры, переживает ручное обновление страницы (в отличие от
 * блока ответа, который может пропасть, оставив отфильтрованные графики).
 * Геометрия задаётся JS-ом (positionResetFab): ровно под штатной кнопкой
 * «Применить фильтры» в левом блоке; fallback — поверх штатной ссылки
 * сброса / центр сайдбара / центр окна. */
#bi-reset-fab {
  position: fixed;
  bottom: 18px;
  z-index: 9998;
  border: none;
  cursor: pointer;
  background: #b3261e;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  /* left: задаётся JS-ом (центр левого сайдбара Superset). Fallback — центр окна. */
  left: 50%;
  transform: translateX(-50%);
}
#bi-reset-fab:hover { background: #8f1d16; }
#bi-reset-fab:disabled { opacity: 0.6; cursor: default; }

/* Кнопка «Запомнить» (ручной контур обучения): появляется, когда запрос не
 * понят (needs_manual) — пользователь настраивает фильтры на дашборде,
 * жмёт «Применить фильтры», затем «Запомнить» (эталон -> правило).
 * Расположена НАД кнопкой сброса, зелёная (сохранение, не сброс). */
#bi-remember-fab {
  position: fixed;
  bottom: 150px;
  z-index: 9998;
  border: none;
  cursor: pointer;
  background: #1e8f5a;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}
#bi-remember-fab:hover { background: #146c45; }
#bi-remember-fab:disabled { opacity: 0.6; cursor: default; }

/* «Один график на запрос»: нерелевантные графики убираются из потока.
 * Маска вешается на КОЛОНКУ графика (.dragdroppable-column), т.к. ширина
 * 600px задана инлайн на .resizable-container внутри неё — маскировка самого
 * holder'а дыру бы не убрала. Правила переупаковки (дыр нет):
 *  - колонка нерелевантного: display:none, flex-ряд схлопывается;
 *  - единственная видимая колонка ряда: на всю ширину + её resizable;
 *  - ряд без видимых колонок: сворачивается целиком. */
.dragdroppable-column.bi-mask-col {
  display: none !important;
}
.dragdroppable-column.bi-wide-col {
  flex: 1 1 100% !important;
  width: 100% !important;
  max-width: 100% !important;
}
.dragdroppable-column.bi-wide-col > .resizable-container {
  width: 100% !important;
  max-width: 100% !important;
}
.dragdroppable-row.bi-row-collapsed {
  display: none !important;
}

/* v28: заголовок панели + кнопка-подсказка «?» в верхнем углу;
 * бабл «что можно спросить на этом дашборде» — НАД формой ввода.
 * Панель всегда светлая (см. #bi-assistant-panel), поэтому бабл без тем. */
.bi-assistant-head-title { flex: 1; }
.bi-assistant-head .bi-assistant-help {
  width: 22px; height: 22px; margin-left: 6px; padding: 0;
  border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.7);
  background: transparent; color: #fff; font-size: 13px; font-weight: 700;
  line-height: 1; cursor: pointer;
}
.bi-assistant-head .bi-assistant-help:hover { background: rgba(255, 255, 255, 0.18); }
.bi-assistant-bubble {
  margin: 0 0 10px;
  background: #eef3fa;
  border: 1px solid #b9cbe8;
  border-radius: 10px;
  padding: 8px 10px;
}
.bi-assistant-bubble[hidden] { display: none; }
.bi-assistant-bubble-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; color: #12315e; margin-bottom: 4px;
}
.bi-assistant-bubble-close {
  background: transparent; border: none; color: #12315e;
  font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.bi-assistant-bubble-intro { font-size: 11px; color: #47617f; margin-bottom: 6px; }
.bi-assistant-bubble-chips { display: flex; flex-wrap: wrap; gap: 4px; }
button.bi-assistant-bubble-chip {
  cursor: pointer; font: inherit; font-size: 11px;
  background: #fff; border: 1px solid #b9cbe8; color: #12315e;
  border-radius: 10px; padding: 2px 8px;
}
button.bi-assistant-bubble-chip:hover { border-color: #1a4a8c; background: #dfeafc; }
button.bi-assistant-bubble-chip:focus-visible {
  outline: 2px solid #1a4a8c; outline-offset: 1px;
}
